diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 09ae15d3b..000000000 --- a/.appveyor.yml +++ /dev/null @@ -1,85 +0,0 @@ -############################################################################ -# URDE appveyor build configuration -############################################################################ -clone_depth: 1 - -platform: - - x64 - -build_cloud: AXIODL-BUILDBOT -image: Windows - -build: - verbosity: detailed - -configuration: - - Release - -cache: - - C:\projects\deps - -install: - ############################################################################ - # All external dependencies are installed in C:\projects\deps - ############################################################################ - - if not exist C:\projects\deps mkdir C:\projects\deps - - cd C:\projects\deps - - ############################################################################ - # Install Ninja - ############################################################################ - - set NINJA_URL=https://github.com/ninja-build/ninja/releases/download/v1.10.0/ninja-win.zip - - if not exist ninja.zip appveyor DownloadFile %NINJA_URL% -FileName ninja.zip - - if not exist ninja 7z x ninja.zip -oC:\projects\deps\ninja > nul - - ############################################################################ - # Install a recent CMake - ############################################################################ - - set CMAKE_URL=https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4-win64-x64.zip - - if not exist cmake.zip appveyor DownloadFile %CMAKE_URL% -FileName cmake.zip - - if not exist cmake 7z x cmake.zip -oC:\projects\deps\cmake > nul - - ############################################################################ - # Install custom LLVM - ############################################################################ - - set LLVM_URL=https://axiodl.com/files/LLVM-10.0.1-win64.exe - - if not exist LLVM-10.0.1-win64.exe appveyor DownloadFile %LLVM_URL% -FileName LLVM-10.0.1-win64.exe - - if not exist llvm-10.0.1 LLVM-10.0.1-win64.exe /S /D=C:\projects\deps\llvm-10.0.1 - -before_build: - # Configure ninja - - set PATH=C:\projects\deps\ninja;%PATH% - - ninja --version - # Configure cmake - - set PATH=C:\projects\deps\cmake\cmake-3.16.4-win64-x64\bin;%PATH% - - cmake --version - # Configure LLVM - - set PATH=C:\projects\deps\llvm-10.0.1\bin;%PATH% - - llvm-config --version - - clang-cl -v - # Configure VS - - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" amd64 - # Fetch submodules - - cd %APPVEYOR_BUILD_FOLDER% - - git submodule update --init --recursive - -build_script: - - mkdir build - - cd build - - cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DLLVM_ROOT_DIR=C:\projects\deps\llvm-10.0.1 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_LINKER=lld-link -DCMAKE_AR=llvm-ar -DCMAKE_RANLIB=llvm-ranlib -GNinja .. - - ninja urde - -#notifications: -# - provider: Slack -# incoming_webhook: -# secure: uoO0I0PWyCx0KLjBOG6d17aSVuEEvYztB/UiF8J0LmTb2O735mAdWcuZHTImDFUGZxeI34/qzOB2JKqF+h8dZA5yiprSTkWIookqQjUokAM= -# - provider: Webhook -# url: https://skyhook.glitch.me/api/webhooks/345359672326356993/M8kBYpqr1JyVNhnAHBwNN5TnZmtWy9_msxAQoeOlaa73UhPn8gLU5uYZCjU1qsAi3sGN/appveyor -# method: POST -# on_build_success: true -# on_build_failure: true -# on_build_status_changed: false - -# Uncomment this to debug AppVeyor failures. -#on_finish: -# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..35276ad62 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,201 @@ +name: Build + +on: + push: + branches-ignore: + - master + paths-ignore: + - '*.json' + - '*.md' + - '*LICENSE' + pull_request: + +jobs: + build-linux: + name: Build Linux (${{matrix.name}} x86_64) + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + include: + - name: GCC + cc: gcc + cxx: g++ + - name: Clang + cc: clang + cxx: clang++ + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get -y install build-essential curl git cmake ninja-build llvm-dev libclang-dev clang lld \ + zlib1g-dev libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev \ + libpulse-dev libudev-dev libpng-dev libncurses5-dev libx11-xcb-dev python3 python-is-python3 qt5-default \ + libcurl4-openssl-dev + # free up disk space + # https://github.com/actions/virtual-environments/issues/2840#issuecomment-790492173 + echo Before + df -h . + sudo apt-get clean + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf /usr/local/share/boost + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + echo After + df -h . + + - name: Create build directory + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: | + cmake $GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_C_COMPILER=${{matrix.cc}} -DCMAKE_CXX_COMPILER=${{matrix.cxx}} + + - name: Build + working-directory: ${{github.workspace}}/build + run: cmake --build . + + build-macos: + name: Build macOS (AppleClang x86_64) + runs-on: macos-10.15 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install dependencies + run: | + brew update + brew install ninja qt@5 graphicsmagick imagemagick + brew link qt@5 + yarn global add create-dmg + + - name: Create build directory + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: | + export PATH="/usr/local/opt/qt@5/bin:$PATH" # FIXME remove + cmake $GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo + + - name: Build + working-directory: ${{github.workspace}}/build + run: cmake --build . + + build-windows-msvc: + name: Build Windows (MSVC x86_64) + if: 'false' # disabled due to memory constraints + runs-on: windows-2019 + env: + LLVM_VERSION: 10.0.1 + Qt_VERSION: 5.15.2 + IPP_VERSION: 2021.2.0.210 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install LLVM + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + $Filename = "LLVM-$env:LLVM_VERSION-win64.exe" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://axiodl.com/files/$Filename", "$TempDir\$Filename") + Start-Process "$TempDir\$Filename" -ArgumentList "/S /D=$env:RUNNER_WORKSPACE\LLVM" -Wait + + - name: Install vcpkg Qt + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + $Filename = "vcpkg-qt-$env:Qt_VERSION.7z" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://axiodl.com/files/$Filename", "$TempDir\$Filename") + 7z x "-o$env:RUNNER_WORKSPACE" -aos "$TempDir\$Filename" + + - name: Install dependencies + run: choco install ninja vulkan-sdk + + - name: Enable Visual Studio environment + uses: ilammy/msvc-dev-cmd@v1 + + - name: Create build directory + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: | + $workspace = $env:RUNNER_WORKSPACE -replace '\\', '/' + cmake $env:GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo ` + -DCMAKE_TOOLCHAIN_FILE="$workspace/vcpkg-qt-$env:Qt_VERSION/scripts/buildsystems/vcpkg.cmake" ` + -DVCPKG_TARGET_TRIPLET=x64-windows-static ` + -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_CXX_FLAGS= -DCMAKE_C_FLAGS= ` + -DLLVM_ROOT_DIR="$workspace/LLVM" + + - name: Build + working-directory: ${{github.workspace}}/build + run: cmake --build . + + build-windows-clang: + name: Build Windows (Clang x86_64) + runs-on: windows-2019 + env: + LLVM_VERSION: 10.0.1 + Qt_VERSION: 5.15.2 + IPP_VERSION: 2021.2.0.210 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install LLVM + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + $Filename = "LLVM-$env:LLVM_VERSION-win64.exe" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://axiodl.com/files/$Filename", "$TempDir\$Filename") + Start-Process "$TempDir\$Filename" -ArgumentList "/S /D=$env:RUNNER_WORKSPACE\LLVM" -Wait + + - name: Install vcpkg Qt + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + $Filename = "vcpkg-qt-$env:Qt_VERSION.7z" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://axiodl.com/files/$Filename", "$TempDir\$Filename") + 7z x "-o$env:RUNNER_WORKSPACE" -aos "$TempDir\$Filename" + + - name: Install dependencies + run: choco install ninja vulkan-sdk + + - name: Enable Visual Studio environment + uses: ilammy/msvc-dev-cmd@v1 + + - name: Create build directory + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: | + $workspace = $env:RUNNER_WORKSPACE -replace '\\', '/' + cmake $env:GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo ` + -DCMAKE_TOOLCHAIN_FILE="$workspace/vcpkg-qt-$env:Qt_VERSION/scripts/buildsystems/vcpkg.cmake" ` + -DVCPKG_TARGET_TRIPLET=x64-windows-static ` + -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ` + -DCMAKE_C_COMPILER=clang-cl ` + -DCMAKE_CXX_COMPILER=clang-cl ` + -DCMAKE_LINKER=lld-link ` + -DLLVM_ROOT_DIR="$workspace/LLVM" + + - name: Build + working-directory: ${{github.workspace}}/build + run: cmake --build . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..5a49422f7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,337 @@ +name: Release + +on: + push: + branches: + - master + paths-ignore: + - '*.json' + - '*.md' + - '*LICENSE' + +jobs: + build-linux: + name: Build Linux (${{matrix.name}} x86_64) + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + include: + - name: GCC + cc: gcc + cxx: g++ + - name: Clang + cc: clang + cxx: clang++ + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install dependencies + run: | + wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main" + sudo apt-get -y install build-essential curl git cmake ninja-build llvm-dev libclang-dev clang lld \ + zlib1g-dev libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev \ + libpulse-dev libudev-dev libpng-dev libncurses5-dev libx11-xcb-dev python3 python-is-python3 qt5-default \ + libcurl4-openssl-dev intel-oneapi-ipp-devel + + yarn global add @sentry/cli + echo "$(yarn global bin)" >> $GITHUB_PATH + + # free up disk space + # https://github.com/actions/virtual-environments/issues/2840#issuecomment-790492173 + echo Before + df -h . + sudo apt-get clean + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf /usr/local/share/boost + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + echo After + df -h . + + - name: Create build directory + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: | + cmake $GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_C_COMPILER=${{matrix.cc}} -DCMAKE_CXX_COMPILER=${{matrix.cxx}} \ + -DSENTRY_DSN="${{secrets.SENTRY_DSN}}" + + - name: Build + working-directory: ${{github.workspace}}/build + run: cmake --build . + + - name: Split debug information + run: ci/split-debug-linux.sh + + - name: Upload debug information + if: ${{matrix.name == 'Clang'}} + env: + SENTRY_AUTH_TOKEN: ${{secrets.SENTRY_AUTH_TOKEN}} + SENTRY_URL: ${{secrets.SENTRY_URL}} + run: ci/upload-debug-linux.sh + + - name: Generate AppImage + run: ci/build-appimage.sh + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: metaforce-${{env.METAFORCE_VERSION}}-linux-${{matrix.cc}}-x86_64 + path: | + Metaforce-*.AppImage + debug.tar.* + + build-macos: + name: Build macOS (AppleClang x86_64) + runs-on: macos-10.15 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install dependencies + run: | + brew update + brew install ninja qt@5 graphicsmagick imagemagick getsentry/tools/sentry-cli + brew link qt@5 + yarn global add create-dmg + + - name: Install Intel IPP + env: + IPP_VERSION: 2021.2.0.192 + run: | + NAME="m_ipp_oneapi_p_${IPP_VERSION}_offline" + curl -LSfs https://registrationcenter-download.intel.com/akdlm/irc_nas/17606/$NAME.dmg -o /tmp/$NAME.dmg + sudo hdiutil attach /tmp/$NAME.dmg -quiet + sudo /Volumes/$NAME/bootstrapper.app/Contents/MacOS/install.sh -c --action install --eula accept + sudo hdiutil detach /Volumes/$NAME -quiet + rm /tmp/$NAME.dmg + + - name: Create build directory + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: | + export PATH="/usr/local/opt/qt@5/bin:$PATH" # FIXME remove + cmake $GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DSENTRY_DSN="${{secrets.SENTRY_DSN}}" + + - name: Build + working-directory: ${{github.workspace}}/build + run: cmake --build . + + - name: Upload debug information + env: + SENTRY_AUTH_TOKEN: ${{secrets.SENTRY_AUTH_TOKEN}} + SENTRY_URL: ${{secrets.SENTRY_URL}} + run: ci/upload-debug-macos.sh + + - name: Import signing certificate + uses: devbotsxyz/xcode-import-certificate@master + with: + certificate-data: ${{ secrets.MACOS_CERTIFICATE_DATA }} + certificate-passphrase: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }} + keychain-password: ${{ secrets.MACOS_KEYCHAIN_PASSWORD }} + + - name: Deploy & codesign application + env: + ASC_USERNAME: ${{secrets.MACOS_ASC_USERNAME}} + ASC_PASSWORD: ${{secrets.MACOS_ASC_PASSWORD}} + ASC_TEAM_ID: ${{secrets.MACOS_ASC_TEAM_ID}} + CODESIGN_IDENT: ${{secrets.MACOS_CODESIGN_IDENT}} + run: ci/build-dmg.sh + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: metaforce-${{env.METAFORCE_VERSION}}-macos-appleclang-x86_64 + path: | + Metaforce *.dmg + debug.tar.* + + build-windows-msvc: + name: Build Windows (MSVC x86_64) + runs-on: [ self-hosted, windows, x64 ] + env: + LLVM_VERSION: 10.0.1 + Qt_VERSION: 5.15.2 +# IPP_VERSION: 2021.2.0.210 + SENTRY_CLI_VERSION: 1.63.2 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install LLVM + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + $Filename = "LLVM-$env:LLVM_VERSION-win64.exe" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://axiodl.com/files/$Filename", "$TempDir\$Filename") + Start-Process "$TempDir\$Filename" -ArgumentList "/S /D=$env:RUNNER_WORKSPACE\LLVM" -Wait + + - name: Install vcpkg Qt + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + $Filename = "vcpkg-qt-$env:Qt_VERSION.7z" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://axiodl.com/files/$Filename", "$TempDir\$Filename") + 7z x "-o$env:RUNNER_WORKSPACE" -aos "$TempDir\$Filename" + + - name: Download sentry-cli + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://github.com/getsentry/sentry-cli/releases/download/$env:SENTRY_CLI_VERSION/sentry-cli-Windows-x86_64.exe", "$TempDir\sentry-cli.exe") + +# - name: Install Intel IPP +# run: | +# $TempDir = "$env:RUNNER_WORKSPACE\temp" +# $Filename = "w_ipp_oneapi_p_${env:IPP_VERSION}_offline.exe" +# New-Item -Path "$TempDir" -ItemType Directory -ea 0 +# (New-Object Net.WebClient).DownloadFile("https://registrationcenter-download.intel.com/akdlm/irc_nas/$Filename", "$TempDir\$Filename") +# Start-Process "$TempDir\$Filename" -ArgumentList "--x --s --f $TempDir\ipp" -Wait +# Start-Process "$TempDir\ipp\bootstrapper.exe" -ArgumentList "--eula accept -c --action install" -Wait + +# - name: Install dependencies +# run: choco install ninja vulkan-sdk + + - name: Enable Visual Studio environment + uses: ilammy/msvc-dev-cmd@v1 + + - name: Create build directory + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: | + $workspace = $env:RUNNER_WORKSPACE -replace '\\', '/' + cmake $env:GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo ` + -DCMAKE_TOOLCHAIN_FILE="$workspace/vcpkg-qt-$env:Qt_VERSION/scripts/buildsystems/vcpkg.cmake" ` + -DVCPKG_TARGET_TRIPLET=x64-windows-static ` + -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_CXX_FLAGS= -DCMAKE_C_FLAGS= ` + -DLLVM_ROOT_DIR="$workspace/LLVM" ` + -DSENTRY_DSN="${{secrets.SENTRY_DSN}}" + + - name: Build + working-directory: ${{github.workspace}}/build + run: cmake --build . + + - name: Upload debug information + working-directory: ${{github.workspace}}/build/Binaries + env: + SENTRY_AUTH_TOKEN: ${{secrets.SENTRY_AUTH_TOKEN}} + SENTRY_URL: ${{secrets.SENTRY_URL}} + run: | + & "$env:RUNNER_WORKSPACE\temp\sentry-cli.exe" upload-dif --org axiodl --project metaforce --include-sources ` + metaforce.exe metaforce.pdb hecl.exe hecl.pdb metaforce-gui.exe metaforce-gui.pdb visigen.exe visigen.pdb + + - name: Compress PDBs + working-directory: ${{github.workspace}}/build/Binaries + run: 7z a -t7z debug.7z metaforce.pdb hecl.pdb metaforce-gui.pdb visigen.pdb + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: metaforce-${{env.METAFORCE_VERSION}}-win32-msvc-x86_64 + path: | + build/Binaries/metaforce.exe + build/Binaries/metaforce-gui.exe + build/Binaries/hecl.exe + build/Binaries/visigen.exe + build/Binaries/crashpad_handler.exe + build/Binaries/debug.7z + + build-windows-clang: + name: Build Windows (Clang x86_64) + runs-on: windows-2019 + env: + LLVM_VERSION: 10.0.1 + Qt_VERSION: 5.15.2 + IPP_VERSION: 2021.2.0.210 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install LLVM + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + $Filename = "LLVM-$env:LLVM_VERSION-win64.exe" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://axiodl.com/files/$Filename", "$TempDir\$Filename") + Start-Process "$TempDir\$Filename" -ArgumentList "/S /D=$env:RUNNER_WORKSPACE\LLVM" -Wait + + - name: Install vcpkg Qt + run: | + $TempDir = "$env:RUNNER_WORKSPACE\temp" + $Filename = "vcpkg-qt-$env:Qt_VERSION.7z" + New-Item -Path "$TempDir" -ItemType Directory -ea 0 + (New-Object Net.WebClient).DownloadFile("https://axiodl.com/files/$Filename", "$TempDir\$Filename") + 7z x "-o$env:RUNNER_WORKSPACE" -aos "$TempDir\$Filename" + +# - name: Install Intel IPP +# run: | +# $TempDir = "$env:RUNNER_WORKSPACE\temp" +# $Filename = "w_ipp_oneapi_p_${env:IPP_VERSION}_offline.exe" +# New-Item -Path "$TempDir" -ItemType Directory -ea 0 +# (New-Object Net.WebClient).DownloadFile("https://registrationcenter-download.intel.com/akdlm/irc_nas/17739/$Filename", "$TempDir\$Filename") +# Start-Process "$TempDir\$Filename" -ArgumentList "--x --s --f $TempDir\ipp" -Wait +# Start-Process "$TempDir\ipp\bootstrapper.exe" -ArgumentList "--eula accept -c --action install" -Wait + + - name: Install dependencies + run: choco install ninja vulkan-sdk + + - name: Enable Visual Studio environment + uses: ilammy/msvc-dev-cmd@v1 + + - name: Create build directory + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: | + $workspace = $env:RUNNER_WORKSPACE -replace '\\', '/' + cmake $env:GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo ` + -DCMAKE_TOOLCHAIN_FILE="$workspace/vcpkg-qt-$env:Qt_VERSION/scripts/buildsystems/vcpkg.cmake" ` + -DVCPKG_TARGET_TRIPLET=x64-windows-static ` + -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ` + -DCMAKE_C_COMPILER=clang-cl ` + -DCMAKE_CXX_COMPILER=clang-cl ` + -DCMAKE_LINKER=lld-link ` + -DLLVM_ROOT_DIR="$workspace/LLVM" ` + -DSENTRY_DSN="${{secrets.SENTRY_DSN}}" + + - name: Build + working-directory: ${{github.workspace}}/build + run: cmake --build . + + - name: Compress PDBs + working-directory: ${{github.workspace}}/build/Binaries + run: 7z a -t7z debug.7z metaforce.pdb hecl.pdb metaforce-gui.pdb visigen.pdb + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: metaforce-${{env.METAFORCE_VERSION}}-win32-clang-x86_64 + path: | + build/Binaries/metaforce.exe + build/Binaries/metaforce-gui.exe + build/Binaries/hecl.exe + build/Binaries/visigen.exe + build/Binaries/crashpad_handler.exe + build/Binaries/debug.7z diff --git a/.gitignore b/.gitignore index dd4d67057..de2f93579 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ version.h *.autosave docs/* .idea/ -Editor/platforms/win/urde.rc +Editor/platforms/win/metaforce.rc .vs/ out/ cmake-build-*/ \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 8bd82cb0d..000000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,198 +0,0 @@ -.build:variables: - variables: &build_variables - GIT_SUBMODULE_STRATEGY: recursive - -.build:macos: &macos_definition - stage: build - tags: - - macos - script: - - mkdir build - - cd build - - > - cmake - -GNinja - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DURDE_DLPACKAGE=urde-$CI_PIPELINE_ID-macos-x86_64-$URDE_VECTOR_ISA - -DURDE_VECTOR_ISA=$URDE_VECTOR_ISA - .. - - ninja urde hecl visigen - - cd Binaries - - cp -R urde.app $CI_PROJECT_DIR/URDE.app - - cd $CI_PROJECT_DIR - - strip -S -o URDE.app/Contents/MacOS/urde URDE.app/Contents/MacOS/urde - - strip -S -o URDE.app/Contents/MacOS/hecl URDE.app/Contents/MacOS/hecl - - strip -S -o URDE.app/Contents/MacOS/visigen URDE.app/Contents/MacOS/visigen - - (if [ "${URDE_MACOS_CODESIGN_UID}" != "" ]; then codesign -s $URDE_MACOS_CODESIGN_UID --deep URDE.app; else echo "Unable to sign app bundle :("; fi); - only: - - release - - dev - artifacts: - name: "urde-$CI_PIPELINE_ID-macos-x86_64-$URDE_VECTOR_ISA" - paths: - - URDE.app/ - expire_in: 1 week - -build:macos:sse3: - <<: *macos_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: sse3 - -build:macos:sse41: - <<: *macos_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: sse41 - -build:macos:avx: - <<: *macos_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: avx - -build:macos:avx2: - <<: *macos_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: avx2 - -.build:linux: &linux_definition - stage: build - tags: - - linux - script: - - mkdir build - - cd build - - > - cmake - -GNinja - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DURDE_DLPACKAGE=urde-$CI_PIPELINE_ID-linux-x86_64-$URDE_VECTOR_ISA - -DURDE_VECTOR_ISA=$URDE_VECTOR_ISA - .. - - nice -n19 ninja -j8 urde hecl visigen - - cp Binaries/urde $CI_PROJECT_DIR - - strip --strip-debug -o $CI_PROJECT_DIR/urde Binaries/urde - - rm -r $CI_PROJECT_DIR/hecl - - strip --strip-debug -o $CI_PROJECT_DIR/hecl Binaries/hecl - - rm -r $CI_PROJECT_DIR/visigen - - strip --strip-debug -o $CI_PROJECT_DIR/visigen Binaries/visigen - only: - - release - - dev - artifacts: - name: "urde-$CI_PIPELINE_ID-linux-x86_64-$URDE_VECTOR_ISA" - paths: - - urde - - hecl - - visigen - expire_in: 1 week - -build:linux:sse3: - <<: *linux_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: sse3 - -build:linux:sse41: - <<: *linux_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: sse41 - -build:linux:avx: - <<: *linux_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: avx - -build:linux:avx2: - <<: *linux_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: avx2 - -.build:win32: &win32_definition - stage: build - tags: - - win32 - script: - - cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat`" && set > %temp%\vcvars.txt" - - > - Get-Content "$env:temp\vcvars.txt" | Foreach-Object { - if ($_ -match "^(.*?)=(.*)$") { - Set-Content "env:\$($matches[1])" $matches[2] - } - } - - mkdir build - - cd build - - > - cmake - -GNinja - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded - -DURDE_DLPACKAGE="urde-$env:CI_PIPELINE_ID-win32-x86_64-$env:URDE_VECTOR_ISA" - -DURDE_VECTOR_ISA="$env:URDE_VECTOR_ISA" - -DLLVM_ROOT_DIR=C:\projects\deps\llvm - -DCMAKE_C_FLAGS= - -DCMAKE_CXX_FLAGS= - .. - - ninja urde hecl visigen - - 'copy Binaries\urde.exe "$env:CI_PROJECT_DIR\urde.exe"' - - 'pdbcopy Binaries\urde.pdb "$env:CI_PROJECT_DIR\urde.pdb" -p' - - 'copy Binaries\hecl.exe "$env:CI_PROJECT_DIR\hecl.exe"' - - 'pdbcopy Binaries\hecl.pdb "$env:CI_PROJECT_DIR\hecl.pdb" -p' - - 'copy Binaries\visigen.exe "$env:CI_PROJECT_DIR\visigen.exe"' - - 'pdbcopy Binaries\visigen.pdb "$env:CI_PROJECT_DIR\visigen.pdb" -p' - only: - - release - - dev - artifacts: - name: "urde-$env:CI_PIPELINE_ID-win32-x86_64-$env:URDE_VECTOR_ISA" - paths: - - urde.exe - - urde.pdb - - hecl.exe - - hecl.pdb - - visigen.exe - - visigen.pdb - expire_in: 1 week - -build:win32:sse2: - <<: *win32_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: sse2 - -build:win32:sse41: - <<: *win32_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: sse41 - -build:win32:avx: - <<: *win32_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: avx - -build:win32:avx2: - <<: *win32_definition - variables: - <<: *build_variables - URDE_VECTOR_ISA: avx2 - -deploy: - stage: deploy - only: - - release - - dev - dependencies: [] - tags: - - server - variables: - GIT_STRATEGY: none - script: - - python3 /var/lib/gitlab-runner/deploy_urde.py $CI_PIPELINE_ID $CI_COMMIT_REF_NAME - diff --git a/.gitmodules b/.gitmodules index 04f58235d..9d50707ab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,42 +1,56 @@ -[submodule "hecl"] - path = hecl - url = ../hecl.git [submodule "nod"] - path = nod + path = extern/nod url = ../nod.git + branch = master [submodule "amuse"] - path = amuse + path = extern/amuse url = ../amuse.git + branch = master [submodule "kabufuda"] - path = kabufuda + path = extern/kabufuda url = ../kabufuda.git + branch = master [submodule "jbus"] - path = jbus + path = extern/jbus url = ../jbus.git + branch = master [submodule "assetnameparser/tinyxml2"] - path = assetnameparser/tinyxml2 + path = extern/tinyxml2 url = ../tinyxml2.git -[submodule "hecl-gui"] - path = hecl-gui - url = ../hecl-gui.git + branch = master [submodule "sanitizers-cmake"] - path = sanitizers-cmake + path = extern/sanitizers-cmake url = https://github.com/arsenm/sanitizers-cmake.git + branch = master [submodule "discord-rpc"] - path = discord-rpc + path = extern/discord-rpc url = https://github.com/discordapp/discord-rpc.git + branch = master [submodule "rapidjson"] - path = rapidjson + path = extern/rapidjson url = https://github.com/Tencent/rapidjson.git + branch = master [submodule "NESEmulator/fixNES"] - path = NESEmulator/fixNES + path = extern/fixNES url = https://github.com/FIX94/fixNES.git -[submodule "Editor/locale"] - path = Editor/locale - url = ../urde-translations.git -[submodule "boo2"] - path = boo2 + branch = master +[submodule "extern/libSquish"] + path = extern/libSquish + url = ../libSquish.git + branch = master +[submodule "extern/athena"] + path = extern/athena + url = ../../libAthena/athena.git + branch = master +[submodule "extern/boo2"] + path = extern/boo2 url = ../boo2.git + branch = master +[submodule "extern/libjpeg-turbo"] + path = extern/libjpeg-turbo + url = ../libjpeg-turbo.git + branch = thp [submodule "zeus"] - path = zeus + path = extern/zeus url = ../zeus.git + branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index 79a94369e..2698bd21b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,26 +1,80 @@ cmake_minimum_required(VERSION 3.15 FATAL_ERROR) -# Allow target_link_libraries with targets in other directories -cmake_policy(SET CMP0079 NEW) -# Set MSVC runtime library flags from CMAKE_MSVC_RUNTIME_LIBRARY -cmake_policy(SET CMP0091 NEW) +cmake_policy(VERSION 3.15...3.20) + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING + "Build type options: Debug Release RelWithDebInfo MinSizeRel" FORCE) +endif () + +# obtain revision info from git +find_package(Git) +if (GIT_FOUND) + # make sure version information gets re-run when the current Git HEAD changes + execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --git-path HEAD + OUTPUT_VARIABLE metaforce_git_head_filename + OUTPUT_STRIP_TRAILING_WHITESPACE) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${metaforce_git_head_filename}") + + execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --symbolic-full-name HEAD + OUTPUT_VARIABLE metaforce_git_head_symbolic + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND ${GIT_EXECUTABLE} rev-parse --git-path ${metaforce_git_head_symbolic} + OUTPUT_VARIABLE metaforce_git_head_symbolic_filename + OUTPUT_STRIP_TRAILING_WHITESPACE) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${metaforce_git_head_symbolic_filename}") + + # defines METAFORCE_WC_REVISION + execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + OUTPUT_VARIABLE METAFORCE_WC_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) + # defines METAFORCE_WC_DESCRIBE + execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --tag --long --dirty + OUTPUT_VARIABLE METAFORCE_WC_DESCRIBE + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # remove hash (and trailing "-0" if needed) from description + string(REGEX REPLACE "(-0)?-[^-]+((-dirty)?)$" "\\2" METAFORCE_WC_DESCRIBE "${METAFORCE_WC_DESCRIBE}") + + # defines METAFORCE_WC_BRANCH + execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE METAFORCE_WC_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + # defines METAFORCE_WC_DATE + execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} log -1 --format=%ad + OUTPUT_VARIABLE METAFORCE_WC_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE) +else () + message(STATUS "Unable to find git, commit information will not be available") +endif () + +if (METAFORCE_WC_DESCRIBE) + string(REGEX REPLACE "v([0-9]+)\.([0-9]+)\.([0-9]+)\-([0-9]+).*" "\\1.\\2.\\3.\\4" METAFORCE_VERSION_STRING "${METAFORCE_WC_DESCRIBE}") + string(REGEX REPLACE "v([0-9]+)\.([0-9]+)\.([0-9]+).*" "\\1.\\2.\\3" METAFORCE_VERSION_STRING "${METAFORCE_VERSION_STRING}") +else () + set(METAFORCE_WC_DESCRIBE "UNKNOWN-VERSION") + set(METAFORCE_VERSION_STRING "0.0.0") +endif () + +string(TIMESTAMP CURRENT_YEAR "%Y") + +# Add version information to CI environment variables +if(DEFINED ENV{GITHUB_ENV}) + file(APPEND "$ENV{GITHUB_ENV}" "METAFORCE_VERSION=${METAFORCE_WC_DESCRIBE}") +endif() +message(STATUS "Metaforce version set to ${METAFORCE_WC_DESCRIBE}") +project(metaforce LANGUAGES C CXX ASM VERSION ${METAFORCE_VERSION_STRING}) + +if (APPLE) + set(PLATFORM_NAME macos) +elseif (WIN32) + set(PLATFORM_NAME win32) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(PLATFORM_NAME linux) +endif () set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries) -if(APPLE) - # Shaddup Xcode - function(add_executable TARGET) - _add_executable(${TARGET} ${ARGN}) - set_target_properties(${TARGET} PROPERTIES XCODE_ATTRIBUTE_WARNING_CFLAGS "") - endfunction() - function(add_library TARGET) - _add_library(${TARGET} ${ARGN}) - list(GET ARGV 1 ARG1) - if(NOT ${ARG1} STREQUAL INTERFACE AND NOT ${ARG1} STREQUAL ALIAS) - set_target_properties(${TARGET} PROPERTIES XCODE_ATTRIBUTE_WARNING_CFLAGS "") - endif() - endfunction() -endif() - if(APPLE AND NOT CMAKE_OSX_SYSROOT) # If the Xcode SDK is lagging behind system version, CMake needs this done first execute_process(COMMAND xcrun --sdk macosx --show-sdk-path @@ -28,8 +82,8 @@ if(APPLE AND NOT CMAKE_OSX_SYSROOT) OUTPUT_STRIP_TRAILING_WHITESPACE) endif() -option(URDE_CROSSCOMPILING "Don't build tools; attempt package import" OFF) -if (URDE_CROSSCOMPILING) +option(METAFORCE_CROSSCOMPILING "Don't build tools; attempt package import" OFF) +if (METAFORCE_CROSSCOMPILING) set(CMAKE_CROSSCOMPILING On) endif() @@ -37,8 +91,6 @@ if(CMAKE_CROSSCOMPILING) set(HAVE_WORDS_BIGENDIAN_EXITCODE 0 CACHE INTEGER "Makes soxr happy" FORCE) endif() -project(urde VERSION 0.1.0) - # MSVC has a "latest" flag, which always uses the newest standard # when available. GCC and Clang posess no such flag, and must be # manually enforced. CMake, curiously, also doesn't have a "latest" @@ -51,26 +103,28 @@ endif() set(BUILD_SHARED_LIBS OFF CACHE BOOL "Force shared libs off" FORCE) set(BUILD_STATIC_LIBS ON CACHE BOOL "Force static libs on" FORCE) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/sanitizers-cmake/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/extern/sanitizers-cmake/cmake") find_package(Sanitizers) -if (NX) - set(URDE_VECTOR_ISA "neon") -else() - set(URDE_VECTOR_ISA "sse2" CACHE STRING "Vector ISA to build for (sse2, sse3, sse41, avx, avx2)") -endif() +if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64) + set(METAFORCE_VECTOR_ISA "sse41" CACHE STRING "Vector ISA to build for (sse2, sse3, sse41, avx, avx2)") +endif () if(MSVC) - if(${URDE_VECTOR_ISA} STREQUAL "avx2") + if(${METAFORCE_VECTOR_ISA} STREQUAL "avx2") add_compile_options(/arch:AVX2) add_compile_definitions(__SSE4_1__=1) message(STATUS "Building with AVX2 Vector ISA") - elseif(${URDE_VECTOR_ISA} STREQUAL "avx") + elseif(${METAFORCE_VECTOR_ISA} STREQUAL "avx") add_compile_options(/arch:AVX) add_compile_definitions(__SSE4_1__=1) message(STATUS "Building with AVX Vector ISA") - elseif(${URDE_VECTOR_ISA} STREQUAL "sse41") + elseif(${METAFORCE_VECTOR_ISA} STREQUAL "sse41") add_compile_definitions(__SSE4_1__=1) + # clang-cl 10 requires -msse4.1, may be fixed in newer versions? + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL Clang) + add_compile_options($<$,$>:-msse4.1>) + endif() message(STATUS "Building with SSE4.1 Vector ISA") else() message(STATUS "Building with SSE2 Vector ISA") @@ -78,7 +132,7 @@ if(MSVC) if(${CMAKE_GENERATOR} MATCHES "Visual Studio*") set(VS_OPTIONS "/MP") - set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT urde) + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT metaforce) endif() # Shaddup MSVC @@ -86,9 +140,24 @@ if(MSVC) _CRT_SECURE_NO_WARNINGS=1 D_SCL_SECURE_NO_WARNINGS=1 _SCL_SECURE_NO_DEPRECATE=1 _CRT_NONSTDC_NO_WARNINGS=1 _ENABLE_EXTENDED_ALIGNED_STORAGE=1 NOMINMAX=1) - add_compile_options(/IGNORE:4221 /wd4018 /wd4800 /wd4005 /wd4311 /wd4068 - /wd4267 /wd4244 /wd4200 /wd4305 /wd4067 /wd4146 /wd4309 /wd4805 ${VS_OPTIONS}) + add_compile_options(/IGNORE:4221 + $<$,$>:/wd4018> + $<$,$>:/wd4800> + $<$,$>:/wd4005> + $<$,$>:/wd4311> + $<$,$>:/wd4068> + $<$,$>:/wd4267> + $<$,$>:/wd4244> + $<$,$>:/wd4200> + $<$,$>:/wd4305> + $<$,$>:/wd4067> + $<$,$>:/wd4146> + $<$,$>:/wd4309> + $<$,$>:/wd4805> + ${VS_OPTIONS}) + string(REPLACE "/GR " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE " /EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_compile_options( # Disable exceptions $<$:/EHsc-> @@ -108,7 +177,6 @@ if(MSVC) # Use latest C++ standard. $<$:/std:c++latest> ) - add_compile_definitions(FMT_EXCEPTIONS=0 _HAS_EXCEPTIONS=0) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # Flags for MSVC (not clang-cl) @@ -120,40 +188,39 @@ if(MSVC) $<$:/Zc:throwingNew> # Link-time Code Generation for Release builds - $<$,$>:/GL> + $<$:/GL> ) # Link-time Code Generation for Release builds set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "/LTCG") - set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "/LTCG") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") - set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") + set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") endif() else() - if(${URDE_VECTOR_ISA} STREQUAL "native") + if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL x86_64) + if(${METAFORCE_VECTOR_ISA} STREQUAL "native") add_compile_options(-march=native) message(STATUS "Building with native ISA") - elseif(${URDE_VECTOR_ISA} STREQUAL "avx2") + elseif(${METAFORCE_VECTOR_ISA} STREQUAL "avx2") add_compile_options(-mavx2) message(STATUS "Building with AVX2 Vector ISA") - elseif(${URDE_VECTOR_ISA} STREQUAL "avx") + elseif(${METAFORCE_VECTOR_ISA} STREQUAL "avx") add_compile_options(-mavx) message(STATUS "Building with AVX Vector ISA") - elseif(${URDE_VECTOR_ISA} STREQUAL "sse41") + elseif(${METAFORCE_VECTOR_ISA} STREQUAL "sse41") add_compile_options(-msse4.1) message(STATUS "Building with SSE4.1 Vector ISA") - elseif(${URDE_VECTOR_ISA} STREQUAL "sse3") + elseif(${METAFORCE_VECTOR_ISA} STREQUAL "sse3") add_compile_options(-msse3) message(STATUS "Building with SSE3 Vector ISA") - elseif(${URDE_VECTOR_ISA} STREQUAL "sse2") + elseif(${METAFORCE_VECTOR_ISA} STREQUAL "sse2") add_compile_options(-msse2) message(STATUS "Building with SSE2 Vector ISA") - elseif(${URDE_VECTOR_ISA} STREQUAL "neon") - message(STATUS "Building with NEON Vector ISA") else() message(STATUS "Building with x87 Vector ISA") endif() + endif() include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-fno-plt HAS_NO_PLT) @@ -161,12 +228,12 @@ else() add_compile_options(-fno-plt) endif() check_cxx_compiler_flag(-fno-asynchronous-unwind-tables HAS_NO_ASYNC_UNWIND_TABLES) - if (HAS_NO_ASYNC_UNWIND_TABLES) + if (HAS_NO_ASYNC_UNWIND_TABLES AND ${CMAKE_BUILD_TYPE} STREQUAL Release) # Binary size reduction add_compile_options(-fno-asynchronous-unwind-tables) endif() - if(URDE_MSAN) + if(METAFORCE_MSAN) add_compile_options($<$:-stdlib=libc++> -fsanitize=memory -fsanitize-memory-track-origins -fsanitize-recover=all) endif() @@ -179,13 +246,16 @@ else() if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") add_compile_options(-Wno-unknown-warning-option -Wno-unused-private-field) elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - add_compile_options(-Wno-lto-type-mismatch) + add_compile_options(-Wno-lto-type-mismatch -Wno-maybe-uninitialized) endif() - add_compile_definitions(FMT_EXCEPTIONS=0) if(APPLE) add_compile_options(-Wno-error=deprecated-declarations - $<$,$>:-flto=thin>) + $<$:-flto=thin>) + if (METAFORCE_ASAN) + add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope) + add_link_options(-fsanitize=address -fsanitize-address-use-after-scope) + endif () endif() endif() @@ -197,9 +267,9 @@ endif() if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - if(${CMAKE_BUILD_TYPE} STREQUAL Debug) + if(${CMAKE_BUILD_TYPE} STREQUAL Debug OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo) # This is required to summarize std::string - add_compile_options(-fno-limit-debug-info) + add_compile_options(-fno-limit-debug-info -fno-omit-frame-pointer) endif() option(USE_LD_LLD "Link with LLD" ON) elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") @@ -241,7 +311,11 @@ if(USE_LD_GOLD) if("${LD_VERSION}" MATCHES "GNU gold") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags") - if(USE_LTO) + if (USE_SPLIT_DWARF) + add_compile_options(-gsplit-dwarf -Wl,--gdb-index) + add_link_options(-gsplit-dwarf -Wl,--gdb-index) + message(STATUS "GNU gold linker enabled with split DWARF.") + elseif (USE_LTO) add_compile_options(-flto) add_link_options(-flto) message(STATUS "GNU gold linker enabled with LTO.") @@ -257,17 +331,15 @@ endif() # Add discord-rpc here if(NOT GEKKO AND NOT NX) - set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/discord-rpc) + set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/discord-rpc) if (NOT CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/fake-prefix) endif() - add_subdirectory(discord-rpc/src) - target_include_directories(discord-rpc PRIVATE rapidjson/include PUBLIC discord-rpc/include) + add_subdirectory(extern/discord-rpc/src) + target_include_directories(discord-rpc PRIVATE extern/rapidjson/include PUBLIC extern/discord-rpc/include) endif() -add_subdirectory(nod) - -set(HECL_DLPACKAGE ${URDE_DLPACKAGE}) +add_subdirectory(extern/nod) set(DATA_SPEC_LIBS RetroDataSpec AssetNameMap) set(HECL_DATASPEC_DECLS @@ -300,7 +372,9 @@ set(HECL_DATASPEC_PUSHES # TODO: Fix weirdness find_package(hsh REQUIRED) add_subdirectory(boo2) +add_subdirectory(extern/xxhash) add_subdirectory(hecl) +add_subdirectory(extern/zeus) target_include_directories(hecl-full PRIVATE ${CMAKE_SOURCE_DIR}) target_include_directories(hecl-light PRIVATE ${CMAKE_SOURCE_DIR}) target_link_libraries(hecl-full PRIVATE zeus nod) @@ -315,19 +389,18 @@ if(NOT TARGET atdna) # Import native atdna if cross-compiling find_package(atdna REQUIRED) if(NOT TARGET atdna) - message(FATAL_ERROR "atdna required for building URDE; please verify LLVM installation") + message(FATAL_ERROR "atdna required for building Metaforce; please verify LLVM installation") endif() endif() -add_subdirectory(amuse) -add_subdirectory(zeus) +add_subdirectory(extern/amuse) add_subdirectory(assetnameparser) add_compile_definitions(URDE_ZIP_INPUT_STREAM=1) # Enable CZipInputStream now that zlib header is known add_subdirectory(DataSpec) -add_subdirectory(kabufuda) +add_subdirectory(extern/kabufuda) -add_subdirectory(jbus) -set(JBUS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jbus/include) +add_subdirectory(extern/jbus) +set(JBUS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/jbus/include) set(CLIENT_SOURCES ${CMAKE_SOURCE_DIR}/Editor/ProjectResourceFactoryBase.hpp @@ -343,35 +416,25 @@ add_subdirectory(visigen) add_dependencies(hecl visigen) if (NOT WINDOWS_STORE AND NOT NX) - find_package(Qt5Widgets PATHS /usr/local/opt/qt) - if (Qt5Widgets_FOUND) - message(STATUS "Qt5 found, hecl-gui will be built") - add_subdirectory(hecl-gui) + if(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) + set(QT_HOMEBREW_PATH /usr/local/opt/qt) + elseif(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) + set(QT_HOMEBREW_PATH /opt/homebrew/opt/qt) else() - message(STATUS "Qt5 not found, hecl-gui will not be built") + set(QT_HOMEBREW_PATH "") + endif() + + find_package(Qt6Widgets QUIET PATHS ${QT_HOMEBREW_PATH}) + find_package(Qt5Widgets QUIET PATHS ${QT_HOMEBREW_PATH}) + if (Qt6Widgets_FOUND) + message(STATUS "Qt6 found, metaforce-gui will be built") + add_subdirectory(metaforce-gui) + elseif(Qt5Widgets_FOUND) + message(STATUS "Qt5 found, metaforce-gui will be built") + add_subdirectory(metaforce-gui) + else() + message(STATUS "Qt5-6 not found, metaforce-gui will not be built") endif() endif() -unset(GIT_EXECUTABLE CACHE) -find_package(Git) -if(GIT_FOUND) - # Get the current working branch - execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE ) - - # Get the latest abbreviated commit hash of the working branch - execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%h WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE - GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE - GIT_COMMIT_HASH_FULL OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%ad WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE - GIT_COMMIT_DATE OUTPUT_STRIP_TRAILING_WHITESPACE) -else() - message(STATUS "Unable to find GIT, commit information will not be available") - set(GIT_BRANCH "") - set(GIT_COMMIT_HASH "") - set(GIT_COMMIT_HASH_FULL "") - set(GIT_COMMIT_DATE "") -endif() - configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_BINARY_DIR}/version.h) diff --git a/CMakeSettings.json b/CMakeSettings.json index 56cbf38af..9934b0489 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -13,7 +13,7 @@ "variables": [ { "name": "CMAKE_MSVC_RUNTIME_LIBRARY", - "value": "MultiThreadedDebug", + "value": "MultiThreadedDebugDLL", "type": "STRING" }, { @@ -30,16 +30,6 @@ "name": "CMAKE_LINKER", "value": "C:\\Program Files\\LLVM\\bin\\lld-link.exe", "type": "FILEPATH" - }, - { - "name": "CMAKE_AR", - "value": "C:\\Program Files\\LLVM\\bin\\llvm-ar.exe", - "type": "FILEPATH" - }, - { - "name": "CMAKE_RANLIB", - "value": "C:\\Program Files\\LLVM\\bin\\llvm-ranlib.exe", - "type": "FILEPATH" } ] }, @@ -56,7 +46,7 @@ "variables": [ { "name": "CMAKE_MSVC_RUNTIME_LIBRARY", - "value": "MultiThreaded", + "value": "MultiThreadedDLL", "type": "STRING" }, { @@ -73,16 +63,6 @@ "name": "CMAKE_LINKER", "value": "C:\\Program Files\\LLVM\\bin\\lld-link.exe", "type": "FILEPATH" - }, - { - "name": "CMAKE_AR", - "value": "C:\\Program Files\\LLVM\\bin\\llvm-ar.exe", - "type": "FILEPATH" - }, - { - "name": "CMAKE_RANLIB", - "value": "C:\\Program Files\\LLVM\\bin\\llvm-ranlib.exe", - "type": "FILEPATH" } ] }, @@ -126,16 +106,6 @@ "name": "CMAKE_LINKER", "value": "C:\\Program Files\\LLVM\\bin\\lld-link.exe", "type": "FILEPATH" - }, - { - "name": "CMAKE_AR", - "value": "C:\\Program Files\\LLVM\\bin\\llvm-ar.exe", - "type": "FILEPATH" - }, - { - "name": "CMAKE_RANLIB", - "value": "C:\\Program Files\\LLVM\\bin\\llvm-ranlib.exe", - "type": "FILEPATH" } ] }, @@ -152,7 +122,7 @@ "variables": [ { "name": "CMAKE_MSVC_RUNTIME_LIBRARY", - "value": "MultiThreadedDebug", + "value": "MultiThreadedDebugDLL", "type": "STRING" }, { @@ -180,7 +150,7 @@ "variables": [ { "name": "CMAKE_MSVC_RUNTIME_LIBRARY", - "value": "MultiThreaded", + "value": "MultiThreadedDLL", "type": "STRING" }, { diff --git a/DataSpec/DNACommon/CMDL.cpp b/DataSpec/DNACommon/CMDL.cpp index be1bc83e4..c137c0146 100644 --- a/DataSpec/DNACommon/CMDL.cpp +++ b/DataSpec/DNACommon/CMDL.cpp @@ -1002,7 +1002,10 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os, athena::io::I FinishBlenderMesh(os, matSetCount, meshIdx); if (rp.first.second) { - os.format(FMT_STRING("mesh.cskr_id = '{}'\n"), rp.first.first); + if (entry.id != 0xB333E1D7) { + // This is the beta phazon suit, we want the (incorrect) weight information, but we don't want to keep the CSKR id + os.format(FMT_STRING("mesh.cskr_id = '{}'\n"), rp.first.first); + } rp.second.second->sendVertexGroupsToBlender(os); } @@ -1014,7 +1017,7 @@ ReadGeomSectionsToBlender, DNAMP1::MaterialSet, std::pair, std::pair>, DNACMDL::SurfaceHeader_1>( hecl::blender::PyOutStream& os, athena::io::IStreamReader& reader, PAKRouter& pakRouter, - const typename PAKRouter::EntryType& entry, + const PAKRouter::EntryType& entry, const std::pair, std::pair>& rp, bool shortNormals, bool shortUVs, std::vector& vertAttribs, int meshIdx, atUint32 secCount, atUint32 matSetCount, const atUint32* secSizes, atUint32 surfaceCount); @@ -1024,7 +1027,7 @@ ReadGeomSectionsToBlender, DNAMP2::MaterialSet, std::pair, std::pair>, DNACMDL::SurfaceHeader_2>( hecl::blender::PyOutStream& os, athena::io::IStreamReader& reader, PAKRouter& pakRouter, - const typename PAKRouter::EntryType& entry, + const PAKRouter::EntryType& entry, const std::pair, std::pair>& rp, bool shortNormals, bool shortUVs, std::vector& vertAttribs, int meshIdx, atUint32 secCount, atUint32 matSetCount, const atUint32* secSizes, atUint32 surfaceCount); @@ -1034,7 +1037,7 @@ ReadGeomSectionsToBlender, DNAMP3::MaterialSet, std::pair, std::pair>, DNACMDL::SurfaceHeader_3>( hecl::blender::PyOutStream& os, athena::io::IStreamReader& reader, PAKRouter& pakRouter, - const typename PAKRouter::EntryType& entry, + const PAKRouter::EntryType& entry, const std::pair, std::pair>& rp, bool shortNormals, bool shortUVs, std::vector& vertAttribs, int meshIdx, atUint32 secCount, atUint32 matSetCount, const atUint32* secSizes, atUint32 surfaceCount); diff --git a/DataSpec/DNACommon/CMakeLists.txt b/DataSpec/DNACommon/CMakeLists.txt index b4387de34..116564f8a 100644 --- a/DataSpec/DNACommon/CMakeLists.txt +++ b/DataSpec/DNACommon/CMakeLists.txt @@ -9,7 +9,7 @@ make_dnalist(CMDL EGMC SAVWCommon ParticleCommon - URDEVersionInfo + MetaforceVersionInfo Tweaks/ITweakPlayerGun) set(DNACOMMON_SOURCES @@ -41,7 +41,7 @@ set(DNACOMMON_SOURCES RigInverter.hpp RigInverter.cpp AROTBuilder.hpp AROTBuilder.cpp OBBTreeBuilder.hpp OBBTreeBuilder.cpp - URDEVersionInfo.hpp + MetaforceVersionInfo.hpp Tweaks/ITweak.hpp Tweaks/TweakWriter.hpp Tweaks/ITweakGame.hpp diff --git a/DataSpec/DNACommon/CRSC.cpp b/DataSpec/DNACommon/CRSC.cpp index 45069cd35..a66b912f0 100644 --- a/DataSpec/DNACommon/CRSC.cpp +++ b/DataSpec/DNACommon/CRSC.cpp @@ -11,12 +11,12 @@ AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_CRSM>) template <> std::string_view PPImpl<_CRSM>::DNAType() { - return "urde::CRSM"sv; + return "CRSM"sv; } template <> std::string_view PPImpl<_CRSM>::DNAType() { - return "urde::CRSM"sv; + return "CRSM"sv; } template diff --git a/DataSpec/DNACommon/DNACommon.cpp b/DataSpec/DNACommon/DNACommon.cpp index d82416c42..42b8763e3 100644 --- a/DataSpec/DNACommon/DNACommon.cpp +++ b/DataSpec/DNACommon/DNACommon.cpp @@ -3,7 +3,7 @@ namespace DataSpec { -logvisor::Module LogDNACommon("urde::DNACommon"); +logvisor::Module LogDNACommon("DataSpec::DNACommon"); thread_local SpecBase* g_curSpec; thread_local PAKRouterBase* g_PakRouter; thread_local hecl::blender::Token* g_ThreadBlenderToken; diff --git a/DataSpec/DNACommon/ELSC.cpp b/DataSpec/DNACommon/ELSC.cpp index 7ea266f71..32d3d3cac 100644 --- a/DataSpec/DNACommon/ELSC.cpp +++ b/DataSpec/DNACommon/ELSC.cpp @@ -11,12 +11,12 @@ AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_ELSM>) template <> std::string_view ELSM::DNAType() { - return "urde::ELSM"sv; + return "ELSM"sv; } template <> std::string_view ELSM::DNAType() { - return "urde::ELSM"sv; + return "ELSM"sv; } template diff --git a/DataSpec/DNACommon/FONT.cpp b/DataSpec/DNACommon/FONT.cpp index 3e3e652b8..2c5a7c2a6 100644 --- a/DataSpec/DNACommon/FONT.cpp +++ b/DataSpec/DNACommon/FONT.cpp @@ -5,7 +5,7 @@ #include namespace DataSpec::DNAFont { -logvisor::Module LogModule("urde::DNAFont"); +logvisor::Module LogModule("DataSpec::DNAFont"); template void FONT::_read(athena::io::IStreamReader& __dna_reader) { diff --git a/DataSpec/DNACommon/FSM2.cpp b/DataSpec/DNACommon/FSM2.cpp index 27b73f457..535c2dc1b 100644 --- a/DataSpec/DNACommon/FSM2.cpp +++ b/DataSpec/DNACommon/FSM2.cpp @@ -9,7 +9,7 @@ #include namespace DataSpec::DNAFSM2 { -logvisor::Module LogDNAFSM2("urde::DNAFSM2"); +logvisor::Module LogDNAFSM2("DataSpec::DNAFSM2"); template template @@ -39,12 +39,12 @@ AT_SPECIALIZE_DNA(FSM2) template <> std::string_view FSM2::DNAType() { - return "urde::FSM2"sv; + return "FSM2"sv; } template <> std::string_view FSM2::DNAType() { - return "urde::FSM2"sv; + return "FSM2"sv; } template struct FSM2; diff --git a/DataSpec/DNACommon/URDEVersionInfo.hpp b/DataSpec/DNACommon/MetaforceVersionInfo.hpp similarity index 91% rename from DataSpec/DNACommon/URDEVersionInfo.hpp rename to DataSpec/DNACommon/MetaforceVersionInfo.hpp index 74813af4b..20505ef13 100644 --- a/DataSpec/DNACommon/URDEVersionInfo.hpp +++ b/DataSpec/DNACommon/MetaforceVersionInfo.hpp @@ -13,7 +13,7 @@ enum class EGame { MetroidPrime3, }; -struct URDEVersionInfo : BigDNA { +struct MetaforceVersionInfo : BigDNA { AT_DECL_DNA_YAML String<-1> version; diff --git a/DataSpec/DNACommon/ParticleCommon.cpp b/DataSpec/DNACommon/ParticleCommon.cpp index 301f6ac56..79c1381ee 100644 --- a/DataSpec/DNACommon/ParticleCommon.cpp +++ b/DataSpec/DNACommon/ParticleCommon.cpp @@ -1,7 +1,7 @@ #include "ParticleCommon.hpp" namespace DataSpec::DNAParticle { -logvisor::Module LogModule("urde::DNAParticle"); +logvisor::Module LogModule("DataSpec::DNAParticle"); template struct PEImpl<_RealElementFactory>; template struct PEImpl<_IntElementFactory>; diff --git a/DataSpec/DNACommon/TXTR.cpp b/DataSpec/DNACommon/TXTR.cpp index 815164cc2..e45654b81 100644 --- a/DataSpec/DNACommon/TXTR.cpp +++ b/DataSpec/DNACommon/TXTR.cpp @@ -846,7 +846,7 @@ bool TXTR::Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { png_infop info = png_create_info_struct(png); png_text textStruct = {}; - textStruct.key = png_charp("urde_nomip"); + textStruct.key = png_charp("metaforce_nomip"); if (numMips == 1) png_set_text(png, info, &textStruct, 1); @@ -1088,13 +1088,13 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat return false; } - /* Disable mipmapping if urde_nomip embedded */ + /* Disable mipmapping if metaforce_nomip embedded */ bool mipmap = true; png_text* textStruct; int numText; png_get_text(pngRead, info, &textStruct, &numText); for (int i = 0; i < numText; ++i) { - if (std::strcmp(textStruct[i].key, "urde_nomip") == 0) { + if (std::strcmp(textStruct[i].key, "metaforce_nomip") == 0) { mipmap = false; } } @@ -1401,13 +1401,13 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP const png_byte colorType = png_get_color_type(pngRead, info); const png_byte bitDepth = png_get_bit_depth(pngRead, info); - /* Disable mipmapping if urde_nomip embedded */ + /* Disable mipmapping if metaforce_nomip embedded */ bool mipmap = true; png_text* textStruct; int numText; png_get_text(pngRead, info, &textStruct, &numText); for (int i = 0; i < numText; ++i) { - if (std::strcmp(textStruct[i].key, "urde_nomip") == 0) { + if (std::strcmp(textStruct[i].key, "metaforce_nomip") == 0) { mipmap = false; } } diff --git a/DataSpec/DNACommon/Tweaks/ITweakGunRes.hpp b/DataSpec/DNACommon/Tweaks/ITweakGunRes.hpp index bdc29dd7f..4583cd02b 100644 --- a/DataSpec/DNACommon/Tweaks/ITweakGunRes.hpp +++ b/DataSpec/DNACommon/Tweaks/ITweakGunRes.hpp @@ -9,8 +9,8 @@ namespace DataSpec { struct ITweakGunRes : ITweak { - using ResId = urde::CAssetId; - using EBeamId = urde::CPlayerState::EBeamId; + using ResId = metaforce::CAssetId; + using EBeamId = metaforce::CPlayerState::EBeamId; ResId x4_gunMotion; ResId x8_grappleArm; @@ -68,7 +68,7 @@ struct ITweakGunRes : ITweak { return x34_weapons[b]; } - void ResolveResources(const urde::IFactory& factory) { + void ResolveResources(const metaforce::IFactory& factory) { x4_gunMotion = factory.GetResourceIdByName(GetGunMotion())->id; x8_grappleArm = factory.GetResourceIdByName(GetGrappleArm())->id; xc_rightHand = factory.GetResourceIdByName(GetRightHand())->id; diff --git a/DataSpec/DNACommon/Tweaks/ITweakPlayerRes.hpp b/DataSpec/DNACommon/Tweaks/ITweakPlayerRes.hpp index 213528a23..328f645ee 100644 --- a/DataSpec/DNACommon/Tweaks/ITweakPlayerRes.hpp +++ b/DataSpec/DNACommon/Tweaks/ITweakPlayerRes.hpp @@ -9,8 +9,8 @@ namespace DataSpec { struct ITweakPlayerRes : ITweak { - using ResId = urde::CAssetId; - using EBeamId = urde::CPlayerState::EBeamId; + using ResId = metaforce::CAssetId; + using EBeamId = metaforce::CPlayerState::EBeamId; ResId x4_saveStationIcon; ResId x8_missileStationIcon; @@ -85,7 +85,7 @@ struct ITweakPlayerRes : ITweak { } } - void ResolveResources(const urde::IFactory& factory) { + void ResolveResources(const metaforce::IFactory& factory) { x4_saveStationIcon = factory.GetResourceIdByName(_GetSaveStationIcon())->id; x8_missileStationIcon = factory.GetResourceIdByName(_GetMissileStationIcon())->id; xc_elevatorIcon = factory.GetResourceIdByName(_GetElevatorIcon())->id; diff --git a/DataSpec/DNAMP1/AFSM.cpp b/DataSpec/DNAMP1/AFSM.cpp index a8c2033ef..72dd25570 100644 --- a/DataSpec/DNAMP1/AFSM.cpp +++ b/DataSpec/DNAMP1/AFSM.cpp @@ -43,7 +43,7 @@ void AFSM::State::Transition::Enumerate(typename BinarySize: trig.binarySize(s); } -std::string_view AFSM::State::Transition::DNAType() { return "urde::DNAMP1::AFSM::Transition"sv; } +std::string_view AFSM::State::Transition::DNAType() { return "DNAMP1::AFSM::Transition"sv; } template <> void AFSM::State::Transition::Trigger::Enumerate(athena::io::IStreamReader& __dna_reader) { @@ -100,7 +100,7 @@ void AFSM::State::Transition::Trigger::Enumerate(size_t& __i } std::string_view AFSM::State::Transition::Trigger::DNAType() { - return "urde::DNAMP1::AFSM::State::Transition::Trigger"sv; + return "DNAMP1::AFSM::State::Transition::Trigger"sv; } } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP1/ANCS.cpp b/DataSpec/DNAMP1/ANCS.cpp index 642da411f..b21a68a44 100644 --- a/DataSpec/DNAMP1/ANCS.cpp +++ b/DataSpec/DNAMP1/ANCS.cpp @@ -139,7 +139,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::Enumer } std::string_view ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::DNAType() { - return "urde::DNAMP1::ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo"sv; + return "DNAMP1::ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo"sv; } template <> @@ -315,7 +315,7 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::Enumerate @@ -606,7 +606,7 @@ void ANCS::CharacterSet::CharacterInfo::Enumerate(athena::io: } std::string_view ANCS::CharacterSet::CharacterInfo::DNAType() { - return "urde::DNAMP1::ANCS::CharacterSet::CharacterInfo"sv; + return "DNAMP1::ANCS::CharacterSet::CharacterInfo"sv; } template <> @@ -688,7 +688,7 @@ void ANCS::AnimationSet::MetaAnimFactory::Enumerate(athena::i } std::string_view ANCS::AnimationSet::MetaAnimFactory::DNAType() { - return "urde::DNAMP1::ANCS::AnimationSet::MetaAnimFactory"sv; + return "DNAMP1::ANCS::AnimationSet::MetaAnimFactory"sv; } template <> @@ -761,7 +761,7 @@ void ANCS::AnimationSet::MetaTransFactory::Enumerate(athena:: } std::string_view ANCS::AnimationSet::MetaTransFactory::DNAType() { - return "urde::DNAMP1::ANCS::AnimationSet::MetaTransFactory"sv; + return "DNAMP1::ANCS::AnimationSet::MetaTransFactory"sv; } template <> @@ -955,7 +955,7 @@ void ANCS::AnimationSet::MetaAnimPrimitive::gatherPrimitives( out[animIdx] = {animName, animId, ANIM::GetEVNTId(rs), false}; } -std::string_view ANCS::AnimationSet::DNAType() { return "urde::DNAMP1::ANCS::AnimationSet"sv; } +std::string_view ANCS::AnimationSet::DNAType() { return "DNAMP1::ANCS::AnimationSet"sv; } bool ANCS::Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath, PAKRouter& pakRouter, const PAK::Entry& entry, bool force, hecl::blender::Token& btok, @@ -994,7 +994,7 @@ bool ANCS::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("can't open '{}' for reading")), yamlPath.getRelativePath()); if (!athena::io::ValidateFromYAMLStream(reader)) { - Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("'{}' is not urde::DNAMP1::ANCS type")), yamlPath.getRelativePath()); + Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("'{}' is not DNAMP1::ANCS type")), yamlPath.getRelativePath()); } athena::io::YAMLDocReader yamlReader; diff --git a/DataSpec/DNAMP1/DNAMP1.cpp b/DataSpec/DNAMP1/DNAMP1.cpp index 30704552c..b0dd457e2 100644 --- a/DataSpec/DNAMP1/DNAMP1.cpp +++ b/DataSpec/DNAMP1/DNAMP1.cpp @@ -30,7 +30,7 @@ #include "PATH.hpp" #include "DataSpec/DNACommon/Tweaks/TweakWriter.hpp" -#include "DataSpec/DNACommon/URDEVersionInfo.hpp" +#include "DataSpec/DNACommon/MetaforceVersionInfo.hpp" #include "Tweaks/CTweakPlayerRes.hpp" #include "Tweaks/CTweakGunRes.hpp" #include "Tweaks/CTweakPlayer.hpp" @@ -49,7 +49,7 @@ #include "SnowForces.hpp" namespace DataSpec::DNAMP1 { -logvisor::Module Log("urde::DNAMP1"); +logvisor::Module Log("DataSpec::DNAMP1"); static bool GetNoShare(std::string_view name) { std::string lowerName(name); diff --git a/DataSpec/DNAMP1/EVNT.cpp b/DataSpec/DNAMP1/EVNT.cpp index 678eb1540..95d5c401c 100644 --- a/DataSpec/DNAMP1/EVNT.cpp +++ b/DataSpec/DNAMP1/EVNT.cpp @@ -23,6 +23,6 @@ void EVNT::Enumerate(typename Op::StreamT& s) { AT_SPECIALIZE_DNA_YAML(EVNT) -std::string_view EVNT::DNAType() { return "urde::DNAMP1::EVNT"sv; } +std::string_view EVNT::DNAType() { return "DNAMP1::EVNT"sv; } } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP1/MLVL.cpp b/DataSpec/DNAMP1/MLVL.cpp index f22e1af3a..8ed471a72 100644 --- a/DataSpec/DNAMP1/MLVL.cpp +++ b/DataSpec/DNAMP1/MLVL.cpp @@ -269,7 +269,7 @@ bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat std::vector depPaths; std::vector lazyPaths; for (std::unique_ptr& obj : layer.objects) { - if (obj->type == int(urde::EScriptObjectType::MemoryRelay)) { + if (obj->type == int(metaforce::EScriptObjectType::MemoryRelay)) { MemoryRelay& memRelay = static_cast(*obj); for (IScriptObject::Connection& conn : memRelay.connections) { MemRelayLink linkOut; @@ -319,7 +319,7 @@ bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat areaOut.depLayers.push_back(areaOut.deps.size()); for (const std::pair& path : layer) { if (path.first) { - urde::SObjectTag tag = g_curSpec->buildTagFromPath(path.first); + metaforce::SObjectTag tag = g_curSpec->buildTagFromPath(path.first); if (tag.id.IsValid()) { if (path.second) areaOut.lazyDeps.emplace_back(tag.id.Value(), tag.type); @@ -348,7 +348,7 @@ bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat layerResources.addSharedPath(path, false); for (const std::pair& path : layerResources.sharedPaths) { - urde::SObjectTag tag = g_curSpec->buildTagFromPath(path.first); + metaforce::SObjectTag tag = g_curSpec->buildTagFromPath(path.first); if (tag.id.IsValid()) { if (path.second) areaOut.lazyDeps.emplace_back(tag.id.Value(), tag.type); @@ -359,7 +359,7 @@ bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat } hecl::ProjectPath pathPath = GetPathBeginsWith(areaDEnum, area.path, _SYS_STR("!path_")); - urde::SObjectTag pathTag = g_curSpec->buildTagFromPath(pathPath); + metaforce::SObjectTag pathTag = g_curSpec->buildTagFromPath(pathPath); if (pathTag.id.IsValid()) { areaOut.deps.emplace_back(pathTag.id.Value(), pathTag.type); areaOut.lazyDeps.emplace_back(0, FOURCC('NONE')); @@ -392,7 +392,7 @@ bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat } bool MLVL::CookMAPW(const hecl::ProjectPath& outPath, const World& wld) { - std::vector mapaTags; + std::vector mapaTags; mapaTags.reserve(wld.areas.size()); for (const World::Area& area : wld.areas) { @@ -411,7 +411,7 @@ bool MLVL::CookMAPW(const hecl::ProjectPath& outPath, const World& wld) { fo.writeUint32Big(0xDEADF00D); fo.writeUint32Big(1); fo.writeUint32Big(mapaTags.size()); - for (const urde::SObjectTag& mapa : mapaTags) + for (const metaforce::SObjectTag& mapa : mapaTags) fo.writeUint32Big(u32(mapa.id.Value())); int64_t rem = fo.position() % 32; if (rem) @@ -479,7 +479,7 @@ bool MLVL::CookSAVW(const hecl::ProjectPath& outPath, const World& wld) { { std::vector scans; for (std::unique_ptr& obj : layer.objects) { - if (obj->type == int(urde::EScriptObjectType::MemoryRelay)) { + if (obj->type == int(metaforce::EScriptObjectType::MemoryRelay)) { MemoryRelay& memRelay = static_cast(*obj); auto iter = std::find(memRelays.begin(), memRelays.end(), memRelay.id); if (iter == memRelays.end()) { @@ -487,7 +487,7 @@ bool MLVL::CookSAVW(const hecl::ProjectPath& outPath, const World& wld) { savw.relays.push_back(memRelay.id); memRelays.push_back(memRelay.id); } - } else if (obj->type == int(urde::EScriptObjectType::SpecialFunction)) { + } else if (obj->type == int(metaforce::EScriptObjectType::SpecialFunction)) { SpecialFunction& specialFunc = static_cast(*obj); if (specialFunc.function == ESpecialFunctionType::CinematicSkip) savw.skippableCutscenes.push_back(specialFunc.id); @@ -497,7 +497,7 @@ bool MLVL::CookSAVW(const hecl::ProjectPath& outPath, const World& wld) { layer.areaId = specialFunc.layerSwitch.area; layer.layer = specialFunc.layerSwitch.layerIdx; } - } else if (obj->type == int(urde::EScriptObjectType::Door)) { + } else if (obj->type == int(metaforce::EScriptObjectType::Door)) { DoorArea& doorArea = static_cast(*obj); savw.doors.push_back(doorArea.id); } diff --git a/DataSpec/DNAMP1/SCAN.cpp b/DataSpec/DNAMP1/SCAN.cpp index c09371284..5fa82ce7c 100644 --- a/DataSpec/DNAMP1/SCAN.cpp +++ b/DataSpec/DNAMP1/SCAN.cpp @@ -66,7 +66,7 @@ void SCAN::Texture::Enumerate(typename WriteYaml::StreamT& w) w.writeFloat("fadeDuration", fadeDuration); } -std::string_view SCAN::Texture::DNAType() { return "urde::DNAMP1::SCAN::Texture"sv; } +std::string_view SCAN::Texture::DNAType() { return "DNAMP1::SCAN::Texture"sv; } template <> void SCAN::Texture::Enumerate(typename BinarySize::StreamT& s) { diff --git a/DataSpec/DNAMP1/SCLY.cpp b/DataSpec/DNAMP1/SCLY.cpp index 6e24003bf..d356a2d17 100644 --- a/DataSpec/DNAMP1/SCLY.cpp +++ b/DataSpec/DNAMP1/SCLY.cpp @@ -91,7 +91,7 @@ void SCLY::Enumerate(athena::io::YAMLDocWriter& docout) { docout.enumerate("layers", layers); } -std::string_view SCLY::DNAType() { return "urde::DNAMP1::SCLY"sv; } +std::string_view SCLY::DNAType() { return "DNAMP1::SCLY"sv; } template <> void SCLY::ScriptLayer::Enumerate(athena::io::IStreamReader& rs) { @@ -191,6 +191,6 @@ void SCLY::ScriptLayer::Enumerate(athena::io::YAMLDocWriter& } } -std::string_view SCLY::ScriptLayer::DNAType() { return "urde::DNAMP1::SCLY::ScriptLayer"sv; } +std::string_view SCLY::ScriptLayer::DNAType() { return "DNAMP1::SCLY::ScriptLayer"sv; } } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP1/STRG.cpp b/DataSpec/DNAMP1/STRG.cpp index 6e893b60c..7ba83bbad 100644 --- a/DataSpec/DNAMP1/STRG.cpp +++ b/DataSpec/DNAMP1/STRG.cpp @@ -458,5 +458,5 @@ void STRG::Enumerate(typename WriteYaml::StreamT& writer) { } } -std::string_view STRG::DNAType() { return "urde::DNAMP1::STRG"sv; } +std::string_view STRG::DNAType() { return "DNAMP1::STRG"sv; } } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP1/ScriptObjects/Oculus.cpp b/DataSpec/DNAMP1/ScriptObjects/Oculus.cpp index 662312cae..158db716f 100644 --- a/DataSpec/DNAMP1/ScriptObjects/Oculus.cpp +++ b/DataSpec/DNAMP1/ScriptObjects/Oculus.cpp @@ -26,7 +26,7 @@ void Oculus::Enumerate(typename Op::StreamT& s) { unknown8 = 0.f; } -std::string_view Oculus::DNAType() { return "urde::DNAMP1::Oculus"sv; } +std::string_view Oculus::DNAType() { return "DNAMP1::Oculus"sv; } AT_SPECIALIZE_DNA_YAML(Oculus) diff --git a/DataSpec/DNAMP1/ScriptObjects/Ridley.cpp b/DataSpec/DNAMP1/ScriptObjects/Ridley.cpp index 919572ff2..1fff77f17 100644 --- a/DataSpec/DNAMP1/ScriptObjects/Ridley.cpp +++ b/DataSpec/DNAMP1/ScriptObjects/Ridley.cpp @@ -61,7 +61,7 @@ void Ridley::Enumerate(typename Op::StreamT& s) { Do(athena::io::PropId{"damageInfo9"}, damageInfo9, s); } -std::string_view Ridley::DNAType() { return "urde::DNAMP1::Ridley"sv; } +std::string_view Ridley::DNAType() { return "DNAMP1::Ridley"sv; } AT_SPECIALIZE_DNA_YAML(Ridley) diff --git a/DataSpec/DNAMP1/ScriptObjects/WorldTeleporter.cpp b/DataSpec/DNAMP1/ScriptObjects/WorldTeleporter.cpp index b6bb0269a..54fcd60b0 100644 --- a/DataSpec/DNAMP1/ScriptObjects/WorldTeleporter.cpp +++ b/DataSpec/DNAMP1/ScriptObjects/WorldTeleporter.cpp @@ -41,7 +41,7 @@ void WorldTeleporter::Enumerate(typename Op::StreamT& s) { } } -std::string_view WorldTeleporter::DNAType() { return "urde::DNAMP1::WorldTeleporter"sv; } +std::string_view WorldTeleporter::DNAType() { return "DNAMP1::WorldTeleporter"sv; } AT_SPECIALIZE_DNA_YAML(WorldTeleporter) diff --git a/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp b/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp index 066f20f56..de19d757b 100644 --- a/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp +++ b/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp @@ -3,56 +3,95 @@ #include #include -namespace DataSpec::DNAMP1 { -hecl::CVar* tw_fov = nullptr; -hecl::CVar* tw_hardmodeDMult = nullptr; -hecl::CVar* tw_hardmodeWMult = nullptr; -hecl::CVar* tw_splashScreensDisabled = nullptr; -namespace { -constexpr std::string_view skFov = "tweak.game.FieldOfView"sv; -constexpr std::string_view skHardModeDamageMultName = "tweak.game.HardModeDamageMult"sv; -constexpr std::string_view skHardModeWeaponMultName = "tweak.game.HardModeWeaponMult"sv; -constexpr std::string_view skSplashScreensDisabled = "tweak.game.SplashScreensDisabled"sv; -} // anonymous namespace +#define DEFINE_CVAR_GLOBAL(name) \ + constexpr std::string_view sk##name = std::string_view("tweak.game." #name); \ + hecl::CVar* tw_##name = nullptr; -void CTweakGame::_tweakGameListener(hecl::CVar* cv) { - if (cv == tw_fov) { - x24_fov = cv->toReal(); - } else if (cv == tw_hardmodeDMult) { - x60_hardmodeDamageMult = cv->toReal(); - } else if (cv == tw_hardmodeWMult) { - x64_hardmodeWeaponMult = cv->toReal(); - } else if (cv == tw_splashScreensDisabled) { - x2b_splashScreensDisabled = cv->toBoolean(); +#define CREATE_CVAR(name, help, value, flags) \ + tw_##name = mgr->findOrMakeCVar(sk##name, help, value, flags); \ + if (tw_##name->wasDeserialized()) { \ + tw_##name->toValue(value); \ + } \ + tw_##name->addListener([this](hecl::CVar* cv) { _tweakListener(cv); }); + +#define CREATE_CVAR_BITFIELD(name, help, value, flags) \ + { \ + bool tmp = value; \ + CREATE_CVAR(name, help, tmp, flags) \ } + +#define UPDATE_CVAR(name, cv, value) \ + if ((cv) == tw_##name) { \ + (cv)->toValue(value); \ + return; \ + } + +#define UPDATE_CVAR_BITFIELD(name, cv, value) \ + { \ + bool tmp = value; \ + UPDATE_CVAR(name, cv, tmp) \ + (value) = tmp; \ + } + +namespace DataSpec::DNAMP1 { + +DEFINE_CVAR_GLOBAL(WorldPrefix); +DEFINE_CVAR_GLOBAL(FieldOfView); +DEFINE_CVAR_GLOBAL(SplashScreensDisabled); +DEFINE_CVAR_GLOBAL(PressStartDelay); +DEFINE_CVAR_GLOBAL(WavecapIntensityNormal); +DEFINE_CVAR_GLOBAL(WavecapIntensityPoison); +DEFINE_CVAR_GLOBAL(WavecapIntensityLava); +DEFINE_CVAR_GLOBAL(RippleIntensityNormal); +DEFINE_CVAR_GLOBAL(RippleIntensityPoison); +DEFINE_CVAR_GLOBAL(RippleIntensityLava); +DEFINE_CVAR_GLOBAL(FluidEnvBumpScale); +DEFINE_CVAR_GLOBAL(WaterFogDistanceBase); +DEFINE_CVAR_GLOBAL(WaterFogDistanceRange); +DEFINE_CVAR_GLOBAL(GravityWaterFogDistanceBase); +DEFINE_CVAR_GLOBAL(GravityWaterFogDistanceRange); +DEFINE_CVAR_GLOBAL(HardModeDamageMult); +DEFINE_CVAR_GLOBAL(HardModeWeaponMult); + +void CTweakGame::_tweakListener(hecl::CVar* cv) { + UPDATE_CVAR(WorldPrefix, cv, x4_worldPrefix); + UPDATE_CVAR(FieldOfView, cv, x24_fov); + UPDATE_CVAR(SplashScreensDisabled, cv, x2b_splashScreensDisabled); + UPDATE_CVAR(PressStartDelay, cv, x30_pressStartDelay); + UPDATE_CVAR(WavecapIntensityNormal, cv, x34_wavecapIntensityNormal); + UPDATE_CVAR(WavecapIntensityPoison, cv, x38_wavecapIntensityPoison); + UPDATE_CVAR(WavecapIntensityLava, cv, x3c_wavecapIntensityLava); + UPDATE_CVAR(RippleIntensityNormal, cv, x40_rippleIntensityNormal); + UPDATE_CVAR(RippleIntensityPoison, cv, x44_rippleIntensityPoison); + UPDATE_CVAR(RippleIntensityLava, cv, x48_rippleIntensityLava); + UPDATE_CVAR(FluidEnvBumpScale, cv, x4c_fluidEnvBumpScale); + UPDATE_CVAR(WaterFogDistanceBase, cv, x50_waterFogDistanceBase); + UPDATE_CVAR(WaterFogDistanceRange, cv, x54_waterFogDistanceRange); + UPDATE_CVAR(GravityWaterFogDistanceBase, cv, x58_gravityWaterFogDistanceBase); + UPDATE_CVAR(GravityWaterFogDistanceRange, cv, x5c_gravityWaterFogDistanceRange); + UPDATE_CVAR(HardModeDamageMult, cv, x60_hardmodeDamageMult); + UPDATE_CVAR(HardModeWeaponMult, cv, x64_hardmodeWeaponMult); } void CTweakGame::initCVars(hecl::CVarManager* mgr) { - auto assignRealValue = [this, mgr](std::string_view name, std::string_view desc, float& v, hecl::CVar::EFlags flags) { - hecl::CVar* cv = mgr->findOrMakeCVar(name, desc, v, flags); - // Check if the CVar was deserialized, this avoid an unnecessary conversion - if (cv->wasDeserialized()) - v = static_cast(cv->toReal()); - cv->addListener([this](hecl::CVar* cv) { _tweakGameListener(cv); }); - return cv; - }; - auto assignBoolValue = [this, mgr](std::string_view name, std::string_view desc, bool& v, hecl::CVar::EFlags flags) { - hecl::CVar* cv = mgr->findOrMakeCVar(name, desc, v, flags); - // Check if the CVar was deserialized, this avoid an unnecessary conversion - if (cv->wasDeserialized()) - v = cv->toBoolean(); - cv->addListener([this](hecl::CVar* cv) { _tweakGameListener(cv); }); - return cv; - }; - - tw_fov = assignRealValue(skFov, "", x24_fov, hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive); - tw_hardmodeDMult = - assignRealValue(skHardModeDamageMultName, "", x60_hardmodeDamageMult, - hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Cheat); - tw_hardmodeWMult = - assignRealValue(skHardModeWeaponMultName, "", x64_hardmodeWeaponMult, - hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Cheat); - tw_splashScreensDisabled = assignBoolValue(skSplashScreensDisabled, "", x2b_splashScreensDisabled, - hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive); + constexpr hecl::CVar::EFlags skDefaultFlags = hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive; + CREATE_CVAR(WorldPrefix, "", x4_worldPrefix, skDefaultFlags); + CREATE_CVAR(FieldOfView, "", x24_fov, skDefaultFlags); + CREATE_CVAR(SplashScreensDisabled, "", x2b_splashScreensDisabled, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive); + CREATE_CVAR(PressStartDelay, "", x30_pressStartDelay, skDefaultFlags); + CREATE_CVAR(WavecapIntensityNormal, "", x34_wavecapIntensityNormal, skDefaultFlags); + CREATE_CVAR(WavecapIntensityPoison, "", x38_wavecapIntensityPoison, skDefaultFlags); + CREATE_CVAR(WavecapIntensityLava, "", x3c_wavecapIntensityLava, skDefaultFlags); + CREATE_CVAR(RippleIntensityNormal, "", x40_rippleIntensityNormal, skDefaultFlags); + CREATE_CVAR(RippleIntensityPoison, "", x44_rippleIntensityPoison, skDefaultFlags); + CREATE_CVAR(RippleIntensityLava, "", x48_rippleIntensityLava, skDefaultFlags); + CREATE_CVAR(FluidEnvBumpScale, "", x4c_fluidEnvBumpScale, skDefaultFlags); + CREATE_CVAR(WaterFogDistanceBase, "", x50_waterFogDistanceBase, skDefaultFlags); + CREATE_CVAR(WaterFogDistanceRange, "", x54_waterFogDistanceRange, skDefaultFlags); + CREATE_CVAR(GravityWaterFogDistanceBase, "", x58_gravityWaterFogDistanceBase, skDefaultFlags); + CREATE_CVAR(GravityWaterFogDistanceRange, "", x5c_gravityWaterFogDistanceRange, skDefaultFlags); + CREATE_CVAR(HardModeDamageMult, "", x60_hardmodeDamageMult, skDefaultFlags); + CREATE_CVAR(HardModeWeaponMult, "", x64_hardmodeWeaponMult, skDefaultFlags); } } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP1/Tweaks/CTweakGame.hpp b/DataSpec/DNAMP1/Tweaks/CTweakGame.hpp index 5fe8c5203..b0868b92f 100644 --- a/DataSpec/DNAMP1/Tweaks/CTweakGame.hpp +++ b/DataSpec/DNAMP1/Tweaks/CTweakGame.hpp @@ -4,10 +4,33 @@ namespace hecl { class CVar; -} +} // namespace hecl namespace DataSpec::DNAMP1 { +#define DEFINE_CVAR_GLOBAL(name) \ + extern hecl::CVar* tw_##name; + +DEFINE_CVAR_GLOBAL(WorldPrefix); +DEFINE_CVAR_GLOBAL(FieldOfView); +DEFINE_CVAR_GLOBAL(SplashScreensDisabled); +DEFINE_CVAR_GLOBAL(PressStartDelay); +DEFINE_CVAR_GLOBAL(WavecapIntensityNormal); +DEFINE_CVAR_GLOBAL(WavecapIntensityPoison); +DEFINE_CVAR_GLOBAL(WavecapIntensityLava); +DEFINE_CVAR_GLOBAL(RippleIntensityNormal); +DEFINE_CVAR_GLOBAL(RippleIntensityPoison); +DEFINE_CVAR_GLOBAL(RippleIntensityLava); +DEFINE_CVAR_GLOBAL(FluidEnvBumpScale); +DEFINE_CVAR_GLOBAL(WaterFogDistanceBase); +DEFINE_CVAR_GLOBAL(WaterFogDistanceRange); +DEFINE_CVAR_GLOBAL(GravityWaterFogDistanceBase); +DEFINE_CVAR_GLOBAL(GravityWaterFogDistanceRange); +DEFINE_CVAR_GLOBAL(HardModeDamageMult); +DEFINE_CVAR_GLOBAL(HardModeWeaponMult); + +#undef DEFINE_CVAR_GLOBAL + struct CTweakGame final : ITweakGame { AT_DECL_DNA_YAML String<-1> x4_worldPrefix; @@ -23,7 +46,7 @@ struct CTweakGame final : ITweakGame { Value x38_wavecapIntensityPoison; Value x3c_wavecapIntensityLava; Value x40_rippleIntensityNormal; - Value x44_rippleIntentityPoison; + Value x44_rippleIntensityPoison; Value x48_rippleIntensityLava; Value x4c_fluidEnvBumpScale; Value x50_waterFogDistanceBase; @@ -42,7 +65,7 @@ struct CTweakGame final : ITweakGame { float GetWavecapIntensityPoison() const override { return x38_wavecapIntensityPoison; } float GetWavecapIntensityLava() const override { return x3c_wavecapIntensityLava; } float GetRippleIntensityNormal() const override { return x40_rippleIntensityNormal; } - float GetRippleIntensityPoison() const override { return x44_rippleIntentityPoison; } + float GetRippleIntensityPoison() const override { return x44_rippleIntensityPoison; } float GetRippleIntensityLava() const override { return x48_rippleIntensityLava; } float GetFluidEnvBumpScale() const override { return x4c_fluidEnvBumpScale; } float GetWaterFogDistanceBase() const override { return x50_waterFogDistanceBase; } @@ -60,7 +83,8 @@ struct CTweakGame final : ITweakGame { } void initCVars(hecl::CVarManager* mgr) override; + private: - void _tweakGameListener(hecl::CVar* cv); + void _tweakListener(hecl::CVar* cv); }; } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP1/Tweaks/CTweakPlayer.cpp b/DataSpec/DNAMP1/Tweaks/CTweakPlayer.cpp index d201703f1..e3fbea5c7 100644 --- a/DataSpec/DNAMP1/Tweaks/CTweakPlayer.cpp +++ b/DataSpec/DNAMP1/Tweaks/CTweakPlayer.cpp @@ -1,8 +1,261 @@ #include "CTweakPlayer.hpp" #include "zeus/Math.hpp" -namespace DataSpec::DNAMP1 { +#include +#include +#define DEFINE_CVAR_GLOBAL(name) \ + constexpr std::string_view sk##name = std::string_view("tweak.player." #name); \ + hecl::CVar* tw_##name = nullptr; + +#define CREATE_CVAR(name, help, value, flags) \ + tw_##name = mgr->findOrMakeCVar(sk##name, help, value, flags); \ + if (tw_##name->wasDeserialized()) { \ + tw_##name->toValue(value); \ + } \ + tw_##name->addListener([this](hecl::CVar* cv) { _tweakListener(cv); }); + +#define CREATE_CVAR_BITFIELD(name, help, value, flags) \ + { \ + bool tmp = value; \ + CREATE_CVAR(name, help, tmp, flags) \ + } + +#define UPDATE_CVAR(name, cv, value) \ + if ((cv) == tw_##name) { \ + (cv)->toValue(value); \ + return; \ + } + +#define UPDATE_CVAR_BITFIELD(name, cv, value) \ + { \ + bool tmp = value; \ + UPDATE_CVAR(name, cv, tmp) \ + (value) = tmp; \ + } + +namespace DataSpec::DNAMP1 { +namespace { +static constexpr hecl::CVar::EFlags skDefaultFlags = + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Cheat | hecl::CVar::EFlags::Archive; +DEFINE_CVAR_GLOBAL(MaxTranslationAccelerationNormal); +DEFINE_CVAR_GLOBAL(MaxTranslationAccelerationAir); +DEFINE_CVAR_GLOBAL(MaxTranslationAccelerationIce); +DEFINE_CVAR_GLOBAL(MaxTranslationAccelerationOrganic); +DEFINE_CVAR_GLOBAL(MaxTranslationAccelerationWater); +DEFINE_CVAR_GLOBAL(MaxTranslationAccelerationLava); +DEFINE_CVAR_GLOBAL(MaxTranslationAccelerationPhazon); +DEFINE_CVAR_GLOBAL(MaxTranslationAccelerationShrubbery); +DEFINE_CVAR_GLOBAL(MaxRotationAccelerationNormal); +DEFINE_CVAR_GLOBAL(MaxRotationAccelerationAir); +DEFINE_CVAR_GLOBAL(MaxRotationAccelerationIce); +DEFINE_CVAR_GLOBAL(MaxRotationAccelerationOrganic); +DEFINE_CVAR_GLOBAL(MaxRotationAccelerationWater); +DEFINE_CVAR_GLOBAL(MaxRotationAccelerationLava); +DEFINE_CVAR_GLOBAL(MaxRotationAccelerationPhazon); +DEFINE_CVAR_GLOBAL(MaxRotationAccelerationShrubbery); +DEFINE_CVAR_GLOBAL(TranslationFrictionNormal); +DEFINE_CVAR_GLOBAL(TranslationFrictionAir); +DEFINE_CVAR_GLOBAL(TranslationFrictionIce); +DEFINE_CVAR_GLOBAL(TranslationFrictionOrganic); +DEFINE_CVAR_GLOBAL(TranslationFrictionWater); +DEFINE_CVAR_GLOBAL(TranslationFrictionLava); +DEFINE_CVAR_GLOBAL(TranslationFrictionPhazon); +DEFINE_CVAR_GLOBAL(TranslationFrictionShrubbery); +DEFINE_CVAR_GLOBAL(RotationFrictionNormal); +DEFINE_CVAR_GLOBAL(RotationFrictionAir); +DEFINE_CVAR_GLOBAL(RotationFrictionIce); +DEFINE_CVAR_GLOBAL(RotationFrictionOrganic); +DEFINE_CVAR_GLOBAL(RotationFrictionWater); +DEFINE_CVAR_GLOBAL(RotationFrictionLava); +DEFINE_CVAR_GLOBAL(RotationFrictionPhazon); +DEFINE_CVAR_GLOBAL(RotationFrictionShrubbery); +DEFINE_CVAR_GLOBAL(RotationMaxSpeedNormal); +DEFINE_CVAR_GLOBAL(RotationMaxSpeedAir); +DEFINE_CVAR_GLOBAL(RotationMaxSpeedIce); +DEFINE_CVAR_GLOBAL(RotationMaxSpeedOrganic); +DEFINE_CVAR_GLOBAL(RotationMaxSpeedWater); +DEFINE_CVAR_GLOBAL(RotationMaxSpeedLava); +DEFINE_CVAR_GLOBAL(RotationMaxSpeedPhazon); +DEFINE_CVAR_GLOBAL(RotationMaxSpeedShrubbery); +DEFINE_CVAR_GLOBAL(TranslationMaxSpeedNormal); +DEFINE_CVAR_GLOBAL(TranslationMaxSpeedAir); +DEFINE_CVAR_GLOBAL(TranslationMaxSpeedIce); +DEFINE_CVAR_GLOBAL(TranslationMaxSpeedOrganic); +DEFINE_CVAR_GLOBAL(TranslationMaxSpeedWater); +DEFINE_CVAR_GLOBAL(TranslationMaxSpeedLava); +DEFINE_CVAR_GLOBAL(TranslationMaxSpeedPhazon); +DEFINE_CVAR_GLOBAL(TranslationMaxSpeedShrubbery); +DEFINE_CVAR_GLOBAL(NormalGravityAcceleration); +DEFINE_CVAR_GLOBAL(FluidGravityAcceleration); +DEFINE_CVAR_GLOBAL(VerticalJumpAcceleration); +DEFINE_CVAR_GLOBAL(HorizontalJumpAcceleration); +DEFINE_CVAR_GLOBAL(VerticalDoubleJumpAcceleration); +DEFINE_CVAR_GLOBAL(HorizontalDoubleJumpAcceleration); +DEFINE_CVAR_GLOBAL(WaterJumpFactor); +DEFINE_CVAR_GLOBAL(WaterBallJumpFactor); +DEFINE_CVAR_GLOBAL(LavaJumpFactor); +DEFINE_CVAR_GLOBAL(LavaBallJumpFactor); +DEFINE_CVAR_GLOBAL(PhazonJumpFactor); +DEFINE_CVAR_GLOBAL(PhazonBallJumpFactor); +DEFINE_CVAR_GLOBAL(AllowedJumpTime); +DEFINE_CVAR_GLOBAL(AllowedDoubleJumpTime); +DEFINE_CVAR_GLOBAL(MinDoubleJumpWindow); +DEFINE_CVAR_GLOBAL(MaxDoubleJumpWindow) +// DEFINE_CVAR_GLOBAL(); // x104_ +DEFINE_CVAR_GLOBAL(MinJumpTime); +DEFINE_CVAR_GLOBAL(MinDoubleJumpTime); +DEFINE_CVAR_GLOBAL(AllowedLedgeTime); +DEFINE_CVAR_GLOBAL(DoubleJumpImpulse); +DEFINE_CVAR_GLOBAL(BackwardsForceMultiplier); +DEFINE_CVAR_GLOBAL(BombJumpRadius); +DEFINE_CVAR_GLOBAL(BombJumpHeight); +DEFINE_CVAR_GLOBAL(EyeOffset); +DEFINE_CVAR_GLOBAL(TurnSpeedMultiplier); +DEFINE_CVAR_GLOBAL(FreeLookTurnSpeedMultiplier); +DEFINE_CVAR_GLOBAL(HorizontalFreeLookAngleVelocity); +DEFINE_CVAR_GLOBAL(VerticalFreeLookAngleVelocity); +DEFINE_CVAR_GLOBAL(FreeLookSpeed); +DEFINE_CVAR_GLOBAL(FreeLookSnapSpeed); +// DEFINE_CVAR_GLOBAL(); // x140_ +DEFINE_CVAR_GLOBAL(FreeLookCenteredThresholdAngle); +DEFINE_CVAR_GLOBAL(FreeLookCenteredTime); +DEFINE_CVAR_GLOBAL(FreeLookDampenFactor); +DEFINE_CVAR_GLOBAL(LeftDivisor); +DEFINE_CVAR_GLOBAL(RightDivisor); +DEFINE_CVAR_GLOBAL(OrbitMinDistanceClose); +DEFINE_CVAR_GLOBAL(OrbitMinDistanceFar); +DEFINE_CVAR_GLOBAL(OrbitMinDistanceDefault); +DEFINE_CVAR_GLOBAL(OrbitNormalDistanceClose); +DEFINE_CVAR_GLOBAL(OrbitNormalDistanceFar); +DEFINE_CVAR_GLOBAL(OrbitNormalDistanceDefault); +DEFINE_CVAR_GLOBAL(OrbitMaxDistanceClose); +DEFINE_CVAR_GLOBAL(OrbitMaxDistanceFar); +DEFINE_CVAR_GLOBAL(OrbitMaxDistanceDefault); +// DEFINE_CVAR_GLOBAL(); // x17c_ +DEFINE_CVAR_GLOBAL(OrbitmodeTimer); +DEFINE_CVAR_GLOBAL(OrbitCameraSpeed); +DEFINE_CVAR_GLOBAL(OrbitUpperAngle); +DEFINE_CVAR_GLOBAL(OrbitLowerAngle); +DEFINE_CVAR_GLOBAL(OrbitHorizontalAngle); +// DEFINE_CVAR_GLOBAL(); // x194_ +// DEFINE_CVAR_GLOBAL(); // x198_ +DEFINE_CVAR_GLOBAL(OrbitMaxTargetDistance); +DEFINE_CVAR_GLOBAL(OrbitMaxLockDistance); +DEFINE_CVAR_GLOBAL(OrbitDistanceThreshold); +DEFINE_CVAR_GLOBAL(OrbitScreenTargetingBoxHalfExtentX); +DEFINE_CVAR_GLOBAL(OrbitScreenScanBoxHalfExtentX); +DEFINE_CVAR_GLOBAL(OrbitScreenTargetingBoxHalfExtentY); +DEFINE_CVAR_GLOBAL(OrbitScreenScanBoxHalfExtentY); +DEFINE_CVAR_GLOBAL(OrbitScreenTargetingBoxCenterX); +DEFINE_CVAR_GLOBAL(OrbitScreenScanBoxCenterX); +DEFINE_CVAR_GLOBAL(OrbitScreenTargetingBoxCenterY); +DEFINE_CVAR_GLOBAL(OrbitScreenScanBoxCenterY); +DEFINE_CVAR_GLOBAL(OrbitZoneTargetingIdealX); +DEFINE_CVAR_GLOBAL(OrbitZoneScanIdealX); +DEFINE_CVAR_GLOBAL(OrbitZoneTargetingIdealY); +DEFINE_CVAR_GLOBAL(OrbitZoneScanIdealY); +DEFINE_CVAR_GLOBAL(OrbitNearX); +DEFINE_CVAR_GLOBAL(OrbitNearZ); +// DEFINE_CVAR_GLOBAL(); // x1e0_ +// DEFINE_CVAR_GLOBAL(); // x1e4_ +DEFINE_CVAR_GLOBAL(OrbitFixedOffsetZDiff); +DEFINE_CVAR_GLOBAL(OrbitZRange); +// DEFINE_CVAR_GLOBAL(); // x1f0_ +// DEFINE_CVAR_GLOBAL(); // x1f4_ +// DEFINE_CVAR_GLOBAL(); // x1f8_ +DEFINE_CVAR_GLOBAL(OrbitPreventionTime); +DEFINE_CVAR_GLOBAL(DashEnabled); +DEFINE_CVAR_GLOBAL(DashOnButtonRelease); +DEFINE_CVAR_GLOBAL(DashButtonHoldCancelTime); +DEFINE_CVAR_GLOBAL(DashStrafeInputThreshold); +DEFINE_CVAR_GLOBAL(SidewaysDoubleJumpImpulse); +DEFINE_CVAR_GLOBAL(SidewaysVerticalDoubleJumpAccel); +DEFINE_CVAR_GLOBAL(SidewaysHorizontalDoubleJumpAccel); +DEFINE_CVAR_GLOBAL(ScanningRange); +DEFINE_CVAR_GLOBAL(ScanRetention); +DEFINE_CVAR_GLOBAL(ScanFreezesGame); +DEFINE_CVAR_GLOBAL(OrbitWhileScanning); +DEFINE_CVAR_GLOBAL(ScanMaxTargetDistance); +DEFINE_CVAR_GLOBAL(ScanMaxLockDistance) +DEFINE_CVAR_GLOBAL(FreeLookTurnsPlayer); +// DEFINE_CVAR_GLOBAL(); // x228_25_ +// DEFINE_CVAR_GLOBAL(); // x228_26_ +DEFINE_CVAR_GLOBAL(MoveDuringFreelook); +DEFINE_CVAR_GLOBAL(HoldButtonsForFreeLook); +// DEFINE_CVAR_GLOBAL(); // x228_30_ +// DEFINE_CVAR_GLOBAL(); // x228_31_ +// DEFINE_CVAR_GLOBAL(); // x229_24_ +DEFINE_CVAR_GLOBAL(AimWhenOrbitingPoint); +DEFINE_CVAR_GLOBAL(StayInFreeLookWhileFiring); +// DEFINE_CVAR_GLOBAL(); // x229_27_ +// DEFINE_CVAR_GLOBAL(); // x229_28_ +DEFINE_CVAR_GLOBAL(OrbitFixedOffset); +DEFINE_CVAR_GLOBAL(GunButtonTogglesHolster); +DEFINE_CVAR_GLOBAL(GunNotFiringHolstersGun); +DEFINE_CVAR_GLOBAL(FallingDoubleJump); +DEFINE_CVAR_GLOBAL(ImpulseDoubleJump); +DEFINE_CVAR_GLOBAL(FiringCancelsCameraPitch); +DEFINE_CVAR_GLOBAL(AssistedAimingIgnoreHorizontal); +DEFINE_CVAR_GLOBAL(AssistedAimingIgnoreVertical); +// DEFINE_CVAR_GLOBAL(); // x22c +// DEFINE_CVAR_GLOBAL(); // x230_ +DEFINE_CVAR_GLOBAL(AimMaxDistance); +// DEFINE_CVAR_GLOBAL(); // x238_ +// DEFINE_CVAR_GLOBAL(); // x23c_ +// DEFINE_CVAR_GLOBAL(); // x240_ +// DEFINE_CVAR_GLOBAL(); // x244_ +// DEFINE_CVAR_GLOBAL(); // x248_ +DEFINE_CVAR_GLOBAL(AimThresholdDistance); +// DEFINE_CVAR_GLOBAL(); // x250_ +// DEFINE_CVAR_GLOBAL(); // x254_ +DEFINE_CVAR_GLOBAL(AimBoxWidth); +DEFINE_CVAR_GLOBAL(AimBoxHeight); +DEFINE_CVAR_GLOBAL(AimTargetTimer); +DEFINE_CVAR_GLOBAL(AimAssistHorizontalAngle); +DEFINE_CVAR_GLOBAL(AimAssistVerticalAngle); +DEFINE_CVAR_GLOBAL(PlayerHeight); +DEFINE_CVAR_GLOBAL(PlayerXYHalfExtent); +DEFINE_CVAR_GLOBAL(StepUpHeight); +DEFINE_CVAR_GLOBAL(StepDownHeight); +DEFINE_CVAR_GLOBAL(PlayerBallHalfExtent); +DEFINE_CVAR_GLOBAL(FirstPersonCameraSpeed); +// DEFINE_CVAR_GLOBAL(); // x284_ +DEFINE_CVAR_GLOBAL(JumpCameraPitchDownStart); +DEFINE_CVAR_GLOBAL(JumpCameraPitchDownFull); +DEFINE_CVAR_GLOBAL(JumpCameraPitchDownAngle); +DEFINE_CVAR_GLOBAL(FallCameraPitchDownStart); +DEFINE_CVAR_GLOBAL(FallCameraPitchDownFull); +DEFINE_CVAR_GLOBAL(FallCameraPitchDownAngle); +DEFINE_CVAR_GLOBAL(OrbitDistanceMax); +DEFINE_CVAR_GLOBAL(GrappleSwingLength); +DEFINE_CVAR_GLOBAL(GrappleSwingPeriod); +DEFINE_CVAR_GLOBAL(GrapplePullSpeedMin); +DEFINE_CVAR_GLOBAL(GrappleCameraSpeed); +DEFINE_CVAR_GLOBAL(MaxGrappleLockedTurnAlignDistance); +DEFINE_CVAR_GLOBAL(GrapplePullSpeedProportion); +DEFINE_CVAR_GLOBAL(GrapplePullSpeedMax); +DEFINE_CVAR_GLOBAL(GrappleLookCenterSpeed); +DEFINE_CVAR_GLOBAL(MaxGrappleTurnSpeed); +DEFINE_CVAR_GLOBAL(GrappleJumpForce); +DEFINE_CVAR_GLOBAL(GrappleReleaseTime); +DEFINE_CVAR_GLOBAL(GrappleJumpMode); +DEFINE_CVAR_GLOBAL(OrbitReleaseBreaksGrapple); +DEFINE_CVAR_GLOBAL(InvertGrappleTurn); +DEFINE_CVAR_GLOBAL(GrappleBeamSpeed); +DEFINE_CVAR_GLOBAL(GrappleBeamXWaveAmplitude); +DEFINE_CVAR_GLOBAL(GrappleBeamZWaveAmplitude); +DEFINE_CVAR_GLOBAL(GrappleBeamAnglePhaseDelta); +// DEFINE_CVAR_GLOBAL(); // x2e8_ +// DEFINE_CVAR_GLOBAL(); // x2ec_ +// DEFINE_CVAR_GLOBAL(); // x2f0_ +// DEFINE_CVAR_GLOBAL(); // x2f4_ +DEFINE_CVAR_GLOBAL(FrozenTimeout); +DEFINE_CVAR_GLOBAL(IceBreakJumpCount); +DEFINE_CVAR_GLOBAL(VariaDamageReduction); +DEFINE_CVAR_GLOBAL(GravityDamageReduction); +DEFINE_CVAR_GLOBAL(PhazonDamageReduction); +} // namespace template <> void CTweakPlayer::Enumerate(athena::io::IStreamReader& __dna_reader) { /* x4_maxTranslationalAcceleration[0] */ @@ -1900,9 +2153,504 @@ void CTweakPlayer::FixupValues() { } std::string_view CTweakPlayer::DNAType() { return "DataSpec::DNAMP1::CTweakPlayer"sv; } - template <> void CTweakPlayer::Enumerate(size_t& __isz) { __isz += 785; } + +void CTweakPlayer::_tweakListener(hecl::CVar* cv) { + UPDATE_CVAR(MaxTranslationAccelerationNormal, cv, x4_maxTranslationalAcceleration[0]); + UPDATE_CVAR(MaxTranslationAccelerationAir, cv, x4_maxTranslationalAcceleration[1]); + UPDATE_CVAR(MaxTranslationAccelerationIce, cv, x4_maxTranslationalAcceleration[2]); + UPDATE_CVAR(MaxTranslationAccelerationOrganic, cv, x4_maxTranslationalAcceleration[3]); + UPDATE_CVAR(MaxTranslationAccelerationWater, cv, x4_maxTranslationalAcceleration[4]); + UPDATE_CVAR(MaxTranslationAccelerationLava, cv, x4_maxTranslationalAcceleration[5]); + UPDATE_CVAR(MaxTranslationAccelerationPhazon, cv, x4_maxTranslationalAcceleration[6]); + UPDATE_CVAR(MaxRotationAccelerationShrubbery, cv, x24_maxRotationalAcceleration[7]); + UPDATE_CVAR(MaxRotationAccelerationNormal, cv, x24_maxRotationalAcceleration[0]); + UPDATE_CVAR(MaxRotationAccelerationAir, cv, x24_maxRotationalAcceleration[1]); + UPDATE_CVAR(MaxRotationAccelerationIce, cv, x24_maxRotationalAcceleration[2]); + UPDATE_CVAR(MaxRotationAccelerationOrganic, cv, x24_maxRotationalAcceleration[3]); + UPDATE_CVAR(MaxRotationAccelerationWater, cv, x24_maxRotationalAcceleration[4]); + UPDATE_CVAR(MaxRotationAccelerationLava, cv, x24_maxRotationalAcceleration[5]); + UPDATE_CVAR(MaxRotationAccelerationPhazon, cv, x24_maxRotationalAcceleration[6]); + UPDATE_CVAR(MaxRotationAccelerationShrubbery, cv, x24_maxRotationalAcceleration[7]); + UPDATE_CVAR(TranslationFrictionNormal, cv, x44_translationFriction[0]); + UPDATE_CVAR(TranslationFrictionAir, cv, x44_translationFriction[1]); + UPDATE_CVAR(TranslationFrictionIce, cv, x44_translationFriction[2]); + UPDATE_CVAR(TranslationFrictionOrganic, cv, x44_translationFriction[3]); + UPDATE_CVAR(TranslationFrictionWater, cv, x44_translationFriction[4]); + UPDATE_CVAR(TranslationFrictionLava, cv, x44_translationFriction[5]); + UPDATE_CVAR(TranslationFrictionPhazon, cv, x44_translationFriction[6]); + UPDATE_CVAR(TranslationFrictionShrubbery, cv, x44_translationFriction[7]); + UPDATE_CVAR(RotationFrictionNormal, cv, x44_translationFriction[2]); + UPDATE_CVAR(RotationFrictionIce, cv, x44_translationFriction[2]); + UPDATE_CVAR(RotationFrictionOrganic, cv, x44_translationFriction[3]); + UPDATE_CVAR(RotationFrictionWater, cv, x44_translationFriction[4]); + UPDATE_CVAR(RotationFrictionLava, cv, x44_translationFriction[5]); + UPDATE_CVAR(RotationFrictionPhazon, cv, x44_translationFriction[6]); + UPDATE_CVAR(RotationFrictionShrubbery, cv, x44_translationFriction[7]); + UPDATE_CVAR(RotationMaxSpeedNormal, cv, x84_rotationMaxSpeed[2]); + UPDATE_CVAR(RotationMaxSpeedIce, cv, x84_rotationMaxSpeed[2]); + UPDATE_CVAR(RotationMaxSpeedOrganic, cv, x84_rotationMaxSpeed[3]); + UPDATE_CVAR(RotationMaxSpeedWater, cv, x84_rotationMaxSpeed[4]); + UPDATE_CVAR(RotationMaxSpeedLava, cv, x84_rotationMaxSpeed[5]); + UPDATE_CVAR(RotationMaxSpeedPhazon, cv, x84_rotationMaxSpeed[6]); + UPDATE_CVAR(RotationMaxSpeedShrubbery, cv, x84_rotationMaxSpeed[7]); + UPDATE_CVAR(TranslationMaxSpeedNormal, cv, xa4_translationMaxSpeed[2]); + UPDATE_CVAR(TranslationMaxSpeedIce, cv, xa4_translationMaxSpeed[2]); + UPDATE_CVAR(TranslationMaxSpeedOrganic, cv, xa4_translationMaxSpeed[3]); + UPDATE_CVAR(TranslationMaxSpeedWater, cv, xa4_translationMaxSpeed[4]); + UPDATE_CVAR(TranslationMaxSpeedLava, cv, xa4_translationMaxSpeed[5]); + UPDATE_CVAR(TranslationMaxSpeedPhazon, cv, xa4_translationMaxSpeed[6]); + UPDATE_CVAR(TranslationMaxSpeedShrubbery, cv, xa4_translationMaxSpeed[7]); + UPDATE_CVAR(NormalGravityAcceleration, cv, xc4_normalGravAccel); + UPDATE_CVAR(FluidGravityAcceleration, cv, xc8_fluidGravAccel); + UPDATE_CVAR(VerticalJumpAcceleration, cv, xcc_verticalJumpAccel); + UPDATE_CVAR(HorizontalJumpAcceleration, cv, xd0_horizontalJumpAccel); + UPDATE_CVAR(VerticalDoubleJumpAcceleration, cv, xd4_verticalDoubleJumpAccel); + UPDATE_CVAR(HorizontalDoubleJumpAcceleration, cv, xd8_horizontalDoubleJumpAccel); + UPDATE_CVAR(WaterJumpFactor, cv, xdc_waterJumpFactor); + UPDATE_CVAR(WaterBallJumpFactor, cv, xe0_waterBallJumpFactor); + UPDATE_CVAR(LavaJumpFactor, cv, xe4_lavaJumpFactor); + UPDATE_CVAR(LavaBallJumpFactor, cv, xe8_lavaBallJumpFactor); + UPDATE_CVAR(PhazonJumpFactor, cv, xec_phazonJumpFactor); + UPDATE_CVAR(PhazonBallJumpFactor, cv, xf0_phazonBallJumpFactor); + UPDATE_CVAR(AllowedJumpTime, cv, xf4_allowedJumpTime); + UPDATE_CVAR(AllowedDoubleJumpTime, cv, xf8_allowedDoubleJumpTime); + UPDATE_CVAR(MinDoubleJumpWindow, cv, xfc_minDoubleJumpWindow); + UPDATE_CVAR(MaxDoubleJumpWindow, cv, x100_maxDoubleJumpWindow); + // UPDATE_CVAR(); // x104_ + UPDATE_CVAR(MinJumpTime, cv, x108_minJumpTime); + UPDATE_CVAR(MinDoubleJumpTime, cv, x10c_minDoubleJumpTime); + UPDATE_CVAR(AllowedLedgeTime, cv, x110_allowedLedgeTime); + UPDATE_CVAR(DoubleJumpImpulse, cv, x114_doubleJumpImpulse); + UPDATE_CVAR(BackwardsForceMultiplier, cv, x118_backwardsForceMultiplier); + UPDATE_CVAR(BombJumpRadius, cv, x11c_bombJumpRadius); + UPDATE_CVAR(BombJumpHeight, cv, x120_bombJumpHeight); + UPDATE_CVAR(EyeOffset, cv, x124_eyeOffset); + UPDATE_CVAR(TurnSpeedMultiplier, cv, x128_turnSpeedMultiplier); + UPDATE_CVAR(FreeLookTurnSpeedMultiplier, cv, x12c_freeLookTurnSpeedMultiplier); + UPDATE_CVAR(HorizontalFreeLookAngleVelocity, cv, x130_horizontalFreeLookAngleVel); + UPDATE_CVAR(VerticalFreeLookAngleVelocity, cv, x134_verticalFreeLookAngleVel); + UPDATE_CVAR(FreeLookSpeed, cv, x138_freeLookSpeed); + UPDATE_CVAR(FreeLookSnapSpeed, cv, x13c_freeLookSnapSpeed); + // UPDATE_CVAR(); // x140_ + UPDATE_CVAR(FreeLookCenteredThresholdAngle, cv, x144_freeLookCenteredThresholdAngle); + UPDATE_CVAR(FreeLookCenteredTime, cv, x148_freeLookCenteredTime); + UPDATE_CVAR(FreeLookDampenFactor, cv, x14c_freeLookDampenFactor); + UPDATE_CVAR(LeftDivisor, cv, x150_leftDiv); + UPDATE_CVAR(RightDivisor, cv, x154_rightDiv); + UPDATE_CVAR(OrbitMinDistanceClose, cv, x158_orbitMinDistance[0]); + UPDATE_CVAR(OrbitMinDistanceFar, cv, x158_orbitMinDistance[1]); + UPDATE_CVAR(OrbitMinDistanceDefault, cv, x158_orbitMinDistance[2]); + UPDATE_CVAR(OrbitNormalDistanceClose, cv, x164_orbitNormalDistance[0]); + UPDATE_CVAR(OrbitNormalDistanceFar, cv, x164_orbitNormalDistance[1]); + UPDATE_CVAR(OrbitNormalDistanceDefault, cv, x164_orbitNormalDistance[2]); + UPDATE_CVAR(OrbitMaxDistanceClose, cv, x170_orbitMaxDistance[0]); + UPDATE_CVAR(OrbitMaxDistanceFar, cv, x170_orbitMaxDistance[1]); + UPDATE_CVAR(OrbitMaxDistanceDefault, cv, x170_orbitMaxDistance[2]); + // UPDATE_CVAR(); // x17c_ + UPDATE_CVAR(OrbitmodeTimer, cv, x180_orbitModeTimer); + UPDATE_CVAR(OrbitCameraSpeed, cv, x184_orbitCameraSpeed); + UPDATE_CVAR(OrbitUpperAngle, cv, x188_orbitUpperAngle); + UPDATE_CVAR(OrbitLowerAngle, cv, x18c_orbitLowerAngle); + UPDATE_CVAR(OrbitHorizontalAngle, cv, x190_orbitHorizAngle); + // UPDATE_CVAR(); // x194_ + // UPDATE_CVAR(); // x198_ + UPDATE_CVAR(OrbitMaxTargetDistance, cv, x19c_orbitMaxTargetDistance); + UPDATE_CVAR(OrbitMaxLockDistance, cv, x1a0_orbitMaxLockDistance); + UPDATE_CVAR(OrbitDistanceThreshold, cv, x1a4_orbitDistanceThreshold); + UPDATE_CVAR(OrbitScreenTargetingBoxHalfExtentX, cv, x1a8_orbitScreenBoxHalfExtentX[0]); + UPDATE_CVAR(OrbitScreenScanBoxHalfExtentX, cv, x1a8_orbitScreenBoxHalfExtentX[1]); + UPDATE_CVAR(OrbitScreenTargetingBoxHalfExtentY, cv, x1b0_orbitScreenBoxHalfExtentY[0]); + UPDATE_CVAR(OrbitScreenScanBoxHalfExtentY, cv, x1b0_orbitScreenBoxHalfExtentY[1]); + UPDATE_CVAR(OrbitScreenTargetingBoxCenterX, cv, x1b8_orbitScreenBoxCenterX[0]); + UPDATE_CVAR(OrbitScreenScanBoxCenterX, cv, x1b8_orbitScreenBoxCenterX[1]); + UPDATE_CVAR(OrbitScreenTargetingBoxCenterY, cv, x1c0_orbitScreenBoxCenterY[0]); + UPDATE_CVAR(OrbitScreenScanBoxCenterY, cv, x1c0_orbitScreenBoxCenterY[1]); + UPDATE_CVAR(OrbitZoneTargetingIdealX, cv, x1c8_orbitZoneIdealX[0]); + UPDATE_CVAR(OrbitZoneScanIdealX, cv, x1c8_orbitZoneIdealX[1]); + UPDATE_CVAR(OrbitZoneTargetingIdealY, cv, x1d0_orbitZoneIdealY[0]); + UPDATE_CVAR(OrbitZoneScanIdealY, cv, x1d0_orbitZoneIdealY[1]); + UPDATE_CVAR(OrbitNearX, cv, x1d8_orbitNearX); + UPDATE_CVAR(OrbitNearZ, cv, x1dc_orbitNearZ); + // UPDATE_CVAR(); // x1e0_ + // UPDATE_CVAR(); // x1e4_ + UPDATE_CVAR(OrbitFixedOffsetZDiff, cv, x1e8_orbitFixedOffsetZDiff); + UPDATE_CVAR(OrbitZRange, cv, x1ec_orbitZRange); + // UPDATE_CVAR(); // x1f0_ + // UPDATE_CVAR(); // x1f4_ + // UPDATE_CVAR(); // x1f8_ + UPDATE_CVAR(OrbitPreventionTime, cv, x1fc_orbitPreventionTime); + UPDATE_CVAR_BITFIELD(DashEnabled, cv, x200_24_dashEnabled); + UPDATE_CVAR_BITFIELD(DashOnButtonRelease, cv, x200_25_dashOnButtonRelease); + UPDATE_CVAR(DashButtonHoldCancelTime, cv, x204_dashButtonHoldCancelTime); + UPDATE_CVAR(DashStrafeInputThreshold, cv, x208_dashStrafeInputThreshold); + UPDATE_CVAR(SidewaysDoubleJumpImpulse, cv, x20c_sidewaysDoubleJumpImpulse); + UPDATE_CVAR(SidewaysVerticalDoubleJumpAccel, cv, x210_sidewaysVerticalDoubleJumpAccel); + UPDATE_CVAR(SidewaysHorizontalDoubleJumpAccel, cv, x214_sidewaysHorizontalDoubleJumpAccel); + UPDATE_CVAR(ScanningRange, cv, x218_scanningRange); + UPDATE_CVAR_BITFIELD(ScanRetention, cv, x21c_24_scanRetention); + UPDATE_CVAR_BITFIELD(ScanFreezesGame, cv, x21c_25_scanFreezesGame); + UPDATE_CVAR_BITFIELD(OrbitWhileScanning, cv, x21c_26_orbitWhileScanning); + UPDATE_CVAR(ScanMaxTargetDistance, cv, x220_scanMaxTargetDistance); + UPDATE_CVAR(ScanMaxLockDistance, cv, x224_scanMaxLockDistance); + UPDATE_CVAR_BITFIELD(FreeLookTurnsPlayer, cv, x228_24_freelookTurnsPlayer); + // UPDATE_CVAR_BITFIELD(); // x228_25_ + // UPDATE_CVAR_BITFIELD(); // x228_26_ + UPDATE_CVAR_BITFIELD(MoveDuringFreelook, cv, x228_27_moveDuringFreeLook); + UPDATE_CVAR_BITFIELD(HoldButtonsForFreeLook, cv, x228_28_holdButtonsForFreeLook); + // UPDATE_CVAR_BITFIELD(); // x228_30_ + // UPDATE_CVAR_BITFIELD(); // x228_31_ + // UPDATE_CVAR_BITFIELD(); // x229_24_ + UPDATE_CVAR_BITFIELD(AimWhenOrbitingPoint, cv, x229_25_aimWhenOrbitingPoint); + UPDATE_CVAR_BITFIELD(StayInFreeLookWhileFiring, cv, x229_26_stayInFreeLookWhileFiring); + // UPDATE_CVAR_BITFIELD(); // x229_27_ + // UPDATE_CVAR_BITFIELD(); // x229_28_ + UPDATE_CVAR_BITFIELD(OrbitFixedOffset, cv, x229_29_orbitFixedOffset); + UPDATE_CVAR_BITFIELD(GunButtonTogglesHolster, cv, x229_30_gunButtonTogglesHolster); + UPDATE_CVAR_BITFIELD(GunNotFiringHolstersGun, cv, x229_31_gunNotFiringHolstersGun); + UPDATE_CVAR_BITFIELD(FallingDoubleJump, cv, x22a_24_fallingDoubleJump); + UPDATE_CVAR_BITFIELD(ImpulseDoubleJump, cv, x22a_25_impulseDoubleJump); + UPDATE_CVAR_BITFIELD(FiringCancelsCameraPitch, cv, x22a_26_firingCancelsCameraPitch); + UPDATE_CVAR_BITFIELD(AssistedAimingIgnoreHorizontal, cv, x22a_27_assistedAimingIgnoreHorizontal); + UPDATE_CVAR_BITFIELD(AssistedAimingIgnoreVertical, cv, x22a_28_assistedAimingIgnoreVertical); + // UPDATE_CVAR(); // x22c + // UPDATE_CVAR(); // x230_ + UPDATE_CVAR(AimMaxDistance, cv, x234_aimMaxDistance); + // UPDATE_CVAR(); // x238_ + // UPDATE_CVAR(); // x23c_ + // UPDATE_CVAR(); // x240_ + // UPDATE_CVAR(); // x244_ + // UPDATE_CVAR(); // x248_ + UPDATE_CVAR(AimThresholdDistance, cv, x24c_aimThresholdDistance); + // UPDATE_CVAR(); // x250_ + // UPDATE_CVAR(); // x254_ + UPDATE_CVAR(AimBoxWidth, cv, x258_aimBoxWidth); + UPDATE_CVAR(AimBoxHeight, cv, x25c_aimBoxHeight); + UPDATE_CVAR(AimTargetTimer, cv, x260_aimTargetTimer); + UPDATE_CVAR(AimAssistHorizontalAngle, cv, x264_aimAssistHorizontalAngle); + UPDATE_CVAR(AimAssistVerticalAngle, cv, x268_aimAssistVerticalAngle); + UPDATE_CVAR(PlayerHeight, cv, x26c_playerHeight); + UPDATE_CVAR(PlayerXYHalfExtent, cv, x270_playerXYHalfExtent); + UPDATE_CVAR(StepUpHeight, cv, x274_stepUpHeight); + UPDATE_CVAR(StepDownHeight, cv, x278_stepDownHeight); + UPDATE_CVAR(PlayerBallHalfExtent, cv, x27c_playerBallHalfExtent); + UPDATE_CVAR(FirstPersonCameraSpeed, cv, x280_firstPersonCameraSpeed); + // UPDATE_CVAR(); // x284_ + UPDATE_CVAR(JumpCameraPitchDownStart, cv, x288_jumpCameraPitchDownStart); + UPDATE_CVAR(JumpCameraPitchDownFull, cv, x28c_jumpCameraPitchDownFull); + UPDATE_CVAR(JumpCameraPitchDownAngle, cv, x290_jumpCameraPitchDownAngle); + UPDATE_CVAR(FallCameraPitchDownStart, cv, x294_fallCameraPitchDownStart); + UPDATE_CVAR(FallCameraPitchDownFull, cv, x298_fallCameraPitchDownFull); + UPDATE_CVAR(FallCameraPitchDownAngle, cv, x29c_fallCameraPitchDownAngle); + UPDATE_CVAR(OrbitDistanceMax, cv, x2a0_orbitDistanceMax); + UPDATE_CVAR(GrappleSwingLength, cv, x2a4_grappleSwingLength); + UPDATE_CVAR(GrappleSwingPeriod, cv, x2a8_grappleSwingPeriod); + UPDATE_CVAR(GrapplePullSpeedMin, cv, x2ac_grapplePullSpeedMin); + UPDATE_CVAR(GrappleCameraSpeed, cv, x2b0_grappleCameraSpeed); + UPDATE_CVAR(MaxGrappleLockedTurnAlignDistance, cv, x2b4_maxGrappleLockedTurnAlignDistance); + UPDATE_CVAR(GrapplePullSpeedProportion, cv, x2b8_grapplePullSpeedProportion); + UPDATE_CVAR(GrapplePullSpeedMax, cv, x2bc_grapplePullSpeedMax); + UPDATE_CVAR(GrappleLookCenterSpeed, cv, x2c0_grappleLookCenterSpeed); + UPDATE_CVAR(MaxGrappleTurnSpeed, cv, x2c4_maxGrappleTurnSpeed); + UPDATE_CVAR(GrappleJumpForce, cv, x2c8_grappleJumpForce); + UPDATE_CVAR(GrappleReleaseTime, cv, x2cc_grappleReleaseTime); + UPDATE_CVAR(GrappleJumpMode, cv, x2d0_grappleJumpMode); + UPDATE_CVAR(OrbitReleaseBreaksGrapple, cv, x2d4_orbitReleaseBreaksGrapple); + UPDATE_CVAR(InvertGrappleTurn, cv, x2d5_invertGrappleTurn); + UPDATE_CVAR(GrappleBeamSpeed, cv, x2d8_grappleBeamSpeed); + UPDATE_CVAR(GrappleBeamXWaveAmplitude, cv, x2dc_grappleBeamXWaveAmplitude); + UPDATE_CVAR(GrappleBeamZWaveAmplitude, cv, x2e0_grappleBeamZWaveAmplitude); + UPDATE_CVAR(GrappleBeamAnglePhaseDelta, cv, x2e4_grappleBeamAnglePhaseDelta); + // UPDATE_CVAR(); // x2e8_ + // UPDATE_CVAR(); // x2ec_ + // UPDATE_CVAR(); // x2f0_ + // UPDATE_CVAR(); // x2f4_ + UPDATE_CVAR(FrozenTimeout, cv, x2f8_frozenTimeout); + UPDATE_CVAR(IceBreakJumpCount, cv, x2fc_iceBreakJumpCount); + UPDATE_CVAR(VariaDamageReduction, cv, x300_variaDamageReduction); + UPDATE_CVAR(GravityDamageReduction, cv, x304_gravityDamageReduction); + UPDATE_CVAR(PhazonDamageReduction, cv, x308_phazonDamageReduction); +} + +void CTweakPlayer::initCVars(hecl::CVarManager* mgr) { + CREATE_CVAR(MaxTranslationAccelerationNormal, + "Max translation acceleration allowed to the player under normal circumstances", + x4_maxTranslationalAcceleration[0], skDefaultFlags); + CREATE_CVAR(MaxTranslationAccelerationAir, "Max translation acceleration allowed to the player while in air", + x4_maxTranslationalAcceleration[1], skDefaultFlags); + CREATE_CVAR(MaxTranslationAccelerationIce, "Max translation acceleration allowed to the player while on ice surfaces", + x4_maxTranslationalAcceleration[2], skDefaultFlags); + CREATE_CVAR(MaxTranslationAccelerationOrganic, + "Max translation acceleration allowed to the player while on organic surfaces", + x4_maxTranslationalAcceleration[3], skDefaultFlags); + CREATE_CVAR(MaxTranslationAccelerationWater, "Max translation acceleration allowed to the player while in water", + x4_maxTranslationalAcceleration[4], skDefaultFlags); + CREATE_CVAR(MaxTranslationAccelerationLava, "Max translation acceleration allowed to the player while in lava", + x4_maxTranslationalAcceleration[5], skDefaultFlags); + CREATE_CVAR(MaxTranslationAccelerationPhazon, "Max translation acceleration allowed to the player while in phazon", + x4_maxTranslationalAcceleration[6], skDefaultFlags); + CREATE_CVAR(MaxTranslationAccelerationShrubbery, + "Max translation acceleration allowed to the player while in shrubbery", + x4_maxTranslationalAcceleration[7], skDefaultFlags); + CREATE_CVAR(MaxRotationAccelerationNormal, + "Max rotation acceleration allowed to the player under normal circumstances", + x24_maxRotationalAcceleration[0], skDefaultFlags); + CREATE_CVAR(MaxRotationAccelerationAir, "Max rotation acceleration allowed to the player while in air", + x24_maxRotationalAcceleration[1], skDefaultFlags); + CREATE_CVAR(MaxRotationAccelerationIce, "Max rotation acceleration allowed to the player while on ice surfaces", + x24_maxRotationalAcceleration[2], skDefaultFlags); + CREATE_CVAR(MaxRotationAccelerationOrganic, + "Max rotation acceleration allowed to the player while on organic surfaces", + x24_maxRotationalAcceleration[3], skDefaultFlags); + CREATE_CVAR(MaxRotationAccelerationWater, "Max rotation acceleration allowed to the player while in water", + x24_maxRotationalAcceleration[4], skDefaultFlags); + CREATE_CVAR(MaxRotationAccelerationLava, "Max rotation acceleration allowed to the player while in lava", + x24_maxRotationalAcceleration[5], skDefaultFlags); + CREATE_CVAR(MaxRotationAccelerationPhazon, "Max rotation acceleration allowed to the player while in phazon", + x24_maxRotationalAcceleration[6], skDefaultFlags); + CREATE_CVAR(MaxRotationAccelerationShrubbery, "Max rotation acceleration allowed to the player while in shrubbery", + x24_maxRotationalAcceleration[7], skDefaultFlags); + CREATE_CVAR(TranslationFrictionNormal, "Translation friction allowed to the player under normal circumstances", + x44_translationFriction[0], skDefaultFlags); + CREATE_CVAR(TranslationFrictionAir, "Translation friction allowed to the player while in air", + x44_translationFriction[1], skDefaultFlags); + CREATE_CVAR(TranslationFrictionIce, "Translation friction allowed to the player while on ice surfaces", + x44_translationFriction[2], skDefaultFlags); + CREATE_CVAR(TranslationFrictionOrganic, "Translation friction allowed to the player while on organic surfaces", + x44_translationFriction[3], skDefaultFlags); + CREATE_CVAR(TranslationFrictionWater, "Translation friction allowed to the player while in water", + x44_translationFriction[4], skDefaultFlags); + CREATE_CVAR(TranslationFrictionLava, "Translation friction allowed to the player while in lava", + x44_translationFriction[5], skDefaultFlags); + CREATE_CVAR(TranslationFrictionPhazon, "Translation friction allowed to the player while in phazon", + x44_translationFriction[6], skDefaultFlags); + CREATE_CVAR(TranslationFrictionShrubbery, "Translation friction allowed to the player while in shrubbery", + x44_translationFriction[7], skDefaultFlags); + CREATE_CVAR(RotationFrictionNormal, "Rotation friction allowed to the player under normal circumstances", + x44_translationFriction[0], skDefaultFlags); + CREATE_CVAR(RotationFrictionAir, "Rotation friction allowed to the player while in air", x44_translationFriction[1], + skDefaultFlags); + CREATE_CVAR(RotationFrictionIce, "Rotation friction allowed to the player while on ice surfaces", + x44_translationFriction[2], skDefaultFlags); + CREATE_CVAR(RotationFrictionOrganic, "Rotation friction allowed to the player while on organic surfaces", + x44_translationFriction[3], skDefaultFlags); + CREATE_CVAR(RotationFrictionWater, "Rotation friction allowed to the player while in water", + x44_translationFriction[4], skDefaultFlags); + CREATE_CVAR(RotationFrictionLava, "Rotation friction allowed to the player while in lava", x44_translationFriction[5], + skDefaultFlags); + CREATE_CVAR(RotationFrictionPhazon, "Rotation friction allowed to the player while in phazon", + x44_translationFriction[6], skDefaultFlags); + CREATE_CVAR(RotationFrictionShrubbery, "Rotation friction allowed to the player while in shrubbery", + x44_translationFriction[7], skDefaultFlags); + CREATE_CVAR(RotationMaxSpeedNormal, "Rotation max speed allowed to the player under normal circumstances", + x84_rotationMaxSpeed[0], skDefaultFlags); + CREATE_CVAR(RotationMaxSpeedAir, "Rotation max speed allowed to the player while in air", x84_rotationMaxSpeed[1], + skDefaultFlags); + CREATE_CVAR(RotationMaxSpeedIce, "Rotation max speed allowed to the player while on ice surfaces", + x84_rotationMaxSpeed[2], skDefaultFlags); + CREATE_CVAR(RotationMaxSpeedOrganic, "Rotation max speed allowed to the player while on organic surfaces", + x84_rotationMaxSpeed[3], skDefaultFlags); + CREATE_CVAR(RotationMaxSpeedWater, "Rotation max speed allowed to the player while in water", x84_rotationMaxSpeed[4], + skDefaultFlags); + CREATE_CVAR(RotationMaxSpeedLava, "Rotation max speed allowed to the player while in lava", x84_rotationMaxSpeed[5], + skDefaultFlags); + CREATE_CVAR(RotationMaxSpeedPhazon, "Rotation max speed allowed to the player while in phazon", + x84_rotationMaxSpeed[6], skDefaultFlags); + CREATE_CVAR(RotationMaxSpeedShrubbery, "Rotation max speed allowed to the player while in shrubbery", + x84_rotationMaxSpeed[7], skDefaultFlags); + CREATE_CVAR(TranslationMaxSpeedNormal, "Translation max speed allowed to the player under normal circumstances", + xa4_translationMaxSpeed[0], skDefaultFlags); + CREATE_CVAR(TranslationMaxSpeedNormal, "Translation max speed allowed to the player under normal circumstances", + xa4_translationMaxSpeed[1], skDefaultFlags); + CREATE_CVAR(TranslationMaxSpeedIce, "Translation max speed allowed to the player while on ice surfaces", + xa4_translationMaxSpeed[2], skDefaultFlags); + CREATE_CVAR(TranslationMaxSpeedOrganic, "Translation max speed allowed to the player while on organic surfaces", + xa4_translationMaxSpeed[3], skDefaultFlags); + CREATE_CVAR(TranslationMaxSpeedWater, "Translation max speed allowed to the player while in water", + xa4_translationMaxSpeed[4], skDefaultFlags); + CREATE_CVAR(TranslationMaxSpeedLava, "Translation max speed allowed to the player while in lava", + xa4_translationMaxSpeed[5], skDefaultFlags); + CREATE_CVAR(TranslationMaxSpeedPhazon, "Translation max speed allowed to the player while in phazon", + xa4_translationMaxSpeed[6], skDefaultFlags); + CREATE_CVAR(TranslationMaxSpeedShrubbery, "Translation max speed allowed to the player while in shrubbery", + xa4_translationMaxSpeed[7], skDefaultFlags); + CREATE_CVAR(NormalGravityAcceleration, "Gravity applied to the player under normal circumstances", + xc4_normalGravAccel, skDefaultFlags); + CREATE_CVAR(FluidGravityAcceleration, "Gravity applied to the player while in water", xc8_fluidGravAccel, + skDefaultFlags); + CREATE_CVAR(VerticalJumpAcceleration, "Vertical acceleration applied while jumping", xcc_verticalJumpAccel, + skDefaultFlags); + CREATE_CVAR(HorizontalJumpAcceleration, "Horizontal acceleration while jumping", xd0_horizontalJumpAccel, + skDefaultFlags); + CREATE_CVAR(VerticalDoubleJumpAcceleration, "Vertical acceleration while double jumping", xd4_verticalDoubleJumpAccel, + skDefaultFlags); + CREATE_CVAR(HorizontalDoubleJumpAcceleration, "Horizontal acceleration while double jumping", + xd8_horizontalDoubleJumpAccel, skDefaultFlags); + CREATE_CVAR(WaterJumpFactor, "Jump Factor while in water", xdc_waterJumpFactor, skDefaultFlags); + CREATE_CVAR(WaterBallJumpFactor, "Jump Factor while morphed in water", xe0_waterBallJumpFactor, skDefaultFlags); + CREATE_CVAR(LavaJumpFactor, "Jump Factor while in lava", xe4_lavaJumpFactor, skDefaultFlags); + CREATE_CVAR(LavaBallJumpFactor, "Jump Factor while morphed in lava", xe8_lavaBallJumpFactor, skDefaultFlags); + CREATE_CVAR(PhazonJumpFactor, "Jump Factor while in phazon", xec_phazonJumpFactor, skDefaultFlags); + CREATE_CVAR(PhazonBallJumpFactor, "Jump Factor while morphed in phazon", xf0_phazonBallJumpFactor, skDefaultFlags); + CREATE_CVAR(AllowedJumpTime, "", xf4_allowedJumpTime, skDefaultFlags); + CREATE_CVAR(AllowedDoubleJumpTime, "", xf8_allowedDoubleJumpTime, skDefaultFlags); + CREATE_CVAR(MinDoubleJumpWindow, "", xfc_minDoubleJumpWindow, skDefaultFlags); + CREATE_CVAR(MaxDoubleJumpWindow, "", x100_maxDoubleJumpWindow, skDefaultFlags); + // CREATE_CVAR(); // x104_ + CREATE_CVAR(MinJumpTime, "", x108_minJumpTime, skDefaultFlags); + CREATE_CVAR(MinDoubleJumpTime, "", x10c_minDoubleJumpTime, skDefaultFlags); + CREATE_CVAR(AllowedLedgeTime, "", x110_allowedLedgeTime, skDefaultFlags); + CREATE_CVAR(DoubleJumpImpulse, "", x114_doubleJumpImpulse, skDefaultFlags); + CREATE_CVAR(BackwardsForceMultiplier, "", x118_backwardsForceMultiplier, skDefaultFlags); + CREATE_CVAR(BombJumpRadius, "", x11c_bombJumpRadius, skDefaultFlags); + CREATE_CVAR(BombJumpHeight, "", x120_bombJumpHeight, skDefaultFlags); + CREATE_CVAR(EyeOffset, "", x124_eyeOffset, skDefaultFlags); + CREATE_CVAR(TurnSpeedMultiplier, "", x128_turnSpeedMultiplier, skDefaultFlags); + CREATE_CVAR(FreeLookTurnSpeedMultiplier, "", x12c_freeLookTurnSpeedMultiplier, skDefaultFlags); + CREATE_CVAR(HorizontalFreeLookAngleVelocity, "", x130_horizontalFreeLookAngleVel, skDefaultFlags); + CREATE_CVAR(VerticalFreeLookAngleVelocity, "", x134_verticalFreeLookAngleVel, skDefaultFlags); + CREATE_CVAR(FreeLookSpeed, "", x138_freeLookSpeed, skDefaultFlags); + CREATE_CVAR(FreeLookSnapSpeed, "", x13c_freeLookSnapSpeed, skDefaultFlags); + // CREATE_CVAR(); // x140_ + CREATE_CVAR(FreeLookCenteredThresholdAngle, "", x144_freeLookCenteredThresholdAngle, skDefaultFlags); + CREATE_CVAR(FreeLookCenteredTime, "", x148_freeLookCenteredTime, skDefaultFlags); + CREATE_CVAR(FreeLookDampenFactor, "", x14c_freeLookDampenFactor, skDefaultFlags); + CREATE_CVAR(LeftDivisor, "", x150_leftDiv, skDefaultFlags); + CREATE_CVAR(RightDivisor, "", x154_rightDiv, skDefaultFlags); + CREATE_CVAR(OrbitMinDistanceClose, "", x158_orbitMinDistance[0], skDefaultFlags); + CREATE_CVAR(OrbitMinDistanceFar, "", x158_orbitMinDistance[1], skDefaultFlags); + CREATE_CVAR(OrbitMinDistanceDefault, "", x158_orbitMinDistance[2], skDefaultFlags); + CREATE_CVAR(OrbitNormalDistanceClose, "", x164_orbitNormalDistance[0], skDefaultFlags); + CREATE_CVAR(OrbitNormalDistanceFar, "", x164_orbitNormalDistance[1], skDefaultFlags); + CREATE_CVAR(OrbitNormalDistanceDefault, "", x164_orbitNormalDistance[2], skDefaultFlags); + CREATE_CVAR(OrbitMaxDistanceClose, "", x170_orbitMaxDistance[0], skDefaultFlags); + CREATE_CVAR(OrbitMaxDistanceFar, "", x170_orbitMaxDistance[1], skDefaultFlags); + CREATE_CVAR(OrbitMaxDistanceDefault, "", x170_orbitMaxDistance[2], skDefaultFlags); + // CREATE_CVAR(); // x17c_ + CREATE_CVAR(OrbitmodeTimer, "", x180_orbitModeTimer, skDefaultFlags); + CREATE_CVAR(OrbitCameraSpeed, "", x184_orbitCameraSpeed, skDefaultFlags); + CREATE_CVAR(OrbitUpperAngle, "", x184_orbitCameraSpeed, skDefaultFlags); + CREATE_CVAR(OrbitLowerAngle, "", x184_orbitCameraSpeed, skDefaultFlags); + CREATE_CVAR(OrbitHorizontalAngle, "", x184_orbitCameraSpeed, skDefaultFlags); + // CREATE_CVAR(); // x194_ + // CREATE_CVAR(); // x198_ + CREATE_CVAR(OrbitMaxTargetDistance, "", x19c_orbitMaxTargetDistance, skDefaultFlags); + CREATE_CVAR(OrbitMaxLockDistance, "", x1a0_orbitMaxLockDistance, skDefaultFlags); + CREATE_CVAR(OrbitDistanceThreshold, "", x1a4_orbitDistanceThreshold, skDefaultFlags); + CREATE_CVAR(OrbitScreenTargetingBoxHalfExtentX, "", x1a8_orbitScreenBoxHalfExtentX[0], skDefaultFlags); + CREATE_CVAR(OrbitScreenScanBoxHalfExtentX, "", x1a8_orbitScreenBoxHalfExtentX[1], skDefaultFlags); + CREATE_CVAR(OrbitScreenTargetingBoxHalfExtentY, "", x1b0_orbitScreenBoxHalfExtentY[0], skDefaultFlags); + CREATE_CVAR(OrbitScreenScanBoxHalfExtentY, "", x1b0_orbitScreenBoxHalfExtentY[1], skDefaultFlags); + CREATE_CVAR(OrbitScreenTargetingBoxCenterX, "", x1b8_orbitScreenBoxCenterX[0], skDefaultFlags); + CREATE_CVAR(OrbitScreenScanBoxCenterX, "", x1b8_orbitScreenBoxCenterX[1], skDefaultFlags); + CREATE_CVAR(OrbitScreenTargetingBoxCenterY, "", x1c0_orbitScreenBoxCenterY[0], skDefaultFlags); + CREATE_CVAR(OrbitScreenScanBoxCenterY, "", x1c0_orbitScreenBoxCenterY[1], skDefaultFlags); + CREATE_CVAR(OrbitZoneTargetingIdealX, "", x1c8_orbitZoneIdealX[0], skDefaultFlags); + CREATE_CVAR(OrbitZoneScanIdealX, "", x1c8_orbitZoneIdealX[1], skDefaultFlags); + CREATE_CVAR(OrbitZoneTargetingIdealY, "", x1d0_orbitZoneIdealY[0], skDefaultFlags); + CREATE_CVAR(OrbitZoneScanIdealY, "", x1d0_orbitZoneIdealY[1], skDefaultFlags); + CREATE_CVAR(OrbitNearX, "", x1d8_orbitNearX, skDefaultFlags); + CREATE_CVAR(OrbitNearZ, "", x1dc_orbitNearZ, skDefaultFlags); + // CREATE_CVAR(); // x1e0_ + // CREATE_CVAR(); // x1e4_ + CREATE_CVAR(OrbitFixedOffsetZDiff, "", x1e8_orbitFixedOffsetZDiff, skDefaultFlags); + CREATE_CVAR(OrbitZRange, "", x1ec_orbitZRange, skDefaultFlags); + // CREATE_CVAR(); // x1f0_ + // CREATE_CVAR(); // x1f4_ + // CREATE_CVAR(); // x1f8_ + CREATE_CVAR(OrbitPreventionTime, "", x1fc_orbitPreventionTime, skDefaultFlags); + CREATE_CVAR_BITFIELD(DashEnabled, "", x200_24_dashEnabled, skDefaultFlags); + CREATE_CVAR_BITFIELD(DashOnButtonRelease, "", x200_25_dashOnButtonRelease, skDefaultFlags); + CREATE_CVAR(DashButtonHoldCancelTime, "", x204_dashButtonHoldCancelTime, skDefaultFlags); + CREATE_CVAR(DashStrafeInputThreshold, "", x208_dashStrafeInputThreshold, skDefaultFlags); + CREATE_CVAR(SidewaysDoubleJumpImpulse, "", x20c_sidewaysDoubleJumpImpulse, skDefaultFlags); + CREATE_CVAR(SidewaysVerticalDoubleJumpAccel, "", x210_sidewaysVerticalDoubleJumpAccel, skDefaultFlags); + CREATE_CVAR(SidewaysHorizontalDoubleJumpAccel, "", x214_sidewaysHorizontalDoubleJumpAccel, skDefaultFlags); + CREATE_CVAR(ScanningRange, "", x218_scanningRange, skDefaultFlags); + CREATE_CVAR_BITFIELD(ScanRetention, "", x21c_24_scanRetention, skDefaultFlags); + CREATE_CVAR_BITFIELD(ScanFreezesGame, "", x21c_25_scanFreezesGame, skDefaultFlags); + CREATE_CVAR_BITFIELD(OrbitWhileScanning, "", x21c_26_orbitWhileScanning, skDefaultFlags); + CREATE_CVAR(ScanMaxTargetDistance, "", x220_scanMaxTargetDistance, skDefaultFlags); + CREATE_CVAR(ScanMaxLockDistance, "", x224_scanMaxLockDistance, skDefaultFlags); + CREATE_CVAR_BITFIELD(FreeLookTurnsPlayer, "", x228_24_freelookTurnsPlayer, skDefaultFlags); + // CREATE_CVAR_BITFIELD(); // x228_25_ + // CREATE_CVAR_BITFIELD(); // x228_26_ + CREATE_CVAR_BITFIELD(MoveDuringFreelook, "", x228_27_moveDuringFreeLook, skDefaultFlags); + CREATE_CVAR_BITFIELD(HoldButtonsForFreeLook, "", x228_28_holdButtonsForFreeLook, skDefaultFlags); + // CREATE_CVAR_BITFIELD(); // x228_30_ + // CREATE_CVAR_BITFIELD(); // x228_31_ + // CREATE_CVAR(); // x229_24_ + CREATE_CVAR_BITFIELD(AimWhenOrbitingPoint, "", x229_25_aimWhenOrbitingPoint, skDefaultFlags); + CREATE_CVAR_BITFIELD(StayInFreeLookWhileFiring, "", x229_26_stayInFreeLookWhileFiring, skDefaultFlags); + // CREATE_CVAR_BITFIELD(); // x229_27_ + // CREATE_CVAR_BITFIELD(); // x229_28_ + CREATE_CVAR_BITFIELD(OrbitFixedOffset, "", x229_29_orbitFixedOffset, skDefaultFlags); + CREATE_CVAR_BITFIELD(GunButtonTogglesHolster, "", x229_30_gunButtonTogglesHolster, skDefaultFlags); + CREATE_CVAR_BITFIELD(GunNotFiringHolstersGun, "", x229_31_gunNotFiringHolstersGun, skDefaultFlags); + CREATE_CVAR_BITFIELD(FallingDoubleJump, "", x22a_24_fallingDoubleJump, skDefaultFlags); + CREATE_CVAR_BITFIELD(ImpulseDoubleJump, "", x22a_25_impulseDoubleJump, skDefaultFlags); + CREATE_CVAR_BITFIELD(FiringCancelsCameraPitch, "", x22a_26_firingCancelsCameraPitch, skDefaultFlags); + CREATE_CVAR_BITFIELD(AssistedAimingIgnoreHorizontal, "", x22a_27_assistedAimingIgnoreHorizontal, skDefaultFlags); + CREATE_CVAR_BITFIELD(AssistedAimingIgnoreVertical, "", x22a_28_assistedAimingIgnoreVertical, skDefaultFlags); + // CREATE_CVAR(); // x22c + // CREATE_CVAR(); // x230_ + CREATE_CVAR(AimMaxDistance, "", x234_aimMaxDistance, skDefaultFlags); + // CREATE_CVAR(); // x238_ + // CREATE_CVAR(); // x23c_ + // CREATE_CVAR(); // x240_ + // CREATE_CVAR(); // x244_ + // CREATE_CVAR(); // x248_ + CREATE_CVAR(AimThresholdDistance, "", x24c_aimThresholdDistance, skDefaultFlags); + // CREATE_CVAR(); // x250_ + // CREATE_CVAR(); // x254_ + CREATE_CVAR(AimBoxWidth, "", x258_aimBoxWidth, skDefaultFlags); + CREATE_CVAR(AimBoxHeight, "", x25c_aimBoxHeight, skDefaultFlags); + CREATE_CVAR(AimTargetTimer, "", x260_aimTargetTimer, skDefaultFlags); + CREATE_CVAR(AimAssistHorizontalAngle, "", x264_aimAssistHorizontalAngle, skDefaultFlags); + CREATE_CVAR(AimAssistVerticalAngle, "", x268_aimAssistVerticalAngle, skDefaultFlags); + CREATE_CVAR(PlayerHeight, "", x26c_playerHeight, skDefaultFlags); + CREATE_CVAR(PlayerXYHalfExtent, "", x270_playerXYHalfExtent, skDefaultFlags); + CREATE_CVAR(StepUpHeight, "", x274_stepUpHeight, skDefaultFlags); + CREATE_CVAR(StepDownHeight, "", x278_stepDownHeight, skDefaultFlags); + CREATE_CVAR(PlayerBallHalfExtent, "", x27c_playerBallHalfExtent, skDefaultFlags); + CREATE_CVAR(FirstPersonCameraSpeed, "", x280_firstPersonCameraSpeed, skDefaultFlags); + // CREATE_CVAR(); // x284_ + CREATE_CVAR(JumpCameraPitchDownStart, "", x288_jumpCameraPitchDownStart, skDefaultFlags); + CREATE_CVAR(JumpCameraPitchDownFull, "", x28c_jumpCameraPitchDownFull, skDefaultFlags); + CREATE_CVAR(JumpCameraPitchDownAngle, "", x290_jumpCameraPitchDownAngle, skDefaultFlags); + CREATE_CVAR(FallCameraPitchDownStart, "", x294_fallCameraPitchDownStart, skDefaultFlags); + CREATE_CVAR(FallCameraPitchDownFull, "", x298_fallCameraPitchDownFull, skDefaultFlags); + CREATE_CVAR(FallCameraPitchDownAngle, "", x29c_fallCameraPitchDownAngle, skDefaultFlags); + CREATE_CVAR(OrbitDistanceMax, "", x2a0_orbitDistanceMax, skDefaultFlags); + CREATE_CVAR(GrappleSwingLength, "", x2a4_grappleSwingLength, skDefaultFlags); + CREATE_CVAR(GrappleSwingPeriod, "", x2a8_grappleSwingPeriod, skDefaultFlags); + CREATE_CVAR(GrapplePullSpeedMin, "", x2ac_grapplePullSpeedMin, skDefaultFlags); + CREATE_CVAR(GrappleCameraSpeed, "", x2b0_grappleCameraSpeed, skDefaultFlags); + CREATE_CVAR(MaxGrappleLockedTurnAlignDistance, "", x2b4_maxGrappleLockedTurnAlignDistance, skDefaultFlags); + CREATE_CVAR(GrapplePullSpeedProportion, "", x2b8_grapplePullSpeedProportion, skDefaultFlags); + CREATE_CVAR(GrapplePullSpeedMax, "", x2bc_grapplePullSpeedMax, skDefaultFlags); + CREATE_CVAR(GrappleLookCenterSpeed, "", x2c0_grappleLookCenterSpeed, skDefaultFlags); + CREATE_CVAR(MaxGrappleTurnSpeed, "", x2c4_maxGrappleTurnSpeed, skDefaultFlags); + CREATE_CVAR(GrappleJumpForce, "", x2c8_grappleJumpForce, skDefaultFlags); + CREATE_CVAR(GrappleReleaseTime, "", x2cc_grappleReleaseTime, skDefaultFlags); + CREATE_CVAR(GrappleJumpMode, "", x2d0_grappleJumpMode, skDefaultFlags); + CREATE_CVAR(OrbitReleaseBreaksGrapple, "", x2d4_orbitReleaseBreaksGrapple, skDefaultFlags); + CREATE_CVAR(InvertGrappleTurn, "", x2d5_invertGrappleTurn, skDefaultFlags); + CREATE_CVAR(GrappleBeamSpeed, "", x2d8_grappleBeamSpeed, skDefaultFlags); + CREATE_CVAR(GrappleBeamXWaveAmplitude, "", x2dc_grappleBeamXWaveAmplitude, skDefaultFlags); + CREATE_CVAR(GrappleBeamZWaveAmplitude, "", x2e0_grappleBeamZWaveAmplitude, skDefaultFlags); + CREATE_CVAR(GrappleBeamAnglePhaseDelta, "", x2e4_grappleBeamAnglePhaseDelta, skDefaultFlags); + // CREATE_CVAR(); // x2e8_ + // CREATE_CVAR(); // x2ec_ + // CREATE_CVAR(); // x2f0_ + // CREATE_CVAR(); // x2f4_ + CREATE_CVAR(FrozenTimeout, "", x2f8_frozenTimeout, skDefaultFlags); + CREATE_CVAR(IceBreakJumpCount, "", x2fc_iceBreakJumpCount, skDefaultFlags); + CREATE_CVAR(VariaDamageReduction, "", x300_variaDamageReduction, skDefaultFlags); + CREATE_CVAR(GravityDamageReduction, "", x304_gravityDamageReduction, skDefaultFlags); + CREATE_CVAR(PhazonDamageReduction, "", x308_phazonDamageReduction, skDefaultFlags); +} } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP1/Tweaks/CTweakPlayer.hpp b/DataSpec/DNAMP1/Tweaks/CTweakPlayer.hpp index 038e1052a..a68a1c9af 100644 --- a/DataSpec/DNAMP1/Tweaks/CTweakPlayer.hpp +++ b/DataSpec/DNAMP1/Tweaks/CTweakPlayer.hpp @@ -1,6 +1,10 @@ #pragma once -#include "../../DNACommon/Tweaks/ITweakPlayer.hpp" +#include "DataSpec/DNACommon/Tweaks/ITweakPlayer.hpp" + +namespace hecl { +class CVar; +} namespace DataSpec::DNAMP1 { @@ -310,6 +314,8 @@ struct CTweakPlayer final : ITweakPlayer { } void FixupValues(); + void initCVars(hecl::CVarManager* mgr) override; + void _tweakListener(hecl::CVar* cv); }; } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP2/ANCS.cpp b/DataSpec/DNAMP2/ANCS.cpp index a9f6b644b..512722d1a 100644 --- a/DataSpec/DNAMP2/ANCS.cpp +++ b/DataSpec/DNAMP2/ANCS.cpp @@ -347,7 +347,7 @@ void ANCS::CharacterSet::CharacterInfo::Enumerate(typename Wr } std::string_view ANCS::CharacterSet::CharacterInfo::DNAType() { - return "urde::DNAMP2::ANCS::CharacterSet::CharacterInfo"sv; + return "DNAMP2::ANCS::CharacterSet::CharacterInfo"sv; } template <> @@ -523,7 +523,7 @@ void ANCS::AnimationSet::Enumerate(typename WriteYaml::Stream } } -std::string_view ANCS::AnimationSet::DNAType() { return "urde::DNAMP2::ANCS::AnimationSet"sv; } +std::string_view ANCS::AnimationSet::DNAType() { return "DNAMP2::ANCS::AnimationSet"sv; } template void ANCS::AnimationSet::EVNT::Enumerate(typename Op::StreamT& s) { @@ -542,6 +542,6 @@ void ANCS::AnimationSet::EVNT::Enumerate(typename Op::StreamT& s) { AT_SPECIALIZE_DNA(ANCS::AnimationSet::EVNT) -std::string_view ANCS::AnimationSet::EVNT::DNAType() { return "urde::DNAMP2::ANCS::AnimationSet::EVNT"sv; } +std::string_view ANCS::AnimationSet::EVNT::DNAType() { return "DNAMP2::ANCS::AnimationSet::EVNT"sv; } } // namespace DataSpec::DNAMP2 diff --git a/DataSpec/DNAMP2/DNAMP2.cpp b/DataSpec/DNAMP2/DNAMP2.cpp index dd08e1b78..709971698 100644 --- a/DataSpec/DNAMP2/DNAMP2.cpp +++ b/DataSpec/DNAMP2/DNAMP2.cpp @@ -22,7 +22,7 @@ #include "Runtime/GCNTypes.hpp" namespace DataSpec::DNAMP2 { -logvisor::Module Log("urde::DNAMP2"); +logvisor::Module Log("DataSpec::DNAMP2"); static bool GetNoShare(std::string_view name) { std::string lowerName(name); diff --git a/DataSpec/DNAMP2/STRG.cpp b/DataSpec/DNAMP2/STRG.cpp index 16c0632f1..f678d4fc0 100644 --- a/DataSpec/DNAMP2/STRG.cpp +++ b/DataSpec/DNAMP2/STRG.cpp @@ -213,6 +213,6 @@ void STRG::Enumerate(athena::io::YAMLDocWriter& writer) { } } -std::string_view STRG::DNAType() { return "urde::DNAMP2::STRG"sv; } +std::string_view STRG::DNAType() { return "DNAMP2::STRG"sv; } } // namespace DataSpec::DNAMP2 diff --git a/DataSpec/DNAMP3/CHAR.cpp b/DataSpec/DNAMP3/CHAR.cpp index 2f7324128..c9318d5d1 100644 --- a/DataSpec/DNAMP3/CHAR.cpp +++ b/DataSpec/DNAMP3/CHAR.cpp @@ -69,7 +69,7 @@ void CHAR::AnimationInfo::EVNT::SFXEvent::Enumerate(athena::i } std::string_view CHAR::AnimationInfo::EVNT::SFXEvent::DNAType() { - return "urde::DNAMP3::CHAR::AnimationInfo::EVNT::SFXEvent"sv; + return "DNAMP3::CHAR::AnimationInfo::EVNT::SFXEvent"sv; } template <> @@ -151,7 +151,7 @@ void CHAR::AnimationInfo::MetaAnimFactory::Enumerate(athena:: } std::string_view CHAR::AnimationInfo::MetaAnimFactory::DNAType() { - return "urde::DNAMP3::CHAR::AnimationInfo::MetaAnimFactory"sv; + return "DNAMP3::CHAR::AnimationInfo::MetaAnimFactory"sv; } } // namespace DataSpec::DNAMP3 diff --git a/DataSpec/DNAMP3/DNAMP3.cpp b/DataSpec/DNAMP3/DNAMP3.cpp index 873e6a0b2..0a284b06d 100644 --- a/DataSpec/DNAMP3/DNAMP3.cpp +++ b/DataSpec/DNAMP3/DNAMP3.cpp @@ -19,7 +19,7 @@ #include "Runtime/GCNTypes.hpp" namespace DataSpec::DNAMP3 { -logvisor::Module Log("urde::DNAMP3"); +logvisor::Module Log("DataSpec::DNAMP3"); static bool GetNoShare(std::string_view name) { std::string lowerName(name); diff --git a/DataSpec/DNAMP3/STRG.cpp b/DataSpec/DNAMP3/STRG.cpp index b40dd735d..e1b7906bc 100644 --- a/DataSpec/DNAMP3/STRG.cpp +++ b/DataSpec/DNAMP3/STRG.cpp @@ -220,6 +220,6 @@ void STRG::Enumerate(athena::io::YAMLDocWriter& writer) { } } -std::string_view STRG::DNAType() { return "urde::DNAMP3::STRG"sv; } +std::string_view STRG::DNAType() { return "DNAMP3::STRG"sv; } } // namespace DataSpec::DNAMP3 diff --git a/DataSpec/SpecBase.cpp b/DataSpec/SpecBase.cpp index 556954967..853ba830d 100644 --- a/DataSpec/SpecBase.cpp +++ b/DataSpec/SpecBase.cpp @@ -8,7 +8,7 @@ #include "DataSpec/DNACommon/DNACommon.hpp" #include "DataSpec/DNACommon/TXTR.hpp" #include "DataSpec/AssetNameMap.hpp" -#include "DataSpec/DNACommon/URDEVersionInfo.hpp" +#include "DataSpec/DNACommon/MetaforceVersionInfo.hpp" #include "hecl/ClientProcess.hpp" #include "nod/DiscBase.hpp" #include "nod/nod.hpp" @@ -22,7 +22,7 @@ namespace DataSpec { -static logvisor::Module Log("urde::SpecBase"); +static logvisor::Module Log("DataSpec::SpecBase"); static const hecl::SystemChar* MomErr[] = {_SYS_STR("Your metroid is in another castle"), _SYS_STR("HECL is experiencing a PTSD attack"), @@ -441,8 +441,8 @@ bool SpecBase::canPackage(const hecl::ProjectPath& path) { return path.isFile() || path.isDirectory(); } -void SpecBase::recursiveBuildResourceList(std::vector& listOut, - std::unordered_set& addedTags, +void SpecBase::recursiveBuildResourceList(std::vector& listOut, + std::unordered_set& addedTags, const hecl::ProjectPath& path, hecl::blender::Token& btok) { hecl::DirectoryEnumerator dEnum(path.getAbsolutePath(), hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true); @@ -452,7 +452,7 @@ void SpecBase::recursiveBuildResourceList(std::vector& listOut if (hecl::ProjectPath(childPath, _SYS_STR("!project.yaml")).isFile() && hecl::ProjectPath(childPath, _SYS_STR("!pool.yaml")).isFile()) { /* Handle AudioGroup case */ - if (urde::SObjectTag tag = tagFromPath(childPath)) { + if (metaforce::SObjectTag tag = tagFromPath(childPath)) { if (addedTags.find(tag) != addedTags.end()) continue; addedTags.insert(tag); @@ -466,7 +466,7 @@ void SpecBase::recursiveBuildResourceList(std::vector& listOut std::vector subPaths; flattenDependencies(childPath, subPaths, btok); for (const auto& subPath : subPaths) { - if (urde::SObjectTag tag = tagFromPath(subPath)) { + if (metaforce::SObjectTag tag = tagFromPath(subPath)) { if (addedTags.find(tag) != addedTags.end()) continue; addedTags.insert(tag); @@ -478,10 +478,10 @@ void SpecBase::recursiveBuildResourceList(std::vector& listOut } void SpecBase::copyBuildListData(std::vector>& fileIndex, - const std::vector& buildList, + const std::vector& buildList, const hecl::Database::DataSpecEntry* entry, bool fast, const hecl::MultiProgressPrinter& progress, athena::io::FileWriter& pakOut, - const std::unordered_map>& mlvlData) { + const std::unordered_map>& mlvlData) { fileIndex.reserve(buildList.size()); int loadIdx = 0; for (const auto& tag : buildList) { @@ -564,9 +564,9 @@ void SpecBase::doPackage(const hecl::ProjectPath& path, const hecl::Database::Da /* Output file */ athena::io::FileWriter pakOut(outPath.getAbsolutePath()); - std::vector buildList; + std::vector buildList; atUint64 resTableOffset = 0; - std::unordered_map> mlvlData; + std::unordered_map> mlvlData; if (IsWorldBlend(path)) /* World PAK */ { @@ -583,9 +583,9 @@ void SpecBase::doPackage(const hecl::ProjectPath& path, const hecl::Database::Da } else if (path.getPathType() == hecl::ProjectPath::Type::Directory) /* General PAK */ { /* Build resource list */ - std::unordered_set addedTags; + std::unordered_set addedTags; recursiveBuildResourceList(buildList, addedTags, path, btok); - std::vector> nameList; + std::vector> nameList; /* Build name list */ for (const auto& item : buildList) { @@ -605,10 +605,10 @@ void SpecBase::doPackage(const hecl::ProjectPath& path, const hecl::Database::Da /* Build resource list */ std::vector subPaths; flattenDependencies(path, subPaths, btok); - std::unordered_set addedTags; - std::vector> nameList; + std::unordered_set addedTags; + std::vector> nameList; for (const auto& subPath : subPaths) { - if (urde::SObjectTag tag = tagFromPath(subPath)) { + if (metaforce::SObjectTag tag = tagFromPath(subPath)) { if (addedTags.find(tag) != addedTags.end()) continue; addedTags.insert(tag); @@ -635,12 +635,12 @@ void SpecBase::doPackage(const hecl::ProjectPath& path, const hecl::Database::Da if (cp) { Log.report(logvisor::Info, FMT_STRING(_SYS_STR("Validating resources"))); progress.setMainIndeterminate(true); - std::vector cookTags; + std::vector cookTags; cookTags.reserve(buildList.size()); /* Ensure CMDLs are enqueued first to minimize synchronous dependency cooking */ for (int i = 0; i < 2; ++i) { - std::unordered_set addedTags; + std::unordered_set addedTags; addedTags.reserve(buildList.size()); for (auto& tag : buildList) { if ((i == 0 && tag.type == FOURCC('CMDL')) || (i == 1 && tag.type != FOURCC('CMDL'))) { @@ -732,7 +732,7 @@ void SpecBase::extractRandomStaticEntropy(const uint8_t* buf, const hecl::Projec png_infop info = png_create_info_struct(png); png_text textStruct = {}; - textStruct.key = png_charp("urde_nomip"); + textStruct.key = png_charp("meta_nomip"); png_set_text(png, info, &textStruct, 1); png_set_IHDR(png, info, 1024, 512, 8, PNG_COLOR_TYPE_GRAY_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, @@ -761,7 +761,7 @@ void SpecBase::clearTagCache() { m_catalogTagToNames.clear(); } -hecl::ProjectPath SpecBase::pathFromTag(const urde::SObjectTag& tag) const { +hecl::ProjectPath SpecBase::pathFromTag(const metaforce::SObjectTag& tag) const { std::unique_lock lk(m_backgroundIndexMutex); auto search = m_tagToPath.find(tag); if (search != m_tagToPath.cend()) @@ -769,14 +769,14 @@ hecl::ProjectPath SpecBase::pathFromTag(const urde::SObjectTag& tag) const { return {}; } -urde::SObjectTag SpecBase::tagFromPath(const hecl::ProjectPath& path) const { +metaforce::SObjectTag SpecBase::tagFromPath(const hecl::ProjectPath& path) const { auto search = m_pathToTag.find(path.hash()); if (search != m_pathToTag.cend()) return search->second; return buildTagFromPath(path); } -bool SpecBase::waitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectPath*& pathOut) { +bool SpecBase::waitForTagReady(const metaforce::SObjectTag& tag, const hecl::ProjectPath*& pathOut) { std::unique_lock lk(m_backgroundIndexMutex); auto search = m_tagToPath.find(tag); if (search == m_tagToPath.end()) { @@ -799,7 +799,7 @@ bool SpecBase::waitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectP return true; } -const urde::SObjectTag* SpecBase::getResourceIdByName(std::string_view name) const { +const metaforce::SObjectTag* SpecBase::getResourceIdByName(std::string_view name) const { std::string lower(name); std::transform(lower.cbegin(), lower.cend(), lower.begin(), tolower); @@ -823,12 +823,12 @@ const urde::SObjectTag* SpecBase::getResourceIdByName(std::string_view name) con return &search->second; } -FourCC SpecBase::getResourceTypeById(urde::CAssetId id) const { +FourCC SpecBase::getResourceTypeById(metaforce::CAssetId id) const { if (!id.IsValid()) return {}; std::unique_lock lk(m_backgroundIndexMutex); - urde::SObjectTag searchTag = {FourCC(), id}; + metaforce::SObjectTag searchTag = {FourCC(), id}; auto search = m_tagToPath.find(searchTag); if (search == m_tagToPath.end()) { if (m_backgroundRunning) { @@ -849,7 +849,7 @@ FourCC SpecBase::getResourceTypeById(urde::CAssetId id) const { return search->first.type; } -void SpecBase::enumerateResources(const std::function& lambda) const { +void SpecBase::enumerateResources(const std::function& lambda) const { waitForIndexComplete(); for (const auto& pair : m_tagToPath) { if (!lambda(pair.first)) @@ -858,7 +858,7 @@ void SpecBase::enumerateResources(const std::function& lambda) const { + const std::function& lambda) const { waitForIndexComplete(); for (const auto& pair : m_catalogNameToTag) { if (!lambda(pair.first, pair.second)) @@ -866,7 +866,7 @@ void SpecBase::enumerateNamedResources( } } -static void WriteTag(athena::io::YAMLDocWriter& cacheWriter, const urde::SObjectTag& pathTag, +static void WriteTag(athena::io::YAMLDocWriter& cacheWriter, const metaforce::SObjectTag& pathTag, const hecl::ProjectPath& path) { auto key = fmt::format(FMT_STRING("{}"), pathTag.id); if (auto* existing = cacheWriter.getCurNode()->findMapChild(key)) { @@ -877,7 +877,7 @@ static void WriteTag(athena::io::YAMLDocWriter& cacheWriter, const urde::SObject } } -static void WriteNameTag(athena::io::YAMLDocWriter& nameWriter, const urde::SObjectTag& pathTag, +static void WriteNameTag(athena::io::YAMLDocWriter& nameWriter, const metaforce::SObjectTag& pathTag, std::string_view name) { nameWriter.writeString(name.data(), fmt::format(FMT_STRING("{}"), pathTag.id)); } @@ -915,7 +915,7 @@ void SpecBase::readCatalog(const hecl::ProjectPath& catalogPath, athena::io::YAM } if (path.isNone()) continue; - urde::SObjectTag pathTag = tagFromPath(path); + metaforce::SObjectTag pathTag = tagFromPath(path); if (pathTag) { std::unique_lock lk(m_backgroundIndexMutex); m_catalogNameToTag[pLower] = pathTag; @@ -956,7 +956,7 @@ void SpecBase::backgroundIndexRecursiveCatalogs(const hecl::ProjectPath& dir, at } } -void SpecBase::insertPathTag(athena::io::YAMLDocWriter& cacheWriter, const urde::SObjectTag& tag, +void SpecBase::insertPathTag(athena::io::YAMLDocWriter& cacheWriter, const metaforce::SObjectTag& tag, const hecl::ProjectPath& path, bool dump) { #if 0 auto search = m_tagToPath.find(tag); @@ -989,7 +989,7 @@ bool SpecBase::addFileToIndex(const hecl::ProjectPath& path, athena::io::YAMLDoc return true; /* Classify intermediate into tag */ - urde::SObjectTag pathTag = buildTagFromPath(path); + metaforce::SObjectTag pathTag = buildTagFromPath(path); if (pathTag) { std::unique_lock lk{m_backgroundIndexMutex}; bool useGlob = false; @@ -1085,7 +1085,7 @@ void SpecBase::backgroundIndexRecursiveProc(const hecl::ProjectPath& dir, athena if (hecl::ProjectPath(path, "!project.yaml").isFile() && hecl::ProjectPath(path, "!pool.yaml").isFile()) { /* Avoid redundant filesystem access for re-caches */ if (m_pathToTag.find(path.hash()) == m_pathToTag.cend()) { - urde::SObjectTag pathTag(SBIG('AGSC'), path.parsedHash32()); + metaforce::SObjectTag pathTag(SBIG('AGSC'), path.parsedHash32()); insertPathTag(cacheWriter, pathTag, path); } } else { @@ -1138,7 +1138,7 @@ void SpecBase::backgroundIndexProc() { if (node.m_seqChildren.size() >= 2) { unsigned long id = strtoul(child.first.c_str(), nullptr, 16); hecl::FourCC type(node.m_seqChildren[0]->m_scalarString.c_str()); - urde::SObjectTag pathTag(type, id); + metaforce::SObjectTag pathTag(type, id); for (auto I = node.m_seqChildren.begin() + 1, E = node.m_seqChildren.end(); I != E; ++I) { hecl::ProjectPath path(m_project.getProjectWorkingPath(), (*I)->m_scalarString); if (!path.isNone()) @@ -1166,7 +1166,7 @@ void SpecBase::backgroundIndexProc() { m_catalogTagToNames.reserve(nameReader.getRootNode()->m_mapChildren.size()); for (const auto& child : nameReader.getRootNode()->m_mapChildren) { unsigned long id = strtoul(child.second->m_scalarString.c_str(), nullptr, 16); - auto search = m_tagToPath.find(urde::SObjectTag(FourCC(), uint32_t(id))); + auto search = m_tagToPath.find(metaforce::SObjectTag(FourCC(), uint32_t(id))); if (search != m_tagToPath.cend()) { std::string chLower = child.first; std::transform(chLower.cbegin(), chLower.cend(), chLower.begin(), tolower); @@ -1224,7 +1224,7 @@ void SpecBase::WriteVersionInfo(hecl::Database::Project& project, const hecl::Pr hecl::ProjectPath versionPath(pakPath, _SYS_STR("version.yaml")); versionPath.makeDirChain(false); - URDEVersionInfo info; + MetaforceVersionInfo info; info.version = m_version; info.region = m_region; info.game = m_game; diff --git a/DataSpec/SpecBase.hpp b/DataSpec/SpecBase.hpp index 00a41d7b3..f9e99bee7 100644 --- a/DataSpec/SpecBase.hpp +++ b/DataSpec/SpecBase.hpp @@ -57,7 +57,7 @@ struct SpecBase : hecl::Database::IDataSpec { virtual bool extractFromDisc(nod::DiscBase& disc, bool force, const hecl::MultiProgressPrinter& progress) = 0; /* Convert path to object tag */ - virtual urde::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const = 0; + virtual metaforce::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const = 0; /* Even if PC spec is being cooked, this will return the vanilla GCN spec */ virtual const hecl::Database::DataSpecEntry& getOriginalSpec() const = 0; @@ -121,15 +121,15 @@ struct SpecBase : hecl::Database::IDataSpec { virtual void buildWorldPakList(const hecl::ProjectPath& worldPath, const hecl::ProjectPath& worldPathCooked, hecl::blender::Token& btok, athena::io::FileWriter& w, - std::vector& listOut, atUint64& resTableOffset, - std::unordered_map>& mlvlData) {} + std::vector& listOut, atUint64& resTableOffset, + std::unordered_map>& mlvlData) {} virtual void buildPakList(hecl::blender::Token& btok, athena::io::FileWriter& w, - const std::vector& list, - const std::vector>& nameList, + const std::vector& list, + const std::vector>& nameList, atUint64& resTableOffset) {} - virtual void writePakFileIndex(athena::io::FileWriter& w, const std::vector& tags, + virtual void writePakFileIndex(athena::io::FileWriter& w, const std::vector& tags, const std::vector>& index, atUint64 resTableOffset) {} - virtual std::pair, size_t> compressPakData(const urde::SObjectTag& tag, + virtual std::pair, size_t> compressPakData(const metaforce::SObjectTag& tag, const uint8_t* data, size_t len) { return {}; } @@ -149,19 +149,19 @@ struct SpecBase : hecl::Database::IDataSpec { void extractRandomStaticEntropy(const uint8_t* buf, const hecl::ProjectPath& pakPath); /* Tag cache functions */ - urde::SObjectTag tagFromPath(const hecl::ProjectPath& path) const; - hecl::ProjectPath pathFromTag(const urde::SObjectTag& tag) const; - bool waitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectPath*& pathOut); - const urde::SObjectTag* getResourceIdByName(std::string_view name) const; - hecl::FourCC getResourceTypeById(urde::CAssetId id) const; - void enumerateResources(const std::function& lambda) const; - void enumerateNamedResources(const std::function& lambda) const; + metaforce::SObjectTag tagFromPath(const hecl::ProjectPath& path) const; + hecl::ProjectPath pathFromTag(const metaforce::SObjectTag& tag) const; + bool waitForTagReady(const metaforce::SObjectTag& tag, const hecl::ProjectPath*& pathOut); + const metaforce::SObjectTag* getResourceIdByName(std::string_view name) const; + hecl::FourCC getResourceTypeById(metaforce::CAssetId id) const; + void enumerateResources(const std::function& lambda) const; + void enumerateNamedResources(const std::function& lambda) const; void cancelBackgroundIndex(); void beginBackgroundIndex(); bool backgroundIndexRunning() const { return m_backgroundRunning; } void waitForIndexComplete() const; - virtual void getTagListForFile(const char* pakName, std::vector& out) const {} + virtual void getTagListForFile(const char* pakName, std::vector& out) const {} SpecBase(const hecl::Database::DataSpecEntry* specEntry, hecl::Database::Project& project, bool pc); ~SpecBase(); @@ -171,10 +171,10 @@ protected: bool m_pc; hecl::ProjectPath m_masterShader; - std::unordered_multimap m_tagToPath; - std::unordered_map m_pathToTag; - std::unordered_map m_catalogNameToTag; - std::unordered_map> m_catalogTagToNames; + std::unordered_multimap m_tagToPath; + std::unordered_map m_pathToTag; + std::unordered_map m_catalogNameToTag; + std::unordered_map> m_catalogTagToNames; void clearTagCache(); hecl::blender::Token m_backgroundBlender; @@ -183,7 +183,7 @@ protected: bool m_backgroundRunning = false; void readCatalog(const hecl::ProjectPath& catalogPath, athena::io::YAMLDocWriter& nameWriter); - void insertPathTag(athena::io::YAMLDocWriter& cacheWriter, const urde::SObjectTag& tag, const hecl::ProjectPath& path, + void insertPathTag(athena::io::YAMLDocWriter& cacheWriter, const metaforce::SObjectTag& tag, const hecl::ProjectPath& path, bool dump = true); bool addFileToIndex(const hecl::ProjectPath& path, athena::io::YAMLDocWriter& cacheWriter); void backgroundIndexRecursiveProc(const hecl::ProjectPath& path, athena::io::YAMLDocWriter& cacheWriter, @@ -192,13 +192,13 @@ protected: int level); void backgroundIndexProc(); - void recursiveBuildResourceList(std::vector& listOut, - std::unordered_set& addedTags, const hecl::ProjectPath& path, + void recursiveBuildResourceList(std::vector& listOut, + std::unordered_set& addedTags, const hecl::ProjectPath& path, hecl::blender::Token& btok); void copyBuildListData(std::vector>& fileIndex, - const std::vector& buildList, const hecl::Database::DataSpecEntry* entry, + const std::vector& buildList, const hecl::Database::DataSpecEntry* entry, bool fast, const hecl::MultiProgressPrinter& progress, athena::io::FileWriter& pakOut, - const std::unordered_map>& mlvlData); + const std::unordered_map>& mlvlData); std::unique_ptr m_disc; bool m_isWii{}; diff --git a/DataSpec/SpecMP1.cpp b/DataSpec/SpecMP1.cpp index b16197aa1..2feda7560 100644 --- a/DataSpec/SpecMP1.cpp +++ b/DataSpec/SpecMP1.cpp @@ -29,7 +29,7 @@ #include "DNACommon/DPSC.hpp" #include "DNACommon/DGRP.hpp" #include "DNACommon/MAPU.hpp" -#include "DNACommon/URDEVersionInfo.hpp" +#include "DNACommon/MetaforceVersionInfo.hpp" #include "DNACommon/Tweaks/TweakWriter.hpp" #include "DNAMP1/Tweaks/CTweakPlayerRes.hpp" #include "DNAMP1/Tweaks/CTweakGunRes.hpp" @@ -57,7 +57,7 @@ namespace DataSpec { using namespace std::literals; -static logvisor::Module Log("urde::SpecMP1"); +static logvisor::Module Log("DataSpec::SpecMP1"); extern hecl::Database::DataSpecEntry SpecEntMP1; extern hecl::Database::DataSpecEntry SpecEntMP1PC; extern hecl::Database::DataSpecEntry SpecEntMP1ORIG; @@ -322,7 +322,7 @@ struct SpecMP1 : SpecBase { hecl::ProjectPath outPath(m_project.getProjectWorkingPath(), _SYS_STR("out")); outPath.makeDir(); disc.getDataPartition()->extractSysFiles(outPath.getAbsolutePath(), ctx); - hecl::ProjectPath mp1OutPath(outPath, m_standalone ? _SYS_STR("files") : _SYS_STR("files/MP1")); + hecl::ProjectPath mp1OutPath(outPath, _SYS_STR("files/MP1")); mp1OutPath.makeDirChain(true); /* Extract non-pak files */ @@ -386,12 +386,7 @@ struct SpecMP1 : SpecBase { TextureCache::Generate(m_pakRouter, m_project, noAramPath); /* Write version data */ - hecl::ProjectPath versionPath; - if (m_standalone) { - versionPath = hecl::ProjectPath(m_project.getProjectWorkingPath(), _SYS_STR("out/files")); - } else { - versionPath = hecl::ProjectPath(m_project.getProjectWorkingPath(), _SYS_STR("out/files/MP1")); - } + hecl::ProjectPath versionPath = hecl::ProjectPath(m_project.getProjectWorkingPath(), _SYS_STR("out/files/MP1")); WriteVersionInfo(m_project, versionPath); return true; } @@ -482,7 +477,7 @@ struct SpecMP1 : SpecBase { }); } - urde::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const override { + metaforce::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const override { if (hecl::StringUtils::EndsWith(path.getAuxInfo(), _SYS_STR(".CSKR"))) return {SBIG('CSKR'), path.parsedHash32()}; else if (hecl::StringUtils::EndsWith(path.getAuxInfo(), _SYS_STR(".ANIM"))) @@ -551,7 +546,7 @@ struct SpecMP1 : SpecBase { athena::io::YAMLDocReader reader; yaml_parser_set_input_file(reader.getParser(), fp.get()); - urde::SObjectTag resTag; + metaforce::SObjectTag resTag; if (reader.ClassTypeOperation([&](std::string_view className) { if (className == DNAParticle::GPSM::DNAType()) { resTag.type = SBIG('PART'); @@ -643,7 +638,7 @@ struct SpecMP1 : SpecBase { return {}; } - void getTagListForFile(const char* pakName, std::vector& out) const override { + void getTagListForFile(const char* pakName, std::vector& out) const override { std::string pathPrefix("MP1/"); pathPrefix += pakName; pathPrefix += '/'; @@ -1001,9 +996,9 @@ struct SpecMP1 : SpecBase { } void buildWorldPakList(const hecl::ProjectPath& worldPath, const hecl::ProjectPath& worldPathCooked, - hecl::blender::Token& btok, athena::io::FileWriter& w, std::vector& listOut, + hecl::blender::Token& btok, athena::io::FileWriter& w, std::vector& listOut, atUint64& resTableOffset, - std::unordered_map>& mlvlData) override { + std::unordered_map>& mlvlData) override { DNAMP1::MLVL mlvl; { athena::io::FileReader r(worldPathCooked.getAbsolutePath()); @@ -1025,7 +1020,7 @@ struct SpecMP1 : SpecBase { } listOut.reserve(count); - urde::SObjectTag worldTag = tagFromPath(worldPath.getWithExtension(_SYS_STR(".*"), true)); + metaforce::SObjectTag worldTag = tagFromPath(worldPath.getWithExtension(_SYS_STR(".*"), true)); w.writeUint32Big(m_pc ? 0x80030005 : 0x00030005); w.writeUint32Big(0); @@ -1039,19 +1034,19 @@ struct SpecMP1 : SpecBase { nameEnt.name = parentDir.getLastComponentUTF8(); nameEnt.write(w); - std::unordered_set addedTags; + std::unordered_set addedTags; for (auto& area : mlvl.areas) { - urde::SObjectTag areaTag(FOURCC('MREA'), area.areaMREAId.toUint64()); + metaforce::SObjectTag areaTag(FOURCC('MREA'), area.areaMREAId.toUint64()); bool dupeRes = false; if (hecl::ProjectPath areaDir = pathFromTag(areaTag).getParentPath()) dupeRes = hecl::ProjectPath(areaDir, _SYS_STR("!duperes")).isFile(); - urde::SObjectTag nameTag(FOURCC('STRG'), area.areaNameId.toUint64()); + metaforce::SObjectTag nameTag(FOURCC('STRG'), area.areaNameId.toUint64()); if (nameTag) listOut.push_back(nameTag); for (const auto& dep : area.deps) { - urde::CAssetId newId = dep.id.toUint64(); + metaforce::CAssetId newId = dep.id.toUint64(); if (dupeRes || addedTags.find(newId) == addedTags.end()) { listOut.emplace_back(dep.type, newId); addedTags.insert(newId); @@ -1086,18 +1081,18 @@ struct SpecMP1 : SpecBase { area.depLayers = std::move(strippedDepLayers); } - urde::SObjectTag nameTag(FOURCC('STRG'), mlvl.worldNameId.toUint64()); + metaforce::SObjectTag nameTag(FOURCC('STRG'), mlvl.worldNameId.toUint64()); if (nameTag) listOut.push_back(nameTag); - urde::SObjectTag savwTag(FOURCC('SAVW'), mlvl.saveWorldId.toUint64()); + metaforce::SObjectTag savwTag(FOURCC('SAVW'), mlvl.saveWorldId.toUint64()); if (savwTag) { if (hecl::ProjectPath savwPath = pathFromTag(savwTag)) m_project.cookPath(savwPath, {}, false, true); listOut.push_back(savwTag); } - urde::SObjectTag mapTag(FOURCC('MAPW'), mlvl.worldMap.toUint64()); + metaforce::SObjectTag mapTag(FOURCC('MAPW'), mlvl.worldMap.toUint64()); if (mapTag) { if (hecl::ProjectPath mapPath = pathFromTag(mapTag)) { m_project.cookPath(mapPath, {}, false, true); @@ -1120,7 +1115,7 @@ struct SpecMP1 : SpecBase { listOut.push_back(mapTag); } - urde::SObjectTag skyboxTag(FOURCC('CMDL'), mlvl.worldSkyboxId.toUint64()); + metaforce::SObjectTag skyboxTag(FOURCC('CMDL'), mlvl.worldSkyboxId.toUint64()); if (skyboxTag) { listOut.push_back(skyboxTag); hecl::ProjectPath skyboxPath = pathFromTag(skyboxTag); @@ -1128,7 +1123,7 @@ struct SpecMP1 : SpecBase { auto data = btok.getBlenderConnection().beginData(); std::vector textures = data.getTextures(); for (const auto& tex : textures) { - urde::SObjectTag texTag = tagFromPath(tex); + metaforce::SObjectTag texTag = tagFromPath(tex); if (!texTag) Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Unable to resolve {}")), tex.getRelativePath()); listOut.push_back(texTag); @@ -1160,8 +1155,8 @@ struct SpecMP1 : SpecBase { } } - void buildPakList(hecl::blender::Token& btok, athena::io::FileWriter& w, const std::vector& list, - const std::vector>& nameList, + void buildPakList(hecl::blender::Token& btok, athena::io::FileWriter& w, const std::vector& list, + const std::vector>& nameList, atUint64& resTableOffset) override { w.writeUint32Big(m_pc ? 0x80030005 : 0x00030005); w.writeUint32Big(0); @@ -1189,13 +1184,13 @@ struct SpecMP1 : SpecBase { } } - void writePakFileIndex(athena::io::FileWriter& w, const std::vector& tags, + void writePakFileIndex(athena::io::FileWriter& w, const std::vector& tags, const std::vector>& index, atUint64 resTableOffset) override { w.seek(resTableOffset, athena::SeekOrigin::Begin); auto it = tags.begin(); for (const auto& item : index) { - const urde::SObjectTag& tag = *it++; + const metaforce::SObjectTag& tag = *it++; DNAMP1::PAK::Entry ent; ent.compressed = atUint32(std::get<2>(item)); ent.type = tag.type; @@ -1206,7 +1201,7 @@ struct SpecMP1 : SpecBase { } } - std::pair, size_t> compressPakData(const urde::SObjectTag& tag, const uint8_t* data, + std::pair, size_t> compressPakData(const metaforce::SObjectTag& tag, const uint8_t* data, size_t len) override { bool doCompress = false; switch (tag.type.toUint32()) { diff --git a/DataSpec/SpecMP2.cpp b/DataSpec/SpecMP2.cpp index 0e4b0c99e..6e2449068 100644 --- a/DataSpec/SpecMP2.cpp +++ b/DataSpec/SpecMP2.cpp @@ -12,7 +12,7 @@ #include "DNACommon/MAPU.hpp" #include "DNACommon/PATH.hpp" #include "DNACommon/TXTR.hpp" -#include "DNACommon/URDEVersionInfo.hpp" +#include "DNACommon/MetaforceVersionInfo.hpp" #include "hecl/ClientProcess.hpp" #include "hecl/Blender/Connection.hpp" @@ -25,7 +25,7 @@ namespace DataSpec { using namespace std::literals; -static logvisor::Module Log("urde::SpecMP2"); +static logvisor::Module Log("DataSpec::SpecMP2"); extern hecl::Database::DataSpecEntry SpecEntMP2; extern hecl::Database::DataSpecEntry SpecEntMP2ORIG; @@ -284,7 +284,7 @@ struct SpecMP2 : SpecBase { hecl::ProjectPath outPath(m_project.getProjectWorkingPath(), _SYS_STR("out")); outPath.makeDir(); disc.getDataPartition()->extractSysFiles(outPath.getAbsolutePath(), ctx); - hecl::ProjectPath mp2OutPath(outPath, m_standalone ? _SYS_STR("files") : _SYS_STR("files/MP2")); + hecl::ProjectPath mp2OutPath(outPath, _SYS_STR("files/MP2")); mp2OutPath.makeDirChain(true); progress.startNewLine(); @@ -327,12 +327,7 @@ struct SpecMP2 : SpecBase { TextureCache::Generate(m_pakRouter, m_project, noAramPath); /* Write version data */ - hecl::ProjectPath versionPath; - if (m_standalone) { - versionPath = hecl::ProjectPath(m_project.getProjectWorkingPath(), _SYS_STR("out/files")); - } else { - versionPath = hecl::ProjectPath(m_project.getProjectWorkingPath(), _SYS_STR("out/files/MP2")); - } + hecl::ProjectPath versionPath = hecl::ProjectPath(m_project.getProjectWorkingPath(), _SYS_STR("out/files/MP2")); WriteVersionInfo(m_project, versionPath); return true; } @@ -361,7 +356,7 @@ struct SpecMP2 : SpecBase { }); } - urde::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const override { return {}; } + metaforce::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const override { return {}; } void cookMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast, hecl::blender::Token& btok, FCookProgress progress) override {} diff --git a/DataSpec/SpecMP3.cpp b/DataSpec/SpecMP3.cpp index 3fa4bd973..e41dacf7d 100644 --- a/DataSpec/SpecMP3.cpp +++ b/DataSpec/SpecMP3.cpp @@ -9,7 +9,7 @@ #include "DataSpec/DNAMP3/MAPA.hpp" #include "DataSpec/DNAMP2/STRG.hpp" #include "DataSpec/DNACommon/TXTR.hpp" -#include "DataSpec/DNACommon/URDEVersionInfo.hpp" +#include "DataSpec/DNACommon/MetaforceVersionInfo.hpp" #include "hecl/ClientProcess.hpp" #include "hecl/Blender/Connection.hpp" @@ -22,7 +22,7 @@ namespace DataSpec { using namespace std::literals; -static logvisor::Module Log("urde::SpecMP3"); +static logvisor::Module Log("DataSpec::SpecMP3"); extern hecl::Database::DataSpecEntry SpecEntMP3; extern hecl::Database::DataSpecEntry SpecEntMP3ORIG; @@ -396,7 +396,7 @@ struct SpecMP3 : SpecBase { hecl::ProjectPath outPath(m_project.getProjectWorkingPath(), _SYS_STR("out")); outPath.makeDir(); disc.getDataPartition()->extractSysFiles(outPath.getAbsolutePath(), ctx); - m_outPath = {outPath, m_standalone ? _SYS_STR("files") : _SYS_STR("files/MP3")}; + m_outPath = {outPath, _SYS_STR("files/MP3")}; m_outPath.makeDirChain(true); currentTarget = _SYS_STR("MP3 Root"); @@ -524,7 +524,7 @@ struct SpecMP3 : SpecBase { return false; } - urde::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const override { return {}; } + metaforce::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const override { return {}; } void cookMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast, hecl::blender::Token& btok, FCookProgress progress) override {} diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index 202ca61cb..063c41eb2 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -2,17 +2,11 @@ add_subdirectory(locale) add_subdirectory(icons) add_subdirectory(badging) -if(URDE_DLPACKAGE) - set(METADATA_VERSION_STRING ${URDE_DLPACKAGE}) -else() - set(METADATA_VERSION_STRING "BETA") -endif() - unset(URDE_PLAT_LIBS) if(WIN32) - configure_file(platforms/win/urde.rc.in "${CMAKE_CURRENT_SOURCE_DIR}/platforms/win/urde.rc" @ONLY) - set(PLAT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/platforms/win/urde.rc" platforms/win/urde.manifest) + configure_file(platforms/win/metaforce.rc.in "${CMAKE_CURRENT_SOURCE_DIR}/platforms/win/metaforce.rc" @ONLY) + set(PLAT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/platforms/win/metaforce.rc" platforms/win/metaforce.manifest) if(WINDOWS_STORE) set(UWP_ASSETS platforms/win/Assets/LargeTile.scale-100.png @@ -45,11 +39,11 @@ if(WIN32) platforms/win/Assets/Square150x150Logo.scale-150.png platforms/win/Assets/Square150x150Logo.scale-200.png platforms/win/Assets/Square150x150Logo.scale-400.png - platforms/win/Assets/urde.scale-100.png - platforms/win/Assets/urde.scale-125.png - platforms/win/Assets/urde.scale-150.png - platforms/win/Assets/urde.scale-200.png - platforms/win/Assets/urde.scale-400.png + platforms/win/Assets/metaforce.scale-100.png + platforms/win/Assets/metaforce.scale-125.png + platforms/win/Assets/metaforce.scale-150.png + platforms/win/Assets/metaforce.scale-200.png + platforms/win/Assets/metaforce.scale-400.png platforms/win/Assets/WideTile.scale-100.png platforms/win/Assets/WideTile.scale-125.png platforms/win/Assets/WideTile.scale-150.png @@ -61,10 +55,7 @@ if(WIN32) list(APPEND PLAT_SRCS ${UWP_ASSETS} platforms/win/Package.appxmanifest) endif() elseif(APPLE) - set(PLAT_SRCS platforms/mac/mainicon.icns) - set_source_files_properties(platforms/mac/mainicon.icns PROPERTIES - MACOSX_PACKAGE_LOCATION Resources) - configure_file(platforms/mac/Info.plist.in "${CMAKE_CURRENT_BINARY_DIR}/Info.plist" @ONLY) + # nothing elseif(UNIX) add_subdirectory(platforms/freedesktop) declare_wmicon_target() @@ -72,7 +63,7 @@ elseif(UNIX) set(URDE_PLAT_LIBS rt) endif() -add_executable(urde-old WIN32 MACOSX_BUNDLE +add_executable(metaforce-old WIN32 main.cpp ${PLAT_SRCS} Space.hpp Space.cpp SplashScreen.hpp SplashScreen.cpp @@ -85,40 +76,37 @@ add_executable(urde-old WIN32 MACOSX_BUNDLE Resource.hpp Resource.cpp Camera.hpp Camera.cpp GameMode.hpp GameMode.cpp) -target_atdna(urde-old atdna_Space.cpp Space.hpp) -target_atdna(urde-old atdna_ResourceBrowser.cpp ResourceBrowser.hpp) -target_atdna(urde-old atdna_ModelViewer.cpp ModelViewer.hpp) -target_atdna(urde-old atdna_ParticleEditor.cpp ParticleEditor.hpp) -target_atdna(urde-old atdna_InformationCenter.cpp InformationCenter.hpp) -target_atdna(urde-old atdna_GameMode.cpp GameMode.hpp) -target_compile_definitions(urde-old PUBLIC URDE_DLPACKAGE="${URDE_DLPACKAGE}") +target_include_directories(metaforce-old PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/Runtime # FIXME atdna cmake issue + ${CMAKE_BINARY_DIR}) -target_include_directories(urde-old PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}) - -target_link_libraries(urde-old - UrdeIcons - UrdeBadging +target_link_libraries(metaforce-old + MetaforceIcons + MetaforceBadging RuntimeCommon + amuse + RetroDataSpec + kabufuda ${URDE_PLAT_LIBS}) -if(COMMAND add_sanitizers) - add_sanitizers(urde-old) -endif() -set_target_properties(urde-old PROPERTIES - MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/Info.plist" - MACOSX_BUNDLE_BUNDLE_NAME "urde") +target_atdna(metaforce-old atdna_Space.cpp Space.hpp) +target_atdna(metaforce-old atdna_ResourceBrowser.cpp ResourceBrowser.hpp) +target_atdna(metaforce-old atdna_ModelViewer.cpp ModelViewer.hpp) +target_atdna(metaforce-old atdna_ParticleEditor.cpp ParticleEditor.hpp) +target_atdna(metaforce-old atdna_InformationCenter.cpp InformationCenter.hpp) +target_atdna(metaforce-old atdna_GameMode.cpp GameMode.hpp) + +if(COMMAND add_sanitizers) + add_sanitizers(metaforce-old) +endif() if (NOT WINDOWS_STORE) - if(APPLE) - add_custom_command(TARGET urde-old POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $) - add_custom_command(TARGET urde-old POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $) - endif() - add_dependencies(urde-old visigen hecl) + add_dependencies(metaforce-old visigen hecl) else() - set_property(TARGET urde-old PROPERTY VS_WINRT_COMPONENT TRUE) + set_property(TARGET metaforce-old PROPERTY VS_WINRT_COMPONENT TRUE) # This should match the Package.appxmanifest - set_property(TARGET urde-old PROPERTY VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION "10.0.14393.0") + set_property(TARGET metaforce-old PROPERTY VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION "10.0.14393.0") endif() diff --git a/Editor/Camera.hpp b/Editor/Camera.hpp index 0a7b78468..9942cfb79 100644 --- a/Editor/Camera.hpp +++ b/Editor/Camera.hpp @@ -6,7 +6,7 @@ #include "zeus/CVector3f.hpp" #include "zeus/Math.hpp" -namespace urde { +namespace metaforce { class Camera { zeus::CFrustum m_frustum; zeus::CProjection m_projection; @@ -22,4 +22,4 @@ public: virtual void think() {} }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/GameMode.cpp b/Editor/GameMode.cpp index b216c4505..dfeda37cf 100644 --- a/Editor/GameMode.cpp +++ b/Editor/GameMode.cpp @@ -1,6 +1,6 @@ #include "GameMode.hpp" -namespace urde { +namespace metaforce { void GameMode::think() { ViewerSpace::think(); } void GameMode::View::draw(boo::IGraphicsCommandQueue* gfxQ) { @@ -8,4 +8,4 @@ void GameMode::View::draw(boo::IGraphicsCommandQueue* gfxQ) { m_gMode.m_main->Draw(); } -} // namespace urde +} // namespace metaforce diff --git a/Editor/GameMode.hpp b/Editor/GameMode.hpp index 545831ce7..b5ab29ddc 100644 --- a/Editor/GameMode.hpp +++ b/Editor/GameMode.hpp @@ -4,7 +4,7 @@ #include "ViewManager.hpp" #include "Runtime/IMain.hpp" -namespace urde { +namespace metaforce { class GameMode : public ViewerSpace { std::shared_ptr m_main; @@ -51,4 +51,4 @@ public: bool usesToolbar() const override { return m_state.showToolbar; } }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/InformationCenter.cpp b/Editor/InformationCenter.cpp index 1193a814a..3a2d69cfc 100644 --- a/Editor/InformationCenter.cpp +++ b/Editor/InformationCenter.cpp @@ -1,3 +1,3 @@ #include "InformationCenter.hpp" -namespace urde {} +namespace metaforce {} diff --git a/Editor/InformationCenter.hpp b/Editor/InformationCenter.hpp index a59767c5f..733d55fc0 100644 --- a/Editor/InformationCenter.hpp +++ b/Editor/InformationCenter.hpp @@ -3,7 +3,7 @@ #include "Space.hpp" #include "ViewManager.hpp" -namespace urde { +namespace metaforce { class InformationCenter : public ViewerSpace { struct State : Space::State { AT_DECL_DNA_YAMLV @@ -47,4 +47,4 @@ public: bool usesToolbar() const override { return true; } }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/ModelViewer.cpp b/Editor/ModelViewer.cpp index bb29fc736..41f83237d 100644 --- a/Editor/ModelViewer.cpp +++ b/Editor/ModelViewer.cpp @@ -1,10 +1,10 @@ #include "ModelViewer.hpp" -namespace urde { +namespace metaforce { void ModelViewer::View::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub) { specter::View::resized(root, sub); m_scissorRect = sub; } -} // namespace urde +} // namespace metaforce diff --git a/Editor/ModelViewer.hpp b/Editor/ModelViewer.hpp index 4d7c3a5be..fe993ebfa 100644 --- a/Editor/ModelViewer.hpp +++ b/Editor/ModelViewer.hpp @@ -4,7 +4,7 @@ #include "ViewManager.hpp" #include "Camera.hpp" -namespace urde { +namespace metaforce { class ModelViewer : public ViewerSpace { struct State : Space::State { AT_DECL_DNA_YAMLV @@ -17,7 +17,7 @@ class ModelViewer : public ViewerSpace { } m_state; const Space::State& spaceState() const override { return m_state; } - std::unique_ptr m_lineRenderer; + std::unique_ptr m_lineRenderer; struct View : specter::View { ModelViewer& m_mv; boo::SWindowRect m_scissorRect; @@ -33,7 +33,7 @@ class ModelViewer : public ViewerSpace { public: ModelViewer(ViewManager& vm, Space* parent) : ViewerSpace(vm, Class::ModelViewer, parent) { reloadState(); - m_lineRenderer.reset(new urde::CLineRenderer(urde::CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true)); + m_lineRenderer.reset(new metaforce::CLineRenderer(metaforce::CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true)); } ModelViewer(ViewManager& vm, Space* parent, const ModelViewer& other) : ModelViewer(vm, parent) { @@ -61,4 +61,4 @@ public: bool usesToolbar() const override { return true; } }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/ParticleEditor.cpp b/Editor/ParticleEditor.cpp index 06e8b04fe..5188d18e2 100644 --- a/Editor/ParticleEditor.cpp +++ b/Editor/ParticleEditor.cpp @@ -1,3 +1,3 @@ #include "ParticleEditor.hpp" -namespace urde {} +namespace metaforce {} diff --git a/Editor/ParticleEditor.hpp b/Editor/ParticleEditor.hpp index 0df827632..58280f8cb 100644 --- a/Editor/ParticleEditor.hpp +++ b/Editor/ParticleEditor.hpp @@ -2,7 +2,7 @@ #include "Space.hpp" -namespace urde { +namespace metaforce { class EffectEditor : public EditorSpace { struct State : Space::State { @@ -29,4 +29,4 @@ public: bool usesToolbar() const override { return true; } }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/ProjectManager.cpp b/Editor/ProjectManager.cpp index 90ab66886..1d0de2a23 100644 --- a/Editor/ProjectManager.cpp +++ b/Editor/ProjectManager.cpp @@ -2,8 +2,9 @@ #include "ViewManager.hpp" #include "DataSpecRegistry.hpp" #include "hecl/Blender/Connection.hpp" +#include "version.h" -namespace urde { +namespace metaforce { static logvisor::Module Log("URDE::ProjectManager"); ProjectManager* ProjectManager::g_SharedManager = nullptr; @@ -63,8 +64,8 @@ bool ProjectManager::newProject(hecl::SystemStringView path) { m_vm.SetupEditorView(); saveProject(); - m_vm.m_mainWindow->setTitle(fmt::format(FMT_STRING(_SYS_STR("{} - URDE [{}]")), - m_proj->getProjectRootPath().getLastComponent(), m_vm.platformName())); + m_vm.m_mainWindow->setTitle(fmt::format(FMT_STRING(_SYS_STR("{} - Metaforce {} [{}]")), + m_proj->getProjectRootPath().getLastComponent(), METAFORCE_WC_DESCRIBE_SYS, m_vm.platformName())); m_vm.DismissSplash(); m_vm.FadeInEditors(); @@ -72,6 +73,7 @@ bool ProjectManager::newProject(hecl::SystemStringView path) { } bool ProjectManager::openProject(hecl::SystemStringView path) { + OPTICK_EVENT(); hecl::SystemString subPath; hecl::ProjectRootPath projPath = hecl::SearchForProject(path, subPath); if (!projPath) { @@ -103,16 +105,17 @@ bool ProjectManager::openProject(hecl::SystemStringView path) { if (needsSave) saveProject(); - m_vm.m_mainWindow->setTitle(fmt::format(FMT_STRING(_SYS_STR("{} - URDE [{}]")), - m_proj->getProjectRootPath().getLastComponent(), m_vm.platformName())); + m_vm.m_mainWindow->setTitle(fmt::format(FMT_STRING(_SYS_STR("{} - Metaforce {} [{}]")), + m_proj->getProjectRootPath().getLastComponent(), METAFORCE_WC_DESCRIBE_SYS, + m_vm.platformName())); m_vm.DismissSplash(); m_vm.FadeInEditors(); m_vm.pushRecentProject(m_proj->getProjectRootPath().getAbsolutePath()); return true; }; - const hecl::ProjectPath urdeSpacesPath(*m_proj, _SYS_STR(".hecl/urde_spaces.yaml")); - athena::io::FileReader reader(urdeSpacesPath.getAbsolutePath()); + const hecl::ProjectPath metaforceSpacesPath(*m_proj, _SYS_STR(".hecl/metaforce_spaces.yaml")); + athena::io::FileReader reader(metaforceSpacesPath.getAbsolutePath()); if (!reader.isOpen()) { return makeProj(true); @@ -124,7 +127,7 @@ bool ProjectManager::openProject(hecl::SystemStringView path) { }; yaml_parser_set_input(r.getParser(), readHandler, &reader); - if (!r.ValidateClassType("UrdeSpacesState")) { + if (!r.ValidateClassType("MetaforceSpacesState")) { return makeProj(true); } @@ -143,7 +146,7 @@ bool ProjectManager::saveProject() { if (!m_proj) return false; - hecl::ProjectPath oldSpacesPath(*m_proj, _SYS_STR(".hecl/~urde_spaces.yaml")); + hecl::ProjectPath oldSpacesPath(*m_proj, _SYS_STR(".hecl/~metaforce_spaces.yaml")); athena::io::FileWriter writer(oldSpacesPath.getAbsolutePath()); if (!writer.isOpen()) return false; @@ -153,7 +156,7 @@ bool ProjectManager::saveProject() { if (!w.finish(&writer)) return false; - hecl::ProjectPath newSpacesPath(*m_proj, _SYS_STR(".hecl/urde_spaces.yaml")); + hecl::ProjectPath newSpacesPath(*m_proj, _SYS_STR(".hecl/metaforce_spaces.yaml")); hecl::Unlink(newSpacesPath.getAbsolutePath().data()); hecl::Rename(oldSpacesPath.getAbsolutePath().data(), newSpacesPath.getAbsolutePath().data()); @@ -164,6 +167,7 @@ bool ProjectManager::saveProject() { } void ProjectManager::mainUpdate() { + OPTICK_EVENT(); if (m_precooking) { if (!m_factoryMP1.IsBusy()) m_precooking = false; @@ -195,4 +199,4 @@ void ProjectManager::shutdown() { hecl::blender::Connection::Shutdown(); } -} // namespace urde +} // namespace metaforce diff --git a/Editor/ProjectManager.hpp b/Editor/ProjectManager.hpp index 2b092ba07..458b3ad71 100644 --- a/Editor/ProjectManager.hpp +++ b/Editor/ProjectManager.hpp @@ -7,7 +7,7 @@ #include "hecl/Runtime.hpp" #include "MP1/MP1.hpp" -namespace urde { +namespace metaforce { class ViewManager; using ConfigReader = athena::io::YAMLDocReader; @@ -55,4 +55,4 @@ public: void shutdown(); }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/ProjectResourceFactoryBase.cpp b/Editor/ProjectResourceFactoryBase.cpp index 5bf32e6ea..0b10f40e9 100644 --- a/Editor/ProjectResourceFactoryBase.cpp +++ b/Editor/ProjectResourceFactoryBase.cpp @@ -7,8 +7,8 @@ #undef min #undef max -namespace urde { -static logvisor::Module Log("urde::ProjectResourceFactoryBase"); +namespace metaforce { +static logvisor::Module Log("metaforce::ProjectResourceFactoryBase"); void ProjectResourceFactoryBase::BeginBackgroundIndex(hecl::Database::Project& proj, const hecl::Database::DataSpecEntry& origSpec, @@ -47,7 +47,7 @@ CFactoryFnReturn ProjectResourceFactoryBase::BuildSync(const SObjectTag& tag, co return ret; } -void ProjectResourceFactoryBase::AsyncTask::EnsurePath(const urde::SObjectTag& tag, const hecl::ProjectPath& path) { +void ProjectResourceFactoryBase::AsyncTask::EnsurePath(const metaforce::SObjectTag& tag, const hecl::ProjectPath& path) { if (!m_workingPath) { m_workingPath = path; @@ -64,7 +64,7 @@ void ProjectResourceFactoryBase::AsyncTask::EnsurePath(const urde::SObjectTag& t m_cookedPath = path.getCookedPath(*m_parent.m_origSpec); if (!m_cookedPath.isFile() || m_cookedPath.getModtime() < path.getModtime()) { /* Last chance type validation */ - urde::SObjectTag verifyTag = m_parent.TagFromPath(path); + metaforce::SObjectTag verifyTag = m_parent.TagFromPath(path); if (verifyTag.type != tag.type) { Log.report(logvisor::Error, FMT_STRING(_SYS_STR("{}: expected type '{}', found '{}'")), path.getRelativePath(), tag.type, verifyTag.type); @@ -181,7 +181,7 @@ bool ProjectResourceFactoryBase::PrepForReadSync(const SObjectTag& tag, const he cooked = path.getCookedPath(*m_origSpec); if (!cooked.isFile() || cooked.getModtime() < path.getModtime()) { /* Last chance type validation */ - urde::SObjectTag verifyTag = TagFromPath(path); + metaforce::SObjectTag verifyTag = TagFromPath(path); if (verifyTag.type != tag.type) { Log.report(logvisor::Error, FMT_STRING(_SYS_STR("{}: expected type '{}', found '{}'")), path.getRelativePath(), tag.type, verifyTag.type); @@ -211,8 +211,8 @@ bool ProjectResourceFactoryBase::PrepForReadSync(const SObjectTag& tag, const he return true; } -std::unique_ptr ProjectResourceFactoryBase::Build(const urde::SObjectTag& tag, - const urde::CVParamTransfer& paramXfer, +std::unique_ptr ProjectResourceFactoryBase::Build(const metaforce::SObjectTag& tag, + const metaforce::CVParamTransfer& paramXfer, CObjectReference* selfRef) { if (!tag.id.IsValid()) Log.report(logvisor::Fatal, FMT_STRING("attempted to access null id on type '{}'"), tag.type); @@ -261,17 +261,17 @@ std::unique_ptr ProjectResourceFactoryBase::Build(const urde::SObjec return BuildSync(tag, *resPath, paramXfer, selfRef); } -std::shared_ptr ProjectResourceFactoryBase::BuildAsyncInternal(const urde::SObjectTag& tag, - const urde::CVParamTransfer& paramXfer, - std::unique_ptr* objOut, +std::shared_ptr ProjectResourceFactoryBase::BuildAsyncInternal(const metaforce::SObjectTag& tag, + const metaforce::CVParamTransfer& paramXfer, + std::unique_ptr* objOut, CObjectReference* selfRef) { if (m_asyncLoadMap.find(tag) != m_asyncLoadMap.end()) return {}; return _AddTask(std::make_unique(*this, tag, objOut, paramXfer, selfRef)); } -void ProjectResourceFactoryBase::BuildAsync(const urde::SObjectTag& tag, const urde::CVParamTransfer& paramXfer, - std::unique_ptr* objOut, CObjectReference* selfRef) { +void ProjectResourceFactoryBase::BuildAsync(const metaforce::SObjectTag& tag, const metaforce::CVParamTransfer& paramXfer, + std::unique_ptr* objOut, CObjectReference* selfRef) { if (!tag.id.IsValid()) Log.report(logvisor::Fatal, FMT_STRING("attempted to access null id on type '{}'"), tag.type); @@ -295,27 +295,27 @@ u32 ProjectResourceFactoryBase::ResourceSize(const SObjectTag& tag) { return fr->length(); } -std::shared_ptr ProjectResourceFactoryBase::LoadResourceAsync(const urde::SObjectTag& tag, +std::shared_ptr ProjectResourceFactoryBase::LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) { if (!tag.id.IsValid()) Log.report(logvisor::Fatal, FMT_STRING("attempted to access null id")); if (m_asyncLoadMap.find(tag) != m_asyncLoadMap.end()) return {}; - return std::static_pointer_cast( + return std::static_pointer_cast( _AddTask(std::make_shared(*this, tag, reinterpret_cast(target)))); } -std::shared_ptr ProjectResourceFactoryBase::LoadResourcePartAsync(const urde::SObjectTag& tag, +std::shared_ptr ProjectResourceFactoryBase::LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size, void* target) { if (!tag.id.IsValid()) Log.report(logvisor::Fatal, FMT_STRING("attempted to access null id")); if (m_asyncLoadMap.find(tag) != m_asyncLoadMap.end()) return {}; - return std::static_pointer_cast( + return std::static_pointer_cast( _AddTask(std::make_shared(*this, tag, reinterpret_cast(target), size, off))); } -std::unique_ptr ProjectResourceFactoryBase::LoadResourceSync(const urde::SObjectTag& tag) { +std::unique_ptr ProjectResourceFactoryBase::LoadResourceSync(const metaforce::SObjectTag& tag) { if (!tag.id.IsValid()) Log.report(logvisor::Fatal, FMT_STRING("attempted to access null id")); @@ -332,7 +332,7 @@ std::unique_ptr ProjectResourceFactoryBase::LoadResourceSync(const urde::S return fr->readUBytes(fr->length()); } -std::unique_ptr ProjectResourceFactoryBase::LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, +std::unique_ptr ProjectResourceFactoryBase::LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) { if (!tag.id.IsValid()) Log.report(logvisor::Fatal, FMT_STRING("attempted to access null id")); @@ -352,7 +352,7 @@ std::unique_ptr ProjectResourceFactoryBase::LoadNewResourcePartSync(const return fr->readUBytes(sz); } -std::shared_ptr ProjectResourceFactoryBase::CookResourceAsync(const urde::SObjectTag& tag) { +std::shared_ptr ProjectResourceFactoryBase::CookResourceAsync(const metaforce::SObjectTag& tag) { if (!tag.id.IsValid()) Log.report(logvisor::Fatal, FMT_STRING("attempted to access null id")); if (m_asyncLoadMap.find(tag) != m_asyncLoadMap.end()) @@ -360,9 +360,9 @@ std::shared_ptr ProjectResourceFactoryBase::CookResourceAsync(const u return _AddTask(std::make_shared(*this, tag)); } -void ProjectResourceFactoryBase::CancelBuild(const urde::SObjectTag& tag) { _RemoveTask(tag); } +void ProjectResourceFactoryBase::CancelBuild(const metaforce::SObjectTag& tag) { _RemoveTask(tag); } -bool ProjectResourceFactoryBase::CanBuild(const urde::SObjectTag& tag) { +bool ProjectResourceFactoryBase::CanBuild(const metaforce::SObjectTag& tag) { if (!tag.id.IsValid()) Log.report(logvisor::Fatal, FMT_STRING("attempted to access null id")); @@ -376,7 +376,7 @@ bool ProjectResourceFactoryBase::CanBuild(const urde::SObjectTag& tag) { return false; } -const urde::SObjectTag* ProjectResourceFactoryBase::GetResourceIdByName(std::string_view name) const { +const metaforce::SObjectTag* ProjectResourceFactoryBase::GetResourceIdByName(std::string_view name) const { return static_cast(*m_cookSpec).getResourceIdByName(name); } @@ -464,4 +464,4 @@ void ProjectResourceFactoryBase::AsyncIdle() { } } -} // namespace urde +} // namespace metaforce diff --git a/Editor/ProjectResourceFactoryBase.hpp b/Editor/ProjectResourceFactoryBase.hpp index 7ed682067..208e3a8bb 100644 --- a/Editor/ProjectResourceFactoryBase.hpp +++ b/Editor/ProjectResourceFactoryBase.hpp @@ -16,14 +16,14 @@ #include #include -namespace urde { +namespace metaforce { class ProjectResourceFactoryBase : public IFactory { friend class ProjectResourcePool; hecl::ClientProcess& m_clientProc; public: - struct AsyncTask : urde::IDvdRequest { + struct AsyncTask : metaforce::IDvdRequest { ProjectResourceFactoryBase& m_parent; SObjectTag x0_tag; @@ -63,7 +63,7 @@ public: /* Cook only */ AsyncTask(ProjectResourceFactoryBase& parent, const SObjectTag& tag) : m_parent(parent), x0_tag(tag) {} - void EnsurePath(const urde::SObjectTag& tag, const hecl::ProjectPath& path); + void EnsurePath(const metaforce::SObjectTag& tag, const hecl::ProjectPath& path); void CookComplete(); bool AsyncPump(); void WaitUntilComplete() override; @@ -78,7 +78,7 @@ protected: const hecl::Database::DataSpecEntry* m_pcSpec = nullptr; /* Used to resolve cooked paths */ std::unique_ptr m_cookSpec; - urde::CFactoryMgr m_factoryMgr; + metaforce::CFactoryMgr m_factoryMgr; std::list> m_asyncLoadList; std::unordered_map>::iterator> m_asyncLoadMap; @@ -98,7 +98,7 @@ protected: bool PrepForReadSync(const SObjectTag& tag, const hecl::ProjectPath& path, std::optional& fr); - bool WaitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectPath*& pathOut) { + bool WaitForTagReady(const metaforce::SObjectTag& tag, const hecl::ProjectPath*& pathOut) { return static_cast(*m_cookSpec).waitForTagReady(tag, pathOut); } SObjectTag TagFromPath(const hecl::ProjectPath& path) const { @@ -120,18 +120,18 @@ protected: bool SyncCook(const hecl::ProjectPath& working); CFactoryFnReturn BuildSync(const SObjectTag& tag, const hecl::ProjectPath& path, const CVParamTransfer& paramXfer, CObjectReference* selfRef); - std::shared_ptr BuildAsyncInternal(const urde::SObjectTag&, const urde::CVParamTransfer&, - std::unique_ptr*, CObjectReference* selfRef); + std::shared_ptr BuildAsyncInternal(const metaforce::SObjectTag&, const metaforce::CVParamTransfer&, + std::unique_ptr*, CObjectReference* selfRef); public: ProjectResourceFactoryBase(hecl::ClientProcess& clientProc) : m_clientProc(clientProc) {} - std::unique_ptr Build(const urde::SObjectTag&, const urde::CVParamTransfer&, + std::unique_ptr Build(const metaforce::SObjectTag&, const metaforce::CVParamTransfer&, CObjectReference* selfRef) override; - void BuildAsync(const urde::SObjectTag&, const urde::CVParamTransfer&, std::unique_ptr*, + void BuildAsync(const metaforce::SObjectTag&, const metaforce::CVParamTransfer&, std::unique_ptr*, CObjectReference* selfRef) override; - void CancelBuild(const urde::SObjectTag&) override; - bool CanBuild(const urde::SObjectTag&) override; - const urde::SObjectTag* GetResourceIdByName(std::string_view) const override; + void CancelBuild(const metaforce::SObjectTag&) override; + bool CanBuild(const metaforce::SObjectTag&) override; + const metaforce::SObjectTag* GetResourceIdByName(std::string_view) const override; FourCC GetResourceTypeById(CAssetId id) const override; hecl::ProjectPath GetCookedPath(const hecl::ProjectPath& working, bool pcTarget) const { return static_cast(*m_cookSpec).getCookedPath(working, pcTarget); @@ -141,13 +141,13 @@ public: void EnumerateNamedResources(const std::function& lambda) const override; u32 ResourceSize(const SObjectTag& tag) override; - std::shared_ptr LoadResourceAsync(const urde::SObjectTag& tag, void* target) override; - std::shared_ptr LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, + std::shared_ptr LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) override; + std::shared_ptr LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size, void* target) override; - std::unique_ptr LoadResourceSync(const urde::SObjectTag& tag) override; - std::unique_ptr LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size) override; + std::unique_ptr LoadResourceSync(const metaforce::SObjectTag& tag) override; + std::unique_ptr LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) override; - std::shared_ptr CookResourceAsync(const urde::SObjectTag& tag); + std::shared_ptr CookResourceAsync(const metaforce::SObjectTag& tag); template bool AsyncPumpTask(ItType& it); @@ -160,4 +160,4 @@ public: ~ProjectResourceFactoryBase() override { Shutdown(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/ProjectResourceFactoryMP1.cpp b/Editor/ProjectResourceFactoryMP1.cpp index 9b9d0a90a..e940a1345 100644 --- a/Editor/ProjectResourceFactoryMP1.cpp +++ b/Editor/ProjectResourceFactoryMP1.cpp @@ -43,7 +43,7 @@ extern hecl::Database::DataSpecEntry SpecEntMP1; extern hecl::Database::DataSpecEntry SpecEntMP1PC; } // namespace DataSpec -namespace urde { +namespace metaforce { ProjectResourceFactoryMP1::ProjectResourceFactoryMP1(hecl::ClientProcess& clientProc) : ProjectResourceFactoryBase(clientProc) { @@ -81,4 +81,4 @@ void ProjectResourceFactoryMP1::IndexMP1Resources(hecl::Database::Project& proj, BeginBackgroundIndex(proj, DataSpec::SpecEntMP1, DataSpec::SpecEntMP1PC); } -} // namespace urde +} // namespace metaforce diff --git a/Editor/ProjectResourceFactoryMP1.hpp b/Editor/ProjectResourceFactoryMP1.hpp index 8839ba0fb..be57121d3 100644 --- a/Editor/ProjectResourceFactoryMP1.hpp +++ b/Editor/ProjectResourceFactoryMP1.hpp @@ -3,7 +3,7 @@ #include "Editor/ProjectResourceFactoryBase.hpp" #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { class MP1OriginalIDs; class CSimplePool; @@ -13,4 +13,4 @@ public: void IndexMP1Resources(hecl::Database::Project& proj, CSimplePool& sp); }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/Resource.cpp b/Editor/Resource.cpp index 22c0318b6..e02d8ff7d 100644 --- a/Editor/Resource.cpp +++ b/Editor/Resource.cpp @@ -1,6 +1,6 @@ #include "Resource.hpp" -namespace urde { +namespace metaforce { Space::Class Resource::DeduceDefaultSpaceClass(const hecl::ProjectPath& path) { athena::io::FileReader r(path.getAbsolutePath(), 32 * 1024, false); @@ -9,4 +9,4 @@ Space::Class Resource::DeduceDefaultSpaceClass(const hecl::ProjectPath& path) { return Space::Class::None; } -} // namespace urde +} // namespace metaforce diff --git a/Editor/Resource.hpp b/Editor/Resource.hpp index 62ab31e45..5385e19b8 100644 --- a/Editor/Resource.hpp +++ b/Editor/Resource.hpp @@ -3,7 +3,7 @@ #include "hecl/Database.hpp" #include "Space.hpp" -namespace urde { +namespace metaforce { /** Combines a ProjectPath with actively used Space references * @@ -43,4 +43,4 @@ private: std::unique_ptr m_rootNode; }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/ResourceBrowser.cpp b/Editor/ResourceBrowser.cpp index 247d0ab7e..5ce3f99e2 100644 --- a/Editor/ResourceBrowser.cpp +++ b/Editor/ResourceBrowser.cpp @@ -1,6 +1,6 @@ #include "ResourceBrowser.hpp" -namespace urde { +namespace metaforce { #define BROWSER_MARGIN 8 bool ResourceBrowser::navigateToPath(const hecl::ProjectPath& pathIn) { @@ -67,4 +67,4 @@ void ResourceBrowser::View::resized(const boo::SWindowRect& root, const boo::SWi } void ResourceBrowser::View::draw(boo::IGraphicsCommandQueue* gfxQ) { m_resListing.m_view->draw(gfxQ); } -} // namespace urde +} // namespace metaforce diff --git a/Editor/ResourceBrowser.hpp b/Editor/ResourceBrowser.hpp index d405a9d77..bb3f24fee 100644 --- a/Editor/ResourceBrowser.hpp +++ b/Editor/ResourceBrowser.hpp @@ -5,7 +5,7 @@ #include "specter/PathButtons.hpp" #include "specter/Table.hpp" -namespace urde { +namespace metaforce { class ResourceBrowser : public Space, public specter::IPathButtonsBinding { struct State : Space::State { @@ -202,4 +202,4 @@ public: unsigned toolbarUnits() const override { return 2; } }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/Space.cpp b/Editor/Space.cpp index 1f1b02a42..213da9762 100644 --- a/Editor/Space.cpp +++ b/Editor/Space.cpp @@ -8,7 +8,7 @@ #include "icons/icons.hpp" #include "specter/Menu.hpp" -namespace urde { +namespace metaforce { static logvisor::Module Log("URDE::Space"); Space::Space(ViewManager& vm, Class cls, Space* parent) @@ -259,4 +259,4 @@ void Space::SpaceMenuNode::SubNode::activated(const boo::SWindowCoord& coord) { } } -} // namespace urde +} // namespace metaforce diff --git a/Editor/Space.hpp b/Editor/Space.hpp index a0ae82b0f..4f6b49aae 100644 --- a/Editor/Space.hpp +++ b/Editor/Space.hpp @@ -16,7 +16,7 @@ class ViewResources; class Toolbar; struct Icon; } // namespace specter -namespace urde { +namespace metaforce { class ViewManager; class RootSpace; class SplitSpace; @@ -172,6 +172,7 @@ public: } void think() override { + OPTICK_EVENT(); if (m_spaceTree) m_spaceTree->think(); } @@ -374,4 +375,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/SplashScreen.cpp b/Editor/SplashScreen.cpp index 712c92f9c..53fd21dda 100644 --- a/Editor/SplashScreen.cpp +++ b/Editor/SplashScreen.cpp @@ -2,7 +2,7 @@ #include "version.h" #include "badging/Badging.hpp" -namespace urde { +namespace metaforce { #define SPLASH_WIDTH 555 #define SPLASH_HEIGHT 300 @@ -33,19 +33,13 @@ SplashScreen::SplashScreen(ViewManager& vm, specter::ViewResources& res) , m_newProjBind(*this) , m_openProjBind(*this) , m_extractProjBind(*this) { - if (GIT_COMMIT_DATE[0] != '\0' && GIT_COMMIT_HASH[0] != '\0' && GIT_BRANCH[0] != '\0') { -#ifdef URDE_DLPACKAGE - if ((URDE_DLPACKAGE)[0]) - m_buildInfoStr = fmt::format(FMT_STRING("{}: {}\n{}: {}\n{}: {}"), vm.translate(), - URDE_DLPACKAGE, vm.translate(), GIT_COMMIT_HASH, - vm.translate(), GIT_COMMIT_DATE); - else -#endif - m_buildInfoStr = fmt::format(FMT_STRING("{}: {}\n{}: {}\n{}: {}"), vm.translate(), GIT_BRANCH, - vm.translate(), GIT_COMMIT_HASH, - vm.translate(), GIT_COMMIT_DATE); + if (METAFORCE_WC_DATE[0] != '\0' && METAFORCE_WC_REVISION[0] != '\0' && METAFORCE_WC_BRANCH[0] != '\0') { + m_buildInfoStr = fmt::format(FMT_STRING("{}: {}\n{}: {}\n{}: {}"), + vm.translate(), METAFORCE_WC_DESCRIBE, + vm.translate(), METAFORCE_WC_BRANCH, + vm.translate(), METAFORCE_WC_REVISION/*, + vm.translate(), METAFORCE_WC_DATE*/); } - m_openProjBind.m_openRecentMenuRoot.m_text = vm.translate(); m_textColorClear[3] = 0.0; } @@ -56,6 +50,7 @@ void SplashScreen::think() { m_fileBrowser.m_view.reset(); return; } + OPTICK_EVENT(); ModalWindow::think(); if (m_fileBrowser.m_view) @@ -274,4 +269,4 @@ void SplashScreen::draw(boo::IGraphicsCommandQueue* gfxQ) { m_fileBrowser.m_view->draw(gfxQ); } -} // namespace urde +} // namespace metaforce diff --git a/Editor/SplashScreen.hpp b/Editor/SplashScreen.hpp index dcad65705..69035656c 100644 --- a/Editor/SplashScreen.hpp +++ b/Editor/SplashScreen.hpp @@ -9,7 +9,7 @@ #include "ViewManager.hpp" -namespace urde { +namespace metaforce { static logvisor::Module Log("specter::SplashScreen"); class SplashScreen : public specter::ModalWindow { @@ -161,4 +161,4 @@ public: void draw(boo::IGraphicsCommandQueue* gfxQ) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index 553b2a88e..2a89052f8 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -16,13 +16,15 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/World/CPlayer.hpp" #include "hecl/Pipeline.hpp" +#include "version.h" #include +#include "optick.h" using YAMLNode = athena::io::YAMLNode; extern hecl::SystemString ExeDir; -namespace urde { +namespace metaforce { void ViewManager::InitMP1(MP1::CMain& main) { main.Init(m_fileStoreManager, &m_cvarManager, m_mainWindow.get(), m_voiceEngine.get(), *m_amuseAllocWrapper); @@ -38,7 +40,7 @@ void ViewManager::InitMP1(MP1::CMain& main) { void ViewManager::TestGameView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub) { specter::View::resized(root, sub); - urde::CGraphics::SetViewportResolution({sub.size[0], sub.size[1]}); + metaforce::CGraphics::SetViewportResolution({sub.size[0], sub.size[1]}); if (m_debugText) { boo::SWindowRect newSub = sub; newSub.location[1] = 5 * m_vm.m_viewResources.pixelFactor(); @@ -53,6 +55,7 @@ void ViewManager::TestGameView::draw(boo::IGraphicsCommandQueue* gfxQ) { } void ViewManager::TestGameView::think() { + OPTICK_EVENT(); if (!m_debugText) { m_debugText.reset(new specter::MultiLineTextView(m_vm.m_viewResources, *this, m_vm.m_viewResources.m_monoFont18)); boo::SWindowRect sub = subRect(); @@ -63,10 +66,13 @@ void ViewManager::TestGameView::think() { if (m_debugText) { std::string overlayText; if (g_StateManager) { - if (m_cvarCommons.m_debugOverlayShowFrameCounter->toBoolean()) + if (m_vm.m_cvarCommons.m_debugOverlayShowFrameCounter->toBoolean()) overlayText += fmt::format(FMT_STRING("Frame: {}\n"), g_StateManager->GetUpdateFrameIndex()); - if (m_cvarCommons.m_debugOverlayShowInGameTime->toBoolean()) { + if (m_vm.m_cvarCommons.m_debugOverlayShowFramerate->toBoolean()) + overlayText += fmt::format(FMT_STRING("FPS: {}\n"), metaforce::CGraphics::GetFPS()); + + if (m_vm.m_cvarCommons.m_debugOverlayShowInGameTime->toBoolean()) { double igt = g_GameState->GetTotalPlayTime(); u32 ms = u64(igt * 1000) % 1000; auto pt = std::div(igt, 3600); @@ -74,17 +80,31 @@ void ViewManager::TestGameView::think() { fmt::format(FMT_STRING("PlayTime: {:02d}:{:02d}:{:02d}.{:03d}\n"), pt.quot, pt.rem / 60, pt.rem % 60, ms); } - if (g_StateManager->Player() && m_cvarCommons.m_debugOverlayPlayerInfo->toBoolean()) { + if (g_StateManager->GetCurrentArea() != nullptr && m_vm.m_cvarCommons.m_debugOverlayShowRoomTimer->toBoolean()) { + double igt = g_GameState->GetTotalPlayTime(); + if (m_currentRoom != g_StateManager->GetCurrentArea()) { + m_currentRoom = static_cast(g_StateManager->GetCurrentArea()); + m_lastRoomTime = igt - m_currentRoomStart; + m_currentRoomStart = igt; + } + double currentRoomTime = igt - m_currentRoomStart; + u32 curFrames = std::round(u32(currentRoomTime * 60)); + u32 lastFrames = std::round(u32(m_lastRoomTime * 60)); + overlayText += fmt::format(FMT_STRING("Room Time:{:8.3f}/{:6d}| Last Room:{:8.3f}/{:6d}\n"), currentRoomTime, + curFrames, m_lastRoomTime, lastFrames); + } + + if (g_StateManager->Player() && m_vm.m_cvarCommons.m_debugOverlayPlayerInfo->toBoolean()) { const CPlayer& pl = g_StateManager->GetPlayer(); const zeus::CQuaternion plQ = zeus::CQuaternion(pl.GetTransform().getRotation().buildMatrix3f()); const zeus::CTransform camXf = g_StateManager->GetCameraManager()->GetCurrentCameraTransform(*g_StateManager); const zeus::CQuaternion camQ = zeus::CQuaternion(camXf.getRotation().buildMatrix3f()); overlayText += fmt::format(FMT_STRING("Player Position: x {}, y {}, z {}\n" - " Roll: {}, Pitch: {}, Yaw: {}\n" - " Momentum: x {}, y: {}, z: {}\n" - " Velocity: x {}, y: {}, z: {}\n" - "Camera Position: x {}, y {}, z {}\n" - " Roll: {}, Pitch: {}, Yaw: {}\n"), + " Roll: {}, Pitch: {}, Yaw: {}\n" + " Momentum: x {}, y: {}, z: {}\n" + " Velocity: x {}, y: {}, z: {}\n" + "Camera Position: x {}, y {}, z {}\n" + " Roll: {}, Pitch: {}, Yaw: {}\n"), pl.GetTranslation().x(), pl.GetTranslation().y(), pl.GetTranslation().z(), zeus::radToDeg(plQ.roll()), zeus::radToDeg(plQ.pitch()), zeus::radToDeg(plQ.yaw()), pl.GetMomentum().x(), pl.GetMomentum().y(), pl.GetMomentum().z(), @@ -92,16 +112,16 @@ void ViewManager::TestGameView::think() { camXf.origin.y(), camXf.origin.z(), zeus::radToDeg(camQ.roll()), zeus::radToDeg(camQ.pitch()), zeus::radToDeg(camQ.yaw())); } - if (m_cvarCommons.m_debugOverlayWorldInfo->toBoolean()) { + if (m_vm.m_cvarCommons.m_debugOverlayWorldInfo->toBoolean()) { TLockedToken tbl = g_SimplePool->GetObj({FOURCC('STRG'), g_StateManager->GetWorld()->IGetStringTableAssetId()}); - const urde::TAreaId aId = g_GameState->CurrentWorldState().GetCurrentAreaId(); + const metaforce::TAreaId aId = g_GameState->CurrentWorldState().GetCurrentAreaId(); overlayText += fmt::format(FMT_STRING("World: 0x{}{}, Area: {}\n"), g_GameState->CurrentWorldAssetId(), (tbl.IsLoaded() ? (" " + hecl::Char16ToUTF8(tbl->GetString(0))).c_str() : ""), aId); } - const urde::TAreaId aId = g_GameState->CurrentWorldState().GetCurrentAreaId(); - if (m_cvarCommons.m_debugOverlayAreaInfo->toBoolean() && g_StateManager->GetWorld() && + const metaforce::TAreaId aId = g_GameState->CurrentWorldState().GetCurrentAreaId(); + if (m_vm.m_cvarCommons.m_debugOverlayAreaInfo->toBoolean() && g_StateManager->GetWorld() && g_StateManager->GetWorld()->DoesAreaExist(aId)) { const auto& layerStates = g_GameState->CurrentWorldState().GetLayerState(); std::string layerBits; @@ -114,17 +134,17 @@ void ViewManager::TestGameView::think() { layerBits += "0"; } overlayText += fmt::format(FMT_STRING("Area AssetId: 0x{}, Total Objects: {}\n" - "Active Layer bits: {}\n"), + "Active Layer bits: {}\n"), g_StateManager->GetWorld()->GetArea(aId)->GetAreaAssetId(), g_StateManager->GetAllObjectList().size(), layerBits); } } - if (m_cvarCommons.m_debugOverlayShowRandomStats->toBoolean()) { - overlayText += fmt::format(FMT_STRING("CRandom16::Next calls: {}\n"), urde::CRandom16::GetNumNextCalls()); + if (m_vm.m_cvarCommons.m_debugOverlayShowRandomStats->toBoolean()) { + overlayText += fmt::format(FMT_STRING("CRandom16::Next calls: {}\n"), metaforce::CRandom16::GetNumNextCalls()); } - if (m_cvarCommons.m_debugOverlayShowResourceStats->toBoolean()) + if (m_vm.m_cvarCommons.m_debugOverlayShowResourceStats->toBoolean()) overlayText += fmt::format(FMT_STRING("Resource Objects: {}\n"), g_SimplePool->GetLiveObjects()); if (!overlayText.empty()) @@ -200,6 +220,7 @@ void ViewManager::DismissSplash() { ViewManager::ViewManager(hecl::Runtime::FileStoreManager& fileMgr, hecl::CVarManager& cvarMgr) : m_fileStoreManager(fileMgr) , m_cvarManager(cvarMgr) +, m_cvarCommons(cvarMgr) , m_projManager(*this) , m_fontCache(fileMgr) , m_locale(locale::SystemLocaleOrEnglish()) @@ -274,6 +295,9 @@ void ViewManager::init(boo::IApplication* app) { m_mainWindow = app->newWindow(_SYS_STR("URDE")); m_mainWindow->showWindow(); m_mainWindow->setWaitCursor(true); + if (m_cvarCommons.getFullscreen()) { + m_mainWindow->setFullscreen(true); + } float pixelFactor = m_mainWindow->getVirtualPixelFactor(); @@ -281,7 +305,8 @@ void ViewManager::init(boo::IApplication* app) { m_pipelineConv = hecl::NewPipelineConverter(m_mainBooFactory); hecl::conv = m_pipelineConv.get(); m_mainPlatformName = m_mainBooFactory->platformName(); - m_mainWindow->setTitle(fmt::format(FMT_STRING(_SYS_STR("URDE [{}]")), m_mainPlatformName)); + m_mainWindow->setTitle( + fmt::format(FMT_STRING(_SYS_STR("Metaforce {} [{}]")), METAFORCE_WC_DESCRIBE_SYS, m_mainPlatformName)); m_mainCommandQueue = m_mainWindow->getCommandQueue(); m_viewResources.init(m_mainBooFactory, &m_fontCache, &m_themeData, pixelFactor); InitializeIcons(m_viewResources); @@ -298,8 +323,13 @@ void ViewManager::init(boo::IApplication* app) { m_amuseAllocWrapper.emplace(*m_voiceEngine); for (const auto& arg : app->getArgs()) { + hecl::Sstat theStat; + if (!hecl::Stat((arg + _SYS_STR("/out")).c_str(), &theStat) && S_ISDIR(theStat.st_mode)) { + hecl::ProjectRootPath rootPath(arg); + hecl::Database::Project tmp(rootPath); // Force project creation + } if (m_deferedProject.empty() && hecl::SearchForProject(arg)) - m_deferedProject = arg; + m_deferedProject = arg + _SYS_STR("/out"); if (arg == _SYS_STR("--no-shader-warmup")) m_noShaderWarmup = true; else if (arg == _SYS_STR("--no-sound")) @@ -328,6 +358,7 @@ bool ViewManager::proc() { return false; if (m_updatePf) { + OPTICK_EVENT("m_updatePf"); m_viewResources.resetPixelFactor(m_reqPf); specter::RootView* root = SetupRootView(); if (m_rootSpace) @@ -340,8 +371,14 @@ bool ViewManager::proc() { m_updatePf = false; } - m_rootView->dispatchEvents(); - m_rootView->internalThink(); + { + OPTICK_EVENT("m_rootView->DispatchEvents"); + m_rootView->dispatchEvents(); + } + { + OPTICK_EVENT("m_rootView->internalThink"); + m_rootView->internalThink(); + } if (m_rootSpace) m_rootSpace->think(); if (m_splash) @@ -363,19 +400,24 @@ bool ViewManager::proc() { if (m_testGameView) m_testGameView->think(); - if (g_Renderer) - g_Renderer->BeginScene(); - m_rootView->draw(gfxQ); - if (g_Renderer) - g_Renderer->EndScene(); - gfxQ->execute(); + { + OPTICK_EVENT("Draw"); + if (g_Renderer) + g_Renderer->BeginScene(); + m_rootView->draw(gfxQ); + if (g_Renderer) + g_Renderer->EndScene(); + gfxQ->execute(); + } if (g_ResFactory) g_ResFactory->AsyncIdle(); #ifndef URDE_MSAN m_voiceEngine->pumpAndMixVoices(); #endif - if (!m_skipWait || !hecl::com_developer->toBoolean()) + if (!m_skipWait || !hecl::com_developer->toBoolean()) { + OPTICK_EVENT("waitForRetrace"); m_mainWindow->waitForRetrace(); + } CBooModel::ClearModelUniformCounters(); CGraphics::TickRenderTimings(); ++logvisor::FrameIndex; @@ -392,4 +434,4 @@ void ViewManager::stop() { m_fontCache.destroyAtlases(); } -} // namespace urde +} // namespace metaforce diff --git a/Editor/ViewManager.hpp b/Editor/ViewManager.hpp index d37a4213c..9533bb797 100644 --- a/Editor/ViewManager.hpp +++ b/Editor/ViewManager.hpp @@ -26,7 +26,7 @@ namespace hecl { class PipelineConverterBase; } -namespace urde { +namespace metaforce { class SplashScreen; class ViewManager final : public specter::IViewManager { @@ -38,6 +38,7 @@ class ViewManager final : public specter::IViewManager { std::shared_ptr m_mainWindow; hecl::Runtime::FileStoreManager& m_fileStoreManager; hecl::CVarManager& m_cvarManager; + hecl::CVarCommons m_cvarCommons; ProjectManager m_projManager; specter::FontCache m_fontCache; specter::DefaultThemeData m_themeData; @@ -58,11 +59,13 @@ class ViewManager final : public specter::IViewManager { class TestGameView : public specter::View { ViewManager& m_vm; std::unique_ptr m_debugText; - hecl::CVarCommons m_cvarCommons; + const void* m_currentRoom = nullptr; + double m_lastRoomTime = 0.f; + double m_currentRoomStart = 0.f; public: TestGameView(ViewManager& vm, specter::ViewResources& res, specter::View& parent, hecl::CVarManager& cvarMgr) - : View(res, parent), m_vm(vm), m_cvarCommons(cvarMgr) {} + : View(res, parent), m_vm(vm) {} void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub) override; void draw(boo::IGraphicsCommandQueue* gfxQ) override; void think() override; @@ -193,4 +196,4 @@ public: void deferOpenProject(const hecl::SystemString& path) { m_deferedProject = path; } }; -} // namespace urde +} // namespace metaforce diff --git a/Editor/badging/Badging.cpp b/Editor/badging/Badging.cpp index 45215a55a..8f4719626 100644 --- a/Editor/badging/Badging.cpp +++ b/Editor/badging/Badging.cpp @@ -7,7 +7,7 @@ extern "C" uint8_t URDE_BADGE[]; extern "C" size_t URDE_BADGE_SZ; -namespace urde { +namespace metaforce { static logvisor::Module Log("URDE::badging"); static specter::Icon g_BadgeIcon; @@ -42,4 +42,4 @@ void DestroyBadging() { g_BadgeIcon.m_tex.reset(); } specter::Icon& GetBadge() { return g_BadgeIcon; } -} // namespace urde +} // namespace metaforce diff --git a/Editor/badging/Badging.hpp b/Editor/badging/Badging.hpp index f7dd6b7e4..ff0b5d42a 100644 --- a/Editor/badging/Badging.hpp +++ b/Editor/badging/Badging.hpp @@ -2,12 +2,12 @@ #include "specter/ViewResources.hpp" -namespace urde { +namespace metaforce { void InitializeBadging(specter::ViewResources& viewRes); void DestroyBadging(); specter::Icon& GetBadge(); -} // namespace urde +} // namespace metaforce #ifndef BADGE_PHRASE #define BADGE_PHRASE "Prototype" diff --git a/Editor/badging/CMakeLists.txt b/Editor/badging/CMakeLists.txt index 043f47642..96e7ebf9d 100644 --- a/Editor/badging/CMakeLists.txt +++ b/Editor/badging/CMakeLists.txt @@ -13,22 +13,22 @@ target_include_directories(packbadge PRIVATE ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_D ################## # Add all targets to the build-tree export set -export(TARGETS packbadge FILE "${CMAKE_CURRENT_BINARY_DIR}/urde-packbadgeTargets.cmake") +export(TARGETS packbadge FILE "${CMAKE_CURRENT_BINARY_DIR}/metaforce-packbadgeTargets.cmake") # Export the package for use from the build-tree # (this registers the build-tree with a global CMake-registry) -export(PACKAGE urde-packbadge) +export(PACKAGE metaforce-packbadge) # Create the atdnaConfig.cmake # ... for the build tree -configure_file(urde-packbadgeConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/urde-packbadgeConfig.cmake" @ONLY) +configure_file(metaforce-packbadgeConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/metaforce-packbadgeConfig.cmake" @ONLY) # ... for the install tree -configure_file(urde-packbadgeConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/urde-packbadgeConfig.cmake" @ONLY) +configure_file(metaforce-packbadgeConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/metaforce-packbadgeConfig.cmake" @ONLY) # ... for both -configure_file(urde-packbadgeConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/urde-packbadgeConfigVersion.cmake" @ONLY) +configure_file(metaforce-packbadgeConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/metaforce-packbadgeConfigVersion.cmake" @ONLY) else() -find_package(urde-packbadge REQUIRED) +find_package(metaforce-packbadge REQUIRED) endif() add_custom_command(OUTPUT badge.bin COMMAND $ @@ -37,6 +37,6 @@ add_custom_command(OUTPUT badge.bin COMMAND $ MAIN_DEPENDENCY badge.png COMMENT "Generating badge.bin") bintoc(badge.cpp ${CMAKE_CURRENT_BINARY_DIR}/badge.bin URDE_BADGE) -add_library(UrdeBadging +add_library(MetaforceBadging badge.cpp badge.bin Badging.hpp Badging.cpp) diff --git a/Editor/badging/urde-packbadgeConfig.cmake.in b/Editor/badging/metaforce-packbadgeConfig.cmake.in similarity index 79% rename from Editor/badging/urde-packbadgeConfig.cmake.in rename to Editor/badging/metaforce-packbadgeConfig.cmake.in index 47f3b47ca..cb77a1e60 100644 --- a/Editor/badging/urde-packbadgeConfig.cmake.in +++ b/Editor/badging/metaforce-packbadgeConfig.cmake.in @@ -5,5 +5,5 @@ get_filename_component(PACKBADGE_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) # Our library dependencies (contains definitions for IMPORTED targets) if(NOT TARGET packbadge AND NOT packbadge_BINARY_DIR) - include("${PACKBADGE_CMAKE_DIR}/urde-packbadgeTargets.cmake") + include("${PACKBADGE_CMAKE_DIR}/metaforce-packbadgeTargets.cmake") endif() diff --git a/Editor/badging/urde-packbadgeConfigVersion.cmake.in b/Editor/badging/metaforce-packbadgeConfigVersion.cmake.in similarity index 100% rename from Editor/badging/urde-packbadgeConfigVersion.cmake.in rename to Editor/badging/metaforce-packbadgeConfigVersion.cmake.in diff --git a/Editor/icons/CMakeLists.txt b/Editor/icons/CMakeLists.txt index fe3eaad29..0e0d090bf 100644 --- a/Editor/icons/CMakeLists.txt +++ b/Editor/icons/CMakeLists.txt @@ -12,22 +12,22 @@ target_include_directories(packicons PRIVATE ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_D ################## # Add all targets to the build-tree export set -export(TARGETS packicons FILE "${CMAKE_CURRENT_BINARY_DIR}/urde-packiconsTargets.cmake") +export(TARGETS packicons FILE "${CMAKE_CURRENT_BINARY_DIR}/metaforce-packiconsTargets.cmake") # Export the package for use from the build-tree # (this registers the build-tree with a global CMake-registry) -export(PACKAGE urde-packicons) +export(PACKAGE metaforce-packicons) # Create the atdnaConfig.cmake # ... for the build tree -configure_file(urde-packiconsConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/urde-packiconsConfig.cmake" @ONLY) +configure_file(metaforce-packiconsConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/metaforce-packiconsConfig.cmake" @ONLY) # ... for the install tree -configure_file(urde-packiconsConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/urde-packiconsConfig.cmake" @ONLY) +configure_file(metaforce-packiconsConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/metaforce-packiconsConfig.cmake" @ONLY) # ... for both -configure_file(urde-packiconsConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/urde-packiconsConfigVersion.cmake" @ONLY) +configure_file(metaforce-packiconsConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/metaforce-packiconsConfigVersion.cmake" @ONLY) else() -find_package(urde-packicons REQUIRED) +find_package(metaforce-packicons REQUIRED) endif() unset(INKSCAPE_BIN CACHE) @@ -59,4 +59,4 @@ else() endif() bintoc(icons_dat.cpp ${CMAKE_CURRENT_BINARY_DIR}/icons.bin URDE_ICONS) -add_library(UrdeIcons icons.cpp icons.hpp icons.bin icons_dat.cpp) +add_library(MetaforceIcons icons.cpp icons.hpp icons.bin icons_dat.cpp) diff --git a/Editor/icons/icons.cpp b/Editor/icons/icons.cpp index 4701c20b5..e06fc6e6b 100644 --- a/Editor/icons/icons.cpp +++ b/Editor/icons/icons.cpp @@ -5,7 +5,7 @@ extern "C" uint8_t URDE_ICONS[]; extern "C" size_t URDE_ICONS_SZ; -namespace urde { +namespace metaforce { static logvisor::Module Log("URDE::icons"); specter::IconAtlas<8, 8> g_IconAtlas; @@ -91,4 +91,4 @@ specter::Icon& GetIcon(MonoIcon icon) { } } -} // namespace urde +} // namespace metaforce diff --git a/Editor/icons/icons.hpp b/Editor/icons/icons.hpp index f2ebd1a3b..b222a65af 100644 --- a/Editor/icons/icons.hpp +++ b/Editor/icons/icons.hpp @@ -3,7 +3,7 @@ #include "specter/Icon.hpp" #include "specter/ViewResources.hpp" -namespace urde { +namespace metaforce { void InitializeIcons(specter::ViewResources& viewRes); void DestroyIcons(); @@ -30,4 +30,4 @@ enum class MonoIcon { }; specter::Icon& GetIcon(MonoIcon icon); -} // namespace urde +} // namespace metaforce diff --git a/Editor/icons/urde-packiconsConfig.cmake.in b/Editor/icons/metaforce-packiconsConfig.cmake.in similarity index 79% rename from Editor/icons/urde-packiconsConfig.cmake.in rename to Editor/icons/metaforce-packiconsConfig.cmake.in index 1d3c7028e..89f7681e6 100644 --- a/Editor/icons/urde-packiconsConfig.cmake.in +++ b/Editor/icons/metaforce-packiconsConfig.cmake.in @@ -5,5 +5,5 @@ get_filename_component(PACKICONS_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) # Our library dependencies (contains definitions for IMPORTED targets) if(NOT TARGET packicons AND NOT packicons_BINARY_DIR) - include("${PACKICONS_CMAKE_DIR}/urde-packiconsTargets.cmake") + include("${PACKICONS_CMAKE_DIR}/metaforce-packiconsTargets.cmake") endif() diff --git a/Editor/icons/urde-packiconsConfigVersion.cmake.in b/Editor/icons/metaforce-packiconsConfigVersion.cmake.in similarity index 100% rename from Editor/icons/urde-packiconsConfigVersion.cmake.in rename to Editor/icons/metaforce-packiconsConfigVersion.cmake.in diff --git a/Editor/locale b/Editor/locale deleted file mode 160000 index 2b16c0902..000000000 --- a/Editor/locale +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2b16c090215130336b401bb5db9831dbc8db78fa diff --git a/Editor/locale/CMakeLists.txt b/Editor/locale/CMakeLists.txt new file mode 100644 index 000000000..15b48d8ff --- /dev/null +++ b/Editor/locale/CMakeLists.txt @@ -0,0 +1,15 @@ +#add_executable(genlocales genlocales.cpp) +#target_link_libraries(genlocales fmt athena-core) +# +#set(LOCALES_IN en_US.yaml en_GB.yaml ja_JP.yaml) +#set(LOCALES_OUT ${CMAKE_CURRENT_BINARY_DIR}/locales-inl.hpp) +#add_custom_command(OUTPUT ${LOCALES_OUT} COMMAND $ +# ARGS ${LOCALES_OUT} ${LOCALES_IN} +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +# DEPENDS genlocales ${LOCALES_IN}) + +add_library(UrdeLocales locales-inl.hpp locale.hpp locale.cpp) +target_link_libraries(UrdeLocales fmt) +target_include_directories(UrdeLocales PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +target_link_libraries(specter PUBLIC UrdeLocales) diff --git a/Editor/locale/en_GB.yaml b/Editor/locale/en_GB.yaml new file mode 100644 index 000000000..2b5a4cf0c --- /dev/null +++ b/Editor/locale/en_GB.yaml @@ -0,0 +1,3 @@ +name: "British English" +en_GB: + color: "Colour" diff --git a/Editor/locale/en_US.yaml b/Editor/locale/en_US.yaml new file mode 100644 index 000000000..3e3871aaf --- /dev/null +++ b/Editor/locale/en_US.yaml @@ -0,0 +1,42 @@ +name: "US English" +en_US: + color: "Color" + branch: "Branch" + commit: "Commit" + release: "Release" + date: "Date" + new_project: "New Project" + open_project: "Open Project" + extract_game: "Extract Game" + name: "Name" + type: "Type" + size: "Size" + directory: "Directory" + file: "File" + file_name: "File Name" + cancel: "Cancel" + system_locations: "System Locations" + recent_projects: "Recent Projects" + recent_files: "Recent Files" + scroll_left: "Scroll Left" + scroll_right: "Scroll Right" + ok: "OK" + cancel: "Cancel" + boundary_action: "Boundary Action" + split: "Split" + join: "Join" + hecl_project: "HECL Project" + no_access_as_dir: "Unable to access '{}' as directory" + file_field_empty: "Unable to save empty file" + overwrite_confirm: "Overwrite '{}'?" + directory_field_empty: "Unable to make empty-named directory" + no_overwrite_file: "Unable to make directory over file" + no_overwrite_project: "Unable to make project within existing project" + no_access_as_file: "Unable to access '{}' as file" + space_types: "Space Types" + resource_browser: "Resource Browser" + effect_editor: "Effect Editor" + model_viewer: "Model Viewer" + information_center: "Information Center" + game_mode: "Game Mode" + version: "Version" \ No newline at end of file diff --git a/Editor/locale/genlocales.cpp b/Editor/locale/genlocales.cpp new file mode 100644 index 000000000..36bad71dd --- /dev/null +++ b/Editor/locale/genlocales.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include "athena/FileReader.hpp" +#include "athena/YAMLDocReader.hpp" + +#include +#include + +int main(int argc, char** argv) { + if (argc < 3) { + fmt::print(FMT_STRING("{} ...\n"), argv[0]); + return 1; + } + + std::ofstream out(argv[1]); + if (!out.is_open()) { + fmt::print(FMT_STRING("Unable to open {} for writing\n"), argv[1]); + return 1; + } + + std::unordered_set seenLocales; + std::stringstream enumLocales; + std::stringstream declLocales; + std::unordered_set seenKeys; + std::stringstream keys; + std::stringstream lookups; + std::stringstream dos; + + for (int i = 2; i < argc; ++i) { + athena::io::FileReader fr(argv[i]); + if (!fr.isOpen()) { + fmt::print(FMT_STRING("Unable to open {} for reading\n"), argv[i]); + return 1; + } + athena::io::YAMLDocReader r; + if (!r.parse(&fr)) { + fmt::print(FMT_STRING("Unable to parse {}\n"), argv[i]); + return 1; + } + + std::string name; + std::string fullName; + athena::io::YAMLNode* listNode = nullptr; + for (const auto& c : r.getRootNode()->m_mapChildren) { + if (c.first == "name") { + fullName = c.second->m_scalarString; + } else { + name = c.first; + listNode = c.second.get(); + } + } + if (fullName.empty()) { + fmt::print(FMT_STRING("Unable to find 'name' node in {}\n"), argv[i]); + return 1; + } + if (!listNode) { + fmt::print(FMT_STRING("Unable to find list node in {}\n"), argv[i]); + return 1; + } + + if (seenLocales.find(name) == seenLocales.end()) { + seenLocales.insert(name); + fmt::print(enumLocales, FMT_STRING(" {},\n"), name); + fmt::print(declLocales, + FMT_STRING("struct {0} {{ static constexpr auto Name = \"{0}\"sv; static constexpr auto FullName = \"{1}\"sv; }};\n"), + name, fullName); + fmt::print(dos, + FMT_STRING(" case ELocale::{0}:\n" + " return act.template Do<{0}>(std::forward(args)...);\n"), name); + fmt::print(lookups, FMT_STRING("/* {} */\n"), name); + for (const auto& k : listNode->m_mapChildren) { + if (seenKeys.find(k.first) == seenKeys.end()) { + seenKeys.insert(k.first); + fmt::print(keys, FMT_STRING("struct {} {{}};\n"), k.first); + } + fmt::print(lookups, + FMT_STRING("template<> struct Lookup<{}, {}> {{ static constexpr auto Value() {{ return FMT_STRING(\"{}\"); }} }};\n"), + name, k.first, k.second->m_scalarString); + } + } + lookups << '\n'; + } + + out << "/* Locales */\n" + "enum class ELocale {\n" + " Invalid = -1,\n"; + out << enumLocales.str(); + out << " MAXLocale\n" + "};\n"; + out << declLocales.str(); + out << "\n" + "using DefaultLocale = en_US;\n" + "template struct Lookup {\n" + " static_assert(!std::is_same_v, \"The default locale must translate all keys\");\n" + " static constexpr auto Value() { return Lookup::Value(); }\n" + "};\n" + "\n" + "/* Keys */\n"; + out << keys.str(); + out << "\n"; + out << lookups.str(); + out << "template \n" + "constexpr auto Do(ELocale l, Action act, Args&&... args) {\n" + " switch (l) {\n" + " default:\n"; + out << dos.str(); + out << " }\n" + "}\n"; + + return 0; +} diff --git a/Editor/locale/ja_JP.yaml b/Editor/locale/ja_JP.yaml new file mode 100644 index 000000000..847736741 --- /dev/null +++ b/Editor/locale/ja_JP.yaml @@ -0,0 +1,19 @@ +name: "日本語" +ja_JP: + color: "色" + branch: "分派" + commit: "預ける" + date: "年月日" + new_project: "新しいプロジェクト" + open_project: "プロジェクトを開きます" + extract_game: "ビデオゲームを抽出" + name: "名" + type: "タイプ" + size: "サイズ" + directory: "ディレクトリ" + file: "ファイル" + file_name: "ファイル名" + cancel: "キャンセル" + system_locations: "システムの場所" + recent_projects: "最近使ったプロジェクト" + recent_files: "最近使用したファイル" diff --git a/Editor/locale/locale.cpp b/Editor/locale/locale.cpp new file mode 100644 index 000000000..ff6d0bb34 --- /dev/null +++ b/Editor/locale/locale.cpp @@ -0,0 +1,37 @@ +#include "locale.hpp" +#include +#include +#include + +#undef min +#undef max + +namespace locale { + +std::vector> ListLocales() { + std::vector> ret; + ret.reserve(std::size_t(ELocale::MAXLocale)); + for (ELocale l = ELocale(0); l < ELocale::MAXLocale; l = ELocale(int(l) + 1)) + ret.emplace_back(GetName(l), GetFullName(l)); + return ret; +} + +ELocale LookupLocale(std::string_view name) { + for (ELocale l = ELocale(0); l < ELocale::MAXLocale; l = ELocale(int(l) + 1)) + if (name == GetName(l)) + return l; + return ELocale::Invalid; +} + +ELocale SystemLocaleOrEnglish() { + const char* sysLocale = std::setlocale(LC_ALL, nullptr); + size_t sysLocaleLen = std::strlen(sysLocale); + for (ELocale l = ELocale(0); l < ELocale::MAXLocale; l = ELocale(int(l) + 1)) { + auto name = GetName(l); + if (!name.compare(0, std::min(name.size(), sysLocaleLen), sysLocale)) + return l; + } + return ELocale::en_US; +} + +} // namespace locale diff --git a/Editor/locale/locale.hpp b/Editor/locale/locale.hpp new file mode 100644 index 000000000..86d4aad7e --- /dev/null +++ b/Editor/locale/locale.hpp @@ -0,0 +1,42 @@ +#pragma once +#include +#include +#include + +#include + +namespace locale { +using namespace std::literals; +#include + +struct DoGetName { + template + constexpr auto Do() { return L::Name; } +}; +constexpr auto GetName(ELocale l) { + return Do(l, DoGetName()); +} + +struct DoGetFullName { + template + constexpr auto Do() { return L::FullName; } +}; +constexpr auto GetFullName(ELocale l) { + return Do(l, DoGetFullName()); +} + +template +struct DoTranslate { + template + constexpr auto Do(Args&&... args) { return fmt::format(Lookup::Value(), std::forward(args)...); } +}; +template +constexpr auto Translate(ELocale l, Args&&... args) { + return Do(l, DoTranslate(), std::forward(args)...); +} + +std::vector> ListLocales(); +ELocale LookupLocale(std::string_view name); +ELocale SystemLocaleOrEnglish(); + +} // namespace locale diff --git a/Editor/locale/locales-inl.hpp b/Editor/locale/locales-inl.hpp new file mode 100644 index 000000000..d67ea09bf --- /dev/null +++ b/Editor/locale/locales-inl.hpp @@ -0,0 +1,134 @@ +/* Locales */ +enum class ELocale { + Invalid = -1, + en_US, + en_GB, + ja_JP, + MAXLocale +}; +struct en_US { static constexpr auto Name = "en_US"sv; static constexpr auto FullName = "US English"sv; }; +struct en_GB { static constexpr auto Name = "en_GB"sv; static constexpr auto FullName = "British English"sv; }; +struct ja_JP { static constexpr auto Name = "ja_JP"sv; static constexpr auto FullName = "日本語"sv; }; + +using DefaultLocale = en_US; +template struct Lookup { + static_assert(!std::is_same_v, "The default locale must translate all keys"); + static constexpr auto Value() { return Lookup::Value(); } +}; + +/* Keys */ +struct color {}; +struct branch {}; +struct commit {}; +struct release {}; +struct date {}; +struct new_project {}; +struct open_project {}; +struct extract_game {}; +struct name {}; +struct type {}; +struct size {}; +struct directory {}; +struct file {}; +struct file_name {}; +struct cancel {}; +struct system_locations {}; +struct recent_projects {}; +struct recent_files {}; +struct scroll_left {}; +struct scroll_right {}; +struct ok {}; +struct boundary_action {}; +struct split {}; +struct join {}; +struct hecl_project {}; +struct no_access_as_dir {}; +struct file_field_empty {}; +struct overwrite_confirm {}; +struct directory_field_empty {}; +struct no_overwrite_file {}; +struct no_overwrite_project {}; +struct no_access_as_file {}; +struct space_types {}; +struct resource_browser {}; +struct effect_editor {}; +struct model_viewer {}; +struct information_center {}; +struct game_mode {}; +struct version {}; + +/* en_US */ +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Color"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Branch"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Commit"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Release"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Date"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("New Project"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Open Project"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Extract Game"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Name"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Type"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Size"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Directory"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("File"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("File Name"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Cancel"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("System Locations"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Recent Projects"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Recent Files"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Scroll Left"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Scroll Right"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("OK"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Boundary Action"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Split"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Join"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("HECL Project"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Unable to access '{}' as directory"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Unable to save empty file"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Overwrite '{}'?"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Unable to make empty-named directory"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Unable to make directory over file"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Unable to make project within existing project"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Unable to access '{}' as file"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Space Types"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Resource Browser"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Effect Editor"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Model Viewer"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Information Center"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Game Mode"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Version"); } }; + +/* en_GB */ +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("Colour"); } }; + +/* ja_JP */ +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("色"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("分派"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("預ける"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("年月日"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("新しいプロジェクト"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("プロジェクトを開きます"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("ビデオゲームを抽出"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("名"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("タイプ"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("サイズ"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("ディレクトリ"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("ファイル"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("ファイル名"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("キャンセル"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("システムの場所"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("最近使ったプロジェクト"); } }; +template<> struct Lookup { static constexpr auto Value() { return FMT_STRING("最近使用したファイル"); } }; + +template +constexpr auto Do(ELocale l, Action act, Args&&... args) { + switch (l) { + default: + case ELocale::en_US: + return act.template Do(std::forward(args)...); + case ELocale::en_GB: + return act.template Do(std::forward(args)...); + case ELocale::ja_JP: + return act.template Do(std::forward(args)...); + } +} diff --git a/Editor/main.cpp b/Editor/main.cpp index 02761ba96..980d12988 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -8,6 +8,8 @@ #include "hecl/CVarCommons.hpp" #include "hecl/Console.hpp" #include "fmt/chrono.h" +#include "version.h" +#include "optick.h" static logvisor::Module AthenaLog("Athena"); static void AthenaExc(athena::error::Level level, const char* file, const char*, int line, fmt::string_view fmt, @@ -15,11 +17,12 @@ static void AthenaExc(athena::error::Level level, const char* file, const char*, AthenaLog.vreport(logvisor::Level(level), fmt, args); } -namespace urde { -static logvisor::Module Log{"URDE"}; +namespace metaforce { +static logvisor::Module Log{"Metaforce"}; static hecl::SystemString CPUFeatureString(const zeus::CPUInfo& cpuInf) { hecl::SystemString features; +#if defined(__x86_64__) || defined(_M_X64) auto AddFeature = [&features](const hecl::SystemChar* str) { if (!features.empty()) features += _SYS_STR(", "); @@ -45,6 +48,7 @@ static hecl::SystemString CPUFeatureString(const zeus::CPUInfo& cpuInf) { AddFeature(_SYS_STR("AVX")); if (cpuInf.AVX2) AddFeature(_SYS_STR("AVX2")); +#endif return features; } @@ -68,6 +72,7 @@ struct Application : boo::IApplicationCallback { initialize(app); m_viewManager->init(app); while (m_running.load()) { + OPTICK_FRAME("MainThread"); if (!m_viewManager->proc()) break; } @@ -116,7 +121,7 @@ struct Application : boo::IApplicationCallback { int64_t getTargetFrameTime() { return m_cvarCommons.getVariableFrameTime() ? 0 : 1000000000L / 60; } }; -} // namespace urde +} // namespace metaforce static hecl::SystemChar CwdBuf[1024]; hecl::SystemString ExeDir; @@ -125,12 +130,12 @@ static void SetupBasics(bool logging) { auto result = zeus::validateCPU(); if (!result.first) { #if _WIN32 && !WINDOWS_STORE - std::wstring msg = fmt::format(FMT_STRING(L"ERROR: This build of URDE requires the following CPU features:\n{}\n"), - urde::CPUFeatureString(result.second)); + std::wstring msg = fmt::format(FMT_STRING(L"ERROR: This build of Metaforce requires the following CPU features:\n{}\n"), + metaforce::CPUFeatureString(result.second)); MessageBoxW(nullptr, msg.c_str(), L"CPU error", MB_OK | MB_ICONERROR); #else - fmt::print(stderr, FMT_STRING("ERROR: This build of URDE requires the following CPU features:\n{}\n"), - urde::CPUFeatureString(result.second)); + fmt::print(stderr, FMT_STRING("ERROR: This build of Metaforce requires the following CPU features:\n{}\n"), + metaforce::CPUFeatureString(result.second)); #endif exit(1); } @@ -139,6 +144,12 @@ static void SetupBasics(bool logging) { if (logging) logvisor::RegisterConsoleLogger(); atSetExceptionHandler(AthenaExc); + +#if SENTRY_ENABLED + hecl::Runtime::FileStoreManager fileMgr{_SYS_STR("sentry-native-metaforce")}; + hecl::SystemUTF8Conv cacheDir{fileMgr.getStoreRoot()}; + logvisor::RegisterSentry("metaforce", METAFORCE_WC_DESCRIBE, cacheDir.c_str()); +#endif } static bool IsClientLoggingEnabled(int argc, const boo::SystemChar** argv) { @@ -156,12 +167,12 @@ int main(int argc, const boo::SystemChar** argv) #endif { if (argc > 1 && !hecl::StrCmp(argv[1], _SYS_STR("--dlpackage"))) { - fmt::print(FMT_STRING("{}\n"), URDE_DLPACKAGE); + fmt::print(FMT_STRING("{}\n"), METAFORCE_DLPACKAGE); return 100; } SetupBasics(IsClientLoggingEnabled(argc, argv)); - hecl::Runtime::FileStoreManager fileMgr{_SYS_STR("urde")}; + hecl::Runtime::FileStoreManager fileMgr{_SYS_STR("metaforce")}; hecl::CVarManager cvarMgr{fileMgr}; hecl::CVarCommons cvarCmns{cvarMgr}; @@ -170,7 +181,7 @@ int main(int argc, const boo::SystemChar** argv) args.push_back(argv[i]); cvarMgr.parseCommandLine(args); - hecl::SystemStringView logFile = hecl::SystemStringConv(cvarCmns.getLogFile()).sys_str(); + hecl::SystemString logFile{hecl::SystemStringConv(cvarCmns.getLogFile()).c_str()}; hecl::SystemString logFilePath; if (!logFile.empty()) { std::time_t time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); @@ -193,10 +204,10 @@ int main(int argc, const boo::SystemChar** argv) /* Handle -j argument */ hecl::SetCpuCountOverride(argc, argv); - urde::Application appCb(fileMgr, cvarMgr, cvarCmns); - int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto, appCb, _SYS_STR("urde"), _SYS_STR("URDE"), argc, - argv, appCb.getGraphicsApi(), appCb.getSamples(), appCb.getAnisotropy(), - appCb.getDeepColor(), appCb.getTargetFrameTime(), false); + metaforce::Application appCb(fileMgr, cvarMgr, cvarCmns); + int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto, appCb, _SYS_STR("metaforce"), + _SYS_STR("Metaforce"), argc, argv, appCb.getGraphicsApi(), appCb.getSamples(), + appCb.getAnisotropy(), appCb.getDeepColor(), appCb.getTargetFrameTime(), false); // printf("IM DYING!!\n"); return ret; } @@ -208,9 +219,9 @@ using namespace Windows::ApplicationModel::Core; [Platform::MTAThread] int WINAPIV main(Platform::Array ^ params) { SetupBasics(false); - urde::Application appCb; + metaforce::Application appCb; auto viewProvider = - ref new boo::ViewProvider(appCb, _SYS_STR("urde"), _SYS_STR("URDE"), _SYS_STR("urde"), params, false); + ref new boo::ViewProvider(appCb, _SYS_STR("metaforce"), _SYS_STR("Metaforce"), _SYS_STR("metaforce"), params, false); CoreApplication::Run(viewProvider); return 0; } diff --git a/Editor/platforms/freedesktop/1024x1024/apps/urde.png b/Editor/platforms/freedesktop/1024x1024/apps/metaforce.png similarity index 100% rename from Editor/platforms/freedesktop/1024x1024/apps/urde.png rename to Editor/platforms/freedesktop/1024x1024/apps/metaforce.png diff --git a/Editor/platforms/freedesktop/128x128/apps/urde.png b/Editor/platforms/freedesktop/128x128/apps/metaforce.png similarity index 100% rename from Editor/platforms/freedesktop/128x128/apps/urde.png rename to Editor/platforms/freedesktop/128x128/apps/metaforce.png diff --git a/Editor/platforms/freedesktop/16x16/apps/urde.png b/Editor/platforms/freedesktop/16x16/apps/metaforce.png similarity index 100% rename from Editor/platforms/freedesktop/16x16/apps/urde.png rename to Editor/platforms/freedesktop/16x16/apps/metaforce.png diff --git a/Editor/platforms/freedesktop/256x256/apps/urde.png b/Editor/platforms/freedesktop/256x256/apps/metaforce.png similarity index 100% rename from Editor/platforms/freedesktop/256x256/apps/urde.png rename to Editor/platforms/freedesktop/256x256/apps/metaforce.png diff --git a/Editor/platforms/freedesktop/32x32/apps/urde.png b/Editor/platforms/freedesktop/32x32/apps/metaforce.png similarity index 100% rename from Editor/platforms/freedesktop/32x32/apps/urde.png rename to Editor/platforms/freedesktop/32x32/apps/metaforce.png diff --git a/Editor/platforms/freedesktop/48x48/apps/urde.png b/Editor/platforms/freedesktop/48x48/apps/metaforce.png similarity index 100% rename from Editor/platforms/freedesktop/48x48/apps/urde.png rename to Editor/platforms/freedesktop/48x48/apps/metaforce.png diff --git a/Editor/platforms/freedesktop/512x512/apps/urde.png b/Editor/platforms/freedesktop/512x512/apps/metaforce.png similarity index 100% rename from Editor/platforms/freedesktop/512x512/apps/urde.png rename to Editor/platforms/freedesktop/512x512/apps/metaforce.png diff --git a/Editor/platforms/freedesktop/64x64/apps/urde.png b/Editor/platforms/freedesktop/64x64/apps/metaforce.png similarity index 100% rename from Editor/platforms/freedesktop/64x64/apps/urde.png rename to Editor/platforms/freedesktop/64x64/apps/metaforce.png diff --git a/Editor/platforms/freedesktop/CMakeLists.txt b/Editor/platforms/freedesktop/CMakeLists.txt index ea3470e63..990fbf1cb 100644 --- a/Editor/platforms/freedesktop/CMakeLists.txt +++ b/Editor/platforms/freedesktop/CMakeLists.txt @@ -7,11 +7,11 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/Editor/platforms/freedesktop/maini COMMAND $ ARGS ${CMAKE_BINARY_DIR}/Editor/platforms/freedesktop/mainicon_netwm.bin DEPENDS - ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/128x128/apps/urde.png - ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/64x64/apps/urde.png - ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/48x48/apps/urde.png - ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/32x32/apps/urde.png - ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/16x16/apps/urde.png + ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/128x128/apps/metaforce.png + ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/64x64/apps/metaforce.png + ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/48x48/apps/metaforce.png + ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/32x32/apps/metaforce.png + ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop/16x16/apps/metaforce.png WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Editor/platforms/freedesktop COMMENT "Generating mainicon_netwm.bin") bintoc(mainicon_netwm.cpp ${CMAKE_BINARY_DIR}/Editor/platforms/freedesktop/mainicon_netwm.bin MAINICON_NETWM) diff --git a/Editor/platforms/freedesktop/mkwmicon.c b/Editor/platforms/freedesktop/mkwmicon.c index 49c0e5949..d3e0dd55c 100644 --- a/Editor/platforms/freedesktop/mkwmicon.c +++ b/Editor/platforms/freedesktop/mkwmicon.c @@ -49,7 +49,7 @@ int main(int argc, char* argv[]) printf("Rendering main icon @%dx%d\n", *d, *d); fflush(stdout); - snprintf(command, 2048, "%dx%d/apps/urde.png", *d, *d); + snprintf(command, 2048, "%dx%d/apps/metaforce.png", *d, *d); FILE* fp = fopen(command, "rb"); if (!fp) { diff --git a/Editor/platforms/freedesktop/urde.desktop b/Editor/platforms/freedesktop/urde.desktop index 6c084fadc..a79047f29 100644 --- a/Editor/platforms/freedesktop/urde.desktop +++ b/Editor/platforms/freedesktop/urde.desktop @@ -2,8 +2,8 @@ Name=URDE GenericName=Game Data Editor Comment=Edit 3D assets from games by Retro Studios -Exec=urde -Icon=urde +Exec=metaforce +Icon=metaforce Terminal=false Type=Application Categories=Graphics;3DGraphics; diff --git a/Editor/platforms/win/Assets/urde.scale-100.png b/Editor/platforms/win/Assets/metaforce.scale-100.png similarity index 100% rename from Editor/platforms/win/Assets/urde.scale-100.png rename to Editor/platforms/win/Assets/metaforce.scale-100.png diff --git a/Editor/platforms/win/Assets/urde.scale-125.png b/Editor/platforms/win/Assets/metaforce.scale-125.png similarity index 100% rename from Editor/platforms/win/Assets/urde.scale-125.png rename to Editor/platforms/win/Assets/metaforce.scale-125.png diff --git a/Editor/platforms/win/Assets/urde.scale-150.png b/Editor/platforms/win/Assets/metaforce.scale-150.png similarity index 100% rename from Editor/platforms/win/Assets/urde.scale-150.png rename to Editor/platforms/win/Assets/metaforce.scale-150.png diff --git a/Editor/platforms/win/Assets/urde.scale-200.png b/Editor/platforms/win/Assets/metaforce.scale-200.png similarity index 100% rename from Editor/platforms/win/Assets/urde.scale-200.png rename to Editor/platforms/win/Assets/metaforce.scale-200.png diff --git a/Editor/platforms/win/Assets/urde.scale-400.png b/Editor/platforms/win/Assets/metaforce.scale-400.png similarity index 100% rename from Editor/platforms/win/Assets/urde.scale-400.png rename to Editor/platforms/win/Assets/metaforce.scale-400.png diff --git a/Editor/platforms/win/Package.appxmanifest b/Editor/platforms/win/Package.appxmanifest index a1a723ccd..10d314de8 100644 --- a/Editor/platforms/win/Package.appxmanifest +++ b/Editor/platforms/win/Package.appxmanifest @@ -1,11 +1,11 @@  - + - URDE + Metaforce AxioDL - Assets\urde.png + Assets\metaforce.png @@ -15,7 +15,7 @@ - + diff --git a/Editor/platforms/win/urde.aps b/Editor/platforms/win/metaforce.aps similarity index 100% rename from Editor/platforms/win/urde.aps rename to Editor/platforms/win/metaforce.aps diff --git a/Editor/platforms/win/urde.manifest b/Editor/platforms/win/metaforce.manifest similarity index 100% rename from Editor/platforms/win/urde.manifest rename to Editor/platforms/win/metaforce.manifest diff --git a/Editor/platforms/win/metaforce.rc.in b/Editor/platforms/win/metaforce.rc.in new file mode 100644 index 000000000..9310d4336 --- /dev/null +++ b/Editor/platforms/win/metaforce.rc.in @@ -0,0 +1,33 @@ +#include "winver.h" +#define IDI_ICON1 101 + +IDI_ICON1 ICON DISCARDABLE "mainicon.ico" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,0 + PRODUCTVERSION 1,0,0,0 + FILEFLAGS 0x0L + FILEFLAGSMASK 0x3fL + FILEOS 0x00040004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "AxioDL" + VALUE "FileDescription", "Metaforce" + VALUE "FileVersion", "@METAFORCE_WC_DESCRIBE@" + VALUE "LegalCopyright", "Copyright (C) 2015-@CURRENT_YEAR@ AxioDL Team" + VALUE "InternalName", "metaforce" + VALUE "OriginalFilename", "metaforce.exe" + VALUE "ProductName", "Metaforce" + VALUE "ProductVersion", "@METAFORCE_WC_DESCRIBE@" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/Editor/platforms/win/urde.rc.in b/Editor/platforms/win/urde.rc.in deleted file mode 100644 index 1f22071c7..000000000 --- a/Editor/platforms/win/urde.rc.in +++ /dev/null @@ -1,33 +0,0 @@ -#include "winver.h" -#define IDI_ICON1 101 - -IDI_ICON1 ICON DISCARDABLE "mainicon.ico" - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,0 - PRODUCTVERSION 1,0,0,0 - FILEFLAGS 0x0L - FILEFLAGSMASK 0x3fL - FILEOS 0x00040004L - FILETYPE 0x1L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "CompanyName", "Antidote / Jackoalan" - VALUE "FileDescription", "URDE" - VALUE "FileVersion", "@METADATA_VERSION_STRING@" - VALUE "LegalCopyright", "Copyright (C) 2015-2018 Antidote / Jackoalan" - VALUE "InternalName", "urde" - VALUE "OriginalFilename", "urde.exe" - VALUE "ProductName", "URDE" - VALUE "ProductVersion", "@METADATA_VERSION_STRING@" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END diff --git a/LICENSE b/LICENSE index 3e86d7696..c5fc3b71e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2015-2018 URDE Contributors +Copyright (c) 2015-2021 Metaforce Contributors Original Authors: Jack Andersen and Phillip "Antidote" Stephens Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/NESEmulator/CMakeLists.txt b/NESEmulator/CMakeLists.txt index 3ef3c0761..d2945268a 100644 --- a/NESEmulator/CMakeLists.txt +++ b/NESEmulator/CMakeLists.txt @@ -1,15 +1,19 @@ -file(GLOB MAPPER_SRCS fixNES/mapper/*.c) +file(GLOB MAPPER_SRCS ../extern/fixNES/mapper/*.c) add_library(NESEmulator CNESEmulator.hpp CNESEmulator.cpp CNESShader.hpp CNESShader.cpp malloc.h - apu.c fixNES/audio_fds.c fixNES/audio_mmc5.c fixNES/audio_vrc6.c fixNES/audio_vrc7.c - fixNES/audio_n163.c fixNES/audio_s5b.c fixNES/cpu.c ppu.c fixNES/mem.c fixNES/input.c - fixNES/mapper.c fixNES/mapperList.c fixNES/fm2play.c fixNES/vrc_irq.c ${MAPPER_SRCS}) + apu.c ../extern/fixNES/audio_fds.c ../extern/fixNES/audio_mmc5.c ../extern/fixNES/audio_vrc6.c + ../extern/fixNES/audio_vrc7.c ../extern/fixNES/audio_n163.c ../extern/fixNES/audio_s5b.c + ../extern/fixNES/cpu.c ppu.c ../extern/fixNES/mem.c ../extern/fixNES/input.c ../extern/fixNES/mapper.c + ../extern/fixNES/mapperList.c ../extern/fixNES/fm2play.c ../extern/fixNES/vrc_irq.c ${MAPPER_SRCS}) hsh_sources(CNESShader.cpp) -target_include_directories(NESEmulator PRIVATE ${CMAKE_SOURCE_DIR}/DataSpec ${CMAKE_SOURCE_DIR}/Runtime - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(NESEmulator PRIVATE + ${CMAKE_SOURCE_DIR}/DataSpec + ${CMAKE_SOURCE_DIR}/Runtime + ${CMAKE_SOURCE_DIR}/extern + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_definitions(NESEmulator PRIVATE COL_32BIT=1 COL_TEX_BSWAP=1) target_link_libraries(NESEmulator PUBLIC hecl-full RuntimeCommon) if (NOT MSVC) - target_compile_options(NESEmulator PRIVATE -Wno-implicit-fallthrough -Wno-format -Wno-pointer-compare - -Wno-memset-elt-size) -endif() -target_hsh(NESEmulator) + target_compile_options(NESEmulator PRIVATE -Wno-implicit-fallthrough -Wno-format -Wno-pointer-compare + -Wno-memset-elt-size) +endif () +target_hsh(NESEmulator) \ No newline at end of file diff --git a/NESEmulator/CNESEmulator.cpp b/NESEmulator/CNESEmulator.cpp index 6b5fa16eb..f28f95432 100644 --- a/NESEmulator/CNESEmulator.cpp +++ b/NESEmulator/CNESEmulator.cpp @@ -14,7 +14,7 @@ #include #include -static urde::MP1::CNESEmulator* EmulatorInst = nullptr; +static metaforce::MP1::CNESEmulator* EmulatorInst = nullptr; extern "C" { @@ -166,7 +166,7 @@ int audioUpdate() { } } -namespace urde::MP1 { +namespace metaforce::MP1 { bool CNESEmulator::EmulatorConstructed = false; static logvisor::Module Log("CNESEmulator"); @@ -766,4 +766,4 @@ void CNESEmulator::LoadPassword(const u8* state) { x38_passwordPending = true; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/NESEmulator/CNESEmulator.hpp b/NESEmulator/CNESEmulator.hpp index af7a0c570..4fcffbab8 100644 --- a/NESEmulator/CNESEmulator.hpp +++ b/NESEmulator/CNESEmulator.hpp @@ -6,7 +6,7 @@ #include "zeus/CMatrix4f.hpp" #include "Graphics/CGraphics.hpp" -namespace urde { +namespace metaforce { struct CFinalInput; class IDvdRequest; @@ -76,4 +76,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/NESEmulator/CNESShader.cpp b/NESEmulator/CNESShader.cpp index a142e0387..fae0ebea6 100644 --- a/NESEmulator/CNESShader.cpp +++ b/NESEmulator/CNESShader.cpp @@ -3,7 +3,7 @@ #include "CNESShader.cpp.hshhead" -namespace urde::MP1 { +namespace metaforce::MP1 { using namespace hsh::pipeline; @@ -19,4 +19,4 @@ void CNESShader::BuildShaderDataBinding(hsh::binding& binding, hsh::vertex_buffe binding.hsh_bind(NESPipeline(vbo, uniBuf, tex)); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/NESEmulator/CNESShader.hpp b/NESEmulator/CNESShader.hpp index 328957587..8214948f9 100644 --- a/NESEmulator/CNESShader.hpp +++ b/NESEmulator/CNESShader.hpp @@ -3,7 +3,7 @@ #include "hsh/hsh.h" #include "Graphics/CGraphics.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CNESShader { public: @@ -11,4 +11,4 @@ public: hsh::uniform_buffer uniBuf, hsh::texture2d tex); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/NESEmulator/fixNES b/NESEmulator/fixNES deleted file mode 160000 index f97b61fd0..000000000 --- a/NESEmulator/fixNES +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f97b61fd06e34c6fc310eb93505671895843ae9c diff --git a/README.md b/README.md index f2bbd49d3..3d27e3835 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -## URDE +## Metaforce +#### Formerly known as URDE + **Status:** Metroid Prime 1 In-Game (all retail GC & Wii versions) **Official Discord Channel:** https://discord.gg/AMBVFuf -![URDE screenshot](assets/urde-screen1.png) +![Metaforce screenshot](assets/urde-screen1.png) ### Download Precompiled builds of the command-line extraction utility (`hecl`) with embedded dataspec libraries are available at https://releases.axiodl.com. This will give you intermediate dumps of original formats as *blender* and *yaml* representations. @@ -14,15 +16,14 @@ Everything else is much too experimental to make portable/stable release builds * Windows 10 (64-bit, D3D11 / Vulkan) * macOS 10.15+ (Metal) * Linux (Vulkan) - * Arch is known to function with [`glx` vendor setup instructions](https://wiki.archlinux.org/index.php/Category:Graphics) *(main development/testing OS)* - * Other distros with reasonably up-to-date packages will work (specific packages TBD) + * Follow [this guide](https://github.com/lutris/docs/blob/master/InstallingDrivers.md) to set up Vulkan & appropriate drivers for your distro. ### Usage (GC versions) * Extract ISO: `hecl extract [path].iso -o mp1` * `mp1` can be substituted with the directory name of your choice -* Repackage game for URDE: `cd mp1; hecl package` -* Run URDE: `urde mp1/out` +* Repackage game for Metaforce: `cd mp1; hecl package` +* Run Metaforce: `metaforce mp1/out` ### Usage (Wii versions) @@ -30,11 +31,11 @@ NFS files dumped from Metroid Prime Trilogy on Wii U VC can be used directly wit * Extract ISO or NFS: `hecl extract [path].[iso/nfs] -o mpt` * `mpt` can be substituted with the directory name of your choice -* Repackage game for URDE: `cd mpt; hecl package MP1` +* Repackage game for Metaforce: `cd mpt; hecl package MP1` * The `MP1` parameter is important here. -* Run URDE: `urde mpt/out` +* Run Metaforce: `metaforce mpt/out` -#### URDE options (non-exhaustive) +#### Metaforce options (non-exhaustive) * `-l`: Enable console logging * `--warp [worldid] [areaid]`: Warp to a specific world/area. Example: `--warp 2 2` @@ -57,21 +58,27 @@ NFS files dumped from Metroid Prime Trilogy on Wii U VC can be used directly wit * `CMake Tools` * `C++ Clang Compiler` * `C++ Clang-cl` -* **[macOS]** [Xcode 1.15+](https://developer.apple.com/xcode/download/) +* **[macOS]** [Xcode 11.5+](https://developer.apple.com/xcode/download/) * **[Linux]** recent development packages of `udev`, `x11`, `xcb`, `xinput`, `glx`, `asound` + * Ubuntu 20.04+ packages + ``` + build-essential curl git ninja-build llvm-dev libclang-dev clang lld zlib1g-dev libcurl4-openssl-dev + libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev libpulse-dev + libudev-dev libpng-dev libncurses5-dev cmake libx11-xcb-dev python3 python-is-python3 qt5-default + ``` ### Prep Directions ```sh -git clone --recursive https://github.com/AxioDL/urde.git -mkdir urde-build -cd urde-build +git clone --recursive https://github.com/AxioDL/metaforce.git +mkdir metaforce-build +cd metaforce-build ``` ### Update Directions ```sh -cd urde +cd metaforce git pull git submodule update --recursive ``` @@ -83,15 +90,15 @@ For Windows, it's recommended to use Visual Studio. See below. #### ninja (Windows/macOS/Linux) ```sh -cd urde-build -cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja ../urde +cd metaforce-build +cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja ../metaforce ninja ``` #### CMake options - Build release optimized (better runtime performance): `-DCMAKE_BUILD_TYPE=Release` - Use clang+lld (faster linking): `-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++` -- Optimize for current CPU (resulting binaries are not portable): `-DURDE_VECTOR_ISA=native` +- Optimize for current CPU (resulting binaries are not portable): `-DMETAFORCE_VECTOR_ISA=native` #### CLion (Windows/macOS/Linux) *(main development / debugging IDE)* @@ -110,14 +117,24 @@ Configure the desired CMake targets to build in the *Projects* area of the IDE. Verify all required VS packages are installed from the above **Build Prerequisites** section. -Open the `urde` directory in Visual Studio (imports CMake configuration). +Open the `metaforce` directory in Visual Studio (imports CMake configuration). MSVC and clang-cl configurations should import automatically. #### Xcode (macOS) ```sh -cmake -G Xcode ../urde +cmake -G Xcode ../metaforce ``` -Then open `urde.xcodeproj` +Then open `metaforce.xcodeproj` + +#### Optional Debug Models +We provide custom debug models for use to visualize certain aspects of the game such as lighting, in order to use +these models you may download them from https://axiodl.com/files/debug_models.zip and extract to `MP1/URDE` in an +existing HECL project (assuming paths are relative), then run the the following command: + +```sh +hecl package MP1/URDE +``` +This will cook and package the debug models and will automatically enable rendering of lights in a debug build of Metaforce. diff --git a/Runtime/Audio/CAudioGroupSet.cpp b/Runtime/Audio/CAudioGroupSet.cpp index db20e67c8..83ca2f65a 100644 --- a/Runtime/Audio/CAudioGroupSet.cpp +++ b/Runtime/Audio/CAudioGroupSet.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { amuse::AudioGroupData CAudioGroupSet::LoadData() { const auto readU32 = [](const u8* ptr) { @@ -33,9 +33,9 @@ amuse::AudioGroupData CAudioGroupSet::LoadData() { CAudioGroupSet::CAudioGroupSet(std::unique_ptr&& in) : m_buffer(std::move(in)), m_data(LoadData()) {} -CFactoryFnReturn FAudioGroupSetDataFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef) { +CFactoryFnReturn FAudioGroupSetDataFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef) { return TToken::GetIObjObjectFor(std::make_unique(std::move(in))); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CAudioGroupSet.hpp b/Runtime/Audio/CAudioGroupSet.hpp index d0b8c968b..4bbaf333e 100644 --- a/Runtime/Audio/CAudioGroupSet.hpp +++ b/Runtime/Audio/CAudioGroupSet.hpp @@ -11,7 +11,7 @@ #include -namespace urde { +namespace metaforce { class CAudioGroupSet { std::unique_ptr m_buffer; @@ -26,7 +26,7 @@ public: std::string_view GetName() const { return x20_name; } }; -CFactoryFnReturn FAudioGroupSetDataFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef); +CFactoryFnReturn FAudioGroupSetDataFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CAudioSys.cpp b/Runtime/Audio/CAudioSys.cpp index eb1c03818..49298644c 100644 --- a/Runtime/Audio/CAudioSys.cpp +++ b/Runtime/Audio/CAudioSys.cpp @@ -6,7 +6,7 @@ #include "Runtime/CSimplePool.hpp" #include "Runtime/Audio/CAudioGroupSet.hpp" -namespace urde { +namespace metaforce { namespace { std::unordered_map> mpGroupSetDB; std::unordered_map mpGroupSetResNameDB; @@ -96,4 +96,4 @@ void CAudioSys::SetDefaultVolumeScale(s16 scale) { s_DefaultVolumeScale = scale; void CAudioSys::SetVolumeScale(s16 scale) { s_VolumeScale = scale; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CAudioSys.hpp b/Runtime/Audio/CAudioSys.hpp index 4352e9e75..76fa2eb20 100644 --- a/Runtime/Audio/CAudioSys.hpp +++ b/Runtime/Audio/CAudioSys.hpp @@ -8,7 +8,7 @@ #include "boo2/audiodev/IAudioVoiceEngine.hpp" #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class CAudioGroupSet; class CSimplePool; @@ -65,4 +65,4 @@ public: static void SetVolumeScale(s16 scale); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CMidiManager.cpp b/Runtime/Audio/CMidiManager.cpp index efaecf6e0..14332d621 100644 --- a/Runtime/Audio/CMidiManager.cpp +++ b/Runtime/Audio/CMidiManager.cpp @@ -1,6 +1,6 @@ #include "Runtime/Audio/CMidiManager.hpp" -namespace urde { +namespace metaforce { std::unordered_set CMidiManager::m_MidiWrappers = {}; @@ -49,4 +49,4 @@ CFactoryFnReturn FMidiDataFactory(const SObjectTag& tag, CInputStream& in, const return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CMidiManager.hpp b/Runtime/Audio/CMidiManager.hpp index 75b915473..1114cb8c6 100644 --- a/Runtime/Audio/CMidiManager.hpp +++ b/Runtime/Audio/CMidiManager.hpp @@ -4,7 +4,7 @@ #include "Runtime/Audio/CSfxManager.hpp" -namespace urde { +namespace metaforce { class CMidiManager { public: @@ -55,4 +55,4 @@ CFactoryFnReturn FMidiDataFactory(const SObjectTag& tag, CInputStream& in, const using CMidiHandle = CMidiManager::CMidiHandle; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CSfxManager.cpp b/Runtime/Audio/CSfxManager.cpp index 71d1caeb2..8394782d4 100644 --- a/Runtime/Audio/CSfxManager.cpp +++ b/Runtime/Audio/CSfxManager.cpp @@ -2,7 +2,7 @@ #include "Runtime/CSimplePool.hpp" -namespace urde { +namespace metaforce { static TLockedToken> mpSfxTranslationTableTok; std::vector* CSfxManager::mpSfxTranslationTable = nullptr; @@ -659,4 +659,4 @@ void CSfxManager::Shutdown() { DisableAuxCallback(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CSfxManager.hpp b/Runtime/Audio/CSfxManager.hpp index f3b60285f..66fff0155 100644 --- a/Runtime/Audio/CSfxManager.hpp +++ b/Runtime/Audio/CSfxManager.hpp @@ -11,7 +11,7 @@ #include -namespace urde { +namespace metaforce { class CSfxManager { static std::vector* mpSfxTranslationTable; @@ -239,4 +239,4 @@ public: using CSfxHandle = CSfxManager::CSfxHandle; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CStaticAudioPlayer.cpp b/Runtime/Audio/CStaticAudioPlayer.cpp index 3191d336f..9e7bce4f8 100644 --- a/Runtime/Audio/CStaticAudioPlayer.cpp +++ b/Runtime/Audio/CStaticAudioPlayer.cpp @@ -3,7 +3,7 @@ #include "Runtime/CDvdFile.hpp" #include "Runtime/CDvdRequest.hpp" -namespace urde { +namespace metaforce { #define RSF_BUFFER_SIZE 0x20000 @@ -99,4 +99,4 @@ void CStaticAudioPlayer::Decode(s16* bufOut, u32 numSamples) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CStaticAudioPlayer.hpp b/Runtime/Audio/CStaticAudioPlayer.hpp index 758063059..fb6cc4bf0 100644 --- a/Runtime/Audio/CStaticAudioPlayer.hpp +++ b/Runtime/Audio/CStaticAudioPlayer.hpp @@ -13,7 +13,7 @@ #include "boo2/audiodev/IAudioVoice.hpp" #include "boo2/audiodev/IAudioVoiceEngine.hpp" -namespace urde { +namespace metaforce { class IDvdRequest; class CStaticAudioPlayer { @@ -72,4 +72,4 @@ public: void StopMixing() { m_voice->stop(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CStreamAudioManager.cpp b/Runtime/Audio/CStreamAudioManager.cpp index b7dc0aec9..414f9a1a0 100644 --- a/Runtime/Audio/CStreamAudioManager.cpp +++ b/Runtime/Audio/CStreamAudioManager.cpp @@ -13,7 +13,7 @@ #include -namespace urde { +namespace metaforce { class CDSPStreamManager; static u32 s_HandleCounter = 0; @@ -1042,4 +1042,4 @@ u8 CStreamAudioManager::g_SfxVolume = 0x7f; bool CStreamAudioManager::g_MusicUnmute = true; bool CStreamAudioManager::g_SfxUnmute = true; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Audio/CStreamAudioManager.hpp b/Runtime/Audio/CStreamAudioManager.hpp index 10b5b1479..6777c6b8f 100644 --- a/Runtime/Audio/CStreamAudioManager.hpp +++ b/Runtime/Audio/CStreamAudioManager.hpp @@ -4,7 +4,7 @@ #include "Runtime/GCNTypes.hpp" -namespace urde { +namespace metaforce { class CStreamAudioManager { static u8 g_MusicVolume; @@ -34,4 +34,4 @@ public: static void Shutdown(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CAutoMapper.cpp b/Runtime/AutoMapper/CAutoMapper.cpp index ff5028e9e..147840f21 100644 --- a/Runtime/AutoMapper/CAutoMapper.cpp +++ b/Runtime/AutoMapper/CAutoMapper.cpp @@ -16,7 +16,7 @@ #include -namespace urde { +namespace metaforce { void CAutoMapper::SAutoMapperRenderState::InterpolateWithClamp(const SAutoMapperRenderState& a, SAutoMapperRenderState& out, @@ -217,6 +217,7 @@ bool CAutoMapper::CheckDummyWorldLoad(CStateManager& mgr) { xa0_curAreaId = aid; dummyWorld->IGetMapWorld()->RecalculateWorldSphere(mwInfo, *dummyWorld); + x24_world = dummyWorld.get(); BeginMapperStateTransition(EAutoMapperState::MapScreen, mgr); x32c_loadingDummyWorld = false; return true; @@ -1558,8 +1559,8 @@ void CAutoMapper::SetupHintNavigation() { for (const CGameHintInfo::SHintLocation& loc : nextHint.GetLocations()) { if (loc.x0_mlvlId != curMlvl) { x1e0_hintSteps.emplace_back(SAutoMapperHintStep::SwitchToUniverse{}); - x1e0_hintSteps.emplace_back(SAutoMapperHintStep::PanToWorld{}, curMlvl); - x1e0_hintSteps.emplace_back(SAutoMapperHintStep::SwitchToWorld{}, curMlvl); + x1e0_hintSteps.emplace_back(SAutoMapperHintStep::PanToWorld{}, loc.x0_mlvlId); + x1e0_hintSteps.emplace_back(SAutoMapperHintStep::SwitchToWorld{}, loc.x0_mlvlId); } else { x1e0_hintSteps.emplace_back(SAutoMapperHintStep::ZoomOut{}); } @@ -1626,4 +1627,4 @@ void CAutoMapper::OnNewInGameGuiState(EInGameGuiState state, CStateManager& mgr) } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CAutoMapper.hpp b/Runtime/AutoMapper/CAutoMapper.hpp index cdaaf36c5..933bfc02f 100644 --- a/Runtime/AutoMapper/CAutoMapper.hpp +++ b/Runtime/AutoMapper/CAutoMapper.hpp @@ -17,7 +17,7 @@ #include #include -namespace urde { +namespace metaforce { class CMapWorldInfo; class CStateManager; class IWorld; @@ -128,7 +128,7 @@ private: ELoadPhase x4_loadPhase = ELoadPhase::LoadResources; TLockedToken x8_mapu; std::vector> x14_dummyWorlds; - CWorld* x24_world; + IWorld* x24_world; TLockedToken x28_frmeMapScreen; // Used to be ptr bool m_frmeInitialized = false; TLockedToken x30_miniMapSamus; @@ -275,4 +275,4 @@ public: return 0.f; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMapArea.cpp b/Runtime/AutoMapper/CMapArea.cpp index 5812be71e..26fc41f3a 100644 --- a/Runtime/AutoMapper/CMapArea.cpp +++ b/Runtime/AutoMapper/CMapArea.cpp @@ -10,7 +10,7 @@ #include "Runtime/World/CGameArea.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { +namespace metaforce { constexpr std::array MinesPostTransforms{{ {0.f, 0.f, 200.f}, {0.f, 0.f, 0.f}, @@ -78,6 +78,7 @@ CMapArea::CMapArea(CInputStream& in, u32 size) } void CMapArea::PostConstruct() { + OPTICK_EVENT(); x38_moStart = x44_buf.get(); x3c_vertexStart = x38_moStart + (x28_mappableObjCount * 0x50); x40_surfaceStart = x3c_vertexStart + (x2c_vertexCount * 12); @@ -302,4 +303,4 @@ CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, con return TToken::GetIObjObjectFor(std::make_unique(in, size)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMapArea.hpp b/Runtime/AutoMapper/CMapArea.hpp index 2ae87174b..1e4868f63 100644 --- a/Runtime/AutoMapper/CMapArea.hpp +++ b/Runtime/AutoMapper/CMapArea.hpp @@ -12,7 +12,7 @@ #include "zeus/CAABox.hpp" #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class IWorld; class CMapArea { public: @@ -84,4 +84,4 @@ public: }; CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&, CObjectReference*); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMapUniverse.cpp b/Runtime/AutoMapper/CMapUniverse.cpp index c9db5b12d..84f68f034 100644 --- a/Runtime/AutoMapper/CMapUniverse.cpp +++ b/Runtime/AutoMapper/CMapUniverse.cpp @@ -4,7 +4,7 @@ #include "Runtime/CGameState.hpp" #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { CMapUniverse::CMapUniverse(CInputStream& in, u32 version) : x0_hexagonId(in.readUint32Big()) { x4_hexagonToken = g_SimplePool->GetObj({FOURCC('MAPA'), x0_hexagonId}); @@ -121,4 +121,4 @@ CFactoryFnReturn FMapUniverseFactory(const SObjectTag&, CInputStream& in, const return TToken::GetIObjObjectFor(std::make_unique(in, version)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMapUniverse.hpp b/Runtime/AutoMapper/CMapUniverse.hpp index 4b7254070..d609cf505 100644 --- a/Runtime/AutoMapper/CMapUniverse.hpp +++ b/Runtime/AutoMapper/CMapUniverse.hpp @@ -12,7 +12,7 @@ #include #include -namespace urde { +namespace metaforce { class CStateManager; class CMapUniverse { public: @@ -124,4 +124,4 @@ public: CFactoryFnReturn FMapUniverseFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference*); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMapWorld.cpp b/Runtime/AutoMapper/CMapWorld.cpp index 90c6502ac..fe58b2c0f 100644 --- a/Runtime/AutoMapper/CMapWorld.cpp +++ b/Runtime/AutoMapper/CMapWorld.cpp @@ -9,7 +9,7 @@ #include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { +namespace metaforce { namespace { struct Support { int x0_; @@ -698,4 +698,4 @@ CFactoryFnReturn FMapWorldFactory(const SObjectTag& tag, CInputStream& in, const return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMapWorld.hpp b/Runtime/AutoMapper/CMapWorld.hpp index 554b0d5c2..fb851bcea 100644 --- a/Runtime/AutoMapper/CMapWorld.hpp +++ b/Runtime/AutoMapper/CMapWorld.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CMapWorldInfo; class CStateManager; class IWorld; @@ -167,4 +167,4 @@ public: CFactoryFnReturn FMapWorldFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& param, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMapWorldInfo.cpp b/Runtime/AutoMapper/CMapWorldInfo.cpp index c506e273e..18bb35ec9 100644 --- a/Runtime/AutoMapper/CMapWorldInfo.cpp +++ b/Runtime/AutoMapper/CMapWorldInfo.cpp @@ -3,7 +3,7 @@ #include "Runtime/CMemoryCardSys.hpp" #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { CMapWorldInfo::CMapWorldInfo(CBitStreamReader& reader, const CSaveWorld& savw, CAssetId mlvlId) { const CSaveWorldMemory& worldMem = g_MemoryCardSys->GetSaveWorldMemory(mlvlId); @@ -117,4 +117,4 @@ bool CMapWorldInfo::IsAnythingSet() const { return x38_mapStationUsed; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMapWorldInfo.hpp b/Runtime/AutoMapper/CMapWorldInfo.hpp index 69ac18b65..2cb325fa4 100644 --- a/Runtime/AutoMapper/CMapWorldInfo.hpp +++ b/Runtime/AutoMapper/CMapWorldInfo.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CSaveWorld; class CMapWorldInfo { @@ -31,4 +31,4 @@ public: bool IsAnythingSet() const; void SetMapStationUsed(bool isUsed) { x38_mapStationUsed = isUsed; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMappableObject.cpp b/Runtime/AutoMapper/CMappableObject.cpp index a92598fc4..6a947f1cd 100644 --- a/Runtime/AutoMapper/CMappableObject.cpp +++ b/Runtime/AutoMapper/CMappableObject.cpp @@ -7,7 +7,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Graphics/CTexture.hpp" -namespace urde { +namespace metaforce { std::array CMappableObject::skDoorVerts{}; constexpr std::array DoorIndices{ @@ -262,4 +262,4 @@ void CMappableObject::Shutdown() { g_doorVbo.reset(); g_doorIbo.reset(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/AutoMapper/CMappableObject.hpp b/Runtime/AutoMapper/CMappableObject.hpp index a2fe513d2..15c2735b0 100644 --- a/Runtime/AutoMapper/CMappableObject.hpp +++ b/Runtime/AutoMapper/CMappableObject.hpp @@ -13,7 +13,7 @@ #include #include -namespace urde { +namespace metaforce { class CMapWorldInfo; class CStateManager; @@ -96,4 +96,4 @@ public: } static void Shutdown(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CArchitectureMessage.hpp b/Runtime/CArchitectureMessage.hpp index 1a7926879..24722c5e1 100644 --- a/Runtime/CArchitectureMessage.hpp +++ b/Runtime/CArchitectureMessage.hpp @@ -6,7 +6,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Input/CFinalInput.hpp" -namespace urde { +namespace metaforce { class CIOWin; enum class EArchMsgTarget { @@ -142,4 +142,4 @@ public: return CArchitectureMessage(target, EArchMsgType::RemoveAllIOWins, std::make_shared()); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CArchitectureQueue.hpp b/Runtime/CArchitectureQueue.hpp index 1c14c2a47..d3d8c532b 100644 --- a/Runtime/CArchitectureQueue.hpp +++ b/Runtime/CArchitectureQueue.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/CArchitectureMessage.hpp" -namespace urde { +namespace metaforce { class CArchitectureQueue { std::list m_list; @@ -19,4 +19,4 @@ public: explicit operator bool() const { return !m_list.empty(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CBasics.hpp b/Runtime/CBasics.hpp index 431a2143c..8e76e67fe 100644 --- a/Runtime/CBasics.hpp +++ b/Runtime/CBasics.hpp @@ -6,7 +6,7 @@ #include "Runtime/GCNTypes.hpp" -namespace urde { +namespace metaforce { using OSTime = s64; @@ -41,4 +41,4 @@ public: static OSCalendarTime ToCalendarTime(std::chrono::system_clock::time_point time); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CBasicsPC.cpp b/Runtime/CBasicsPC.cpp index 9fa4649d6..b207a4451 100644 --- a/Runtime/CBasicsPC.cpp +++ b/Runtime/CBasicsPC.cpp @@ -24,7 +24,7 @@ static u64 MachToDolphinDenom; static LARGE_INTEGER PerfFrequency; #endif -namespace urde { +namespace metaforce { void CBasics::Initialize() { #if __APPLE__ @@ -140,4 +140,4 @@ OSCalendarTime CBasics::ToCalendarTime(std::chrono::system_clock::time_point tim return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CCRC32.cpp b/Runtime/CCRC32.cpp index 4b6e3df98..3c7fe60cc 100644 --- a/Runtime/CCRC32.cpp +++ b/Runtime/CCRC32.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { namespace { constexpr std::array crc32Table{ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, @@ -62,4 +62,4 @@ uint32_t CCRC32::Calculate(const void* data, uint32_t length) { return checksum; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CCRC32.hpp b/Runtime/CCRC32.hpp index 2bd7961c2..d4fad3866 100644 --- a/Runtime/CCRC32.hpp +++ b/Runtime/CCRC32.hpp @@ -2,11 +2,11 @@ #include -namespace urde { +namespace metaforce { class CCRC32 { public: static uint32_t Calculate(const void* data, uint32_t length); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CDependencyGroup.cpp b/Runtime/CDependencyGroup.cpp index 0aa37c59b..bc6064eae 100644 --- a/Runtime/CDependencyGroup.cpp +++ b/Runtime/CDependencyGroup.cpp @@ -1,7 +1,7 @@ #include "Runtime/CDependencyGroup.hpp" #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { CDependencyGroup::CDependencyGroup(CInputStream& in) { ReadFromStream(in); } void CDependencyGroup::ReadFromStream(CInputStream& in) { @@ -17,4 +17,4 @@ CFactoryFnReturn FDependencyGroupFactory([[maybe_unused]] const SObjectTag& tag, return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CDependencyGroup.hpp b/Runtime/CDependencyGroup.hpp index e38a176d2..40f5bb1f2 100644 --- a/Runtime/CDependencyGroup.hpp +++ b/Runtime/CDependencyGroup.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/CFactoryMgr.hpp" -namespace urde { +namespace metaforce { class CDependencyGroup { std::vector x0_objectTags; @@ -15,4 +15,4 @@ public: CFactoryFnReturn FDependencyGroupFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& param, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CDvdFile.cpp b/Runtime/CDvdFile.cpp index 39e9764f0..94ec79905 100644 --- a/Runtime/CDvdFile.cpp +++ b/Runtime/CDvdFile.cpp @@ -3,7 +3,7 @@ #include "Runtime/CDvdRequest.hpp" #include "Runtime/CStopwatch.hpp" -namespace urde { +namespace metaforce { hecl::ProjectPath CDvdFile::m_DvdRoot; std::unordered_map CDvdFile::m_caseInsensitiveMap; @@ -28,6 +28,9 @@ public: } bool IsComplete() override { return m_complete.load(); } void PostCancelRequest() override { + if (m_complete.load() || m_cancel.load()) { + return; + } std::unique_lock waitlk{CDvdFile::m_WaitMutex}; m_cancel.store(true); } @@ -146,4 +149,4 @@ void CDvdFile::Shutdown() { m_RequestQueue.clear(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CDvdFile.hpp b/Runtime/CDvdFile.hpp index 5cb6007f6..53a3d2357 100644 --- a/Runtime/CDvdFile.hpp +++ b/Runtime/CDvdFile.hpp @@ -13,7 +13,7 @@ #include -namespace urde { +namespace metaforce { enum class ESeekOrigin { Begin = 0, Cur = 1, End = 2 }; @@ -63,4 +63,4 @@ public: u64 Length() const { return m_reader->length(); } std::string_view GetPath() const { return x18_path; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CDvdRequest.hpp b/Runtime/CDvdRequest.hpp index 6b34d5373..de7c070f6 100644 --- a/Runtime/CDvdRequest.hpp +++ b/Runtime/CDvdRequest.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde { +namespace metaforce { class IDvdRequest { public: @@ -14,4 +14,4 @@ public: virtual EMediaType GetMediaType() const = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CFactoryMgr.cpp b/Runtime/CFactoryMgr.cpp index 46f8893f5..72fda9658 100644 --- a/Runtime/CFactoryMgr.cpp +++ b/Runtime/CFactoryMgr.cpp @@ -4,11 +4,12 @@ #include #include #include +#include "optick.h" #include "Runtime/CStopwatch.hpp" #include "Runtime/IObj.hpp" -namespace urde { +namespace metaforce { constexpr std::array TypeTable{ FOURCC('CLSN'), FOURCC('CMDL'), FOURCC('CSKR'), FOURCC('ANIM'), FOURCC('CINF'), FOURCC('TXTR'), FOURCC('PLTT'), FOURCC('FONT'), FOURCC('ANCS'), FOURCC('EVNT'), FOURCC('MADF'), FOURCC('MLVL'), FOURCC('MREA'), FOURCC('MAPW'), @@ -18,7 +19,7 @@ constexpr std::array TypeTable{ FOURCC('HINT'), FOURCC('MAPU'), FOURCC('DUMB'), FOURCC('OIDS'), }; -CFactoryFnReturn CFactoryMgr::MakeObject(const SObjectTag& tag, urde::CInputStream& in, +CFactoryFnReturn CFactoryMgr::MakeObject(const SObjectTag& tag, metaforce::CInputStream& in, const CVParamTransfer& paramXfer, CObjectReference* selfRef) { auto search = m_factories.find(tag.type); if (search == m_factories.end()) @@ -27,7 +28,7 @@ CFactoryFnReturn CFactoryMgr::MakeObject(const SObjectTag& tag, urde::CInputStre return search->second(tag, in, paramXfer, selfRef); } -bool CFactoryMgr::CanMakeMemory(const urde::SObjectTag& tag) const { +bool CFactoryMgr::CanMakeMemory(const metaforce::SObjectTag& tag) const { auto search = m_memFactories.find(tag.type); return search != m_memFactories.cend(); } @@ -35,6 +36,7 @@ bool CFactoryMgr::CanMakeMemory(const urde::SObjectTag& tag) const { CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr&& buf, int size, bool compressed, const CVParamTransfer& paramXfer, CObjectReference* selfRef) { + OPTICK_EVENT(); std::unique_ptr localBuf = std::move(buf); const auto memFactoryIter = m_memFactories.find(tag.type); @@ -81,4 +83,4 @@ CFactoryMgr::ETypeTable CFactoryMgr::FourCCToTypeIdx(FourCC fcc) { FourCC CFactoryMgr::TypeIdxToFourCC(ETypeTable fcc) { return TypeTable[size_t(fcc)]; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CFactoryMgr.hpp b/Runtime/CFactoryMgr.hpp index db048d82e..0f5b3e8b3 100644 --- a/Runtime/CFactoryMgr.hpp +++ b/Runtime/CFactoryMgr.hpp @@ -6,7 +6,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { struct SObjectTag; class CVParamTransfer; class IObj; @@ -16,9 +16,9 @@ class CFactoryMgr { std::unordered_map m_memFactories; public: - CFactoryFnReturn MakeObject(const SObjectTag& tag, urde::CInputStream& in, const CVParamTransfer& paramXfer, + CFactoryFnReturn MakeObject(const SObjectTag& tag, metaforce::CInputStream& in, const CVParamTransfer& paramXfer, CObjectReference* selfRef); - bool CanMakeMemory(const urde::SObjectTag& tag) const; + bool CanMakeMemory(const metaforce::SObjectTag& tag) const; CFactoryFnReturn MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr&& buf, int size, bool compressed, const CVParamTransfer& paramXfer, CObjectReference* selfRef); void AddFactory(FourCC key, FFactoryFunc func) { m_factories.insert_or_assign(key, std::move(func)); } @@ -71,4 +71,4 @@ public: static FourCC TypeIdxToFourCC(ETypeTable fcc); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameAllocator.cpp b/Runtime/CGameAllocator.cpp index 59b045635..ce786ff48 100644 --- a/Runtime/CGameAllocator.cpp +++ b/Runtime/CGameAllocator.cpp @@ -1,7 +1,7 @@ #include "Runtime/CGameAllocator.hpp" -namespace urde { -logvisor::Module AllocLog("urde::CGameAllocator"); +namespace metaforce { +logvisor::Module AllocLog("metaforce::CGameAllocator"); #pragma GCC diagnostic ignored "-Wclass-memaccess" @@ -54,4 +54,4 @@ void CGameAllocator::Free(u8* ptr) { /* Invalidate chunk allocation descriptor */ memset(info, 0, ROUND_UP_64(info->len + sizeof(SChunkDescription))); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameAllocator.hpp b/Runtime/CGameAllocator.hpp index a80500ca9..6bdeb3b24 100644 --- a/Runtime/CGameAllocator.hpp +++ b/Runtime/CGameAllocator.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CGameAllocator { struct SAllocationDescription { std::unique_ptr memptr; @@ -27,4 +27,4 @@ public: static u8* Alloc(size_t len); static void Free(u8* ptr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameDebug.hpp b/Runtime/CGameDebug.hpp index 0a94ffbfa..f4519b01a 100644 --- a/Runtime/CGameDebug.hpp +++ b/Runtime/CGameDebug.hpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { struct CFinalInput; const char* StringForControlOption(int); @@ -39,4 +39,4 @@ public: void AddDebugOption(const CDebugOption&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameHintInfo.cpp b/Runtime/CGameHintInfo.cpp index 887e15224..be625c576 100644 --- a/Runtime/CGameHintInfo.cpp +++ b/Runtime/CGameHintInfo.cpp @@ -4,7 +4,7 @@ #include "Runtime/CToken.hpp" #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { CGameHintInfo::CGameHintInfo(CInputStream& in, s32 version) { u32 hintCount = in.readUint32Big(); @@ -45,4 +45,4 @@ CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream& in, const CVParam return TToken::GetIObjObjectFor(std::make_unique(in, version)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameHintInfo.hpp b/Runtime/CGameHintInfo.hpp index 0ce7b2caa..96b04e070 100644 --- a/Runtime/CGameHintInfo.hpp +++ b/Runtime/CGameHintInfo.hpp @@ -6,7 +6,7 @@ #include "Runtime/IFactory.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CGameHintInfo { public: struct SHintLocation { @@ -46,4 +46,4 @@ public: }; CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream&, const CVParamTransfer&, CObjectReference*); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameOptions.cpp b/Runtime/CGameOptions.cpp index 69bf3511a..f1e3ebfda 100644 --- a/Runtime/CGameOptions.cpp +++ b/Runtime/CGameOptions.cpp @@ -16,7 +16,7 @@ #include -namespace urde { +namespace metaforce { constexpr std::array VisorOpts{{ {EGameOption::VisorOpacity, 21, 0.f, 255.f, 1.f, EOptionType::Float}, @@ -752,4 +752,4 @@ void CHintOptions::Update(float dt, const CStateManager& stateMgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameOptions.hpp b/Runtime/CGameOptions.hpp index dd4a56caf..b8c7f20e6 100644 --- a/Runtime/CGameOptions.hpp +++ b/Runtime/CGameOptions.hpp @@ -8,7 +8,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Audio/CAudioSys.hpp" -namespace urde { +namespace metaforce { struct CFinalInput; class CStateManager; @@ -203,4 +203,4 @@ public: void Update(float dt, const CStateManager& stateMgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameState.cpp b/Runtime/CGameState.cpp index 25497b69c..743f446f2 100644 --- a/Runtime/CGameState.cpp +++ b/Runtime/CGameState.cpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { union BitsToDouble { struct { #if BYTE_ORDER == __LITTLE_ENDIAN @@ -284,4 +284,4 @@ void CGameState::InitializeMemoryStates() { WriteBackupBuf(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CGameState.hpp b/Runtime/CGameState.hpp index 84d92acda..610d906ca 100644 --- a/Runtime/CGameState.hpp +++ b/Runtime/CGameState.hpp @@ -14,7 +14,7 @@ #include "Runtime/World/CWorld.hpp" #include "Runtime/World/CWorldTransManager.hpp" -namespace urde { +namespace metaforce { class CSaveWorldMemory; class CWorldLayerState { @@ -129,4 +129,4 @@ public: }; static GameFileStateInfo LoadGameFileState(const u8* data); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CIOWin.hpp b/Runtime/CIOWin.hpp index 43a3df3d8..70dcc91c0 100644 --- a/Runtime/CIOWin.hpp +++ b/Runtime/CIOWin.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CArchitectureMessage; class CArchitectureQueue; @@ -28,4 +28,4 @@ public: size_t GetNameHash() const { return m_nameHash; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CIOWinManager.cpp b/Runtime/CIOWinManager.cpp index a5fa8eb48..3c55de8e5 100644 --- a/Runtime/CIOWinManager.cpp +++ b/Runtime/CIOWinManager.cpp @@ -3,7 +3,7 @@ #include "Runtime/CArchitectureMessage.hpp" #include "Runtime/CIOWin.hpp" -namespace urde { +namespace metaforce { bool CIOWinManager::OnIOWinMessage(const CArchitectureMessage& msg) { switch (msg.GetType()) { @@ -251,4 +251,4 @@ void CIOWinManager::AddIOWin(std::weak_ptr chIow, int pumpPrio, int draw x0_drawRoot = newNode; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CIOWinManager.hpp b/Runtime/CIOWinManager.hpp index 9aadc67b8..44c86f9bb 100644 --- a/Runtime/CIOWinManager.hpp +++ b/Runtime/CIOWinManager.hpp @@ -7,7 +7,7 @@ #include "Runtime/CIOWin.hpp" #include "Runtime/rstl.hpp" -namespace urde { +namespace metaforce { class CIOWinManager { struct IOWinPQNode { @@ -37,4 +37,4 @@ public: bool IsEmpty() const { return x0_drawRoot == nullptr && x4_pumpRoot == nullptr; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CInGameTweakManagerBase.hpp b/Runtime/CInGameTweakManagerBase.hpp index 2d41a2efa..7c75ea903 100644 --- a/Runtime/CInGameTweakManagerBase.hpp +++ b/Runtime/CInGameTweakManagerBase.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CTweakValue { public: @@ -73,4 +73,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CMFGameBase.hpp b/Runtime/CMFGameBase.hpp index b73d1c71c..3a61b9f5f 100644 --- a/Runtime/CMFGameBase.hpp +++ b/Runtime/CMFGameBase.hpp @@ -2,7 +2,7 @@ #include "Runtime/CIOWin.hpp" -namespace urde { +namespace metaforce { class CMFGameBase : public CIOWin { public: @@ -14,4 +14,4 @@ public: explicit CMFGameLoaderBase(const char* name) : CIOWin(name) {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index 1990ae3c7..1ebca9c13 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -3,7 +3,7 @@ #include "boo2/boo2.hpp" #include "logvisor/logvisor.hpp" -namespace urde { +namespace metaforce { template class Delegate : public boo2::DelegateBase { @@ -14,5 +14,5 @@ class Delegate : public boo2::DelegateBase { int main(int argc, char** argv) noexcept { logvisor::RegisterConsoleLogger(); - return boo2::Application::exec(argc, argv, "urde"sv); + return boo2::Application::exec(argc, argv, "metaforce"sv); } diff --git a/Runtime/CMain.hpp b/Runtime/CMain.hpp index 92ef8f517..abe5f82df 100644 --- a/Runtime/CMain.hpp +++ b/Runtime/CMain.hpp @@ -1,5 +1,5 @@ #pragma once -namespace urde { +namespace metaforce { } diff --git a/Runtime/CMainFlowBase.cpp b/Runtime/CMainFlowBase.cpp index 478e29770..cd98a8c48 100644 --- a/Runtime/CMainFlowBase.cpp +++ b/Runtime/CMainFlowBase.cpp @@ -2,7 +2,7 @@ #include "Runtime/CArchitectureMessage.hpp" -namespace urde { +namespace metaforce { CIOWin::EMessageReturn CMainFlowBase::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) { switch (msg.GetType()) { @@ -21,4 +21,4 @@ CIOWin::EMessageReturn CMainFlowBase::OnMessage(const CArchitectureMessage& msg, return EMessageReturn::Normal; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CMainFlowBase.hpp b/Runtime/CMainFlowBase.hpp index f16ad0fbe..af874f924 100644 --- a/Runtime/CMainFlowBase.hpp +++ b/Runtime/CMainFlowBase.hpp @@ -2,7 +2,7 @@ #include "Runtime/CIOWin.hpp" -namespace urde { +namespace metaforce { enum class EClientFlowStates { Unspecified = -1, PreFrontEnd = 7, FrontEnd = 8, Game = 14, GameExit = 15 }; @@ -17,4 +17,4 @@ public: virtual void SetGameState(EClientFlowStates state, CArchitectureQueue& queue) = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index f7ba5b480..97d20cf97 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -139,7 +139,7 @@ set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) set(RUNTIME_LIBRARIES RetroDataSpec AssetNameMapNull NESEmulator libjpeg-turbo jbus kabufuda logvisor) if(NOT GEKKO AND NOT NX) - list(APPEND RUNTIME_LIBRARIES discord-rpc) + list(APPEND RUNTIME_LIBRARIES discord-rpc OptickCore) endif() add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A}) diff --git a/Runtime/CMemoryCardSys.cpp b/Runtime/CMemoryCardSys.cpp index bd7453df1..e98f7da9c 100644 --- a/Runtime/CMemoryCardSys.cpp +++ b/Runtime/CMemoryCardSys.cpp @@ -6,15 +6,19 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Graphics/CTexture.hpp" #include "Runtime/GuiSys/CStringTable.hpp" +#include +#include -namespace urde { - +namespace metaforce { +namespace { using ECardResult = kabufuda::ECardResult; static kabufuda::SystemString g_CardImagePaths[2] = {}; static kabufuda::Card g_CardStates[2] = {kabufuda::Card{"GM8E", "01"}, kabufuda::Card{"GM8E", "01"}}; // static kabufuda::ECardResult g_OpResults[2] = {}; - +hecl::CVar* mc_dolphinAPath = nullptr; +hecl::CVar* mc_dolphinBPath = nullptr; +} // namespace CSaveWorldIntermediate::CSaveWorldIntermediate(CAssetId mlvl, CAssetId savw) : x0_mlvlId(mlvl), x8_savwId(savw) { if (!savw.IsValid()) x2c_dummyWorld = std::make_unique(mlvl, false); @@ -35,7 +39,7 @@ bool CSaveWorldIntermediate::InitializePump() { xc_areaIds.reserve(areaCount); for (u32 i = 0; i < areaCount; ++i) { const IGameArea* area = wld.IGetAreaAlways(i); - xc_areaIds.emplace_back(area->IGetAreaId()); + xc_areaIds.emplace_back(area->IGetAreaSaveId()); } CAssetId mlvlId = wld.IGetWorldAssetId(); @@ -67,6 +71,12 @@ const CSaveWorldMemory& CMemoryCardSys::GetSaveWorldMemory(CAssetId wldId) const } CMemoryCardSys::CMemoryCardSys() { + mc_dolphinAPath = hecl::CVarManager::instance()->findOrMakeCVar( + "memcard.PathA"sv, "Path to the memory card image for SlotA"sv, ""sv, + (hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::System | hecl::CVar::EFlags::ModifyRestart)); + mc_dolphinBPath = hecl::CVarManager::instance()->findOrMakeCVar( + "memcard.PathB"sv, "Path to the memory card image for SlotB"sv, ""sv, + (hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::System | hecl::CVar::EFlags::ModifyRestart)); x0_hints = g_SimplePool->GetObj("HINT_Hints"); xc_memoryWorlds.reserve(16); x1c_worldInter.emplace(); @@ -139,16 +149,25 @@ bool CMemoryCardSys::InitializePump() { } if (done) { - std::sort(x20_scanStates.begin(), x20_scanStates.end(), [&](const auto& a, const auto& b) { - return a.first < b.first; - }); + std::sort(x20_scanStates.begin(), x20_scanStates.end(), + [&](const auto& a, const auto& b) { return a.first < b.first; }); x1c_worldInter = std::nullopt; } return false; } -std::pair CMemoryCardSys::GetAreaAndWorldIdForSaveId(s32 saveId) const { return {kInvalidAreaId, -1}; } +std::pair CMemoryCardSys::GetAreaAndWorldIdForSaveId(s32 saveId) const { + for (const auto& [mlvl, saveWorld] : xc_memoryWorlds) { + for (TAreaId areaId = 0; areaId < saveWorld.xc_areaIds.size(); ++areaId) { + if (saveWorld.xc_areaIds[areaId] == saveId) { + return {mlvl, areaId}; + } + } + } + + return {{}, kInvalidAreaId}; +} void CMemoryCardSys::CCardFileInfo::LockBannerToken(CAssetId bannerTxtr, CSimplePool& sp) { x3c_bannerTex = bannerTxtr; @@ -202,7 +221,8 @@ void CMemoryCardSys::CCardFileInfo::BuildCardBuffer() { __attribute__((nonstring)) #endif char comment[64]; - strncpy(comment, x28_comment.data(), 64); + std::memset(comment, 0, std::size(comment)); + std::strncpy(comment, x28_comment.data(), std::size(comment) - 1); w.writeBytes(comment, 64); WriteBannerData(w); WriteIconData(w); @@ -320,9 +340,25 @@ ECardResult CMemoryCardSys::CCardFileInfo::WriteFile() { ECardResult CMemoryCardSys::CCardFileInfo::CloseFile() { return CMemoryCardSys::CloseFile(m_handle); } +void CMemoryCardSys::_ResolveDolphinCardPath(const hecl::CVar* cv, kabufuda::ECardSlot slot) { +#if CARD_UCS2 + if (cv != nullptr && cv->toWideLiteral().empty()) { + g_CardImagePaths[int(slot)] = ResolveDolphinCardPath(slot); + } else if (cv != nullptr) { + g_CardImagePaths[int(slot)] = cv->toWideLiteral(); + } +#else + if (cv != nullptr && cv->toLiteral().empty()) { + g_CardImagePaths[int(slot)] = ResolveDolphinCardPath(slot); + } else if (cv != nullptr) { + g_CardImagePaths[int(slot)] = cv->toLiteral(); + } +#endif +} + kabufuda::ProbeResults CMemoryCardSys::CardProbe(kabufuda::ECardSlot port) { - g_CardImagePaths[0] = ResolveDolphinCardPath(kabufuda::ECardSlot::SlotA); - g_CardImagePaths[1] = ResolveDolphinCardPath(kabufuda::ECardSlot::SlotB); + _ResolveDolphinCardPath(mc_dolphinAPath, kabufuda::ECardSlot::SlotA); + _ResolveDolphinCardPath(mc_dolphinBPath, kabufuda::ECardSlot::SlotB); kabufuda::ProbeResults res = kabufuda::Card::probeCardFile(g_CardImagePaths[int(port)]); // g_OpResults[int(port)] = res.x0_error; @@ -544,4 +580,4 @@ void CMemoryCardSys::Shutdown() { UnmountCard(kabufuda::ECardSlot::SlotB); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CMemoryCardSys.hpp b/Runtime/CMemoryCardSys.hpp index 6281ca773..2dedf83f9 100644 --- a/Runtime/CMemoryCardSys.hpp +++ b/Runtime/CMemoryCardSys.hpp @@ -14,7 +14,7 @@ #include -namespace urde { +namespace metaforce { class CDummyWorld; class CSimplePool; class CStringTable; @@ -24,7 +24,7 @@ class CSaveWorldMemory { CAssetId x0_strgId; CAssetId x4_savwId; u32 x8_areaCount; - std::vector xc_areaIds; + std::vector xc_areaIds; std::vector x1c_defaultLayerStates; TLockedToken x2c_worldName; /* used to be optional */ TLockedToken x3c_saveWorld; /* used to be optional */ @@ -48,7 +48,7 @@ class CSaveWorldIntermediate { CAssetId x0_mlvlId; CAssetId x4_strgId; CAssetId x8_savwId; - std::vector xc_areaIds; + std::vector xc_areaIds; std::vector x1c_defaultLayerStates; std::unique_ptr x2c_dummyWorld; TLockedToken x34_saveWorld; /* Used to be auto_ptr */ @@ -67,6 +67,7 @@ class CMemoryCardSys { rstl::reserved_vector x30_scanCategoryCounts; public: + static void _ResolveDolphinCardPath(const hecl::CVar* cv, kabufuda::ECardSlot slot); static kabufuda::SystemString ResolveDolphinCardPath(kabufuda::ECardSlot slot); static kabufuda::SystemString CreateDolphinCard(kabufuda::ECardSlot slot); static kabufuda::SystemString _CreateDolphinCard(kabufuda::ECardSlot slot); @@ -151,7 +152,7 @@ public: } }; - std::pair GetAreaAndWorldIdForSaveId(s32 saveId) const; + std::pair GetAreaAndWorldIdForSaveId(s32 saveId) const; static kabufuda::ProbeResults CardProbe(kabufuda::ECardSlot port); static ECardResult MountCard(kabufuda::ECardSlot port); static ECardResult UnmountCard(kabufuda::ECardSlot port); @@ -176,4 +177,4 @@ public: static void Shutdown(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CMemoryCardSysNix.cpp b/Runtime/CMemoryCardSysNix.cpp index fa31b6cc8..c1afd706b 100644 --- a/Runtime/CMemoryCardSysNix.cpp +++ b/Runtime/CMemoryCardSysNix.cpp @@ -2,7 +2,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/IMain.hpp" -namespace urde { +namespace metaforce { kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) { if (g_Main->IsUSA() && !g_Main->IsTrilogy()) { @@ -56,4 +56,4 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl return {}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CMemoryCardSysOSX.cpp b/Runtime/CMemoryCardSysOSX.cpp index b62be99b8..1c5628e5c 100644 --- a/Runtime/CMemoryCardSysOSX.cpp +++ b/Runtime/CMemoryCardSysOSX.cpp @@ -1,7 +1,7 @@ #include "CMemoryCardSys.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/IMain.hpp" -namespace urde { +namespace metaforce { kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) { if (g_Main->IsUSA() && !g_Main->IsTrilogy()) { @@ -44,4 +44,4 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl return {}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CMemoryCardSysWin.cpp b/Runtime/CMemoryCardSysWin.cpp index fa869cd8a..c32d83924 100644 --- a/Runtime/CMemoryCardSysWin.cpp +++ b/Runtime/CMemoryCardSysWin.cpp @@ -5,7 +5,7 @@ #include -namespace urde { +namespace metaforce { #if WINDOWS_STORE using namespace Windows::Storage; @@ -120,4 +120,4 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl return {}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CObjectList.cpp b/Runtime/CObjectList.cpp index e0c6a89de..e4555d11d 100644 --- a/Runtime/CObjectList.cpp +++ b/Runtime/CObjectList.cpp @@ -1,9 +1,9 @@ #include "Runtime/CObjectList.hpp" #include -namespace urde { +namespace metaforce { namespace { -logvisor::Module Log("urde::CObjectList"); +logvisor::Module Log("metaforce::CObjectList"); } CObjectList::CObjectList(EGameObjectList listEnum) : x2004_listEnum(listEnum) {} @@ -105,4 +105,4 @@ CEntity* CObjectList::GetValidObjectById(TUniqueId uid) { bool CObjectList::IsQualified(const CEntity&) const { return true; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CObjectList.hpp b/Runtime/CObjectList.hpp index 68efd1d1d..d451ef9f7 100644 --- a/Runtime/CObjectList.hpp +++ b/Runtime/CObjectList.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { enum class EGameObjectList { Invalid = -1, @@ -91,4 +91,4 @@ public: u16 size() const { return x200a_count; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CPakFile.cpp b/Runtime/CPakFile.cpp index e5b4986f5..4cb56c565 100644 --- a/Runtime/CPakFile.cpp +++ b/Runtime/CPakFile.cpp @@ -1,13 +1,13 @@ #include "Runtime/CPakFile.hpp" -namespace urde { -static logvisor::Module Log("urde::CPakFile"); +namespace metaforce { +static logvisor::Module Log("metaforce::CPakFile"); CPakFile::CPakFile(std::string_view filename, bool buildDepList, bool worldPak, bool override) : CDvdFile(filename) { if (!CDvdFile::operator bool()) Log.report(logvisor::Fatal, FMT_STRING("{}: Unable to open"), GetPath()); x28_24_buildDepList = buildDepList; - //x28_24_buildDepList = true; // Always do this so URDE can rapidly pre-warm shaders + //x28_24_buildDepList = true; // Always do this so metaforce can rapidly pre-warm shaders x28_26_worldPak = worldPak; m_override = override; } @@ -180,4 +180,4 @@ void CPakFile::AsyncIdle() { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CPakFile.hpp b/Runtime/CPakFile.hpp index e868405b6..b43ce88e5 100644 --- a/Runtime/CPakFile.hpp +++ b/Runtime/CPakFile.hpp @@ -10,7 +10,7 @@ #include "Runtime/CStringExtras.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CPakFile : public CDvdFile { friend class CResLoader; @@ -78,4 +78,4 @@ public: CAssetId GetMLVLId() const { return m_mlvlId; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CPlayMovieBase.hpp b/Runtime/CPlayMovieBase.hpp index 0c86a81f4..3f7014199 100644 --- a/Runtime/CPlayMovieBase.hpp +++ b/Runtime/CPlayMovieBase.hpp @@ -3,7 +3,7 @@ #include "Runtime/CIOWin.hpp" #include "Runtime/Graphics/CMoviePlayer.hpp" -namespace urde { +namespace metaforce { class CPlayMovieBase : public CIOWin { CMoviePlayer x18_moviePlayer; @@ -14,4 +14,4 @@ public: void Draw() override {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CPlayerState.cpp b/Runtime/CPlayerState.cpp index 6c6a1a0f6..6b5ee1fa0 100644 --- a/Runtime/CPlayerState.cpp +++ b/Runtime/CPlayerState.cpp @@ -14,7 +14,7 @@ #include -namespace urde { +namespace metaforce { namespace { constexpr std::array PowerUpMaxValues{ 1, 1, 1, 1, 250, 1, 1, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -371,7 +371,7 @@ void CPlayerState::AddPowerUp(CPlayerState::EItemType type, u32 capacity) { } } -void CPlayerState::ReInitalizePowerUp(CPlayerState::EItemType type, u32 capacity) { +void CPlayerState::ReInitializePowerUp(CPlayerState::EItemType type, u32 capacity) { x24_powerups[u32(type)].x4_capacity = 0; AddPowerUp(type, capacity); } @@ -450,4 +450,4 @@ CPlayerState::EItemType CPlayerState::ItemNameToType(std::string_view name) { return iter->second; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CPlayerState.hpp b/Runtime/CPlayerState.hpp index 54e877827..e989d771f 100644 --- a/Runtime/CPlayerState.hpp +++ b/Runtime/CPlayerState.hpp @@ -9,7 +9,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/World/CHealthInfo.hpp" -namespace urde { +namespace metaforce { class CPlayerState { friend class CWorldTransManager; @@ -151,7 +151,7 @@ public: static float GetEnergyTankCapacity() { return 100.f; } static float GetBaseHealthCapacity() { return 99.f; } float CalculateHealth(); - void ReInitalizePowerUp(EItemType type, u32 capacity); + void ReInitializePowerUp(EItemType type, u32 capacity); void AddPowerUp(EItemType type, u32 capacity); u32 GetLogScans() const { return x180_scanCompletionRate.first; } u32 GetTotalLogScans() const { return x180_scanCompletionRate.second; } @@ -171,4 +171,4 @@ public: bool CanTakeDamage() const { return m_canTakeDamage; } void SetCanTakeDamage(bool c) { m_canTakeDamage = c; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CRandom16.cpp b/Runtime/CRandom16.cpp index c59033224..4cf44ec54 100644 --- a/Runtime/CRandom16.cpp +++ b/Runtime/CRandom16.cpp @@ -1,6 +1,6 @@ #include "Runtime/CRandom16.hpp" -namespace urde { +namespace metaforce { CRandom16* CRandom16::g_randomNumber = nullptr; // &DefaultRandom; CGlobalRandom* CGlobalRandom::g_currentGlobalRandom = nullptr; //&DefaultGlobalRandom; @@ -11,4 +11,4 @@ u32 g_numNextCalls = 0; void CRandom16::IncrementNumNextCalls() { ++g_numNextCalls; } u32 CRandom16::GetNumNextCalls() { return g_numNextCalls; } void CRandom16::ResetNumNextCalls() { g_numNextCalls = 0; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CRandom16.hpp b/Runtime/CRandom16.hpp index 3d18ec7ea..1a8e9ff05 100644 --- a/Runtime/CRandom16.hpp +++ b/Runtime/CRandom16.hpp @@ -2,7 +2,7 @@ #include "Runtime/GCNTypes.hpp" -namespace urde { +namespace metaforce { class CRandom16 { s32 m_seed; @@ -53,4 +53,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CRelayTracker.cpp b/Runtime/CRelayTracker.cpp index 9428af090..2485bc66d 100644 --- a/Runtime/CRelayTracker.cpp +++ b/Runtime/CRelayTracker.cpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { CRelayTracker::CRelayTracker(CBitStreamReader& in, const CSaveWorld& saveWorld) { const u32 relayCount = saveWorld.GetRelayCount(); @@ -95,4 +95,4 @@ void CRelayTracker::PutTo(CBitStreamWriter& out, const CSaveWorld& saveWorld) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CRelayTracker.hpp b/Runtime/CRelayTracker.hpp index fdeb8bb0e..980a5b6a1 100644 --- a/Runtime/CRelayTracker.hpp +++ b/Runtime/CRelayTracker.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/ScriptObjectSupport.hpp" -namespace urde { +namespace metaforce { class CSaveWorld; class CStateManager; @@ -38,4 +38,4 @@ public: void PutTo(CBitStreamWriter& out, const CSaveWorld& saveWorld); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CResFactory.cpp b/Runtime/CResFactory.cpp index 2968b6d02..22ec21111 100644 --- a/Runtime/CResFactory.cpp +++ b/Runtime/CResFactory.cpp @@ -2,8 +2,9 @@ #include "Runtime/CSimplePool.hpp" #include "Runtime/CStopwatch.hpp" +#include "optick.h" -namespace urde { +namespace metaforce { static logvisor::Module Log("CResFactory"); void CResFactory::AddToLoadList(SLoadingData&& data) { @@ -33,6 +34,7 @@ CFactoryFnReturn CResFactory::BuildSync(const SObjectTag& tag, const CVParamTran } bool CResFactory::PumpResource(SLoadingData& data) { + OPTICK_EVENT(); if (data.x8_dvdReq && data.x8_dvdReq->IsComplete()) { data.x8_dvdReq.reset(); *data.xc_targetPtr = @@ -74,11 +76,12 @@ void CResFactory::BuildAsync(const SObjectTag& tag, const CVParamTransfer& xfer, } void CResFactory::AsyncIdle() { + OPTICK_EVENT(); if (m_loadList.empty()) return; auto startTime = std::chrono::steady_clock::now(); while (std::chrono::duration_cast(std::chrono::steady_clock::now() - startTime).count() < - 2) { + 5) { auto& task = m_loadList.front(); if (PumpResource(task)) { m_loadMap.erase(task.x0_tag); @@ -112,4 +115,4 @@ void CResFactory::LoadPersistentResources(CSimplePool& sp) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CResFactory.hpp b/Runtime/CResFactory.hpp index c7efaa6d1..b43731240 100644 --- a/Runtime/CResFactory.hpp +++ b/Runtime/CResFactory.hpp @@ -10,7 +10,7 @@ #include "Runtime/IFactory.hpp" #include "Runtime/IVParamObj.hpp" -namespace urde { +namespace metaforce { class IDvdRequest; class CSimplePool; @@ -53,13 +53,13 @@ public: bool CanBuild(const SObjectTag& tag) override { return x4_loader.ResourceExists(tag); } - u32 ResourceSize(const urde::SObjectTag& tag) override { return x4_loader.ResourceSize(tag); } + u32 ResourceSize(const metaforce::SObjectTag& tag) override { return x4_loader.ResourceSize(tag); } - std::unique_ptr LoadResourceSync(const urde::SObjectTag& tag) override { + std::unique_ptr LoadResourceSync(const metaforce::SObjectTag& tag) override { return x4_loader.LoadResourceSync(tag); } - std::unique_ptr LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size) override { + std::unique_ptr LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) override { return x4_loader.LoadNewResourcePartSync(tag, off, size); } @@ -67,11 +67,11 @@ public: return x4_loader.GetTagListForFile(pakName, out); } - std::shared_ptr LoadResourceAsync(const urde::SObjectTag& tag, void* target) override { + std::shared_ptr LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) override { return x4_loader.LoadResourceAsync(tag, target); } - std::shared_ptr LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, + std::shared_ptr LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size, void* target) override { return x4_loader.LoadResourcePartAsync(tag, off, size, target); } @@ -101,4 +101,4 @@ public: CFactoryMgr* GetFactoryMgr() override { return &x5c_factoryMgr; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CResLoader.cpp b/Runtime/CResLoader.cpp index 43cade117..482becd53 100644 --- a/Runtime/CResLoader.cpp +++ b/Runtime/CResLoader.cpp @@ -2,7 +2,7 @@ #include "Runtime/CPakFile.hpp" -namespace urde { +namespace metaforce { static logvisor::Module Log("CResLoader"); CResLoader::CResLoader() { x48_curPak = x18_pakLoadedList.end(); } @@ -100,7 +100,7 @@ std::shared_ptr CResLoader::LoadResourceAsync(const SObjectTag& tag x50_cachedResInfo->GetOffset()); } -std::unique_ptr CResLoader::LoadResourceSync(const urde::SObjectTag& tag) { +std::unique_ptr CResLoader::LoadResourceSync(const metaforce::SObjectTag& tag) { CPakFile* file = FindResourceForLoad(tag.id); u32 size = ROUND_UP_32(x50_cachedResInfo->GetSize()); std::unique_ptr ret(new u8[size]); @@ -108,7 +108,7 @@ std::unique_ptr CResLoader::LoadResourceSync(const urde::SObjectTag& tag) return ret; } -std::unique_ptr CResLoader::LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size) { +std::unique_ptr CResLoader::LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) { CPakFile* file = FindResourceForLoad(tag.id); std::unique_ptr ret(new u8[size]); file->SyncSeekRead(ret.get(), size, ESeekOrigin::Begin, x50_cachedResInfo->GetOffset() + off); @@ -305,4 +305,4 @@ void CResLoader::EnumerateNamedResources(const std::function LoadNewResourceSync(const SObjectTag& tag, void* extBuf = nullptr); std::shared_ptr LoadResourcePartAsync(const SObjectTag& tag, u32 off, u32 size, void* buf); std::shared_ptr LoadResourceAsync(const SObjectTag& tag, void* buf); - std::unique_ptr LoadResourceSync(const urde::SObjectTag& tag); - std::unique_ptr LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size); + std::unique_ptr LoadResourceSync(const metaforce::SObjectTag& tag); + std::unique_ptr LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size); void GetTagListForFile(const char* pakName, std::vector& out) const; bool GetResourceCompression(const SObjectTag& tag) const; u32 ResourceSize(const SObjectTag& tag) const; @@ -62,4 +62,4 @@ public: const std::list>& GetPaks() const { return x18_pakLoadedList; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CSaveWorld.cpp b/Runtime/CSaveWorld.cpp index 5f6928ac0..c1dfed047 100644 --- a/Runtime/CSaveWorld.cpp +++ b/Runtime/CSaveWorld.cpp @@ -2,7 +2,7 @@ #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { CSaveWorld::CSaveWorld(CInputStream& in) { in.readUint32Big(); const u32 version = in.readUint32Big(); @@ -88,4 +88,4 @@ CFactoryFnReturn FSaveWorldFactory([[maybe_unused]] const SObjectTag& tag, CInpu return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CSaveWorld.hpp b/Runtime/CSaveWorld.hpp index 097ed3522..6b2d6af1c 100644 --- a/Runtime/CSaveWorld.hpp +++ b/Runtime/CSaveWorld.hpp @@ -7,7 +7,7 @@ #include "Runtime/CFactoryMgr.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CSaveWorld { public: @@ -48,4 +48,4 @@ public: CFactoryFnReturn FSaveWorldFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& param, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CScannableObjectInfo.cpp b/Runtime/CScannableObjectInfo.cpp index a4787d253..d950522fc 100644 --- a/Runtime/CScannableObjectInfo.cpp +++ b/Runtime/CScannableObjectInfo.cpp @@ -2,7 +2,7 @@ #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { CScannableObjectInfo::CScannableObjectInfo(CInputStream& in, CAssetId resId) : x0_scannableObjectId(resId) { const u32 version = in.readUint32Big(); Load(in, version); @@ -69,4 +69,4 @@ CFactoryFnReturn FScannableObjectInfoFactory(const SObjectTag& tag, CInputStream CObjectReference*) { return TToken::GetIObjObjectFor(std::make_unique(in, tag.id)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CScannableObjectInfo.hpp b/Runtime/CScannableObjectInfo.hpp index 565a382f8..f844ff01e 100644 --- a/Runtime/CScannableObjectInfo.hpp +++ b/Runtime/CScannableObjectInfo.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { class CScannableObjectInfo { public: enum class EPanelType {}; @@ -45,4 +45,4 @@ public: CFactoryFnReturn FScannableObjectInfoFactory(const SObjectTag&, CInputStream&, const CVParamTransfer&, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CSimplePool.cpp b/Runtime/CSimplePool.cpp index 65dfee1a8..731059e1f 100644 --- a/Runtime/CSimplePool.cpp +++ b/Runtime/CSimplePool.cpp @@ -5,7 +5,7 @@ #include -namespace urde { +namespace metaforce { CSimplePool::CSimplePool(IFactory& factory) : x18_factory(factory), x1c_paramXfer(new TObjOwnerParam(this)) {} @@ -68,4 +68,4 @@ std::vector CSimplePool::GetReferencedTags() const { return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CSimplePool.hpp b/Runtime/CSimplePool.hpp index bc477536a..852a35b29 100644 --- a/Runtime/CSimplePool.hpp +++ b/Runtime/CSimplePool.hpp @@ -7,7 +7,7 @@ #include "Runtime/IVParamObj.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CObjectReference; class IFactory; @@ -35,4 +35,4 @@ public: size_t GetLiveObjects() const { return x8_resources.size(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CSortedLists.cpp b/Runtime/CSortedLists.cpp index 2a9ecbb99..b02ae76a0 100644 --- a/Runtime/CSortedLists.cpp +++ b/Runtime/CSortedLists.cpp @@ -5,7 +5,7 @@ #include #include -namespace urde { +namespace metaforce { namespace { template auto AccessElement(T& arr, S idx) -> typename T::reference { @@ -328,4 +328,4 @@ bool CSortedListManager::ActorInLists(const CActor* actor) const { return node.x2a_populated; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CSortedLists.hpp b/Runtime/CSortedLists.hpp index ce7d49e4a..bc47b4911 100644 --- a/Runtime/CSortedLists.hpp +++ b/Runtime/CSortedLists.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { enum class ESortedList { MinX, MinY, MinZ, MaxX, MaxY, MaxZ }; struct SSortedList { @@ -54,4 +54,4 @@ public: bool ActorInLists(const CActor* actor) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 88b4684b8..2d4961954 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -8,6 +8,7 @@ #include "Runtime/Camera/CGameCamera.hpp" #include "Runtime/CGameState.hpp" #include "Runtime/CMemoryCardSys.hpp" +#include "Runtime/Collision/CCollisionActor.hpp" #include "Runtime/Collision/CCollidableSphere.hpp" #include "Runtime/Collision/CGameCollision.hpp" #include "Runtime/Collision/CMaterialFilter.hpp" @@ -51,9 +52,16 @@ #include #include -namespace urde { +namespace metaforce { +namespace { +hecl::CVar* debugToolDrawAiPath = nullptr; +hecl::CVar* debugToolDrawLighting = nullptr; +hecl::CVar* debugToolDrawCollisionActors = nullptr; +hecl::CVar* debugToolDrawMazePath = nullptr; +hecl::CVar* debugToolDrawPlatformCollision = nullptr; hecl::CVar* sm_logScripting = nullptr; -logvisor::Module LogModule("urde::CStateManager"); +} // namespace +logvisor::Module LogModule("metaforce::CStateManager"); CStateManager::CStateManager(const std::weak_ptr& relayTracker, const std::weak_ptr& mwInfo, const std::weak_ptr& playerState, const std::weak_ptr& wtMgr, @@ -117,7 +125,8 @@ CStateManager::CStateManager(const std::weak_ptr& relayTracker, x90c_loaderFuncs[size_t(EScriptObjectType::GrapplePoint)] = ScriptLoader::LoadGrapplePoint; x90c_loaderFuncs[size_t(EScriptObjectType::PuddleSpore)] = ScriptLoader::LoadPuddleSpore; x90c_loaderFuncs[size_t(EScriptObjectType::DebugCameraWaypoint)] = ScriptLoader::LoadDebugCameraWaypoint; - x90c_loaderFuncs[size_t(EScriptObjectType::SpiderBallAttractionSurface)] = ScriptLoader::LoadSpiderBallAttractionSurface; + x90c_loaderFuncs[size_t(EScriptObjectType::SpiderBallAttractionSurface)] = + ScriptLoader::LoadSpiderBallAttractionSurface; x90c_loaderFuncs[size_t(EScriptObjectType::PuddleToadGamma)] = ScriptLoader::LoadPuddleToadGamma; x90c_loaderFuncs[size_t(EScriptObjectType::DistanceFog)] = ScriptLoader::LoadDistanceFog; x90c_loaderFuncs[size_t(EScriptObjectType::FireFlea)] = ScriptLoader::LoadFireFlea; @@ -192,7 +201,7 @@ CStateManager::CStateManager(const std::weak_ptr& relayTracker, x90c_loaderFuncs[size_t(EScriptObjectType::Burrower)] = ScriptLoader::LoadBurrower; x90c_loaderFuncs[size_t(EScriptObjectType::ScriptBeam)] = ScriptLoader::LoadBeam; x90c_loaderFuncs[size_t(EScriptObjectType::WorldLightFader)] = ScriptLoader::LoadWorldLightFader; - x90c_loaderFuncs[size_t(EScriptObjectType::MetroidPrimeStage2)] = ScriptLoader::LoadMetroidPrimeStage2; + x90c_loaderFuncs[size_t(EScriptObjectType::MetroidPrimeStage2)] = ScriptLoader::LoadMetroidPrimeEssence; x90c_loaderFuncs[size_t(EScriptObjectType::MetroidPrimeStage1)] = ScriptLoader::LoadMetroidPrimeStage1; x90c_loaderFuncs[size_t(EScriptObjectType::MazeNode)] = ScriptLoader::LoadMazeNode; x90c_loaderFuncs[size_t(EScriptObjectType::OmegaPirate)] = ScriptLoader::LoadOmegaPirate; @@ -427,9 +436,7 @@ void CStateManager::SetupParticleHook(const CActor& actor) const { void CStateManager::MurderScriptInstanceNames() { xb40_uniqueInstanceNames.clear(); } -std::string CStateManager::HashInstanceName(CInputStream& in) { - return in.readString(); -} +std::string CStateManager::HashInstanceName(CInputStream& in) { return in.readString(); } void CStateManager::SetActorAreaId(CActor& actor, TAreaId aid) { const TAreaId actorAid = actor.GetAreaIdAlways(); @@ -534,21 +541,56 @@ void CStateManager::BuildDynamicLightListForWorld() { } } } - void CStateManager::DrawDebugStuff() const { -#ifndef NDEBUG + if (hecl::com_developer != nullptr && !hecl::com_developer->toBoolean()) { + return; + } + + // FIXME: Add proper globals for CVars + if (debugToolDrawAiPath == nullptr || debugToolDrawCollisionActors == nullptr || debugToolDrawLighting == nullptr || + debugToolDrawMazePath == nullptr || debugToolDrawPlatformCollision == nullptr) { + debugToolDrawAiPath = hecl::CVarManager::instance()->findCVar("debugTool.drawAiPath"); + debugToolDrawMazePath = hecl::CVarManager::instance()->findCVar("debugTool.drawMazePath"); + debugToolDrawCollisionActors = hecl::CVarManager::instance()->findCVar("debugTool.drawCollisionActors"); + debugToolDrawLighting = hecl::CVarManager::instance()->findCVar("debugTool.drawLighting"); + debugToolDrawPlatformCollision = hecl::CVarManager::instance()->findCVar("debugTool.drawPlatformCollision"); + return; + } + CGraphics::SetModelMatrix(zeus::CTransform()); for (CEntity* ent : GetActorObjectList()) { if (const TCastToPtr ai = ent) { if (CPathFindSearch* path = ai->GetSearchPath()) { - path->DebugDraw(); + if (debugToolDrawAiPath->toBoolean()) { + path->DebugDraw(); + } + } + } else if (const TCastToPtr light = ent) { + if (debugToolDrawLighting->toBoolean()) { + light->DebugDraw(); + } + } else if (const TCastToPtr colAct = ent) { + if (colAct->GetUniqueId() == x870_cameraManager->GetBallCamera()->GetCollisionActorId()) { + continue; + } + if (debugToolDrawCollisionActors->toBoolean()) { + colAct->DebugDraw(); + } + } else if (const TCastToPtr plat = ent) { + if (debugToolDrawPlatformCollision->toBoolean() && plat->GetActive()) { + plat->DebugDraw(); } } } - if (xf70_currentMaze) { + + auto* gameArea = x850_world->GetArea(x850_world->GetCurrentAreaId()); + if (gameArea != nullptr && debugToolDrawLighting->toBoolean()) { + gameArea->DebugDraw(); + } + + if (xf70_currentMaze && debugToolDrawMazePath->toBoolean()) { xf70_currentMaze->DebugRender(); } -#endif } void CStateManager::RenderCamerasAndAreaLights() { @@ -738,6 +780,7 @@ void CStateManager::DrawWorld() { g_Renderer->SetThermalColdScale(xf28_thermColdScale2 + xf24_thermColdScale1); for (int i = areaCount - 1; i >= 0; --i) { + OPTICK_EVENT("CStateManager::DrawWorld DrawArea"); const CGameArea& area = *areaArr[i]; SetupFogForArea(area); g_Renderer->EnablePVS(pvsArr[i], area.x4_selfIdx); @@ -1430,6 +1473,7 @@ void CStateManager::LoadScriptObjects(TAreaId aid, CInputStream& in, std::vector std::pair CStateManager::LoadScriptObject(TAreaId aid, EScriptObjectType type, u32 length, CInputStream& in) { + OPTICK_EVENT(); const TEditorId id = in.readUint32Big(); const u32 connCount = in.readUint32Big(); length -= 8; @@ -1485,7 +1529,9 @@ std::pair CStateManager::LoadScriptObject(TAreaId aid, ESc ScriptObjectTypeToStr(type), name); return {kInvalidEditorId, kInvalidUniqueId}; } else { +#ifndef NDEBUG LogModule.report(logvisor::Info, FMT_STRING("Loaded {} in area {}"), ent->GetName(), ent->GetAreaIdAlways()); +#endif return {id, ent->GetUniqueId()}; } } @@ -1588,7 +1634,8 @@ void CStateManager::KnockBackPlayer(CPlayer& player, const zeus::CVector3f& pos, usePower = power * 1000.f; const auto surface = player.x2b0_outOfWaterTicks == 2 ? player.x2ac_surfaceRestraint : CPlayer::ESurfaceRestraints::Water; - if (surface != CPlayer::ESurfaceRestraints::Normal && player.GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit) { + if (surface != CPlayer::ESurfaceRestraints::Normal && + player.GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit) { usePower /= 7.f; } } else { @@ -1700,7 +1747,8 @@ void CStateManager::ApplyRadiusDamage(const CActor& a1, const zeus::CVector3f& p } } - const CDamageVulnerability* vuln = rad > 0.f ? a2.GetDamageVulnerability(pos, delta, info) : a2.GetDamageVulnerability(); + const CDamageVulnerability* vuln = + rad > 0.f ? a2.GetDamageVulnerability(pos, delta, info) : a2.GetDamageVulnerability(); if (vuln->WeaponHurts(info.GetWeaponMode(), true)) { const float dam = info.GetRadiusDamage(*vuln); @@ -1976,8 +2024,9 @@ bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqu } if (alive && damager && info.GetKnockBackPower() > 0.f) { - const zeus::CVector3f delta = + zeus::CVector3f delta = knockbackVec.isZero() ? (damagee->GetTranslation() - damager->GetTranslation()) : knockbackVec; + delta.z() = FLT_EPSILON; ApplyKnockBack(*damagee, info, *dVuln, delta.normalized(), 0.f); } } @@ -2299,6 +2348,7 @@ void CStateManager::MoveActors(float dt) { void CStateManager::CrossTouchActors() { std::array visits{}; + rstl::reserved_vector nearList; for (CEntity* ent : GetActorObjectList()) { if (ent == nullptr) { @@ -2320,7 +2370,7 @@ void CStateManager::CrossTouchActors() { filter = CMaterialFilter::MakeExclude(EMaterialTypes::Trigger); } - rstl::reserved_vector nearList; + nearList.clear(); BuildNearList(nearList, *touchAABB, filter, &actor); for (const auto& id : nearList) { @@ -2824,4 +2874,11 @@ void CStateManager::sub_80044098(const CCollisionResponseData& colRespData, cons TUniqueId uid, const CWeaponMode& weaponMode, u32 w1, u8 thermalFlags) { // TODO implement } -} // namespace urde + +const CGameArea* CStateManager::GetCurrentArea() const { + if (x850_world == nullptr || x850_world->GetCurrentAreaId() == kInvalidAreaId) { + return nullptr; + } + return x850_world->GetAreaAlways(x850_world->GetCurrentAreaId()); +}; +} // namespace metaforce diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 52ee72a08..8ce3f841c 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -34,7 +34,7 @@ #include #include -namespace urde { +namespace metaforce { class CActor; class CActorModelParticles; class CDamageInfo; @@ -464,6 +464,7 @@ public: void sub_80044098(const CCollisionResponseData& colRespData, const CRayCastResult& rayCast, TUniqueId uid, const CWeaponMode& weaponMode, u32 w1, u8 thermalFlags); + const CGameArea* GetCurrentArea() const; void SetWarping(bool warp) { m_warping = warp; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CStaticInterference.cpp b/Runtime/CStaticInterference.cpp index 417368733..b44d6007c 100644 --- a/Runtime/CStaticInterference.cpp +++ b/Runtime/CStaticInterference.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { CStaticInterference::CStaticInterference(size_t sourceCount) { x0_sources.reserve(sourceCount); } @@ -61,4 +61,4 @@ void CStaticInterference::AddSource(TUniqueId id, float magnitude, float duratio } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CStaticInterference.hpp b/Runtime/CStaticInterference.hpp index 4a9bff666..be6ceeb50 100644 --- a/Runtime/CStaticInterference.hpp +++ b/Runtime/CStaticInterference.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CStateManager; struct CStaticInterferenceSource { @@ -23,4 +23,4 @@ public: void AddSource(TUniqueId id, float magnitude, float duration); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CStopwatch.hpp b/Runtime/CStopwatch.hpp index 87397fd88..50cb9653e 100644 --- a/Runtime/CStopwatch.hpp +++ b/Runtime/CStopwatch.hpp @@ -3,7 +3,7 @@ #include #include -namespace urde { +namespace metaforce { class CStopwatch { std::chrono::steady_clock::time_point m_start; @@ -27,4 +27,4 @@ public: return t; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CStringExtras.hpp b/Runtime/CStringExtras.hpp index afa6f4505..c7acb4091 100644 --- a/Runtime/CStringExtras.hpp +++ b/Runtime/CStringExtras.hpp @@ -4,7 +4,7 @@ #include #include -namespace urde { +namespace metaforce { class CStringExtras { public: @@ -38,4 +38,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CTextureCache.cpp b/Runtime/CTextureCache.cpp index 0dda5efd8..34bc7c89a 100644 --- a/Runtime/CTextureCache.cpp +++ b/Runtime/CTextureCache.cpp @@ -1,7 +1,7 @@ #include "Runtime/CTextureCache.hpp" #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { CTextureCache::CTextureCache(CInputStream& in) { u32 textureCount = in.readUint32Big(); for (u32 i = 0; i < textureCount; ++i) { diff --git a/Runtime/CTextureCache.hpp b/Runtime/CTextureCache.hpp index 220e0ba5c..30acaef73 100644 --- a/Runtime/CTextureCache.hpp +++ b/Runtime/CTextureCache.hpp @@ -1,7 +1,7 @@ #pragma once #include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/CTexture.hpp" -namespace urde { +namespace metaforce { class CPaletteInfo { u32 m_format; u32 m_elementCount; @@ -42,6 +42,6 @@ public: const CTextureInfo* GetTextureInfo(CAssetId id) const; }; -CFactoryFnReturn FTextureCacheFactory(const urde::SObjectTag& tag, CInputStream& in, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef); +CFactoryFnReturn FTextureCacheFactory(const metaforce::SObjectTag& tag, CInputStream& in, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef); } \ No newline at end of file diff --git a/Runtime/CTimeProvider.cpp b/Runtime/CTimeProvider.cpp index b8bceabb5..7fb723495 100644 --- a/Runtime/CTimeProvider.cpp +++ b/Runtime/CTimeProvider.cpp @@ -2,7 +2,7 @@ #include "Runtime/Graphics/CGraphics.hpp" -namespace urde { +namespace metaforce { static CTimeProvider* s_currentTimeProvider = nullptr; CTimeProvider::CTimeProvider(const float& time) : x0_currentTime(time), x8_lastProvider(s_currentTimeProvider) { @@ -23,4 +23,4 @@ CTimeProvider::~CTimeProvider() { CGraphics::SetExternalTimeProvider(s_currentTimeProvider); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CTimeProvider.hpp b/Runtime/CTimeProvider.hpp index af99cb2bf..e8fbe2cd8 100644 --- a/Runtime/CTimeProvider.hpp +++ b/Runtime/CTimeProvider.hpp @@ -1,5 +1,5 @@ #pragma once -namespace urde { +namespace metaforce { class CTimeProvider { public: const float& x0_currentTime; // in seconds @@ -9,4 +9,4 @@ public: CTimeProvider(const float& time); ~CTimeProvider(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CToken.cpp b/Runtime/CToken.cpp index 38bfa24ed..94f756b71 100644 --- a/Runtime/CToken.cpp +++ b/Runtime/CToken.cpp @@ -1,6 +1,6 @@ #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { u16 CObjectReference::RemoveReference() { --x0_refCount; if (x0_refCount == 0) { @@ -155,4 +155,4 @@ CToken::~CToken() { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/CToken.hpp b/Runtime/CToken.hpp index fde3a4435..d56459df3 100644 --- a/Runtime/CToken.hpp +++ b/Runtime/CToken.hpp @@ -8,7 +8,7 @@ #include "Runtime/IVParamObj.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class IObjectStore; /** Shared data-structure for CToken references, analogous to std::shared_ptr */ @@ -185,4 +185,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CBallCamera.cpp b/Runtime/Camera/CBallCamera.cpp index 6a43ab13d..8bc5cdedd 100644 --- a/Runtime/Camera/CBallCamera.cpp +++ b/Runtime/Camera/CBallCamera.cpp @@ -4,12 +4,11 @@ #include #include "Runtime/CStateManager.hpp" -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/rstl.hpp" #include "Runtime/Camera/CFirstPersonCamera.hpp" #include "Runtime/Camera/CPathCamera.hpp" #include "Runtime/Collision/CCollisionActor.hpp" #include "Runtime/Collision/CGameCollision.hpp" +#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Input/ControlMapper.hpp" #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CScriptCameraHint.hpp" @@ -17,10 +16,11 @@ #include "Runtime/World/CScriptDoor.hpp" #include "Runtime/World/CScriptSpindleCamera.hpp" #include "Runtime/World/CScriptWater.hpp" +#include "Runtime/rstl.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { void CCameraSpring::Reset() { x4_k2Sqrt = 2.f * std::sqrt(x0_k); @@ -37,8 +37,9 @@ float CCameraSpring::ApplyDistanceSpring(float targetX, float curX, float dt) { float useX = xc_tardis * x10_dx * dt + curX; x10_dx += xc_tardis * (x0_k * (targetX - curX) - x4_k2Sqrt * x10_dx) * dt; useX = std::max(useX, targetX); - if (useX - targetX > x8_max) + if (useX - targetX > x8_max) { useX = targetX + x8_max; + } return useX; } @@ -98,9 +99,10 @@ void CBallCamera::SetupColliders(std::vector& out, float xMag, float theta = startAngle; for (int i = 0; i < count; ++i) { float z = std::cos(theta) * zMag; - if (theta > M_PIF / 2.f) + if (theta > M_PIF / 2.f) { z *= 0.25f; - out.emplace_back(radius, zeus::CVector3f{std::sin(theta) * xMag, 0.f, z}, CCameraSpring{k, max, 1.f}, 1.f); + } + out.emplace_back(radius, zeus::CVector3f{xMag * std::sin(theta), 0.f, z}, CCameraSpring{k, max, 1.f}, 1.f); theta += 2.f * M_PIF / float(count); } } @@ -112,7 +114,7 @@ void CBallCamera::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CSt switch (msg) { case EScriptObjectMessage::Registered: { x46c_collisionActorId = stateMgr.AllocateUniqueId(); - CCollisionActor* colAct = + auto* colAct = new CCollisionActor(x46c_collisionActorId, GetAreaId(), kInvalidUniqueId, true, 0.3f, 1.f, "BallCamera"sv); colAct->SetMaterialFilter(CMaterialFilter::MakeIncludeExclude( {EMaterialTypes::Solid}, {EMaterialTypes::Player, EMaterialTypes::CameraPassthrough})); @@ -121,8 +123,8 @@ void CBallCamera::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CSt colAct->SetTranslation(GetTranslation()); stateMgr.AddObject(colAct); colAct->SetMovable(false); - CMotionState mState(GetTranslation(), zeus::CNUQuaternion::fromAxisAngle(zeus::skForward, 0.f), - zeus::skZero3f, zeus::CAxisAngle()); + CMotionState mState(GetTranslation(), zeus::CNUQuaternion::fromAxisAngle(zeus::skForward, 0.f), zeus::skZero3f, + zeus::CAxisAngle()); colAct->SetLastNonCollidingState(mState); SetMaterialFilter(CMaterialFilter::MakeIncludeExclude( {}, {EMaterialTypes::Solid, EMaterialTypes::ProjectilePassthrough, EMaterialTypes::Player, @@ -140,31 +142,36 @@ void CBallCamera::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CSt } void CBallCamera::ProcessInput(const CFinalInput& input, CStateManager& mgr) { - if (input.ControllerIdx() != 0) + if (input.ControllerIdx() != 0) { return; + } if (TCastToConstPtr player = mgr.GetObjectById(xe8_watchedObject)) { if (player->GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed) { switch (x400_state) { case EBallCameraState::Chase: - if (!ControlMapper::GetDigitalInput(ControlMapper::ECommands::ChaseCamera, input) || player->IsInFreeLook()) + if (!ControlMapper::GetDigitalInput(ControlMapper::ECommands::ChaseCamera, input) || player->IsInFreeLook()) { SetState(EBallCameraState::Default, mgr); + } break; case EBallCameraState::Boost: - if (!player->GetMorphBall()->IsInBoost()) + if (!player->GetMorphBall()->IsInBoost()) { SetState(EBallCameraState::Default, mgr); + } break; case EBallCameraState::Default: - if (x18c_25_chaseAllowed && ControlMapper::GetPressInput(ControlMapper::ECommands::ChaseCamera, input)) + if (x18c_25_chaseAllowed && ControlMapper::GetPressInput(ControlMapper::ECommands::ChaseCamera, input)) { SetState(EBallCameraState::Chase, mgr); + } break; default: break; } if (x18c_26_boostAllowed && x400_state != EBallCameraState::Boost && - (player->GetMorphBall()->IsInBoost() || player->GetMorphBall()->GetBoostChargeTime() > 0.f)) + (player->GetMorphBall()->IsInBoost() || player->GetMorphBall()->GetBoostChargeTime() > 0.f)) { SetState(EBallCameraState::Boost, mgr); + } } } } @@ -276,10 +283,11 @@ void CBallCamera::BuildSplineNav(CStateManager& mgr) { zeus::CVector3f pt2 = pt1 + (x35c_splineIntermediatePos - GetTranslation()) * (0.5f + downFactor); x37c_camSpline.AddKnot(pt2, zeus::skForward); zeus::CVector3f pt2Ball = ballPos - pt2; - if (pt2Ball.canBeNormalized()) + if (pt2Ball.canBeNormalized()) { pt2Ball.normalize(); - else + } else { pt2Ball = mgr.GetPlayer().GetMoveDir(); + } zeus::CVector3f desiredPosition = FindDesiredPosition(distance, elevation, pt2Ball, mgr, false); x37c_camSpline.AddKnot(desiredPosition, zeus::skForward); x37c_camSpline.UpdateSplineLength(); @@ -320,42 +328,47 @@ void CBallCamera::BuildSplineArc(CStateManager& mgr) { rstl::reserved_vector nearList; CRayCastResult result = mgr.RayWorldIntersection(intersectId, pt1, -delta.normalized(), delta.magnitude(), BallCameraFilter, nearList); - if (result.IsValid()) + if (result.IsValid()) { pt1 = delta.normalized() * 1.5f + result.GetPoint(); - else + } else { pt1 = halfwayPoint + delta; + } x37c_camSpline.AddKnot(pt1, zeus::skForward); FindDesiredPosition(distance, elevation, mgr.GetPlayer().GetMoveDir(), mgr, false); delta = rot.transform(delta); zeus::CVector3f pt2 = halfwayPoint + delta; result = mgr.RayWorldIntersection(intersectId, pt2, -delta.normalized(), delta.magnitude(), BallCameraFilter, nearList); - if (result.IsValid()) + if (result.IsValid()) { pt2 = delta.normalized() * 2.f + result.GetPoint(); - else + } else { pt2 = halfwayPoint + delta; + } x37c_camSpline.AddKnot(pt2, zeus::skForward); delta = rot.transform(delta); zeus::CVector3f pt3 = delta + halfwayPoint; result = mgr.RayWorldIntersection(intersectId, pt3, -delta.normalized(), delta.magnitude(), BallCameraFilter, nearList); - if (result.IsValid()) + if (result.IsValid()) { pt3 = delta.normalized() * 2.f + result.GetPoint(); - else + } else { pt3 = halfwayPoint + delta; + } x37c_camSpline.AddKnot(pt3, zeus::skForward); CMaterialList intersectMat; if (!SplineIntersectTest(intersectMat, mgr) && intersectMat.HasMaterial(EMaterialTypes::Wall)) { delta = pt1 - halfwayPoint; result = mgr.RayWorldIntersection(intersectId, pt1, -delta.normalized(), delta.magnitude(), BallCameraFilter, nearList); - if (result.IsValid() && !result.GetMaterial().HasMaterial(EMaterialTypes::Pillar)) + if (result.IsValid() && !result.GetMaterial().HasMaterial(EMaterialTypes::Pillar)) { x37c_camSpline.SetKnotPosition(1, result.GetPoint() - delta.normalized() * 0.3f * 1.25f); + } delta = pt2 - halfwayPoint; result = mgr.RayWorldIntersection(intersectId, pt2, -delta.normalized(), delta.magnitude(), BallCameraFilter, nearList); - if (result.IsValid() && !result.GetMaterial().HasMaterial(EMaterialTypes::Pillar)) + if (result.IsValid() && !result.GetMaterial().HasMaterial(EMaterialTypes::Pillar)) { x37c_camSpline.SetKnotPosition(2, result.GetPoint() - delta.normalized() * 0.3f * 1.25f); + } x37c_camSpline.UpdateSplineLength(); if (!SplineIntersectTest(intersectMat, mgr)) { x36c_splineState = ESplineState::Invalid; @@ -382,10 +395,11 @@ void CBallCamera::UpdatePlayerMovement(float dt, CStateManager& mgr) { x2f0_ballDelta = ballPos - x2dc_prevBallPos; x2fc_ballDeltaFlat = x2f0_ballDelta; x2fc_ballDeltaFlat.z() = 0.f; - if (x2fc_ballDeltaFlat.canBeNormalized()) + if (x2fc_ballDeltaFlat.canBeNormalized()) { x2e8_ballVelFlat = x2fc_ballDeltaFlat.magnitude() / dt; - else + } else { x2e8_ballVelFlat = 0.f; + } x2dc_prevBallPos = ballPos; x18d_28_obtuseDirection = false; zeus::CVector3f camToBallFlat = ballPos - GetTranslation(); @@ -393,28 +407,33 @@ void CBallCamera::UpdatePlayerMovement(float dt, CStateManager& mgr) { if (camToBallFlat.canBeNormalized()) { camToBallFlat.normalize(); if (std::fabs(std::acos(zeus::clamp(-1.f, camToBallFlat.dot(mgr.GetPlayer().GetMoveDir()), 1.f))) > - zeus::degToRad(100.f)) + zeus::degToRad(100.f)) { x18d_28_obtuseDirection = true; + } } x308_speedFactor = 0.f; float tmpVel = x2e8_ballVelFlat - 4.f; - if (tmpVel > 0.f) + if (tmpVel > 0.f) { x308_speedFactor = zeus::clamp(-1.f, std::fabs(std::sin(zeus::degToRad(tmpVel / (x2ec_maxBallVel - 4.f) * 90.f))), 1.f); + } x190_curMinDistance = x308_speedFactor * (x198_maxDistance - x194_targetMinDistance) + x194_targetMinDistance; - if (x308_speedFactor > 0.5f && mgr.GetPlayer().GetPlayerMovementState() == CPlayer::EPlayerMovementState::OnGround) + if (x308_speedFactor > 0.5f && mgr.GetPlayer().GetPlayerMovementState() == CPlayer::EPlayerMovementState::OnGround) { x30c_speedingTime += dt * x308_speedFactor; - else + } else { x30c_speedingTime = 0.f; + } x30c_speedingTime = zeus::clamp(0.f, x30c_speedingTime, 3.f); } void CBallCamera::UpdateTransform(const zeus::CVector3f& lookDir, const zeus::CVector3f& pos, float dt, CStateManager& mgr) { zeus::CVector3f useLookDir = lookDir; - if (x18d_31_overrideLookDir) - if (const CScriptCameraHint* hint = mgr.GetCameraManager()->GetCameraHint(mgr)) + if (x18d_31_overrideLookDir) { + if (const CScriptCameraHint* hint = mgr.GetCameraManager()->GetCameraHint(mgr)) { useLookDir = hint->GetTransform().basis[1]; + } + } zeus::CVector3f lookDirFlat = useLookDir; lookDirFlat.z() = 0.f; if (!lookDirFlat.canBeNormalized()) { @@ -438,15 +457,18 @@ void CBallCamera::UpdateTransform(const zeus::CVector3f& lookDir, const zeus::CV float maxAngleDelta = (1.f - lookUpDot) * zeus::degToRad(720.f) * dt; if (x36c_splineState == ESplineState::Nav) { maxAngleDelta = zeus::degToRad(240.f) * dt; - if (angleDelta > maxAngleDelta) + if (angleDelta > maxAngleDelta) { angleDelta = maxAngleDelta; + } } - if (angleDelta > maxAngleDelta && !mgr.GetPlayer().IsMorphBallTransitioning() && lookUpDot > 0.999f) + if (angleDelta > maxAngleDelta && !mgr.GetPlayer().IsMorphBallTransitioning() && lookUpDot > 0.999f) { angleDelta = maxAngleDelta; + } switch (x400_state) { case EBallCameraState::Chase: - if (x18c_25_chaseAllowed) + if (x18c_25_chaseAllowed) { angleDelta = dt * x40c_chaseAnglePerSecond * angleSpeedMul; + } break; case EBallCameraState::Boost: angleDelta = dt * x438_boostAnglePerSecond * angleSpeedMul; @@ -475,22 +497,27 @@ zeus::CVector3f CBallCamera::ConstrainYawAngle(const CPlayer& player, float dist lookDir = player.GetMoveDir(); TCastToConstPtr door = mgr.GetObjectById(x3dc_tooCloseActorId); if ((!door || !door->x2a8_26_isOpen) && - (x400_state == EBallCameraState::Boost || x400_state == EBallCameraState::Chase)) + (x400_state == EBallCameraState::Boost || x400_state == EBallCameraState::Chase)) { lookDir = player.GetLeaveMorphDir(); + } } - if (player.GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Unmorphing) + if (player.GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Unmorphing) { lookDir = player.GetLeaveMorphDir(); - if (lookDir.canBeNormalized()) + } + if (lookDir.canBeNormalized()) { lookDir.normalize(); - else + } else { lookDir = -playerToCamFlat; - if (playerToCamFlat.canBeNormalized()) + } + if (playerToCamFlat.canBeNormalized()) { playerToCamFlat.normalize(); - else + } else { return -lookDir; + } float angleProj = zeus::clamp(-1.f, playerToCamFlat.dot(-lookDir), 1.f); - if (angleProj >= 1.f) + if (angleProj >= 1.f) { return -lookDir; + } return zeus::CQuaternion::lookAt(playerToCamFlat, -lookDir, distance * dt * zeus::clamp(0.f, std::acos(angleProj) / yawSpeed, 1.f)) .transform(playerToCamFlat); @@ -516,8 +543,9 @@ void CBallCamera::CheckFailsafe(float dt, CStateManager& mgr) { x35c_splineIntermediatePos = ballPos; if (ShouldResetSpline(mgr) && !x18e_25_noSpline && x350_obscuringMaterial.HasMaterial(EMaterialTypes::Floor) && mgr.RayCollideWorld(ballPos, ballPos + zeus::CVector3f(0.f, 0.f, -2.5f), nearList, BallCameraFilter, - nullptr)) + nullptr)) { BuildSplineNav(mgr); + } } } } else { @@ -527,8 +555,9 @@ void CBallCamera::CheckFailsafe(float dt, CStateManager& mgr) { if (!x18c_31_clearLOS) { x34c_obscuredTime += dt; - if (ShouldResetSpline(mgr) && !x18e_25_noSpline && x350_obscuringMaterial.HasMaterial(EMaterialTypes::Pillar)) + if (ShouldResetSpline(mgr) && !x18e_25_noSpline && x350_obscuringMaterial.HasMaterial(EMaterialTypes::Pillar)) { BuildSplineArc(mgr); + } } else { x34c_obscuredTime = 0.f; } @@ -541,23 +570,27 @@ void CBallCamera::CheckFailsafe(float dt, CStateManager& mgr) { !x18c_31_clearLOS && x36c_splineState == ESplineState::Invalid; bool doFailsafe = x3e4_pendingFailsafe; - if ((GetTranslation() - ballPos).magnitude() < 0.3f + g_tweakPlayer->GetPlayerBallHalfExtent()) + if ((GetTranslation() - ballPos).magnitude() < 0.3f + g_tweakPlayer->GetPlayerBallHalfExtent()) { doFailsafe = true; + } if (x18e_27_nearbyDoorClosed) { x18e_27_nearbyDoorClosed = false; - if (result.IsValid()) + if (result.IsValid()) { doFailsafe = true; + } } if (x18e_28_nearbyDoorClosing) { x18e_28_nearbyDoorClosing = false; - if (IsBallNearDoor(GetTranslation(), mgr)) + if (IsBallNearDoor(GetTranslation(), mgr)) { doFailsafe = true; + } } - if (doFailsafe) + if (doFailsafe) { ActivateFailsafe(dt, mgr); + } } void CBallCamera::UpdateObjectTooCloseId(CStateManager& mgr) { @@ -581,10 +614,11 @@ void CBallCamera::UpdateObjectTooCloseId(CStateManager& mgr) { void CBallCamera::UpdateAnglePerSecond(float dt) { float delta = x1a8_targetAnglePerSecond - x1a4_curAnglePerSecond; - if (std::fabs(delta) >= M_PIF / 1800.f) + if (std::fabs(delta) >= M_PIF / 1800.f) { x1a4_curAnglePerSecond += zeus::clamp(-1.f, delta / M_PIF, 1.f) * (10.471975f * dt); - else + } else { x1a4_curAnglePerSecond = x1a8_targetAnglePerSecond; + } } void CBallCamera::UpdateUsingPathCameras(float dt, CStateManager& mgr) { @@ -596,8 +630,10 @@ void CBallCamera::UpdateUsingPathCameras(float dt, CStateManager& mgr) { zeus::CVector3f CBallCamera::GetFixedLookTarget(const zeus::CVector3f& hintToLookDir, CStateManager& mgr) const { const CScriptCameraHint* hint = mgr.GetCameraManager()->GetCameraHint(mgr); - if (!hint) + if (hint == nullptr) { return hintToLookDir; + } + zeus::CVector3f hintDir = hint->GetTransform().basis[1]; zeus::CVector3f hintDirFlat = hintDir; hintDirFlat.z() = 0.f; @@ -611,10 +647,11 @@ zeus::CVector3f CBallCamera::GetFixedLookTarget(const zeus::CVector3f& hintToLoo zeus::CVector3f hintToLookDirFlat = hintToLookDir; hintToLookDirFlat.z() = 0.f; - if (hintToLookDir.canBeNormalized() && hintToLookDirFlat.canBeNormalized()) + if (hintToLookDir.canBeNormalized() && hintToLookDirFlat.canBeNormalized()) { hintToLookDirFlat.normalize(); - else + } else { hintToLookDirFlat = hintDirFlat; + } float attitude = std::acos(zeus::clamp(-1.f, hintToLookDir.dot(hintToLookDirFlat), 1.f)); if (x18c_29_clampAttitude) { @@ -622,15 +659,18 @@ zeus::CVector3f CBallCamera::GetFixedLookTarget(const zeus::CVector3f& hintToLoo attitude = refAttitude + zeus::clamp(-x1ac_attitudeRange, attitude - refAttitude, x1ac_attitudeRange); } - if (hintToLookDir.z() >= 0.f) + if (hintToLookDir.z() >= 0.f) { attitude = -attitude; + } float azimuth = std::acos(zeus::clamp(-1.f, hintToLookDirFlat.dot(hintDirFlat), 1.f)); - if (x18c_30_clampAzimuth) + if (x18c_30_clampAzimuth) { azimuth = zeus::clamp(-x1b0_azimuthRange, azimuth, x1b0_azimuthRange); + } - if (hintToLookDirFlat.x() * hintDirFlat.y() - hintDirFlat.x() * hintToLookDirFlat.y() >= 0.f) + if (hintToLookDirFlat.x() * hintDirFlat.y() - hintDirFlat.x() * hintToLookDirFlat.y() >= 0.f) { azimuth = -azimuth; + } zeus::CQuaternion quat; quat.rotateZ(azimuth); @@ -647,8 +687,9 @@ void CBallCamera::UpdateUsingFixedCameras(float dt, CStateManager& mgr) { zeus::CVector3f hintToLookPos = x1d8_lookPos - hint->GetTranslation(); if (hintToLookPos.canBeNormalized()) { hintToLookPos = GetFixedLookTarget(hintToLookPos.normalized(), mgr); - if ((hint->GetHint().GetOverrideFlags() & 0x40) != 0) + if ((hint->GetHint().GetOverrideFlags() & 0x40) != 0) { x18d_26_lookAtBall = true; + } UpdateTransform(hintToLookPos, hint->GetTranslation(), dt, mgr); } break; @@ -703,10 +744,11 @@ zeus::CVector3f CBallCamera::MoveCollisionActor(const zeus::CVector3f& pos, floa act->SetVelocityWR(TweenVelocity(oldVel, newVel, 50.f, dt)); CGameCollision::Move(mgr, *act, dt, nullptr); posDelta2 = act->GetTranslation() - pos; - if (posDelta2.magnitude() > 0.1f) + if (posDelta2.magnitude() > 0.1f) { x478_shortMoveCount += 1; - else + } else { x478_shortMoveCount = 0; + } } else { act->Stop(); x478_shortMoveCount = 0; @@ -736,15 +778,17 @@ void CBallCamera::UpdateUsingFreeLook(float dt, CStateManager& mgr) { zeus::CVector3f ballPos = mgr.GetPlayer().GetBallPosition(); zeus::CVector3f knotToBall = ballPos - x37c_camSpline.GetKnotPosition(2); - if (knotToBall.canBeNormalized()) + if (knotToBall.canBeNormalized()) { knotToBall.normalize(); - else + } else { knotToBall = mgr.GetPlayer().GetMoveDir(); + } zeus::CVector3f knot3 = x37c_camSpline.GetKnotPosition(3); zeus::CVector3f desiredPos = FindDesiredPosition(distance, elevation, knotToBall, mgr, false); - if (x370_24_reevalSplineEnd) + if (x370_24_reevalSplineEnd) { x37c_camSpline.SetKnotPosition(3, desiredPos); + } x374_splineCtrl -= dt; @@ -785,7 +829,8 @@ void CBallCamera::UpdateUsingFreeLook(float dt, CStateManager& mgr) { } x37c_camSpline.UpdateSplineLength(); - const zeus::CVector3f pos = x37c_camSpline.GetInterpolatedSplinePointByLength(splineT * x37c_camSpline.x44_length).origin; + const zeus::CVector3f pos = + x37c_camSpline.GetInterpolatedSplinePointByLength(splineT * x37c_camSpline.x44_length).origin; if (const TCastToPtr act = mgr.ObjectById(x46c_collisionActorId)) { CMaterialFilter filter = act->GetMaterialFilter(); CMaterialFilter tmpFilter = filter; @@ -814,8 +859,9 @@ void CBallCamera::UpdateUsingFreeLook(float dt, CStateManager& mgr) { } zeus::CVector3f CBallCamera::InterpolateCameraElevation(const zeus::CVector3f& camPos, float dt) { - if (x1a0_elevation < 2.f) + if (x1a0_elevation < 2.f) { return camPos; + } zeus::CVector3f ret = camPos; if (!x18c_31_clearLOS && x350_obscuringMaterial.HasMaterial(EMaterialTypes::Floor)) { @@ -832,8 +878,9 @@ zeus::CVector3f CBallCamera::InterpolateCameraElevation(const zeus::CVector3f& c zeus::CVector3f CBallCamera::CalculateCollidersCentroid(const std::vector& colliderList, int numObscured) const { - if (colliderList.size() < 3) + if (colliderList.size() < 3) { return zeus::skForward; + } int clearColliders = 0; const CCameraCollider* prevCol = &colliderList.back(); @@ -857,9 +904,10 @@ zeus::CVector3f CBallCamera::CalculateCollidersCentroid(const std::vector(clearColliders / colliderList.size()) <= x330_clearColliderThreshold) { return zeus::skForward; - } else if (0.f != accumCross) { + } + if (0.f != accumCross) { float baryCross = 3.f * accumCross; return {accumX / baryCross, 0.f, accumZ / baryCross}; } @@ -872,55 +920,65 @@ zeus::CVector3f CBallCamera::ApplyColliders() { zeus::CVector3f mediumCentroid = CalculateCollidersCentroid(x274_mediumColliders, x2c8_mediumCollidersObsCount); zeus::CVector3f largeCentroid = CalculateCollidersCentroid(x284_largeColliders, x2cc_largeCollidersObsCount); - if (smallCentroid.y() == 0.f) + if (smallCentroid.y() == 0.f) { x2a0_smallCentroid = smallCentroid; - else + } else { x2a0_smallCentroid = zeus::skZero3f; + } float centroidX = x2a0_smallCentroid.x(); float centroidZ = x2a0_smallCentroid.z(); - if (mediumCentroid.y() == 0.f) + if (mediumCentroid.y() == 0.f) { x2ac_mediumCentroid = mediumCentroid; - else + } else { x2ac_mediumCentroid = zeus::skZero3f; + } centroidX += x2ac_mediumCentroid.x(); centroidZ += x2ac_mediumCentroid.z(); - if (largeCentroid.y() == 0.f) + if (largeCentroid.y() == 0.f) { x2b8_largeCentroid = largeCentroid; - else + } else { x2b8_largeCentroid = zeus::skZero3f; + } centroidX += x2b8_largeCentroid.x(); centroidZ += x2b8_largeCentroid.z(); - if (x18c_31_clearLOS) + if (x18c_31_clearLOS) { centroidX /= 1.5f; + } centroidZ /= 3.f; if (!x18c_31_clearLOS && x368_obscuringObjectId == kInvalidUniqueId) { float xMul = 1.5f; float zMul = 1.f; - if (x350_obscuringMaterial.HasMaterial(EMaterialTypes::Floor)) + if (x350_obscuringMaterial.HasMaterial(EMaterialTypes::Floor)) { zMul += 2.f * x358_unobscureMag; - if (x350_obscuringMaterial.HasMaterial(EMaterialTypes::Wall)) + } + if (x350_obscuringMaterial.HasMaterial(EMaterialTypes::Wall)) { xMul += 3.f * zeus::clamp(0.f, x358_unobscureMag - 0.25f, 1.f); + } centroidX *= xMul; centroidZ *= zMul; } - if (!x18c_28_volumeCollider) + if (!x18c_28_volumeCollider) { return zeus::skZero3f; + } - if (std::fabs(centroidX) < 0.05f) + if (std::fabs(centroidX) < 0.05f) { centroidX = 0.f; - if (std::fabs(centroidZ) < 0.05f) + } + if (std::fabs(centroidZ) < 0.05f) { centroidZ = 0.f; + } - if (x18c_31_clearLOS) + if (x18c_31_clearLOS) { centroidZ *= 0.5f; + } return {centroidX, 0.f, centroidZ}; } @@ -961,13 +1019,15 @@ void CBallCamera::UpdateColliders(const zeus::CTransform& xf, std::vector= 4) + if (x328_avoidGeomCycle >= 4) { x328_avoidGeomCycle = 0; + } return ApplyColliders(); } @@ -1009,17 +1070,20 @@ zeus::CVector3f CBallCamera::AvoidGeometryFull(const zeus::CTransform& xf, zeus::CAABox CBallCamera::CalculateCollidersBoundingBox(const std::vector& colliderList, CStateManager& mgr) const { zeus::CAABox aabb; - for (const CCameraCollider& col : colliderList) + for (const CCameraCollider& col : colliderList) { aabb.accumulateBounds(col.x2c_lastWorldPos); + } aabb.accumulateBounds(mgr.GetPlayer().GetTranslation()); return aabb; } int CBallCamera::CountObscuredColliders(const std::vector& colliderList) const { int ret = 0; - for (const CCameraCollider& c : colliderList) - if (c.x4c_occlusionCount >= 2) + for (const CCameraCollider& c : colliderList) { + if (c.x4c_occlusionCount >= 2) { ++ret; + } + } return ret; } @@ -1028,23 +1092,26 @@ void CBallCamera::UpdateCollidersDistances(std::vector& collide float theta = angOffset; for (CCameraCollider& col : colliderList) { float z = std::cos(theta) * zMag; - if (theta > M_PIF / 2.f) + if (theta > M_PIF / 2.f) { z *= 0.25f; + } col.x14_localPos = {std::sin(theta) * xMag, 0.f, z}; theta += 2.f * M_PIF / float(colliderList.size()); } } void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { - if (mgr.GetPlayer().GetBombJumpCount() == 1) + if (mgr.GetPlayer().GetBombJumpCount() == 1) { return; + } zeus::CVector3f ballPos = mgr.GetPlayer().GetBallPosition(); if (mgr.GetPlayer().GetBombJumpCount() == 2) { zeus::CVector3f camToLookDir = x1d8_lookPos - GetTranslation(); - if (x18d_26_lookAtBall) + if (x18d_26_lookAtBall) { camToLookDir = ballPos - GetTranslation(); + } if (camToLookDir.canBeNormalized()) { camToLookDir.normalize(); @@ -1052,7 +1119,7 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { } } else if (mgr.GetPlayer().GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Unmorphed || x18d_25_avoidGeometryFull) { - //zeus::CTransform oldXf = x34_transform; + // zeus::CTransform oldXf = x34_transform; zeus::CVector3f oldPos = GetTranslation(); x2c4_smallCollidersObsCount = CountObscuredColliders(x264_smallColliders); x2c8_mediumCollidersObsCount = CountObscuredColliders(x274_mediumColliders); @@ -1061,14 +1128,16 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { zeus::CVector3f ballToCamFlat = GetTranslation() - ballPos; ballToCamFlat.z() = 0.f; float ballToCamFlatMag = 0.f; - if (ballToCamFlat.canBeNormalized()) + if (ballToCamFlat.canBeNormalized()) { ballToCamFlatMag = ballToCamFlat.magnitude(); - else + } else { ballToCamFlat = -mgr.GetPlayer().GetMoveDir(); + } posAtBallLevel = GetTranslation() - posAtBallLevel; zeus::CTransform ballToUnderCamLook; - if ((posAtBallLevel - ballPos).canBeNormalized()) + if ((posAtBallLevel - ballPos).canBeNormalized()) { ballToUnderCamLook = zeus::lookAt(ballPos, posAtBallLevel); + } float distance = x214_ballCameraSpring.ApplyDistanceSpring(x190_curMinDistance, ballToCamFlatMag, (3.f + x308_speedFactor) * dt); zeus::CVector3f camToBall = ballPos - GetTranslation(); @@ -1091,10 +1160,12 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { if (x34c_obscuredTime > 0.f || x350_obscuringMaterial.HasMaterial(EMaterialTypes::Floor) || x350_obscuringMaterial.HasMaterial(EMaterialTypes::Wall)) { x32c_colliderMag += 2.f * dt; - if (x32c_colliderMag < 2.f) + if (x32c_colliderMag < 2.f) { x32c_colliderMag = 2.f; - if (x32c_colliderMag > 2.f) + } + if (x32c_colliderMag > 2.f) { x32c_colliderMag = 2.f; + } UpdateCollidersDistances(x264_smallColliders, 2.31f * x32c_colliderMag, 2.31f * x32c_colliderMag * 0.5f, -M_PIF / 2.f); UpdateCollidersDistances(x274_mediumColliders, 4.62f * x32c_colliderMag, 4.62f * x32c_colliderMag * 0.5f, @@ -1104,8 +1175,9 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { } } else { float targetColliderMag = 1.f; - if (x18d_24_prevClearLOS && mgr.GetPlayer().GetMoveSpeed() < 1.f) + if (x18d_24_prevClearLOS && mgr.GetPlayer().GetMoveSpeed() < 1.f) { targetColliderMag = 0.25f; + } x32c_colliderMag += (targetColliderMag - x32c_colliderMag) * dt * 2.f; UpdateCollidersDistances(x264_smallColliders, x32c_colliderMag * 2.31f, x32c_colliderMag * 2.31f, -M_PIF / 2.f); UpdateCollidersDistances(x274_mediumColliders, x32c_colliderMag * 4.62f, x32c_colliderMag * 4.62f, -M_PIF / 2.f); @@ -1120,10 +1192,11 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { if (!door->x2a8_26_isOpen) { if (x400_state == EBallCameraState::Boost) { zeus::CVector3f ballToCam = GetTranslation() - ballPos; - if (ballToCam.canBeNormalized()) + if (ballToCam.canBeNormalized()) { ballToCam.normalize(); - else + } else { ballToCam = GetTransform().basis[1]; + } if (std::fabs(ballToCamFlatMag - x430_boostElevation) < 1.f) { ballToCam = ConstrainYawAngle(mgr.GetPlayer(), g_tweakBall->GetBallCameraBoostDistance(), g_tweakBall->GetBallCameraBoostYawSpeed(), dt, mgr); @@ -1138,10 +1211,11 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { if (x18c_25_chaseAllowed && (x400_state == EBallCameraState::Chase || x188_behaviour == EBallCameraBehaviour::FreezeLookPosition)) { zeus::CVector3f ballToCam = GetTranslation() - ballPos; - if (ballToCam.canBeNormalized()) + if (ballToCam.canBeNormalized()) { ballToCam.normalize(); - else + } else { ballToCam = GetTransform().basis[1]; + } if (std::fabs(ballToCamFlatMag - x404_chaseElevation) < 3.f) { ballToCam = ConstrainYawAngle(mgr.GetPlayer(), g_tweakBall->GetBallCameraChaseDistance(), g_tweakBall->GetBallCameraChaseYawSpeed(), dt, mgr); @@ -1160,15 +1234,17 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { desiredBallToCam = x45c_overrideBallToCam; if (x18c_27_obscureAvoidance) { zeus::CVector3f ballToCamDir = x45c_overrideBallToCam; - if (ballToCamDir.canBeNormalized()) + if (ballToCamDir.canBeNormalized()) { ballToCamDir.normalize(); - else + } else { ballToCamDir = -mgr.GetPlayer().GetMoveDir(); + } TUniqueId intersectId = kInvalidUniqueId; CRayCastResult result = mgr.RayWorldIntersection(intersectId, ballPos, ballToCamDir, distance, BallCameraFilter, nearList); - if (result.IsValid()) + if (result.IsValid()) { desiredBallToCam = ballToCamDir * result.GetT() * 0.9f; + } } noDoor = false; } @@ -1191,52 +1267,62 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { x1e4_nextLookXf = lookXf; lookXf = oldLookXf; zeus::CVector3f colliderPointLocal; - if (x18d_25_avoidGeometryFull || !x18c_31_clearLOS) + if (x18d_25_avoidGeometryFull || !x18c_31_clearLOS) { colliderPointLocal = AvoidGeometryFull(lookXf, nearList, dt, mgr); - else + } else { colliderPointLocal = AvoidGeometry(lookXf, nearList, dt, mgr); + } zeus::CVector3f ballToCam2 = GetTranslation() - ballPos; ballToCam2.z() = 0.f; if (ballToCam2.magnitude() < 2.f) { - if (x18c_31_clearLOS && x478_shortMoveCount > 2) + if (x18c_31_clearLOS && x478_shortMoveCount > 2) { colliderPointLocal = colliderPointLocal / float(x478_shortMoveCount); + } if (d < 3.f) { colliderPointLocal = colliderPointLocal * 0.25f; - if (x18c_31_clearLOS && x478_shortMoveCount > 0) + if (x18c_31_clearLOS && x478_shortMoveCount > 0) { colliderPointLocal = colliderPointLocal * x308_speedFactor; + } } - if (d < 1.f) + if (d < 1.f) { colliderPointLocal = zeus::skZero3f; + } } zeus::CVector3f camDelta = lookXf.rotate(colliderPointLocal) + desiredCamPos - ballPos; - if (camDelta.canBeNormalized()) + if (camDelta.canBeNormalized()) { camDelta.normalize(); + } zeus::CVector3f desiredPos = camDelta * distance + ballPos; - if (x188_behaviour == EBallCameraBehaviour::PathCameraDesiredPos) - if (TCastToConstPtr cam = mgr.GetObjectById(mgr.GetCameraManager()->GetPathCameraId())) + if (x188_behaviour == EBallCameraBehaviour::PathCameraDesiredPos) { + if (TCastToConstPtr cam = mgr.GetObjectById(mgr.GetCameraManager()->GetPathCameraId())) { desiredPos = cam->GetTranslation(); + } + } camDelta = x294_dampedPos - desiredPos; float camDeltaMag = camDelta.magnitude(); - if (camDelta.canBeNormalized()) + if (camDelta.canBeNormalized()) { camDelta.normalize(); + } x294_dampedPos = camDelta * x228_ballCameraCentroidSpring.ApplyDistanceSpring(0.f, camDeltaMag, dt) + desiredPos; zeus::CVector3f posDelta = oldPos - x294_dampedPos; camDeltaMag = posDelta.magnitude(); - if (posDelta.canBeNormalized()) + if (posDelta.canBeNormalized()) { posDelta.normalize(); + } float cDistSpringMag = x250_ballCameraCentroidDistanceSpring.ApplyDistanceSpring( 0.f, camDeltaMag, (x18d_28_obtuseDirection ? 3.f : 1.f) * dt); - if (x400_state == EBallCameraState::Boost) + if (x400_state == EBallCameraState::Boost) { cDistSpringMag = x448_ballCameraBoostSpring.ApplyDistanceSpring(0.f, camDeltaMag, dt); - else if (x18c_25_chaseAllowed && - (x400_state == EBallCameraState::Chase || x188_behaviour == EBallCameraBehaviour::FreezeLookPosition)) + } else if (x18c_25_chaseAllowed && + (x400_state == EBallCameraState::Chase || x188_behaviour == EBallCameraBehaviour::FreezeLookPosition)) { cDistSpringMag = x41c_ballCameraChaseSpring.ApplyDistanceSpring(0.f, camDeltaMag, dt); + } zeus::CVector3f finalPos = posDelta * cDistSpringMag + x294_dampedPos; if (mgr.GetPlayer().GetMorphBall()->GetSpiderBallState() != CMorphBall::ESpiderBallState::Active && @@ -1246,23 +1332,29 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { finalPos = oldPos + delta; } - if (noDoor && x400_state != EBallCameraState::ToBall) + if (noDoor && x400_state != EBallCameraState::ToBall) { finalPos = InterpolateCameraElevation(finalPos, dt); + } - if (x18d_29_noElevationInterp) + if (x18d_29_noElevationInterp) { finalPos.z() = elevation + ballPos.z(); + } if (ballToCam2.magnitude() < 2.f) { - if (finalPos.z() < 2.f + ballPos.z()) + if (finalPos.z() < 2.f + ballPos.z()) { finalPos.z() = 2.f + ballPos.z(); + } x214_ballCameraSpring.Reset(); } finalPos = ClampElevationToWater(finalPos, mgr); - if (ballToCam2.magnitude() < 2.f && x3dc_tooCloseActorId != kInvalidUniqueId && x3e0_tooCloseActorDist < 5.f) - if (TCastToConstPtr door = mgr.GetObjectById(x3dc_tooCloseActorId)) - if (!door->x2a8_26_isOpen) + if (ballToCam2.magnitude() < 2.f && x3dc_tooCloseActorId != kInvalidUniqueId && x3e0_tooCloseActorDist < 5.f) { + if (TCastToConstPtr door = mgr.GetObjectById(x3dc_tooCloseActorId)) { + if (!door->x2a8_26_isOpen) { finalPos = GetTranslation(); + } + } + } float backupZ = finalPos.z(); finalPos = MoveCollisionActor(finalPos, dt, mgr); @@ -1273,15 +1365,17 @@ void CBallCamera::UpdateUsingColliders(float dt, CStateManager& mgr) { } zeus::CVector3f lookDir = x1d8_lookPos - finalPos; - if (x18d_26_lookAtBall) + if (x18d_26_lookAtBall) { lookDir = ballPos - finalPos; + } if (lookDir.canBeNormalized()) { lookDir.normalize(); UpdateTransform(lookDir, finalPos, dt, mgr); } - if (x470_clampVelTimer > 0.f) + if (x470_clampVelTimer > 0.f) { x470_clampVelTimer -= dt; + } } } @@ -1386,10 +1480,11 @@ void CBallCamera::UpdateUsingTransitions(float dt, CStateManager& mgr) { float yawSpeed = M_PIF; zeus::CVector3f playerToCamDir = GetTranslation() - mgr.GetPlayer().GetTranslation(); zeus::CVector3f moveDir = mgr.GetPlayer().GetMoveDir(); - if (playerToCamDir.canBeNormalized()) + if (playerToCamDir.canBeNormalized()) { playerToCamDir.normalize(); - else + } else { playerToCamDir = -moveDir; + } if (moveDir.canBeNormalized()) { moveDir.normalize(); yawSpeed = std::fabs(std::acos(zeus::clamp(-1.f, playerToCamDir.dot(-moveDir), 1.f))) * morphT / dt; @@ -1405,10 +1500,11 @@ void CBallCamera::UpdateUsingTransitions(float dt, CStateManager& mgr) { finalToBall.z() = 0.f; zeus::CVector3f lookPos = ballPos; lookPos.z() = morphT * (eyePos.z() - ballPos.z()) + ballPos.z(); - if (finalToBall.canBeNormalized()) + if (finalToBall.canBeNormalized()) { SetTransform(zeus::lookAt(finalPos, lookPos)); - else + } else { SetTransform(mgr.GetCameraManager()->GetFirstPersonCamera()->GetTransform()); + } } else { SetTransform(mgr.GetCameraManager()->GetFirstPersonCamera()->GetTransform()); } @@ -1441,7 +1537,7 @@ zeus::CTransform CBallCamera::UpdateCameraPositions(float dt, const zeus::CTrans } zeus::CVector3f CBallCamera::GetFailsafeSplinePoint(const std::vector& points, float t) { - t *= (points.size() - 3); + t *= float(points.size() - 3); int baseIdx = 0; while (t > 1.f) { t -= 1.f; @@ -1476,10 +1572,12 @@ bool CBallCamera::CheckFailsafeFromMorphBallState(CStateManager& mgr) const { const CRayCastResult& resB = resultsB[i]; if (resA.IsValid()) { zeus::CVector3f separation = resA.GetPoint() - resB.GetPoint(); - if (separation.magnitude() < 0.00001f) + if (separation.magnitude() < 0.00001f) { separation = GetFailsafeSplinePoint(x47c_failsafeState->x90_splinePoints, (1.f + i) / 6.f) - resA.GetPoint(); - if (separation.magnitude() > 0.3f) + } + if (separation.magnitude() > 0.3f) { return false; + } } } return true; @@ -1513,8 +1611,9 @@ bool CBallCamera::SplineIntersectTest(CMaterialList& intersectMat, CStateManager const CRayCastResult& resB = xd10[i]; if (resA.IsValid()) { zeus::CVector3f xdd4 = resA.GetPoint() - resB.GetPoint(); - if (xdd4.magnitude() < 0.00001f) + if (xdd4.magnitude() < 0.00001f) { xdd4 = x37c_camSpline.GetInterpolatedSplinePointByTime(1.f + i, 12.f) - resA.GetPoint(); + } if (xdd4.magnitude() > 0.3f) { intersectMat = resA.GetMaterial(); return false; @@ -1562,10 +1661,11 @@ void CBallCamera::ActivateFailsafe(float dt, CStateManager& mgr) { bool CBallCamera::ConstrainElevationAndDistance(float& elevation, float& distance, float dt, CStateManager& mgr) { zeus::CVector3f ballToCam = GetTranslation() - mgr.GetPlayer().GetBallPosition(); float ballToCamMag = 0.f; - if (ballToCam.canBeNormalized()) + if (ballToCam.canBeNormalized()) { ballToCamMag = ballToCam.toVec2f().magnitude(); - else + } else { ballToCam = -mgr.GetPlayer().GetMoveDir(); + } bool doorClose = false; float stretchFac = 1.f; @@ -1601,12 +1701,14 @@ bool CBallCamera::ConstrainElevationAndDistance(float& elevation, float& distanc zeus::CVector3f CBallCamera::FindDesiredPosition(float distance, float elevation, const zeus::CVector3f& dir, CStateManager& mgr, bool fullTest) { TCastToConstPtr player = mgr.GetObjectById(xe8_watchedObject); - if (!player) - return {}; + if (!player) { + return zeus::skZero3f; + } zeus::CVector3f useDir = dir; - if (!dir.canBeNormalized()) + if (!dir.canBeNormalized()) { useDir = zeus::skForward; + } zeus::CTransform lookDirXf = zeus::lookAt(zeus::skZero3f, useDir); zeus::CVector3f ballPos = player->GetBallPosition(); @@ -1614,8 +1716,9 @@ zeus::CVector3f CBallCamera::FindDesiredPosition(float distance, float elevation float dist = distance; ConstrainElevationAndDistance(elev, dist, 0.f, mgr); zeus::CVector3f eyePos = player->GetEyePosition(); - if (!mgr.RayCollideWorld(ballPos, eyePos, BallCameraFilter, nullptr)) + if (!mgr.RayCollideWorld(ballPos, eyePos, BallCameraFilter, nullptr)) { eyePos = ballPos; + } zeus::CVector3f idealLookVec(0.f, -dist, elev - (eyePos.z() - ballPos.z())); idealLookVec = lookDirXf.getRotation() * idealLookVec; @@ -1647,14 +1750,16 @@ zeus::CVector3f CBallCamera::FindDesiredPosition(float distance, float elevation foundClear = true; lookVec = lookVecNeg; break; - } else if (mgr.RayCollideWorld(eyePos, eyePos + lookVecPos, nearList, BallCameraFilter, nullptr)) { + } + + if (mgr.RayCollideWorld(eyePos, eyePos + lookVecPos, nearList, BallCameraFilter, nullptr)) { foundClear = true; lookVec = lookVecPos; break; - } else { - lookVecNeg = xfNeg * lookVecNeg; - lookVecPos = xfPos * lookVecPos; } + + lookVecNeg = xfNeg * lookVecNeg; + lookVecPos = xfPos * lookVecPos; } idealLookDist -= 0.3f; } @@ -1717,14 +1822,15 @@ zeus::CVector3f CBallCamera::FindDesiredPosition(float distance, float elevation foundClear = true; lookVec = lookVecNeg2; break; - } else if (mgr.RayCollideWorld(eyePos, eyePos + lookVecPos2, nearList, BallCameraFilter, nullptr)) { + } + if (mgr.RayCollideWorld(eyePos, eyePos + lookVecPos2, nearList, BallCameraFilter, nullptr)) { foundClear = true; lookVec = lookVecPos2; break; - } else { - lookVecNeg2 = xfNeg2 * lookVecNeg2; - lookVecPos2 = xfPos2 * lookVecPos2; } + + lookVecNeg2 = xfNeg2 * lookVecNeg2; + lookVecPos2 = xfPos2 * lookVecPos2; } idealLookDist -= 0.3f; } @@ -1732,10 +1838,11 @@ zeus::CVector3f CBallCamera::FindDesiredPosition(float distance, float elevation } } - if (!foundClear) + if (!foundClear) { return GetTranslation(); - else - return eyePos + lookVec; + } + + return eyePos + lookVec; } bool CBallCamera::DetectCollision(const zeus::CVector3f& from, const zeus::CVector3f& to, float radius, float& d, @@ -1755,8 +1862,9 @@ bool CBallCamera::DetectCollision(const zeus::CVector3f& from, const zeus::CVect mgr.BuildColliderList(nearList, mgr.GetPlayer(), aabb); CAreaCollisionCache cache(aabb); CGameCollision::BuildAreaCollisionCache(mgr, cache); - if (cache.HasCacheOverflowed()) + if (cache.HasCacheOverflowed()) { clear = false; + } CCollidableSphere cSphere({zeus::skZero3f, radius}, {EMaterialTypes::Solid}); if (CGameCollision::DetectCollisionBoolean_Cached( mgr, cache, cSphere, zeus::CTransform::Translate(from), @@ -1796,19 +1904,22 @@ void CBallCamera::Think(float dt, CStateManager& mgr) { switch (mgr.GetPlayer().GetCameraState()) { default: if (!x18d_27_forceProcessing) { - if (colAct) + if (colAct) { colAct->SetActive(false); + } return; } [[fallthrough]]; case CPlayer::EPlayerCameraState::Ball: case CPlayer::EPlayerCameraState::Transitioning: case CPlayer::EPlayerCameraState::Two: { - if (colAct) + if (colAct) { colAct->SetActive(true); + } zeus::CTransform oldXf = x34_transform; - if (mgr.GetPlayer().GetBombJumpCount() != 1) + if (mgr.GetPlayer().GetBombJumpCount() != 1) { UpdateLookAtPosition(dt, mgr); + } CheckFailsafe(dt, mgr); UpdateObjectTooCloseId(mgr); UpdateAnglePerSecond(dt); @@ -1828,10 +1939,11 @@ void CBallCamera::Think(float dt, CStateManager& mgr) { case EBallCameraBehaviour::Default: case EBallCameraBehaviour::FreezeLookPosition: case EBallCameraBehaviour::HintBallToCam: - if (x36c_splineState != ESplineState::Invalid) + if (x36c_splineState != ESplineState::Invalid) { UpdateUsingFreeLook(dt, mgr); - else + } else { UpdateUsingColliders(dt, mgr); + } break; case EBallCameraBehaviour::SpindleCamera: UpdateUsingSpindleCameras(dt, mgr); @@ -1870,8 +1982,9 @@ bool CBallCamera::CheckTransitionLineOfSight(const zeus::CVector3f& eyePos, cons mgr.BuildColliderList(nearList, mgr.GetPlayer(), aabb); CAreaCollisionCache cache(aabb); CGameCollision::BuildAreaCollisionCache(mgr, cache); - if (cache.HasCacheOverflowed()) + if (cache.HasCacheOverflowed()) { clear = false; + } if (clear) { CCollisionInfo cinfo; double d = eyeToBehindMag; @@ -1899,11 +2012,12 @@ bool CBallCamera::TransitionFromMorphBallState(CStateManager& mgr) { zeus::CVector3f eyePos = mgr.GetPlayer().GetEyePosition(); float lookDist = (x47c_failsafeState->x60_lookPos - x47c_failsafeState->x30_camXf.origin).magnitude(); zeus::CVector3f behindPos = x47c_failsafeState->x0_playerXf.basis[1] * (0.6f * -lookDist) + eyePos; - float eyeToOccDist; - if (CheckTransitionLineOfSight(eyePos, behindPos, eyeToOccDist, 0.6f, mgr)) + float eyeToOccDist = 0.f; + if (CheckTransitionLineOfSight(eyePos, behindPos, eyeToOccDist, 0.6f, mgr)) { x47c_failsafeState->x6c_behindPos = x47c_failsafeState->x0_playerXf.basis[1] * -eyeToOccDist + eyePos; - else + } else { x47c_failsafeState->x6c_behindPos = behindPos; + } x47c_failsafeState->x90_splinePoints.clear(); x47c_failsafeState->x90_splinePoints.reserve(4); x47c_failsafeState->x90_splinePoints.push_back(x47c_failsafeState->x30_camXf.origin); @@ -1981,25 +2095,30 @@ void CBallCamera::UpdateLookAtPosition(float dt, CStateManager& mgr) { dirNorm.normalize(); zeus::CVector3f lookAtOffsetAhead(x308_speedFactor * x1b4_lookAtOffset.x(), x308_speedFactor * x1b4_lookAtOffset.y(), x1b4_lookAtOffset.z()); - if (x18c_25_chaseAllowed && (x400_state == EBallCameraState::Chase || x400_state == EBallCameraState::One)) + if (x18c_25_chaseAllowed && (x400_state == EBallCameraState::Chase || x400_state == EBallCameraState::One)) { lookAtOffsetAhead = zeus::CVector3f(x308_speedFactor * x410_chaseLookAtOffset.x(), x308_speedFactor * x410_chaseLookAtOffset.y(), x410_chaseLookAtOffset.z()); - if (mgr.GetCameraManager()->IsInterpolationCameraActive()) + } + if (mgr.GetCameraManager()->IsInterpolationCameraActive()) { lookAtOffsetAhead = zeus::CVector3f(0.f, 0.f, x1b4_lookAtOffset.z()); + } zeus::CTransform moveXf = player->CreateTransformFromMovementDirection().getRotation(); - if (x2fc_ballDeltaFlat.canBeNormalized()) + if (x2fc_ballDeltaFlat.canBeNormalized()) { lookAtOffsetAhead = moveXf * lookAtOffsetAhead; + } zeus::CVector3f lookAtPosAhead = ballPos + lookAtOffsetAhead; x1c0_lookPosAhead = lookAtPosAhead; x1cc_fixedLookPos = ballPos + zeus::CVector3f(0.f, 0.f, lookAtOffsetAhead.z()); zeus::CVector3f aheadToCurrentLookDelta = x1d8_lookPos - lookAtPosAhead; float aheadToCurrentLookMag = aheadToCurrentLookDelta.magnitude(); - if (aheadToCurrentLookDelta.canBeNormalized()) + if (aheadToCurrentLookDelta.canBeNormalized()) { aheadToCurrentLookDelta.normalize(); + } float lookAtSpringMag = x23c_ballCameraLookAtSpring.ApplyDistanceSpringNoMax( 0.f, aheadToCurrentLookMag, (2.f * zeus::clamp(0.f, x30c_speedingTime / 3.f, 1.f) + 1.f) * dt); - if (lookAtSpringMag > 0.0001f) + if (lookAtSpringMag > 0.0001f) { lookAtPosAhead += aheadToCurrentLookDelta * lookAtSpringMag; + } aheadToCurrentLookDelta = lookAtPosAhead - x1d8_lookPos; if (x18d_26_lookAtBall) { x1d8_lookPos = ballPos; @@ -2047,8 +2166,9 @@ void CBallCamera::UpdateLookAtPosition(float dt, CStateManager& mgr) { zeus::CTransform CBallCamera::UpdateLookDirection(const zeus::CVector3f& dir, CStateManager& mgr) { zeus::CVector3f useDir = dir; - if (!dir.canBeNormalized()) + if (!dir.canBeNormalized()) { useDir = zeus::skForward; + } float elevation = x1a0_elevation; float distance = x190_curMinDistance; ConstrainElevationAndDistance(elevation, distance, 0.f, mgr); @@ -2065,25 +2185,32 @@ void CBallCamera::ApplyCameraHint(CStateManager& mgr) { x18c_26_boostAllowed = (hint->GetHint().GetOverrideFlags() & 0x4) != 0; x18c_27_obscureAvoidance = (hint->GetHint().GetOverrideFlags() & 0x8) != 0; x18c_28_volumeCollider = (hint->GetHint().GetOverrideFlags() & 0x10) != 0; - if ((hint->GetHint().GetOverrideFlags() & 0x40) != 0) + if ((hint->GetHint().GetOverrideFlags() & 0x40) != 0) { x18d_26_lookAtBall = true; + } x18d_29_noElevationInterp = (hint->GetHint().GetOverrideFlags() & 0x4000) != 0; x18d_30_directElevation = (hint->GetHint().GetOverrideFlags() & 0x8000) != 0; x18d_31_overrideLookDir = (hint->GetHint().GetOverrideFlags() & 0x10000) != 0; x18e_24_noElevationVelClamp = (hint->GetHint().GetOverrideFlags() & 0x20000) != 0; x18e_25_noSpline = x18e_26_ = (hint->GetHint().GetOverrideFlags() & 0x80000) != 0; - if ((hint->GetHint().GetOverrideFlags() & 0x400000) != 0) + if ((hint->GetHint().GetOverrideFlags() & 0x400000) != 0) { x194_targetMinDistance = hint->GetHint().GetMinDist(); - if ((hint->GetHint().GetOverrideFlags() & 0x800000) != 0) + } + if ((hint->GetHint().GetOverrideFlags() & 0x800000) != 0) { x198_maxDistance = hint->GetHint().GetMaxDist(); - if ((hint->GetHint().GetOverrideFlags() & 0x1000000) != 0) + } + if ((hint->GetHint().GetOverrideFlags() & 0x1000000) != 0) { x19c_backwardsDistance = hint->GetHint().GetBackwardsDist(); - if ((hint->GetHint().GetOverrideFlags() & 0x80000000) != 0) + } + if ((hint->GetHint().GetOverrideFlags() & 0x80000000) != 0) { x1a0_elevation = hint->GetHint().GetElevation(); - if ((hint->GetHint().GetOverrideFlags() & 0x2000000) != 0) + } + if ((hint->GetHint().GetOverrideFlags() & 0x2000000) != 0) { x1b4_lookAtOffset = hint->GetHint().GetLookAtOffset(); - if ((hint->GetHint().GetOverrideFlags() & 0x4000000) != 0) + } + if ((hint->GetHint().GetOverrideFlags() & 0x4000000) != 0) { x410_chaseLookAtOffset = hint->GetHint().GetChaseLookAtOffset(); + } if ((hint->GetHint().GetOverrideFlags() & 0x10000000) != 0) { x18c_29_clampAttitude = true; x1ac_attitudeRange = hint->GetHint().GetAttitudeRange(); @@ -2096,14 +2223,17 @@ void CBallCamera::ApplyCameraHint(CStateManager& mgr) { } else { x18c_30_clampAzimuth = false; } - if ((hint->GetHint().GetOverrideFlags() & 0x8000000) != 0) + if ((hint->GetHint().GetOverrideFlags() & 0x8000000) != 0) { SetFovInterpolation(x15c_currentFov, hint->GetHint().GetFov(), 1.f, 0.f); - if ((hint->GetHint().GetOverrideFlags() & 0x40000000) != 0) + } + if ((hint->GetHint().GetOverrideFlags() & 0x40000000) != 0) { x1a8_targetAnglePerSecond = hint->GetHint().GetAnglePerSecond(); - if ((hint->GetHint().GetOverrideFlags() & 0x200) != 0) + } + if ((hint->GetHint().GetOverrideFlags() & 0x200) != 0) { mgr.GetPlayer().SetControlDirectionInterpolation(hint->GetHint().GetControlInterpDur()); - else + } else { mgr.GetPlayer().ResetControlDirectionInterpolation(); + } switch (hint->GetHint().GetBehaviourType()) { case EBallCameraBehaviour::HintBallToCam: { x45c_overrideBallToCam = hint->GetHint().GetBallToCam(); @@ -2129,10 +2259,11 @@ void CBallCamera::ApplyCameraHint(CStateManager& mgr) { zeus::CVector3f lookDir = mgr.GetPlayer().GetTranslation() - mgr.GetCameraManager()->GetCurrentCameraTransform(mgr).origin; lookDir.z() = 0.f; - if (lookDir.canBeNormalized()) + if (lookDir.canBeNormalized()) { lookDir.normalize(); - else + } else { lookDir = mgr.GetPlayer().GetMoveDir(); + } TeleportCamera(UpdateLookDirection(lookDir, mgr), mgr); } else { TeleportCamera(zeus::lookAt(hint->GetTranslation(), x1d8_lookPos), mgr); @@ -2162,8 +2293,9 @@ void CBallCamera::ApplyCameraHint(CStateManager& mgr) { break; } - if ((hint->GetHint().GetOverrideFlags() & 0x20) != 0) + if ((hint->GetHint().GetOverrideFlags() & 0x20) != 0) { mgr.GetCameraManager()->SetPlayerCamera(mgr, GetUniqueId()); + } } } @@ -2175,15 +2307,17 @@ void CBallCamera::ResetPosition(CStateManager& mgr) { } void CBallCamera::DoorClosed(TUniqueId doorId) { - if (doorId != x3dc_tooCloseActorId) + if (doorId != x3dc_tooCloseActorId) { return; + } x18e_27_nearbyDoorClosed = true; } void CBallCamera::DoorClosing(TUniqueId doorId) { - if (doorId != x3dc_tooCloseActorId) + if (doorId != x3dc_tooCloseActorId) { return; + } x18e_28_nearbyDoorClosing = true; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CBallCamera.hpp b/Runtime/Camera/CBallCamera.hpp index 6fdc1e338..503aa5f13 100644 --- a/Runtime/Camera/CBallCamera.hpp +++ b/Runtime/Camera/CBallCamera.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CPlayer; class CCameraSpring { @@ -150,12 +150,12 @@ private: zeus::CVector3f x35c_splineIntermediatePos; TUniqueId x368_obscuringObjectId = kInvalidUniqueId; ESplineState x36c_splineState = ESplineState::Invalid; - bool x370_24_reevalSplineEnd : 1; + bool x370_24_reevalSplineEnd : 1 = false; float x374_splineCtrl = 0.f; float x378_splineCtrlRange; CCameraSpline x37c_camSpline{false}; CMaterialList x3c8_collisionExcludeList = {EMaterialTypes::NoStepLogic}; - bool x3d0_24_camBehindFloorOrWall : 1; + bool x3d0_24_camBehindFloorOrWall : 1 = false; float x3d4_elevInterpTimer = 0.f; float x3d8_elevInterpStart = 0.f; TUniqueId x3dc_tooCloseActorId = kInvalidUniqueId; @@ -202,12 +202,13 @@ private: void UpdateUsingPathCameras(float dt, CStateManager& mgr); zeus::CVector3f GetFixedLookTarget(const zeus::CVector3f& hintToLookDir, CStateManager& mgr) const; void UpdateUsingFixedCameras(float dt, CStateManager& mgr); - zeus::CVector3f ComputeVelocity(const zeus::CVector3f& curVel, const zeus::CVector3f& posDelta) const; + [[nodiscard]] zeus::CVector3f ComputeVelocity(const zeus::CVector3f& curVel, const zeus::CVector3f& posDelta) const; zeus::CVector3f TweenVelocity(const zeus::CVector3f& curVel, const zeus::CVector3f& newVel, float rate, float dt); zeus::CVector3f MoveCollisionActor(const zeus::CVector3f& pos, float dt, CStateManager& mgr); void UpdateUsingFreeLook(float dt, CStateManager& mgr); zeus::CVector3f InterpolateCameraElevation(const zeus::CVector3f& camPos, float dt); - zeus::CVector3f CalculateCollidersCentroid(const std::vector& colliderList, int numObscured) const; + [[nodiscard]] zeus::CVector3f CalculateCollidersCentroid(const std::vector& colliderList, + int numObscured) const; zeus::CVector3f ApplyColliders(); void UpdateColliders(const zeus::CTransform& xf, std::vector& colliderList, int& it, int count, float tolerance, const rstl::reserved_vector& nearList, float dt, @@ -218,7 +219,7 @@ private: float dt, CStateManager& mgr); zeus::CAABox CalculateCollidersBoundingBox(const std::vector& colliderList, CStateManager& mgr) const; - int CountObscuredColliders(const std::vector& colliderList) const; + [[nodiscard]] int CountObscuredColliders(const std::vector& colliderList) const; void UpdateCollidersDistances(std::vector& colliderList, float xMag, float zMag, float angOffset); void UpdateUsingColliders(float dt, CStateManager& mgr); void UpdateUsingSpindleCameras(float dt, CStateManager& mgr); @@ -248,16 +249,16 @@ public: void ProcessInput(const CFinalInput& input, CStateManager& mgr) override; void Reset(const zeus::CTransform&, CStateManager& mgr) override; void Render(CStateManager& mgr) override; - EBallCameraBehaviour GetBehaviour() const { return x188_behaviour; } - EBallCameraState GetState() const { return x400_state; } + [[nodiscard]] EBallCameraBehaviour GetBehaviour() const { return x188_behaviour; } + [[nodiscard]] EBallCameraState GetState() const { return x400_state; } void SetState(EBallCameraState state, CStateManager& mgr); void Think(float dt, CStateManager& mgr) override; bool TransitionFromMorphBallState(CStateManager& mgr); - TUniqueId GetTooCloseActorId() const { return x3dc_tooCloseActorId; } - float GetTooCloseActorDistance() const { return x3e0_tooCloseActorDist; } + [[nodiscard]] TUniqueId GetTooCloseActorId() const { return x3dc_tooCloseActorId; } + [[nodiscard]] float GetTooCloseActorDistance() const { return x3e0_tooCloseActorDist; } void TeleportCamera(const zeus::CVector3f& pos, CStateManager& mgr); void TeleportCamera(const zeus::CTransform& xf, CStateManager& mgr); - const zeus::CVector3f& GetLookPos() const { return x1d8_lookPos; } + [[nodiscard]] const zeus::CVector3f& GetLookPos() const { return x1d8_lookPos; } void ResetToTweaks(CStateManager& mgr); void UpdateLookAtPosition(float dt, CStateManager& mgr); zeus::CTransform UpdateLookDirection(const zeus::CVector3f& dir, CStateManager& mgr); @@ -267,10 +268,11 @@ public: void ResetPosition(CStateManager& mgr); void DoorClosed(TUniqueId doorId); void DoorClosing(TUniqueId doorId); - const zeus::CVector3f& GetLookPosAhead() const { return x1c0_lookPosAhead; } - const zeus::CVector3f& GetFixedLookPos() const { return x1cc_fixedLookPos; } + [[nodiscard]] const zeus::CVector3f& GetLookPosAhead() const { return x1c0_lookPosAhead; } + [[nodiscard]] const zeus::CVector3f& GetFixedLookPos() const { return x1cc_fixedLookPos; } + const TUniqueId GetCollisionActorId() const { return x46c_collisionActorId; } static bool IsBallNearDoor(const zeus::CVector3f& pos, CStateManager& mgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCameraFilter.cpp b/Runtime/Camera/CCameraFilter.cpp index 426463ae5..f6028b113 100644 --- a/Runtime/Camera/CCameraFilter.cpp +++ b/Runtime/Camera/CCameraFilter.cpp @@ -12,7 +12,7 @@ #include #include -namespace urde { +namespace metaforce { template void CCameraFilterPass::Update(float dt) { @@ -224,4 +224,4 @@ void CCameraBlurPass::SetBlur(EBlurType type, float amount, float duration) { void CCameraBlurPass::DisableBlur(float duration) { SetBlur(EBlurType::NoBlur, 0.f, duration); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCameraFilter.hpp b/Runtime/Camera/CCameraFilter.hpp index 0cd731804..292a8bc53 100644 --- a/Runtime/Camera/CCameraFilter.hpp +++ b/Runtime/Camera/CCameraFilter.hpp @@ -13,7 +13,7 @@ #include "hsh/hsh.h" #include "zeus/CColor.hpp" -namespace urde { +namespace metaforce { enum class EFilterType { Passthru, Multiply, @@ -155,4 +155,4 @@ public: EBlurType GetCurrType() const { return x10_curType; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCameraManager.cpp b/Runtime/Camera/CCameraManager.cpp index 036c9fad6..848bee6ab 100644 --- a/Runtime/Camera/CCameraManager.cpp +++ b/Runtime/Camera/CCameraManager.cpp @@ -18,7 +18,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { float CCameraManager::sFirstPersonFOV = 55.f; CCameraManager::CCameraManager(TUniqueId curCameraId) : x0_curCameraId(curCameraId) { @@ -732,4 +732,4 @@ void CCameraManager::SetFogDensity(float fogDensityTarget, float fogDensitySpeed x9c_fogDensityFactorTarget = fogDensityTarget; x98_fogDensitySpeed = (x9c_fogDensityFactorTarget >= x94_fogDensityFactor ? fogDensitySpeed : -fogDensitySpeed); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCameraManager.hpp b/Runtime/Camera/CCameraManager.hpp index 3c43ba103..2f0f33adc 100644 --- a/Runtime/Camera/CCameraManager.hpp +++ b/Runtime/Camera/CCameraManager.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class CBallCamera; class CCameraShakeData; class CCinematicCamera; @@ -146,4 +146,4 @@ public: bool ShouldBypassInterpolation() { return false; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCameraShakeData.cpp b/Runtime/Camera/CCameraShakeData.cpp index 490b3c9de..28a25d3ed 100644 --- a/Runtime/Camera/CCameraShakeData.cpp +++ b/Runtime/Camera/CCameraShakeData.cpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { SCameraShakePoint SCameraShakePoint::LoadCameraShakePoint(CInputStream& in) { u32 useEnvelope = ScriptLoader::LoadParameterFlags(in); @@ -136,4 +136,4 @@ const CCameraShakeData CCameraShakeData::skChargedShotCameraShakeData{ CCameraShakerComponent{}, }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCameraShakeData.hpp b/Runtime/Camera/CCameraShakeData.hpp index 7e9ebd2e8..b1a4de181 100644 --- a/Runtime/Camera/CCameraShakeData.hpp +++ b/Runtime/Camera/CCameraShakeData.hpp @@ -4,7 +4,7 @@ #include -namespace urde { +namespace metaforce { class CRandom16; class CStateManager; @@ -179,4 +179,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCameraSpline.cpp b/Runtime/Camera/CCameraSpline.cpp index 3079feb64..b7cf42b7e 100644 --- a/Runtime/Camera/CCameraSpline.cpp +++ b/Runtime/Camera/CCameraSpline.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CCameraSpline::CCameraSpline(bool closedLoop) : x48_closedLoop(closedLoop) {} void CCameraSpline::CalculateKnots(TUniqueId cameraId, const std::vector& connections, @@ -13,11 +13,12 @@ void CCameraSpline::CalculateKnots(TUniqueId cameraId, const std::vector waypoint = mgr.ObjectById(mgr.GetIdForScript(lastConn->x8_objId)); x14_wpTracker.clear(); x14_wpTracker.reserve(4); @@ -93,7 +94,7 @@ float CCameraSpline::GetKnotT(size_t idx) const { float CCameraSpline::CalculateSplineLength() { float ret = 0.f; x24_t.clear(); - if (x4_positions.size() > 0) { + if (!x4_positions.empty()) { zeus::CVector3f prevPoint = x4_positions[0]; float tDiv = 1.f / float(x4_positions.size() - 1); for (size_t i = 0; i < x4_positions.size(); ++i) { @@ -394,4 +395,4 @@ float CCameraSpline::ClampLength(const zeus::CVector3f& pos, bool collide, const return x44_length; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCameraSpline.hpp b/Runtime/Camera/CCameraSpline.hpp index 7dd48aece..576339bff 100644 --- a/Runtime/Camera/CCameraSpline.hpp +++ b/Runtime/Camera/CCameraSpline.hpp @@ -3,7 +3,7 @@ #include "World/CEntityInfo.hpp" #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class CStateManager; class CMaterialFilter; @@ -40,4 +40,4 @@ public: bool IsClosedLoop() const { return x48_closedLoop; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCinematicCamera.cpp b/Runtime/Camera/CCinematicCamera.cpp index 61a9427b1..875e67057 100644 --- a/Runtime/Camera/CCinematicCamera.cpp +++ b/Runtime/Camera/CCinematicCamera.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CCinematicCamera::CCinematicCamera(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, float shotDuration, float fovy, float znear, @@ -454,4 +454,4 @@ void CCinematicCamera::CalculateWaypoints(CStateManager& mgr) { void CCinematicCamera::SendArrivedMsg(TUniqueId reciever, CStateManager& mgr) { mgr.SendScriptMsgAlways(reciever, GetUniqueId(), EScriptObjectMessage::Arrived); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CCinematicCamera.hpp b/Runtime/Camera/CCinematicCamera.hpp index 9a4fcac8e..0f8646b9c 100644 --- a/Runtime/Camera/CCinematicCamera.hpp +++ b/Runtime/Camera/CCinematicCamera.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CCinematicCamera : public CGameCamera { std::vector x188_viewPoints; @@ -56,4 +56,4 @@ public: float GetDuration() const { return x1e8_duration; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CFirstPersonCamera.cpp b/Runtime/Camera/CFirstPersonCamera.cpp index 9523e9c50..70eec0884 100644 --- a/Runtime/Camera/CFirstPersonCamera.cpp +++ b/Runtime/Camera/CFirstPersonCamera.cpp @@ -8,11 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace DataSpec::DNAMP1 { -extern hecl::CVar* tw_fov; -} - -namespace urde { +namespace metaforce { CFirstPersonCamera::CFirstPersonCamera(TUniqueId uid, const zeus::CTransform& xf, TUniqueId watchedObj, float orbitCameraSpeed, float fov, float nearz, float farz, float aspect) @@ -20,7 +16,7 @@ CFirstPersonCamera::CFirstPersonCamera(TUniqueId uid, const zeus::CTransform& xf nearz, farz, aspect, watchedObj, false, 0) , x188_orbitCameraSpeed(orbitCameraSpeed) , x190_gunFollowXf(xf) { - DataSpec::DNAMP1::tw_fov->addListener([this](hecl::CVar* cv) { _fovListener(cv); }); + DataSpec::DNAMP1::tw_FieldOfView->addListener([this](hecl::CVar* cv) { _fovListener(cv); }); } void CFirstPersonCamera::Accept(IVisitor& visitor) { visitor.Visit(this); } @@ -337,4 +333,4 @@ void CFirstPersonCamera::_fovListener(hecl::CVar* cv) { x170_24_perspDirty = true; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CFirstPersonCamera.hpp b/Runtime/Camera/CFirstPersonCamera.hpp index 01ed95497..55ab79373 100644 --- a/Runtime/Camera/CFirstPersonCamera.hpp +++ b/Runtime/Camera/CFirstPersonCamera.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { class CFirstPersonCamera : public CGameCamera { float x188_orbitCameraSpeed; @@ -37,4 +37,4 @@ public: void SetLockCamera(bool v) { x18c_lockCamera = v; } void DeferBallTransitionProcessing() { x1c6_24_deferBallTransitionProcessing = true; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CGameCamera.cpp b/Runtime/Camera/CGameCamera.cpp index dc3508d8f..d86d7c825 100644 --- a/Runtime/Camera/CGameCamera.cpp +++ b/Runtime/Camera/CGameCamera.cpp @@ -4,7 +4,7 @@ #include "Runtime/Camera/CCameraManager.hpp" #include "Runtime/World/CActorParameters.hpp" -namespace urde { +namespace metaforce { CGameCamera::CGameCamera(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, float fovy, float znear, float zfar, float aspect, @@ -134,4 +134,4 @@ void CGameCamera::SkipFovInterpolation() { x178_perspInterpRemTime = x174_delayTime = 0.f; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CGameCamera.hpp b/Runtime/Camera/CGameCamera.hpp index c0d33805e..5152252ff 100644 --- a/Runtime/Camera/CGameCamera.hpp +++ b/Runtime/Camera/CGameCamera.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { struct CFinalInput; class CGameCamera : public CActor { @@ -54,4 +54,4 @@ public: void SetFovInterpolation(float start, float end, float time, float delayTime); void SkipFovInterpolation(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CInterpolationCamera.cpp b/Runtime/Camera/CInterpolationCamera.cpp index 56c37d097..7120dc040 100644 --- a/Runtime/Camera/CInterpolationCamera.cpp +++ b/Runtime/Camera/CInterpolationCamera.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CInterpolationCamera::CInterpolationCamera(TUniqueId uid, const zeus::CTransform& xf) : CGameCamera(uid, false, "Interpolation Camera", @@ -205,4 +205,4 @@ bool CInterpolationCamera::InterpolateWithDistance(zeus::CTransform& xf, const z return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CInterpolationCamera.hpp b/Runtime/Camera/CInterpolationCamera.hpp index b34cde012..549fefa5c 100644 --- a/Runtime/Camera/CInterpolationCamera.hpp +++ b/Runtime/Camera/CInterpolationCamera.hpp @@ -5,7 +5,7 @@ #include #include -namespace urde { +namespace metaforce { class CInterpolationCamera : public CGameCamera { TUniqueId x188_targetId = kInvalidUniqueId; @@ -38,4 +38,4 @@ public: void DeactivateInterpCamera(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CPathCamera.cpp b/Runtime/Camera/CPathCamera.cpp index ea39057ae..abb8ab5c0 100644 --- a/Runtime/Camera/CPathCamera.cpp +++ b/Runtime/Camera/CPathCamera.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CPathCamera::CPathCamera(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, float lengthExtent, float filterMag, float filterProportion, float minEaseDist, @@ -211,4 +211,4 @@ void CPathCamera::ClampToClosedDoor(CStateManager& mgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Camera/CPathCamera.hpp b/Runtime/Camera/CPathCamera.hpp index 7757e76a1..31df65fec 100644 --- a/Runtime/Camera/CPathCamera.hpp +++ b/Runtime/Camera/CPathCamera.hpp @@ -3,7 +3,7 @@ #include "Runtime/Camera/CCameraSpline.hpp" #include "Runtime/Camera/CGameCamera.hpp" -namespace urde { +namespace metaforce { class CPathCamera : public CGameCamera { public: @@ -36,4 +36,4 @@ public: void ClampToClosedDoor(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CActorLights.cpp b/Runtime/Character/CActorLights.cpp index 7e252fc23..35f6ac7e0 100644 --- a/Runtime/Character/CActorLights.cpp +++ b/Runtime/Character/CActorLights.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { s32 CActorLights::sFrameSchedulerCount = 0; CActorLights::CActorLights(u32 areaUpdateFramePeriod, const zeus::CVector3f& actorPosBias, int maxDynamicLights, @@ -510,4 +510,4 @@ u32 CActorLights::GetActiveLightCount() const { return x144_dynamicLights.size(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CActorLights.hpp b/Runtime/Character/CActorLights.hpp index 6c437a2ed..c1c8de5fc 100644 --- a/Runtime/Character/CActorLights.hpp +++ b/Runtime/Character/CActorLights.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CBooModel; class CGameArea; class CStateManager; @@ -91,4 +91,4 @@ public: void SetActorPositionBias(const zeus::CVector3f& bias) { x2ac_actorPosBias = bias; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAdditiveAnimPlayback.cpp b/Runtime/Character/CAdditiveAnimPlayback.cpp index fde744ded..37ab95148 100644 --- a/Runtime/Character/CAdditiveAnimPlayback.cpp +++ b/Runtime/Character/CAdditiveAnimPlayback.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CCharLayoutInfo.hpp" #include "Runtime/Character/CSegStatementSet.hpp" -namespace urde { +namespace metaforce { CAdditiveAnimPlayback::CAdditiveAnimPlayback(const std::weak_ptr& anim, float weight, bool active, const CAdditiveAnimationInfo& info, bool fadeOut) @@ -101,4 +101,4 @@ void CAdditiveAnimPlayback::SetWeight(float w) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAdditiveAnimPlayback.hpp b/Runtime/Character/CAdditiveAnimPlayback.hpp index 637a287d8..c85ac976d 100644 --- a/Runtime/Character/CAdditiveAnimPlayback.hpp +++ b/Runtime/Character/CAdditiveAnimPlayback.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CAdditiveAnimationInfo; class CAnimTreeNode; class CCharLayoutInfo; @@ -55,4 +55,4 @@ public: bool NeedsFadeOut() const { return x20_needsFadeOut; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAdditiveBodyState.cpp b/Runtime/Character/CAdditiveBodyState.cpp index 587e89499..fefb2a9b7 100644 --- a/Runtime/Character/CAdditiveBodyState.cpp +++ b/Runtime/Character/CAdditiveBodyState.cpp @@ -6,16 +6,16 @@ #include "Runtime/Character/CPASDatabase.hpp" #include "Runtime/Character/CPASAnimParmData.hpp" -namespace urde { +namespace metaforce { void CABSAim::Start(CBodyController& bc, CStateManager& mgr) { // const CBCAdditiveAimCmd* cmd = // static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::AdditiveAim)); - const CPASAnimState* aimState = bc.GetPASDatabase().GetAnimState(22); + const CPASAnimState* aimState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::AdditiveAim); // Left, Right, Up, Down for (size_t i = 0; i < x8_anims.size(); ++i) { - const CPASAnimParmData parms(22, CPASAnimParm::FromEnum(s32(i))); + const CPASAnimParmData parms(pas::EAnimationState::AdditiveAim, CPASAnimParm::FromEnum(s32(i))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); x8_anims[i] = best.second; x18_angles[i] = zeus::degToRad(aimState->GetAnimParmData(x8_anims[i], 1).GetReal32Value()); @@ -99,7 +99,7 @@ void CABSFlinch::Start(CBodyController& bc, CStateManager& mgr) { static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::AdditiveFlinch)); x4_weight = cmd->GetWeight(); - CPASAnimParmData parms(23); + CPASAnimParmData parms(pas::EAnimationState::AdditiveFlinch); std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); x8_anim = best.second; @@ -145,7 +145,7 @@ void CABSReaction::Start(CBodyController& bc, CStateManager& mgr) { xc_type = cmd->GetType(); x10_active = cmd->GetIsActive(); - CPASAnimParmData parms(24, CPASAnimParm::FromEnum(s32(xc_type))); + CPASAnimParmData parms(pas::EAnimationState::AdditiveReaction, CPASAnimParm::FromEnum(s32(xc_type))); std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); x8_anim = best.second; @@ -197,4 +197,4 @@ void CABSReaction::StopAnimation(CBodyController& bc) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAdditiveBodyState.hpp b/Runtime/Character/CAdditiveBodyState.hpp index 3c2c3bbb6..8330e0d0f 100644 --- a/Runtime/Character/CAdditiveBodyState.hpp +++ b/Runtime/Character/CAdditiveBodyState.hpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CBodyStateCmdMgr.hpp" #include "Runtime/Character/CharacterCommon.hpp" -namespace urde { +namespace metaforce { class CActor; class CBodyController; class CStateManager; @@ -71,4 +71,4 @@ public: void Shutdown(CBodyController& bc) override { StopAnimation(bc); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAllFormatsAnimSource.cpp b/Runtime/Character/CAllFormatsAnimSource.cpp index 025eed532..7e852ede9 100644 --- a/Runtime/Character/CAllFormatsAnimSource.cpp +++ b/Runtime/Character/CAllFormatsAnimSource.cpp @@ -6,8 +6,8 @@ #include -namespace urde { -static logvisor::Module Log("urde::CAllFormatsAnimSource"); +namespace metaforce { +static logvisor::Module Log("metaforce::CAllFormatsAnimSource"); void CAnimFormatUnion::SubConstruct(u8* storage, EAnimFormat fmt, CInputStream& in, IObjectStore& store) { switch (fmt) { @@ -67,4 +67,4 @@ CFactoryFnReturn AnimSourceFactory(const SObjectTag& tag, CInputStream& in, cons return TToken::GetIObjObjectFor(std::make_unique(in, *sp, tag)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAllFormatsAnimSource.hpp b/Runtime/Character/CAllFormatsAnimSource.hpp index b8a60f9e8..1388c2583 100644 --- a/Runtime/Character/CAllFormatsAnimSource.hpp +++ b/Runtime/Character/CAllFormatsAnimSource.hpp @@ -10,7 +10,7 @@ #include -namespace urde { +namespace metaforce { class IAnimReader; class IObjectStore; @@ -48,4 +48,4 @@ public: CFactoryFnReturn AnimSourceFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& params, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimCharacterSet.cpp b/Runtime/Character/CAnimCharacterSet.cpp index 15a7a7943..a85150f8f 100644 --- a/Runtime/Character/CAnimCharacterSet.cpp +++ b/Runtime/Character/CAnimCharacterSet.cpp @@ -2,7 +2,7 @@ #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { CAnimCharacterSet::CAnimCharacterSet(CInputStream& in) : x0_version(in.readUint16Big()), x4_characterSet(in), x1c_animationSet(in) {} @@ -12,4 +12,4 @@ CFactoryFnReturn FAnimCharacterSet(const SObjectTag&, CInputStream& in, const CV return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimCharacterSet.hpp b/Runtime/Character/CAnimCharacterSet.hpp index 94bba47cf..24795ed91 100644 --- a/Runtime/Character/CAnimCharacterSet.hpp +++ b/Runtime/Character/CAnimCharacterSet.hpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CAnimationSet.hpp" #include "Runtime/Character/CCharacterSet.hpp" -namespace urde { +namespace metaforce { class CAnimCharacterSet { u16 x0_version; @@ -19,4 +19,4 @@ public: CFactoryFnReturn FAnimCharacterSet(const SObjectTag&, CInputStream&, const CVParamTransfer&, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimData.cpp b/Runtime/Character/CAnimData.cpp index ebbba498e..620541a0e 100644 --- a/Runtime/Character/CAnimData.cpp +++ b/Runtime/Character/CAnimData.cpp @@ -26,7 +26,7 @@ #include -namespace urde { +namespace metaforce { static logvisor::Module Log("CAnimData"); rstl::reserved_vector CAnimData::g_BoolPOINodes; @@ -553,6 +553,7 @@ void CAnimData::Render(CSkinnedModel& model, const CModelFlags& drawFlags, void CAnimData::SetupRender(CSkinnedModel& model, const CModelFlags& drawFlags, const std::optional& morphEffect, const float* morphMagnitudes) { + OPTICK_EVENT(); if (!x220_30_poseBuilt) { x2fc_poseBuilder.BuildNoScale(x224_pose); x220_30_poseBuilt = true; @@ -560,7 +561,9 @@ void CAnimData::SetupRender(CSkinnedModel& model, const CModelFlags& drawFlags, PoseSkinnedModel(model, x224_pose, drawFlags, morphEffect, morphMagnitudes); } -void CAnimData::DrawSkinnedModel(CSkinnedModel& model, const CModelFlags& flags) { model.Draw(flags); } +void CAnimData::DrawSkinnedModel(CSkinnedModel& model, const CModelFlags& flags) { + model.Draw(flags); +} void CAnimData::PreRender() { if (!x220_31_poseCached) { @@ -894,4 +897,4 @@ void CAnimData::SetParticleCEXTValue(std::string_view name, int idx, float value x120_particleDB.SetCEXTValue(search->second.front().GetComponentName(), idx, value); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimData.hpp b/Runtime/Character/CAnimData.hpp index 62905ca84..71edfaaed 100644 --- a/Runtime/Character/CAnimData.hpp +++ b/Runtime/Character/CAnimData.hpp @@ -60,7 +60,7 @@ enum class EUserEventType { EffectOff = 34 }; -namespace urde { +namespace metaforce { class CAnimTreeNode; class CAnimationManager; class CBoolPOINode; @@ -252,4 +252,4 @@ public: void MarkPoseDirty() { x220_30_poseBuilt = false; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimPOIData.cpp b/Runtime/Character/CAnimPOIData.cpp index 54014bf3e..0f9328307 100644 --- a/Runtime/Character/CAnimPOIData.cpp +++ b/Runtime/Character/CAnimPOIData.cpp @@ -2,7 +2,7 @@ #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { CAnimPOIData::CAnimPOIData(CInputStream& in) : x0_version(in.readUint32Big()) { u32 boolCount = in.readUint32Big(); @@ -33,4 +33,4 @@ CFactoryFnReturn AnimPOIDataFactory(const SObjectTag& tag, CInputStream& in, con return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimPOIData.hpp b/Runtime/Character/CAnimPOIData.hpp index 577bc688c..d51acde57 100644 --- a/Runtime/Character/CAnimPOIData.hpp +++ b/Runtime/Character/CAnimPOIData.hpp @@ -9,7 +9,7 @@ #include "Runtime/Character/CParticlePOINode.hpp" #include "Runtime/Character/CSoundPOINode.hpp" -namespace urde { +namespace metaforce { class CAnimPOIData { u32 x0_version; @@ -30,4 +30,4 @@ public: CFactoryFnReturn AnimPOIDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& parms, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimPerSegmentData.hpp b/Runtime/Character/CAnimPerSegmentData.hpp index e9f252eef..7b74c7a46 100644 --- a/Runtime/Character/CAnimPerSegmentData.hpp +++ b/Runtime/Character/CAnimPerSegmentData.hpp @@ -3,7 +3,7 @@ #include #include -namespace urde { +namespace metaforce { struct CAnimPerSegmentData { zeus::CQuaternion x0_rotation; @@ -11,4 +11,4 @@ struct CAnimPerSegmentData { bool x1c_hasOffset = false; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimPlaybackParms.hpp b/Runtime/Character/CAnimPlaybackParms.hpp index 0515185d1..c1979c067 100644 --- a/Runtime/Character/CAnimPlaybackParms.hpp +++ b/Runtime/Character/CAnimPlaybackParms.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { class CAnimPlaybackParms { s32 x0_animA = -1; s32 x4_animB = -1; @@ -45,4 +45,4 @@ public: constexpr void SetBlendFactor(float f) { x8_blendWeight = f; } constexpr bool GetIsPlayAnimation() const { return xc_animating; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimSource.cpp b/Runtime/Character/CAnimSource.cpp index 6d884c56c..7ab35115e 100644 --- a/Runtime/Character/CAnimSource.cpp +++ b/Runtime/Character/CAnimSource.cpp @@ -7,7 +7,7 @@ #include "Runtime/Character/CSegIdList.hpp" #include "Runtime/Character/CSegStatementSet.hpp" -namespace urde { +namespace metaforce { static constexpr float ClampZeroToOne(float in) { return std::clamp(in, 0.0f, 1.0f); } @@ -215,4 +215,4 @@ bool CAnimSource::HasOffset(const CSegId& seg) const { return transIdx != 0xff; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimSource.hpp b/Runtime/Character/CAnimSource.hpp index 26dc312cb..4f554e06b 100644 --- a/Runtime/Character/CAnimSource.hpp +++ b/Runtime/Character/CAnimSource.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CAnimPOIData; class CBoolPOINode; class CInt32POINode; @@ -78,4 +78,4 @@ public: const CSegId& GetRootBoneId() const { return x1c_rootBone; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimSourceReader.cpp b/Runtime/Character/CAnimSourceReader.cpp index c4effdb7c..fd27d6686 100644 --- a/Runtime/Character/CAnimSourceReader.cpp +++ b/Runtime/Character/CAnimSourceReader.cpp @@ -8,7 +8,7 @@ #include "Runtime/Character/CParticlePOINode.hpp" #include "Runtime/Character/CSoundPOINode.hpp" -namespace urde { +namespace metaforce { CAnimSourceInfo::CAnimSourceInfo(TSubAnimTypeToken token) : x4_token(std::move(token)) {} @@ -381,4 +381,4 @@ CAnimSourceReader::CAnimSourceReader(const CAnimSourceReader& other) , x54_source(other.x54_source) , x64_steadyStateInfo(other.x64_steadyStateInfo) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimSourceReader.hpp b/Runtime/Character/CAnimSourceReader.hpp index 8509d1885..d955f7070 100644 --- a/Runtime/Character/CAnimSourceReader.hpp +++ b/Runtime/Character/CAnimSourceReader.hpp @@ -11,7 +11,7 @@ #include "Runtime/Character/CParticleData.hpp" #include "Runtime/Character/IAnimReader.hpp" -namespace urde { +namespace metaforce { class IAnimSourceInfo { public: @@ -104,4 +104,4 @@ public: zeus::CQuaternion VGetRotation(const CSegId& seg) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimSysContext.hpp b/Runtime/Character/CAnimSysContext.hpp index 4a75b23ba..30f1fa8f5 100644 --- a/Runtime/Character/CAnimSysContext.hpp +++ b/Runtime/Character/CAnimSysContext.hpp @@ -7,7 +7,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/Character/CTransitionDatabaseGame.hpp" -namespace urde { +namespace metaforce { class CSimplePool; struct CAnimSysContext { @@ -19,4 +19,4 @@ struct CAnimSysContext { : x0_transDB(std::move(transDB)), x8_random(std::make_shared(randomSeed)), xc_store(store) {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeAnimReaderContainer.cpp b/Runtime/Character/CAnimTreeAnimReaderContainer.cpp index 325205bb6..50d5d3fcb 100644 --- a/Runtime/Character/CAnimTreeAnimReaderContainer.cpp +++ b/Runtime/Character/CAnimTreeAnimReaderContainer.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CFBStreamedAnimReader.hpp" -namespace urde { +namespace metaforce { CAnimTreeAnimReaderContainer::CAnimTreeAnimReaderContainer(std::string_view name, std::shared_ptr reader, u32 dbIdx) @@ -97,4 +97,4 @@ void CAnimTreeAnimReaderContainer::VGetWeightedReaders( out.emplace_back(std::make_pair(w, x14_reader)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeAnimReaderContainer.hpp b/Runtime/Character/CAnimTreeAnimReaderContainer.hpp index 44d55afe0..4642eddf2 100644 --- a/Runtime/Character/CAnimTreeAnimReaderContainer.hpp +++ b/Runtime/Character/CAnimTreeAnimReaderContainer.hpp @@ -8,7 +8,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Character/CAnimTreeNode.hpp" -namespace urde { +namespace metaforce { class CAnimTreeAnimReaderContainer : public CAnimTreeNode { std::shared_ptr x14_reader; @@ -48,4 +48,4 @@ public: SAdvancementResults VGetAdvancementResults(const CCharAnimTime& a, const CCharAnimTime& b) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeBlend.cpp b/Runtime/Character/CAnimTreeBlend.cpp index 8dbabbd8d..af05e6ac9 100644 --- a/Runtime/Character/CAnimTreeBlend.cpp +++ b/Runtime/Character/CAnimTreeBlend.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CAnimTreeBlend.hpp" -namespace urde { +namespace metaforce { std::string CAnimTreeBlend::CreatePrimitiveName(const std::shared_ptr& a, const std::shared_ptr& b, float scale) { @@ -63,4 +63,4 @@ void CAnimTreeBlend::SetBlendingWeight(float w) { x24_blendWeight = w; } float CAnimTreeBlend::VGetBlendingWeight() const { return x24_blendWeight; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeBlend.hpp b/Runtime/Character/CAnimTreeBlend.hpp index 5717c6e30..6030247f5 100644 --- a/Runtime/Character/CAnimTreeBlend.hpp +++ b/Runtime/Character/CAnimTreeBlend.hpp @@ -5,7 +5,7 @@ #include "Runtime/Character/CAnimTreeTweenBase.hpp" -namespace urde { +namespace metaforce { class CAnimTreeBlend : public CAnimTreeTweenBase { float x24_blendWeight; @@ -25,4 +25,4 @@ public: float VGetBlendingWeight() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeDoubleChild.cpp b/Runtime/Character/CAnimTreeDoubleChild.cpp index 2a9d251c0..42d775db1 100644 --- a/Runtime/Character/CAnimTreeDoubleChild.cpp +++ b/Runtime/Character/CAnimTreeDoubleChild.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CAnimTreeDoubleChild.hpp" -namespace urde { +namespace metaforce { CAnimTreeDoubleChild::CAnimTreeDoubleChild(const std::weak_ptr& a, const std::weak_ptr& b, std::string_view name) @@ -157,4 +157,4 @@ void CAnimTreeDoubleChild::VGetWeightedReaders( x18_b->VGetWeightedReaders(out, w); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeDoubleChild.hpp b/Runtime/Character/CAnimTreeDoubleChild.hpp index 22ddbbb2b..b94dae770 100644 --- a/Runtime/Character/CAnimTreeDoubleChild.hpp +++ b/Runtime/Character/CAnimTreeDoubleChild.hpp @@ -6,7 +6,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Character/CAnimTreeNode.hpp" -namespace urde { +namespace metaforce { class CAnimTreeDoubleChild : public CAnimTreeNode { public: @@ -59,4 +59,4 @@ public: const std::shared_ptr& GetLeftChild() const { return x14_a; } const std::shared_ptr& GetRightChild() const { return x18_b; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeLoopIn.cpp b/Runtime/Character/CAnimTreeLoopIn.cpp index b3c655cbb..c53a54884 100644 --- a/Runtime/Character/CAnimTreeLoopIn.cpp +++ b/Runtime/Character/CAnimTreeLoopIn.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CTreeUtils.hpp" -namespace urde { +namespace metaforce { std::string CAnimTreeLoopIn::CreatePrimitiveName(const std::weak_ptr& a, const std::weak_ptr& b, @@ -101,4 +101,4 @@ SAdvancementResults CAnimTreeLoopIn::VAdvanceView(const CCharAnimTime& dt) { return res; } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/Character/CAnimTreeLoopIn.hpp b/Runtime/Character/CAnimTreeLoopIn.hpp index f1c30730a..82ff6b39f 100644 --- a/Runtime/Character/CAnimTreeLoopIn.hpp +++ b/Runtime/Character/CAnimTreeLoopIn.hpp @@ -8,7 +8,7 @@ #include "Runtime/Character/CAnimTreeSingleChild.hpp" #include "Runtime/Character/CSequenceHelper.hpp" -namespace urde { +namespace metaforce { class CAnimTreeLoopIn : public CAnimTreeSingleChild { std::shared_ptr x18_nextAnim; @@ -42,4 +42,4 @@ public: SAdvancementResults VAdvanceView(const CCharAnimTime& dt) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeNode.cpp b/Runtime/Character/CAnimTreeNode.cpp index efbad4e5d..b73cd30bd 100644 --- a/Runtime/Character/CAnimTreeNode.cpp +++ b/Runtime/Character/CAnimTreeNode.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CAnimTreeNode.hpp" -namespace urde { +namespace metaforce { CAnimTreeEffectiveContribution CAnimTreeNode::GetContributionOfHighestInfluence() const { return VGetContributionOfHighestInfluence(); @@ -10,4 +10,4 @@ u32 CAnimTreeNode::GetNumChildren() const { return VGetNumChildren(); } std::shared_ptr CAnimTreeNode::GetBestUnblendedChild() const { return VGetBestUnblendedChild(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeNode.hpp b/Runtime/Character/CAnimTreeNode.hpp index d18b94eb9..3071722a0 100644 --- a/Runtime/Character/CAnimTreeNode.hpp +++ b/Runtime/Character/CAnimTreeNode.hpp @@ -7,7 +7,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/Character/IAnimReader.hpp" -namespace urde { +namespace metaforce { class CAnimTreeNode : public IAnimReader { protected: @@ -39,4 +39,4 @@ public: std::string_view GetName() const { return x4_name; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeSequence.cpp b/Runtime/Character/CAnimTreeSequence.cpp index fadc46b5e..a964abc07 100644 --- a/Runtime/Character/CAnimTreeSequence.cpp +++ b/Runtime/Character/CAnimTreeSequence.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CTreeUtils.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { CAnimTreeSequence::CAnimTreeSequence(std::vector> seq, CAnimSysContext animSys, std::string_view name) @@ -121,4 +121,4 @@ std::unique_ptr CAnimTreeSequence::VClone() const { x18_animCtx, x4_name, x3c_fundamentals, x94_curTime); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeSequence.hpp b/Runtime/Character/CAnimTreeSequence.hpp index 56e038097..f8a3c5ac6 100644 --- a/Runtime/Character/CAnimTreeSequence.hpp +++ b/Runtime/Character/CAnimTreeSequence.hpp @@ -8,7 +8,7 @@ #include "Runtime/Character/CAnimTreeSingleChild.hpp" #include "Runtime/Character/CSequenceHelper.hpp" -namespace urde { +namespace metaforce { class IMetaAnim; class CTransitionDatabaseGame; @@ -42,4 +42,4 @@ public: std::unique_ptr VClone() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeSingleChild.cpp b/Runtime/Character/CAnimTreeSingleChild.cpp index 0100c0797..2bc59a3d3 100644 --- a/Runtime/Character/CAnimTreeSingleChild.cpp +++ b/Runtime/Character/CAnimTreeSingleChild.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CAnimTreeSingleChild.hpp" -namespace urde { +namespace metaforce { CAnimTreeSingleChild::CAnimTreeSingleChild(const std::weak_ptr& node, std::string_view name) : CAnimTreeNode(name), x14_child(node.lock()) {} @@ -62,4 +62,4 @@ u32 CAnimTreeSingleChild::Depth() const { return x14_child->Depth() + 1; } u32 CAnimTreeSingleChild::VGetNumChildren() const { return x14_child->VGetNumChildren() + 1; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeSingleChild.hpp b/Runtime/Character/CAnimTreeSingleChild.hpp index 9ed59f795..676865db2 100644 --- a/Runtime/Character/CAnimTreeSingleChild.hpp +++ b/Runtime/Character/CAnimTreeSingleChild.hpp @@ -6,7 +6,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Character/CAnimTreeNode.hpp" -namespace urde { +namespace metaforce { class CAnimTreeSingleChild : public CAnimTreeNode { protected: @@ -42,4 +42,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeTimeScale.cpp b/Runtime/Character/CAnimTreeTimeScale.cpp index a7c2ecba1..5403d8909 100644 --- a/Runtime/Character/CAnimTreeTimeScale.cpp +++ b/Runtime/Character/CAnimTreeTimeScale.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CAnimTreeTimeScale.hpp" -namespace urde { +namespace metaforce { CAnimTreeTimeScale::CAnimTreeTimeScale(const std::weak_ptr& node, float scale, std::string_view name) : CAnimTreeSingleChild(node, name) @@ -197,4 +197,4 @@ SAdvancementResults CAnimTreeTimeScale::VAdvanceView(const CCharAnimTime& dt) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeTimeScale.hpp b/Runtime/Character/CAnimTreeTimeScale.hpp index f591e10a6..8ef1af663 100644 --- a/Runtime/Character/CAnimTreeTimeScale.hpp +++ b/Runtime/Character/CAnimTreeTimeScale.hpp @@ -8,7 +8,7 @@ #include "Runtime/Character/CAnimTreeSingleChild.hpp" #include "Runtime/Character/CTimeScaleFunctions.hpp" -namespace urde { +namespace metaforce { class CAnimTreeTimeScale : public CAnimTreeSingleChild { std::unique_ptr x18_timeScale; @@ -46,4 +46,4 @@ public: SAdvancementResults VAdvanceView(const CCharAnimTime& dt) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeTransition.cpp b/Runtime/Character/CAnimTreeTransition.cpp index 5d5c107c2..4928c4180 100644 --- a/Runtime/Character/CAnimTreeTransition.cpp +++ b/Runtime/Character/CAnimTreeTransition.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CAnimTreeTransition.hpp" -namespace urde { +namespace metaforce { std::string CAnimTreeTransition::CreatePrimitiveName(const std::weak_ptr&, const std::weak_ptr&, float) { @@ -140,4 +140,4 @@ float CAnimTreeTransition::VGetBlendingWeight() const { return x2c_timeInTrans.GetSeconds() / x24_transDur.GetSeconds(); return 0.f; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeTransition.hpp b/Runtime/Character/CAnimTreeTransition.hpp index 86ba96ec9..e856422ab 100644 --- a/Runtime/Character/CAnimTreeTransition.hpp +++ b/Runtime/Character/CAnimTreeTransition.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Character/CAnimTreeTweenBase.hpp" -namespace urde { +namespace metaforce { class CAnimTreeTransition : public CAnimTreeTweenBase { protected: @@ -36,4 +36,4 @@ public: void SetBlendingWeight(float w) override; float VGetBlendingWeight() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeTweenBase.cpp b/Runtime/Character/CAnimTreeTweenBase.cpp index 8452c06d2..784ee1a8d 100644 --- a/Runtime/Character/CAnimTreeTweenBase.cpp +++ b/Runtime/Character/CAnimTreeTweenBase.cpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CSegIdList.hpp" #include "Runtime/Character/CSegStatementSet.hpp" -namespace urde { +namespace metaforce { s32 CAnimTreeTweenBase::sAdvancementDepth = 0; @@ -124,4 +124,4 @@ std::optional> CAnimTreeTweenBase::VSimplified() { return {tmpUnblended->Clone()}; } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimTreeTweenBase.hpp b/Runtime/Character/CAnimTreeTweenBase.hpp index e0f41a4dc..6880b4e99 100644 --- a/Runtime/Character/CAnimTreeTweenBase.hpp +++ b/Runtime/Character/CAnimTreeTweenBase.hpp @@ -6,7 +6,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Character/CAnimTreeDoubleChild.hpp" -namespace urde { +namespace metaforce { class CAnimTreeTweenBase : public CAnimTreeDoubleChild { static s32 sAdvancementDepth; @@ -45,4 +45,4 @@ public: static void DecAdvancementDepth() { sAdvancementDepth--; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimation.cpp b/Runtime/Character/CAnimation.cpp index cbb27be3d..d7de743bb 100644 --- a/Runtime/Character/CAnimation.cpp +++ b/Runtime/Character/CAnimation.cpp @@ -2,11 +2,11 @@ #include "Runtime/Character/CMetaAnimFactory.hpp" -namespace urde { +namespace metaforce { CAnimation::CAnimation(CInputStream& in) { x0_name = in.readString(); x10_anim = CMetaAnimFactory::CreateMetaAnim(in); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimation.hpp b/Runtime/Character/CAnimation.hpp index be592bbb4..696d7e1cb 100644 --- a/Runtime/Character/CAnimation.hpp +++ b/Runtime/Character/CAnimation.hpp @@ -6,7 +6,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/CMetaAnimFactory.hpp" -namespace urde { +namespace metaforce { class IMetaAnim; class CAnimation { @@ -19,4 +19,4 @@ public: std::string_view GetMetaAnimName() const { return x0_name; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimationDatabase.hpp b/Runtime/Character/CAnimationDatabase.hpp index 93f4c19e2..53ebcea78 100644 --- a/Runtime/Character/CAnimationDatabase.hpp +++ b/Runtime/Character/CAnimationDatabase.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CPrimitive; class IMetaAnim; @@ -20,4 +20,4 @@ public: virtual void GetUniquePrimitivesFromMetaAnim(std::set&, std::string_view) const = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimationDatabaseGame.cpp b/Runtime/Character/CAnimationDatabaseGame.cpp index 764fee1b4..8963a11bb 100644 --- a/Runtime/Character/CAnimationDatabaseGame.cpp +++ b/Runtime/Character/CAnimationDatabaseGame.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CPrimitive.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { CAnimationDatabaseGame::CAnimationDatabaseGame(const std::vector& anims) { x10_anims.reserve(anims.size()); @@ -34,4 +34,4 @@ void CAnimationDatabaseGame::GetUniquePrimitivesFromMetaAnim(std::set& primsOut, std::string_view name) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimationManager.cpp b/Runtime/Character/CAnimationManager.cpp index d7c69634b..062603a40 100644 --- a/Runtime/Character/CAnimationManager.cpp +++ b/Runtime/Character/CAnimationManager.cpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CAnimationDatabaseGame.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { const CAnimationDatabaseGame* CAnimationManager::GetAnimationDatabase() const { return x0_animDB.GetObj(); } @@ -17,4 +17,4 @@ const std::shared_ptr& CAnimationManager::GetMetaAnimation(s32 idx) c return x0_animDB->GetMetaAnim(idx); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimationManager.hpp b/Runtime/Character/CAnimationManager.hpp index 26956ed29..dba0e24c2 100644 --- a/Runtime/Character/CAnimationManager.hpp +++ b/Runtime/Character/CAnimationManager.hpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CAnimationDatabaseGame.hpp" #include "Runtime/Character/CAnimSysContext.hpp" -namespace urde { +namespace metaforce { class CAnimTreeNode; class CSimplePool; class IMetaAnim; @@ -26,4 +26,4 @@ public: const std::shared_ptr& GetMetaAnimation(s32) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimationSet.cpp b/Runtime/Character/CAnimationSet.cpp index a3ae93fe8..690b1a3c7 100644 --- a/Runtime/Character/CAnimationSet.cpp +++ b/Runtime/Character/CAnimationSet.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CMetaTransFactory.hpp" -namespace urde { +namespace metaforce { CAnimationSet::CAnimationSet(CInputStream& in) : x0_tableCount(in.readUint16Big()) { u32 animationCount = in.readUint32Big(); @@ -45,4 +45,4 @@ CAnimationSet::CAnimationSet(CInputStream& in) : x0_tableCount(in.readUint16Big( } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAnimationSet.hpp b/Runtime/Character/CAnimationSet.hpp index 55ae41fba..18cdd5e0a 100644 --- a/Runtime/Character/CAnimationSet.hpp +++ b/Runtime/Character/CAnimationSet.hpp @@ -11,7 +11,7 @@ #include "Runtime/Character/CHalfTransition.hpp" #include "Runtime/Character/CTransition.hpp" -namespace urde { +namespace metaforce { class CAnimationSet { u16 x0_tableCount; @@ -34,4 +34,4 @@ public: const CAdditiveAnimationInfo& GetDefaultAdditiveInfo() const { return x38_defaultAdditiveInfo; } const std::vector>& GetAnimResIds() const { return x50_animRes; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAssetFactory.cpp b/Runtime/Character/CAssetFactory.cpp index cf95602c8..c78d94b1a 100644 --- a/Runtime/Character/CAssetFactory.cpp +++ b/Runtime/Character/CAssetFactory.cpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CCharLayoutInfo.hpp" #include "Runtime/Character/CModelData.hpp" -namespace urde { +namespace metaforce { CFactoryFnReturn CCharacterFactoryBuilder::CDummyFactory::Build(const SObjectTag& tag, const CVParamTransfer&, CObjectReference* selfRef) { @@ -36,24 +36,24 @@ void CCharacterFactoryBuilder::CDummyFactory::EnumerateResources( void CCharacterFactoryBuilder::CDummyFactory::EnumerateNamedResources( const std::function& lambda) const {} -u32 CCharacterFactoryBuilder::CDummyFactory::ResourceSize(const urde::SObjectTag& tag) { return 0; } +u32 CCharacterFactoryBuilder::CDummyFactory::ResourceSize(const metaforce::SObjectTag& tag) { return 0; } -std::shared_ptr CCharacterFactoryBuilder::CDummyFactory::LoadResourceAsync(const urde::SObjectTag& tag, +std::shared_ptr CCharacterFactoryBuilder::CDummyFactory::LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) { return {}; } -std::shared_ptr CCharacterFactoryBuilder::CDummyFactory::LoadResourcePartAsync(const urde::SObjectTag& tag, +std::shared_ptr CCharacterFactoryBuilder::CDummyFactory::LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size, void* target) { return {}; } -std::unique_ptr CCharacterFactoryBuilder::CDummyFactory::LoadResourceSync(const urde::SObjectTag& tag) { +std::unique_ptr CCharacterFactoryBuilder::CDummyFactory::LoadResourceSync(const metaforce::SObjectTag& tag) { return {}; } -std::unique_ptr CCharacterFactoryBuilder::CDummyFactory::LoadNewResourcePartSync(const urde::SObjectTag& tag, +std::unique_ptr CCharacterFactoryBuilder::CDummyFactory::LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) { return {}; } @@ -64,4 +64,4 @@ TToken CCharacterFactoryBuilder::GetFactory(const CAnimRes& r return x4_dummyStore.GetObj({SBIG('ANCS'), res.GetId()}); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CAssetFactory.hpp b/Runtime/Character/CAssetFactory.hpp index 975124f7d..7364d6f6d 100644 --- a/Runtime/Character/CAssetFactory.hpp +++ b/Runtime/Character/CAssetFactory.hpp @@ -8,7 +8,7 @@ #include "Runtime/IFactory.hpp" #include "Runtime/IObj.hpp" -namespace urde { +namespace metaforce { class CCharacterFactory; class CAnimRes; @@ -27,12 +27,12 @@ public: void EnumerateResources(const std::function& lambda) const override; void EnumerateNamedResources(const std::function& lambda) const override; - u32 ResourceSize(const urde::SObjectTag& tag) override; - std::shared_ptr LoadResourceAsync(const urde::SObjectTag& tag, void* target) override; - std::shared_ptr LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, + u32 ResourceSize(const metaforce::SObjectTag& tag) override; + std::shared_ptr LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) override; + std::shared_ptr LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size, void* target) override; - std::unique_ptr LoadResourceSync(const urde::SObjectTag& tag) override; - std::unique_ptr LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size) override; + std::unique_ptr LoadResourceSync(const metaforce::SObjectTag& tag) override; + std::unique_ptr LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) override; }; private: @@ -44,4 +44,4 @@ public: TToken GetFactory(const CAnimRes& res); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBodyController.cpp b/Runtime/Character/CBodyController.cpp index 4e077b60e..f0bb979bf 100644 --- a/Runtime/Character/CBodyController.cpp +++ b/Runtime/Character/CBodyController.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CBodyController::CBodyController(CActor& actor, float turnSpeed, EBodyType bodyType) : x0_actor(actor) @@ -80,7 +80,7 @@ void CBodyController::Update(float dt, CStateManager& mgr) { } } -bool CBodyController::HasBodyState(pas::EAnimationState state) const { return GetPASDatabase().HasState(s32(state)); } +bool CBodyController::HasBodyState(pas::EAnimationState state) const { return GetPASDatabase().HasState(state); } void CBodyController::SetCurrentAnimation(const CAnimPlaybackParms& parms, bool loop, bool noTrans) { x0_actor.GetModelData()->GetAnimationData()->SetAnimation(parms, noTrans); @@ -269,7 +269,8 @@ void CBodyController::UpdateFrozenInfo(float dt, CStateManager& mgr) { } bool CBodyController::HasIceBreakoutState() const { - CPASAnimParmData parms(24, CPASAnimParm::FromEnum(3)); + CPASAnimParmData parms(pas::EAnimationState::AdditiveReaction, + CPASAnimParm::FromEnum(static_cast(pas::EAdditiveReactionType::IceBreakout))); std::pair best = GetPASDatabase().FindBestAnimation(parms, -1); return best.first > 0.f; } @@ -288,4 +289,4 @@ void CBodyController::FrozenBreakout() { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBodyController.hpp b/Runtime/Character/CBodyController.hpp index 980085c16..a9078f82d 100644 --- a/Runtime/Character/CBodyController.hpp +++ b/Runtime/Character/CBodyController.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class CActor; class CAnimPlaybackParms; class CPASAnimParmData; @@ -103,4 +103,4 @@ public: void SetRestrictedFlyerMoveSpeed(float speed) { x330_restrictedFlyerMoveSpeed = speed; } bool GetActive() const { return x300_25_active; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBodyState.cpp b/Runtime/Character/CBodyState.cpp index ccc529a3d..47c769c7c 100644 --- a/Runtime/Character/CBodyState.cpp +++ b/Runtime/Character/CBodyState.cpp @@ -8,12 +8,12 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { void CBSAttack::Start(CBodyController& bc, CStateManager& mgr) { const auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::MeleeAttack)); const CPASDatabase& pasDatabase = bc.GetPASDatabase(); - const CPASAnimParmData parms(7, CPASAnimParm::FromEnum(s32(cmd->GetAttackSeverity())), + const CPASAnimParmData parms(pas::EAnimationState::MeleeAttack, CPASAnimParm::FromEnum(s32(cmd->GetAttackSeverity())), CPASAnimParm::FromEnum(s32(bc.GetLocomotionType()))); const std::pair best = pasDatabase.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); @@ -121,13 +121,14 @@ void CBSProjectileAttack::Start(CBodyController& bc, CStateManager& mgr) { zeus::CRelAngle angle = std::atan2(localDelta.y(), localDelta.x()); angle.makeRel(); const float attackAngle = angle.asDegrees(); - const CPASAnimParmData parms(18, CPASAnimParm::FromEnum(s32(cmd->GetAttackSeverity())), - CPASAnimParm::FromReal32(angle.asDegrees()), - CPASAnimParm::FromEnum(s32(bc.GetLocomotionType()))); + const CPASAnimParmData parms( + pas::EAnimationState::ProjectileAttack, CPASAnimParm::FromEnum(s32(cmd->GetAttackSeverity())), + CPASAnimParm::FromReal32(angle.asDegrees()), CPASAnimParm::FromEnum(s32(bc.GetLocomotionType()))); const std::pair best1 = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (cmd->BlendTwoClosest()) { - const std::pair best2 = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), best1.second); - const CPASAnimState* projAttackState = bc.GetPASDatabase().GetAnimState(18); + const std::pair best2 = + bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), best1.second); + const CPASAnimState* projAttackState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::ProjectileAttack); float angle1 = projAttackState->GetAnimParmData(best1.second, 1).GetReal32Value(); float angle2 = projAttackState->GetAnimParmData(best2.second, 1).GetReal32Value(); if (angle1 - angle2 > 180.f) { @@ -178,7 +179,7 @@ pas::EAnimationState CBSProjectileAttack::UpdateBody(float dt, CBodyController& void CBSDie::Start(CBodyController& bc, CStateManager& mgr) { bool shouldReset = true; if (bc.ShouldPlayDeathAnims()) { - const CPASAnimParmData parms(4, CPASAnimParm::FromEnum(s32(bc.GetFallState()))); + const CPASAnimParmData parms(pas::EAnimationState::Death, CPASAnimParm::FromEnum(s32(bc.GetFallState()))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > 0.f) { const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); @@ -210,12 +211,12 @@ void CBSFall::Start(CBodyController& bc, CStateManager& mgr) { zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetHitDirection()); zeus::CRelAngle angle = std::atan2(localDir.y(), localDir.z()); angle.makeRel(); - const CPASAnimParmData parms(0, CPASAnimParm::FromReal32(angle.asDegrees()), + const CPASAnimParmData parms(pas::EAnimationState::Fall, CPASAnimParm::FromReal32(angle.asDegrees()), CPASAnimParm::FromEnum(s32(cmd->GetHitSeverity()))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); - const CPASAnimState* knockdownState = bc.GetPASDatabase().GetAnimState(0); + const CPASAnimState* knockdownState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Fall); if (!knockdownState->GetAnimParmData(best.second, 2).GetBoolValue()) { const float animAngle = zeus::degToRad(knockdownState->GetAnimParmData(best.second, 0).GetReal32Value()); zeus::CRelAngle delta1 = angle - animAngle; @@ -255,7 +256,7 @@ void CBSFall::Shutdown(CBodyController& bc) { bc.SetFallState(xc_fallState); } void CBSGetup::Start(CBodyController& bc, CStateManager& mgr) { const auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Getup)); - const CPASAnimParmData parms(1, CPASAnimParm::FromEnum(s32(bc.GetFallState())), + const CPASAnimParmData parms(pas::EAnimationState::Getup, CPASAnimParm::FromEnum(s32(bc.GetFallState())), CPASAnimParm::FromEnum(s32(cmd->GetGetupType()))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > FLT_EPSILON) { @@ -263,7 +264,8 @@ void CBSGetup::Start(CBodyController& bc, CStateManager& mgr) { const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); } - x4_fallState = pas::EFallState(bc.GetPASDatabase().GetAnimState(1)->GetAnimParmData(best.second, 2).GetEnumValue()); + x4_fallState = pas::EFallState( + bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Getup)->GetAnimParmData(best.second, 2).GetEnumValue()); } else { x4_fallState = pas::EFallState::Zero; } @@ -296,12 +298,12 @@ void CBSKnockBack::Start(CBodyController& bc, CStateManager& mgr) { const zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetHitDirection()); zeus::CRelAngle angle = std::atan2(localDir.y(), localDir.x()); angle.makeRel(); - const CPASAnimParmData parms(6, CPASAnimParm::FromReal32(angle.asDegrees()), + const CPASAnimParmData parms(pas::EAnimationState::KnockBack, CPASAnimParm::FromReal32(angle.asDegrees()), CPASAnimParm::FromEnum(s32(cmd->GetHitSeverity()))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); - const CPASAnimState* knockbackState = bc.GetPASDatabase().GetAnimState(6); + const CPASAnimState* knockbackState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::KnockBack); if (!knockbackState->GetAnimParmData(best.second, 2).GetBoolValue()) { const float animAngle = zeus::degToRad(knockbackState->GetAnimParmData(best.second, 0).GetReal32Value()); zeus::CRelAngle delta1 = angle - animAngle; @@ -353,11 +355,12 @@ pas::EAnimationState CBSKnockBack::UpdateBody(float dt, CBodyController& bc, CSt } CBSLieOnGround::CBSLieOnGround(CActor& actor) { - x4_24_hasGroundHit = actor.GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase().HasState(11); + x4_24_hasGroundHit = actor.GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase().HasState( + pas::EAnimationState::GroundHit); } void CBSLieOnGround::Start(CBodyController& bc, CStateManager& mgr) { - const CPASAnimParmData parms(2, CPASAnimParm::FromEnum(s32(bc.GetFallState()))); + const CPASAnimParmData parms(pas::EAnimationState::LieOnGround, CPASAnimParm::FromEnum(s32(bc.GetFallState()))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > 0.f) { const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); @@ -388,7 +391,7 @@ void CBSLieOnGround::Shutdown(CBodyController& bc) { bc.EnableAnimation(true); } void CBSStep::Start(CBodyController& bc, CStateManager& mgr) { const auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Step)); - const CPASAnimParmData parms(3, CPASAnimParm::FromEnum(s32(cmd->GetStepDirection())), + const CPASAnimParmData parms(pas::EAnimationState::Step, CPASAnimParm::FromEnum(s32(cmd->GetStepDirection())), CPASAnimParm::FromEnum(s32(cmd->GetStepType()))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); } @@ -450,12 +453,14 @@ void CBSTurn::Start(CBodyController& bc, CStateManager& mgr) { x8_dest = zeus::CVector2f(bc.GetCommandMgr().GetFaceVector().toVec2f()); const float deltaAngle = zeus::radToDeg(zeus::CVector2f::getAngleDiff(lookDir2d, x8_dest)); x10_turnDir = pas::ETurnDirection(zeus::CVector2f(lookDir2d.y(), -lookDir2d.x()).dot(x8_dest) > 0.f); - const CPASAnimParmData parms(8, CPASAnimParm::FromEnum(s32(x10_turnDir)), CPASAnimParm::FromReal32(deltaAngle), + const CPASAnimParmData parms(pas::EAnimationState::Turn, CPASAnimParm::FromEnum(s32(x10_turnDir)), + CPASAnimParm::FromReal32(deltaAngle), CPASAnimParm::FromEnum(s32(bc.GetLocomotionType()))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); - const float animAngle = bc.GetPASDatabase().GetAnimState(8)->GetAnimParmData(best.second, 1).GetReal32Value(); + const float animAngle = + bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Turn)->GetAnimParmData(best.second, 1).GetReal32Value(); x4_rotateSpeed = zeus::degToRad((x10_turnDir == pas::ETurnDirection::Left) ? animAngle - deltaAngle : deltaAngle - animAngle); const float timeRem = bc.GetAnimTimeRemaining(); @@ -539,14 +544,15 @@ pas::EAnimationState CBSTurn::UpdateBody(float dt, CBodyController& bc, CStateMa } void CBSFlyerTurn::Start(CBodyController& bc, CStateManager& mgr) { - if (bc.GetPASDatabase().GetAnimState(8)->HasAnims()) { + if (bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Turn)->HasAnims()) { CBSTurn::Start(bc, mgr); } else { x8_dest = zeus::CVector2f(bc.GetCommandMgr().GetFaceVector().toVec2f()); const zeus::CVector3f& lookDir = bc.GetOwner().GetTransform().basis[1]; const zeus::CVector2f lookDir2d(lookDir.toVec2f()); x10_turnDir = pas::ETurnDirection(zeus::CVector2f(lookDir2d.y(), -lookDir2d.x()).dot(x8_dest) > 0.f); - const CPASAnimParmData parms(5, CPASAnimParm::FromEnum(0), CPASAnimParm::FromEnum(s32(bc.GetLocomotionType()))); + const CPASAnimParmData parms(pas::EAnimationState::Locomotion, CPASAnimParm::FromEnum(0), + CPASAnimParm::FromEnum(s32(bc.GetLocomotionType()))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.second != bc.GetCurrentAnimId()) { const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); @@ -556,7 +562,7 @@ void CBSFlyerTurn::Start(CBodyController& bc, CStateManager& mgr) { } pas::EAnimationState CBSFlyerTurn::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) { - if (bc.GetPASDatabase().GetAnimState(8)->HasAnims()) { + if (bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Turn)->HasAnims()) { return CBSTurn::UpdateBody(dt, bc, mgr); } @@ -580,12 +586,12 @@ void CBSLoopAttack::Start(CBodyController& bc, CStateManager& mgr) { xc_25_advance = false; if (bc.GetLocomotionType() == pas::ELocomotionType::Crouch) { - const CPASAnimParmData parms(9, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData parms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_loopAttackType))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); } else { x4_state = pas::ELoopState::Begin; - const CPASAnimParmData parms(9, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData parms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_loopAttackType))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > FLT_EPSILON) { @@ -593,7 +599,7 @@ void CBSLoopAttack::Start(CBodyController& bc, CStateManager& mgr) { bc.SetCurrentAnimation(playParms, false, false); } else { x4_state = pas::ELoopState::Loop; - const CPASAnimParmData loopParms(9, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData loopParms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_loopAttackType))); bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom()); } @@ -652,7 +658,8 @@ pas::EAnimationState CBSLoopAttack::UpdateBody(float dt, CBodyController& bc, CS return pas::EAnimationState::Locomotion; } if (bc.IsAnimationOver()) { - const CPASAnimParmData parms(9, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(s32(x8_loopAttackType))); + const CPASAnimParmData parms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(1), + CPASAnimParm::FromEnum(s32(x8_loopAttackType))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); x4_state = pas::ELoopState::Loop; } else if (!bc.GetCommandMgr().GetTargetVector().isZero()) { @@ -662,7 +669,8 @@ pas::EAnimationState CBSLoopAttack::UpdateBody(float dt, CBodyController& bc, CS case pas::ELoopState::Loop: if (xc_25_advance && (!xc_24_waitForAnimOver || bc.IsAnimationOver())) { if (bc.GetLocomotionType() != pas::ELocomotionType::Crouch) { - const CPASAnimParmData parms(9, CPASAnimParm::FromEnum(2), CPASAnimParm::FromEnum(s32(x8_loopAttackType))); + const CPASAnimParmData parms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(2), + CPASAnimParm::FromEnum(s32(x8_loopAttackType))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); x4_state = pas::ELoopState::End; } else { @@ -697,14 +705,15 @@ void CBSLoopReaction::Start(CBodyController& bc, CStateManager& mgr) { } x4_state = pas::ELoopState::Begin; - const CPASAnimParmData parms(10, CPASAnimParm::FromEnum(s32(x8_reactionType)), CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::LoopReaction, CPASAnimParm::FromEnum(s32(x8_reactionType)), + CPASAnimParm::FromEnum(s32(x4_state))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > FLT_EPSILON) { const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); } else { x4_state = pas::ELoopState::Loop; - const CPASAnimParmData loopParms(10, CPASAnimParm::FromEnum(s32(x8_reactionType)), + const CPASAnimParmData loopParms(pas::EAnimationState::LoopReaction, CPASAnimParm::FromEnum(s32(x8_reactionType)), CPASAnimParm::FromEnum(s32(x4_state))); bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom()); } @@ -748,7 +757,8 @@ pas::EAnimationState CBSLoopReaction::GetBodyStateTransition(float dt, const CBo } bool CBSLoopReaction::PlayExitAnimation(CBodyController& bc, CStateManager& mgr) const { - const CPASAnimParmData parms(10, CPASAnimParm::FromEnum(int(x8_reactionType)), CPASAnimParm::FromEnum(2)); + const CPASAnimParmData parms(pas::EAnimationState::LoopReaction, CPASAnimParm::FromEnum(int(x8_reactionType)), + CPASAnimParm::FromEnum(2)); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > 0.f) { const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); @@ -772,7 +782,8 @@ pas::EAnimationState CBSLoopReaction::UpdateBody(float dt, CBodyController& bc, } } else { if (bc.IsAnimationOver()) { - const CPASAnimParmData parms(10, CPASAnimParm::FromEnum(s32(x8_reactionType)), CPASAnimParm::FromEnum(1)); + const CPASAnimParmData parms(pas::EAnimationState::LoopReaction, CPASAnimParm::FromEnum(s32(x8_reactionType)), + CPASAnimParm::FromEnum(1)); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); x4_state = pas::ELoopState::Loop; } else if (!bc.GetCommandMgr().GetTargetVector().isZero()) { @@ -810,12 +821,12 @@ void CBSGroundHit::Start(CBodyController& bc, CStateManager& mgr) { const zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetHitDirection()); zeus::CRelAngle angle = std::atan2(localDir.y(), localDir.x()); angle.makeRel(); - const CPASAnimParmData parms(11, CPASAnimParm::FromEnum(s32(bc.GetFallState())), + const CPASAnimParmData parms(pas::EAnimationState::GroundHit, CPASAnimParm::FromEnum(s32(bc.GetFallState())), CPASAnimParm::FromReal32(angle.asDegrees())); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); - const CPASAnimState* groundHitState = bc.GetPASDatabase().GetAnimState(11); + const CPASAnimState* groundHitState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::GroundHit); if (!groundHitState->GetAnimParmData(best.second, 2).GetBoolValue()) { const float animAngle = zeus::degToRad(groundHitState->GetAnimParmData(best.second, 1).GetReal32Value()); zeus::CRelAngle delta1 = angle - animAngle; @@ -860,7 +871,7 @@ void CBSGenerate::Start(CBodyController& bc, CStateManager& mgr) { const auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Generate)); s32 anim; if (!cmd->UseSpecialAnimId()) { - const CPASAnimParmData parms(12, CPASAnimParm::FromEnum(s32(cmd->GetGenerateType()))); + const CPASAnimParmData parms(pas::EAnimationState::Generate, CPASAnimParm::FromEnum(s32(cmd->GetGenerateType()))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); anim = best.second; } else { @@ -918,7 +929,8 @@ void CBSJump::Start(CBodyController& bc, CStateManager& mgr) { } if (!cmd->StartInJumpLoop()) { x4_state = pas::EJumpState::IntoJump; - const CPASAnimParmData parms(13, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_jumpType))); + const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)), + CPASAnimParm::FromEnum(s32(x8_jumpType))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); } else { PlayJumpLoop(mgr, bc); @@ -949,7 +961,8 @@ bool CBSJump::CheckForWallJump(CBodyController& bc, CStateManager& mgr) { const float xExtent = (aabb.max.x() - aabb.min.x()) * 0.5f; if (distToWall < 1.414f * xExtent || (act->MadeSolidCollision() && distToWall < 3.f * xExtent)) { x4_state = x30_26_wallBounceRight ? pas::EJumpState::WallBounceRight : pas::EJumpState::WallBounceLeft; - const CPASAnimParmData parms(13, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_jumpType))); + const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)), + CPASAnimParm::FromEnum(s32(x8_jumpType))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor); return true; @@ -963,7 +976,8 @@ void CBSJump::CheckForLand(CBodyController& bc, CStateManager& mgr) { if (const TCastToPtr act = bc.GetOwner()) { if (act->MadeSolidCollision() || act->IsOnGround()) { x4_state = pas::EJumpState::OutOfJump; - const CPASAnimParmData parms(13, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_jumpType))); + const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)), + CPASAnimParm::FromEnum(s32(x8_jumpType))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor); } @@ -971,7 +985,8 @@ void CBSJump::CheckForLand(CBodyController& bc, CStateManager& mgr) { } void CBSJump::PlayJumpLoop(CStateManager& mgr, CBodyController& bc) { - const CPASAnimParmData parms(13, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(s32(x8_jumpType))); + const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(1), + CPASAnimParm::FromEnum(s32(x8_jumpType))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > 99.f) { x4_state = pas::EJumpState::AmbushJump; @@ -979,7 +994,7 @@ void CBSJump::PlayJumpLoop(CStateManager& mgr, CBodyController& bc) { bc.SetCurrentAnimation(playParms, false, false); } else { x4_state = pas::EJumpState::Loop; - const CPASAnimParmData loopParms(13, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData loopParms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_jumpType))); bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom()); } @@ -1013,7 +1028,7 @@ pas::EAnimationState CBSJump::UpdateBody(float dt, CBodyController& bc, CStateMa } if (bc.IsAnimationOver()) { x4_state = pas::EJumpState::Loop; - const CPASAnimParmData parms(13, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_jumpType))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); } else { @@ -1045,7 +1060,7 @@ pas::EAnimationState CBSJump::UpdateBody(float dt, CBodyController& bc, CStateMa if (bc.IsAnimationOver()) { mgr.SendScriptMsg(&bc.GetOwner(), kInvalidUniqueId, EScriptObjectMessage::Falling); x4_state = pas::EJumpState::Loop; - const CPASAnimParmData parms(13, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_jumpType))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); x30_27_wallBounceComplete = true; @@ -1070,10 +1085,7 @@ pas::EAnimationState CBSJump::UpdateBody(float dt, CBodyController& bc, CStateMa } bool CBSJump::ApplyAnimationDeltas() const { - if (x4_state == pas::EJumpState::AmbushJump || x4_state == pas::EJumpState::Loop) { - return false; - } - return true; + return !(x4_state == pas::EJumpState::AmbushJump || x4_state == pas::EJumpState::Loop); } bool CBSJump::IsInAir(const CBodyController& bc) const { @@ -1089,12 +1101,12 @@ void CBSHurled::Start(CBodyController& bc, CStateManager& mgr) { zeus::CRelAngle angle = std::atan2(localDir.y(), localDir.x()); angle.makeRel(); x8_knockAngle = angle.asDegrees(); - const CPASAnimParmData parms(14, CPASAnimParm::FromInt32(-1), CPASAnimParm::FromReal32(x8_knockAngle), - CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(-1), + CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(s32(x4_state))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); - const CPASAnimState* hurledState = bc.GetPASDatabase().GetAnimState(14); + const CPASAnimState* hurledState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Hurled); xc_animSeries = hurledState->GetAnimParmData(best.second, 0).GetInt32Value(); mgr.SendScriptMsg(&bc.GetOwner(), kInvalidUniqueId, EScriptObjectMessage::Falling); mgr.SendScriptMsg(&bc.GetOwner(), kInvalidUniqueId, EScriptObjectMessage::Jumped); @@ -1132,8 +1144,8 @@ pas::EAnimationState CBSHurled::GetBodyStateTransition(float dt, CBodyController } void CBSHurled::Recover(CStateManager& mgr, CBodyController& bc, pas::EHurledState state) { - const CPASAnimParmData parms(14, CPASAnimParm::FromInt32(xc_animSeries), CPASAnimParm::FromReal32(x8_knockAngle), - CPASAnimParm::FromEnum(s32(state))); + const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries), + CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(s32(state))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > FLT_EPSILON) { const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); @@ -1147,8 +1159,8 @@ void CBSHurled::Recover(CStateManager& mgr, CBodyController& bc, pas::EHurledSta } void CBSHurled::PlayStrikeWallAnimation(CBodyController& bc, CStateManager& mgr) { - const CPASAnimParmData parms(14, CPASAnimParm::FromInt32(xc_animSeries), CPASAnimParm::FromReal32(x8_knockAngle), - CPASAnimParm::FromEnum(3)); + const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries), + CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(3)); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first <= FLT_EPSILON) { @@ -1161,12 +1173,12 @@ void CBSHurled::PlayStrikeWallAnimation(CBodyController& bc, CStateManager& mgr) } void CBSHurled::PlayLandAnimation(CBodyController& bc, CStateManager& mgr) { - const CPASAnimParmData parms(14, CPASAnimParm::FromInt32(xc_animSeries), CPASAnimParm::FromReal32(x8_knockAngle), - CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries), + CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(s32(x4_state))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); - const CPASAnimState* hurledState = bc.GetPASDatabase().GetAnimState(14); + const CPASAnimState* hurledState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Hurled); bc.SetFallState(pas::EFallState(hurledState->GetAnimParmData(best.second, 3).GetEnumValue())); if (const TCastToPtr act = bc.GetOwner()) { mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor); @@ -1220,7 +1232,7 @@ pas::EAnimationState CBSHurled::UpdateBody(float dt, CBodyController& bc, CState switch (x4_state) { case pas::EHurledState::KnockIntoAir: { if (bc.IsAnimationOver()) { - const CPASAnimParmData parms(14, CPASAnimParm::FromInt32(xc_animSeries), + const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries), CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(1)); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); x4_state = pas::EHurledState::KnockLoop; @@ -1244,7 +1256,7 @@ pas::EAnimationState CBSHurled::UpdateBody(float dt, CBodyController& bc, CState case pas::EHurledState::StrikeWall: if (bc.IsAnimationOver()) { x4_state = pas::EHurledState::StrikeWallFallLoop; - const CPASAnimParmData parms(14, CPASAnimParm::FromInt32(xc_animSeries), + const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries), CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(s32(x4_state))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); x28_landedDur = 0.f; @@ -1289,14 +1301,14 @@ void CBSSlide::Start(CBodyController& bc, CStateManager& mgr) { const auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Slide)); const zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetSlideDirection()); const float angle = std::atan2(localDir.y(), localDir.x()); - const CPASAnimParmData parms(15, CPASAnimParm::FromEnum(s32(cmd->GetSlideType())), + const CPASAnimParmData parms(pas::EAnimationState::Slide, CPASAnimParm::FromEnum(s32(cmd->GetSlideType())), CPASAnimParm::FromReal32(zeus::radToDeg(angle))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); bc.SetCurrentAnimation(playParms, false, false); const float timeRem = bc.GetAnimTimeRemaining(); if (timeRem > FLT_EPSILON) { - const CPASAnimState* slideState = bc.GetPASDatabase().GetAnimState(15); + const CPASAnimState* slideState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Slide); const float animAngle = zeus::degToRad(slideState->GetAnimParmData(best.second, 1).GetReal32Value()); const float delta1 = zeus::CRelAngle(angle - animAngle).asRel(); const float flippedAngle = (delta1 > M_PIF) ? delta1 - 2.f * M_PIF : delta1; @@ -1337,7 +1349,7 @@ pas::EAnimationState CBSSlide::UpdateBody(float dt, CBodyController& bc, CStateM void CBSTaunt::Start(CBodyController& bc, CStateManager& mgr) { const auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Taunt)); - const CPASAnimParmData parms(16, CPASAnimParm::FromEnum(s32(cmd->GetTauntType()))); + const CPASAnimParmData parms(pas::EAnimationState::Taunt, CPASAnimParm::FromEnum(s32(cmd->GetTauntType()))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); } @@ -1425,7 +1437,7 @@ void CBSCover::Start(CBodyController& bc, CStateManager& mgr) { const auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Cover)); x8_coverDirection = cmd->GetDirection(); x4_state = pas::ECoverState::IntoCover; - const CPASAnimParmData parms(19, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData parms(pas::EAnimationState::Cover, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_coverDirection))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const zeus::CQuaternion orientDelta = @@ -1466,7 +1478,7 @@ pas::EAnimationState CBSCover::UpdateBody(float dt, CBodyController& bc, CStateM case pas::ECoverState::IntoCover: if (bc.IsAnimationOver()) { x4_state = pas::ECoverState::Cover; - const CPASAnimParmData parms(19, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData parms(pas::EAnimationState::Cover, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_coverDirection))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); } @@ -1481,12 +1493,12 @@ pas::EAnimationState CBSCover::UpdateBody(float dt, CBodyController& bc, CStateM if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState) || xc_needsExit) { xc_needsExit = false; x4_state = pas::ECoverState::OutOfCover; - const CPASAnimParmData parms(19, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData parms(pas::EAnimationState::Cover, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_coverDirection))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); } else if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LeanFromCover)) { x4_state = pas::ECoverState::Lean; - const CPASAnimParmData parms(19, CPASAnimParm::FromEnum(s32(x4_state)), + const CPASAnimParmData parms(pas::EAnimationState::Cover, CPASAnimParm::FromEnum(s32(x4_state)), CPASAnimParm::FromEnum(s32(x8_coverDirection))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); } @@ -1509,7 +1521,7 @@ void CBSWallHang::Start(CBodyController& bc, CStateManager& mgr) { x4_state = pas::EWallHangState::IntoJump; x8_wpId = cmd->GetTarget(); x18_25_needsExit = false; - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); } @@ -1534,7 +1546,7 @@ bool CBSWallHang::CheckForLand(CBodyController& bc, CStateManager& mgr) { if (const TCastToPtr ai = bc.GetOwner()) { if (ai->MadeSolidCollision() || ai->IsOnGround()) { x4_state = pas::EWallHangState::DetachOutOfJump; - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); mgr.SendScriptMsg(ai.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor); return true; @@ -1553,7 +1565,7 @@ bool CBSWallHang::CheckForWall(CBodyController& bc, CStateManager& mgr) { if (magSq < 1.f || ai->MadeSolidCollision()) { x4_state = pas::EWallHangState::IntoWallHang; - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); const zeus::CVector3f& target = wp ? wp->GetTranslation() : ai->GetTranslation(); const CAnimPlaybackParms playParms(best.second, nullptr, &target, &bc.GetOwner().GetTransform(), @@ -1586,7 +1598,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta if (st == pas::EAnimationState::Invalid) { switch (x4_state) { case pas::EWallHangState::IntoJump: { - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(1)); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(1)); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > 0.f) { x4_state = pas::EWallHangState::JumpArc; @@ -1594,7 +1606,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta bc.SetCurrentAnimation(playParms, false, false); } else { x4_state = pas::EWallHangState::JumpAirLoop; - const CPASAnimParmData loopParms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData loopParms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom()); } if (const TCastToPtr act = bc.GetOwner()) { @@ -1616,7 +1628,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta SetLaunchVelocity(bc); if (bc.IsAnimationOver()) { x4_state = pas::EWallHangState::JumpAirLoop; - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); } else { CheckForWall(bc, mgr); @@ -1633,7 +1645,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta case pas::EWallHangState::IntoWallHang: { if (bc.IsAnimationOver()) { x4_state = pas::EWallHangState::WallHang; - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); } else if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState)) { x18_25_needsExit = true; @@ -1655,7 +1667,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta } if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState) || x18_25_needsExit) { x4_state = pas::EWallHangState::OutOfWallHang; - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.PlayBestAnimation(parms, *mgr.GetActiveRandom()); } FixInPlace(bc); @@ -1664,7 +1676,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta case pas::EWallHangState::Five: { if (bc.IsAnimationOver()) { x4_state = pas::EWallHangState::WallHang; - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); } FixInPlace(bc); @@ -1672,7 +1684,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta } case pas::EWallHangState::OutOfWallHang: { if (bc.IsAnimationOver()) { - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(7)); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(7)); const std::pair best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (best.first > 0.f) { x4_state = pas::EWallHangState::OutOfWallHangTurn; @@ -1680,7 +1692,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta bc.SetCurrentAnimation(playParms, false, false); } else { x4_state = pas::EWallHangState::DetachJumpLoop; - const CPASAnimParmData loopParms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData loopParms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom()); } if (const TCastToPtr act = bc.GetOwner()) { @@ -1701,7 +1713,7 @@ pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CSta SetLaunchVelocity(bc); if (bc.IsAnimationOver()) { x4_state = pas::EWallHangState::DetachJumpLoop; - const CPASAnimParmData parms(20, CPASAnimParm::FromEnum(s32(x4_state))); + const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state))); bc.LoopBestAnimation(parms, *mgr.GetActiveRandom()); } else { CheckForLand(bc, mgr); @@ -1923,7 +1935,8 @@ CBSBiPedLocomotion::CBSBiPedLocomotion(CActor& actor) { for (int i = 0; i < 14; ++i) { rstl::reserved_vector, 8>& innerVec = x8_anims.emplace_back(); for (int j = 0; j < 8; ++j) { - const CPASAnimParmData parms(5, CPASAnimParm::FromEnum(j), CPASAnimParm::FromEnum(i)); + const CPASAnimParmData parms(pas::EAnimationState::Locomotion, CPASAnimParm::FromEnum(j), + CPASAnimParm::FromEnum(i)); const std::pair best = pasDatabase.FindBestAnimation(parms, -1); float avgVel = 0.f; if (best.second != -1) { @@ -2159,7 +2172,8 @@ float CBSNewFlyerLocomotion::UpdateLocomotionAnimation(float dt, float velMag, C CBSRestrictedLocomotion::CBSRestrictedLocomotion(CActor& actor) { const CPASDatabase& pasDatabase = actor.GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase(); for (int i = 0; i < 14; ++i) { - const CPASAnimParmData parms(5, CPASAnimParm::FromEnum(0), CPASAnimParm::FromEnum(i)); + const CPASAnimParmData parms(pas::EAnimationState::Locomotion, CPASAnimParm::FromEnum(0), + CPASAnimParm::FromEnum(i)); const std::pair best = pasDatabase.FindBestAnimation(parms, -1); x8_anims.push_back(best.second); } @@ -2189,4 +2203,4 @@ float CBSRestrictedFlyerLocomotion::ApplyLocomotionPhysics(float dt, CBodyContro return 0.f; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBodyState.hpp b/Runtime/Character/CBodyState.hpp index 0a82ea638..f17be786b 100644 --- a/Runtime/Character/CBodyState.hpp +++ b/Runtime/Character/CBodyState.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CBodyController; class CStateManager; class CActor; @@ -404,4 +404,4 @@ public: explicit CBSRestrictedFlyerLocomotion(CActor& actor); float ApplyLocomotionPhysics(float dt, CBodyController& bc) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBodyStateCmdMgr.cpp b/Runtime/Character/CBodyStateCmdMgr.cpp index 139a8bc3b..13e5c1ded 100644 --- a/Runtime/Character/CBodyStateCmdMgr.cpp +++ b/Runtime/Character/CBodyStateCmdMgr.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { CBodyStateCmdMgr::CBodyStateCmdMgr() { x40_commandTable.push_back(&xb8_getup); @@ -87,4 +87,4 @@ void CBodyStateCmdMgr::ClearLocomotionCmds() { x3c_steeringSpeed = 0.f; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBodyStateCmdMgr.hpp b/Runtime/Character/CBodyStateCmdMgr.hpp index 9e7773d68..4949a77c3 100644 --- a/Runtime/Character/CBodyStateCmdMgr.hpp +++ b/Runtime/Character/CBodyStateCmdMgr.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CBodyStateCmd { EBodyStateCmd x4_cmd; @@ -452,4 +452,4 @@ public: const zeus::CVector3f& GetAdditiveTargetVector() const { return x24_additiveTarget; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBodyStateInfo.cpp b/Runtime/Character/CBodyStateInfo.cpp index a3a480127..a74d8cd19 100644 --- a/Runtime/Character/CBodyStateInfo.cpp +++ b/Runtime/Character/CBodyStateInfo.cpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CBodyController.hpp" #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { CBodyStateInfo::CBodyStateInfo(CActor& actor, EBodyType type) { x34_24_changeLocoAtEndOfAnimOnly = false; @@ -48,321 +48,321 @@ CBodyStateInfo::CBodyStateInfo(CActor& actor, EBodyType type) { x1c_additiveStates.emplace_back(pas::EAnimationState::AdditiveReaction, std::make_unique()); } -std::unique_ptr CBodyStateInfo::SetupRestrictedFlyerBodyStates(int stateId, CActor& actor) const { +std::unique_ptr CBodyStateInfo::SetupRestrictedFlyerBodyStates(pas::EAnimationState stateId, CActor& actor) const { switch (stateId) { - case 0: + case pas::EAnimationState::Fall: return std::make_unique(); - case 1: + case pas::EAnimationState::Getup: return std::make_unique(); - case 2: + case pas::EAnimationState::LieOnGround: return std::make_unique(actor); - case 3: + case pas::EAnimationState::Step: return std::make_unique(); - case 4: + case pas::EAnimationState::Death: return std::make_unique(); - case 5: + case pas::EAnimationState::Locomotion: return std::make_unique(actor); - case 6: + case pas::EAnimationState::KnockBack: return std::make_unique(); - case 7: + case pas::EAnimationState::MeleeAttack: return std::make_unique(); - case 18: + case pas::EAnimationState::ProjectileAttack: return std::make_unique(); - case 9: + case pas::EAnimationState::LoopAttack: return std::make_unique(); - case 8: + case pas::EAnimationState::Turn: return std::make_unique(); - case 10: + case pas::EAnimationState::LoopReaction: return std::make_unique(); - case 11: + case pas::EAnimationState::GroundHit: return std::make_unique(); - case 12: + case pas::EAnimationState::Generate: return std::make_unique(); - case 13: + case pas::EAnimationState::Jump: return std::make_unique(); - case 14: + case pas::EAnimationState::Hurled: return std::make_unique(); - case 15: + case pas::EAnimationState::Slide: return std::make_unique(); - case 16: + case pas::EAnimationState::Taunt: return std::make_unique(); - case 17: + case pas::EAnimationState::Scripted: return std::make_unique(); default: return {}; } } -std::unique_ptr CBodyStateInfo::SetupNewFlyerBodyStates(int stateId, CActor& actor) const { +std::unique_ptr CBodyStateInfo::SetupNewFlyerBodyStates(pas::EAnimationState stateId, CActor& actor) const { switch (stateId) { - case 0: + case pas::EAnimationState::Fall: return std::make_unique(); - case 1: + case pas::EAnimationState::Getup: return std::make_unique(); - case 2: + case pas::EAnimationState::LieOnGround: return std::make_unique(actor); - case 3: + case pas::EAnimationState::Step: return std::make_unique(); - case 4: + case pas::EAnimationState::Death: return std::make_unique(); - case 5: + case pas::EAnimationState::Locomotion: return std::make_unique(actor); - case 6: + case pas::EAnimationState::KnockBack: return std::make_unique(); - case 7: + case pas::EAnimationState::MeleeAttack: return std::make_unique(); - case 18: + case pas::EAnimationState::ProjectileAttack: return std::make_unique(); - case 9: + case pas::EAnimationState::LoopAttack: return std::make_unique(); - case 8: + case pas::EAnimationState::Turn: return std::make_unique(); - case 10: + case pas::EAnimationState::LoopReaction: return std::make_unique(); - case 11: + case pas::EAnimationState::GroundHit: return std::make_unique(); - case 12: + case pas::EAnimationState::Generate: return std::make_unique(); - case 13: + case pas::EAnimationState::Jump: return std::make_unique(); - case 14: + case pas::EAnimationState::Hurled: return std::make_unique(); - case 15: + case pas::EAnimationState::Slide: return std::make_unique(); - case 16: + case pas::EAnimationState::Taunt: return std::make_unique(); - case 17: + case pas::EAnimationState::Scripted: return std::make_unique(); default: return {}; } } -std::unique_ptr CBodyStateInfo::SetupWallWalkerBodyStates(int stateId, CActor& actor) const { +std::unique_ptr CBodyStateInfo::SetupWallWalkerBodyStates(pas::EAnimationState stateId, CActor& actor) const { switch (stateId) { - case 0: + case pas::EAnimationState::Fall: return std::make_unique(); - case 1: + case pas::EAnimationState::Getup: return std::make_unique(); - case 2: + case pas::EAnimationState::LieOnGround: return std::make_unique(actor); - case 3: + case pas::EAnimationState::Step: return std::make_unique(); - case 4: + case pas::EAnimationState::Death: return std::make_unique(); - case 5: + case pas::EAnimationState::Locomotion: return std::make_unique(actor); - case 6: + case pas::EAnimationState::KnockBack: return std::make_unique(); - case 7: + case pas::EAnimationState::MeleeAttack: return std::make_unique(); - case 18: + case pas::EAnimationState::ProjectileAttack: return std::make_unique(); - case 9: + case pas::EAnimationState::LoopAttack: return std::make_unique(); - case 8: + case pas::EAnimationState::Turn: return std::make_unique(); - case 10: + case pas::EAnimationState::LoopReaction: return std::make_unique(); - case 11: + case pas::EAnimationState::GroundHit: return std::make_unique(); - case 12: + case pas::EAnimationState::Generate: return std::make_unique(); - case 13: + case pas::EAnimationState::Jump: return std::make_unique(); - case 14: + case pas::EAnimationState::Hurled: return std::make_unique(); - case 15: + case pas::EAnimationState::Slide: return std::make_unique(); - case 16: + case pas::EAnimationState::Taunt: return std::make_unique(); - case 17: + case pas::EAnimationState::Scripted: return std::make_unique(); default: return {}; } } -std::unique_ptr CBodyStateInfo::SetupPitchableBodyStates(int stateId, CActor& actor) const { +std::unique_ptr CBodyStateInfo::SetupPitchableBodyStates(pas::EAnimationState stateId, CActor& actor) const { switch (stateId) { - case 0: + case pas::EAnimationState::Fall: return std::make_unique(); - case 1: + case pas::EAnimationState::Getup: return std::make_unique(); - case 2: + case pas::EAnimationState::LieOnGround: return std::make_unique(actor); - case 3: + case pas::EAnimationState::Step: return std::make_unique(); - case 4: + case pas::EAnimationState::Death: return std::make_unique(); - case 5: + case pas::EAnimationState::Locomotion: return std::make_unique(actor, true); - case 6: + case pas::EAnimationState::KnockBack: return std::make_unique(); - case 7: + case pas::EAnimationState::MeleeAttack: return std::make_unique(); - case 18: + case pas::EAnimationState::ProjectileAttack: return std::make_unique(); - case 9: + case pas::EAnimationState::LoopAttack: return std::make_unique(); - case 8: + case pas::EAnimationState::Turn: return std::make_unique(); - case 10: + case pas::EAnimationState::LoopReaction: return std::make_unique(); - case 11: + case pas::EAnimationState::GroundHit: return std::make_unique(); - case 12: + case pas::EAnimationState::Generate: return std::make_unique(); - case 13: + case pas::EAnimationState::Jump: return std::make_unique(); - case 14: + case pas::EAnimationState::Hurled: return std::make_unique(); - case 15: + case pas::EAnimationState::Slide: return std::make_unique(); - case 16: + case pas::EAnimationState::Taunt: return std::make_unique(); - case 17: + case pas::EAnimationState::Scripted: return std::make_unique(); default: return {}; } } -std::unique_ptr CBodyStateInfo::SetupFlyerBodyStates(int stateId, CActor& actor) const { +std::unique_ptr CBodyStateInfo::SetupFlyerBodyStates(pas::EAnimationState stateId, CActor& actor) const { switch (stateId) { - case 0: + case pas::EAnimationState::Fall: return std::make_unique(); - case 1: + case pas::EAnimationState::Getup: return std::make_unique(); - case 2: + case pas::EAnimationState::LieOnGround: return std::make_unique(actor); - case 3: + case pas::EAnimationState::Step: return std::make_unique(); - case 4: + case pas::EAnimationState::Death: return std::make_unique(); - case 5: + case pas::EAnimationState::Locomotion: return std::make_unique(actor, false); - case 6: + case pas::EAnimationState::KnockBack: return std::make_unique(); - case 7: + case pas::EAnimationState::MeleeAttack: return std::make_unique(); - case 18: + case pas::EAnimationState::ProjectileAttack: return std::make_unique(); - case 9: + case pas::EAnimationState::LoopAttack: return std::make_unique(); - case 8: + case pas::EAnimationState::Turn: return std::make_unique(); - case 10: + case pas::EAnimationState::LoopReaction: return std::make_unique(); - case 11: + case pas::EAnimationState::GroundHit: return std::make_unique(); - case 12: + case pas::EAnimationState::Generate: return std::make_unique(); - case 13: + case pas::EAnimationState::Jump: return std::make_unique(); - case 14: + case pas::EAnimationState::Hurled: return std::make_unique(); - case 15: + case pas::EAnimationState::Slide: return std::make_unique(); - case 16: + case pas::EAnimationState::Taunt: return std::make_unique(); - case 17: + case pas::EAnimationState::Scripted: return std::make_unique(); default: return {}; } } -std::unique_ptr CBodyStateInfo::SetupRestrictedBodyStates(int stateId, CActor& actor) const { +std::unique_ptr CBodyStateInfo::SetupRestrictedBodyStates(pas::EAnimationState stateId, CActor& actor) const { switch (stateId) { - case 0: + case pas::EAnimationState::Fall: return std::make_unique(); - case 1: + case pas::EAnimationState::Getup: return std::make_unique(); - case 2: + case pas::EAnimationState::LieOnGround: return std::make_unique(actor); - case 3: + case pas::EAnimationState::Step: return std::make_unique(); - case 4: + case pas::EAnimationState::Death: return std::make_unique(); - case 5: + case pas::EAnimationState::Locomotion: return std::make_unique(actor); - case 6: + case pas::EAnimationState::KnockBack: return std::make_unique(); - case 7: + case pas::EAnimationState::MeleeAttack: return std::make_unique(); - case 18: + case pas::EAnimationState::ProjectileAttack: return std::make_unique(); - case 9: + case pas::EAnimationState::LoopAttack: return std::make_unique(); - case 8: + case pas::EAnimationState::Turn: return std::make_unique(); - case 10: + case pas::EAnimationState::LoopReaction: return std::make_unique(); - case 11: + case pas::EAnimationState::GroundHit: return std::make_unique(); - case 12: + case pas::EAnimationState::Generate: return std::make_unique(); - case 13: + case pas::EAnimationState::Jump: return std::make_unique(); - case 14: + case pas::EAnimationState::Hurled: return std::make_unique(); - case 15: + case pas::EAnimationState::Slide: return std::make_unique(); - case 16: + case pas::EAnimationState::Taunt: return std::make_unique(); - case 17: + case pas::EAnimationState::Scripted: return std::make_unique(); - case 19: + case pas::EAnimationState::Cover: return std::make_unique(); default: return {}; } } -std::unique_ptr CBodyStateInfo::SetupBiPedalBodyStates(int stateId, CActor& actor) const { +std::unique_ptr CBodyStateInfo::SetupBiPedalBodyStates(pas::EAnimationState stateId, CActor& actor) const { switch (stateId) { - case 0: + case pas::EAnimationState::Fall: return std::make_unique(); - case 1: + case pas::EAnimationState::Getup: return std::make_unique(); - case 2: + case pas::EAnimationState::LieOnGround: return std::make_unique(actor); - case 3: + case pas::EAnimationState::Step: return std::make_unique(); - case 4: + case pas::EAnimationState::Death: return std::make_unique(); - case 5: + case pas::EAnimationState::Locomotion: return std::make_unique(actor); - case 6: + case pas::EAnimationState::KnockBack: return std::make_unique(); - case 7: + case pas::EAnimationState::MeleeAttack: return std::make_unique(); - case 18: + case pas::EAnimationState::ProjectileAttack: return std::make_unique(); - case 9: + case pas::EAnimationState::LoopAttack: return std::make_unique(); - case 8: + case pas::EAnimationState::Turn: return std::make_unique(); - case 10: + case pas::EAnimationState::LoopReaction: return std::make_unique(); - case 11: + case pas::EAnimationState::GroundHit: return std::make_unique(); - case 12: + case pas::EAnimationState::Generate: return std::make_unique(); - case 13: + case pas::EAnimationState::Jump: return std::make_unique(); - case 14: + case pas::EAnimationState::Hurled: return std::make_unique(); - case 15: + case pas::EAnimationState::Slide: return std::make_unique(); - case 16: + case pas::EAnimationState::Taunt: return std::make_unique(); - case 17: + case pas::EAnimationState::Scripted: return std::make_unique(); - case 19: + case pas::EAnimationState::Cover: return std::make_unique(); - case 20: + case pas::EAnimationState::WallHang: return std::make_unique(); default: return {}; @@ -434,4 +434,4 @@ bool CBodyStateInfo::ApplyHeadTracking() const { return GetCurrentState()->ApplyHeadTracking(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBodyStateInfo.hpp b/Runtime/Character/CBodyStateInfo.hpp index bd440683c..6f4392cd1 100644 --- a/Runtime/Character/CBodyStateInfo.hpp +++ b/Runtime/Character/CBodyStateInfo.hpp @@ -10,7 +10,7 @@ #include "Runtime/Character/CBodyState.hpp" #include "Runtime/Character/CharacterCommon.hpp" -namespace urde { +namespace metaforce { class CActor; class CBodyStateInfo { @@ -22,13 +22,13 @@ class CBodyStateInfo { pas::EAnimationState x2c_additiveState = pas::EAnimationState::AdditiveIdle; float x30_maxPitch = 0.f; bool x34_24_changeLocoAtEndOfAnimOnly; - std::unique_ptr SetupRestrictedFlyerBodyStates(int stateId, CActor& actor) const; - std::unique_ptr SetupNewFlyerBodyStates(int stateId, CActor& actor) const; - std::unique_ptr SetupWallWalkerBodyStates(int stateId, CActor& actor) const; - std::unique_ptr SetupPitchableBodyStates(int stateId, CActor& actor) const; - std::unique_ptr SetupFlyerBodyStates(int stateId, CActor& actor) const; - std::unique_ptr SetupRestrictedBodyStates(int stateId, CActor& actor) const; - std::unique_ptr SetupBiPedalBodyStates(int stateId, CActor& actor) const; + std::unique_ptr SetupRestrictedFlyerBodyStates(pas::EAnimationState stateId, CActor& actor) const; + std::unique_ptr SetupNewFlyerBodyStates(pas::EAnimationState stateId, CActor& actor) const; + std::unique_ptr SetupWallWalkerBodyStates(pas::EAnimationState stateId, CActor& actor) const; + std::unique_ptr SetupPitchableBodyStates(pas::EAnimationState stateId, CActor& actor) const; + std::unique_ptr SetupFlyerBodyStates(pas::EAnimationState stateId, CActor& actor) const; + std::unique_ptr SetupRestrictedBodyStates(pas::EAnimationState stateId, CActor& actor) const; + std::unique_ptr SetupBiPedalBodyStates(pas::EAnimationState stateId, CActor& actor) const; public: CBodyStateInfo(CActor& actor, EBodyType type); @@ -48,4 +48,4 @@ public: bool ApplyHeadTracking() const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBoneTracking.cpp b/Runtime/Character/CBoneTracking.cpp index af7490ece..4f4b560ed 100644 --- a/Runtime/Character/CBoneTracking.cpp +++ b/Runtime/Character/CBoneTracking.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CBoneTracking::CBoneTracking(const CAnimData& animData, std::string_view bone, float maxTrackingAngle, float angSpeed, EBoneTrackingFlags flags) @@ -107,4 +107,4 @@ void CBoneTracking::UnsetTarget() { x34_target = kInvalidUniqueId; } void CBoneTracking::SetTargetPosition(const zeus::CVector3f& targetPos) { x24_targetPosition = targetPos; } void CBoneTracking::SetNoHorizontalAim(bool b) { x36_28_noHorizontalAim = b; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBoneTracking.hpp b/Runtime/Character/CBoneTracking.hpp index e349f7fbb..56693b2fc 100644 --- a/Runtime/Character/CBoneTracking.hpp +++ b/Runtime/Character/CBoneTracking.hpp @@ -10,7 +10,7 @@ #include #include -namespace urde { +namespace metaforce { class CAnimData; class CStateManager; class CBodyController; @@ -55,4 +55,4 @@ public: void SetNoHorizontalAim(bool b); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBoolPOINode.cpp b/Runtime/Character/CBoolPOINode.cpp index c4d2624f7..50e847dfe 100644 --- a/Runtime/Character/CBoolPOINode.cpp +++ b/Runtime/Character/CBoolPOINode.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CAnimSourceReader.hpp" -namespace urde { +namespace metaforce { CBoolPOINode::CBoolPOINode() : CPOINode("root", EPOIType::EmptyBool, CCharAnimTime(), -1, false, 1.f, -1, 0) {} @@ -14,4 +14,4 @@ CBoolPOINode CBoolPOINode::CopyNodeMinusStartTime(const CBoolPOINode& node, cons return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CBoolPOINode.hpp b/Runtime/Character/CBoolPOINode.hpp index c64468da7..d8bcc39cf 100644 --- a/Runtime/Character/CBoolPOINode.hpp +++ b/Runtime/Character/CBoolPOINode.hpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CPOINode.hpp" -namespace urde { +namespace metaforce { class IAnimSourceInfo; class CBoolPOINode : public CPOINode { @@ -15,4 +15,4 @@ public: static CBoolPOINode CopyNodeMinusStartTime(const CBoolPOINode& node, const CCharAnimTime& startTime); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharAnimTime.cpp b/Runtime/Character/CCharAnimTime.cpp index 089ea0fe9..93de6bdec 100644 --- a/Runtime/Character/CCharAnimTime.cpp +++ b/Runtime/Character/CCharAnimTime.cpp @@ -3,7 +3,7 @@ #include #include -namespace urde { +namespace metaforce { bool CCharAnimTime::EqualsZero() const { if (x4_type == EType::ZeroIncreasing || x4_type == EType::ZeroSteady || x4_type == EType::ZeroDecreasing) @@ -76,52 +76,38 @@ bool CCharAnimTime::operator>(const CCharAnimTime& other) const { return (!(*thi bool CCharAnimTime::operator<(const CCharAnimTime& other) const { if (x4_type == EType::NonZero) { - if (other.x4_type == EType::NonZero) + if (other.x4_type == EType::NonZero) { return x0_time < other.x0_time; - if (other.EqualsZero()) - return x0_time < 0.f; - else - return other.x0_time > 0.f; - } - - if (EqualsZero()) { - if (other.EqualsZero()) { - int type = -1; - if (x4_type != EType::ZeroDecreasing) { - if (x4_type != EType::ZeroSteady) - type = 1; - else - type = 0; - } - - int otherType = -1; - if (other.x4_type != EType::ZeroDecreasing) { - if (other.x4_type != EType::ZeroSteady) - otherType = 1; - else - otherType = 0; - } - - return type < otherType; } - if (other.x4_type == EType::NonZero) - return other.x0_time > 0.f; - return other.x0_time > 0.f; // ? + return other.EqualsZero() ? x0_time < 0.f : other.x0_time > 0; } - if (other.x4_type == EType::Infinity) - return x0_time < 0.f && other.x0_time > 0.f; - return x0_time < 0.f; + if (!EqualsZero()) { + if (other.x4_type == EType::Infinity) { + return x0_time >= 0 || other.x0_time <= 0.f; + } + + return x0_time < 0.f; + } + + if (!other.EqualsZero()) { + if (other.x4_type == EType::NonZero) { + return other.x0_time > 0.f; + } + + return other.x0_time > 0.f; + } + + int type = x4_type == EType::ZeroDecreasing ? -1 : x4_type == EType::ZeroSteady ? 0 : 1; + int otherType = other.x4_type == EType::ZeroDecreasing ? -1 : other.x4_type == EType::ZeroSteady ? 0 : 1; + + return type < otherType; } -CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other) { - return *this = *this * other; -} +CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other) { return *this = *this * other; } -CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) { - return *this = *this + other; -} +CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) { return *this = *this + other; } CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const { if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) { @@ -157,9 +143,7 @@ CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const { return {EType::ZeroIncreasing, 0.f}; } -CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other) { - return *this = *this - other; -} +CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other) { return *this = *this - other; } CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const { if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) { @@ -266,4 +250,4 @@ float CCharAnimTime::operator/(const CCharAnimTime& other) const { return x0_time / other.x0_time; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharAnimTime.hpp b/Runtime/Character/CCharAnimTime.hpp index e28e36e7d..e2aa45e3b 100644 --- a/Runtime/Character/CCharAnimTime.hpp +++ b/Runtime/Character/CCharAnimTime.hpp @@ -5,7 +5,7 @@ #undef min #undef max -namespace urde { +namespace metaforce { class CCharAnimTime { public: @@ -42,4 +42,4 @@ public: CCharAnimTime operator*(const float& other) const; float operator/(const CCharAnimTime& other) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharLayoutInfo.cpp b/Runtime/Character/CCharLayoutInfo.cpp index 74921214b..64b1941d5 100644 --- a/Runtime/Character/CCharLayoutInfo.cpp +++ b/Runtime/Character/CCharLayoutInfo.cpp @@ -2,7 +2,7 @@ #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { zeus::CVector3f CCharLayoutInfo::GetFromParentUnrotated(const CSegId& id) const { const CCharLayoutNode::Bone& bone = x0_node->GetBoneMap()[id]; @@ -65,4 +65,4 @@ CFactoryFnReturn FCharLayoutInfo(const SObjectTag&, CInputStream& in, const CVPa return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharLayoutInfo.hpp b/Runtime/Character/CCharLayoutInfo.hpp index 663a0f0d3..1678f3281 100644 --- a/Runtime/Character/CCharLayoutInfo.hpp +++ b/Runtime/Character/CCharLayoutInfo.hpp @@ -13,7 +13,7 @@ #include -namespace urde { +namespace metaforce { class CCharLayoutNode { public: @@ -48,4 +48,4 @@ public: CFactoryFnReturn FCharLayoutInfo(const SObjectTag&, CInputStream&, const CVParamTransfer&, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharacterFactory.cpp b/Runtime/Character/CCharacterFactory.cpp index c0d2e71d7..50aba8405 100644 --- a/Runtime/Character/CCharacterFactory.cpp +++ b/Runtime/Character/CCharacterFactory.cpp @@ -15,7 +15,7 @@ #include "Runtime/Character/CTransitionManager.hpp" #include "Runtime/Graphics/CSkinnedModel.hpp" -namespace urde { +namespace metaforce { CFactoryFnReturn CCharacterFactory::CDummyFactory::Build(const SObjectTag& tag, const CVParamTransfer& params, CObjectReference* selfRef) { @@ -55,21 +55,21 @@ void CCharacterFactory::CDummyFactory::EnumerateResources(const std::function& lambda) const {} -u32 CCharacterFactory::CDummyFactory::ResourceSize(const urde::SObjectTag& tag) { return 0; } +u32 CCharacterFactory::CDummyFactory::ResourceSize(const metaforce::SObjectTag& tag) { return 0; } -std::shared_ptr CCharacterFactory::CDummyFactory::LoadResourceAsync(const urde::SObjectTag& tag, +std::shared_ptr CCharacterFactory::CDummyFactory::LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) { return {}; } -std::shared_ptr CCharacterFactory::CDummyFactory::LoadResourcePartAsync(const urde::SObjectTag& tag, +std::shared_ptr CCharacterFactory::CDummyFactory::LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size, void* target) { return {}; } -std::unique_ptr CCharacterFactory::CDummyFactory::LoadResourceSync(const urde::SObjectTag& tag) { return {}; } +std::unique_ptr CCharacterFactory::CDummyFactory::LoadResourceSync(const metaforce::SObjectTag& tag) { return {}; } -std::unique_ptr CCharacterFactory::CDummyFactory::LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, +std::unique_ptr CCharacterFactory::CDummyFactory::LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) { return {}; } @@ -158,4 +158,4 @@ CCharacterFactory::CCharacterFactory(CSimplePool& store, const CAnimCharacterSet x30_animSourceDB.push_back(store.GetObj({SBIG('ANIM'), prim.GetAnimResId()})); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharacterFactory.hpp b/Runtime/Character/CCharacterFactory.hpp index b1dcf44ed..a4ac2ba47 100644 --- a/Runtime/Character/CCharacterFactory.hpp +++ b/Runtime/Character/CCharacterFactory.hpp @@ -11,7 +11,7 @@ #include "Runtime/IObjFactory.hpp" #include "Runtime/Character/CAnimationSet.hpp" -namespace urde { +namespace metaforce { class CAdditiveAnimationInfo; class CAllFormatsAnimSource; class CAnimCharacterSet; @@ -38,12 +38,12 @@ public: void EnumerateResources(const std::function& lambda) const override; void EnumerateNamedResources(const std::function& lambda) const override; - u32 ResourceSize(const urde::SObjectTag& tag) override; - std::shared_ptr LoadResourceAsync(const urde::SObjectTag& tag, void* target) override; - std::shared_ptr LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, + u32 ResourceSize(const metaforce::SObjectTag& tag) override; + std::shared_ptr LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) override; + std::shared_ptr LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size, void* target) override; - std::unique_ptr LoadResourceSync(const urde::SObjectTag& tag) override; - std::unique_ptr LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size) override; + std::unique_ptr LoadResourceSync(const metaforce::SObjectTag& tag) override; + std::unique_ptr LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) override; }; private: @@ -76,4 +76,4 @@ public: bool HasAdditiveInfo(s32 idx) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharacterInfo.cpp b/Runtime/Character/CCharacterInfo.cpp index f5610f613..7dec11562 100644 --- a/Runtime/Character/CCharacterInfo.cpp +++ b/Runtime/Character/CCharacterInfo.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CCharacterInfo.hpp" -namespace urde { +namespace metaforce { CCharacterInfo::CParticleResData::CParticleResData(CInputStream& in, u16 tableCount) { const u32 partCount = in.readUint32Big(); @@ -101,4 +101,4 @@ s32 CCharacterInfo::GetAnimationIndex(std::string_view name) const { return -1; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharacterInfo.hpp b/Runtime/Character/CCharacterInfo.hpp index 9f57b57d9..81dd92902 100644 --- a/Runtime/Character/CCharacterInfo.hpp +++ b/Runtime/Character/CCharacterInfo.hpp @@ -11,7 +11,7 @@ #include -namespace urde { +namespace metaforce { class CCharacterInfo { friend class CAnimData; @@ -68,4 +68,4 @@ public: s32 GetAnimationIndex(std::string_view) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharacterSet.cpp b/Runtime/Character/CCharacterSet.cpp index df95c94ca..a0bc9bbdc 100644 --- a/Runtime/Character/CCharacterSet.cpp +++ b/Runtime/Character/CCharacterSet.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CCharacterSet.hpp" -namespace urde { +namespace metaforce { CCharacterSet::CCharacterSet(CInputStream& in) : x0_version(in.readUint16Big()) { u32 charCount = in.readUint32Big(); @@ -10,4 +10,4 @@ CCharacterSet::CCharacterSet(CInputStream& in) : x0_version(in.readUint16Big()) } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CCharacterSet.hpp b/Runtime/Character/CCharacterSet.hpp index f3c8e46f7..2addb1bc7 100644 --- a/Runtime/Character/CCharacterSet.hpp +++ b/Runtime/Character/CCharacterSet.hpp @@ -6,7 +6,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/Character/CCharacterInfo.hpp" -namespace urde { +namespace metaforce { class CCharacterSet { u16 x0_version; @@ -17,4 +17,4 @@ public: const std::map& GetCharacterInfoMap() const { return x4_characters; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CEffectComponent.cpp b/Runtime/Character/CEffectComponent.cpp index 8839ff438..050a960d9 100644 --- a/Runtime/Character/CEffectComponent.cpp +++ b/Runtime/Character/CEffectComponent.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CEffectComponent.hpp" -namespace urde { +namespace metaforce { SObjectTag CEffectComponent::GetSObjectTagFromStream(CInputStream& in) { return SObjectTag(in); } @@ -13,4 +13,4 @@ CEffectComponent::CEffectComponent(CInputStream& in) { x30_flags = in.readUint32Big(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CEffectComponent.hpp b/Runtime/Character/CEffectComponent.hpp index f0a8a688c..856d33ab1 100644 --- a/Runtime/Character/CEffectComponent.hpp +++ b/Runtime/Character/CEffectComponent.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Character/CParticleData.hpp" -namespace urde { +namespace metaforce { class CEffectComponent { std::string x0_name; @@ -28,4 +28,4 @@ public: u32 GetFlags() const { return x30_flags; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CFBStreamedAnimReader.cpp b/Runtime/Character/CFBStreamedAnimReader.cpp index 09f10a4da..a2a80ff6c 100644 --- a/Runtime/Character/CFBStreamedAnimReader.cpp +++ b/Runtime/Character/CFBStreamedAnimReader.cpp @@ -8,7 +8,7 @@ #include "Runtime/Character/CSegIdList.hpp" #include "Runtime/Character/CSegStatementSet.hpp" -namespace urde { +namespace metaforce { void CFBStreamedAnimReaderTotals::Allocate(u32 chanCount) { const u32 chan2 = chanCount * 2; @@ -202,9 +202,9 @@ void CFBStreamedPairOfTotals::SetTime(CBitLevelLoader& loader, const CCharAnimTi prior = cur; priorTime = curTime; x78_t = 0.f; - } else + } else { x78_t = (time - priorTime) / (curTime - priorTime); - + } break; } ++cur; @@ -218,14 +218,22 @@ void CFBStreamedPairOfTotals::SetTime(CBitLevelLoader& loader, const CCharAnimTi loader.Reset(); } - if (next != -1) - while (u32(next) > Next().x1c_curKey) + if (prior != -1 && next == -1) { + next = prior; + x78_t = 1.f; + } + if (next != -1) { + while (u32(next) > Next().x1c_curKey) { DoIncrement(loader); + } + } - if (!Prior().IsCalculated()) + if (!Prior().IsCalculated()) { Prior().CalculateDown(); - if (!Next().IsCalculated()) + } + if (!Next().IsCalculated()) { Next().CalculateDown(); + } } void CFBStreamedPairOfTotals::DoIncrement(CBitLevelLoader& loader) { @@ -500,4 +508,4 @@ zeus::CQuaternion CFBStreamedAnimReader::VGetRotation(const CSegId& seg) const { template class TAnimSourceInfo; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CFBStreamedAnimReader.hpp b/Runtime/Character/CFBStreamedAnimReader.hpp index aa892f081..39a394876 100644 --- a/Runtime/Character/CFBStreamedAnimReader.hpp +++ b/Runtime/Character/CFBStreamedAnimReader.hpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CAnimSourceReader.hpp" #include "Runtime/Character/CFBStreamedCompression.hpp" -namespace urde { +namespace metaforce { class CBitLevelLoader; template @@ -122,4 +122,4 @@ public: zeus::CQuaternion VGetRotation(const CSegId& seg) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CFBStreamedCompression.cpp b/Runtime/Character/CFBStreamedCompression.cpp index cd8ce8b23..a2be29412 100644 --- a/Runtime/Character/CFBStreamedCompression.cpp +++ b/Runtime/Character/CFBStreamedCompression.cpp @@ -4,7 +4,7 @@ #include #include "Runtime/Character/CFBStreamedAnimReader.hpp" -namespace urde { +namespace metaforce { namespace { template T ReadValue(const u8* data) { @@ -271,4 +271,4 @@ float CFBStreamedCompression::CalculateAverageVelocity(const u8* chans) const { return accumMag / GetAnimationDuration().GetSeconds(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CFBStreamedCompression.hpp b/Runtime/Character/CFBStreamedCompression.hpp index 5c519280f..2d06cd1cc 100644 --- a/Runtime/Character/CFBStreamedCompression.hpp +++ b/Runtime/Character/CFBStreamedCompression.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class IObjectStore; class CFBStreamedCompression { @@ -82,4 +82,4 @@ public: const std::vector& GetSoundPOIStream() const { return x8_evntToken->GetSoundPOIStream(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CGroundMovement.cpp b/Runtime/Character/CGroundMovement.cpp index e337c2ef9..31a4145c6 100644 --- a/Runtime/Character/CGroundMovement.cpp +++ b/Runtime/Character/CGroundMovement.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { void CGroundMovement::CheckFalling(CPhysicsActor& actor, CStateManager& mgr, float) { bool oob = true; @@ -742,4 +742,4 @@ CMaterialList CGroundMovement::MoveObjectAnalytical(CStateManager& mgr, CPhysics return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CGroundMovement.hpp b/Runtime/Character/CGroundMovement.hpp index bfcdcd5fd..74d4d08bd 100644 --- a/Runtime/Character/CGroundMovement.hpp +++ b/Runtime/Character/CGroundMovement.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CAreaCollisionCache; class CCollisionInfoList; class CMaterialFilter; @@ -69,4 +69,4 @@ public: SMoveObjectResult& result); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CHalfTransition.cpp b/Runtime/Character/CHalfTransition.cpp index 3c240eb5f..36a00f1e3 100644 --- a/Runtime/Character/CHalfTransition.cpp +++ b/Runtime/Character/CHalfTransition.cpp @@ -2,11 +2,11 @@ #include "Runtime/Character/CMetaTransFactory.hpp" -namespace urde { +namespace metaforce { CHalfTransition::CHalfTransition(CInputStream& in) { x0_id = in.readUint32Big(); x4_trans = CMetaTransFactory::CreateMetaTrans(in); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CHalfTransition.hpp b/Runtime/Character/CHalfTransition.hpp index 76d5a58bb..6d6150fb3 100644 --- a/Runtime/Character/CHalfTransition.hpp +++ b/Runtime/Character/CHalfTransition.hpp @@ -6,7 +6,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/IMetaTrans.hpp" -namespace urde { +namespace metaforce { class CHalfTransition { u32 x0_id; @@ -18,4 +18,4 @@ public: const std::shared_ptr& GetMetaTrans() const { return x4_trans; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CHierarchyPoseBuilder.cpp b/Runtime/Character/CHierarchyPoseBuilder.cpp index 763316e08..a06e2b468 100644 --- a/Runtime/Character/CHierarchyPoseBuilder.cpp +++ b/Runtime/Character/CHierarchyPoseBuilder.cpp @@ -5,7 +5,7 @@ #include -namespace urde { +namespace metaforce { void CHierarchyPoseBuilder::BuildIntoHierarchy(const CCharLayoutInfo& layout, const CSegId& boneId, const CSegId& nullId) { @@ -160,4 +160,4 @@ CHierarchyPoseBuilder::CHierarchyPoseBuilder(const CLayoutDescription& layout) BuildIntoHierarchy(layoutInfo, id, 2); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CHierarchyPoseBuilder.hpp b/Runtime/Character/CHierarchyPoseBuilder.hpp index abe1f13e2..64ad23477 100644 --- a/Runtime/Character/CHierarchyPoseBuilder.hpp +++ b/Runtime/Character/CHierarchyPoseBuilder.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CCharLayoutInfo; class CLayoutDescription; class CPoseAsTransforms; @@ -47,4 +47,4 @@ public: TSegIdMap& GetTreeMap() { return x38_treeMap; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CIkChain.cpp b/Runtime/Character/CIkChain.cpp index dbd0c44e0..a0adb83b0 100644 --- a/Runtime/Character/CIkChain.cpp +++ b/Runtime/Character/CIkChain.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CAnimData.hpp" -namespace urde { +namespace metaforce { void CIkChain::Update(float dt) { if (x44_24_activated) @@ -83,4 +83,4 @@ void CIkChain::Solve(zeus::CQuaternion& q1, zeus::CQuaternion& q2, const zeus::C q1 = zeus::CQuaternion::fromAxisAngle(crossVecB * (1.f / crossVecB.magnitude()), angle) * q1; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CIkChain.hpp b/Runtime/Character/CIkChain.hpp index 6908f0e2c..d46b93961 100644 --- a/Runtime/Character/CIkChain.hpp +++ b/Runtime/Character/CIkChain.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CAnimData; class CSegId; class CIkChain { @@ -33,4 +33,4 @@ public: void PreRender(CAnimData&, const zeus::CTransform&, const zeus::CVector3f&); void Solve(zeus::CQuaternion&, zeus::CQuaternion&, const zeus::CVector3f&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CInt32POINode.cpp b/Runtime/Character/CInt32POINode.cpp index a314a9df0..9c4870242 100644 --- a/Runtime/Character/CInt32POINode.cpp +++ b/Runtime/Character/CInt32POINode.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CAnimSourceReader.hpp" -namespace urde { +namespace metaforce { CInt32POINode::CInt32POINode() : CInt32POINode(""sv, EPOIType::EmptyInt32, CCharAnimTime(), -1, false, 1.f, -1, 0, 0, "root"sv) {} @@ -19,4 +19,4 @@ CInt32POINode CInt32POINode::CopyNodeMinusStartTime(const CInt32POINode& node, c return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CInt32POINode.hpp b/Runtime/Character/CInt32POINode.hpp index 2ca709b42..b632a65d4 100644 --- a/Runtime/Character/CInt32POINode.hpp +++ b/Runtime/Character/CInt32POINode.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/Character/CPOINode.hpp" -namespace urde { +namespace metaforce { class IAnimSourceInfo; class CInt32POINode : public CPOINode { @@ -22,4 +22,4 @@ public: static CInt32POINode CopyNodeMinusStartTime(const CInt32POINode& node, const CCharAnimTime& startTime); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CLayoutDescription.hpp b/Runtime/Character/CLayoutDescription.hpp index e6f29864a..ac39e8241 100644 --- a/Runtime/Character/CLayoutDescription.hpp +++ b/Runtime/Character/CLayoutDescription.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CCharLayoutInfo; class CLayoutDescription { @@ -40,4 +40,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimBlend.cpp b/Runtime/Character/CMetaAnimBlend.cpp index 521f43a45..a6c68d5e8 100644 --- a/Runtime/Character/CMetaAnimBlend.cpp +++ b/Runtime/Character/CMetaAnimBlend.cpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CAnimTreeBlend.hpp" #include "Runtime/Character/CMetaAnimFactory.hpp" -namespace urde { +namespace metaforce { CMetaAnimBlend::CMetaAnimBlend(CInputStream& in) { x4_animA = CMetaAnimFactory::CreateMetaAnim(in); @@ -29,4 +29,4 @@ std::shared_ptr CMetaAnimBlend::VGetAnimationTree(const CAnimSysC CAnimTreeBlend::CreatePrimitiveName(a, b, xc_blend)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimBlend.hpp b/Runtime/Character/CMetaAnimBlend.hpp index 52bee1aa7..8b9997465 100644 --- a/Runtime/Character/CMetaAnimBlend.hpp +++ b/Runtime/Character/CMetaAnimBlend.hpp @@ -5,7 +5,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { class CMetaAnimBlend : public IMetaAnim { std::shared_ptr x4_animA; @@ -22,4 +22,4 @@ public: const CMetaAnimTreeBuildOrders& orders) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimFactory.cpp b/Runtime/Character/CMetaAnimFactory.cpp index 0efc33c20..daf92802e 100644 --- a/Runtime/Character/CMetaAnimFactory.cpp +++ b/Runtime/Character/CMetaAnimFactory.cpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CMetaAnimRandom.hpp" #include "Runtime/Character/CMetaAnimSequence.hpp" -namespace urde { +namespace metaforce { std::shared_ptr CMetaAnimFactory::CreateMetaAnim(CInputStream& in) { EMetaAnimType type = EMetaAnimType(in.readUint32Big()); @@ -29,4 +29,4 @@ std::shared_ptr CMetaAnimFactory::CreateMetaAnim(CInputStream& in) { return {}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimFactory.hpp b/Runtime/Character/CMetaAnimFactory.hpp index 291bc368c..8f2d423ee 100644 --- a/Runtime/Character/CMetaAnimFactory.hpp +++ b/Runtime/Character/CMetaAnimFactory.hpp @@ -5,11 +5,11 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { class CMetaAnimFactory { public: static std::shared_ptr CreateMetaAnim(CInputStream& in); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimPhaseBlend.cpp b/Runtime/Character/CMetaAnimPhaseBlend.cpp index bbec54c51..68212cb2a 100644 --- a/Runtime/Character/CMetaAnimPhaseBlend.cpp +++ b/Runtime/Character/CMetaAnimPhaseBlend.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CAnimTreeTimeScale.hpp" #include "Runtime/Character/CMetaAnimFactory.hpp" -namespace urde { +namespace metaforce { CMetaAnimPhaseBlend::CMetaAnimPhaseBlend(CInputStream& in) { x4_animA = CMetaAnimFactory::CreateMetaAnim(in); @@ -40,4 +40,4 @@ std::shared_ptr CMetaAnimPhaseBlend::VGetAnimationTree(const CAni CAnimTreeBlend::CreatePrimitiveName(tsa, tsb, xc_blend)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimPhaseBlend.hpp b/Runtime/Character/CMetaAnimPhaseBlend.hpp index c8131ff59..df612b3c2 100644 --- a/Runtime/Character/CMetaAnimPhaseBlend.hpp +++ b/Runtime/Character/CMetaAnimPhaseBlend.hpp @@ -5,7 +5,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { class CMetaAnimPhaseBlend : public IMetaAnim { std::shared_ptr x4_animA; @@ -22,4 +22,4 @@ public: const CMetaAnimTreeBuildOrders& orders) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimPlay.cpp b/Runtime/Character/CMetaAnimPlay.cpp index 148464cdb..eca98a950 100644 --- a/Runtime/Character/CMetaAnimPlay.cpp +++ b/Runtime/Character/CMetaAnimPlay.cpp @@ -5,7 +5,7 @@ #include "Runtime/Character/CAnimSysContext.hpp" #include "Runtime/Character/CAnimTreeAnimReaderContainer.hpp" -namespace urde { +namespace metaforce { CMetaAnimPlay::CMetaAnimPlay(CInputStream& in) : x4_primitive(in), x1c_startTime(in) {} @@ -22,4 +22,4 @@ std::shared_ptr CMetaAnimPlay::VGetAnimationTree(const CAnimSysCo x4_primitive.GetName(), CAllFormatsAnimSource::GetNewReader(prim, x1c_startTime), x4_primitive.GetAnimDbIdx()); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimPlay.hpp b/Runtime/Character/CMetaAnimPlay.hpp index 2939fc24a..0508ea1ee 100644 --- a/Runtime/Character/CMetaAnimPlay.hpp +++ b/Runtime/Character/CMetaAnimPlay.hpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CPrimitive.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { class CMetaAnimPlay : public IMetaAnim { CPrimitive x4_primitive; @@ -19,4 +19,4 @@ public: const CMetaAnimTreeBuildOrders& orders) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimRandom.cpp b/Runtime/Character/CMetaAnimRandom.cpp index 48c978667..02f1f1342 100644 --- a/Runtime/Character/CMetaAnimRandom.cpp +++ b/Runtime/Character/CMetaAnimRandom.cpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CAnimSysContext.hpp" #include "Runtime/Character/CMetaAnimFactory.hpp" -namespace urde { +namespace metaforce { CMetaAnimRandom::RandomData CMetaAnimRandom::CreateRandomData(CInputStream& in) { CMetaAnimRandom::RandomData ret; @@ -39,4 +39,4 @@ std::shared_ptr CMetaAnimRandom::VGetAnimationTree(const CAnimSys return useRd->first->GetAnimationTree(animSys, orders); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimRandom.hpp b/Runtime/Character/CMetaAnimRandom.hpp index 8ee2a6b29..272c01bb6 100644 --- a/Runtime/Character/CMetaAnimRandom.hpp +++ b/Runtime/Character/CMetaAnimRandom.hpp @@ -7,7 +7,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { class CMetaAnimRandom : public IMetaAnim { using RandomData = std::vector, u32>>; @@ -23,4 +23,4 @@ public: const CMetaAnimTreeBuildOrders& orders) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimSequence.cpp b/Runtime/Character/CMetaAnimSequence.cpp index a781ddba5..a96539731 100644 --- a/Runtime/Character/CMetaAnimSequence.cpp +++ b/Runtime/Character/CMetaAnimSequence.cpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CAnimTreeSequence.hpp" #include "Runtime/Character/CMetaAnimFactory.hpp" -namespace urde { +namespace metaforce { std::vector> CMetaAnimSequence::CreateSequence(CInputStream& in) { std::vector> ret; @@ -41,4 +41,4 @@ std::shared_ptr CMetaAnimSequence::VGetAnimationTree(const CAnimS return std::make_shared(x4_sequence, animSys, ""); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaAnimSequence.hpp b/Runtime/Character/CMetaAnimSequence.hpp index bc644b3e9..f937cce8c 100644 --- a/Runtime/Character/CMetaAnimSequence.hpp +++ b/Runtime/Character/CMetaAnimSequence.hpp @@ -6,7 +6,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { class CMetaAnimSequence : public IMetaAnim { std::vector> x4_sequence; @@ -21,4 +21,4 @@ public: const CMetaAnimTreeBuildOrders& orders) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransFactory.cpp b/Runtime/Character/CMetaTransFactory.cpp index 146645f65..1ae7d87fd 100644 --- a/Runtime/Character/CMetaTransFactory.cpp +++ b/Runtime/Character/CMetaTransFactory.cpp @@ -5,7 +5,7 @@ #include "Runtime/Character/CMetaTransSnap.hpp" #include "Runtime/Character/CMetaTransTrans.hpp" -namespace urde { +namespace metaforce { std::shared_ptr CMetaTransFactory::CreateMetaTrans(CInputStream& in) { EMetaTransType type = EMetaTransType(in.readUint32Big()); @@ -25,4 +25,4 @@ std::shared_ptr CMetaTransFactory::CreateMetaTrans(CInputStream& in) return {}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransFactory.hpp b/Runtime/Character/CMetaTransFactory.hpp index d56e54342..503c8331f 100644 --- a/Runtime/Character/CMetaTransFactory.hpp +++ b/Runtime/Character/CMetaTransFactory.hpp @@ -5,11 +5,11 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/IMetaTrans.hpp" -namespace urde { +namespace metaforce { class CMetaTransFactory { public: static std::shared_ptr CreateMetaTrans(CInputStream& in); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransMetaAnim.cpp b/Runtime/Character/CMetaTransMetaAnim.cpp index ce7365a71..c894a41ab 100644 --- a/Runtime/Character/CMetaTransMetaAnim.cpp +++ b/Runtime/Character/CMetaTransMetaAnim.cpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CAnimTreeLoopIn.hpp" #include "Runtime/Character/CMetaAnimFactory.hpp" -namespace urde { +namespace metaforce { CMetaTransMetaAnim::CMetaTransMetaAnim(CInputStream& in) : x4_metaAnim(CMetaAnimFactory::CreateMetaAnim(in)) {} @@ -16,4 +16,4 @@ std::shared_ptr CMetaTransMetaAnim::VGetTransitionTree(const std: CAnimTreeLoopIn::CreatePrimitiveName(a, b, animNode)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransMetaAnim.hpp b/Runtime/Character/CMetaTransMetaAnim.hpp index 21e193015..55400a798 100644 --- a/Runtime/Character/CMetaTransMetaAnim.hpp +++ b/Runtime/Character/CMetaTransMetaAnim.hpp @@ -6,7 +6,7 @@ #include "Runtime/Character/IMetaAnim.hpp" #include "Runtime/Character/IMetaTrans.hpp" -namespace urde { +namespace metaforce { class CMetaTransMetaAnim : public IMetaTrans { std::shared_ptr x4_metaAnim; @@ -20,4 +20,4 @@ public: const CAnimSysContext& animSys) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransPhaseTrans.cpp b/Runtime/Character/CMetaTransPhaseTrans.cpp index 6b1804993..f158da0aa 100644 --- a/Runtime/Character/CMetaTransPhaseTrans.cpp +++ b/Runtime/Character/CMetaTransPhaseTrans.cpp @@ -5,7 +5,7 @@ #include "Runtime/Character/CAnimTreeTransition.hpp" #include "Runtime/Character/CTimeScaleFunctions.hpp" -namespace urde { +namespace metaforce { CMetaTransPhaseTrans::CMetaTransPhaseTrans(CInputStream& in) { x4_transDur = CCharAnimTime(in); @@ -37,4 +37,4 @@ std::shared_ptr CMetaTransPhaseTrans::VGetTransitionTree(const st CAnimTreeTransition::CreatePrimitiveName(tsA, tsB, x4_transDur.GetSeconds())); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransPhaseTrans.hpp b/Runtime/Character/CMetaTransPhaseTrans.hpp index 49005655c..08fd2ba98 100644 --- a/Runtime/Character/CMetaTransPhaseTrans.hpp +++ b/Runtime/Character/CMetaTransPhaseTrans.hpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CCharAnimTime.hpp" #include "Runtime/Character/IMetaTrans.hpp" -namespace urde { +namespace metaforce { class CMetaTransPhaseTrans : public IMetaTrans { CCharAnimTime x4_transDur; @@ -21,4 +21,4 @@ public: const CAnimSysContext& animSys) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransSnap.cpp b/Runtime/Character/CMetaTransSnap.cpp index 92d1711ca..302a85c7a 100644 --- a/Runtime/Character/CMetaTransSnap.cpp +++ b/Runtime/Character/CMetaTransSnap.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CMetaTransSnap.hpp" -namespace urde { +namespace metaforce { std::shared_ptr CMetaTransSnap::VGetTransitionTree(const std::weak_ptr& a, const std::weak_ptr& b, @@ -8,4 +8,4 @@ std::shared_ptr CMetaTransSnap::VGetTransitionTree(const std::wea return b.lock(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransSnap.hpp b/Runtime/Character/CMetaTransSnap.hpp index 78b40af48..091b73f68 100644 --- a/Runtime/Character/CMetaTransSnap.hpp +++ b/Runtime/Character/CMetaTransSnap.hpp @@ -3,7 +3,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/IMetaTrans.hpp" -namespace urde { +namespace metaforce { class CMetaTransSnap : public IMetaTrans { public: @@ -14,4 +14,4 @@ public: const CAnimSysContext& animSys) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransTrans.cpp b/Runtime/Character/CMetaTransTrans.cpp index 102d28310..a64b86b30 100644 --- a/Runtime/Character/CMetaTransTrans.cpp +++ b/Runtime/Character/CMetaTransTrans.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CAnimTreeTransition.hpp" -namespace urde { +namespace metaforce { CMetaTransTrans::CMetaTransTrans(CInputStream& in) { x4_transDur = CCharAnimTime(in); @@ -18,4 +18,4 @@ std::shared_ptr CMetaTransTrans::VGetTransitionTree(const std::we xc_, a, b, x4_transDur, xd_runA, x10_flags, CAnimTreeTransition::CreatePrimitiveName(a, b, x4_transDur.GetSeconds())); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CMetaTransTrans.hpp b/Runtime/Character/CMetaTransTrans.hpp index f1f259975..5a0b0f2a7 100644 --- a/Runtime/Character/CMetaTransTrans.hpp +++ b/Runtime/Character/CMetaTransTrans.hpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CCharAnimTime.hpp" #include "Runtime/Character/IMetaTrans.hpp" -namespace urde { +namespace metaforce { class CMetaTransTrans : public IMetaTrans { CCharAnimTime x4_transDur; @@ -21,4 +21,4 @@ public: const CAnimSysContext& animSys) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CModelData.cpp b/Runtime/Character/CModelData.cpp index 469299fa9..a44709135 100644 --- a/Runtime/Character/CModelData.cpp +++ b/Runtime/Character/CModelData.cpp @@ -17,8 +17,8 @@ #include -namespace urde { -static logvisor::Module Log("urde::CModelData"); +namespace metaforce { +static logvisor::Module Log("metaforce::CModelData"); CModelData::~CModelData() = default; @@ -437,4 +437,4 @@ void CModelData::DisintegrateDraw(EWhichModel which, const zeus::CTransform& xf, } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CModelData.hpp b/Runtime/Character/CModelData.hpp index feb5baa9b..33f71d906 100644 --- a/Runtime/Character/CModelData.hpp +++ b/Runtime/Character/CModelData.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CActorLights; class CAnimData; class CCharAnimTime; @@ -172,4 +172,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASAnimInfo.cpp b/Runtime/Character/CPASAnimInfo.cpp index 6a11905b1..930d1edc0 100644 --- a/Runtime/Character/CPASAnimInfo.cpp +++ b/Runtime/Character/CPASAnimInfo.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CPASAnimInfo.hpp" -namespace urde { +namespace metaforce { CPASAnimInfo::CPASAnimInfo(u32 id, rstl::reserved_vector&& parms) : x0_id(id), x4_parms(std::move(parms)) {} @@ -35,4 +35,4 @@ CPASAnimParm CPASAnimInfo::GetAnimParmData(size_t idx, CPASAnimParm::EParmType t } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASAnimInfo.hpp b/Runtime/Character/CPASAnimInfo.hpp index a679f71f7..bcf3f17fd 100644 --- a/Runtime/Character/CPASAnimInfo.hpp +++ b/Runtime/Character/CPASAnimInfo.hpp @@ -4,7 +4,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Character/CPASAnimParm.hpp" -namespace urde { +namespace metaforce { class CPASAnimInfo { u32 x0_id; @@ -18,4 +18,4 @@ public: CPASAnimParm GetAnimParmData(size_t idx, CPASAnimParm::EParmType type) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASAnimParm.hpp b/Runtime/Character/CPASAnimParm.hpp index bf706374f..6637ae076 100644 --- a/Runtime/Character/CPASAnimParm.hpp +++ b/Runtime/Character/CPASAnimParm.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CPASAnimParm { public: @@ -65,4 +65,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASAnimParmData.cpp b/Runtime/Character/CPASAnimParmData.cpp index 0b0ade4ef..59df1c3ec 100644 --- a/Runtime/Character/CPASAnimParmData.cpp +++ b/Runtime/Character/CPASAnimParmData.cpp @@ -1,8 +1,8 @@ #include "Runtime/Character/CPASAnimParmData.hpp" -namespace urde { +namespace metaforce { -CPASAnimParmData::CPASAnimParmData(s32 stateId, const CPASAnimParm& parm1, const CPASAnimParm& parm2, +CPASAnimParmData::CPASAnimParmData(pas::EAnimationState stateId, const CPASAnimParm& parm1, const CPASAnimParm& parm2, const CPASAnimParm& parm3, const CPASAnimParm& parm4, const CPASAnimParm& parm5, const CPASAnimParm& parm6, const CPASAnimParm& parm7, const CPASAnimParm& parm8) : x0_stateId(stateId) { @@ -16,4 +16,4 @@ CPASAnimParmData::CPASAnimParmData(s32 stateId, const CPASAnimParm& parm1, const x4_parms.push_back(parm8); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASAnimParmData.hpp b/Runtime/Character/CPASAnimParmData.hpp index 41ad3521f..29473e338 100644 --- a/Runtime/Character/CPASAnimParmData.hpp +++ b/Runtime/Character/CPASAnimParmData.hpp @@ -2,17 +2,18 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" +#include "Runtime/Character/CharacterCommon.hpp" #include "Runtime/Character/CPASAnimParm.hpp" -namespace urde { +namespace metaforce { class CPASAnimParmData { - s32 x0_stateId; + pas::EAnimationState x0_stateId; rstl::reserved_vector x4_parms; public: CPASAnimParmData() = default; - explicit CPASAnimParmData(s32 stateId, const CPASAnimParm& parm1 = CPASAnimParm::NoParameter(), + explicit CPASAnimParmData(pas::EAnimationState stateId, const CPASAnimParm& parm1 = CPASAnimParm::NoParameter(), const CPASAnimParm& parm2 = CPASAnimParm::NoParameter(), const CPASAnimParm& parm3 = CPASAnimParm::NoParameter(), const CPASAnimParm& parm4 = CPASAnimParm::NoParameter(), @@ -21,9 +22,9 @@ public: const CPASAnimParm& parm7 = CPASAnimParm::NoParameter(), const CPASAnimParm& parm8 = CPASAnimParm::NoParameter()); - s32 GetStateId() const { return x0_stateId; } + pas::EAnimationState GetStateId() const { return x0_stateId; } const rstl::reserved_vector& GetAnimParmData() const { return x4_parms; } - static auto NoParameters(s32 stateId) { return CPASAnimParmData(stateId); } + static auto NoParameters(pas::EAnimationState stateId) { return CPASAnimParmData(stateId); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASAnimState.cpp b/Runtime/Character/CPASAnimState.cpp index 3bde8b003..1c02ffd78 100644 --- a/Runtime/Character/CPASAnimState.cpp +++ b/Runtime/Character/CPASAnimState.cpp @@ -2,6 +2,7 @@ #include "Runtime/CRandom16.hpp" #include "Runtime/rstl.hpp" +#include "Runtime/Character/CharacterCommon.hpp" #include "Runtime/Character/CPASAnimParmData.hpp" #include @@ -10,10 +11,10 @@ #include -namespace urde { +namespace metaforce { CPASAnimState::CPASAnimState(CInputStream& in) { - x0_id = in.readUint32Big(); + x0_id = static_cast(in.readUint32Big()); u32 parmCount = in.readUint32Big(); u32 animCount = in.readUint32Big(); @@ -58,7 +59,7 @@ CPASAnimState::CPASAnimState(CInputStream& in) { } } -CPASAnimState::CPASAnimState(int stateId) : x0_id(stateId) {} +CPASAnimState::CPASAnimState(pas::EAnimationState stateId) : x0_id(stateId) {} CPASAnimParm CPASAnimState::GetAnimParmData(s32 animId, size_t parmIdx) const { const auto search = rstl::binary_find(x14_anims.cbegin(), x14_anims.cend(), animId, @@ -252,4 +253,4 @@ float CPASAnimState::ComputeAngularPercentErrorWeight(size_t idx, const CPASAnim return (val >= FLT_EPSILON ? 0.f : 1.f); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASAnimState.hpp b/Runtime/Character/CPASAnimState.hpp index 493152edd..98c258acc 100644 --- a/Runtime/Character/CPASAnimState.hpp +++ b/Runtime/Character/CPASAnimState.hpp @@ -4,14 +4,15 @@ #include #include "Runtime/IOStreams.hpp" +#include "Runtime/Character/CharacterCommon.hpp" #include "Runtime/Character/CPASAnimInfo.hpp" #include "Runtime/Character/CPASParmInfo.hpp" -namespace urde { +namespace metaforce { class CRandom16; class CPASAnimParmData; class CPASAnimState { - s32 x0_id; + pas::EAnimationState x0_id; std::vector x4_parms; std::vector x14_anims; mutable std::vector x24_selectionCache; @@ -24,8 +25,8 @@ class CPASAnimState { public: explicit CPASAnimState(CInputStream& in); - explicit CPASAnimState(int stateId); - s32 GetStateId() const { return x0_id; } + explicit CPASAnimState(pas::EAnimationState stateId); + pas::EAnimationState GetStateId() const { return x0_id; } size_t GetNumAnims() const { return x14_anims.size(); } bool HasAnims() const { return !x14_anims.empty(); } CPASAnimParm GetAnimParmData(s32 animId, size_t parmIdx) const; @@ -33,4 +34,4 @@ public: s32 ignoreAnim) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASDatabase.cpp b/Runtime/Character/CPASDatabase.cpp index b15f70952..d6d922684 100644 --- a/Runtime/Character/CPASDatabase.cpp +++ b/Runtime/Character/CPASDatabase.cpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { void CPASDatabase::AddAnimState(CPASAnimState&& state) { auto it = std::lower_bound(x0_states.begin(), x0_states.end(), state, @@ -47,4 +47,4 @@ std::pair CPASDatabase::FindBestAnimation(const CPASAnimParmData& da return (*it).FindBestAnimation(data.GetAnimParmData(), rand, ignoreAnim); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASDatabase.hpp b/Runtime/Character/CPASDatabase.hpp index e06afeec4..ddd7d786d 100644 --- a/Runtime/Character/CPASDatabase.hpp +++ b/Runtime/Character/CPASDatabase.hpp @@ -7,7 +7,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/CPASAnimState.hpp" -namespace urde { +namespace metaforce { class CRandom16; class CPASAnimParmData; @@ -24,7 +24,7 @@ public: std::pair FindBestAnimation(const CPASAnimParmData& data, CRandom16& rand, s32 ignoreAnim) const; s32 GetDefaultState() const { return x10_defaultState; } size_t GetNumAnimStates() const { return x0_states.size(); } - const CPASAnimState* GetAnimState(s32 id) const { + const CPASAnimState* GetAnimState(pas::EAnimationState id) const { for (const CPASAnimState& state : x0_states) if (id == state.GetStateId()) return &state; @@ -39,11 +39,11 @@ public: return &x0_states[index]; } - bool HasState(s32 id) const { + bool HasState(pas::EAnimationState id) const { const auto& st = std::find_if(x0_states.begin(), x0_states.end(), [&id](const CPASAnimState& other) -> bool { return other.GetStateId() == id; }); return st != x0_states.end(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASParmInfo.cpp b/Runtime/Character/CPASParmInfo.cpp index 942bb0fe4..80920c0b4 100644 --- a/Runtime/Character/CPASParmInfo.cpp +++ b/Runtime/Character/CPASParmInfo.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CPASParmInfo.hpp" -namespace urde { +namespace metaforce { CPASParmInfo::CPASParmInfo(CInputStream& in) { xc_min.m_int = 0; @@ -35,4 +35,4 @@ CPASParmInfo::CPASParmInfo(CInputStream& in) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPASParmInfo.hpp b/Runtime/Character/CPASParmInfo.hpp index 63b6db404..6b10b5dd0 100644 --- a/Runtime/Character/CPASParmInfo.hpp +++ b/Runtime/Character/CPASParmInfo.hpp @@ -3,7 +3,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/CPASAnimParm.hpp" -namespace urde { +namespace metaforce { class CPASParmInfo { public: @@ -25,4 +25,4 @@ public: CPASAnimParm::UParmValue GetWeightMaxValue() const { return x10_max; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPOINode.cpp b/Runtime/Character/CPOINode.cpp index 3d1196b51..9e3ece784 100644 --- a/Runtime/Character/CPOINode.cpp +++ b/Runtime/Character/CPOINode.cpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CParticlePOINode.hpp" #include "Runtime/Character/CSoundPOINode.hpp" -namespace urde { +namespace metaforce { CPOINode::CPOINode(std::string_view name, EPOIType type, const CCharAnimTime& time, s32 index, bool unique, float weight, s32 e, s32 f) @@ -120,4 +120,4 @@ template size_t _getPOIList(const CCharAnimTime& time, CSoundPOIN size_t iterator, u32 unk1, const std::vector& stream, const CCharAnimTime& curTime); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPOINode.hpp b/Runtime/Character/CPOINode.hpp index 8c58fd4f7..c7e2bdbff 100644 --- a/Runtime/Character/CPOINode.hpp +++ b/Runtime/Character/CPOINode.hpp @@ -6,7 +6,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/CCharAnimTime.hpp" -namespace urde { +namespace metaforce { class IAnimSourceInfo; enum class EPOIType : u16 { @@ -61,4 +61,4 @@ template size_t _getPOIList(const CCharAnimTime& time, T* listOut, size_t capacity, size_t iterator, u32 unk1, const std::vector& stream, const CCharAnimTime& curTime); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CParticleData.cpp b/Runtime/Character/CParticleData.cpp index 48c0c60cd..c54b8bc26 100644 --- a/Runtime/Character/CParticleData.cpp +++ b/Runtime/Character/CParticleData.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CParticleData.hpp" -namespace urde { +namespace metaforce { CParticleData::CParticleData(CInputStream& in) : x0_duration(in.readUint32Big()) @@ -9,4 +9,4 @@ CParticleData::CParticleData(CInputStream& in) , x1c_scale(in.readFloatBig()) , x20_parentMode(EParentedMode(in.readUint32Big())) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CParticleData.hpp b/Runtime/Character/CParticleData.hpp index 7ba389327..80f14dbd7 100644 --- a/Runtime/Character/CParticleData.hpp +++ b/Runtime/Character/CParticleData.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { class CParticleData { public: @@ -47,4 +47,4 @@ public: float GetScale() const { return x18_scale; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CParticleDatabase.cpp b/Runtime/Character/CParticleDatabase.cpp index 0cc5fc213..dc6f65e91 100644 --- a/Runtime/Character/CParticleDatabase.cpp +++ b/Runtime/Character/CParticleDatabase.cpp @@ -8,7 +8,7 @@ #include "Runtime/Particle/CParticleElectric.hpp" #include "Runtime/Particle/CParticleSwoosh.hpp" -namespace urde { +namespace metaforce { CParticleDatabase::CParticleDatabase() = default; @@ -448,4 +448,4 @@ void CParticleDatabase::InsertParticleGen(bool oneShot, int flags, std::string_v } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CParticleDatabase.hpp b/Runtime/Character/CParticleDatabase.hpp index 7b832b07f..931e2fa23 100644 --- a/Runtime/Character/CParticleDatabase.hpp +++ b/Runtime/Character/CParticleDatabase.hpp @@ -14,7 +14,7 @@ #include #include -namespace urde { +namespace metaforce { class CCharLayoutInfo; class CPoseAsTransforms; @@ -71,4 +71,4 @@ public: bool AreAnySystemsDrawnWithModel() const { return xb4_25_anySystemsDrawnWithModel; } void SetUpdatesEnabled(bool active) { xb4_24_updatesEnabled = active; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CParticleGenInfo.cpp b/Runtime/Character/CParticleGenInfo.cpp index 1ffb93378..a76fcfba2 100644 --- a/Runtime/Character/CParticleGenInfo.cpp +++ b/Runtime/Character/CParticleGenInfo.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CParticleGenInfo::CParticleGenInfo(const SObjectTag& part, int frameCount, std::string_view boneName, const zeus::CVector3f& scale, CParticleData::EParentedMode parentMode, int flags, @@ -146,4 +146,4 @@ void CParticleGenInfoGeneric::DeleteLight(CStateManager& mgr) { } void CParticleGenInfoGeneric::SetModulationColor(const zeus::CColor& color) { x84_system->SetModulationColor(color); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CParticleGenInfo.hpp b/Runtime/Character/CParticleGenInfo.hpp index b1f8e1992..3965d0c4b 100644 --- a/Runtime/Character/CParticleGenInfo.hpp +++ b/Runtime/Character/CParticleGenInfo.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CParticleGen; class CStateManager; struct SObjectTag; @@ -108,4 +108,4 @@ public: void SetModulationColor(const zeus::CColor& color) override; const std::shared_ptr& GetParticleSystem() const { return x84_system; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CParticlePOINode.cpp b/Runtime/Character/CParticlePOINode.cpp index 514b57700..b72be371a 100644 --- a/Runtime/Character/CParticlePOINode.cpp +++ b/Runtime/Character/CParticlePOINode.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CAnimSourceReader.hpp" -namespace urde { +namespace metaforce { CParticlePOINode::CParticlePOINode() : CPOINode("root", EPOIType::Particle, CCharAnimTime(), -1, false, 1.f, -1, 0) {} @@ -15,4 +15,4 @@ CParticlePOINode CParticlePOINode::CopyNodeMinusStartTime(const CParticlePOINode return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CParticlePOINode.hpp b/Runtime/Character/CParticlePOINode.hpp index 33180a624..9225d896c 100644 --- a/Runtime/Character/CParticlePOINode.hpp +++ b/Runtime/Character/CParticlePOINode.hpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CParticleData.hpp" #include "Runtime/Character/CPOINode.hpp" -namespace urde { +namespace metaforce { class IAnimSourceInfo; class CParticlePOINode : public CPOINode { @@ -17,4 +17,4 @@ public: static CParticlePOINode CopyNodeMinusStartTime(const CParticlePOINode& node, const CCharAnimTime& startTime); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPoseAsTransforms.cpp b/Runtime/Character/CPoseAsTransforms.cpp index 8c7b91d57..1631476e2 100644 --- a/Runtime/Character/CPoseAsTransforms.cpp +++ b/Runtime/Character/CPoseAsTransforms.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CCharLayoutInfo.hpp" -namespace urde { +namespace metaforce { CPoseAsTransforms::CPoseAsTransforms(u8 boneCount) : x1_count(boneCount), xd0_transformArr(new Transform[boneCount]) {} @@ -58,4 +58,4 @@ void CPoseAsTransforms::Insert(const CSegId& id, const zeus::CMatrix3f& rotation ++x0_nextId; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPoseAsTransforms.hpp b/Runtime/Character/CPoseAsTransforms.hpp index e896eb438..1c5cf5bb6 100644 --- a/Runtime/Character/CPoseAsTransforms.hpp +++ b/Runtime/Character/CPoseAsTransforms.hpp @@ -12,7 +12,7 @@ #include #include -namespace urde { +namespace metaforce { class CPoseAsTransforms { friend class CAnimData; public: @@ -42,4 +42,4 @@ public: const zeus::CVector3f& restOffset); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPrimitive.cpp b/Runtime/Character/CPrimitive.cpp index af081a2b9..3857528c0 100644 --- a/Runtime/Character/CPrimitive.cpp +++ b/Runtime/Character/CPrimitive.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CPrimitive.hpp" -namespace urde { +namespace metaforce { CPrimitive::CPrimitive(CInputStream& in) { x0_animId = in.readUint32Big(); @@ -8,4 +8,4 @@ CPrimitive::CPrimitive(CInputStream& in) { x8_animName = in.readString(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CPrimitive.hpp b/Runtime/Character/CPrimitive.hpp index db9a44c8f..0fcf01c49 100644 --- a/Runtime/Character/CPrimitive.hpp +++ b/Runtime/Character/CPrimitive.hpp @@ -5,7 +5,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CPrimitive { CAssetId x0_animId; @@ -20,4 +20,4 @@ public: bool operator<(const CPrimitive& other) const { return x8_animName < other.x8_animName; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CRagDoll.cpp b/Runtime/Character/CRagDoll.cpp index ef4c79499..7f7ba3a25 100644 --- a/Runtime/Character/CRagDoll.cpp +++ b/Runtime/Character/CRagDoll.cpp @@ -7,7 +7,7 @@ #include "Runtime/Collision/CMaterialFilter.hpp" #include "Runtime/Collision/CMetroidAreaCollider.hpp" -namespace urde { +namespace metaforce { void CRagDoll::CRagDollLengthConstraint::Update() { zeus::CVector3f delta = x4_p2->x4_curPos - x0_p1->x4_curPos; @@ -321,4 +321,4 @@ void CRagDoll::Prime(CStateManager& mgr, const zeus::CTransform& xf, CModelData& x68_26_primed = true; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CRagDoll.hpp b/Runtime/Character/CRagDoll.hpp index 3f1ca7c62..c29a1aac1 100644 --- a/Runtime/Character/CRagDoll.hpp +++ b/Runtime/Character/CRagDoll.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CCharLayoutInfo; class CHierarchyPoseBuilder; class CModelData; @@ -132,4 +132,4 @@ public: u32 GetImpactCount() const { return x4c_impactCount; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSegId.hpp b/Runtime/Character/CSegId.hpp index 7a930b3ff..3bcaa78d2 100644 --- a/Runtime/Character/CSegId.hpp +++ b/Runtime/Character/CSegId.hpp @@ -3,7 +3,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CSegId { u8 x0_segId = 0xFF; @@ -26,4 +26,4 @@ public: constexpr bool IsInvalid() const noexcept { return x0_segId == 0xFF; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSegIdList.cpp b/Runtime/Character/CSegIdList.cpp index b5f0a5d8b..aecb44d48 100644 --- a/Runtime/Character/CSegIdList.cpp +++ b/Runtime/Character/CSegIdList.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CSegIdList.hpp" -namespace urde { +namespace metaforce { CSegIdList::CSegIdList(CInputStream& in) { u32 count = in.readUint32Big(); @@ -9,4 +9,4 @@ CSegIdList::CSegIdList(CInputStream& in) { x0_list.emplace_back(in); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSegIdList.hpp b/Runtime/Character/CSegIdList.hpp index 37eceb21c..8ff76daa3 100644 --- a/Runtime/Character/CSegIdList.hpp +++ b/Runtime/Character/CSegIdList.hpp @@ -5,7 +5,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/CSegId.hpp" -namespace urde { +namespace metaforce { class CSegIdList { std::vector x0_list; @@ -15,4 +15,4 @@ public: const std::vector& GetList() const { return x0_list; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSegStatementSet.cpp b/Runtime/Character/CSegStatementSet.cpp index a0bd0ca6f..962e82301 100644 --- a/Runtime/Character/CSegStatementSet.cpp +++ b/Runtime/Character/CSegStatementSet.cpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CCharLayoutInfo.hpp" #include "Runtime/Character/CSegIdList.hpp" -namespace urde { +namespace metaforce { void CSegStatementSet::Add(const CSegIdList& list, const CCharLayoutInfo& layout, const CSegStatementSet& other, float weight) { @@ -17,4 +17,4 @@ void CSegStatementSet::Add(const CSegIdList& list, const CCharLayoutInfo& layout } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSegStatementSet.hpp b/Runtime/Character/CSegStatementSet.hpp index 48b40c7d4..76513547c 100644 --- a/Runtime/Character/CSegStatementSet.hpp +++ b/Runtime/Character/CSegStatementSet.hpp @@ -5,7 +5,7 @@ #include "Runtime/Character/CAnimPerSegmentData.hpp" #include "Runtime/Character/CSegId.hpp" -namespace urde { +namespace metaforce { class CCharLayoutInfo; class CSegIdList; @@ -22,4 +22,4 @@ public: const CAnimPerSegmentData& operator[](const CSegId& idx) const { return x4_segData[idx]; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSequenceHelper.cpp b/Runtime/Character/CSequenceHelper.cpp index 85adad75e..a0bcda365 100644 --- a/Runtime/Character/CSequenceHelper.cpp +++ b/Runtime/Character/CSequenceHelper.cpp @@ -10,7 +10,7 @@ #include "Runtime/Character/CTreeUtils.hpp" #include "Runtime/Character/IMetaAnim.hpp" -namespace urde { +namespace metaforce { CSequenceFundamentals::CSequenceFundamentals(const CSteadyStateAnimInfo& ssInfo, std::vector boolNodes, std::vector int32Nodes, @@ -110,4 +110,4 @@ CSequenceFundamentals CSequenceHelper::ComputeSequenceFundamentals() { return {{false, duration, offset}, boolNodes, int32Nodes, particleNodes, soundNodes}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSequenceHelper.hpp b/Runtime/Character/CSequenceHelper.hpp index da275ec72..819d66b7c 100644 --- a/Runtime/Character/CSequenceHelper.hpp +++ b/Runtime/Character/CSequenceHelper.hpp @@ -11,7 +11,7 @@ #include "Runtime/Character/CSoundPOINode.hpp" #include "Runtime/Character/CTransitionDatabaseGame.hpp" -namespace urde { +namespace metaforce { class IMetaAnim; class CSequenceFundamentals { @@ -45,4 +45,4 @@ public: CSequenceFundamentals ComputeSequenceFundamentals(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSkinBank.cpp b/Runtime/Character/CSkinBank.cpp index 517679b67..487a58875 100644 --- a/Runtime/Character/CSkinBank.cpp +++ b/Runtime/Character/CSkinBank.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CPoseAsTransforms.hpp" -namespace urde { +namespace metaforce { CSkinBank::CSkinBank(CInputStream& in) { u32 boneCount = in.readUint32Big(); @@ -18,4 +18,4 @@ void CSkinBank::GetBankTransforms(std::vector& out, con } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSkinBank.hpp b/Runtime/Character/CSkinBank.hpp index 604d19b17..843a12c1e 100644 --- a/Runtime/Character/CSkinBank.hpp +++ b/Runtime/Character/CSkinBank.hpp @@ -5,7 +5,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/CSegId.hpp" -namespace urde { +namespace metaforce { class CPoseAsTransforms; class CSkinBank { @@ -16,4 +16,4 @@ public: void GetBankTransforms(std::vector& out, const CPoseAsTransforms& pose) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSkinRules.cpp b/Runtime/Character/CSkinRules.cpp index 0aac67bdc..8ce0ca4c9 100644 --- a/Runtime/Character/CSkinRules.cpp +++ b/Runtime/Character/CSkinRules.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CPoseAsTransforms.hpp" #include "Runtime/Graphics/CModel.hpp" -namespace urde { +namespace metaforce { CSkinRules::CSkinRules(CInputStream& in) { u32 bankCount = in.readUint32Big(); @@ -25,6 +25,7 @@ CSkinRules::CSkinRules(CInputStream& in) { void CSkinRules::TransformVerticesCPU(std::vector>& vnOut, const CPoseAsTransforms& pose, const CModel& model) const { + OPTICK_EVENT(); vnOut.resize(m_poolToSkinIdx.size()); for (size_t i = 0; i < m_poolToSkinIdx.size(); ++i) { const CVirtualBone& vb = m_virtualBones[m_poolToSkinIdx[i]]; @@ -46,4 +47,4 @@ CFactoryFnReturn FSkinRulesFactory(const SObjectTag& tag, CInputStream& in, cons return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSkinRules.hpp b/Runtime/Character/CSkinRules.hpp index ddcac476a..aa5dd8851 100644 --- a/Runtime/Character/CSkinRules.hpp +++ b/Runtime/Character/CSkinRules.hpp @@ -8,7 +8,7 @@ #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class CPoseAsTransforms; class CModel; @@ -44,6 +44,10 @@ public: void GetBankTransforms(std::vector& out, const CPoseAsTransforms& pose, int skinBankIdx) const { + // FIXME: This is definitely not proper behavior, this is here to fix the phazon suit crashing + if (x0_skinBanks.size() <= skinBankIdx) { + return; + } x0_skinBanks[skinBankIdx].GetBankTransforms(out, pose); } @@ -54,4 +58,4 @@ public: CFactoryFnReturn FSkinRulesFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& params, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSoundPOINode.cpp b/Runtime/Character/CSoundPOINode.cpp index c7ac311cf..53a2b3c1f 100644 --- a/Runtime/Character/CSoundPOINode.cpp +++ b/Runtime/Character/CSoundPOINode.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CAnimSourceReader.hpp" -namespace urde { +namespace metaforce { CSoundPOINode::CSoundPOINode() : CPOINode("root", EPOIType::Sound, CCharAnimTime(), -1, false, 1.f, -1, 0) @@ -23,4 +23,4 @@ CSoundPOINode CSoundPOINode::CopyNodeMinusStartTime(const CSoundPOINode& node, c return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSoundPOINode.hpp b/Runtime/Character/CSoundPOINode.hpp index 4e243fd5c..cb1144351 100644 --- a/Runtime/Character/CSoundPOINode.hpp +++ b/Runtime/Character/CSoundPOINode.hpp @@ -3,7 +3,7 @@ #include "Runtime/Character/CCharAnimTime.hpp" #include "Runtime/Character/CPOINode.hpp" -namespace urde { +namespace metaforce { class IAnimSourceInfo; class CSoundPOINode : public CPOINode { @@ -23,4 +23,4 @@ public: float GetMaxDist() const { return x40_maxDist; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSteeringBehaviors.cpp b/Runtime/Character/CSteeringBehaviors.cpp index 86b29ae35..b23a4d5d3 100644 --- a/Runtime/Character/CSteeringBehaviors.cpp +++ b/Runtime/Character/CSteeringBehaviors.cpp @@ -3,7 +3,7 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/World/CPhysicsActor.hpp" -namespace urde { +namespace metaforce { zeus::CVector3f CSteeringBehaviors::Flee(const CPhysicsActor& actor, const zeus::CVector3f& v0) const { zeus::CVector3f actVec = actor.GetTranslation() - v0; @@ -363,4 +363,4 @@ zeus::CVector3f CSteeringBehaviors::ProjectOrbitalPosition(const zeus::CVector3f return usePos; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CSteeringBehaviors.hpp b/Runtime/Character/CSteeringBehaviors.hpp index 12a0f2d8d..e9813b4c8 100644 --- a/Runtime/Character/CSteeringBehaviors.hpp +++ b/Runtime/Character/CSteeringBehaviors.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { class CPhysicsActor; class CStateManager; @@ -41,4 +41,4 @@ public: const zeus::CVector3f& orbitPoint, float dt, float preThinkDt); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTimeScaleFunctions.cpp b/Runtime/Character/CTimeScaleFunctions.cpp index 18817fea7..83b99fa80 100644 --- a/Runtime/Character/CTimeScaleFunctions.cpp +++ b/Runtime/Character/CTimeScaleFunctions.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { std::unique_ptr IVaryingAnimationTimeScale::Clone() const { return VClone(); } @@ -87,4 +87,4 @@ std::unique_ptr CLinearAnimationTimeScale::VGetFunct return x4_desc.FunctionMirroredAround(value); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTimeScaleFunctions.hpp b/Runtime/Character/CTimeScaleFunctions.hpp index 0829b96e3..720c36167 100644 --- a/Runtime/Character/CTimeScaleFunctions.hpp +++ b/Runtime/Character/CTimeScaleFunctions.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Character/CCharAnimTime.hpp" -namespace urde { +namespace metaforce { enum class EVaryingAnimationTimeScaleType { Constant, Linear }; @@ -55,4 +55,4 @@ public: std::unique_ptr VGetFunctionMirrored(float value) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTransition.cpp b/Runtime/Character/CTransition.cpp index 4df34a5aa..db98cd867 100644 --- a/Runtime/Character/CTransition.cpp +++ b/Runtime/Character/CTransition.cpp @@ -1,6 +1,6 @@ #include "Runtime/Character/CTransition.hpp" -namespace urde { +namespace metaforce { CTransition::CTransition(CInputStream& in) : x0_id(in.readUint32Big()) @@ -8,4 +8,4 @@ CTransition::CTransition(CInputStream& in) , x8_animB(in.readUint32Big()) , xc_trans(CMetaTransFactory::CreateMetaTrans(in)) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTransition.hpp b/Runtime/Character/CTransition.hpp index 80f74ab70..8a062f03f 100644 --- a/Runtime/Character/CTransition.hpp +++ b/Runtime/Character/CTransition.hpp @@ -6,7 +6,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Character/CMetaTransFactory.hpp" -namespace urde { +namespace metaforce { class CTransition { u32 x0_id; @@ -22,4 +22,4 @@ public: const std::shared_ptr& GetMetaTrans() const { return xc_trans; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTransitionDatabase.hpp b/Runtime/Character/CTransitionDatabase.hpp index 891bbf166..076496fe7 100644 --- a/Runtime/Character/CTransitionDatabase.hpp +++ b/Runtime/Character/CTransitionDatabase.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class IMetaTrans; class CTransitionDatabase { @@ -12,4 +12,4 @@ public: virtual const std::shared_ptr& GetMetaTrans(u32, u32) const = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTransitionDatabaseGame.cpp b/Runtime/Character/CTransitionDatabaseGame.cpp index 37a09bbdc..fd3407587 100644 --- a/Runtime/Character/CTransitionDatabaseGame.cpp +++ b/Runtime/Character/CTransitionDatabaseGame.cpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { CTransitionDatabaseGame::CTransitionDatabaseGame(const std::vector& transitions, const std::vector& halfTransitions, @@ -42,4 +42,4 @@ const std::shared_ptr& CTransitionDatabaseGame::GetMetaTrans(u32 a, return x10_defaultTrans; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTransitionDatabaseGame.hpp b/Runtime/Character/CTransitionDatabaseGame.hpp index d464cd6b6..16e71c454 100644 --- a/Runtime/Character/CTransitionDatabaseGame.hpp +++ b/Runtime/Character/CTransitionDatabaseGame.hpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CTransitionDatabase.hpp" -namespace urde { +namespace metaforce { class CTransition; class CHalfTransition; @@ -22,4 +22,4 @@ public: const std::shared_ptr& GetMetaTrans(u32, u32) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTransitionManager.cpp b/Runtime/Character/CTransitionManager.cpp index 94a867e8a..e7225fe2e 100644 --- a/Runtime/Character/CTransitionManager.cpp +++ b/Runtime/Character/CTransitionManager.cpp @@ -2,11 +2,11 @@ #include "Runtime/Character/CTreeUtils.hpp" -namespace urde { +namespace metaforce { std::shared_ptr CTransitionManager::GetTransitionTree(const std::shared_ptr& a, const std::shared_ptr& b) const { return CTreeUtils::GetTransitionTree(a, b, x0_animCtx); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTransitionManager.hpp b/Runtime/Character/CTransitionManager.hpp index d5466bdd5..682ea607f 100644 --- a/Runtime/Character/CTransitionManager.hpp +++ b/Runtime/Character/CTransitionManager.hpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CAnimSysContext.hpp" #include "Runtime/Character/CTransitionDatabaseGame.hpp" -namespace urde { +namespace metaforce { class CAnimTreeNode; class CRandom16; class CSimplePool; @@ -20,4 +20,4 @@ public: const std::shared_ptr& b) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTreeUtils.cpp b/Runtime/Character/CTreeUtils.cpp index 8c64f0d4d..c87c1eb90 100644 --- a/Runtime/Character/CTreeUtils.cpp +++ b/Runtime/Character/CTreeUtils.cpp @@ -5,7 +5,7 @@ #include "Runtime/Character/CTransitionDatabaseGame.hpp" #include "Runtime/Character/IMetaTrans.hpp" -namespace urde { +namespace metaforce { std::shared_ptr CTreeUtils::GetTransitionTree(const std::weak_ptr& a, const std::weak_ptr& b, @@ -16,4 +16,4 @@ std::shared_ptr CTreeUtils::GetTransitionTree(const std::weak_ptr ->GetTransitionTree(a, b, animCtx); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CTreeUtils.hpp b/Runtime/Character/CTreeUtils.hpp index 9397c51d7..11428694c 100644 --- a/Runtime/Character/CTreeUtils.hpp +++ b/Runtime/Character/CTreeUtils.hpp @@ -4,7 +4,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CAnimTreeNode; struct CAnimSysContext; @@ -15,4 +15,4 @@ public: const CAnimSysContext& animCtx); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/CharacterCommon.hpp b/Runtime/Character/CharacterCommon.hpp index c87ebfea7..0ccb8674d 100644 --- a/Runtime/Character/CharacterCommon.hpp +++ b/Runtime/Character/CharacterCommon.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde { +namespace metaforce { namespace pas { enum class ELocomotionType { Invalid = -1, @@ -25,31 +25,31 @@ enum class ELocomotionAnim { Invalid = -1, Idle, Walk, Run, BackUp, StrafeLeft, enum class EAnimationState { Invalid = -1, - Fall, - Getup, - LieOnGround, - Step, - Death, - Locomotion, - KnockBack, - MeleeAttack, - Turn, - LoopAttack, - LoopReaction, - GroundHit, - Generate, - Jump, - Hurled, - Slide, - Taunt, - Scripted, - ProjectileAttack, - Cover, - WallHang, - AdditiveIdle, - AdditiveAim, - AdditiveFlinch, - AdditiveReaction + Fall = 0, + Getup = 1, + LieOnGround = 2, + Step = 3, + Death = 4, + Locomotion = 5, + KnockBack = 6, + MeleeAttack = 7, + Turn = 8, + LoopAttack = 9, + LoopReaction = 10, + GroundHit = 11, + Generate = 12, + Jump = 13, + Hurled = 14, + Slide = 15, + Taunt = 16, + Scripted = 17, + ProjectileAttack = 18, + Cover = 19, + WallHang = 20, + AdditiveIdle = 21, + AdditiveAim = 22, + AdditiveFlinch = 23, + AdditiveReaction = 24 }; enum class EHurledState { @@ -64,7 +64,7 @@ enum class EHurledState { Seven }; -enum class EFallState { Invalid = -1, Zero, One , Two}; +enum class EFallState { Invalid = -1, Zero, One, Two }; enum class EReactionType { Invalid = -1, Zero, One, Two, Three }; @@ -156,4 +156,4 @@ enum class EBodyStateCmd { StopReaction }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/IAnimReader.cpp b/Runtime/Character/IAnimReader.cpp index fcb5f8009..8b212b567 100644 --- a/Runtime/Character/IAnimReader.cpp +++ b/Runtime/Character/IAnimReader.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CCharAnimTime.hpp" -namespace urde { +namespace metaforce { SAdvancementDeltas SAdvancementDeltas::Interpolate(const SAdvancementDeltas& a, const SAdvancementDeltas& b, float oldWeight, float newWeight) { @@ -54,4 +54,4 @@ size_t IAnimReader::GetSoundPOIList(const CCharAnimTime& time, CSoundPOINode* li return 0; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/IAnimReader.hpp b/Runtime/Character/IAnimReader.hpp index eb005e741..6988d90a0 100644 --- a/Runtime/Character/IAnimReader.hpp +++ b/Runtime/Character/IAnimReader.hpp @@ -13,7 +13,7 @@ #include #include -namespace urde { +namespace metaforce { class CBoolPOINode; class CInt32POINode; class CParticlePOINode; @@ -146,4 +146,4 @@ public: std::unique_ptr Clone() const { return VClone(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/IMetaAnim.cpp b/Runtime/Character/IMetaAnim.cpp index 58a350985..1b45a5626 100644 --- a/Runtime/Character/IMetaAnim.cpp +++ b/Runtime/Character/IMetaAnim.cpp @@ -7,7 +7,7 @@ #include "Runtime/Character/CCharAnimTime.hpp" #include "Runtime/Character/IAnimReader.hpp" -namespace urde { +namespace metaforce { std::shared_ptr IMetaAnim::GetAnimationTree(const CAnimSysContext& animSys, const CMetaAnimTreeBuildOrders& orders) const { @@ -50,4 +50,4 @@ CCharAnimTime IMetaAnim::GetTime(const CPreAdvanceIndicator& ind, const IAnimRea return {}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/IMetaAnim.hpp b/Runtime/Character/IMetaAnim.hpp index c941dafc5..7313bc6ff 100644 --- a/Runtime/Character/IMetaAnim.hpp +++ b/Runtime/Character/IMetaAnim.hpp @@ -7,7 +7,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Character/CCharAnimTime.hpp" -namespace urde { +namespace metaforce { class CAnimTreeNode; class CPrimitive; class IAnimReader; @@ -68,4 +68,4 @@ public: static CCharAnimTime GetTime(const CPreAdvanceIndicator& ind, const IAnimReader& anim); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/IMetaTrans.hpp b/Runtime/Character/IMetaTrans.hpp index 862e2564f..c23033000 100644 --- a/Runtime/Character/IMetaTrans.hpp +++ b/Runtime/Character/IMetaTrans.hpp @@ -4,7 +4,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CAnimTreeNode; struct CAnimSysContext; @@ -25,4 +25,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/IVaryingAnimationTimeScale.hpp b/Runtime/Character/IVaryingAnimationTimeScale.hpp index aea324e67..8cdb96ec1 100644 --- a/Runtime/Character/IVaryingAnimationTimeScale.hpp +++ b/Runtime/Character/IVaryingAnimationTimeScale.hpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CCharAnimTime.hpp" -namespace urde { +namespace metaforce { class IVaryingAnimationTimeScale { public: virtual ~IVaryingAnimationTimeScale() = default; @@ -21,4 +21,4 @@ public: std::unique_ptr Clone() const { return VClone(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Character/TSegIdMap.hpp b/Runtime/Character/TSegIdMap.hpp index f52c66730..1f0e5255d 100644 --- a/Runtime/Character/TSegIdMap.hpp +++ b/Runtime/Character/TSegIdMap.hpp @@ -6,7 +6,7 @@ #include "Runtime/Character/CSegId.hpp" -namespace urde { +namespace metaforce { template class TSegIdMap { @@ -72,4 +72,4 @@ public: u32 GetCapacity() const { return x1_capacity; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CAABoxFilter.cpp b/Runtime/Collision/CAABoxFilter.cpp index 77583c3b1..fd9652eda 100644 --- a/Runtime/Collision/CAABoxFilter.cpp +++ b/Runtime/Collision/CAABoxFilter.cpp @@ -3,7 +3,7 @@ #include "Runtime/Collision/CCollisionInfoList.hpp" #include "Runtime/Collision/CollisionUtil.hpp" -namespace urde { +namespace metaforce { void CAABoxFilter::Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const { FilterBoxFloorCollisions(in, out); @@ -27,4 +27,4 @@ void CAABoxFilter::FilterBoxFloorCollisions(const CCollisionInfoList& in, CColli CollisionUtil::AddAverageToFront(temp, out); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CAABoxFilter.hpp b/Runtime/Collision/CAABoxFilter.hpp index 59e5c92c6..d5e0d1686 100644 --- a/Runtime/Collision/CAABoxFilter.hpp +++ b/Runtime/Collision/CAABoxFilter.hpp @@ -2,7 +2,7 @@ #include "Runtime/Collision/ICollisionFilter.hpp" -namespace urde { +namespace metaforce { class CCollisionInfoList; class CAABoxFilter : public ICollisionFilter { @@ -12,4 +12,4 @@ public: static void FilterBoxFloorCollisions(const CCollisionInfoList& in, CCollisionInfoList& out); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CAreaOctTree.cpp b/Runtime/Collision/CAreaOctTree.cpp index 38dd381e3..045dd4081 100644 --- a/Runtime/Collision/CAreaOctTree.cpp +++ b/Runtime/Collision/CAreaOctTree.cpp @@ -10,7 +10,7 @@ #include #include -namespace urde { +namespace metaforce { static bool _close_enough(float f1, float f2, float epsilon) { return std::fabs(f1 - f2) <= epsilon; } @@ -620,4 +620,4 @@ void CAreaOctTree::GetTriangleVertexIndices(u16 idx, u16 indicesOut[3]) const { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CAreaOctTree.hpp b/Runtime/Collision/CAreaOctTree.hpp index a1c2b57ea..359f1a9be 100644 --- a/Runtime/Collision/CAreaOctTree.hpp +++ b/Runtime/Collision/CAreaOctTree.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CMaterialFilter; class CAreaOctTree { friend class CBooRenderer; @@ -116,4 +116,4 @@ public: static std::unique_ptr MakeFromMemory(const u8* buf, unsigned int size); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CBallFilter.cpp b/Runtime/Collision/CBallFilter.cpp index 6067547cf..d364bc8a0 100644 --- a/Runtime/Collision/CBallFilter.cpp +++ b/Runtime/Collision/CBallFilter.cpp @@ -1,10 +1,10 @@ #include "Runtime/Collision/CBallFilter.hpp" #include "Runtime/Collision/CollisionUtil.hpp" -namespace urde { +namespace metaforce { void CBallFilter::Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const { CollisionUtil::AddAverageToFront(in, out); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CBallFilter.hpp b/Runtime/Collision/CBallFilter.hpp index 7ba532a03..6b25e47df 100644 --- a/Runtime/Collision/CBallFilter.hpp +++ b/Runtime/Collision/CBallFilter.hpp @@ -2,7 +2,7 @@ #include "Runtime/Collision/ICollisionFilter.hpp" -namespace urde { +namespace metaforce { class CCollisionInfoList; class CPhysicsActor; @@ -12,4 +12,4 @@ public: void Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableAABox.cpp b/Runtime/Collision/CCollidableAABox.cpp index 1841c95fe..17775844d 100644 --- a/Runtime/Collision/CCollidableAABox.cpp +++ b/Runtime/Collision/CCollidableAABox.cpp @@ -5,7 +5,7 @@ #include "Runtime/Collision/CInternalRayCastStructure.hpp" #include "Runtime/Collision/CollisionUtil.hpp" -namespace urde { +namespace metaforce { constexpr CCollisionPrimitive::Type sType(CCollidableAABox::SetStaticTableIndex, "CCollidableAABox"); CCollidableAABox::CCollidableAABox() = default; @@ -112,4 +112,4 @@ bool AABox_AABox_Bool(const CInternalCollisionStructure& collision) { } } // namespace Collide -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableAABox.hpp b/Runtime/Collision/CCollidableAABox.hpp index 4714bc7f2..d4f7c123f 100644 --- a/Runtime/Collision/CCollidableAABox.hpp +++ b/Runtime/Collision/CCollidableAABox.hpp @@ -5,7 +5,7 @@ #include -namespace urde { +namespace metaforce { namespace Collide { bool AABox_AABox(const CInternalCollisionStructure&, CCollisionInfoList&); bool AABox_AABox_Bool(const CInternalCollisionStructure&); @@ -35,4 +35,4 @@ public: static bool CollideMovingAABox(const CInternalCollisionStructure&, const zeus::CVector3f&, double&, CCollisionInfo&); static bool CollideMovingSphere(const CInternalCollisionStructure&, const zeus::CVector3f&, double&, CCollisionInfo&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableCollisionSurface.cpp b/Runtime/Collision/CCollidableCollisionSurface.cpp index ef55b3f03..3c853124b 100644 --- a/Runtime/Collision/CCollidableCollisionSurface.cpp +++ b/Runtime/Collision/CCollidableCollisionSurface.cpp @@ -1,10 +1,10 @@ #include "Runtime/Collision/CCollidableCollisionSurface.hpp" -namespace urde { +namespace metaforce { constexpr CCollisionPrimitive::Type sType(CCollidableCollisionSurface::SetStaticTableIndex, "CCollidableCollisionSurface"); const CCollisionPrimitive::Type& CCollidableCollisionSurface::GetType() { return sType; } void CCollidableCollisionSurface::SetStaticTableIndex(u32 index) { sTableIndex = index; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableCollisionSurface.hpp b/Runtime/Collision/CCollidableCollisionSurface.hpp index e4ec95ba4..da5f49115 100644 --- a/Runtime/Collision/CCollidableCollisionSurface.hpp +++ b/Runtime/Collision/CCollidableCollisionSurface.hpp @@ -3,7 +3,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/Collision/CCollisionPrimitive.hpp" -namespace urde { +namespace metaforce { class CCollidableCollisionSurface { static inline u32 sTableIndex = UINT32_MAX; @@ -11,4 +11,4 @@ public: static const CCollisionPrimitive::Type& GetType(); static void SetStaticTableIndex(u32 index); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableOBBTree.cpp b/Runtime/Collision/CCollidableOBBTree.cpp index 2e3c9b012..ff224bfe0 100644 --- a/Runtime/Collision/CCollidableOBBTree.cpp +++ b/Runtime/Collision/CCollidableOBBTree.cpp @@ -7,9 +7,9 @@ #include "Runtime/Collision/CMaterialFilter.hpp" #include "Runtime/Collision/CollisionUtil.hpp" -namespace urde { +namespace metaforce { -CCollidableOBBTree::CCollidableOBBTree(const COBBTree* tree, const urde::CMaterialList& material) +CCollidableOBBTree::CCollidableOBBTree(const COBBTree* tree, const metaforce::CMaterialList& material) : CCollisionPrimitive(material), x10_tree(tree) {} bool CCollidableOBBTree::LineIntersectsLeaf(const COBBTree::CLeafData& leaf, CRayCastInfo& info) const { @@ -570,4 +570,4 @@ zeus::CAABox CCollidableOBBTree::CalculateAABox(const zeus::CTransform& xf) cons zeus::CAABox CCollidableOBBTree::CalculateLocalAABox() const { return x10_tree->CalculateLocalAABox(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableOBBTree.hpp b/Runtime/Collision/CCollidableOBBTree.hpp index 735919753..014c81141 100644 --- a/Runtime/Collision/CCollidableOBBTree.hpp +++ b/Runtime/Collision/CCollidableOBBTree.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class CRayCastInfo { const zeus::CMRay& x0_ray; const CMaterialFilter& x4_filter; @@ -86,4 +86,4 @@ public: CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableOBBTreeGroup.cpp b/Runtime/Collision/CCollidableOBBTreeGroup.cpp index 12e2ba331..6e9a41804 100644 --- a/Runtime/Collision/CCollidableOBBTreeGroup.cpp +++ b/Runtime/Collision/CCollidableOBBTreeGroup.cpp @@ -7,7 +7,7 @@ #include "Runtime/Collision/CInternalRayCastStructure.hpp" #include "Runtime/Collision/CollisionUtil.hpp" -namespace urde { +namespace metaforce { constexpr CCollisionPrimitive::Type sType(CCollidableOBBTreeGroup::SetStaticTableIndex, "CCollidableOBBTreeGroup"); CCollidableOBBTreeGroupContainer::CCollidableOBBTreeGroupContainer(CInputStream& in) { @@ -229,4 +229,4 @@ CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag& tag, CInputStr std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableOBBTreeGroup.hpp b/Runtime/Collision/CCollidableOBBTreeGroup.hpp index 24e0e0670..c60e44b1a 100644 --- a/Runtime/Collision/CCollidableOBBTreeGroup.hpp +++ b/Runtime/Collision/CCollidableOBBTreeGroup.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollidableOBBTreeGroupContainer { friend class CCollidableOBBTreeGroup; std::vector> x0_trees; @@ -52,4 +52,4 @@ public: CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableSphere.cpp b/Runtime/Collision/CCollidableSphere.cpp index ae48d7df3..559d866d9 100644 --- a/Runtime/Collision/CCollidableSphere.cpp +++ b/Runtime/Collision/CCollidableSphere.cpp @@ -5,7 +5,7 @@ #include "Runtime/Collision/CInternalRayCastStructure.hpp" #include "Runtime/Collision/CollisionUtil.hpp" -namespace urde { +namespace metaforce { constexpr CCollisionPrimitive::Type sType(CCollidableSphere::SetStaticTableIndex, "CCollidableSphere"); namespace Collide { @@ -281,4 +281,4 @@ bool CCollidableSphere::Sphere_AABox_Bool(const zeus::CSphere& sphere, const zeu return mag <= sphere.radius * sphere.radius; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollidableSphere.hpp b/Runtime/Collision/CCollidableSphere.hpp index cb0b3f5e7..5415e5e0f 100644 --- a/Runtime/Collision/CCollidableSphere.hpp +++ b/Runtime/Collision/CCollidableSphere.hpp @@ -5,7 +5,7 @@ #include #include -namespace urde { +namespace metaforce { namespace Collide { bool Sphere_AABox(const CInternalCollisionStructure&, CCollisionInfoList&); bool Sphere_AABox_Bool(const CInternalCollisionStructure&); @@ -38,4 +38,4 @@ public: static bool CollideMovingSphere(const CInternalCollisionStructure&, const zeus::CVector3f&, double&, CCollisionInfo&); static bool Sphere_AABox_Bool(const zeus::CSphere& sphere, const zeus::CAABox& aabb); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionActor.cpp b/Runtime/Collision/CCollisionActor.cpp index a8007ceca..b8f78939d 100644 --- a/Runtime/Collision/CCollisionActor.cpp +++ b/Runtime/Collision/CCollisionActor.cpp @@ -8,16 +8,16 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { constexpr CMaterialList skDefaultCollisionActorMaterials = CMaterialList(EMaterialTypes::Solid, EMaterialTypes::CollisionActor, EMaterialTypes::ScanPassthrough, EMaterialTypes::CameraPassthrough); CCollisionActor::CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, const zeus::CVector3f& extent, const zeus::CVector3f& center, bool active, float mass, std::string_view name) -: CPhysicsActor(uid, active, "CollisionActor", CEntityInfo(areaId, CEntity::NullConnectionList), - zeus::CTransform(), CModelData::CModelDataNull(), skDefaultCollisionActorMaterials, - zeus::skNullBox, SMoverData(mass), CActorParameters::None(), 0.3f, 0.1f) +: CPhysicsActor(uid, active, "CollisionActor", CEntityInfo(areaId, CEntity::NullConnectionList), zeus::CTransform(), + CModelData::CModelDataNull(), skDefaultCollisionActorMaterials, zeus::skNullBox, SMoverData(mass), + CActorParameters::None(), 0.3f, 0.1f) , x258_primitiveType(EPrimitiveType::OBBTreeGroup) , x25c_owner(owner) , x260_boxSize(extent) @@ -34,9 +34,9 @@ CCollisionActor::CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, CCollisionActor::CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, const zeus::CVector3f& boxSize, bool active, float mass, std::string_view name) -: CPhysicsActor(uid, active, "CollisionActor", CEntityInfo(areaId, CEntity::NullConnectionList), - zeus::CTransform(), CModelData::CModelDataNull(), skDefaultCollisionActorMaterials, - zeus::skNullBox, SMoverData(mass), CActorParameters::None(), 0.3f, 0.1f) +: CPhysicsActor(uid, active, "CollisionActor", CEntityInfo(areaId, CEntity::NullConnectionList), zeus::CTransform(), + CModelData::CModelDataNull(), skDefaultCollisionActorMaterials, zeus::skNullBox, SMoverData(mass), + CActorParameters::None(), 0.3f, 0.1f) , x258_primitiveType(EPrimitiveType::AABox) , x25c_owner(owner) , x260_boxSize(boxSize) @@ -53,9 +53,9 @@ CCollisionActor::CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, CCollisionActor::CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, bool active, float radius, float mass, std::string_view name) -: CPhysicsActor(uid, active, "CollisionActor", CEntityInfo(areaId, CEntity::NullConnectionList), - zeus::CTransform(), CModelData::CModelDataNull(), skDefaultCollisionActorMaterials, - zeus::skNullBox, SMoverData(mass), CActorParameters::None(), 0.3f, 0.1f) +: CPhysicsActor(uid, active, "CollisionActor", CEntityInfo(areaId, CEntity::NullConnectionList), zeus::CTransform(), + CModelData::CModelDataNull(), skDefaultCollisionActorMaterials, zeus::skNullBox, SMoverData(mass), + CActorParameters::None(), 0.3f, 0.1f) , x258_primitiveType(EPrimitiveType::Sphere) , x25c_owner(owner) , x284_spherePrimitive(std::make_unique( @@ -179,4 +179,17 @@ void CCollisionActor::SetSphereRadius(float radius) { x288_sphereRadius = radius; x284_spherePrimitive->SetSphereRadius(radius); } -} // namespace urde +void CCollisionActor::DebugDraw() { + zeus::CAABox aabox; + if (x258_primitiveType == EPrimitiveType::OBBTreeGroup) + aabox = x27c_obbTreeGroupPrimitive->CalculateAABox(x34_transform); + else if (x258_primitiveType == EPrimitiveType::AABox) + aabox = x280_aaboxPrimitive->CalculateAABox(x34_transform); + else if (x258_primitiveType == EPrimitiveType::Sphere) + aabox = x284_spherePrimitive->CalculateAABox(x34_transform); + m_aabox.setAABB(aabox); + zeus::CColor col = !GetActive() ? zeus::skRed : zeus::skGreen; + col.a() = 0.5f; + m_aabox.draw(col); +} +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionActor.hpp b/Runtime/Collision/CCollisionActor.hpp index 09435e251..a108688f4 100644 --- a/Runtime/Collision/CCollisionActor.hpp +++ b/Runtime/Collision/CCollisionActor.hpp @@ -3,13 +3,14 @@ #include #include +#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include "Runtime/World/CDamageVulnerability.hpp" #include "Runtime/World/CHealthInfo.hpp" #include "Runtime/World/CPhysicsActor.hpp" #include -namespace urde { +namespace metaforce { class CCollidableSphere; class CCollidableOBBTreeGroup; class CCollidableOBBTreeGroupContainer; @@ -32,6 +33,7 @@ class CCollisionActor : public CPhysicsActor { EWeaponCollisionResponseTypes x300_responseType = EWeaponCollisionResponseTypes::EnemyNormal; zeus::CVector3f x304_extendedTouchBounds = zeus::skZero3f; + CAABoxShader m_aabox; public: CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, const zeus::CVector3f& extent, const zeus::CVector3f& center, bool active, float mass, std::string_view name); @@ -42,6 +44,7 @@ public: void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) override; + void DebugDraw(); CHealthInfo* HealthInfo(CStateManager& mgr) override; const CDamageVulnerability* GetDamageVulnerability() const override; const CDamageVulnerability* GetDamageVulnerability(const zeus::CVector3f& vec1, const zeus::CVector3f& vec2, @@ -66,4 +69,4 @@ public: void SetSphereRadius(float radius); float GetSphereRadius() const { return x288_sphereRadius; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionActorManager.cpp b/Runtime/Collision/CCollisionActorManager.cpp index 81b8b6d35..29ec16f51 100644 --- a/Runtime/Collision/CCollisionActorManager.cpp +++ b/Runtime/Collision/CCollisionActorManager.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CCollisionActorManager::CCollisionActorManager(CStateManager& mgr, TUniqueId owner, TAreaId area, const std::vector& descs, bool active) @@ -246,4 +246,4 @@ std::optional CCollisionActorManager::GetDeviation(const CState return std::nullopt; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionActorManager.hpp b/Runtime/Collision/CCollisionActorManager.hpp index 158632851..51e69d1eb 100644 --- a/Runtime/Collision/CCollisionActorManager.hpp +++ b/Runtime/Collision/CCollisionActorManager.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CAnimData; class CCollisionActor; class CMaterialList; @@ -43,4 +43,4 @@ public: static zeus::CTransform GetWRLocatorTransform(const CAnimData& animData, CSegId id, const zeus::CTransform& worldXf, const zeus::CTransform& localXf); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionEdge.cpp b/Runtime/Collision/CCollisionEdge.cpp index 4ec1b6932..d7733136b 100644 --- a/Runtime/Collision/CCollisionEdge.cpp +++ b/Runtime/Collision/CCollisionEdge.cpp @@ -1,8 +1,8 @@ #include "Runtime/Collision/CCollisionEdge.hpp" -namespace urde { +namespace metaforce { CCollisionEdge::CCollisionEdge(CInputStream& in) { x0_index1 = in.readUint16Big(); x2_index2 = in.readUint16Big(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionEdge.hpp b/Runtime/Collision/CCollisionEdge.hpp index 7c976a058..10d9e90e3 100644 --- a/Runtime/Collision/CCollisionEdge.hpp +++ b/Runtime/Collision/CCollisionEdge.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CCollisionEdge { u16 x0_index1 = -1; u16 x2_index2 = -1; @@ -20,4 +20,4 @@ public: x2_index2 = hecl::SBig(x2_index2); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionInfo.cpp b/Runtime/Collision/CCollisionInfo.cpp index 20ab3b27e..d89743d54 100644 --- a/Runtime/Collision/CCollisionInfo.cpp +++ b/Runtime/Collision/CCollisionInfo.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { CCollisionInfo CCollisionInfo::GetSwapped() const { CCollisionInfo ret; @@ -25,4 +25,4 @@ void CCollisionInfo::Swap() { zeus::CVector3f CCollisionInfo::GetExtreme() const { return x0_point + xc_extentX + x18_extentY + x24_extentZ; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionInfo.hpp b/Runtime/Collision/CCollisionInfo.hpp index cb8e83bf9..5a290e071 100644 --- a/Runtime/Collision/CCollisionInfo.hpp +++ b/Runtime/Collision/CCollisionInfo.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollisionInfo { friend class CCollisionInfoList; @@ -66,4 +66,4 @@ public: const zeus::CVector3f& GetPoint() const { return x0_point; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionInfoList.hpp b/Runtime/Collision/CCollisionInfoList.hpp index 4216f3158..75c3f0a48 100644 --- a/Runtime/Collision/CCollisionInfoList.hpp +++ b/Runtime/Collision/CCollisionInfoList.hpp @@ -4,7 +4,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Collision/CCollisionInfo.hpp" -namespace urde { +namespace metaforce { class CCollisionInfoList { rstl::reserved_vector x0_list; @@ -89,4 +89,4 @@ public: } } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionPrimitive.cpp b/Runtime/Collision/CCollisionPrimitive.cpp index 139d1e560..8a0d65812 100644 --- a/Runtime/Collision/CCollisionPrimitive.cpp +++ b/Runtime/Collision/CCollisionPrimitive.cpp @@ -10,7 +10,7 @@ #include "Runtime/Collision/CMaterialFilter.hpp" #include "Runtime/Collision/InternalColliders.hpp" -namespace urde { +namespace metaforce { s32 CCollisionPrimitive::sNumTypes = 0; bool CCollisionPrimitive::sInitComplete = false; bool CCollisionPrimitive::sTypesAdded = false; @@ -265,4 +265,4 @@ void CCollisionPrimitive::Uninitialize() { sTableOfBooleanCollidables.reset(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionPrimitive.hpp b/Runtime/Collision/CCollisionPrimitive.hpp index bbe619908..63cbebf2f 100644 --- a/Runtime/Collision/CCollisionPrimitive.hpp +++ b/Runtime/Collision/CCollisionPrimitive.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollisionPrimitive; class CMaterialFilter; @@ -169,4 +169,4 @@ public: static void Uninitialize(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionResponseData.cpp b/Runtime/Collision/CCollisionResponseData.cpp index 20b25204b..e99c8fbc1 100644 --- a/Runtime/Collision/CCollisionResponseData.cpp +++ b/Runtime/Collision/CCollisionResponseData.cpp @@ -11,7 +11,7 @@ #include "Runtime/Particle/CParticleDataFactory.hpp" #include "Runtime/Particle/CSwooshDescription.hpp" -namespace urde { +namespace metaforce { namespace { constexpr std::array skWorldMaterialTable{ EWeaponCollisionResponseTypes::Default, EWeaponCollisionResponseTypes::Unknown2, @@ -253,4 +253,4 @@ CFactoryFnReturn FCollisionResponseDataFactory(const SObjectTag& tag, CInputStre CSimplePool* sp = vparms.GetOwnedObj(); return TToken::GetIObjObjectFor(std::make_unique(in, sp)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionResponseData.hpp b/Runtime/Collision/CCollisionResponseData.hpp index 4b61ca6d4..351f367c4 100644 --- a/Runtime/Collision/CCollisionResponseData.hpp +++ b/Runtime/Collision/CCollisionResponseData.hpp @@ -11,7 +11,7 @@ #include "Runtime/Collision/CMaterialList.hpp" #include "Runtime/Particle/CDecalDescription.hpp" -namespace urde { +namespace metaforce { class CGenDescription; class CSimplePool; @@ -141,4 +141,4 @@ public: CFactoryFnReturn FCollisionResponseDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionSurface.cpp b/Runtime/Collision/CCollisionSurface.cpp index f1b48e350..791d1f400 100644 --- a/Runtime/Collision/CCollisionSurface.cpp +++ b/Runtime/Collision/CCollisionSurface.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { CCollisionSurface::CCollisionSurface(const zeus::CVector3f& a, const zeus::CVector3f& b, const zeus::CVector3f& c, u32 flags) : x0_data{a, b, c}, x24_flags(flags) {} @@ -17,4 +17,4 @@ zeus::CPlane CCollisionSurface::GetPlane() const { return {norm, norm.dot(x0_data[0])}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CCollisionSurface.hpp b/Runtime/Collision/CCollisionSurface.hpp index ea7a6ce50..7fa139b08 100644 --- a/Runtime/Collision/CCollisionSurface.hpp +++ b/Runtime/Collision/CCollisionSurface.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollisionSurface { public: using Vertices = std::array; @@ -25,4 +25,4 @@ public: zeus::CPlane GetPlane() const; u32 GetSurfaceFlags() const { return x24_flags; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CGameCollision.cpp b/Runtime/Collision/CGameCollision.cpp index 8352be196..7f1902999 100644 --- a/Runtime/Collision/CGameCollision.cpp +++ b/Runtime/Collision/CGameCollision.cpp @@ -17,7 +17,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static float CollisionImpulseFiniteVsInfinite(float mass, float velNormDot, float restitution) { return mass * -(1.f + restitution) * velNormDot; @@ -682,6 +682,23 @@ bool CGameCollision::DetectDynamicCollisionMoving(const CCollisionPrimitive& pri return ret; } +bool CGameCollision::DetectCollision(const CStateManager& mgr, const CCollisionPrimitive& prim, const zeus::CTransform& xf, + const CMaterialFilter& filter, const rstl::reserved_vector& nearList, + TUniqueId& idOut, CCollisionInfoList& infoOut) { + bool ret = false; + CMaterialList exclude = filter.ExcludeList(); + if (!exclude.HasMaterial(EMaterialTypes::Occluder) && DetectStaticCollision(mgr, prim, xf, filter, infoOut)) { + ret = true; + } + + TUniqueId tmpId = kInvalidUniqueId; + if (DetectDynamicCollision(prim, xf, nearList, tmpId, infoOut, mgr)) { + ret = true; + idOut = tmpId; + } + return ret; +} + void CGameCollision::MakeCollisionCallbacks(CStateManager& mgr, CPhysicsActor& actor, TUniqueId id, const CCollisionInfoList& list) { actor.CollidedWith(id, list, mgr); @@ -1017,4 +1034,4 @@ void CGameCollision::AvoidStaticCollisionWithinRadius(const CStateManager& mgr, actor.SetVelocityWR(actor.GetVelocity() + (dt * (mass * velocity))); } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CGameCollision.hpp b/Runtime/Collision/CGameCollision.hpp index ac3b9e292..ec7e91a81 100644 --- a/Runtime/Collision/CGameCollision.hpp +++ b/Runtime/Collision/CGameCollision.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CActor; class CCollisionInfo; @@ -105,6 +105,9 @@ public: const rstl::reserved_vector& nearList, const zeus::CVector3f& vec, TUniqueId& idOut, CCollisionInfo& infoOut, double& d, const CStateManager& mgr); + static bool DetectCollision(const CStateManager& mgr, const CCollisionPrimitive& prim, const zeus::CTransform& xf, + const CMaterialFilter& filter, const rstl::reserved_vector& nearList, + TUniqueId& idOut, CCollisionInfoList& infoOut); static void MakeCollisionCallbacks(CStateManager& mgr, CPhysicsActor& actor, TUniqueId id, const CCollisionInfoList& list); static void SendScriptMessages(CStateManager& mgr, CActor& a0, CActor* a1, const CCollisionInfoList& list); @@ -122,4 +125,4 @@ public: static void AvoidStaticCollisionWithinRadius(const CStateManager& mgr, CPhysicsActor& actor, u32 iterations, float dt, float height, float size, float mass, float radius); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CInternalRayCastStructure.hpp b/Runtime/Collision/CInternalRayCastStructure.hpp index e08e5170e..84848d292 100644 --- a/Runtime/Collision/CInternalRayCastStructure.hpp +++ b/Runtime/Collision/CInternalRayCastStructure.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { class CInternalRayCastStructure { zeus::CMRay x0_ray; float x38_maxTime; @@ -25,4 +25,4 @@ public: const zeus::CTransform& GetTransform() const { return x3c_xf; } const CMaterialFilter& GetFilter() const { return x6c_filter; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CJointCollisionDescription.cpp b/Runtime/Collision/CJointCollisionDescription.cpp index cbba49cc2..a04da6da4 100644 --- a/Runtime/Collision/CJointCollisionDescription.cpp +++ b/Runtime/Collision/CJointCollisionDescription.cpp @@ -1,6 +1,6 @@ #include "Runtime/Collision/CJointCollisionDescription.hpp" -namespace urde { +namespace metaforce { CJointCollisionDescription::CJointCollisionDescription(ECollisionType colType, CSegId pivotId, CSegId nextId, const zeus::CVector3f& bounds, const zeus::CVector3f& pivotPoint, @@ -58,4 +58,4 @@ void CJointCollisionDescription::ScaleAllBounds(const zeus::CVector3f& scale) { x28_maxSeparation *= scale.x(); x18_pivotPoint *= scale; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CJointCollisionDescription.hpp b/Runtime/Collision/CJointCollisionDescription.hpp index 2410ccdca..f2cb954a5 100644 --- a/Runtime/Collision/CJointCollisionDescription.hpp +++ b/Runtime/Collision/CJointCollisionDescription.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { struct SJointInfo { const char* from; const char* to; @@ -89,4 +89,4 @@ public: CSegId GetPivotId() const { return x8_pivotId; } void ScaleAllBounds(const zeus::CVector3f& scale); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CMaterialFilter.cpp b/Runtime/Collision/CMaterialFilter.cpp index ddd9b9dfa..475387ca3 100644 --- a/Runtime/Collision/CMaterialFilter.cpp +++ b/Runtime/Collision/CMaterialFilter.cpp @@ -1,5 +1,5 @@ #include "Runtime/Collision/CMaterialFilter.hpp" -namespace urde { +namespace metaforce { const CMaterialFilter CMaterialFilter::skPassEverything({0x00000000FFFFFFFF}, {0}, EFilterType::Always); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CMaterialFilter.hpp b/Runtime/Collision/CMaterialFilter.hpp index 198c43bbd..13fa2d52a 100644 --- a/Runtime/Collision/CMaterialFilter.hpp +++ b/Runtime/Collision/CMaterialFilter.hpp @@ -2,7 +2,7 @@ #include "Runtime/Collision/CMaterialList.hpp" -namespace urde { +namespace metaforce { class CMaterialFilter { public: enum class EFilterType { Always, Include, Exclude, IncludeExclude }; @@ -35,6 +35,9 @@ public: constexpr const CMaterialList& GetExcludeList() const noexcept { return x8_exclude; } constexpr CMaterialList& IncludeList() noexcept { return x0_include; } constexpr CMaterialList& ExcludeList() noexcept { return x8_exclude; } + const CMaterialList& IncludeList() const noexcept { return x0_include; } + const CMaterialList& ExcludeList() const noexcept { return x8_exclude; } + constexpr bool Passes(const CMaterialList& list) const noexcept { switch (x10_type) { @@ -53,4 +56,4 @@ public: } } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CMaterialList.hpp b/Runtime/Collision/CMaterialList.hpp index df798a8ea..12684a67b 100644 --- a/Runtime/Collision/CMaterialList.hpp +++ b/Runtime/Collision/CMaterialList.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { enum class EMaterialTypes { NoStepLogic = 0, Stone = 1, @@ -137,4 +137,4 @@ public: void Union(const CMaterialList& other) noexcept { x0_list |= other.x0_list; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CMetroidAreaCollider.cpp b/Runtime/Collision/CMetroidAreaCollider.cpp index 089433d28..ba90f2ddc 100644 --- a/Runtime/Collision/CMetroidAreaCollider.cpp +++ b/Runtime/Collision/CMetroidAreaCollider.cpp @@ -4,7 +4,7 @@ #include "Runtime/Collision/CMaterialFilter.hpp" #include "Runtime/Collision/CollisionUtil.hpp" -namespace urde { +namespace metaforce { u32 CMetroidAreaCollider::g_CalledClip = 0; u32 CMetroidAreaCollider::g_RejectedByClip = 0; @@ -951,4 +951,4 @@ void CAreaCollisionCache::AddOctreeLeafCache(const CMetroidAreaCollider::COctree } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CMetroidAreaCollider.hpp b/Runtime/Collision/CMetroidAreaCollider.hpp index 08a1fc10c..57803fcaf 100644 --- a/Runtime/Collision/CMetroidAreaCollider.hpp +++ b/Runtime/Collision/CMetroidAreaCollider.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollisionInfo; class CCollisionInfoList; class CMaterialList; @@ -191,4 +191,4 @@ public: { return x18_leafCaches.end(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/COBBTree.cpp b/Runtime/Collision/COBBTree.cpp index 2849ca96f..7eee3d37b 100644 --- a/Runtime/Collision/COBBTree.cpp +++ b/Runtime/Collision/COBBTree.cpp @@ -4,7 +4,7 @@ #include "Runtime/Collision/CCollidableOBBTreeGroup.hpp" -namespace urde { +namespace metaforce { namespace { constexpr std::array DefaultEdgeMaterials{ 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 2, @@ -244,4 +244,4 @@ COBBTree::CLeafData::CLeafData(CInputStream& in) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/COBBTree.hpp b/Runtime/Collision/COBBTree.hpp index 58ef0ec4d..2d14c5883 100644 --- a/Runtime/Collision/COBBTree.hpp +++ b/Runtime/Collision/COBBTree.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollidableOBBTreeGroupContainer; class COBBTree { @@ -93,4 +93,4 @@ public: zeus::CAABox CalculateAABox(const zeus::CTransform&) const; const CNode& GetRoot() const { return *x88_root; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CRayCastResult.cpp b/Runtime/Collision/CRayCastResult.cpp index cad892038..3ec63466a 100644 --- a/Runtime/Collision/CRayCastResult.cpp +++ b/Runtime/Collision/CRayCastResult.cpp @@ -1,6 +1,6 @@ #include "Runtime/Collision/CRayCastResult.hpp" -namespace urde { +namespace metaforce { void CRayCastResult::MakeInvalid() { /* NOTE: CRayCastResult: Enable this if it's required, this is a total guess - Phil */ @@ -19,4 +19,4 @@ void CRayCastResult::Transform(const zeus::CTransform& xf) { x10_plane = zeus::CPlane(xf.rotate(x10_plane.normal()), x10_plane.normal().dot(x4_point)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CRayCastResult.hpp b/Runtime/Collision/CRayCastResult.hpp index cabd64655..839b70154 100644 --- a/Runtime/Collision/CRayCastResult.hpp +++ b/Runtime/Collision/CRayCastResult.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CRayCastResult { public: enum class EInvalid : u8 { Invalid, Valid }; @@ -42,4 +42,4 @@ public: void Transform(const zeus::CTransform&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/CollisionUtil.cpp b/Runtime/Collision/CollisionUtil.cpp index f81259b98..89736c31e 100644 --- a/Runtime/Collision/CollisionUtil.cpp +++ b/Runtime/Collision/CollisionUtil.cpp @@ -9,7 +9,7 @@ #include -namespace urde::CollisionUtil { +namespace metaforce::CollisionUtil { bool LineIntersectsOBBox(const zeus::COBBox& obb, const zeus::CMRay& ray, float& d) { zeus::CVector3f norm; return RayAABoxIntersection(ray.getInvUnscaledTransformRay(obb.transform), {-obb.extents, obb.extents}, norm, d); @@ -1185,4 +1185,4 @@ void AddAverageToFront(const CCollisionInfoList& in, CCollisionInfoList& out) { out.Add(info, false); } } -} // namespace urde::CollisionUtil +} // namespace metaforce::CollisionUtil diff --git a/Runtime/Collision/CollisionUtil.hpp b/Runtime/Collision/CollisionUtil.hpp index a0c4f179a..79a6e53f8 100644 --- a/Runtime/Collision/CollisionUtil.hpp +++ b/Runtime/Collision/CollisionUtil.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollisionInfoList; namespace CollisionUtil { bool LineIntersectsOBBox(const zeus::COBBox&, const zeus::CMRay&, float&); @@ -47,4 +47,4 @@ bool AABox_AABox_Moving(const zeus::CAABox& aabb0, const zeus::CAABox& aabb1, co zeus::CVector3f& point, zeus::CVector3f& normal); void AddAverageToFront(const CCollisionInfoList& in, CCollisionInfoList& out); } // namespace CollisionUtil -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/ICollisionFilter.hpp b/Runtime/Collision/ICollisionFilter.hpp index e0a7a0d53..afd6dff35 100644 --- a/Runtime/Collision/ICollisionFilter.hpp +++ b/Runtime/Collision/ICollisionFilter.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde { +namespace metaforce { class CActor; class CCollisionInfoList; @@ -15,4 +15,4 @@ public: virtual void Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Collision/InternalColliders.cpp b/Runtime/Collision/InternalColliders.cpp index f1abdeb6b..1bf8b3f01 100644 --- a/Runtime/Collision/InternalColliders.cpp +++ b/Runtime/Collision/InternalColliders.cpp @@ -4,7 +4,7 @@ #include "Runtime/Collision/CCollidableCollisionSurface.hpp" #include "Runtime/Collision/CCollidableSphere.hpp" -namespace urde::InternalColliders { +namespace metaforce::InternalColliders { void AddTypes() { CCollisionPrimitive::InitAddType(CCollidableAABox::GetType()); CCollisionPrimitive::InitAddType(CCollidableCollisionSurface::GetType()); @@ -27,4 +27,4 @@ void AddColliders() { CCollisionPrimitive::InitAddMovingCollider(CCollidableSphere::CollideMovingSphere, "CCollidableSphere", "CCollidableSphere"); } -} // namespace urde::InternalColliders +} // namespace metaforce::InternalColliders diff --git a/Runtime/Collision/InternalColliders.hpp b/Runtime/Collision/InternalColliders.hpp index 305a13645..fa43c8070 100644 --- a/Runtime/Collision/InternalColliders.hpp +++ b/Runtime/Collision/InternalColliders.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde::InternalColliders { +namespace metaforce::InternalColliders { void AddTypes(); void AddColliders(); -} // namespace urde::InternalColliders +} // namespace metaforce::InternalColliders diff --git a/Runtime/GameGlobalObjects.cpp b/Runtime/GameGlobalObjects.cpp index e1940f8c3..e0d532eb5 100644 --- a/Runtime/GameGlobalObjects.cpp +++ b/Runtime/GameGlobalObjects.cpp @@ -1,6 +1,6 @@ #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { namespace MP1 { class CGameArchitectureSupport* g_archSupport = nullptr; } @@ -35,4 +35,4 @@ ITweakParticle* g_tweakParticle = nullptr; ITweakBall* g_tweakBall = nullptr; ITweakGuiColors* g_tweakGuiColors = nullptr; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GameGlobalObjects.hpp b/Runtime/GameGlobalObjects.hpp index 5ddcf4c4b..7902647aa 100644 --- a/Runtime/GameGlobalObjects.hpp +++ b/Runtime/GameGlobalObjects.hpp @@ -36,7 +36,7 @@ #include "Runtime/CTextureCache.hpp" -namespace urde { +namespace metaforce { extern class IMain* g_Main; namespace MP1 { extern class CGameArchitectureSupport* g_archSupport; @@ -98,4 +98,4 @@ extern ITweakParticle* g_tweakParticle; extern ITweakBall* g_tweakBall; extern ITweakGuiColors* g_tweakGuiColors; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GameObjectLists.cpp b/Runtime/GameObjectLists.cpp index 024cbc7ed..80b56f0e5 100644 --- a/Runtime/GameObjectLists.cpp +++ b/Runtime/GameObjectLists.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CActorList::CActorList() : CObjectList(EGameObjectList::Actor) {} @@ -51,4 +51,4 @@ CGameLightList::CGameLightList() : CObjectList(EGameObjectList::GameLight) {} bool CGameLightList::IsQualified(const CEntity& lt) const { return TCastToConstPtr(lt).IsValid(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GameObjectLists.hpp b/Runtime/GameObjectLists.hpp index 2c23e5f4f..5bf8e54be 100644 --- a/Runtime/GameObjectLists.hpp +++ b/Runtime/GameObjectLists.hpp @@ -2,7 +2,7 @@ #include "Runtime/CObjectList.hpp" -namespace urde { +namespace metaforce { class CActorList : public CObjectList { public: @@ -51,4 +51,4 @@ public: bool IsQualified(const CEntity&) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index 7954bc3c8..86b74a1c5 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -26,7 +26,7 @@ #define FOGVOL_NEAR 0.2 #define SPHERE_RAMP_RES 32 -namespace urde { +namespace metaforce { namespace { struct FogVolumeControl { std::array, 12> xfc_{ @@ -222,6 +222,7 @@ CBooRenderer::CAreaListItem::CAreaListItem(const std::vector thisLights; thisLights.reserve(lightCount); @@ -761,6 +762,7 @@ void CBooRenderer::DisablePVS() { xc8_pvs = std::nullopt; } void CBooRenderer::UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode, bool activateLights, int cubeFace, const CModelFlags* ballShadowFlags) { + OPTICK_EVENT(); SetupRendererStates(); CModelFlags flags; @@ -772,14 +774,17 @@ void CBooRenderer::UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode, if (shadowMode == EWorldShadowMode::BallOnWorldShadow || shadowMode == EWorldShadowMode::BallOnWorldIds) continue; - for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) { - CBooModel* model = *it; - if (model->TryLockTextures()) { - if (activateLights) - ActivateLightsForModel(&item, *model); - model->UpdateUniformData(flags, nullptr, nullptr, bufIdx); + CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { + for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) { + CBooModel* model = *it; + if (model->TryLockTextures()) { + if (activateLights) + ActivateLightsForModel(&item, *model); + model->UpdateUniformData(flags, nullptr, nullptr, bufIdx, &ctx); + } } - } + return true; + } BooTrace); } } @@ -1040,6 +1045,7 @@ void CBooRenderer::SetViewport(int left, int bottom, int width, int height) { void CBooRenderer::SetDebugOption(EDebugOption, int) {} void CBooRenderer::BeginScene() { + OPTICK_EVENT(); CGraphics::SetViewport(0, 0, g_Viewport.x8_width, g_Viewport.xc_height); CGraphics::SetCullMode(ERglCullMode::Back); CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, true); @@ -1067,6 +1073,7 @@ void CBooRenderer::BeginScene() { } void CBooRenderer::EndScene() { + OPTICK_EVENT(); CGraphics::EndScene(); if (x2dc_reflectionAge >= 2) { // Delete reflection tex x14c_ @@ -1161,6 +1168,7 @@ void CBooRenderer::SetThermal(bool thermal, float level, const zeus::CColor& col x2f4_thermColor = color; CDecal::SetMoveRedToAlphaBuffer(false); CElementGen::SetMoveRedToAlphaBuffer(false); + m_thermalHotPass = false; } void CBooRenderer::SetThermalColdScale(float scale) { x2f8_thermColdScale = zeus::clamp(0.f, scale, 1.f); } @@ -1418,4 +1426,4 @@ void CBooRenderer::BindMainDrawTarget() { g_Viewport = CachedVP; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index 485800eb1..4bab1ddcf 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -30,7 +30,7 @@ #include #include -namespace urde { +namespace metaforce { class CBooModel; class CMemorySys; class CParticleGen; @@ -323,4 +323,4 @@ public: bool IsInAreaDraw() const { return x318_30_inAreaDraw; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CDrawable.hpp b/Runtime/Graphics/CDrawable.hpp index 5329fb267..5a84a1dd5 100644 --- a/Runtime/Graphics/CDrawable.hpp +++ b/Runtime/Graphics/CDrawable.hpp @@ -3,7 +3,7 @@ #include "Runtime/GCNTypes.hpp" #include -namespace urde { +namespace metaforce { enum class EDrawableType : u16 { WorldSurface, Particle, Actor, SimpleShadow, Decal }; class CDrawable { @@ -24,4 +24,4 @@ public: const void* GetData() const { return x4_data; } u16 GetExtraSort() const { return x2_extraSort; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CDrawablePlaneObject.hpp b/Runtime/Graphics/CDrawablePlaneObject.hpp index 0ade8d42a..48bab8e6e 100644 --- a/Runtime/Graphics/CDrawablePlaneObject.hpp +++ b/Runtime/Graphics/CDrawablePlaneObject.hpp @@ -3,7 +3,7 @@ #include "Runtime/Graphics/CDrawable.hpp" #include -namespace urde { +namespace metaforce { class CDrawablePlaneObject : public CDrawable { friend class Buckets; u16 x24_targetBucket = 0; @@ -22,4 +22,4 @@ public: , x3c_25_zOnly{zOnly} {} const zeus::CPlane& GetPlane() const { return x2c_plane; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index 452b2d511..cb154ed0d 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { /// GX global state ERglEnum gx_DepthTest; @@ -53,6 +53,9 @@ SViewport g_Viewport = { 0, 0, 640, 480, 640 / 2.f, 480 / 2.f, 0.0f, }; u32 CGraphics::g_FrameCounter = 0; +u32 CGraphics::g_Framerate = 0; +u32 CGraphics::g_FramesPast = 0; +frame_clock::time_point CGraphics::g_FrameStartTime = frame_clock::now(); const std::array CGraphics::skCubeBasisMats{{ /* Right */ @@ -159,6 +162,8 @@ void CGraphics::EndScene() { g_LastFrameUsedAbove = g_InterruptLastFrameUsedAbove; ++g_FrameCounter; + + UpdateFPSCounter(); } void CGraphics::SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1) {} @@ -411,10 +416,23 @@ float CGraphics::GetSecondsMod900() { } void CGraphics::TickRenderTimings() { + OPTICK_EVENT(); g_RenderTimings = (g_RenderTimings + 1) % u32(900 * 60); g_DefaultSeconds = g_RenderTimings / 60.f; } +static constexpr u64 FPS_REFRESH_RATE = 1000; +void CGraphics::UpdateFPSCounter() { + ++g_FramesPast; + + std::chrono::duration timeElapsed = frame_clock::now() - g_FrameStartTime; + if (timeElapsed.count() > FPS_REFRESH_RATE) { + g_Framerate = g_FramesPast; + g_FrameStartTime = frame_clock::now(); + g_FramesPast = 0; + } +} + boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null; boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr; boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr; @@ -464,4 +482,4 @@ const CTevCombiners::CTevPass CGraphics::sTevPass805a6038( const CTevCombiners::CTevPass CGraphics::sTevPass805a6084( {GX::TevColorArg::CC_ZERO, GX::TevColorArg::CC_CPREV, GX::TevColorArg::CC_APREV, GX::TevColorArg::CC_ZERO}, {GX::TevAlphaArg::CA_ZERO, GX::TevAlphaArg::CA_ZERO, GX::TevAlphaArg::CA_ZERO, GX::TevAlphaArg::CA_APREV}); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index c5ecba40f..5e46996c5 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -2,6 +2,8 @@ #include #include +#include +#include "optick.h" #include "Runtime/RetroTypes.hpp" @@ -17,7 +19,9 @@ #include #include -namespace urde { +using frame_clock = std::chrono::high_resolution_clock; + +namespace metaforce { extern hecl::CVar* g_disableLighting; class CLight; class CTimeProvider; @@ -336,7 +340,12 @@ public: static float GetSecondsMod900(); static void TickRenderTimings(); static u32 g_FrameCounter; + static u32 g_Framerate; + static u32 g_FramesPast; + static frame_clock::time_point g_FrameStartTime; static u32 GetFrameCounter() { return g_FrameCounter; } + static u32 GetFPS() { return g_Framerate; } + static void UpdateFPSCounter(); static hsh::owner g_SpareTexture; @@ -678,7 +687,7 @@ public: }; #define SCOPED_GRAPHICS_DEBUG_GROUP(...) GraphicsDebugGroup _GfxDbg_(__VA_ARGS__); #else -#define SCOPED_GRAPHICS_DEBUG_GROUP(...) +#define SCOPED_GRAPHICS_DEBUG_GROUP(name, ...) OPTICK_EVENT_DYNAMIC(name) #endif -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CGraphicsPalette.hpp b/Runtime/Graphics/CGraphicsPalette.hpp index 6c7b7e25b..3c83d78b7 100644 --- a/Runtime/Graphics/CGraphicsPalette.hpp +++ b/Runtime/Graphics/CGraphicsPalette.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { enum class EPaletteFormat { IA8 = 0x0, @@ -32,4 +32,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CLight.cpp b/Runtime/Graphics/CLight.cpp index ff40f8bb8..e56b05498 100644 --- a/Runtime/Graphics/CLight.cpp +++ b/Runtime/Graphics/CLight.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { constexpr zeus::CVector3f kDefaultPosition(0.f, 0.f, 0.f); constexpr zeus::CVector3f kDefaultDirection(0.f, -1.f, 0.f); @@ -113,4 +113,4 @@ CLight CLight::BuildLocalAmbient(const zeus::CVector3f& pos, const zeus::CColor& return CLight(ELightType::LocalAmbient, pos, kDefaultDirection, color, 180.f); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CLight.hpp b/Runtime/Graphics/CLight.hpp index b2b699efe..4321de1b4 100644 --- a/Runtime/Graphics/CLight.hpp +++ b/Runtime/Graphics/CLight.hpp @@ -5,7 +5,7 @@ #include #include -namespace urde { +namespace metaforce { enum class ELightType { Spot = 0, @@ -103,4 +103,4 @@ public: static CLight BuildLocalAmbient(const zeus::CVector3f& pos, const zeus::CColor& color); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CLineRenderer.cpp b/Runtime/Graphics/CLineRenderer.cpp index 08ab726a5..2b1d11240 100644 --- a/Runtime/Graphics/CLineRenderer.cpp +++ b/Runtime/Graphics/CLineRenderer.cpp @@ -4,12 +4,13 @@ #include -namespace urde { -logvisor::Module LineRendererLog("urde::CLineRenderer"); +namespace metaforce { +logvisor::Module LineRendererLog("metaforce::CLineRenderer"); CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts, hsh::texture2d texture, bool additive, hsh::Compare zComp) : m_mode(mode), m_maxVerts(maxVerts) { + OPTICK_EVENT(); if (maxVerts < 2) { LineRendererLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("maxVerts < 2, maxVerts = {}")), maxVerts); return; @@ -342,4 +343,4 @@ void CLineRenderer::Render(bool alphaWrite, const zeus::CColor& moduColor) { #endif } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CLineRenderer.hpp b/Runtime/Graphics/CLineRenderer.hpp index c7aea2287..546ecb995 100644 --- a/Runtime/Graphics/CLineRenderer.hpp +++ b/Runtime/Graphics/CLineRenderer.hpp @@ -11,7 +11,7 @@ #include "zeus/CVector3f.hpp" #include "zeus/CVector4f.hpp" -namespace urde { +namespace metaforce { class CLineRenderer { public: @@ -74,4 +74,4 @@ public: void Render(bool alphaWrite = false, const zeus::CColor& moduColor = zeus::skWhite); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CMetroidModelInstance.hpp b/Runtime/Graphics/CMetroidModelInstance.hpp index 02d9bb38a..59709576e 100644 --- a/Runtime/Graphics/CMetroidModelInstance.hpp +++ b/Runtime/Graphics/CMetroidModelInstance.hpp @@ -13,7 +13,7 @@ #include #include -namespace urde { +namespace metaforce { class CBooModel; struct CBooSurface; @@ -44,4 +44,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index 84553b1f6..8617b76ad 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -17,7 +17,7 @@ #include "zeus/CAABox.hpp" #include "zeus/CColor.hpp" -namespace urde { +namespace metaforce { class CLight; class CModel; class CPoseAsTransforms; @@ -40,7 +40,7 @@ struct CModelFlags { : x0_blendMode(blendMode), x1_matSetIdx(shadIdx), x2_flags(flags), x4_color(col) {} /* Flags - 0x1: depth equal + 0x1: depth lequal 0x2: depth update 0x4: render without texture lock 0x8: depth greater @@ -55,7 +55,7 @@ struct CModelFlags { bool operator!=(const CModelFlags& other) const { return !operator==(other); } }; -/* urde addition: doesn't require hacky stashing of +/* metaforce addition: doesn't require hacky stashing of * pointers within loaded CMDL buffer */ struct CBooSurface { DataSpec::DNACMDL::SurfaceHeader_2 m_data; @@ -146,7 +146,7 @@ private: CModelShaders::FragmentUniform m_lightingData{}; bool m_lightsActive = false; - /* urde addition: boo! */ + /* metaforce addition: boo! */ size_t m_uniformDataSize = 0; std::vector m_instances; ModelInstance m_ballShadowInstance; @@ -158,7 +158,7 @@ private: hsh::texture2d m_lastDrawnOneTexture; hsh::texturecube m_lastDrawnReflectionCube; - ModelInstance* PushNewModelInstance(int sharedLayoutBuf = -1); + ModelInstance* PushNewModelInstance(int sharedLayoutBuf = -1, boo::IGraphicsDataFactory::Context* ctx = nullptr); void DrawAlphaSurfaces(const CModelFlags& flags) const; void DrawNormalSurfaces(const CModelFlags& flags) const; void DrawSurfaces(const CModelFlags& flags) const; @@ -196,7 +196,8 @@ public: void VerifyCurrentShader(int shaderIdx); hsh::dynamic_owner* UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose, - int sharedLayoutBuf = -1); + int sharedLayoutBuf = -1, + boo::IGraphicsDataFactory::Context* ctx = nullptr); void DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); void DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); void Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); @@ -255,7 +256,7 @@ class CModel { // CModel* x34_prev = nullptr; int x38_lastFrame; - /* urde addition: boo2! */ + /* metaforce addition: boo2! */ hsh::owner m_staticVbo; hecl::HMDLMeta m_hmdlMeta; std::unique_ptr m_dynamicVertexData; @@ -291,8 +292,8 @@ public: const hecl::HMDLMeta& GetHMDLMeta() const { return m_hmdlMeta; } }; -CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef); +CFactoryFnReturn FModelFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef); template constexpr auto MapVertData(const hecl::HMDLMeta& meta, F&& Func) { @@ -332,4 +333,4 @@ constexpr auto MapVertData(const hecl::HMDLMeta& meta, F&& Func) { // fallback return Func.template operator()>(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 427bb5ca1..232be78aa 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -16,9 +16,9 @@ #include #include -namespace urde { +namespace metaforce { namespace { -logvisor::Module Log("urde::CBooModel"); +logvisor::Module Log("metaforce::CBooModel"); CBooModel* g_FirstModel = nullptr; constexpr zeus::CMatrix4f ReflectBaseMtx{ @@ -46,6 +46,7 @@ void CBooModel::Shutdown() { } void CBooModel::ClearModelUniformCounters() { + OPTICK_EVENT(); for (CBooModel* model = g_FirstModel; model; model = model->m_next) model->ClearUniformCounter(); } @@ -215,7 +216,8 @@ GeometryUniformLayout::GeometryUniformLayout(const CModel* model, const Material } } -ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) { +ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf, boo::IGraphicsDataFactory::Context* ctx) { + OPTICK_EVENT(); if (!x40_24_texturesLoaded && !g_DummyTextures) { return nullptr; } @@ -733,7 +735,7 @@ hsh::dynamic_owner* CBooModel::UpdateUniformData(co if (sharedLayoutBuf >= 0) { if (m_instances.size() <= sharedLayoutBuf) { do { - inst = PushNewModelInstance(m_instances.size()); + inst = PushNewModelInstance(m_instances.size(), ctx); if (inst == nullptr) { return nullptr; } @@ -744,7 +746,7 @@ hsh::dynamic_owner* CBooModel::UpdateUniformData(co m_uniUpdateCount = sharedLayoutBuf + 1; } else { if (m_instances.size() <= m_uniUpdateCount) { - inst = PushNewModelInstance(sharedLayoutBuf); + inst = PushNewModelInstance(sharedLayoutBuf, ctx); if (inst == nullptr) { return nullptr; } @@ -1057,11 +1059,11 @@ void CModel::WarmupShaders(const SObjectTag& cmdlTag) { modelObj->_WarmupShaders(); } -CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef) { +CFactoryFnReturn FModelFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef) { CSimplePool* sp = vparms.GetOwnedObj(); CFactoryFnReturn ret = TToken::GetIObjObjectFor(std::make_unique(std::move(in), len, sp, selfRef)); return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CMoviePlayer.cpp b/Runtime/Graphics/CMoviePlayer.cpp index 5482316ab..f6e898721 100644 --- a/Runtime/Graphics/CMoviePlayer.cpp +++ b/Runtime/Graphics/CMoviePlayer.cpp @@ -9,7 +9,7 @@ #include "CMoviePlayer.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CMoviePlayerPipeline : pipeline, BlendAttachment, depth_write> { @@ -217,7 +217,7 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo for (int i = 0; i < 3; ++i) { CTHPTextureSet& set = x80_textures.emplace_back(); if (deinterlace) { - /* urde addition: this way interlaced THPs don't look horrible */ + /* metaforce addition: this way interlaced THPs don't look horrible */ set.Y[0] = hsh::create_dynamic_texture2d({x6c_videoInfo.width, x6c_videoInfo.height / 2}, hsh::R8_UNORM, 1); set.Y[1] = hsh::create_dynamic_texture2d({x6c_videoInfo.width, x6c_videoInfo.height / 2}, hsh::R8_UNORM, 1); set.U = hsh::create_dynamic_texture2d({x6c_videoInfo.width / 2, x6c_videoInfo.height / 2}, hsh::R8_UNORM, 1); @@ -314,7 +314,7 @@ void CMoviePlayer::MixAudio(s16* out, const s16* in, u32 samples) { tex->playedSamples += thisSamples; samples -= thisSamples; } else { - /* urde addition: failsafe for buffer overrun */ + /* metaforce addition: failsafe for buffer overrun */ if (in) std::memcpy(out, in, samples * 4); else @@ -333,7 +333,7 @@ void CMoviePlayer::MixStaticAudio(s16* out, const s16* in, u32 samples) { const u8* thisOffsetLeft = &StaticAudio[StaticAudioOffset / 2]; const u8* thisOffsetRight = &StaticAudio[StaticAudioSize / 2 + StaticAudioOffset / 2]; - /* urde addition: mix samples with `in` or no mix */ + /* metaforce addition: mix samples with `in` or no mix */ if (in) { for (u32 i = 0; i < thisSamples; i += 2) { out[0] = DSPSampClamp( @@ -415,7 +415,7 @@ void CMoviePlayer::DrawFrame() { tex.binding[m_deinterlace ? (xfc_fieldIndex != 0) : 0].draw(0, 4); /* ensure second field is being displayed by VI to signal advance - * (faked in urde with continuous xor) */ + * (faked in metaforce with continuous xor) */ if (!xfc_fieldIndex && CGraphics::g_LastFrameUsedAbove) xf4_26_fieldFlip = true; @@ -611,4 +611,4 @@ void CMoviePlayer::PostDVDReadRequestIfNeeded() { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CMoviePlayer.hpp b/Runtime/Graphics/CMoviePlayer.hpp index 15a4e84ab..62f72dec9 100644 --- a/Runtime/Graphics/CMoviePlayer.hpp +++ b/Runtime/Graphics/CMoviePlayer.hpp @@ -8,7 +8,7 @@ #include "Graphics/CGraphics.hpp" -namespace urde { +namespace metaforce { class CMoviePlayer : public CDvdFile { public: @@ -147,4 +147,4 @@ public: static void Shutdown(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CPVSAreaSet.cpp b/Runtime/Graphics/CPVSAreaSet.cpp index 1caa15add..450b661d9 100644 --- a/Runtime/Graphics/CPVSAreaSet.cpp +++ b/Runtime/Graphics/CPVSAreaSet.cpp @@ -1,6 +1,6 @@ #include "Runtime/Graphics/CPVSAreaSet.hpp" -namespace urde { +namespace metaforce { CPVSAreaSet::CPVSAreaSet(const u8* data, u32 len) { CMemoryInStream r(data, len); @@ -18,4 +18,4 @@ CPVSAreaSet::CPVSAreaSet(const u8* data, u32 len) { x20_octree = CPVSVisOctree::MakePVSVisOctree(octreeData); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CPVSAreaSet.hpp b/Runtime/Graphics/CPVSAreaSet.hpp index dfee06e3b..9778b9ea9 100644 --- a/Runtime/Graphics/CPVSAreaSet.hpp +++ b/Runtime/Graphics/CPVSAreaSet.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/CPVSVisOctree.hpp" -namespace urde { +namespace metaforce { class CPVSAreaSet { u32 x0_numFeatures; @@ -37,4 +37,4 @@ public: CPVSVisSet Get2ndLightSet(size_t lightIdx) const { return _GetLightSet(lightIdx); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CPVSVisOctree.cpp b/Runtime/Graphics/CPVSVisOctree.cpp index ed278b2d4..37391418d 100644 --- a/Runtime/Graphics/CPVSVisOctree.cpp +++ b/Runtime/Graphics/CPVSVisOctree.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { CPVSVisOctree CPVSVisOctree::MakePVSVisOctree(const u8* data) { CMemoryInStream r(data, 68); @@ -90,4 +90,4 @@ s32 CPVSVisOctree::IterateSearch(u8 nodeData, const zeus::CVector3f& tp) const { highFlags[2] * axisCounts[0] * axisCounts[1] * bool(nodeData & 0x4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CPVSVisOctree.hpp b/Runtime/Graphics/CPVSVisOctree.hpp index 9116546ac..ad49ff0e2 100644 --- a/Runtime/Graphics/CPVSVisOctree.hpp +++ b/Runtime/Graphics/CPVSVisOctree.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { class CPVSVisOctree { zeus::CAABox x0_aabb; @@ -31,4 +31,4 @@ public: s32 IterateSearch(u8 nodeData, const zeus::CVector3f& tp) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CPVSVisSet.cpp b/Runtime/Graphics/CPVSVisSet.cpp index 7ed070c17..f8180a56d 100644 --- a/Runtime/Graphics/CPVSVisSet.cpp +++ b/Runtime/Graphics/CPVSVisSet.cpp @@ -2,7 +2,7 @@ #include "Runtime/Graphics/CPVSVisOctree.hpp" -namespace urde { +namespace metaforce { void CPVSVisSet::Reset(EPVSVisSetState state) { x0_state = state; @@ -88,4 +88,4 @@ void CPVSVisSet::SetTestPoint(const CPVSVisOctree& octree, const zeus::CVector3f } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CPVSVisSet.hpp b/Runtime/Graphics/CPVSVisSet.hpp index 51967d7b9..ab5fbf19b 100644 --- a/Runtime/Graphics/CPVSVisSet.hpp +++ b/Runtime/Graphics/CPVSVisSet.hpp @@ -3,7 +3,7 @@ #include "Runtime/RetroTypes.hpp" #include -namespace urde { +namespace metaforce { class CPVSVisOctree; enum class EPVSVisSetState { EndOfTree, NodeFound, OutOfBounds }; @@ -23,4 +23,4 @@ public: void SetTestPoint(const CPVSVisOctree& octree, const zeus::CVector3f&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CRainSplashGenerator.cpp b/Runtime/Graphics/CRainSplashGenerator.cpp index 27b1d20fe..175f922a2 100644 --- a/Runtime/Graphics/CRainSplashGenerator.cpp +++ b/Runtime/Graphics/CRainSplashGenerator.cpp @@ -5,7 +5,7 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { +namespace metaforce { CRainSplashGenerator::CRainSplashGenerator(const zeus::CVector3f& scale, u32 maxSplashes, u32 genRate, float minZ, float alpha) @@ -188,4 +188,4 @@ void CRainSplashGenerator::GeneratePoints(const std::vector -namespace urde { +namespace metaforce { class CStateManager; class CRainSplashGenerator { @@ -73,4 +73,4 @@ public: bool IsRaining() const { return x48_25_raining; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CSimpleShadow.cpp b/Runtime/Graphics/CSimpleShadow.cpp index 91cc6cbc7..ee5c22e41 100644 --- a/Runtime/Graphics/CSimpleShadow.cpp +++ b/Runtime/Graphics/CSimpleShadow.cpp @@ -3,7 +3,7 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/Collision/CGameCollision.hpp" -namespace urde { +namespace metaforce { CSimpleShadow::CSimpleShadow(float scale, float userAlpha, float maxObjHeight, float displacement) : x30_scale(scale), x38_userAlpha(userAlpha), x40_maxObjHeight(maxObjHeight), x44_displacement(displacement) {} @@ -81,4 +81,4 @@ void CSimpleShadow::Calculate(const zeus::CAABox& aabb, const zeus::CTransform& } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CSimpleShadow.hpp b/Runtime/Graphics/CSimpleShadow.hpp index ec36cae07..acf8827e5 100644 --- a/Runtime/Graphics/CSimpleShadow.hpp +++ b/Runtime/Graphics/CSimpleShadow.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CTexture; class CStateManager; @@ -36,4 +36,4 @@ public: void Render(const TLockedToken& tex); void Calculate(const zeus::CAABox& aabb, const zeus::CTransform& xf, const CStateManager& mgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CSkinnedModel.cpp b/Runtime/Graphics/CSkinnedModel.cpp index 562db8d89..df4d6f663 100644 --- a/Runtime/Graphics/CSkinnedModel.cpp +++ b/Runtime/Graphics/CSkinnedModel.cpp @@ -5,8 +5,8 @@ #include -namespace urde { -static logvisor::Module Log("urde::CSkinnedModel"); +namespace metaforce { +static logvisor::Module Log("metaforce::CSkinnedModel"); CSkinnedModel::CSkinnedModel(TLockedToken model, TLockedToken skinRules, TLockedToken layoutInfo, int shaderIdx, int drawInsts) @@ -53,6 +53,7 @@ void CSkinnedModel::Calculate(const CPoseAsTransforms& pose, const CModelFlags& } void CSkinnedModel::Draw(const CModelFlags& drawFlags) const { + OPTICK_EVENT(); if (m_modelInst->TryLockTextures()) m_modelInst->DrawSurfaces(drawFlags); } @@ -64,4 +65,4 @@ CMorphableSkinnedModel::CMorphableSkinnedModel(IObjectStore& store, CAssetId mod CSkinnedModel::FPointGenerator CSkinnedModel::g_PointGenFunc = nullptr; void* CSkinnedModel::g_PointGenCtx = nullptr; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CSkinnedModel.hpp b/Runtime/Graphics/CSkinnedModel.hpp index 82dbdf89b..e977c1078 100644 --- a/Runtime/Graphics/CSkinnedModel.hpp +++ b/Runtime/Graphics/CSkinnedModel.hpp @@ -11,7 +11,7 @@ #include -namespace urde { +namespace metaforce { class CCharLayoutInfo; class CModel; class CPoseAsTransforms; @@ -66,4 +66,4 @@ public: const float* GetMorphMagnitudes() const { return x40_morphMagnitudes.get(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CTexture.hpp b/Runtime/Graphics/CTexture.hpp index fda1d5e3b..27bdcfab3 100644 --- a/Runtime/Graphics/CTexture.hpp +++ b/Runtime/Graphics/CTexture.hpp @@ -9,7 +9,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/Graphics/CGraphics.hpp" -namespace urde { +namespace metaforce { class CVParamTransfer; class CTextureInfo; @@ -81,7 +81,7 @@ public: const CTextureInfo* GetTextureInfo() const { return m_textureInfo; } }; -CFactoryFnReturn FTextureFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef); +CFactoryFnReturn FTextureFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CTextureBoo.cpp b/Runtime/Graphics/CTextureBoo.cpp index 2bbd50f83..d3e565ffa 100644 --- a/Runtime/Graphics/CTextureBoo.cpp +++ b/Runtime/Graphics/CTextureBoo.cpp @@ -8,9 +8,9 @@ #include "Runtime/CTextureCache.hpp" #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { namespace { -logvisor::Module Log("urde::CTextureBoo"); +logvisor::Module Log("metaforce::CTextureBoo"); /* GX uses this upsampling technique to extract full 8-bit range */ constexpr u8 Convert3To8(u8 v) { @@ -727,8 +727,8 @@ hsh::texture2d_array CTexture::GetFontTexture(EFontType tp) { return m_booTex.get(); } -CFactoryFnReturn FTextureFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef) { +CFactoryFnReturn FTextureFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef) { u32 u32Owned = vparms.GetOwnedObj(); const CTextureInfo* inf = nullptr; if (g_TextureCache) @@ -737,4 +737,4 @@ CFactoryFnReturn FTextureFactory(const urde::SObjectTag& tag, std::unique_ptr(std::move(in), len, u32Owned == SBIG('OTEX'), inf)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/CVertexMorphEffect.cpp b/Runtime/Graphics/CVertexMorphEffect.cpp index 3a3d0ed81..eb4678d3b 100644 --- a/Runtime/Graphics/CVertexMorphEffect.cpp +++ b/Runtime/Graphics/CVertexMorphEffect.cpp @@ -2,7 +2,7 @@ #include "Runtime/Character/CSkinRules.hpp" -namespace urde { +namespace metaforce { CVertexMorphEffect::CVertexMorphEffect(const zeus::CUnitVector3f& v1, const zeus::CVector3f& v2, float diagExtent, float f2, CRandom16& random) @@ -12,4 +12,4 @@ void CVertexMorphEffect::MorphVertices(std::vector& skinRules, const CPoseAsTransforms& pose) const {} -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/Graphics/CVertexMorphEffect.hpp b/Runtime/Graphics/CVertexMorphEffect.hpp index 7984a376d..49a7c294f 100644 --- a/Runtime/Graphics/CVertexMorphEffect.hpp +++ b/Runtime/Graphics/CVertexMorphEffect.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CRandom16; class CSkinRules; @@ -34,4 +34,4 @@ public: void Update(float) {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/IRenderer.hpp b/Runtime/Graphics/IRenderer.hpp index 2555bf064..66226eeee 100644 --- a/Runtime/Graphics/IRenderer.hpp +++ b/Runtime/Graphics/IRenderer.hpp @@ -13,7 +13,7 @@ #include #include -namespace urde { +namespace metaforce { class CAreaOctTree; class CLight; class CMetroidModelInstance; @@ -104,4 +104,4 @@ public: virtual void PrepareDynamicLights(const std::vector& lights) = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/IWeaponRenderer.cpp b/Runtime/Graphics/IWeaponRenderer.cpp index e90f25928..4f48c1312 100644 --- a/Runtime/Graphics/IWeaponRenderer.cpp +++ b/Runtime/Graphics/IWeaponRenderer.cpp @@ -2,8 +2,8 @@ #include "Runtime/Particle/CParticleGen.hpp" -namespace urde { +namespace metaforce { void CDefaultWeaponRenderer::AddParticleGen(CParticleGen& gen) { gen.Render(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/IWeaponRenderer.hpp b/Runtime/Graphics/IWeaponRenderer.hpp index 42e706dbd..63033a118 100644 --- a/Runtime/Graphics/IWeaponRenderer.hpp +++ b/Runtime/Graphics/IWeaponRenderer.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde { +namespace metaforce { class CParticleGen; class IWeaponRenderer { @@ -14,4 +14,4 @@ public: void AddParticleGen(CParticleGen&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index 2f059fc39..c2e51ba81 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -6,7 +6,7 @@ #include "Runtime/Graphics/CGraphics.hpp" #include "CAABoxShader.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CAABoxShaderPipeline : pipeline, @@ -66,4 +66,4 @@ void CAABoxShader::draw(const zeus::CColor& color) { m_dataBind.draw(0, VertexCount); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CAABoxShader.hpp b/Runtime/Graphics/Shaders/CAABoxShader.hpp index f53bee3ce..7ba34940c 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.hpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.hpp @@ -7,7 +7,7 @@ class CColor; class CAABox; } // namespace zeus -namespace urde { +namespace metaforce { class CAABoxShader { public: struct Vert { @@ -29,4 +29,4 @@ public: void draw(const zeus::CColor& color); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp index 5b261fb28..e2bcd6515 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp @@ -8,7 +8,7 @@ #include "CCameraBlurFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CCameraBlurFilterPipeline : FilterPipeline { @@ -82,4 +82,4 @@ void CCameraBlurFilter::draw(float amount, bool clearDepth) { m_dataBind.draw(0, 4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp index f5612aa21..e0926a609 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp @@ -3,7 +3,7 @@ #include "hsh/hsh.h" #include "zeus/CVector4f.hpp" -namespace urde { +namespace metaforce { class CCameraBlurFilter { friend struct CCameraBlurFilterPipeline; @@ -29,4 +29,4 @@ public: void draw(float amount, bool clearDepth = false); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp index 238edb25a..356032980 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp @@ -7,7 +7,7 @@ #include "CColoredQuadFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -89,4 +89,4 @@ void CWideScreenFilter::SetViewportToFull() { CGraphics::g_SpareTexture.attach(rect); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp index 7f8ee2167..51fa8f21a 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp @@ -8,7 +8,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CTexture; enum class EFilterShape; @@ -52,4 +52,4 @@ public: static void SetViewportToFull(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.cpp b/Runtime/Graphics/Shaders/CColoredStripShader.cpp index a6adb77b0..ac4cb31da 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.cpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.cpp @@ -8,7 +8,7 @@ #include "CColoredStripShader.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.hpp b/Runtime/Graphics/Shaders/CColoredStripShader.hpp index 964766797..708d1193f 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.hpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.hpp @@ -5,7 +5,7 @@ #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" -namespace urde { +namespace metaforce { class CColoredStripShader { public: diff --git a/Runtime/Graphics/Shaders/CDecalShaders.cpp b/Runtime/Graphics/Shaders/CDecalShaders.cpp index 1a11ec97b..6c1e05bac 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.cpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.cpp @@ -6,7 +6,7 @@ #include "CDecalShaders.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -51,4 +51,4 @@ void CDecalShaders::BuildShaderDataBinding(hsh::binding& binding, CQuadDecal& de } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CDecalShaders.hpp b/Runtime/Graphics/Shaders/CDecalShaders.hpp index 9e350d970..982506f65 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.hpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.hpp @@ -2,7 +2,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { struct CQuadDecal; class CDecalShaders { @@ -10,4 +10,4 @@ public: static void BuildShaderDataBinding(hsh::binding& binding, CQuadDecal& decal, hsh::texture2d tex); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.cpp b/Runtime/Graphics/Shaders/CElementGenShaders.cpp index bcc85cd15..49646b219 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.cpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.cpp @@ -12,7 +12,7 @@ enum class BlendMode { #include "CElementGenShaders.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -147,4 +147,4 @@ void CElementGenShaders::BuildShaderDataBinding(CElementGen& gen) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.hpp b/Runtime/Graphics/Shaders/CElementGenShaders.hpp index 830b4b524..fd971358b 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.hpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.hpp @@ -3,7 +3,7 @@ #include #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CElementGen; class CElementGenShaders { @@ -13,4 +13,4 @@ public: static void BuildShaderDataBinding(CElementGen& gen); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp index b6a465377..c13468b23 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp @@ -4,7 +4,7 @@ #include "CEnergyBarShader.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CEnergyBarShaderPipeline @@ -79,4 +79,4 @@ void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector @@ -46,4 +46,4 @@ void CEnvFxShaders::BuildShaderDataBinding(CEnvFxManager& fxMgr, CEnvFxManagerGr CEnvFxShadersPipeline(vboBuf, envFxUniBuf, fogUniBuf, texFlake, texEnv)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CEnvFxShaders.hpp b/Runtime/Graphics/Shaders/CEnvFxShaders.hpp index 58e175f60..fe08e4b35 100644 --- a/Runtime/Graphics/Shaders/CEnvFxShaders.hpp +++ b/Runtime/Graphics/Shaders/CEnvFxShaders.hpp @@ -4,7 +4,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CEnvFxManager; class CEnvFxManagerGrid; @@ -25,4 +25,4 @@ public: static void BuildShaderDataBinding(CEnvFxManager& fxMgr, CEnvFxManagerGrid& grid); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp index 29dd7b69d..2ccf4f06a 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp @@ -3,7 +3,7 @@ #include "Runtime/World/CRipple.hpp" #include "Runtime/World/CRippleManager.hpp" -namespace urde { +namespace metaforce { void CFluidPlaneShader::PrepareBinding(u32 maxVertCount) { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { @@ -166,4 +166,4 @@ void CFluidPlaneShader::loadVerts(const std::vector& verts, const std::v m_pvbo->load(pVerts.data(), pVerts.size() * sizeof(PatchVertex)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp index 4c7f82543..cf57593fc 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp @@ -13,7 +13,7 @@ #include "zeus/CVector3f.hpp" #include "zeus/CVector4f.hpp" -namespace urde { +namespace metaforce { enum class EFluidType { NormalWater, PoisonWater, Lava, PhazonFluid, Four, ThickLava }; @@ -108,4 +108,4 @@ public: void loadVerts(const std::vector& verts, const std::vector& pVerts); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp b/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp index e41449b4d..e16cc4393 100644 --- a/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp +++ b/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp @@ -9,7 +9,7 @@ #include "CFogVolumeFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -82,4 +82,4 @@ void CFogVolumeFilter::draw1WayPass(const zeus::CColor& color) { m_dataBind1Way.draw(0, 4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp b/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp index 16cdd3d69..15037e497 100644 --- a/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp +++ b/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp @@ -6,7 +6,7 @@ namespace zeus { class CColor; } // namespace zeus -namespace urde { +namespace metaforce { class CFogVolumeFilter { public: @@ -30,4 +30,4 @@ public: void draw1WayPass(const zeus::CColor& color); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp index 5c8954ff6..5a558e78b 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp @@ -4,7 +4,7 @@ #include "CFogVolumePlaneShader.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -81,4 +81,4 @@ void CFogVolumePlaneShader::draw(size_t pass) { m_dataBinds[pass].draw(0, m_verts.size()); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp index 48bfb96f3..690133067 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp @@ -9,7 +9,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CFogVolumePlaneShader { public: @@ -36,4 +36,4 @@ public: void draw(size_t pass); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp index 581551003..5edac2dd9 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp @@ -2,7 +2,7 @@ #include "Runtime/Graphics/CLineRenderer.hpp" #include "CLineRendererShaders.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -74,4 +74,4 @@ void CLineRendererShaders::BindShader(CLineRenderer& renderer, hsh::texture2d te } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp index 7f47de828..44f689f25 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp @@ -4,7 +4,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CLineRenderer; class CLineRendererShaders { @@ -13,4 +13,4 @@ public: hsh::Compare zcomp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp index c333a48a9..a3d070057 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp @@ -4,7 +4,7 @@ #include "CMapSurfaceShader.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CMapSurfaceShaderPipeline : pipeline, BlendAttachment<>, depth_compare, @@ -29,4 +29,4 @@ void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) { m_dataBind.draw_indexed(start, count); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp index f3799567e..eae552a85 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp @@ -7,7 +7,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CMapSurfaceShader { public: @@ -31,4 +31,4 @@ public: void draw(const zeus::CColor& color, u32 start, u32 count); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CModelShaders.cpp b/Runtime/Graphics/Shaders/CModelShaders.cpp index 8cc6669ef..d64166c0c 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.cpp +++ b/Runtime/Graphics/Shaders/CModelShaders.cpp @@ -10,7 +10,7 @@ #include "zeus/CAABox.hpp" -namespace urde { +namespace metaforce { using BlendMaterial = hecl::blender::Material; using MaterialBlendMode = BlendMaterial::BlendMode; @@ -73,7 +73,7 @@ using DynReflectionTexType = typename DynReflectionTex::type; #include "CModelShaders.cpp.hshhead" -namespace urde { +namespace metaforce { void CModelShaders::FragmentUniform::ActivateLights(const std::vector& lts) { ambient = zeus::skClear; @@ -1183,4 +1183,4 @@ struct CCubeMaterial { }; #endif -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CModelShaders.hpp b/Runtime/Graphics/Shaders/CModelShaders.hpp index a3358029b..d81ec602a 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.hpp +++ b/Runtime/Graphics/Shaders/CModelShaders.hpp @@ -18,7 +18,7 @@ namespace hecl::Backend { class ShaderTag; } // namespace hecl::Backend -namespace urde { +namespace metaforce { class CLight; struct CModelFlags; struct CBooSurface; @@ -27,7 +27,10 @@ class CBooModel; enum class EExtendedShader : uint8_t { Flat, Lighting, - Thermal, + ThermalModel, + ThermalModelNoZTestNoZWrite, + ThermalStatic, + ThermalStaticNoZWrite, ForcedAlpha, ForcedAdditive, SolidColor, @@ -138,4 +141,4 @@ struct ModelInstance { }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp index 01812cc4d..8807bb899 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp @@ -7,7 +7,7 @@ #include "CParticleSwooshShaders.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -67,4 +67,4 @@ void CParticleSwooshShaders::BuildShaderDataBinding(CParticleSwoosh& gen) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp index e04e6df44..11051acbd 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp @@ -4,7 +4,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CParticleSwoosh; class CParticleSwooshShaders { @@ -25,4 +25,4 @@ public: static void BuildShaderDataBinding(CParticleSwoosh& gen); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp index 61d047b08..b66b0b7c1 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp @@ -2,12 +2,13 @@ #include +#include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" #include "CPhazonSuitFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CPhazonSuitFilterPipeline : pipeline, AdditiveAttachment<>, depth_write> { @@ -161,4 +162,4 @@ void CPhazonSuitFilter::draw(const zeus::CColor& color, float indScale, float in m_dataBind.draw(0, 4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp index 93f209f5b..809b8aef1 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp @@ -6,7 +6,7 @@ namespace zeus { class CColor; } // namespace zeus -namespace urde { +namespace metaforce { class CTexture; class CPhazonSuitFilter { @@ -42,4 +42,4 @@ public: void draw(const zeus::CColor& color, float indScale, float indOffX, float indOffY); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp index e9c20e570..47ca9d631 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp @@ -5,7 +5,7 @@ #include "CRadarPaintShader.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CRadarPaintShaderPipeline : pipeline, AdditiveAttachment<>, depth_write> { @@ -39,4 +39,4 @@ void CRadarPaintShader::draw(const std::vector& instances, const CText m_dataBind.draw_instanced(0, 4, instances.size()); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp index 8df43282b..8f5863ea0 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp @@ -5,7 +5,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CTexture; class CRadarPaintShader { @@ -30,4 +30,4 @@ public: void draw(const std::vector& instances, const CTexture* tex); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp index 37cc6d434..465bd7e0b 100644 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp +++ b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp @@ -8,7 +8,7 @@ #include "CRandomStaticFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -94,4 +94,4 @@ void CRandomStaticFilter::draw(const zeus::CColor& color, float t) { m_dataBind.draw(0, 4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp index cf38b7606..258d5c2f6 100644 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp +++ b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp @@ -4,7 +4,7 @@ #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { class CTexture; enum class EFilterShape; @@ -43,4 +43,4 @@ public: : CCookieCutterDepthRandomStaticFilter(type) {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp index bdc1713f5..859c291b3 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp @@ -7,7 +7,7 @@ #include "CScanLinesFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -41,4 +41,4 @@ void CScanLinesFilter::draw(const zeus::CColor& color) { m_dataBind.draw(0, 670); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp index 885f228e3..14da4ef81 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp @@ -6,7 +6,7 @@ #include "zeus/CColor.hpp" -namespace urde { +namespace metaforce { class CTexture; enum class EFilterShape; @@ -42,4 +42,4 @@ public: explicit CScanLinesFilterOdd(EFilterType type, const TLockedToken&) : CScanLinesFilterOdd(type) {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp index e9481fb90..40711b685 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp @@ -6,7 +6,7 @@ #include "CSpaceWarpFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CSpaceWarpFilterPipeline @@ -168,4 +168,4 @@ void CSpaceWarpFilter::draw(const zeus::CVector3f& pt) { m_dataBind.draw(0, 4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp index 5d8465b56..100f1d6e4 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp @@ -8,7 +8,7 @@ #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class CSpaceWarpFilter { public: @@ -39,4 +39,4 @@ public: void draw(const zeus::CVector3f& pt); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.cpp b/Runtime/Graphics/Shaders/CTextSupportShader.cpp index bbcf562a9..1625dffe8 100644 --- a/Runtime/Graphics/Shaders/CTextSupportShader.cpp +++ b/Runtime/Graphics/Shaders/CTextSupportShader.cpp @@ -8,7 +8,7 @@ #include "CTextSupportShader.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; constexpr hsh::sampler ClampEdgeSamp(hsh::Linear, hsh::Linear, hsh::Linear, hsh::ClampToEdge, hsh::ClampToEdge, @@ -140,4 +140,4 @@ void CTextSupportShader::BuildImageShaderBinding(CTextRenderBuffer& buf, BooImag } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.hpp b/Runtime/Graphics/Shaders/CTextSupportShader.hpp index e9c3ab3b6..3abfacae2 100644 --- a/Runtime/Graphics/Shaders/CTextSupportShader.hpp +++ b/Runtime/Graphics/Shaders/CTextSupportShader.hpp @@ -10,7 +10,7 @@ #include "zeus/CVector2i.hpp" #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class CGlyph; class CFontImageDef; class CTextRenderBuffer; @@ -47,4 +47,4 @@ public: static void BuildImageShaderBinding(CTextRenderBuffer& buf, BooImage& img, CGuiWidget::EGuiModelDrawFlags flags); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index ba3b701d8..9d0cde953 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -7,7 +7,7 @@ #include "CTexturedQuadFilter.cpp.hshhead" -namespace urde { +namespace metaforce { template struct CTexturedQuadFilterPipeline : FilterPipeline { @@ -193,4 +193,4 @@ CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, TLockedToke m_tex = tex; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index fb52dea3f..fa7e7a032 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -10,7 +10,7 @@ #include "zeus/CVector2f.hpp" #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class CTexture; enum class EFilterShape; @@ -62,4 +62,4 @@ public: explicit CTexturedQuadFilterAlpha(EFilterType type, hsh::render_texture2d tex); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp index a840657ef..e00436304 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp @@ -6,7 +6,7 @@ #include "CThermalColdFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CThermalColdFilterPipeline : pipeline, @@ -69,4 +69,4 @@ void CThermalColdFilter::draw() { m_dataBind.draw(0, 4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp index 423d44293..974735377 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp @@ -7,7 +7,7 @@ #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" -namespace urde { +namespace metaforce { class CThermalColdFilter { public: @@ -42,4 +42,4 @@ public: void draw(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp index 87fffead9..ad2722372 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp @@ -6,7 +6,7 @@ #include "CThermalHotFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CThermalHotFilterPipeline @@ -53,4 +53,4 @@ void CThermalHotFilter::draw() { m_dataBind.draw(0, 4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp index 46f6e722d..59ae339ea 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp @@ -5,7 +5,7 @@ #include "hsh/hsh.h" #include "zeus/CColor.hpp" -namespace urde { +namespace metaforce { class CThermalHotFilter { public: @@ -31,4 +31,4 @@ public: void draw(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp index 04829ae2e..57f4d179d 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp @@ -7,7 +7,7 @@ #include "CWorldShadowShader.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; template @@ -79,4 +79,4 @@ void CWorldShadowShader::blendPreviousShadow() { void CWorldShadowShader::resolveTexture() { m_tex.resolve_color_binding(0, hsh::rect2d{{}, {m_w, m_h}}, false); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp index ce32c9b2c..510bc1224 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp @@ -8,7 +8,7 @@ #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" -namespace urde { +namespace metaforce { class CWorldShadowShader { public: @@ -45,4 +45,4 @@ public: hsh::render_texture2d GetTexture() const { return m_tex.get_color(0); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp index 96fceec19..724176536 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp @@ -6,7 +6,7 @@ #include "CXRayBlurFilter.cpp.hshhead" -namespace urde { +namespace metaforce { using namespace hsh::pipeline; struct CXRayBlurFilterPipeline @@ -86,4 +86,4 @@ void CXRayBlurFilter::draw(float amount) { m_dataBind.draw(0, 4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp index 47f8db92c..340d205dc 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -7,7 +7,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CTexture; class CXRayBlurFilter { @@ -32,4 +32,4 @@ public: void draw(float amount); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CAuiEnergyBarT01.cpp b/Runtime/GuiSys/CAuiEnergyBarT01.cpp index 4676352b0..16abc7f74 100644 --- a/Runtime/GuiSys/CAuiEnergyBarT01.cpp +++ b/Runtime/GuiSys/CAuiEnergyBarT01.cpp @@ -4,7 +4,7 @@ #include "Runtime/GuiSys/CGuiSys.hpp" #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" -namespace urde { +namespace metaforce { CAuiEnergyBarT01::CAuiEnergyBarT01(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId txtrId) : CGuiWidget(parms), xb8_txtrId(txtrId) { @@ -149,4 +149,4 @@ std::shared_ptr CAuiEnergyBarT01::Create(CGuiFrame* frame, CInputStr return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CAuiEnergyBarT01.hpp b/Runtime/GuiSys/CAuiEnergyBarT01.hpp index 6fca40fba..5c32ab1d7 100644 --- a/Runtime/GuiSys/CAuiEnergyBarT01.hpp +++ b/Runtime/GuiSys/CAuiEnergyBarT01.hpp @@ -12,7 +12,7 @@ #include #include -namespace urde { +namespace metaforce { class CSimplePool; class CAuiEnergyBarT01 : public CGuiWidget { @@ -66,4 +66,4 @@ public: static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CAuiImagePane.cpp b/Runtime/GuiSys/CAuiImagePane.cpp index 6691ac541..30d82ae02 100644 --- a/Runtime/GuiSys/CAuiImagePane.cpp +++ b/Runtime/GuiSys/CAuiImagePane.cpp @@ -5,7 +5,7 @@ #include "Runtime/Graphics/CTexture.hpp" #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" -namespace urde { +namespace metaforce { CAuiImagePane::CAuiImagePane(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId tex0, CAssetId tex1, rstl::reserved_vector&& coords, @@ -195,4 +195,4 @@ void CAuiImagePane::SetAnimationParms(const zeus::CVector2f& tileSize, float int x148_fadeDuration = fadeDuration; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CAuiImagePane.hpp b/Runtime/GuiSys/CAuiImagePane.hpp index bf99786ad..a27a44500 100644 --- a/Runtime/GuiSys/CAuiImagePane.hpp +++ b/Runtime/GuiSys/CAuiImagePane.hpp @@ -14,7 +14,7 @@ namespace zeus { class CColor; } -namespace urde { +namespace metaforce { class CSimplePool; class CTexture; @@ -60,4 +60,4 @@ public: void SetDeResFactor(float d) { x14c_deResFactor = d; } void SetFlashFactor(float t) { x150_flashFactor = t; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CAuiMeter.cpp b/Runtime/GuiSys/CAuiMeter.cpp index 724d65584..5addf96dd 100644 --- a/Runtime/GuiSys/CAuiMeter.cpp +++ b/Runtime/GuiSys/CAuiMeter.cpp @@ -5,7 +5,7 @@ #include -namespace urde { +namespace metaforce { CAuiMeter::CAuiMeter(const CGuiWidgetParms& parms, bool noRoundUp, u32 maxCapacity, u32 workerCount) : CGuiGroup(parms, 0, false), xc4_noRoundUp(noRoundUp), xc8_maxCapacity(maxCapacity), xcc_capacity(maxCapacity) { @@ -98,4 +98,4 @@ std::shared_ptr CAuiMeter::Create(CGuiFrame* frame, CInputStream& in return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CAuiMeter.hpp b/Runtime/GuiSys/CAuiMeter.hpp index be0b83eae..e791395bb 100644 --- a/Runtime/GuiSys/CAuiMeter.hpp +++ b/Runtime/GuiSys/CAuiMeter.hpp @@ -6,7 +6,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/GuiSys/CGuiGroup.hpp" -namespace urde { +namespace metaforce { class CSimplePool; class CAuiMeter : public CGuiGroup { @@ -31,4 +31,4 @@ public: static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CCompoundTargetReticle.cpp b/Runtime/GuiSys/CCompoundTargetReticle.cpp index 470fc308b..bd733aecf 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.cpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { namespace { constexpr char skCrosshairsReticleAssetName[] = "CMDL_Crosshairs"; [[maybe_unused]] constexpr char skOrbitZoneReticleAssetName[] = "CMDL_OrbitZone"; @@ -1069,4 +1069,4 @@ void CCompoundTargetReticle::Touch() { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CCompoundTargetReticle.hpp b/Runtime/GuiSys/CCompoundTargetReticle.hpp index dd70eb2b4..6742e7eb8 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.hpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CActor; class CModel; class CScriptGrapplePoint; @@ -158,4 +158,4 @@ public: static float CalculateClampedScale(const zeus::CVector3f&, float, float, float, const CStateManager&); void Touch(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CConsoleOutputWindow.cpp b/Runtime/GuiSys/CConsoleOutputWindow.cpp index f010c5de3..ee7cb8fbf 100644 --- a/Runtime/GuiSys/CConsoleOutputWindow.cpp +++ b/Runtime/GuiSys/CConsoleOutputWindow.cpp @@ -1,7 +1,7 @@ #include "Runtime/GuiSys/CConsoleOutputWindow.hpp" #include "Runtime/Graphics/CGraphics.hpp" -namespace urde { +namespace metaforce { CConsoleOutputWindow::CConsoleOutputWindow(int, float, float) : CIOWin("Console Output Window") {} @@ -13,4 +13,4 @@ void CConsoleOutputWindow::Draw() { //SCOPED_GRAPHICS_DEBUG_GROUP("CConsoleOutputWindow::Draw", zeus::skGreen); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CConsoleOutputWindow.hpp b/Runtime/GuiSys/CConsoleOutputWindow.hpp index 40a8bb69f..5f2927495 100644 --- a/Runtime/GuiSys/CConsoleOutputWindow.hpp +++ b/Runtime/GuiSys/CConsoleOutputWindow.hpp @@ -2,7 +2,7 @@ #include "Runtime/CIOWin.hpp" -namespace urde { +namespace metaforce { class CConsoleOutputWindow : public CIOWin { public: @@ -11,4 +11,4 @@ public: void Draw() override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CDrawStringOptions.hpp b/Runtime/GuiSys/CDrawStringOptions.hpp index 749aa2882..7dfc72758 100644 --- a/Runtime/GuiSys/CDrawStringOptions.hpp +++ b/Runtime/GuiSys/CDrawStringOptions.hpp @@ -4,7 +4,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/GuiSys/CGuiTextSupport.hpp" -namespace urde { +namespace metaforce { class CDrawStringOptions { friend class CColorOverrideInstruction; @@ -21,4 +21,4 @@ public: CDrawStringOptions() : x4_colors(16) {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CErrorOutputWindow.cpp b/Runtime/GuiSys/CErrorOutputWindow.cpp index aae8942d9..0bccee052 100644 --- a/Runtime/GuiSys/CErrorOutputWindow.cpp +++ b/Runtime/GuiSys/CErrorOutputWindow.cpp @@ -2,7 +2,7 @@ #include "Runtime/Graphics/CGraphics.hpp" -namespace urde { +namespace metaforce { CErrorOutputWindow::CErrorOutputWindow(bool flag) : CIOWin("Error Output Window") { x18_24_ = false; @@ -20,4 +20,4 @@ void CErrorOutputWindow::Draw() { //SCOPED_GRAPHICS_DEBUG_GROUP("CErrorOutputWindow::Draw", zeus::skGreen); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CErrorOutputWindow.hpp b/Runtime/GuiSys/CErrorOutputWindow.hpp index b6088a9ba..dd85bd38a 100644 --- a/Runtime/GuiSys/CErrorOutputWindow.hpp +++ b/Runtime/GuiSys/CErrorOutputWindow.hpp @@ -3,7 +3,7 @@ #include "Runtime/CIOWin.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CErrorOutputWindow : public CIOWin { public: @@ -25,4 +25,4 @@ public: void Draw() override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CFontImageDef.cpp b/Runtime/GuiSys/CFontImageDef.cpp index 7a0db90b1..56b5e4b7c 100644 --- a/Runtime/GuiSys/CFontImageDef.cpp +++ b/Runtime/GuiSys/CFontImageDef.cpp @@ -4,7 +4,7 @@ #include "Runtime/Graphics/CTexture.hpp" -namespace urde { +namespace metaforce { CFontImageDef::CFontImageDef(const std::vector>& texs, float interval, const zeus::CVector2f& cropFactor) @@ -35,4 +35,4 @@ s32 CFontImageDef::CalculateHeight() const { return scaledH - (scaledH - CalculateBaseline()); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CFontImageDef.hpp b/Runtime/GuiSys/CFontImageDef.hpp index 80355cd4f..44d477932 100644 --- a/Runtime/GuiSys/CFontImageDef.hpp +++ b/Runtime/GuiSys/CFontImageDef.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CTexture; class CFontImageDef { @@ -22,4 +22,4 @@ public: s32 CalculateHeight() const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CFontRenderState.cpp b/Runtime/GuiSys/CFontRenderState.cpp index ef91455e0..ebe70893c 100644 --- a/Runtime/GuiSys/CFontRenderState.cpp +++ b/Runtime/GuiSys/CFontRenderState.cpp @@ -2,7 +2,7 @@ #include "Runtime/GuiSys/CRasterFont.hpp" -namespace urde { +namespace metaforce { CFontRenderState::CFontRenderState() { x54_colors[0] = zeus::skWhite; @@ -81,4 +81,4 @@ void CFontRenderState::RefreshColor(EColorType tp) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CFontRenderState.hpp b/Runtime/GuiSys/CFontRenderState.hpp index ec42f469f..9a4e64044 100644 --- a/Runtime/GuiSys/CFontRenderState.hpp +++ b/Runtime/GuiSys/CFontRenderState.hpp @@ -7,7 +7,7 @@ #include "Runtime/GuiSys/CGuiTextSupport.hpp" #include "Runtime/GuiSys/CSaveableState.hpp" -namespace urde { +namespace metaforce { class CBlockInstruction; class CLineInstruction; @@ -38,4 +38,4 @@ public: void RefreshColor(EColorType tp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiCamera.cpp b/Runtime/GuiSys/CGuiCamera.cpp index 521fd7134..b5ade0c7f 100644 --- a/Runtime/GuiSys/CGuiCamera.cpp +++ b/Runtime/GuiSys/CGuiCamera.cpp @@ -4,7 +4,7 @@ #include "Runtime/GuiSys/CGuiFrame.hpp" #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" -namespace urde { +namespace metaforce { CGuiCamera::CGuiCamera(const CGuiWidgetParms& parms, float left, float right, float top, float bottom, float znear, float zfar) @@ -65,4 +65,4 @@ std::shared_ptr CGuiCamera::Create(CGuiFrame* frame, CInputStream& i return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiCamera.hpp b/Runtime/GuiSys/CGuiCamera.hpp index 824a55c7e..f44885bc4 100644 --- a/Runtime/GuiSys/CGuiCamera.hpp +++ b/Runtime/GuiSys/CGuiCamera.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/GuiSys/CGuiWidget.hpp" -namespace urde { +namespace metaforce { class CSimplePool; class CGuiCamera : public CGuiWidget { @@ -53,4 +53,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiCompoundWidget.cpp b/Runtime/GuiSys/CGuiCompoundWidget.cpp index 27aefb6a6..179bba7d5 100644 --- a/Runtime/GuiSys/CGuiCompoundWidget.cpp +++ b/Runtime/GuiSys/CGuiCompoundWidget.cpp @@ -1,6 +1,6 @@ #include "Runtime/GuiSys/CGuiCompoundWidget.hpp" -namespace urde { +namespace metaforce { CGuiCompoundWidget::CGuiCompoundWidget(const CGuiWidgetParms& parms) : CGuiWidget(parms) {} @@ -32,4 +32,4 @@ CGuiWidget* CGuiCompoundWidget::GetWorkerWidget(int id) const { return nullptr; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiCompoundWidget.hpp b/Runtime/GuiSys/CGuiCompoundWidget.hpp index 97752f7fe..878b017c4 100644 --- a/Runtime/GuiSys/CGuiCompoundWidget.hpp +++ b/Runtime/GuiSys/CGuiCompoundWidget.hpp @@ -2,7 +2,7 @@ #include "Runtime/GuiSys/CGuiWidget.hpp" -namespace urde { +namespace metaforce { class CGuiCompoundWidget : public CGuiWidget { public: @@ -14,4 +14,4 @@ public: virtual CGuiWidget* GetWorkerWidget(int id) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiFrame.cpp b/Runtime/GuiSys/CGuiFrame.cpp index 588cdfda6..d3bea309e 100644 --- a/Runtime/GuiSys/CGuiFrame.cpp +++ b/Runtime/GuiSys/CGuiFrame.cpp @@ -14,7 +14,7 @@ #include -namespace urde { +namespace metaforce { CGuiFrame::CGuiFrame(CAssetId id, CGuiSys& sys, int a, int b, int c, CSimplePool* sp) : x0_id(id), x8_guiSys(sys), x4c_a(a), x50_b(b), x54_c(c) { @@ -281,4 +281,4 @@ std::unique_ptr RGuiFrameFactoryInGame(const SObjectTag& tag, CInputStream return TToken::GetIObjObjectFor(std::move(frame)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiFrame.hpp b/Runtime/GuiSys/CGuiFrame.hpp index 574c610c0..725705f11 100644 --- a/Runtime/GuiSys/CGuiFrame.hpp +++ b/Runtime/GuiSys/CGuiFrame.hpp @@ -10,7 +10,7 @@ #include "Runtime/GuiSys/CGuiWidgetIdDB.hpp" #include "Runtime/GuiSys/CGuiWidget.hpp" -namespace urde { +namespace metaforce { class CBooModel; class CGuiCamera; class CGuiLight; @@ -112,4 +112,4 @@ public: std::unique_ptr RGuiFrameFactoryInGame(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiGroup.cpp b/Runtime/GuiSys/CGuiGroup.cpp index 9a6bda8fc..105387c3d 100644 --- a/Runtime/GuiSys/CGuiGroup.cpp +++ b/Runtime/GuiSys/CGuiGroup.cpp @@ -1,6 +1,6 @@ #include "Runtime/GuiSys/CGuiGroup.hpp" -namespace urde { +namespace metaforce { void CGuiGroup::LoadWidgetFnMap() {} @@ -50,4 +50,4 @@ std::shared_ptr CGuiGroup::Create(CGuiFrame* frame, CInputStream& in return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiGroup.hpp b/Runtime/GuiSys/CGuiGroup.hpp index 9a1bc4f43..964300b07 100644 --- a/Runtime/GuiSys/CGuiGroup.hpp +++ b/Runtime/GuiSys/CGuiGroup.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/GuiSys/CGuiCompoundWidget.hpp" -namespace urde { +namespace metaforce { class CGuiGroup : public CGuiCompoundWidget { u32 xb8_workerCount = 0; @@ -24,4 +24,4 @@ public: static void LoadWidgetFnMap(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiHeadWidget.cpp b/Runtime/GuiSys/CGuiHeadWidget.cpp index 42edb8be9..d64815e87 100644 --- a/Runtime/GuiSys/CGuiHeadWidget.cpp +++ b/Runtime/GuiSys/CGuiHeadWidget.cpp @@ -1,7 +1,7 @@ #include "Runtime/GuiSys/CGuiHeadWidget.hpp" #include "Runtime/GuiSys/CGuiFrame.hpp" -namespace urde { +namespace metaforce { CGuiHeadWidget::CGuiHeadWidget(const CGuiWidgetParms& parms) : CGuiWidget(parms) {} @@ -13,4 +13,4 @@ std::shared_ptr CGuiHeadWidget::Create(CGuiFrame* frame, CInputStrea return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiHeadWidget.hpp b/Runtime/GuiSys/CGuiHeadWidget.hpp index cd710fe2c..89536b530 100644 --- a/Runtime/GuiSys/CGuiHeadWidget.hpp +++ b/Runtime/GuiSys/CGuiHeadWidget.hpp @@ -2,7 +2,7 @@ #include "Runtime/GuiSys/CGuiWidget.hpp" -namespace urde { +namespace metaforce { class CGuiHeadWidget : public CGuiWidget { public: @@ -15,4 +15,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiLight.cpp b/Runtime/GuiSys/CGuiLight.cpp index c1299931b..c65166b55 100644 --- a/Runtime/GuiSys/CGuiLight.cpp +++ b/Runtime/GuiSys/CGuiLight.cpp @@ -1,7 +1,7 @@ #include "Runtime/GuiSys/CGuiLight.hpp" #include "Runtime/GuiSys/CGuiFrame.hpp" -namespace urde { +namespace metaforce { CGuiLight::CGuiLight(const CGuiWidgetParms& parms, const CLight& light) : CGuiWidget(parms) @@ -93,4 +93,4 @@ std::shared_ptr CGuiLight::Create(CGuiFrame* frame, CInputStream& in return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiLight.hpp b/Runtime/GuiSys/CGuiLight.hpp index 2a077df11..b93e79fdd 100644 --- a/Runtime/GuiSys/CGuiLight.hpp +++ b/Runtime/GuiSys/CGuiLight.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { class CSimplePool; class CGuiLight : public CGuiWidget { @@ -48,4 +48,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiModel.cpp b/Runtime/GuiSys/CGuiModel.cpp index d5675c183..a26a66878 100644 --- a/Runtime/GuiSys/CGuiModel.cpp +++ b/Runtime/GuiSys/CGuiModel.cpp @@ -6,7 +6,7 @@ #include "Runtime/GuiSys/CGuiSys.hpp" #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" -namespace urde { +namespace metaforce { CGuiModel::CGuiModel(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId modelId, u32 lightMask, bool flag) : CGuiWidget(parms), xc8_modelId(modelId), xcc_lightMask(lightMask) { @@ -118,4 +118,4 @@ std::shared_ptr CGuiModel::Create(CGuiFrame* frame, CInputStream& in return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiModel.hpp b/Runtime/GuiSys/CGuiModel.hpp index 024c9ba25..863c61027 100644 --- a/Runtime/GuiSys/CGuiModel.hpp +++ b/Runtime/GuiSys/CGuiModel.hpp @@ -6,7 +6,7 @@ #include "Runtime/Graphics/CModel.hpp" #include "Runtime/GuiSys/CGuiWidget.hpp" -namespace urde { +namespace metaforce { class CSimplePool; class CGuiModel : public CGuiWidget { @@ -28,4 +28,4 @@ public: static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiObject.cpp b/Runtime/GuiSys/CGuiObject.cpp index 157540949..b963011c4 100644 --- a/Runtime/GuiSys/CGuiObject.cpp +++ b/Runtime/GuiSys/CGuiObject.cpp @@ -2,7 +2,7 @@ #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" -namespace urde { +namespace metaforce { void CGuiObject::Update(float dt) { if (x68_child) @@ -117,4 +117,4 @@ void CGuiObject::SetLocalTransform(const zeus::CTransform& xf) { RecalculateTransforms(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiObject.hpp b/Runtime/GuiSys/CGuiObject.hpp index 298cd756d..ce3cffd97 100644 --- a/Runtime/GuiSys/CGuiObject.hpp +++ b/Runtime/GuiSys/CGuiObject.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { struct CGuiWidgetDrawParms; class CGuiObject : public std::enable_shared_from_this { @@ -48,4 +48,4 @@ public: void SetLocalTransform(const zeus::CTransform& xf); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiPane.cpp b/Runtime/GuiSys/CGuiPane.cpp index ed217d08d..aa13c6044 100644 --- a/Runtime/GuiSys/CGuiPane.cpp +++ b/Runtime/GuiSys/CGuiPane.cpp @@ -1,6 +1,6 @@ #include "Runtime/GuiSys/CGuiPane.hpp" -namespace urde { +namespace metaforce { CGuiPane::CGuiPane(const CGuiWidgetParms& parms, const zeus::CVector2f& dim, const zeus::CVector3f& scaleCenter) : CGuiWidget(parms), xb8_dim(dim), xc8_scaleCenter(scaleCenter) { @@ -46,4 +46,4 @@ std::shared_ptr CGuiPane::Create(CGuiFrame* frame, CInputStream& in, return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiPane.hpp b/Runtime/GuiSys/CGuiPane.hpp index dc183fcd4..d5fcb991e 100644 --- a/Runtime/GuiSys/CGuiPane.hpp +++ b/Runtime/GuiSys/CGuiPane.hpp @@ -9,7 +9,7 @@ #include "zeus/CVector2f.hpp" #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class CGuiPane : public CGuiWidget { protected: @@ -34,4 +34,4 @@ public: static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiSliderGroup.cpp b/Runtime/GuiSys/CGuiSliderGroup.cpp index 0cf7ef52a..16c0555ab 100644 --- a/Runtime/GuiSys/CGuiSliderGroup.cpp +++ b/Runtime/GuiSys/CGuiSliderGroup.cpp @@ -3,7 +3,7 @@ #include "Runtime/GuiSys/CGuiModel.hpp" #include "Runtime/Input/CFinalInput.hpp" -namespace urde { +namespace metaforce { CGuiSliderGroup::CGuiSliderGroup(const CGuiWidgetParms& parms, float min, float max, float def, float inc) : CGuiCompoundWidget(parms) @@ -168,4 +168,4 @@ std::shared_ptr CGuiSliderGroup::Create(CGuiFrame* frame, CInputStre return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiSliderGroup.hpp b/Runtime/GuiSys/CGuiSliderGroup.hpp index 22c2470ad..7d34ec24b 100644 --- a/Runtime/GuiSys/CGuiSliderGroup.hpp +++ b/Runtime/GuiSys/CGuiSliderGroup.hpp @@ -6,7 +6,7 @@ #include "Runtime/GuiSys/CGuiCompoundWidget.hpp" -namespace urde { +namespace metaforce { class CSimplePool; class CGuiSliderGroup : public CGuiCompoundWidget { @@ -60,4 +60,4 @@ public: static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiSys.cpp b/Runtime/GuiSys/CGuiSys.cpp index 1888da21b..6010d6527 100644 --- a/Runtime/GuiSys/CGuiSys.cpp +++ b/Runtime/GuiSys/CGuiSys.cpp @@ -18,7 +18,7 @@ #include "Runtime/GuiSys/CTextExecuteBuffer.hpp" #include "Runtime/GuiSys/CTextParser.hpp" -namespace urde { +namespace metaforce { CGuiSys* g_GuiSys = nullptr; CTextExecuteBuffer* g_TextExecuteBuf = nullptr; @@ -92,4 +92,4 @@ void CGuiSys::ViewportResizeFrame(CGuiFrame* frame) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiSys.hpp b/Runtime/GuiSys/CGuiSys.hpp index d82cc5aa8..5ce5036d8 100644 --- a/Runtime/GuiSys/CGuiSys.hpp +++ b/Runtime/GuiSys/CGuiSys.hpp @@ -10,7 +10,7 @@ #include -namespace urde { +namespace metaforce { class CGuiFrame; class CGuiObject; class CGuiWidget; @@ -58,4 +58,4 @@ extern CTextExecuteBuffer* g_TextExecuteBuf; /** Global CTextParser instance */ extern CTextParser* g_TextParser; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiTableGroup.cpp b/Runtime/GuiSys/CGuiTableGroup.cpp index e2d3353a2..f366edfe7 100644 --- a/Runtime/GuiSys/CGuiTableGroup.cpp +++ b/Runtime/GuiSys/CGuiTableGroup.cpp @@ -1,7 +1,7 @@ #include "Runtime/GuiSys/CGuiTableGroup.hpp" #include "Runtime/Input/CFinalInput.hpp" -namespace urde { +namespace metaforce { bool CGuiTableGroup::CRepeatState::Update(float dt, bool state) { if (x0_timer == 0.f) { @@ -228,4 +228,4 @@ std::shared_ptr CGuiTableGroup::Create(CGuiFrame* frame, CInputStrea return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiTableGroup.hpp b/Runtime/GuiSys/CGuiTableGroup.hpp index 4f4b3d0f3..8bb8a5dc2 100644 --- a/Runtime/GuiSys/CGuiTableGroup.hpp +++ b/Runtime/GuiSys/CGuiTableGroup.hpp @@ -5,7 +5,7 @@ #include "Runtime/GuiSys/CGuiCompoundWidget.hpp" -namespace urde { +namespace metaforce { class CGuiTableGroup : public CGuiCompoundWidget { public: @@ -94,4 +94,4 @@ public: static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiTextPane.cpp b/Runtime/GuiSys/CGuiTextPane.cpp index dafb36b8b..8cff5cf46 100644 --- a/Runtime/GuiSys/CGuiTextPane.cpp +++ b/Runtime/GuiSys/CGuiTextPane.cpp @@ -9,7 +9,7 @@ #include "Runtime/GuiSys/CGuiSys.hpp" #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" -namespace urde { +namespace metaforce { namespace { constexpr std::array NormalPoints{{ {0.f, 0.f, -1.f}, @@ -154,4 +154,4 @@ std::shared_ptr CGuiTextPane::Create(CGuiFrame* frame, CInputStream& return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiTextPane.hpp b/Runtime/GuiSys/CGuiTextPane.hpp index ba8281188..d304e5316 100644 --- a/Runtime/GuiSys/CGuiTextPane.hpp +++ b/Runtime/GuiSys/CGuiTextPane.hpp @@ -6,7 +6,7 @@ #include "Runtime/GuiSys/CGuiPane.hpp" #include "Runtime/GuiSys/CGuiTextSupport.hpp" -namespace urde { +namespace metaforce { class CGuiTextPane : public CGuiPane { CGuiTextSupport xd4_textSupport; @@ -30,4 +30,4 @@ public: static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiTextSupport.cpp b/Runtime/GuiSys/CGuiTextSupport.cpp index 7a93a8e9b..a34ceea0f 100644 --- a/Runtime/GuiSys/CGuiTextSupport.cpp +++ b/Runtime/GuiSys/CGuiTextSupport.cpp @@ -9,7 +9,7 @@ #include "Runtime/GuiSys/CTextExecuteBuffer.hpp" #include "Runtime/GuiSys/CTextParser.hpp" -namespace urde { +namespace metaforce { CGuiTextSupport::CGuiTextSupport(CAssetId fontId, const CGuiTextProperties& props, const zeus::CColor& fontCol, const zeus::CColor& outlineCol, const zeus::CColor& geomCol, s32 padX, s32 padY, @@ -344,4 +344,4 @@ void CGuiTextSupport::SetPage(int page) { x3c_curTime = 0.f; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiTextSupport.hpp b/Runtime/GuiSys/CGuiTextSupport.hpp index f612cac1c..8e7cc85d6 100644 --- a/Runtime/GuiSys/CGuiTextSupport.hpp +++ b/Runtime/GuiSys/CGuiTextSupport.hpp @@ -14,7 +14,7 @@ #include -namespace urde { +namespace metaforce { class CSimplePool; class CTextExecuteBuffer; class CTextRenderBuffer; @@ -138,4 +138,4 @@ public: void SetPage(int page); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiWidget.cpp b/Runtime/GuiSys/CGuiWidget.cpp index 66a14d0c8..a3ec88dc2 100644 --- a/Runtime/GuiSys/CGuiWidget.cpp +++ b/Runtime/GuiSys/CGuiWidget.cpp @@ -3,8 +3,8 @@ #include -namespace urde { -static logvisor::Module Log("urde::CGuiWidget"); +namespace metaforce { +static logvisor::Module Log("metaforce::CGuiWidget"); CGuiWidget::CGuiWidget(const CGuiWidgetParms& parms) : x70_selfId(parms.x6_selfId) @@ -257,4 +257,4 @@ void CGuiWidget::SetIsActive(bool active) { OnActiveChange(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiWidget.hpp b/Runtime/GuiSys/CGuiWidget.hpp index 0e03b677f..1f3f59127 100644 --- a/Runtime/GuiSys/CGuiWidget.hpp +++ b/Runtime/GuiSys/CGuiWidget.hpp @@ -15,7 +15,7 @@ #include "zeus/CTransform.hpp" #include "zeus/CVector3f.hpp" -namespace urde { +namespace metaforce { class CGuiFrame; class CGuiTextSupport; struct CFinalInput; @@ -145,4 +145,4 @@ public: CGuiFrame* GetGuiFrame() const { return xb0_frame; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiWidgetDrawParms.hpp b/Runtime/GuiSys/CGuiWidgetDrawParms.hpp index ef1347e30..78cb2b901 100644 --- a/Runtime/GuiSys/CGuiWidgetDrawParms.hpp +++ b/Runtime/GuiSys/CGuiWidgetDrawParms.hpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { struct CGuiWidgetDrawParms { float x0_alphaMod = 1.f; @@ -15,4 +15,4 @@ struct CGuiWidgetDrawParms { static constexpr CGuiWidgetDrawParms Default() { return {}; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiWidgetIdDB.cpp b/Runtime/GuiSys/CGuiWidgetIdDB.cpp index 4455cc85a..972d1450e 100644 --- a/Runtime/GuiSys/CGuiWidgetIdDB.cpp +++ b/Runtime/GuiSys/CGuiWidgetIdDB.cpp @@ -1,6 +1,6 @@ #include "Runtime/GuiSys/CGuiWidgetIdDB.hpp" -namespace urde { +namespace metaforce { CGuiWidgetIdDB::CGuiWidgetIdDB() { AddWidget("kGSYS_DummyWidgetID", 0); @@ -38,4 +38,4 @@ s16 CGuiWidgetIdDB::AddWidget(std::string_view name) { return findId; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CGuiWidgetIdDB.hpp b/Runtime/GuiSys/CGuiWidgetIdDB.hpp index 65197094c..d048ef30a 100644 --- a/Runtime/GuiSys/CGuiWidgetIdDB.hpp +++ b/Runtime/GuiSys/CGuiWidgetIdDB.hpp @@ -5,7 +5,7 @@ #include #include "Runtime/GCNTypes.hpp" -namespace urde { +namespace metaforce { class CGuiWidgetIdDB { std::unordered_map x0_dbMap; @@ -18,4 +18,4 @@ public: s16 AddWidget(std::string_view name); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudBallInterface.cpp b/Runtime/GuiSys/CHudBallInterface.cpp index 74677b489..fde28f18d 100644 --- a/Runtime/GuiSys/CHudBallInterface.cpp +++ b/Runtime/GuiSys/CHudBallInterface.cpp @@ -7,7 +7,7 @@ #include "Runtime/GuiSys/CGuiModel.hpp" #include "Runtime/GuiSys/CGuiTextPane.hpp" -namespace urde { +namespace metaforce { CHudBallInterface::CHudBallInterface(CGuiFrame& selHud, int pbAmount, int pbCapacity, int availableBombs, bool hasBombs, bool hasPb) @@ -97,4 +97,4 @@ void CHudBallInterface::SetBallModeFactor(float t) { zeus::CTransform::Translate(x34_camPos + zeus::CVector3f(0.f, 0.f, (t * tmp - tmp) * 0.01f))); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudBallInterface.hpp b/Runtime/GuiSys/CHudBallInterface.hpp index 818154df4..dc1c4e5ad 100644 --- a/Runtime/GuiSys/CHudBallInterface.hpp +++ b/Runtime/GuiSys/CHudBallInterface.hpp @@ -3,7 +3,7 @@ #include "Runtime/rstl.hpp" #include -namespace urde { +namespace metaforce { class CGuiCamera; class CGuiFrame; class CGuiModel; @@ -31,4 +31,4 @@ public: void SetBallModeFactor(float t); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudBossEnergyInterface.cpp b/Runtime/GuiSys/CHudBossEnergyInterface.cpp index 0a0a30bbd..1dba88b44 100644 --- a/Runtime/GuiSys/CHudBossEnergyInterface.cpp +++ b/Runtime/GuiSys/CHudBossEnergyInterface.cpp @@ -5,7 +5,7 @@ #include "Runtime/GuiSys/CGuiFrame.hpp" #include "Runtime/GuiSys/CGuiTextPane.hpp" -namespace urde { +namespace metaforce { CHudBossEnergyInterface::CHudBossEnergyInterface(CGuiFrame& selHud) { x14_basewidget_bossenergystuff = selHud.FindWidget("basewidget_bossenergystuff"); @@ -54,4 +54,4 @@ std::pair CHudBossEnergyInterface::BossEnergyC return {zeus::CVector3f(x, 0.f, 0.f), zeus::CVector3f(x, 0.f, 0.4f)}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudBossEnergyInterface.hpp b/Runtime/GuiSys/CHudBossEnergyInterface.hpp index 57a586a31..0d9b5a907 100644 --- a/Runtime/GuiSys/CHudBossEnergyInterface.hpp +++ b/Runtime/GuiSys/CHudBossEnergyInterface.hpp @@ -3,7 +3,7 @@ #include "Runtime/RetroTypes.hpp" #include -namespace urde { +namespace metaforce { class CAuiEnergyBarT01; class CGuiFrame; class CGuiTextPane; @@ -27,4 +27,4 @@ public: static std::pair BossEnergyCoordFunc(float t); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudDecoInterface.cpp b/Runtime/GuiSys/CHudDecoInterface.cpp index 0a1e77a81..cbc572a9c 100644 --- a/Runtime/GuiSys/CHudDecoInterface.cpp +++ b/Runtime/GuiSys/CHudDecoInterface.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { void IHudDecoInterface::SetReticuleTransform(const zeus::CMatrix3f& xf) {} void IHudDecoInterface::SetDecoRotation(float angle) {} @@ -536,4 +536,4 @@ void CHudDecoInterfaceThermal::UpdateHudAlpha() { x78_basewidget_pivot->SetColor(color); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudDecoInterface.hpp b/Runtime/GuiSys/CHudDecoInterface.hpp index f31e4f558..59c6a6669 100644 --- a/Runtime/GuiSys/CHudDecoInterface.hpp +++ b/Runtime/GuiSys/CHudDecoInterface.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class CGuiFrame; struct CFinalInput; class CStateManager; @@ -187,4 +187,4 @@ public: void UpdateHudAlpha() override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudEnergyInterface.cpp b/Runtime/GuiSys/CHudEnergyInterface.cpp index 64144dcfa..abfeab6bd 100644 --- a/Runtime/GuiSys/CHudEnergyInterface.cpp +++ b/Runtime/GuiSys/CHudEnergyInterface.cpp @@ -10,7 +10,7 @@ #include "Runtime/GuiSys/CGuiTextPane.hpp" #include "Runtime/GuiSys/CStringTable.hpp" -namespace urde { +namespace metaforce { constexpr std::array CoordFuncs{ CHudEnergyInterface::CombatEnergyCoordFunc, CHudEnergyInterface::CombatEnergyCoordFunc, @@ -171,4 +171,4 @@ std::pair CHudEnergyInterface::BallEnergyCoord return {zeus::CVector3f(x, 0.f, 0.f), zeus::CVector3f(x, 0.f, 0.088887997f)}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudEnergyInterface.hpp b/Runtime/GuiSys/CHudEnergyInterface.hpp index deacdd906..798a22ecc 100644 --- a/Runtime/GuiSys/CHudEnergyInterface.hpp +++ b/Runtime/GuiSys/CHudEnergyInterface.hpp @@ -4,7 +4,7 @@ #include "Runtime/GuiSys/CHudInterface.hpp" #include -namespace urde { +namespace metaforce { class CAuiEnergyBarT01; class CAuiMeter; class CGuiFrame; @@ -43,4 +43,4 @@ public: static std::pair BallEnergyCoordFunc(float t); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudFreeLookInterface.cpp b/Runtime/GuiSys/CHudFreeLookInterface.cpp index bd9735ad9..cdef057cb 100644 --- a/Runtime/GuiSys/CHudFreeLookInterface.cpp +++ b/Runtime/GuiSys/CHudFreeLookInterface.cpp @@ -4,7 +4,7 @@ #include "Runtime/GuiSys/CGuiFrame.hpp" #include "Runtime/GuiSys/CGuiModel.hpp" -namespace urde { +namespace metaforce { CHudFreeLookInterface::CHudFreeLookInterface(CGuiFrame& selHud, EHudType hudType, bool inFreeLook, bool lookControlHeld, bool lockedOnObj) @@ -145,4 +145,4 @@ void CHudFreeLookInterfaceXRay::SetFreeLookState(bool inFreeLook, bool lookContr x24_basewidget_freelook->SetVisibility(visible, ETraversalMode::Children); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudFreeLookInterface.hpp b/Runtime/GuiSys/CHudFreeLookInterface.hpp index 3494a2132..aa175b8fc 100644 --- a/Runtime/GuiSys/CHudFreeLookInterface.hpp +++ b/Runtime/GuiSys/CHudFreeLookInterface.hpp @@ -4,7 +4,7 @@ #include "Runtime/GuiSys/CHudInterface.hpp" #include -namespace urde { +namespace metaforce { class CGuiFrame; class CGuiModel; class CGuiWidget; @@ -68,4 +68,4 @@ public: void SetFreeLookState(bool inFreeLook, bool lookControlHeld, bool lockedOnObj, float vertLookAngle) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudHelmetInterface.cpp b/Runtime/GuiSys/CHudHelmetInterface.cpp index f28dfecaf..6bdb0fdfe 100644 --- a/Runtime/GuiSys/CHudHelmetInterface.cpp +++ b/Runtime/GuiSys/CHudHelmetInterface.cpp @@ -5,7 +5,7 @@ #include "Runtime/GuiSys/CGuiCamera.hpp" #include "Runtime/GuiSys/CGuiFrame.hpp" -namespace urde { +namespace metaforce { CHudHelmetInterface::CHudHelmetInterface(CGuiFrame& helmetFrame) { x40_camera = helmetFrame.GetFrameCamera(); @@ -60,4 +60,4 @@ void CHudHelmetInterface::SetIsVisibleDebug(bool helmet, bool glow) { UpdateVisibility(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudHelmetInterface.hpp b/Runtime/GuiSys/CHudHelmetInterface.hpp index 0d34a9f35..489986e8a 100644 --- a/Runtime/GuiSys/CHudHelmetInterface.hpp +++ b/Runtime/GuiSys/CHudHelmetInterface.hpp @@ -3,7 +3,7 @@ #include "Runtime/RetroTypes.hpp" #include -namespace urde { +namespace metaforce { class CGuiCamera; class CGuiFrame; class CGuiWidget; @@ -35,4 +35,4 @@ public: void SetIsVisibleDebug(bool helmet, bool glow); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudInterface.hpp b/Runtime/GuiSys/CHudInterface.hpp index 411d717e9..866dd2c89 100644 --- a/Runtime/GuiSys/CHudInterface.hpp +++ b/Runtime/GuiSys/CHudInterface.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde { +namespace metaforce { enum class EHudType { Combat, Scan, XRay, Thermal, Ball }; diff --git a/Runtime/GuiSys/CHudMissileInterface.cpp b/Runtime/GuiSys/CHudMissileInterface.cpp index 45d5a9425..ab530339e 100644 --- a/Runtime/GuiSys/CHudMissileInterface.cpp +++ b/Runtime/GuiSys/CHudMissileInterface.cpp @@ -10,7 +10,7 @@ #include "Runtime/GuiSys/CGuiTextPane.hpp" #include "Runtime/GuiSys/CStringTable.hpp" -namespace urde { +namespace metaforce { constexpr std::array CoordFuncs{ CHudMissileInterface::CombatMissileBarCoordFunc, nullptr, CHudMissileInterface::XRayMissileBarCoordFunc, @@ -266,4 +266,4 @@ std::pair CHudMissileInterface::ThermalMissile return {zeus::CVector3f(-0.5f * c - 0.1f, 0.f, b), zeus::CVector3f(-0.1f, 0.f, b)}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudMissileInterface.hpp b/Runtime/GuiSys/CHudMissileInterface.hpp index 33e27b012..4966aad66 100644 --- a/Runtime/GuiSys/CHudMissileInterface.hpp +++ b/Runtime/GuiSys/CHudMissileInterface.hpp @@ -4,7 +4,7 @@ #include "Runtime/GuiSys/CHudInterface.hpp" #include -namespace urde { +namespace metaforce { class CAuiEnergyBarT01; class CGuiFrame; class CGuiModel; @@ -56,4 +56,4 @@ public: static std::pair ThermalMissileBarCoordFunc(float t); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudRadarInterface.cpp b/Runtime/GuiSys/CHudRadarInterface.cpp index fb0b2eaf2..5bb5481a2 100644 --- a/Runtime/GuiSys/CHudRadarInterface.cpp +++ b/Runtime/GuiSys/CHudRadarInterface.cpp @@ -16,7 +16,7 @@ #include -namespace urde { +namespace metaforce { CHudRadarInterface::CHudRadarInterface(CGuiFrame& baseHud, CStateManager& stateMgr) { x0_txtrRadarPaint = g_SimplePool->GetObj("TXTR_RadarPaint"); @@ -159,4 +159,4 @@ void CHudRadarInterface::Draw(const CStateManager& mgr, float alpha) { m_paintShader.draw(m_paintInsts, x0_txtrRadarPaint.GetObj()); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudRadarInterface.hpp b/Runtime/GuiSys/CHudRadarInterface.hpp index 159342dc5..05bc01caf 100644 --- a/Runtime/GuiSys/CHudRadarInterface.hpp +++ b/Runtime/GuiSys/CHudRadarInterface.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CGuiCamera; class CGuiFrame; class CGuiWidget; @@ -45,4 +45,4 @@ public: void Draw(const CStateManager& mgr, float alpha); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudThreatInterface.cpp b/Runtime/GuiSys/CHudThreatInterface.cpp index 285707df0..25b6fcdae 100644 --- a/Runtime/GuiSys/CHudThreatInterface.cpp +++ b/Runtime/GuiSys/CHudThreatInterface.cpp @@ -10,7 +10,7 @@ #include "Runtime/GuiSys/CStringTable.hpp" #include "Runtime/Audio/CSfxManager.hpp" -namespace urde { +namespace metaforce { constexpr std::array CoordFuncs{ CHudThreatInterface::CombatThreatBarCoordFunc, nullptr, CHudThreatInterface::XRayThreatBarCoordFunc, @@ -234,4 +234,4 @@ std::pair CHudThreatInterface::ThermalThreatBa return {zeus::CVector3f(0.1f, 0.f, b), zeus::CVector3f(0.5f * c + 0.1f, 0.f, b)}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudThreatInterface.hpp b/Runtime/GuiSys/CHudThreatInterface.hpp index abb12af6d..95433056e 100644 --- a/Runtime/GuiSys/CHudThreatInterface.hpp +++ b/Runtime/GuiSys/CHudThreatInterface.hpp @@ -4,7 +4,7 @@ #include "Runtime/GuiSys/CHudInterface.hpp" #include -namespace urde { +namespace metaforce { class CAuiEnergyBarT01; class CGuiFrame; class CGuiModel; @@ -47,4 +47,4 @@ public: static std::pair ThermalThreatBarCoordFunc(float t); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudVisorBeamMenu.cpp b/Runtime/GuiSys/CHudVisorBeamMenu.cpp index 2cc4a9388..b0e882ae1 100644 --- a/Runtime/GuiSys/CHudVisorBeamMenu.cpp +++ b/Runtime/GuiSys/CHudVisorBeamMenu.cpp @@ -10,7 +10,7 @@ #include "Runtime/GuiSys/CGuiTextPane.hpp" #include "Runtime/GuiSys/CStringTable.hpp" -namespace urde { +namespace metaforce { constexpr std::array BaseMenuNames{ "BaseWidget_VisorMenu"sv, @@ -317,4 +317,4 @@ void CHudVisorBeamMenu::SetSelection(int selection, int pending, float interp) { x10_interp = interp; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CHudVisorBeamMenu.hpp b/Runtime/GuiSys/CHudVisorBeamMenu.hpp index d24820060..8e4f5611d 100644 --- a/Runtime/GuiSys/CHudVisorBeamMenu.hpp +++ b/Runtime/GuiSys/CHudVisorBeamMenu.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" -namespace urde { +namespace metaforce { class CGuiFrame; class CGuiModel; class CGuiTextPane; @@ -56,4 +56,4 @@ public: void SetSelection(int selection, int pending, float interp); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CInstruction.cpp b/Runtime/GuiSys/CInstruction.cpp index 963bf0bfd..cdc5578c3 100644 --- a/Runtime/GuiSys/CInstruction.cpp +++ b/Runtime/GuiSys/CInstruction.cpp @@ -5,7 +5,7 @@ #include "Runtime/GuiSys/CRasterFont.hpp" #include "Runtime/GuiSys/CTextRenderBuffer.hpp" -namespace urde { +namespace metaforce { void CInstruction::PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const {} @@ -307,4 +307,4 @@ void CWordInstruction::PageInvoke(CFontRenderState& state, CTextRenderBuffer* bu state.x108_lineInitialized = false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CInstruction.hpp b/Runtime/GuiSys/CInstruction.hpp index 79eb5c2f0..175e8c994 100644 --- a/Runtime/GuiSys/CInstruction.hpp +++ b/Runtime/GuiSys/CInstruction.hpp @@ -6,7 +6,7 @@ #include "Runtime/GuiSys/CFontImageDef.hpp" #include "Runtime/GuiSys/CGuiTextSupport.hpp" -namespace urde { +namespace metaforce { class CFontImageDef; class CFontRenderState; class CTextRenderBuffer; @@ -194,4 +194,4 @@ public: void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/COrbitPointMarker.cpp b/Runtime/GuiSys/COrbitPointMarker.cpp index db5cfb2a8..a63cc9a24 100644 --- a/Runtime/GuiSys/COrbitPointMarker.cpp +++ b/Runtime/GuiSys/COrbitPointMarker.cpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { COrbitPointMarker::COrbitPointMarker() { x0_zOffset = g_tweakTargeting->GetOrbitPointZOffset(); @@ -95,4 +95,4 @@ void COrbitPointMarker::Draw(const CStateManager& mgr) const { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/COrbitPointMarker.hpp b/Runtime/GuiSys/COrbitPointMarker.hpp index b910babfe..593e432e2 100644 --- a/Runtime/GuiSys/COrbitPointMarker.hpp +++ b/Runtime/GuiSys/COrbitPointMarker.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CStateManager; class COrbitPointMarker { float x0_zOffset; @@ -26,4 +26,4 @@ public: void Update(float dt, const CStateManager& mgr); void Draw(const CStateManager& mgr) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CRasterFont.cpp b/Runtime/GuiSys/CRasterFont.cpp index f3fb99c78..53e1d46b4 100644 --- a/Runtime/GuiSys/CRasterFont.cpp +++ b/Runtime/GuiSys/CRasterFont.cpp @@ -7,8 +7,8 @@ #include "Runtime/GuiSys/CDrawStringOptions.hpp" #include "Runtime/GuiSys/CTextRenderBuffer.hpp" -namespace urde { -CRasterFont::CRasterFont(urde::CInputStream& in, urde::IObjectStore& store) { +namespace metaforce { +CRasterFont::CRasterFont(metaforce::CInputStream& in, metaforce::IObjectStore& store) { u32 magic = 0; in.readBytesToBuf(&magic, 4); if (magic != SBIG('FONT')) @@ -216,4 +216,4 @@ std::unique_ptr FRasterFontFactory([[maybe_unused]] const SObjectTag& tag, return TToken::GetIObjObjectFor(std::make_unique(in, *sp)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CRasterFont.hpp b/Runtime/GuiSys/CRasterFont.hpp index ea0a8029c..7b9c629da 100644 --- a/Runtime/GuiSys/CRasterFont.hpp +++ b/Runtime/GuiSys/CRasterFont.hpp @@ -11,7 +11,7 @@ #include -namespace urde { +namespace metaforce { class CDrawStringOptions; class CTextRenderBuffer; class IObjectStore; @@ -157,4 +157,4 @@ public: std::unique_ptr FRasterFontFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CSaveableState.cpp b/Runtime/GuiSys/CSaveableState.cpp index fccaa9199..2b73ff43d 100644 --- a/Runtime/GuiSys/CSaveableState.cpp +++ b/Runtime/GuiSys/CSaveableState.cpp @@ -2,7 +2,7 @@ #include "Runtime/GuiSys/CRasterFont.hpp" -namespace urde { +namespace metaforce { bool CSaveableState::IsFinishedLoading() const { if (!x48_font || !x48_font.IsLoaded()) @@ -10,4 +10,4 @@ bool CSaveableState::IsFinishedLoading() const { return x48_font->IsFinishedLoading(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CSaveableState.hpp b/Runtime/GuiSys/CSaveableState.hpp index 7b875f000..2809a2347 100644 --- a/Runtime/GuiSys/CSaveableState.hpp +++ b/Runtime/GuiSys/CSaveableState.hpp @@ -10,7 +10,7 @@ #include -namespace urde { +namespace metaforce { class CSaveableState { friend class CColorOverrideInstruction; friend class CFontInstruction; @@ -39,4 +39,4 @@ public: bool IsFinishedLoading() const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CScanDisplay.cpp b/Runtime/GuiSys/CScanDisplay.cpp index 24852e2f1..cbbe5a349 100644 --- a/Runtime/GuiSys/CScanDisplay.cpp +++ b/Runtime/GuiSys/CScanDisplay.cpp @@ -16,7 +16,7 @@ #include -namespace urde { +namespace metaforce { void CScanDisplay::CDataDot::Update(float dt) { if (x20_remTime > 0.f) { x20_remTime = std::max(0.f, x20_remTime - dt); @@ -454,4 +454,4 @@ void CScanDisplay::Draw() { dot.Draw(g_tweakGuiColors->GetScanDataDotColor(), g_tweakGui->GetScanDataDotRadius() * vpRatio); } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CScanDisplay.hpp b/Runtime/GuiSys/CScanDisplay.hpp index 45b205bcf..8d116e081 100644 --- a/Runtime/GuiSys/CScanDisplay.hpp +++ b/Runtime/GuiSys/CScanDisplay.hpp @@ -14,7 +14,7 @@ #include #include -namespace urde { +namespace metaforce { class CAuiImagePane; class CGuiFrame; class CGuiModel; @@ -95,4 +95,4 @@ public: TUniqueId ScanTarget() const { return x10_objId; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CSplashScreen.cpp b/Runtime/GuiSys/CSplashScreen.cpp index f4fd01a50..a1c93f089 100644 --- a/Runtime/GuiSys/CSplashScreen.cpp +++ b/Runtime/GuiSys/CSplashScreen.cpp @@ -8,7 +8,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Camera/CCameraFilter.hpp" -namespace urde { +namespace metaforce { constexpr std::array SplashTextures{"TXTR_NintendoLogo"sv, "TXTR_RetroLogo"sv, "TXTR_DolbyLogo"sv}; @@ -76,4 +76,4 @@ void CSplashScreen::Draw() { m_quad.draw(color, 1.f, rect); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CSplashScreen.hpp b/Runtime/GuiSys/CSplashScreen.hpp index 4737ea26b..f1feaabcd 100644 --- a/Runtime/GuiSys/CSplashScreen.hpp +++ b/Runtime/GuiSys/CSplashScreen.hpp @@ -5,7 +5,7 @@ #include "Runtime/Graphics/CTexture.hpp" #include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" -namespace urde { +namespace metaforce { class CSplashScreen : public CIOWin { public: @@ -27,4 +27,4 @@ public: void Draw() override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CStringTable.cpp b/Runtime/GuiSys/CStringTable.cpp index 13d91889d..2874e052c 100644 --- a/Runtime/GuiSys/CStringTable.cpp +++ b/Runtime/GuiSys/CStringTable.cpp @@ -4,7 +4,7 @@ #include "Runtime/CToken.hpp" -namespace urde { +namespace metaforce { namespace { constexpr std::array languages{ FOURCC('ENGL'), FOURCC('FREN'), FOURCC('GERM'), FOURCC('SPAN'), FOURCC('ITAL'), FOURCC('DUTC'), FOURCC('JAPN'), @@ -77,4 +77,4 @@ CFactoryFnReturn FStringTableFactory(const SObjectTag&, CInputStream& in, const return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CStringTable.hpp b/Runtime/GuiSys/CStringTable.hpp index 88d574b78..d122958d3 100644 --- a/Runtime/GuiSys/CStringTable.hpp +++ b/Runtime/GuiSys/CStringTable.hpp @@ -5,7 +5,7 @@ #include "Runtime/IFactory.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CStringTable { static FourCC mCurrentLanguage; u32 x0_stringCount = 0; @@ -23,4 +23,4 @@ public: CFactoryFnReturn FStringTableFactory(const SObjectTag&, CInputStream&, const CVParamTransfer&, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CTargetingManager.cpp b/Runtime/GuiSys/CTargetingManager.cpp index c22052cfb..d2b536e57 100644 --- a/Runtime/GuiSys/CTargetingManager.cpp +++ b/Runtime/GuiSys/CTargetingManager.cpp @@ -5,7 +5,7 @@ #include "Runtime/Camera/CGameCamera.hpp" #include "Runtime/Graphics/CBooRenderer.hpp" -namespace urde { +namespace metaforce { CTargetingManager::CTargetingManager(const CStateManager& mgr) : x0_targetReticule(mgr) {} @@ -36,4 +36,4 @@ void CTargetingManager::Draw(const CStateManager& mgr, bool hideLockon) { void CTargetingManager::Touch() { x0_targetReticule.Touch(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CTargetingManager.hpp b/Runtime/GuiSys/CTargetingManager.hpp index 4a48380bd..18ea7f889 100644 --- a/Runtime/GuiSys/CTargetingManager.hpp +++ b/Runtime/GuiSys/CTargetingManager.hpp @@ -3,7 +3,7 @@ #include "Runtime/GuiSys/CCompoundTargetReticle.hpp" #include "Runtime/GuiSys/COrbitPointMarker.hpp" -namespace urde { +namespace metaforce { class CStateManager; class CTargetingManager { CCompoundTargetReticle x0_targetReticule; @@ -17,4 +17,4 @@ public: void Touch(); CCompoundTargetReticle& CompoundTargetReticle() { return x0_targetReticule; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CTextExecuteBuffer.cpp b/Runtime/GuiSys/CTextExecuteBuffer.cpp index 89c44e898..6cac32e35 100644 --- a/Runtime/GuiSys/CTextExecuteBuffer.cpp +++ b/Runtime/GuiSys/CTextExecuteBuffer.cpp @@ -9,7 +9,7 @@ #include "Runtime/GuiSys/CTextRenderBuffer.hpp" #include "Runtime/GuiSys/CWordBreakTables.hpp" -namespace urde { +namespace metaforce { CTextRenderBuffer CTextExecuteBuffer::BuildRenderBuffer(CGuiWidget::EGuiModelDrawFlags df) const { CTextRenderBuffer ret(CTextRenderBuffer::EMode::AllocTally, df); @@ -404,4 +404,4 @@ void CTextExecuteBuffer::Clear() { xbc_spaceDistance = 0; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CTextExecuteBuffer.hpp b/Runtime/GuiSys/CTextExecuteBuffer.hpp index e7dd10e75..c27c2e66e 100644 --- a/Runtime/GuiSys/CTextExecuteBuffer.hpp +++ b/Runtime/GuiSys/CTextExecuteBuffer.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class CBlockInstruction; class CFontImageDef; class CInstruction; @@ -70,4 +70,4 @@ public: void Clear(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CTextParser.cpp b/Runtime/GuiSys/CTextParser.cpp index 154e7d5f3..cfe8527e0 100644 --- a/Runtime/GuiSys/CTextParser.cpp +++ b/Runtime/GuiSys/CTextParser.cpp @@ -3,7 +3,7 @@ #include "Runtime/GuiSys/CFontImageDef.hpp" #include "Runtime/GuiSys/CTextExecuteBuffer.hpp" -namespace urde { +namespace metaforce { static float u16stof(const char16_t* str) { char cstr[16]; @@ -298,4 +298,4 @@ void CTextParser::ParseText(CTextExecuteBuffer& out, const char16_t* str, int le out.AddString(str + b, e - b); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CTextParser.hpp b/Runtime/GuiSys/CTextParser.hpp index 39d574b70..b878bad85 100644 --- a/Runtime/GuiSys/CTextParser.hpp +++ b/Runtime/GuiSys/CTextParser.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/GuiSys/CGuiTextSupport.hpp" -namespace urde { +namespace metaforce { class CFontImageDef; class CTextExecuteBuffer; @@ -32,4 +32,4 @@ public: const std::vector>* txtrMap); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CTextRenderBuffer.cpp b/Runtime/GuiSys/CTextRenderBuffer.cpp index 4dd3e46db..b999e5ae7 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.cpp +++ b/Runtime/GuiSys/CTextRenderBuffer.cpp @@ -10,7 +10,7 @@ #include "Runtime/GuiSys/CRasterFont.hpp" #include "Runtime/GuiSys/CTextExecuteBuffer.hpp" -namespace urde { +namespace metaforce { struct CTextRenderBuffer::BooPrimitiveMark { Command m_cmd; @@ -204,4 +204,4 @@ std::pair CTextRenderBuffer::AccumulateTextBou return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CTextRenderBuffer.hpp b/Runtime/GuiSys/CTextRenderBuffer.hpp index 233a04a1c..aadbe6446 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.hpp +++ b/Runtime/GuiSys/CTextRenderBuffer.hpp @@ -16,7 +16,7 @@ #include "zeus/CVector2f.hpp" #include "zeus/CVector2i.hpp" -namespace urde { +namespace metaforce { class CGlyph; class CGraphicsPalette; class CRasterFont; @@ -132,4 +132,4 @@ public: std::pair AccumulateTextBounds() const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CWordBreakTables.cpp b/Runtime/GuiSys/CWordBreakTables.cpp index f132bb4e5..69a94610a 100644 --- a/Runtime/GuiSys/CWordBreakTables.cpp +++ b/Runtime/GuiSys/CWordBreakTables.cpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/rstl.hpp" -namespace urde { +namespace metaforce { namespace { struct CCharacterIdentifier { wchar_t chr; @@ -54,4 +54,4 @@ int CWordBreakTables::GetEndRank(wchar_t ch) { return search->rank; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/GuiSys/CWordBreakTables.hpp b/Runtime/GuiSys/CWordBreakTables.hpp index 119b91cf7..274f58911 100644 --- a/Runtime/GuiSys/CWordBreakTables.hpp +++ b/Runtime/GuiSys/CWordBreakTables.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde { +namespace metaforce { class CWordBreakTables { public: @@ -8,4 +8,4 @@ public: static int GetEndRank(wchar_t ch); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IFactory.hpp b/Runtime/IFactory.hpp index b145b1b70..72d1f86b3 100644 --- a/Runtime/IFactory.hpp +++ b/Runtime/IFactory.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CFactoryMgr; class CObjectReference; class CResLoader; @@ -16,10 +16,10 @@ class IDvdRequest; class IObj; using CFactoryFnReturn = std::unique_ptr; -using FFactoryFunc = std::function; -using FMemFactoryFunc = std::function&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef)>; +using FFactoryFunc = std::function; +using FMemFactoryFunc = std::function&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef)>; class IFactory { public: @@ -38,13 +38,13 @@ public: virtual void AsyncIdle() {} /* Non-factory versions, replaces CResLoader */ - virtual u32 ResourceSize(const urde::SObjectTag& tag) = 0; - virtual std::shared_ptr LoadResourceAsync(const urde::SObjectTag& tag, void* target) = 0; - virtual std::shared_ptr LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, + virtual u32 ResourceSize(const metaforce::SObjectTag& tag) = 0; + virtual std::shared_ptr LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) = 0; + virtual std::shared_ptr LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size, void* target) = 0; - virtual std::unique_ptr LoadResourceSync(const urde::SObjectTag& tag) = 0; - virtual std::unique_ptr LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size) = 0; + virtual std::unique_ptr LoadResourceSync(const metaforce::SObjectTag& tag) = 0; + virtual std::unique_ptr LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) = 0; virtual void GetTagListForFile(const char* pakName, std::vector& out) const {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IMain.hpp b/Runtime/IMain.hpp index effb0a1e6..35b71fadf 100644 --- a/Runtime/IMain.hpp +++ b/Runtime/IMain.hpp @@ -5,13 +5,13 @@ #include "amuse/amuse.hpp" #include "boo2/audiodev/IAudioVoiceEngine.hpp" #include "hecl/Runtime.hpp" -#include "DataSpec/DNACommon/URDEVersionInfo.hpp" +#include "DataSpec/DNACommon/MetaforceVersionInfo.hpp" namespace hecl { class CVarManager; } // namespace hecl -namespace urde { +namespace metaforce { using ERegion = DataSpec::ERegion; using EGame = DataSpec::EGame; @@ -48,4 +48,4 @@ public: virtual bool IsTrilogy() const = 0; virtual std::string_view GetVersionString() const=0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IOStreams.cpp b/Runtime/IOStreams.cpp index 2b76b7e67..da890cd47 100644 --- a/Runtime/IOStreams.cpp +++ b/Runtime/IOStreams.cpp @@ -1,7 +1,7 @@ #include "Runtime/IOStreams.hpp" #include -namespace urde { +namespace metaforce { #define DUMP_BITS 0 @@ -137,4 +137,4 @@ atUint64 CZipInputStream::readUBytesToBuf(void* buf, atUint64 len) { return x30_zstrm.total_out; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IOStreams.hpp b/Runtime/IOStreams.hpp index 1fe75f4bd..6aef9d55c 100644 --- a/Runtime/IOStreams.hpp +++ b/Runtime/IOStreams.hpp @@ -12,7 +12,7 @@ #include #endif -namespace urde { +namespace metaforce { using CInputStream = athena::io::IStreamReader; using COutputStream = athena::io::IStreamWriter; @@ -71,4 +71,4 @@ public: }; #endif -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IObj.hpp b/Runtime/IObj.hpp index 2c45ed233..f6df9645d 100644 --- a/Runtime/IObj.hpp +++ b/Runtime/IObj.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class IObj { public: @@ -30,4 +30,4 @@ public: T* GetObj() { return static_cast(m_objPtr); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IObjFactory.hpp b/Runtime/IObjFactory.hpp index c67f3a65b..67f68efd8 100644 --- a/Runtime/IObjFactory.hpp +++ b/Runtime/IObjFactory.hpp @@ -1,10 +1,10 @@ #pragma once -namespace urde { +namespace metaforce { class IObjFactory { public: virtual ~IObjFactory() = default; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IObjectStore.hpp b/Runtime/IObjectStore.hpp index db76a6893..a3506b4bf 100644 --- a/Runtime/IObjectStore.hpp +++ b/Runtime/IObjectStore.hpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { class CToken; class CVParamTransfer; class IFactory; @@ -22,4 +22,4 @@ public: virtual void ObjectUnreferenced(const SObjectTag&) = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IRuntimeMain.hpp b/Runtime/IRuntimeMain.hpp index 0a24715bf..b8c02512b 100644 --- a/Runtime/IRuntimeMain.hpp +++ b/Runtime/IRuntimeMain.hpp @@ -1,9 +1,9 @@ #pragma once -namespace urde { +namespace metaforce { struct IRuntimeMain { void init() = 0; int proc() = 0; void stop() = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/ITweak.hpp b/Runtime/ITweak.hpp index 05aff8296..160d9a046 100644 --- a/Runtime/ITweak.hpp +++ b/Runtime/ITweak.hpp @@ -1,8 +1,8 @@ #pragma once -namespace urde { +namespace metaforce { class ITweak { public: virtual ~ITweak() = default; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/IVParamObj.hpp b/Runtime/IVParamObj.hpp index 83d307883..642ef20e9 100644 --- a/Runtime/IVParamObj.hpp +++ b/Runtime/IVParamObj.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/IObj.hpp" -namespace urde { +namespace metaforce { class IVParamObj : public IObj { public: @@ -44,4 +44,4 @@ public: static CVParamTransfer Null() noexcept { return CVParamTransfer(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CFinalInput.cpp b/Runtime/Input/CFinalInput.cpp index 5c85666d2..f896381cf 100644 --- a/Runtime/Input/CFinalInput.cpp +++ b/Runtime/Input/CFinalInput.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { CFinalInput::CFinalInput() = default; @@ -208,4 +208,4 @@ CFinalInput CFinalInput::ScaleAnalogueSticks(float leftDiv, float rightDiv) cons ret.m_rightMul = 1.f / rightDiv; return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CFinalInput.hpp b/Runtime/Input/CFinalInput.hpp index c640ed086..3c959e2d6 100644 --- a/Runtime/Input/CFinalInput.hpp +++ b/Runtime/Input/CFinalInput.hpp @@ -8,7 +8,7 @@ #include "boo2/inputdev/DolphinSmashAdapter.hpp" -namespace urde { +namespace metaforce { struct CFinalInput { float x0_dt = 0.0f; @@ -177,4 +177,4 @@ struct CFinalInput { const std::optional& GetKBM() const { return m_kbm; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CInputGenerator.cpp b/Runtime/Input/CInputGenerator.cpp index 4ebc1c8d2..e5feb22a4 100644 --- a/Runtime/Input/CInputGenerator.cpp +++ b/Runtime/Input/CInputGenerator.cpp @@ -3,7 +3,7 @@ #include "Runtime/CArchitectureMessage.hpp" #include "Runtime/CArchitectureQueue.hpp" -namespace urde { +namespace metaforce { void CInputGenerator::Update(float dt, CArchitectureQueue& queue) { if (m_firstFrame) { @@ -49,4 +49,4 @@ void CInputGenerator::Update(float dt, CArchitectureQueue& queue) { queue.Push(MakeMsg::CreateUserInput(EArchMsgTarget::Game, kbInput)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CInputGenerator.hpp b/Runtime/Input/CInputGenerator.hpp index 57bcc63c6..5be228257 100644 --- a/Runtime/Input/CInputGenerator.hpp +++ b/Runtime/Input/CInputGenerator.hpp @@ -9,7 +9,7 @@ #include "boo2/inputdev/DeviceFinder.hpp" -namespace urde { +namespace metaforce { class CArchitectureQueue; enum class EIOPort { Zero, One, Two, Three }; @@ -186,4 +186,4 @@ public: void Update(float dt, CArchitectureQueue& queue); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CKeyboardMouseController.hpp b/Runtime/Input/CKeyboardMouseController.hpp index 2a461a993..1078a7039 100644 --- a/Runtime/Input/CKeyboardMouseController.hpp +++ b/Runtime/Input/CKeyboardMouseController.hpp @@ -3,7 +3,7 @@ #include #include "boo2/boo2.hpp" -namespace urde { +namespace metaforce { struct CKeyboardMouseControllerData { std::array m_charKeys{}; @@ -15,4 +15,4 @@ struct CKeyboardMouseControllerData { hsh::offset2dF m_accumScroll; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CLibnxController.hpp b/Runtime/Input/CLibnxController.hpp index 2a0e3c7d3..b0291578d 100644 --- a/Runtime/Input/CLibnxController.hpp +++ b/Runtime/Input/CLibnxController.hpp @@ -5,7 +5,7 @@ #include #include "boo2/boo2.hpp" -namespace urde { +namespace metaforce { struct CLibnxControllerData { u64 keysDown; diff --git a/Runtime/Input/CRumbleGenerator.cpp b/Runtime/Input/CRumbleGenerator.cpp index b4b68ecfa..d778010c1 100644 --- a/Runtime/Input/CRumbleGenerator.cpp +++ b/Runtime/Input/CRumbleGenerator.cpp @@ -2,7 +2,7 @@ #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { CRumbleGenerator::CRumbleGenerator() { HardStopAll(); @@ -109,4 +109,4 @@ void CRumbleGenerator::Stop(s16 id, EIOPort port) { vox.Deactivate(id, false); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CRumbleGenerator.hpp b/Runtime/Input/CRumbleGenerator.hpp index 9ffaf3798..46bca6c57 100644 --- a/Runtime/Input/CRumbleGenerator.hpp +++ b/Runtime/Input/CRumbleGenerator.hpp @@ -6,7 +6,7 @@ #include "Runtime/Input/CInputGenerator.hpp" #include "Runtime/Input/CRumbleVoice.hpp" -namespace urde { +namespace metaforce { class CRumbleGenerator { std::array x0_voices; std::array xc0_periodTime; @@ -24,4 +24,4 @@ public: bool IsDisabled() const { return xf0_24_disabled; } void SetDisabled(bool disabled) { xf0_24_disabled = disabled; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CRumbleManager.cpp b/Runtime/Input/CRumbleManager.cpp index 32fa03bd9..c00db013f 100644 --- a/Runtime/Input/CRumbleManager.cpp +++ b/Runtime/Input/CRumbleManager.cpp @@ -6,7 +6,7 @@ #include "Runtime/Input/RumbleFxTable.hpp" #include "Runtime/World/CPlayer.hpp" -namespace urde { +namespace metaforce { s16 CRumbleManager::Rumble(CStateManager& mgr, const zeus::CVector3f& pos, ERumbleFxId fx, float dist, ERumblePriority priority) { @@ -24,4 +24,4 @@ s16 CRumbleManager::Rumble(CStateManager& mgr, ERumbleFxId fx, float gain, ERumb return -1; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CRumbleManager.hpp b/Runtime/Input/CRumbleManager.hpp index c820dacec..9d642196c 100644 --- a/Runtime/Input/CRumbleManager.hpp +++ b/Runtime/Input/CRumbleManager.hpp @@ -5,7 +5,7 @@ #include -namespace urde { +namespace metaforce { class CStateManager; class CRumbleManager { CRumbleGenerator x0_rumbleGenerator; @@ -23,4 +23,4 @@ public: s16 Rumble(CStateManager& mgr, const zeus::CVector3f& pos, ERumbleFxId fx, float dist, ERumblePriority priority); s16 Rumble(CStateManager& mgr, ERumbleFxId fx, float gain, ERumblePriority priority); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CRumbleVoice.cpp b/Runtime/Input/CRumbleVoice.cpp index 4c21805a1..8981f14be 100644 --- a/Runtime/Input/CRumbleVoice.cpp +++ b/Runtime/Input/CRumbleVoice.cpp @@ -1,6 +1,6 @@ #include "Runtime/Input/CRumbleVoice.hpp" -namespace urde { +namespace metaforce { CRumbleVoice::CRumbleVoice() : x0_datas(4), x10_deltas(4, SAdsrDelta::Stopped()) { x20_handleIds.resize(4); @@ -156,4 +156,4 @@ void CRumbleVoice::Deactivate(s16 id, bool b1) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/CRumbleVoice.hpp b/Runtime/Input/CRumbleVoice.hpp index 842250037..7dcb09cd0 100644 --- a/Runtime/Input/CRumbleVoice.hpp +++ b/Runtime/Input/CRumbleVoice.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" -namespace urde { +namespace metaforce { enum class ERumbleFxId { Zero = 0, One = 1, @@ -91,4 +91,4 @@ public: void Deactivate(s16 id, bool b1); ERumblePriority GetPriority(s16 idx) const { return x10_deltas[idx].x1c_priority; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/ControlMapper.cpp b/Runtime/Input/ControlMapper.cpp index 914d11592..a98df4d42 100644 --- a/Runtime/Input/ControlMapper.cpp +++ b/Runtime/Input/ControlMapper.cpp @@ -8,7 +8,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Input/CFinalInput.hpp" -namespace urde { +namespace metaforce { namespace { constexpr std::array skCommandDescs{ "Forward", "Backward", "Turn Left", @@ -416,4 +416,4 @@ const char* ControlMapper::GetDescriptionForFunction(EFunctionList func) { return skFunctionDescs[size_t(func)]; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/ControlMapper.hpp b/Runtime/Input/ControlMapper.hpp index 7c5b3e7fa..92fa9f6b3 100644 --- a/Runtime/Input/ControlMapper.hpp +++ b/Runtime/Input/ControlMapper.hpp @@ -4,7 +4,7 @@ #include "boo2/boo2.hpp" -namespace urde { +namespace metaforce { struct CFinalInput; class ControlMapper { @@ -136,4 +136,4 @@ constexpr ControlMapper::EKBMFunctionList operator+(ControlMapper::EKBMFunctionL return ControlMapper::EKBMFunctionList(static_cast(a) + static_cast(b)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/IController.hpp b/Runtime/Input/IController.hpp index efae5ecd0..d6069d40a 100644 --- a/Runtime/Input/IController.hpp +++ b/Runtime/Input/IController.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde { +namespace metaforce { class IController { public: @@ -9,4 +9,4 @@ public: virtual void SetMotorState(EMotorState state) = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Input/RumbleFxTable.cpp b/Runtime/Input/RumbleFxTable.cpp index f35a6f6ee..8aad0dd74 100644 --- a/Runtime/Input/RumbleFxTable.cpp +++ b/Runtime/Input/RumbleFxTable.cpp @@ -1,6 +1,6 @@ #include "Runtime/Input/RumbleFxTable.hpp" -namespace urde { +namespace metaforce { constexpr RumbleFXTable RumbleFxTable{{ /* attackGain, autoReleaseDur, attackDur, decayDur, sustainGain, releaseDur, hasSustain, autoRelease */ diff --git a/Runtime/Input/RumbleFxTable.hpp b/Runtime/Input/RumbleFxTable.hpp index 9d649537c..030d90386 100644 --- a/Runtime/Input/RumbleFxTable.hpp +++ b/Runtime/Input/RumbleFxTable.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/Input/CRumbleVoice.hpp" -namespace urde { +namespace metaforce { using RumbleFXTable = std::array; diff --git a/Runtime/MP1/CArtifactDoll.cpp b/Runtime/MP1/CArtifactDoll.cpp index f0b97ec4d..8b46bd128 100644 --- a/Runtime/MP1/CArtifactDoll.cpp +++ b/Runtime/MP1/CArtifactDoll.cpp @@ -13,7 +13,7 @@ #include #include -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array ArtifactPieceModels{ "CMDL_Piece1", // Truth @@ -180,4 +180,4 @@ bool CArtifactDoll::CheckLoadComplete() { return true; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CArtifactDoll.hpp b/Runtime/MP1/CArtifactDoll.hpp index 549c6e13f..eb79d671a 100644 --- a/Runtime/MP1/CArtifactDoll.hpp +++ b/Runtime/MP1/CArtifactDoll.hpp @@ -8,7 +8,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Character/CActorLights.hpp" -namespace urde { +namespace metaforce { class CModel; namespace MP1 { @@ -34,4 +34,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CAudioStateWin.cpp b/Runtime/MP1/CAudioStateWin.cpp index 89ca24fb1..fb18e3fd1 100644 --- a/Runtime/MP1/CAudioStateWin.cpp +++ b/Runtime/MP1/CAudioStateWin.cpp @@ -7,7 +7,7 @@ #include "Runtime/Audio/CSfxManager.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CIOWin::EMessageReturn CAudioStateWin::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) { CMain* m = static_cast(g_Main); @@ -26,4 +26,4 @@ CIOWin::EMessageReturn CAudioStateWin::OnMessage(const CArchitectureMessage& msg return EMessageReturn::Normal; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CAudioStateWin.hpp b/Runtime/MP1/CAudioStateWin.hpp index fb6dd7064..937a3f8d4 100644 --- a/Runtime/MP1/CAudioStateWin.hpp +++ b/Runtime/MP1/CAudioStateWin.hpp @@ -2,11 +2,11 @@ #include "Runtime/CIOWin.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CAudioStateWin : public CIOWin { public: CAudioStateWin() : CIOWin("CAudioStateWin") {} CIOWin::EMessageReturn OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CAutoSave.cpp b/Runtime/MP1/CAutoSave.cpp index ce69028be..cdd092e02 100644 --- a/Runtime/MP1/CAutoSave.cpp +++ b/Runtime/MP1/CAutoSave.cpp @@ -2,7 +2,7 @@ #include "CSaveGameScreen.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CAutoSave::CAutoSave() : CIOWin("AutoSave"sv), x14_savegameScreen(new CSaveGameScreen(ESaveContext::InGame, g_GameState->GetCardSerial())) { static_cast(g_Main)->RefreshGameState(); @@ -26,4 +26,4 @@ CIOWin::EMessageReturn CAutoSave::OnMessage(const CArchitectureMessage& msg, CAr return EMessageReturn::Exit; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CAutoSave.hpp b/Runtime/MP1/CAutoSave.hpp index 658b3f6f2..4ba3a7fcf 100644 --- a/Runtime/MP1/CAutoSave.hpp +++ b/Runtime/MP1/CAutoSave.hpp @@ -2,7 +2,7 @@ #include "Runtime/CIOWin.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CSaveGameScreen; class CAutoSave : CIOWin { std::unique_ptr x14_savegameScreen; @@ -14,4 +14,4 @@ public: bool GetIsContinueDraw() const override { return false; } EMessageReturn OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CCredits.cpp b/Runtime/MP1/CCredits.cpp index 1c229dbc7..9b896cea7 100644 --- a/Runtime/MP1/CCredits.cpp +++ b/Runtime/MP1/CCredits.cpp @@ -2,7 +2,7 @@ #include "Runtime/Graphics/CGraphics.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CCredits::CCredits() : CIOWin("Credits") {} @@ -14,4 +14,4 @@ void CCredits::Draw() { SCOPED_GRAPHICS_DEBUG_GROUP("CCredits::Draw", zeus::skGreen); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CCredits.hpp b/Runtime/MP1/CCredits.hpp index 6648a8a83..d5efabd56 100644 --- a/Runtime/MP1/CCredits.hpp +++ b/Runtime/MP1/CCredits.hpp @@ -2,7 +2,7 @@ #include "Runtime/CIOWin.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CCredits : public CIOWin { public: @@ -12,4 +12,4 @@ public: void Draw() override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CFaceplateDecoration.cpp b/Runtime/MP1/CFaceplateDecoration.cpp index 2c45c778a..f8e8d21e6 100644 --- a/Runtime/MP1/CFaceplateDecoration.cpp +++ b/Runtime/MP1/CFaceplateDecoration.cpp @@ -6,7 +6,7 @@ #include "Runtime/Particle/CGenDescription.hpp" #include "Runtime/World/CPlayer.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CFaceplateDecoration::CFaceplateDecoration(CStateManager& stateMgr) {} @@ -43,4 +43,4 @@ void CFaceplateDecoration::Draw(CStateManager& stateMgr) { } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CFaceplateDecoration.hpp b/Runtime/MP1/CFaceplateDecoration.hpp index 94891bfaa..92116d0d4 100644 --- a/Runtime/MP1/CFaceplateDecoration.hpp +++ b/Runtime/MP1/CFaceplateDecoration.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" -namespace urde { +namespace metaforce { class CStateManager; namespace MP1 { @@ -24,4 +24,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CFrontEndUI.cpp b/Runtime/MP1/CFrontEndUI.cpp index e69e4befe..3b79cd6bb 100644 --- a/Runtime/MP1/CFrontEndUI.cpp +++ b/Runtime/MP1/CFrontEndUI.cpp @@ -29,7 +29,7 @@ #include "Runtime/MP1/CSlideShow.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { #define FE_USE_SECONDS_IN_ELAPSED 1 @@ -2320,4 +2320,4 @@ CIOWin::EMessageReturn CFrontEndUI::OnMessage(const CArchitectureMessage& msg, C return EMessageReturn::Normal; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CFrontEndUI.hpp b/Runtime/MP1/CFrontEndUI.hpp index 529e8b4c8..fa0338d0a 100644 --- a/Runtime/MP1/CFrontEndUI.hpp +++ b/Runtime/MP1/CFrontEndUI.hpp @@ -19,7 +19,7 @@ #include -namespace urde { +namespace metaforce { class CAudioGroupSet; class CDependencyGroup; class CGuiFrame; @@ -379,4 +379,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CGBASupport.cpp b/Runtime/MP1/CGBASupport.cpp index 15351be26..cc3ba3d63 100644 --- a/Runtime/MP1/CGBASupport.cpp +++ b/Runtime/MP1/CGBASupport.cpp @@ -8,7 +8,7 @@ #include #include -namespace urde::MP1 { +namespace metaforce::MP1 { static jbus::Listener g_JbusListener; static std::unique_ptr g_JbusEndpoint; @@ -222,4 +222,4 @@ void CGBASupport::StartLink() { x40_siChan = -1; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CGBASupport.hpp b/Runtime/MP1/CGBASupport.hpp index 29d7a95de..7cf9190b6 100644 --- a/Runtime/MP1/CGBASupport.hpp +++ b/Runtime/MP1/CGBASupport.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/CDvdFile.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CGBASupport : public CDvdFile { public: @@ -51,4 +51,4 @@ public: bool IsFusionBeat() const { return x45_fusionBeat; } }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CGameCubeDoll.cpp b/Runtime/MP1/CGameCubeDoll.cpp index 285ac0a82..e8ac9f944 100644 --- a/Runtime/MP1/CGameCubeDoll.cpp +++ b/Runtime/MP1/CGameCubeDoll.cpp @@ -4,7 +4,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Graphics/CBooRenderer.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CGameCubeDoll::CGameCubeDoll() { x0_model = g_SimplePool->GetObj("CMDL_GameCube"); @@ -56,4 +56,4 @@ bool CGameCubeDoll::CheckLoadComplete() { return false; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CGameCubeDoll.hpp b/Runtime/MP1/CGameCubeDoll.hpp index 2d81041b4..3797cc609 100644 --- a/Runtime/MP1/CGameCubeDoll.hpp +++ b/Runtime/MP1/CGameCubeDoll.hpp @@ -7,7 +7,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Character/CActorLights.hpp" -namespace urde { +namespace metaforce { class CModel; namespace MP1 { @@ -29,4 +29,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CInGameGuiManager.cpp b/Runtime/MP1/CInGameGuiManager.cpp index b9b872a3c..c507e061d 100644 --- a/Runtime/MP1/CInGameGuiManager.cpp +++ b/Runtime/MP1/CInGameGuiManager.cpp @@ -21,7 +21,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::array InGameGuiDGRPs{ "InGameGui_DGRP"sv, "Ice_DGRP"sv, "Phazon_DGRP"sv, "Plasma_DGRP"sv, @@ -641,4 +641,4 @@ bool CInGameGuiManager::GetIsGameDraw() const { // return x3c_pauseScreenBlur->IsGameDraw(); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CInGameGuiManager.hpp b/Runtime/MP1/CInGameGuiManager.hpp index 7c3e252c7..2173ee038 100644 --- a/Runtime/MP1/CInGameGuiManager.hpp +++ b/Runtime/MP1/CInGameGuiManager.hpp @@ -27,7 +27,7 @@ #include #include -namespace urde { +namespace metaforce { class CActorLights; class CArchitectureQueue; class CAutoMapper; @@ -138,4 +138,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CInGameGuiManagerCommon.hpp b/Runtime/MP1/CInGameGuiManagerCommon.hpp index 3e72a91ce..eb5e1eee8 100644 --- a/Runtime/MP1/CInGameGuiManagerCommon.hpp +++ b/Runtime/MP1/CInGameGuiManagerCommon.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde::MP1 { +namespace metaforce::MP1 { enum class EInGameGuiState { Zero, InGame, MapScreen, PauseGame, PauseLogBook, PauseSaveGame, PauseHUDMessage }; diff --git a/Runtime/MP1/CInGameTweakManager.hpp b/Runtime/MP1/CInGameTweakManager.hpp index 0be9131f8..4317c9e22 100644 --- a/Runtime/MP1/CInGameTweakManager.hpp +++ b/Runtime/MP1/CInGameTweakManager.hpp @@ -2,10 +2,10 @@ #include "Runtime/CInGameTweakManagerBase.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CInGameTweakManager : public CInGameTweakManagerBase { public: }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CInventoryScreen.cpp b/Runtime/MP1/CInventoryScreen.cpp index 7657aa91e..c84591c1c 100644 --- a/Runtime/MP1/CInventoryScreen.cpp +++ b/Runtime/MP1/CInventoryScreen.cpp @@ -9,7 +9,7 @@ #include "Runtime/Input/ControlMapper.hpp" #include "Runtime/IMain.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { struct SInventoryItem { u32 idx; @@ -566,4 +566,4 @@ void CInventoryScreen::UpdateSamusDollPulses() { x19c_samusDoll->SetPulseVisor(pulseVisor); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CInventoryScreen.hpp b/Runtime/MP1/CInventoryScreen.hpp index 8cd4f6764..21ee50c21 100644 --- a/Runtime/MP1/CInventoryScreen.hpp +++ b/Runtime/MP1/CInventoryScreen.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CDependencyGroup; namespace MP1 { @@ -60,4 +60,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CLogBookScreen.cpp b/Runtime/MP1/CLogBookScreen.cpp index 25f6b14ce..fe24947a7 100644 --- a/Runtime/MP1/CLogBookScreen.cpp +++ b/Runtime/MP1/CLogBookScreen.cpp @@ -11,7 +11,7 @@ #include "Runtime/MP1/CArtifactDoll.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CLogBookScreen::CLogBookScreen(const CStateManager& mgr, CGuiFrame& frame, const CStringTable& pauseStrg) : CPauseScreenBase(mgr, frame, pauseStrg, true) { @@ -440,4 +440,4 @@ bool CLogBookScreen::ShouldRightTableAdvance() const { u32 CLogBookScreen::GetRightTableCount() const { return x1f0_curViewScans.size(); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CLogBookScreen.hpp b/Runtime/MP1/CLogBookScreen.hpp index 246678a63..4a100ed1a 100644 --- a/Runtime/MP1/CLogBookScreen.hpp +++ b/Runtime/MP1/CLogBookScreen.hpp @@ -9,13 +9,13 @@ #include "Runtime/rstl.hpp" #include "Runtime/MP1/CPauseScreenBase.hpp" -namespace urde { +namespace metaforce { class CPlayerState; class CScannableObjectInfo; class CStringTable; -} // namespace urde +} // namespace metaforce -namespace urde::MP1 { +namespace metaforce::MP1 { class CArtifactDoll; class CLogBookScreen : public CPauseScreenBase { @@ -65,4 +65,4 @@ public: u32 GetRightTableCount() const override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CMFGame.cpp b/Runtime/MP1/CMFGame.cpp index bd0d0e71c..577fbbd34 100644 --- a/Runtime/MP1/CMFGame.cpp +++ b/Runtime/MP1/CMFGame.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CMFGame::CMFGame(const std::weak_ptr& stateMgr, const std::weak_ptr& guiMgr, const CArchitectureQueue&) @@ -372,4 +372,4 @@ void CMFGameLoader::Draw() { g_GameState->GetWorldTransitionManager()->Draw(); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CMFGame.hpp b/Runtime/MP1/CMFGame.hpp index 3284006ee..ecf089a93 100644 --- a/Runtime/MP1/CMFGame.hpp +++ b/Runtime/MP1/CMFGame.hpp @@ -8,7 +8,7 @@ #include "Runtime/Graphics/Shaders/CColoredQuadFilter.hpp" #include "Runtime/MP1/CInGameGuiManager.hpp" -namespace urde { +namespace metaforce { class CStateManager; class CToken; @@ -65,4 +65,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CMainFlow.cpp b/Runtime/MP1/CMainFlow.cpp index 5cf040a5f..19643012a 100644 --- a/Runtime/MP1/CMainFlow.cpp +++ b/Runtime/MP1/CMainFlow.cpp @@ -16,7 +16,7 @@ #include "Runtime/MP1/CStateSetterFlow.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { void CMainFlow::AdvanceGameState(CArchitectureQueue& queue) { switch (x14_gameState) { @@ -100,4 +100,4 @@ void CMainFlow::SetGameState(EClientFlowStates state, CArchitectureQueue& queue) } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CMainFlow.hpp b/Runtime/MP1/CMainFlow.hpp index 04c0f0da1..ec805c725 100644 --- a/Runtime/MP1/CMainFlow.hpp +++ b/Runtime/MP1/CMainFlow.hpp @@ -2,7 +2,7 @@ #include "Runtime/CMainFlowBase.hpp" -namespace urde { +namespace metaforce { class CArchitectureMessage; class CArchitectureQueue; @@ -19,4 +19,4 @@ public: } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CMemoryCardDriver.cpp b/Runtime/MP1/CMemoryCardDriver.cpp index a8a1b2669..a1d14bb7c 100644 --- a/Runtime/MP1/CMemoryCardDriver.cpp +++ b/Runtime/MP1/CMemoryCardDriver.cpp @@ -5,7 +5,7 @@ #include "Runtime/CCRC32.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::array SaveFileNames{"MetroidPrime A", "MetroidPrime B"}; @@ -39,6 +39,9 @@ ECardResult CMemoryCardDriver::SFileInfo::TryFileRead() { ECardResult CMemoryCardDriver::SFileInfo::FileRead() { x34_saveData.clear(); + if (x24_saveFileData.empty()) { + return ECardResult::CRC_MISMATCH; + } u32 existingCrc = hecl::SBig(*reinterpret_cast(x24_saveFileData.data())); u32 newCrc = CCRC32::Calculate(x24_saveFileData.data() + 4, x24_saveFileData.size() - 4); if (existingCrc == newCrc) { @@ -796,4 +799,4 @@ void CMemoryCardDriver::Update() { static_cast(g_Main)->SetCardBusy(cardBusy); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CMemoryCardDriver.hpp b/Runtime/MP1/CMemoryCardDriver.hpp index 732e39181..fec06aa25 100644 --- a/Runtime/MP1/CMemoryCardDriver.hpp +++ b/Runtime/MP1/CMemoryCardDriver.hpp @@ -8,7 +8,7 @@ #include "Runtime/CGameState.hpp" #include "Runtime/CMemoryCardSys.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CMemoryCardDriver { friend class CSaveGameScreen; @@ -195,4 +195,4 @@ public: } }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CMessageScreen.cpp b/Runtime/MP1/CMessageScreen.cpp index ec1a1613f..ba4006f9e 100644 --- a/Runtime/MP1/CMessageScreen.cpp +++ b/Runtime/MP1/CMessageScreen.cpp @@ -9,7 +9,7 @@ #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" #include "Runtime/Input/CFinalInput.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CMessageScreen::CMessageScreen(CAssetId msg, float delayTime) : x74_delayTime(delayTime) { x0_msg = g_SimplePool->GetObj({FOURCC('STRG'), msg}); @@ -132,4 +132,4 @@ void CMessageScreen::Draw() const { x18_loadedMsgScreen->Draw(CGuiWidgetDrawParms(x70_blurAmt, zeus::skZero3f)); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CMessageScreen.hpp b/Runtime/MP1/CMessageScreen.hpp index db52a0678..799ed467f 100644 --- a/Runtime/MP1/CMessageScreen.hpp +++ b/Runtime/MP1/CMessageScreen.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { struct CFinalInput; class CGuiModel; class CGuiTextPane; @@ -46,4 +46,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/COptionsScreen.cpp b/Runtime/MP1/COptionsScreen.cpp index dfff47b5e..bcb5aae61 100644 --- a/Runtime/MP1/COptionsScreen.cpp +++ b/Runtime/MP1/COptionsScreen.cpp @@ -7,7 +7,7 @@ #include "Runtime/GuiSys/CGuiTextPane.hpp" #include "Runtime/Input/RumbleFxTable.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { COptionsScreen::COptionsScreen(const CStateManager& mgr, CGuiFrame& frame, const CStringTable& pauseStrg) : CPauseScreenBase(mgr, frame, pauseStrg), x1a0_gameCube{std::make_unique()} {} @@ -254,4 +254,4 @@ u32 COptionsScreen::GetRightTableCount() const { return GameOptionsRegistry[x70_tablegroup_leftlog->GetUserSelection()].first; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/COptionsScreen.hpp b/Runtime/MP1/COptionsScreen.hpp index f6c5ccd1e..25ed4369f 100644 --- a/Runtime/MP1/COptionsScreen.hpp +++ b/Runtime/MP1/COptionsScreen.hpp @@ -7,7 +7,7 @@ #include "Runtime/MP1/CPauseScreenBase.hpp" #include "Runtime/MP1/CQuitGameScreen.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class COptionsScreen : public CPauseScreenBase { std::unique_ptr x19c_quitGame; @@ -41,4 +41,4 @@ public: u32 GetRightTableCount() const override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CPauseScreen.cpp b/Runtime/MP1/CPauseScreen.cpp index ad9a710f2..a06dfee63 100644 --- a/Runtime/MP1/CPauseScreen.cpp +++ b/Runtime/MP1/CPauseScreen.cpp @@ -10,7 +10,7 @@ #include "Runtime/MP1/CLogBookScreen.hpp" #include "Runtime/MP1/COptionsScreen.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CPauseScreen::CPauseScreen(ESubScreen subscreen, const CDependencyGroup& suitDgrp, const CDependencyGroup& ballDgrp) : x0_initialSubScreen(subscreen) @@ -354,4 +354,4 @@ float CPauseScreen::GetHelmetCamYOff() const { return 0.f; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CPauseScreen.hpp b/Runtime/MP1/CPauseScreen.hpp index 4233869d9..2178653a6 100644 --- a/Runtime/MP1/CPauseScreen.hpp +++ b/Runtime/MP1/CPauseScreen.hpp @@ -7,7 +7,7 @@ #include "Runtime/MP1/CInGameGuiManager.hpp" #include "Runtime/MP1/CPauseScreenBase.hpp" -namespace urde { +namespace metaforce { class CDependencyGroup; namespace MP1 { @@ -83,4 +83,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CPauseScreenBase.cpp b/Runtime/MP1/CPauseScreenBase.cpp index 837a903de..28f876363 100644 --- a/Runtime/MP1/CPauseScreenBase.cpp +++ b/Runtime/MP1/CPauseScreenBase.cpp @@ -15,7 +15,7 @@ #include "Runtime/GuiSys/CStringTable.hpp" #include "Runtime/IMain.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CPauseScreenBase::CPauseScreenBase(const CStateManager& mgr, CGuiFrame& frame, const CStringTable& pauseStrg, bool isLogBook) @@ -531,4 +531,4 @@ std::string CPauseScreenBase::GetImagePaneName(size_t i) { return fmt::format(FMT_STRING("imagepane_pane{}"), PaneSuffixes[i]); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CPauseScreenBase.hpp b/Runtime/MP1/CPauseScreenBase.hpp index bbc62508f..9a905e888 100644 --- a/Runtime/MP1/CPauseScreenBase.hpp +++ b/Runtime/MP1/CPauseScreenBase.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CArchitectureQueue; class CAuiImagePane; class CGuiModel; @@ -137,4 +137,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CPauseScreenBlur.cpp b/Runtime/MP1/CPauseScreenBlur.cpp index 360b662bb..c797238a2 100644 --- a/Runtime/MP1/CPauseScreenBlur.cpp +++ b/Runtime/MP1/CPauseScreenBlur.cpp @@ -4,7 +4,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Audio/CSfxManager.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CPauseScreenBlur::CPauseScreenBlur() : x4_mapLightQuarter(g_SimplePool->GetObj("TXTR_MapLightQuarter")) {} @@ -99,4 +99,4 @@ void CPauseScreenBlur::Draw(const CStateManager&) { } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CPauseScreenBlur.hpp b/Runtime/MP1/CPauseScreenBlur.hpp index 1aa04d242..26f2fc8f2 100644 --- a/Runtime/MP1/CPauseScreenBlur.hpp +++ b/Runtime/MP1/CPauseScreenBlur.hpp @@ -7,7 +7,7 @@ #include "Runtime/Graphics/Shaders/CScanLinesFilter.hpp" #include "Runtime/MP1/CInGameGuiManagerCommon.hpp" -namespace urde { +namespace metaforce { class CStateManager; namespace MP1 { @@ -40,4 +40,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CPlayMovie.cpp b/Runtime/MP1/CPlayMovie.cpp index fcffdaf28..2405b6762 100644 --- a/Runtime/MP1/CPlayMovie.cpp +++ b/Runtime/MP1/CPlayMovie.cpp @@ -1,6 +1,6 @@ #include "Runtime/MP1/CPlayMovie.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { const char* kMovies[] = {"Video/wingame.thp", "Video/wingame_best.thp", "Video/wingame_best.thp", "Video/losegame.thp", "Video/05_tallonText.thp", "Video/AfterCredits.thp", @@ -12,4 +12,4 @@ CPlayMovie::CPlayMovie(EWhichMovie which) : CPlayMovieBase("CPlayMovie", kMovies (void)x18_which; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CPlayMovie.hpp b/Runtime/MP1/CPlayMovie.hpp index c0b5dd0ee..f83430333 100644 --- a/Runtime/MP1/CPlayMovie.hpp +++ b/Runtime/MP1/CPlayMovie.hpp @@ -3,7 +3,7 @@ #include "Runtime/CPlayMovieBase.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CPlayMovie : public CPlayMovieBase { public: @@ -31,4 +31,4 @@ public: explicit CPlayMovie(EWhichMovie which); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CPlayerVisor.cpp b/Runtime/MP1/CPlayerVisor.cpp index 63df9d604..426b66a18 100644 --- a/Runtime/MP1/CPlayerVisor.cpp +++ b/Runtime/MP1/CPlayerVisor.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CPlayerVisor::CPlayerVisor(CStateManager&) : x108_newScanPane(EFilterType::Blend, CGraphics::g_SpareTexture.get_color(0)) { @@ -670,4 +670,4 @@ float CPlayerVisor::GetDesiredViewportScaleY(const CStateManager& mgr) const { return mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::Combat ? 1.f : xc8_vpScaleY; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CPlayerVisor.hpp b/Runtime/MP1/CPlayerVisor.hpp index 594b999d8..6d3f14258 100644 --- a/Runtime/MP1/CPlayerVisor.hpp +++ b/Runtime/MP1/CPlayerVisor.hpp @@ -11,7 +11,7 @@ #include -namespace urde { +namespace metaforce { class CStateManager; class CTargetingManager; @@ -92,4 +92,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CPreFrontEnd.cpp b/Runtime/MP1/CPreFrontEnd.cpp index b9f7d5ee7..e21ec0c66 100644 --- a/Runtime/MP1/CPreFrontEnd.cpp +++ b/Runtime/MP1/CPreFrontEnd.cpp @@ -4,7 +4,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CPreFrontEnd::CPreFrontEnd() : CIOWin("Pre front-end window") {} @@ -28,4 +28,4 @@ CIOWin::EMessageReturn CPreFrontEnd::OnMessage(const CArchitectureMessage& msg, return EMessageReturn::RemoveIOWinAndExit; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CPreFrontEnd.hpp b/Runtime/MP1/CPreFrontEnd.hpp index 54a2c02f8..3e955553e 100644 --- a/Runtime/MP1/CPreFrontEnd.hpp +++ b/Runtime/MP1/CPreFrontEnd.hpp @@ -2,7 +2,7 @@ #include "Runtime/CIOWin.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CPreFrontEnd : public CIOWin { bool x14_resourceTweaksRegistered = false; @@ -12,4 +12,4 @@ public: EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CQuitGameScreen.cpp b/Runtime/MP1/CQuitGameScreen.cpp index 39e660c67..9b1a66d83 100644 --- a/Runtime/MP1/CQuitGameScreen.cpp +++ b/Runtime/MP1/CQuitGameScreen.cpp @@ -14,7 +14,7 @@ #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" #include "Runtime/GuiSys/CStringTable.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::array Titles{24, 25, 26, 27, 28}; @@ -117,4 +117,4 @@ CQuitGameScreen::CQuitGameScreen(EQuitType tp) : x0_type(tp) { m_blackScreen.emplace(EFilterType::Blend); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CQuitGameScreen.hpp b/Runtime/MP1/CQuitGameScreen.hpp index ea339d06a..7cf7deeab 100644 --- a/Runtime/MP1/CQuitGameScreen.hpp +++ b/Runtime/MP1/CQuitGameScreen.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/Shaders/CColoredQuadFilter.hpp" -namespace urde { +namespace metaforce { struct CFinalInput; class CGuiFrame; class CGuiTableGroup; @@ -40,4 +40,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CSamusDoll.cpp b/Runtime/MP1/CSamusDoll.cpp index 8a6bd617b..fbe974d77 100644 --- a/Runtime/MP1/CSamusDoll.cpp +++ b/Runtime/MP1/CSamusDoll.cpp @@ -16,7 +16,7 @@ #include #include -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array, 8> SpiderBallGlassModels{{ {"SamusSpiderBallGlassCMDL", 0}, @@ -660,4 +660,4 @@ void CSamusDoll::BeginViewInterpolate(bool zoomIn) { x80_fixedZoom = zoomIn ? -2.2f : -3.6f; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CSamusDoll.hpp b/Runtime/MP1/CSamusDoll.hpp index 48ac340e3..756579e6e 100644 --- a/Runtime/MP1/CSamusDoll.hpp +++ b/Runtime/MP1/CSamusDoll.hpp @@ -18,7 +18,7 @@ #include #include -namespace urde { +namespace metaforce { class CDependencyGroup; namespace MP1 { @@ -111,4 +111,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CSamusFaceReflection.cpp b/Runtime/MP1/CSamusFaceReflection.cpp index 5754dd92c..430397d27 100644 --- a/Runtime/MP1/CSamusFaceReflection.cpp +++ b/Runtime/MP1/CSamusFaceReflection.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { static const zeus::CTransform PreXf = zeus::CTransform::Scale(0.3f) * zeus::CTransform::Translate(0.f, 0.5f, 0.f); @@ -102,4 +102,4 @@ void CSamusFaceReflection::Update(float dt, const CStateManager& mgr, CRandom16& } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CSamusFaceReflection.hpp b/Runtime/MP1/CSamusFaceReflection.hpp index e44fb60b8..fa2ed5f1f 100644 --- a/Runtime/MP1/CSamusFaceReflection.hpp +++ b/Runtime/MP1/CSamusFaceReflection.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CSamusFaceReflection { CModelData x0_modelData; @@ -25,4 +25,4 @@ public: void Update(float dt, const CStateManager& stateMgr, CRandom16& rand); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CSamusHud.cpp b/Runtime/MP1/CSamusHud.cpp index fdef4b36b..0555e2a80 100644 --- a/Runtime/MP1/CSamusHud.cpp +++ b/Runtime/MP1/CSamusHud.cpp @@ -15,7 +15,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CSamusHud* CSamusHud::g_SamusHud = nullptr; @@ -1653,4 +1653,4 @@ void CSamusHud::InternalDeferHintMemo(CAssetId strg, u32 strgIdx, const CHUDMemo x554_hudMemoIdx = strgIdx; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CSamusHud.hpp b/Runtime/MP1/CSamusHud.hpp index 136556e03..f8ca033bb 100644 --- a/Runtime/MP1/CSamusHud.hpp +++ b/Runtime/MP1/CSamusHud.hpp @@ -28,7 +28,7 @@ #include #include -namespace urde { +namespace metaforce { class CGuiFrame; class CGuiLight; class CStateManager; @@ -237,4 +237,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CSaveGameScreen.cpp b/Runtime/MP1/CSaveGameScreen.cpp index ce89e4183..223986c0d 100644 --- a/Runtime/MP1/CSaveGameScreen.cpp +++ b/Runtime/MP1/CSaveGameScreen.cpp @@ -10,7 +10,7 @@ #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { using EState = CMemoryCardDriver::EState; using EError = CMemoryCardDriver::EError; @@ -634,4 +634,4 @@ std::unique_ptr CSaveGameScreen::ConstructCardDriver(bool imp g_ResFactory->GetResourceIdByName("TXTR_SaveIcon1")->id, importPersistent); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CSaveGameScreen.hpp b/Runtime/MP1/CSaveGameScreen.hpp index db3ed27c5..61f3b1692 100644 --- a/Runtime/MP1/CSaveGameScreen.hpp +++ b/Runtime/MP1/CSaveGameScreen.hpp @@ -9,7 +9,7 @@ #include "Runtime/MP1/CMemoryCardDriver.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CGuiTableGroup; class CGuiTextPane; class CSaveWorld; @@ -109,4 +109,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CSlideShow.cpp b/Runtime/MP1/CSlideShow.cpp index 12b86fa14..c94b5964c 100644 --- a/Runtime/MP1/CSlideShow.cpp +++ b/Runtime/MP1/CSlideShow.cpp @@ -5,7 +5,7 @@ #include "Editor/ProjectManager.hpp" #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { namespace { bool AreAllDepsLoaded(const std::vector>& deps) { return std::all_of(deps.cbegin(), deps.cend(), [](const auto& dep) { return dep.IsLoaded(); }); @@ -152,4 +152,4 @@ u32 CSlideShow::SlideShowGalleryFlags() { return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CSlideShow.hpp b/Runtime/MP1/CSlideShow.hpp index 0c6d9ecab..706375ddc 100644 --- a/Runtime/MP1/CSlideShow.hpp +++ b/Runtime/MP1/CSlideShow.hpp @@ -16,7 +16,7 @@ #include #include -namespace urde { +namespace metaforce { class CTexture; class CSlideShow : public CIOWin { @@ -108,4 +108,4 @@ public: static u32 SlideShowGalleryFlags(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CSplashScreen.cpp b/Runtime/MP1/CSplashScreen.cpp index 316071f77..7baf77840 100644 --- a/Runtime/MP1/CSplashScreen.cpp +++ b/Runtime/MP1/CSplashScreen.cpp @@ -5,7 +5,7 @@ #include "CArchitectureMessage.hpp" #include "zeus/CColor.hpp" -namespace urde { +namespace metaforce { extern CSimplePool* g_simplePool; namespace MP1 { static const char* SplashTextures[] = {"TXTR_NintendLogo", "TXTR_RetroLogo", "TXTR_DolbyLogo"}; @@ -64,4 +64,4 @@ void CSplashScreen::Draw() const { } } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/CSplashScreen.hpp b/Runtime/MP1/CSplashScreen.hpp index b0f8a27eb..38e249883 100644 --- a/Runtime/MP1/CSplashScreen.hpp +++ b/Runtime/MP1/CSplashScreen.hpp @@ -3,7 +3,7 @@ #include "CIOWin.hpp" #include "CToken.hpp" -namespace urde { +namespace metaforce { class CTexture; namespace MP1 { class CSplashScreen : public CIOWin { diff --git a/Runtime/MP1/CStateSetterFlow.cpp b/Runtime/MP1/CStateSetterFlow.cpp index 3ebcedb74..6a9e69870 100644 --- a/Runtime/MP1/CStateSetterFlow.cpp +++ b/Runtime/MP1/CStateSetterFlow.cpp @@ -4,7 +4,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/MP1/MP1.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CStateSetterFlow::CStateSetterFlow() : CIOWin("") {} @@ -50,4 +50,4 @@ CIOWin::EMessageReturn CStateSetterFlow::OnMessage(const CArchitectureMessage& m return EMessageReturn::Exit; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CStateSetterFlow.hpp b/Runtime/MP1/CStateSetterFlow.hpp index 25e1a1d85..6ca7c81f6 100644 --- a/Runtime/MP1/CStateSetterFlow.hpp +++ b/Runtime/MP1/CStateSetterFlow.hpp @@ -2,7 +2,7 @@ #include "Runtime/CIOWin.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CStateSetterFlow : public CIOWin { public: @@ -10,4 +10,4 @@ public: EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CTweaks.cpp b/Runtime/MP1/CTweaks.cpp index fb9d86943..8343ffb39 100644 --- a/Runtime/MP1/CTweaks.cpp +++ b/Runtime/MP1/CTweaks.cpp @@ -21,7 +21,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { static logvisor::Module Log("MP1::CTweaks"); @@ -134,4 +134,4 @@ void CTweaks::RegisterResourceTweaks(hecl::CVarManager* cvarMgr) { g_tweakPlayerRes->initCVars(cvarMgr); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/CTweaks.hpp b/Runtime/MP1/CTweaks.hpp index c9977e523..0a0770fa9 100644 --- a/Runtime/MP1/CTweaks.hpp +++ b/Runtime/MP1/CTweaks.hpp @@ -6,7 +6,7 @@ namespace hecl { class CVarManager; } -namespace urde { +namespace metaforce { namespace MP1 { @@ -17,4 +17,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 4cf293b30..bda58d2ef 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -35,6 +35,7 @@ #include "Runtime/Particle/CParticleSwooshDataFactory.hpp" #include "Runtime/Particle/CProjectileWeaponDataFactory.hpp" #include "Runtime/Particle/CWeaponDescription.hpp" +#include "Runtime/World/CPatterned.hpp" #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CStateMachine.hpp" #include "Runtime/World/CScriptMazeNode.hpp" @@ -49,7 +50,7 @@ #include #endif -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { struct AudioGroupInfo { const char* name; @@ -355,6 +356,7 @@ void CMain::InitializeSubsystems() { CAnimData::InitializeCache(); CDecalManager::Initialize(); CGBASupport::Initialize(); + CPatterned::Initialize(); } void CMain::MemoryCardInitializePump() { @@ -401,7 +403,7 @@ void CMain::Give(hecl::Console* console, const std::vector& args) { std::shared_ptr pState = g_GameState->GetPlayerState(); if (type == "all") { for (u32 item = 0; item < u32(CPlayerState::EItemType::Max); ++item) { - pState->ReInitalizePowerUp(CPlayerState::EItemType(item), + pState->ReInitializePowerUp(CPlayerState::EItemType(item), CPlayerState::GetPowerUpMaxValue(CPlayerState::EItemType(item))); pState->IncrPickup(CPlayerState::EItemType(item), CPlayerState::GetPowerUpMaxValue(CPlayerState::EItemType(item))); @@ -437,9 +439,9 @@ void CMain::Give(hecl::Console* console, const std::vector& args) { /* Handle special case with Missiles */ if (eType == CPlayerState::EItemType::Missiles) { u32 tmp = ((u32(itemAmt) / 5) + (itemAmt % 5)) * 5; - pState->ReInitalizePowerUp(eType, tmp); + pState->ReInitializePowerUp(eType, tmp); } else { - pState->ReInitalizePowerUp(eType, itemAmt); + pState->ReInitializePowerUp(eType, itemAmt); } } @@ -471,7 +473,7 @@ void CMain::Remove(hecl::Console*, const std::vector& args) { } else { CPlayerState::EItemType eType = CPlayerState::ItemNameToType(type); if (eType != CPlayerState::EItemType::Invalid) { - pState->ReInitalizePowerUp(eType, 0); + pState->ReInitializePowerUp(eType, 0); if (g_StateManager != nullptr) { g_StateManager->Player()->AsyncLoadSuit(*g_StateManager); } @@ -1026,4 +1028,4 @@ int CMain::appMain(boo::IApplication* app) { #endif -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index 1389b5eb6..f3bfef7be 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -42,7 +42,7 @@ struct DiscordUser; -namespace urde { +namespace metaforce { class IFactory; class IObjectStore; @@ -253,7 +253,7 @@ private: bool m_firstFrame = true; using delta_clock = std::chrono::high_resolution_clock; std::chrono::time_point m_prevFrameTime; - DataSpec::URDEVersionInfo m_version; + DataSpec::MetaforceVersionInfo m_version; CCameraFilterPass m_alphaPass; void InitializeSubsystems(); @@ -338,4 +338,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CActorContraption.cpp b/Runtime/MP1/World/CActorContraption.cpp index 17cd3bb1f..a516c35f1 100644 --- a/Runtime/MP1/World/CActorContraption.cpp +++ b/Runtime/MP1/World/CActorContraption.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { MP1::CActorContraption::CActorContraption(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const zeus::CAABox& aabox, @@ -101,4 +101,4 @@ CFlameThrower* MP1::CActorContraption::CreateFlameThrower(std::string_view name, mgr.AddObject(ret); return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CActorContraption.hpp b/Runtime/MP1/World/CActorContraption.hpp index ede6bba12..a120663c9 100644 --- a/Runtime/MP1/World/CActorContraption.hpp +++ b/Runtime/MP1/World/CActorContraption.hpp @@ -7,7 +7,7 @@ #include "Runtime/World/CDamageInfo.hpp" #include "Runtime/World/CScriptActor.hpp" -namespace urde { +namespace metaforce { class CFlameThrower; namespace MP1 { class CActorContraption : public CScriptActor { @@ -31,4 +31,4 @@ public: void ResetFlameThrowers(CStateManager& mgr); }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CAtomicAlpha.cpp b/Runtime/MP1/World/CAtomicAlpha.cpp index 11dd29f66..63a62cad3 100644 --- a/Runtime/MP1/World/CAtomicAlpha.cpp +++ b/Runtime/MP1/World/CAtomicAlpha.cpp @@ -9,7 +9,7 @@ #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::array skBombLocators{ "bomb1_LCTR"sv, "bomb2_LCTR"sv, @@ -163,4 +163,4 @@ void CAtomicAlpha::Attack(CStateManager& mgr, EStateMsg msg, float) { x450_bodyController->SetLocomotionType(pas::ELocomotionType::Relaxed); } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CAtomicAlpha.hpp b/Runtime/MP1/World/CAtomicAlpha.hpp index d69a79f58..7d4316541 100644 --- a/Runtime/MP1/World/CAtomicAlpha.hpp +++ b/Runtime/MP1/World/CAtomicAlpha.hpp @@ -7,7 +7,7 @@ #include "Runtime/World/CPatterned.hpp" #include "Runtime/World/CPathFindSearch.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CAtomicAlpha : public CPatterned { static constexpr u32 skBombCount = 4; struct SBomb { @@ -60,4 +60,4 @@ public: CProjectileInfo* GetProjectileInfo() override { return &x668_bombProjectile; } }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CAtomicBeta.cpp b/Runtime/MP1/World/CAtomicBeta.cpp index 43e5e3e56..c614f5178 100644 --- a/Runtime/MP1/World/CAtomicBeta.cpp +++ b/Runtime/MP1/World/CAtomicBeta.cpp @@ -10,7 +10,7 @@ #include "Runtime/Weapon/CPlayerGun.hpp" #include "Runtime/World/CPlayer.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::array skBombLocators{ "bomb2_LCTR"sv, "bomb3_LCTR"sv, @@ -172,4 +172,4 @@ bool CAtomicBeta::IsPlayerBeamChargedEnough(const CStateManager& mgr) { const CPlayerGun* gun = mgr.GetPlayer().GetPlayerGun(); return (gun->IsCharging() ? gun->GetChargeBeamFactor() : 0.f) > 0.1f; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CAtomicBeta.hpp b/Runtime/MP1/World/CAtomicBeta.hpp index 2e8cd388a..5e7e87540 100644 --- a/Runtime/MP1/World/CAtomicBeta.hpp +++ b/Runtime/MP1/World/CAtomicBeta.hpp @@ -7,11 +7,11 @@ #include -namespace urde { +namespace metaforce { class CWeaponDescription; } -namespace urde::MP1 { +namespace metaforce::MP1 { class CAtomicBeta final : public CPatterned { static constexpr u32 kBombCount = 3; rstl::reserved_vector x568_projectileIds; @@ -63,4 +63,4 @@ public: void Death(CStateManager&, const zeus::CVector3f&, EScriptObjectState) override; static bool IsPlayerBeamChargedEnough(const CStateManager& mgr); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CBabygoth.cpp b/Runtime/MP1/World/CBabygoth.cpp index 6306aca84..a701a2082 100644 --- a/Runtime/MP1/World/CBabygoth.cpp +++ b/Runtime/MP1/World/CBabygoth.cpp @@ -22,7 +22,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::string_view skpMouthDamageJoint = "LCTR_SHEMOUTH"sv; constexpr std::array skSphereJointList{{ @@ -97,7 +97,7 @@ CBabygoth::CBabygoth(TUniqueId uid, std::string_view name, const CEntityInfo& in x460_knockBackController.SetEnableShock(true); x460_knockBackController.SetEnableExplodeDeath(true); x8d4_stepBackwardDist = - GetAnimationDistance(CPASAnimParmData(3, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(0))) * + GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::Step, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(0))) * GetModelData()->GetScale().y(); // B_backward_sheegoth xa08_noShellModel->SetLayoutInfo(GetModelData()->GetAnimationData()->GetModelData()->GetLayoutInfo()); MakeThermalColdAndHot(); @@ -1238,4 +1238,4 @@ bool CBabygoth::Listen(const zeus::CVector3f& origin, EListenNoiseType noiseType xa48_30_heardPlayerFire = true; return true; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CBabygoth.hpp b/Runtime/MP1/World/CBabygoth.hpp index adf19e027..c72534c26 100644 --- a/Runtime/MP1/World/CBabygoth.hpp +++ b/Runtime/MP1/World/CBabygoth.hpp @@ -9,12 +9,12 @@ #include "Runtime/World/CPathFindSearch.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde { +namespace metaforce { class CCollisionActorManager; class CWeaponDescription; -} // namespace urde +} // namespace metaforce -namespace urde::MP1 { +namespace metaforce::MP1 { struct CBabygothData { float x0_fireballAttackTime; float x4_fireballAttackTimeVariance; @@ -315,4 +315,4 @@ public: CProjectileInfo* GetProjectileInfo() override { return &x958_iceProjectile; } }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CBeetle.cpp b/Runtime/MP1/World/CBeetle.cpp index 350e5fd41..d7fccc917 100644 --- a/Runtime/MP1/World/CBeetle.cpp +++ b/Runtime/MP1/World/CBeetle.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CBeetle::CBeetle(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, CPatterned::EFlavorType flavor, @@ -32,10 +32,10 @@ CBeetle::CBeetle(TUniqueId uid, std::string_view name, const CEntityInfo& info, , x7ac_tailVuln(tailVuln) , x814_attackDelayTimer(initialAttackDelay) , x834_retreatTime(retreatTime) { - x5a0_headbuttDist = GetAnimationDistance(CPASAnimParmData(7, CPASAnimParm::FromEnum(0), CPASAnimParm::FromEnum(1))); + x5a0_headbuttDist = GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::MeleeAttack, CPASAnimParm::FromEnum(0), CPASAnimParm::FromEnum(1))); x5a4_jumpBackwardDist = x64_modelData->GetScale().y() * - GetAnimationDistance(CPASAnimParmData(3, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(0))); + GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::Step, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(0))); MakeThermalColdAndHot(); if (x3fc_flavor == EFlavorType::One) x460_knockBackController.SetLocomotionDuringElectrocution(true); @@ -983,4 +983,4 @@ CPathFindSearch* CBeetle::GetSearchPath() { return &x5fc_pathFindSearch; } float CBeetle::GetGravityConstant() const { return 4.f * CPhysicsActor::GravityConstant(); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CBeetle.hpp b/Runtime/MP1/World/CBeetle.hpp index cffd48f2a..962fcf097 100644 --- a/Runtime/MP1/World/CBeetle.hpp +++ b/Runtime/MP1/World/CBeetle.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { namespace MP1 { class CBeetle : public CPatterned { @@ -117,4 +117,4 @@ public: float GetGravityConstant() const override; }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CBloodFlower.cpp b/Runtime/MP1/World/CBloodFlower.cpp index 1991851f5..049cc63e3 100644 --- a/Runtime/MP1/World/CBloodFlower.cpp +++ b/Runtime/MP1/World/CBloodFlower.cpp @@ -12,7 +12,7 @@ #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CScriptTrigger.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CBloodFlower::CBloodFlower(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, CAssetId partId1, CAssetId wpscId1, const CActorParameters& actParms, CAssetId wpscId2, const CDamageInfo& dInfo1, @@ -268,4 +268,4 @@ CTargetableProjectile* CBloodFlower::CreateArcProjectile(CStateManager& mgr, con return targProj; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CBloodFlower.hpp b/Runtime/MP1/World/CBloodFlower.hpp index 294fc5b72..d7b0ca2a0 100644 --- a/Runtime/MP1/World/CBloodFlower.hpp +++ b/Runtime/MP1/World/CBloodFlower.hpp @@ -6,14 +6,14 @@ #include "Runtime/Weapon/CProjectileInfo.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde { +namespace metaforce { class CGenDescription; class CElementGen; class CWeaponDescription; class CTargetableProjectile; -} // namespace urde +} // namespace metaforce -namespace urde::MP1 { +namespace metaforce::MP1 { class CBloodFlower : public CPatterned { TLockedToken x568_podEffectDesc; std::unique_ptr x574_podEffect; @@ -69,4 +69,4 @@ public: void BulbAttack(CStateManager&, EStateMsg, float) override; void PodAttack(CStateManager&, EStateMsg, float) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CBouncyGrenade.cpp b/Runtime/MP1/World/CBouncyGrenade.cpp index fadbeff5a..42e3d650f 100644 --- a/Runtime/MP1/World/CBouncyGrenade.cpp +++ b/Runtime/MP1/World/CBouncyGrenade.cpp @@ -8,7 +8,7 @@ #include "Runtime/World/CPlayer.hpp" #include "Runtime/Collision/CCollisionActor.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CBouncyGrenade::CBouncyGrenade(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParams, TUniqueId parentId, const SBouncyGrenadeData& data, float velocity, @@ -18,16 +18,16 @@ CBouncyGrenade::CBouncyGrenade(TUniqueId uid, std::string_view name, const CEnti , x258_data(data) , x294_numBounces(data.GetNumBounces()) , x298_parentId(parentId) -, x2a0_elementGen1(std::make_unique(g_SimplePool->GetObj({'PART', data.GetElementGenId1()}))) -, x2a4_elementGen2(std::make_unique(g_SimplePool->GetObj({'PART', data.GetElementGenId2()}))) -, x2a8_elementGen3(std::make_unique(g_SimplePool->GetObj({'PART', data.GetElementGenId3()}))) +, x2a0_elementGenCombat(std::make_unique(g_SimplePool->GetObj({'PART', data.GetElementGenId1()}))) +, x2a4_elementGenXRay(std::make_unique(g_SimplePool->GetObj({'PART', data.GetElementGenId2()}))) +, x2a8_elementGenThermal(std::make_unique(g_SimplePool->GetObj({'PART', data.GetElementGenId3()}))) , x2ac_elementGen4(std::make_unique(g_SimplePool->GetObj({'PART', data.GetElementGenId4()}))) , x2b0_explodePlayerDistance(explodePlayerDistance) { SetMomentumWR({0.f, 0.f, -GravityConstant() * GetMass()}); SetVelocityWR(velocity * xf.frontVector()); - x2a0_elementGen1->SetParticleEmission(false); - x2a4_elementGen2->SetParticleEmission(false); - x2a8_elementGen3->SetParticleEmission(false); + x2a0_elementGenCombat->SetParticleEmission(false); + x2a4_elementGenXRay->SetParticleEmission(false); + x2a8_elementGenThermal->SetParticleEmission(false); x2ac_elementGen4->SetParticleEmission(true); CMaterialFilter filter = GetMaterialFilter(); filter.ExcludeList().Add(EMaterialTypes::Character); @@ -42,9 +42,9 @@ void CBouncyGrenade::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& } const auto visor = mgr.GetPlayerState()->GetActiveVisor(mgr); if (visor == CPlayerState::EPlayerVisor::Combat || visor == CPlayerState::EPlayerVisor::Scan) { - g_Renderer->AddParticleGen(*x2a0_elementGen1); + g_Renderer->AddParticleGen(*x2a0_elementGenCombat); } else if (visor == CPlayerState::EPlayerVisor::XRay || visor == CPlayerState::EPlayerVisor::Thermal) { - g_Renderer->AddParticleGen(*x2a8_elementGen3); + g_Renderer->AddParticleGen(*x2a8_elementGenThermal); } } @@ -103,7 +103,7 @@ void CBouncyGrenade::Render(CStateManager& mgr) { CElementGen::SetSubtractBlend(true); CElementGen::SetMoveRedToAlphaBuffer(true); CGraphics::SetFog(ERglFogMode::PerspLin, 0.f, 75.f, zeus::skBlack); - x2a4_elementGen2->Render(); + x2a4_elementGenXRay->Render(); mgr.SetupFogForArea(GetAreaIdAlways()); CElementGen::SetSubtractBlend(false); CElementGen::SetMoveRedToAlphaBuffer(false); @@ -115,7 +115,7 @@ void CBouncyGrenade::Think(float dt, CStateManager& mgr) { const zeus::CTransform& orientation = GetTransform().getRotation(); const zeus::CVector3f& translation = GetTranslation(); const zeus::CVector3f& scale = GetModelData()->GetScale(); - auto UpdateElementGen = [ orientation, translation, scale, dt ](CElementGen & gen) constexpr { + auto UpdateElementGen = [ orientation, translation, scale, dt ](CElementGen & gen) { gen.SetOrientation(orientation); gen.SetGlobalTranslation(translation); gen.SetGlobalScale(scale); @@ -123,9 +123,9 @@ void CBouncyGrenade::Think(float dt, CStateManager& mgr) { }; if (x2b4_24_exploded) { Stop(); - UpdateElementGen(*x2a0_elementGen1); - UpdateElementGen(*x2a4_elementGen2); - UpdateElementGen(*x2a8_elementGen3); + UpdateElementGen(*x2a0_elementGenCombat); + UpdateElementGen(*x2a4_elementGenXRay); + UpdateElementGen(*x2a8_elementGenThermal); } else { UpdateElementGen(*x2ac_elementGen4); } @@ -140,8 +140,8 @@ void CBouncyGrenade::Think(float dt, CStateManager& mgr) { Explode(mgr, kInvalidUniqueId); } } - if (x2a0_elementGen1->IsSystemDeletable() && x2a4_elementGen2->IsSystemDeletable() && - x2a8_elementGen3->IsSystemDeletable()) { + if (x2a0_elementGenCombat->IsSystemDeletable() && x2a4_elementGenXRay->IsSystemDeletable() && + x2a8_elementGenThermal->IsSystemDeletable()) { mgr.FreeScriptObject(GetUniqueId()); } } @@ -156,9 +156,9 @@ void CBouncyGrenade::Explode(CStateManager& mgr, TUniqueId uid) { x2b4_24_exploded = true; CSfxManager::AddEmitter(x258_data.GetExplodeSfx(), GetTranslation(), zeus::skUp, false, false, 0x7f, GetAreaIdAlways()); - x2a0_elementGen1->SetParticleEmission(true); - x2a4_elementGen2->SetParticleEmission(true); - x2a8_elementGen3->SetParticleEmission(true); + x2a0_elementGenCombat->SetParticleEmission(true); + x2a4_elementGenXRay->SetParticleEmission(true); + x2a8_elementGenThermal->SetParticleEmission(true); x2ac_elementGen4->SetParticleEmission(false); const CDamageInfo& dInfo = x258_data.GetDamageInfo(); @@ -207,4 +207,4 @@ void CBouncyGrenade::Explode(CStateManager& mgr, TUniqueId uid) { } } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CBouncyGrenade.hpp b/Runtime/MP1/World/CBouncyGrenade.hpp index c60aa7e1d..f3445791f 100644 --- a/Runtime/MP1/World/CBouncyGrenade.hpp +++ b/Runtime/MP1/World/CBouncyGrenade.hpp @@ -8,7 +8,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { struct SGrenadeVelocityInfo { private: float x0_mass; @@ -64,9 +64,9 @@ private: u32 x294_numBounces; TUniqueId x298_parentId; float x29c_ = 0.f; - std::unique_ptr x2a0_elementGen1; - std::unique_ptr x2a4_elementGen2; - std::unique_ptr x2a8_elementGen3; + std::unique_ptr x2a0_elementGenCombat; + std::unique_ptr x2a4_elementGenXRay; + std::unique_ptr x2a8_elementGenThermal; std::unique_ptr x2ac_elementGen4; float x2b0_explodePlayerDistance; bool x2b4_24_exploded : 1 = false; @@ -88,4 +88,4 @@ public: private: void Explode(CStateManager& mgr, TUniqueId uid); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CBurrower.cpp b/Runtime/MP1/World/CBurrower.cpp index 91f87ed92..b898c9980 100644 --- a/Runtime/MP1/World/CBurrower.cpp +++ b/Runtime/MP1/World/CBurrower.cpp @@ -11,7 +11,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr CDamageVulnerability skVulnerability{ EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, @@ -295,4 +295,4 @@ const std::optional>& CBurrower::GetDeathExplosion return x520_deathExplosionParticle; } -} // namespace urde::MP1 \ No newline at end of file +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CBurrower.hpp b/Runtime/MP1/World/CBurrower.hpp index 46dac3999..b0ad4dfcd 100644 --- a/Runtime/MP1/World/CBurrower.hpp +++ b/Runtime/MP1/World/CBurrower.hpp @@ -4,7 +4,7 @@ #include "Runtime/World/CPatterned.hpp" #include "Runtime/World/CPathFindSearch.hpp" -namespace urde { +namespace metaforce { class CElementGen; namespace MP1 { @@ -51,4 +51,4 @@ public: const std::optional>& GetDeathExplosionParticle() const override; }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CChozoGhost.cpp b/Runtime/MP1/World/CChozoGhost.cpp index a24be34a0..b6464c02d 100644 --- a/Runtime/MP1/World/CChozoGhost.cpp +++ b/Runtime/MP1/World/CChozoGhost.cpp @@ -13,7 +13,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CChozoGhost::CBehaveChance::CBehaveChance(CInputStream& in) : x0_propertyCount(in.readUint32Big()) , x4_lurk(in.readFloatBig()) @@ -105,11 +105,11 @@ CChozoGhost::CChozoGhost(TUniqueId uid, std::string_view name, const CEntityInfo x578_.Token().Lock(); x5a0_.Token().Lock(); x668_ = GetModelData()->GetScale().z() * - GetAnimationDistance(CPASAnimParmData(13, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(0))); + GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(0))); x66c_ = GetModelData()->GetScale().z() * - GetAnimationDistance(CPASAnimParmData(15, CPASAnimParm::FromEnum(1), CPASAnimParm::FromReal32(90.f))); + GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::Slide, CPASAnimParm::FromEnum(1), CPASAnimParm::FromReal32(90.f))); x670_ = GetModelData()->GetScale().z() * - GetAnimationDistance(CPASAnimParmData(7, CPASAnimParm::FromEnum(2), CPASAnimParm::FromEnum(1))); + GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::MeleeAttack, CPASAnimParm::FromEnum(2), CPASAnimParm::FromEnum(1))); if (projectileVisorEffect.IsValid()) x640_projectileVisor = g_SimplePool->GetObj({SBIG('PART'), projectileVisorEffect}); @@ -759,4 +759,4 @@ void CChozoGhost::FindBestAnchor(CStateManager& mgr) { x2e0_destPos = GetTranslation(); } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CChozoGhost.hpp b/Runtime/MP1/World/CChozoGhost.hpp index f698674d9..35d024e82 100644 --- a/Runtime/MP1/World/CChozoGhost.hpp +++ b/Runtime/MP1/World/CChozoGhost.hpp @@ -9,7 +9,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { enum class EBehaveType { Lurk, Taunt, Attack, Move, None }; class CChozoGhost : public CPatterned { @@ -149,4 +149,4 @@ public: float GetGravityConstant() const override { return 60.f; } CProjectileInfo* GetProjectileInfo() override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CDrone.cpp b/Runtime/MP1/World/CDrone.cpp index 40f68b3bc..abc0a17c2 100644 --- a/Runtime/MP1/World/CDrone.cpp +++ b/Runtime/MP1/World/CDrone.cpp @@ -23,7 +23,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { CDrone::CDrone(TUniqueId uid, std::string_view name, EFlavorType flavor, const CEntityInfo& info, const zeus::CTransform& xf, float f1, CModelData&& mData, const CPatternedInfo& pInfo, const CActorParameters& actParms, EMovementType movement, EColliderType colliderType, EBodyType bodyType, @@ -1184,4 +1184,4 @@ void CDrone::Dead(CStateManager& mgr, EStateMsg msg, float arg) { } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CDrone.hpp b/Runtime/MP1/World/CDrone.hpp index a27cbbb0e..ba2d6e109 100644 --- a/Runtime/MP1/World/CDrone.hpp +++ b/Runtime/MP1/World/CDrone.hpp @@ -5,7 +5,7 @@ #include "Runtime/World/CPathFindSearch.hpp" #include "Runtime/World/CVisorFlare.hpp" -namespace urde { +namespace metaforce { class CWeaponDescription; namespace MP1 { class CDrone : public CPatterned { @@ -176,4 +176,4 @@ public: virtual int sub_8015f150() { return 3; } }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CDroneLaser.cpp b/Runtime/MP1/World/CDroneLaser.cpp index 848eb7a8c..2caf94e92 100644 --- a/Runtime/MP1/World/CDroneLaser.cpp +++ b/Runtime/MP1/World/CDroneLaser.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CDroneLaser::CDroneLaser(TUniqueId uid, TAreaId aId, const zeus::CTransform& xf, CAssetId particle) : CActor(uid, true, "DroneLaser"sv, CEntityInfo(aId, CEntity::NullConnectionList), xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic), CActorParameters::None().HotInThermal(true), kInvalidUniqueId) @@ -86,4 +86,4 @@ void CDroneLaser::sub_80167754(CStateManager& mgr, const zeus::CVector3f& pos, c x104_beamParticle->SetTranslation(pos); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CDroneLaser.hpp b/Runtime/MP1/World/CDroneLaser.hpp index e415025f6..b4b497cb4 100644 --- a/Runtime/MP1/World/CDroneLaser.hpp +++ b/Runtime/MP1/World/CDroneLaser.hpp @@ -1,7 +1,7 @@ #pragma once #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CElementGen; namespace MP1 { class CDroneLaser : public CActor { @@ -25,4 +25,4 @@ public: void sub_80167754(CStateManager& mgr, const zeus::CVector3f& pos, const zeus::CVector3f& look); }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CElitePirate.cpp b/Runtime/MP1/World/CElitePirate.cpp index 82bbe2973..867c0f08e 100644 --- a/Runtime/MP1/World/CElitePirate.cpp +++ b/Runtime/MP1/World/CElitePirate.cpp @@ -19,7 +19,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array skLeftArmJointList{{ {"L_shoulder", "L_elbow", 1.f, 1.5f}, @@ -1213,4 +1213,4 @@ void CElitePirate::SPositionHistory::AddValue(const zeus::CVector3f& pos) { x4_values.emplace_back(pos); } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CElitePirate.hpp b/Runtime/MP1/World/CElitePirate.hpp index 7155947ab..df40598a2 100644 --- a/Runtime/MP1/World/CElitePirate.hpp +++ b/Runtime/MP1/World/CElitePirate.hpp @@ -10,7 +10,7 @@ #include "Runtime/World/CPathFindSearch.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CElitePirateData { private: float x0_tauntInterval; @@ -243,4 +243,4 @@ private: const zeus::CVector3f& projectilePos) const; void ShakeCamera(CStateManager& mgr); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CEnergyBall.cpp b/Runtime/MP1/World/CEnergyBall.cpp index dc0e1377e..18a1a3f64 100644 --- a/Runtime/MP1/World/CEnergyBall.cpp +++ b/Runtime/MP1/World/CEnergyBall.cpp @@ -6,7 +6,7 @@ #include "Runtime/World/CPatternedInfo.hpp" #include "Runtime/World/CPlayer.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CEnergyBall::CEnergyBall(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms, const CPatternedInfo& pInfo, s32 w1, float f1, const CDamageInfo& dInfo1, float f2, const CAssetId& a1, s16 sfxId1, diff --git a/Runtime/MP1/World/CEnergyBall.hpp b/Runtime/MP1/World/CEnergyBall.hpp index 2333b9c4c..6bcd59cfe 100644 --- a/Runtime/MP1/World/CEnergyBall.hpp +++ b/Runtime/MP1/World/CEnergyBall.hpp @@ -7,7 +7,7 @@ #include "Runtime/World/CDamageInfo.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CEnergyBall : public CPatterned { CSteeringBehaviors x568_steeringBehaviors; float x56c_ = 0.f; diff --git a/Runtime/MP1/World/CEyeball.cpp b/Runtime/MP1/World/CEyeball.cpp index 5ed3ebd6c..7c723e130 100644 --- a/Runtime/MP1/World/CEyeball.cpp +++ b/Runtime/MP1/World/CEyeball.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::string_view skEyeLocator = "Laser_LCTR"sv; CEyeball::CEyeball(TUniqueId uid, std::string_view name, CPatterned::EFlavorType flavor, const CEntityInfo& info, @@ -247,4 +247,4 @@ void CEyeball::Death(CStateManager& mgr, const zeus::CVector3f& pos, EScriptObje CPatterned::Death(mgr, pos, state); SetTransform(oldXf); } -} // namespace urde::MP1 \ No newline at end of file +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CEyeball.hpp b/Runtime/MP1/World/CEyeball.hpp index cbfc0176e..8204d5293 100644 --- a/Runtime/MP1/World/CEyeball.hpp +++ b/Runtime/MP1/World/CEyeball.hpp @@ -10,7 +10,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CEyeball : public CPatterned { float x568_attackDelay; float x56c_attackStartTime; @@ -64,4 +64,4 @@ public: bool ShouldAttack(CStateManager&, float) override { return x60c_26_alert; } bool ShouldFire(CStateManager&, float) override { return !x60c_27_attackDisabled; } }; -} // namespace urde::MP1 \ No newline at end of file +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CFireFlea.cpp b/Runtime/MP1/World/CFireFlea.cpp index d57cdf1bf..4b5b2d161 100644 --- a/Runtime/MP1/World/CFireFlea.cpp +++ b/Runtime/MP1/World/CFireFlea.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr zeus::CColor skEndFadeColor{1.f, 1.f, 0.5f, 1.f}; constexpr zeus::CColor skStartFadeColor{1.f, 0.f, 0.f, 0.f}; @@ -97,7 +97,7 @@ bool CFireFlea::InPosition(CStateManager& mgr, float dt) { return (xd80_targetPos - GetTranslation()).magnitude() < 25.f; } -bool CFireFlea::HearShot(urde::CStateManager& mgr, float arg) { +bool CFireFlea::HearShot(metaforce::CStateManager& mgr, float arg) { x570_nearList.clear(); mgr.BuildNearList(x570_nearList, zeus::CAABox(GetTranslation() - 10.f, GetTranslation() + 10.f), CMaterialFilter::MakeInclude({EMaterialTypes::Projectile}), nullptr); @@ -211,4 +211,4 @@ void CFireFlea::Flee(CStateManager& mgr, EStateMsg msg, float) { x450_bodyController->SetLocomotionType(pas::ELocomotionType::Relaxed); } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFireFlea.hpp b/Runtime/MP1/World/CFireFlea.hpp index d95b0d59e..cfae4dd7a 100644 --- a/Runtime/MP1/World/CFireFlea.hpp +++ b/Runtime/MP1/World/CFireFlea.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CFireFlea : public CPatterned { class CDeathCameraEffect : public CEntity { u32 x34_ = 13; @@ -53,4 +53,4 @@ public: void Flee(CStateManager&, EStateMsg, float) override; CPathFindSearch* GetSearchPath() override { return &xd8c_pathFind; } }; -} // namespace urde::MP1 \ No newline at end of file +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CFlaahgra.cpp b/Runtime/MP1/World/CFlaahgra.cpp index 36af39252..d06db8fd0 100644 --- a/Runtime/MP1/World/CFlaahgra.cpp +++ b/Runtime/MP1/World/CFlaahgra.cpp @@ -21,7 +21,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr zeus::CColor skFlaahgraDamageColor{0.5f, 0.5f, 0.f, 1.f}; constexpr zeus::CColor skUnkColor{0.5f, 0.f, 0.f, 1.f}; constexpr zeus::CVector3f skUnkVec1{0.5f, 7.f, 0.f}; @@ -1433,4 +1433,4 @@ std::optional CFlaahgraPlants::GetTouchBounds() const { } return x110_aabox; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFlaahgra.hpp b/Runtime/MP1/World/CFlaahgra.hpp index d3ded2b4c..2f1e0ac92 100644 --- a/Runtime/MP1/World/CFlaahgra.hpp +++ b/Runtime/MP1/World/CFlaahgra.hpp @@ -18,15 +18,15 @@ #include #include -namespace urde { +namespace metaforce { class CBoneTracking; class CCollisionActorManager; class CDependencyGroup; class CElementGen; class CGenDescription; -} // namespace urde +} // namespace metaforce -namespace urde::MP1 { +namespace metaforce::MP1 { class CFlaahgraData { friend class CFlaahgra; float x0_; @@ -242,4 +242,4 @@ public: void SpecialAttack(CStateManager&, EStateMsg, float) override; void Enraged(CStateManager&, EStateMsg, float) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFlaahgraProjectile.cpp b/Runtime/MP1/World/CFlaahgraProjectile.cpp index e84492835..e226621a4 100644 --- a/Runtime/MP1/World/CFlaahgraProjectile.cpp +++ b/Runtime/MP1/World/CFlaahgraProjectile.cpp @@ -3,7 +3,7 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/World/CPlayer.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CFlaahgraProjectile::CFlaahgraProjectile(bool bigStrike, const TToken& desc, const zeus::CTransform& xf, const CDamageInfo& damage, TUniqueId uid, @@ -26,4 +26,4 @@ void CFlaahgraProjectile::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId se } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFlaahgraProjectile.hpp b/Runtime/MP1/World/CFlaahgraProjectile.hpp index b7444a1fc..0a593e2ca 100644 --- a/Runtime/MP1/World/CFlaahgraProjectile.hpp +++ b/Runtime/MP1/World/CFlaahgraProjectile.hpp @@ -2,7 +2,7 @@ #include "Runtime/Weapon/CEnergyProjectile.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CFlaahgraProjectile : public CEnergyProjectile { bool x3d8_bigStrike; @@ -14,4 +14,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager &mgr) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFlaahgraTentacle.cpp b/Runtime/MP1/World/CFlaahgraTentacle.cpp index 810a23cd9..f4c58726d 100644 --- a/Runtime/MP1/World/CFlaahgraTentacle.cpp +++ b/Runtime/MP1/World/CFlaahgraTentacle.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::string_view skpTentacleTip = "Arm_12"sv; constexpr std::array skJointList{{ @@ -272,4 +272,4 @@ void CFlaahgraTentacle::Death(CStateManager& mgr, const zeus::CVector3f& directi x400_25_alive = false; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFlaahgraTentacle.hpp b/Runtime/MP1/World/CFlaahgraTentacle.hpp index fc2ca11e8..c0da6d480 100644 --- a/Runtime/MP1/World/CFlaahgraTentacle.hpp +++ b/Runtime/MP1/World/CFlaahgraTentacle.hpp @@ -9,7 +9,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CFlaahgraTentacle : public CPatterned { s32 x568_ = -1; std::unique_ptr x56c_collisionManager; @@ -53,4 +53,4 @@ public: void InActive(CStateManager&, EStateMsg, float) override; void Death(CStateManager& mgr, const zeus::CVector3f& direction, EScriptObjectState state) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFlickerBat.cpp b/Runtime/MP1/World/CFlickerBat.cpp index 665a41b9b..7d673675f 100644 --- a/Runtime/MP1/World/CFlickerBat.cpp +++ b/Runtime/MP1/World/CFlickerBat.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CFlickerBat::CFlickerBat(TUniqueId uid, std::string_view name, CPatterned::EFlavorType flavor, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, @@ -250,4 +250,4 @@ void CFlickerBat::ToggleVisible(CStateManager& mgr) { x578_fadeRemTime = 1.f; x57c_ooFadeDur = 1.f / x578_fadeRemTime; } -} // namespace urde::MP1 \ No newline at end of file +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CFlickerBat.hpp b/Runtime/MP1/World/CFlickerBat.hpp index dc1705324..d064e62cd 100644 --- a/Runtime/MP1/World/CFlickerBat.hpp +++ b/Runtime/MP1/World/CFlickerBat.hpp @@ -2,7 +2,7 @@ #include "Runtime/World/CPatterned.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CFlickerBat final : public CPatterned { public: enum class EFlickerBatState { Visible, Hidden, FadeIn, FadeOut }; @@ -48,4 +48,4 @@ public: void FlickerBatStateChanged(EFlickerBatState, CStateManager&); void CheckStaticIntersection(CStateManager&); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFlyingPirate.cpp b/Runtime/MP1/World/CFlyingPirate.cpp index 5d3e0e0a0..5726d897c 100644 --- a/Runtime/MP1/World/CFlyingPirate.cpp +++ b/Runtime/MP1/World/CFlyingPirate.cpp @@ -19,7 +19,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array skBurstsFlying{{ {4, {3, 4, 11, 12, -1, 0, 0, 0}, 0.1f, 0.05f}, @@ -322,7 +322,7 @@ CFlyingPirate::CFlyingPirate(TUniqueId uid, std::string_view name, const CEntity x864_missileSegments.push_back(animData->GetLocatorSegId("L_Missile_LCTR"sv)); x864_missileSegments.push_back(animData->GetLocatorSegId("R_Missile_LCTR"sv)); x850_height = modelData->GetScale().x() * - GetAnimationDistance(CPASAnimParmData{3, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(1)}); + GetAnimationDistance(CPASAnimParmData{pas::EAnimationState::Step, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(1)}); if (x568_data.xd8_particleGen1.IsValid() && x568_data.xdc_particleGen2.IsValid() && x568_data.xe0_particleGen3.IsValid()) { x65c_particleGenDescs.push_back(g_SimplePool->GetObj({SBIG('PART'), x568_data.xd8_particleGen1})); @@ -747,7 +747,7 @@ void CFlyingPirate::FireProjectile(CStateManager& mgr, float dt) { } if (projectileFired) { const std::pair anim = x450_bodyController->GetPASDatabase().FindBestAnimation( - CPASAnimParmData{24, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); + CPASAnimParmData{pas::EAnimationState::AdditiveReaction, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); if (anim.first > 0.f) { GetModelData()->GetAnimationData()->AddAdditiveAnimation(anim.second, 1.f, false, true); } @@ -1705,4 +1705,4 @@ void CFlyingPirate::Think(float dt, CStateManager& mgr) { } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CFlyingPirate.hpp b/Runtime/MP1/World/CFlyingPirate.hpp index 18bc5d9ec..f3d9b6c06 100644 --- a/Runtime/MP1/World/CFlyingPirate.hpp +++ b/Runtime/MP1/World/CFlyingPirate.hpp @@ -9,7 +9,7 @@ #include "Runtime/World/CPathFindSearch.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { enum class EFlyingPirateType : u32 { FlyingPirate = 1, AquaPirate = 2, @@ -215,4 +215,4 @@ private: void AddToTeam(CStateManager& mgr); void RemoveFromTeam(CStateManager& mgr); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CGrenadeLauncher.cpp b/Runtime/MP1/World/CGrenadeLauncher.cpp index 4dbd70d19..bef05751f 100644 --- a/Runtime/MP1/World/CGrenadeLauncher.cpp +++ b/Runtime/MP1/World/CGrenadeLauncher.cpp @@ -10,7 +10,7 @@ #include "Runtime/World/CPatterned.hpp" #include "Runtime/World/CPlayer.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CGrenadeLauncher::CGrenadeLauncher(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const zeus::CAABox& bounds, const CHealthInfo& healthInfo, const CDamageVulnerability& vulnerability, @@ -32,7 +32,8 @@ CGrenadeLauncher::CGrenadeLauncher(TUniqueId uid, std::string_view name, const C GetModelData()->EnableLooping(true); const CPASDatabase& pasDatabase = GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase(); for (size_t i = 0; i < x3c8_animIds.size(); ++i) { - const auto result = pasDatabase.FindBestAnimation(CPASAnimParmData{22, CPASAnimParm::FromEnum(int(i))}, -1); + const auto result = pasDatabase.FindBestAnimation( + CPASAnimParmData{pas::EAnimationState::AdditiveAim, CPASAnimParm::FromEnum(int(i))}, -1); x3c8_animIds[i] = result.second; } } @@ -285,7 +286,9 @@ void CGrenadeLauncher::UpdateStartAnimation() { constexpr std::array arr{0, 3}; const auto anim = animData->GetCharacterInfo().GetPASDatabase().FindBestAnimation( - CPASAnimParmData{5, CPASAnimParm::FromEnum(0), CPASAnimParm::FromEnum(arr[x258_started])}, -1); + CPASAnimParmData{pas::EAnimationState::Locomotion, CPASAnimParm::FromEnum(0), + CPASAnimParm::FromEnum(arr[x258_started])}, + -1); if (anim.first > 0.f) { animData->SetAnimation({anim.second, -1, 1.f, true}, false); modelData->EnableLooping(true); @@ -299,7 +302,8 @@ void CGrenadeLauncher::LaunchGrenade(CStateManager& mgr) { return; } - const auto& anim = animData->GetCharacterInfo().GetPASDatabase().FindBestAnimation(CPASAnimParmData{23}, -1); + const auto& anim = animData->GetCharacterInfo().GetPASDatabase().FindBestAnimation( + CPASAnimParmData{pas::EAnimationState::AdditiveFlinch}, -1); if (anim.first > 0.f) { animData->AddAdditiveAnimation(anim.second, 1.f, false, true); const zeus::CVector3f origin = @@ -332,4 +336,4 @@ void CGrenadeLauncher::LaunchGrenade(CStateManager& mgr) { x3f8_explodePlayerDistance)); } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CGrenadeLauncher.hpp b/Runtime/MP1/World/CGrenadeLauncher.hpp index 611cfe293..b0a1c70a2 100644 --- a/Runtime/MP1/World/CGrenadeLauncher.hpp +++ b/Runtime/MP1/World/CGrenadeLauncher.hpp @@ -19,7 +19,7 @@ #include #include -namespace urde::MP1 { +namespace metaforce::MP1 { struct SGrenadeTrajectoryInfo { private: float x0_velocityMin; @@ -125,4 +125,4 @@ private: void UpdateStartAnimation(); void LaunchGrenade(CStateManager& mgr); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CIceAttackProjectile.cpp b/Runtime/MP1/World/CIceAttackProjectile.cpp index 292860a51..33d87fb7a 100644 --- a/Runtime/MP1/World/CIceAttackProjectile.cpp +++ b/Runtime/MP1/World/CIceAttackProjectile.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CIceAttackProjectile::CIceAttackProjectile(const TToken& gen1, const TToken& gen2, const TToken& gen3, TUniqueId uid, TAreaId areaId, @@ -61,4 +61,4 @@ void CIceAttackProjectile::AddToRenderer(const zeus::CFrustum& frustum, CStateMa void CIceAttackProjectile::Render(CStateManager& mgr) {} void CIceAttackProjectile::Touch(CActor& act, CStateManager& mgr) {} -} // namespace urde::MP1 \ No newline at end of file +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CIceAttackProjectile.hpp b/Runtime/MP1/World/CIceAttackProjectile.hpp index 109de5fcd..7d753c97e 100644 --- a/Runtime/MP1/World/CIceAttackProjectile.hpp +++ b/Runtime/MP1/World/CIceAttackProjectile.hpp @@ -3,7 +3,7 @@ #include "Runtime/World/CActor.hpp" #include "Runtime/World/CDamageInfo.hpp" -namespace urde { +namespace metaforce { class CElementGen; namespace MP1 { class CIceAttackProjectile : public CActor { @@ -52,4 +52,4 @@ public: void Touch(CActor& act, CStateManager& mgr) override; }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CIceSheegoth.cpp b/Runtime/MP1/World/CIceSheegoth.cpp index d1cfd2b94..544348de8 100644 --- a/Runtime/MP1/World/CIceSheegoth.cpp +++ b/Runtime/MP1/World/CIceSheegoth.cpp @@ -22,7 +22,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array skSphereJointList = {{ {"Jaw_end_LCTR", 0.55f}, @@ -112,7 +112,8 @@ CIceSheegoth::CIceSheegoth(TUniqueId uid, std::string_view name, const CEntityIn x460_knockBackController.SetX82_24(false); x460_knockBackController.SetEnableLaggedBurnDeath(false); x460_knockBackController.SetEnableExplodeDeath(false); - x950_ = GetAnimationDistance(CPASAnimParmData(3, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(0))) * + x950_ = GetAnimationDistance( + CPASAnimParmData(pas::EAnimationState::Step, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(0))) * GetModelData()->GetScale().y(); xa9c_->SetGlobalScale(GetModelData()->GetScale()); xab0_->SetGlobalScale(GetModelData()->GetScale()); @@ -1509,4 +1510,4 @@ bool CIceSheegoth::IsClosestSheegoth(CStateManager& mgr, const rstl::reserved_ve } return true; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CIceSheegoth.hpp b/Runtime/MP1/World/CIceSheegoth.hpp index 20c1656b7..f1d77115b 100644 --- a/Runtime/MP1/World/CIceSheegoth.hpp +++ b/Runtime/MP1/World/CIceSheegoth.hpp @@ -6,7 +6,7 @@ #include "Runtime/World/CPathFindSearch.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde { +namespace metaforce { class CCollisionActorManager; class CElementGen; class CParticleElectric; @@ -252,4 +252,4 @@ public: CProjectileInfo* GetProjectileInfo() override { return &xa58_; } }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CJellyZap.cpp b/Runtime/MP1/World/CJellyZap.cpp index bdf201212..aef1a3c0a 100644 --- a/Runtime/MP1/World/CJellyZap.cpp +++ b/Runtime/MP1/World/CJellyZap.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr CMaterialFilter kPlayerFilter = CMaterialFilter::MakeInclude({EMaterialTypes::Player}); CJellyZap::CJellyZap(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, @@ -231,4 +231,4 @@ const CDamageVulnerability* CJellyZap::GetDamageVulnerability(const zeus::CVecto const CDamageInfo& info) const { return CActor::GetDamageVulnerability(pos, dir, info); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CJellyZap.hpp b/Runtime/MP1/World/CJellyZap.hpp index 72e69d073..e4c62c994 100644 --- a/Runtime/MP1/World/CJellyZap.hpp +++ b/Runtime/MP1/World/CJellyZap.hpp @@ -2,7 +2,7 @@ #include "Runtime/World/CPatterned.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CJellyZap : public CPatterned { u32 x568_ = 0; CDamageInfo x56c_attackDamage; @@ -59,4 +59,4 @@ public: bool InAttackPosition(CStateManager&, float) override; bool InDetectionRange(CStateManager&, float) override; }; -} // namespace urde::MP1 \ No newline at end of file +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CMagdolite.cpp b/Runtime/MP1/World/CMagdolite.cpp index 465b39403..bebf5aee5 100644 --- a/Runtime/MP1/World/CMagdolite.cpp +++ b/Runtime/MP1/World/CMagdolite.cpp @@ -15,7 +15,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array skSpineJoints{{ @@ -676,4 +676,4 @@ TUniqueId CMagdolite::FindSuitableTarget(CStateManager& mgr, EScriptObjectState return tmpId; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMagdolite.hpp b/Runtime/MP1/World/CMagdolite.hpp index 21ca215bc..a1faceab6 100644 --- a/Runtime/MP1/World/CMagdolite.hpp +++ b/Runtime/MP1/World/CMagdolite.hpp @@ -4,7 +4,7 @@ #include "Runtime/Weapon/CFlameInfo.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde { +namespace metaforce { class CCollisionActorManager; class CSkinnedModel; class CWeaponDescription; @@ -100,4 +100,4 @@ public: bool ShouldRetreat(CStateManager& mgr, float arg) override; }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CMakeLists.txt b/Runtime/MP1/World/CMakeLists.txt index 15f231e82..0417d8109 100644 --- a/Runtime/MP1/World/CMakeLists.txt +++ b/Runtime/MP1/World/CMakeLists.txt @@ -32,6 +32,7 @@ set(MP1_WORLD_SOURCES CMetroidPrimeExo.hpp CMetroidPrimeExo.cpp CMetroidPrimeProjectile.hpp CMetroidPrimeProjectile.cpp CMetroidPrimeRelay.hpp CMetroidPrimeRelay.cpp + CMetroidPrimeEssence.hpp CMetroidPrimeEssence.cpp CNewIntroBoss.hpp CNewIntroBoss.cpp COmegaPirate.hpp COmegaPirate.cpp CParasite.hpp CParasite.cpp diff --git a/Runtime/MP1/World/CMetaree.cpp b/Runtime/MP1/World/CMetaree.cpp index 2434111cd..2e220799d 100644 --- a/Runtime/MP1/World/CMetaree.cpp +++ b/Runtime/MP1/World/CMetaree.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CMetaree::CMetaree(TUniqueId uid, std::string_view name, EFlavorType flavor, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, const CDamageInfo& dInfo, float f1, const zeus::CVector3f& v1, float f2, EBodyType bodyType, @@ -177,4 +177,4 @@ bool CMetaree::InRange(CStateManager& mgr, float arg) { } bool CMetaree::ShouldAttack(CStateManager&, float) { return GetTranslation().z() < x584_lookPos.z(); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetaree.hpp b/Runtime/MP1/World/CMetaree.hpp index 61ed8eada..cb379eec9 100644 --- a/Runtime/MP1/World/CMetaree.hpp +++ b/Runtime/MP1/World/CMetaree.hpp @@ -7,7 +7,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CMetaree : public CPatterned { float x568_delay; float x56c_haltDelay; @@ -49,4 +49,4 @@ public: bool InRange(CStateManager&, float) override; bool ShouldAttack(CStateManager&, float) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroid.cpp b/Runtime/MP1/World/CMetroid.cpp index f46f92ef6..3a2508aba 100644 --- a/Runtime/MP1/World/CMetroid.cpp +++ b/Runtime/MP1/World/CMetroid.cpp @@ -12,7 +12,7 @@ #include "Runtime/World/ScriptLoader.hpp" #include "Runtime/MP1/World/CMetroidBeta.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr CDamageVulnerability skGammaRedDamageVulnerability{ EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Immune, @@ -89,8 +89,8 @@ CMetroid::CMetroid(TUniqueId uid, std::string_view name, EFlavorType flavor, con , x81c_patternedInfo(pInfo) , x954_actParams(aParms) , x9bc_parent(other) { - x808_loopAttackDistance = - GetAnimationDistance(CPASAnimParmData{9, CPASAnimParm::FromEnum(2), CPASAnimParm::FromEnum(3)}); + x808_loopAttackDistance = GetAnimationDistance( + CPASAnimParmData{pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(2), CPASAnimParm::FromEnum(3)}); UpdateTouchBounds(); SetCoefficientOfRestitutionModifier(0.9f); x460_knockBackController.SetX82_24(false); @@ -1451,4 +1451,4 @@ void CMetroid::WallHang(CStateManager& mgr, EStateMsg msg, float dt) { } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroid.hpp b/Runtime/MP1/World/CMetroid.hpp index 154717aa1..42f7c01c5 100644 --- a/Runtime/MP1/World/CMetroid.hpp +++ b/Runtime/MP1/World/CMetroid.hpp @@ -11,7 +11,7 @@ #include "Runtime/World/CPatternedInfo.hpp" #include "Runtime/MP1/World/CSpacePirate.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CMetroidData { private: @@ -207,4 +207,4 @@ private: void UpdateTouchBounds(); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroidBeta.cpp b/Runtime/MP1/World/CMetroidBeta.cpp index 011c0d509..86035acd7 100644 --- a/Runtime/MP1/World/CMetroidBeta.cpp +++ b/Runtime/MP1/World/CMetroidBeta.cpp @@ -15,7 +15,7 @@ #include "Runtime/World/CWorld.hpp" #include "Runtime/World/ScriptLoader.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CMetroidBetaData::CMetroidBetaData(CInputStream& in) : x0_(in) @@ -338,4 +338,4 @@ void CMetroidBeta::AddToTeam(CStateManager& mgr) { CTeamAiRole::ETeamAiRole::Invalid); } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroidBeta.hpp b/Runtime/MP1/World/CMetroidBeta.hpp index f61e50752..e34b58805 100644 --- a/Runtime/MP1/World/CMetroidBeta.hpp +++ b/Runtime/MP1/World/CMetroidBeta.hpp @@ -9,13 +9,13 @@ #include -namespace urde { +namespace metaforce { class CCollisionActorManager; class CElementGen; class CParticleSwoosh; -} // namespace urde +} // namespace metaforce -namespace urde::MP1 { +namespace metaforce::MP1 { class CMetroidBetaData { friend class CMetroidBeta; @@ -143,4 +143,4 @@ public: void RenderHitBallEffect() const; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroidPrimeEssence.cpp b/Runtime/MP1/World/CMetroidPrimeEssence.cpp new file mode 100644 index 000000000..36df76642 --- /dev/null +++ b/Runtime/MP1/World/CMetroidPrimeEssence.cpp @@ -0,0 +1,722 @@ +#include "Runtime/MP1/World/CMetroidPrimeEssence.hpp" + +#include "Runtime/CSimplePool.hpp" +#include "Runtime/CStateManager.hpp" +#include "Runtime/Collision/CCollisionActor.hpp" +#include "Runtime/Collision/CCollisionActorManager.hpp" +#include "Runtime/Collision/CGameCollision.hpp" +#include "Runtime/GameGlobalObjects.hpp" +#include "Runtime/Graphics/CBooRenderer.hpp" +#include "Runtime/Weapon/CGameProjectile.hpp" +#include "Runtime/World/CGameArea.hpp" +#include "Runtime/World/CPatternedInfo.hpp" +#include "Runtime/World/CPlayer.hpp" +#include "Runtime/World/CScriptWaypoint.hpp" +#include "Runtime/World/CWorld.hpp" + +#include "DataSpec/DNAMP1/SFX/MetroidPrime.h" + +#include "TCastTo.hpp" // Generated file, do not modify include path + +namespace metaforce::MP1 { +namespace { +std::array skJointInfo{{ + {"lockon_target_LCTR", 1.5f}, +}}; + +std::array skUnkInts1{{0, 1, 0, 2}}; +std::array skUnkInts2{{1, 2, 3}}; + +} // namespace +CMetroidPrimeEssence::CMetroidPrimeEssence(metaforce::TUniqueId uid, std::string_view name, const metaforce::CEntityInfo& info, + const zeus::CTransform& xf, + metaforce::CModelData&& mData, + const metaforce::CPatternedInfo& pInfo, const metaforce::CActorParameters& actParms, metaforce::CAssetId particle1, const metaforce::CDamageInfo& dInfo, float f1, metaforce::CAssetId electric, u32 w1, metaforce::CAssetId particle2) +: CPatterned(ECharacter::MetroidPrimeEssence, uid, name, EFlavorType::Zero, info, xf, std::move(mData), pInfo, + EMovementType::Flyer, EColliderType::One, EBodyType::Flyer, actParms, EKnockBackVariant::Medium) +, x568_(g_SimplePool->GetObj({FOURCC('PART'), particle2})) +, x574_searchPath(nullptr, 3, pInfo.GetPathfindingIndex(), 1.f, 1.f) +, x660_(particle1) +, x664_(electric) +, x698_(dInfo) +, x6b4_(xf.origin) +, x70c_(CSfxManager::TranslateSFXID(w1)) { + CreateShadow(false); + MakeThermalColdAndHot(); +} + +void CMetroidPrimeEssence::Think(float dt, CStateManager& mgr) { + if (!GetActive()) { + return; + } + + CPatterned::Think(dt, mgr); + if (IsAlive()) { + UpdatePhase(dt, mgr); + } + + x450_bodyController->FaceDirection((mgr.GetPlayer().GetTranslation() - GetTranslation()).normalized(), dt); + x658_collisionManager->Update(dt, mgr, CCollisionActorManager::EUpdateOptions::ObjectSpace); + UpdateHealth(mgr); + CountListeningAi(mgr); + if (x70e_30_) { + x6d4_ = 2.f * dt + x6d4_; + if (x6d4_ >= 1.f) { + x6d4_ = 0.f; + } + + sub8027ce5c(-4.f * x6d4_ * (x6d4_ - 1.f)); + } +} + +void CMetroidPrimeEssence::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId other, CStateManager& mgr) { + CPatterned::AcceptScriptMsg(msg, other, mgr); + + switch (msg) { + case EScriptObjectMessage::Activate: + x658_collisionManager->SetActive(mgr, true); + break; + case EScriptObjectMessage::Deactivate: + x658_collisionManager->SetActive(mgr, false); + break; + case EScriptObjectMessage::Start: + x70e_25_ = true; + break; + case EScriptObjectMessage::Stop: + x70e_25_ = false; + break; + case EScriptObjectMessage::Touched: { + if (TCastToPtr colAct = mgr.ObjectById(other)) { + if (colAct->GetLastTouchedObject() == mgr.GetPlayer().GetUniqueId()) { + mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), GetContactDamage(), + CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); + x420_curDamageRemTime = x424_damageWaitTime; + } + } + break; + } + case EScriptObjectMessage::Registered: { + SetupCollisionActorManager(mgr); + x658_collisionManager->SetActive(mgr, true); + x6cc_ = GetModelData()->GetScale().x(); + x6d0_ = 0.9f * x6cc_ + x6cc_; + x55c_moveScale.splat(1.f / (0.625f * x6cc_)); + const float hp = GetHealthInfo(mgr)->GetHP(); + x6c0_ = 0.3f * hp; + if (hp > 0.f) { + x6c4_ = 1.f / hp; + } + x450_bodyController->Activate(mgr); + break; + } + case EScriptObjectMessage::Deleted: { + x658_collisionManager->Destroy(mgr); + mgr.SetBossParams(kInvalidUniqueId, 0.f, 0); + break; + } + case EScriptObjectMessage::InitializedInArea: { + x574_searchPath.SetArea(mgr.GetWorld()->GetArea(GetAreaIdAlways())->GetPostConstructed()->x10bc_pathArea); + x704_bossUtilityWaypointId = GetWaypointForState(mgr, EScriptObjectState::Play, EScriptObjectMessage::Activate); + break; + } + case EScriptObjectMessage::Damage: { + if (TCastToPtr colAct = mgr.ObjectById(other)) { + if (TCastToConstPtr proj = mgr.GetObjectById(colAct->GetLastTouchedObject())) { + if (proj->GetOwnerId() == mgr.GetPlayer().GetUniqueId()) { + if (colAct->GetDamageVulnerability()->WeaponHits(proj->GetDamageInfo().GetWeaponMode(), false) && + proj->GetDamageInfo().GetWeaponMode().GetType() == EWeaponType::Phazon) { + sub8027cee0(mgr); + TakeDamage(zeus::skForward, 1.f); + if (!x70e_24_ && !x70e_26_) { + GetBodyController()->GetCommandMgr().DeliverCmd( + CBCKnockBackCmd{GetTransform().frontVector(), pas::ESeverity::One}); + sub8027cce0(mgr); + } + } + } + } + } else if (TCastToConstPtr proj = mgr.GetObjectById(other)) { + mgr.ApplyDamage(other, x706_lockOnTargetCollider, proj->GetOwnerId(), proj->GetDamageInfo(), + CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); + } + break; + } + default: + break; + } +} + +void CMetroidPrimeEssence::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) { + CPatterned::PreRender(mgr, frustum); +} + +void CMetroidPrimeEssence::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) { + + if (GetActive() && x65c_) { + g_Renderer->AddParticleGen(*x65c_); + } + CPatterned::AddToRenderer(frustum, mgr); +} + +void CMetroidPrimeEssence::Render(CStateManager& mgr) { + if (x70e_27_) { + mgr.DrawSpaceWarp(x6b4_, 1.f); + } + CPatterned::Render(mgr); +} + +zeus::CVector3f CMetroidPrimeEssence::GetAimPosition(const CStateManager& mgr, float dt) const { + if (TCastToConstPtr colAct = mgr.GetObjectById(x706_lockOnTargetCollider)) { + return colAct->GetTranslation(); + } + return CPatterned::GetAimPosition(mgr, dt); +} + +void CMetroidPrimeEssence::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, + float dt) { + + switch (type) { + case EUserEventType::EggLay: { + if (x70e_29_ && x6d8_ != 0 && x6e4_ < x6f8_) { + const float ang1 = zeus::degToRad(22.5f) * mgr.GetActiveRandom()->Range(-1, 1); + const float ang2 = zeus::degToRad(45.0f) * mgr.GetActiveRandom()->Range(-1, 1); + zeus::CVector3f pos = + x668_ * zeus::CVector3f{2.f * -std::sin(ang1), (2.f * (2.f * std::cos(ang1)) * std::sin(ang2)), + 2.f * ((2.f * std::cos(ang1)) * std::cos(ang2))}; + if (TCastToPtr wp = mgr.ObjectById(x704_bossUtilityWaypointId)) { + wp->SetTransform(zeus::lookAt(pos, mgr.GetPlayer().GetAimPosition(mgr, 0.f))); + if (sub8027e870(wp->GetTransform(), mgr)) { + SendScriptMsgs(EScriptObjectState::Zero, mgr, EScriptObjectMessage::None); + x6b4_ = wp->GetTranslation(); + } + } + } + return; + } + case EUserEventType::EventStart: { + if (!x70e_31_) { + SendScriptMsgs(EScriptObjectState::CameraTarget, mgr, EScriptObjectMessage::None); + x70e_31_ = true; + } + return; + } + case EUserEventType::BeginAction: { + SShockWaveData data(x660_, x698_, 2.f, x664_, x70c_); + data.SetSpeedIncrease(180.f); + DropShockwave(mgr, data); + ShakeCamera(mgr, 1.f); + return; + } + case EUserEventType::Activate: { + sub8027d824(mgr); + return; + } + case EUserEventType::Deactivate: + x70e_27_ = false; + [[fallthrough]]; + default: + break; + } + CPatterned::DoUserAnimEvent(mgr, node, type, dt); +} + +void CMetroidPrimeEssence::Death(CStateManager& mgr, const zeus::CVector3f& direction, EScriptObjectState state) { + if (!IsAlive()) { + return; + } + + KillAiInArea(mgr); + SetParticleEffectState(mgr, false); + if (TCastToPtr colAct = mgr.ObjectById(x706_lockOnTargetCollider)) { + colAct->AddMaterial(EMaterialTypes::ProjectilePassthrough, mgr); + } + CPatterned::Death(mgr, direction, state); +} + +void CMetroidPrimeEssence::Dead(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg != EStateMsg::Update || GetModelData()->GetAnimationData()->IsAnimTimeRemaining(dt, "Whole Body"sv)) { + return; + } + + DeathDelete(mgr); +} + +void CMetroidPrimeEssence::PathFind(CStateManager& mgr, EStateMsg msg, float dt) { + CPatterned::PathFind(mgr, msg, dt); + if (msg == EStateMsg::Update) { + sub8027cb40(mgr.GetPlayer().GetTranslation()); + } +} + +void CMetroidPrimeEssence::Halt(CStateManager& mgr, EStateMsg msg, float dt) { + // Intentionally empty +} + +void CMetroidPrimeEssence::Generate(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + zeus::CVector3f lookPos = mgr.GetPlayer().GetTranslation(); + lookPos.z() = GetTranslation().z(); + zeus::CTransform xf = zeus::lookAt(GetTranslation(), lookPos); + xf.origin = GetTranslation(); + SetTransform(xf); + } else if (msg == EStateMsg::Deactivate) { + mgr.SetBossParams(GetUniqueId(), GetHealthInfo(mgr)->GetHP(), 91); + SetParticleEffectState(mgr, true); + } +} + +void CMetroidPrimeEssence::JumpBack(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + x700_ = sub8027cfd4(mgr, true); + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::Step, &CPatterned::TryStep, x700_); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + } +} + +void CMetroidPrimeEssence::Skid(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::Step, &CPatterned::TryStep, 5); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + } +} + +void CMetroidPrimeEssence::FadeIn(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + x6f8_ = sub8027d428(); + x32c_animState = EAnimState::Ready; + x70e_24_ = true; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::ProjectileAttack, &CPatterned::TryProjectileAttack, 0); + } else if (msg == EStateMsg::Deactivate) { + x70e_24_ = false; + x70e_27_ = false; + x70e_29_ = false; + x70e_30_ = false; + x32c_animState = EAnimState::NotReady; + } +} + +void CMetroidPrimeEssence::FadeOut(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg != EStateMsg::Activate) { + return; + } + + DoPhaseTransition(mgr); +} + +void CMetroidPrimeEssence::Taunt(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::Taunt, &CPatterned::TryTaunt, 2); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + } +} + +void CMetroidPrimeEssence::TelegraphAttack(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + x70e_30_ = true; + } else if (msg == EStateMsg::Update) { + if (!x70e_31_) { + TryCommand(mgr, pas::EAnimationState::MeleeAttack, &CPatterned::TryMeleeAttack, 2); + } else { + TryCommand(mgr, pas::EAnimationState::ProjectileAttack, &CPatterned::TryProjectileAttack, 5); + } + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + x70e_30_ = false; + sub8027ce5c(dt); + } +} + +void CMetroidPrimeEssence::Dodge(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + x700_ = sub8027cfd4(mgr, false); + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::Step, &CPatterned::TryStep, x700_); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + } +} + +void CMetroidPrimeEssence::PathFindEx(CStateManager& mgr, EStateMsg msg, float dt) { + CPatterned::PathFind(mgr, msg, dt); + if (msg == EStateMsg::Activate) { + x70e_24_ = true; + } else if (msg == EStateMsg::Update) { + sub8027cb40(x2e0_destPos); + } else if (msg == EStateMsg::Deactivate) { + x70e_24_ = false; + } +} + +bool CMetroidPrimeEssence::HasPatrolPath(CStateManager& mgr, float dt) { + return !x70e_31_ && CPatterned::HasPatrolPath(mgr, dt); +} + +bool CMetroidPrimeEssence::ShouldAttack(CStateManager& mgr, float dt) { + if (x70e_31_) { + return x70e_25_; + } + return true; +} + +bool CMetroidPrimeEssence::InPosition(CStateManager& mgr, float dt) { + return (GetTranslation().z() - mgr.GetPlayer().GetTranslation().z()) > 0.25f; +} + +bool CMetroidPrimeEssence::CoverFind(CStateManager& mgr, float dt) { + return (x2e0_destPos - GetTranslation()).magSquared() < 90.f; +} + +bool CMetroidPrimeEssence::ShouldTaunt(CStateManager& mgr, float dt) { + const CHealthInfo* info = GetHealthInfo(mgr); + if (!info || info->GetHP() <= x6c0_) { + return false; + } + + return mgr.GetActiveRandom()->Next() % 100 < 50; +} + +bool CMetroidPrimeEssence::ShouldCrouch(CStateManager& mgr, float dt) { + if (x6f0_ < x6f4_) { + ++x6f0_; + return false; + } + + x6f4_ = std::min(x6e8_ + static_cast(3.f * (1.f - x6c4_ * GetHealthInfo(mgr)->GetHP())), x6ec_); + x6f0_ = 0; + return true; +} + +bool CMetroidPrimeEssence::ShouldMove(CStateManager& mgr, float dt) { return x70e_31_; } + +CPathFindSearch* CMetroidPrimeEssence::GetSearchPath() { return &x574_searchPath; } + +void CMetroidPrimeEssence::sub8027cb40(const zeus::CVector3f& vec) { + pas::EStepDirection stepDir = GetStepDirection(GetBodyController()->GetCommandMgr().GetMoveVector()); + GetBodyController()->GetCommandMgr().ClearLocomotionCmds(); + if (stepDir == pas::EStepDirection::Forward && + GetTransform().frontVector().normalized().dot((x2e0_destPos - GetTranslation()).normalized()) < + zeus::degToRad(-15.f)) { + stepDir = pas::EStepDirection::Backward; + } + + GetBodyController()->GetCommandMgr().DeliverCmd(CBCStepCmd(stepDir, pas::EStepType::Normal)); + GetBodyController()->GetCommandMgr().DeliverTargetVector(vec - GetTranslation()); +} + +void CMetroidPrimeEssence::sub8027cce0(CStateManager& mgr) { + if (CSfxManager::IsPlaying(x708_)) { + return; + } + CAudioSys::C3DEmitterParmData emitterData{zeus::skZero3f, zeus::skZero3f, 1000.f, 0.1f, 1, SFXsfx0B67, 1.f, + 0.16f, false, 127}; + emitterData.x0_pos = GetTargetTransform(mgr).origin; + x708_ = CSfxManager::AddEmitter(emitterData, true, 127, false, GetAreaIdAlways()); +} + +zeus::CTransform CMetroidPrimeEssence::GetTargetTransform(CStateManager& mgr) { + if (TCastToPtr colAct = mgr.ObjectById(x706_lockOnTargetCollider)) { + return colAct->GetTransform(); + } + + return GetTransform(); +} + +void CMetroidPrimeEssence::sub8027ce5c(float dt) { + const auto matCount = static_cast(GetModelData()->GetNumMaterialSets() - 2); + u32 iVar1 = matCount - (matCount * dt); + if (x6fc_ != iVar1) { + x6fc_ = iVar1; + } +} + +void CMetroidPrimeEssence::sub8027cee0(CStateManager& mgr) { + const float hp = x6c4_ * GetHealthInfo(mgr)->GetHP(); + if (hp <= 0.f) { + return; + } + + bool sendMsg = false; + if (x6d8_ == 0 && hp < 0.75f) { + x6d8_ = 1; + } else if (x6d8_ == 1 && hp < 0.5f) { + sendMsg = true; + x6d8_ = 2; + } else if (x6d8_ == 2 && hp < 0.25f) { + sendMsg = true; + x6d8_ = 3; + } + + if (sendMsg) { + SendScriptMsgs(EScriptObjectState::DeactivateState, mgr, EScriptObjectMessage::None); + } +} + +u32 CMetroidPrimeEssence::sub8027cfd4(CStateManager& mgr, bool w1) { + auto startIndex = static_cast(!w1); + zeus::CTransform xf = GetTargetTransform(mgr); + std::array directions; + directions[0] = -xf.frontVector(); + directions[2] = xf.rightVector(); + directions[1] = -directions[2]; + u32 uVar5 = 1 << size_t(startIndex); + for (auto i = size_t(startIndex); i < 3; ++i) { + CRayCastResult res = mgr.RayStaticIntersection(xf.origin, directions[i], 20.f, CMaterialFilter::skPassEverything); + if (res.IsInvalid()) { + uVar5 |= 1 << i; + } + } + + u32 uVar3 = 0; + if (uVar5 < 8) { + u32 numBits = zeus::PopCount(uVar5); + if (numBits == 2) { + u32 uVar1_ = mgr.GetActiveRandom()->Next(); + if ((uVar1_ & 1) == false) { + uVar3 = (uVar5 & 1) ^ 1; + } else { + uVar3 = ((uVar5 >> 2) & 1) + 1; + } + } else if (numBits < 2) { + uVar3 = uVar5 >> 1; + } else if (numBits == 3) { + uVar3 = mgr.GetActiveRandom()->Range(startIndex, 2); + } + } + + return skUnkInts2[uVar3]; +} + +void CMetroidPrimeEssence::DoPhaseTransition(CStateManager& mgr) { + x330_stateMachineState.SetDelay(2.f); + x70e_26_ = true; + x70e_27_ = true; + x6c8_ = 1.f; + x70e_29_ = false; + + bool uVar3 = x6dc_ == skUnkInts1[size_t(mgr.GetPlayerState()->GetCurrentVisor())]; + if (skUnkInts1[size_t(mgr.GetPlayerState()->GetCurrentVisor())] == x6dc_) { + x65c_ = std::make_unique(x568_, CElementGen::EModelOrientationType::Normal, + CElementGen::EOptionalSystemFlags::One); + + if (x65c_) { + zeus::CTransform xf = GetTargetTransform(mgr); + x65c_->SetGlobalScale(GetModelData()->GetScale()); + x65c_->SetGlobalOrientation(xf.getRotation()); + x65c_->SetGlobalTranslation(xf.origin); + } + } + + CSfxManager::AddEmitter(SFXsfx0B7D + uVar3, GetTranslation(), zeus::skZero3f, true, false, 127, kInvalidAreaId); + x6e0_ = x6dc_; + ++x6dc_; + if (x6dc_ > 2) { + x6dc_ = 0; + } +} + +void CMetroidPrimeEssence::ShakeCamera(CStateManager& mgr, float f1) { + float mag = 0.5f - (0.01f * (GetTranslation() - mgr.GetPlayer().GetTranslation()).magnitude()); + if (mag < 0.f || mgr.GetPlayer().GetSurfaceRestraint() == CPlayer::ESurfaceRestraints::Air) { + return; + } + + mgr.GetCameraManager()->AddCameraShaker(CCameraShakeData(0.5f, mag), true); +} + +void CMetroidPrimeEssence::DropShockwave(CStateManager& mgr, const SShockWaveData& shockWaveData) { + CRayCastResult res = RayStaticIntersection(mgr); + if (res.IsInvalid()) { + return; + } + + mgr.AddObject(new CShockWave(mgr.AllocateUniqueId(), "Shockwave", CEntityInfo(GetAreaIdAlways(), NullConnectionList), + zeus::CTransform::Translate(res.GetPoint()), GetUniqueId(), shockWaveData, 1.5f, 0.5f)); +} + +CRayCastResult CMetroidPrimeEssence::RayStaticIntersection(CStateManager& mgr) { + return mgr.RayStaticIntersection(GetTranslation(), -zeus::skUp, 30.f, CMaterialFilter::skPassEverything); +} + +void CMetroidPrimeEssence::SetParticleEffectState(CStateManager& mgr, bool active) { + GetModelData()->GetAnimationData()->SetParticleEffectState("Eyes"sv, active, mgr); + GetModelData()->GetAnimationData()->SetParticleEffectState("Head"sv, active, mgr); +} + +void CMetroidPrimeEssence::sub8027d824(CStateManager& mgr) { + CRayCastResult res = RayStaticIntersection(mgr); + if (res.IsInvalid()) { + return; + } + + x668_ = zeus::CTransform::Translate(res.GetPoint()); + if (TCastToPtr wp = mgr.ObjectById(x704_bossUtilityWaypointId)) { + wp->SetTransform(x668_); + SendScriptMsgs(EScriptObjectState::AboutToMassivelyDie, mgr, EScriptObjectMessage::None); + x70e_29_ = true; + } +} + +bool CMetroidPrimeEssence::sub8027e870(const zeus::CTransform& xf, CStateManager& mgr) { + rstl::reserved_vector nearList; + mgr.BuildNearList(nearList, {xf.origin - 2.f, xf.origin + 2.f}, CMaterialFilter::MakeInclude(EMaterialTypes::AIBlock), + this); + + CCollidableSphere sphere({zeus::skZero3f, 2.f}, CMaterialList(EMaterialTypes::Solid, EMaterialTypes::AIBlock)); + CCollisionInfoList infoList; + TUniqueId tmpId = kInvalidUniqueId; + CGameCollision::DetectCollision( + mgr, sphere, xf, + CMaterialFilter::MakeIncludeExclude( + {EMaterialTypes ::Solid, EMaterialTypes ::Player, EMaterialTypes ::Character, EMaterialTypes ::AIBlock}, + {EMaterialTypes ::ProjectilePassthrough}), + nearList, tmpId, infoList); + + if (infoList.GetCount() >= 1) { + return false; + } + + if (TCastToPtr colAct = mgr.ObjectById(x706_lockOnTargetCollider)) { + zeus::CVector3f direction = (xf.origin - colAct->GetTranslation()).normalized(); + CRayCastResult res = + mgr.RayStaticIntersection(colAct->GetTranslation(), direction, direction.magnitude(), + CMaterialFilter::MakeExclude({EMaterialTypes::ProjectilePassthrough})); + if (res.IsInvalid()) { + return true; + } + } + return false; +} + +void CMetroidPrimeEssence::KillAiInArea(CStateManager& mgr) { + for (auto* ent : mgr.GetListeningAiObjectList()) { + if (TCastToPtr ai = ent) { + if (ai != this && ai->GetActive() && ai->GetAreaIdAlways() == GetAreaIdAlways()) { + static_cast(ai.GetPtr())->MassiveDeath(mgr); + } + } + } +} + +void CMetroidPrimeEssence::CountListeningAi(CStateManager& mgr) { + x6e0_ = 0; + for (auto* ent : mgr.GetListeningAiObjectList()) { + if (TCastToPtr ai = ent) { + if (ai != this && ai->GetActive() && ai->GetAreaIdAlways() == GetAreaIdAlways()) { + ++x6e4_; + } + } + } +} + +void CMetroidPrimeEssence::UpdatePhase(float dt, CStateManager& mgr) { + if (skUnkInts1[size_t(mgr.GetPlayerState()->GetCurrentVisor())] == x6dc_) { + x42c_color.a() = 1.f - x6c8_; + GetModelData()->SetScale(zeus::CVector3f((x6cc_ - x6d0_) + x6d0_)); + if (!x70e_28_) { + AddMaterial(EMaterialTypes::Orbit, EMaterialTypes::Target, mgr); + SetParticleEffectState(mgr, true); + x70e_28_ = true; + } + } else { + x42c_color.a() = skUnkInts1[size_t(mgr.GetPlayerState()->GetCurrentVisor())] == x6e0_ ? x6c8_ : 0.f; + GetModelData()->SetScale(zeus::CVector3f((x6cc_ - x6d0_) + x6d0_)); + if (x70e_28_) { + RemoveMaterial(EMaterialTypes::Orbit, EMaterialTypes::Target, mgr); + SetParticleEffectState(mgr, false); + x70e_28_ = false; + } + } + + zeus::CTransform xf = GetTargetTransform(mgr); + if (x70e_26_) { + x6c8_ -= 0.5f * dt; + x6b4_ = xf.origin; + if (x6c8_ < 0.f) { + x6c8_ = 0.f; + x70e_26_ = false; + x70e_27_ = false; + } + } + + if (!x65c_) { + return; + } + + if (!x65c_->IsSystemDeletable()) { + x65c_->SetGlobalOrientation(xf.getRotation()); + x65c_->SetGlobalTranslation(xf.origin); + x65c_->Update(dt); + } else { + x65c_.reset(); + } +} + +void CMetroidPrimeEssence::UpdateHealth(CStateManager& mgr) { + if (!IsAlive()) { + return; + } + + if (TCastToPtr colAct = mgr.ObjectById(x706_lockOnTargetCollider)) { + colAct->SetDamageVulnerability(*GetDamageVulnerability()); + HealthInfo(mgr)->SetHP(colAct->GetHealthInfo(mgr)->GetHP()); + } + + if (GetHealthInfo(mgr)->GetHP() <= 0.f) { + Death(mgr, zeus::skZero3f, EScriptObjectState::DeathRattle); + RemoveMaterial(EMaterialTypes::Orbit, EMaterialTypes::Target, mgr); + } +} + +void CMetroidPrimeEssence::SetLockOnTargetHealthAndDamageVulns(CStateManager& mgr) { + if (TCastToPtr colAct = mgr.ObjectById(x706_lockOnTargetCollider)) { + *colAct->HealthInfo(mgr) = *HealthInfo(mgr); + colAct->SetDamageVulnerability(*GetDamageVulnerability()); + } +} + +void CMetroidPrimeEssence::AddSphereCollisions(SSphereJointInfo* info, size_t count, + std::vector& vecOut) { + const CAnimData* animData = GetModelData()->GetAnimationData(); + for (size_t i = 0; i < count; ++i) { + CSegId segId = animData->GetLocatorSegId(info[i].name); + if (segId.IsInvalid()) { + continue; + } + vecOut.push_back(CJointCollisionDescription::SphereCollision(segId, info[i].radius, info[i].name, 1000.f)); + } +} + +void CMetroidPrimeEssence::SetupCollisionActorManager(CStateManager& mgr) { + std::vector joints; + AddSphereCollisions(skJointInfo.data(), skJointInfo.size(), joints); + x658_collisionManager = + std::make_unique(mgr, GetUniqueId(), GetAreaIdAlways(), joints, false); + + for (size_t i = 0; i < x658_collisionManager->GetNumCollisionActors(); ++i) { + const auto& info = x658_collisionManager->GetCollisionDescFromIndex(i); + if (TCastToPtr colAct = mgr.ObjectById(info.GetCollisionActorId())) { + if (info.GetName() == "lockon_target_LCTR"sv) { + x706_lockOnTargetCollider = info.GetCollisionActorId(); + } + } + } + + SetLockOnTargetHealthAndDamageVulns(mgr); + SetMaterialFilter(CMaterialFilter::MakeIncludeExclude( + {EMaterialTypes::Solid}, {EMaterialTypes::CollisionActor, EMaterialTypes::Player, EMaterialTypes::Character})); + AddMaterial(EMaterialTypes::ProjectilePassthrough, mgr); +} + +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CMetroidPrimeEssence.hpp b/Runtime/MP1/World/CMetroidPrimeEssence.hpp new file mode 100644 index 000000000..1846baed6 --- /dev/null +++ b/Runtime/MP1/World/CMetroidPrimeEssence.hpp @@ -0,0 +1,111 @@ +#pragma once + +#include "Runtime/Collision/CJointCollisionDescription.hpp" +#include "Runtime/MP1/World/CShockWave.hpp" +#include "Runtime/World/CPathFindSearch.hpp" +#include "Runtime/World/CPatterned.hpp" + +namespace metaforce { +class CCollisionActorManager; +namespace MP1 { +class CMetroidPrimeEssence : public CPatterned { + TCachedToken x568_; + CPathFindSearch x574_searchPath; + std::unique_ptr x658_collisionManager; + std::unique_ptr x65c_; + CAssetId x660_; + CAssetId x664_; + zeus::CTransform x668_; + CDamageInfo x698_; + zeus::CVector3f x6b4_; + float x6c0_ = 0.f; + float x6c4_ = 0.f; + float x6c8_ = 0.f; + float x6cc_ = 4.f; + float x6d0_ = 0.9f * x6cc_ + x6cc_; + float x6d4_ = 0.f; + u32 x6d8_ = 0; + u32 x6dc_ = 0; + u32 x6e0_ = x6dc_; + u32 x6e4_ = 0; + u32 x6e8_ = 2; + u32 x6ec_ = 4; + u32 x6f0_ = 0; + u32 x6f4_ = x6e8_ - 1; + u32 x6f8_ = 2; + u32 x6fc_ = 0; + u32 x700_ = 1; + TUniqueId x704_bossUtilityWaypointId = kInvalidUniqueId; + TUniqueId x706_lockOnTargetCollider = kInvalidUniqueId; + CSfxHandle x708_; + s16 x70c_; + bool x70e_24_ : 1 = false; + bool x70e_25_ : 1 = true; + bool x70e_26_ : 1 = false; + bool x70e_27_ : 1 = false; + bool x70e_28_ : 1 = true; + bool x70e_29_ : 1 = false; + bool x70e_30_ : 1 = false; + bool x70e_31_ : 1 = false; + + void sub8027cb40(const zeus::CVector3f& vec); + void sub8027cce0(CStateManager& mgr); + zeus::CTransform GetTargetTransform(CStateManager& mgr); + void sub8027ce5c(float f1); + void sub8027cee0(CStateManager& mgr); + u32 sub8027cfd4(CStateManager& mgr, bool w1); + void DoPhaseTransition(CStateManager& mgr); + u32 sub8027d428() { return 2; /* Decided by fair dice roll, guaranteed to be random */} + void ShakeCamera(CStateManager& mgr, float f1); + void DropShockwave(CStateManager& mgr, const SShockWaveData& shockWaveData); + CRayCastResult RayStaticIntersection(CStateManager& mgr); + void SetParticleEffectState(CStateManager& mgr, bool active); + void sub8027d824(CStateManager& mgr); + bool sub8027e870(const zeus::CTransform& xf, CStateManager& mgr); + void KillAiInArea(CStateManager& mgr); + void CountListeningAi(CStateManager& mgr); + void UpdatePhase(float dt, CStateManager& mgr); + void UpdateHealth(CStateManager& mgr); + void SetLockOnTargetHealthAndDamageVulns(CStateManager& mgr); + void AddSphereCollisions(SSphereJointInfo* info, size_t count, std::vector& vecOut); + void SetupCollisionActorManager(CStateManager& mgr); + +public: + DEFINE_PATTERNED(MetroidPrimeEssence); + + CMetroidPrimeEssence(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, + CModelData&& mData, const CPatternedInfo& pInfo, const CActorParameters& actParms, + CAssetId particle1, const CDamageInfo& dInfo, float f1, CAssetId electric, u32 w1, + CAssetId particle2); + + void Think(float dt, CStateManager& mgr) override; + void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId other, CStateManager& mgr) override; + void PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) override; + void AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) override; + void Render(CStateManager& mgr) override; + zeus::CVector3f GetAimPosition(const CStateManager& mgr, float dt) const override; + void DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) override; + void Death(CStateManager& mgr, const zeus::CVector3f& direction, EScriptObjectState state) override; + void Dead(CStateManager& mgr, EStateMsg msg, float dt) override; + void PathFind(CStateManager& mgr, EStateMsg msg, float dt) override; + void Halt(CStateManager& mgr, EStateMsg msg, float dt) override; + void Generate(CStateManager& mgr, EStateMsg msg, float dt) override; + void JumpBack(CStateManager& mgr, EStateMsg msg, float dt) override; + void Skid(CStateManager& mgr, EStateMsg msg, float dt) override; + void FadeIn(CStateManager& mgr, EStateMsg msg, float dt) override; + void FadeOut(CStateManager& mgr, EStateMsg msg, float dt) override; + void Taunt(CStateManager& mgr, EStateMsg msg, float dt) override; + void TelegraphAttack(CStateManager& mgr, EStateMsg msg, float dt) override; + void Dodge(CStateManager& mgr, EStateMsg msg, float dt) override; + void PathFindEx(CStateManager& mgr, EStateMsg msg, float dt) override; + bool HasPatrolPath(CStateManager& mgr, float dt) override; + bool ShouldAttack(CStateManager& mgr, float dt) override; + bool InPosition(CStateManager& mgr, float dt) override; + bool CoverFind(CStateManager& mgr, float dt) override; + bool ShouldTaunt(CStateManager& mgr, float dt) override; + bool ShouldCrouch(CStateManager& mgr, float dt) override; + bool ShouldMove(CStateManager& mgr, float dt) override; + CPathFindSearch* GetSearchPath() override; +}; +} // namespace MP1 +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/MP1/World/CMetroidPrimeExo.cpp b/Runtime/MP1/World/CMetroidPrimeExo.cpp index 260ac4a6f..b7ec925d8 100644 --- a/Runtime/MP1/World/CMetroidPrimeExo.cpp +++ b/Runtime/MP1/World/CMetroidPrimeExo.cpp @@ -3,11 +3,163 @@ #include "DataSpec/DNAMP1/ScriptObjects/MetroidPrimeStage1.hpp" #include "Runtime/CSimplePool.hpp" +#include "Runtime/CStateManager.hpp" +#include "Runtime/Collision/CCollisionActor.hpp" +#include "Runtime/Collision/CCollisionActorManager.hpp" +#include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/GameGlobalObjects.hpp" +#include "Runtime/MP1/World/CEnergyBall.hpp" +#include "Runtime/MP1/World/CMetroidPrimeRelay.hpp" +#include "Runtime/Particle/CElementGen.hpp" +#include "Runtime/Particle/CParticleElectric.hpp" +#include "Runtime/Particle/CParticleSwoosh.hpp" +#include "Runtime/Weapon/CPlasmaProjectile.hpp" +#include "Runtime/World/CHUDBillboardEffect.hpp" +#include "Runtime/World/CPlayer.hpp" +#include "Runtime/World/CProjectedShadow.hpp" +#include "Runtime/World/CScriptWaypoint.hpp" +#include "Runtime/World/CWorld.hpp" #include "Runtime/World/ScriptLoader.hpp" -namespace urde::MP1 { +#include "TCastTo.hpp" // Generated file, do not modify include path +namespace metaforce::MP1 { + +namespace { +std::array skLocomotions{{ + pas::ELocomotionType::Internal10, + pas::ELocomotionType::Internal11, + pas::ELocomotionType::Internal12, +}}; +std::array skTaunts{{ + pas::ETauntType::One, + pas::ETauntType::Two, + pas::ETauntType::Zero, +}}; + +std::array skSphereJoints{{ + {"Sphere_LCTR", 1.5f}, + {"Skeleton_Root", 2.3f}, + {"Head_LockON_SDK", 0.92f}, +}}; + +std::array skBodyJoints{{ + {"R_shoulder", "R_elbow", {0.6, 0.6, 0.6}}, {"R_elbow", "R_wrist", {0.3f, 0.3f, 0.3f}}, + {"R_wrist", "R_hand_LCTR", {0.3f, 0.3f, 0.3f}}, {"R_hand_LCTR", "R_leg_LCTR", {0.4f, 1.2f, 0.4f}}, + {"R_front_1", "R_front_2", {0.2f, 0.2f, 0.2f}}, {"R_front_2", "R_front_3", {0.2f, 0.2f, 0.2f}}, + {"R_front_3", "F_R_leg_LCTR", {0.2f, 0.2f, 0.7f}}, {"R_stinger_1", "R_stinger_2", {0.2f, 0.2f, 0.2f}}, + {"R_stinger_2", "R_spike_LCTR", {0.2f, 0.2f, 0.2f}}, {"L_shoulder", "L_elbow", {0.6, 0.6, 0.6}}, + {"L_elbow", "L_wrist", {0.3f, 0.3f, 0.3f}}, {"L_wrist", "L_hand_LCTR", {0.3f, 0.3f, 0.3f}}, + {"L_hand_LCTR", "L_leg_LCTR", {0.4f, 1.2f, 0.4f}}, {"L_front_1", "L_front_2", {0.2f, 0.2f, 0.2f}}, + {"L_front_2", "L_front_3", {0.2f, 0.2f, 0.2f}}, {"L_front_3", "F_L_leg_LCTR", {0.2f, 0.2f, 0.7f}}, + {"L_stinger_1", "L_stinger_2", {0.4f, 0.4f, 0.4f}}, {"L_stinger_2", "L_spike_LCTR", {0.2f, 0.2f, 0.2f}}, + {"B_shoulder", "B_elbow", {0.8f, 0.8f, 0.8f}}, {"B_elbow", "B_wrist", {0.7f, 0.7f, 0.7f}}, + {"B_wrist", "B_leg_LCTR", {0.6f, 0.1f, 0.6f}}, {"Head_LCTR", "Horn_LCTR", {0.8f, 0.1f, 0.6f}}, + {"Jaw_1", "C_bottomtooth", {2.f, 0.2f, 0.5f}}, +}}; + +std::array skHealthConstants{{ + 2420.f, + 1760.f, + 880.f, + 0.f, +}}; + +std::array skDrillerLocators{{"driller_LCTR1"sv, "driller_LCTR2"sv}}; + +std::array skEffectNames{{ + "Flame_Head"sv, + "Flame_HeadLockOn"sv, + "Flame_Lshoulder"sv, + "Flame_Rshoulder"sv, +}}; + +std::array skLegLocators{{ + "R_front_2"sv, + "L_front_2"sv, + "R_front_1"sv, + "L_front_1"sv, + ""sv, + ""sv, + "R_elbow"sv, + "L_elbow"sv, + ""sv, + ""sv, + "Head"sv, + "Head_LCTR"sv, + ""sv, + ""sv, + "R_shoulder"sv, + "L_shoulder"sv, + "R_stinger_2"sv, + "L_stinger_2"sv, + "R_spike_LCTR"sv, + "L_spike_LCTR"sv, +}}; + +std::array skBoneTrackingNames{{ + "L_eye_1"sv, + "L_eye_2"sv, + "L_eye_3"sv, + "R_eye_1"sv, + "R_eye_2"sv, + "R_eye_3"sv, +}}; + +std::array, 14> skSomeMeleeValues{{ + {{3, 3, 3}}, + {{-1, -1, -1}}, + {{2, 2, 2}}, + {{5, 5, 5}}, + {{8, 8, 8}}, + {{11, 11, 11}}, + {{1, 1, 1}}, + {{4, 4, 4}}, + {{7, 7, 7}}, + {{4, 7, 1}}, + {{-1, -1, -1}}, + {{-1, 2, -1}}, + {{-1, -1, -1}}, + {{0, 0, 0}}, +}}; + +std::array skSomeValues1{{ + 7, + 5, + 18, + 18, + 18, + 18, + 18, + 18, + 18, + 7, + 5, + 7, + 17, + 18, + 9, + 2, + 11, +}}; + +std::array, 14> skSomeValues2{{ + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Internal10, pas::ELocomotionType::Internal11, pas::ELocomotionType::Internal12}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Internal8, pas::ELocomotionType::Internal8, pas::ELocomotionType::Internal8}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, + {{pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid, pas::ELocomotionType::Invalid}}, +}}; +} // namespace SPrimeStruct2B::SPrimeStruct2B(CInputStream& in) : x0_propertyCount(in.readUint32Big()) , x4_particle1(in.readUint32Big()) @@ -20,26 +172,19 @@ SPrimeStruct2B::SPrimeStruct2B(CInputStream& in) , x38_(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) , x3a_(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) {} -SPrimeStruct5::SPrimeStruct5(CInputStream& in) -: x0_propertyCount(in.readUint32Big()) -, x4_(in.readUint32Big()) -, x8_(in.readUint32Big()) -, xc_(in.readUint32Big()) -, x10_(in.readUint32Big()) -, x14_(in.readUint32Big()) -, x18_(in.readUint32Big()) -, x1c_(in.readUint32Big()) -, x20_(in.readUint32Big()) {} - SPrimeStruct4::SPrimeStruct4(CInputStream& in) -: x0_beamInfo(in), x44_(in.readUint32Big()), x48_dInfo1(in), x64_struct5(in), x88_(in.readFloatBig()), x8c_dInfo2(in) {} +: x0_beamInfo(in) +, x44_(in.readUint32Big()) +, x48_dInfo1(in) +, x64_struct5(CPlasmaProjectile::LoadPlayerEffectResources(in)) +, x88_(in.readFloatBig()) +, x8c_dInfo2(in) {} SPrimeStruct6::SPrimeStruct6(CInputStream& in) -: x0_propertyCount(in.readUint32Big()) -, x4_damageVulnerability(in) -, x6c_color(zeus::CColor::ReadRGBABig(in)) -, x70_(in.readUint32Big()) -, x74_(in.readUint32Big()) {} +: x0_propertyCount(in.readUint32Big()), x4_damageVulnerability(in), x6c_color(zeus::CColor::ReadRGBABig(in)) { + x70_[0] = in.readUint32Big(); + x70_[1] = in.readUint32Big(); +} static CPatternedInfo LoadPatternedInfo(CInputStream& in) { std::pair pcount = CPatternedInfo::HasCorrectParameterCount(in); @@ -67,8 +212,9 @@ static CCameraShakeData LoadCameraShakeData(CInputStream& in) { static rstl::reserved_vector LoadPrimeStruct4s(CInputStream& in) { rstl::reserved_vector ret; - for (int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) { ret.emplace_back(in); + } return ret; } @@ -107,8 +253,9 @@ SPrimeExoParameters::SPrimeExoParameters(CInputStream& in) SPrimeExoRoomParameters::SPrimeExoRoomParameters(CInputStream& in) { u32 propCount = std::min(u32(14), in.readUint32Big()); - for (u32 i = 0; i < propCount; ++i) + for (u32 i = 0; i < propCount; ++i) { x0_.push_back(in.readFloatBig()); + } } CMetroidPrimeExo::CMetroidPrimeExo( @@ -121,6 +268,1631 @@ CMetroidPrimeExo::CMetroidPrimeExo( const CCameraShakeData& shakeData6, CAssetId particle2, CAssetId swoosh, CAssetId particle3, CAssetId particle4, const rstl::reserved_vector& struct6s) : CPatterned(ECharacter::MetroidPrimeExo, uid, name, EFlavorType::Zero, info, xf, std::move(mData), pInfo, - EMovementType::Flyer, EColliderType::One, EBodyType::Flyer, aParms, EKnockBackVariant::Large) {} + EMovementType::Flyer, EColliderType::One, EBodyType::Flyer, aParms, EKnockBackVariant::Large) +, x588_(struct6s) +, x8e8_headUpAdditiveBodyAnimIndex( + GetModelData()->GetAnimationData()->GetCharacterInfo().GetAnimationIndex("B_headup_additive_body"sv)) +, x91c_(pw1) +, x930_(struct2b) +, xc48_(g_SimplePool->GetObj({FOURCC('PART'), particle1})) +, xc50_(std::make_unique(xc48_, CElementGen::EModelOrientationType::Normal, + CElementGen::EOptionalSystemFlags::One)) +, xc78_(wpsc1, dInfo1) +, xca0_(shakeData4) +, xd74_(wpsc2, dInfo2) +, xd9c_(shakeData5) +, xe70_(projectileInfo) +, xeb4_(dInfo3) +, xed0_(shakeData6) +, xfa4_(g_SimplePool->GetObj("Effect_Electric"sv)) +, xfac_(std::make_unique(xfa4_)) +, x1014_(g_SimplePool->GetObj({FOURCC('PART'), particle3})) +, x101c_(g_SimplePool->GetObj({FOURCC('PART'), particle4})) +, x1024_(std::make_unique(x1014_, CElementGen::EModelOrientationType::Normal, + CElementGen::EOptionalSystemFlags::One)) +, x108c_(shakeData1) +, x1294_(shakeData2) +, x1368_(shakeData3) +, x143c_(std::make_unique(128, 128, true)) { + for (const auto& struct4 : struct4s) { + x96c_.emplace_back(struct4.x0_beamInfo); + xb30_.emplace_back(struct4.x64_struct5); + xbc4_.emplace_back(struct4.x8c_dInfo2); + xa80_.emplace_back(struct4.x44_, struct4.x48_dInfo1); + } -} // namespace urde::MP1 + x460_knockBackController.SetAutoResetImpulse(false); + x460_knockBackController.SetEnableBurn(false); + x460_knockBackController.SetEnableFreeze(false); + xc78_.Token().Lock(); + xd74_.Token().Lock(); + xfc4_.emplace_back(g_SimplePool->GetObj({FOURCC('PART'), particle2})); + xfc4_.emplace_back(g_SimplePool->GetObj({FOURCC('PART'), particle2})); + xfd8_.emplace_back(g_SimplePool->GetObj({FOURCC('SWSH'), swoosh})); + xfd8_.emplace_back(g_SimplePool->GetObj({FOURCC('SWSH'), swoosh})); + xfec_.emplace_back(std::make_unique(xfc4_[0])); + xfec_.emplace_back(std::make_unique(xfc4_[1])); + x1000_.emplace_back(std::make_unique(xfd8_[0], 0)); + x1000_.emplace_back(std::make_unique(xfd8_[1], 0)); + x102c_.push_back(0.3f); + x102c_.push_back(0.3f); + x1038_.push_back(0.f); + x1038_.push_back(2.f); +} + +void CMetroidPrimeExo::PreThink(float dt, CStateManager& mgr) { + CPatterned::PreThink(dt, mgr); + if (!GetActive()) { + return; + } + + if (TCastToConstPtr colAct = mgr.GetObjectById(x8cc_headColActor)) { + x8c8_ = colAct->GetHealthInfo(mgr)->GetHP(); + } +} + +void CMetroidPrimeExo::Think(float dt, CStateManager& mgr) { + CPatterned::Think(dt, mgr); + if (!GetActive()) { + return; + } + UpdateAreaId(mgr); + UpdateBoneTracking(dt, mgr); + UpdateCollision(dt, mgr); + UpdateHealthInfo(mgr); + UpdateColorChange(dt, mgr); + UpdateHeadAnimation(dt); + UpdatePlasmaProjectile(dt, mgr); + sub80274e6c(dt, mgr); + UpdateEnergyBalls(dt, mgr); + UpdatePhysicsDummy(mgr); + UpdateContactDamage(mgr); + UpdateTimers(dt); + UpdateSfxEmitter(dt, mgr); + sub80275e54(dt, mgr); +} + +void CMetroidPrimeExo::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId other, CStateManager& mgr) { + switch (msg) { + case EScriptObjectMessage::Activate: + x56c_collisionManager->SetActive(mgr, true); + break; + case EScriptObjectMessage::Deactivate: + x56c_collisionManager->SetActive(mgr, false); + break; + case EScriptObjectMessage::Start: + x1444_24_ = true; + break; + case EScriptObjectMessage::Touched: + DoContactDamage(other, mgr); + break; + case EScriptObjectMessage::Registered: + CreateShadow(false); + x450_bodyController->Activate(mgr); + x450_bodyController->SetLocomotionType(pas::ELocomotionType::Internal11); + SetupBoneTracking(); + SetupCollisionActorManager(mgr); + SetEyesParticleEffectState(mgr, true); + SetBoneTrackingTarget(mgr, true); + CreatePlasmaProjectiles(mgr); + CreatePhysicsDummy(mgr); + sub802755ac(mgr, true); + CreateHUDBillBoard(mgr); + mgr.GetPlayer().SetFrozenTimeoutBias(2.f); + break; + case EScriptObjectMessage::Deleted: { + x56c_collisionManager->Destroy(mgr); + FreePlasmaProjectiles(mgr); + sub802740cc(mgr); + FreeBillboard(mgr); + mgr.GetPlayer().SetFrozenTimeoutBias(0.f); + break; + } + case EScriptObjectMessage::InitializedInArea: + RemoveMaterial(EMaterialTypes::AIBlock, mgr); + UpdateRelay(mgr, GetAreaIdAlways()); + if (GetAreaIdAlways() == mgr.GetWorld()->GetCurrentAreaId()) { + SendStateToRelay(EScriptObjectState::MaxReached, mgr); + } + + if (xfac_) { + xfac_->SetParticleEmission(false); + } + break; + case EScriptObjectMessage::Damage: + sub8027827c(other, mgr); + [[fallthrough]]; + case EScriptObjectMessage::InvulnDamage: + return; + default: + break; + } + CPatterned::AcceptScriptMsg(msg, other, mgr); +} + +void CMetroidPrimeExo::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) { + CPatterned::PreRender(mgr, frustum); + x143c_->RenderShadowBuffer(mgr, *GetModelData(), GetTransform(), 1, zeus::skZero3f, 1.f, 5.f); + x143c_->Set_x98(0.8f); +} + +void CMetroidPrimeExo::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) { + CPatterned::AddToRenderer(frustum, mgr); + + if (frustum.aabbFrustumTest(*xc50_->GetBounds())) { + g_Renderer->AddParticleGen(*xc50_); + } + + if (frustum.aabbFrustumTest(*xfac_->GetBounds())) { + g_Renderer->AddParticleGen(*xfac_); + } + + if (frustum.aabbFrustumTest(*x1024_->GetBounds())) { + g_Renderer->AddParticleGen(*x1024_); + } + + for (size_t i = 0; i < 2; ++i) { + if (frustum.aabbFrustumTest(*xfec_[i]->GetBounds())) { + g_Renderer->AddParticleGen(*xfec_[i]); + } + + if (x1054_24_) { + g_Renderer->AddParticleGen(*x1000_[i]); + } + } +} + +void CMetroidPrimeExo::Render(CStateManager& mgr) { + g_Renderer->SetGXRegister1Color(x8d8_); + CPatterned::Render(mgr); +} + +bool CMetroidPrimeExo::CanRenderUnsorted(const CStateManager& mgr) const { + return mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::XRay; +} + +void CMetroidPrimeExo::Touch(CActor& act, CStateManager& mgr) { CPatterned::Touch(act, mgr); } + +void CMetroidPrimeExo::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) { + if (type == EUserEventType::ScreenShake) { + return; + } + if (type == EUserEventType::EffectOff) { + xc50_->SetParticleEmission(false); + return; + } + if (type == EUserEventType::EffectOn && x92c_ == 7) { + xc50_->SetParticleEmission(true); + if (auto* ent = static_cast(mgr.ObjectById(xb24_plasmaProjectileIds[x570_]))) { + zeus::CColor col = ent->GetInnerColor(); + col.a() = 1.f; + xc50_->SetModulationColor(col); + } + return; + } + if (type == EUserEventType::DamageOn) { + if (x92c_ == 11) { + sub802755ac(mgr, true); + x1054_26_ = true; + } else if (x92c_ == 7) { + FirePlasmaProjectile(mgr, true); + } + } else if (type == EUserEventType::DamageOff) { + if (x92c_ == 1) { + sub802755ac(mgr, false); + } else if (x92c_ == 7) { + FirePlasmaProjectile(mgr, false); + } + return; + } + if (type == EUserEventType::Projectile) {} + CPatterned::DoUserAnimEvent(mgr, node, type, dt); +} + +void CMetroidPrimeExo::SelectTarget(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x330_stateMachineState.SetDelay(zeus::clamp(0.2f, x924_ * 0.25f, 1.f)); + } else if (msg == EStateMsg::Update) { + sub80275800(mgr); + } else if (msg == EStateMsg::Deactivate) { + sub802738d4(mgr); + x1054_27_ = false; + } +} + +void CMetroidPrimeExo::Run(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x92c_ = 10; + x1084_ = 1.9666666f; + TUniqueId wpId = sub802769e0(mgr, true); + if (TCastToConstPtr wp = mgr.GetObjectById(wpId)) { + GetBodyController()->SetLocomotionType(sub80275e14(1)); + SetDestPos(wp->GetTranslation()); + x2dc_destObj = wpId; + x2ec_reflectedDestPos = GetTranslation(); + x328_24_inPosition = false; + } + SetEyesParticleEffectState(mgr, false); + } else if (msg == EStateMsg::Update) { + ApproachDest(mgr); + } else if (msg == EStateMsg::Deactivate) { + x92c_ = 0; + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + SetEyesParticleEffectState(mgr, true); + sub802738d4(mgr); + } +} + +void CMetroidPrimeExo::Attack(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + x92c_ = 6; + x1084_ = 0.2f; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::MeleeAttack, &CPatterned::TryMeleeAttack, sub80275e34(9)); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + x92c_ = 0; + sub802738d4(mgr); + x1254_ = 2; + } +} + +void CMetroidPrimeExo::TurnAround(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x92c_ = 9; + x32c_animState = EAnimState::Ready; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::Step, &CPatterned::TryStep, 3); + zeus::CVector3f vec = sub8027464c(mgr); + if ((vec - GetTranslation()).normalized().dot(mgr.GetPlayer().GetTranslation() - GetTranslation()) < 15.f) { + sub802747b8(arg, mgr, vec); + } + } else if (msg == EStateMsg::Deactivate) { + x92c_ = 0; + x32c_animState = EAnimState::NotReady; + } +} + +void CMetroidPrimeExo::Active(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x107c_ = 0.4f; + x1084_ = x1088_; + x3b4_speed = 1.f; + } else if (msg == EStateMsg::Update) { + if ((x570_ != 0 || x1078_ != 1) && x107c_ < 0.f && x1084_ < 0.f) { + x107c_ = x1080_; + x1084_ = 0.9f; + x1078_ = mgr.GetActiveRandom()->Next() % 3; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } + } else if (msg == EStateMsg::Deactivate) { + x1088_ = 0.2f; + } +} + +void CMetroidPrimeExo::InActive(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x1084_ = x1080_; + x1084_ = 0.2f; + x400_24_hitByPlayerProjectile = false; + x914_24_ = true; + SetEyesParticleEffectState(mgr, false); + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + UpdateHeadHealthInfo(mgr); + x3b4_speed = 1.f; + } else if (msg == EStateMsg::Update) { + if (x107c_ < 0.f && x1084_ < 0.f) { + x107c_ = x1080_; + x1084_ = 0.9f; + x1078_ = mgr.GetActiveRandom()->Next() % 3; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } + } else if (msg == EStateMsg::Deactivate) { + x914_24_ = false; + x1444_24_ = false; + SetEyesParticleEffectState(mgr, true); + sub802738d4(mgr); + x1084_ = x1080_; + x1088_ = x1084_; + mgr.SetBossParams(GetUniqueId(), 2860.0f, 91); + x8d0_ = x8d4_; + } +} + +void CMetroidPrimeExo::CoverAttack(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + x92c_ = 1; + x1084_ = 1.9666666f; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::MeleeAttack, &CPatterned::TryMeleeAttack, sub80275e34(0)); + zeus::CVector3f vec = (16.f * GetTransform().frontVector()) + GetTranslation(); + zeus::CVector3f direction = (vec - GetTranslation()).normalized(); + if (direction.dot(mgr.GetPlayer().GetTranslation() - GetTranslation()) < 15.f) { + sub802747b8(arg, mgr, vec - mgr.GetPlayer().GetTranslation()); + } + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + x92c_ = 0; + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } +} + +void CMetroidPrimeExo::Crouch(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::MeleeAttack, &CPatterned::TryMeleeAttack, 5); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + sub802738d4(mgr); + } +} + +void CMetroidPrimeExo::Taunt(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::Taunt, &CPatterned::TryTaunt, u32(skTaunts[x1078_])); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + } +} + +void CMetroidPrimeExo::Suck(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + GetBodyController()->SetLocomotionType(sub80275e14(10)); + x92c_ = 11; + x1054_25_ = false; + x1084_ = 0.8f; + mgr.GetPlayer().AttachActorToPlayer(GetUniqueId(), false); + } else if (msg == EStateMsg::Deactivate) { + mgr.GetPlayer().DetachActorFromPlayer(); + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + x92c_ = 0; + sub802755ac(mgr, false); + sub802738d4(mgr); + x1088_ = 0.6f; + if (mgr.GetPlayer().GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed) { + mgr.GetPlayer().SetOrbitRequestForTarget(GetUniqueId(), CPlayer::EPlayerOrbitRequest::ActivateOrbitSource, mgr); + x402_28_isMakingBigStrike = true; + x504_damageDur = 0.35f; + mgr.SendScriptMsgAlways(mgr.GetPlayer().GetUniqueId(), GetUniqueId(), EScriptObjectMessage::Damage); + mgr.GetPlayer().ApplyImpulseWR( + 60.f * (mgr.GetPlayer().GetMass() * (mgr.GetPlayer().GetTranslation() - GetTranslation()).normalized()), {}); + } + x1054_27_ = true; + } +} + +void CMetroidPrimeExo::ProjectileAttack(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + x92c_ = 7; + x1088_ = 1.0999999f; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::ProjectileAttack, &CPatterned::TryProjectileAttack, sub80275e34(x1254_)); + if (x32c_animState == EAnimState::Repeat) { + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + x92c_ = 0; + sub802738d4(mgr); + x1088_ = 1.2166667; + xc50_->SetParticleEmission(false); + FirePlasmaProjectile(mgr, false); + x1254_ = 2; + } +} + +void CMetroidPrimeExo::Flinch(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + SetEyesParticleEffectState(mgr, false); + DisableHeadOrbitAndTarget(mgr); + x8f4_28_ = false; + x8f4_27_ = false; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::KnockBack, &CPatterned::TryKnockBack_Front, 5); + if (x428_damageCooldownTimer < 0.25f * 0.33f) { + x428_damageCooldownTimer = 0.33f; + } + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + SetEyesParticleEffectState(mgr, true); + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + EnableHeadOrbitAndTarget(mgr); + } +} + +void CMetroidPrimeExo::Dodge(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::Step, &CPatterned::TryStep, 0); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + } +} + +void CMetroidPrimeExo::Retreat(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + SendStateToRelay(EScriptObjectState::Zero, mgr); + if (TCastToConstPtr wp = + mgr.GetObjectById(sub80276b3c(mgr, EScriptObjectState::CloseIn, EScriptObjectMessage::Follow))) { + SetTransform(wp->GetTransform()); + } + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::Scripted, &CPatterned::TryScripted, x918_); + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + if (TCastToConstPtr wp = + mgr.GetObjectById(sub80276b3c(mgr, EScriptObjectState::Retreat, EScriptObjectMessage::Follow))) { + SetTransform(wp->GetTransform()); + } + ++x91c_; + } +} + +void CMetroidPrimeExo::Cover(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + x92c_ = 12; + x1084_ = 1.2666667f; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::ProjectileAttack, &CPatterned::TryProjectileAttack, sub80275e34(13)); + if (x32c_animState == EAnimState::Repeat) { + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + x92c_ = 0; + sub802738d4(mgr); + x1254_ = 2; + } +} + +void CMetroidPrimeExo::Approach(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::MeleeAttack, &CPatterned::TryMeleeAttack, 2); + if (x32c_animState == EAnimState::Repeat) { + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + SetEyesParticleEffectState(mgr, true); + sub802738d4(mgr); + } +} + +void CMetroidPrimeExo::Enraged(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg != EStateMsg::Activate) { + return; + } + sub802786fc(mgr); +} + +void CMetroidPrimeExo::SpecialAttack(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg == EStateMsg::Activate) { + x32c_animState = EAnimState::Ready; + if (x1254_ == 2) { + x92c_ = 2; + } else if (x1254_ == 3) { + x92c_ = 3; + } else if (x1254_ == 4) { + x92c_ = 4; + } else if (x1254_ == 5) { + x92c_ = 5; + } + x1084_ = 1.2666667f; + sub80274054(mgr); + } else if (msg == EStateMsg::Update) { + TryCommand(mgr, pas::EAnimationState::ProjectileAttack, &CPatterned::TryProjectileAttack, sub80275e34(x1254_)); + if (x32c_animState == EAnimState::Repeat) { + x1078_ = 1; + GetBodyController()->SetLocomotionType(skLocomotions[x1078_]); + } + } else if (msg == EStateMsg::Deactivate) { + x32c_animState = EAnimState::NotReady; + x92c_ = 0; + sub802738d4(mgr); + } +} + +void CMetroidPrimeExo::Growth(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg != EStateMsg::Activate) { + return; + } + x3b4_speed = 1.4f; +} + +void CMetroidPrimeExo::Land(CStateManager& mgr, EStateMsg msg, float arg) { + if (msg != EStateMsg::Activate) { + return; + } + + sub802786fc(mgr); +} + +bool CMetroidPrimeExo::TooClose(CStateManager& mgr, float arg) { return CPatterned::TooClose(mgr, arg); } + +bool CMetroidPrimeExo::InMaxRange(CStateManager& mgr, float arg) { + return CPatterned::InMaxRange(mgr, arg) || (sub80277224(3.f, mgr) && sub80277224(7.f, mgr) && sub80277224(15.f, mgr)); +} + +bool CMetroidPrimeExo::PlayerSpot(CStateManager& mgr, float arg) { return mgr.GetPlayer().GetFrozenState(); } + +bool CMetroidPrimeExo::ShouldAttack(CStateManager& mgr, float arg) { return x1254_ == 9; } + +bool CMetroidPrimeExo::ShouldDoubleSnap(CStateManager& mgr, float arg) { + return !(!x328_24_inPosition && x2dc_destObj == kInvalidUniqueId && sub80277224(11.f, mgr)); +} + +bool CMetroidPrimeExo::InPosition(CStateManager& mgr, float arg) { return x1084_ <= 0.f; } + +bool CMetroidPrimeExo::ShouldTurn(CStateManager& mgr, float arg) { + return GetTransform().frontVector().dot(mgr.GetPlayer().GetTranslation() - GetTranslation()) < 0.f; +} + +bool CMetroidPrimeExo::CoverCheck(CStateManager& mgr, float arg) { return sub80277224(-8.f, mgr); } + +bool CMetroidPrimeExo::CoverFind(CStateManager& mgr, float arg) { return x1254_ == 12; } + +bool CMetroidPrimeExo::CoveringFire(CStateManager& mgr, float arg) { return x1254_ == 13; } + +bool CMetroidPrimeExo::AggressionCheck(CStateManager& mgr, float arg) { + return (mgr.GetPlayer().GetTranslation() - GetLctrTransform("Jaw_1"sv).origin).magSquared() < 324.f; +} + +bool CMetroidPrimeExo::AttackOver(CStateManager& mgr, float arg) { return x8f4_28_ || x8f4_27_ || x1054_25_; } + +bool CMetroidPrimeExo::ShouldFire(CStateManager& mgr, float arg) { return x1254_ == 6 || x1254_ == 7 || x1254_ == 8; } + +bool CMetroidPrimeExo::ShouldFlinch(CStateManager& mgr, float arg) { return x8f4_27_; } + +bool CMetroidPrimeExo::ShouldRetreat(CStateManager& mgr, float arg) { return x8f4_28_; } + +bool CMetroidPrimeExo::ShouldCrouch(CStateManager& mgr, float arg) { return x1254_ == 10; } + +bool CMetroidPrimeExo::ShouldMove(CStateManager& mgr, float arg) { return x1254_ == 1; } + +bool CMetroidPrimeExo::AIStage(CStateManager& mgr, float arg) { + return (arg < 0.25f && x1078_ == 0) || (arg >= 0.75f && x1078_ == 2) || (x1078_ == 1 && arg > 0.25f && arg <= 0.75f); +} + +bool CMetroidPrimeExo::StartAttack(CStateManager& mgr, float arg) { return x920_ <= 0.f; } + +bool CMetroidPrimeExo::ShouldSpecialAttack(CStateManager& mgr, float arg) { + return x1254_ == 2 || x1254_ == 3 || x1254_ == 4 || x1254_ == 5; +} + +bool CMetroidPrimeExo::CodeTrigger(CStateManager& mgr, float arg) { return x1444_24_; } + +CProjectileInfo* CMetroidPrimeExo::GetProjectileInfo() { + if (x92c_ == 5) { + return &xd74_; + } + if (x92c_ < 5 && x92c_ > 1) { + return &xc78_; + } + + return nullptr; +} + +void CMetroidPrimeExo::sub802738d4(CStateManager& mgr) { x920_ = mgr.GetActiveRandom()->Range(x924_, x928_); } + +void CMetroidPrimeExo::UpdateEnergyBalls(float dt, CStateManager& mgr) { + if (x1074_ > 0.f) { + for (size_t i = 0; i < x106c_energyBallIds.size(); ++i) { + if (auto* ball = CPatterned::CastTo(mgr.ObjectById(x106c_energyBallIds[i]))) { + ball->SetTransform(GetLctrTransform(skDrillerLocators[i])); + } + } + } else { + x106c_energyBallIds.clear(); + } +} + +u32 CMetroidPrimeExo::CountEnergyBalls(CStateManager& mgr) { + u32 ret = 0; + for (auto* ent : mgr.GetPhysicsActorObjectList()) { + if (CPatterned::CastTo(ent) != nullptr && ent->GetAreaIdAlways() == GetAreaIdAlways() && + ent->GetActive()) { + ++ret; + } + } + return ret; +} + +void CMetroidPrimeExo::sub80273d38(CStateManager& mgr) {} + +void CMetroidPrimeExo::UpdatePhysicsDummy(CStateManager& mgr) { + if (TCastToPtr physAct = mgr.ObjectById(xeac_)) { + zeus::CVector3f diffVec = mgr.GetPlayer().GetTranslation() - GetTranslation(); + if (!zeus::close_enough(diffVec, zeus::skZero3f)) { + zeus::CVector3f direction = diffVec.normalized(); + physAct->SetVelocityWR((direction.dot(GetTransform().frontVector()) > 0.f ? 7.5f : 5.f) * direction); + } else { + physAct->SetVelocityWR(zeus::skZero3f); + } + } +} + +void CMetroidPrimeExo::sub80274054(CStateManager& mgr) { + if (TCastToPtr act = mgr.ObjectById(xeac_)) { + act->SetTranslation(mgr.GetPlayer().GetTranslation()); + } +} + +void CMetroidPrimeExo::sub802740cc(CStateManager& mgr) {} + +void CMetroidPrimeExo::CreatePhysicsDummy(CStateManager& mgr) { + xeac_ = mgr.AllocateUniqueId(); + mgr.AddObject(new CPhysicsDummy(xeac_, true, ""sv, CEntityInfo(GetAreaIdAlways(), NullConnectionList))); +} + +void CMetroidPrimeExo::SetBillboardEmission(CStateManager& mgr, bool emission) { + if (TCastToPtr billboard = mgr.ObjectById(x1044_billboardId)) { + billboard->GetParticleGen()->SetParticleEmission(emission); + } +} + +void CMetroidPrimeExo::FreeBillboard(CStateManager& mgr) { mgr.FreeScriptObject(x1044_billboardId); } + +zeus::CVector3f CMetroidPrimeExo::sub8027464c(CStateManager& mgr) { + TUniqueId uid = sub80276b3c(mgr, EScriptObjectState::Attack, EScriptObjectMessage::Follow); + + float dVar4 = 0.f; + zeus::CVector3f tmpVec; + for (; uid != kInvalidUniqueId;) { + auto wp = TCastToConstPtr(mgr.GetObjectById(uid)); + if (wp) { + tmpVec += wp->GetTranslation(); + dVar4 += 1.f; + } + uid = wp->NextWaypoint(mgr); + } + + if (dVar4 <= 0.f) { + return zeus::skZero3f; + } + + return (1.f / dVar4) * tmpVec; +} + +void CMetroidPrimeExo::CreateHUDBillBoard(CStateManager& mgr) { + x1044_billboardId = mgr.AllocateUniqueId(); + mgr.AddObject(new CHUDBillboardEffect( + {x101c_}, std::nullopt, x1044_billboardId, true, ""sv, CHUDBillboardEffect::GetNearClipDistance(mgr), + CHUDBillboardEffect::GetScaleForPOV(mgr), zeus::skWhite, zeus::skOne3f, zeus::skZero3f)); +} + +void CMetroidPrimeExo::sub802747b8(float f1, CStateManager& mgr, const zeus::CVector3f& vec) { + if (mgr.RayCollideWorld(mgr.GetPlayer().GetTranslation(), mgr.GetPlayer().GetTranslation() + (0.2f * zeus::skDown), + CMaterialFilter::MakeInclude({EMaterialTypes::Floor, EMaterialTypes::Platform}), this)) { + mgr.GetPlayer().ApplyImpulseWR((10.f * mgr.GetPlayer().GetMass()) * zeus::skUp, {}); + mgr.GetPlayer().SetMoveState(CPlayer::EPlayerMovementState::ApplyJump, mgr); + } + zeus::CVector3f vec2 = vec; + vec2.z() = 0.f; + if (!zeus::close_enough(vec2, zeus::skZero3f)) { + mgr.GetPlayer().ApplyImpulseWR(f1 * (mgr.GetPlayer().GetMass() * (120.f * vec2)), {}); + mgr.GetPlayer().UseCollisionImpulses(); + mgr.GetPlayer().SetAccelerationChangeTimer(2.f * f1); + } +} + +void CMetroidPrimeExo::sub802749e8(float f1, float f2, float f3, const zeus::CVector3f& vec1, + const zeus::CVector3f& vec2) {} + +void CMetroidPrimeExo::sub80274e6c(float f1, CStateManager& mgr) { + if (GetBodyController()->GetPercentageFrozen() > 0.f && x1054_24_) { + sub802755ac(mgr, false); + x1054_25_ = true; + } + + constexpr std::array EyeLocators{{ + "L_eye_3"sv, + "R_eye_3"sv, + }}; + float dVar9 = 0.f; + for (size_t i = 0; i < 2; ++i) { + x102c_[i] -= f1; + x1038_[i] += f1; + zeus::CTransform xf = GetLctrTransform(EyeLocators[i]); + zeus::CVector3f off = + (mgr.GetPlayer().GetTranslation() + (g_tweakPlayer->GetPlayerBallHalfExtent() * zeus::skUp) + + (g_tweakPlayer->GetPlayerBallHalfExtent() * xf.origin - mgr.GetPlayer().GetTranslation()).normalized()); + if (x1054_24_) { + float dVar13 = zeus::clamp(0.f, 2.f * (x102c_[i] / 0.3f) - 1.f, 1.f); + float dVar12 = 1.f - dVar13; + float tmp = zeus::clamp(0.f, 0.5f + (x102c_[i] / 0.3f), 1.f); + zeus::CVector3f local_154 = off * dVar12 + (xf.origin * dVar13); + sub802749e8(2.f * tmp, 0.5f * tmp, x1038_[i], xf.origin, local_154); + if (tmp <= 0.f) { + if (mgr.RayCollideWorld(xf.origin, local_154, + CMaterialFilter::MakeIncludeExclude( + {EMaterialTypes::Solid}, {EMaterialTypes::Player, EMaterialTypes::CollisionActor}), + this)) { + x1054_25_ = true; + } + } else if (dVar13 <= 0.f) { + dVar9 += 1.f - tmp; + } + x1024_->SetTranslation(local_154); + } else if (CParticleSwoosh::GetAliveParticleSystemCount() != 0) { + float tmp1 = zeus::clamp(0.f, 3.f * (x102c_[i] / 0.3f) - 2.f, 1.f); + float tmp2 = zeus::clamp(0.f, 0.5f + (x102c_[i] / 0.3f), 1.f); + sub802749e8(tmp2, tmp2, x1038_[i], xf.origin, xf.origin * (1.f - tmp1) + (off * tmp1)); + x1000_[i]->Update(f1); + } + xfec_[i]->Update(f1); + } + x1024_->Update(f1); + if ((0.5f * dVar9) > 0.9f && x1054_24_) { + x1024_->SetParticleEmission(true); + SetBillboardEmission(mgr, true); + } + + if (zeus::close_enough(0.f, dVar9)) { + return; + } + + if (mgr.GetPlayer().GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed) { + if (mgr.GetPlayer().GetMorphBall()->IsBoosting()) { + x1054_25_ = true; + } + if (mgr.GetPlayer().GetAttachedActorStruggle() == 1.f) { + x1054_25_ = true; + } + } + zeus::CTransform jawXf = GetLctrTransform("Jaw_1"sv); + zeus::CVector3f direction = (jawXf.origin - mgr.GetPlayer().GetTranslation()).normalized(); + + float offX = (mgr.GetPlayer().GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed ? 31.49f + : mgr.GetPlayer().GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit ? 136.5f + : 20.4749f); + if ((x1054_26_ && dVar9 > 0.75f) || x1048_ > 0.f) { + if (!x1054_26_) { + x1048_ -= f1; + } else { + x1054_26_ = false; + x1048_ = std::sqrt(1.5f / GravityConstant()); + } + mgr.GetPlayer().ApplyImpulseWR(f1 * (mgr.GetPlayer().GetMass() * std::sqrt(1.5f * GravityConstant()) * zeus::skUp), + {}); + mgr.GetPlayer().SetMoveState(CPlayer::EPlayerMovementState::ApplyJump, mgr); + } + + mgr.GetPlayer().ApplyImpulseWR(f1 * ((0.5f * dVar9) * offX + direction), {}); + mgr.GetPlayer().UseCollisionImpulses(); + mgr.GetPlayer().SetAccelerationChangeTimer(2.f * f1); +} + +void CMetroidPrimeExo::sub802755ac(CStateManager& mgr, bool b1) { + for (size_t i = 0; i < 2; ++i) { + x1000_[i]->SetParticleEmission(b1); + if (!b1) { + x1024_->SetParticleEmission(false); + SetBillboardEmission(mgr, false); + } else if (x1054_24_ != b1) { + x102c_[i] = 0.3f; + for (size_t j = 0; j < x1000_[i]->GetSwooshes().size(); ++j) { + x1000_[i]->ForceOneUpdate(0.f); + } + } + } + x1054_24_ = b1; +} + +void CMetroidPrimeExo::EnableHeadOrbitAndTarget(CStateManager& mgr) { + if (TCastToPtr colAct = mgr.ObjectById(x8cc_headColActor)) { + colAct->AddMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr); + } +} + +void CMetroidPrimeExo::DisableHeadOrbitAndTarget(CStateManager& mgr) { + if (TCastToPtr colAct = mgr.ObjectById(x8cc_headColActor)) { + colAct->RemoveMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr); + } +} + +void CMetroidPrimeExo::UpdateTimers(float dt) { + if (GetBodyController()->GetPercentageFrozen() != 0.f) { + return; + } + + x107c_ -= dt; + x1084_ -= dt * GetModelData()->GetAnimationData()->GetSpeedScale(); + x920_ -= dt; +} + +void CMetroidPrimeExo::sub80275800(CStateManager& mgr) { + TUniqueId tmpId = sub802769e0(mgr, true); + + u32 flags = 0x13c1; + if (tmpId != kInvalidUniqueId) { + if (TCastToConstPtr wp = mgr.GetObjectById(tmpId)) { + if ((wp->GetTranslation() - GetTranslation()).magSquared() > 16.f) { + flags = 0x13c3; + } + } + } + + if (!x1054_27_) { + flags |= 0x400; + } + if (GetTransform().frontVector().dot(mgr.GetPlayer().GetTranslation() - GetTranslation()) > 30.f) { + flags |= 0x3c; + } + + if (CountEnergyBalls(mgr) == 0) { + flags |= 0x2000; + } + + if (sub80277224(7.f, mgr)) { + flags |= 0x800; + } + + sub802759a8(mgr, flags); +} + +void CMetroidPrimeExo::sub802759a8(CStateManager& mgr, u32 w1) { + float dVar7 = 0.f; + const auto& parms = x1160_[x570_]; + for (size_t i = 0; i < 14; ++i) { + if (((w1 & (1 << i)) != 0u) && sub80275d68(i)) { + dVar7 += sub80275b04(parms, i); + } + } + + if (dVar7 > 30000.0f) { + sub80275b68(); + } + + dVar7 = mgr.GetActiveRandom()->Range(0.f, dVar7); + x1254_ = -1; + float dVar5 = 0.f; + for (size_t i = 0; i < 13; ++i) { + if (((w1 & (1 << i)) != 0u) && sub80275d68(i)) { + float dVar6 = sub80275b04(parms, i); + if ((dVar5 < dVar7) && (dVar7 < (dVar5 + dVar6))) { + x1254_ = i; + x1258_[i] += 3.f; + break; + } + + dVar5 += dVar6; + } + } +} + +float CMetroidPrimeExo::sub80275b04(const SPrimeExoRoomParameters& roomParms, int w2) { + float dVar1 = 0.f; + if (!zeus::close_enough(0.f, x1258_[w2])) { + const float tmpFloat = roomParms.GetFloatValue(w2); + dVar1 = (tmpFloat * tmpFloat) / x1258_[w2]; + } + + return dVar1; +} + +void CMetroidPrimeExo::sub80275b68() { + float fVar9 = 0.f; + for (float f : x1258_) { + fVar9 += f; + } + + if (zeus::close_enough(fVar9, 0.f)) { + return; + } + + for (float& f : x1258_) { + f /= fVar9; + } +} + +void CMetroidPrimeExo::sub80275c60(CStateManager& mgr, int w1) { + if (x570_ == -1) { + return; + } + + x1258_.clear(); + + for (size_t i = 0; i < 14; ++i) { + x1258_.push_back(x1160_[x570_].GetFloatValue(i)); + } + + if (x1078_ == -1) { + return; + } + + for (size_t i = 0; i < 40; ++i) { + sub802759a8(mgr, -1); + } +} + +bool CMetroidPrimeExo::sub80275d68(int w1) { + // TODO(antidote): Simplify expressions and rename globals + const s32 iVar1 = skSomeValues1[w1]; + if (iVar1 == 7 || iVar1 == 18) { + return (-1 - ((skSomeMeleeValues[w1][x1078_] >> 24) | (((skSomeMeleeValues[w1][x1078_] + 1) >> 24) >> 7))) != 0; + } + if (iVar1 == 5) { + return (-1 - ((int(skSomeValues2[w1][x1078_]) >> 24) | (((int(skSomeValues2[w1][x1078_]) + 1) >> 24) >> 7))) != 0; + } + + return iVar1 == 17; +} + +pas::ELocomotionType CMetroidPrimeExo::sub80275e14(int w1) { return skSomeValues2[w1][x1078_]; } + +u32 CMetroidPrimeExo::sub80275e34(int w1) const { return skSomeMeleeValues[w1][x1078_]; } + +void CMetroidPrimeExo::sub80275e54(float dt, CStateManager& mgr) { + if (!xfac_) { + return; + } + + xfac_->SetGlobalOrientation(GetTransform().getRotation()); + xfac_->SetGlobalTranslation(GetTranslation()); + xfac_->SetGlobalScale(GetModelData()->GetScale()); + if (xfc0_) { + CSfxManager::UpdateEmitter(xfbc_, GetTranslation(), zeus::skZero3f, 1.f); + xfac_->SetParticleEmission(true); + const auto* animData = GetModelData()->GetAnimationData(); + for (size_t i = 0; i < 4; ++i) { + xfac_->SetOverrideIPos( + animData + ->GetLocatorTransform(animData->GetLocatorSegId(skLegLocators[mgr.GetActiveRandom()->Range(0, 19)]), + nullptr) + .origin); + xfac_->SetOverrideFPos( + animData + ->GetLocatorTransform(animData->GetLocatorSegId(skLegLocators[mgr.GetActiveRandom()->Range(0, 19)]), + nullptr) + .origin); + xfac_->ForceParticleCreation(1); + } + + xfac_->SetParticleEmission(false); + xfb4_ -= dt; + if (xfb4_ <= 0.f) { + sub80276204(mgr, false); + } + } + xfac_->Update(dt); +} + +void CMetroidPrimeExo::UpdateSfxEmitter(float f1, CStateManager& mgr) { + if (!xfc1_) { + return; + } + + xfb8_ -= f1; + if (xfb8_ <= 0.f) { + sub8027639c(mgr, false); + } + + if (xfbc_) { + CSfxManager::UpdateEmitter(xfbc_, GetTranslation(), zeus::skZero3f, 1.f); + } +} + +void CMetroidPrimeExo::sub80276204(CStateManager& mgr, bool b1) { + if (b1 && xfc1_) { + sub8027639c(mgr, false); + } + + xfc0_ = b1; + if (!b1) { + CSfxManager::RemoveEmitter(xfbc_); + xfbc_.reset(); + GetBodyController()->GetCommandMgr().DeliverCmd(CBodyStateCmd{EBodyStateCmd::StopReaction}); + } else { + if (xfbc_) { + xfbc_.reset(); + } + xfbc_ = CSfxManager::AddEmitter(SFXsfx0519, GetTranslation(), zeus::skZero3f, 1.f, true, true, 127, kInvalidAreaId); + GetBodyController()->GetCommandMgr().DeliverCmd( + CBCAdditiveReactionCmd(pas::EAdditiveReactionType::Electrocution, 1.f, true)); + } +} + +void CMetroidPrimeExo::sub8027639c(CStateManager& mgr, bool b1) { + if (b1 && xfc0_) { + sub80276204(mgr, false); + } + + for (size_t i = 0; i < 4; ++i) { + GetModelData()->GetAnimationData()->SetParticleEffectState(skEffectNames[i], b1, mgr); + } + + xfc1_ = b1; + if (!b1) { + CSfxManager::RemoveEmitter(xfbc_); + xfbc_.reset(); + } else { + if (xfbc_) { + xfbc_.reset(); + } + xfbc_ = CSfxManager::AddEmitter(SFXsfx051A, GetTranslation(), zeus::skZero3f, 1.f, true, true, 127, kInvalidAreaId); + } +} + +void CMetroidPrimeExo::SetActorAreaId(CStateManager& mgr, TUniqueId uid, TAreaId aid) { + if (auto* act = static_cast(mgr.ObjectById(uid))) { + mgr.SetActorAreaId(*act, aid); + } +} + +void CMetroidPrimeExo::UpdateAreaId(CStateManager& mgr) { + if (!x914_24_) { + return; + } + + TAreaId curAreaId = mgr.GetWorld()->GetCurrentAreaId(); + if (GetAreaIdAlways() == curAreaId) { + if (x1444_25_) { + x1444_25_ = false; + SendStateToRelay(EScriptObjectState::MaxReached, mgr); + } + } else if (!IsRelayValid(mgr, curAreaId)) { + x1444_25_ = true; + } else { + SetActorAreaId(mgr, GetUniqueId(), curAreaId); + + for (size_t i = 0; i < x56c_collisionManager->GetNumCollisionActors(); ++i) { + SetActorAreaId(mgr, x56c_collisionManager->GetCollisionDescFromIndex(i).GetCollisionActorId(), curAreaId); + } + + for (const auto& uid : xb24_plasmaProjectileIds) { + SetActorAreaId(mgr, uid, curAreaId); + } + + SetActorAreaId(mgr, xeac_, curAreaId); + UpdateRelay(mgr, GetAreaIdAlways()); + SendStateToRelay(EScriptObjectState::MaxReached, mgr); + } +} + +void CMetroidPrimeExo::SendStateToRelay(EScriptObjectState state, CStateManager& mgr) { + if (TCastToPtr relay = mgr.ObjectById(x568_relayId)) { + relay->SendScriptMsgs(state, mgr, EScriptObjectMessage::None); + } +} + +void CMetroidPrimeExo::sub80276754(CStateManager& mgr) { + x1160_.clear(); + if (TCastToConstPtr relay = mgr.GetObjectById(x568_relayId)) { + x1160_ = relay->GetRoomParameters(); + x8c0_ = relay->GetHealthInfo1(); + x924_ = relay->Get_xc84(); + x928_ = relay->Get_xc88(); + x1080_ = relay->Get_xc8c(); + x1440_ = relay->Get_xc90(); + x918_ = relay->Get_xcac(); + x584_ = relay->Get_xc94(); + x574_ = relay->Get_xc98(); + x8d4_ = relay->Get_xcb0(); + x57c_ = relay->Get_xcb4(); + sub80275c60(mgr, relay->Get_xcb4()); + } +} + +TUniqueId CMetroidPrimeExo::sub802769e0(CStateManager& mgr, bool b1) { + TUniqueId uid = sub80276b3c(mgr, EScriptObjectState::Attack, EScriptObjectMessage::Follow); + float lastDot = 0.f; + TUniqueId lastUid = kInvalidUniqueId; + while (uid != kInvalidUniqueId) { + if (TCastToConstPtr wp = mgr.GetObjectById(uid)) { + float dot = GetTransform().frontVector().dot(wp->GetTranslation() - GetTranslation()); + + if ((b1 && dot > 0.f && dot > lastDot) || (!b1 && dot < 0.f && dot < lastDot)) { + lastUid = uid; + lastDot = dot; + } + uid = wp->NextWaypoint(mgr); + } else { + uid = kInvalidUniqueId; + } + } + + return lastUid; +} + +TUniqueId CMetroidPrimeExo::sub80276b3c(CStateManager& mgr, EScriptObjectState state, EScriptObjectMessage msg) { + if (TCastToConstPtr relay = mgr.GetObjectById(x568_relayId)) { + rstl::reserved_vector uids; + for (const auto& conn : relay->GetConnectionList()) { + if (conn.x0_state != state || conn.x4_msg != msg) { + continue; + } + + TUniqueId uid = mgr.GetIdForScript(conn.x8_objId); + const auto* ent = mgr.GetObjectById(uid); + if (ent != nullptr && ent->GetActive()) { + uids.push_back(uid); + if (uids.size() == 8) { + break; + } + } + } + + if (!uids.empty()) { + return uids[mgr.GetActiveRandom()->Next() % uids.size()]; + } + } + return kInvalidUniqueId; +} + +void CMetroidPrimeExo::UpdateRelay(CStateManager& mgr, TAreaId areaId) { + if (x568_relayId != kInvalidUniqueId) { + if (TCastToPtr relay = mgr.ObjectById(x568_relayId)) { + relay->SetMetroidPrimeExoId(kInvalidUniqueId); + } + } + + TEditorId tmpEditorId = kInvalidEditorId; + for (auto* ent : mgr.GetAllObjectList()) { + if (TCastToPtr relay = ent) { + if (relay->GetActive() && relay->GetAreaIdAlways() == areaId) { + tmpEditorId = relay->GetEditorId(); + } + } + } + + x568_relayId = kInvalidUniqueId; + if (tmpEditorId != kInvalidEditorId) { + TUniqueId uid = mgr.GetIdForScript(tmpEditorId); + x568_relayId = uid; + if (TCastToPtr relay = mgr.ObjectById(uid)) { + relay->SetMetroidPrimeExoId(GetUniqueId()); + } + } + + sub80276754(mgr); + sub80273d38(mgr); +} + +bool CMetroidPrimeExo::IsRelayValid(CStateManager& mgr, TAreaId aid) { + TEditorId tmpId = kInvalidEditorId; + + for (const auto* ent : mgr.GetAllObjectList()) { + if (TCastToConstPtr relay = ent) { + if (relay->GetAreaIdAlways() == aid) { + tmpId = relay->GetEditorId(); + } + } + } + + return tmpId != kInvalidEditorId; +} + +bool CMetroidPrimeExo::sub80277224(float f1, CStateManager& mgr) { + TUniqueId uid = sub802769e0(mgr, f1 >= 0.f); + + if (TCastToConstPtr wp = mgr.GetObjectById(uid)) { + const float dist = (wp->GetTranslation() - GetTranslation()).magSquared(); + const float scaleMag = f1 * (0.57735026f * GetModelData()->GetScale().magSquared()); + if (f1 < 0.f) { + return dist > scaleMag; + } + return dist < scaleMag; + } + return false; +} + +void CMetroidPrimeExo::FirePlasmaProjectile(CStateManager& mgr, bool b1) { + if (b1) { + xc58_curPlasmaProjectile = x570_; + if (auto* proj = + static_cast(mgr.ObjectById(xb24_plasmaProjectileIds[xc58_curPlasmaProjectile]))) { + if (proj->GetDamageInfo().GetWeaponMode().GetType() == EWeaponType::Power) { + proj->AddAttrib(EProjectileAttrib::BigStrike); + proj->SetDamageDuration(1.4f); + } + + xc60_ = GetTargetVector(mgr); + xc6c_ = xc60_; + xc5c_ = 0.f; + proj->Fire(zeus::lookAt(GetLctrTransform("Jaw_1"sv).origin, xc60_), mgr, false); + } + } else { + for (const auto& plasmaId : xb24_plasmaProjectileIds) { + if (auto* proj = static_cast(mgr.ObjectById(plasmaId))) { + if (proj->IsFiring()) { + proj->ResetBeam(mgr, false); + } + } + } + } +} + +void CMetroidPrimeExo::UpdatePlasmaProjectile(float dt, CStateManager& mgr) { + zeus::CTransform jawXf = GetLctrTransform("Jaw_1"sv); + xc50_->SetTranslation(jawXf.origin); + xc50_->SetOrientation(jawXf.getRotation()); + xc50_->Update(dt); + if (xc58_curPlasmaProjectile >= 0 && xc58_curPlasmaProjectile < 4) { + if (auto* ent = + static_cast(mgr.ObjectById(xb24_plasmaProjectileIds[xc58_curPlasmaProjectile]))) { + if (!ent->GetActive()) { + return; + } + + if (GetBodyController()->GetPercentageFrozen() > 0.f) { + FirePlasmaProjectile(mgr, false); + } + + zeus::CTransform xf; + xc5c_ = zeus::clamp(0.f, xc5c_ + dt, 1.4f); + const float fVar1 = xc5c_ / 1.f; + const float fVar2 = 1.f - fVar1; + zeus::CVector3f vec1 = xc60_ * fVar2 + xc6c_ * fVar1; + zeus::CVector3f vec2 = vec1 - jawXf.origin; + if (vec2.normalized().dot(GetTransform().frontVector()) <= zeus::degToRad(40.f)) { + xf = (zeus::CQuaternion::lookAt(GetTransform().frontVector(), vec2.normalized(), zeus::degToRad(45.f)) * + zeus::CQuaternion(GetTransform().buildMatrix3f())) + .toTransform(); + } else { + xf = zeus::lookAt(jawXf.origin, vec1); + } + + ent->UpdateFx(xf, dt, mgr); + } + } +} + +zeus::CVector3f CMetroidPrimeExo::GetTargetVector(CStateManager& mgr) { + constexpr auto MatFilter = CMaterialFilter::MakeIncludeExclude( + {EMaterialTypes::Solid}, {EMaterialTypes::Character, EMaterialTypes::Player, EMaterialTypes::Projectile}); + rstl::reserved_vector nearList; + mgr.BuildNearList(nearList, GetTranslation(), zeus::skDown, 150.f, MatFilter, this); + + TUniqueId uid = kInvalidUniqueId; + CRayCastResult res = + mgr.RayWorldIntersection(uid, mgr.GetPlayer().GetTranslation(), zeus::skDown, 150.f, MatFilter, nearList); + const auto pos = 0.5f * (mgr.GetPlayer().GetAimPosition(mgr, 0.f) + mgr.GetPlayer().GetTranslation()); + if (res.IsInvalid()) { + return pos; + } + + return res.GetPoint() + zeus::CVector3f{0.f, 0.f, pos.z() - mgr.GetPlayer().GetTranslation().z()}; +} + +void CMetroidPrimeExo::FreePlasmaProjectiles(CStateManager& mgr) { + for (auto& uid : xb24_plasmaProjectileIds) { + mgr.FreeScriptObject(uid); + uid = kInvalidUniqueId; + } +} + +void CMetroidPrimeExo::CreatePlasmaProjectiles(CStateManager& mgr) { + xc50_->SetParticleEmission(false); + xc50_->SetGlobalScale(GetModelData()->GetScale()); + + for (size_t i = 0; i < x96c_.size(); ++i) { + xb24_plasmaProjectileIds[i] = mgr.AllocateUniqueId(); + CDamageInfo dInfo = xa80_[i].GetDamage(); + dInfo.SetWeaponMode(CWeaponMode(EWeaponType::PoisonWater)); + EProjectileAttrib flags = EProjectileAttrib::PlayerUnFreeze; + if (xa80_[i].GetDamage().GetWeaponMode().GetType() == EWeaponType::Ice) { + flags = EProjectileAttrib::None; + } + mgr.AddObject(new CPlasmaProjectile(xa80_[i].Token(), ""sv, xa80_[i].GetDamage().GetWeaponMode().GetType(), + x96c_[i], {}, EMaterialTypes::Character, dInfo, xb24_plasmaProjectileIds[i], + GetAreaIdAlways(), GetUniqueId(), xb30_[i], true, flags)); + } +} + +void CMetroidPrimeExo::UpdateContactDamage(CStateManager& mgr) { + const auto* mData = GetModelData(); + zeus::CVector3f max = GetTranslation() + zeus::CVector3f{(0.57735026f * mData->GetScale().magnitude()) * 6.f, + (0.57735026f * mData->GetScale().magnitude()) * 6.f, + (0.57735026f * mData->GetScale().magnitude()) * 5.5f}; + zeus::CVector3f min = GetTranslation() + zeus::CVector3f{(0.57735026f * mData->GetScale().magnitude()) * -6.f, + (0.57735026f * mData->GetScale().magnitude()) * -6.f, + (0.57735026f * mData->GetScale().magnitude()) * 2.f}; + x8f8_ = zeus::CAABox{min, max}; + + if (mgr.GetPlayer().GetTouchBounds()->intersects(x8f8_)) { + mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), GetContactDamage(), + CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); + x420_curDamageRemTime = x424_damageWaitTime; + } +} + +void CMetroidPrimeExo::UpdateColorChange(float f1, CStateManager& mgr) { + if (!x8f4_24_) { + return; + } + + if (x8e4_ >= 1.f) { + x8d8_ = x8e0_; + x8f4_24_ = false; + GetModelData()->GetAnimationData()->SetParticleEffectState("ColorChange"sv, false, mgr); + } else { + x8e4_ = std::max(1.f, x8e4_ + f1 / 0.3f); + x8d8_ = zeus::CColor::lerp(x8dc_, x8e0_, x8e4_); + } +} + +void CMetroidPrimeExo::sub80278130(const zeus::CColor& col) { + x8e4_ = 0.f; + x8f4_24_ = true; + x8e0_ = col; + x8dc_ = x8d8_; +} + +void CMetroidPrimeExo::UpdateHeadAnimation(float f1) { + if (x8e8_headUpAdditiveBodyAnimIndex == -1) { + return; + } + if (!x8f4_25_) { + if (x8ec_ > 0.f) { + x8ec_ = std::min(0.f, x8ec_ - f1 / 0.1f); + } + } else if (x8ec_ < 1.f) { + x8ec_ = std::max(1.f, x8ec_ + f1 / 0.5f); + } + + if (x8ec_ > 0.f || x8f4_26_) { + if (x8ec_ <= FLT_EPSILON) { + GetModelData()->GetAnimationData()->DelAdditiveAnimation(x8e8_headUpAdditiveBodyAnimIndex); + x8f4_26_ = false; + } else { + GetModelData()->GetAnimationData()->AddAdditiveAnimation(x8e8_headUpAdditiveBodyAnimIndex, x8ec_, true, false); + x8f4_26_ = true; + } + } +} + +void CMetroidPrimeExo::sub8027827c(TUniqueId uid, CStateManager& mgr) { + if (uid == x8cc_headColActor) { + if (TCastToConstPtr colAct = mgr.GetObjectById(uid)) { + if (!IsAlive()) { + return; + } + + if (TCastToConstPtr wp = mgr.GetObjectById(colAct->GetLastTouchedObject())) { + if (colAct->GetDamageVulnerability()->WeaponHurts(wp->GetDamageInfo().GetWeaponMode(), false)) { + x428_damageCooldownTimer = 0.33f; + if (wp->GetDamageInfo().GetWeaponMode().GetType() == EWeaponType::Ice) { + if (TCastToPtr wat = mgr.ObjectById(uid)) { + wat->HealthInfo(mgr)->SetHP(wat->HealthInfo(mgr)->GetHP() - + (0.5f * (x8c8_ - wat->GetHealthInfo(mgr)->GetHP()))); + } + } + if (wp->GetDamageInfo().GetWeaponMode().GetType() == EWeaponType::Wave && + (wp->GetDamageInfo().GetWeaponMode().IsCharged() || wp->GetDamageInfo().GetWeaponMode().IsComboed())) { + xfb4_ = 1.5f; + sub80276204(mgr, true); + } + + if (wp->GetDamageInfo().GetWeaponMode().GetType() == EWeaponType::Plasma && + (wp->GetDamageInfo().GetWeaponMode().IsCharged() || wp->GetDamageInfo().GetWeaponMode().IsComboed())) { + xfb8_ = 1.5f; + sub8027639c(mgr, true); + xfc1_ = true; + } + + if (wp->GetDamageInfo().GetWeaponMode().GetType() == EWeaponType::Ice && + wp->GetDamageInfo().GetWeaponMode().IsComboed()) { + Freeze(mgr, zeus::skZero3f, colAct->GetTranslation() - wp->GetTranslation(), 2.f); + } + } + } + } + } +} + +void CMetroidPrimeExo::sub80278508(CStateManager& mgr, int w1, bool b1) { + if (x570_ != w1) { + GetModelData()->GetAnimationData()->SetParticleEffectState("ColorChange", true, mgr); + + CAudioSys::C3DEmitterParmData emitterData{ + GetTranslation(), zeus::skZero3f, 1000.f, 0.1f, 1, SFXsfx0B9A, 1.f, 0.16f, false, 127}; + CSfxManager::AddEmitter(emitterData, true, 127, false, GetAreaIdAlways()); + } + x570_ = w1; + sub80278130(x588_[x570_].x6c_color); + if (TCastToPtr colAct = mgr.ObjectById(x8cc_headColActor)) { + if (b1 == false) { + colAct->SetDamageVulnerability(CDamageVulnerability::ImmuneVulnerabilty()); + mgr.GetPlayer().SetOrbitRequestForTarget(GetUniqueId(), CPlayer::EPlayerOrbitRequest::ActivateOrbitSource, mgr); + colAct->RemoveMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr); + } else { + colAct->SetDamageVulnerability(x588_[x570_].x4_damageVulnerability); + colAct->AddMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr); + } + } +} + +void CMetroidPrimeExo::sub802786fc(CStateManager& mgr) { + int w1 = 0; + if (!x584_) { + w1 = x570_; + u32 iVar2 = 0; + do { + ++iVar2; + if (iVar2 < 10) { + w1 = x588_[w1].x70_[mgr.GetActiveRandom()->Next() & 1]; + } else if (iVar2 < 19) { + w1 = x588_[w1].x70_[1]; + } else { + break; + } + } while (((x57c_ & (1 << w1)) != 0u) || ((x580_ & (1 << w1)) != 0)); + x580_ |= 1 << w1; + } else { + w1 = x588_[x570_].x70_[mgr.GetActiveRandom()->Next() & 1]; + } + + sub80278508(mgr, w1, x8f4_25_); + sub80275c60(mgr, w1); +} + +void CMetroidPrimeExo::SetEyesParticleEffectState(CStateManager& mgr, bool b) { + x8f4_25_ = b; + sub80278508(mgr, x570_, b); + GetModelData()->GetAnimationData()->SetParticleEffectState("Eyes"sv, b, mgr); + + if (!b) { + sub80278130(zeus::skBlack); + } else { + sub80278130(x588_[x570_].x6c_color); + } +} + +void CMetroidPrimeExo::UpdateHeadHealthInfo(CStateManager& mgr) { + if (TCastToPtr colAct = mgr.ObjectById(x8cc_headColActor)) { + *colAct->HealthInfo(mgr) = x8c0_; + } +} + +void CMetroidPrimeExo::UpdateHealthInfo(CStateManager& mgr) { + if (TCastToPtr colAct = mgr.ObjectById(x8cc_headColActor)) { + auto* hInfo = colAct->HealthInfo(mgr); + if (hInfo->GetHP() <= 0.f && !x8f4_28_) { + x8f4_28_ = true; + --x8d0_; + if (x8d0_ == 0) { + x400_24_hitByPlayerProjectile = true; + } + } + + if (x8f4_28_) { + UpdateHeadHealthInfo(mgr); + } + + if (x91c_ > -1 && x91c_ < 4) { + if (x914_24_) { + HealthInfo(mgr)->SetHP(skHealthConstants[std::max(0, x91c_ - 1)]); + } else { + HealthInfo(mgr)->SetHP(std::max(0.f, hInfo->GetHP()) + skHealthConstants[x91c_] + + (static_cast(x8d0_ - 1) * x8c0_.GetHP())); + } + } + } +} + +void CMetroidPrimeExo::SetBoneTrackingTarget(CStateManager& mgr, bool active) { + for (auto& boneTracking : x76c_) { + boneTracking.SetActive(active); + boneTracking.SetTarget(mgr.GetPlayer().GetUniqueId()); + } +} + +void CMetroidPrimeExo::UpdateBoneTracking(float dt, CStateManager& mgr) { + CAnimData* animData = GetModelData()->GetAnimationData(); + animData->PreRender(); + for (auto tracking : x76c_) { + tracking.Update(dt); + tracking.PreRender(mgr, *animData, GetTransform(), GetModelData()->GetScale(), *GetBodyController()); + } + + if (xe4_30_outOfFrustum) { + xe4_27_notInSortedLists = !x1054_24_; + } +} + +void CMetroidPrimeExo::DoContactDamage(TUniqueId uid, CStateManager& mgr) { + if (TCastToConstPtr colAct = mgr.GetObjectById(uid)) { + if (!IsAlive()) { + return; + } + + if (colAct->GetLastTouchedObject() == mgr.GetPlayer().GetUniqueId()) { + if (mgr.GetPlayer().GetFrozenState()) { + mgr.GetPlayer().UnFreeze(mgr); + } + + if (x420_curDamageRemTime <= 0.f) { + mgr.ApplyDamage(GetUniqueId(), colAct->GetLastTouchedObject(), GetUniqueId(), GetContactDamage(), + CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); + x420_curDamageRemTime = x424_damageWaitTime; + } + } else if (TCastToConstPtr act = mgr.GetObjectById(colAct->GetLastTouchedObject())) { + if (!act->GetMaterialList().HasMaterial(EMaterialTypes::Platform)) { + return; + } + + mgr.ApplyDamage(GetUniqueId(), colAct->GetLastTouchedObject(), GetUniqueId(), GetContactDamage(), + CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); + } + } +} + +void CMetroidPrimeExo::UpdateCollision(float dt, CStateManager& mgr) { + x56c_collisionManager->Update(dt, mgr, CCollisionActorManager::EUpdateOptions::ObjectSpace); + zeus::CTransform xf = GetLocatorTransform("Skeleton_Root"sv); + MoveCollisionPrimitive(GetTransform().rotate(GetModelData()->GetScale() * xf.origin)); +} + +void CMetroidPrimeExo::SetupBoneTracking() { + for (size_t i = 0; i < 6; ++i) { + x76c_.emplace_back(*GetModelData()->GetAnimationData(), skBoneTrackingNames[i], zeus::degToRad(80.f), + zeus::degToRad(180.f), EBoneTrackingFlags::NoParentOrigin); + } +} + +void CMetroidPrimeExo::SetupCollisionActorManager(CStateManager& mgr) { + std::vector joints; + joints.reserve(skBodyJoints.size() + skSphereJoints.size()); + for (auto& skBodyJoint : skBodyJoints) { + CSegId to = GetModelData()->GetAnimationData()->GetLocatorSegId(skBodyJoint.to); + CSegId from = GetModelData()->GetAnimationData()->GetLocatorSegId(skBodyJoint.from); + joints.push_back(CJointCollisionDescription::OBBAutoSizeCollision( + to, from, skBodyJoint.bounds, CJointCollisionDescription::EOrientationType::One, + std::string(skBodyJoint.to) + std::string(skBodyJoint.from), 200.f)); + } + + for (auto& skSphereJoint : skSphereJoints) { + joints.push_back(CJointCollisionDescription::SphereCollision( + GetModelData()->GetAnimationData()->GetLocatorSegId(skSphereJoint.name), skSphereJoint.radius, + skSphereJoint.name, 200.f)); + } + + x56c_collisionManager = + std::make_unique(mgr, GetUniqueId(), GetAreaIdAlways(), joints, GetActive()); + + for (size_t i = 0; i < x56c_collisionManager->GetNumCollisionActors(); ++i) { + const auto& jInfo = x56c_collisionManager->GetCollisionDescFromIndex(i); + if (jInfo.GetName() == "Head_LockON_SDK"sv) { + x8cc_headColActor = jInfo.GetCollisionActorId(); + } + + if (TCastToPtr colAct = mgr.ObjectById(jInfo.GetCollisionActorId())) { + if (jInfo.GetCollisionActorId() != x1046_) { + colAct->SetDamageVulnerability(*GetDamageVulnerability()); + } + } + } + + x56c_collisionManager->AddMaterial(mgr, CMaterialList(EMaterialTypes::AIJoint, EMaterialTypes::CameraPassthrough)); + SetMaterialFilter(CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::Player})); + AddMaterial(EMaterialTypes::ProjectilePassthrough, mgr); + RemoveMaterial(EMaterialTypes::Solid, EMaterialTypes::Orbit, EMaterialTypes::Solid, mgr); + UpdateHeadHealthInfo(mgr); +} + +void CMetroidPrimeExo::CPhysicsDummy::Accept(IVisitor& visitor) { visitor.Visit(this); } +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroidPrimeExo.hpp b/Runtime/MP1/World/CMetroidPrimeExo.hpp index 221f917eb..f76807295 100644 --- a/Runtime/MP1/World/CMetroidPrimeExo.hpp +++ b/Runtime/MP1/World/CMetroidPrimeExo.hpp @@ -1,17 +1,24 @@ #pragma once -#include "Runtime/rstl.hpp" #include "Runtime/Camera/CCameraShakeData.hpp" +#include "Runtime/Character/CBoneTracking.hpp" #include "Runtime/MP1/World/CMetroidPrimeProjectile.hpp" #include "Runtime/Weapon/CBeamInfo.hpp" +#include "Runtime/Weapon/CPlasmaProjectile.hpp" +#include "Runtime/Weapon/CProjectileInfo.hpp" #include "Runtime/World/CActorParameters.hpp" #include "Runtime/World/CPatterned.hpp" #include "Runtime/World/CPatternedInfo.hpp" +#include "Runtime/rstl.hpp" #include -namespace urde { +namespace metaforce { class CCameraShakeData; +class CCollisionActorManager; +class CGenDescription; +class CElementGen; +class CProjectedShadow; namespace MP1 { @@ -29,24 +36,11 @@ struct SPrimeStruct2B { explicit SPrimeStruct2B(CInputStream& in); }; -struct SPrimeStruct5 { - u32 x0_propertyCount; - CAssetId x4_; - u32 x8_; - CAssetId xc_; - CAssetId x10_; - u32 x14_; - u32 x18_; - u32 x1c_; - u32 x20_; - explicit SPrimeStruct5(CInputStream& in); -}; - struct SPrimeStruct4 { CBeamInfo x0_beamInfo; u32 x44_; CDamageInfo x48_dInfo1; - SPrimeStruct5 x64_struct5; + CPlasmaProjectile::PlayerEffectResources x64_struct5; float x88_; CDamageInfo x8c_dInfo2; explicit SPrimeStruct4(CInputStream& in); @@ -56,8 +50,7 @@ struct SPrimeStruct6 { u32 x0_propertyCount; CDamageVulnerability x4_damageVulnerability; zeus::CColor x6c_color; - u32 x70_; - u32 x74_; + std::array x70_; explicit SPrimeStruct6(CInputStream& in); }; @@ -92,9 +85,182 @@ struct SPrimeExoParameters { struct SPrimeExoRoomParameters { rstl::reserved_vector x0_; explicit SPrimeExoRoomParameters(CInputStream& in); + + float GetFloatValue(size_t idx) const { return x0_[idx]; } }; class CMetroidPrimeExo : public CPatterned { + class CPhysicsDummy : public CPhysicsActor { + public: + CPhysicsDummy(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info) + : CPhysicsActor(uid, active, name, info, {}, CModelData::CModelDataNull(), + CMaterialList(EMaterialTypes::Target, EMaterialTypes::ExcludeFromRadar), zeus::CAABox{-1.f, 1.f}, + SMoverData(1.f), CActorParameters::None(), 0.3f, 0.1f) {} + void Accept(IVisitor& visitor) override; + }; + TUniqueId x568_relayId = kInvalidUniqueId; + std::unique_ptr x56c_collisionManager; + s32 x570_ = 1; + u32 x574_ = 1; + u32 x578_ = 0; + u32 x57c_ = 0; + u32 x580_ = 0; + bool x584_ = false; + rstl::reserved_vector x588_; + rstl::reserved_vector x76c_; + CHealthInfo x8c0_ = CHealthInfo(150.f, 0.f); + float x8c8_ = 0.f; + TUniqueId x8cc_headColActor = kInvalidUniqueId; + u32 x8d0_ = 3; + u32 x8d4_ = 3; + zeus::CColor x8d8_ = zeus::skBlack; + zeus::CColor x8dc_ = zeus::skBlack; + zeus::CColor x8e0_ = zeus::skBlack; + float x8e4_ = 0.f; + s32 x8e8_headUpAdditiveBodyAnimIndex; + float x8ec_ = 0.f; + float x8f0_ = 0.f; + bool x8f4_24_ : 1 = false; + bool x8f4_25_ : 1 = false; + bool x8f4_26_ : 1 = false; + bool x8f4_27_ : 1 = false; + bool x8f4_28_ : 1 = false; + zeus::CAABox x8f8_; + float x910_ = 5.f; + bool x914_24_ : 1 = false; + s32 x918_ = -1; + s32 x91c_; + float x920_ = 0.f; + float x924_ = 4.f; + float x928_ = 5.f; + u32 x92c_ = 0; + SPrimeStruct2B x930_; + rstl::reserved_vector x96c_; + rstl::reserved_vector xa80_; + rstl::reserved_vector xb24_plasmaProjectileIds = {{kInvalidUniqueId, kInvalidUniqueId, kInvalidUniqueId, + kInvalidUniqueId}}; + rstl::reserved_vector xb30_; + rstl::reserved_vector xbc4_; + TLockedToken xc48_; + std::unique_ptr xc50_; + s32 xc58_curPlasmaProjectile = -1; + float xc5c_ = 0.f; + zeus::CVector3f xc60_; + zeus::CVector3f xc6c_; + CProjectileInfo xc78_; + CCameraShakeData xca0_; + CProjectileInfo xd74_; + CCameraShakeData xd9c_; + SPrimeProjectileInfo xe70_; + TUniqueId xeac_ = kInvalidUniqueId; + u32 xeb0_ = 0; + CDamageInfo xeb4_; + CCameraShakeData xed0_; + TLockedToken xfa4_; + std::unique_ptr xfac_; + float xfb4_ = 0.f; + float xfb8_ = 0.f; + CSfxHandle xfbc_; + bool xfc0_ = false; + bool xfc1_ = false; + rstl::reserved_vector, 2> xfc4_; + rstl::reserved_vector, 2> xfd8_; + rstl::reserved_vector, 2> xfec_; + rstl::reserved_vector, 2> x1000_; + TToken x1014_; + TToken x101c_; + std::unique_ptr x1024_; + rstl::reserved_vector x102c_; + rstl::reserved_vector x1038_; + TUniqueId x1044_billboardId = kInvalidUniqueId; + TUniqueId x1046_ = kInvalidUniqueId; + float x1048_ = 0.f; + float x104c_ = 75.f; + float x1050_ = 0.f; + bool x1054_24_ : 1 = false; + bool x1054_25_ : 1 = false; + bool x1054_26_ : 1 = false; + bool x1054_27_ : 1 = false; + rstl::reserved_vector x106c_energyBallIds; + float x1074_ = 0.f; + s32 x1078_ = -1; + float x107c_ = 0.f; + float x1080_; + float x1084_ = 0.f; + float x1088_ = 0.f; + CCameraShakeData x108c_; + rstl::reserved_vector x1160_; + s32 x1254_ = -1; + rstl::reserved_vector x1258_; + CCameraShakeData x1294_; + CCameraShakeData x1368_; + std::unique_ptr x143c_; + s32 x1440_ = 0; + bool x1444_24_ : 1 = false; + bool x1444_25_ : 1 = false; + + void sub802738d4(CStateManager& mgr); + void UpdateEnergyBalls(float dt, CStateManager& mgr); + u32 CountEnergyBalls(CStateManager& mgr); + void sub80273d38(CStateManager& mgr); + void UpdatePhysicsDummy(CStateManager& mgr); + void sub80274054(CStateManager& mgr); + void sub802740cc(CStateManager& mgr); + void CreatePhysicsDummy(CStateManager& mgr); + void SetBillboardEmission(CStateManager& mgr, bool emission); + void FreeBillboard(CStateManager& mgr); + zeus::CVector3f sub8027464c(CStateManager& mgr); + void CreateHUDBillBoard(CStateManager& mgr); + void sub802747b8(float f1, CStateManager& mgr, const zeus::CVector3f& vec); + void sub802749e8(float f1, float f2, float f3, const zeus::CVector3f& vec1, const zeus::CVector3f& vec2); + void sub80274e6c(float f1, CStateManager& mgr); + void sub802755ac(CStateManager& mgr, bool b1); + void EnableHeadOrbitAndTarget(CStateManager& mgr); + void DisableHeadOrbitAndTarget(CStateManager& mgr); + void UpdateTimers(float mgr); + void sub80275800(CStateManager& mgr); + void sub802759a8(CStateManager& mgr, u32 w1); + float sub80275b04(const SPrimeExoRoomParameters& roomParms, int w2); + void sub80275b68(); + void sub80275c60(CStateManager& mgr, int w1); + bool sub80275d68(int w1); + pas::ELocomotionType sub80275e14(int w1); + u32 sub80275e34(int w1) const; + void sub80275e54(float f1, CStateManager& mgr); + void UpdateSfxEmitter(float f1, CStateManager& mgr); + void sub80276204(CStateManager& mgr, bool b1); + void sub8027639c(CStateManager& mgr, bool b1); + void SetActorAreaId(CStateManager& mgr, TUniqueId uid, TAreaId aid); + void UpdateAreaId(CStateManager& mgr); + void SendStateToRelay(EScriptObjectState state, CStateManager& mgr); + void sub80276754(CStateManager& mgr); + TUniqueId sub802769e0(CStateManager& mgr, bool b1); + TUniqueId sub80276b3c(CStateManager& mgr, EScriptObjectState state, EScriptObjectMessage msg); + void UpdateRelay(CStateManager& mgr, TAreaId areaId); + bool IsRelayValid(CStateManager& mgr, TAreaId w2); + bool sub80277224(float f1, CStateManager& mgr); + void FirePlasmaProjectile(CStateManager& mgr, bool b1); + void UpdatePlasmaProjectile(float dt, CStateManager& mgr); + zeus::CVector3f GetTargetVector(CStateManager& mgr); + void FreePlasmaProjectiles(CStateManager& mgr); + void CreatePlasmaProjectiles(CStateManager& mgr); + void UpdateContactDamage(CStateManager& mgr); + void UpdateColorChange(float f1, CStateManager& mgr); + void sub80278130(const zeus::CColor& col); + void UpdateHeadAnimation(float f1); + void sub8027827c(TUniqueId uid, CStateManager& mgr); + void sub80278508(CStateManager& mgr, int w1, bool b1); + void sub802786fc(CStateManager& mgr); + void SetEyesParticleEffectState(CStateManager& mgr, bool b); + void UpdateHeadHealthInfo(CStateManager& mgr); + void UpdateHealthInfo(CStateManager& mgr); + void SetBoneTrackingTarget(CStateManager& mgr, bool active); + void UpdateBoneTracking(float f1, CStateManager& mgr); + void DoContactDamage(TUniqueId uid, CStateManager& mgr); + void UpdateCollision(float dt, CStateManager& mgr); + void SetupBoneTracking(); + void SetupCollisionActorManager(CStateManager& mgr); + public: DEFINE_PATTERNED(MetroidPrimeExo); CMetroidPrimeExo(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, @@ -106,7 +272,60 @@ public: const CCameraShakeData& shakeData5, const SPrimeProjectileInfo& projectileInfo, const CDamageInfo& dInfo3, const CCameraShakeData& shakeData6, CAssetId particle2, CAssetId swoosh, CAssetId particle3, CAssetId particle4, const rstl::reserved_vector& struct6s); + + void PreThink(float dt, CStateManager& mgr) override; + void Think(float dt, CStateManager& mgr) override; + void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId other, CStateManager& mgr) override; + void PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) override; + void AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) override; + void Render(CStateManager& mgr) override; + bool CanRenderUnsorted(const CStateManager& mgr) const override; + void Touch(CActor& act, CStateManager& mgr) override; + void DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) override; + void SelectTarget(CStateManager& mgr, EStateMsg msg, float arg) override; + void Run(CStateManager& mgr, EStateMsg msg, float arg) override; + void Attack(CStateManager& mgr, EStateMsg msg, float arg) override; + void TurnAround(CStateManager& mgr, EStateMsg msg, float arg) override; + void Active(CStateManager& mgr, EStateMsg msg, float arg) override; + void InActive(CStateManager& mgr, EStateMsg msg, float arg) override; + void CoverAttack(CStateManager& mgr, EStateMsg msg, float arg) override; + void Crouch(CStateManager& mgr, EStateMsg msg, float arg) override; + void Taunt(CStateManager& mgr, EStateMsg msg, float arg) override; + void Suck(CStateManager& mgr, EStateMsg msg, float arg) override; + void ProjectileAttack(CStateManager& mgr, EStateMsg msg, float arg) override; + void Flinch(CStateManager& mgr, EStateMsg msg, float arg) override; + void Dodge(CStateManager& mgr, EStateMsg msg, float arg) override; + void Retreat(CStateManager& mgr, EStateMsg msg, float arg) override; + void Cover(CStateManager& mgr, EStateMsg msg, float arg) override; + void Approach(CStateManager& mgr, EStateMsg msg, float arg) override; + void Enraged(CStateManager& mgr, EStateMsg msg, float arg) override; + void SpecialAttack(CStateManager& mgr, EStateMsg msg, float arg) override; + void Growth(CStateManager& mgr, EStateMsg msg, float arg) override; + void Land(CStateManager& mgr, EStateMsg msg, float arg) override; + bool TooClose(CStateManager& mgr, float arg) override; + bool InMaxRange(CStateManager& mgr, float arg) override; + bool PlayerSpot(CStateManager& mgr, float arg) override; + bool ShouldAttack(CStateManager& mgr, float arg) override; + bool ShouldDoubleSnap(CStateManager& mgr, float arg) override; + bool InPosition(CStateManager& mgr, float arg) override; + bool ShouldTurn(CStateManager& mgr, float arg) override; + bool ShouldJumpBack(CStateManager& mgr, float arg) override { return x1254_ == 11; } + bool CoverCheck(CStateManager& mgr, float arg) override; + bool CoverFind(CStateManager& mgr, float arg) override; + bool CoveringFire(CStateManager& mgr, float arg) override; + bool AggressionCheck(CStateManager& mgr, float arg) override; + bool AttackOver(CStateManager& mgr, float arg) override; + bool ShouldFire(CStateManager& mgr, float arg) override; + bool ShouldFlinch(CStateManager& mgr, float arg) override; + bool ShouldRetreat(CStateManager& mgr, float arg) override; + bool ShouldCrouch(CStateManager& mgr, float arg) override; + bool ShouldMove(CStateManager& mgr, float arg) override; + bool AIStage(CStateManager& mgr, float arg) override; + bool StartAttack(CStateManager& mgr, float arg) override; + bool ShouldSpecialAttack(CStateManager& mgr, float arg) override; + bool CodeTrigger(CStateManager& mgr, float arg) override; + CProjectileInfo* GetProjectileInfo() override; }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CMetroidPrimeProjectile.cpp b/Runtime/MP1/World/CMetroidPrimeProjectile.cpp index 0075db6fe..b56b574d8 100644 --- a/Runtime/MP1/World/CMetroidPrimeProjectile.cpp +++ b/Runtime/MP1/World/CMetroidPrimeProjectile.cpp @@ -3,7 +3,7 @@ #include "Runtime/CSimplePool.hpp" #include "Runtime/GameGlobalObjects.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { SPrimeProjectileInfo::SPrimeProjectileInfo(CInputStream& in) : x0_propertyCount(in.readUint32Big()) @@ -29,4 +29,4 @@ CMetroidPrimeProjectile::CMetroidPrimeProjectile( visorParticle, visorSfx, sendCollideMsg) , x3d8_auxData(auxData) {} -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroidPrimeProjectile.hpp b/Runtime/MP1/World/CMetroidPrimeProjectile.hpp index 0d0db410b..677fdc704 100644 --- a/Runtime/MP1/World/CMetroidPrimeProjectile.hpp +++ b/Runtime/MP1/World/CMetroidPrimeProjectile.hpp @@ -3,7 +3,7 @@ #include "Runtime/CToken.hpp" #include "Runtime/Weapon/CEnergyProjectile.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { struct SPrimeProjectileInfo { u32 x0_propertyCount; @@ -32,4 +32,4 @@ public: bool sendCollideMsg); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroidPrimeRelay.cpp b/Runtime/MP1/World/CMetroidPrimeRelay.cpp index 56868e6fc..24a8339d3 100644 --- a/Runtime/MP1/World/CMetroidPrimeRelay.cpp +++ b/Runtime/MP1/World/CMetroidPrimeRelay.cpp @@ -1,8 +1,10 @@ #include "Runtime/MP1/World/CMetroidPrimeRelay.hpp" +#include "Runtime/MP1/World/CMetroidPrimeExo.hpp" +#include "Runtime/CStateManager.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CMetroidPrimeRelay::CMetroidPrimeRelay(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, const zeus::CTransform& xf, const zeus::CVector3f& scale, @@ -27,5 +29,44 @@ CMetroidPrimeRelay::CMetroidPrimeRelay(TUniqueId uid, std::string_view name, con , xcb8_roomParms(std::move(roomParms)) {} void CMetroidPrimeRelay::Accept(IVisitor& visitor) { visitor.Visit(this); } +void CMetroidPrimeRelay::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr) { + if (x34_mpUid != objId) { + ForwardMessageToMetroidPrimeExo(msg, mgr); + } + if (msg == EScriptObjectMessage::InitializedInArea) { + GetOrBuildMetroidPrimeExo(mgr); + } +} -} // namespace urde::MP1 +void CMetroidPrimeRelay::ForwardMessageToMetroidPrimeExo(EScriptObjectMessage msg, CStateManager& mgr) { + if (auto* exo = CPatterned::CastTo(mgr.ObjectById(x34_mpUid))) { + mgr.SendScriptMsg(exo, GetUniqueId(), msg); + } +} + +void CMetroidPrimeRelay::GetOrBuildMetroidPrimeExo(CStateManager& mgr) { + if (!GetActive()) { + return; + } + + for (const auto act : mgr.GetPhysicsActorObjectList()) { + if (CPatterned::CastTo(act) != nullptr) { + return; + } + } + + const auto& animParms = x74_parms.x4_patternedInfo.GetAnimationParameters(); + CModelData mData( + CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), x68_scale, animParms.GetInitialAnimation(), true)); + auto* exo = new CMetroidPrimeExo( + mgr.AllocateUniqueId(), "Metroid Prime! (Stage 1)"sv, CEntityInfo(GetAreaId(), NullConnectionList), x38_xf, std::move(mData), + x74_parms.x4_patternedInfo, x74_parms.x13c_actorParms, x74_parms.x1a4_, x74_parms.x1a8_, x74_parms.x27c_, + x74_parms.x350_, x74_parms.x424_, x74_parms.x460_particle1, x74_parms.x464_, x74_parms.x708_wpsc1, + x74_parms.x70c_dInfo1, x74_parms.x728_shakeData1, x74_parms.x7fc_wpsc2, x74_parms.x800_dInfo2, + x74_parms.x81c_shakeData2, x74_parms.x8f0_, x74_parms.x92c_, x74_parms.x948_, x74_parms.xa1c_particle2, + x74_parms.xa20_swoosh, x74_parms.xa24_particle3, x74_parms.xa28_particle4, x74_parms.xa2c_); + mgr.AddObject(exo); + mgr.SendScriptMsg(exo, kInvalidUniqueId, EScriptObjectMessage::InitializedInArea); +} + +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CMetroidPrimeRelay.hpp b/Runtime/MP1/World/CMetroidPrimeRelay.hpp index fe645648d..1b26592cf 100644 --- a/Runtime/MP1/World/CMetroidPrimeRelay.hpp +++ b/Runtime/MP1/World/CMetroidPrimeRelay.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CMetroidPrimeRelay : public CEntity { TUniqueId x34_mpUid = kInvalidUniqueId; @@ -28,13 +28,30 @@ class CMetroidPrimeRelay : public CEntity { u32 xcb4_w5; rstl::reserved_vector xcb8_roomParms; + void ForwardMessageToMetroidPrimeExo(EScriptObjectMessage msg, CStateManager& mgr); + void GetOrBuildMetroidPrimeExo(CStateManager& mgr); public: CMetroidPrimeRelay(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, const zeus::CTransform& xf, const zeus::CVector3f& scale, SPrimeExoParameters&& parms, float f1, float f2, float f3, u32 w1, bool b1, u32 w2, const CHealthInfo& hInfo1, const CHealthInfo& hInfo2, u32 w3, u32 w4, u32 w5, rstl::reserved_vector&& roomParms); void Accept(IVisitor& visitor) override; - TUniqueId GetMetroidPrimeExoId() const { return x34_mpUid; } + void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager &stateMgr) override; + [[nodiscard]] TUniqueId GetMetroidPrimeExoId() const { return x34_mpUid; } + void SetMetroidPrimeExoId(TUniqueId uid) { x34_mpUid = uid; } + float Get_xc84() const { return xc84_f1; } + float Get_xc88() const { return xc88_f2; } + float Get_xc8c() const { return xc8c_f3; } + u32 Get_xc90() const { return xc90_w1; } + bool Get_xc94() const { return xc94_b1; } + u32 Get_xc98() const { return xc98_w2; } + CHealthInfo GetHealthInfo1() const { return xc9c_hInfo1; } + CHealthInfo GetHealthInfo2() const { return xca4_hInfo2; } + u32 Get_xcac() const { return xcac_w3; } + u32 Get_xcb0() const { return xcb0_w4; } + u32 Get_xcb4() const { return xcb4_w5; } + rstl::reserved_vector GetRoomParameters() const { return xcb8_roomParms; } + }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CNewIntroBoss.cpp b/Runtime/MP1/World/CNewIntroBoss.cpp index d875b6801..691901030 100644 --- a/Runtime/MP1/World/CNewIntroBoss.cpp +++ b/Runtime/MP1/World/CNewIntroBoss.cpp @@ -13,7 +13,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::array skSphereJoints{{ {"Head_1", 1.5f}, @@ -354,7 +354,7 @@ bool CNewIntroBoss::ShouldAttack(CStateManager& mgr, float dt) { bool CNewIntroBoss::AIStage(CStateManager& mgr, float) { return x568_locomotion != GetLocoForHealth(mgr); } -bool CNewIntroBoss::AnimOver(urde::CStateManager&, float) { return x56c_stateProg == 3; } +bool CNewIntroBoss::AnimOver(metaforce::CStateManager&, float) { return x56c_stateProg == 3; } void CNewIntroBoss::Generate(CStateManager& mgr, EStateMsg msg, float dt) { if (msg == EStateMsg::Activate) { @@ -434,4 +434,4 @@ void CNewIntroBoss::Patrol(CStateManager& mgr, EStateMsg msg, float dt) { } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CNewIntroBoss.hpp b/Runtime/MP1/World/CNewIntroBoss.hpp index a864b6202..d2f4726f0 100644 --- a/Runtime/MP1/World/CNewIntroBoss.hpp +++ b/Runtime/MP1/World/CNewIntroBoss.hpp @@ -10,7 +10,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollisionActorManager; class CDamageInfo; @@ -82,4 +82,4 @@ public: }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/COmegaPirate.cpp b/Runtime/MP1/World/COmegaPirate.cpp index 110d23da2..d21316245 100644 --- a/Runtime/MP1/World/COmegaPirate.cpp +++ b/Runtime/MP1/World/COmegaPirate.cpp @@ -17,7 +17,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array skSphereJoints{{ {"lockon_target_LCTR", 1.f}, @@ -599,7 +599,6 @@ void COmegaPirate::JumpBack(CStateManager& mgr, EStateMsg msg, float dt) { } bool COmegaPirate::Landed(CStateManager& mgr, float arg) { - fmt::print(FMT_STRING("OMEGA: {} pieces healed\n"), xb4c_armorPiecesHealed); return xb4c_armorPiecesHealed == 4; } @@ -1161,10 +1160,7 @@ void COmegaPirate::TeleportToFurthestPlatform(CStateManager& mgr) { zeus::CVector3f COmegaPirate::FindGround(const zeus::CVector3f& pos, CStateManager& mgr) const { auto result = mgr.RayStaticIntersection(pos, zeus::skDown, 30.f, CMaterialFilter::MakeInclude(EMaterialTypes::Solid)); - if (result.IsValid()) { - return result.GetPoint(); - } - return pos; + return result.IsValid() ? result.GetPoint() : pos; } void COmegaPirate::UpdateNormalAlpha(CStateManager& mgr, float dt) { @@ -1417,4 +1413,4 @@ void COmegaPirate::DeathDestroy(CStateManager& mgr) { xa38_collisionActorMgr1->SetActive(mgr, false); xa9c_collisionActorMgr2->SetActive(mgr, false); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/COmegaPirate.hpp b/Runtime/MP1/World/COmegaPirate.hpp index eec2ec6cc..ef986ea89 100644 --- a/Runtime/MP1/World/COmegaPirate.hpp +++ b/Runtime/MP1/World/COmegaPirate.hpp @@ -2,7 +2,7 @@ #include "Runtime/MP1/World/CElitePirate.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class COmegaPirate : public CElitePirate { private: class CFlash : public CActor { @@ -189,4 +189,4 @@ private: void sub_8028c840(u32 arg, CStateManager& mgr); zeus::CVector3f FindGround(const zeus::CVector3f& pos, CStateManager& mgr) const; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CParasite.cpp b/Runtime/MP1/World/CParasite.cpp index 7d8423cb6..19e89d724 100644 --- a/Runtime/MP1/World/CParasite.cpp +++ b/Runtime/MP1/World/CParasite.cpp @@ -17,7 +17,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { const float CParasite::flt_805A8FB0 = 2.f * std::sqrt(2.5f / CPhysicsActor::GravityConstant()); const float CParasite::skAttackVelocity = 15.f / 2.f * (std::sqrt(2.5f / CPhysicsActor::GravityConstant())); @@ -867,4 +867,4 @@ void CParasite::UpdateJumpVelocity() { SetVelocityWR(vec); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CParasite.hpp b/Runtime/MP1/World/CParasite.hpp index 762ebc478..1a456c7fc 100644 --- a/Runtime/MP1/World/CParasite.hpp +++ b/Runtime/MP1/World/CParasite.hpp @@ -7,11 +7,11 @@ #include -namespace urde { +namespace metaforce { class CModelData; } -namespace urde::MP1 { +namespace metaforce::MP1 { class CParasite : public CWallWalker { class CRepulsor { zeus::CVector3f x0_v; @@ -147,4 +147,4 @@ public: bool IsOnGround() const override; virtual void UpdateWalkerAnimation(CStateManager&, float); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPhazonHealingNodule.cpp b/Runtime/MP1/World/CPhazonHealingNodule.cpp index cbd7c6692..71fddfde0 100644 --- a/Runtime/MP1/World/CPhazonHealingNodule.cpp +++ b/Runtime/MP1/World/CPhazonHealingNodule.cpp @@ -5,7 +5,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/World/CPatternedInfo.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { CPhazonHealingNodule::CPhazonHealingNodule(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParams, const CPatternedInfo& pInfo, @@ -183,4 +183,4 @@ void CPhazonHealingNodule::MassiveFrozenDeath(CStateManager& mgr) { } void CPhazonHealingNodule::PhazeOut(CStateManager& mgr) { Death(mgr, zeus::skZero3f, EScriptObjectState::Dead); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPhazonHealingNodule.hpp b/Runtime/MP1/World/CPhazonHealingNodule.hpp index d068d822e..e9b5f1f0b 100644 --- a/Runtime/MP1/World/CPhazonHealingNodule.hpp +++ b/Runtime/MP1/World/CPhazonHealingNodule.hpp @@ -3,7 +3,7 @@ #include "Runtime/World/CPatterned.hpp" #include "Runtime/Particle/CParticleElectric.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CPhazonHealingNodule : public CPatterned { private: int x568_active = 0; @@ -47,4 +47,4 @@ public: private: void UpdateParticleElectric(CStateManager& mgr); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPhazonPool.cpp b/Runtime/MP1/World/CPhazonPool.cpp index a9c4b86f2..f1f2ee630 100644 --- a/Runtime/MP1/World/CPhazonPool.cpp +++ b/Runtime/MP1/World/CPhazonPool.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CPhazonPool::CPhazonPool(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, const zeus::CVector3f& scale, bool active, CAssetId w1, CAssetId w2, CAssetId w3, CAssetId w4, u32 p11, const CDamageInfo& dInfo, const zeus::CVector3f& orientedForce, @@ -153,25 +153,25 @@ void CPhazonPool::Think(float dt, CStateManager& mgr) { x1c4_ = 0.f; dVar5 = dt; } - x1a0_ -= x1bc_ * (dt * x1cc_) + dVar5; - x1a4_ = x1a0_ / x19c_; - if (x1a4_ < 0.001f) { - if (x1e0_24_) { - shouldFree = true; - } else { - SetCallTouch(false); - if (x1e0_25_) { - x1dc_ = 0; - SetActive(false); - } else { - x1dc_ = 3; - x1d0_ = x1c8_; - } - } - SetEmitParticles(false); - } - x1cc_ = 0.f; } + x1a0_ -= x1bc_ * (dt * x1cc_) + dVar5; + x1a4_ = x1a0_ / x19c_; + if (x1a4_ < 0.001f) { + if (x1e0_24_) { + shouldFree = true; + } else { + SetCallTouch(false); + if (x1e0_25_) { + x1dc_ = 0; + SetActive(false); + } else { + x1dc_ = 3; + x1d0_ = x1c8_; + } + } + SetEmitParticles(false); + } + x1cc_ = 0.f; } else if (x1dc_ == 3) { x1d0_ -= dt; if (x1d0_ <= 0.f) { @@ -268,4 +268,4 @@ void CPhazonPool::SetEmitParticles(bool val) { x170_elementGen1->SetParticleEmission(val); } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPhazonPool.hpp b/Runtime/MP1/World/CPhazonPool.hpp index 2a5f8132f..b6f7e1442 100644 --- a/Runtime/MP1/World/CPhazonPool.hpp +++ b/Runtime/MP1/World/CPhazonPool.hpp @@ -4,7 +4,7 @@ #include "Runtime/Particle/CElementGen.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CPhazonPool : public CScriptTrigger { private: std::list> x150_inhabitants; @@ -54,4 +54,4 @@ private: void RemoveInhabitants(CStateManager& mgr); void SetEmitParticles(bool val); }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPuddleSpore.cpp b/Runtime/MP1/World/CPuddleSpore.cpp index 28a435a1a..f00c67b83 100644 --- a/Runtime/MP1/World/CPuddleSpore.cpp +++ b/Runtime/MP1/World/CPuddleSpore.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr u32 kEyeCount = 16; constexpr std::array kEyeLocators{ @@ -46,10 +46,14 @@ CPuddleSpore::CPuddleSpore(TUniqueId uid, std::string_view name, EFlavorType fla } zeus::CAABox CPuddleSpore::CalculateBoundingBox() const { - return {(zeus::CVector3f(-x590_halfExtent, -x590_halfExtent, x598_) + x584_bodyOrigin) * 0.05f + - GetBaseBoundingBox().min * 0.95f, - (zeus::CVector3f(x590_halfExtent, x590_halfExtent, x594_height * x59c_ + x598_) + x584_bodyOrigin) * 0.05f + - GetBaseBoundingBox().max * 0.95f}; + auto aaBox = GetBaseBoundingBox(); + + return {{(-x590_halfExtent + x584_bodyOrigin.x()) * 0.05f + (aaBox.min.x() * 0.95f), + (-x590_halfExtent + x584_bodyOrigin.y()) * 0.05f + (aaBox.min.y() * 0.95f), + (x598_ + x584_bodyOrigin.z()) * 0.05f + (aaBox.min.z() * 0.95f)}, + {(x590_halfExtent + x584_bodyOrigin.x()) * 0.05f + (aaBox.max.x() * 0.95f), + (x590_halfExtent + x584_bodyOrigin.y()) * 0.05f + (aaBox.max.y() * 0.95f), + (x594_height * x59c_ + x598_ + x584_bodyOrigin.z()) * 0.05f + (aaBox.max.z() * 0.95f)}}; } void CPuddleSpore::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { @@ -69,7 +73,17 @@ bool CPuddleSpore::HitShell(const zeus::CVector3f& point) const { } void CPuddleSpore::KnockPlayer(CStateManager& mgr, float arg) { - // TODO implement + auto selfBox = GetBoundingBox(); + auto playerBox = mgr.GetPlayer().GetBoundingBox(); + if (selfBox.max.z() < ((playerBox.min.z() + playerBox.max.z()) * .5f) && playerBox.min.x() <= selfBox.max.x() && + playerBox.min.y() <= selfBox.max.y() && selfBox.min.x() <= playerBox.max.x() && + selfBox.min.y() <= playerBox.max.y() && playerBox.min.z() - selfBox.max.z() < 0.2f) { + const float scale = + mgr.GetPlayer().GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed ? 1.5f : 1.f; + mgr.GetPlayer().ApplyImpulseWR(scale * (arg * mgr.GetPlayer().GetMass()) * x34_transform.rotate({1.f, 0.f, 0.3f}), + {}); + mgr.GetPlayer().SetMoveState(CPlayer::EPlayerMovementState::ApplyJump, mgr); + } } void CPuddleSpore::UpdateBoundingState(const zeus::CAABox& box, CStateManager& mgr, float dt) { @@ -87,19 +101,22 @@ void CPuddleSpore::UpdateBoundingState(const zeus::CAABox& box, CStateManager& m } if (selfBox.intersects(plBox)) { - float bias = (x5c8_ == 2 ? 0.001f : -0.0001f) + (selfBox.max.z() - plBox.min.z()); + float bias = (x5c8_ == 2 ? FLT_EPSILON : -FLT_EPSILON) + (selfBox.max.z() - plBox.min.z()); if (bias > 0.f && selfBox.max.z() < plBox.max.z()) { - bool hadPlayerMat = player.GetMaterialList().HasMaterial(EMaterialTypes::Player); - if (hadPlayerMat) + bool hadGroundColliderMat = player.GetMaterialList().HasMaterial(EMaterialTypes::GroundCollider); + if (hadGroundColliderMat) { player.RemoveMaterial(EMaterialTypes::GroundCollider, mgr); + } + player.RemoveMaterial(EMaterialTypes::Player, mgr); CPhysicsState state = player.GetPhysicsState(); player.MoveToOR(bias * zeus::CVector3f{0.f, 0.f, 1.f}, dt); CGameCollision::Move(mgr, player, dt, nullptr); state.SetTranslation(player.GetTranslation()); player.SetPhysicsState(state); - if (hadPlayerMat) + if (hadGroundColliderMat) { player.AddMaterial(EMaterialTypes::GroundCollider, mgr); + } player.AddMaterial(EMaterialTypes::Player, mgr); } } @@ -147,7 +164,7 @@ void CPuddleSpore::Touch(CActor& act, CStateManager& mgr) { if (TCastToPtr proj = act) { if (proj->GetOwnerId() == mgr.GetPlayer().GetUniqueId()) - x400_24_hitByPlayerProjectile = HitShell(proj->GetTranslation()); + x400_24_hitByPlayerProjectile = !HitShell(proj->GetTranslation()); } } @@ -173,18 +190,19 @@ void CPuddleSpore::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node projInfo->GetDamage(), mgr.AllocateUniqueId(), GetAreaIdAlways(), GetUniqueId(), kInvalidUniqueId, EProjectileAttrib::None, false, zeus::skOne3f, {}, 0xFFFF, false)); } - } else + } else { CPatterned::DoUserAnimEvent(mgr, node, type, dt); + } } bool CPuddleSpore::ShouldTurn(CStateManager& mgr, float) { - zeus::CAABox plBox = mgr.GetPlayer().GetBoundingBox(); - zeus::CAABox selfBox = GetBoundingBox(); - - if (plBox.max.z() >= selfBox.min.z() + selfBox.max.z() * 0.5f || plBox.max.x() < selfBox.min.x() || - plBox.max.y() < selfBox.min.y() || selfBox.max.x() < plBox.min.y() || selfBox.max.y() < plBox.min.y() || - x450_bodyController->GetBodyStateInfo().GetCurrentStateId() != pas::EAnimationState::Getup) - return x568_ >= x578_; + auto selfBox = GetBoundingBox(); + auto plBox = mgr.GetPlayer().GetBoundingBox(); + if (((plBox.min.z() + plBox.max.z()) * 0.5f) <= selfBox.max.z() || selfBox.max.x() < plBox.min.x() || + selfBox.max.y() < plBox.min.y() || plBox.max.x() < selfBox.min.x() || plBox.max.y() < selfBox.min.y() || + mgr.GetPlayer().GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed) { + return x578_ <= x568_; + } return true; } @@ -257,7 +275,7 @@ void CPuddleSpore::TurnAround(CStateManager& mgr, EStateMsg msg, float) { x450_bodyController->GetCommandMgr().DeliverCmd(CBCKnockDownCmd({1.f, 0.f, 0.f}, pas::ESeverity::One)); } } else if (x5cc_ == 1 && - x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::LieOnGround) { + x450_bodyController->GetBodyStateInfo().GetCurrentStateId() != pas::EAnimationState::LieOnGround) { x5cc_ = 2; } } else if (msg == EStateMsg::Deactivate) { @@ -297,4 +315,4 @@ void CPuddleSpore::Attack(CStateManager& mgr, EStateMsg msg, float) { x32c_animState = EAnimState::NotReady; } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPuddleSpore.hpp b/Runtime/MP1/World/CPuddleSpore.hpp index a00e9d21b..6e257e655 100644 --- a/Runtime/MP1/World/CPuddleSpore.hpp +++ b/Runtime/MP1/World/CPuddleSpore.hpp @@ -9,7 +9,7 @@ #include "Runtime/Weapon/CProjectileInfo.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CPuddleSpore : public CPatterned { float x568_ = 0.f; float x56c_ = 0.f; @@ -81,4 +81,4 @@ public: void GetUp(CStateManager&, EStateMsg, float) override; void Attack(CStateManager&, EStateMsg, float) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPuddleToadGamma.cpp b/Runtime/MP1/World/CPuddleToadGamma.cpp index 0fe8b5cc6..941185626 100644 --- a/Runtime/MP1/World/CPuddleToadGamma.cpp +++ b/Runtime/MP1/World/CPuddleToadGamma.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr zeus::CVector3f skBellyOffset(0.f, 0.1f, -.3f); @@ -336,4 +336,4 @@ void CPuddleToadGamma::Crouch(CStateManager& mgr, EStateMsg msg, float) { } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPuddleToadGamma.hpp b/Runtime/MP1/World/CPuddleToadGamma.hpp index 8b5f1a289..a27c47b16 100644 --- a/Runtime/MP1/World/CPuddleToadGamma.hpp +++ b/Runtime/MP1/World/CPuddleToadGamma.hpp @@ -8,7 +8,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CPuddleToadGamma final : public CPatterned { u32 x568_stateProg = 0; @@ -75,4 +75,4 @@ public: bool Inside(CStateManager&, float) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPuffer.cpp b/Runtime/MP1/World/CPuffer.cpp index 3dbc3c897..890472875 100644 --- a/Runtime/MP1/World/CPuffer.cpp +++ b/Runtime/MP1/World/CPuffer.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { constexpr std::array GasLocators{ "Gas_01_LCTR"sv, "Gas_02_LCTR"sv, "Gas_03_LCTR"sv, "Gas_04_LCTR"sv, "Gas_05_LCTR"sv, @@ -143,4 +143,4 @@ void CPuffer::sub8025bfa4(CStateManager& mgr) { x5d0_enabledParticles = 0; } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CPuffer.hpp b/Runtime/MP1/World/CPuffer.hpp index af8e0c8f9..cba9ab13e 100644 --- a/Runtime/MP1/World/CPuffer.hpp +++ b/Runtime/MP1/World/CPuffer.hpp @@ -7,7 +7,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CPuffer : public CPatterned { zeus::CVector3f x568_face; TToken x574_cloudEffect; @@ -40,4 +40,4 @@ public: void Touch(CActor&, CStateManager&) override; void Death(CStateManager&, const zeus::CVector3f&, EScriptObjectState) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CRidley.cpp b/Runtime/MP1/World/CRidley.cpp index 585b4eaab..e8550bdc8 100644 --- a/Runtime/MP1/World/CRidley.cpp +++ b/Runtime/MP1/World/CRidley.cpp @@ -18,7 +18,7 @@ #include "Runtime/World/CScriptWaypoint.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { struct SSomeRidleyStruct { u32 x0_; @@ -283,7 +283,8 @@ CRidley::CRidley(TUniqueId uid, std::string_view name, const CEntityInfo& info, } xae4_ = GetModelData()->GetScale().x() * - GetAnimationDistance(CPASAnimParmData(7, CPASAnimParm::FromEnum(4), CPASAnimParm::FromEnum(3))); + GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::MeleeAttack, CPASAnimParm::FromEnum(4), + CPASAnimParm::FromEnum(3))); x460_knockBackController.SetAnimationStateRange(EKnockBackAnimationState::Flinch, EKnockBackAnimationState::Flinch); x460_knockBackController.SetEnableBurn(false); x460_knockBackController.SetEnableFreeze(false); @@ -292,7 +293,7 @@ CRidley::CRidley(TUniqueId uid, std::string_view name, const CEntityInfo& info, CreateShadow(false); } -void CRidley::SetupCollisionActorManager(urde::CStateManager& mgr) { +void CRidley::SetupCollisionActorManager(metaforce::CStateManager& mgr) { const auto& animData = GetModelData()->GetAnimationData(); std::vector joints; joints.reserve(skTail.size()); @@ -835,7 +836,7 @@ void CRidley::sub8025784c(CStateManager& mgr) { xa31_27_ = false; } -void CRidley::sub80255d58(urde::CStateManager& mgr) { +void CRidley::sub80255d58(metaforce::CStateManager& mgr) { xb04_ = skSomeRidleyStruct[xcb0_][xcb4_].x4_ < mgr.GetActiveRandom()->Range(0.f, 100.f) ? skSomeRidleyStruct[xcb0_][xcb4_].x8_ : skSomeRidleyStruct[xcb0_][xcb4_].x0_; @@ -850,7 +851,7 @@ void CRidley::sub80255d58(urde::CStateManager& mgr) { xcc4_ = 1; } -void CRidley::sub80257744(urde::CStateManager& mgr) { +void CRidley::sub80257744(metaforce::CStateManager& mgr) { for (size_t i = 0; i < x984_bodyCollision->GetNumCollisionActors(); ++i) { const auto& colDesc = x984_bodyCollision->GetCollisionDescFromIndex(i); if (TCastToPtr colAct = mgr.ObjectById(colDesc.GetCollisionActorId())) { @@ -864,12 +865,12 @@ void CRidley::sub80257744(urde::CStateManager& mgr) { xa31_27_ = true; } -void CRidley::FirePlasma(urde::CStateManager& mgr) { +void CRidley::FirePlasma(metaforce::CStateManager& mgr) { if (xb64_plasmaProjectile == kInvalidUniqueId) { xb64_plasmaProjectile = mgr.AllocateUniqueId(); mgr.AddObject(new CPlasmaProjectile(xb68_.Token(), ""sv, EWeaponType::AI, x568_data.x64_, {}, EMaterialTypes::Character, xb68_.GetDamage(), xb64_plasmaProjectile, - GetAreaIdAlways(), GetUniqueId(), CPlasmaProjectile::PlayerEffectResoures(), + GetAreaIdAlways(), GetUniqueId(), CPlasmaProjectile::PlayerEffectResources(), false, EProjectileAttrib::KeepInCinematic)); } @@ -1270,7 +1271,7 @@ void CRidley::CoverAttack(CStateManager& mgr, EStateMsg msg, float arg) { } } -void CRidley::Crouch(urde::CStateManager& mgr, urde::EStateMsg msg, float arg) { +void CRidley::Crouch(metaforce::CStateManager& mgr, metaforce::EStateMsg msg, float arg) { if (msg == EStateMsg::Activate) { SetMomentumWR(GetGravityConstant() * zeus::skDown); if (xc64_aiStage == 3) { @@ -1327,7 +1328,7 @@ void CRidley::Flee(CStateManager& mgr, EStateMsg msg, float arg) { } } -void CRidley::Lurk(urde::CStateManager& mgr, urde::EStateMsg msg, float arg) { +void CRidley::Lurk(metaforce::CStateManager& mgr, metaforce::EStateMsg msg, float arg) { if (msg == EStateMsg::Activate) { if (!xa33_25_) { zeus::CVector3f vec = GetTranslation() - xa84_.origin; @@ -1613,7 +1614,7 @@ bool CRidley::ShouldRetreat(CStateManager& mgr, float arg) { return xa34_26_; } bool CRidley::ShouldCrouch(CStateManager& mgr, float arg) { return xb04_ == 1; } -bool CRidley::ShouldMove(urde::CStateManager& mgr, float arg) { +bool CRidley::ShouldMove(metaforce::CStateManager& mgr, float arg) { if (xb0c_ == 5) { xa34_25_ = true; return true; @@ -1676,7 +1677,7 @@ void CRidley::FacePlayer(float arg, CStateManager& mgr) { x450_bodyController->FaceDirection((mgr.GetPlayer().GetTranslation() - GetTranslation()).normalized(), arg); } -void CRidley::sub80253710(urde::CStateManager& mgr) { +void CRidley::sub80253710(metaforce::CStateManager& mgr) { xb08_ = xb0c_; float fVar1 = 100.f * mgr.GetActiveRandom()->Float(); float fVar6 = 0.f + skFloats[xb08_].x0_; @@ -1723,4 +1724,4 @@ void CRidley::sub80253710(urde::CStateManager& mgr) { if (frontMag > 0.f && diffMag < x2fc_minAttackRange && xb08_ != 4) xb0c_ = 4; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CRidley.hpp b/Runtime/MP1/World/CRidley.hpp index 9c7a92b41..552cc5633 100644 --- a/Runtime/MP1/World/CRidley.hpp +++ b/Runtime/MP1/World/CRidley.hpp @@ -11,7 +11,7 @@ #include "Runtime/World/CPatterned.hpp" #include "Runtime/World/CProjectedShadow.hpp" -namespace urde { +namespace metaforce { class CParticleElectric; namespace MP1 { class CRidleyData { @@ -271,4 +271,4 @@ public: bool IsDizzy(CStateManager& mgr, float arg) override; }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CRipper.cpp b/Runtime/MP1/World/CRipper.cpp index 9796489db..db7c07300 100644 --- a/Runtime/MP1/World/CRipper.cpp +++ b/Runtime/MP1/World/CRipper.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CRipper::CRipper(TUniqueId uid, std::string_view name, EFlavorType type, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, const CActorParameters& actParms, const CGrappleParameters& grappleParms) @@ -184,4 +184,4 @@ zeus::CQuaternion CRipperControlledPlatform::Move(float arg, CStateManager& mgr) } return {}; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CRipper.hpp b/Runtime/MP1/World/CRipper.hpp index cd2774239..7d8b1e19b 100644 --- a/Runtime/MP1/World/CRipper.hpp +++ b/Runtime/MP1/World/CRipper.hpp @@ -4,7 +4,7 @@ #include "Runtime/World/CPatterned.hpp" #include "Runtime/World/CScriptPlatform.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { class CRipper : public CPatterned { CGrappleParameters x568_grappleParams; @@ -49,4 +49,4 @@ public: zeus::CQuaternion Move(float, CStateManager &) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CSeedling.cpp b/Runtime/MP1/World/CSeedling.cpp index 87b73df0c..591f5c1d8 100644 --- a/Runtime/MP1/World/CSeedling.cpp +++ b/Runtime/MP1/World/CSeedling.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array, 2> skNeedleLocators{{ { @@ -226,4 +226,4 @@ void CSeedling::MassiveDeath(CStateManager& mgr) { CPatterned::MassiveDeath(mgr); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CSeedling.hpp b/Runtime/MP1/World/CSeedling.hpp index 38ee49280..04f4747c4 100644 --- a/Runtime/MP1/World/CSeedling.hpp +++ b/Runtime/MP1/World/CSeedling.hpp @@ -9,7 +9,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CSeedling : public CWallWalker { CPathFindSearch x5d8_searchPath; std::unique_ptr x6bc_spikeData; @@ -45,4 +45,4 @@ public: bool ShouldAttack(CStateManager&, float) override; void MassiveDeath(CStateManager&) override; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CShockWave.cpp b/Runtime/MP1/World/CShockWave.cpp index 9ed19e8ef..a6f3f431f 100644 --- a/Runtime/MP1/World/CShockWave.cpp +++ b/Runtime/MP1/World/CShockWave.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CShockWave::CShockWave(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, TUniqueId parent, const SShockWaveData& data, float minActiveTime, float knockback) : CActor(uid, true, name, info, xf, CModelData::CModelDataNull(), {EMaterialTypes::Projectile}, @@ -175,4 +175,4 @@ void CShockWave::Touch(CActor& actor, CStateManager& mgr) { bool CShockWave::IsHit(TUniqueId id) const { return std::find(x170_hitIds.begin(), x170_hitIds.end(), id) != x170_hitIds.end(); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CShockWave.hpp b/Runtime/MP1/World/CShockWave.hpp index 4eddadbec..742f7d507 100644 --- a/Runtime/MP1/World/CShockWave.hpp +++ b/Runtime/MP1/World/CShockWave.hpp @@ -1,10 +1,10 @@ #pragma once +#include "Runtime/Particle/CElementGen.hpp" #include "Runtime/World/CActor.hpp" #include "Runtime/World/CDamageInfo.hpp" -#include "Runtime/Particle/CElementGen.hpp" -namespace urde::MP1 { +namespace metaforce::MP1 { struct SShockWaveData { private: u32 x0_ = 8; @@ -31,6 +31,7 @@ public: [[nodiscard]] float GetWidthPercent() const { return x28_widthPercent; } [[nodiscard]] float GetInitialExpansionSpeed() const { return x2c_initialExpansionSpeed; } [[nodiscard]] float GetSpeedIncrease() const { return x30_speedIncrease; } + void SetSpeedIncrease(float speed) { x30_speedIncrease = speed; } [[nodiscard]] CAssetId GetWeaponDescId() const { return x34_weaponDesc; } [[nodiscard]] u16 GetElectrocuteSfx() const { return x38_electrocuteSfx; } }; @@ -70,4 +71,4 @@ public: private: [[nodiscard]] bool IsHit(TUniqueId id) const; }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CSpacePirate.cpp b/Runtime/MP1/World/CSpacePirate.cpp index 48d5c9ea7..333dde9dd 100644 --- a/Runtime/MP1/World/CSpacePirate.cpp +++ b/Runtime/MP1/World/CSpacePirate.cpp @@ -21,7 +21,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array skParts{ "Collar"sv, "Neck_1"sv, "R_shoulder"sv, "R_elbow"sv, "R_wrist"sv, "L_shoulder"sv, "L_elbow"sv, @@ -149,7 +149,7 @@ constexpr std::array skBursts{ }; } // Anonymous namespace -CSpacePirate::CSpacePirateData::CSpacePirateData(urde::CInputStream& in, u32 propCount) +CSpacePirate::CSpacePirateData::CSpacePirateData(metaforce::CInputStream& in, u32 propCount) : x0_AggressionCheck(in.readFloatBig()) , x4_CoverCheck(in.readFloatBig()) , x8_SearchRadius(in.readFloatBig()) @@ -416,10 +416,10 @@ CSpacePirate::CSpacePirate(TUniqueId uid, std::string_view name, const CEntityIn if (!x634_29_onlyAttackInRange) { x7a4_intoJumpDist = - GetAnimationDistance(CPASAnimParmData(13, CPASAnimParm::FromEnum(0), CPASAnimParm::FromEnum(0))); - x848_dodgeDist = GetAnimationDistance(CPASAnimParmData(3, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(1))); + GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(0), CPASAnimParm::FromEnum(0))); + x848_dodgeDist = GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::Step, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(1))); x84c_breakDodgeDist = - GetAnimationDistance(CPASAnimParmData(3, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(2))); + GetAnimationDistance(CPASAnimParmData(pas::EAnimationState::Step, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(2))); } else { x450_bodyController->BodyStateInfo().SetLocoAnimChangeAtEndOfAnimOnly(true); } @@ -588,7 +588,7 @@ bool CSpacePirate::FireProjectile(float dt, CStateManager& mgr) { } if (ret) { const auto bestAnim = x450_bodyController->GetPASDatabase().FindBestAnimation( - CPASAnimParmData{24, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); + CPASAnimParmData{pas::EAnimationState::AdditiveReaction, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); if (bestAnim.first > 0.f) { x64_modelData->GetAnimationData()->AddAdditiveAnimation(bestAnim.second, 1.f, false, true); } @@ -1847,7 +1847,7 @@ void CSpacePirate::Taunt(CStateManager& mgr, EStateMsg msg, float dt) { bool withOtherPirate = true; if (x634_27_melee) { const auto bestAnim = x450_bodyController->GetPASDatabase().FindBestAnimation( - CPASAnimParmData{16, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); + CPASAnimParmData{pas::EAnimationState::Taunt, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); if (bestAnim.first > 0.f) { withOtherPirate = false; x760_taunt = pas::ETauntType::Two; @@ -2550,4 +2550,4 @@ float CSpacePirate::GetGravityConstant() const { return 50.f; } CProjectileInfo* CSpacePirate::GetProjectileInfo() { return &x568_pirateData.x20_Projectile; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CSpacePirate.hpp b/Runtime/MP1/World/CSpacePirate.hpp index b5b9f359b..c7ec1b081 100644 --- a/Runtime/MP1/World/CSpacePirate.hpp +++ b/Runtime/MP1/World/CSpacePirate.hpp @@ -14,7 +14,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CSpacePirate; class CPirateRagDoll : public CRagDoll { @@ -333,4 +333,4 @@ public: TUniqueId GetAttachedActor() const { return x7b4_attachedActor; } bool IsTrooper() const { return x636_24_trooper; } }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CSpankWeed.cpp b/Runtime/MP1/World/CSpankWeed.cpp index 433f2fba8..3ecc6c777 100644 --- a/Runtime/MP1/World/CSpankWeed.cpp +++ b/Runtime/MP1/World/CSpankWeed.cpp @@ -9,8 +9,8 @@ #include -namespace urde::MP1 { -logvisor::Module SpankLog("urde::MP1::SpankWeed"); +namespace metaforce::MP1 { +logvisor::Module SpankLog("metaforce::MP1::SpankWeed"); constexpr std::array kArmCollision{{ {"Arm_4", 1.5f}, @@ -334,4 +334,4 @@ void CSpankWeed::KnockBack(const zeus::CVector3f& backVec, CStateManager& mgr, c float CSpankWeed::GetPlayerDistance(CStateManager& mgr) const { return (mgr.GetPlayer().GetTranslation() - x5a8_lockonTarget).magSquared(); } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CSpankWeed.hpp b/Runtime/MP1/World/CSpankWeed.hpp index 978d27e4d..8227083a2 100644 --- a/Runtime/MP1/World/CSpankWeed.hpp +++ b/Runtime/MP1/World/CSpankWeed.hpp @@ -7,7 +7,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CSpankWeed : public CPatterned { float x568_maxDetectionRange; float x56c_detectionHeightRange; @@ -53,4 +53,4 @@ public: void KnockBack(const zeus::CVector3f&, CStateManager&, const CDamageInfo& info, EKnockBackType type, bool inDeferred, float magnitude) override; }; -} // namespace urde::MP1 \ No newline at end of file +} // namespace metaforce::MP1 \ No newline at end of file diff --git a/Runtime/MP1/World/CThardus.cpp b/Runtime/MP1/World/CThardus.cpp index a415d7404..2bf1e2167 100644 --- a/Runtime/MP1/World/CThardus.cpp +++ b/Runtime/MP1/World/CThardus.cpp @@ -26,7 +26,7 @@ #include #include -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array skDamageableSphereJointInfoList1{{ {"R_knee", 1.f}, @@ -1181,7 +1181,7 @@ bool CThardus::ShouldTurn(CStateManager& mgr, float arg) { } bool CThardus::HitSomething(CStateManager& mgr, float arg) { return mgr.GetPlayer().GetFrozenState(); } -void CThardus::GatherWaypoints(urde::CScriptWaypoint* wp, urde::CStateManager& mgr, +void CThardus::GatherWaypoints(metaforce::CScriptWaypoint* wp, metaforce::CStateManager& mgr, rstl::reserved_vector& uids) { if (uids.size() < uids.capacity() && wp->GetActive()) { uids.push_back(wp->GetUniqueId()); @@ -1349,7 +1349,7 @@ void CThardus::sub801dbbdc(CStateManager& mgr, CDestroyableRock* rock) { } void CThardus::UpdateNonDestroyableCollisionActorMaterials(EUpdateMaterialMode mode, EMaterialTypes mat, - urde::CStateManager& mgr) { + metaforce::CStateManager& mgr) { for (const auto& uid : x634_nonDestroyableActors) { if (TCastToPtr col = mgr.ObjectById(uid)) { if (mode == EUpdateMaterialMode::Remove) { @@ -1445,7 +1445,7 @@ zeus::CVector3f CThardus::sub801de550(CStateManager& mgr) { unkVec.push_back(lastIdx); } - zeus::CVector2f plVec = mgr.GetPlayer().GetTranslation().toVec2f(); + //zeus::CVector2f plVec = mgr.GetPlayer().GetTranslation().toVec2f(); float maxDist = 0.f; float curDist = 0.f; @@ -1594,4 +1594,4 @@ zeus::CVector2f CThardus::sub801dc60c(float arg, CStateManager& mgr) { return ret; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CThardus.hpp b/Runtime/MP1/World/CThardus.hpp index 49dd4135c..e48179da3 100644 --- a/Runtime/MP1/World/CThardus.hpp +++ b/Runtime/MP1/World/CThardus.hpp @@ -4,7 +4,7 @@ #include "Runtime/World/CPatterned.hpp" #include "Runtime/World/CPathFindSearch.hpp" -namespace urde { +namespace metaforce { class CCollisionActorManager; namespace MP1 { class CThardus : public CPatterned { @@ -257,4 +257,4 @@ public: const zeus::CVector3f& v1); }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CThardusRockProjectile.cpp b/Runtime/MP1/World/CThardusRockProjectile.cpp index c6631619f..d0038053a 100644 --- a/Runtime/MP1/World/CThardusRockProjectile.cpp +++ b/Runtime/MP1/World/CThardusRockProjectile.cpp @@ -18,7 +18,7 @@ #include "Runtime/MP1/World/CThardus.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { namespace { constexpr std::array skRockCollisions{{ {"Rock_01_Collision_LCTR", 1.5f}, @@ -413,4 +413,4 @@ void CThardusRockProjectile::UpdateDestroyableRockCollisionActors(CStateManager& } } } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CThardusRockProjectile.hpp b/Runtime/MP1/World/CThardusRockProjectile.hpp index 414e3bbfa..8f3b0cd8b 100644 --- a/Runtime/MP1/World/CThardusRockProjectile.hpp +++ b/Runtime/MP1/World/CThardusRockProjectile.hpp @@ -2,7 +2,7 @@ #include "Runtime/World/CPatterned.hpp" #include "Runtime/Collision/CJointCollisionDescription.hpp" -namespace urde { +namespace metaforce { class CCollisionActorManager; struct SSphereJointInfo; namespace MP1 { @@ -69,4 +69,4 @@ public: bool ShouldMove(CStateManager& mgr, float arg) override; }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MP1/World/CTryclops.cpp b/Runtime/MP1/World/CTryclops.cpp index 9f153e81e..ed4fee8f2 100644 --- a/Runtime/MP1/World/CTryclops.cpp +++ b/Runtime/MP1/World/CTryclops.cpp @@ -12,7 +12,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { const CDamageVulnerability CTryclops::skVulnerabilities = CDamageVulnerability( EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Normal, EVulnerability::Deflect, EVulnerability::Deflect, @@ -661,4 +661,4 @@ bool CTryclops::sub8025dbd0(CStateManager& mgr) { return false; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CTryclops.hpp b/Runtime/MP1/World/CTryclops.hpp index 6d951b121..a62808b8c 100644 --- a/Runtime/MP1/World/CTryclops.hpp +++ b/Runtime/MP1/World/CTryclops.hpp @@ -5,7 +5,7 @@ #include -namespace urde::MP1 { +namespace metaforce::MP1 { class CTryclops : public CPatterned { static const CDamageVulnerability skVulnerabilities; @@ -91,4 +91,4 @@ public: bool IsDizzy(CStateManager&, float) override; CPathFindSearch* GetSearchPath() override { return &x568_pathFindSearch; } }; -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CWarWasp.cpp b/Runtime/MP1/World/CWarWasp.cpp index c84d9bf53..f9f4069a9 100644 --- a/Runtime/MP1/World/CWarWasp.cpp +++ b/Runtime/MP1/World/CWarWasp.cpp @@ -14,7 +14,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde::MP1 { +namespace metaforce::MP1 { CWarWasp::CWarWasp(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, CPatterned::EFlavorType flavor, CPatterned::EColliderType collider, const CDamageInfo& dInfo1, const CActorParameters& actorParms, @@ -1222,4 +1222,4 @@ bool CWarWasp::ShouldSpecialAttack(CStateManager& mgr, float arg) { CPathFindSearch* CWarWasp::GetSearchPath() { return &x590_pfSearch; } CProjectileInfo* CWarWasp::GetProjectileInfo() { return &x6d4_projectileInfo; } -} // namespace urde::MP1 +} // namespace metaforce::MP1 diff --git a/Runtime/MP1/World/CWarWasp.hpp b/Runtime/MP1/World/CWarWasp.hpp index 77d0df813..02f2eacd9 100644 --- a/Runtime/MP1/World/CWarWasp.hpp +++ b/Runtime/MP1/World/CWarWasp.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class CDamageInfo; namespace MP1 { class CWarWasp : public CPatterned { @@ -119,4 +119,4 @@ public: CProjectileInfo* GetProjectileInfo() override; }; } // namespace MP1 -} // namespace urde +} // namespace metaforce diff --git a/Runtime/MkCastTo.py b/Runtime/MkCastTo.py index 2864c154c..a53a411ec 100644 --- a/Runtime/MkCastTo.py +++ b/Runtime/MkCastTo.py @@ -90,7 +90,7 @@ sourcef = open('TCastTo.cpp', 'w') headerf.write('''#pragma once -namespace urde { +namespace metaforce { class CEntity; ''') @@ -164,7 +164,7 @@ for tp in CENTITY_TYPES: sourcef.write('#include "%s"\n' % tp[1]) sourcef.write(''' -namespace urde { +namespace metaforce { template TCastToPtr::TCastToPtr(CEntity* p) { if (p) p->Accept(*this); else ptr = nullptr; } diff --git a/Runtime/Particle/CColorElement.cpp b/Runtime/Particle/CColorElement.cpp index 482312bff..6650c97b0 100644 --- a/Runtime/Particle/CColorElement.cpp +++ b/Runtime/Particle/CColorElement.cpp @@ -9,7 +9,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Color_Elements */ -namespace urde { +namespace metaforce { CCEKeyframeEmitter::CCEKeyframeEmitter(CInputStream& in) { x4_percent = in.readUint32Big(); @@ -141,4 +141,4 @@ bool CCEParticleColor::GetValue(int /*frame*/, zeus::CColor& colorOut) const { return false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CColorElement.hpp b/Runtime/Particle/CColorElement.hpp index 1323aceef..41998157a 100644 --- a/Runtime/Particle/CColorElement.hpp +++ b/Runtime/Particle/CColorElement.hpp @@ -8,7 +8,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Color_Elements */ -namespace urde { +namespace metaforce { class CCEKeyframeEmitter : public CColorElement { u32 x4_percent; @@ -97,4 +97,4 @@ class CCEParticleColor : public CColorElement { public: bool GetValue(int frame, zeus::CColor& colorOut) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CDecal.cpp b/Runtime/Particle/CDecal.cpp index e47af6f31..21d2103e6 100644 --- a/Runtime/Particle/CDecal.cpp +++ b/Runtime/Particle/CDecal.cpp @@ -3,7 +3,7 @@ #include "Runtime/Graphics/CModel.hpp" #include "Runtime/Particle/CParticleGlobals.hpp" -namespace urde { +namespace metaforce { CRandom16 CDecal::sDecalRandom; bool CDecal::sMoveRedToAlphaBuffer = false; @@ -278,4 +278,4 @@ void CDecal::Update(float dt) { ++x58_frameIdx; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CDecal.hpp b/Runtime/Particle/CDecal.hpp index f2af7892a..4fbc09154 100644 --- a/Runtime/Particle/CDecal.hpp +++ b/Runtime/Particle/CDecal.hpp @@ -12,7 +12,7 @@ #include #include -namespace urde { +namespace metaforce { struct SQuadDescr; struct CQuadDecal { bool x0_24_invalid : 1 = true; @@ -55,4 +55,4 @@ public: static bool GetMoveRedToAlphaBuffer() { return sMoveRedToAlphaBuffer; }; static void SetMoveRedToAlphaBuffer(bool); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CDecalDataFactory.cpp b/Runtime/Particle/CDecalDataFactory.cpp index 91af4022d..7500438b0 100644 --- a/Runtime/Particle/CDecalDataFactory.cpp +++ b/Runtime/Particle/CDecalDataFactory.cpp @@ -5,8 +5,8 @@ #include "Runtime/Graphics/CModel.hpp" #include "Runtime/Particle/CParticleDataFactory.hpp" -namespace urde { -static logvisor::Module Log("urde::CDecalDataFactory"); +namespace metaforce { +static logvisor::Module Log("metaforce::CDecalDataFactory"); using CPF = CParticleDataFactory; std::unique_ptr CDecalDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) { @@ -130,4 +130,4 @@ CFactoryFnReturn FDecalDataFactory(const SObjectTag& tag, CInputStream& in, cons CSimplePool* sp = vparms.GetOwnedObj(); return TToken::GetIObjObjectFor(CDecalDataFactory::GetGeneratorDesc(in, sp)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CDecalDataFactory.hpp b/Runtime/Particle/CDecalDataFactory.hpp index 54628447a..f4676af8d 100644 --- a/Runtime/Particle/CDecalDataFactory.hpp +++ b/Runtime/Particle/CDecalDataFactory.hpp @@ -9,7 +9,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Particle/CDecalDescription.hpp" -namespace urde { +namespace metaforce { class CSimplePool; class CDecalDataFactory { @@ -23,4 +23,4 @@ public: CFactoryFnReturn FDecalDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference*); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CDecalDescription.hpp b/Runtime/Particle/CDecalDescription.hpp index 2af2b111c..0da845f15 100644 --- a/Runtime/Particle/CDecalDescription.hpp +++ b/Runtime/Particle/CDecalDescription.hpp @@ -9,7 +9,7 @@ #include "Runtime/Particle/CUVElement.hpp" #include "Runtime/Particle/CVectorElement.hpp" -namespace urde { +namespace metaforce { struct SQuadDescr { std::unique_ptr x0_LFT; @@ -36,4 +36,4 @@ public: bool x5c_25_DMOO : 1 = false; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CDecalManager.cpp b/Runtime/Particle/CDecalManager.cpp index 18a9675f2..aaa54e935 100644 --- a/Runtime/Particle/CDecalManager.cpp +++ b/Runtime/Particle/CDecalManager.cpp @@ -7,7 +7,7 @@ #include "Runtime/Particle/CDecal.hpp" #include "Runtime/Particle/CDecalDescription.hpp" -namespace urde { +namespace metaforce { bool CDecalManager::m_PoolInitialized = false; s32 CDecalManager::m_FreeIndex = 63; float CDecalManager::m_DeltaTimeSinceLastDecalCreation = 0.f; @@ -89,6 +89,7 @@ void CDecalManager::Update(float dt, CStateManager& mgr) { void CDecalManager::AddDecal(const TToken& decal, const zeus::CTransform& xf, bool notIce, CStateManager& mgr) { + OPTICK_EVENT(); if (m_LastDecalCreatedIndex != -1 && m_DeltaTimeSinceLastDecalCreation < 0.75f && m_LastDecalCreatedAssetId == decal.GetObjectTag()->id) { SDecal& existingDecal = m_DecalPool[m_LastDecalCreatedIndex]; @@ -112,4 +113,4 @@ void CDecalManager::AddDecal(const TToken& decal, const zeus: m_ActiveIndexList.push_back(thisIndex); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CDecalManager.hpp b/Runtime/Particle/CDecalManager.hpp index 4a499ad06..bb25fd589 100644 --- a/Runtime/Particle/CDecalManager.hpp +++ b/Runtime/Particle/CDecalManager.hpp @@ -8,7 +8,7 @@ #include "Runtime/Particle/CDecal.hpp" #include -namespace urde { +namespace metaforce { class CStateManager; class CDecalManager { @@ -41,4 +41,4 @@ public: CStateManager& mgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CElectricDescription.hpp b/Runtime/Particle/CElectricDescription.hpp index 54580af28..80532a864 100644 --- a/Runtime/Particle/CElectricDescription.hpp +++ b/Runtime/Particle/CElectricDescription.hpp @@ -10,7 +10,7 @@ #include "Runtime/Particle/CUVElement.hpp" #include "Runtime/Particle/CVectorElement.hpp" -namespace urde { +namespace metaforce { class CElectricDescription { public: std::unique_ptr x0_LIFE; @@ -34,4 +34,4 @@ public: SChildGeneratorDesc x60_EPSM; bool x70_ZERY = false; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index f3065fd5b..da68efb4c 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -15,9 +15,9 @@ #define MAX_GLOBAL_PARTICLES 2560 -namespace urde { +namespace metaforce { namespace { -logvisor::Module Log("urde::CElementGen"); +logvisor::Module Log("metaforce::CElementGen"); constexpr std::array ShadClsSizes{ sizeof(SParticleInstanceTex), @@ -78,7 +78,6 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie if (CIntElement* mbspElem = desc->x48_x34_MBSP.get()) mbspElem->GetValue(x74_curFrame, x270_MBSP); - m_maxMBSP = x270_MBSP; if (CModVectorElement* elem = desc->x7c_x68_VEL1.get()) { x280_VELSources[0] = elem; @@ -147,13 +146,15 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie if (CIntElement* maxpElem = desc->x28_x1c_MAXP.get()) { maxpElem->GetValue(x74_curFrame, x90_MAXP); - m_maxMAXP = maxpElem->GetMaxValue(); } - m_maxMAXP = std::min(m_maxMAXP, 256); - x30_particles.reserve(m_maxMAXP); + s32 count = std::min(256, x90_MAXP); + x30_particles.reserve(count); + if (x26d_28_enableADV) { + x60_advValues.resize(count); + } if (x2c_orientType == EModelOrientationType::One) - x50_parentMatrices.resize(m_maxMAXP); + x50_parentMatrices.resize(x90_MAXP); x26c_31_LINE = desc->x44_24_x30_24_LINE; x26d_24_FXLL = desc->x44_25_x30_25_FXLL; @@ -200,13 +201,45 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie hsh::texture2d tex{}; if (texr) tex = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - int maxVerts = (m_maxMAXP == 0 ? 256 : m_maxMAXP); + int maxVerts = x90_MAXP; m_lineRenderer = std::make_unique(CLineRenderer::EPrimitiveMode::Lines, maxVerts * 2, tex, bool(x26c_26_AAPH), x26c_28_zTest ? hsh::LEqual : hsh::Always); } else { m_shaderClass = CElementGenShaders::GetShaderClass(*this); } + _RecreatePipelines(); +} + +CElementGen::~CElementGen() { + --g_ParticleSystemAliveCount; + g_ParticleAliveCount -= x30_particles.size(); +} + +bool CElementGen::Update(double t) { + s32 oldMax = x90_MAXP; + CParticleGlobals::SParticleSystem* prevSystem = CParticleGlobals::instance()->m_currentParticleSystem; + CParticleGlobals::SParticleSystem thisSystem{FOURCC('PART'), this}; + CParticleGlobals::instance()->m_currentParticleSystem = &thisSystem; + CGenDescription* desc = x1c_genDesc.GetObj(); + CIntElement* pswtElem = desc->x10_x4_PSWT.get(); + if (pswtElem && !x26d_25_warmedUp) { + int pswt = 0; + pswtElem->GetValue(x74_curFrame, pswt); + //Log.report(logvisor::Info, FMT_STRING("Running warmup on particle system 0x%08x for %d ticks."), desc, pswt); + InternalUpdate((1.f / 60.f) * pswt); + x26d_25_warmedUp = true; + } + bool ret = InternalUpdate(t); + CParticleGlobals::instance()->m_currentParticleSystem = prevSystem; + + if (oldMax != x90_MAXP) { + _RecreatePipelines(); + } + return ret; +} + +void CElementGen::_RecreatePipelines() { size_t maxInsts = x26c_30_MBLR ? (m_maxMBSP * m_maxMAXP) : m_maxMAXP; maxInsts = (maxInsts == 0 ? 256 : maxInsts); @@ -242,29 +275,6 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie CElementGenShaders::BuildShaderDataBinding(*this); } -CElementGen::~CElementGen() { - --g_ParticleSystemAliveCount; - g_ParticleAliveCount -= x30_particles.size(); -} - -bool CElementGen::Update(double t) { - CParticleGlobals::SParticleSystem* prevSystem = CParticleGlobals::instance()->m_currentParticleSystem; - CParticleGlobals::SParticleSystem thisSystem{FOURCC('PART'), this}; - CParticleGlobals::instance()->m_currentParticleSystem = &thisSystem; - CGenDescription* desc = x1c_genDesc.GetObj(); - CIntElement* pswtElem = desc->x10_x4_PSWT.get(); - if (pswtElem && !x26d_25_warmedUp) { - int pswt = 0; - pswtElem->GetValue(x74_curFrame, pswt); - //Log.report(logvisor::Info, FMT_STRING("Running warmup on particle system 0x%08x for %d ticks."), desc, pswt); - InternalUpdate((1.f / 60.f) * pswt); - x26d_25_warmedUp = true; - } - bool ret = InternalUpdate(t); - CParticleGlobals::instance()->m_currentParticleSystem = prevSystem; - return ret; -} - bool CElementGen::InternalUpdate(double dt) { CGlobalRandom gr(x27c_randState); CGenDescription* desc = x1c_genDesc.GetObj(); @@ -287,7 +297,6 @@ bool CElementGen::InternalUpdate(double dt) { if (x26c_30_MBLR && dt > 0.0) { if (CIntElement* mbspElem = desc->x48_x34_MBSP.get()) mbspElem->GetValue(x74_curFrame, x270_MBSP); - x270_MBSP = std::min(x270_MBSP, m_maxMBSP); } int frameUpdateCount = 0; @@ -356,12 +365,7 @@ void CElementGen::AccumulateBounds(const zeus::CVector3f& pos, float size) { } void CElementGen::UpdateAdvanceAccessParameters(u32 activeParticleCount, s32 particleFrame) { - if (activeParticleCount >= x60_advValues.size()) { - CParticleGlobals::instance()->m_particleAccessParameters = nullptr; - return; - } - - CGenDescription* desc = x1c_genDesc.GetObj(); + CGenDescription* desc = x28_loadedGenDesc; std::array& arr = x60_advValues[activeParticleCount]; CParticleGlobals::instance()->m_particleAccessParameters = &arr; @@ -417,10 +421,7 @@ void CElementGen::UpdateExistingParticles() { x25c_activeParticleCount = 0; CParticleGlobals::instance()->SetEmitterTime(x74_curFrame); - if (x25c_activeParticleCount < x60_advValues.size()) - CParticleGlobals::instance()->m_particleAccessParameters = &x60_advValues[x25c_activeParticleCount]; - else - CParticleGlobals::instance()->m_particleAccessParameters = nullptr; + CParticleGlobals::instance()->m_particleAccessParameters = nullptr; for (auto it = x30_particles.begin(); it != x30_particles.end();) { CParticle& particle = *it; @@ -497,27 +498,34 @@ void CElementGen::UpdateExistingParticles() { void CElementGen::CreateNewParticles(int count) { CGenDescription* desc = x1c_genDesc.GetObj(); - if (!g_ParticleSystemInitialized) + if (!g_ParticleSystemInitialized) { Initialize(); - if (!count || x30_particles.size() >= x90_MAXP) - return; + } - if (count + x30_particles.size() > x90_MAXP) + if (x30_particles.size() >= x90_MAXP) { + return; + } + + if (count + x30_particles.size() > x90_MAXP) { count = x90_MAXP - x30_particles.size(); - int newTotalCount = g_ParticleAliveCount + count; - if (newTotalCount > 2560) + } + + if (g_ParticleAliveCount + count > 2560) { count = 2560 - g_ParticleAliveCount; + } CGlobalRandom gr(x27c_randState); - x30_particles.reserve(x90_MAXP); - if (x26d_28_enableADV && x60_advValues.empty()) - x60_advValues.resize(m_maxMAXP); + x30_particles.reserve(count + x90_MAXP); + if (x26d_28_enableADV && x60_advValues.capacity() < count + x30_particles.size()) { + x60_advValues.resize(std::min(int(x60_advValues.capacity() * 2), x90_MAXP)); + } CParticleGlobals::instance()->m_particleAccessParameters = nullptr; for (int i = 0; i < count; ++i) { CParticle& particle = x30_particles.emplace_back(); ++g_ParticleAliveCount; + u32 particleCount = x30_particles.size() - 1; ++x25c_activeParticleCount; ++x260_cumulativeParticles; if (x2c_orientType == EModelOrientationType::One) { @@ -531,14 +539,16 @@ void CElementGen::CreateNewParticles(int count) { CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame); CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(0); g_currentParticle = &particle; - if (x26d_28_enableADV) - UpdateAdvanceAccessParameters(x30_particles.size() - 1, 0); + if (x26d_28_enableADV) { + UpdateAdvanceAccessParameters(particleCount, 0); + } particle.x0_endFrame += x74_curFrame; - if (CColorElement* colr = desc->x30_x24_COLR.get()) + if (CColorElement* colr = desc->x30_x24_COLR.get()) { colr->GetValue(0, particle.x34_color); - else + } else { particle.x34_color = zeus::skWhite; + } if (CEmitterElement* emtr = desc->x40_x2c_EMTR.get()) { emtr->GetValue(x74_curFrame, particle.x4_pos, particle.x1c_vel); @@ -597,6 +607,7 @@ void CElementGen::UpdatePSTranslationAndOrientation() { } std::unique_ptr CElementGen::ConstructChildParticleSystem(const TToken& desc) const { + OPTICK_EVENT(); auto ret = std::make_unique(desc, EModelOrientationType::Normal, x26d_27_enableOPTS ? EOptionalSystemFlags::Two : EOptionalSystemFlags::One); ret->x26d_26_modelsUseLights = x26d_26_modelsUseLights; @@ -823,6 +834,14 @@ u32 CElementGen::GetSystemCount() const { } void CElementGen::Render(const CActorLights* actorLights) { + // Check to make sure our buffers are ready to render + if (!x26c_31_LINE && (!m_instBuf || !m_uniformBuf)) { + return; + } + if (x28_loadedGenDesc->x45_24_x31_26_PMUS && (!m_instBufPmus || !m_uniformBufPmus)) { + return; + } + SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::Render {}"), *x1c_genDesc.GetObjectTag()).c_str(), zeus::skYellow); @@ -853,8 +872,15 @@ void CElementGen::Render(const CActorLights* actorLights) { } void CElementGen::RenderModels(const CActorLights* actorLights) { - CGenDescription* desc = x1c_genDesc.GetObj(); + // Check to make sure our buffers are ready to render + if (!x26c_31_LINE && (!m_instBuf || !m_uniformBuf)) { + return; + } + if (x28_loadedGenDesc->x45_24_x31_26_PMUS && (!m_instBufPmus || !m_uniformBufPmus)) { + return; + } + CParticleGlobals::instance()->m_particleAccessParameters = nullptr; if (x26d_26_modelsUseLights) { CGraphics::SetLightState(x274_backupLightActive); } else { @@ -862,6 +888,8 @@ void CElementGen::RenderModels(const CActorLights* actorLights) { } CGlobalRandom gr(x27c_randState); + CGenDescription* desc = x1c_genDesc.GetObj(); + SUVElementSet uvs = {0.f, 0.f, 1.f, 1.f}; CUVElement* texr = desc->x54_x40_TEXR.get(); CTexture* cachedTex = nullptr; @@ -960,10 +988,10 @@ void CElementGen::RenderModels(const CActorLights* actorLights) { CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame - particle.x28_startFrame); int partFrame = x74_curFrame - particle.x28_startFrame - 1; CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(partFrame); - if (i < x60_advValues.size()) + if (x26d_28_enableADV) { CParticleGlobals::instance()->m_particleAccessParameters = &x60_advValues[i]; - else - CParticleGlobals::instance()->m_particleAccessParameters = nullptr; + } + CVectorElement* pmop = desc->x6c_x58_PMOP.get(); if (pmop) pmop->GetValue(partFrame, pmopVec); @@ -1912,4 +1940,4 @@ void CElementGen::Reset() { void CElementGen::SetMoveRedToAlphaBuffer(bool move) { sMoveRedToAlphaBuffer = move; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CElementGen.hpp b/Runtime/Particle/CElementGen.hpp index 3e7055c90..50f3e9332 100644 --- a/Runtime/Particle/CElementGen.hpp +++ b/Runtime/Particle/CElementGen.hpp @@ -19,7 +19,7 @@ #include #include -namespace urde { +namespace metaforce { class CActorLights; class CGenDescription; class CLight; @@ -66,7 +66,6 @@ private: bool x88_particleEmission = true; float x8c_generatorRemainder = 0.f; int x90_MAXP = 0; - int m_maxMAXP = 256; u16 x94_randomSeed = g_GlobalSeed; float x98_generatorRate = 1.f; std::array x9c_externalVars{}; @@ -102,7 +101,6 @@ private: bool x26d_27_enableOPTS : 1; bool x26d_28_enableADV : 1 = false; int x270_MBSP = 0; - int m_maxMBSP = 0; ERglLightBits x274_backupLightActive = ERglLightBits::None; std::array x278_hasVMD{}; CRandom16 x27c_randState; @@ -139,6 +137,7 @@ private: void AccumulateBounds(const zeus::CVector3f& pos, float size); + void _RecreatePipelines(); public: explicit CElementGen(TToken gen, EModelOrientationType orientType = EModelOrientationType::Normal, EOptionalSystemFlags flags = EOptionalSystemFlags::One); @@ -223,11 +222,10 @@ public: static void SetMoveRedToAlphaBuffer(bool move); s32 GetMaxParticles() const { return x90_MAXP; } - s32 GetMaxMaxParticles() const { return m_maxMAXP; } std::vector const& GetParticles() const { return x30_particles; } std::vector &GetParticles() { return x30_particles; } }; ENABLE_BITWISE_ENUM(CElementGen::EOptionalSystemFlags) -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CEmitterElement.cpp b/Runtime/Particle/CEmitterElement.cpp index 08feb3d12..a3f2eebb5 100644 --- a/Runtime/Particle/CEmitterElement.cpp +++ b/Runtime/Particle/CEmitterElement.cpp @@ -4,7 +4,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Emitter_Elements */ -namespace urde { +namespace metaforce { bool CEESimpleEmitter::GetValue(int frame, zeus::CVector3f& pPos, zeus::CVector3f& pVel) const { x4_loc->GetValue(frame, pPos); @@ -71,4 +71,4 @@ bool CVEAngleSphere::GetValue(int frame, zeus::CVector3f& pPos, zeus::CVector3f& return false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CEmitterElement.hpp b/Runtime/Particle/CEmitterElement.hpp index 8d8969d0d..73fbb42d4 100644 --- a/Runtime/Particle/CEmitterElement.hpp +++ b/Runtime/Particle/CEmitterElement.hpp @@ -5,7 +5,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Emitter_Elements */ -namespace urde { +namespace metaforce { class CEESimpleEmitter : public CEmitterElement { std::unique_ptr x4_loc; @@ -52,4 +52,4 @@ public: bool GetValue(int frame, zeus::CVector3f& pPos, zeus::CVector3f& pVel) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CFlameWarp.cpp b/Runtime/Particle/CFlameWarp.cpp index 2cc4e6e68..ed43e6706 100644 --- a/Runtime/Particle/CFlameWarp.cpp +++ b/Runtime/Particle/CFlameWarp.cpp @@ -4,7 +4,7 @@ #include "Runtime/CStateManager.hpp" -namespace urde { +namespace metaforce { void CFlameWarp::ModifyParticles(std::vector& particles) { if (x9c_stateMgr == nullptr || particles.size() < 9) { @@ -99,4 +99,4 @@ zeus::CAABox CFlameWarp::CalculateBounds() const { return ret; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CFlameWarp.hpp b/Runtime/Particle/CFlameWarp.hpp index 6e414dcc8..8f4eccb80 100644 --- a/Runtime/Particle/CFlameWarp.hpp +++ b/Runtime/Particle/CFlameWarp.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { class CStateManager; class CFlameWarp : public CWarp { @@ -48,4 +48,4 @@ public: void ResetPosition(const zeus::CVector3f& pos); zeus::CAABox CalculateBounds() const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CGenDescription.hpp b/Runtime/Particle/CGenDescription.hpp index 8593d426a..4687e8455 100644 --- a/Runtime/Particle/CGenDescription.hpp +++ b/Runtime/Particle/CGenDescription.hpp @@ -14,7 +14,7 @@ /* Documentation at: https://wiki.axiodl.com/w/PART_(File_Format) */ -namespace urde { +namespace metaforce { class CGenDescription { public: @@ -110,4 +110,4 @@ public: CGenDescription() = default; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CIntElement.cpp b/Runtime/Particle/CIntElement.cpp index 6367dfa1e..9109ab937 100644 --- a/Runtime/Particle/CIntElement.cpp +++ b/Runtime/Particle/CIntElement.cpp @@ -9,7 +9,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Int_Elements */ -namespace urde { +namespace metaforce { CIEKeyframeEmitter::CIEKeyframeEmitter(CInputStream& in) { x4_percent = in.readUint32Big(); @@ -299,4 +299,4 @@ int CIERealToInt::GetMaxValue() const { return 1; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CIntElement.hpp b/Runtime/Particle/CIntElement.hpp index f9d490b86..b47011242 100644 --- a/Runtime/Particle/CIntElement.hpp +++ b/Runtime/Particle/CIntElement.hpp @@ -7,7 +7,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Int_Elements */ -namespace urde { +namespace metaforce { class CIEKeyframeEmitter : public CIntElement { u32 x4_percent; @@ -218,4 +218,4 @@ public: int GetMaxValue() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CModVectorElement.cpp b/Runtime/Particle/CModVectorElement.cpp index 05b8ea66f..ff0163f42 100644 --- a/Runtime/Particle/CModVectorElement.cpp +++ b/Runtime/Particle/CModVectorElement.cpp @@ -7,7 +7,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Mod_Vector_Elements */ -namespace urde { +namespace metaforce { bool CMVEImplosion::GetValue(int frame, zeus::CVector3f& pVel, zeus::CVector3f& pPos) const { zeus::CVector3f av; @@ -237,4 +237,4 @@ bool CMVESwirl::GetValue(int frame, zeus::CVector3f& pVel, zeus::CVector3f& pPos return false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CModVectorElement.hpp b/Runtime/Particle/CModVectorElement.hpp index f7fcf4600..5d5e95f89 100644 --- a/Runtime/Particle/CModVectorElement.hpp +++ b/Runtime/Particle/CModVectorElement.hpp @@ -5,7 +5,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Mod_Vector_Elements */ -namespace urde { +namespace metaforce { class CMVEImplosion : public CModVectorElement { std::unique_ptr x4_implPoint; @@ -173,4 +173,4 @@ public: bool GetValue(int frame, zeus::CVector3f& pVel, zeus::CVector3f& pPos) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleDataFactory.cpp b/Runtime/Particle/CParticleDataFactory.cpp index fe8454601..95125c537 100644 --- a/Runtime/Particle/CParticleDataFactory.cpp +++ b/Runtime/Particle/CParticleDataFactory.cpp @@ -8,8 +8,8 @@ #include "Runtime/Particle/CGenDescription.hpp" #include "Runtime/Particle/CSwooshDescription.hpp" -namespace urde { -static logvisor::Module Log("urde::CParticleDataFactory"); +namespace metaforce { +static logvisor::Module Log("metaforce::CParticleDataFactory"); float CParticleDataFactory::GetReal(CInputStream& in) { return in.readFloatBig(); } @@ -1036,4 +1036,4 @@ CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const return TToken::GetIObjObjectFor(CParticleDataFactory::GetGeneratorDesc(in, sp)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleDataFactory.hpp b/Runtime/Particle/CParticleDataFactory.hpp index 889a5fac3..b5ea0e839 100644 --- a/Runtime/Particle/CParticleDataFactory.hpp +++ b/Runtime/Particle/CParticleDataFactory.hpp @@ -10,7 +10,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/CModel.hpp" -namespace urde { +namespace metaforce { class CColorElement; class CElectricDescription; class CEmitterElement; @@ -99,7 +99,7 @@ public: CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace urde +} // namespace metaforce // FIXME hacky workaround for MSVC; these need to be complete types // but introduce circular dependencies if included at the start diff --git a/Runtime/Particle/CParticleElectric.cpp b/Runtime/Particle/CParticleElectric.cpp index dc8182e5c..6c28bc892 100644 --- a/Runtime/Particle/CParticleElectric.cpp +++ b/Runtime/Particle/CParticleElectric.cpp @@ -16,7 +16,7 @@ #include #include -namespace urde { +namespace metaforce { u16 CParticleElectric::g_GlobalSeed = 99; @@ -830,4 +830,4 @@ void CParticleElectric::DestroyParticles() { // Empty } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleElectric.hpp b/Runtime/Particle/CParticleElectric.hpp index 013630235..8077fbbc9 100644 --- a/Runtime/Particle/CParticleElectric.hpp +++ b/Runtime/Particle/CParticleElectric.hpp @@ -19,7 +19,7 @@ #include #include -namespace urde { +namespace metaforce { class CElectricDescription; class CParticleElectric : public CParticleGen { @@ -146,4 +146,4 @@ public: FourCC Get4CharId() const override { return FOURCC('ELSC'); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleElectricDataFactory.cpp b/Runtime/Particle/CParticleElectricDataFactory.cpp index 7f4059ebd..b1e8293d6 100644 --- a/Runtime/Particle/CParticleElectricDataFactory.cpp +++ b/Runtime/Particle/CParticleElectricDataFactory.cpp @@ -6,8 +6,8 @@ #include "Runtime/Graphics/CModel.hpp" #include "Runtime/Particle/CElectricDescription.hpp" -namespace urde { -static logvisor::Module Log("urde::CParticleElectricDataFactory"); +namespace metaforce { +static logvisor::Module Log("metaforce::CParticleElectricDataFactory"); using CPF = CParticleDataFactory; @@ -128,4 +128,4 @@ CFactoryFnReturn FParticleElectricDataFactory(const SObjectTag& tag, CInputStrea CSimplePool* sp = vparms.GetOwnedObj(); return TToken::GetIObjObjectFor(CParticleElectricDataFactory::GetGeneratorDesc(in, sp)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleElectricDataFactory.hpp b/Runtime/Particle/CParticleElectricDataFactory.hpp index 7ec5e749e..692a12741 100644 --- a/Runtime/Particle/CParticleElectricDataFactory.hpp +++ b/Runtime/Particle/CParticleElectricDataFactory.hpp @@ -8,7 +8,7 @@ #include "Runtime/IObj.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CElectricDescription; class CSimplePool; class CParticleElectricDataFactory { @@ -22,4 +22,4 @@ public: CFactoryFnReturn FParticleElectricDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference*); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleGen.cpp b/Runtime/Particle/CParticleGen.cpp index 632bcd37a..90845d99e 100644 --- a/Runtime/Particle/CParticleGen.cpp +++ b/Runtime/Particle/CParticleGen.cpp @@ -1,7 +1,7 @@ #include "Runtime/Particle/CParticleGen.hpp" -namespace urde { +namespace metaforce { void CParticleGen::AddModifier(CWarp* mod) { x4_modifierList.push_back(mod); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleGen.hpp b/Runtime/Particle/CParticleGen.hpp index b6387d1f6..39513bc1a 100644 --- a/Runtime/Particle/CParticleGen.hpp +++ b/Runtime/Particle/CParticleGen.hpp @@ -11,7 +11,7 @@ #include #include -namespace urde { +namespace metaforce { class CWarp; class CActorLights; @@ -64,4 +64,4 @@ public: virtual void AddModifier(CWarp* mod); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleGlobals.cpp b/Runtime/Particle/CParticleGlobals.cpp index 3bd62e8e3..20856a3dd 100644 --- a/Runtime/Particle/CParticleGlobals.cpp +++ b/Runtime/Particle/CParticleGlobals.cpp @@ -1,5 +1,5 @@ #include "Runtime/Particle/CParticleGlobals.hpp" -namespace urde { +namespace metaforce { std::unique_ptr CParticleGlobals::g_ParticleGlobals; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleGlobals.hpp b/Runtime/Particle/CParticleGlobals.hpp index f8ce74ca7..014cb9051 100644 --- a/Runtime/Particle/CParticleGlobals.hpp +++ b/Runtime/Particle/CParticleGlobals.hpp @@ -10,7 +10,7 @@ #include "zeus/CVector3f.hpp" #include "zeus/CVector4f.hpp" -namespace urde { +namespace metaforce { class CElementGen; class CParticleGlobals { CParticleGlobals() = default; @@ -85,4 +85,4 @@ struct SParticleUniforms { hsh::float4 moduColor; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleSwoosh.cpp b/Runtime/Particle/CParticleSwoosh.cpp index 22e88613b..190cb08c0 100644 --- a/Runtime/Particle/CParticleSwoosh.cpp +++ b/Runtime/Particle/CParticleSwoosh.cpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { int CParticleSwoosh::g_ParticleSystemAliveCount = 0; @@ -1080,4 +1080,4 @@ void CParticleSwoosh::DestroyParticles() { // Empty } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleSwoosh.hpp b/Runtime/Particle/CParticleSwoosh.hpp index 7fbaef985..3d6fa699d 100644 --- a/Runtime/Particle/CParticleSwoosh.hpp +++ b/Runtime/Particle/CParticleSwoosh.hpp @@ -18,7 +18,7 @@ #include #include -namespace urde { +namespace metaforce { class CSwooshDescription; class CParticleSwoosh : public CParticleGen { @@ -215,9 +215,14 @@ public: } } + void ForceOneUpdate(float dt) { + x1d0_26_forceOneUpdate = true; + Update(dt); + } std::vector const& GetSwooshes() const { return x15c_swooshes; } std::vector& GetSwooshes() { return x15c_swooshes; } u32 GetCurParticle() const { return x158_curParticle; } + static u32 GetAliveParticleSystemCount() { return g_ParticleSystemAliveCount; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleSwooshDataFactory.cpp b/Runtime/Particle/CParticleSwooshDataFactory.cpp index 76ef71e19..407f33ad6 100644 --- a/Runtime/Particle/CParticleSwooshDataFactory.cpp +++ b/Runtime/Particle/CParticleSwooshDataFactory.cpp @@ -7,8 +7,8 @@ #include "Runtime/Particle/CGenDescription.hpp" #include "Runtime/Particle/CSwooshDescription.hpp" -namespace urde { -static logvisor::Module Log("urde::CParticleSwooshDataFactory"); +namespace metaforce { +static logvisor::Module Log("metaforce::CParticleSwooshDataFactory"); using CPF = CParticleDataFactory; @@ -137,4 +137,4 @@ CFactoryFnReturn FParticleSwooshDataFactory(const SObjectTag& tag, CInputStream& CSimplePool* sp = vparms.GetOwnedObj(); return TToken::GetIObjObjectFor(CParticleSwooshDataFactory::GetGeneratorDesc(in, sp)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CParticleSwooshDataFactory.hpp b/Runtime/Particle/CParticleSwooshDataFactory.hpp index e27fab23f..d6d4a88fc 100644 --- a/Runtime/Particle/CParticleSwooshDataFactory.hpp +++ b/Runtime/Particle/CParticleSwooshDataFactory.hpp @@ -8,7 +8,7 @@ #include "Runtime/IObj.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CSwooshDescription; class CSimplePool; class CParticleSwooshDataFactory { @@ -21,4 +21,4 @@ public: CFactoryFnReturn FParticleSwooshDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference*); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CProjectileWeaponDataFactory.cpp b/Runtime/Particle/CProjectileWeaponDataFactory.cpp index c234a8907..d02d0f5b6 100644 --- a/Runtime/Particle/CProjectileWeaponDataFactory.cpp +++ b/Runtime/Particle/CProjectileWeaponDataFactory.cpp @@ -9,8 +9,8 @@ #include "Runtime/Particle/CSwooshDescription.hpp" #include "Runtime/Particle/CWeaponDescription.hpp" -namespace urde { -static logvisor::Module Log("urde::CProjectileWeaponDataFactory"); +namespace metaforce { +static logvisor::Module Log("metaforce::CProjectileWeaponDataFactory"); using CPF = CParticleDataFactory; @@ -173,4 +173,4 @@ CFactoryFnReturn FProjectileWeaponDataFactory(const SObjectTag& tag, CInputStrea CSimplePool* sp = vparms.GetOwnedObj(); return TToken::GetIObjObjectFor(CProjectileWeaponDataFactory::GetGeneratorDesc(in, sp)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CProjectileWeaponDataFactory.hpp b/Runtime/Particle/CProjectileWeaponDataFactory.hpp index 4cd9bd9d2..1ec523057 100644 --- a/Runtime/Particle/CProjectileWeaponDataFactory.hpp +++ b/Runtime/Particle/CProjectileWeaponDataFactory.hpp @@ -8,7 +8,7 @@ #include "Runtime/IObj.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CSimplePool; class CWeaponDescription; @@ -22,4 +22,4 @@ public: CFactoryFnReturn FProjectileWeaponDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference*); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CRealElement.cpp b/Runtime/Particle/CRealElement.cpp index 2ae594de7..e42ddd4fc 100644 --- a/Runtime/Particle/CRealElement.cpp +++ b/Runtime/Particle/CRealElement.cpp @@ -10,7 +10,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Real_Elements */ -namespace urde { +namespace metaforce { CREKeyframeEmitter::CREKeyframeEmitter(CInputStream& in) { x4_percent = in.readUint32Big(); @@ -351,4 +351,4 @@ bool CREGetComponentAlpha::GetValue(int frame, float& valOut) const { return false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CRealElement.hpp b/Runtime/Particle/CRealElement.hpp index 034bc8447..7db541d30 100644 --- a/Runtime/Particle/CRealElement.hpp +++ b/Runtime/Particle/CRealElement.hpp @@ -8,7 +8,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Real_Elements */ -namespace urde { +namespace metaforce { class CREKeyframeEmitter : public CRealElement { u32 x4_percent; @@ -357,4 +357,4 @@ public: bool GetValue(int frame, float& valOut) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CSpawnSystemKeyframeData.cpp b/Runtime/Particle/CSpawnSystemKeyframeData.cpp index ddd3e1503..4a039cc18 100644 --- a/Runtime/Particle/CSpawnSystemKeyframeData.cpp +++ b/Runtime/Particle/CSpawnSystemKeyframeData.cpp @@ -4,7 +4,7 @@ #include "Runtime/Graphics/CModel.hpp" #include "Runtime/Particle/CElectricDescription.hpp" -namespace urde { +namespace metaforce { CSpawnSystemKeyframeData::CSpawnSystemKeyframeData(CInputStream& in) { x0 = in.readUint32Big(); @@ -54,4 +54,4 @@ CSpawnSystemKeyframeData::GetSpawnedSystemsAtFrame(u32 frame) { return emptyReturn; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CSpawnSystemKeyframeData.hpp b/Runtime/Particle/CSpawnSystemKeyframeData.hpp index d254e14ad..b7b02bb18 100644 --- a/Runtime/Particle/CSpawnSystemKeyframeData.hpp +++ b/Runtime/Particle/CSpawnSystemKeyframeData.hpp @@ -7,7 +7,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CSimplePool; class CGenDescription; @@ -41,4 +41,4 @@ public: std::vector& GetSpawnedSystemsAtFrame(u32 frame); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CSwooshDescription.hpp b/Runtime/Particle/CSwooshDescription.hpp index 8910bebaf..ecd2ccae4 100644 --- a/Runtime/Particle/CSwooshDescription.hpp +++ b/Runtime/Particle/CSwooshDescription.hpp @@ -11,7 +11,7 @@ #include "Runtime/Particle/CUVElement.hpp" #include "Runtime/Particle/CVectorElement.hpp" -namespace urde { +namespace metaforce { class CSwooshDescription { public: std::unique_ptr x0_PSLT; @@ -45,4 +45,4 @@ public: CSwooshDescription() = default; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CUVElement.cpp b/Runtime/Particle/CUVElement.cpp index d364ac190..1bf85a527 100644 --- a/Runtime/Particle/CUVElement.cpp +++ b/Runtime/Particle/CUVElement.cpp @@ -2,7 +2,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#UV_Elements */ -namespace urde { +namespace metaforce { CUVEAnimTexture::CUVEAnimTexture(TToken&& tex, std::unique_ptr&& tileW, std::unique_ptr&& tileH, std::unique_ptr&& strideW, @@ -64,4 +64,4 @@ void CUVEAnimTexture::GetValueUV(int frame, SUVElementSet& valOut) const { valOut = x2c_uvElems[tile]; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CUVElement.hpp b/Runtime/Particle/CUVElement.hpp index bf7ea25eb..77162a2bb 100644 --- a/Runtime/Particle/CUVElement.hpp +++ b/Runtime/Particle/CUVElement.hpp @@ -10,7 +10,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#UV_Elements */ -namespace urde { +namespace metaforce { class CToken; struct SUVElementSet { @@ -58,4 +58,4 @@ public: bool HasConstantUV() const override { return false; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CVectorElement.cpp b/Runtime/Particle/CVectorElement.cpp index 3e910bd84..32afa1541 100644 --- a/Runtime/Particle/CVectorElement.cpp +++ b/Runtime/Particle/CVectorElement.cpp @@ -9,7 +9,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Vector_Elements */ -namespace urde { +namespace metaforce { CVEKeyframeEmitter::CVEKeyframeEmitter(CInputStream& in) { x4_percent = in.readUint32Big(); @@ -296,4 +296,4 @@ bool CVEColorToVector::GetValue(int frame, zeus::CVector3f& valOut) const { return false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CVectorElement.hpp b/Runtime/Particle/CVectorElement.hpp index 940326a10..60f1443bf 100644 --- a/Runtime/Particle/CVectorElement.hpp +++ b/Runtime/Particle/CVectorElement.hpp @@ -10,7 +10,7 @@ /* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Vector_Elements */ -namespace urde { +namespace metaforce { class CVEKeyframeEmitter : public CVectorElement { u32 x4_percent; @@ -209,4 +209,4 @@ public: bool GetValue(int frame, zeus::CVector3f& valOut) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CWarp.hpp b/Runtime/Particle/CWarp.hpp index cbb0d4a09..0bdc36ebc 100644 --- a/Runtime/Particle/CWarp.hpp +++ b/Runtime/Particle/CWarp.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Particle/CParticleGen.hpp" -namespace urde { +namespace metaforce { class CWarp { public: @@ -17,4 +17,4 @@ public: virtual FourCC Get4CharID() = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/CWeaponDescription.hpp b/Runtime/Particle/CWeaponDescription.hpp index 0144fe111..a1a95fd9b 100644 --- a/Runtime/Particle/CWeaponDescription.hpp +++ b/Runtime/Particle/CWeaponDescription.hpp @@ -10,7 +10,7 @@ #include "Runtime/Particle/CRealElement.hpp" #include "Runtime/Particle/CVectorElement.hpp" -namespace urde { +namespace metaforce { class CCollisionResponseData; struct SCollisionResponseData { @@ -59,4 +59,4 @@ public: bool x29_SPS2 = false; bool x29_FC60 = false; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Particle/IElement.hpp b/Runtime/Particle/IElement.hpp index e7cecd29a..9111f7b7c 100644 --- a/Runtime/Particle/IElement.hpp +++ b/Runtime/Particle/IElement.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class IElement { public: @@ -48,4 +48,4 @@ public: virtual bool GetValue(int frame, zeus::CVector3f& pPos, zeus::CVector3f& pVel) const = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/RetroTypes.cpp b/Runtime/RetroTypes.cpp index 3a94df7d5..3cb13e09a 100644 --- a/Runtime/RetroTypes.cpp +++ b/Runtime/RetroTypes.cpp @@ -5,8 +5,8 @@ #include -namespace urde { -logvisor::Module Log("urde::RetroTypes::CAssetId"); +namespace metaforce { +logvisor::Module Log("metaforce::RetroTypes::CAssetId"); CAssetId::CAssetId(CInputStream& in) { if (g_Main) { @@ -32,4 +32,4 @@ void CAssetId::PutTo(COutputStream& out) { Log.report(logvisor::Fatal, FMT_STRING("PutTo called before runtime Main entered!")); } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/RetroTypes.hpp b/Runtime/RetroTypes.hpp index a7bf1d1f0..460022263 100644 --- a/Runtime/RetroTypes.hpp +++ b/Runtime/RetroTypes.hpp @@ -22,7 +22,7 @@ using namespace std::literals; -namespace urde { +namespace metaforce { using FourCC = hecl::FourCC; @@ -151,7 +151,7 @@ public: return std::nullopt; } - return {urde::GetAverage(this->data(), this->size())}; + return {metaforce::GetAverage(this->data(), this->size())}; } [[nodiscard]] std::optional GetEntry(int i) const { @@ -166,24 +166,24 @@ public: [[nodiscard]] size_t Size() const { return this->size(); } }; -} // namespace urde +} // namespace metaforce namespace std { template <> -struct hash { - size_t operator()(const urde::SObjectTag& tag) const noexcept { return tag.id.Value(); } +struct hash { + size_t operator()(const metaforce::SObjectTag& tag) const noexcept { return tag.id.Value(); } }; template <> -struct hash { - size_t operator()(const urde::CAssetId& id) const noexcept { return id.Value(); } +struct hash { + size_t operator()(const metaforce::CAssetId& id) const noexcept { return id.Value(); } }; } // namespace std -FMT_CUSTOM_FORMATTER(urde::CAssetId, "{:08X}", obj.Value()) -FMT_CUSTOM_FORMATTER(urde::TEditorId, "{:08X}", obj.id) -FMT_CUSTOM_FORMATTER(urde::TUniqueId, "{:04X}", obj.id) -FMT_CUSTOM_FORMATTER(urde::SObjectTag, "{} {}", obj.type, obj.id) +FMT_CUSTOM_FORMATTER(metaforce::CAssetId, "{:08X}", obj.Value()) +FMT_CUSTOM_FORMATTER(metaforce::TEditorId, "{:08X}", obj.id) +FMT_CUSTOM_FORMATTER(metaforce::TUniqueId, "{:04X}", obj.id) +FMT_CUSTOM_FORMATTER(metaforce::SObjectTag, "{} {}", obj.type, obj.id) FMT_CUSTOM_FORMATTER(zeus::CVector3f, "({} {} {})", float(obj.x()), float(obj.y()), float(obj.z())) FMT_CUSTOM_FORMATTER(zeus::CVector2f, "({} {})", float(obj.x()), float(obj.y())) diff --git a/Runtime/Weapon/CAuxWeapon.cpp b/Runtime/Weapon/CAuxWeapon.cpp index 8e555c0cf..ce40ef2a6 100644 --- a/Runtime/Weapon/CAuxWeapon.cpp +++ b/Runtime/Weapon/CAuxWeapon.cpp @@ -8,7 +8,7 @@ #include "Runtime/Weapon/CNewFlameThrower.hpp" #include "Runtime/Weapon/CWaveBuster.hpp" -namespace urde { +namespace metaforce { constexpr CCameraShakeData skHardShake{ 0.3f, 100.f, @@ -342,4 +342,4 @@ void CAuxWeapon::SetNewTarget(TUniqueId targetId, CStateManager& mgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CAuxWeapon.hpp b/Runtime/Weapon/CAuxWeapon.hpp index bc48dc4ec..d6465f39c 100644 --- a/Runtime/Weapon/CAuxWeapon.hpp +++ b/Runtime/Weapon/CAuxWeapon.hpp @@ -9,7 +9,7 @@ #include "Runtime/Weapon/CGunWeapon.hpp" #include "Runtime/Weapon/CWeapon.hpp" -namespace urde { +namespace metaforce { class CAuxWeapon { TCachedToken x0_missile; @@ -52,4 +52,4 @@ public: void SetNewTarget(TUniqueId targetId, CStateManager& mgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CBeamInfo.hpp b/Runtime/Weapon/CBeamInfo.hpp index 8df00f49b..d800a489f 100644 --- a/Runtime/Weapon/CBeamInfo.hpp +++ b/Runtime/Weapon/CBeamInfo.hpp @@ -4,7 +4,7 @@ #include "Runtime/RetroTypes.hpp" #include -namespace urde { +namespace metaforce { class CBeamInfo { u32 x0_; /* @@ -89,4 +89,4 @@ public: const zeus::CColor& GetOuterColor() const { return x40_outerColor; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CBeamProjectile.cpp b/Runtime/Weapon/CBeamProjectile.cpp index fb19a22d4..ebdf04325 100644 --- a/Runtime/Weapon/CBeamProjectile.cpp +++ b/Runtime/Weapon/CBeamProjectile.cpp @@ -3,7 +3,7 @@ #include "Runtime/CStateManager.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CBeamProjectile::CBeamProjectile(const TToken& wDesc, std::string_view name, EWeaponType wType, const zeus::CTransform& xf, s32 maxLength, float beamRadius, float travelSpeed, @@ -90,6 +90,6 @@ void CBeamProjectile::UpdateFx(const zeus::CTransform& xf, float dt, CStateManag x324_xf = xf; } -void CBeamProjectile::Accept(urde::IVisitor& visitor) { visitor.Visit(this); } +void CBeamProjectile::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CBeamProjectile.hpp b/Runtime/Weapon/CBeamProjectile.hpp index a0adc1290..9db00eaeb 100644 --- a/Runtime/Weapon/CBeamProjectile.hpp +++ b/Runtime/Weapon/CBeamProjectile.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CBeamProjectile : public CGameProjectile { public: enum class EDamageType { @@ -66,4 +66,4 @@ public: virtual void UpdateFx(const zeus::CTransform&, float, CStateManager&); virtual void Fire(const zeus::CTransform&, CStateManager&, bool) = 0; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CBomb.cpp b/Runtime/Weapon/CBomb.cpp index 525be1219..b5f8ec367 100644 --- a/Runtime/Weapon/CBomb.cpp +++ b/Runtime/Weapon/CBomb.cpp @@ -11,7 +11,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CBomb::CBomb(const TCachedToken& particle1, const TCachedToken& particle2, TUniqueId uid, TAreaId aid, TUniqueId playerId, float f1, const zeus::CTransform& xf, @@ -33,7 +33,7 @@ CBomb::CBomb(const TCachedToken& particle1, const TCachedToken< x184_particle2->SetGlobalTranslation(xf.origin); } -void CBomb::Accept(urde::IVisitor& visitor) { visitor.Visit(this); } +void CBomb::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); } void CBomb::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { if (msg == EScriptObjectMessage::Registered) { @@ -63,7 +63,7 @@ void CBomb::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManag constexpr CMaterialFilter kSolidFilter = CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::Character, EMaterialTypes::Player, EMaterialTypes::ProjectilePassthrough}); -void CBomb::Think(float dt, urde::CStateManager& mgr) { +void CBomb::Think(float dt, metaforce::CStateManager& mgr) { CWeapon::Think(dt, mgr); if (x190_24_isNotDetonated) { @@ -125,7 +125,7 @@ void CBomb::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) { g_Renderer->AddParticleGen(*x184_particle2, closestPoint, aabox); } -void CBomb::Touch(CActor&, urde::CStateManager&) { +void CBomb::Touch(CActor&, metaforce::CStateManager&) { #if 0 x190_24_isNotDetonated; /* wat? */ #endif @@ -160,4 +160,4 @@ void CBomb::UpdateLight(float dt, CStateManager& mgr) { light->SetLight(x184_particle2->GetLight()); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CBomb.hpp b/Runtime/Weapon/CBomb.hpp index 3f89e6c7a..ebaaf91d5 100644 --- a/Runtime/Weapon/CBomb.hpp +++ b/Runtime/Weapon/CBomb.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CElementGen; class CBomb : public CWeapon { @@ -46,4 +46,4 @@ public: bool IsBeingDragged() const { return x190_25_beingDragged; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CBurstFire.cpp b/Runtime/Weapon/CBurstFire.cpp index 013f48a1c..c315fab5b 100644 --- a/Runtime/Weapon/CBurstFire.cpp +++ b/Runtime/Weapon/CBurstFire.cpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { CBurstFire::CBurstFire(const SBurst* const* burstDefs, s32 firstBurstCount) : x10_firstBurstCounter(firstBurstCount) { while (*burstDefs) { x1c_burstDefs.push_back(*burstDefs); @@ -96,4 +96,4 @@ float CBurstFire::GetMaxXError() const { return g_tweakPlayer->GetPlayerXYHalfEx float CBurstFire::GetMaxZError() const { return g_tweakPlayer->GetEyeOffset(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CBurstFire.hpp b/Runtime/Weapon/CBurstFire.hpp index d00f2ec3d..2ee8baa79 100644 --- a/Runtime/Weapon/CBurstFire.hpp +++ b/Runtime/Weapon/CBurstFire.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { class CStateManager; struct SBurst { @@ -47,4 +47,4 @@ public: bool ShouldFire() const { return x14_24_shouldFire; } bool IsBurstSet() const { return x18_curBursts != nullptr; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CElectricBeamProjectile.cpp b/Runtime/Weapon/CElectricBeamProjectile.cpp index 9b420bdc0..9328e7b82 100644 --- a/Runtime/Weapon/CElectricBeamProjectile.cpp +++ b/Runtime/Weapon/CElectricBeamProjectile.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CElectricBeamProjectile::CElectricBeamProjectile(const TToken& wDesc, EWeaponType wType, const SElectricBeamInfo& elec, const zeus::CTransform& xf, EMaterialTypes matTypes, const CDamageInfo& dInfo, TUniqueId uid, @@ -109,4 +109,4 @@ void CElectricBeamProjectile::Fire(const zeus::CTransform&, CStateManager&, bool SetActive(true); x480_ = 0.f; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CElectricBeamProjectile.hpp b/Runtime/Weapon/CElectricBeamProjectile.hpp index ce537d816..6f19545ec 100644 --- a/Runtime/Weapon/CElectricBeamProjectile.hpp +++ b/Runtime/Weapon/CElectricBeamProjectile.hpp @@ -4,7 +4,7 @@ #include "Runtime/Weapon/CBeamProjectile.hpp" -namespace urde { +namespace metaforce { struct SElectricBeamInfo { TToken x0_electricDescription; float x8_maxLength; @@ -38,4 +38,4 @@ public: void ResetBeam(CStateManager&, bool) override; void Fire(const zeus::CTransform&, CStateManager&, bool) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CEnergyProjectile.cpp b/Runtime/Weapon/CEnergyProjectile.cpp index f76ae75aa..485ab1a09 100644 --- a/Runtime/Weapon/CEnergyProjectile.cpp +++ b/Runtime/Weapon/CEnergyProjectile.cpp @@ -14,7 +14,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CEnergyProjectile::CEnergyProjectile(bool active, const TToken& desc, EWeaponType type, const zeus::CTransform& xf, EMaterialTypes excludeMat, const CDamageInfo& damage, @@ -406,4 +406,4 @@ void CEnergyProjectile::StopProjectile(CStateManager& mgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CEnergyProjectile.hpp b/Runtime/Weapon/CEnergyProjectile.hpp index 31371aa48..6b58d3db4 100644 --- a/Runtime/Weapon/CEnergyProjectile.hpp +++ b/Runtime/Weapon/CEnergyProjectile.hpp @@ -3,7 +3,7 @@ #include "CGameProjectile.hpp" #include "Camera/CCameraShakeData.hpp" -namespace urde { +namespace metaforce { class CEnergyProjectile : public CGameProjectile { CSfxHandle x2e8_sfx; @@ -42,4 +42,4 @@ public: void Set3d0_26(bool v) { x3d0_26_ = v; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CFidget.cpp b/Runtime/Weapon/CFidget.cpp index b393e8f27..b842f1ab1 100644 --- a/Runtime/Weapon/CFidget.cpp +++ b/Runtime/Weapon/CFidget.cpp @@ -3,7 +3,7 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/World/CPlayer.hpp" -namespace urde { +namespace metaforce { static float kMinorFidgetDelay = 20.f; static float kMajorFidgetDelay = 20.f; @@ -136,4 +136,4 @@ void CFidget::ResetAll() { x34_24_loading = false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CFidget.hpp b/Runtime/Weapon/CFidget.hpp index 5158221b4..4728651db 100644 --- a/Runtime/Weapon/CFidget.hpp +++ b/Runtime/Weapon/CFidget.hpp @@ -3,7 +3,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Weapon/CGunMotion.hpp" -namespace urde { +namespace metaforce { class CStateManager; class CFidget { @@ -46,4 +46,4 @@ public: void DoneLoading() { x34_24_loading = false; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CFlameInfo.cpp b/Runtime/Weapon/CFlameInfo.cpp index b9a30ff0a..ff6ccd3ec 100644 --- a/Runtime/Weapon/CFlameInfo.cpp +++ b/Runtime/Weapon/CFlameInfo.cpp @@ -1,6 +1,6 @@ #include "Runtime/Weapon/CFlameInfo.hpp" -namespace urde { +namespace metaforce { CFlameInfo::CFlameInfo(s32 w1, s32 w2, CAssetId flameFxId, s32 w3, float f1, float f2, float f3) : x0_propertyCount(w1), x4_attributes(w2), x8_flameFxId(flameFxId), xc_length(w3), x10_(f1), x18_(f2), x1c_(f3) {} @@ -13,4 +13,4 @@ CFlameInfo::CFlameInfo(CInputStream& in) , x10_(in.readFloatBig()) , x18_(in.readFloatBig()) , x1c_(in.readFloatBig()) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CFlameInfo.hpp b/Runtime/Weapon/CFlameInfo.hpp index 134da9143..3606f0e43 100644 --- a/Runtime/Weapon/CFlameInfo.hpp +++ b/Runtime/Weapon/CFlameInfo.hpp @@ -3,7 +3,7 @@ #include "Runtime/Weapon/CGameProjectile.hpp" #include "Runtime/IOStreams.hpp" -namespace urde { +namespace metaforce { class CFlameInfo { friend class CFlameThrower; s32 x0_propertyCount; @@ -23,4 +23,4 @@ public: [[nodiscard]] s32 GetLength() const { return xc_length; } [[nodiscard]] CAssetId GetFlameFxId() const { return x8_flameFxId; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CFlameThrower.cpp b/Runtime/Weapon/CFlameThrower.cpp index 80692d028..7b59a14a6 100644 --- a/Runtime/Weapon/CFlameThrower.cpp +++ b/Runtime/Weapon/CFlameThrower.cpp @@ -13,7 +13,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { const zeus::CVector3f CFlameThrower::kLightOffset(0, 3.f, 2.f); CFlameThrower::CFlameThrower(const TToken& wDesc, std::string_view name, EWeaponType wType, @@ -249,4 +249,4 @@ void CFlameThrower::Think(float dt, CStateManager& mgr) { } } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CFlameThrower.hpp b/Runtime/Weapon/CFlameThrower.hpp index e1eab06c7..aa7d307a6 100644 --- a/Runtime/Weapon/CFlameThrower.hpp +++ b/Runtime/Weapon/CFlameThrower.hpp @@ -5,7 +5,7 @@ #include "Runtime/Particle/CFlameWarp.hpp" #include "Runtime/Weapon/CGameProjectile.hpp" -namespace urde { +namespace metaforce { class CFlameInfo; class CElementGen; class CFlameThrower : public CGameProjectile { @@ -59,4 +59,4 @@ public: void Fire(const zeus::CTransform&, CStateManager&, bool); bool GetParticlesActive() const { return x400_25_particlesActive; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGSComboFire.cpp b/Runtime/Weapon/CGSComboFire.cpp index 6a227db29..cf724c772 100644 --- a/Runtime/Weapon/CGSComboFire.cpp +++ b/Runtime/Weapon/CGSComboFire.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CAnimData.hpp" #include "Runtime/Character/CPASAnimParmData.hpp" -namespace urde { +namespace metaforce { bool CGSComboFire::Update(CAnimData& data, float dt, CStateManager& mgr) { if (x8_cueAnimId != -1) { @@ -46,7 +46,8 @@ s32 CGSComboFire::SetAnim(CAnimData& data, s32 gunId, s32 loopState, CStateManag useLoopState = loopState; x10_25_idle = false; const CPASDatabase& pas = data.GetCharacterInfo().GetPASDatabase(); - CPASAnimParmData parms(4, CPASAnimParm::FromInt32(gunId), CPASAnimParm::FromEnum(useLoopState)); + CPASAnimParmData parms(pas::EAnimationState::Death, CPASAnimParm::FromInt32(gunId), + CPASAnimParm::FromEnum(useLoopState)); auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); x10_24_over = false; xc_gunId = gunId; @@ -62,4 +63,4 @@ s32 CGSComboFire::SetAnim(CAnimData& data, s32 gunId, s32 loopState, CStateManag return anim.second; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGSComboFire.hpp b/Runtime/Weapon/CGSComboFire.hpp index 622f97135..ade08e076 100644 --- a/Runtime/Weapon/CGSComboFire.hpp +++ b/Runtime/Weapon/CGSComboFire.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CAnimData; class CStateManager; @@ -26,4 +26,4 @@ public: s32 SetAnim(CAnimData& data, s32 gunId, s32 loopState, CStateManager& mgr, float delay); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGSFidget.cpp b/Runtime/Weapon/CGSFidget.cpp index f3766ecf8..667ca7e5e 100644 --- a/Runtime/Weapon/CGSFidget.cpp +++ b/Runtime/Weapon/CGSFidget.cpp @@ -5,17 +5,17 @@ #include "Runtime/Character/CAnimData.hpp" #include "Runtime/Weapon/WeaponCommon.hpp" -namespace urde { +namespace metaforce { bool CGSFidget::Update(CAnimData& data, float dt, CStateManager& mgr) { return !data.IsAnimTimeRemaining(0.001f, "Whole Body"); } s32 CGSFidget::SetAnim(CAnimData& data, s32 type, s32 gunId, s32 animSet, CStateManager& mgr) { const CPASDatabase& pas = data.GetCharacterInfo().GetPASDatabase(); - CPASAnimParmData parms(1, CPASAnimParm::FromEnum(type), CPASAnimParm::FromInt32(gunId), + CPASAnimParmData parms(pas::EAnimationState::Getup, CPASAnimParm::FromEnum(type), CPASAnimParm::FromInt32(gunId), CPASAnimParm::FromInt32(animSet)); auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); - bool loop = pas.GetAnimState(1)->GetAnimParmData(anim.second, 3).GetBoolValue(); + bool loop = pas.GetAnimState(pas::EAnimationState::Getup)->GetAnimParmData(anim.second, 3).GetBoolValue(); x14_gunId = gunId; x18_animSet = animSet; if (anim.second != -1) { @@ -28,7 +28,7 @@ s32 CGSFidget::SetAnim(CAnimData& data, s32 type, s32 gunId, s32 animSet, CState } void CGSFidget::LoadAnimAsync(CAnimData& data, s32 type, s32 gunId, s32 animSet, CStateManager& mgr) { - CPASAnimParmData parms(1, CPASAnimParm::FromEnum(type), CPASAnimParm::FromInt32(gunId), + CPASAnimParmData parms(pas::EAnimationState::Getup, CPASAnimParm::FromEnum(type), CPASAnimParm::FromInt32(gunId), CPASAnimParm::FromInt32(animSet)); auto anim = data.GetCharacterInfo().GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); if (anim.second != -1) @@ -38,4 +38,4 @@ void CGSFidget::LoadAnimAsync(CAnimData& data, s32 type, s32 gunId, s32 animSet, void CGSFidget::UnLoadAnim() { x0_anims.clear(); } bool CGSFidget::IsAnimLoaded() const { return NWeaponTypes::are_tokens_ready(x0_anims); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGSFidget.hpp b/Runtime/Weapon/CGSFidget.hpp index 1317089be..d5fd7f45d 100644 --- a/Runtime/Weapon/CGSFidget.hpp +++ b/Runtime/Weapon/CGSFidget.hpp @@ -5,7 +5,7 @@ #include "Runtime/CToken.hpp" #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CAnimData; class CStateManager; class CGSFidget { @@ -22,4 +22,4 @@ public: bool IsAnimLoaded() const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGSFreeLook.cpp b/Runtime/Weapon/CGSFreeLook.cpp index c865de0f0..df4209fcd 100644 --- a/Runtime/Weapon/CGSFreeLook.cpp +++ b/Runtime/Weapon/CGSFreeLook.cpp @@ -3,7 +3,7 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/Character/CPASAnimParmData.hpp" -namespace urde { +namespace metaforce { bool CGSFreeLook::Update(CAnimData& data, float dt, CStateManager& mgr) { if (x4_cueAnimId != -1) { @@ -36,11 +36,11 @@ s32 CGSFreeLook::SetAnim(CAnimData& data, s32 gunId, s32 setId, s32 loopState, C useLoopState = loopState; x14_idle = false; const CPASDatabase& pas = data.GetCharacterInfo().GetPASDatabase(); - CPASAnimParmData parms(3, CPASAnimParm::FromInt32(gunId), CPASAnimParm::FromInt32(setId), + CPASAnimParmData parms(pas::EAnimationState::Step, CPASAnimParm::FromInt32(gunId), CPASAnimParm::FromInt32(setId), CPASAnimParm::FromEnum(useLoopState)); auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); xc_gunId = gunId; - x10_setId = pas.GetAnimState(3)->GetAnimParmData(anim.second, 1).GetInt32Value(); + x10_setId = pas.GetAnimState(pas::EAnimationState::Step)->GetAnimParmData(anim.second, 1).GetInt32Value(); x8_loopState = useLoopState; if (delay != 0.f) { x0_delay = delay; @@ -53,4 +53,4 @@ s32 CGSFreeLook::SetAnim(CAnimData& data, s32 gunId, s32 setId, s32 loopState, C return anim.second; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGSFreeLook.hpp b/Runtime/Weapon/CGSFreeLook.hpp index b7e53d8ef..2e2f090ea 100644 --- a/Runtime/Weapon/CGSFreeLook.hpp +++ b/Runtime/Weapon/CGSFreeLook.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CAnimData; class CStateManager; @@ -24,4 +24,4 @@ public: s32 SetAnim(CAnimData& data, s32 gunId, s32 setId, s32 loopState, CStateManager& mgr, float delay); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGameProjectile.cpp b/Runtime/Weapon/CGameProjectile.cpp index 46a7f0a13..2c90279e8 100644 --- a/Runtime/Weapon/CGameProjectile.cpp +++ b/Runtime/Weapon/CGameProjectile.cpp @@ -15,7 +15,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CGameProjectile::CGameProjectile(bool active, const TToken& wDesc, std::string_view name, EWeaponType wType, const zeus::CTransform& xf, EMaterialTypes excludeMat, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, TUniqueId owner, @@ -43,7 +43,7 @@ CGameProjectile::CGameProjectile(bool active, const TToken& , x2e4_27_inWater(underwater) , x2e4_28_sendProjectileCollideMsg(sendCollideMsg) {} -void CGameProjectile::Accept(urde::IVisitor& visitor) { visitor.Visit(this); } +void CGameProjectile::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); } void CGameProjectile::ResolveCollisionWithActor(const CRayCastResult& res, CActor& act, CStateManager& mgr) { const zeus::CVector3f revDir = -x34_transform.basis[1].normalized(); @@ -459,4 +459,4 @@ std::optional CGameProjectile::GetTouchBounds() const { return std::nullopt; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGameProjectile.hpp b/Runtime/Weapon/CGameProjectile.hpp index a75ede1a3..39a933995 100644 --- a/Runtime/Weapon/CGameProjectile.hpp +++ b/Runtime/Weapon/CGameProjectile.hpp @@ -15,7 +15,7 @@ #include #include -namespace urde { +namespace metaforce { class CGenDescription; class CWeaponDescription; @@ -90,4 +90,4 @@ public: void SetMinHomingDistance(float dist) { x2e0_minHomingDist = dist; } void SetHitProjectileOwner(TUniqueId id) { x2c4_hitProjectileOwner = id; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGrappleArm.cpp b/Runtime/Weapon/CGrappleArm.cpp index d8a919e1c..815608209 100644 --- a/Runtime/Weapon/CGrappleArm.cpp +++ b/Runtime/Weapon/CGrappleArm.cpp @@ -13,7 +13,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { float CGrappleArm::g_GrappleBeamAnglePhaseDelta = 0.875f; float CGrappleArm::g_GrappleBeamXWaveAmplitude = 0.25f; @@ -614,4 +614,4 @@ void CGrappleArm::ReturnToDefault(CStateManager& mgr, float dt, bool setState) { x328_gunController->ReturnToDefault(mgr, dt, setState); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGrappleArm.hpp b/Runtime/Weapon/CGrappleArm.hpp index 9d287073f..a8546e8cb 100644 --- a/Runtime/Weapon/CGrappleArm.hpp +++ b/Runtime/Weapon/CGrappleArm.hpp @@ -14,7 +14,7 @@ #include -namespace urde { +namespace metaforce { class CActorLights; class CStateManager; struct CModelFlags; @@ -137,4 +137,4 @@ public: const CGunController* GunController() const { return x328_gunController.get(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGunController.cpp b/Runtime/Weapon/CGunController.cpp index a5708f0db..d08a758d7 100644 --- a/Runtime/Weapon/CGunController.cpp +++ b/Runtime/Weapon/CGunController.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CCharLayoutInfo.hpp" #include "Runtime/Character/CPASAnimParmData.hpp" -namespace urde { +namespace metaforce { void CGunController::LoadFidgetAnimAsync(CStateManager& mgr, s32 type, s32 gunId, s32 animSet) { x30_fidget.LoadAnimAsync(*x0_modelData.GetAnimationData(), type, gunId, animSet, mgr); @@ -48,8 +48,9 @@ void CGunController::EnterStruck(CStateManager& mgr, float angle, bool bigStrike } const CPASDatabase& pasDatabase = x0_modelData.GetAnimationData()->GetCharacterInfo().GetPASDatabase(); - CPASAnimParmData parms(2, CPASAnimParm::FromInt32(x4_freeLook.GetGunId()), CPASAnimParm::FromReal32(angle), - CPASAnimParm::FromBool(bigStrike), CPASAnimParm::FromBool(b2)); + CPASAnimParmData parms(pas::EAnimationState::LieOnGround, CPASAnimParm::FromInt32(x4_freeLook.GetGunId()), + CPASAnimParm::FromReal32(angle), CPASAnimParm::FromBool(bigStrike), + CPASAnimParm::FromBool(b2)); std::pair anim = pasDatabase.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); x0_modelData.GetAnimationData()->EnableLooping(false); CAnimPlaybackParms aparms(anim.second, -1, 1.f, true); @@ -75,7 +76,7 @@ void CGunController::EnterIdle(CStateManager& mgr) { } const CPASDatabase& pasDatabase = x0_modelData.GetAnimationData()->GetCharacterInfo().GetPASDatabase(); - CPASAnimParmData parms(5, parm); + CPASAnimParmData parms(pas::EAnimationState::Locomotion, parm); std::pair anim = pasDatabase.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); x0_modelData.GetAnimationData()->EnableLooping(false); CAnimPlaybackParms aparms(anim.second, -1, 1.f, true); @@ -161,7 +162,8 @@ void CGunController::ReturnToDefault(CStateManager& mgr, float dt, bool setState void CGunController::ReturnToBasePosition(CStateManager& mgr, float) { const CPASDatabase& pasDatabase = x0_modelData.GetAnimationData()->GetCharacterInfo().GetPASDatabase(); - std::pair anim = pasDatabase.FindBestAnimation(CPASAnimParmData(6), *mgr.GetActiveRandom(), -1); + std::pair anim = + pasDatabase.FindBestAnimation(CPASAnimParmData(pas::EAnimationState::KnockBack), *mgr.GetActiveRandom(), -1); x0_modelData.GetAnimationData()->EnableLooping(false); CAnimPlaybackParms parms(anim.second, -1, 1.f, true); x0_modelData.GetAnimationData()->SetAnimation(parms, false); @@ -174,4 +176,4 @@ void CGunController::Reset() { x58_25_enteredComboFire = false; x50_gunState = EGunState::Inactive; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGunController.hpp b/Runtime/Weapon/CGunController.hpp index 0698a4551..c98da0afe 100644 --- a/Runtime/Weapon/CGunController.hpp +++ b/Runtime/Weapon/CGunController.hpp @@ -5,7 +5,7 @@ #include "Runtime/Weapon/CGSFidget.hpp" #include "Runtime/Weapon/CGSFreeLook.hpp" -namespace urde { +namespace metaforce { enum class EGunState { Inactive, Default, FreeLook, ComboFire, Idle, Fidget, Strike, BigStrike }; class CGunController { @@ -37,4 +37,4 @@ public: void Reset(); s32 GetCurAnimId() const { return x54_curAnimId; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGunMotion.cpp b/Runtime/Weapon/CGunMotion.cpp index 85e6d6246..e4d205930 100644 --- a/Runtime/Weapon/CGunMotion.cpp +++ b/Runtime/Weapon/CGunMotion.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CPASAnimParmData.hpp" #include "Runtime/Weapon/WeaponCommon.hpp" -namespace urde { +namespace metaforce { CGunMotion::CGunMotion(CAssetId ancsId, const zeus::CVector3f& scale) : x0_modelData(CAnimRes(ancsId, 0, scale, 0, false), 1), x4c_gunController(x0_modelData) { @@ -22,19 +22,19 @@ bool CGunMotion::PlayPasAnim(SamusGun::EAnimationState state, CStateManager& mgr bool loop = true; switch (state) { case SamusGun::EAnimationState::Wander: { - CPASAnimParmData parms((s32(state))); + CPASAnimParmData parms((pas::EAnimationState(state))); auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); animId = anim.second; break; } case SamusGun::EAnimationState::Idle: { - CPASAnimParmData parms(s32(state), CPASAnimParm::FromEnum(0)); + CPASAnimParmData parms(pas::EAnimationState(state), CPASAnimParm::FromEnum(0)); auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); animId = anim.second; break; } case SamusGun::EAnimationState::Struck: { - CPASAnimParmData parms(s32(state), CPASAnimParm::FromInt32(0), CPASAnimParm::FromReal32(angle), + CPASAnimParmData parms(pas::EAnimationState(state), CPASAnimParm::FromInt32(0), CPASAnimParm::FromReal32(angle), CPASAnimParm::FromBool(bigStrike), CPASAnimParm::FromBool(false)); auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1); animId = anim.second; @@ -86,4 +86,4 @@ void CGunMotion::Draw(const CStateManager& mgr, const zeus::CTransform& xf) { x0_modelData.Render(mgr, xf, nullptr, flags); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGunMotion.hpp b/Runtime/Weapon/CGunMotion.hpp index 64cd18341..f226e6b65 100644 --- a/Runtime/Weapon/CGunMotion.hpp +++ b/Runtime/Weapon/CGunMotion.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { namespace SamusGun { enum class EAnimationState { Wander, Fidget, Struck, FreeLook, ComboFire, Idle, BasePosition }; @@ -37,4 +37,4 @@ public: bool IsAnimPlaying() const { return xb8_24_animPlaying; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGunWeapon.cpp b/Runtime/Weapon/CGunWeapon.cpp index ac8bc0261..ca5b00779 100644 --- a/Runtime/Weapon/CGunWeapon.cpp +++ b/Runtime/Weapon/CGunWeapon.cpp @@ -12,7 +12,7 @@ #include "Runtime/Weapon/CEnergyProjectile.hpp" #include "Runtime/Weapon/CWeapon.hpp" -namespace urde { +namespace metaforce { namespace { constexpr std::array skBeamXferNames{ "PowerXfer", "IceXfer", "WaveXfer", "PlasmaXfer", "PhazonXfer", @@ -176,6 +176,7 @@ constexpr std::array CGunWeapon::skShootAnim{4, 3}; void CGunWeapon::Fire(bool underwater, float dt, EChargeState chargeState, const zeus::CTransform& xf, CStateManager& mgr, TUniqueId homingTarget, float chargeFactor1, float chargeFactor2) { + OPTICK_EVENT(); CDamageInfo dInfo = GetDamageInfo(mgr, chargeState, chargeFactor1); zeus::CVector3f scale(chargeState == EChargeState::Normal ? 1.f : chargeFactor2); bool partialCharge = chargeState == EChargeState::Normal ? false : !zeus::close_enough(chargeFactor1, 1.f); @@ -592,4 +593,4 @@ bool CGunWeapon::IsChargeAnimOver() const { return !(x218_25_enableCharge && x10_solidModelData->GetAnimationData()->IsAnimTimeRemaining(0.001f, "Whole Body")); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CGunWeapon.hpp b/Runtime/Weapon/CGunWeapon.hpp index 6b2ef42cd..39ab12f20 100644 --- a/Runtime/Weapon/CGunWeapon.hpp +++ b/Runtime/Weapon/CGunWeapon.hpp @@ -22,7 +22,7 @@ #include -namespace urde { +namespace metaforce { class CActorLights; struct CModelFlags; @@ -160,4 +160,4 @@ public: static CDamageInfo GetShotDamageInfo(const SShotParam& shotParam, CStateManager& mgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CIceBeam.cpp b/Runtime/Weapon/CIceBeam.cpp index a22c9db03..819ad2e15 100644 --- a/Runtime/Weapon/CIceBeam.cpp +++ b/Runtime/Weapon/CIceBeam.cpp @@ -5,7 +5,7 @@ #include "Runtime/CSimplePool.hpp" #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { CIceBeam::CIceBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId, EMaterialTypes playerMaterial, const zeus::CVector3f& scale) @@ -141,4 +141,4 @@ void CIceBeam::Unload(CStateManager& mgr) { bool CIceBeam::IsLoaded() const { return CGunWeapon::IsLoaded() && x248_24_loaded; } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/Weapon/CIceBeam.hpp b/Runtime/Weapon/CIceBeam.hpp index e28c85544..b8d5b530a 100644 --- a/Runtime/Weapon/CIceBeam.hpp +++ b/Runtime/Weapon/CIceBeam.hpp @@ -4,7 +4,7 @@ #include "Runtime/Weapon/CGunWeapon.hpp" -namespace urde { +namespace metaforce { class CIceBeam final : public CGunWeapon { TCachedToken x21c_iceSmoke; @@ -33,4 +33,4 @@ public: bool IsLoaded() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CNewFlameThrower.cpp b/Runtime/Weapon/CNewFlameThrower.cpp index ef430c030..aa840b244 100644 --- a/Runtime/Weapon/CNewFlameThrower.cpp +++ b/Runtime/Weapon/CNewFlameThrower.cpp @@ -20,7 +20,7 @@ #include "Runtime/World/CScriptTrigger.hpp" #include "Runtime/Graphics/CBooRenderer.hpp" -namespace urde { +namespace metaforce { namespace { constexpr CMaterialFilter skExcludeProjectilePassthrough = CMaterialFilter::MakeExclude(EMaterialTypes::ProjectilePassthrough); @@ -368,15 +368,6 @@ void CNewFlameThrower::UpdateFx(const zeus::CTransform& xf, float dt, CStateMana float tmp = std::clamp(unk.magnitude() * 30.f, 1.f, x37c_26_runningSlowish ? 2.f : 4.f); x3b4_numSmokeParticlesSpawned = std::max(static_cast(round(tmp)), x3b4_numSmokeParticlesSpawned - 1); - // INSERT - if ((x35c_mainSmokeGen->GetParticles().size() + x3b4_numSmokeParticlesSpawned) > - x35c_mainSmokeGen->GetMaxMaxParticles()) { - x3b4_numSmokeParticlesSpawned = x3b4_numSmokeParticlesSpawned - - ((x35c_mainSmokeGen->GetParticles().size() + x3b4_numSmokeParticlesSpawned) - - x35c_mainSmokeGen->GetMaxMaxParticles()); - } - // END INSERT - // This limit shouldn't be needed, m_maxMAXP should be removed? x35c_mainSmokeGen->SetTranslation(swoosh_1.xc_translation); x35c_mainSmokeGen->SetOrientation(swoosh_1.x38_orientation); @@ -799,4 +790,4 @@ void CNewFlameThrower::SetWorldLighting(CStateManager& mgr, TAreaId area, float } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CNewFlameThrower.hpp b/Runtime/Weapon/CNewFlameThrower.hpp index ca01a9ab6..e42ef89d2 100644 --- a/Runtime/Weapon/CNewFlameThrower.hpp +++ b/Runtime/Weapon/CNewFlameThrower.hpp @@ -11,7 +11,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Weapon/CGameProjectile.hpp" -namespace urde { +namespace metaforce { class CCollisionPrimitive; class CCollisionInfoList; class CCollisionInfo; @@ -116,4 +116,4 @@ public: void AddToRenderer(zeus::CFrustum const& planes, CStateManager& mgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPhazonBeam.cpp b/Runtime/Weapon/CPhazonBeam.cpp index 1ec346a9a..d3d32a1ec 100644 --- a/Runtime/Weapon/CPhazonBeam.cpp +++ b/Runtime/Weapon/CPhazonBeam.cpp @@ -9,7 +9,7 @@ #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { +namespace metaforce { CPhazonBeam::CPhazonBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId, EMaterialTypes playerMaterial, const zeus::CVector3f& scale) @@ -26,8 +26,9 @@ CPhazonBeam::CPhazonBeam(CAssetId characterId, EWeaponType type, TUniqueId playe void CPhazonBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) { TAreaId aid = mgr.GetPlayer().GetAreaIdAlways(); - if (msg == EScriptObjectMessage::Deleted && aid != kInvalidAreaId) + if (msg == EScriptObjectMessage::Deleted && aid != kInvalidAreaId) { mgr.GetWorld()->GetArea(aid)->SetWeaponWorldLighting(4.f, 1.f); + } } void CPhazonBeam::StopBeam(CStateManager& mgr, bool b1) { @@ -37,8 +38,9 @@ void CPhazonBeam::StopBeam(CStateManager& mgr, bool b1) { void CPhazonBeam::UpdateBeam(float dt, const zeus::CTransform& targetXf, const zeus::CVector3f& localBeamPos, CStateManager& mgr) { - if (x234_chargeFxGen) + if (x234_chargeFxGen) { x234_chargeFxGen->SetParticleEmission(IsFiring()); + } CGunWeapon::UpdateMuzzleFx(dt, x4_scale, localBeamPos, IsFiring()); } @@ -61,8 +63,9 @@ void CPhazonBeam::PreRenderGunFx(const CStateManager& mgr, const zeus::CTransfor } void CPhazonBeam::PostRenderGunFx(const CStateManager& mgr, const zeus::CTransform& xf) { - if (x234_chargeFxGen) + if (x234_chargeFxGen) { x234_chargeFxGen->Render(); + } CGunWeapon::PostRenderGunFx(mgr, xf); } @@ -101,10 +104,11 @@ void CPhazonBeam::Update(float dt, CStateManager& mgr) { TAreaId aid = mgr.GetPlayer().GetAreaIdAlways(); if (aid != kInvalidAreaId) { CGameArea* area = mgr.GetWorld()->GetArea(aid); - if (x278_fireTime > 1.f / 6.f) + if (x278_fireTime > 1.f / 6.f) { area->SetWeaponWorldLighting(4.f, 1.f); - else + } else { area->SetWeaponWorldLighting(4.f, 0.9f); + } } if (!IsLoaded()) { @@ -118,17 +122,17 @@ void CPhazonBeam::Update(float dt, CStateManager& mgr) { x274_25_clipWipeActive = true; } } - } - - if (x274_25_clipWipeActive) { + } else if (x274_25_clipWipeActive) { x268_clipWipeScale += 0.75f * dt; - if (x268_clipWipeScale > 1.f) + if (x268_clipWipeScale > 1.f) { x268_clipWipeScale = 1.f; + } if (x268_clipWipeScale > 0.4f) { - if (x26c_clipWipeTranslate < 0.5f) + if (x26c_clipWipeTranslate < 0.5f) { x26c_clipWipeTranslate += 0.75f * dt; - else + } else { x274_25_clipWipeActive = false; + } } } else if (x274_26_veinsAlphaActive) { x270_indirectAlpha = x10_solidModelData->GetLocatorTransform("phazonScale_LCTR_SDK").origin.y(); @@ -216,8 +220,10 @@ void CPhazonBeam::Draw(bool drawSuitArm, const CStateManager& mgr, const zeus::C } void CPhazonBeam::DrawMuzzleFx(const CStateManager& mgr) const { - if (IsFiring()) - CGunWeapon::DrawMuzzleFx(mgr); + if (!IsFiring()) { + return; + } + CGunWeapon::DrawMuzzleFx(mgr); } -} // namespace urde +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/Weapon/CPhazonBeam.hpp b/Runtime/Weapon/CPhazonBeam.hpp index e424f045d..352f972a3 100644 --- a/Runtime/Weapon/CPhazonBeam.hpp +++ b/Runtime/Weapon/CPhazonBeam.hpp @@ -5,7 +5,7 @@ #include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include "Runtime/Weapon/CGunWeapon.hpp" -namespace urde { +namespace metaforce { class CPhazonBeam final : public CGunWeapon { TCachedToken x21c_phazonVeins; @@ -53,4 +53,4 @@ public: void DrawMuzzleFx(const CStateManager& mgr) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPlasmaBeam.cpp b/Runtime/Weapon/CPlasmaBeam.cpp index 4e692117d..6f6d60797 100644 --- a/Runtime/Weapon/CPlasmaBeam.cpp +++ b/Runtime/Weapon/CPlasmaBeam.cpp @@ -7,7 +7,7 @@ #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { +namespace metaforce { namespace { constexpr CCameraShakeData CameraShaker{0.125f, 0.25f}; constexpr std::array kSoundId{SFXwpn_fire_plasma_normal, SFXwpn_fire_plasma_charged}; @@ -146,4 +146,4 @@ void CPlasmaBeam::Unload(CStateManager& mgr) { bool CPlasmaBeam::IsLoaded() const { return CGunWeapon::IsLoaded() && x22c_24_loaded; } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/Weapon/CPlasmaBeam.hpp b/Runtime/Weapon/CPlasmaBeam.hpp index 21fc9956a..3ec1bb2d1 100644 --- a/Runtime/Weapon/CPlasmaBeam.hpp +++ b/Runtime/Weapon/CPlasmaBeam.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/Weapon/CGunWeapon.hpp" -namespace urde { +namespace metaforce { class CPlasmaBeam final : public CGunWeapon { TCachedToken x21c_plasma2nd1; @@ -42,4 +42,4 @@ public: bool IsLoaded() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPlasmaProjectile.cpp b/Runtime/Weapon/CPlasmaProjectile.cpp index abd798d95..57f9ba2d7 100644 --- a/Runtime/Weapon/CPlasmaProjectile.cpp +++ b/Runtime/Weapon/CPlasmaProjectile.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CPlasmaProjectile::RenderObjects::RenderObjects(hsh::texture2d tex, hsh::texture2d glowTex) @@ -27,7 +27,7 @@ CPlasmaProjectile::RenderObjects::RenderObjects(hsh::texture2d tex, CPlasmaProjectile::CPlasmaProjectile(const TToken& wDesc, std::string_view name, EWeaponType wType, const CBeamInfo& bInfo, const zeus::CTransform& xf, EMaterialTypes matType, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, TUniqueId owner, - const PlayerEffectResoures& res, bool growingBeam, EProjectileAttrib attribs) + const PlayerEffectResources& res, bool growingBeam, EProjectileAttrib attribs) : CBeamProjectile(wDesc, name, wType, xf, bInfo.GetLength(), bInfo.GetRadius(), bInfo.GetTravelSpeed(), matType, dInfo, uid, aid, owner, attribs, growingBeam) , x478_beamAttributes(bInfo.GetBeamAttributes()) @@ -440,4 +440,4 @@ void CPlasmaProjectile::Render(CStateManager& mgr) { (flags & 0x10) ? m_renderObjs->m_beamStrip4Sub : m_renderObjs->m_beamStrip4); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPlasmaProjectile.hpp b/Runtime/Weapon/CPlasmaProjectile.hpp index cc2ea0372..70a8275af 100644 --- a/Runtime/Weapon/CPlasmaProjectile.hpp +++ b/Runtime/Weapon/CPlasmaProjectile.hpp @@ -15,14 +15,26 @@ #include -namespace urde { +namespace metaforce { class CPlasmaProjectile : public CBeamProjectile { public: - struct PlayerEffectResoures : rstl::reserved_vector { - PlayerEffectResoures(CAssetId a = {}, CAssetId b = {}, CAssetId c = {}, CAssetId d = {}, + struct PlayerEffectResources : rstl::reserved_vector { + PlayerEffectResources(CAssetId a = {}, CAssetId b = {}, CAssetId c = {}, CAssetId d = {}, CAssetId e = {}, CAssetId f = {}, CAssetId g = {}, CAssetId h = {}) : rstl::reserved_vector({a, b, c, d, e, f, g, h}) {} }; + static PlayerEffectResources LoadPlayerEffectResources(CInputStream& in) { + u32 propCount = in.readUint32(); + CAssetId a{in}; + CAssetId b{in}; + CAssetId c{in}; + CAssetId d{in}; + CAssetId e{in}; + CAssetId f{in}; + CAssetId g{in}; + CAssetId h{in}; + return {a, b, c, d, e, f, g, h}; + } private: std::vector x468_lights; s32 x478_beamAttributes; @@ -106,7 +118,7 @@ public: CPlasmaProjectile(const TToken& wDesc, std::string_view name, EWeaponType wType, const CBeamInfo& bInfo, const zeus::CTransform& xf, EMaterialTypes matType, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, TUniqueId owner, - const PlayerEffectResoures& res, bool growingBeam, EProjectileAttrib attribs); + const PlayerEffectResources& res, bool growingBeam, EProjectileAttrib attribs); void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) override; @@ -117,5 +129,8 @@ public: bool CanRenderUnsorted(const CStateManager& mgr) const override; void AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) override; void Render(CStateManager& mgr) override; + zeus::CColor GetInnerColor() const { return x490_innerColor; } + zeus::CColor GetOuterColor() const { return x494_outerColor; } + bool IsFiring() const { return x548_26_firing; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPlayerGun.cpp b/Runtime/Weapon/CPlayerGun.cpp index 69523d6ce..9061b946a 100644 --- a/Runtime/Weapon/CPlayerGun.cpp +++ b/Runtime/Weapon/CPlayerGun.cpp @@ -15,7 +15,7 @@ #include "Runtime/Weapon/CEnergyProjectile.hpp" #include "Runtime/Weapon/CPowerBomb.hpp" -namespace urde { +namespace metaforce { namespace { std::array kVerticalAngleTable{-30.f, 0.f, 30.f}; std::array kHorizontalAngleTable{30.f, 30.f, 30.f}; @@ -345,9 +345,11 @@ void CPlayerGun::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CSt if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::PhazonSuit) && isUnmorphed) { x835_24_canFirePhazon = true; x835_25_inPhazonBeam = true; - if (x833_28_phazonBeamActive && static_cast(x72c_currentBeam)->IsFiring()) - if (TCastToPtr ent = mgr.ObjectById(sender)) + if (x833_28_phazonBeamActive && static_cast(x72c_currentBeam)->IsFiring()) { + if (TCastToPtr ent = mgr.ObjectById(sender)) { mgr.SendScriptMsg(ent.GetPtr(), x538_playerId, EScriptObjectMessage::Decrement); + } + } } break; case EScriptObjectMessage::RemovePhazonPoolInhabitant: @@ -366,8 +368,9 @@ void CPlayerGun::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CSt if (ai->IsMakingBigStrike()) { x394_damageTimer = ai->GetDamageDuration(); bigStrike = true; - if (player.GetAttachedActor() != kInvalidUniqueId) + if (player.GetAttachedActor() != kInvalidUniqueId) { metroidAttached = CPatterned::CastTo(mgr.GetObjectById(player.GetAttachedActor())) != nullptr; + } } } if (!x834_30_inBigStrike) { @@ -656,13 +659,15 @@ void CPlayerGun::HandlePhazonBeamChange(CStateManager& mgr) { void CPlayerGun::HandleWeaponChange(const CFinalInput& input, CStateManager& mgr) { x833_25_ = false; - if (ControlMapper::GetPressInput(ControlMapper::ECommands::Morph, input)) + if (ControlMapper::GetPressInput(ControlMapper::ECommands::Morph, input)) { StopContinuousBeam(mgr, true); + } if ((x2f8_stateFlags & 0x8) != 0x8) { - if (!x835_25_inPhazonBeam) + if (!x835_25_inPhazonBeam) { HandleBeamChange(input, mgr); - else + } else { HandlePhazonBeamChange(mgr); + } } } @@ -670,8 +675,9 @@ void CPlayerGun::ProcessInput(const CFinalInput& input, CStateManager& mgr) { CPlayerState& state = *mgr.GetPlayerState(); bool damageNotMorphed = (x834_30_inBigStrike && mgr.GetPlayer().GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed); - if (x832_24_coolingCharge || damageNotMorphed || (x2f8_stateFlags & 0x8) == 0x8) + if (x832_24_coolingCharge || damageNotMorphed || (x2f8_stateFlags & 0x8) == 0x8) { return; + } if (state.HasPowerUp(CPlayerState::EItemType::ChargeBeam)) { if (!state.ItemEnabled(CPlayerState::EItemType::ChargeBeam)) state.EnableItem(CPlayerState::EItemType::ChargeBeam); @@ -1323,8 +1329,9 @@ void CPlayerGun::CancelLockOn() { } void CPlayerGun::FireSecondary(float dt, CStateManager& mgr) { - if (mgr.GetCameraManager()->IsInCinematicCamera()) + if (mgr.GetCameraManager()->IsInCinematicCamera()) { return; + } if (x835_25_inPhazonBeam || x318_comboAmmoIdx == 0 || !mgr.GetPlayerState()->HasPowerUp(skItemArr[x318_comboAmmoIdx]) || (x2f8_stateFlags & 0x4) != 0x4) { @@ -1340,16 +1347,18 @@ void CPlayerGun::FireSecondary(float dt, CStateManager& mgr) { x832_26_comboFiring ? mgr.GetPlayerState()->GetMissileCostForAltAttack() : 1); comboFired = true; } - if (x300_remainingMissiles > 5) + if (x300_remainingMissiles > 5) { x300_remainingMissiles = 5; - else + } else { x300_remainingMissiles -= 1; + } } if (comboFired) { TUniqueId targetId = GetTargetId(mgr); - if (x832_26_comboFiring && targetId == kInvalidUniqueId && x310_currentBeam == CPlayerState::EBeamId::Wave) + if (x832_26_comboFiring && targetId == kInvalidUniqueId && x310_currentBeam == CPlayerState::EBeamId::Wave) { targetId = mgr.GetPlayer().GetAimTarget(); + } zeus::CTransform fireXf = x833_29_pointBlankWorldSurface ? x448_elbowWorldXf : x4a8_gunWorldXf * x418_beamLocalXf; if (!x833_29_pointBlankWorldSurface && x364_gunStrikeCoolTimer <= 0.f) { zeus::CVector3f backupOrigin = fireXf.origin; @@ -1909,8 +1918,9 @@ void CPlayerGun::Update(float grappleSwingT, float cameraBobT, float dt, CStateM x350_shakeZ = chargeShakeTbl[mgr.GetActiveRandom()->Next() % 3] * x340_chargeBeamFactor; } - if (!x72c_currentBeam->IsLoaded()) + if (!x72c_currentBeam->IsLoaded()) { return; + } GetLctrWithShake(x4d8_gunLocalXf, x73c_gunMotion->GetModelData(), "GBSE_SDK", true, true); GetLctrWithShake(x418_beamLocalXf, x72c_currentBeam->GetSolidModelData(), "LBEAM", false, true); @@ -2297,4 +2307,4 @@ TUniqueId CPlayerGun::DropPowerBomb(CStateManager& mgr) { mgr.AddObject(*pBomb); return uid; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPlayerGun.hpp b/Runtime/Weapon/CPlayerGun.hpp index 3176e9f6b..f97397f1b 100644 --- a/Runtime/Weapon/CPlayerGun.hpp +++ b/Runtime/Weapon/CPlayerGun.hpp @@ -29,7 +29,7 @@ #include #include -namespace urde { +namespace metaforce { struct CFinalInput; class CPlayerGun { @@ -357,4 +357,4 @@ public: CAuxWeapon& GetAuxWeapon() const { return *x744_auxWeapon; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPowerBeam.cpp b/Runtime/Weapon/CPowerBeam.cpp index 21bcfa596..a42e64a0a 100644 --- a/Runtime/Weapon/CPowerBeam.cpp +++ b/Runtime/Weapon/CPowerBeam.cpp @@ -5,7 +5,7 @@ #include "Runtime/CSimplePool.hpp" #include "Runtime/GameGlobalObjects.hpp" -namespace urde { +namespace metaforce { CPowerBeam::CPowerBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId, EMaterialTypes playerMaterial, const zeus::CVector3f& scale) @@ -137,4 +137,4 @@ void CPowerBeam::Unload(CStateManager& mgr) { bool CPowerBeam::IsLoaded() const { return CGunWeapon::IsLoaded() && x244_25_loaded; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPowerBeam.hpp b/Runtime/Weapon/CPowerBeam.hpp index d031ec676..71776e8f0 100644 --- a/Runtime/Weapon/CPowerBeam.hpp +++ b/Runtime/Weapon/CPowerBeam.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/Weapon/CGunWeapon.hpp" -namespace urde { +namespace metaforce { class CPowerBeam final : public CGunWeapon { enum class ESmokeState { Inactive, Active, Done }; @@ -33,4 +33,4 @@ public: bool IsLoaded() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPowerBomb.cpp b/Runtime/Weapon/CPowerBomb.cpp index 1b43075ab..dce9c62e1 100644 --- a/Runtime/Weapon/CPowerBomb.cpp +++ b/Runtime/Weapon/CPowerBomb.cpp @@ -14,7 +14,7 @@ #include -namespace urde { +namespace metaforce { constexpr zeus::CColor kFadeColor(COLOR(0xffffff7)); CPowerBomb::CPowerBomb(const TToken& particle, TUniqueId uid, TAreaId aid, TUniqueId playerId, @@ -93,8 +93,8 @@ void CPowerBomb::AddToRenderer(const zeus::CFrustum&, CStateManager&) { g_Renderer->AddParticleGen(*x168_particle); } -void CPowerBomb::ApplyDynamicDamage(const zeus::CVector3f& pos, urde::CStateManager& mgr) { +void CPowerBomb::ApplyDynamicDamage(const zeus::CVector3f& pos, metaforce::CStateManager& mgr) { mgr.ApplyDamageToWorld(xec_ownerId, *this, pos, x12c_curDamageInfo, xf8_filter); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CPowerBomb.hpp b/Runtime/Weapon/CPowerBomb.hpp index a69cc9a90..405cbf80c 100644 --- a/Runtime/Weapon/CPowerBomb.hpp +++ b/Runtime/Weapon/CPowerBomb.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CElementGen; class CPowerBomb : public CWeapon { @@ -36,4 +36,4 @@ public: void ApplyDynamicDamage(const zeus::CVector3f&, CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CProjectileInfo.cpp b/Runtime/Weapon/CProjectileInfo.cpp index a876b6d10..140cbc4cb 100644 --- a/Runtime/Weapon/CProjectileInfo.cpp +++ b/Runtime/Weapon/CProjectileInfo.cpp @@ -7,9 +7,9 @@ #include "Runtime/World/CDamageInfo.hpp" #include "Runtime/World/CPlayer.hpp" -namespace urde { +namespace metaforce { -CProjectileInfo::CProjectileInfo(urde::CInputStream& in) +CProjectileInfo::CProjectileInfo(metaforce::CInputStream& in) : x0_weaponDescription(g_SimplePool->GetObj({SBIG('WPSC'), CAssetId(in)})), xc_damageInfo(in) {} CProjectileInfo::CProjectileInfo(CAssetId proj, const CDamageInfo& dInfo) @@ -74,4 +74,4 @@ zeus::CVector3f CProjectileInfo::PredictInterceptPos(const zeus::CVector3f& gunP return PredictInterceptPos(gunPos, aimPos, player, gravity, GetProjectileSpeed(), dt); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CProjectileInfo.hpp b/Runtime/Weapon/CProjectileInfo.hpp index 7f388c359..8ef453c87 100644 --- a/Runtime/Weapon/CProjectileInfo.hpp +++ b/Runtime/Weapon/CProjectileInfo.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CPlayer; class CProjectileInfo { TCachedToken x0_weaponDescription; @@ -26,4 +26,4 @@ public: void SetDamage(const CDamageInfo& damageInfo) { xc_damageInfo = damageInfo; } TCachedToken& Token() { return x0_weaponDescription; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CProjectileWeapon.cpp b/Runtime/Weapon/CProjectileWeapon.cpp index d50a92903..bbe62ec50 100644 --- a/Runtime/Weapon/CProjectileWeapon.cpp +++ b/Runtime/Weapon/CProjectileWeapon.cpp @@ -5,7 +5,7 @@ #include "Runtime/Graphics/CModel.hpp" #include "Runtime/Particle/CParticleGlobals.hpp" -namespace urde { +namespace metaforce { u16 CProjectileWeapon::g_GlobalSeed = 99; @@ -438,4 +438,4 @@ void CProjectileWeapon::Update(float dt) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CProjectileWeapon.hpp b/Runtime/Weapon/CProjectileWeapon.hpp index 34613ba9e..10be49cd9 100644 --- a/Runtime/Weapon/CProjectileWeapon.hpp +++ b/Runtime/Weapon/CProjectileWeapon.hpp @@ -18,7 +18,7 @@ #include #include -namespace urde { +namespace metaforce { class CDecalDescription; class CGenDescription; class CModel; @@ -101,4 +101,4 @@ public: double GameTime() const { return xd0_curTime; } static constexpr float GetTickPeriod() { return 0.0166667f; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CTargetableProjectile.cpp b/Runtime/Weapon/CTargetableProjectile.cpp index ce6b6e748..1d36b4d55 100644 --- a/Runtime/Weapon/CTargetableProjectile.cpp +++ b/Runtime/Weapon/CTargetableProjectile.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CTargetableProjectile::CTargetableProjectile( const TToken& desc, EWeaponType type, const zeus::CTransform& xf, EMaterialTypes materials, @@ -61,4 +61,4 @@ void CTargetableProjectile::ResolveCollisionWithActor(const CRayCastResult& res, CEnergyProjectile::ResolveCollisionWithActor(res, act, mgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CTargetableProjectile.hpp b/Runtime/Weapon/CTargetableProjectile.hpp index bbe9a862f..7f0c3fbb2 100644 --- a/Runtime/Weapon/CTargetableProjectile.hpp +++ b/Runtime/Weapon/CTargetableProjectile.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Weapon/CEnergyProjectile.hpp" -namespace urde { +namespace metaforce { class CTargetableProjectile : public CEnergyProjectile { TLockedToken x3d8_weaponDesc; @@ -26,4 +26,4 @@ public: void ResolveCollisionWithActor(const CRayCastResult& res, CActor& act, CStateManager& mgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CWaveBeam.cpp b/Runtime/Weapon/CWaveBeam.cpp index 1641a8e64..a5ec16f65 100644 --- a/Runtime/Weapon/CWaveBeam.cpp +++ b/Runtime/Weapon/CWaveBeam.cpp @@ -6,7 +6,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Weapon/CEnergyProjectile.hpp" -namespace urde { +namespace metaforce { namespace { constexpr float skShotAnglePitch = 120.f; @@ -165,4 +165,4 @@ void CWaveBeam::Unload(CStateManager& mgr) { bool CWaveBeam::IsLoaded() const { return CGunWeapon::IsLoaded() && x258_24_loaded; } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/Weapon/CWaveBeam.hpp b/Runtime/Weapon/CWaveBeam.hpp index db12f9b7d..9bb43e3f1 100644 --- a/Runtime/Weapon/CWaveBeam.hpp +++ b/Runtime/Weapon/CWaveBeam.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Weapon/CGunWeapon.hpp" -namespace urde { +namespace metaforce { class CWaveBeam final : public CGunWeapon { TCachedToken x21c_waveBeam; @@ -34,4 +34,4 @@ public: bool IsLoaded() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CWaveBuster.cpp b/Runtime/Weapon/CWaveBuster.cpp index 50a59e5b4..5aa698c22 100644 --- a/Runtime/Weapon/CWaveBuster.cpp +++ b/Runtime/Weapon/CWaveBuster.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CWaveBuster::CWaveBuster(const TToken& desc, EWeaponType type, const zeus::CTransform& xf, EMaterialTypes matType, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, TUniqueId owner, @@ -69,4 +69,4 @@ std::optional CWaveBuster::GetTouchBounds() const { return GetProjectileBounds(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CWaveBuster.hpp b/Runtime/Weapon/CWaveBuster.hpp index 95245c8cc..f3f1faf00 100644 --- a/Runtime/Weapon/CWaveBuster.hpp +++ b/Runtime/Weapon/CWaveBuster.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CWaveBuster : public CGameProjectile { zeus::CTransform x2e8_originalXf; @@ -61,4 +61,4 @@ public: std::optional GetTouchBounds() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CWeapon.cpp b/Runtime/Weapon/CWeapon.cpp index ef5934533..3af683635 100644 --- a/Runtime/Weapon/CWeapon.cpp +++ b/Runtime/Weapon/CWeapon.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CWeapon::CWeapon(TUniqueId uid, TAreaId aid, bool active, TUniqueId owner, EWeaponType type, std::string_view name, const zeus::CTransform& xf, const CMaterialFilter& filter, const CMaterialList& mList, @@ -20,7 +20,7 @@ CWeapon::CWeapon(TUniqueId uid, TAreaId aid, bool active, TUniqueId owner, EWeap , x110_origDamageInfo(dInfo) , x12c_curDamageInfo(dInfo) {} -void CWeapon::Accept(urde::IVisitor& visitor) { visitor.Visit(this); } +void CWeapon::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); } void CWeapon::Think(float dt, CStateManager& mgr) { x148_curTime += dt; @@ -98,4 +98,4 @@ void CWeapon::FluidFXThink(EFluidState state, CScriptWater& water, CStateManager } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CWeapon.hpp b/Runtime/Weapon/CWeapon.hpp index 3c4a475cc..de2d5bd8d 100644 --- a/Runtime/Weapon/CWeapon.hpp +++ b/Runtime/Weapon/CWeapon.hpp @@ -8,7 +8,7 @@ #include "Runtime/World/CDamageInfo.hpp" #include "Runtime/Weapon/WeaponCommon.hpp" -namespace urde { +namespace metaforce { class CWeapon : public CActor { protected: EProjectileAttrib xe8_projectileAttribs; @@ -50,4 +50,4 @@ public: const CWeaponMode&, EProjectileAttrib) const override; void FluidFXThink(EFluidState state, CScriptWater& water, CStateManager& mgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CWeaponMgr.cpp b/Runtime/Weapon/CWeaponMgr.cpp index 28cfa89e0..2795f65c9 100644 --- a/Runtime/Weapon/CWeaponMgr.cpp +++ b/Runtime/Weapon/CWeaponMgr.cpp @@ -1,6 +1,6 @@ #include "Runtime/Weapon/CWeaponMgr.hpp" -namespace urde { +namespace metaforce { void CWeaponMgr::Add(TUniqueId uid, EWeaponType type) { auto iter = x0_weapons.emplace(uid, rstl::reserved_vector()).first; @@ -63,4 +63,4 @@ s32 CWeaponMgr::GetIndex(TUniqueId uid) const { return s32(std::distance(x0_weapons.cbegin(), iter)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CWeaponMgr.hpp b/Runtime/Weapon/CWeaponMgr.hpp index f9d2e5d8b..89241af7e 100644 --- a/Runtime/Weapon/CWeaponMgr.hpp +++ b/Runtime/Weapon/CWeaponMgr.hpp @@ -6,7 +6,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/Weapon/WeaponCommon.hpp" -namespace urde { +namespace metaforce { class CWeaponMgr { std::map> x0_weapons; @@ -20,4 +20,4 @@ public: s32 GetIndex(TUniqueId) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/CWeaponMode.hpp b/Runtime/Weapon/CWeaponMode.hpp index 55371f8ae..e057bef77 100644 --- a/Runtime/Weapon/CWeaponMode.hpp +++ b/Runtime/Weapon/CWeaponMode.hpp @@ -2,7 +2,7 @@ #include "Runtime/Weapon/WeaponCommon.hpp" -namespace urde { +namespace metaforce { class CWeaponMode { EWeaponType x0_weaponType = EWeaponType::None; bool x4_24_charged : 1 = false; @@ -29,4 +29,4 @@ public: static constexpr CWeaponMode Bomb() { return CWeaponMode(EWeaponType::Bomb); } static constexpr CWeaponMode PowerBomb() { return CWeaponMode(EWeaponType::PowerBomb); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/Weapon/WeaponCommon.cpp b/Runtime/Weapon/WeaponCommon.cpp index ef6ade659..e20c4bbf9 100644 --- a/Runtime/Weapon/WeaponCommon.cpp +++ b/Runtime/Weapon/WeaponCommon.cpp @@ -7,7 +7,7 @@ #include "Runtime/Character/CAnimData.hpp" #include "Runtime/Character/CPrimitive.hpp" -namespace urde::NWeaponTypes { +namespace metaforce::NWeaponTypes { void primitive_set_to_token_vector(const CAnimData& animData, const std::set& primSet, std::vector& tokensOut, bool preLock) { @@ -159,4 +159,4 @@ CSfxHandle play_sfx(u16 sfx, bool underwater, bool looped, float pan) { return hnd; } -} // namespace urde::NWeaponTypes +} // namespace metaforce::NWeaponTypes diff --git a/Runtime/Weapon/WeaponCommon.hpp b/Runtime/Weapon/WeaponCommon.hpp index 74c183927..5f7a3b05c 100644 --- a/Runtime/Weapon/WeaponCommon.hpp +++ b/Runtime/Weapon/WeaponCommon.hpp @@ -10,7 +10,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Audio/CSfxManager.hpp" -namespace urde { +namespace metaforce { class CAnimData; class CPrimitive; class CStateManager; @@ -90,4 +90,4 @@ CSfxHandle play_sfx(u16 sfx, bool underwater, bool looped, float pan); } // namespace NWeaponTypes -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CActor.cpp b/Runtime/World/CActor.cpp index de84c2c7f..88cbf7061 100644 --- a/Runtime/World/CActor.cpp +++ b/Runtime/World/CActor.cpp @@ -18,7 +18,7 @@ #include -namespace urde { +namespace metaforce { static CMaterialList MakeActorMaterialList(const CMaterialList& materialList, const CActorParameters& params) { CMaterialList ret = materialList; if (params.GetVisorParameters().x0_4_b1) @@ -695,4 +695,4 @@ void CActor::MoveScannableObjectInfoToActor(CActor* act, CStateManager& mgr) { act->AddMaterial(EMaterialTypes::Scannable, mgr); RemoveMaterial(EMaterialTypes::Scannable, mgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CActor.hpp b/Runtime/World/CActor.hpp index 9a5abb2ce..3b8aa49eb 100644 --- a/Runtime/World/CActor.hpp +++ b/Runtime/World/CActor.hpp @@ -13,7 +13,7 @@ #include -namespace urde { +namespace metaforce { class CActorParameters; class CWeaponMode; @@ -194,5 +194,6 @@ public: CSimpleShadow* Shadow() { return x94_simpleShadow.get(); } void MoveScannableObjectInfoToActor(CActor*, CStateManager&); const zeus::CAABox& GetRenderBounds() const { return x9c_renderBounds; } + void SetNotInSortedLists(bool notIn) { xe4_27_notInSortedLists = notIn; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CActorModelParticles.cpp b/Runtime/World/CActorModelParticles.cpp index b548a4871..0cf602226 100644 --- a/Runtime/World/CActorModelParticles.cpp +++ b/Runtime/World/CActorModelParticles.cpp @@ -16,7 +16,7 @@ #include "Runtime/World/CScriptPlayerActor.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { +namespace metaforce { static bool IsMediumOrLarge(const CActor& act) { if (const TCastToConstPtr pat = act) { @@ -686,4 +686,4 @@ void CActorModelParticles::Render(const CStateManager& mgr, const CActor& actor) CGraphics::SetModelMatrix(backupModel); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CActorModelParticles.hpp b/Runtime/World/CActorModelParticles.hpp index 524ca1505..e4ce99e48 100644 --- a/Runtime/World/CActorModelParticles.hpp +++ b/Runtime/World/CActorModelParticles.hpp @@ -17,7 +17,7 @@ #include #include -namespace urde { +namespace metaforce { class CStateManager; class CEntity; class CElementGen; @@ -172,4 +172,4 @@ public: void LightDudeOnFire(CActor& act); const CTexture* GetAshyTexture(const CActor& act); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CActorParameters.hpp b/Runtime/World/CActorParameters.hpp index 32f76e370..a83124a64 100644 --- a/Runtime/World/CActorParameters.hpp +++ b/Runtime/World/CActorParameters.hpp @@ -7,7 +7,7 @@ #include "Runtime/World/CScannableParameters.hpp" #include "Runtime/World/CVisorParameters.hpp" -namespace urde { +namespace metaforce { class CActorParameters { friend class ScriptLoader; @@ -66,4 +66,4 @@ public: float GetFadeInTime() const { return x5c_fadeInTime; } float GetFadeOutTime() const { return x60_fadeOutTime; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CAi.cpp b/Runtime/World/CAi.cpp index 56e77bd79..c97dd2a97 100644 --- a/Runtime/World/CAi.cpp +++ b/Runtime/World/CAi.cpp @@ -7,7 +7,7 @@ #include "Runtime/World/CScriptWater.hpp" #include "Runtime/World/CStateMachine.hpp" -namespace urde { +namespace metaforce { static CMaterialList MakeAiMaterialList(const CMaterialList& in) { CMaterialList ret = in; @@ -48,11 +48,12 @@ void CAi::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager } EWeaponCollisionResponseTypes CAi::GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&, - const urde::CWeaponMode&, urde::EProjectileAttrib) const { + const metaforce::CWeaponMode&, + metaforce::EProjectileAttrib) const { return EWeaponCollisionResponseTypes::EnemyNormal; } -void CAi::FluidFXThink(EFluidState state, CScriptWater& water, urde::CStateManager& mgr) { +void CAi::FluidFXThink(EFluidState state, CScriptWater& water, metaforce::CStateManager& mgr) { if (state == EFluidState::EnteredFluid || state == EFluidState::LeftFluid) { float dt = mgr.GetFluidPlaneManager()->GetLastSplashDeltaTime(GetUniqueId()); if (dt >= 0.02f) { @@ -85,4 +86,4 @@ CAiTriggerFunc CAi::GetTriggerFunc(std::string_view func) { return m_FuncMap->Ge const CStateMachine* CAi::GetStateMachine() const { return x2c8_stateMachine.GetObj(); } void CAi::CreateFuncLookup(CAiFuncMap* funcMap) { m_FuncMap = funcMap; } CAiFuncMap* CAi::m_FuncMap = nullptr; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CAi.hpp b/Runtime/World/CAi.hpp index de4dd8569..6770076c0 100644 --- a/Runtime/World/CAi.hpp +++ b/Runtime/World/CAi.hpp @@ -14,7 +14,7 @@ #include -namespace urde { +namespace metaforce { enum class EListenNoiseType { PlayerFire, BombExplode, ProjectileExplode }; @@ -187,4 +187,4 @@ public: virtual bool ShouldCallForBackup(CStateManager&, float) { return false; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CAiFuncMap.cpp b/Runtime/World/CAiFuncMap.cpp index 9518d5d10..5acfc0ec4 100644 --- a/Runtime/World/CAiFuncMap.cpp +++ b/Runtime/World/CAiFuncMap.cpp @@ -3,7 +3,7 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/World/CAi.hpp" -namespace urde { +namespace metaforce { CAiFuncMap::CAiFuncMap() { /* Ai States */ x0_stateFuncs.reserve(55); @@ -156,4 +156,4 @@ CAiTriggerFunc CAiFuncMap::GetTriggerFunc(std::string_view func) const { return iter->second; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CAiFuncMap.hpp b/Runtime/World/CAiFuncMap.hpp index 5c77d53eb..53d939215 100644 --- a/Runtime/World/CAiFuncMap.hpp +++ b/Runtime/World/CAiFuncMap.hpp @@ -3,7 +3,7 @@ #include #include -namespace urde { +namespace metaforce { class CAi; class CStateManager; @@ -21,4 +21,4 @@ public: CAiStateFunc GetStateFunc(std::string_view func) const; CAiTriggerFunc GetTriggerFunc(std::string_view func) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CAmbientAI.cpp b/Runtime/World/CAmbientAI.cpp index 81f77c1da..b614e6049 100644 --- a/Runtime/World/CAmbientAI.cpp +++ b/Runtime/World/CAmbientAI.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CAmbientAI::CAmbientAI(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const zeus::CAABox& aabox, const CMaterialList& matList, float mass, @@ -135,4 +135,4 @@ void CAmbientAI::RandomizePlaybackRate(CStateManager& mgr) { GetModelData()->GetAnimationData()->MultiplyPlaybackRate(0.4f * mgr.GetActiveRandom()->Float() + 0.8f); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CAmbientAI.hpp b/Runtime/World/CAmbientAI.hpp index 67f799266..30fb4ea9f 100644 --- a/Runtime/World/CAmbientAI.hpp +++ b/Runtime/World/CAmbientAI.hpp @@ -13,7 +13,7 @@ namespace zeus { class CTransform; } -namespace urde { +namespace metaforce { class CAmbientAI : public CPhysicsActor { enum class EAnimationState { Ready, Alert, Impact }; @@ -44,4 +44,4 @@ public: void RandomizePlaybackRate(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CAnimationParameters.hpp b/Runtime/World/CAnimationParameters.hpp index 7cb29aedc..486ca8708 100644 --- a/Runtime/World/CAnimationParameters.hpp +++ b/Runtime/World/CAnimationParameters.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CAnimationParameters { CAssetId x0_ancs; @@ -22,4 +22,4 @@ public: void SetCharacter(u32 charIdx) { x4_charIdx = charIdx; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CDamageInfo.cpp b/Runtime/World/CDamageInfo.cpp index bed1c7d5b..7e7228173 100644 --- a/Runtime/World/CDamageInfo.cpp +++ b/Runtime/World/CDamageInfo.cpp @@ -4,7 +4,7 @@ #include "DataSpec/DNACommon/Tweaks/ITweakPlayerGun.hpp" -namespace urde { +namespace metaforce { CDamageInfo::CDamageInfo(const DataSpec::SShotParam& other) : x0_weaponMode(CWeaponMode(EWeaponType(other.weaponType), other.charged, other.combo, other.instaKill)) @@ -54,4 +54,4 @@ CDamageInfo::CDamageInfo(const CDamageInfo& other, float dt) { x14_knockback = other.x14_knockback; x18_24_noImmunity = true; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CDamageInfo.hpp b/Runtime/World/CDamageInfo.hpp index 15013f24e..40880fd05 100644 --- a/Runtime/World/CDamageInfo.hpp +++ b/Runtime/World/CDamageInfo.hpp @@ -8,7 +8,7 @@ namespace DataSpec { struct SShotParam; } -namespace urde { +namespace metaforce { class CDamageVulnerability; class CDamageInfo { CWeaponMode x0_weaponMode; @@ -67,4 +67,4 @@ public: x14_knockback *= m; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CDamageVulnerability.cpp b/Runtime/World/CDamageVulnerability.cpp index a5f64db54..9027bacbd 100644 --- a/Runtime/World/CDamageVulnerability.cpp +++ b/Runtime/World/CDamageVulnerability.cpp @@ -1,6 +1,6 @@ #include "Runtime/World/CDamageVulnerability.hpp" -namespace urde { +namespace metaforce { const CDamageVulnerability CDamageVulnerability::sNormalVulnerability( EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, @@ -225,4 +225,4 @@ EVulnerability CDamageVulnerability::GetVulnerability(const CWeaponMode& mode, b return vuln; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CDamageVulnerability.hpp b/Runtime/World/CDamageVulnerability.hpp index b73587ad5..8c92526ed 100644 --- a/Runtime/World/CDamageVulnerability.hpp +++ b/Runtime/World/CDamageVulnerability.hpp @@ -3,7 +3,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Weapon/CWeaponMode.hpp" -namespace urde { +namespace metaforce { enum class EVulnerability { Weak, Normal, Deflect, Immune, PassThrough, DirectWeak, DirectNormal, DirectImmune }; enum class EDeflectType { None, One, Two, Three, Four }; @@ -123,4 +123,4 @@ public: static const CDamageVulnerability& ReflectVulnerabilty() { return sReflectVulnerability; } static const CDamageVulnerability& PassThroughVulnerabilty() { return sPassThroughVulnerability; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CDestroyableRock.cpp b/Runtime/World/CDestroyableRock.cpp index 893cd881b..ad8a774d8 100644 --- a/Runtime/World/CDestroyableRock.cpp +++ b/Runtime/World/CDestroyableRock.cpp @@ -3,7 +3,7 @@ #include "Runtime/CPlayerState.hpp" #include "Runtime/CStateManager.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CDestroyableRock::CDestroyableRock(TUniqueId id, bool active, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& modelData, float mass, @@ -22,7 +22,7 @@ CDestroyableRock::CDestroyableRock(TUniqueId id, bool active, std::string_view n CreateShadow(false); } -void CDestroyableRock::Accept(urde::IVisitor& visitor) { visitor.Visit(this); } +void CDestroyableRock::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); } void CDestroyableRock::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) { if (GetActive()) { if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::Thermal) { @@ -60,4 +60,4 @@ void CDestroyableRock::Think(float dt, CStateManager& mgr) { xd0_damageMag = damageMag; CEntity::Think(dt, mgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CDestroyableRock.hpp b/Runtime/World/CDestroyableRock.hpp index b800d7088..8425f1fb7 100644 --- a/Runtime/World/CDestroyableRock.hpp +++ b/Runtime/World/CDestroyableRock.hpp @@ -4,7 +4,7 @@ #include "Runtime/World/CAi.hpp" -namespace urde { +namespace metaforce { class CDestroyableRock : public CAi { @@ -66,4 +66,4 @@ public: void Set_x340(bool v) { x340_ = v; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEffect.cpp b/Runtime/World/CEffect.cpp index 619aa7e80..30e1fbf20 100644 --- a/Runtime/World/CEffect.cpp +++ b/Runtime/World/CEffect.cpp @@ -2,10 +2,10 @@ #include "Runtime/World/CActorParameters.hpp" -namespace urde { +namespace metaforce { CEffect::CEffect(TUniqueId uid, const CEntityInfo& info, bool active, std::string_view name, const zeus::CTransform& xf) : CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic), CActorParameters::None(), kInvalidUniqueId) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEffect.hpp b/Runtime/World/CEffect.hpp index d43df85ee..e1966e2f2 100644 --- a/Runtime/World/CEffect.hpp +++ b/Runtime/World/CEffect.hpp @@ -2,7 +2,7 @@ #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CEffect : public CActor { public: @@ -12,4 +12,4 @@ public: void Render(CStateManager&) override {} }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEnergyDrainSource.cpp b/Runtime/World/CEnergyDrainSource.cpp index dee555c64..15b1a7ae8 100644 --- a/Runtime/World/CEnergyDrainSource.cpp +++ b/Runtime/World/CEnergyDrainSource.cpp @@ -1,7 +1,7 @@ #include "Runtime/World/CEnergyDrainSource.hpp" -namespace urde { +namespace metaforce { CEnergyDrainSource::CEnergyDrainSource(TUniqueId src, float intensity) : x0_source(src), x4_intensity(intensity) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEnergyDrainSource.hpp b/Runtime/World/CEnergyDrainSource.hpp index c71e4713d..ee2e64bbd 100644 --- a/Runtime/World/CEnergyDrainSource.hpp +++ b/Runtime/World/CEnergyDrainSource.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CEnergyDrainSource { TUniqueId x0_source; float x4_intensity; @@ -13,4 +13,4 @@ public: void SetEnergyDrainIntensity(float in) { x4_intensity = in; } float GetEnergyDrainIntensity() const { return x4_intensity; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEntity.cpp b/Runtime/World/CEntity.cpp index 5e5410215..e2cd2a00a 100644 --- a/Runtime/World/CEntity.cpp +++ b/Runtime/World/CEntity.cpp @@ -2,7 +2,7 @@ #include "Runtime/CStateManager.hpp" -namespace urde { +namespace metaforce { const std::vector CEntity::NullConnectionList; CEntity::CEntity(TUniqueId uniqueId, const CEntityInfo& info, bool active, std::string_view name) @@ -49,4 +49,4 @@ void CEntity::SendScriptMsgs(EScriptObjectState state, CStateManager& stateMgr, } } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEntity.hpp b/Runtime/World/CEntity.hpp index 896011002..26e14543d 100644 --- a/Runtime/World/CEntity.hpp +++ b/Runtime/World/CEntity.hpp @@ -7,7 +7,7 @@ #include "Runtime/World/CEntityInfo.hpp" #include "Runtime/World/ScriptObjectSupport.hpp" -namespace urde { +namespace metaforce { class CStateManager; class IVisitor; @@ -61,4 +61,4 @@ public: std::string_view GetName() const { return x10_name; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEntityInfo.hpp b/Runtime/World/CEntityInfo.hpp index abbfc09af..e9740bdf7 100644 --- a/Runtime/World/CEntityInfo.hpp +++ b/Runtime/World/CEntityInfo.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/ScriptObjectSupport.hpp" -namespace urde { +namespace metaforce { struct SConnection { EScriptObjectState x0_state; EScriptObjectMessage x4_msg; @@ -24,4 +24,4 @@ public: std::vector GetConnectionList() const { return x4_conns; } TEditorId GetEditorId() const { return x14_editorId; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEnvFxManager.cpp b/Runtime/World/CEnvFxManager.cpp index 75be08d88..dfc232ec1 100644 --- a/Runtime/World/CEnvFxManager.cpp +++ b/Runtime/World/CEnvFxManager.cpp @@ -17,7 +17,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static rstl::reserved_vector g_SnowForces; @@ -597,4 +597,4 @@ void CEnvFxManager::Initialize() { g_SnowForces.push_back(r.readVec2fBig()); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CEnvFxManager.hpp b/Runtime/World/CEnvFxManager.hpp index 62df540a6..8a1480477 100644 --- a/Runtime/World/CEnvFxManager.hpp +++ b/Runtime/World/CEnvFxManager.hpp @@ -15,7 +15,7 @@ #include "zeus/CTransform.hpp" #include "zeus/CVector2i.hpp" -namespace urde { +namespace metaforce { class CActor; class CStateManager; class CTexture; @@ -144,4 +144,4 @@ public: static void Initialize(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CExplosion.cpp b/Runtime/World/CExplosion.cpp index 6773279b2..2eb3224a8 100644 --- a/Runtime/World/CExplosion.cpp +++ b/Runtime/World/CExplosion.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CExplosion::CExplosion(const TLockedToken& particle, TUniqueId uid, bool active, const CEntityInfo& info, std::string_view name, const zeus::CTransform& xf, u32 flags, @@ -119,4 +119,4 @@ void CExplosion::Render(CStateManager& mgr) { } bool CExplosion::CanRenderUnsorted(const CStateManager&) const { return false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CExplosion.hpp b/Runtime/World/CExplosion.hpp index 36bd81f51..2280234d6 100644 --- a/Runtime/World/CExplosion.hpp +++ b/Runtime/World/CExplosion.hpp @@ -7,7 +7,7 @@ #include "Runtime/Particle/CGenDescription.hpp" #include "Runtime/World/CEffect.hpp" -namespace urde { +namespace metaforce { class CExplosion : public CEffect { std::unique_ptr xe8_particleGen; @@ -38,4 +38,4 @@ public: bool CanRenderUnsorted(const CStateManager&) const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFire.cpp b/Runtime/World/CFire.cpp index 75b8db4df..ac8347a83 100644 --- a/Runtime/World/CFire.cpp +++ b/Runtime/World/CFire.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CFire::CFire(TToken effect, TUniqueId uid, TAreaId aId, bool active, TUniqueId owner, const zeus::CTransform& xf, const CDamageInfo& dInfo, const zeus::CAABox& aabox, const zeus::CVector3f& vec, bool b1, CAssetId visorEffect, bool b2, bool b3, bool b4, float f1, float f2, @@ -101,4 +101,4 @@ void CFire::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) { CActor::AddToRenderer(frustum, mgr); } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CFire.hpp b/Runtime/World/CFire.hpp index 6830e638d..c55955d38 100644 --- a/Runtime/World/CFire.hpp +++ b/Runtime/World/CFire.hpp @@ -6,7 +6,7 @@ #include "Runtime/World/CActor.hpp" #include "Runtime/World/CDamageInfo.hpp" -namespace urde { +namespace metaforce { class CElementGen; class CFire : public CActor { std::unique_ptr xe8_; @@ -45,4 +45,4 @@ public: void Touch(CActor&, CStateManager&) override; void AddToRenderer(const zeus::CFrustum&, CStateManager&) override; }; -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CFishCloud.cpp b/Runtime/World/CFishCloud.cpp index 125a2f7ad..e5175a55a 100644 --- a/Runtime/World/CFishCloud.cpp +++ b/Runtime/World/CFishCloud.cpp @@ -13,7 +13,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CFishCloud::CFishCloud(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& scale, const zeus::CTransform& xf, CModelData&& mData, @@ -782,4 +782,4 @@ bool CFishCloud::AddAttractor(TUniqueId sourceId, bool swirl, float radius, floa return false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFishCloud.hpp b/Runtime/World/CFishCloud.hpp index e859d1f50..947d1b53b 100644 --- a/Runtime/World/CFishCloud.hpp +++ b/Runtime/World/CFishCloud.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class CFishCloud : public CActor { class CBoid { @@ -150,4 +150,4 @@ public: bool AddAttractor(TUniqueId source, bool swirl, float radius, float priority); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFishCloudModifier.cpp b/Runtime/World/CFishCloudModifier.cpp index 1d4277659..517bf3489 100644 --- a/Runtime/World/CFishCloudModifier.cpp +++ b/Runtime/World/CFishCloudModifier.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CFishCloudModifier::CFishCloudModifier(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& eInfo, const zeus::CVector3f& pos, bool isRepulsor, bool swirl, float radius, float priority) @@ -55,4 +55,4 @@ void CFishCloudModifier::RemoveSelf(CStateManager& mgr) { } } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFishCloudModifier.hpp b/Runtime/World/CFishCloudModifier.hpp index 0d5efde12..f21b320cb 100644 --- a/Runtime/World/CFishCloudModifier.hpp +++ b/Runtime/World/CFishCloudModifier.hpp @@ -2,7 +2,7 @@ #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CFishCloudModifier : public CActor { float xe8_radius; float xec_priority; @@ -19,4 +19,4 @@ public: void AddSelf(CStateManager&); void RemoveSelf(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidPlane.cpp b/Runtime/World/CFluidPlane.cpp index e9744ac43..47a430a30 100644 --- a/Runtime/World/CFluidPlane.cpp +++ b/Runtime/World/CFluidPlane.cpp @@ -6,7 +6,7 @@ #include "Runtime/World/CRipple.hpp" #include "Runtime/World/CScriptWater.hpp" -namespace urde { +namespace metaforce { CFluidPlane::CFluidPlane(CAssetId texPattern1, CAssetId texPattern2, CAssetId texColor, float alpha, EFluidType fluidType, float rippleIntensity, const CFluidUVMotion& motion) @@ -312,6 +312,7 @@ void CFluidPlane::RenderStripWithRipples(float curY, const Heights& heights, con void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const Heights& heights, const Flags& flags, bool noRipples, bool flagIs1, std::vector& vOut, std::vector& pvOut) { + OPTICK_EVENT(); if (noRipples) { m_shader->bindRegular(); @@ -483,4 +484,4 @@ void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const H } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidPlane.hpp b/Runtime/World/CFluidPlane.hpp index 73eb051d4..753a0df56 100644 --- a/Runtime/World/CFluidPlane.hpp +++ b/Runtime/World/CFluidPlane.hpp @@ -17,7 +17,7 @@ #include #include -namespace urde { +namespace metaforce { class CFluidUVMotion; class CRipple; class CRippleManager; @@ -179,4 +179,4 @@ public: const CTexture& GetTexturePattern2() const { return *x20_texPattern2; } bool HasTexturePattern2() const { return x20_texPattern2.HasReference(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidPlaneCPU.cpp b/Runtime/World/CFluidPlaneCPU.cpp index 5eba767cd..d4fe09a1f 100644 --- a/Runtime/World/CFluidPlaneCPU.cpp +++ b/Runtime/World/CFluidPlaneCPU.cpp @@ -10,7 +10,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { constexpr u32 kTableSize = 2048; CFluidPlaneCPU::CTurbulence::CTurbulence(float speed, float distance, float freqMax, float freqMin, float phaseMax, @@ -129,6 +129,7 @@ CFluidPlaneShader::RenderSetupInfo CFluidPlaneCPU::RenderSetup(const CStateManag const zeus::CTransform& xf, const zeus::CTransform& areaXf, const zeus::CAABox& aabb, const CScriptWater* water) { + OPTICK_EVENT(); CFluidPlaneShader::RenderSetupInfo out; const float uvT = mgr.GetFluidPlaneManager()->GetUVT(); @@ -872,4 +873,4 @@ void CFluidPlaneCPU::Render(const CStateManager& mgr, float alpha, const zeus::C m_shader->doneDrawing(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidPlaneCPU.hpp b/Runtime/World/CFluidPlaneCPU.hpp index b3e53a76c..5d5329f5c 100644 --- a/Runtime/World/CFluidPlaneCPU.hpp +++ b/Runtime/World/CFluidPlaneCPU.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CFluidUVMotion; class CFluidPlaneCPU : public CFluidPlane { @@ -121,4 +121,4 @@ public: bool HasTurbulence() const { return x120_turbulence.HasTurbulence(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidPlaneDoor.cpp b/Runtime/World/CFluidPlaneDoor.cpp index 5cc804d00..fb7e3e2e8 100644 --- a/Runtime/World/CFluidPlaneDoor.cpp +++ b/Runtime/World/CFluidPlaneDoor.cpp @@ -3,7 +3,7 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/World/CFluidPlaneCPU.hpp" -namespace urde { +namespace metaforce { CFluidPlaneDoor::CFluidPlaneDoor(CAssetId patternTex1, CAssetId patternTex2, CAssetId colorTex, float tileSize, u32 tileSubdivisions, EFluidType fluidType, float alpha, @@ -102,4 +102,4 @@ void CFluidPlaneDoor::Render(const CStateManager& mgr, float alpha, const zeus:: m_shader->doneDrawing(); } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CFluidPlaneDoor.hpp b/Runtime/World/CFluidPlaneDoor.hpp index 32ca87014..333c6df41 100644 --- a/Runtime/World/CFluidPlaneDoor.hpp +++ b/Runtime/World/CFluidPlaneDoor.hpp @@ -5,7 +5,7 @@ #include "Runtime/Graphics/Shaders/CFluidPlaneShader.hpp" #include "Runtime/World/CFluidPlane.hpp" -namespace urde { +namespace metaforce { class CFluidPlaneDoor final : public CFluidPlane { float xa0_tileSize; int xa4_tileSubdivisions; @@ -29,4 +29,4 @@ public: u32 gridDimX, u32 gridDimY, const zeus::CVector3f& areaCenter) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidPlaneGPU.cpp b/Runtime/World/CFluidPlaneGPU.cpp index 6495ab4d7..5d53aa0c1 100644 --- a/Runtime/World/CFluidPlaneGPU.cpp +++ b/Runtime/World/CFluidPlaneGPU.cpp @@ -1,6 +1,6 @@ #include "Runtime/World/CFluidPlaneGPU.hpp" -namespace urde { +namespace metaforce { CFluidPlaneGPU::CFluidPlaneGPU(CAssetId texPattern1, CAssetId texPattern2, CAssetId texColor, CAssetId bumpMap, CAssetId envMap, CAssetId envBumpMap, CAssetId lightMap, float unitsPerLightmapTexel, @@ -78,4 +78,4 @@ void CFluidPlaneGPU::RenderStripWithRipples(float curY, const Heights& heights, } } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CFluidPlaneGPU.hpp b/Runtime/World/CFluidPlaneGPU.hpp index b735a1e09..e1f796bd9 100644 --- a/Runtime/World/CFluidPlaneGPU.hpp +++ b/Runtime/World/CFluidPlaneGPU.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CFluidPlaneCPU.hpp" -namespace urde { +namespace metaforce { class CFluidPlaneGPU final : public CFluidPlaneCPU { public: @@ -22,4 +22,4 @@ public: std::vector& pvOut) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidPlaneManager.cpp b/Runtime/World/CFluidPlaneManager.cpp index 48917c26f..186991c71 100644 --- a/Runtime/World/CFluidPlaneManager.cpp +++ b/Runtime/World/CFluidPlaneManager.cpp @@ -4,7 +4,7 @@ #include "Runtime/World/CExplosion.hpp" #include "Runtime/World/CScriptWater.hpp" -namespace urde { +namespace metaforce { CFluidPlaneManager::CFluidProfile CFluidPlaneManager::sProfile = {}; @@ -143,4 +143,4 @@ void CFluidPlaneManager::SetupRippleMap() { } BooTrace); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidPlaneManager.hpp b/Runtime/World/CFluidPlaneManager.hpp index a299693d1..f21b287ea 100644 --- a/Runtime/World/CFluidPlaneManager.hpp +++ b/Runtime/World/CFluidPlaneManager.hpp @@ -6,7 +6,7 @@ #include "hsh/hsh.h" -namespace urde { +namespace metaforce { class CStateManager; class CScriptWater; @@ -63,4 +63,4 @@ public: CRippleManager& RippleManager() { return x0_rippleManager; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidUVMotion.cpp b/Runtime/World/CFluidUVMotion.cpp index 2018038ec..4d8c41345 100644 --- a/Runtime/World/CFluidUVMotion.cpp +++ b/Runtime/World/CFluidUVMotion.cpp @@ -4,7 +4,7 @@ #include -namespace urde { +namespace metaforce { CFluidUVMotion::CFluidUVMotion(float timeToWrap, float orientation, const SFluidLayerMotion& colorLayer, const SFluidLayerMotion& pattern1Layer, const SFluidLayerMotion& pattern2Layer) @@ -61,4 +61,4 @@ CFluidUVMotion::FluidOffsets CFluidUVMotion::CalculateFluidTextureOffset(float t return offsets; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CFluidUVMotion.hpp b/Runtime/World/CFluidUVMotion.hpp index e8d1eb8dd..9de9a079e 100644 --- a/Runtime/World/CFluidUVMotion.hpp +++ b/Runtime/World/CFluidUVMotion.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" -namespace urde { +namespace metaforce { class CFluidUVMotion { public: enum class EFluidUVMotion { @@ -53,4 +53,4 @@ public: // In game binaries this uses an out pointer instead of return by value. FluidOffsets CalculateFluidTextureOffset(float t) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index c8eddf768..002d7a4f9 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -14,7 +14,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static logvisor::Module Log("CGameArea"); @@ -305,16 +305,19 @@ CDummyGameArea::CDummyGameArea(CInputStream& in, int idx, int mlvlVersion) { zeus::CAABox aabb; aabb.readBoundingBoxBig(in); xc_mrea = in.readUint32Big(); - if (mlvlVersion > 15) + if (mlvlVersion > 15) { x10_areaId = in.readUint32Big(); + } else { + x10_areaId = -1; + } u32 attachAreaCount = in.readUint32Big(); x44_attachedAreaIndices.reserve(attachAreaCount); for (u32 i = 0; i < attachAreaCount; ++i) x44_attachedAreaIndices.push_back(in.readUint16Big()); - ::urde::ReadDependencyList(in); - ::urde::ReadDependencyList(in); + ::metaforce::ReadDependencyList(in); + ::metaforce::ReadDependencyList(in); if (mlvlVersion > 13) { u32 depCount = in.readUint32Big(); @@ -332,7 +335,7 @@ std::pair, s32> CDummyGameArea::IGetScriptingMemoryAlways( return GetScriptingMemoryAlways(*this); } -TAreaId CDummyGameArea::IGetAreaId() const { return x10_areaId; } +s32 CDummyGameArea::IGetAreaSaveId() const { return x10_areaId; } CAssetId CDummyGameArea::IGetAreaAssetId() const { return xc_mrea; } @@ -354,9 +357,9 @@ CGameArea::CGameArea(CInputStream& in, int idx, int mlvlVersion) : x4_selfIdx(id x84_mrea = in.readUint32Big(); if (mlvlVersion > 15) - x88_areaId = in.readInt32Big(); + x88_areaId = in.readUint32Big(); else - x88_areaId = -1; + x88_areaId = INT_MAX; const u32 attachedCount = in.readUint32Big(); x8c_attachedAreaIndices.reserve(attachedCount); @@ -364,8 +367,8 @@ CGameArea::CGameArea(CInputStream& in, int idx, int mlvlVersion) : x4_selfIdx(id x8c_attachedAreaIndices.emplace_back(in.readUint16Big()); } - x9c_deps1 = ::urde::ReadDependencyList(in); - xac_deps2 = ::urde::ReadDependencyList(in); + x9c_deps1 = ::metaforce::ReadDependencyList(in); + xac_deps2 = ::metaforce::ReadDependencyList(in); const zeus::CAABox aabb = x6c_aabb.getTransformedAABox(xc_transform); x6c_aabb = aabb; @@ -1191,10 +1194,69 @@ void CGameArea::SetAreaAttributes(const CScriptAreaAttributes* areaAttributes) { x12c_postConstructed->x1128_worldLightingLevel = areaAttributes->GetWorldLightingLevel(); } -bool CGameArea::CAreaObjectList::IsQualified(const CEntity& ent) const { return (ent.GetAreaIdAlways() == x200c_areaIdx); } +bool CGameArea::CAreaObjectList::IsQualified(const CEntity& ent) const { + return (ent.GetAreaIdAlways() == x200c_areaIdx); +} void CGameArea::WarmupShaders(const SObjectTag& mreaTag) { // Calling this version of the constructor performs warmup implicitly [[maybe_unused]] CGameArea area(mreaTag.id); } -} // namespace urde +void CGameArea::DebugDraw() { + if (!m_debugSphereRes) { + const auto* tok = g_ResFactory->GetResourceIdByName("CMDL_DebugSphere"); + if (tok != nullptr && tok->type == FOURCC('CMDL')) { + m_debugSphereRes = CStaticRes(tok->id, zeus::skOne3f); + } + } + + if (m_debugSphereRes && !m_debugSphereModel) { + m_debugSphereModel = std::make_unique(*m_debugSphereRes); + } + + if (!m_debugConeRes) { + const auto* tok = g_ResFactory->GetResourceIdByName("CMDL_DebugLightCone"); + if (tok != nullptr && tok->type == FOURCC('CMDL')) { + m_debugConeRes = CStaticRes(tok->id, zeus::skOne3f); + } + } + + if (m_debugConeRes && !m_debugConeModel) { + m_debugConeModel = std::make_unique(*m_debugConeRes); + } + + if (IsPostConstructed()) { + for (const auto& light : x12c_postConstructed->x70_gfxLightsA) { + DebugDrawLight(light); + } + for (const auto& light : x12c_postConstructed->x90_gfxLightsB) { + DebugDrawLight(light); + } + } +} + +void CGameArea::DebugDrawLight(const CLight& light) { + if (light.GetType() == ELightType::LocalAmbient) { + return; + } + g_Renderer->SetGXRegister1Color(light.GetColor()); + CModelFlags modelFlags; + modelFlags.x0_blendMode = 5; + modelFlags.x4_color = zeus::skWhite; + modelFlags.x4_color.a() = 0.5f; + if ((light.GetType() == ELightType::Spot || light.GetType() == ELightType::Directional) && m_debugConeModel) { + m_debugConeModel->Render(CModelData::EWhichModel::Normal, + zeus::lookAt(light.GetPosition(), light.GetPosition() + light.GetDirection()) * + zeus::CTransform::Scale(zeus::clamp(-90.f, light.GetRadius(), 90.f)), + nullptr, modelFlags); + } else if (m_debugSphereModel) { + m_debugSphereModel->Render(CModelData::EWhichModel::Normal, zeus::CTransform::Translate(light.GetPosition()), + nullptr, modelFlags); + m_debugSphereModel->Render(CModelData::EWhichModel::Normal, + zeus::CTransform::Translate(light.GetPosition()) * + zeus::CTransform::Scale(light.GetRadius()), + nullptr, modelFlags); + } +} + +} // namespace metaforce diff --git a/Runtime/World/CGameArea.hpp b/Runtime/World/CGameArea.hpp index b703991aa..44501fd31 100644 --- a/Runtime/World/CGameArea.hpp +++ b/Runtime/World/CGameArea.hpp @@ -15,7 +15,7 @@ #include "Runtime/World/CPathFindArea.hpp" #include "Runtime/World/CWorldLight.hpp" #include "Runtime/World/IGameArea.hpp" - +#include "Runtime/Character/CModelData.hpp" #include #include @@ -23,7 +23,7 @@ #include #include -namespace urde { +namespace metaforce { class CStateManager; class CScriptAreaAttributes; struct SMREAHeader { @@ -47,7 +47,7 @@ class CDummyGameArea final : public IGameArea { int x4_mlvlVersion; CAssetId x8_nameSTRG; CAssetId xc_mrea; - TAreaId x10_areaId; + s32 x10_areaId; zeus::CTransform x14_transform; std::vector x44_attachedAreaIndices; std::vector x54_docks; @@ -56,7 +56,7 @@ public: CDummyGameArea(CInputStream& in, int idx, int mlvlVersion); std::pair, s32> IGetScriptingMemoryAlways() const override; - TAreaId IGetAreaId() const override; + s32 IGetAreaSaveId() const override; CAssetId IGetAreaAssetId() const override; bool IIsActive() const override; TAreaId IGetAttachedAreaId(int) const override; @@ -268,6 +268,10 @@ private: void UpdateThermalVisor(float dt); void UpdateWeaponWorldLighting(float dt); + std::optional m_debugSphereRes; + std::unique_ptr m_debugSphereModel; + std::optional m_debugConeRes; + std::unique_ptr m_debugConeModel; public: explicit CGameArea(CInputStream& in, int idx, int mlvlVersion); explicit CGameArea(CAssetId mreaId); // Warmup constructor @@ -279,7 +283,7 @@ public: std::pair, s32> IGetScriptingMemoryAlways() const override; TAreaId GetAreaId() const { return x4_selfIdx; } - TAreaId IGetAreaId() const override { return x4_selfIdx; } + s32 IGetAreaSaveId() const override { return x88_areaId; } CAssetId IGetAreaAssetId() const override { return x84_mrea; } bool IIsActive() const override; TAreaId IGetAttachedAreaId(int) const override; @@ -362,8 +366,8 @@ public: CGameArea* GetNext() const { return x130_next; } static void WarmupShaders(const SObjectTag& mreaTag); - - s32 GetAreaSaveId() const { return x88_areaId; } + void DebugDraw(); + void DebugDrawLight(const CLight& light); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CGameLight.cpp b/Runtime/World/CGameLight.cpp index e03019125..2a7cb77fe 100644 --- a/Runtime/World/CGameLight.cpp +++ b/Runtime/World/CGameLight.cpp @@ -2,10 +2,13 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/World/CActorParameters.hpp" +#include "Runtime/GameGlobalObjects.hpp" +#include "Runtime/CSimplePool.hpp" +#include "Graphics/CBooRenderer.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CGameLight::CGameLight(TUniqueId uid, TAreaId aid, bool active, std::string_view name, const zeus::CTransform& xf, TUniqueId parentId, const CLight& light, u32 sourceId, u32 priority, float lifeTime) @@ -53,4 +56,30 @@ CLight CGameLight::GetLight() const { return ret; } -} // namespace urde + +void CGameLight::DebugDraw() { + if (!m_debugRes) { + const auto* tok = (xec_light.GetType() == ELightType::Spot || xec_light.GetType() == ELightType::Directional) + ? g_ResFactory->GetResourceIdByName("CMDL_DebugLightCone") + : g_ResFactory->GetResourceIdByName("CMDL_DebugSphere"); + if (tok != nullptr && tok->type == FOURCC('CMDL')) { + m_debugRes = CStaticRes(tok->id, zeus::skOne3f); + } + } + + if (m_debugRes && !m_debugModel) { + m_debugModel = std::make_unique(*m_debugRes); + } + + if (m_debugModel) { + g_Renderer->SetGXRegister1Color(xec_light.GetColor()); + CModelFlags modelFlags; + modelFlags.x0_blendMode = 5; + modelFlags.x4_color = zeus::skWhite; + modelFlags.x4_color.a() = 0.5f; + m_debugModel->Render(CModelData::EWhichModel::Normal, zeus::CTransform::Translate(xec_light.GetPosition()), nullptr, + modelFlags); + m_debugModel->Render(CModelData::EWhichModel::Normal, x34_transform, nullptr, modelFlags); + } +} +} // namespace metaforce diff --git a/Runtime/World/CGameLight.hpp b/Runtime/World/CGameLight.hpp index d840a8bc9..8da595ec8 100644 --- a/Runtime/World/CGameLight.hpp +++ b/Runtime/World/CGameLight.hpp @@ -6,7 +6,7 @@ #include "Runtime/World/CActor.hpp" #include "Runtime/Graphics/CLight.hpp" -namespace urde { +namespace metaforce { class CGameLight : public CActor { TUniqueId xe8_parentId; CLight xec_light; @@ -14,6 +14,9 @@ class CGameLight : public CActor { u32 x140_priority; float x144_lifeTime; + + std::optional m_debugRes; + std::unique_ptr m_debugModel; public: CGameLight(TUniqueId uid, TAreaId aid, bool active, std::string_view name, const zeus::CTransform& xf, TUniqueId parentId, const CLight& light, u32 sourceId, u32 priority, float lifeTime); @@ -24,5 +27,7 @@ public: void SetLight(const CLight& light); CLight GetLight() const; TUniqueId GetParentId() const { return xe8_parentId; } + + void DebugDraw(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CGrappleParameters.hpp b/Runtime/World/CGrappleParameters.hpp index 18375018c..21df68ecb 100644 --- a/Runtime/World/CGrappleParameters.hpp +++ b/Runtime/World/CGrappleParameters.hpp @@ -1,6 +1,6 @@ #pragma once -namespace urde { +namespace metaforce { class CGrappleParameters { float x0_a; @@ -35,4 +35,4 @@ public: bool GetLockSwingTurn() const { return x2c_lockSwingTurn; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CHUDBillboardEffect.cpp b/Runtime/World/CHUDBillboardEffect.cpp index 450c33192..deb55abc5 100644 --- a/Runtime/World/CHUDBillboardEffect.cpp +++ b/Runtime/World/CHUDBillboardEffect.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { u32 CHUDBillboardEffect::g_IndirectTexturedBillboardCount = 0; u32 CHUDBillboardEffect::g_BillboardCount = 0; @@ -105,4 +105,4 @@ float CHUDBillboardEffect::GetNearClipDistance(CStateManager& mgr) { zeus::CVector3f CHUDBillboardEffect::GetScaleForPOV(CStateManager& mgr) { return {0.155f, 1.f, 0.155f}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CHUDBillboardEffect.hpp b/Runtime/World/CHUDBillboardEffect.hpp index 8b0e77d34..2794491d4 100644 --- a/Runtime/World/CHUDBillboardEffect.hpp +++ b/Runtime/World/CHUDBillboardEffect.hpp @@ -12,7 +12,7 @@ #include -namespace urde { +namespace metaforce { class CGenDescription; class CElectricDescription; @@ -48,4 +48,4 @@ public: static zeus::CVector3f GetScaleForPOV(CStateManager& mgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CHUDMemoParms.hpp b/Runtime/World/CHUDMemoParms.hpp index 761f8a00b..cceac81d7 100644 --- a/Runtime/World/CHUDMemoParms.hpp +++ b/Runtime/World/CHUDMemoParms.hpp @@ -2,7 +2,7 @@ #include "Runtime/IOStreams.hpp" -namespace urde { +namespace metaforce { class CHUDMemoParms { float x0_dispTime = 0.f; @@ -25,4 +25,4 @@ public: bool IsHintMemo() const { return x6_hintMemo; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CHealthInfo.cpp b/Runtime/World/CHealthInfo.cpp index 3a9f93d6f..efee7e7e9 100644 --- a/Runtime/World/CHealthInfo.cpp +++ b/Runtime/World/CHealthInfo.cpp @@ -1,6 +1,6 @@ #include "Runtime/World/CHealthInfo.hpp" -namespace urde { +namespace metaforce { CHealthInfo::CHealthInfo(CInputStream& in) { in.readUint32Big(); @@ -8,4 +8,4 @@ CHealthInfo::CHealthInfo(CInputStream& in) { x4_knockbackResistance = in.readFloatBig(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CHealthInfo.hpp b/Runtime/World/CHealthInfo.hpp index a69b52035..60c9dbd6a 100644 --- a/Runtime/World/CHealthInfo.hpp +++ b/Runtime/World/CHealthInfo.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CHealthInfo { float x0_health; @@ -20,4 +20,4 @@ public: void SetKnockbackResistance(float r) { x4_knockbackResistance = r; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CIceImpact.cpp b/Runtime/World/CIceImpact.cpp index db176105f..703efd104 100644 --- a/Runtime/World/CIceImpact.cpp +++ b/Runtime/World/CIceImpact.cpp @@ -2,7 +2,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CIceImpact::CIceImpact(const TLockedToken& particle, TUniqueId uid, TAreaId aid, bool active, std::string_view name, const zeus::CTransform& xf, u32 flags, const zeus::CVector3f& scale, @@ -11,4 +11,4 @@ CIceImpact::CIceImpact(const TLockedToken& particle, TUniqueId void CIceImpact::Accept(IVisitor& visitor) { visitor.Visit(this); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CIceImpact.hpp b/Runtime/World/CIceImpact.hpp index a746ad7f3..5f9b74a05 100644 --- a/Runtime/World/CIceImpact.hpp +++ b/Runtime/World/CIceImpact.hpp @@ -2,7 +2,7 @@ #include "Runtime/World/CEffect.hpp" -namespace urde { +namespace metaforce { class CIceImpact : public CEffect { public: @@ -12,4 +12,4 @@ public: void Accept(IVisitor& visitor) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CKnockBackController.cpp b/Runtime/World/CKnockBackController.cpp index a46f566ab..ef3fb8338 100644 --- a/Runtime/World/CKnockBackController.cpp +++ b/Runtime/World/CKnockBackController.cpp @@ -4,7 +4,7 @@ #include "Runtime/Character/CPASAnimParmData.hpp" #include "Runtime/World/CPatterned.hpp" -namespace urde { +namespace metaforce { constexpr std::array, 19>, 3> KnockBackParmsTable{{ {{ @@ -494,8 +494,8 @@ void CKnockBackController::DoKnockBackAnimation(const zeus::CVector3f& backVec, break; } case EKnockBackAnimationState::Flinch: { - const std::pair bestAnim = - parent.GetBodyController()->GetPASDatabase().FindBestAnimation(CPASAnimParmData(23), *mgr.GetActiveRandom(), -1); + const std::pair bestAnim = parent.GetBodyController()->GetPASDatabase().FindBestAnimation( + CPASAnimParmData(pas::EAnimationState::AdditiveFlinch), *mgr.GetActiveRandom(), -1); if (bestAnim.first > 0.f) { parent.GetModelData()->GetAnimationData()->AddAdditiveAnimation(bestAnim.second, 1.f, false, true); x64_flinchRemTime = @@ -633,4 +633,4 @@ void CKnockBackController::KnockBack(const zeus::CVector3f& backVec, CStateManag ResetKnockBackImpulse(parent, vec, 2.f); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CKnockBackController.hpp b/Runtime/World/CKnockBackController.hpp index 82a0f500a..adb0fcf03 100644 --- a/Runtime/World/CKnockBackController.hpp +++ b/Runtime/World/CKnockBackController.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class CDamageInfo; class CPatterned; @@ -142,4 +142,4 @@ public: bool TestAvailableState(EKnockBackAnimationState s) const { return x80_availableStates.test(size_t(s)); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CLightParameters.hpp b/Runtime/World/CLightParameters.hpp index 2e4779dfb..f7d1daa7c 100644 --- a/Runtime/World/CLightParameters.hpp +++ b/Runtime/World/CLightParameters.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class CLightParameters { friend class CActor; @@ -95,4 +95,4 @@ public: const zeus::CColor& GetNoLightsAmbient() const { return x18_noLightsAmbient; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CMorphBall.cpp b/Runtime/World/CMorphBall.cpp index 1cb5ed77f..c5834e1a9 100644 --- a/Runtime/World/CMorphBall.cpp +++ b/Runtime/World/CMorphBall.cpp @@ -20,7 +20,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { namespace { float kSpiderBallCollisionRadius; @@ -1951,7 +1951,7 @@ void CMorphBall::CollidedWith(TUniqueId id, const CCollisionInfoList& list, CSta if (wakeMaterial == EMaterialTypes::NoStepLogic) { if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Floor)) { - EMaterialTypes tmpMaterial; + EMaterialTypes tmpMaterial = EMaterialTypes::NoStepLogic; if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Dirt)) { tmpMaterial = EMaterialTypes::Dirt; } else { @@ -2164,12 +2164,11 @@ float CMorphBall::CalculateSurfaceFriction() const { } void CMorphBall::ApplyGravity(const CStateManager& mgr) { - const float mass = x0_player.GetMass(); - const bool hasGravitySuit = mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit); - const bool useWaterGravity = x0_player.CheckSubmerged() && !hasGravitySuit; - const float gravity = useWaterGravity ? g_tweakBall->GetBallWaterGravity() : g_tweakBall->GetBallGravity(); - - x0_player.SetMomentumWR(zeus::CVector3f(0.f, 0.f, gravity * mass)); + if (!x0_player.CheckSubmerged() || mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit)) { + x0_player.SetMomentumWR({0.f, 0.f, x0_player.GetMass() * g_tweakBall->GetBallGravity()}); + } else { + x0_player.SetMomentumWR({0.f, 0.f, x0_player.GetMass() * g_tweakBall->GetBallWaterGravity()}); + } } void CMorphBall::SpinToSpeed(float holdMag, const zeus::CVector3f& torque, float mag) { @@ -2405,4 +2404,4 @@ void CMorphBall::StopEffects() { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CMorphBall.hpp b/Runtime/World/CMorphBall.hpp index 2d66e143c..9dcc70d40 100644 --- a/Runtime/World/CMorphBall.hpp +++ b/Runtime/World/CMorphBall.hpp @@ -17,7 +17,7 @@ #include #include -namespace urde { +namespace metaforce { class CActorLights; class CDamageInfo; class CPlayer; @@ -180,7 +180,7 @@ public: void GetBallContactMaterials() const {} void GetWallBumpCounter() const {} void GetBoostChargeTimer() const {} - bool IsBoosting() const { return false; } + bool IsBoosting() const { return x1de4_24_inBoost; } float GetBallRadius() const; float GetBallTouchRadius() const; float ForwardInput(const CFinalInput& input) const; @@ -291,4 +291,4 @@ public: static const std::array BallAuxGlowColors; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CMorphBallShadow.cpp b/Runtime/World/CMorphBallShadow.cpp index 80603efeb..d7504fc4a 100644 --- a/Runtime/World/CMorphBallShadow.cpp +++ b/Runtime/World/CMorphBallShadow.cpp @@ -7,7 +7,7 @@ #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { +namespace metaforce { void CMorphBallShadow::GatherAreas(const CStateManager& mgr) { x18_areas.clear(); @@ -153,4 +153,4 @@ void CMorphBallShadow::Render(const CStateManager& mgr, float alpha) { g_Renderer->DrawOverlappingWorldModelShadows(alphaVal, x30_worldModelBits, xb8_shadowVolume, alpha); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CMorphBallShadow.hpp b/Runtime/World/CMorphBallShadow.hpp index e1c281c40..9deb7881e 100644 --- a/Runtime/World/CMorphBallShadow.hpp +++ b/Runtime/World/CMorphBallShadow.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CActor; class CGameArea; class CPlayer; @@ -32,4 +32,4 @@ public: void Render(const CStateManager& mgr, float alpha); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPathFindArea.cpp b/Runtime/World/CPathFindArea.cpp index ec3aae84b..131852a14 100644 --- a/Runtime/World/CPathFindArea.cpp +++ b/Runtime/World/CPathFindArea.cpp @@ -3,7 +3,7 @@ #include "Runtime/CToken.hpp" #include "Runtime/IVParamObj.hpp" -namespace urde { +namespace metaforce { static logvisor::Module Log("CPathFindArea"); @@ -265,8 +265,8 @@ bool CPFArea::PathExists(const CPFRegion* r1, const CPFRegion* r2, u32 flags) co return ((x168_connectionsGround[d.quot] >> u32(d.rem)) & 0x1u) != 0; } -CFactoryFnReturn FPathFindAreaFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference*) { +CFactoryFnReturn FPathFindAreaFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference*) { return TToken::GetIObjObjectFor(std::make_unique(std::move(in), len)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPathFindArea.hpp b/Runtime/World/CPathFindArea.hpp index 0f586702d..f96081bd4 100644 --- a/Runtime/World/CPathFindArea.hpp +++ b/Runtime/World/CPathFindArea.hpp @@ -13,7 +13,7 @@ #include #include -namespace urde { +namespace metaforce { class CVParamTransfer; class CObjectReference; @@ -112,6 +112,6 @@ public: bool PathExists(const CPFRegion* r1, const CPFRegion* r2, u32 flags) const; }; -CFactoryFnReturn FPathFindAreaFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const urde::CVParamTransfer& vparms, CObjectReference* selfRef); -} // namespace urde +CFactoryFnReturn FPathFindAreaFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, + const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef); +} // namespace metaforce diff --git a/Runtime/World/CPathFindRegion.cpp b/Runtime/World/CPathFindRegion.cpp index 56f00621c..dc74b710d 100644 --- a/Runtime/World/CPathFindRegion.cpp +++ b/Runtime/World/CPathFindRegion.cpp @@ -2,7 +2,7 @@ #include "Runtime/World/CPathFindArea.hpp" -namespace urde { +namespace metaforce { CPFNode::CPFNode(CMemoryInStream& in) { x0_position.readBig(in); @@ -267,4 +267,4 @@ bool CPFRegion::IsPointInsidePaddedAABox(const zeus::CVector3f& point, float pad point.z() >= x34_aabb.min.z() - padding && point.z() <= x34_aabb.max.z() + padding; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPathFindRegion.hpp b/Runtime/World/CPathFindRegion.hpp index 5bb294f88..226c6d951 100644 --- a/Runtime/World/CPathFindRegion.hpp +++ b/Runtime/World/CPathFindRegion.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CPFArea; class CPFLink; class CPFRegionData; @@ -132,4 +132,4 @@ public: x14_cost = x18_g + x1c_h; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPathFindSearch.cpp b/Runtime/World/CPathFindSearch.cpp index 65620edde..0cc8a912f 100644 --- a/Runtime/World/CPathFindSearch.cpp +++ b/Runtime/World/CPathFindSearch.cpp @@ -2,7 +2,7 @@ #include "Runtime/Graphics/CGraphics.hpp" -namespace urde { +namespace metaforce { CPathFindSearch::CPathFindSearch(CPFArea* area, u32 flags, u32 index, float chRadius, float chHeight) : x0_area(area), xd0_chHeight(chHeight), xd4_chRadius(chRadius), xdc_flags(flags), xe0_indexMask(1u << index) {} @@ -364,4 +364,4 @@ void CPathFindSearch::DebugDraw() { m_viz->Draw(*this); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPathFindSearch.hpp b/Runtime/World/CPathFindSearch.hpp index 2e1fc6418..a9fee0160 100644 --- a/Runtime/World/CPathFindSearch.hpp +++ b/Runtime/World/CPathFindSearch.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class CPathFindSearch; class CPathFindVisualizer { @@ -64,4 +64,4 @@ public: void DebugDraw(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPathFindSpline.cpp b/Runtime/World/CPathFindSpline.cpp index 32680d42e..cae5b49ad 100644 --- a/Runtime/World/CPathFindSpline.cpp +++ b/Runtime/World/CPathFindSpline.cpp @@ -1,6 +1,6 @@ #include "Runtime/World/CPathFindSearch.hpp" -namespace urde { +namespace metaforce { bool CPathFindSearch::SegmentOver(const zeus::CVector3f& p1) const { if (x4_waypoints.size() > 1 && xc8_curWaypoint < x4_waypoints.size() - 1) { @@ -70,4 +70,4 @@ float CPathFindSearch::RemainingPathDistance(const zeus::CVector3f& pos) const { return f31; } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CPatterned.cpp b/Runtime/World/CPatterned.cpp index c27232542..be0a5beac 100644 --- a/Runtime/World/CPatterned.cpp +++ b/Runtime/World/CPatterned.cpp @@ -1,11 +1,9 @@ #include "Runtime/World/CPatterned.hpp" -#include "Runtime/CStateManager.hpp" -#include "Runtime/CSimplePool.hpp" -#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Camera/CFirstPersonCamera.hpp" #include "Runtime/Character/CAnimData.hpp" #include "Runtime/Character/CPASAnimParmData.hpp" +#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Graphics/CSkinnedModel.hpp" #include "Runtime/MP1/World/CMetroid.hpp" #include "Runtime/MP1/World/CSpacePirate.hpp" @@ -21,9 +19,15 @@ #include "Runtime/World/CScriptWaypoint.hpp" #include "Runtime/World/CStateMachine.hpp" -#include "TCastTo.hpp" // Generated file, do not modify include path +#include -namespace urde { +#include "TCastTo.hpp" // Generated file, do not modify include path +#include + +namespace metaforce { +namespace { +hecl::CVar* cv_disableAi = nullptr; +} // namespace constexpr CMaterialList skPatternedGroundMaterialList(EMaterialTypes::Character, EMaterialTypes::Solid, EMaterialTypes::Orbit, EMaterialTypes::GroundCollider, @@ -78,17 +82,21 @@ CPatterned::CPatterned(ECharacter character, TUniqueId uid, std::string_view nam x514_deathExplosionOffset = pInfo.x110_particle1Scale; x540_iceDeathExplosionOffset = pInfo.x124_particle2Scale; - if (pInfo.x11c_particle1.IsValid()) + if (pInfo.x11c_particle1.IsValid()) { x520_deathExplosionParticle = {g_SimplePool->GetObj({FOURCC('PART'), pInfo.x11c_particle1})}; + } - if (pInfo.x120_electric.IsValid()) + if (pInfo.x120_electric.IsValid()) { x530_deathExplosionElectric = {g_SimplePool->GetObj({FOURCC('ELSC'), pInfo.x120_electric})}; + } - if (pInfo.x130_particle2.IsValid()) + if (pInfo.x130_particle2.IsValid()) { x54c_iceDeathExplosionParticle = {g_SimplePool->GetObj({FOURCC('PART'), pInfo.x130_particle2})}; + } - if (x404_contactDamage.GetRadius() > 0.f) + if (x404_contactDamage.GetRadius() > 0.f) { x404_contactDamage.SetRadius(0.f); + } xe6_29_renderParticleDBInside = false; if (x64_modelData) { @@ -97,7 +105,7 @@ CPatterned::CPatterned(ECharacter character, TUniqueId uid, std::string_view nam } } -void CPatterned::Accept(urde::IVisitor& visitor) { visitor.Visit(this); } +void CPatterned::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); } void CPatterned::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { CAi::AcceptScriptMsg(msg, uid, mgr); @@ -115,8 +123,8 @@ void CPatterned::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CState if (HasModelData() && GetModelData()->HasAnimData() && GetModelData()->GetAnimationData()->GetIceModel()) { const auto& baseAABB = GetBaseBoundingBox(); float diagExtent = (baseAABB.max - baseAABB.min).magnitude() * 0.5f; - x510_vertexMorph = std::make_shared(zeus::skRight, zeus::CVector3f{}, diagExtent, - 0.f, *mgr.GetActiveRandom()); + x510_vertexMorph = std::make_shared(zeus::skRight, zeus::CVector3f{}, diagExtent, 0.f, + *mgr.GetActiveRandom()); } xf8_25_angularEnabled = true; @@ -144,8 +152,9 @@ void CPatterned::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CState x3a0_latestLeashPosition = GetTranslation(); break; case EScriptObjectMessage::Deleted: - if (x330_stateMachineState.GetActorState() != nullptr) + if (x330_stateMachineState.GetActorState() != nullptr) { x330_stateMachineState.GetActorState()->CallFunc(mgr, *this, EStateMsg::Deactivate, 0.f); + } break; case EScriptObjectMessage::Damage: { if (TCastToConstPtr proj = mgr.GetObjectById(uid)) { @@ -172,8 +181,9 @@ void CPatterned::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CState } case EScriptObjectMessage::InvulnDamage: { if (TCastToConstPtr proj = mgr.GetObjectById(uid)) { - if (proj->GetOwnerId() == mgr.GetPlayer().GetUniqueId()) + if (proj->GetOwnerId() == mgr.GetPlayer().GetUniqueId()) { x400_24_hitByPlayerProjectile = true; + } } break; } @@ -189,25 +199,32 @@ void CPatterned::MakeThermalColdAndHot() { void CPatterned::UpdateThermalFrozenState(bool thawed) { x402_31_thawed = thawed; - if (x403_24_keepThermalVisorState) + if (x403_24_keepThermalVisorState) { return; + } xe6_27_thermalVisorFlags = u8(thawed ? 2 : 1); } void CPatterned::Think(float dt, CStateManager& mgr) { - if (!GetActive()) + if (!GetActive() || (cv_disableAi != nullptr && cv_disableAi->toBoolean())) { + Stop(); + ClearForcesAndTorques(); return; + } - if (x402_30_updateThermalFrozenState) + if (x402_30_updateThermalFrozenState) { UpdateThermalFrozenState(x450_bodyController->GetPercentageFrozen() == 0.f); + } - if (x64_modelData->GetAnimationData()->GetIceModel()) + if (x64_modelData->GetAnimationData()->GetIceModel()) { x510_vertexMorph->Update(dt); + } if (x402_26_dieIf80PercFrozen) { float froz = x450_bodyController->GetPercentageFrozen(); - if (froz > 0.8f) + if (froz > 0.8f) { x400_29_pendingMassiveFrozenDeath = true; + } } if (!x400_25_alive) { @@ -221,10 +238,11 @@ void CPatterned::Think(float dt, CStateManager& mgr) { } } else { x3e0_xDamageDelay -= dt; - if (x403_26_stateControlledMassiveDeath && x330_stateMachineState.GetName()) { + if (x403_26_stateControlledMassiveDeath && x330_stateMachineState.GetName() != nullptr) { bool isDead = x330_stateMachineState.GetName() == "Dead"sv; - if (isDead && x330_stateMachineState.x8_time > 15.f) + if (isDead && x330_stateMachineState.x8_time > 15.f) { MassiveDeath(mgr); + } } } } @@ -232,22 +250,26 @@ void CPatterned::Think(float dt, CStateManager& mgr) { UpdateAlphaDelta(dt, mgr); x3e4_lastHP = HealthInfo(mgr)->GetHP(); - if (!x330_stateMachineState.x4_state) + if (x330_stateMachineState.x4_state == nullptr) { x330_stateMachineState.SetState(mgr, *this, GetStateMachine(), "Start"sv); + } zeus::CVector3f diffVec = x4e4_latestPredictedTranslation - GetTranslation(); - if (!x328_25_verticalMovement) + if (!x328_25_verticalMovement) { diffVec.z() = 0.f; + } - if (diffVec.magSquared() > (0.1f * dt)) + if (diffVec.magSquared() > (0.1f * dt)) { x4f0_predictedLeashTime += dt; - else + } else { x4f0_predictedLeashTime = 0.f; + } if (x460_knockBackController.x81_26_enableShock) { /* Shock on logical falling edge */ - if (!x401_31_nextPendingShock && x402_24_pendingShock) + if (!x401_31_nextPendingShock && x402_24_pendingShock) { Shock(mgr, 0.5f + mgr.GetActiveRandom()->Range(0.f, 0.5f), 0.2f); + } x402_24_pendingShock = x401_31_nextPendingShock; x401_31_nextPendingShock = false; @@ -274,14 +296,17 @@ void CPatterned::Think(float dt, CStateManager& mgr) { CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {}); } } else { - if (x3ec_pendingFireDamage > 0.f) + if (x3ec_pendingFireDamage > 0.f) { x3ec_pendingFireDamage = 0.f; - if (x450_bodyController->IsFrozen()) + } + if (x450_bodyController->IsFrozen()) { mgr.GetActorModelParticles()->StopThermalHotParticles(*this); + } } - if (x401_27_phazingOut || x401_28_burning) + if (x401_27_phazingOut || x401_28_burning) { x3e8_alphaDelta = -0.33333334f; + } if (x401_30_pendingDeath) { x401_30_pendingDeath = false; @@ -296,51 +321,58 @@ void CPatterned::Think(float dt, CStateManager& mgr) { x434_posDelta = deltas.x0_posDelta; x440_rotDelta = deltas.xc_rotDelta; - if (x403_25_enableStateMachine && x450_bodyController->GetPercentageFrozen() < 1.f) + if (x403_25_enableStateMachine && x450_bodyController->GetPercentageFrozen() < 1.f) { x330_stateMachineState.Update(mgr, *this, thinkDt); + } ThinkAboutMove(thinkDt); x460_knockBackController.Update(thinkDt, mgr, *this); x4e4_latestPredictedTranslation = GetTranslation() + PredictMotion(thinkDt).x0_translation; x328_26_solidCollision = false; - if (x420_curDamageRemTime > 0.f) + if (x420_curDamageRemTime > 0.f) { x420_curDamageRemTime -= dt; + } - if (x401_28_burning && x3f4_burnThinkRateTimer > dt) + if (x401_28_burning && x3f4_burnThinkRateTimer > dt) { x3f4_burnThinkRateTimer -= dt; + } xd0_damageMag = x50c_baseDamageMag; UpdateDamageColor(dt); if (!x450_bodyController->IsFrozen()) { - if (x3a0_latestLeashPosition == zeus::CVector3f()) + if (x3a0_latestLeashPosition == zeus::CVector3f()) { x3a0_latestLeashPosition = GetTranslation(); + } if (x3cc_playerLeashRadius != 0.f) { - zeus::CVector3f diffVec = (GetTranslation() - mgr.GetPlayer().GetTranslation()); - if (diffVec.magSquared() > x3cc_playerLeashRadius * x3cc_playerLeashRadius) + if ((GetTranslation() - mgr.GetPlayer().GetTranslation()).magSquared() > + x3cc_playerLeashRadius * x3cc_playerLeashRadius) { x3d4_curPlayerLeashTime += dt; - else + } else { x3d4_curPlayerLeashTime = 0.f; + } } } else { RemoveEmitter(); } - if (x2f8_waypointPauseRemTime > 0.f) + if (x2f8_waypointPauseRemTime > 0.f) { x2f8_waypointPauseRemTime -= dt; + } } void CPatterned::CollidedWith(TUniqueId other, const CCollisionInfoList& list, CStateManager& mgr) { if (x420_curDamageRemTime <= 0.f) { if (TCastToPtr player = mgr.ObjectById(other)) { - bool jumpOnHead = player->GetTimeSinceJump() < 5.f && list.GetCount() != 0 && - list.Front().GetNormalLeft().z() > 0.707f; + bool jumpOnHead = + player->GetTimeSinceJump() < 5.f && list.GetCount() != 0 && list.Front().GetNormalLeft().z() > 0.707f; if (x400_25_alive || jumpOnHead) { CDamageInfo cDamage = GetContactDamage(); - if (!x400_25_alive || x450_bodyController->IsFrozen()) + if (!x400_25_alive || x450_bodyController->IsFrozen()) { cDamage.SetDamage(0.f); + } if (jumpOnHead) { mgr.ApplyDamage(GetUniqueId(), player->GetUniqueId(), GetUniqueId(), cDamage, CMaterialFilter::skPassEverything, -player->GetVelocity()); @@ -356,10 +388,11 @@ void CPatterned::CollidedWith(TUniqueId other, const CCollisionInfoList& list, C static constexpr CMaterialList testList(EMaterialTypes::Solid, EMaterialTypes::Ceiling, EMaterialTypes::Wall, EMaterialTypes::Floor, EMaterialTypes::Character); for (const CCollisionInfo& info : list) { - if (info.GetMaterialLeft().Intersection(testList)) { + if (info.GetMaterialLeft().Intersection(testList) != 0u) { if (!info.GetMaterialLeft().HasMaterial(EMaterialTypes::Floor)) { - if (!x310_moveVec.isZero() && info.GetNormalLeft().dot(x310_moveVec) >= 0.f) + if (!x310_moveVec.isZero() && info.GetNormalLeft().dot(x310_moveVec) >= 0.f) { continue; + } } else if (!x400_31_isFlyer) { continue; } @@ -371,24 +404,26 @@ void CPatterned::CollidedWith(TUniqueId other, const CCollisionInfoList& list, C } void CPatterned::Touch(CActor& act, CStateManager& mgr) { - if (!x400_25_alive) + if (!x400_25_alive) { return; + } if (TCastToPtr proj = act) { - if (mgr.GetPlayer().GetUniqueId() == proj->GetOwnerId()) + if (mgr.GetPlayer().GetUniqueId() == proj->GetOwnerId()) { x400_24_hitByPlayerProjectile = true; + } } } std::optional CPatterned::GetTouchBounds() const { return GetBoundingBox(); } -bool CPatterned::CanRenderUnsorted(const urde::CStateManager& mgr) const { +bool CPatterned::CanRenderUnsorted(const metaforce::CStateManager& mgr) const { return x64_modelData->GetAnimationData()->GetParticleDB().AreAnySystemsDrawnWithModel() ? false : CActor::CanRenderUnsorted(mgr); } -zeus::CVector3f CPatterned::GetAimPosition(const urde::CStateManager& mgr, float dt) const { +zeus::CVector3f CPatterned::GetAimPosition(const metaforce::CStateManager& mgr, float dt) const { zeus::CVector3f offset; if (dt > 0.f) { offset = PredictMotion(dt).x0_translation; @@ -510,10 +545,11 @@ void CPatterned::KnockBack(const zeus::CVector3f& backVec, CStateManager& mgr, c break; case EKnockBackAnimationFollowUp::ExplodeDeath: Death(mgr, zeus::skZero3f, EScriptObjectState::DeathRattle); - if (GetDeathExplosionParticle() || x530_deathExplosionElectric) + if (GetDeathExplosionParticle() || x530_deathExplosionElectric) { MassiveDeath(mgr); - else if (x450_bodyController->IsFrozen()) + } else if (x450_bodyController->IsFrozen()) { x450_bodyController->FrozenBreakout(); + } break; case EKnockBackAnimationFollowUp::IceDeath: Death(mgr, zeus::skZero3f, EScriptObjectState::DeathRattle); @@ -576,8 +612,9 @@ bool CPatterned::HasAttackPattern(CStateManager& mgr, float arg) { } bool CPatterned::NoPathNodes(CStateManager&, float arg) { - if (CPathFindSearch* search = GetSearchPath()) + if (CPathFindSearch* search = GetSearchPath()) { return search->OnPath(GetTranslation()) != CPathFindSearch::EResult::Success; + } return true; } @@ -585,8 +622,9 @@ constexpr float skActorApproachDistance = 3.f; bool CPatterned::PathShagged(CStateManager&, float arg) { if (CPathFindSearch* search = GetSearchPath()) { - if (search->IsShagged()) + if (search->IsShagged()) { return true; + } if (search->GetCurrentWaypoint() > 0 && x401_24_pathOverCount == 0) { zeus::CVector3f origPoint = GetTranslation() + 0.3f * zeus::skUp; zeus::CVector3f point = origPoint; @@ -598,17 +636,22 @@ bool CPatterned::PathShagged(CStateManager&, float arg) { } bool CPatterned::PathFound(CStateManager&, float arg) { - if (CPathFindSearch* search = GetSearchPath()) - if (!search->IsShagged()) + if (CPathFindSearch* search = GetSearchPath()) { + if (!search->IsShagged()) { return true; + } + } return false; } bool CPatterned::PathOver(CStateManager&, float arg) { - if (CPathFindSearch* search = GetSearchPath()) - if (x328_25_verticalMovement || x328_27_onGround) - if (!search->IsShagged() && search->IsOver()) + if (CPathFindSearch* search = GetSearchPath()) { + if (x328_25_verticalMovement || x328_27_onGround) { + if (!search->IsShagged() && search->IsOver()) { return true; + } + } + } return false; } @@ -638,8 +681,9 @@ bool CPatterned::PlayerSpot(CStateManager& mgr, float arg) { bool CPatterned::SpotPlayer(CStateManager& mgr, float arg) { zeus::CVector3f gunToPlayer = mgr.GetPlayer().GetAimPosition(mgr, 0.f) - GetGunEyePos(); float lookDot = gunToPlayer.dot(x34_transform.basis[1]); - if (lookDot > 0.f) + if (lookDot > 0.f) { return lookDot * lookDot > gunToPlayer.magSquared() * x3c4_detectionAngle; + } return false; } @@ -657,8 +701,9 @@ bool CPatterned::InDetectionRange(CStateManager& mgr, float arg) { const float maxRange = x3bc_detectionRange * x3bc_detectionRange; const float dist = delta.magSquared(); if (dist < maxRange) { - if (x3c0_detectionHeightRange > 0.f) + if (x3c0_detectionHeightRange > 0.f) { return delta.z() * delta.z() < x3c0_detectionHeightRange * x3c0_detectionHeightRange; + } return true; } return false; @@ -680,15 +725,16 @@ bool CPatterned::InRange(CStateManager& mgr, float arg) { bool CPatterned::OffLine(CStateManager&, float arg) { zeus::CVector3f curLine = GetTranslation() - x2ec_reflectedDestPos; zeus::CVector3f pathLine = x2e0_destPos - x2ec_reflectedDestPos; - float distSq; + float distSq = 0.f; if (curLine.dot(pathLine) <= 0.f) { distSq = curLine.magSquared(); } else { pathLine.normalize(); distSq = (curLine - pathLine.dot(curLine) * pathLine).magSquared(); zeus::CVector3f delta = GetTranslation() - x2e0_destPos; - if (pathLine.dot(delta) > 0.f) + if (pathLine.dot(delta) > 0.f) { distSq = delta.magSquared(); + } } return distSq > arg * arg; } @@ -700,10 +746,11 @@ void CPatterned::PathFind(CStateManager& mgr, EStateMsg msg, float dt) { if (search->Search(GetTranslation(), x2e0_destPos) == CPathFindSearch::EResult::Success) { x2ec_reflectedDestPos = GetTranslation(); zeus::CVector3f destPos; - if (search->GetCurrentWaypoint() + 1 < search->GetWaypoints().size()) + if (search->GetCurrentWaypoint() + 1 < search->GetWaypoints().size()) { destPos = search->GetWaypoints()[search->GetCurrentWaypoint() + 1]; - else + } else { destPos = search->GetWaypoints()[search->GetCurrentWaypoint()]; + } SetDestPos(destPos); x328_24_inPosition = false; ApproachDest(mgr); @@ -712,16 +759,18 @@ void CPatterned::PathFind(CStateManager& mgr, EStateMsg msg, float dt) { } case EStateMsg::Update: { if (search->GetCurrentWaypoint() < search->GetWaypoints().size() - 1) { - if (x328_25_verticalMovement || x328_27_onGround) + if (x328_25_verticalMovement || x328_27_onGround) { x401_24_pathOverCount += 1; + } zeus::CVector3f biasedPos = GetTranslation() + 0.3f * zeus::skUp; x2ec_reflectedDestPos = biasedPos - (x2e0_destPos - biasedPos); ApproachDest(mgr); zeus::CVector3f biasedForward = x34_transform.basis[1] * x64_modelData->GetScale().y() + biasedPos; search->GetSplinePointWithLookahead(biasedForward, biasedPos, 3.f * x64_modelData->GetScale().y()); SetDestPos(biasedForward); - if (search->SegmentOver(biasedPos)) + if (search->SegmentOver(biasedPos)) { search->SetCurrentWaypoint(search->GetCurrentWaypoint() + 1); + } } break; } @@ -765,8 +814,9 @@ void CPatterned::TargetPlayer(CStateManager& mgr, EStateMsg msg, float dt) { void CPatterned::TargetPatrol(CStateManager& mgr, EStateMsg msg, float dt) { if (msg == EStateMsg::Activate) { x2dc_destObj = GetWaypointForState(mgr, EScriptObjectState::Patrol, EScriptObjectMessage::Follow); - if (TCastToConstPtr act = mgr.GetObjectById(x2dc_destObj)) + if (TCastToConstPtr act = mgr.GetObjectById(x2dc_destObj)) { SetDestPos(act->GetTranslation()); + } x2ec_reflectedDestPos = GetTranslation(); x328_24_inPosition = false; } @@ -841,18 +891,21 @@ void CPatterned::Patrol(CStateManager& mgr, EStateMsg msg, float dt) { } } } - if (x2dc_destObj == kInvalidUniqueId) + if (x2dc_destObj == kInvalidUniqueId) { x2d8_patrolState = EPatrolState::Done; + } UpdateDest(mgr); ApproachDest(mgr); break; case EPatrolState::Pause: - if (x2f8_waypointPauseRemTime <= 0.f) + if (x2f8_waypointPauseRemTime <= 0.f) { x2d8_patrolState = EPatrolState::Patrol; + } break; case EPatrolState::Done: - if (x2dc_destObj != kInvalidUniqueId) + if (x2dc_destObj != kInvalidUniqueId) { x2d8_patrolState = EPatrolState::Patrol; + } break; default: break; @@ -868,12 +921,13 @@ void CPatterned::Patrol(CStateManager& mgr, EStateMsg msg, float dt) { } void CPatterned::TryCommand(CStateManager& mgr, pas::EAnimationState state, CPatternedTryFunc func, int arg) { - if (state == x450_bodyController->GetCurrentStateId()) + if (state == x450_bodyController->GetCurrentStateId()) { x32c_animState = EAnimState::Repeat; - else if (x32c_animState == EAnimState::Ready) + } else if (x32c_animState == EAnimState::Ready) { (this->*func)(mgr, arg); - else + } else { x32c_animState = EAnimState::Over; + } } void CPatterned::TryLoopReaction(CStateManager& mgr, int arg) { @@ -906,7 +960,7 @@ void CPatterned::TryJump(CStateManager& mgr, int arg) { void CPatterned::TryTurn(CStateManager& mgr, int arg) { x450_bodyController->GetCommandMgr().DeliverCmd( - CBCLocomotionCmd(zeus::skZero3f, (x2e0_destPos - GetTranslation()).normalized(), 1.f)); + CBCLocomotionCmd(zeus::skZero3f, (x2e0_destPos - GetTranslation()).normalized(), 1.f)); } void CPatterned::TryGetUp(CStateManager& mgr, int arg) { @@ -935,8 +989,8 @@ void CPatterned::TryBreakDodge(CStateManager& mgr, int arg) { void CPatterned::TryCover(CStateManager& mgr, int arg) { if (CScriptCoverPoint* cp = GetCoverPoint(mgr, x2dc_destObj)) { - x450_bodyController->GetCommandMgr().DeliverCmd(CBCCoverCmd(pas::ECoverDirection(arg), cp->GetTranslation(), - -cp->GetTransform().basis[1])); + x450_bodyController->GetCommandMgr().DeliverCmd( + CBCCoverCmd(pas::ECoverDirection(arg), cp->GetTranslation(), -cp->GetTransform().basis[1])); } } @@ -952,7 +1006,7 @@ void CPatterned::TryKnockBack_Front(CStateManager& mgr, int arg) { x450_bodyController->GetCommandMgr().DeliverCmd(CBCKnockBackCmd(GetTransform().frontVector(), pas::ESeverity(arg))); } -void CPatterned::TryGenerateDeactivate(urde::CStateManager& mgr, int arg) { +void CPatterned::TryGenerateDeactivate(metaforce::CStateManager& mgr, int arg) { x450_bodyController->GetCommandMgr().DeliverCmd(CBCGenerateCmd(pas::EGenerateType(arg), zeus::skZero3f)); } @@ -960,13 +1014,18 @@ void CPatterned::TryStep(CStateManager& mgr, int arg) { x450_bodyController->GetCommandMgr().DeliverCmd(CBCStepCmd(pas::EStepDirection(arg), pas::EStepType::Normal)); } +void CPatterned::TryScripted(CStateManager& mgr, int arg) { + x450_bodyController->GetCommandMgr().DeliverCmd(CBCScriptedCmd(arg, false, false, 0.f)); +} + void CPatterned::BuildBodyController(EBodyType bodyType) { - if (x450_bodyController) + if (x450_bodyController) { return; + } x450_bodyController = std::make_unique(*this, x3b8_turnSpeed, bodyType); - auto anim = - x450_bodyController->GetPASDatabase().FindBestAnimation(CPASAnimParmData(24, CPASAnimParm::FromEnum(0)), -1); + auto anim = x450_bodyController->GetPASDatabase().FindBestAnimation( + CPASAnimParmData(pas::EAnimationState::AdditiveReaction, CPASAnimParm::FromEnum(0)), -1); x460_knockBackController.x81_26_enableShock = anim.first > 0.f; } @@ -974,17 +1033,17 @@ void CPatterned::GenerateDeathExplosion(CStateManager& mgr) { if (auto particle = GetDeathExplosionParticle()) { zeus::CTransform xf(GetTransform()); xf.origin = GetTransform() * (x64_modelData->GetScale() * x514_deathExplosionOffset); - CExplosion* explo = new CExplosion(*particle, mgr.AllocateUniqueId(), true, - CEntityInfo(GetAreaIdAlways(), CEntity::NullConnectionList), "", xf, 1, - zeus::skOne3f, zeus::skWhite); + auto* explo = new CExplosion(*particle, mgr.AllocateUniqueId(), true, + CEntityInfo(GetAreaIdAlways(), CEntity::NullConnectionList), "", xf, 1, zeus::skOne3f, + zeus::skWhite); mgr.AddObject(explo); } if (x530_deathExplosionElectric) { zeus::CTransform xf(GetTransform()); xf.origin = GetTransform() * (x64_modelData->GetScale() * x514_deathExplosionOffset); - CExplosion* explo = new CExplosion(*x530_deathExplosionElectric, mgr.AllocateUniqueId(), true, - CEntityInfo(GetAreaIdAlways(), CEntity::NullConnectionList), "", xf, 1, - zeus::skOne3f, zeus::skWhite); + auto* explo = new CExplosion(*x530_deathExplosionElectric, mgr.AllocateUniqueId(), true, + CEntityInfo(GetAreaIdAlways(), CEntity::NullConnectionList), "", xf, 1, zeus::skOne3f, + zeus::skWhite); mgr.AddObject(explo); } } @@ -1003,24 +1062,25 @@ void CPatterned::GenerateIceDeathExplosion(CStateManager& mgr) { if (x54c_iceDeathExplosionParticle) { zeus::CTransform xf(GetTransform()); xf.origin = GetTransform() * (x64_modelData->GetScale() * x540_iceDeathExplosionOffset); - CExplosion* explo = new CExplosion(*x54c_iceDeathExplosionParticle, mgr.AllocateUniqueId(), true, - CEntityInfo(GetAreaIdAlways(), CEntity::NullConnectionList), "", xf, 1, - zeus::skOne3f, zeus::skWhite); + auto* explo = new CExplosion(*x54c_iceDeathExplosionParticle, mgr.AllocateUniqueId(), true, + CEntityInfo(GetAreaIdAlways(), CEntity::NullConnectionList), "", xf, 1, zeus::skOne3f, + zeus::skWhite); mgr.AddObject(explo); } } void CPatterned::MassiveFrozenDeath(CStateManager& mgr) { - if (x458_iceShatterSfx == 0xffff) + if (x458_iceShatterSfx == 0xffff) { x458_iceShatterSfx = x454_deathSfx; - CSfxManager::AddEmitter(x458_iceShatterSfx, GetTranslation(), zeus::skZero3f, true, false, 0x7f, - kInvalidAreaId); + } + CSfxManager::AddEmitter(x458_iceShatterSfx, GetTranslation(), zeus::skZero3f, true, false, 0x7f, kInvalidAreaId); SendScriptMsgs(EScriptObjectState::MassiveFrozenDeath, mgr, EScriptObjectMessage::None); GenerateIceDeathExplosion(mgr); float toPlayerDist = (mgr.GetPlayer().GetTranslation() - GetTranslation()).magnitude(); - if (toPlayerDist < 40.f) + if (toPlayerDist < 40.f) { mgr.GetCameraManager()->AddCameraShaker( CCameraShakeData::BuildPatternedExplodeShakeData(GetTranslation(), 0.25f, 0.3f, 40.f), true); + } DeathDelete(mgr); x400_28_pendingMassiveDeath = x400_29_pendingMassiveFrozenDeath = false; } @@ -1057,8 +1117,9 @@ void CPatterned::Shock(CStateManager& mgr, float duration, float damage) { void CPatterned::Freeze(CStateManager& mgr, const zeus::CVector3f& pos, const zeus::CUnitVector3f& dir, float frozenDur) { - if (x402_25_lostMassiveFrozenHP) + if (x402_25_lostMassiveFrozenHP) { x402_26_dieIf80PercFrozen = true; + } bool playSfx = false; if (x450_bodyController->IsFrozen()) { x450_bodyController->Freeze(x460_knockBackController.GetActiveParms().xc_intoFreezeDur, frozenDur, @@ -1067,18 +1128,17 @@ void CPatterned::Freeze(CStateManager& mgr, const zeus::CVector3f& pos, const ze playSfx = true; } else if (!x450_bodyController->IsElectrocuting() && !x450_bodyController->IsOnFire()) { x450_bodyController->Freeze(x4f4_intoFreezeDur, frozenDur, x4f8_outofFreezeDur); - if (x510_vertexMorph) + if (x510_vertexMorph) { x510_vertexMorph->Reset(dir, pos, x4f4_intoFreezeDur); + } playSfx = true; } if (playSfx) { - u16 sfx; - if (x460_knockBackController.GetVariant() != EKnockBackVariant::Small && - CPatterned::CastTo(mgr.GetObjectById(GetUniqueId()))) - sfx = SFXsfx0701; - else - sfx = SFXsfx0708; + u16 sfx = (x460_knockBackController.GetVariant() != EKnockBackVariant::Small && + CPatterned::CastTo(mgr.GetObjectById(GetUniqueId())) != nullptr) + ? SFXsfx0701 + : SFXsfx0708; CSfxManager::AddEmitter(sfx, GetTranslation(), zeus::skZero3f, true, false, 0x7f, kInvalidAreaId); } } @@ -1099,14 +1159,14 @@ void CPatterned::SetupPlayerCollision(bool v) { } CGameProjectile* CPatterned::LaunchProjectile(const zeus::CTransform& gunXf, CStateManager& mgr, int maxAllowed, - EProjectileAttrib attrib, bool playerHoming, - const std::optional>& visorParticle, - u16 visorSfx, bool sendCollideMsg, const zeus::CVector3f& scale) { + EProjectileAttrib attrib, bool playerHoming, + const std::optional>& visorParticle, + u16 visorSfx, bool sendCollideMsg, const zeus::CVector3f& scale) { CProjectileInfo* pInfo = GetProjectileInfo(); - if (pInfo->Token().IsLoaded()) { + if (pInfo && pInfo->Token().IsLoaded()) { if (mgr.CanCreateProjectile(GetUniqueId(), EWeaponType::AI, maxAllowed)) { TUniqueId homingId = playerHoming ? mgr.GetPlayer().GetUniqueId() : kInvalidUniqueId; - CEnergyProjectile* newProjectile = + auto* newProjectile = new CEnergyProjectile(true, pInfo->Token(), EWeaponType::AI, gunXf, EMaterialTypes::Character, pInfo->GetDamage(), mgr.AllocateUniqueId(), GetAreaIdAlways(), GetUniqueId(), homingId, attrib, false, scale, visorParticle, visorSfx, sendCollideMsg); @@ -1173,8 +1233,9 @@ void CPatterned::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, } void CPatterned::UpdateAlphaDelta(float dt, CStateManager& mgr) { - if (x3e8_alphaDelta == 0.f) + if (x3e8_alphaDelta == 0.f) { return; + } float alpha = dt * x3e8_alphaDelta + x42c_color.a(); if (alpha > 1.f) { @@ -1183,8 +1244,9 @@ void CPatterned::UpdateAlphaDelta(float dt, CStateManager& mgr) { } else if (alpha < 0.f) { alpha = 0.f; x3e8_alphaDelta = 0.f; - if (x400_27_fadeToDeath) + if (x400_27_fadeToDeath) { DeathDelete(mgr); + } } x94_simpleShadow->SetUserAlpha(alpha); SetModelAlpha(alpha); @@ -1200,18 +1262,19 @@ void CPatterned::UpdateDamageColor(float dt) { if (x428_damageCooldownTimer > 0.f) { x428_damageCooldownTimer = std::max(0.f, x428_damageCooldownTimer - dt); float alpha = x42c_color.a(); - x42c_color = - zeus::CColor::lerp(zeus::skBlack, x430_damageColor, std::min(x428_damageCooldownTimer / 0.33f, 1.f)); + x42c_color = zeus::CColor::lerp(zeus::skBlack, x430_damageColor, std::min(x428_damageCooldownTimer / 0.33f, 1.f)); x42c_color.a() = alpha; - if (!x450_bodyController->IsFrozen()) + if (!x450_bodyController->IsFrozen()) { xd0_damageMag = x50c_baseDamageMag + x428_damageCooldownTimer; + } } } CScriptCoverPoint* CPatterned::GetCoverPoint(CStateManager& mgr, TUniqueId id) const { if (id != kInvalidUniqueId) { - if (TCastToPtr cp = mgr.ObjectById(id)) + if (TCastToPtr cp = mgr.ObjectById(id)) { return cp.GetPtr(); + } } return nullptr; } @@ -1221,7 +1284,7 @@ void CPatterned::SetCoverPoint(CScriptCoverPoint* cp, TUniqueId& id) { id = cp->GetUniqueId(); } -void CPatterned::ReleaseCoverPoint(CStateManager& mgr, TUniqueId& id) { +void CPatterned::ReleaseCoverPoint(CStateManager& mgr, TUniqueId& id) const { if (CScriptCoverPoint* cp = GetCoverPoint(mgr, id)) { cp->SetInUse(false); id = kInvalidUniqueId; @@ -1234,38 +1297,48 @@ TUniqueId CPatterned::GetWaypointForState(CStateManager& mgr, EScriptObjectState for (const auto& conn : GetConnectionList()) { if (conn.x0_state == state && conn.x4_msg == msg) { TUniqueId id = mgr.GetIdForScript(conn.x8_objId); - if (const CEntity* ent = mgr.GetObjectById(id)) - if (ent->GetActive()) + if (const CEntity* ent = mgr.GetObjectById(id)) { + if (ent->GetActive()) { ids.push_back(id); + } + } } } - if (!ids.empty()) + if (!ids.empty()) { return ids[mgr.GetActiveRandom()->Next() % ids.size()]; + } return kInvalidUniqueId; } void CPatterned::UpdateActorKeyframe(CStateManager& mgr) const { - if (TCastToConstPtr wp = mgr.GetObjectById(x2dc_destObj)) - for (const auto& conn : wp->GetConnectionList()) - if (conn.x0_state == EScriptObjectState::Arrived && conn.x4_msg == EScriptObjectMessage::Action) - if (TCastToPtr kf = mgr.ObjectById(mgr.GetIdForScript(conn.x8_objId))) - if (kf->GetActive() && kf->IsPassive()) + if (TCastToConstPtr wp = mgr.GetObjectById(x2dc_destObj)) { + for (const auto& conn : wp->GetConnectionList()) { + if (conn.x0_state == EScriptObjectState::Arrived && conn.x4_msg == EScriptObjectMessage::Action) { + if (TCastToPtr kf = mgr.ObjectById(mgr.GetIdForScript(conn.x8_objId))) { + if (kf->GetActive() && kf->IsPassive()) { kf->UpdateEntity(GetUniqueId(), mgr); + } + } + } + } + } } pas::EStepDirection CPatterned::GetStepDirection(const zeus::CVector3f& moveVec) const { zeus::CVector3f localMove = x34_transform.transposeRotate(moveVec); float angle = zeus::CVector3f::getAngleDiff(localMove, zeus::skForward); - if (angle < zeus::degToRad(45.f)) + if (angle < zeus::degToRad(45.f)) { return pas::EStepDirection::Forward; - else if (angle > zeus::degToRad(135.f)) + } + if (angle > zeus::degToRad(135.f)) { return pas::EStepDirection::Backward; - else if (localMove.dot(zeus::skRight) > 0.f) + } + if (localMove.dot(zeus::skRight) > 0.f) { return pas::EStepDirection::Right; - else - return pas::EStepDirection::Left; + } + return pas::EStepDirection::Left; } bool CPatterned::IsPatternObstructed(CStateManager& mgr, const zeus::CVector3f& p0, const zeus::CVector3f& p1) const { @@ -1296,9 +1369,9 @@ void CPatterned::UpdateDest(CStateManager& mgr) { if (TCastToConstPtr wp2 = mgr.GetObjectById(x2dc_destObj)) { x3b0_moveSpeed = wp->GetSpeed(); x30c_behaviourOrient = EBehaviourOrient(wp->GetBehaviourOrient()); - if (wp->GetBehaviourModifiers() & 0x2) { + if ((wp->GetBehaviourModifiers() & 0x2) != 0) { x450_bodyController->GetCommandMgr().DeliverCmd(CBCJumpCmd(wp2->GetTranslation(), pas::EJumpType::Normal)); - } else if (wp->GetBehaviourModifiers() & 0x4) { + } else if ((wp->GetBehaviourModifiers() & 0x4) != 0) { TUniqueId wp3Id = wp2->NextWaypoint(mgr); if (wp3Id != kInvalidUniqueId) { if (TCastToConstPtr wp3 = mgr.GetObjectById(wp3Id)) { @@ -1313,9 +1386,11 @@ void CPatterned::UpdateDest(CStateManager& mgr) { } } - if (x2dc_destObj != kInvalidUniqueId) - if (TCastToConstPtr act = mgr.GetObjectById(x2dc_destObj)) + if (x2dc_destObj != kInvalidUniqueId) { + if (TCastToConstPtr act = mgr.GetObjectById(x2dc_destObj)) { SetDestPos(act->GetTranslation()); + } + } } void CPatterned::ApproachDest(CStateManager& mgr) { @@ -1326,23 +1401,26 @@ void CPatterned::ApproachDest(CStateManager& mgr) { faceVec.z() = 0.f; } zeus::CVector3f pathLine = x2e0_destPos - x2ec_reflectedDestPos; - if (pathLine.dot(moveVec) <= 0.f) + if (pathLine.dot(moveVec) <= 0.f) { x328_24_inPosition = true; - else if (moveVec.magSquared() < 3.f * 3.f) + } else if (moveVec.magSquared() < 3.f * 3.f) { moveVec = pathLine; + } if (!x328_24_inPosition) { - if (moveVec.canBeNormalized()) + if (moveVec.canBeNormalized()) { moveVec.normalize(); + } switch (x30c_behaviourOrient) { case EBehaviourOrient::MoveDir: faceVec = moveVec; break; case EBehaviourOrient::Destination: - if (x39c_curPattern && x39c_curPattern < x38c_patterns.size()) { + if (x39c_curPattern != 0u && x39c_curPattern < x38c_patterns.size()) { faceVec = x38c_patterns[x39c_curPattern].GetForward(); } else if (x2dc_destObj != kInvalidUniqueId) { - if (TCastToConstPtr wp = mgr.GetObjectById(x2dc_destObj)) + if (TCastToConstPtr wp = mgr.GetObjectById(x2dc_destObj)) { faceVec = wp->GetTransform().basis[1]; + } } break; default: @@ -1389,10 +1467,11 @@ zeus::CQuaternion CPatterned::FindPatternRotation(const zeus::CVector3f& dir) co dirFlat.normalize(); zeus::CQuaternion q; - if ((wpDeltaFlat - dirFlat).magSquared() > 3.99f) + if ((wpDeltaFlat - dirFlat).magSquared() > 3.99f) { q.rotateZ(zeus::degToRad(180.f)); - else + } else { q = zeus::CQuaternion::shortestRotationArc(wpDeltaFlat, dirFlat); + } if (x328_25_verticalMovement) { q = zeus::CQuaternion::shortestRotationArc( @@ -1431,11 +1510,9 @@ void CPatterned::UpdatePatternDestPos(CStateManager& mgr) { zeus::CVector3f patternDir = FindPatternDir(mgr); SetDestPos(FindPatternRotation(patternDir).transform(x38c_patterns[x39c_curPattern].GetPos())); if (x37c_patternFit == EPatternFit::Zero) { - float magSq; - if (x328_25_verticalMovement) - magSq = patternDir.magSquared() / x368_destWPDelta.magSquared(); - else - magSq = patternDir.toVec2f().magSquared() / x368_destWPDelta.toVec2f().magSquared(); + float magSq = x328_25_verticalMovement + ? patternDir.magSquared() / x368_destWPDelta.magSquared() + : patternDir.toVec2f().magSquared() / x368_destWPDelta.toVec2f().magSquared(); SetDestPos(std::sqrt(magSq) * x2e0_destPos); } } else { @@ -1461,37 +1538,41 @@ void CPatterned::UpdatePatternDestPos(CStateManager& mgr) { void CPatterned::SetupPattern(CStateManager& mgr) { EScriptObjectState state = GetDesiredAttackState(mgr); x2dc_destObj = GetWaypointForState(mgr, state, EScriptObjectMessage::Follow); - if (x2dc_destObj == kInvalidUniqueId && state != EScriptObjectState::Attack) + if (x2dc_destObj == kInvalidUniqueId && state != EScriptObjectState::Attack) { x2dc_destObj = GetWaypointForState(mgr, EScriptObjectState::Attack, EScriptObjectMessage::Follow); + } x38c_patterns.clear(); if (x2dc_destObj != kInvalidUniqueId) { x350_patternStartPos = GetTranslation(); x35c_patternStartPlayerPos = mgr.GetPlayer().GetTranslation(); auto destWPs = GetDestWaypoints(mgr); - if (destWPs.first) { + if (destWPs.first != nullptr) { x374_patternTranslate = EPatternTranslate(destWPs.first->GetPatternTranslate()); x378_patternOrient = EPatternOrient(destWPs.first->GetPatternOrient()); x37c_patternFit = EPatternFit(destWPs.first->GetPatternFit()); - if (destWPs.second) + if (destWPs.second != nullptr) { x368_destWPDelta = destWPs.second->GetTranslation() - destWPs.first->GetTranslation(); - else + } else { x368_destWPDelta = zeus::skZero3f; + } int numPatterns = 0; CScriptWaypoint* curWp = destWPs.first; do { ++numPatterns; curWp = TCastToPtr(mgr.ObjectById(curWp->NextWaypoint(mgr))).GetPtr(); - if (!curWp) + if (curWp == nullptr) { break; + } } while (curWp->GetUniqueId() != destWPs.first->GetUniqueId()); x38c_patterns.reserve(numPatterns); zeus::CVector3f basePos; switch (x374_patternTranslate) { case EPatternTranslate::RelativePlayerStart: - if (destWPs.second) + if (destWPs.second != nullptr) { basePos = destWPs.second->GetTranslation(); + } break; case EPatternTranslate::Absolute: break; @@ -1503,14 +1584,16 @@ void CPatterned::SetupPattern(CStateManager& mgr) { curWp = destWPs.first; do { zeus::CVector3f wpForward = curWp->GetTransform().basis[1]; - if (x368_destWPDelta != zeus::skZero3f) + if (x368_destWPDelta != zeus::skZero3f) { wpForward = FindPatternRotation(FindPatternDir(mgr)).transform(wpForward); + } x38c_patterns.emplace_back(curWp->GetTranslation() - basePos, wpForward, curWp->GetSpeed(), curWp->GetBehaviour(), curWp->GetBehaviourOrient(), curWp->GetBehaviourModifiers(), curWp->GetAnimation()); curWp = TCastToPtr(mgr.ObjectById(curWp->NextWaypoint(mgr))).GetPtr(); - if (!curWp) + if (curWp == nullptr) { break; + } } while (curWp->GetUniqueId() != destWPs.first->GetUniqueId()); } } @@ -1529,12 +1612,13 @@ void CPatterned::SetupPattern(CStateManager& mgr) { EScriptObjectState CPatterned::GetDesiredAttackState(CStateManager& mgr) const { float deltaMagSq = (GetTranslation() - mgr.GetPlayer().GetTranslation()).magSquared(); - if (deltaMagSq < x2fc_minAttackRange * x2fc_minAttackRange) + if (deltaMagSq < x2fc_minAttackRange * x2fc_minAttackRange) { return EScriptObjectState::Retreat; - else if (deltaMagSq > x300_maxAttackRange * x300_maxAttackRange) + } + if (deltaMagSq > x300_maxAttackRange * x300_maxAttackRange) { return EScriptObjectState::CloseIn; - else - return EScriptObjectState::Attack; + } + return EScriptObjectState::Attack; } float CPatterned::GetAnimationDistance(const CPASAnimParmData& data) const { @@ -1551,35 +1635,39 @@ void CPatterned::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) { if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::Thermal) { SetCalculateLighting(false); x90_actorLights->BuildConstantAmbientLighting(zeus::skWhite); - } else + } else { SetCalculateLighting(true); + } zeus::CColor col = x42c_color; u8 alpha = GetModelAlphau8(mgr); - if (x402_27_noXrayModel && mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay) + if (x402_27_noXrayModel && mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay) { alpha = 76; + } if (alpha < 255) { - if (col.r() == 0.f && col.g() == 0.f && col.b() == 0.f) + if (col.r() == 0.f && col.g() == 0.f && col.b() == 0.f) { col = zeus::skWhite; /* Not being damaged */ + } if (x401_29_laggedBurnDeath) { int stripedAlpha = 255; - if (alpha > 127) + if (alpha > 127) { stripedAlpha = (alpha - 128) * 2; - xb4_drawFlags = CModelFlags(3, 0, 3, zeus::CColor(0.f, (stripedAlpha * stripedAlpha) / 65025.f)); + } + xb4_drawFlags = CModelFlags(3, 0, 3, zeus::CColor(0.f, float(stripedAlpha * stripedAlpha) / 65025.f)); } else if (x401_28_burning) { xb4_drawFlags = CModelFlags(5, 0, 3, zeus::CColor(0.f, 1.f)); } else { zeus::CColor col2 = col; - col2.a() = alpha / 255.f; + col2.a() = float(alpha) / 255.f; xb4_drawFlags = CModelFlags(5, 0, 3, col2); } } else { if (col.r() != 0.f || col.g() != 0.f || col.b() != 0.f) { /* Being damaged */ zeus::CColor col2 = col; - col2.a() = alpha / 255.f; + col2.a() = float(alpha) / 255.f; xb4_drawFlags = CModelFlags(2, 0, 3, col2); } else { xb4_drawFlags = CModelFlags(0, 0, 3, zeus::skWhite); @@ -1592,7 +1680,8 @@ void CPatterned::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) { void CPatterned::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) { if (x402_29_drawParticles) { if (x64_modelData && !x64_modelData->IsNull()) { - int mask, target; + int mask = 0; + int target = 0; mgr.GetCharacterRenderMaskAndTarget(x402_31_thawed, mask, target); if (CAnimData* aData = x64_modelData->GetAnimationData()) { aData->GetParticleDB().AddToRendererClippedMasked(frustum, mask, target); @@ -1606,8 +1695,9 @@ void CPatterned::RenderIceModelWithFlags(const CModelFlags& flags) const { CModelFlags useFlags = flags; useFlags.x1_matSetIdx = 0; CAnimData* animData = x64_modelData->GetAnimationData(); - if (CMorphableSkinnedModel* iceModel = animData->GetIceModel().GetObj()) + if (CMorphableSkinnedModel* iceModel = animData->GetIceModel().GetObj()) { animData->Render(*iceModel, useFlags, {*x510_vertexMorph}, iceModel->GetMorphMagnitudes()); + } } void CPatterned::Render(CStateManager& mgr) { @@ -1623,9 +1713,10 @@ void CPatterned::Render(CStateManager& mgr) { if (x401_28_burning) { const CTexture* ashy = mgr.GetActorModelParticles()->GetAshyTexture(*this); u8 alpha = GetModelAlphau8(mgr); - if (ashy && ((!x401_29_laggedBurnDeath && alpha <= 255) || alpha <= 127)) { - if (xe5_31_pointGeneratorParticles) + if (ashy != nullptr && ((!x401_29_laggedBurnDeath && alpha <= 255) || alpha <= 127)) { + if (xe5_31_pointGeneratorParticles) { mgr.SetupParticleHook(*this); + } zeus::CColor addColor; if (x401_29_laggedBurnDeath) { addColor = zeus::skClear; @@ -1633,7 +1724,7 @@ void CPatterned::Render(CStateManager& mgr) { addColor = mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot ? zeus::skWhite : zeus::skBlack; } x64_modelData->DisintegrateDraw(mgr, GetTransform(), *ashy, addColor, - alpha * (x401_29_laggedBurnDeath ? 0.00787402f : 0.00392157f)); + float(alpha) * (x401_29_laggedBurnDeath ? 0.00787402f : 0.00392157f)); if (xe5_31_pointGeneratorParticles) { CSkinnedModel::ClearPointGeneratorFunc(); mgr.GetActorModelParticles()->Render(mgr, *this); @@ -1665,14 +1756,16 @@ void CPatterned::ThinkAboutMove(float dt) { if (doMove && x39c_curPattern < x38c_patterns.size()) { zeus::CVector3f frontVec = GetTransform().frontVector(); zeus::CVector3f x31cCpy = x31c_faceVec; - if (x31c_faceVec.magSquared() > 0.1f) + if (x31c_faceVec.magSquared() > 0.1f) { x31cCpy.normalize(); + } float mag = frontVec.dot(x31cCpy); switch (x3f8_moveState) { case EMoveState::Zero: - if (!x328_26_solidCollision) + if (!x328_26_solidCollision) { break; + } [[fallthrough]]; case EMoveState::One: doMove = false; @@ -1692,8 +1785,9 @@ void CPatterned::ThinkAboutMove(float dt) { x3f8_moveState = EMoveState::Zero; break; } - if (mag > 0.9f) + if (mag > 0.9f) { x3f8_moveState = EMoveState::Four; + } break; case EMoveState::Four: x328_24_inPosition = true; @@ -1707,26 +1801,36 @@ void CPatterned::ThinkAboutMove(float dt) { if (!x401_26_disableMove && doMove) { const CBodyState* state = x450_bodyController->GetBodyStateInfo().GetCurrentState(); - if (state->ApplyAnimationDeltas() && !zeus::close_enough(x2e0_destPos - GetTranslation(), {})) + if (state->ApplyAnimationDeltas() && !zeus::close_enough(x2e0_destPos - GetTranslation(), {})) { MoveToOR((x64_modelData->GetScale() * x434_posDelta) * x55c_moveScale, dt); + } } RotateToOR(x440_rotDelta, dt); } void CPatterned::PhazeOut(CStateManager& mgr) { - if (!x400_27_fadeToDeath) + if (!x400_27_fadeToDeath) { SendScriptMsgs(EScriptObjectState::DeathRattle, mgr, EScriptObjectMessage::None); + } x401_27_phazingOut = true; x450_bodyController->SetPlaybackRate(0.f); x64_modelData->GetAnimationData()->GetParticleDB().SetUpdatesEnabled(false); } bool CPatterned::ApplyBoneTracking() const { - if (x400_25_alive) + if (x400_25_alive) { return x460_knockBackController.GetFlinchRemTime() <= 0.f; + } return false; } -} // namespace urde +void CPatterned::Initialize() { + if (cv_disableAi == nullptr) { + cv_disableAi = hecl::CVarManager::instance()->findOrMakeCVar("disableAi"sv, "Disables AI state machines", false, + hecl::CVar::EFlags::Cheat | hecl::CVar::EFlags::Game); + } +} + +} // namespace metaforce diff --git a/Runtime/World/CPatterned.hpp b/Runtime/World/CPatterned.hpp index 7c2bf7e6f..ad4f2e09c 100644 --- a/Runtime/World/CPatterned.hpp +++ b/Runtime/World/CPatterned.hpp @@ -22,7 +22,7 @@ #define DEFINE_PATTERNED(type) static constexpr ECharacter CharacterType = ECharacter::type #endif -namespace urde { +namespace metaforce { class CPatternedInfo; class CProjectileInfo; class CPathFindSearch; @@ -338,6 +338,7 @@ public: void TryKnockBack_Front(CStateManager& mgr, int arg); void TryGenerateDeactivate(CStateManager& mgr, int arg); void TryStep(CStateManager& mgr, int arg); + void TryScripted(CStateManager& mgr, int arg); virtual bool KnockbackWhenFrozen() const { return true; } virtual void MassiveDeath(CStateManager& mgr); @@ -381,7 +382,7 @@ public: void UpdateDamageColor(float dt); CScriptCoverPoint* GetCoverPoint(CStateManager& mgr, TUniqueId id) const; void SetCoverPoint(CScriptCoverPoint* cp, TUniqueId& id); - void ReleaseCoverPoint(CStateManager& mgr, TUniqueId& id); + void ReleaseCoverPoint(CStateManager& mgr, TUniqueId& id) const; bool MadeSolidCollision() const { return x328_26_solidCollision; } bool IsMakingBigStrike() const { return x402_28_isMakingBigStrike; } @@ -416,6 +417,7 @@ public: return nullptr; } + static void Initialize(); // endregion }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPatternedInfo.cpp b/Runtime/World/CPatternedInfo.cpp index bd10bd176..48052d52a 100644 --- a/Runtime/World/CPatternedInfo.cpp +++ b/Runtime/World/CPatternedInfo.cpp @@ -2,7 +2,7 @@ #include "Runtime/Audio/CSfxManager.hpp" -namespace urde { +namespace metaforce { CPatternedInfo::CPatternedInfo(CInputStream& in, u32 pcount) : x0_mass(in.readFloatBig()) @@ -52,4 +52,4 @@ std::pair CPatternedInfo::HasCorrectParameterCount(CInputStream& in) u32 pcount = in.readUint32Big(); return {(pcount >= 35 && pcount <= 38), pcount}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPatternedInfo.hpp b/Runtime/World/CPatternedInfo.hpp index 2cb0a9b00..050903147 100644 --- a/Runtime/World/CPatternedInfo.hpp +++ b/Runtime/World/CPatternedInfo.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CPatternedInfo { friend class CPatterned; @@ -71,4 +71,4 @@ public: bool GetActive() const { return xf8_active; } void SetActive(bool active) { xf8_active = active; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPhysicsActor.cpp b/Runtime/World/CPhysicsActor.cpp index b894a6b6a..ec0da2d89 100644 --- a/Runtime/World/CPhysicsActor.cpp +++ b/Runtime/World/CPhysicsActor.cpp @@ -2,7 +2,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CPhysicsActor::CPhysicsActor(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CMaterialList& matList, @@ -10,14 +10,13 @@ CPhysicsActor::CPhysicsActor(TUniqueId uid, bool active, std::string_view name, float stepUp, float stepDown) : CActor(uid, active, name, info, xf, std::move(mData), matList, actorParms, kInvalidUniqueId) , xe8_mass(moverData.x30_mass) -, xec_massRecip(moverData.x30_mass <= 0.f ? 1.f : 1.f / moverData.x30_mass) +, xec_massRecip(moverData.x30_mass > 0.f ? 1.f / moverData.x30_mass : 1.f) , x150_momentum(moverData.x18_momentum) , x1a4_baseBoundingBox(box) , x1c0_collisionPrimitive(box, matList) , x1f4_lastNonCollidingState(xf.origin, xf.buildMatrix3f()) , x23c_stepUpHeight(stepUp) , x240_stepDownHeight(stepDown) { - xf8_24_movable = true; SetMass(moverData.x30_mass); MoveCollisionPrimitive(zeus::skZero3f); SetVelocityOR(moverData.x0_velocity); @@ -78,7 +77,7 @@ zeus::CAABox CPhysicsActor::GetMotionVolume(float dt) const { } zeus::CVector3f CPhysicsActor::CalculateNewVelocityWR_UsingImpulses() const { - return x138_velocity + (xec_massRecip * (x168_impulse + x18c_moveImpulse)); + return x138_velocity + xec_massRecip * (x168_impulse + x18c_moveImpulse); } zeus::CAABox CPhysicsActor::GetBoundingBox() const { @@ -92,8 +91,9 @@ void CPhysicsActor::AddMotionState(const CMotionState& mst) { zeus::CNUQuaternion q{x34_transform.buildMatrix3f()}; q += mst.xc_orientation; zeus::CQuaternion quat = zeus::CQuaternion::fromNUQuaternion(q); - //if (TCastToPtr(this)) { - // printf("ADD %f %f %f\n", float(mst.x0_translation.x()), float(mst.x0_translation.y()), float(mst.x0_translation.z())); + // if (TCastToPtr(this)) { + // printf("ADD %f %f %f\n", float(mst.x0_translation.x()), float(mst.x0_translation.y()), + // float(mst.x0_translation.z())); //} SetTransform(zeus::CTransform(quat, x34_transform.origin)); @@ -132,7 +132,7 @@ void CPhysicsActor::SetMass(float mass) { tensor = 1.0f / mass; xec_massRecip = tensor; - SetInertiaTensorScalar(mass / 6.f); + SetInertiaTensorScalar(0.16666667f * mass); } void CPhysicsActor::SetAngularVelocityOR(const zeus::CAxisAngle& angVel) { @@ -177,11 +177,11 @@ void CPhysicsActor::MoveToOR(const zeus::CVector3f& trans, float d) { } void CPhysicsActor::MoveToInOneFrameWR(const zeus::CVector3f& trans, float d) { - x18c_moveImpulse += xe8_mass * (trans - x34_transform.origin) * (1.f / d); + x18c_moveImpulse += (1.f / d) * xe8_mass * (trans - x34_transform.origin); } void CPhysicsActor::MoveToWR(const zeus::CVector3f& trans, float d) { - xfc_constantForce = xe8_mass * (trans - x34_transform.origin) * (1.f / d); + xfc_constantForce = (1.f / d) * xe8_mass * (trans - x34_transform.origin); ComputeDerivedQuantities(); } @@ -193,7 +193,7 @@ zeus::CAxisAngle CPhysicsActor::GetRotateToORAngularMomentumWR(const zeus::CQuat } zeus::CVector3f CPhysicsActor::GetMoveToORImpulseWR(const zeus::CVector3f& trans, float d) const { - return (xe8_mass * x34_transform.rotate(trans)) * (1.f / d); + return (1.f / d) * xe8_mass * x34_transform.rotate(trans); } void CPhysicsActor::ClearImpulses() { @@ -220,10 +220,8 @@ void CPhysicsActor::ComputeDerivedQuantities() { } bool CPhysicsActor::WillMove(const CStateManager&) const { - return !zeus::close_enough(zeus::skZero3f, x138_velocity) || - !zeus::close_enough(zeus::skZero3f, x168_impulse) || - !zeus::close_enough(zeus::skZero3f, x174_torque) || - !zeus::close_enough(zeus::skZero3f, x18c_moveImpulse) || + return !zeus::close_enough(zeus::skZero3f, x138_velocity) || !zeus::close_enough(zeus::skZero3f, x168_impulse) || + !zeus::close_enough(zeus::skZero3f, x174_torque) || !zeus::close_enough(zeus::skZero3f, x18c_moveImpulse) || !zeus::close_enough(zeus::skZero3f, x144_angularVelocity) || !zeus::close_enough(zeus::skZero3f, x180_angularImpulse) || !zeus::close_enough(zeus::skZero3f, x198_moveAngularImpulse) || @@ -269,17 +267,15 @@ CMotionState CPhysicsActor::PredictMotion(float dt) const { CMotionState CPhysicsActor::PredictLinearMotion(float dt) const { zeus::CVector3f velocity = CalculateNewVelocityWR_UsingImpulses(); - return {velocity * dt, - {0.f, zeus::skZero3f}, - ((x15c_force + x150_momentum) * dt) + x168_impulse, + return {dt * velocity, zeus::CNUQuaternion(0.f, zeus::skZero3f), (dt * (x15c_force + x150_momentum)) + x168_impulse, zeus::CAxisAngle()}; } CMotionState CPhysicsActor::PredictAngularMotion(float dt) const { const zeus::CVector3f v1 = xf4_inertiaTensorRecip * (x180_angularImpulse + x198_moveAngularImpulse); zeus::CNUQuaternion q = 0.5f * zeus::CNUQuaternion(0.f, x144_angularVelocity.getVector() + v1); - CMotionState ret = {zeus::skZero3f, (q * zeus::CNUQuaternion(x34_transform.buildMatrix3f())) * dt, - zeus::skZero3f, (x174_torque * dt) + x180_angularImpulse}; + CMotionState ret = {zeus::skZero3f, (q * zeus::CNUQuaternion(x34_transform.buildMatrix3f())) * dt, zeus::skZero3f, + (x174_torque * dt) + x180_angularImpulse}; return ret; } @@ -314,4 +310,4 @@ void CPhysicsActor::UseCollisionImpulses() { ComputeDerivedQuantities(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPhysicsActor.hpp b/Runtime/World/CPhysicsActor.hpp index 887ae123c..b4daaba05 100644 --- a/Runtime/World/CPhysicsActor.hpp +++ b/Runtime/World/CPhysicsActor.hpp @@ -10,7 +10,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollisionInfoList; struct SMoverData; @@ -81,15 +81,10 @@ class CPhysicsActor : public CActor { protected: float xe8_mass; float xec_massRecip; - float xf0_inertiaTensor; - float xf4_inertiaTensorRecip; - union { - struct { - bool xf8_24_movable : 1; - bool xf8_25_angularEnabled : 1; - }; - u8 _dummy = 0; - }; + float xf0_inertiaTensor = 0.f; + float xf4_inertiaTensorRecip = 0.f; + bool xf8_24_movable : 1 = true; + bool xf8_25_angularEnabled : 1 = false; bool xf9_standardCollider = false; zeus::CVector3f xfc_constantForce; zeus::CAxisAngle x108_angularMomentum; @@ -214,4 +209,4 @@ public: void UseCollisionImpulses(); static constexpr float GravityConstant() { return 9.81f * 2.5f; } /* 9.81 m/s ^ 2 is normal acceleration under earth gravity, Tallon 4 is 2.5 times that */ }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index 14423b3ea..db5050ec4 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -34,9 +34,9 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { namespace { -logvisor::Module Log("urde::CPlayer"); +logvisor::Module Log("metaforce::CPlayer"); constexpr CMaterialFilter SolidMaterialFilter = CMaterialFilter::MakeInclude(CMaterialList(EMaterialTypes::Solid)); @@ -6265,4 +6265,4 @@ float CPlayer::GetAverageSpeed() const { return x4f8_moveSpeed; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPlayer.hpp b/Runtime/World/CPlayer.hpp index ae73c7955..ea30fe013 100644 --- a/Runtime/World/CPlayer.hpp +++ b/Runtime/World/CPlayer.hpp @@ -14,7 +14,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollidableSphere; class CDamageInfo; class CFirstPersonCamera; @@ -605,6 +605,7 @@ public: bool AttachActorToPlayer(TUniqueId id, bool disableGun); TUniqueId GetAttachedActor() const { return x26c_attachedActor; } float GetAttachedActorStruggle() const { return xa28_attachedActorStruggle; } + void SetFrozenTimeoutBias(float bias) { x758_frozenTimeoutBias = bias; } float GetDistanceUnderWater() const { return x828_distanceUnderWater; } TUniqueId GetRidingPlatformId() const { return x82e_ridingPlatform; } const zeus::CVector3f& GetLastVelocity() const { return x794_lastVelocity; } @@ -620,5 +621,6 @@ public: float GetAverageSpeed() const; bool IsInWaterMovement() const { return x9c4_31_inWaterMovement; } void SetNoDamageLoopSfx(bool val) { x9c7_24_noDamageLoopSfx = val; } + void SetAccelerationChangeTimer(float time) { x2d4_accelerationChangeTimer = time; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPlayerCameraBob.cpp b/Runtime/World/CPlayerCameraBob.cpp index fb38d13e1..84656c2f3 100644 --- a/Runtime/World/CPlayerCameraBob.cpp +++ b/Runtime/World/CPlayerCameraBob.cpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { float CPlayerCameraBob::kCameraBobExtentX = 0.071f; float CPlayerCameraBob::kCameraBobExtentY = 0.142f; float CPlayerCameraBob::kCameraBobPeriod = 0.47f; @@ -226,4 +226,4 @@ void CPlayerCameraBob::ReadTweaks(CInputStream& in) { kGunBobMagnitude = in.readFloatBig(); kHelmetBobMagnitude = in.readFloatBig(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPlayerCameraBob.hpp b/Runtime/World/CPlayerCameraBob.hpp index e8561594e..9122be915 100644 --- a/Runtime/World/CPlayerCameraBob.hpp +++ b/Runtime/World/CPlayerCameraBob.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class CStateManager; class CPlayerCameraBob { @@ -103,4 +103,4 @@ public: zeus::CTransform CalculateCameraBobTransformation() const; static void ReadTweaks(CInputStream& in); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPlayerEnergyDrain.cpp b/Runtime/World/CPlayerEnergyDrain.cpp index 602217c30..d0f284d67 100644 --- a/Runtime/World/CPlayerEnergyDrain.cpp +++ b/Runtime/World/CPlayerEnergyDrain.cpp @@ -4,7 +4,7 @@ #include "Runtime/CStateManager.hpp" -namespace urde { +namespace metaforce { CPlayerEnergyDrain::CPlayerEnergyDrain(u32 numSources) { x0_sources.reserve(numSources); } @@ -35,4 +35,4 @@ void CPlayerEnergyDrain::ProcessEnergyDrain(const CStateManager& mgr, float dt) else x10_energyDrainTime += dt; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CPlayerEnergyDrain.hpp b/Runtime/World/CPlayerEnergyDrain.hpp index 403b71e2c..ab97bfe42 100644 --- a/Runtime/World/CPlayerEnergyDrain.hpp +++ b/Runtime/World/CPlayerEnergyDrain.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CEnergyDrainSource.hpp" -namespace urde { +namespace metaforce { class CStateManager; class CPlayerEnergyDrain { std::vector x0_sources; @@ -20,4 +20,4 @@ public: float GetEnergyDrainTime() const { return x10_energyDrainTime; } void ProcessEnergyDrain(const CStateManager&, float); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CProjectedShadow.cpp b/Runtime/World/CProjectedShadow.cpp index 3ea0d3053..1abaabe93 100644 --- a/Runtime/World/CProjectedShadow.cpp +++ b/Runtime/World/CProjectedShadow.cpp @@ -1,6 +1,6 @@ #include "Runtime/World/CProjectedShadow.hpp" -namespace urde { +namespace metaforce { CProjectedShadow::CProjectedShadow(u32 w, u32 h, bool persistent) : x0_texture(CTexture(ETexelFormat::I4, w, h, 1)), x81_persistent(persistent) {} @@ -11,4 +11,4 @@ void CProjectedShadow::Render(const CStateManager& mgr) {} void CProjectedShadow::RenderShadowBuffer(const CStateManager&, const CModelData&, const zeus::CTransform&, s32, const zeus::CVector3f&, float, float) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CProjectedShadow.hpp b/Runtime/World/CProjectedShadow.hpp index 97977bb76..5bd8f1dd6 100644 --- a/Runtime/World/CProjectedShadow.hpp +++ b/Runtime/World/CProjectedShadow.hpp @@ -6,7 +6,7 @@ #include #include -namespace urde { +namespace metaforce { class CStateManager; class CModelData; class CProjectedShadow { @@ -28,5 +28,6 @@ public: float, float); void Unset_X80() { x80_ = false; } + void Set_x98(float f) { x98_ = f; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CRepulsor.cpp b/Runtime/World/CRepulsor.cpp index 8e8145a36..44d1d44d8 100644 --- a/Runtime/World/CRepulsor.cpp +++ b/Runtime/World/CRepulsor.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CRepulsor::CRepulsor(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& pos, float radius) : CActor(uid, active, name, info, zeus::CTransform::Translate(pos), CModelData::CModelDataNull(), CMaterialList(), @@ -16,4 +16,4 @@ void CRepulsor::Accept(IVisitor& visitor) { visitor.Visit(this); } void CRepulsor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) { CActor::AcceptScriptMsg(msg, objId, stateMgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CRepulsor.hpp b/Runtime/World/CRepulsor.hpp index 58784a52b..4c2e62c8e 100644 --- a/Runtime/World/CRepulsor.hpp +++ b/Runtime/World/CRepulsor.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CRepulsor : public CActor { float xe8_affectRadius; @@ -15,4 +15,4 @@ public: float GetAffectRadius() const { return xe8_affectRadius; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CRipple.cpp b/Runtime/World/CRipple.cpp index 22099bd4b..d24a6818c 100644 --- a/Runtime/World/CRipple.cpp +++ b/Runtime/World/CRipple.cpp @@ -2,7 +2,7 @@ #include "Runtime/CRandom16.hpp" -namespace urde { +namespace metaforce { static CRandom16 sRippleRandom(0xABBA); CRipple::CRipple(TUniqueId id, const zeus::CVector3f& center, float intensity) : x0_id(id), x8_center(center) { @@ -21,4 +21,4 @@ CRipple::CRipple(TUniqueId id, const zeus::CVector3f& center, float intensity) : x34_phase = 1.f / x30_ooPhase; x38_lookupPhase = 256.f * x34_phase; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CRipple.hpp b/Runtime/World/CRipple.hpp index 86be8c647..f9a8aa3e7 100644 --- a/Runtime/World/CRipple.hpp +++ b/Runtime/World/CRipple.hpp @@ -3,7 +3,7 @@ #include "Runtime/RetroTypes.hpp" #include -namespace urde { +namespace metaforce { class CRipple { private: TUniqueId x0_id; @@ -38,4 +38,4 @@ public: float GetPhase() const { return x34_phase; } float GetLookupPhase() const { return x38_lookupPhase; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CRippleManager.cpp b/Runtime/World/CRippleManager.cpp index c86d95a92..76bfd4304 100644 --- a/Runtime/World/CRippleManager.cpp +++ b/Runtime/World/CRippleManager.cpp @@ -1,6 +1,6 @@ #include "Runtime/World/CRippleManager.hpp" -namespace urde { +namespace metaforce { CRippleManager::CRippleManager(int maxRipples, float alpha) : x14_alpha(alpha) { Init(maxRipples); } @@ -42,4 +42,4 @@ void CRippleManager::AddRipple(const CRipple& ripple) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CRippleManager.hpp b/Runtime/World/CRippleManager.hpp index 2de208590..98c4b498a 100644 --- a/Runtime/World/CRippleManager.hpp +++ b/Runtime/World/CRippleManager.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CRipple.hpp" -namespace urde { +namespace metaforce { class CRippleManager { float x0_maxTimeFalloff = 0.f; @@ -26,4 +26,4 @@ public: float GetAlpha() const { return x14_alpha; } }; -}; // namespace urde +}; // namespace metaforce diff --git a/Runtime/World/CScannableParameters.hpp b/Runtime/World/CScannableParameters.hpp index 8977a0e42..48a5f3922 100644 --- a/Runtime/World/CScannableParameters.hpp +++ b/Runtime/World/CScannableParameters.hpp @@ -2,7 +2,7 @@ #include "Runtime/RetroTypes.hpp" -namespace urde { +namespace metaforce { class CScannableParameters { CAssetId x0_scanId; @@ -12,4 +12,4 @@ public: constexpr explicit CScannableParameters(CAssetId id) : x0_scanId(id) {} [[nodiscard]] constexpr CAssetId GetScanId() const { return x0_scanId; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptActor.cpp b/Runtime/World/CScriptActor.cpp index fc1ef8e69..96623ac81 100644 --- a/Runtime/World/CScriptActor.cpp +++ b/Runtime/World/CScriptActor.cpp @@ -14,7 +14,7 @@ #include -namespace urde { +namespace metaforce { CScriptActor::CScriptActor(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const zeus::CAABox& aabb, float mass, float zMomentum, @@ -150,8 +150,10 @@ void CScriptActor::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) if (x2e2_24_noThermalHotZ && xe6_27_thermalVisorFlags == 2) { if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::Thermal) { xb4_drawFlags.x2_flags &= ~3; // Disable Z test/update + xb4_drawFlags.m_noZTest = true; } else { xb4_drawFlags.x2_flags |= 3; // Enable Z test/update + xb4_drawFlags.m_noZTest = false; } } @@ -200,4 +202,4 @@ std::optional CScriptActor::GetTouchBounds() const { void CScriptActor::Touch(CActor&, CStateManager&) { // Empty } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptActor.hpp b/Runtime/World/CScriptActor.hpp index 624244bbc..66baaa46b 100644 --- a/Runtime/World/CScriptActor.hpp +++ b/Runtime/World/CScriptActor.hpp @@ -5,7 +5,7 @@ #include "Runtime/World/CHealthInfo.hpp" #include "Runtime/World/CPhysicsActor.hpp" -namespace urde { +namespace metaforce { class CScriptActor : public CPhysicsActor { protected: @@ -46,4 +46,4 @@ public: CHealthInfo* HealthInfo(CStateManager&) override { return &x260_currentHealth; } bool IsPlayerActor() const { return x2e3_24_isPlayerActor; } }; -}; // namespace urde +}; // namespace metaforce diff --git a/Runtime/World/CScriptActorKeyframe.cpp b/Runtime/World/CScriptActorKeyframe.cpp index 6d3b159e1..262fc047f 100644 --- a/Runtime/World/CScriptActorKeyframe.cpp +++ b/Runtime/World/CScriptActorKeyframe.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptActorKeyframe::CScriptActorKeyframe(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 animId, bool looping, float lifetime, bool isPassive, u32 fadeOut, bool active, float totalPlayback) @@ -128,4 +128,4 @@ void CScriptActorKeyframe::UpdateEntity(TUniqueId uid, CStateManager& mgr) { } } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptActorKeyframe.hpp b/Runtime/World/CScriptActorKeyframe.hpp index 017d0404b..951561f26 100644 --- a/Runtime/World/CScriptActorKeyframe.hpp +++ b/Runtime/World/CScriptActorKeyframe.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptActorKeyframe : public CEntity { private: s32 x34_animationId; @@ -30,4 +30,4 @@ public: bool IsPassive() const { return x44_25_isPassive; } void SetIsPassive(bool b) { x44_25_isPassive = b; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptActorRotate.cpp b/Runtime/World/CScriptActorRotate.cpp index 1f1333cfe..b465461e2 100644 --- a/Runtime/World/CScriptActorRotate.cpp +++ b/Runtime/World/CScriptActorRotate.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptActorRotate::CScriptActorRotate(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& rotation, float maxTime, bool updateActors, bool updateOnCreation, bool active) @@ -44,11 +44,11 @@ void CScriptActorRotate::Think(float dt, CStateManager& mgr) { for (const auto& actorPair : x48_actors) { if (const TCastToPtr act = mgr.ObjectById(actorPair.first)) { - const zeus::CTransform xf = zeus::CTransform::RotateZ(zeus::degToRad(timeOffset * x34_rotation.z())) * + const zeus::CTransform xf = zeus::CTransform::RotateX(zeus::degToRad(timeOffset * x34_rotation.x())) * zeus::CTransform::RotateY(zeus::degToRad(timeOffset * x34_rotation.y())) * - zeus::CTransform::RotateX(zeus::degToRad(timeOffset * x34_rotation.x())); + zeus::CTransform::RotateZ(zeus::degToRad(timeOffset * x34_rotation.z())); zeus::CTransform localRot = actorPair.second * xf; - localRot.origin = act->GetTranslation(); + localRot.origin += act->GetTranslation(); act->SetTransform(localRot); if (const TCastToPtr plat = mgr.ObjectById(actorPair.first)) { @@ -57,8 +57,8 @@ void CScriptActorRotate::Think(float dt, CStateManager& mgr) { } } - if (x58_24_updateRotation) { - if (!x58_25_skipSpiderBallWaypoints) { + if (!x58_24_updateRotation) { + if (x58_25_updateSpiderBallWaypoints) { UpdateSpiderBallWaypoints(mgr); } @@ -82,11 +82,11 @@ void CScriptActorRotate::UpdatePlatformRiders(std::vector& riders, CScr act->SetTransform(rider.x8_transform); act->SetTranslation(act->GetTranslation() + plat.GetTranslation()); - if (x58_24_updateRotation) { + if (!x58_24_updateRotation) { riderXf = {act->GetTransform().basis, act->GetTranslation() - plat.GetTranslation()}; if (TCastToConstPtr(act.GetPtr())) { - x58_25_skipSpiderBallWaypoints = true; + x58_25_updateSpiderBallWaypoints = true; } } @@ -128,22 +128,21 @@ void CScriptActorRotate::UpdateActors(bool next, CStateManager& mgr) { void CScriptActorRotate::UpdateSpiderBallWaypoints(CStateManager& mgr) { rstl::reserved_vector waypointIds; CObjectList& objectList = mgr.GetAllObjectList(); - for (const CEntity* ent : objectList) { - if (const TCastToConstPtr wp = ent) { + for (CEntity* ent : objectList) { + if (const TCastToPtr wp = ent) { waypointIds.push_back(wp->GetUniqueId()); + wp->ClearWaypoints(); } } for (const TUniqueId& uid : waypointIds) { auto* wp = static_cast(mgr.ObjectById(uid)); if (wp) { -#if 0 - wp->sub_801187B4(mgr); - wp->xe4_27_ = true; -#endif + wp->BuildWaypointListAndBounds(mgr); + wp->SetNotInSortedLists(false); } } - x58_25_skipSpiderBallWaypoints = false; + x58_25_updateSpiderBallWaypoints = false; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptActorRotate.hpp b/Runtime/World/CScriptActorRotate.hpp index e5a517ba0..1dc288fd8 100644 --- a/Runtime/World/CScriptActorRotate.hpp +++ b/Runtime/World/CScriptActorRotate.hpp @@ -10,7 +10,7 @@ #include #include -namespace urde { +namespace metaforce { struct SRiders; class CScriptPlatform; class CScriptActorRotate : public CEntity { @@ -19,7 +19,7 @@ class CScriptActorRotate : public CEntity { float x44_currentTime = 0.f; std::map x48_actors; bool x58_24_updateRotation : 1 = false; - bool x58_25_skipSpiderBallWaypoints : 1 = false; + bool x58_25_updateSpiderBallWaypoints : 1 = false; bool x58_26_updateActors : 1; bool x58_27_updateOnCreation : 1; @@ -36,4 +36,4 @@ public: void Think(float, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptAiJumpPoint.cpp b/Runtime/World/CScriptAiJumpPoint.cpp index b54961f39..034c2a276 100644 --- a/Runtime/World/CScriptAiJumpPoint.cpp +++ b/Runtime/World/CScriptAiJumpPoint.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptAiJumpPoint::CScriptAiJumpPoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, zeus::CTransform& xf, bool active, float apex) : CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic), @@ -50,4 +50,4 @@ bool CScriptAiJumpPoint::GetInUse(TUniqueId uid) const { return x108_24_inUse || x110_timeRemaining > 0.f || (x10a_occupant != kInvalidUniqueId && uid != kInvalidUniqueId && x10a_occupant != uid); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptAiJumpPoint.hpp b/Runtime/World/CScriptAiJumpPoint.hpp index 6e4042580..5046f8dd5 100644 --- a/Runtime/World/CScriptAiJumpPoint.hpp +++ b/Runtime/World/CScriptAiJumpPoint.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { class CScriptAiJumpPoint : public CActor { private: float xe8_apex; @@ -32,4 +32,4 @@ public: TUniqueId GetJumpTarget() const { return x10e_nextWaypoint; } float GetJumpApex() const { return xe8_apex; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptAreaAttributes.cpp b/Runtime/World/CScriptAreaAttributes.cpp index 1e9cab788..8f6f64891 100644 --- a/Runtime/World/CScriptAreaAttributes.cpp +++ b/Runtime/World/CScriptAreaAttributes.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptAreaAttributes::CScriptAreaAttributes(TUniqueId uid, const CEntityInfo& info, bool showSkybox, EEnvFxType fxType, float envFxDensity, float thermalHeat, float xrayFogDistance, @@ -44,4 +44,4 @@ void CScriptAreaAttributes::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptAreaAttributes.hpp b/Runtime/World/CScriptAreaAttributes.hpp index 0b15bc880..383449337 100644 --- a/Runtime/World/CScriptAreaAttributes.hpp +++ b/Runtime/World/CScriptAreaAttributes.hpp @@ -3,7 +3,7 @@ #include "Runtime/World/CEntity.hpp" #include "Runtime/World/CEnvFxManager.hpp" -namespace urde { +namespace metaforce { class CScriptAreaAttributes : public CEntity { bool x34_24_showSkybox : 1; EEnvFxType x38_envFx; @@ -32,4 +32,4 @@ public: float GetWorldLightingLevel() const { return x48_worldLightingLevel; } EPhazonType GetPhazonType() const { return x50_phazon; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptBallTrigger.cpp b/Runtime/World/CScriptBallTrigger.cpp index a07ac78a9..162e4ef44 100644 --- a/Runtime/World/CScriptBallTrigger.cpp +++ b/Runtime/World/CScriptBallTrigger.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static zeus::CAABox calculate_ball_aabox() { const float extent = 0.33f * g_tweakPlayer->GetPlayerBallHalfExtent(); @@ -66,7 +66,7 @@ void CScriptBallTrigger::Think(float dt, CStateManager& mgr) { } else { const zeus::CVector3f offset = radiusPosDif.normalized(); if (std::cos(zeus::degToRad(x154_minAngle)) < (-offset).dot(x15c_forceAngle) && distance < x158_maxDistance) { - const float force = zeus::min((1.f / dt * distance), x150_force * (distance * distance)); + const float force = zeus::min((1.f / dt * distance), x150_force * (x158_maxDistance / (distance * distance))); player.ApplyForceWR(force * (player.GetMass() * offset), zeus::CAxisAngle()); } } @@ -94,4 +94,4 @@ void CScriptBallTrigger::InhabitantExited(CActor& act, CStateManager&) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptBallTrigger.hpp b/Runtime/World/CScriptBallTrigger.hpp index aa61d4878..7bb377cac 100644 --- a/Runtime/World/CScriptBallTrigger.hpp +++ b/Runtime/World/CScriptBallTrigger.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CScriptBallTrigger : public CScriptTrigger { float x150_force; float x154_minAngle; @@ -25,4 +25,4 @@ public: void InhabitantAdded(CActor&, CStateManager&) override; void InhabitantExited(CActor&, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptBeam.cpp b/Runtime/World/CScriptBeam.cpp index 6e7e0320b..3c3de9c6a 100644 --- a/Runtime/World/CScriptBeam.cpp +++ b/Runtime/World/CScriptBeam.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptBeam::CScriptBeam(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, const TToken& weaponDesc, const CBeamInfo& bInfo, @@ -54,4 +54,4 @@ void CScriptBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CSt CActor::AcceptScriptMsg(msg, objId, mgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptBeam.hpp b/Runtime/World/CScriptBeam.hpp index 202aab4df..924c0db79 100644 --- a/Runtime/World/CScriptBeam.hpp +++ b/Runtime/World/CScriptBeam.hpp @@ -6,7 +6,7 @@ #include "Runtime/World/CActor.hpp" #include "Runtime/World/CDamageInfo.hpp" -namespace urde { +namespace metaforce { class CWeaponDescription; class CScriptBeam : public CActor { TCachedToken xe8_weaponDescription; @@ -22,4 +22,4 @@ public: void Think(float, CStateManager&) override; void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraBlurKeyframe.cpp b/Runtime/World/CScriptCameraBlurKeyframe.cpp index 51298cdff..7240d4eec 100644 --- a/Runtime/World/CScriptCameraBlurKeyframe.cpp +++ b/Runtime/World/CScriptCameraBlurKeyframe.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptCameraBlurKeyframe::CScriptCameraBlurKeyframe(TUniqueId uid, std::string_view name, const CEntityInfo& info, EBlurType type, float amount, u32 unk, float timeIn, float timeOut, bool active) @@ -36,4 +36,4 @@ void CScriptCameraBlurKeyframe::AcceptScriptMsg(EScriptObjectMessage msg, TUniqu void CScriptCameraBlurKeyframe::Accept(IVisitor& visitor) { visitor.Visit(this); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraBlurKeyframe.hpp b/Runtime/World/CScriptCameraBlurKeyframe.hpp index 2916bd382..672350d04 100644 --- a/Runtime/World/CScriptCameraBlurKeyframe.hpp +++ b/Runtime/World/CScriptCameraBlurKeyframe.hpp @@ -6,7 +6,7 @@ #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptCameraBlurKeyframe : public CEntity { EBlurType x34_type; float x38_amount; @@ -21,4 +21,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; void Accept(IVisitor& visitor) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraFilterKeyframe.cpp b/Runtime/World/CScriptCameraFilterKeyframe.cpp index 14aa52213..2c7397ab8 100644 --- a/Runtime/World/CScriptCameraFilterKeyframe.cpp +++ b/Runtime/World/CScriptCameraFilterKeyframe.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptCameraFilterKeyframe::CScriptCameraFilterKeyframe(TUniqueId uid, std::string_view name, const CEntityInfo& info, EFilterType type, EFilterShape shape, u32 filterIdx, u32 unk, const zeus::CColor& color, float timeIn, float timeOut, @@ -45,4 +45,4 @@ void CScriptCameraFilterKeyframe::AcceptScriptMsg(EScriptObjectMessage msg, TUni void CScriptCameraFilterKeyframe::Accept(IVisitor& visitor) { visitor.Visit(this); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraFilterKeyframe.hpp b/Runtime/World/CScriptCameraFilterKeyframe.hpp index 96e050142..d5f82b3f1 100644 --- a/Runtime/World/CScriptCameraFilterKeyframe.hpp +++ b/Runtime/World/CScriptCameraFilterKeyframe.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CScriptCameraFilterKeyframe : public CEntity { EFilterType x34_type; EFilterShape x38_shape; @@ -27,4 +27,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; void Accept(IVisitor& visitor) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraHint.cpp b/Runtime/World/CScriptCameraHint.cpp index 2ff3b5788..6c5a60887 100644 --- a/Runtime/World/CScriptCameraHint.cpp +++ b/Runtime/World/CScriptCameraHint.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptCameraHint::CScriptCameraHint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, s32 priority, @@ -130,4 +130,4 @@ void CScriptCameraHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId send CActor::AcceptScriptMsg(msg, sender, mgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraHint.hpp b/Runtime/World/CScriptCameraHint.hpp index 3826497da..3b3119e6f 100644 --- a/Runtime/World/CScriptCameraHint.hpp +++ b/Runtime/World/CScriptCameraHint.hpp @@ -10,7 +10,7 @@ #include #include -namespace urde { +namespace metaforce { class CCameraHint { u32 x4_overrideFlags; @@ -110,4 +110,4 @@ public: TUniqueId GetDelegatedCamera() const { return x164_delegatedCamera; } const zeus::CTransform& GetOriginalTransform() const { return x168_origXf; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraHintTrigger.cpp b/Runtime/World/CScriptCameraHintTrigger.cpp index 16345ea11..646329a85 100644 --- a/Runtime/World/CScriptCameraHintTrigger.cpp +++ b/Runtime/World/CScriptCameraHintTrigger.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptCameraHintTrigger::CScriptCameraHintTrigger(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& scale, @@ -60,4 +60,4 @@ std::optional CScriptCameraHintTrigger::GetTouchBounds() const { return {xe8_obb.calculateAABox()}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraHintTrigger.hpp b/Runtime/World/CScriptCameraHintTrigger.hpp index 5001c43ce..63f03050f 100644 --- a/Runtime/World/CScriptCameraHintTrigger.hpp +++ b/Runtime/World/CScriptCameraHintTrigger.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class CScriptCameraHintTrigger : public CActor { zeus::COBBox xe8_obb; zeus::CVector3f x124_scale; @@ -28,4 +28,4 @@ public: void Touch(CActor& other, CStateManager& mgr) override; std::optional GetTouchBounds() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraPitchVolume.cpp b/Runtime/World/CScriptCameraPitchVolume.cpp index 71454cdb3..7fd1c0e79 100644 --- a/Runtime/World/CScriptCameraPitchVolume.cpp +++ b/Runtime/World/CScriptCameraPitchVolume.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { const zeus::CVector3f CScriptCameraPitchVolume::skScaleFactor = zeus::CVector3f(0.5f); CScriptCameraPitchVolume::CScriptCameraPitchVolume(TUniqueId uid, bool active, std::string_view name, @@ -58,7 +58,7 @@ void CScriptCameraPitchVolume::Touch(CActor& act, CStateManager& mgr) { x13c_24_entered = xe8_obbox.AABoxIntersectsBox(plBox.value()); } -void CScriptCameraPitchVolume::Entered(urde::CStateManager& mgr) { +void CScriptCameraPitchVolume::Entered(metaforce::CStateManager& mgr) { x13c_25_occupied = true; mgr.GetCameraManager()->GetFirstPersonCamera()->SetScriptPitchId(GetUniqueId()); } @@ -67,4 +67,4 @@ void CScriptCameraPitchVolume::Exited(CStateManager& mgr) { x13c_25_occupied = false; mgr.GetCameraManager()->GetFirstPersonCamera()->SetScriptPitchId(kInvalidUniqueId); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraPitchVolume.hpp b/Runtime/World/CScriptCameraPitchVolume.hpp index cb92f95da..094b7d6fc 100644 --- a/Runtime/World/CScriptCameraPitchVolume.hpp +++ b/Runtime/World/CScriptCameraPitchVolume.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CScriptCameraPitchVolume : public CActor { static const zeus::CVector3f skScaleFactor; zeus::COBBox xe8_obbox; @@ -35,4 +35,4 @@ public: void Entered(CStateManager&); void Exited(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraShaker.cpp b/Runtime/World/CScriptCameraShaker.cpp index 71aed95da..7717d5828 100644 --- a/Runtime/World/CScriptCameraShaker.cpp +++ b/Runtime/World/CScriptCameraShaker.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptCameraShaker::CScriptCameraShaker(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, const CCameraShakeData& shakeData) @@ -38,4 +38,4 @@ void CScriptCameraShaker::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId ob CEntity::AcceptScriptMsg(msg, objId, stateMgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraShaker.hpp b/Runtime/World/CScriptCameraShaker.hpp index 0c6404201..18df3237f 100644 --- a/Runtime/World/CScriptCameraShaker.hpp +++ b/Runtime/World/CScriptCameraShaker.hpp @@ -5,7 +5,7 @@ #include "Runtime/Camera/CCameraShakeData.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptCameraShaker : public CEntity { CCameraShakeData x34_shakeData; @@ -17,4 +17,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraWaypoint.cpp b/Runtime/World/CScriptCameraWaypoint.cpp index 4ead129db..551ca7486 100644 --- a/Runtime/World/CScriptCameraWaypoint.cpp +++ b/Runtime/World/CScriptCameraWaypoint.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptCameraWaypoint::CScriptCameraWaypoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, float hfov, u32 w1) @@ -39,4 +39,4 @@ TUniqueId CScriptCameraWaypoint::GetRandomNextWaypointId(CStateManager& mgr) con return candidateIds[mgr.GetActiveRandom()->Range(0, s32(candidateIds.size() - 1))]; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCameraWaypoint.hpp b/Runtime/World/CScriptCameraWaypoint.hpp index 014037d73..f76e6a2cb 100644 --- a/Runtime/World/CScriptCameraWaypoint.hpp +++ b/Runtime/World/CScriptCameraWaypoint.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CScriptCameraWaypoint : public CActor { float xe8_hfov; @@ -23,4 +23,4 @@ public: float GetHFov() const { return xe8_hfov; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptColorModulate.cpp b/Runtime/World/CScriptColorModulate.cpp index f43b2355b..6d9092a2c 100644 --- a/Runtime/World/CScriptColorModulate.cpp +++ b/Runtime/World/CScriptColorModulate.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptColorModulate::CScriptColorModulate(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CColor& colorA, const zeus::CColor& colorB, EBlendMode blendMode, float timeA2B, float timeB2A, bool doReverse, bool resetTargetWhenDone, @@ -272,4 +272,4 @@ void CScriptColorModulate::End(CStateManager& stateMgr) { stateMgr.FreeScriptObject(GetUniqueId()); } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptColorModulate.hpp b/Runtime/World/CScriptColorModulate.hpp index 58b1c17db..700cd7c6c 100644 --- a/Runtime/World/CScriptColorModulate.hpp +++ b/Runtime/World/CScriptColorModulate.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { struct CModelFlags; class CScriptColorModulate : public CEntity { @@ -54,4 +54,4 @@ public: static TUniqueId FadeInHelper(CStateManager& mgr, TUniqueId obj, float fadetime); void End(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptControllerAction.cpp b/Runtime/World/CScriptControllerAction.cpp index 6c834f7fa..2be11cedf 100644 --- a/Runtime/World/CScriptControllerAction.cpp +++ b/Runtime/World/CScriptControllerAction.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptControllerAction::CScriptControllerAction(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, ControlMapper::ECommands command, bool mapScreenResponse, @@ -40,4 +40,4 @@ void CScriptControllerAction::Think(float, CStateManager& stateMgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptControllerAction.hpp b/Runtime/World/CScriptControllerAction.hpp index 63351a2e9..0290932b7 100644 --- a/Runtime/World/CScriptControllerAction.hpp +++ b/Runtime/World/CScriptControllerAction.hpp @@ -6,7 +6,7 @@ #include "Runtime/Input/ControlMapper.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptControllerAction : public CEntity { ControlMapper::ECommands x34_command; @@ -22,4 +22,4 @@ public: void Think(float, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCounter.cpp b/Runtime/World/CScriptCounter.cpp index 01fbb569c..a3d0e9420 100644 --- a/Runtime/World/CScriptCounter.cpp +++ b/Runtime/World/CScriptCounter.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptCounter::CScriptCounter(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 initial, s32 max, bool autoReset, bool active) @@ -67,4 +67,4 @@ void CScriptCounter::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CEntity::AcceptScriptMsg(msg, objId, stateMgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCounter.hpp b/Runtime/World/CScriptCounter.hpp index 95ddd2e5d..aa480e9e1 100644 --- a/Runtime/World/CScriptCounter.hpp +++ b/Runtime/World/CScriptCounter.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptCounter : public CEntity { s32 x34_initial; @@ -20,4 +20,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCoverPoint.cpp b/Runtime/World/CScriptCoverPoint.cpp index 398a4f6c4..f5210d578 100644 --- a/Runtime/World/CScriptCoverPoint.cpp +++ b/Runtime/World/CScriptCoverPoint.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptCoverPoint::CScriptCoverPoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, zeus::CTransform xf, bool active, u32 flags, bool crouch, float horizontalAngle, float verticalAngle, float coverTime) @@ -84,4 +84,4 @@ void CScriptCoverPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptCoverPoint.hpp b/Runtime/World/CScriptCoverPoint.hpp index a772e6d1a..ccaade702 100644 --- a/Runtime/World/CScriptCoverPoint.hpp +++ b/Runtime/World/CScriptCoverPoint.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class CScriptCoverPoint : public CActor { bool xe8_26_landHere : 1; bool xe8_27_wallHang : 1; @@ -50,4 +50,4 @@ public: } void Reserve(TUniqueId id) { xfa_occupant = id; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDamageableTrigger.cpp b/Runtime/World/CScriptDamageableTrigger.cpp index d745042a6..07bd9e407 100644 --- a/Runtime/World/CScriptDamageableTrigger.cpp +++ b/Runtime/World/CScriptDamageableTrigger.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static CActorParameters MakeDamageableTriggerActorParms(const CActorParameters& aParams, const CVisorParameters& vParams) { CActorParameters ret = aParams; ret.SetVisorParameters(vParams); @@ -215,4 +215,4 @@ std::optional CScriptDamageableTrigger::GetTouchBounds() const { return std::nullopt; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDamageableTrigger.hpp b/Runtime/World/CScriptDamageableTrigger.hpp index 350611475..fd13900e9 100644 --- a/Runtime/World/CScriptDamageableTrigger.hpp +++ b/Runtime/World/CScriptDamageableTrigger.hpp @@ -13,7 +13,7 @@ #include #include -namespace urde { +namespace metaforce { class CVisorParameters; class CScriptDamageableTrigger : public CActor { @@ -62,4 +62,4 @@ public: void Think(float, CStateManager&) override; std::optional GetTouchBounds() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDebris.cpp b/Runtime/World/CScriptDebris.cpp index f724dd40f..5570c047a 100644 --- a/Runtime/World/CScriptDebris.cpp +++ b/Runtime/World/CScriptDebris.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptDebris::CScriptDebris(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& aParams, CAssetId particleId, @@ -414,4 +414,4 @@ void CScriptDebris::CollidedWith(TUniqueId, const CCollisionInfoList& colList, C } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDebris.hpp b/Runtime/World/CScriptDebris.hpp index 9d44ee853..937841c3b 100644 --- a/Runtime/World/CScriptDebris.hpp +++ b/Runtime/World/CScriptDebris.hpp @@ -10,7 +10,7 @@ #include #include -namespace urde { +namespace metaforce { class CElementGen; class CScriptDebris : public CPhysicsActor { public: @@ -84,4 +84,4 @@ public: void CollidedWith(TUniqueId uid, const CCollisionInfoList&, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDebugCameraWaypoint.cpp b/Runtime/World/CScriptDebugCameraWaypoint.cpp index 47f488e3d..486f9db34 100644 --- a/Runtime/World/CScriptDebugCameraWaypoint.cpp +++ b/Runtime/World/CScriptDebugCameraWaypoint.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptDebugCameraWaypoint::CScriptDebugCameraWaypoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, u32 w1) @@ -14,4 +14,4 @@ CScriptDebugCameraWaypoint::CScriptDebugCameraWaypoint(TUniqueId uid, std::strin void CScriptDebugCameraWaypoint::Accept(IVisitor& visitor) { visitor.Visit(this); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDebugCameraWaypoint.hpp b/Runtime/World/CScriptDebugCameraWaypoint.hpp index 75e9242d6..538c648a4 100644 --- a/Runtime/World/CScriptDebugCameraWaypoint.hpp +++ b/Runtime/World/CScriptDebugCameraWaypoint.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CScriptDebugCameraWaypoint : public CActor { u32 xe8_w1; @@ -17,4 +17,4 @@ public: void Accept(IVisitor&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDistanceFog.cpp b/Runtime/World/CScriptDistanceFog.cpp index 7e2c9ee6b..8606dcf62 100644 --- a/Runtime/World/CScriptDistanceFog.cpp +++ b/Runtime/World/CScriptDistanceFog.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptDistanceFog::CScriptDistanceFog(TUniqueId uid, std::string_view name, const CEntityInfo& info, ERglFogMode mode, const zeus::CColor& color, const zeus::CVector2f& range, float colorDelta, const zeus::CVector2f& rangeDelta, bool expl, bool active, float thermalTarget, @@ -71,4 +71,4 @@ void CScriptDistanceFog::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId obj } } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDistanceFog.hpp b/Runtime/World/CScriptDistanceFog.hpp index 0a58dc5c0..ae967c4b1 100644 --- a/Runtime/World/CScriptDistanceFog.hpp +++ b/Runtime/World/CScriptDistanceFog.hpp @@ -8,7 +8,7 @@ #include #include -namespace urde { +namespace metaforce { class CScriptDistanceFog : public CEntity { ERglFogMode x34_mode; zeus::CColor x38_color; @@ -29,4 +29,4 @@ public: void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDock.cpp b/Runtime/World/CScriptDock.cpp index 0c3d3c6fe..2e8435bef 100644 --- a/Runtime/World/CScriptDock.cpp +++ b/Runtime/World/CScriptDock.cpp @@ -11,7 +11,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { constexpr auto skDockMaterialList = CMaterialList{EMaterialTypes::Trigger, EMaterialTypes::Immovable, EMaterialTypes::AIBlock}; @@ -236,4 +236,4 @@ void CScriptDock::SetLoadConnected(CStateManager& mgr, bool loadOther) { dock->SetShouldLoadOther(dock->GetReferenceCount(), loadOther); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDock.hpp b/Runtime/World/CScriptDock.hpp index dda19d112..083f85fb1 100644 --- a/Runtime/World/CScriptDock.hpp +++ b/Runtime/World/CScriptDock.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CPhysicsActor.hpp" -namespace urde { +namespace metaforce { class CScriptDock : public CPhysicsActor { enum class EDockState { Idle, PlayerTouched, EnterNextArea, Three }; @@ -42,4 +42,4 @@ public: void AreaUnloaded(CStateManager&); void SetLoadConnected(CStateManager&, bool); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDockAreaChange.cpp b/Runtime/World/CScriptDockAreaChange.cpp index b40b26ba4..62deef920 100644 --- a/Runtime/World/CScriptDockAreaChange.cpp +++ b/Runtime/World/CScriptDockAreaChange.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptDockAreaChange::CScriptDockAreaChange(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 w1, bool active) : CEntity(uid, info, active, name), x34_dockReference(w1) {} @@ -34,4 +34,4 @@ void CScriptDockAreaChange::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId CEntity::AcceptScriptMsg(msg, objId, stateMgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDockAreaChange.hpp b/Runtime/World/CScriptDockAreaChange.hpp index 0e6c07610..9a798399a 100644 --- a/Runtime/World/CScriptDockAreaChange.hpp +++ b/Runtime/World/CScriptDockAreaChange.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptDockAreaChange : public CEntity { s32 x34_dockReference; @@ -15,4 +15,4 @@ public: void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDoor.cpp b/Runtime/World/CScriptDoor.cpp index 78384e62b..cd801102f 100644 --- a/Runtime/World/CScriptDoor.cpp +++ b/Runtime/World/CScriptDoor.cpp @@ -12,7 +12,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static CMaterialList MakeDoorMaterialList(bool open) { CMaterialList ret; @@ -410,4 +410,4 @@ std::optional CScriptDoor::GetProjectileBounds() const { return std::nullopt; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptDoor.hpp b/Runtime/World/CScriptDoor.hpp index 0f0ef087b..2b49ffc61 100644 --- a/Runtime/World/CScriptDoor.hpp +++ b/Runtime/World/CScriptDoor.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CScriptDoor : public CPhysicsActor { public: @@ -63,4 +63,4 @@ public: bool IsOpen() const { return x2a8_26_isOpen; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptEMPulse.cpp b/Runtime/World/CScriptEMPulse.cpp index 4ef92348b..2180219ca 100644 --- a/Runtime/World/CScriptEMPulse.cpp +++ b/Runtime/World/CScriptEMPulse.cpp @@ -11,7 +11,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptEMPulse::CScriptEMPulse(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, float initialRadius, float finalRadius, @@ -97,4 +97,4 @@ zeus::CAABox CScriptEMPulse::CalculateBoundingBox() const { return zeus::CAABox(GetTranslation() - xf0_currentRadius, GetTranslation() + xf0_currentRadius); } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CScriptEMPulse.hpp b/Runtime/World/CScriptEMPulse.hpp index 4a3bcbcab..d1545d343 100644 --- a/Runtime/World/CScriptEMPulse.hpp +++ b/Runtime/World/CScriptEMPulse.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CElementGen; class CGenDescription; @@ -32,4 +32,4 @@ public: std::optional GetTouchBounds() const override; void Touch(CActor&, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptEffect.cpp b/Runtime/World/CScriptEffect.cpp index de1c7ec3e..eb69f62a3 100644 --- a/Runtime/World/CScriptEffect.cpp +++ b/Runtime/World/CScriptEffect.cpp @@ -16,7 +16,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { u32 CScriptEffect::g_NumParticlesUpdating = 0; u32 CScriptEffect::g_NumParticlesRendered = 0; @@ -384,4 +384,4 @@ bool CScriptEffect::AreBothSystemsDeleteable() const { return true; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptEffect.hpp b/Runtime/World/CScriptEffect.hpp index 25397d0ae..c7bf07111 100644 --- a/Runtime/World/CScriptEffect.hpp +++ b/Runtime/World/CScriptEffect.hpp @@ -6,7 +6,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CElementGen; class CParticleElectric; @@ -72,4 +72,4 @@ public: } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptGenerator.cpp b/Runtime/World/CScriptGenerator.cpp index 5311f7222..e58b743fd 100644 --- a/Runtime/World/CScriptGenerator.cpp +++ b/Runtime/World/CScriptGenerator.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptGenerator::CScriptGenerator(TUniqueId uid, std::string_view name, const CEntityInfo& info, u32 spawnCount, bool noReuseFollowers, const zeus::CVector3f& vec1, bool noInheritXf, bool active, @@ -139,4 +139,4 @@ void CScriptGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sende CEntity::AcceptScriptMsg(msg, sender, stateMgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptGenerator.hpp b/Runtime/World/CScriptGenerator.hpp index 76b154b20..90c0a3eff 100644 --- a/Runtime/World/CScriptGenerator.hpp +++ b/Runtime/World/CScriptGenerator.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { class CScriptGenerator : public CEntity { u32 x34_spawnCount; @@ -24,4 +24,4 @@ public: void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptGrapplePoint.cpp b/Runtime/World/CScriptGrapplePoint.cpp index 7d96927c4..639f7bd53 100644 --- a/Runtime/World/CScriptGrapplePoint.cpp +++ b/Runtime/World/CScriptGrapplePoint.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptGrapplePoint::CScriptGrapplePoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& transform, bool active, const CGrappleParameters& params) @@ -50,4 +50,4 @@ void CScriptGrapplePoint::AddToRenderer(const zeus::CFrustum&, CStateManager& mg CActor::EnsureRendered(mgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptGrapplePoint.hpp b/Runtime/World/CScriptGrapplePoint.hpp index eb67176f5..3547b4b94 100644 --- a/Runtime/World/CScriptGrapplePoint.hpp +++ b/Runtime/World/CScriptGrapplePoint.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { class CScriptGrapplePoint : public CActor { zeus::CAABox xe8_touchBounds; CGrappleParameters x100_parameters; @@ -24,4 +24,4 @@ public: void AddToRenderer(const zeus::CFrustum&, CStateManager&) override; const CGrappleParameters& GetGrappleParameters() const { return x100_parameters; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptGunTurret.cpp b/Runtime/World/CScriptGunTurret.cpp index c1a5b726a..c3938bb6b 100644 --- a/Runtime/World/CScriptGunTurret.cpp +++ b/Runtime/World/CScriptGunTurret.cpp @@ -18,7 +18,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { namespace { constexpr CMaterialList skGunMaterialList = {EMaterialTypes::Solid, EMaterialTypes::Character, EMaterialTypes::Orbit, EMaterialTypes::Target}; @@ -279,7 +279,7 @@ void CScriptGunTurret::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, break; } case EScriptObjectMessage::Damage: { - if (x258_type == ETurretComponent::Gun && GetHealthInfo(mgr)->GetHP() > 0.f) { + if (x258_type == ETurretComponent::Gun && GetHealthInfo(mgr)->GetHP() <= 0.f) { if (const TCastToConstPtr proj = mgr.GetObjectById(uid)) { if ((proj->GetAttribField() & EProjectileAttrib::Wave) == EProjectileAttrib::Wave) { x520_state = ETurretState::Frenzy; @@ -439,10 +439,11 @@ void CScriptGunTurret::LaunchProjectile(CStateManager& mgr) { GetAreaIdAlways(), GetUniqueId(), kInvalidUniqueId, EProjectileAttrib::None, false, zeus::skOne3f, x458_visorEffectDesc, x2d4_data.GetVisorSoundId(), false); mgr.AddObject(proj); - const auto pair = - x64_modelData->GetAnimationData()->GetCharacterInfo().GetPASDatabase().FindBestAnimation( - CPASAnimParmData(18, CPASAnimParm::FromEnum(1), CPASAnimParm::FromReal32(90.f), - CPASAnimParm::FromEnum(skStateToLocoTypeLookup[size_t(x520_state)])), -1); + const auto pair = x64_modelData->GetAnimationData()->GetCharacterInfo().GetPASDatabase().FindBestAnimation( + CPASAnimParmData(pas::EAnimationState::ProjectileAttack, CPASAnimParm::FromEnum(1), + CPASAnimParm::FromReal32(90.f), + CPASAnimParm::FromEnum(skStateToLocoTypeLookup[size_t(x520_state)])), + -1); if (pair.first > 0.f) { x64_modelData->EnableLooping(false); x64_modelData->GetAnimationData()->SetAnimation(CAnimPlaybackParms(pair.second, -1, 1.f, true), false); @@ -451,7 +452,7 @@ void CScriptGunTurret::LaunchProjectile(CStateManager& mgr) { void CScriptGunTurret::PlayAdditiveFlinchAnimation(CStateManager& mgr) { const auto pair = GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase().FindBestAnimation( - CPASAnimParmData(23), *mgr.GetActiveRandom(), -1); + CPASAnimParmData(pas::EAnimationState::AdditiveFlinch), *mgr.GetActiveRandom(), -1); if (pair.first > 0.f) { GetModelData()->GetAnimationData()->AddAdditiveAnimation(pair.second, 1.f, false, true); } @@ -727,7 +728,7 @@ void CScriptGunTurret::UpdateTurretAnimation() { return; } - const auto parmData = CPASAnimParmData(5, CPASAnimParm::FromEnum(0), + const auto parmData = CPASAnimParmData(pas::EAnimationState::Locomotion, CPASAnimParm::FromEnum(0), CPASAnimParm::FromEnum(skStateToLocoTypeLookup[size_t(x520_state)])); const auto pair = GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase().FindBestAnimation(parmData, -1); @@ -1214,7 +1215,8 @@ void CScriptGunTurret::PlayAdditiveChargingAnimation(CStateManager& mgr) { } const auto pair = GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase().FindBestAnimation( - CPASAnimParmData(24, CPASAnimParm::FromEnum(2)), *mgr.GetActiveRandom(), -1); + CPASAnimParmData(pas::EAnimationState::AdditiveReaction, CPASAnimParm::FromEnum(2)), *mgr.GetActiveRandom(), + -1); if (pair.first > 0.f) { x55c_additiveChargeAnim = pair.second; GetModelData()->GetAnimationData()->AddAdditiveAnimation(pair.second, 1.f, true, false); @@ -1304,4 +1306,4 @@ bool CScriptGunTurret::IsInsignificantRotation(float dt) const { zeus::degToRad(2.f) * dt; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptGunTurret.hpp b/Runtime/World/CScriptGunTurret.hpp index 65bc8097c..9a4dc7824 100644 --- a/Runtime/World/CScriptGunTurret.hpp +++ b/Runtime/World/CScriptGunTurret.hpp @@ -13,7 +13,7 @@ #include #include -namespace urde { +namespace metaforce { class CCollisionActorManager; class CElementGen; @@ -231,4 +231,4 @@ public: CHealthInfo* HealthInfo(CStateManager&) override { return &x264_healthInfo; } const CDamageVulnerability* GetDamageVulnerability() const override { return &x26c_damageVuln; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptHUDMemo.cpp b/Runtime/World/CScriptHUDMemo.cpp index 76ca45762..1feadb2f1 100644 --- a/Runtime/World/CScriptHUDMemo.cpp +++ b/Runtime/World/CScriptHUDMemo.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptHUDMemo::CScriptHUDMemo(TUniqueId uid, std::string_view name, const CEntityInfo& info, const CHUDMemoParms& parms, EDisplayType disp, CAssetId msg, bool active) @@ -39,4 +39,4 @@ void CScriptHUDMemo::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CS CEntity::AcceptScriptMsg(msg, uid, mgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptHUDMemo.hpp b/Runtime/World/CScriptHUDMemo.hpp index 75949946a..f0a44af59 100644 --- a/Runtime/World/CScriptHUDMemo.hpp +++ b/Runtime/World/CScriptHUDMemo.hpp @@ -8,7 +8,7 @@ #include "Runtime/World/CEntity.hpp" #include "Runtime/World/CHUDMemoParms.hpp" -namespace urde { +namespace metaforce { class CScriptHUDMemo : public CEntity { public: @@ -29,4 +29,4 @@ public: void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptMazeNode.cpp b/Runtime/World/CScriptMazeNode.cpp index d387bef95..2502d9662 100644 --- a/Runtime/World/CScriptMazeNode.cpp +++ b/Runtime/World/CScriptMazeNode.cpp @@ -7,13 +7,11 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { std::array sMazeSeeds; -#ifndef NDEBUG std::array sDebugCellPos; -#endif CScriptMazeNode::CScriptMazeNode(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, s32 col, s32 row, s32 side, @@ -116,7 +114,7 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C } } } - for (const auto& ent : mgr.GetAllObjectList()) { + for (const auto ent : mgr.GetAllObjectList()) { if (TCastToPtr node = ent) { if (node->xe8_col == xe8_col - 1 && node->xec_row == xec_row && node->xf0_side == ESide::Right) { auto& cell = maze->GetCell(xe8_col - 1, xec_row); @@ -163,14 +161,12 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C maze->GenerateObstacles(); mgr.SetCurrentMaze(std::move(maze)); } -#ifndef NDEBUG if (xf0_side == ESide::Right) { sDebugCellPos[xe8_col + xec_row * skMazeCols] = GetTranslation(); } else if (xe8_col == skMazeCols - 1) { // Last column does not have right nodes, but we can infer the position sDebugCellPos[xe8_col + xec_row * skMazeCols] = GetTranslation() - zeus::CVector3f{1.1875f, -0.1215f, 1.2187f}; } -#endif } } // URDE change: used to be in the above if branch @@ -356,11 +352,9 @@ void CMazeState::Initialize() { auto& cell = GetCell(*idx); if (cell.x1_26_checked) { cell.x1_25_onPath = true; -#ifndef NDEBUG if (pathLength > 0) { m_path.push_back(*idx); } -#endif } } x94_24_initialized = true; @@ -371,7 +365,7 @@ void CMazeState::GenerateObstacles() { Initialize(); } - auto GetRandom = [this](s32 offset) constexpr { + auto GetRandom = [this](s32 offset) { s32 tmp = x0_rand.Next(); return tmp + ((tmp / 5) * -5) + offset; }; @@ -467,7 +461,6 @@ void CMazeState::GenerateObstacles() { }; } -#ifndef NDEBUG void CMazeState::DebugRender() { m_renderer.Reset(); m_renderer.AddVertex(sDebugCellPos[skEnterCol + skEnterRow * skMazeCols], zeus::skBlue, 2.f); @@ -484,5 +477,4 @@ void CMazeState::DebugRender() { } m_renderer.Render(); } -#endif -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptMazeNode.hpp b/Runtime/World/CScriptMazeNode.hpp index cd8e52b99..9b14bcdea 100644 --- a/Runtime/World/CScriptMazeNode.hpp +++ b/Runtime/World/CScriptMazeNode.hpp @@ -11,7 +11,7 @@ #include -namespace urde { +namespace metaforce { constexpr s32 skMazeCols = 9; constexpr s32 skMazeRows = 7; constexpr s32 skEnterCol = 4; @@ -54,11 +54,9 @@ class CMazeState { s32 x90_targetRow; bool x94_24_initialized : 1 = false; -#ifndef NDEBUG std::vector m_path; CLineRenderer m_renderer = {CLineRenderer::EPrimitiveMode::LineStrip, skMazeRows* skMazeCols, hsh::texture2d{}, true, hsh::Compare::LEqual}; -#endif public: CMazeState(s32 enterCol, s32 enterRow, s32 targetCol, s32 targetRow) @@ -67,9 +65,7 @@ public: void Initialize(); void GenerateObstacles(); -#ifndef NDEBUG void DebugRender(); -#endif [[nodiscard]] SMazeCell& GetCell(u32 col, u32 row) { #ifndef NDEBUG @@ -119,4 +115,4 @@ private: void Reset(CStateManager& mgr); void SendScriptMsgs(CStateManager& mgr, EScriptObjectMessage msg); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptMemoryRelay.cpp b/Runtime/World/CScriptMemoryRelay.cpp index ff706c7e9..44909e364 100644 --- a/Runtime/World/CScriptMemoryRelay.cpp +++ b/Runtime/World/CScriptMemoryRelay.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptMemoryRelay::CScriptMemoryRelay(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool defaultActive, bool skipSendActive, bool ignoreMessages) @@ -36,4 +36,4 @@ void CScriptMemoryRelay::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId obj CEntity::AcceptScriptMsg(msg, objId, stateMgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptMemoryRelay.hpp b/Runtime/World/CScriptMemoryRelay.hpp index 2f0b31c64..05935d28a 100644 --- a/Runtime/World/CScriptMemoryRelay.hpp +++ b/Runtime/World/CScriptMemoryRelay.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptMemoryRelay : public CEntity { bool x34_24_defaultActive; bool x34_25_skipSendActive; @@ -16,4 +16,4 @@ public: void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptMidi.cpp b/Runtime/World/CScriptMidi.cpp index 35c267076..00b23486a 100644 --- a/Runtime/World/CScriptMidi.cpp +++ b/Runtime/World/CScriptMidi.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptMidi::CScriptMidi(TUniqueId id, const CEntityInfo& info, std::string_view name, bool active, CAssetId csng, float fadeIn, float fadeOut, s32 volume) @@ -77,4 +77,4 @@ void CScriptMidi::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CSt } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptMidi.hpp b/Runtime/World/CScriptMidi.hpp index 296d0682f..efeb77e30 100644 --- a/Runtime/World/CScriptMidi.hpp +++ b/Runtime/World/CScriptMidi.hpp @@ -7,7 +7,7 @@ #include "Runtime/Audio/CMidiManager.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptMidi : public CEntity { TToken x34_song; @@ -28,4 +28,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPickup.cpp b/Runtime/World/CScriptPickup.cpp index b09cb98df..ab846fd3b 100644 --- a/Runtime/World/CScriptPickup.cpp +++ b/Runtime/World/CScriptPickup.cpp @@ -15,7 +15,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptPickup::CScriptPickup(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& aParams, const zeus::CAABox& aabb, CPlayerState::EItemType itemType, s32 amount, s32 capacity, CAssetId pickupEffect, @@ -172,4 +172,4 @@ void CScriptPickup::Touch(CActor& act, CStateManager& mgr) { } } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPickup.hpp b/Runtime/World/CScriptPickup.hpp index db5b0a8be..52f26e27b 100644 --- a/Runtime/World/CScriptPickup.hpp +++ b/Runtime/World/CScriptPickup.hpp @@ -6,7 +6,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CPhysicsActor.hpp" -namespace urde { +namespace metaforce { class CScriptPickup : public CPhysicsActor { CPlayerState::EItemType x258_itemType; s32 x25c_amount; @@ -37,4 +37,4 @@ public: CPlayerState::EItemType GetItem() const { return x258_itemType; } void SetGenerated() { x28c_24_generated = true; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPickupGenerator.cpp b/Runtime/World/CScriptPickupGenerator.cpp index 55e8be35b..77e9f7265 100644 --- a/Runtime/World/CScriptPickupGenerator.cpp +++ b/Runtime/World/CScriptPickupGenerator.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptPickupGenerator::CScriptPickupGenerator(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& pos, float frequency, bool active) @@ -176,4 +176,4 @@ void CScriptPickupGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId CEntity::AcceptScriptMsg(msg, sender, stateMgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPickupGenerator.hpp b/Runtime/World/CScriptPickupGenerator.hpp index b05e23a3b..f42810eb1 100644 --- a/Runtime/World/CScriptPickupGenerator.hpp +++ b/Runtime/World/CScriptPickupGenerator.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CScriptPickupGenerator : public CEntity { zeus::CVector3f x34_position; float x40_frequency; @@ -22,4 +22,4 @@ public: void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPlatform.cpp b/Runtime/World/CScriptPlatform.cpp index 188a3d7e4..ad7640b70 100644 --- a/Runtime/World/CScriptPlatform.cpp +++ b/Runtime/World/CScriptPlatform.cpp @@ -16,7 +16,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { constexpr auto skPlatformMaterialList = CMaterialList{EMaterialTypes::Solid, EMaterialTypes::Immovable, EMaterialTypes::Platform, EMaterialTypes::Occluder}; @@ -560,4 +560,12 @@ zeus::CQuaternion CScriptPlatform::Move(float dt, CStateManager& mgr) { return zeus::CQuaternion(); } -} // namespace urde +void CScriptPlatform::DebugDraw() { + if (!m_boxFilter) { + m_boxFilter = {CAABoxShader()}; + } + + m_boxFilter->setAABB(*GetTouchBounds()); + m_boxFilter->draw({1.f, 0.f, 1.f, .5f}); +} +} // namespace metaforce diff --git a/Runtime/World/CScriptPlatform.hpp b/Runtime/World/CScriptPlatform.hpp index c4020896e..aaf44c803 100644 --- a/Runtime/World/CScriptPlatform.hpp +++ b/Runtime/World/CScriptPlatform.hpp @@ -12,12 +12,13 @@ #include "Runtime/World/CDamageVulnerability.hpp" #include "Runtime/World/CHealthInfo.hpp" #include "Runtime/World/CPhysicsActor.hpp" +#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include #include #include -namespace urde { +namespace metaforce { class CFluidPlane; struct SRiders { @@ -72,6 +73,7 @@ class CScriptPlatform : public CPhysicsActor { static rstl::reserved_vector BuildNearListFromRiders(CStateManager& mgr, const std::vector& movedRiders); + std::optional m_boxFilter; public: CScriptPlatform(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms, const zeus::CAABox& aabb, float speed, @@ -114,5 +116,7 @@ public: virtual void SplashThink(const zeus::CAABox&, const CFluidPlane&, float, CStateManager&) const; virtual zeus::CQuaternion Move(float, CStateManager&); + + void DebugDraw(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPlayerActor.cpp b/Runtime/World/CScriptPlayerActor.cpp index 1aa4cefd0..137d724d3 100644 --- a/Runtime/World/CScriptPlayerActor.cpp +++ b/Runtime/World/CScriptPlayerActor.cpp @@ -14,7 +14,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptPlayerActor::CScriptPlayerActor(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, const CAnimRes& animRes, CModelData&& mData, const zeus::CAABox& aabox, bool setBoundingBox, const CMaterialList& list, @@ -419,8 +419,8 @@ void CScriptPlayerActor::Render(CStateManager& mgr) { const float radius = zeus::clamp(0.25f, (6.f - vecFromCam.magnitude()) / 6.f, 2.f); const float offsetX = std::sin(x34c_phazonOffsetAngle); const float offsetY = std::sin(x34c_phazonOffsetAngle) * 0.5f; - g_Renderer->DrawPhazonSuitIndirectEffect(zeus::CColor(0.1f, 1.f), x338_phazonIndirectTexture, zeus::skWhite, - radius, 0.05f, offsetX, offsetY); + //g_Renderer->DrawPhazonSuitIndirectEffect(zeus::CColor(0.1f, 1.f), x338_phazonIndirectTexture, zeus::skWhite, + // radius, 0.05f, offsetX, offsetY); } } @@ -454,4 +454,4 @@ void CScriptPlayerActor::TouchModels(const CStateManager& mgr) const { } } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPlayerActor.hpp b/Runtime/World/CScriptPlayerActor.hpp index c40d359d7..bb71f8633 100644 --- a/Runtime/World/CScriptPlayerActor.hpp +++ b/Runtime/World/CScriptPlayerActor.hpp @@ -7,7 +7,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CScriptActor.hpp" -namespace urde { +namespace metaforce { class CScriptPlayerActor : public CScriptActor { CAnimRes x2e8_suitRes; CPlayerState::EBeamId x304_beam; @@ -66,4 +66,4 @@ public: void Render(CStateManager& mgr) override; void TouchModels(const CStateManager& mgr) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPlayerHint.cpp b/Runtime/World/CScriptPlayerHint.cpp index ee8faf6ac..62906076f 100644 --- a/Runtime/World/CScriptPlayerHint.cpp +++ b/Runtime/World/CScriptPlayerHint.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptPlayerHint::CScriptPlayerHint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, u32 priority, u32 overrideFlags) @@ -91,4 +91,4 @@ void CScriptPlayerHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId send CActor::AcceptScriptMsg(msg, sender, mgr); } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CScriptPlayerHint.hpp b/Runtime/World/CScriptPlayerHint.hpp index 878148aad..10be641fc 100644 --- a/Runtime/World/CScriptPlayerHint.hpp +++ b/Runtime/World/CScriptPlayerHint.hpp @@ -6,7 +6,7 @@ #include "Runtime/rstl.hpp" #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CScriptPlayerHint : public CActor { rstl::reserved_vector xe8_objectList; @@ -29,4 +29,4 @@ public: void SetDeactivated() { xfc_deactivated = true; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPlayerStateChange.cpp b/Runtime/World/CScriptPlayerStateChange.cpp index 056eb2b5a..a9b163716 100644 --- a/Runtime/World/CScriptPlayerStateChange.cpp +++ b/Runtime/World/CScriptPlayerStateChange.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptPlayerStateChange::CScriptPlayerStateChange(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, u32 itemType, u32 itemCount, u32 itemCapacity, EControl control, EControlCommandOption controlCmdOpt) @@ -40,4 +40,4 @@ void CScriptPlayerStateChange::AcceptScriptMsg(EScriptObjectMessage msg, TUnique CEntity::AcceptScriptMsg(msg, objId, stateMgr); } -} // namespace urde \ No newline at end of file +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CScriptPlayerStateChange.hpp b/Runtime/World/CScriptPlayerStateChange.hpp index d8f297460..539679e2c 100644 --- a/Runtime/World/CScriptPlayerStateChange.hpp +++ b/Runtime/World/CScriptPlayerStateChange.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptPlayerStateChange : public CEntity { public: enum class EControl { Unfiltered, Filtered }; @@ -24,4 +24,4 @@ public: void Accept(IVisitor& visit) override; void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPointOfInterest.cpp b/Runtime/World/CScriptPointOfInterest.cpp index 8b0c09704..1acf88568 100644 --- a/Runtime/World/CScriptPointOfInterest.cpp +++ b/Runtime/World/CScriptPointOfInterest.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptPointOfInterest::CScriptPointOfInterest(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, @@ -41,4 +41,4 @@ void CScriptPointOfInterest::CalculateRenderBounds() { std::optional CScriptPointOfInterest::GetTouchBounds() const { return {zeus::CAABox{x34_transform.origin, x34_transform.origin}}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptPointOfInterest.hpp b/Runtime/World/CScriptPointOfInterest.hpp index e7bb74eb5..e7ebcdda0 100644 --- a/Runtime/World/CScriptPointOfInterest.hpp +++ b/Runtime/World/CScriptPointOfInterest.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CScannableParameters; class CScriptPointOfInterest : public CActor { @@ -22,4 +22,4 @@ public: void CalculateRenderBounds() override; std::optional GetTouchBounds() const override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptRandomRelay.cpp b/Runtime/World/CScriptRandomRelay.cpp index ee3c20564..95f547355 100644 --- a/Runtime/World/CScriptRandomRelay.cpp +++ b/Runtime/World/CScriptRandomRelay.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptRandomRelay::CScriptRandomRelay(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 sendSetSize, s32 sendSetVariance, bool percentSize, bool active) : CEntity(uid, info, active, name) @@ -67,4 +67,4 @@ void CScriptRandomRelay::SendLocalScriptMsgs(EScriptObjectState state, CStateMan stateMgr.SendScriptMsg(o.first, GetUniqueId(), o.second); } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptRandomRelay.hpp b/Runtime/World/CScriptRandomRelay.hpp index 6a4f9c8c8..f5a69deba 100644 --- a/Runtime/World/CScriptRandomRelay.hpp +++ b/Runtime/World/CScriptRandomRelay.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptRandomRelay : public CEntity { s32 x34_sendSetSize; s32 x38_sendSetVariance; @@ -19,4 +19,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; void SendLocalScriptMsgs(EScriptObjectState state, CStateManager& stateMgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptRelay.cpp b/Runtime/World/CScriptRelay.cpp index a4e4dad98..cdeab93df 100644 --- a/Runtime/World/CScriptRelay.cpp +++ b/Runtime/World/CScriptRelay.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptRelay::CScriptRelay(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active) : CEntity(uid, info, active, name) {} @@ -66,4 +66,4 @@ void CScriptRelay::UpdateObjectRef(CStateManager& stateMgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptRelay.hpp b/Runtime/World/CScriptRelay.hpp index c280acf1f..c175bed53 100644 --- a/Runtime/World/CScriptRelay.hpp +++ b/Runtime/World/CScriptRelay.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptRelay : public CEntity { TUniqueId x34_nextRelay = kInvalidUniqueId; u32 x38_sendCount = 0; @@ -18,4 +18,4 @@ public: void Think(float, CStateManager& stateMgr) override; void UpdateObjectRef(CStateManager& stateMgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptRipple.cpp b/Runtime/World/CScriptRipple.cpp index dae886bd5..a5e59a69f 100644 --- a/Runtime/World/CScriptRipple.cpp +++ b/Runtime/World/CScriptRipple.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptRipple::CScriptRipple(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& vec, bool active, float f1) @@ -37,4 +37,4 @@ void CScriptRipple::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSt } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptRipple.hpp b/Runtime/World/CScriptRipple.hpp index 8f9090acf..d1fbbe25a 100644 --- a/Runtime/World/CScriptRipple.hpp +++ b/Runtime/World/CScriptRipple.hpp @@ -6,7 +6,7 @@ #include -namespace urde { +namespace metaforce { class CScriptRipple : public CEntity { float x34_magnitude; zeus::CVector3f x38_center; @@ -18,4 +18,4 @@ public: void Think(float, CStateManager&) override {} void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptRoomAcoustics.cpp b/Runtime/World/CScriptRoomAcoustics.cpp index 976268ed8..4f8b8d7e7 100644 --- a/Runtime/World/CScriptRoomAcoustics.cpp +++ b/Runtime/World/CScriptRoomAcoustics.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static TAreaId s_ActiveAcousticsAreaId = kInvalidAreaId; @@ -82,4 +82,4 @@ void CScriptRoomAcoustics::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o void CScriptRoomAcoustics::Accept(IVisitor& visitor) { visitor.Visit(this); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptRoomAcoustics.hpp b/Runtime/World/CScriptRoomAcoustics.hpp index ca1e0e4b9..dd690b31a 100644 --- a/Runtime/World/CScriptRoomAcoustics.hpp +++ b/Runtime/World/CScriptRoomAcoustics.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { class CScriptRoomAcoustics : public CEntity { u32 x34_volumeScale; @@ -42,4 +42,4 @@ public: static void DisableAuxCallbacks(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptShadowProjector.cpp b/Runtime/World/CScriptShadowProjector.cpp index aaf63414d..914a1ea2c 100644 --- a/Runtime/World/CScriptShadowProjector.cpp +++ b/Runtime/World/CScriptShadowProjector.cpp @@ -6,7 +6,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptShadowProjector::CScriptShadowProjector(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, const zeus::CVector3f& offset, @@ -89,4 +89,4 @@ void CScriptShadowProjector::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId } void CScriptShadowProjector::PreRender(CStateManager&, const zeus::CFrustum&) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptShadowProjector.hpp b/Runtime/World/CScriptShadowProjector.hpp index 48e52965e..5d592b328 100644 --- a/Runtime/World/CScriptShadowProjector.hpp +++ b/Runtime/World/CScriptShadowProjector.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CProjectedShadow; class CScriptShadowProjector : public CActor { @@ -34,4 +34,4 @@ public: void AddToRenderer(const zeus::CFrustum&, CStateManager&) override {} void CreateProjectedShadow(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSound.cpp b/Runtime/World/CScriptSound.cpp index 38543f309..38a0a986f 100644 --- a/Runtime/World/CScriptSound.cpp +++ b/Runtime/World/CScriptSound.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { bool CScriptSound::sFirstInFrame = false; CScriptSound::CScriptSound(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, @@ -25,7 +25,7 @@ CScriptSound::CScriptSound(TUniqueId uid, std::string_view name, const CEntityIn , x10e_vol(vol / 127.f) , x110_(w3) , x112_prio(s16(prio)) -, x114_pan(pan / 64.f - 1.f) +, x114_pan(amuse::convertMusyXPanToAmusePan(pan)) , x116_(w6) , x118_pitch(pitch / 8192.f) , x11c_25_looped(looped) @@ -225,4 +225,4 @@ void CScriptSound::StopSound(CStateManager& mgr) { xec_sfxHandle.reset(); } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSound.hpp b/Runtime/World/CScriptSound.hpp index 6cb980a8c..d0ccdef3a 100644 --- a/Runtime/World/CScriptSound.hpp +++ b/Runtime/World/CScriptSound.hpp @@ -6,7 +6,7 @@ #include "Runtime/Audio/CSfxManager.hpp" #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CScriptSound : public CActor { static bool sFirstInFrame; @@ -26,7 +26,7 @@ class CScriptSound : public CActor { s16 x110_; s16 x112_prio; float x114_pan; - bool x116_; + short x116_; float x118_pitch; bool x11c_24_playRequested : 1 = false; bool x11c_25_looped : 1; @@ -55,4 +55,4 @@ public: void PlaySound(CStateManager&); void StopSound(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpawnPoint.cpp b/Runtime/World/CScriptSpawnPoint.cpp index 645081504..6dc2b9e42 100644 --- a/Runtime/World/CScriptSpawnPoint.cpp +++ b/Runtime/World/CScriptSpawnPoint.cpp @@ -1,36 +1,22 @@ #include "Runtime/World/CScriptSpawnPoint.hpp" #include "Runtime/CStateManager.hpp" -#include "Runtime/Particle/CGenDescription.hpp" #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CWorld.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptSpawnPoint::CScriptSpawnPoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, const rstl::reserved_vector& itemCounts, bool defaultSpawn, bool active, bool morphed) -: CEntity(uid, info, active, name), x34_xf(xf), x64_itemCounts(itemCounts) { -#ifndef NDEBUG - x64_itemCounts[size_t(CPlayerState::EItemType::MorphBall)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::MorphBallBombs)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::PhazonSuit)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::ThermalVisor)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::XRayVisor)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::GrappleBeam)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::BoostBall)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::ChargeBeam)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::PowerBombs)] = 8; - x64_itemCounts[size_t(CPlayerState::EItemType::SpaceJumpBoots)] = 1; - x64_itemCounts[size_t(CPlayerState::EItemType::Missiles)] = - std::max(x64_itemCounts[size_t(CPlayerState::EItemType::Missiles)], u32(5)); -#endif - x10c_24_firstSpawn = defaultSpawn; - x10c_25_morphed = morphed; -} +: CEntity(uid, info, active, name) +, x34_xf(xf) +, x64_itemCounts(itemCounts) +, x10c_24_firstSpawn(defaultSpawn) +, x10c_25_morphed(morphed) { } void CScriptSpawnPoint::Accept(IVisitor& visitor) { visitor.Visit(this); } @@ -42,7 +28,7 @@ void CScriptSpawnPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objI using EPlayerItemType = CPlayerState::EItemType; const std::shared_ptr& plState = stateMgr.GetPlayerState(); for (u32 i = 0; i < u32(EPlayerItemType::Max); ++i) { - plState->ReInitalizePowerUp(EPlayerItemType(i), GetPowerup(EPlayerItemType(i))); + plState->ReInitializePowerUp(EPlayerItemType(i), GetPowerup(EPlayerItemType(i))); plState->ResetAndIncrPickUp(EPlayerItemType(i), GetPowerup(EPlayerItemType(i))); } } @@ -83,4 +69,4 @@ u32 CScriptSpawnPoint::GetPowerup(CPlayerState::EItemType item) const { } return x64_itemCounts[idx]; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpawnPoint.hpp b/Runtime/World/CScriptSpawnPoint.hpp index 20a488de5..512752d58 100644 --- a/Runtime/World/CScriptSpawnPoint.hpp +++ b/Runtime/World/CScriptSpawnPoint.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class CScriptSpawnPoint : public CEntity { zeus::CTransform x34_xf; @@ -28,4 +28,4 @@ public: u32 GetPowerup(CPlayerState::EItemType item) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpecialFunction.cpp b/Runtime/World/CScriptSpecialFunction.cpp index c2ca954a0..a967ac74f 100644 --- a/Runtime/World/CScriptSpecialFunction.cpp +++ b/Runtime/World/CScriptSpecialFunction.cpp @@ -22,7 +22,7 @@ #include -namespace urde { +namespace metaforce { CScriptSpecialFunction::CScriptSpecialFunction(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, ESpecialFunction func, @@ -1005,4 +1005,4 @@ void CScriptSpecialFunction::AddOrUpdateEmitter(float pitch, CSfxHandle& handle, CScriptSpecialFunction::SRingController::SRingController(TUniqueId uid, float rotateSpeed, bool reachedTarget) : x0_id(uid), x4_rotateSpeed(rotateSpeed), x8_reachedTarget(reachedTarget) {} -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpecialFunction.hpp b/Runtime/World/CScriptSpecialFunction.hpp index a3cfd882a..572d10592 100644 --- a/Runtime/World/CScriptSpecialFunction.hpp +++ b/Runtime/World/CScriptSpecialFunction.hpp @@ -12,7 +12,7 @@ #include #include -namespace urde { +namespace metaforce { class CScriptSpecialFunction : public CActor { public: enum class ESpecialFunction { @@ -144,4 +144,4 @@ public: u32 GetSpecialEnding(const CStateManager&) const; void AddOrUpdateEmitter(float pitch, CSfxHandle& handle, u16 id, const zeus::CVector3f& pos, float vol); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpiderBallAttractionSurface.cpp b/Runtime/World/CScriptSpiderBallAttractionSurface.cpp index 40c9390b6..40f8d534b 100644 --- a/Runtime/World/CScriptSpiderBallAttractionSurface.cpp +++ b/Runtime/World/CScriptSpiderBallAttractionSurface.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptSpiderBallAttractionSurface::CScriptSpiderBallAttractionSurface(TUniqueId uid, std::string_view name, const CEntityInfo& info, @@ -37,4 +37,4 @@ void CScriptSpiderBallAttractionSurface::Touch(CActor& actor, CStateManager& mgr // Empty } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpiderBallAttractionSurface.hpp b/Runtime/World/CScriptSpiderBallAttractionSurface.hpp index 90d31503e..4aa116bbb 100644 --- a/Runtime/World/CScriptSpiderBallAttractionSurface.hpp +++ b/Runtime/World/CScriptSpiderBallAttractionSurface.hpp @@ -7,7 +7,7 @@ #include #include -namespace urde { +namespace metaforce { class CScriptSpiderBallAttractionSurface : public CActor { zeus::CVector3f xe8_scale; @@ -24,4 +24,4 @@ public: const zeus::CVector3f& GetScale() const { return xe8_scale; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpiderBallWaypoint.cpp b/Runtime/World/CScriptSpiderBallWaypoint.cpp index 8de35f469..ff952293f 100644 --- a/Runtime/World/CScriptSpiderBallWaypoint.cpp +++ b/Runtime/World/CScriptSpiderBallWaypoint.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptSpiderBallWaypoint::CScriptSpiderBallWaypoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, u32 w1) : CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic), @@ -204,4 +204,4 @@ void CScriptSpiderBallWaypoint::GetClosestPointAlongWaypoints(CStateManager& mgr } closestWaypoint = wp; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpiderBallWaypoint.hpp b/Runtime/World/CScriptSpiderBallWaypoint.hpp index 32d209bcf..f9d5cae59 100644 --- a/Runtime/World/CScriptSpiderBallWaypoint.hpp +++ b/Runtime/World/CScriptSpiderBallWaypoint.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CScriptSpiderBallWaypoint : public CActor { enum class ECheckActiveWaypoint { Check, SkipCheck }; u32 xe8_; @@ -31,5 +31,9 @@ public: const CScriptSpiderBallWaypoint*& closestWaypoint, zeus::CVector3f& closestPoint, zeus::CVector3f& deltaBetweenPoints, float deltaBetweenInterpDist, zeus::CVector3f& interpDeltaBetweenPoints) const; + void ClearWaypoints() { + xfc_aabox.reset(); + xec_waypoints.clear(); + } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpindleCamera.cpp b/Runtime/World/CScriptSpindleCamera.cpp index 63bca54e3..8a6c98103 100644 --- a/Runtime/World/CScriptSpindleCamera.cpp +++ b/Runtime/World/CScriptSpindleCamera.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { SSpindleProperty::SSpindleProperty(CInputStream& in) { x4_input = ESpindleInput(in.readUint32Big()); @@ -369,4 +369,4 @@ void CScriptSpindleCamera::Render(CStateManager&) { // Empty } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSpindleCamera.hpp b/Runtime/World/CScriptSpindleCamera.hpp index 4e9d15d8f..649634cdb 100644 --- a/Runtime/World/CScriptSpindleCamera.hpp +++ b/Runtime/World/CScriptSpindleCamera.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { enum class ESpindleInput { Constant, @@ -110,4 +110,4 @@ public: void ProcessInput(const CFinalInput& input, CStateManager& mgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSteam.cpp b/Runtime/World/CScriptSteam.cpp index eca0a01a6..209c64d8f 100644 --- a/Runtime/World/CScriptSteam.cpp +++ b/Runtime/World/CScriptSteam.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptSteam::CScriptSteam(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& pos, const zeus::CAABox& aabb, const CDamageInfo& dInfo, const zeus::CVector3f& orientedForce, @@ -59,4 +59,4 @@ void CScriptSteam::Think(float dt, CStateManager& mgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSteam.hpp b/Runtime/World/CScriptSteam.hpp index 40d83e0a7..72a253af5 100644 --- a/Runtime/World/CScriptSteam.hpp +++ b/Runtime/World/CScriptSteam.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CScriptTrigger.hpp" -namespace urde { +namespace metaforce { class CScriptSteam : public CScriptTrigger { bool x150_; @@ -26,4 +26,4 @@ public: void Think(float, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptStreamedMusic.cpp b/Runtime/World/CScriptStreamedMusic.cpp index d98f695cd..049d356c8 100644 --- a/Runtime/World/CScriptStreamedMusic.cpp +++ b/Runtime/World/CScriptStreamedMusic.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { bool CScriptStreamedMusic::IsDSPFile(std::string_view fileName) { if (CStringExtras::CompareCaseInsensitive(fileName, "sw")) { @@ -96,4 +96,4 @@ void CScriptStreamedMusic::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptStreamedMusic.hpp b/Runtime/World/CScriptStreamedMusic.hpp index e307ddc8d..8f2532c0e 100644 --- a/Runtime/World/CScriptStreamedMusic.hpp +++ b/Runtime/World/CScriptStreamedMusic.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CStateManager; class CScriptStreamedMusic : public CEntity { @@ -33,4 +33,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSwitch.cpp b/Runtime/World/CScriptSwitch.cpp index 016401497..715a99099 100644 --- a/Runtime/World/CScriptSwitch.cpp +++ b/Runtime/World/CScriptSwitch.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptSwitch::CScriptSwitch(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, bool opened, bool closeOnOpened) : CEntity(uid, info, active, name), x34_opened(opened), x35_closeOnOpened(closeOnOpened) {} @@ -30,4 +30,4 @@ void CScriptSwitch::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, C CEntity::AcceptScriptMsg(msg, objId, mgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptSwitch.hpp b/Runtime/World/CScriptSwitch.hpp index 920374725..f1a3615a8 100644 --- a/Runtime/World/CScriptSwitch.hpp +++ b/Runtime/World/CScriptSwitch.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptSwitch : public CEntity { bool x34_opened; bool x35_closeOnOpened; @@ -14,4 +14,4 @@ public: void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptTargetingPoint.cpp b/Runtime/World/CScriptTargetingPoint.cpp index 2b51561ce..4af53b533 100644 --- a/Runtime/World/CScriptTargetingPoint.cpp +++ b/Runtime/World/CScriptTargetingPoint.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptTargetingPoint::CScriptTargetingPoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active) @@ -30,4 +30,4 @@ void CScriptTargetingPoint::Think(float dt, CStateManager&) { } bool CScriptTargetingPoint::GetLocked() const { return !x20_conns.empty(); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptTargetingPoint.hpp b/Runtime/World/CScriptTargetingPoint.hpp index e74d4cdec..0d4475b2b 100644 --- a/Runtime/World/CScriptTargetingPoint.hpp +++ b/Runtime/World/CScriptTargetingPoint.hpp @@ -5,7 +5,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CScriptTargetingPoint : public CActor { private: bool xe8_e4_ : 1 = false; @@ -22,4 +22,4 @@ public: bool GetLocked() const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptTimer.cpp b/Runtime/World/CScriptTimer.cpp index 4b625d465..97cb0fec1 100644 --- a/Runtime/World/CScriptTimer.cpp +++ b/Runtime/World/CScriptTimer.cpp @@ -4,7 +4,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptTimer::CScriptTimer(TUniqueId uid, std::string_view name, const CEntityInfo& info, float startTime, float maxRandDelay, bool loop, bool autoStart, bool active) @@ -76,4 +76,4 @@ void CScriptTimer::ApplyTime(float dt, CStateManager& mgr) { x42_isTiming = true; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptTimer.hpp b/Runtime/World/CScriptTimer.hpp index c73f7ea96..e33aad7bd 100644 --- a/Runtime/World/CScriptTimer.hpp +++ b/Runtime/World/CScriptTimer.hpp @@ -3,7 +3,7 @@ #include #include "Runtime/World/CEntity.hpp" -namespace urde { +namespace metaforce { class CScriptTimer : public CEntity { float x34_time; @@ -25,4 +25,4 @@ public: void ApplyTime(float, CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptTrigger.cpp b/Runtime/World/CScriptTrigger.cpp index 534f89f1e..ee7093512 100644 --- a/Runtime/World/CScriptTrigger.cpp +++ b/Runtime/World/CScriptTrigger.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptTrigger::CScriptTrigger(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& pos, const zeus::CAABox& bounds, const CDamageInfo& dInfo, @@ -54,7 +54,7 @@ void CScriptTrigger::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CS } } - CEntity::AcceptScriptMsg(msg, uid, mgr); + CActor::AcceptScriptMsg(msg, uid, mgr); } CScriptTrigger::CObjectTracker* CScriptTrigger::FindObject(TUniqueId id) { @@ -298,4 +298,4 @@ void CScriptTrigger::Touch(CActor& act, CStateManager& mgr) { zeus::CAABox CScriptTrigger::GetTriggerBoundsWR() const { return {x130_bounds.min + x34_transform.origin, x130_bounds.max + x34_transform.origin}; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptTrigger.hpp b/Runtime/World/CScriptTrigger.hpp index 0aba70371..ba270a21f 100644 --- a/Runtime/World/CScriptTrigger.hpp +++ b/Runtime/World/CScriptTrigger.hpp @@ -9,7 +9,7 @@ #include #include -namespace urde { +namespace metaforce { // TODO - Phil: Figure out what each of the DetectProjectiles actually mean enum class ETriggerFlags : u32 { @@ -90,4 +90,4 @@ public: } bool IsPlayerTriggerProc() const { return x148_28_playerTriggerProc; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptVisorFlare.cpp b/Runtime/World/CScriptVisorFlare.cpp index 5777d2409..076c13c19 100644 --- a/Runtime/World/CScriptVisorFlare.cpp +++ b/Runtime/World/CScriptVisorFlare.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptVisorFlare::CScriptVisorFlare(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, const zeus::CVector3f& pos, CVisorFlare::EBlendMode blendMode, bool b1, float f1, @@ -42,4 +42,4 @@ void CScriptVisorFlare::AddToRenderer(const zeus::CFrustum&, CStateManager& stat void CScriptVisorFlare::Render(CStateManager& stateMgr) { xe8_flare.Render(GetTranslation(), stateMgr); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptVisorFlare.hpp b/Runtime/World/CScriptVisorFlare.hpp index 0cda8755c..852dddb98 100644 --- a/Runtime/World/CScriptVisorFlare.hpp +++ b/Runtime/World/CScriptVisorFlare.hpp @@ -5,7 +5,7 @@ #include "Runtime/World/CActor.hpp" #include "Runtime/World/CVisorFlare.hpp" -namespace urde { +namespace metaforce { class CScriptVisorFlare : public CActor { CVisorFlare xe8_flare; @@ -24,4 +24,4 @@ public: void Render(CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptVisorGoo.cpp b/Runtime/World/CScriptVisorGoo.cpp index c75850560..509ef0ef4 100644 --- a/Runtime/World/CScriptVisorGoo.cpp +++ b/Runtime/World/CScriptVisorGoo.cpp @@ -9,7 +9,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptVisorGoo::CScriptVisorGoo(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CAssetId particle, CAssetId electric, float minDist, @@ -121,4 +121,4 @@ void CScriptVisorGoo::Touch(CActor& other, CStateManager& mgr) { // Empty } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptVisorGoo.hpp b/Runtime/World/CScriptVisorGoo.hpp index e53bcf58f..3ce310c86 100644 --- a/Runtime/World/CScriptVisorGoo.hpp +++ b/Runtime/World/CScriptVisorGoo.hpp @@ -7,7 +7,7 @@ #include -namespace urde { +namespace metaforce { class CScriptVisorGoo : public CActor { TToken xe8_particleDesc; @@ -36,4 +36,4 @@ public: void Touch(CActor&, CStateManager&) override; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptWater.cpp b/Runtime/World/CScriptWater.cpp index e3da2c0f5..d001fbf78 100644 --- a/Runtime/World/CScriptWater.cpp +++ b/Runtime/World/CScriptWater.cpp @@ -12,14 +12,14 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { constexpr std::array kSplashScales{ 1.0f, 3.0f, 0.709f, 1.19f, 0.709f, 1.f, }; CScriptWater::CScriptWater( CStateManager& mgr, TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& pos, - const zeus::CAABox& box, const urde::CDamageInfo& dInfo, zeus::CVector3f& orientedForce, ETriggerFlags triggerFlags, + const zeus::CAABox& box, const metaforce::CDamageInfo& dInfo, zeus::CVector3f& orientedForce, ETriggerFlags triggerFlags, bool thermalCold, bool allowRender, CAssetId patternMap1, CAssetId patternMap2, CAssetId colorMap, CAssetId bumpMap, CAssetId envMap, CAssetId envBumpMap, CAssetId unusedMap, const zeus::CVector3f& bumpLightDir, float bumpScale, float morphInTime, float morphOutTime, bool active, EFluidType fluidType, bool b4, float alpha, @@ -601,4 +601,4 @@ bool CScriptWater::CanRippleAtPoint(const zeus::CVector3f& point) const { return x2d8_tileIntersects[yTile * x2c4_gridDimX + xTile]; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptWater.hpp b/Runtime/World/CScriptWater.hpp index 1089dc280..6511647ff 100644 --- a/Runtime/World/CScriptWater.hpp +++ b/Runtime/World/CScriptWater.hpp @@ -14,7 +14,7 @@ #include #include -namespace urde { +namespace metaforce { class CDamageInfo; class CFluidUVMotion; @@ -80,7 +80,7 @@ class CScriptWater : public CScriptTrigger { public: CScriptWater(CStateManager& mgr, TUniqueId uid, std::string_view name, const CEntityInfo& info, - const zeus::CVector3f& pos, const zeus::CAABox& box, const urde::CDamageInfo& dInfo, + const zeus::CVector3f& pos, const zeus::CAABox& box, const metaforce::CDamageInfo& dInfo, zeus::CVector3f& orientedForce, ETriggerFlags triggerFlags, bool thermalCold, bool allowRender, CAssetId patternMap1, CAssetId patternMap2, CAssetId colorMap, CAssetId bumpMap, CAssetId envMap, CAssetId envBumpMap, CAssetId unusedMap, const zeus::CVector3f& bumpLightDir, float bumpScale, @@ -137,4 +137,4 @@ public: bool CanRippleAtPoint(const zeus::CVector3f& point) const; const zeus::CColor& GetInsideFogColor() const { return x2a8_insideFogColor; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptWaypoint.cpp b/Runtime/World/CScriptWaypoint.cpp index 0171c0b58..16696bb4d 100644 --- a/Runtime/World/CScriptWaypoint.cpp +++ b/Runtime/World/CScriptWaypoint.cpp @@ -5,7 +5,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptWaypoint::CScriptWaypoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, float speed, float pause, @@ -68,4 +68,4 @@ TUniqueId CScriptWaypoint::NextWaypoint(CStateManager& mgr) const { return ids[int(mgr.GetActiveRandom()->Float() * ids.size() * 0.99f)]; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptWaypoint.hpp b/Runtime/World/CScriptWaypoint.hpp index 0963963a5..28dbcdab0 100644 --- a/Runtime/World/CScriptWaypoint.hpp +++ b/Runtime/World/CScriptWaypoint.hpp @@ -5,7 +5,7 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/World/CActor.hpp" -namespace urde { +namespace metaforce { class CScriptWaypoint : public CActor { float xe8_speed; @@ -38,4 +38,4 @@ public: u8 GetBehaviourOrient() const { return xf8_behaviourOrient; } u16 GetBehaviourModifiers() const { return xfa_behaviourModifiers; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptWorldTeleporter.cpp b/Runtime/World/CScriptWorldTeleporter.cpp index 160723b3a..08914c9a4 100644 --- a/Runtime/World/CScriptWorldTeleporter.cpp +++ b/Runtime/World/CScriptWorldTeleporter.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CScriptWorldTeleporter::CScriptWorldTeleporter(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, CAssetId worldId, CAssetId areaId) : CEntity(uid, info, active, name) @@ -123,4 +123,4 @@ void CScriptWorldTeleporter::StartTransition(CStateManager& mgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CScriptWorldTeleporter.hpp b/Runtime/World/CScriptWorldTeleporter.hpp index f6a13019c..02752e930 100644 --- a/Runtime/World/CScriptWorldTeleporter.hpp +++ b/Runtime/World/CScriptWorldTeleporter.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CScriptWorldTeleporter : public CEntity { enum class ETeleporterType { NoTransition, Elevator, Text }; @@ -46,4 +46,4 @@ public: void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) override; void StartTransition(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CSnakeWeedSwarm.cpp b/Runtime/World/CSnakeWeedSwarm.cpp index bca3f6772..aba624b43 100644 --- a/Runtime/World/CSnakeWeedSwarm.cpp +++ b/Runtime/World/CSnakeWeedSwarm.cpp @@ -13,7 +13,7 @@ #include "Runtime/World/CWorld.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static constexpr CMaterialFilter skMaterialFilter = CMaterialFilter::MakeInclude({EMaterialTypes::Solid}); @@ -77,7 +77,7 @@ CSnakeWeedSwarm::CSnakeWeedSwarm(TUniqueId uid, bool active, std::string_view na } } -void CSnakeWeedSwarm::Accept(urde::IVisitor& visitor) { visitor.Visit(this); } +void CSnakeWeedSwarm::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); } void CSnakeWeedSwarm::AllocateSkinnedModels(CStateManager& mgr, CModelData::EWhichModel which) { for (int i = 0; i < x1b0_modelData.size(); ++i) { @@ -437,4 +437,4 @@ std::optional CSnakeWeedSwarm::GetTouchBounds() const { return std::nullopt; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CSnakeWeedSwarm.hpp b/Runtime/World/CSnakeWeedSwarm.hpp index 2b40af53e..4b4ec94dd 100644 --- a/Runtime/World/CSnakeWeedSwarm.hpp +++ b/Runtime/World/CSnakeWeedSwarm.hpp @@ -5,7 +5,7 @@ #include "Runtime/World/CActor.hpp" #include "Runtime/World/CDamageInfo.hpp" -namespace urde { +namespace metaforce { class CAnimationParameters; class CSnakeWeedSwarm : public CActor { @@ -126,4 +126,4 @@ private: void EmitParticles2(const zeus::CVector3f& pos); void RenderBoid(u32 idx, const CBoid& boid, u32& posesToBuild) const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CStateMachine.cpp b/Runtime/World/CStateMachine.cpp index 9d2083988..2127ce4ca 100644 --- a/Runtime/World/CStateMachine.cpp +++ b/Runtime/World/CStateMachine.cpp @@ -3,8 +3,12 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/World/CAi.hpp" -namespace urde { -static logvisor::Module Log("urde::CStateMachine"); +#include + +namespace metaforce { +namespace { +logvisor::Module Log("metaforce::CStateMachine"); +} CStateMachine::CStateMachine(CInputStream& in) { CAiTrigger* lastTrig = nullptr; @@ -136,4 +140,4 @@ CFactoryFnReturn FAiFiniteStateMachineFactory(const SObjectTag& tag, CInputStrea return TToken::GetIObjObjectFor(std::make_unique(in)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CStateMachine.hpp b/Runtime/World/CStateMachine.hpp index 2445024a5..671030044 100644 --- a/Runtime/World/CStateMachine.hpp +++ b/Runtime/World/CStateMachine.hpp @@ -9,7 +9,7 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/World/CAiFuncMap.hpp" -namespace urde { +namespace metaforce { class CAiState; class CStateManager; @@ -117,4 +117,4 @@ public: CFactoryFnReturn FAiFiniteStateMachineFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference*); -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CTeamAiMgr.cpp b/Runtime/World/CTeamAiMgr.cpp index a084ca3be..3983e2a2c 100644 --- a/Runtime/World/CTeamAiMgr.cpp +++ b/Runtime/World/CTeamAiMgr.cpp @@ -7,7 +7,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { struct TeamAiRoleSorter { enum class Type { @@ -394,4 +394,4 @@ TUniqueId CTeamAiMgr::GetTeamAiMgr(const CAi& ai, const CStateManager& mgr) { return kInvalidUniqueId; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CTeamAiMgr.hpp b/Runtime/World/CTeamAiMgr.hpp index 782888ac3..4f7cdd7ea 100644 --- a/Runtime/World/CTeamAiMgr.hpp +++ b/Runtime/World/CTeamAiMgr.hpp @@ -5,7 +5,7 @@ #include -namespace urde { +namespace metaforce { class CStateManager; class CAi; @@ -119,4 +119,4 @@ public: static TUniqueId GetTeamAiMgr(const CAi& ai, const CStateManager& mgr); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CTeamAiTypes.hpp b/Runtime/World/CTeamAiTypes.hpp index 1b1cc9dbf..4fa5c13c9 100644 --- a/Runtime/World/CTeamAiTypes.hpp +++ b/Runtime/World/CTeamAiTypes.hpp @@ -1,7 +1,7 @@ #pragma once -namespace urde { +namespace metaforce { class CTeamAiTypes {}; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CVisorFlare.cpp b/Runtime/World/CVisorFlare.cpp index 0e46e3e8f..050d6baae 100644 --- a/Runtime/World/CVisorFlare.cpp +++ b/Runtime/World/CVisorFlare.cpp @@ -7,7 +7,7 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/CSimplePool.hpp" -namespace urde { +namespace metaforce { std::optional CVisorFlare::LoadFlareDef(CInputStream& in) { u32 propCount = in.readUint32Big(); @@ -96,4 +96,4 @@ void CVisorFlare::Render(const zeus::CVector3f& pos, const CStateManager& mgr) c } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CVisorFlare.hpp b/Runtime/World/CVisorFlare.hpp index c60beab6d..821b9f1c9 100644 --- a/Runtime/World/CVisorFlare.hpp +++ b/Runtime/World/CVisorFlare.hpp @@ -8,7 +8,7 @@ #include -namespace urde { +namespace metaforce { class CActor; class CStateManager; class CTexture; @@ -57,4 +57,4 @@ public: static std::optional LoadFlareDef(CInputStream& in); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CVisorParameters.hpp b/Runtime/World/CVisorParameters.hpp index ef248ed19..8e6a8e161 100644 --- a/Runtime/World/CVisorParameters.hpp +++ b/Runtime/World/CVisorParameters.hpp @@ -2,7 +2,7 @@ #include "Runtime/GCNTypes.hpp" -namespace urde { +namespace metaforce { class CVisorParameters { public: @@ -15,4 +15,4 @@ public: u8 GetMask() const { return x0_mask; } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWallCrawlerSwarm.cpp b/Runtime/World/CWallCrawlerSwarm.cpp index 65a8242bc..0296e660e 100644 --- a/Runtime/World/CWallCrawlerSwarm.cpp +++ b/Runtime/World/CWallCrawlerSwarm.cpp @@ -23,7 +23,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { static CMaterialList MakeMaterialList() { return CMaterialList(EMaterialTypes::Scannable, EMaterialTypes::Trigger, EMaterialTypes::NonSolidDamageable, @@ -1243,4 +1243,4 @@ void CWallCrawlerSwarm::ApplyRadiusDamage(const zeus::CVector3f& pos, const CDam } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWallCrawlerSwarm.hpp b/Runtime/World/CWallCrawlerSwarm.hpp index d5157443d..661311e23 100644 --- a/Runtime/World/CWallCrawlerSwarm.hpp +++ b/Runtime/World/CWallCrawlerSwarm.hpp @@ -17,7 +17,7 @@ #include #include -namespace urde { +namespace metaforce { class CAreaCollisionCache; class CWallCrawlerSwarm : public CActor { public: @@ -202,4 +202,4 @@ public: bool GetLockOnLocationValid(int id) const { return id >= 0 && id < x108_boids.size() && x108_boids[id].GetActive(); } const zeus::CVector3f& GetLockOnLocation(int id) const { return x108_boids[id].GetTranslation(); } }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWallWalker.cpp b/Runtime/World/CWallWalker.cpp index 673150ef6..739d21964 100644 --- a/Runtime/World/CWallWalker.cpp +++ b/Runtime/World/CWallWalker.cpp @@ -8,7 +8,7 @@ #include "TCastTo.hpp" // Generated file, do not modify include path -namespace urde { +namespace metaforce { CWallWalker::CWallWalker(ECharacter chr, TUniqueId uid, std::string_view name, EFlavorType flavType, const CEntityInfo& eInfo, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, EMovementType mType, EColliderType colType, EBodyType bType, @@ -180,4 +180,4 @@ void CWallWalker::UpdateWPDestination(CStateManager& mgr) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWallWalker.hpp b/Runtime/World/CWallWalker.hpp index 21428b5bc..63ff20aed 100644 --- a/Runtime/World/CWallWalker.hpp +++ b/Runtime/World/CWallWalker.hpp @@ -9,7 +9,7 @@ #include -namespace urde { +namespace metaforce { class CWallWalker : public CPatterned { public: enum class EWalkerType { Parasite = 0, Oculus = 1, Geemer = 2, IceZoomer = 3, Seedling = 4 }; @@ -58,4 +58,4 @@ public: const CCollisionPrimitive* GetCollisionPrimitive() const override { return &x590_colSphere; } void UpdateWPDestination(CStateManager&); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWorld.cpp b/Runtime/World/CWorld.cpp index 616bb880a..9a46ee779 100644 --- a/Runtime/World/CWorld.cpp +++ b/Runtime/World/CWorld.cpp @@ -14,7 +14,7 @@ #include "Runtime/World/CScriptAreaAttributes.hpp" #include "Runtime/World/CScriptRoomAcoustics.hpp" -namespace urde { +namespace metaforce { CWorld::CSoundGroupData::CSoundGroupData(int grpId, CAssetId agsc) : x0_groupId(grpId), x4_agscId(agsc) { x1c_groupData = g_SimplePool->GetObj(SObjectTag{FOURCC('AGSC'), agsc}); @@ -723,4 +723,4 @@ TAreaId CWorld::GetAreaIdForSaveId(s32 saveId) const { return TAreaId(std::distance(x18_areas.cbegin(), iter)); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWorld.hpp b/Runtime/World/CWorld.hpp index 586474632..ae6951c79 100644 --- a/Runtime/World/CWorld.hpp +++ b/Runtime/World/CWorld.hpp @@ -15,7 +15,7 @@ #include "Runtime/World/CGameArea.hpp" #include "Runtime/World/ScriptObjectSupport.hpp" -namespace urde { +namespace metaforce { class CGameArea; class CResFactory; class IGameArea; @@ -225,4 +225,4 @@ struct CWorldLayers { static void ReadWorldLayers(athena::io::MemoryReader& r, int version, CAssetId mlvlId); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWorldLight.cpp b/Runtime/World/CWorldLight.cpp index e47165e9d..218a1d6c1 100644 --- a/Runtime/World/CWorldLight.cpp +++ b/Runtime/World/CWorldLight.cpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { CWorldLight::CWorldLight(CInputStream& in) : x0_type(EWorldLightType(in.readUint32Big())) , x4_color(zeus::CVector3f::ReadBig(in)) @@ -67,4 +67,4 @@ CLight CWorldLight::GetAsCGraphicsLight() const { zeus::CColor{x4_color.x(), x4_color.y(), x4_color.z(), 1.f}, distC, distL, distQ, 1.f, 0.f, 0.f); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWorldLight.hpp b/Runtime/World/CWorldLight.hpp index 4302617c2..00d088397 100644 --- a/Runtime/World/CWorldLight.hpp +++ b/Runtime/World/CWorldLight.hpp @@ -3,7 +3,7 @@ #include "Runtime/Graphics/CLight.hpp" #include -namespace urde { +namespace metaforce { class CWorldLight { public: enum class EWorldLightType { @@ -45,4 +45,4 @@ public: CLight GetAsCGraphicsLight() const; }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWorldShadow.cpp b/Runtime/World/CWorldShadow.cpp index b3ba176d6..6d6660bf0 100644 --- a/Runtime/World/CWorldShadow.cpp +++ b/Runtime/World/CWorldShadow.cpp @@ -4,7 +4,7 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { +namespace metaforce { CWorldShadow::CWorldShadow(u32 w, u32 h, bool rgba8) : m_shader(w, h) {} @@ -112,4 +112,4 @@ void CWorldShadow::BuildLightShadowTexture(const CStateManager& mgr, TAreaId aid void CWorldShadow::ResetBlur() { x88_blurReset = true; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWorldShadow.hpp b/Runtime/World/CWorldShadow.hpp index 993f5389b..6c0e91ed4 100644 --- a/Runtime/World/CWorldShadow.hpp +++ b/Runtime/World/CWorldShadow.hpp @@ -9,7 +9,7 @@ #define CWORLDSHADOW_FEEDBACK 0 -namespace urde { +namespace metaforce { class CStateManager; class CWorldShadow { @@ -34,4 +34,4 @@ public: void ResetBlur(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWorldTransManager.cpp b/Runtime/World/CWorldTransManager.cpp index f577fc3ff..ff5f52c53 100644 --- a/Runtime/World/CWorldTransManager.cpp +++ b/Runtime/World/CWorldTransManager.cpp @@ -18,7 +18,7 @@ #include -namespace urde { +namespace metaforce { int CWorldTransManager::GetSuitCharIdx() { CPlayerState& state = *g_GameState->GetPlayerState(); @@ -491,4 +491,4 @@ void CWorldTransManager::SfxStart() { x28_sfxHandle = CSfxManager::SfxStart(x24_sfx, x2c_volume, x2d_panning, false, 127, true, -1); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/CWorldTransManager.hpp b/Runtime/World/CWorldTransManager.hpp index b91804443..9a62d1140 100644 --- a/Runtime/World/CWorldTransManager.hpp +++ b/Runtime/World/CWorldTransManager.hpp @@ -20,7 +20,7 @@ #include #include -namespace urde { +namespace metaforce { class CSimplePool; class CWorldTransManager { @@ -127,4 +127,4 @@ public: static bool WaitForModelsAndTextures(); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/IGameArea.cpp b/Runtime/World/IGameArea.cpp index c3ad19ff7..82f98e1d9 100644 --- a/Runtime/World/IGameArea.cpp +++ b/Runtime/World/IGameArea.cpp @@ -1,7 +1,7 @@ #include "Runtime/World/IGameArea.hpp" -namespace urde { -IGameArea::Dock::Dock(urde::CInputStream& in, const zeus::CTransform& xf) { +namespace metaforce { +IGameArea::Dock::Dock(metaforce::CInputStream& in, const zeus::CTransform& xf) { u32 refCount = in.readUint32Big(); x4_dockReferences.reserve(refCount); for (u32 i = 0; i < refCount; i++) { @@ -61,4 +61,4 @@ zeus::CVector3f IGameArea::Dock::GetPoint(s32 idx) const { return x14_planeVertices[idx]; } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/IGameArea.hpp b/Runtime/World/IGameArea.hpp index 9eb2c870b..97081dce1 100644 --- a/Runtime/World/IGameArea.hpp +++ b/Runtime/World/IGameArea.hpp @@ -10,7 +10,7 @@ #include #include -namespace urde { +namespace metaforce { class CEntity; class IGameArea { @@ -49,7 +49,7 @@ public: }; virtual std::pair, s32> IGetScriptingMemoryAlways() const = 0; - virtual TAreaId IGetAreaId() const = 0; + virtual s32 IGetAreaSaveId() const = 0; virtual CAssetId IGetAreaAssetId() const = 0; virtual bool IIsActive() const = 0; virtual TAreaId IGetAttachedAreaId(int) const = 0; @@ -67,4 +67,4 @@ enum class EChain { AliveJudgement, }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 5638b3266..9735f2023 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -31,6 +31,7 @@ #include "Runtime/MP1/World/CDrone.hpp" #include "Runtime/MP1/World/CMetroid.hpp" #include "Runtime/MP1/World/CMetroidBeta.hpp" +#include "Runtime/MP1/World/CMetroidPrimeEssence.hpp" #include "Runtime/MP1/World/CMetroidPrimeRelay.hpp" #include "Runtime/MP1/World/CNewIntroBoss.hpp" #include "Runtime/MP1/World/COmegaPirate.hpp" @@ -127,8 +128,8 @@ #include "Runtime/World/CWallCrawlerSwarm.hpp" #include "Runtime/World/CWorld.hpp" -namespace urde { -static logvisor::Module Log("urde::ScriptLoader"); +namespace metaforce { +static logvisor::Module Log("metaforce::ScriptLoader"); constexpr SObjectTag MorphballDoorANCS = {FOURCC('ANCS'), 0x1F9DA858}; @@ -3693,10 +3694,32 @@ CEntity* ScriptLoader::LoadWorldLightFader(CStateManager& mgr, CInputStream& in, 0.f, zeus::skZero2f, false, active, 0.f, 0.f, f1, f2); } -CEntity* ScriptLoader::LoadMetroidPrimeStage2(CStateManager& mgr, CInputStream& in, int propCount, - const CEntityInfo& info) { - return nullptr; -} +CEntity* ScriptLoader::LoadMetroidPrimeEssence(CStateManager& mgr, CInputStream& in, int propCount, + const CEntityInfo& info) { + if (!EnsurePropertyCount(propCount, 11, "MetroidPrimeEssence")) { + return nullptr; + } + + SScaledActorHead aHead = LoadScaledActorHead(in, mgr); + auto [valid, pInfoPropCount] = CPatternedInfo::HasCorrectParameterCount(in); + if (!valid) { + return nullptr; + } + CPatternedInfo pInfo{in, pInfoPropCount}; + CActorParameters actParms = LoadActorParameters(in); + CAssetId particle1{in}; + CDamageInfo dInfo{in}; + CAssetId electric{in}; + u32 w3 = in.readUint32Big(); + CAssetId particle2{in}; + + const CAnimationParameters& animParms = pInfo.GetAnimationParameters(); + CModelData mData{CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), aHead.x40_scale, + animParms.GetInitialAnimation(), true)}; + return new MP1::CMetroidPrimeEssence(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, + std::move(mData), pInfo, actParms, particle1, dInfo, aHead.x40_scale.y(), + electric, w3, particle2); +}; CEntity* ScriptLoader::LoadMetroidPrimeStage1(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { @@ -3907,4 +3930,4 @@ CEntity* ScriptLoader::LoadEnergyBall(CStateManager& mgr, CInputStream& in, int std::move(mData), actParms, pInfo, w1, f1, dInfo1, f2, a1, sfxId1, a2, a3, sfxId2, f3, f4, a4, dInfo2, f5); } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/ScriptLoader.hpp b/Runtime/World/ScriptLoader.hpp index 86d6cea48..c85134f92 100644 --- a/Runtime/World/ScriptLoader.hpp +++ b/Runtime/World/ScriptLoader.hpp @@ -5,7 +5,7 @@ #include #include -namespace urde { +namespace metaforce { class CActorParameters; class CAnimationParameters; class CCameraShakeData; @@ -154,7 +154,7 @@ public: static CEntity* LoadBurrower(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadBeam(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadWorldLightFader(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); - static CEntity* LoadMetroidPrimeStage2(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); + static CEntity* LoadMetroidPrimeEssence(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadMetroidPrimeStage1(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadMazeNode(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadOmegaPirate(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); @@ -165,4 +165,4 @@ public: static CEntity* LoadEnergyBall(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); }; -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/ScriptObjectSupport.cpp b/Runtime/World/ScriptObjectSupport.cpp index 45be31f16..2967f2178 100644 --- a/Runtime/World/ScriptObjectSupport.cpp +++ b/Runtime/World/ScriptObjectSupport.cpp @@ -2,7 +2,7 @@ using namespace std::literals; -namespace urde { +namespace metaforce { std::string_view ScriptObjectTypeToStr(EScriptObjectType type) { switch (type) { @@ -443,4 +443,4 @@ std::string_view ScriptObjectMessageToStr(EScriptObjectMessage message) { } } -} // namespace urde +} // namespace metaforce diff --git a/Runtime/World/ScriptObjectSupport.hpp b/Runtime/World/ScriptObjectSupport.hpp index 5af019a04..0284d81a3 100644 --- a/Runtime/World/ScriptObjectSupport.hpp +++ b/Runtime/World/ScriptObjectSupport.hpp @@ -2,7 +2,7 @@ #include -namespace urde { +namespace metaforce { enum class EScriptObjectType { Actor = 0x00, @@ -229,4 +229,4 @@ std::string_view ScriptObjectTypeToStr(EScriptObjectType type); std::string_view ScriptObjectStateToStr(EScriptObjectState state); std::string_view ScriptObjectMessageToStr(EScriptObjectMessage message); -} // namespace urde +} // namespace metaforce diff --git a/Shaders/CMakeLists.txt b/Shaders/CMakeLists.txt index deaa035be..73ba1eb03 100644 --- a/Shaders/CMakeLists.txt +++ b/Shaders/CMakeLists.txt @@ -1,46 +1,65 @@ -include_directories(../hecl/include - ../hecl/extern/boo/include - ../hecl/extern/athena/include - ../specter/zeus/include - ../nod/include - ../nod/logvisor/include - ../nod/logvisor/fmt/include - ../DataSpec - ../Runtime - ..) -add_compile_definitions(ZE_ATHENA_TYPES=1) add_shader(CAABoxShader) +target_link_libraries(shader_CAABoxShader PRIVATE hecl-light) add_shader(CCameraBlurFilter) +target_link_libraries(shader_CCameraBlurFilter PRIVATE hecl-light) add_shader(CColoredQuadFilter) +target_link_libraries(shader_CColoredQuadFilter PRIVATE hecl-light) add_shader(CColoredStripShader) +target_link_libraries(shader_CColoredStripShader PRIVATE hecl-light) add_shader(CDecalShaders) +target_link_libraries(shader_CDecalShaders PRIVATE hecl-light) add_shader(CElementGenShaders) +target_link_libraries(shader_CElementGenShaders PRIVATE hecl-light) add_shader(CEnergyBarShader) +target_link_libraries(shader_CEnergyBarShader PRIVATE hecl-light) add_shader(CEnvFxShaders) +target_link_libraries(shader_CEnvFxShaders PRIVATE hecl-light) add_shader(CFogVolumeFilter) +target_link_libraries(shader_CFogVolumeFilter PRIVATE hecl-light) add_shader(CFogVolumePlaneShader) +target_link_libraries(shader_CFogVolumePlaneShader PRIVATE hecl-light) add_shader(CLineRendererShaders) +target_link_libraries(shader_CLineRendererShaders PRIVATE hecl-light) add_shader(CMapSurfaceShader) +target_link_libraries(shader_CMapSurfaceShader PRIVATE hecl-light) add_shader(CMoviePlayerShader) +target_link_libraries(shader_CMoviePlayerShader PRIVATE hecl-light) add_shader(CNESShader) +target_link_libraries(shader_CNESShader PRIVATE hecl-light) add_shader(CParticleSwooshShaders) +target_link_libraries(shader_CParticleSwooshShaders PRIVATE hecl-light) add_shader(CPhazonSuitFilter) +target_link_libraries(shader_CPhazonSuitFilter PRIVATE hecl-light) add_shader(CRadarPaintShader) +target_link_libraries(shader_CRadarPaintShader PRIVATE hecl-light) add_shader(CRandomStaticFilter) +target_link_libraries(shader_CRandomStaticFilter PRIVATE hecl-light) add_shader(CScanLinesFilter) +target_link_libraries(shader_CScanLinesFilter PRIVATE hecl-light) add_shader(CSpaceWarpFilter) +target_link_libraries(shader_CSpaceWarpFilter PRIVATE hecl-light) add_shader(CTextSupportShader) +target_link_libraries(shader_CTextSupportShader PRIVATE hecl-light) add_shader(CTexturedQuadFilter) +target_link_libraries(shader_CTexturedQuadFilter PRIVATE hecl-light) add_shader(CThermalColdFilter) +target_link_libraries(shader_CThermalColdFilter PRIVATE hecl-light) add_shader(CThermalHotFilter) +target_link_libraries(shader_CThermalHotFilter PRIVATE hecl-light) add_shader(CWorldShadowShader) +target_link_libraries(shader_CWorldShadowShader PRIVATE hecl-light) add_shader(CXRayBlurFilter) +target_link_libraries(shader_CXRayBlurFilter PRIVATE hecl-light) add_special_shader(shader_CFluidPlaneShader shader_CFluidPlaneShader.cpp shader_CFluidPlaneShaderGLSL.cpp shader_CFluidPlaneShaderHLSL.cpp shader_CFluidPlaneShaderMetal.cpp) +target_link_libraries(shader_CFluidPlaneShader PRIVATE hecl-light) add_special_shader(shader_CModelShaders shader_CModelShadersGLSL.cpp shader_CModelShadersHLSL.cpp - shader_CModelShadersMetal.cpp) \ No newline at end of file + shader_CModelShadersMetal.cpp) +target_link_libraries(shader_CModelShaders PRIVATE hecl-light nod) +# FIXME hack for DataSpec includes +target_include_directories(shader_CModelShaders PRIVATE ${CMAKE_SOURCE_DIR}) \ No newline at end of file diff --git a/Shaders/CModelShaders.frag.glsl b/Shaders/CModelShaders.frag.glsl index 8cc8cdeb5..e9612afc5 100644 --- a/Shaders/CModelShaders.frag.glsl +++ b/Shaders/CModelShaders.frag.glsl @@ -146,7 +146,7 @@ vec3 LightingFunc() { } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) vec3 LightingFunc() { return vec3(1.0); } @@ -156,7 +156,7 @@ UBINDING2 uniform ThermalUniform { }; #endif -#if defined(URDE_THERMAL_COLD) +#if defined(URDE_THERMAL_COLD) || defined(URDE_THERMAL_STATIC) vec3 LightingFunc() { return vec3(1.0); } @@ -268,7 +268,7 @@ vec4 PostFunc(vec4 colorIn) { } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) vec4 PostFunc(vec4 colorIn) { return texture(extTex0, vtf.extUvs[0]).rrrr * tmulColor + taddColor; } @@ -280,6 +280,12 @@ vec4 PostFunc(vec4 colorIn) { } #endif +#if defined(URDE_THERMAL_STATIC) +vec4 PostFunc(vec4 colorIn) { + return colorIn; +} +#endif + #if defined(URDE_SOLID) vec4 PostFunc(vec4 colorIn) { return solidColor; diff --git a/Shaders/CModelShaders.frag.hlsl b/Shaders/CModelShaders.frag.hlsl index 4319dd212..d59f44185 100644 --- a/Shaders/CModelShaders.frag.hlsl +++ b/Shaders/CModelShaders.frag.hlsl @@ -145,7 +145,7 @@ float3 LightingFunc(in VertToFrag vtf) { } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) float3 LightingFunc(in VertToFrag vtf) { return float3(1.0, 1.0, 1.0); } @@ -155,7 +155,7 @@ cbuffer ThermalUniform : register(b2) { }; #endif -#if defined(URDE_THERMAL_COLD) +#if defined(URDE_THERMAL_COLD) || defined(URDE_THERMAL_STATIC) float3 LightingFunc(in VertToFrag vtf) { return float3(1.0, 1.0, 1.0); } @@ -267,7 +267,7 @@ float4 PostFunc(in VertToFrag vtf, float4 colorIn) { } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) float4 PostFunc(in VertToFrag vtf, float4 colorIn) { return extTex0.Sample(samp, vtf.extUvs[0]).rrrr * tmulColor + taddColor; } @@ -279,6 +279,12 @@ float4 PostFunc(in VertToFrag vtf, float4 colorIn) { } #endif +#if defined(URDE_THERMAL_STATIC) +float4 PostFunc(in VertToFrag vtf, float4 colorIn) { + return colorIn; +} +#endif + #if defined(URDE_SOLID) float4 PostFunc(in VertToFrag vtf, float4 colorIn) { return solidColor; diff --git a/Shaders/CModelShaders.frag.metal b/Shaders/CModelShaders.frag.metal index 08065600e..679e02f92 100644 --- a/Shaders/CModelShaders.frag.metal +++ b/Shaders/CModelShaders.frag.metal @@ -126,7 +126,7 @@ float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, textur } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) struct LightingUniform { float4 tmulColor; float4 taddColor; @@ -136,7 +136,7 @@ float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, textur } #endif -#if defined(URDE_THERMAL_COLD) +#if defined(URDE_THERMAL_COLD) || defined(URDE_THERMAL_STATIC) struct LightingUniform {}; float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { return float3(1.0, 1.0, 1.0); @@ -251,7 +251,7 @@ float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, texture2d extTex1, texture2d extTex2, sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { @@ -267,6 +267,14 @@ float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, } #endif +#if defined(URDE_THERMAL_STATIC) +float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, + texture2d extTex0, texture2d extTex1, texture2d extTex2, + sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { + return colorIn; +} +#endif + #if defined(URDE_SOLID) float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, texture2d extTex1, texture2d extTex2, diff --git a/Shaders/CPhazonSuitFilter.shader b/Shaders/CPhazonSuitFilter.shader index ccd688db2..f18de24fa 100644 --- a/Shaders/CPhazonSuitFilter.shader +++ b/Shaders/CPhazonSuitFilter.shader @@ -264,6 +264,13 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #attribute uv4 #srcfac one #dstfac zero +#colorwrite false +#alphawrite true +#depthwrite false +#culling none +#depthtest none +#primitive tristrips +#overwritealpha true #vertex glsl layout(location=0) in vec4 posIn; diff --git a/Shaders/shader_CFluidPlaneShaderGLSL.cpp b/Shaders/shader_CFluidPlaneShaderGLSL.cpp index 7e7e218f4..12011089d 100644 --- a/Shaders/shader_CFluidPlaneShaderGLSL.cpp +++ b/Shaders/shader_CFluidPlaneShaderGLSL.cpp @@ -328,7 +328,10 @@ static std::string _BuildFS(const SFluidPlaneShaderInfo& info) { std::stringstream out; int nextTex = 0; int nextTCG = 3; - int bumpMapUv, envBumpMapUv, envMapUv, lightmapUv; + int bumpMapUv = -1; + int envBumpMapUv = -1; + int envMapUv = -1; + int lightmapUv = -1; out << "#define TEXTURE_DECLS "; if (info.m_hasPatternTex1) diff --git a/Shaders/shader_CFluidPlaneShaderHLSL.cpp b/Shaders/shader_CFluidPlaneShaderHLSL.cpp index ebf81e869..824936bf9 100644 --- a/Shaders/shader_CFluidPlaneShaderHLSL.cpp +++ b/Shaders/shader_CFluidPlaneShaderHLSL.cpp @@ -364,7 +364,10 @@ static std::string _BuildFS(const SFluidPlaneShaderInfo& info) { int nextTex = 0; int nextTCG = 3; int nextMtx = 4; - int bumpMapUv, envBumpMapUv, envMapUv, lightmapUv; + int bumpMapUv = -1; + int envBumpMapUv = -1; + int envMapUv = -1; + int lightmapUv = -1; out << "#define TEXTURE_DECLS "; if (info.m_hasPatternTex1) diff --git a/Shaders/shader_CFluidPlaneShaderMetal.cpp b/Shaders/shader_CFluidPlaneShaderMetal.cpp index 728d580a3..035d00c50 100644 --- a/Shaders/shader_CFluidPlaneShaderMetal.cpp +++ b/Shaders/shader_CFluidPlaneShaderMetal.cpp @@ -362,7 +362,10 @@ static std::string _BuildFS(const SFluidPlaneShaderInfo& info) { std::stringstream out; int nextTex = 0; int nextTCG = 3; - int bumpMapUv, envBumpMapUv, envMapUv, lightmapUv; + int bumpMapUv = -1; + int envBumpMapUv = -1; + int envMapUv = -1; + int lightmapUv = -1; out << "#define TEXTURE_PARAMS "; if (info.m_hasPatternTex1) diff --git a/amuse b/amuse deleted file mode 160000 index fe04c9a13..000000000 --- a/amuse +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fe04c9a137705f2c44f487222a05ee6b6e18d89d diff --git a/assetnameparser/CMakeLists.txt b/assetnameparser/CMakeLists.txt index a088a485b..5249d8428 100644 --- a/assetnameparser/CMakeLists.txt +++ b/assetnameparser/CMakeLists.txt @@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) # because of c++17 set(TINYXML_LIB_VERSION "5.0.1") set(TINYXML_LIB_SOVERSION "5") -add_library(tinyxml2_static STATIC tinyxml2/tinyxml2.cpp tinyxml2/tinyxml2.h) +add_library(tinyxml2_static STATIC + "${CMAKE_SOURCE_DIR}/extern/tinyxml2/tinyxml2.cpp" + "${CMAKE_SOURCE_DIR}/extern/tinyxml2/tinyxml2.h") +target_include_directories(tinyxml2_static INTERFACE "${CMAKE_SOURCE_DIR}/extern") set_target_properties(tinyxml2_static PROPERTIES COMPILE_DEFINITONS "TINYXML2_EXPORT" VERSION "${TINYXML_LIB_VERSION}" diff --git a/assetnameparser/main.cpp b/assetnameparser/main.cpp index 0a4d8d3a8..3b178cf9c 100644 --- a/assetnameparser/main.cpp +++ b/assetnameparser/main.cpp @@ -2,9 +2,10 @@ #include #include #include +#include -#include #include "tinyxml2/tinyxml2.h" +#include #ifndef _WIN32 #include @@ -33,6 +34,51 @@ #endif namespace { + +uint32_t crc32(const uint8_t * data, uint64_t length, uint32_t seed, uint32_t final) { + static const uint32_t crc32Table[256] = { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, + 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, + 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, + 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, + 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, + 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, + 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, + 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, + 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, + 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, + 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, + 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, + 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, + 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, + 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, + 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, + 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, + 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, + 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, + 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, + 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, + 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D}; + + if (!data) + return seed; + + uint32_t checksum = seed; + int pos = 0; + + while (length--) + checksum = (checksum >> 8) ^ crc32Table[(checksum & 0xFF) ^ data[pos++]]; + + return checksum ^ final; +} + logvisor::Module Log("AssetNameParser"); // TODO: Clean this up @@ -186,6 +232,43 @@ FILEPtr Fopen(const SystemChar* path, const SystemChar* mode, FileLockType lock } } // Anonymous namespace +std::string getValidExtension(const std::string& type) { + if (type == "ANIM") { + return "ani"; + } + if (type == "ANCS") { + return "acs"; + } + if (type == "PART") { + return "gpsm.part"; + } + if (type == "ELSC") { + return "elsm.elsc"; + } + if (type == "SWHC") { + return "swsh.swhc"; + } + if (type == "DPSC") { + return "dpsm.dpsc"; + } + if (type == "CRSC") { + return "crsm.crsc"; + } + if (type == "WPSC") { + return "wpsm.wpsc"; + } + if (type == "FONT") { + return "rpff"; + } + if (type == "MLVL") { + return "mwld"; + } + if (type == "CINF") { + return "cin"; + } + return type; +} + #if _WIN32 int wmain(int argc, const wchar_t* argv[]) #else @@ -239,12 +322,18 @@ int main(int argc, const char* argv[]) Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Malformed Value entry, [Name,Directory,Type] required"))); return 0; } - assets.emplace_back(); bool autoGen = strncasecmp(autoGenNameElm->GetText(), "true", 4) == 0 && strncasecmp(autoGenDirElm->GetText(), "true", 4) == 0; - if (!autoGen) { - SAsset& asset = assets.back(); + uint64_t id = strtoull(keyElm->GetText(), nullptr, 16); + std::string dir = dirElm->GetText(); + std::string name = nameElm->GetText(); + std::string type = typeElm->GetText(); + std::string projPath = "$/" + dir + name + "." + getValidExtension(type); + std::transform(projPath.begin(), projPath.end(), projPath.begin(), [](unsigned char c) -> unsigned char { return std::tolower(c); }); + uint32_t tmpId = crc32(reinterpret_cast(projPath.c_str()), projPath.length(), 0xFFFFFFFF, 0); + if (!autoGen || tmpId == id) { + SAsset& asset = assets.emplace_back(); asset.type = typeElm->GetText(); - asset.id = strtoull(keyElm->GetText(), nullptr, 16); + asset.id = id; asset.name = nameElm->GetText(); asset.dir = dirElm->GetText(); } @@ -259,12 +348,12 @@ int main(int argc, const char* argv[]) uint32_t assetCount = SBig(uint32_t(assets.size())); FourCC sentinel(SBIG('AIDM')); - fwrite(&sentinel, sizeof(sentinel), 1, f.get()); - fwrite(&assetCount, sizeof(assetCount), 1, f.get()); + fwrite(&sentinel, sizeof(FourCC), 1, f.get()); + fwrite(&assetCount, sizeof(uint32_t), 1, f.get()); for (const SAsset& asset : assets) { fwrite(&asset.type, sizeof(asset.type), 1, f.get()); uint64_t id = SBig(asset.id); - fwrite(&id, sizeof(id), 1, f.get()); + fwrite(&id, sizeof(uint64_t), 1, f.get()); uint32_t tmp = SBig(uint32_t(asset.name.length())); fwrite(&tmp, sizeof(tmp), 1, f.get()); fwrite(asset.name.c_str(), 1, SBig(tmp), f.get()); diff --git a/assetnameparser/tinyxml2 b/assetnameparser/tinyxml2 deleted file mode 160000 index c1f1de724..000000000 --- a/assetnameparser/tinyxml2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c1f1de724f5b1b82dca54c9ce6cc3ba130243949 diff --git a/ci/build-appimage.sh b/ci/build-appimage.sh new file mode 100755 index 000000000..8614dde33 --- /dev/null +++ b/ci/build-appimage.sh @@ -0,0 +1,13 @@ +#!/bin/bash -ex + +# Get linuxdeploy +curl -OL https://github.com/encounter/linuxdeploy/releases/download/continuous/linuxdeploy-$(uname -m).AppImage +curl -OL https://github.com/encounter/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-$(uname -m).AppImage +chmod +x linuxdeploy-$(uname -m).AppImage linuxdeploy-plugin-qt-$(uname -m).AppImage + +# Build AppImage +mkdir -p appdir/usr/{bin,share/{applications,icons/hicolor}} +cp build/Binaries/{hecl,metaforce-gui,metaforce,visigen} appdir/usr/bin +cp -r metaforce-gui/platforms/freedesktop/{16x16,32x32,48x48,64x64,128x128,256x256,512x512,1024x1024} appdir/usr/share/icons/hicolor +cp metaforce-gui/platforms/freedesktop/metaforce.desktop appdir/usr/share/applications +VERSION="$METAFORCE_VERSION" NO_STRIP=1 ./linuxdeploy-$(uname -m).AppImage --appdir appdir --plugin qt --output appimage diff --git a/ci/build-dmg.sh b/ci/build-dmg.sh new file mode 100755 index 000000000..864f29428 --- /dev/null +++ b/ci/build-dmg.sh @@ -0,0 +1,11 @@ +#!/bin/bash -ex +cd build/Binaries +mv metaforce-gui.app Metaforce.app +# order is important +for i in visigen hecl metaforce crashpad_handler; do + codesign --timestamp --options runtime -s "$CODESIGN_IDENT" Metaforce.app/Contents/MacOS/$i +done +macdeployqt Metaforce.app -sign-for-notarization="$CODESIGN_IDENT" -no-strip +create-dmg Metaforce.app --identity="$CODESIGN_IDENT" "$GITHUB_WORKSPACE" +xcrun altool -t osx -f "$GITHUB_WORKSPACE"/*.dmg --primary-bundle-id com.axiodl.URDE --notarize-app \ + -u "$ASC_USERNAME" -p "$ASC_PASSWORD" --team-id "$ASC_TEAM_ID" \ No newline at end of file diff --git a/ci/split-debug-linux.sh b/ci/split-debug-linux.sh new file mode 100755 index 000000000..91f551bea --- /dev/null +++ b/ci/split-debug-linux.sh @@ -0,0 +1,7 @@ +#!/bin/bash -ex +cd build/Binaries +for f in hecl metaforce-gui metaforce visigen; do + objcopy --only-keep-debug $f $f.dbg + objcopy --strip-debug --add-gnu-debuglink=$f.dbg $f +done +tar acfv "$GITHUB_WORKSPACE"/debug.tar.xz -- *.dbg \ No newline at end of file diff --git a/ci/upload-debug-linux.sh b/ci/upload-debug-linux.sh new file mode 100755 index 000000000..2fbf9b9eb --- /dev/null +++ b/ci/upload-debug-linux.sh @@ -0,0 +1,2 @@ +#!/bin/bash -ex +sentry-cli upload-dif --org axiodl --project metaforce {hecl,metaforce-gui,metaforce,visigen}{,.dbg} --include-sources diff --git a/ci/upload-debug-macos.sh b/ci/upload-debug-macos.sh new file mode 100755 index 000000000..528d8bbc8 --- /dev/null +++ b/ci/upload-debug-macos.sh @@ -0,0 +1,9 @@ +#!/bin/bash -ex +cd build/Binaries/metaforce-gui.app/Contents/MacOS +for f in hecl metaforce-gui metaforce visigen; do + dsymutil $f + strip -S $f +done +sentry-cli upload-dif --org axiodl --project metaforce {hecl,metaforce-gui,metaforce,visigen}{,.dSYM} --include-sources +tar acfv "$GITHUB_WORKSPACE"/debug.tar.xz -- *.dSYM +rm -r -- *.dSYM diff --git a/discord-rpc b/discord-rpc deleted file mode 160000 index e6390c8c4..000000000 --- a/discord-rpc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e6390c8c4190b59f1cc98bcec688e0037b84974d diff --git a/extern/amuse b/extern/amuse new file mode 160000 index 000000000..4e07b3b68 --- /dev/null +++ b/extern/amuse @@ -0,0 +1 @@ +Subproject commit 4e07b3b685f75e01d370412daaf758bf284238b1 diff --git a/extern/athena b/extern/athena new file mode 160000 index 000000000..991ffede7 --- /dev/null +++ b/extern/athena @@ -0,0 +1 @@ +Subproject commit 991ffede795a60b3bf8765601afda1ef02424ee8 diff --git a/boo2 b/extern/boo2 similarity index 100% rename from boo2 rename to extern/boo2 diff --git a/extern/discord-rpc b/extern/discord-rpc new file mode 160000 index 000000000..963aa9f3e --- /dev/null +++ b/extern/discord-rpc @@ -0,0 +1 @@ +Subproject commit 963aa9f3e5ce81a4682c6ca3d136cddda614db33 diff --git a/extern/fixNES b/extern/fixNES new file mode 160000 index 000000000..156fcaca9 --- /dev/null +++ b/extern/fixNES @@ -0,0 +1 @@ +Subproject commit 156fcaca9f4cd9c23d423737994c45cfb05d16ca diff --git a/jbus b/extern/jbus similarity index 100% rename from jbus rename to extern/jbus diff --git a/extern/kabufuda b/extern/kabufuda new file mode 160000 index 000000000..106bb02fb --- /dev/null +++ b/extern/kabufuda @@ -0,0 +1 @@ +Subproject commit 106bb02fbf6e482af2621f9b5e3ea099fcf1d53a diff --git a/extern/libSquish b/extern/libSquish new file mode 160000 index 000000000..fd5e6f4fe --- /dev/null +++ b/extern/libSquish @@ -0,0 +1 @@ +Subproject commit fd5e6f4fe294bcdde24e591fcef37dd5d740e060 diff --git a/extern/libjpeg-turbo b/extern/libjpeg-turbo new file mode 160000 index 000000000..3d2da99c6 --- /dev/null +++ b/extern/libjpeg-turbo @@ -0,0 +1 @@ +Subproject commit 3d2da99c69d000c6351f6d2390b694f800e5ef4d diff --git a/extern/libpng/ANNOUNCE b/extern/libpng/ANNOUNCE new file mode 100644 index 000000000..9f1b66583 --- /dev/null +++ b/extern/libpng/ANNOUNCE @@ -0,0 +1,115 @@ +Libpng 1.6.19 - November 12, 2015 + +This is a public release of libpng, intended for use in production codes. + +Files available for download: + +Source files with LF line endings (for Unix/Linux) and with a +"configure" script + + libpng-1.6.19.tar.xz (LZMA-compressed, recommended) + libpng-1.6.19.tar.gz + +Source files with CRLF line endings (for Windows), without the +"configure" script + + lpng1619.7z (LZMA-compressed, recommended) + lpng1619.zip + +Other information: + + libpng-1.6.19-README.txt + libpng-1.6.19-LICENSE.txt + libpng-1.6.19-*.asc (armored detached GPG signatures) + +Changes since the last public release (1.6.18): + + Updated obsolete information about the simplified API macros in the + manual pages (Bug report by Arc Riley). + Avoid potentially dereferencing NULL info_ptr in png_info_init_3(). + Rearranged png.h to put the major sections in the same order as + in libpng17. + Eliminated unused PNG_COST_SHIFT, PNG_WEIGHT_SHIFT, PNG_COST_FACTOR, and + PNG_WEIGHT_FACTOR macros. + Suppressed some warnings from the Borland C++ 5.5.1/5.82 compiler + (Bug report by Viktor Szakats). Several warnings remain and are + unavoidable, where we test for overflow. + Fixed potential leak of png_pixels in contrib/pngminus/pnm2png.c + Fixed uninitialized variable in contrib/gregbook/rpng2-x.c + Moved config.h.in~ from the "libpng_autotools_files" list to the + "libpng_autotools_extra" list in autogen.sh because it was causing a + false positive for missing files (bug report by Robert C. Seacord). + Removed unreachable "break" statements in png.c, pngread.c, and pngrtran.c + to suppress clang warnings (Bug report by Viktor Szakats). + Fixed some bad links in the man page. + Changed "n bit" to "n-bit" in comments. + Added signed/unsigned 16-bit safety net. This removes the dubious + 0x8000 flag definitions on 16-bit systems. They aren't supported + yet the defs *probably* work, however it seems much safer to do this + and be advised if anyone, contrary to advice, is building libpng 1.6 + on a 16-bit system. It also adds back various switch default clauses + for GCC; GCC errors out if they are not present (with an appropriately + high level of warnings). + Safely convert num_bytes to a png_byte in png_set_sig_bytes() (Robert + Seacord). + Fixed the recently reported 1's complement security issue by replacing + the value that is illegal in the PNG spec, in both signed and unsigned + values, with 0. Illegal unsigned values (anything greater than or equal + to 0x80000000) can still pass through, but since these are not illegal + in ANSI-C (unlike 0x80000000 in the signed case) the checking that + occurs later can catch them (John Bowler). + Fixed png_save_int_32 when int is not 2's complement (John Bowler). + Updated libpng16 with all the recent test changes from libpng17, + including changes to pngvalid.c to ensure that the original, + distributed, version of contrib/visupng/cexcept.h can be used + (John Bowler). + pngvalid contains the correction to the use of SAVE/STORE_ + UNKNOWN_CHUNKS; a bug revealed by changes in libpng 1.7. More + tests contain the --strict option to detect warnings and the + pngvalid-standard test has been corrected so that it does not + turn on progressive-read. There is a separate test which does + that. (John Bowler) + Also made some signed/unsigned fixes. + Make pngstest error limits version specific. Splitting the machine + generated error structs out to a file allows the values to be updated + without changing pngstest.c itself. Since libpng 1.6 and 1.7 have + slightly different error limits this simplifies maintenance. The + makepngs.sh script has also been updated to more accurately reflect + current problems in libpng 1.7 (John Bowler). + Incorporated new test PNG files into make check. tests/pngstest-* + are changed so that the new test files are divided into 8 groups by + gamma and alpha channel. These tests have considerably better code + and pixel-value coverage than contrib/pngsuite; however,coverage is + still incomplete (John Bowler). + Removed the '--strict' in 1.6 because of the double-gamma-correction + warning, updated pngstest-errors.h for the errors detected with the + new contrib/testspngs PNG test files (John Bowler). + Worked around rgb-to-gray issues in libpng 1.6. The previous + attempts to ignore the errors in the code aren't quite enough to + deal with the 'channel selection' encoding added to libpng 1.7; abort. + Fixed 'pow' macros in pngvalid.c. It is legal for 'pow' to be a + macro, therefore the argument list cannot contain preprocessing + directives. Make sure pow is a function where this happens. This is + a minimal safe fix, the issue only arises in non-performance-critical + code (bug report by Curtis Leach, fix by John Bowler). + Added sPLT support to pngtest.c + Prevent setting or writing over-length PLTE chunk (Cosmin Truta). + Silently truncate over-length PLTE chunk while reading. + Libpng incorrectly calculated the output rowbytes when the application + decreased either the number of channels or the bit depth (or both) in + a user transform. This was safe; libpng overallocated buffer space + (potentially by quite a lot; up to 4 times the amount required) but, + from 1.5.4 on, resulted in a png_error (John Bowler). + Fixed some inconsequential cut-and-paste typos in png_set_cHRM_XYZ_fixed(). + Clarified COPYRIGHT information to state explicitly that versions + are derived from previous versions. + Removed much of the long list of previous versions from png.h and + libpng.3. + +Send comments/corrections/commendations to png-mng-implement at lists.sf.net +(subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe) +or to glennrp at users.sourceforge.net + +Glenn R-P diff --git a/extern/libpng/CHANGES b/extern/libpng/CHANGES new file mode 100644 index 000000000..2e4d2bb29 --- /dev/null +++ b/extern/libpng/CHANGES @@ -0,0 +1,5424 @@ +#if 0 +CHANGES - changes for libpng + +version 0.1 [March 29, 1995] + initial work-in-progress release + +version 0.2 [April 1, 1995] + added reader into png.h + fixed small problems in stub file + +version 0.3 [April 8, 1995] + added pull reader + split up pngwrite.c to several files + added pnglib.txt + added example.c + cleaned up writer, adding a few new transformations + fixed some bugs in writer + interfaced with zlib 0.5 + added K&R support + added check for 64 KB blocks for 16 bit machines + +version 0.4 [April 26, 1995] + cleaned up code and commented code + simplified time handling into png_time + created png_color_16 and png_color_8 to handle color needs + cleaned up color type defines + fixed various bugs + made various names more consistent + interfaced with zlib 0.71 + cleaned up zTXt reader and writer (using zlib's Reset functions) + split transformations into pngrtran.c and pngwtran.c + +version 0.5 [April 30, 1995] + interfaced with zlib 0.8 + fixed many reading and writing bugs + saved using 3 spaces instead of tabs + +version 0.6 [May 1, 1995] + first beta release + added png_large_malloc() and png_large_free() + added png_size_t + cleaned up some compiler warnings + added png_start_read_image() + +version 0.7 [June 24, 1995] + cleaned up lots of bugs + finished dithering and other stuff + added test program + changed name from pnglib to libpng + +version 0.71 [June 26, 1995] + changed pngtest.png for zlib 0.93 + fixed error in libpng.txt and example.c + +version 0.8 [August 20, 1995] + cleaned up some bugs + added png_set_filler() + split up pngstub.c into pngmem.c, pngio.c, and pngerror.c + added #define's to remove unwanted code + moved png_info_init() to png.c + added old_size into png_realloc() + added functions to manually set filtering and compression info + changed compression parameters based on image type + optimized filter selection code + added version info + changed external functions passing floats to doubles (k&r problems?) + put all the configurable stuff in pngconf.h + enabled png_set_shift to work with paletted images on read + added png_read_update_info() - updates info structure with transformations + +Version 0.81 [August, 1995] + incorporated Tim Wegner's medium model code (thanks, Tim) + +Version 0.82 [September, 1995] + [unspecified changes] + +Version 0.85 [December, 1995] + added more medium model code (almost everything's a far) + added i/o, error, and memory callback functions + fixed some bugs (16-bit, 4-bit interlaced, etc.) + added first run progressive reader (barely tested) + +Version 0.86 [January, 1996] + fixed bugs + improved documentation + +Version 0.87 [January, 1996] + fixed medium model bugs + fixed other bugs introduced in 0.85 and 0.86 + added some minor documentation + +Version 0.88 [January, 1996] + fixed progressive bugs + replaced tabs with spaces + cleaned up documentation + added callbacks for read/write and warning/error functions + +Version 0.89 [June 5, 1996] + Added new initialization API to make libpng work better with shared libs + we now have png_create_read_struct(), png_create_write_struct(), + png_create_info_struct(), png_destroy_read_struct(), and + png_destroy_write_struct() instead of the separate calls to + malloc and png_read_init(), png_info_init(), and png_write_init() + Changed warning/error callback functions to fix bug - this means you + should use the new initialization API if you were using the old + png_set_message_fn() calls, and that the old API no longer exists + so that people are aware that they need to change their code + Changed filter selection API to allow selection of multiple filters + since it didn't work in previous versions of libpng anyways + Optimized filter selection code + Fixed png_set_background() to allow using an arbitrary RGB color for + paletted images + Fixed gamma and background correction for paletted images, so + png_correct_palette is not needed unless you are correcting an + external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED + in pngconf.h) - if nobody uses this, it may disappear in the future. + Fixed bug with Borland 64K memory allocation (Alexander Lehmann) + Fixed bug in interlace handling (Smarasderagd, I think) + Added more error checking for writing and image to reduce invalid files + Separated read and write functions so that they won't both be linked + into a binary when only reading or writing functionality is used + New pngtest image also has interlacing and zTXt + Updated documentation to reflect new API + +Version 0.89c [June 17, 1996] + Bug fixes. + +Version 0.90 [January, 1997] + Made CRC errors/warnings on critical and ancillary chunks configurable + libpng will use the zlib CRC routines by (compile-time) default + Changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner) + Added external C++ wrapper statements to png.h (Gilles Dauphin) + Allow PNG file to be read when some or all of file signature has already + been read from the beginning of the stream. ****This affects the size + of info_struct and invalidates all programs that use a shared libpng**** + Fixed png_filler() declarations + Fixed? background color conversions + Fixed order of error function pointers to match documentation + Current chunk name is now available in png_struct to reduce the number + of nearly identical error messages (will simplify multi-lingual + support when available) + Try to get ready for unknown-chunk callback functions: + - previously read critical chunks are flagged, so the chunk handling + routines can determine if the chunk is in the right place + - all chunk handling routines have the same prototypes, so we will + be able to handle all chunks via a callback mechanism + Try to fix Linux "setjmp" buffer size problems + Removed png_large_malloc, png_large_free, and png_realloc functions. + +Version 0.95 [March, 1997] + Fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never + Fixed bug in PNG file signature compares when start != 0 + Changed parameter type of png_set_filler(...filler...) from png_byte + to png_uint_32 + Added test for MACOS to ensure that both math.h and fp.h are not #included + Added macros for libpng to be compiled as a Windows DLL (Andreas Kupries) + Added "packswap" transformation, which changes the endianness of + packed-pixel bytes (Kevin Bracey) + Added "strip_alpha" transformation, which removes the alpha channel of + input images without using it (not necessarily a good idea) + Added "swap_alpha" transformation, which puts the alpha channel in front + of the color bytes instead of after + Removed all implicit variable tests which assume NULL == 0 (I think) + Changed several variables to "png_size_t" to show 16/32-bit limitations + Added new pCAL chunk read/write support + Added experimental filter selection weighting (Greg Roelofs) + Removed old png_set_rgbx() and png_set_xrgb() functions that have been + obsolete for about 2 years now (use png_set_filler() instead) + Added macros to read 16- and 32-bit ints directly from buffer, to be + used only on those systems that support it (namely PowerPC and 680x0) + With some testing, this may become the default for MACOS/PPC systems. + Only calculate CRC on data if we are going to use it + Added macros for zTXt compression type PNG_zTXt_COMPRESSION_??? + Added macros for simple libpng debugging output selectable at compile time + Removed PNG_READ_END_MODE in progressive reader (Smarasderagd) + More description of info_struct in libpng.txt and png.h + More instructions in example.c + More chunk types tested in pngtest.c + Renamed pngrcb.c to pngset.c, and all png_read_ functions to be + png_set_. We now have corresponding png_get_ + functions in pngget.c to get information in info_ptr. This isolates + the application from the internal organization of png_info_struct + (good for shared library implementations). + +Version 0.96 [May, 1997] + Fixed serious bug with < 8bpp images introduced in 0.95 + Fixed 256-color transparency bug (Greg Roelofs) + Fixed up documentation (Greg Roelofs, Laszlo Nyul) + Fixed "error" in pngconf.h for Linux setjmp() behavior + Fixed DOS medium model support (Tim Wegner) + Fixed png_check_keyword() for case with error in static string text + Added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul) + Added typecasts to quiet compiler errors + Added more debugging info + +Version 0.97 [January, 1998] + Removed PNG_USE_OWN_CRC capability + Relocated png_set_crc_action from pngrutil.c to pngrtran.c + Fixed typecasts of "new_key", etc. (Andreas Dilger) + Added RFC 1152 [sic] date support + Fixed bug in gamma handling of 4-bit grayscale + Added 2-bit grayscale gamma handling (Glenn R-P) + Added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P) + Minor corrections in libpng.txt + Added simple sRGB support (Glenn R-P) + Easier conditional compiling, e.g., + define PNG_READ/WRITE_NOT_FULLY_SUPPORTED; + all configurable options can be selected from command-line instead + of having to edit pngconf.h (Glenn R-P) + Fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P) + Added more conditions for png_do_background, to avoid changing + black pixels to background when a background is supplied and + no pixels are transparent + Repaired PNG_NO_STDIO behavior + Tested NODIV support and made it default behavior (Greg Roelofs) + Added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler) + Regularized version numbering scheme and bumped shared-library major + version number to 2 to avoid problems with libpng 0.89 apps + (Greg Roelofs) + +Version 0.98 [January, 1998] + Cleaned up some typos in libpng.txt and in code documentation + Fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler) + Cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c + Changed recommendation about file_gamma for PC images to .51 from .45, + in example.c and libpng.txt, added comments to distinguish between + screen_gamma, viewing_gamma, and display_gamma. + Changed all references to RFC1152 to read RFC1123 and changed the + PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED + Added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent) + Changed srgb_intent from png_byte to int to avoid compiler bugs + +Version 0.99 [January 30, 1998] + Free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler) + Fixed a longstanding "packswap" bug in pngtrans.c + Fixed some inconsistencies in pngconf.h that prevented compiling with + PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined + Fixed some typos and made other minor rearrangement of libpng.txt (Andreas) + Changed recommendation about file_gamma for PC images to .50 from .51 in + example.c and libpng.txt, and changed file_gamma for sRGB images to .45 + Added a number of functions to access information from the png structure + png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit) + Added TARGET_MACOS similar to zlib-1.0.8 + Define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined + Added type casting to all png_malloc() function calls + +Version 0.99a [January 31, 1998] + Added type casts and parentheses to all returns that return a value.(Tim W.) + +Version 0.99b [February 4, 1998] + Added type cast png_uint_32 on malloc function calls where needed. + Changed type of num_hist from png_uint_32 to int (same as num_palette). + Added checks for rowbytes overflow, in case png_size_t is less than 32 bits. + Renamed makefile.elf to makefile.lnx. + +Version 0.99c [February 7, 1998] + More type casting. Removed erroneous overflow test in pngmem.c. + Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes. + Added UNIX manual pages libpng.3 (incorporating libpng.txt) and png.5. + +Version 0.99d [February 11, 1998] + Renamed "far_to_near()" "png_far_to_near()" + Revised libpng.3 + Version 99c "buffered" operations didn't work as intended. Replaced them + with png_memcpy_check() and png_memset_check(). + Added many "if (png_ptr == NULL) return" to quell compiler warnings about + unused png_ptr, mostly in pngget.c and pngset.c. + Check for overlength tRNS chunk present when indexed-color PLTE is read. + Cleaned up spelling errors in libpng.3/libpng.txt + Corrected a problem with png_get_tRNS() which returned undefined trans array + +Version 0.99e [February 28, 1998] + Corrected png_get_tRNS() again. + Add parentheses for easier reading of pngget.c, fixed "||" should be "&&". + Touched up example.c to make more of it compileable, although the entire + file still can't be compiled (Willem van Schaik) + Fixed a bug in png_do_shift() (Bryan Tsai) + Added a space in png.h prototype for png_write_chunk_start() + Replaced pngtest.png with one created with zlib 1.1.1 + Changed pngtest to report PASS even when file size is different (Jean-loup G.) + Corrected some logic errors in png_do_invert_alpha() (Chris Patterson) + +Version 0.99f [March 5, 1998] + Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey) + Moved makefiles into a "scripts" directory, and added INSTALL instruction file + Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok) + Added pointers to "note on libpng versions" in makefile.lnx and README + Added row callback feature when reading and writing nonprogressive rows + and added a test of this feature in pngtest.c + Added user transform callbacks, with test of the feature in pngtest.c + +Version 0.99g [March 6, 1998, morning] + Minor changes to pngtest.c to suppress compiler warnings. + Removed "beta" language from documentation. + +Version 0.99h [March 6, 1998, evening] + Minor changes to previous minor changes to pngtest.c + Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED + and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro + Added user transform capability + +Version 1.00 [March 7, 1998] + Changed several typedefs in pngrutil.c + Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik) + Replaced "while(1)" with "for(;;)" + Added PNGARG() to prototypes in pngtest.c and removed some prototypes + Updated some of the makefiles (Tom Lane) + Changed some typedefs (s_start, etc.) in pngrutil.c + Fixed dimensions of "short_months" array in pngwrite.c + Replaced ansi2knr.c with the one from jpeg-v6 + +Version 1.0.0 [March 8, 1998] + Changed name from 1.00 to 1.0.0 (Adam Costello) + Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert) + +Version 1.0.0a [March 9, 1998] + Fixed three bugs in pngrtran.c to make gamma+background handling consistent + (Greg Roelofs) + Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz + for major, minor, and bugfix releases. This is 10001. (Adam Costello, + Tom Lane) + Make months range from 1-12 in png_convert_to_rfc1123 + +Version 1.0.0b [March 13, 1998] + Quieted compiler complaints about two empty "for" loops in pngrutil.c + Minor changes to makefile.s2x + Removed #ifdef/#endif around a png_free() in pngread.c + +Version 1.0.1 [March 14, 1998] + Changed makefile.s2x to reduce security risk of using a relative pathname + Fixed some typos in the documentation (Greg). + Fixed a problem with value of "channels" returned by png_read_update_info() + +Version 1.0.1a [April 21, 1998] + Optimized Paeth calculations by replacing abs() function calls with intrinsics + plus other loop optimizations. Improves avg decoding speed by about 20%. + Commented out i386istic "align" compiler flags in makefile.lnx. + Reduced the default warning level in some makefiles, to make them consistent. + Removed references to IJG and JPEG in the ansi2knr.c copyright statement. + Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation. + Added grayscale and 16-bit capability to png_do_read_filler(). + Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes + too large when writing an image with bit_depth < 8 (Bob Dellaca). + Corrected some bugs in the experimental weighted filtering heuristics. + Moved a misplaced pngrutil code block that truncates tRNS if it has more + than num_palette entries -- test was done before num_palette was defined. + Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins). + Changed compiler flags in makefile.wat for better optimization + (Pawel Mrochen). + +Version 1.0.1b [May 2, 1998] + Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg). + Relocated the png_composite macros from pngrtran.c to png.h (Greg). + Added makefile.sco (contributed by Mike Hopkirk). + Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a. + Fixed a bug in pngrtran.c that would set channels=5 under some circumstances. + More work on the Paeth-filtering, achieving imperceptible speedup + (A Kleinert). + More work on loop optimization which may help when compiled with C++ + compilers. + Added warnings when people try to use transforms they've defined out. + Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran. + Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg) + +Version 1.0.1c [May 11, 1998] + Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for + filler bytes should have been 0xff instead of 0xf. + Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images. + Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED + out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h + Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED, + for consistency, in pngconf.h + Added individual "ifndef PNG_NO_[CAPABILITY]" in pngconf.h to make it easier + to remove unwanted capabilities via the compile line + Made some corrections to grammar (which, it's) in documentation (Greg). + Corrected example.c, use of row_pointers in png_write_image(). + +Version 1.0.1d [May 24, 1998] + Corrected several statements that used side effects illegally in pngrutil.c + and pngtrans.c, that were introduced in version 1.0.1b + Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert) + More corrections to example.c, use of row_pointers in png_write_image() + and png_read_rows(). + Added pngdll.mak and pngdef.pas to scripts directory, contributed by + Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5 + Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.) + Changed several loops from count-down to count-up, for consistency. + +Version 1.0.1e [June 6, 1998] + Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and + added warnings when people try to set png_read_fn and png_write_fn in + the same structure. + Added a test such that png_do_gamma will be done when num_trans==0 + for truecolor images that have defined a background. This corrects an + error that was introduced in libpng-0.90 that can cause gamma processing + to be skipped. + Added tests in png.h to include "trans" and "trans_values" in structures + when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined. + Add png_free(png_ptr->time_buffer) in png_destroy_read_struct() + Moved png_convert_to_rfc_1123() from pngwrite.c to png.c + Added capability for user-provided malloc_fn() and free_fn() functions, + and revised pngtest.c to demonstrate their use, replacing the + PNGTEST_DEBUG_MEM feature. + Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner). + +Version 1.0.2 [June 14, 1998] + Fixed two bugs in makefile.bor . + +Version 1.0.2a [December 30, 1998] + Replaced and extended code that was removed from png_set_filler() in 1.0.1a. + Fixed a bug in png_do_filler() that made it fail to write filler bytes in + the left-most pixel of each row (Kevin Bracey). + Changed "static pngcharp tIME_string" to "static char tIME_string[30]" + in pngtest.c (Duncan Simpson). + Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk + even when no tIME chunk was present in the source file. + Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit. + Fixed a problem in png_read_push_finish_row(), which would not skip some + passes that it should skip, for images that are less than 3 pixels high. + Interchanged the order of calls to png_do_swap() and png_do_shift() + in pngwtran.c (John Cromer). + Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h . + Changed "bad adaptive filter type" from error to warning in pngrutil.c . + Fixed a documentation error about default filtering with 8-bit indexed-color. + Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO + (L. Peter Deutsch). + Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions. + Added png_get_copyright() and png_get_header_version() functions. + Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c + Added information about debugging in libpng.txt and libpng.3 . + Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and + makefile.sco. + Removed lines after Dynamic Dependencies" in makefile.aco . + Revised makefile.dec to make a shared library (Jeremie Petit). + Removed trailing blanks from all files. + +Version 1.0.2a [January 6, 1999] + Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h + Added "if" tests to silence complaints about unused png_ptr in png.h and png.c + Changed "check_if_png" function in example.c to return true (nonzero) if PNG. + Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig() + which is obsolete. + +Version 1.0.3 [January 14, 1999] + Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice) + Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO. + +Version 1.0.3a [August 12, 1999] + Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning + if an attempt is made to read an interlaced image when it's not supported. + Added check if png_ptr->trans is defined before freeing it in pngread.c + Modified the Y2K statement to include versions back to version 0.71 + Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c + Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments) + Replaced leading blanks with tab characters in makefile.hux + Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents. + Changed (float)red and (float)green to (double)red, (double)green + in png_set_rgb_to_gray() to avoid "promotion" problems in AIX. + Fixed a bug in pngconf.h that omitted when PNG_DEBUG==0 (K Bracey). + Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt). + Updated documentation to refer to the PNG-1.2 specification. + Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c + in makefile.knr, INSTALL, and README (L. Peter Deutsch) + Fixed bugs in calculation of the length of rowbytes when adding alpha + channels to 16-bit images, in pngrtran.c (Chris Nokleberg) + Added function png_set_user_transform_info() to store user_transform_ptr, + user_depth, and user_channels into the png_struct, and a function + png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg) + Added function png_set_empty_plte_permitted() to make libpng useable + in MNG applications. + Corrected the typedef for png_free_ptr in png.h (Jesse Jones). + Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be + consistent with PNG-1.2, and allow variance of 500 before complaining. + Added assembler code contributed by Intel in file pngvcrd.c and modified + makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, + Gilles Vollant) + Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy. + Added some aliases for png_set_expand() in pngrtran.c, namely + png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS() + (Greg Roelofs, in "PNG: The Definitive Guide"). + Added makefile.beo for BEOS on X86, contributed by Sander Stok. + +Version 1.0.3b [August 26, 1999] + Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h + Changed leading blanks to tabs in all makefiles. + Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code. + Made alternate versions of png_set_expand() in pngrtran.c, namely + png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha + (Greg Roelofs, in "PNG: The Definitive Guide"). Deleted the 1.0.3a aliases. + Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h + Revised calculation of num_blocks in pngmem.c to avoid a potentially + negative shift distance, whose results are undefined in the C language. + Added a check in pngset.c to prevent writing multiple tIME chunks. + Added a check in pngwrite.c to detect invalid small window_bits sizes. + +Version 1.0.3d [September 4, 1999] + Fixed type casting of igamma in pngrutil.c + Added new png_expand functions to scripts/pngdef.pas and pngos2.def + Added a demo read_user_transform_fn that examines the row filters in pngtest.c + +Version 1.0.4 [September 24, 1999, not distributed publicly] + Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined + Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h + Made several minor corrections to pngtest.c + Renamed the makefiles with longer but more user friendly extensions. + Copied the PNG copyright and license to a separate LICENSE file. + Revised documentation, png.h, and example.c to remove reference to + "viewing_gamma" which no longer appears in the PNG specification. + Revised pngvcrd.c to use MMX code for interlacing only on the final pass. + Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a + Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX + assembler code) and makefile.vcwin32 (doesn't). + Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING) + Added a copy of pngnow.png to the distribution. + +Version 1.0.4a [September 25, 1999] + Increase max_pixel_depth in pngrutil.c if a user transform needs it. + Changed several division operations to right-shifts in pngvcrd.c + +Version 1.0.4b [September 30, 1999] + Added parentheses in line 3732 of pngvcrd.c + Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1 + +Version 1.0.4c [October 1, 1999] + Added a "png_check_version" function in png.c and pngtest.c that will generate + a helpful compiler error if an old png.h is found in the search path. + Changed type of png_user_transform_depth|channels from int to png_byte. + Added "Libpng is OSI Certified Open Source Software" statement to png.h + +Version 1.0.4d [October 6, 1999] + Changed 0.45 to 0.45455 in png_set_sRGB() + Removed unused PLTE entries from pngnow.png + Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly. + +Version 1.0.4e [October 10, 1999] + Fixed sign error in pngvcrd.c (Greg Roelofs) + Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P) + +Version 1.0.4f [October 15, 1999] + Surrounded example.c code with #if 0 .. #endif to prevent people from + inadvertently trying to compile it. + Changed png_get_header_version() from a function to a macro in png.h + Added type casting mostly in pngrtran.c and pngwtran.c + Removed some pointless "ptr = NULL" in pngmem.c + Added a "contrib" directory containing the source code from Greg's book. + +Version 1.0.5 [October 15, 1999] + Minor editing of the INSTALL and README files. + +Version 1.0.5a [October 23, 1999] + Added contrib/pngsuite and contrib/pngminus (Willem van Schaik) + Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans) + Further optimization and bugfix of pngvcrd.c + Revised pngset.c so that it does not allocate or free memory in the user's + text_ptr structure. Instead, it makes its own copy. + Created separate write_end_info_struct in pngtest.c for a more severe test. + Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak. + +Version 1.0.5b [November 23, 1999] + Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and + PNG_FLAG_WROTE_tIME from flags to mode. + Added png_write_info_before_PLTE() function. + Fixed some typecasting in contrib/gregbook/*.c + Updated scripts/makevms.com and added makevms.com to contrib/gregbook + and contrib/pngminus (Martin Zinser) + +Version 1.0.5c [November 26, 1999] + Moved png_get_header_version from png.h to png.c, to accommodate ansi2knr. + Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to + accommodate making DLL's: Moved usr_png_ver from global variable to function + png_get_header_ver() in png.c. Moved png_sig to png_sig_bytes in png.c and + eliminated use of png_sig in pngwutil.c. Moved the various png_CHNK arrays + into pngtypes.h. Eliminated use of global png_pass arrays. Declared the + png_CHNK and png_pass arrays to be "const". Made the global arrays + available to applications (although none are used in libpng itself) when + PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined. + Removed some extraneous "-I" from contrib/pngminus/makefile.std + Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2. + Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3 + +Version 1.0.5d [November 29, 1999] + Add type cast (png_const_charp) two places in png.c + Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays. + Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available + to applications a macro "PNG_USE_LOCAL_ARRAYS". + comment out (with #ifdef) all the new declarations when + PNG_USE_GLOBAL_ARRAYS is defined. + Added PNG_EXPORT_VAR macro to accommodate making DLL's. + +Version 1.0.5e [November 30, 1999] + Added iCCP, iTXt, and sPLT support; added "lang" member to the png_text + structure; refactored the inflate/deflate support to make adding new chunks + with trailing compressed parts easier in the future, and added new functions + png_free_iCCP, png_free_pCAL, png_free_sPLT, png_free_text, png_get_iCCP, + png_get_spalettes, png_set_iCCP, png_set_spalettes (Eric S. Raymond). + NOTE: Applications that write text chunks MUST define png_text->lang + before calling png_set_text(). It must be set to NULL if you want to + write tEXt or zTXt chunks. If you want your application to be able to + run with older versions of libpng, use + + #ifdef PNG_iTXt_SUPPORTED + png_text[i].lang = NULL; + #endif + + Changed png_get_oFFs() and png_set_oFFs() to use signed rather than unsigned + offsets (Eric S. Raymond). + Combined PNG_READ_cHNK_SUPPORTED and PNG_WRITE_cHNK_SUPPORTED macros into + PNG_cHNK_SUPPORTED and combined the three types of PNG_text_SUPPORTED + macros, leaving the separate macros also available. + Removed comments on #endifs at the end of many short, non-nested #if-blocks. + +Version 1.0.5f [December 6, 1999] + Changed makefile.solaris to issue a warning about potential problems when + the ucb "ld" is in the path ahead of the ccs "ld". + Removed "- [date]" from the "synopsis" line in libpng.3 and libpngpf.3. + Added sCAL chunk support (Eric S. Raymond). + +Version 1.0.5g [December 7, 1999] + Fixed "png_free_spallettes" typo in png.h + Added code to handle new chunks in pngpread.c + Moved PNG_CHNK string macro definitions outside of PNG_NO_EXTERN block + Added "translated_key" to png_text structure and png_write_iTXt(). + Added code in pngwrite.c to work around a newly discovered zlib bug. + +Version 1.0.5h [December 10, 1999] + NOTE: regarding the note for version 1.0.5e, the following must also + be included in your code: + png_text[i].translated_key = NULL; + Unknown chunk handling is now supported. + Option to eliminate all floating point support was added. Some new + fixed-point functions such as png_set_gAMA_fixed() were added. + Expanded tabs and removed trailing blanks in source files. + +Version 1.0.5i [December 13, 1999] + Added some type casts to silence compiler warnings. + Renamed "png_free_spalette" to "png_free_spalettes" for consistency. + Removed leading blanks from a #define in pngvcrd.c + Added some parameters to the new png_set_keep_unknown_chunks() function. + Added a test for up->location != 0 in the first instance of writing + unknown chunks in pngwrite.c + Changed "num" to "i" in png_free_spalettes() and png_free_unknowns() to + prevent recursion. + Added png_free_hIST() function. + Various patches to fix bugs in the sCAL and integer cHRM processing, + and to add some convenience macros for use with sCAL. + +Version 1.0.5j [December 21, 1999] + Changed "unit" parameter of png_write_sCAL from png_byte to int, to work + around buggy compilers. + Added new type "png_fixed_point" for integers that hold float*100000 values + Restored backward compatibility of tEXt/zTXt chunk processing: + Restored the first four members of png_text to the same order as v.1.0.5d. + Added members "lang_key" and "itxt_length" to png_text struct. Set + text_length=0 when "text" contains iTXt data. Use the "compression" + member to distinguish among tEXt/zTXt/iTXt types. Added + PNG_ITXT_COMPRESSION_NONE (1) and PNG_ITXT_COMPRESSION_zTXt(2) macros. + The "Note" above, about backward incompatibility of libpng-1.0.5e, no + longer applies. + Fixed png_read|write_iTXt() to read|write parameters in the right order, + and to write the iTXt chunk after IDAT if it appears in the end_ptr. + Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs) + Reversed the order of trying to write floating-point and fixed-point gAMA. + +Version 1.0.5k [December 27, 1999] + Added many parentheses, e.g., "if (a && b & c)" becomes "if (a && (b & c))" + Added png_handle_as_unknown() function (Glenn) + Added png_free_chunk_list() function and chunk_list and num_chunk_list members + of png_ptr. + Eliminated erroneous warnings about multiple sPLT chunks and sPLT-after-PLTE. + Fixed a libpng-1.0.5h bug in pngrutil.c that was issuing erroneous warnings + about ignoring incorrect gAMA with sRGB (gAMA was in fact not ignored) + Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR). + Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is. + Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP(). + +Version 1.0.5l [January 1, 2000] + Added functions png_set_read_user_chunk_fn() and png_get_user_chunk_ptr() + for setting a callback function to handle unknown chunks and for + retrieving the associated user pointer (Glenn). + +Version 1.0.5m [January 7, 2000] + Added high-level functions png_read_png(), png_write_png(), png_free_pixels(). + +Version 1.0.5n [January 9, 2000] + Added png_free_PLTE() function, and modified png_set_PLTE() to malloc its + own memory for info_ptr->palette. This makes it safe for the calling + application to free its copy of the palette any time after it calls + png_set_PLTE(). + +Version 1.0.5o [January 20, 2000] + Cosmetic changes only (removed some trailing blanks and TABs) + +Version 1.0.5p [January 31, 2000] + Renamed pngdll.mak to makefile.bd32 + Cosmetic changes in pngtest.c + +Version 1.0.5q [February 5, 2000] + Relocated the makefile.solaris warning about PATH problems. + Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg) + Revised makefile.gcmmx + Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros + +Version 1.0.5r [February 7, 2000] + Removed superfluous prototype for png_get_itxt from png.h + Fixed a bug in pngrtran.c that improperly expanded the background color. + Return *num_text=0 from png_get_text() when appropriate, and fix documentation + of png_get_text() in libpng.txt/libpng.3. + +Version 1.0.5s [February 18, 2000] + Added "png_jmp_env()" macro to pngconf.h, to help people migrate to the + new error handler that's planned for the next libpng release, and changed + example.c, pngtest.c, and contrib programs to use this macro. + Revised some of the DLL-export macros in pngconf.h (Greg Roelofs) + Fixed a bug in png_read_png() that caused it to fail to expand some images + that it should have expanded. + Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions + in pngget.c + Changed the allocation of palette, history, and trans arrays back to + the version 1.0.5 method (linking instead of copying) which restores + backward compatibility with version 1.0.5. Added some remarks about + that in example.c. Added "free_me" member to info_ptr and png_ptr + and added png_free_data() function. + Updated makefile.linux and makefile.gccmmx to make directories conditionally. + Made cosmetic changes to pngasmrd.h + Added png_set_rows() and png_get_rows(), for use with png_read|write_png(). + Modified png_read_png() to allocate info_ptr->row_pointers only if it + hasn't already been allocated. + +Version 1.0.5t [March 4, 2000] + Changed png_jmp_env() migration aiding macro to png_jmpbuf(). + Fixed "interlace" typo (should be "interlaced") in contrib/gregbook/read2-x.c + Fixed bug with use of PNG_BEFORE_IHDR bit in png_ptr->mode, introduced when + PNG_FLAG_HAVE_CHUNK_HEADER was moved into png_ptr->mode in version 1.0.5b + Files in contrib/gregbook were revised to use png_jmpbuf() and to select + a 24-bit visual if one is available, and to allow abbreviated options. + Files in contrib/pngminus were revised to use the png_jmpbuf() macro. + Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s + +Version 1.0.5u [March 5, 2000] + Simplified the code that detects old png.h in png.c and pngtest.c + Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp) + Increased precision of rgb_to_gray calculations from 8 to 15 bits and + added png_set_rgb_to_gray_fixed() function. + Added makefile.bc32 (32-bit Borland C++, C mode) + +Version 1.0.5v [March 11, 2000] + Added some parentheses to the png_jmpbuf macro definition. + Updated references to the zlib home page, which has moved to freesoftware.com. + Corrected bugs in documentation regarding png_read_row() and png_write_row(). + Updated documentation of png_rgb_to_gray calculations in libpng.3/libpng.txt. + Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3, + revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin) + +Version 1.0.6 [March 20, 2000] + Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c + Added makefile.sggcc (SGI IRIX with gcc) + +Version 1.0.6d [April 7, 2000] + Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO + Added data_length parameter to png_decompress_chunk() function + Revised documentation to remove reference to abandoned png_free_chnk functions + Fixed an error in png_rgb_to_gray_fixed() + Revised example.c, usage of png_destroy_write_struct(). + Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file + Added a check for info_ptr->free_me&PNG_FREE_TEXT when freeing text in png.c + Simplify png_sig_bytes() function to remove use of non-ISO-C strdup(). + +Version 1.0.6e [April 9, 2000] + Added png_data_freer() function. + In the code that checks for over-length tRNS chunks, added check of + info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann) + Minor revisions of libpng.txt/libpng.3. + Check for existing data and free it if the free_me flag is set, in png_set_*() + and png_handle_*(). + Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED + is defined. + Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c + and mentioned the purposes of the two macros in libpng.txt/libpng.3. + +Version 1.0.6f [April 14, 2000] + Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data. + Add checks in png_set_text() for NULL members of the input text structure. + Revised libpng.txt/libpng.3. + Removed superfluous prototype for png_set_iTXt from png.h + Removed "else" from pngread.c, after png_error(), and changed "0" to "length". + Changed several png_errors about malformed ancillary chunks to png_warnings. + +Version 1.0.6g [April 24, 2000] + Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined. + Relocated paragraph about png_set_background() in libpng.3/libpng.txt + and other revisions (Matthias Benckmann) + Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and + png_ptr members to restore binary compatibility with libpng-1.0.5 + (breaks compatibility with libpng-1.0.6). + +Version 1.0.6h [April 24, 2000] + Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds + libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h) + This is a temporary change for test purposes. + +Version 1.0.6i [May 2, 2000] + Rearranged some members at the end of png_info and png_struct, to put + unknown_chunks_num and free_me within the original size of the png_structs + and free_me, png_read_user_fn, and png_free_fn within the original png_info, + because some old applications allocate the structs directly instead of + using png_create_*(). + Added documentation of user memory functions in libpng.txt/libpng.3 + Modified png_read_png so that it will use user_allocated row_pointers + if present, unless free_me directs that it be freed, and added description + of the use of png_set_rows() and png_get_rows() in libpng.txt/libpng.3. + Added PNG_LEGACY_SUPPORTED macro, and #ifdef out all new (since version + 1.00) members of png_struct and png_info, to regain binary compatibility + when you define this macro. Capabilities lost in this event + are user transforms (new in version 1.0.0),the user transform pointer + (new in version 1.0.2), rgb_to_gray (new in 1.0.5), iCCP, sCAL, sPLT, + the high-level interface, and unknown chunks support (all new in 1.0.6). + This was necessary because of old applications that allocate the structs + directly as authors were instructed to do in libpng-0.88 and earlier, + instead of using png_create_*(). + Added modes PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT which + can be used to detect codes that directly allocate the structs, and + code to check these modes in png_read_init() and png_write_init() and + generate a libpng error if the modes aren't set and PNG_LEGACY_SUPPORTED + was not defined. + Added makefile.intel and updated makefile.watcom (Pawel Mrochen) + +Version 1.0.6j [May 3, 2000] + Overloaded png_read_init() and png_write_init() with macros that convert + calls to png_read_init_2() or png_write_init_2() that check the version + and structure sizes. + +Version 1.0.7beta11 [May 7, 2000] + Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes + which are no longer used. + Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is + defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXT_SUPPORTED + is defined. + Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory + overrun when old applications fill the info_ptr->text structure directly. + Added PNGAPI macro, and added it to the definitions of all exported functions. + Relocated version macro definitions ahead of the includes of zlib.h and + pngconf.h in png.h. + +Version 1.0.7beta12 [May 12, 2000] + Revised pngset.c to avoid a problem with expanding the png_debug macro. + Deleted some extraneous defines from pngconf.h + Made PNG_NO_CONSOLE_IO the default condition when PNG_BUILD_DLL is defined. + Use MSC _RPTn debugging instead of fprintf if _MSC_VER is defined. + Added png_access_version_number() function. + Check for mask&PNG_FREE_CHNK (for TEXT, SCAL, PCAL) in png_free_data(). + Expanded libpng.3/libpng.txt information about png_data_freer(). + +Version 1.0.7beta14 [May 17, 2000] (beta13 was not published) + Changed pnggccrd.c and pngvcrd.c to handle bad adaptive filter types as + warnings instead of errors, as pngrutil.c does. + Set the PNG_INFO_IDAT valid flag in png_set_rows() so png_write_png() + will actually write IDATs. + Made the default PNG_USE_LOCAL_ARRAYS depend on PNG_DLL instead of WIN32. + Make png_free_data() ignore its final parameter except when freeing data + that can have multiple instances (text, sPLT, unknowns). + Fixed a new bug in png_set_rows(). + Removed info_ptr->valid tests from png_free_data(), as in version 1.0.5. + Added png_set_invalid() function. + Fixed incorrect illustrations of png_destroy_write_struct() in example.c. + +Version 1.0.7beta15 [May 30, 2000] + Revised the deliberately erroneous Linux setjmp code in pngconf.h to produce + fewer error messages. + Rearranged checks for Z_OK to check the most likely path first in pngpread.c + and pngwutil.c. + Added checks in pngtest.c for png_create_*() returning NULL, and mentioned + in libpng.txt/libpng.3 the need for applications to check this. + Changed names of png_default_*() functions in pngtest to pngtest_*(). + Changed return type of png_get_x|y_offset_*() from png_uint_32 to png_int_32. + Fixed some bugs in the unused PNG_INCH_CONVERSIONS functions in pngget.c + Set each pointer to NULL after freeing it in png_free_data(). + Worked around a problem in pngconf.h; AIX's strings.h defines an "index" + macro that conflicts with libpng's png_color_16.index. (Dimitri + Papadapoulos) + Added "msvc" directory with MSVC++ project files (Simon-Pierre Cadieux). + +Version 1.0.7beta16 [June 4, 2000] + Revised the workaround of AIX string.h "index" bug. + Added a check for overlength PLTE chunk in pngrutil.c. + Added PNG_NO_POINTER_INDEXING macro to use array-indexing instead of pointer + indexing in pngrutil.c and pngwutil.c to accommodate a buggy compiler. + Added a warning in png_decompress_chunk() when it runs out of data, e.g. + when it tries to read an erroneous PhotoShop iCCP chunk. + Added PNG_USE_DLL macro. + Revised the copyright/disclaimer/license notice. + Added contrib/msvctest directory + +Version 1.0.7rc1 [June 9, 2000] + Corrected the definition of PNG_TRANSFORM_INVERT_ALPHA (0x0400 not 0x0200) + Added contrib/visupng directory (Willem van Schaik) + +Version 1.0.7beta18 [June 23, 2000] + Revised PNGAPI definition, and pngvcrd.c to work with __GCC__ + and do not redefine PNGAPI if it is passed in via a compiler directive. + Revised visupng/PngFile.c to remove returns from within the Try block. + Removed leading underscores from "_PNG_H" and "_PNG_SAVE_BSD_SOURCE" macros. + Updated contrib/visupng/cexcept.h to version 1.0.0. + Fixed bugs in pngwrite.c and pngwutil.c that prevented writing iCCP chunks. + +Version 1.0.7rc2 [June 28, 2000] + Updated license to include disclaimers required by UCITA. + Fixed "DJBPP" typo in pnggccrd.c introduced in beta18. + +Version 1.0.7 [July 1, 2000] + Revised the definition of "trans_values" in libpng.3/libpng.txt + +Version 1.0.8beta1 [July 8, 2000] + Added png_free(png_ptr, key) two places in pngpread.c to stop memory leaks. + Changed PNG_NO_STDIO to PNG_NO_CONSOLE_IO, several places in pngrutil.c and + pngwutil.c. + Changed PNG_EXPORT_VAR to use PNG_IMPEXP, in pngconf.h. + Removed unused "#include " from png.c + Added WindowsCE support. + Revised pnggccrd.c to work with gcc-2.95.2 and in the Cygwin environment. + +Version 1.0.8beta2 [July 10, 2000] + Added project files to the wince directory and made further revisions + of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE. + +Version 1.0.8beta3 [July 11, 2000] + Only set the PNG_FLAG_FREE_TRNS or PNG_FREE_TRNS flag in png_handle_tRNS() + for indexed-color input files to avoid potential double-freeing trans array + under some unusual conditions; problem was introduced in version 1.0.6f. + Further revisions to pngtest.c and files in the wince subdirectory. + +Version 1.0.8beta4 [July 14, 2000] + Added the files pngbar.png and pngbar.jpg to the distribution. + Added makefile.cygwin, and cygwin support in pngconf.h + Added PNG_NO_ZALLOC_ZERO macro (makes png_zalloc skip zeroing memory) + +Version 1.0.8rc1 [July 16, 2000] + Revised png_debug() macros and statements to eliminate compiler warnings. + +Version 1.0.8 [July 24, 2000] + Added png_flush() in pngwrite.c, after png_write_IEND(). + Updated makefile.hpux to build a shared library. + +Version 1.0.9beta1 [November 10, 2000] + Fixed typo in scripts/makefile.hpux + Updated makevms.com in scripts and contrib/* and contrib/* (Martin Zinser) + Fixed seqence-point bug in contrib/pngminus/png2pnm (Martin Zinser) + Changed "cdrom.com" in documentation to "libpng.org" + Revised pnggccrd.c to get it all working, and updated makefile.gcmmx (Greg). + Changed type of "params" from voidp to png_voidp in png_read|write_png(). + Make sure PNGAPI and PNG_IMPEXP are defined in pngconf.h. + Revised the 3 instances of WRITEFILE in pngtest.c. + Relocated "msvc" and "wince" project subdirectories into "dll" subdirectory. + Updated png.rc in dll/msvc project + Revised makefile.dec to define and use LIBPATH and INCPATH + Increased size of global png_libpng_ver[] array from 12 to 18 chars. + Made global png_libpng_ver[], png_sig[] and png_pass_*[] arrays const. + Removed duplicate png_crc_finish() from png_handle_bKGD() function. + Added a warning when application calls png_read_update_info() multiple times. + Revised makefile.cygwin + Fixed bugs in iCCP support in pngrutil.c and pngwutil.c. + Replaced png_set_empty_plte_permitted() with png_permit_mng_features(). + +Version 1.0.9beta2 [November 19, 2000] + Renamed the "dll" subdirectory "projects". + Added borland project files to "projects" subdirectory. + Set VS_FF_PRERELEASE and VS_FF_PATCHED flags in msvc/png.rc when appropriate. + Add error message in png_set_compression_buffer_size() when malloc fails. + +Version 1.0.9beta3 [November 23, 2000] + Revised PNG_LIBPNG_BUILD_TYPE macro in png.h, used in the msvc project. + Removed the png_flush() in pngwrite.c that crashes some applications + that don't set png_output_flush_fn. + Added makefile.macosx and makefile.aix to scripts directory. + +Version 1.0.9beta4 [December 1, 2000] + Change png_chunk_warning to png_warning in png_check_keyword(). + Increased the first part of msg buffer from 16 to 18 in png_chunk_error(). + +Version 1.0.9beta5 [December 15, 2000] + Added support for filter method 64 (for PNG datastreams embedded in MNG). + +Version 1.0.9beta6 [December 18, 2000] + Revised png_set_filter() to accept filter method 64 when appropriate. + Added new PNG_HAVE_PNG_SIGNATURE bit to png_ptr->mode and use it to + help prevent applications from using MNG features in PNG datastreams. + Added png_permit_mng_features() function. + Revised libpng.3/libpng.txt. Changed "filter type" to "filter method". + +Version 1.0.9rc1 [December 23, 2000] + Revised test for PNG_HAVE_PNG_SIGNATURE in pngrutil.c + Fixed error handling of unknown compression type in png_decompress_chunk(). + In pngconf.h, define __cdecl when _MSC_VER is defined. + +Version 1.0.9beta7 [December 28, 2000] + Changed PNG_TEXT_COMPRESSION_zTXt to PNG_COMPRESSION_TYPE_BASE several places. + Revised memory management in png_set_hIST and png_handle_hIST in a backward + compatible manner. PLTE and tRNS were revised similarly. + Revised the iCCP chunk reader to ignore trailing garbage. + +Version 1.0.9beta8 [January 12, 2001] + Moved pngasmrd.h into pngconf.h. + Improved handling of out-of-spec garbage iCCP chunks generated by PhotoShop. + +Version 1.0.9beta9 [January 15, 2001] + Added png_set_invalid, png_permit_mng_features, and png_mmx_supported to + wince and msvc project module definition files. + Minor revision of makefile.cygwin. + Fixed bug with progressive reading of narrow interlaced images in pngpread.c + +Version 1.0.9beta10 [January 16, 2001] + Do not typedef png_FILE_p in pngconf.h when PNG_NO_STDIO is defined. + Fixed "png_mmx_supported" typo in project definition files. + +Version 1.0.9beta11 [January 19, 2001] + Updated makefile.sgi to make shared library. + Removed png_mmx_support() function and disabled PNG_MNG_FEATURES_SUPPORTED + by default, for the benefit of DLL forward compatibility. These will + be re-enabled in version 1.2.0. + +Version 1.0.9rc2 [January 22, 2001] + Revised cygwin support. + +Version 1.0.9 [January 31, 2001] + Added check of cygwin's ALL_STATIC in pngconf.h + Added "-nommx" parameter to contrib/gregbook/rpng2-win and rpng2-x demos. + +Version 1.0.10beta1 [March 14, 2001] + Revised makefile.dec, makefile.sgi, and makefile.sggcc; added makefile.hpgcc. + Reformatted libpng.3 to eliminate bad line breaks. + Added checks for _mmx_supported in the read_filter_row function of pnggccrd.c + Added prototype for png_mmx_support() near the top of pnggccrd.c + Moved some error checking from png_handle_IHDR to png_set_IHDR. + Added PNG_NO_READ_SUPPORTED and PNG_NO_WRITE_SUPPORTED macros. + Revised png_mmx_support() function in pnggccrd.c + Restored version 1.0.8 PNG_WRITE_EMPTY_PLTE_SUPPORTED behavior in pngwutil.c + Fixed memory leak in contrib/visupng/PngFile.c + Fixed bugs in png_combine_row() in pnggccrd.c and pngvcrd.c (C version) + Added warnings when retrieving or setting gamma=0. + Increased the first part of msg buffer from 16 to 18 in png_chunk_warning(). + +Version 1.0.10rc1 [March 23, 2001] + Changed all instances of memcpy, strcpy, and strlen to png_memcpy, png_strcpy, + and png_strlen. + Revised png_mmx_supported() function in pnggccrd.c to return proper value. + Fixed bug in progressive reading (pngpread.c) with small images (height < 8). + +Version 1.0.10 [March 30, 2001] + Deleted extraneous space (introduced in 1.0.9) from line 42 of makefile.cygwin + Added beos project files (Chris Herborth) + +Version 1.0.11beta1 [April 3, 2001] + Added type casts on several png_malloc() calls (Dimitri Papadapoulos). + Removed a no-longer needed AIX work-around from pngconf.h + Changed several "//" single-line comments to C-style in pnggccrd.c + +Version 1.0.11beta2 [April 11, 2001] + Removed PNGAPI from several functions whose prototypes did not have PNGAPI. + Updated scripts/pngos2.def + +Version 1.0.11beta3 [April 14, 2001] + Added checking the results of many instances of png_malloc() for NULL + +Version 1.0.11beta4 [April 20, 2001] + Undid the changes from version 1.0.11beta3. Added a check for NULL return + from user's malloc_fn(). + Removed some useless type casts of the NULL pointer. + Added makefile.netbsd + +Version 1.0.11 [April 27, 2001] + Revised makefile.netbsd + +Version 1.0.12beta1 [May 14, 2001] + Test for Windows platform in pngconf.h when including malloc.h (Emmanuel Blot) + Updated makefile.cygwin and handling of Cygwin's ALL_STATIC in pngconf.h + Added some never-to-be-executed code in pnggccrd.c to quiet compiler warnings. + Eliminated the png_error about apps using png_read|write_init(). Instead, + libpng will reallocate the png_struct and info_struct if they are too small. + This retains future binary compatibility for old applications written for + libpng-0.88 and earlier. + +Version 1.2.0beta1 [May 6, 2001] + Bumped DLLNUM to 2. + Re-enabled PNG_MNG_FEATURES_SUPPORTED and enabled PNG_ASSEMBLER_CODE_SUPPORTED + by default. + Added runtime selection of MMX features. + Added png_set_strip_error_numbers function and related macros. + +Version 1.2.0beta2 [May 7, 2001] + Finished merging 1.2.0beta1 with version 1.0.11 + Added a check for attempts to read or write PLTE in grayscale PNG datastreams. + +Version 1.2.0beta3 [May 17, 2001] + Enabled user memory function by default. + Modified png_create_struct so it passes user mem_ptr to user memory allocator. + Increased png_mng_features flag from png_byte to png_uint_32. + Bumped shared-library (so-number) and dll-number to 3. + +Version 1.2.0beta4 [June 23, 2001] + Check for missing profile length field in iCCP chunk and free chunk_data + in case of truncated iCCP chunk. + Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc + Bumped dll-number from 2 to 3 in makefile.cygwin + Revised contrib/gregbook/rpng*-x.c to avoid a memory leak and to exit cleanly + if user attempts to run it on an 8-bit display. + Updated contrib/gregbook + Use png_malloc instead of png_zalloc to allocate palette in pngset.c + Updated makefile.ibmc + Added some typecasts to eliminate gcc 3.0 warnings. Changed prototypes + of png_write_oFFS width and height from png_uint_32 to png_int_32. + Updated example.c + Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c + +Version 1.2.0beta5 [August 8, 2001] + Revised contrib/gregbook + Revised makefile.gcmmx + Revised pnggccrd.c to conditionally compile some thread-unsafe code only + when PNG_THREAD_UNSAFE_OK is defined. + Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with + value exceeding 2^bit_depth-1 + Revised makefile.sgi and makefile.sggcc + Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c + Removed restriction that do_invert_mono only operate on 1-bit opaque files + +Version 1.2.0 [September 1, 2001] + Changed a png_warning() to png_debug() in pnggccrd.c + Fixed contrib/gregbook/rpng-x.c, rpng2-x.c to avoid crash with XFreeGC(). + +Version 1.2.1beta1 [October 19, 2001] + Revised makefile.std in contrib/pngminus + Include background_1 in png_struct regardless of gamma support. + Revised makefile.netbsd and makefile.macosx, added makefile.darwin. + Revised example.c to provide more details about using row_callback(). + +Version 1.2.1beta2 [October 25, 2001] + Added type cast to each NULL appearing in a function call, except for + WINCE functions. + Added makefile.so9. + +Version 1.2.1beta3 [October 27, 2001] + Removed type casts from all NULLs. + Simplified png_create_struct_2(). + +Version 1.2.1beta4 [November 7, 2001] + Revised png_create_info_struct() and png_creat_struct_2(). + Added error message if png_write_info() was omitted. + Type cast NULLs appearing in function calls when _NO_PROTO or + PNG_TYPECAST_NULL is defined. + +Version 1.2.1rc1 [November 24, 2001] + Type cast NULLs appearing in function calls except when PNG_NO_TYPECAST_NULL + is defined. + Changed typecast of "size" argument to png_size_t in pngmem.c calls to + the user malloc_fn, to agree with the prototype in png.h + Added a pop/push operation to pnggccrd.c, to preserve Eflag (Maxim Sobolev) + Updated makefile.sgi to recognize LIBPATH and INCPATH. + Updated various makefiles so "make clean" does not remove previous major + version of the shared library. + +Version 1.2.1rc2 [December 4, 2001] + Always allocate 256-entry internal palette, hist, and trans arrays, to + avoid out-of-bounds memory reference caused by invalid PNG datastreams. + Added a check for prefix_length > data_length in iCCP chunk handler. + +Version 1.2.1 [December 7, 2001] + None. + +Version 1.2.2beta1 [February 22, 2002] + Fixed a bug with reading the length of iCCP profiles (Larry Reeves). + Revised makefile.linux, makefile.gcmmx, and makefile.sgi to generate + libpng.a, libpng12.so (not libpng.so.3), and libpng12/png.h + Revised makefile.darwin to remove "-undefined suppress" option. + Added checks for gamma and chromaticity values over 21474.83, which exceed + the limit for PNG unsigned 32-bit integers when encoded. + Revised calls to png_create_read_struct() and png_create_write_struct() + for simpler debugging. + Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK) + +Version 1.2.2beta2 [February 23, 2002] + Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths. + Check for invalid image dimensions in png_get_IHDR. + Added missing "fi;" in the install target of the SGI makefiles. + Added install-static to all makefiles that make shared libraries. + Always do gamma compensation when image is partially transparent. + +Version 1.2.2beta3 [March 7, 2002] + Compute background.gray and background_1.gray even when color_type is RGB + in case image gets reduced to gray later. + Modified shared-library makefiles to install pkgconfig/libpngNN.pc. + Export (with PNGAPI) png_zalloc, png_zfree, and png_handle_as_unknown + Removed unused png_write_destroy_info prototype from png.h + Eliminated incorrect use of width_mmx from pnggccrd.c in pixel_bytes == 8 case + Added install-shared target to all makefiles that make shared libraries. + Stopped a double free of palette, hist, and trans when not using free_me. + Added makefile.32sunu for Sun Ultra 32 and makefile.64sunu for Sun Ultra 64. + +Version 1.2.2beta4 [March 8, 2002] + Compute background.gray and background_1.gray even when color_type is RGB + in case image gets reduced to gray later (Jason Summers). + Relocated a misplaced /bin/rm in the "install-shared" makefile targets + Added PNG_1_0_X macro which can be used to build a 1.0.x-compatible library. + +Version 1.2.2beta5 [March 26, 2002] + Added missing PNGAPI to several function definitions. + Check for invalid bit_depth or color_type in png_get_IHDR(), and + check for missing PLTE or IHDR in png_push_read_chunk() (Matthias Clasen). + Revised iTXt support to accept NULL for lang and lang_key. + Compute gamma for color components of background even when color_type is gray. + Changed "()" to "{}" in scripts/libpng.pc.in. + Revised makefiles to put png.h and pngconf.h only in $prefix/include/libpngNN + Revised makefiles to make symlink to libpng.so.NN in addition to libpngNN.so + +Version 1.2.2beta6 [March 31, 2002] + +Version 1.0.13beta1 [March 31, 2002] + Prevent png_zalloc() from trying to memset memory that it failed to acquire. + Add typecasts of PNG_MAX_UINT in pngset_cHRM_fixed() (Matt Holgate). + Ensure that the right function (user or default) is used to free the + png_struct after an error in png_create_read_struct_2(). + +Version 1.2.2rc1 [April 7, 2002] + +Version 1.0.13rc1 [April 7, 2002] + Save the ebx register in pnggccrd.c (Sami Farin) + Add "mem_ptr = png_ptr->mem_ptr" in png_destroy_write_struct() (Paul Gardner). + Updated makefiles to put headers in include/libpng and remove old include/*.h. + +Version 1.2.2 [April 15, 2002] + +Version 1.0.13 [April 15, 2002] + Revised description of png_set_filter() in libpng.3/libpng.txt. + Revised makefile.netbsd and added makefile.neNNbsd and makefile.freebsd + +Version 1.0.13patch01 [April 17, 2002] + +Version 1.2.2patch01 [April 17, 2002] + Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and + makefile.sggcc + Fixed VER -> PNGVER typo in makefile.macosx and added install-static to + install + Added install: target to makefile.32sunu and makefile.64sunu + +Version 1.0.13patch03 [April 18, 2002] + +Version 1.2.2patch03 [April 18, 2002] + Revised 15 makefiles to link libpng.a to libpngNN.a and the include libpng + subdirectory to libpngNN subdirectory without the full pathname. + Moved generation of libpng.pc from "install" to "all" in 15 makefiles. + +Version 1.2.3rc1 [April 28, 2002] + Added install-man target to 15 makefiles (Dimitri Papadopolous-Orfanos). + Added $(DESTDIR) feature to 24 makefiles (Tim Mooney) + Fixed bug with $prefix, should be $(prefix) in makefile.hpux. + Updated cygwin-specific portion of pngconf.h and revised makefile.cygwin + Added a link from libpngNN.pc to libpng.pc in 15 makefiles. + Added links from include/libpngNN/*.h to include/*.h in 24 makefiles. + Revised makefile.darwin to make relative links without full pathname. + Added setjmp() at the end of png_create_*_struct_2() in case user forgets + to put one in their application. + Restored png_zalloc() and png_zfree() prototypes to version 1.2.1 and + removed them from module definition files. + +Version 1.2.3rc2 [May 1, 2002] + Fixed bug in reporting number of channels in pngget.c and pngset.c, + that was introduced in version 1.2.2beta5. + Exported png_zalloc(), png_zfree(), png_default_read(), png_default_write(), + png_default_flush(), and png_push_fill_buffer() and included them in + module definition files. + Added "libpng.pc" dependency to the "install-shared" target in 15 makefiles. + +Version 1.2.3rc3 [May 1, 2002] + Revised prototype for png_default_flush() + Remove old libpng.pc and libpngNN.pc before installing new ones. + +Version 1.2.3rc4 [May 2, 2002] + Typos in *.def files (png_default_read|write -> png_default_read|write_data) + In makefiles, changed rm libpng.NN.pc to rm libpngNN.pc + Added libpng-config and libpngNN-config and modified makefiles to install + them. + Changed $(MANPATH) to $(DESTDIR)$(MANPATH) in makefiles + Added "Win32 DLL VB" configuration to projects/msvc/libpng.dsp + +Version 1.2.3rc5 [May 11, 2002] + Changed "error" and "message" in prototypes to "error_message" and + "warning_message" to avoid namespace conflict. + Revised 15 makefiles to build libpng-config from libpng-config-*.in + Once more restored png_zalloc and png_zfree to regular nonexported form. + Restored png_default_read|write_data, png_default_flush, png_read_fill_buffer + to nonexported form, but with PNGAPI, and removed them from module def + files. + +Version 1.2.3rc6 [May 14, 2002] + Removed "PNGAPI" from png_zalloc() and png_zfree() in png.c + Changed "Gz" to "Gd" in projects/msvc/libpng.dsp and zlib.dsp. + Removed leftover libpng-config "sed" script from four makefiles. + Revised libpng-config creating script in 16 makefiles. + +Version 1.2.3 [May 22, 2002] + Revised libpng-config target in makefile.cygwin. + Removed description of png_set_mem_fn() from documentation. + Revised makefile.freebsd. + Minor cosmetic changes to 15 makefiles, e.g., $(DI) = $(DESTDIR)/$(INCDIR). + Revised projects/msvc/README.txt + Changed -lpng to -lpngNN in LDFLAGS in several makefiles. + +Version 1.2.4beta1 [May 24, 2002] + Added libpng.pc and libpng-config to "all:" target in 16 makefiles. + Fixed bug in 16 makefiles: $(DESTDIR)/$(LIBPATH) to $(DESTDIR)$(LIBPATH) + Added missing "\" before closing double quote in makefile.gcmmx. + Plugged various memory leaks; added png_malloc_warn() and png_set_text_2() + functions. + +Version 1.2.4beta2 [June 25, 2002] + Plugged memory leak of png_ptr->current_text (Matt Holgate). + Check for buffer overflow before reading CRC in pngpread.c (Warwick Allison) + Added -soname to the loader flags in makefile.dec, makefile.sgi, and + makefile.sggcc. + Added "test-installed" target to makefile.linux, makefile.gcmmx, + makefile.sgi, and makefile.sggcc. + +Version 1.2.4beta3 [June 28, 2002] + Plugged memory leak of row_buf in pngtest.c when there is a png_error(). + Detect buffer overflow in pngpread.c when IDAT is corrupted with extra data. + Added "test-installed" target to makefile.32sunu, makefile.64sunu, + makefile.beos, makefile.darwin, makefile.dec, makefile.macosx, + makefile.solaris, makefile.hpux, makefile.hpgcc, and makefile.so9. + +Version 1.2.4rc1 and 1.0.14rc1 [July 2, 2002] + Added "test-installed" target to makefile.cygwin and makefile.sco. + Revised pnggccrd.c to be able to back out version 1.0.x via PNG_1_0_X macro. + +Version 1.2.4 and 1.0.14 [July 8, 2002] + Changed png_warning() to png_error() when width is too large to process. + +Version 1.2.4patch01 [July 20, 2002] + Revised makefile.cygwin to use DLL number 12 instead of 13. + +Version 1.2.5beta1 [August 6, 2002] + Added code to contrib/gregbook/readpng2.c to ignore unused chunks. + Replaced toucan.png in contrib/gregbook (it has been corrupt since 1.0.11) + Removed some stray *.o files from contrib/gregbook. + Changed png_error() to png_warning() about "Too much data" in pngpread.c + and about "Extra compressed data" in pngrutil.c. + Prevent png_ptr->pass from exceeding 7 in png_push_finish_row(). + Updated makefile.hpgcc + Updated png.c and pnggccrd.c handling of return from png_mmx_support() + +Version 1.2.5beta2 [August 15, 2002] + Only issue png_warning() about "Too much data" in pngpread.c when avail_in + is nonzero. + Updated makefiles to install a separate libpng.so.3 with its own rpath. + +Version 1.2.5rc1 and 1.0.15rc1 [August 24, 2002] + Revised makefiles to not remove previous minor versions of shared libraries. + +Version 1.2.5rc2 and 1.0.15rc2 [September 16, 2002] + Revised 13 makefiles to remove "-lz" and "-L$(ZLIBLIB)", etc., from shared + library loader directive. + Added missing "$OBJSDLL" line to makefile.gcmmx. + Added missing "; fi" to makefile.32sunu. + +Version 1.2.5rc3 and 1.0.15rc3 [September 18, 2002] + Revised libpng-config script. + +Version 1.2.5 and 1.0.15 [October 3, 2002] + Revised makefile.macosx, makefile.darwin, makefile.hpgcc, and makefile.hpux, + and makefile.aix. + Relocated two misplaced PNGAPI lines in pngtest.c + +Version 1.2.6beta1 [October 22, 2002] + Commented out warning about uninitialized mmx_support in pnggccrd.c. + Changed "IBMCPP__" flag to "__IBMCPP__" in pngconf.h. + Relocated two more misplaced PNGAPI lines in pngtest.c + Fixed memory overrun bug in png_do_read_filler() with 16-bit datastreams, + introduced in version 1.0.2. + Revised makefile.macosx, makefile.dec, makefile.aix, and makefile.32sunu. + +Version 1.2.6beta2 [November 1, 2002] + Added libpng-config "--ldopts" output. + Added "AR=ar" and "ARFLAGS=rc" and changed "ar rc" to "$(AR) $(ARFLAGS)" + in makefiles. + +Version 1.2.6beta3 [July 18, 2004] + Reverted makefile changes from version 1.2.6beta2 and some of the changes + from version 1.2.6beta1; these will be postponed until version 1.2.7. + Version 1.2.6 is going to be a simple bugfix release. + Changed the one instance of "ln -sf" to "ln -f -s" in each Sun makefile. + Fixed potential overrun in pngerror.c by using strncpy instead of memcpy. + Added "#!/bin/sh" at the top of configure, for recognition of the + 'x' flag under Cygwin (Cosmin). + Optimized vacuous tests that silence compiler warnings, in png.c (Cosmin). + Added support for PNG_USER_CONFIG, in pngconf.h (Cosmin). + Fixed the special memory handler for Borland C under DOS, in pngmem.c + (Cosmin). + Removed some spurious assignments in pngrutil.c (Cosmin). + Replaced 65536 with 65536L, and 0xffff with 0xffffL, to silence warnings + on 16-bit platforms (Cosmin). + Enclosed shift op expressions in parentheses, to silence warnings (Cosmin). + Used proper type png_fixed_point, to avoid problems on 16-bit platforms, + in png_handle_sRGB() (Cosmin). + Added compression_type to png_struct, and optimized the window size + inside the deflate stream (Cosmin). + Fixed definition of isnonalpha(), in pngerror.c and pngrutil.c (Cosmin). + Fixed handling of unknown chunks that come after IDAT (Cosmin). + Allowed png_error() and png_warning() to work even if png_ptr == NULL + (Cosmin). + Replaced row_info->rowbytes with row_bytes in png_write_find_filter() + (Cosmin). + Fixed definition of PNG_LIBPNG_VER_DLLNUM (Simon-Pierre). + Used PNG_LIBPNG_VER and PNG_LIBPNG_VER_STRING instead of the hardcoded + values in png.c (Simon-Pierre, Cosmin). + Initialized png_libpng_ver[] with PNG_LIBPNG_VER_STRING (Simon-Pierre). + Replaced PNG_LIBPNG_VER_MAJOR with PNG_LIBPNG_VER_DLLNUM in png.rc + (Simon-Pierre). + Moved the definition of PNG_HEADER_VERSION_STRING near the definitions + of the other PNG_LIBPNG_VER_... symbols in png.h (Cosmin). + Relocated #ifndef PNGAPI guards in pngconf.h (Simon-Pierre, Cosmin). + Updated scripts/makefile.vc(a)win32 (Cosmin). + Updated the MSVC project (Simon-Pierre, Cosmin). + Updated the Borland C++ Builder project (Cosmin). + Avoided access to asm_flags in pngvcrd.c, if PNG_1_0_X is defined (Cosmin). + Commented out warning about uninitialized mmx_support in pngvcrd.c (Cosmin). + Removed scripts/makefile.bd32 and scripts/pngdef.pas (Cosmin). + Added extra guard around inclusion of Turbo C memory headers, in pngconf.h + (Cosmin). + Renamed projects/msvc/ to projects/visualc6/, and projects/borland/ to + projects/cbuilder5/ (Cosmin). + Moved projects/visualc6/png32ms.def to scripts/pngw32.def, + and projects/visualc6/png.rc to scripts/pngw32.rc (Cosmin). + Added projects/visualc6/pngtest.dsp; removed contrib/msvctest/ (Cosmin). + Changed line endings to DOS style in cbuilder5 and visualc6 files, even + in the tar.* distributions (Cosmin). + Updated contrib/visupng/VisualPng.dsp (Cosmin). + Updated contrib/visupng/cexcept.h to version 2.0.0 (Cosmin). + Added a separate distribution with "configure" and supporting files (Junichi). + +Version 1.2.6beta4 [July 28, 2004] + Added user ability to change png_size_t via a PNG_SIZE_T macro. + Added png_sizeof() and png_convert_size() functions. + Added PNG_SIZE_MAX (maximum value of a png_size_t variable. + Added check in png_malloc_default() for (size_t)size != (png_uint_32)size + which would indicate an overflow. + Changed sPLT failure action from png_error to png_warning and abandon chunk. + Changed sCAL and iCCP failures from png_error to png_warning and abandon. + Added png_get_uint_31(png_ptr, buf) function. + Added PNG_UINT_32_MAX macro. + Renamed PNG_MAX_UINT to PNG_UINT_31_MAX. + Made png_zalloc() issue a png_warning and return NULL on potential + overflow. + Turn on PNG_NO_ZALLOC_ZERO by default in version 1.2.x + Revised "clobber list" in pnggccrd.c so it will compile under gcc-3.4. + Revised Borland portion of png_malloc() to return NULL or issue + png_error() according to setting of PNG_FLAG_MALLOC_NULL_MEM_OK. + Added PNG_NO_SEQUENTIAL_READ_SUPPORTED macro to conditionally remove + sequential read support. + Added some "#if PNG_WRITE_SUPPORTED" blocks. + Added #ifdef to remove some redundancy in png_malloc_default(). + Use png_malloc instead of png_zalloc to allocate the pallete. + +Version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004] + Fixed buffer overflow vulnerability (CVE-2004-0597) in png_handle_tRNS(). + Fixed NULL dereference vulnerability (CVE-2004-0598) in png_handle_iCCP(). + Fixed integer overflow vulnerability (CVE-2004-0599) in png_read_png(). + Fixed some harmless bugs in png_handle_sBIT, etc, that would cause + duplicate chunk types to go undetected. + Fixed some timestamps in the -config version + Rearranged order of processing of color types in png_handle_tRNS(). + Added ROWBYTES macro to calculate rowbytes without integer overflow. + Updated makefile.darwin and removed makefile.macosx from scripts directory. + Imposed default one million column, one-million row limits on the image + dimensions, and added png_set_user_limits() function to override them. + Revised use of PNG_SET_USER_LIMITS_SUPPORTED macro. + Fixed wrong cast of returns from png_get_user_width|height_max(). + Changed some "keep the compiler happy" from empty statements to returns, + Revised libpng.txt to remove 1.2.x stuff from the 1.0.x distribution + +Version 1.0.16rc2 and 1.2.6rc2 [August 7, 2004] + Revised makefile.darwin and makefile.solaris. Removed makefile.macosx. + Revised pngtest's png_debug_malloc() to use png_malloc() instead of + png_malloc_default() which is not supposed to be exported. + Fixed off-by-one error in one of the conversions to PNG_ROWBYTES() in + pngpread.c. Bug was introduced in 1.2.6rc1. + Fixed bug in RGB to RGBX transformation introduced in 1.2.6rc1. + Fixed old bug in RGB to Gray transformation. + Fixed problem with 64-bit compilers by casting arguments to abs() + to png_int_32. + Changed "ln -sf" to "ln -f -s" in three makefiles (solaris, sco, so9). + Changed "HANDLE_CHUNK_*" to "PNG_HANDLE_CHUNK_*" (Cosmin) + Added "-@/bin/rm -f $(DL)/$(LIBNAME).so.$(PNGMAJ)" to 15 *NIX makefiles. + Added code to update the row_info->colortype in png_do_read_filler() (MSB). + +Version 1.0.16rc3 and 1.2.6rc3 [August 9, 2004] + Eliminated use of "abs()" in testing cHRM and gAMA values, to avoid + trouble with some 64-bit compilers. Created PNG_OUT_OF_RANGE() macro. + Revised documentation of png_set_keep_unknown_chunks(). + Check handle_as_unknown status in pngpread.c, as in pngread.c previously. + Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_INTERNAL section of png.h + Added "rim" definitions for CONST4 and CONST6 in pnggccrd.c + +Version 1.0.16rc4 and 1.2.6rc4 [August 10, 2004] + Fixed mistake in pngtest.c introduced in 1.2.6rc2 (declaration of + "pinfo" was out of place). + +Version 1.0.16rc5 and 1.2.6rc5 [August 10, 2004] + Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_ASSEMBLER_CODE_SUPPORTED + section of png.h where they were inadvertently placed in version rc3. + +Version 1.2.6 and 1.0.16 [August 15, 2004] + Revised pngtest so memory allocation testing is only done when PNG_DEBUG==1. + +Version 1.2.7beta1 [August 26, 2004] + Removed unused pngasmrd.h file. + Removed references to uu.net for archived files. Added references to + PNG Spec (second edition) and the PNG ISO/IEC Standard. + Added "test-dd" target in 15 makefiles, to run pngtest in DESTDIR. + Fixed bug with "optimized window size" in the IDAT datastream, that + causes libpng to write PNG files with incorrect zlib header bytes. + +Version 1.2.7beta2 [August 28, 2004] + Fixed bug with sCAL chunk and big-endian machines (David Munro). + Undid new code added in 1.2.6rc2 to update the color_type in + png_set_filler(). + Added png_set_add_alpha() that updates color type. + +Version 1.0.17rc1 and 1.2.7rc1 [September 4, 2004] + Revised png_set_strip_filler() to not remove alpha if color_type has alpha. + +Version 1.2.7 and 1.0.17 [September 12, 2004] + Added makefile.hp64 + Changed projects/msvc/png32ms.def to scripts/png32ms.def in makefile.cygwin + +Version 1.2.8beta1 [November 1, 2004] + Fixed bug in png_text_compress() that would fail to complete a large block. + Fixed bug, introduced in libpng-1.2.7, that overruns a buffer during + strip alpha operation in png_do_strip_filler(). + Added PNG_1_2_X definition in pngconf.h + Use #ifdef to comment out png_info_init in png.c and png_read_init in + pngread.c (as of 1.3.0) + +Version 1.2.8beta2 [November 2, 2004] + Reduce color_type to a nonalpha type after strip alpha operation in + png_do_strip_filler(). + +Version 1.2.8beta3 [November 3, 2004] + Revised definitions of PNG_MAX_UINT_32, PNG_MAX_SIZE, and PNG_MAXSUM + +Version 1.2.8beta4 [November 12, 2004] + Fixed (again) definition of PNG_LIBPNG_VER_DLLNUM in png.h (Cosmin). + Added PNG_LIBPNG_BUILD_PRIVATE in png.h (Cosmin). + Set png_ptr->zstream.data_type to Z_BINARY, to avoid unnecessary detection + of data type in deflate (Cosmin). + Deprecated but continue to support SPECIALBUILD and PRIVATEBUILD in favor of + PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING. + +Version 1.2.8beta5 [November 20, 2004] + Use png_ptr->flags instead of png_ptr->transformations to pass + PNG_STRIP_ALPHA info to png_do_strip_filler(), to preserve ABI + compatibility. + Revised handling of SPECIALBUILD, PRIVATEBUILD, + PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING. + +Version 1.2.8rc1 [November 24, 2004] + Moved handling of BUILD macros from pngconf.h to png.h + Added definition of PNG_LIBPNG_BASE_TYPE in png.h, inadvertently + omitted from beta5. + Revised scripts/pngw32.rc + Despammed mailing addresses by masking "@" with "at". + Inadvertently installed a supposedly faster test version of pngrutil.c + +Version 1.2.8rc2 [November 26, 2004] + Added two missing "\" in png.h + Change tests in pngread.c and pngpread.c to + if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) + png_do_read_transformations(png_ptr); + +Version 1.2.8rc3 [November 28, 2004] + Reverted pngrutil.c to version libpng-1.2.8beta5. + Added scripts/makefile.elf with supporting code in pngconf.h for symbol + versioning (John Bowler). + +Version 1.2.8rc4 [November 29, 2004] + Added projects/visualc7 (Simon-pierre). + +Version 1.2.8rc5 [November 29, 2004] + Fixed new typo in scripts/pngw32.rc + +Version 1.2.8 [December 3, 2004] + Removed projects/visualc7, added projects/visualc71. + +Version 1.2.9beta1 [February 21, 2006] + Initialized some structure members in pngwutil.c to avoid gcc-4.0.0 complaints + Revised man page and libpng.txt to make it clear that one should not call + png_read_end or png_write_end after png_read_png or png_write_png. + Updated references to png-mng-implement mailing list. + Fixed an incorrect typecast in pngrutil.c + Added PNG_NO_READ_SUPPORTED conditional for making a write-only library. + Added PNG_NO_WRITE_INTERLACING_SUPPORTED conditional. + Optimized alpha-inversion loops in pngwtran.c + Moved test for nonzero gamma outside of png_build_gamma_table() in pngrtran.c + Make sure num_trans is <= 256 before copying data in png_set_tRNS(). + Make sure num_palette is <= 256 before copying data in png_set_PLTE(). + Interchanged order of write_swap_alpha and write_invert_alpha transforms. + Added parentheses in the definition of PNG_LIBPNG_BUILD_TYPE (Cosmin). + Optimized zlib window flag (CINFO) in contrib/pngsuite/*.png (Cosmin). + Updated scripts/makefile.bc32 for Borland C++ 5.6 (Cosmin). + Exported png_get_uint_32, png_save_uint_32, png_get_uint_16, png_save_uint_16, + png_get_int_32, png_save_int_32, png_get_uint_31 (Cosmin). + Added type cast (png_byte) in png_write_sCAL() (Cosmin). + Fixed scripts/makefile.cygwin (Christian Biesinger, Cosmin). + Default iTXt support was inadvertently enabled. + +Version 1.2.9beta2 [February 21, 2006] + Check for png_rgb_to_gray and png_gray_to_rgb read transformations before + checking for png_read_dither in pngrtran.c + Revised checking of chromaticity limits to accommodate extended RGB + colorspace (John Denker). + Changed line endings in some of the project files to CRLF, even in the + "Unix" tar distributions (Cosmin). + Made png_get_int_32 and png_save_int_32 always available (Cosmin). + Updated scripts/pngos2.def, scripts/pngw32.def and projects/wince/png32ce.def + with the newly exported functions. + Eliminated distributions without the "configure" script. + Updated INSTALL instructions. + +Version 1.2.9beta3 [February 24, 2006] + Fixed CRCRLF line endings in contrib/visupng/VisualPng.dsp + Made libpng.pc respect EXEC_PREFIX (D. P. Kreil, J. Bowler) + Removed reference to pngasmrd.h from Makefile.am + Renamed CHANGES to ChangeLog. + Renamed LICENSE to COPYING. + Renamed ANNOUNCE to NEWS. + Created AUTHORS file. + +Version 1.2.9beta4 [March 3, 2006] + Changed definition of PKGCONFIG from $prefix/lib to $libdir in configure.ac + Reverted to filenames LICENSE and ANNOUNCE; removed AUTHORS and COPYING. + Removed newline from the end of some error and warning messages. + Removed test for sqrt() from configure.ac and configure. + Made swap tables in pngtrans.c PNG_CONST (Carlo Bramix). + Disabled default iTXt support that was inadvertently enabled in + libpng-1.2.9beta1. + Added "OS2" to list of systems that don't need underscores, in pnggccrd.c + Removed libpng version and date from *.c files. + +Version 1.2.9beta5 [March 4, 2006] + Removed trailing blanks from source files. + Put version and date of latest change in each source file, and changed + copyright year accordingly. + More cleanup of configure.ac, Makefile.am, and associated scripts. + Restored scripts/makefile.elf which was inadvertently deleted. + +Version 1.2.9beta6 [March 6, 2006] + Fixed typo (RELEASE) in configuration files. + +Version 1.2.9beta7 [March 7, 2006] + Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am + Fixed inconsistent #ifdef's around png_sig_bytes() and png_set_sCAL_s() + in png.h. + Updated makefile.elf as suggested by debian. + Made cosmetic changes to some makefiles, adding LN_SF and other macros. + Made some makefiles accept "exec_prefix". + +Version 1.2.9beta8 [March 9, 2006] + Fixed some "#if defined (..." which should be "#if defined(..." + Bug introduced in libpng-1.2.8. + Fixed inconsistency in definition of png_default_read_data() + Restored blank that was lost from makefile.sggcc "clean" target in beta7. + Revised calculation of "current" and "major" for irix in ltmain.sh + Changed "mkdir" to "MKDIR_P" in some makefiles. + Separated PNG_EXPAND and PNG_EXPAND_tRNS. + Added png_set_expand_gray_1_2_4_to_8() and deprecated + png_set_gray_1_2_4_to_8() which also expands tRNS to alpha. + +Version 1.2.9beta9 [March 10, 2006] + Include "config.h" in pngconf.h when available. + Added some checks for NULL png_ptr or NULL info_ptr (timeless) + +Version 1.2.9beta10 [March 20, 2006] + Removed extra CR from contrib/visualpng/VisualPng.dsw (Cosmin) + Made pnggccrd.c PIC-compliant (Christian Aichinger). + Added makefile.mingw (Wolfgang Glas). + Revised pngconf.h MMX checking. + +Version 1.2.9beta11 [March 22, 2006] + Fixed out-of-order declaration in pngwrite.c that was introduced in beta9 + Simplified some makefiles by using LIBSO, LIBSOMAJ, and LIBSOVER macros. + +Version 1.2.9rc1 [March 31, 2006] + Defined PNG_USER_PRIVATEBUILD when including "pngusr.h" (Cosmin). + Removed nonsensical assertion check from pngtest.c (Cosmin). + +Version 1.2.9 [April 14, 2006] + Revised makefile.beos and added "none" selector in ltmain.sh + +Version 1.2.10beta1 [April 15, 2006] + Renamed "config.h" to "png_conf.h" and revised Makefile.am to add + -DPNG_BUILDING_LIBPNG to compile directive, and modified pngconf.h + to include png_conf.h only when PNG_BUILDING_LIBPNG is defined. + +Version 1.2.10beta2 [April 15, 2006] + Manually updated Makefile.in and configure. Changed png_conf.h.in + back to config.h. + +Version 1.2.10beta3 [April 15, 2006] + Change png_conf.h back to config.h in pngconf.h. + +Version 1.2.10beta4 [April 16, 2006] + Change PNG_BUILDING_LIBPNG to PNG_CONFIGURE_LIBPNG in config/Makefile*. + +Version 1.2.10beta5 [April 16, 2006] + Added a configure check for compiling assembler code in pnggccrd.c + +Version 1.2.10beta6 [April 17, 2006] + Revised the configure check for pnggccrd.c + Moved -DPNG_CONFIGURE_LIBPNG into @LIBPNG_DEFINES@ + Added @LIBPNG_DEFINES@ to arguments when building libpng.sym + +Version 1.2.10beta7 [April 18, 2006] + Change "exec_prefix=$prefix" to "exec_prefix=$(prefix)" in makefiles. + +Version 1.2.10rc1 [April 19, 2006] + Ensure pngconf.h doesn't define both PNG_USE_PNGGCCRD and PNG_USE_PNGVCRD + Fixed "LN_FS" typo in makefile.sco and makefile.solaris. + +Version 1.2.10rc2 [April 20, 2006] + Added a backslash between -DPNG_CONFIGURE_LIBPNG and -DPNG_NO_ASSEMBLER_CODE + in configure.ac and configure + Made the configure warning about versioned symbols less arrogant. + +Version 1.2.10rc3 [April 21, 2006] + Added a note in libpng.txt that png_set_sig_bytes(8) can be used when + writing an embedded PNG without the 8-byte signature. + Revised makefiles and configure to avoid making links to libpng.so.* + +Version 1.2.10 [April 23, 2006] + Reverted configure to "rc2" state. + +Version 1.2.11beta1 [May 31, 2006] + scripts/libpng.pc.in contained "configure" style version info and would + not work with makefiles. + The shared-library makefiles were linking to libpng.so.0 instead of + libpng.so.3 compatibility as the library. + +Version 1.2.11beta2 [June 2, 2006] + Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid + buffer overflow. + Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb) + +Version 1.2.11beta3 [June 5, 2006] + Prepended "#! /bin/sh" to ltmail.sh and contrib/pngminus/*.sh (Cosmin). + Removed the accidental leftover Makefile.in~ (Cosmin). + Avoided potential buffer overflow and optimized buffer in + png_write_sCAL(), png_write_sCAL_s() (Cosmin). + Removed the include directories and libraries from CFLAGS and LDFLAGS + in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin). + +Version 1.2.11beta4 [June 6, 2006] + Allow zero-length IDAT chunks after the entire zlib datastream, but not + after another intervening chunk type. + +Version 1.0.19rc1, 1.2.11rc1 [June 13, 2006] + Deleted extraneous square brackets from [config.h] in configure.ac + +Version 1.0.19rc2, 1.2.11rc2 [June 14, 2006] + Added prototypes for PNG_INCH_CONVERSIONS functions to png.h + Revised INSTALL and autogen.sh + Fixed typo in several makefiles (-W1 should be -Wl) + Added typedef for png_int_32 and png_uint_32 on 64-bit systems. + +Version 1.0.19rc3, 1.2.11rc3 [June 15, 2006] + Removed the new typedefs for 64-bit systems (delay until version 1.4.0) + Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid + reading out of bounds. + +Version 1.0.19rc4, 1.2.11rc4 [June 15, 2006] + Really removed the new typedefs for 64-bit systems. + +Version 1.0.19rc5, 1.2.11rc5 [June 22, 2006] + Removed png_sig_bytes entry from scripts/pngw32.def + +Version 1.0.19, 1.2.11 [June 26, 2006] + None. + +Version 1.0.20, 1.2.12 [June 27, 2006] + Really increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid + buffer overflow. + +Version 1.2.13beta1 [October 2, 2006] + Removed AC_FUNC_MALLOC from configure.ac + Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h + Change "logical" to "bitwise" throughout documentation. + Detect and fix attempt to write wrong iCCP profile length (CVE-2006-7244) + +Version 1.0.21, 1.2.13 [November 14, 2006] + Fix potential buffer overflow in sPLT chunk handler. + Fix Makefile.am to not try to link to noexistent files. + Check all exported functions for NULL png_ptr. + +Version 1.2.14beta1 [November 17, 2006] + Relocated three misplaced tests for NULL png_ptr. + Built Makefile.in with automake-1.9.6 instead of 1.9.2. + Build configure with autoconf-2.60 instead of 2.59 + +Version 1.2.14beta2 [November 17, 2006] + Added some typecasts in png_zalloc(). + +Version 1.2.14rc1 [November 20, 2006] + Changed "strtod" to "png_strtod" in pngrutil.c + +Version 1.0.22, 1.2.14 [November 27, 2006] + Added missing "$(srcdir)" in Makefile.am and Makefile.in + +Version 1.2.15beta1 [December 3, 2006] + Generated configure with autoconf-2.61 instead of 2.60 + Revised configure.ac to update libpng.pc and libpng-config. + +Version 1.2.15beta2 [December 3, 2006] + Always export MMX asm functions, just stubs if not building pnggccrd.c + +Version 1.2.15beta3 [December 4, 2006] + Add "png_bytep" typecast to profile while calculating length in pngwutil.c + +Version 1.2.15beta4 [December 7, 2006] + Added scripts/CMakeLists.txt + Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta + +Version 1.2.15beta5 [December 7, 2006] + Changed some instances of PNG_ASSEMBLER_* to PNG_MMX_* in pnggccrd.c + Revised scripts/CMakeLists.txt + +Version 1.2.15beta6 [December 13, 2006] + Revised scripts/CMakeLists.txt and configure.ac + +Version 1.2.15rc1 [December 18, 2006] + Revised scripts/CMakeLists.txt + +Version 1.2.15rc2 [December 21, 2006] + Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers. + Added scripts/makefile.nommx + +Version 1.2.15rc3 [December 25, 2006] + Fixed shared library numbering error that was introduced in 1.2.15beta6. + +Version 1.2.15rc4 [December 27, 2006] + Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set. + +Version 1.2.15rc5 [December 31, 2006] + Revised handling of rgb_to_gray. + +Version 1.2.15 [January 5, 2007] + Added some (unsigned long) typecasts in pngtest.c to avoid printing errors. + +Version 1.2.16beta1 [January 6, 2007] + Fix bugs in makefile.nommx + +Version 1.2.16beta2 [January 16, 2007] + Revised scripts/CMakeLists.txt + +Version 1.2.16 [January 31, 2007] + No changes. + +Version 1.2.17beta1 [March 6, 2007] + Revised scripts/CMakeLists.txt to install both shared and static libraries. + Deleted a redundant line from pngset.c. + +Version 1.2.17beta2 [April 26, 2007] + Relocated misplaced test for png_ptr == NULL in pngpread.c + Change "==" to "&" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN + flags. + Changed remaining instances of PNG_ASSEMBLER_* to PNG_MMX_* + Added pngerror() when write_IHDR fails in deflateInit2(). + Added "const" to some array declarations. + Mention examples of libpng usage in the libpng*.txt and libpng.3 documents. + +Version 1.2.17rc1 [May 4, 2007] + No changes. + +Version 1.2.17rc2 [May 8, 2007] + Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications + calling set_unknown_chunk_location() need them. + Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in + png_set_expand_gray_1_2_4_to_8(). + Added png_ptr->unknown_chunk to hold working unknown chunk data, so it + can be free'ed in case of error. Revised unknown chunk handling in + pngrutil.c and pngpread.c to use this structure. + +Version 1.2.17rc3 [May 8, 2007] + Revised symbol-handling in configure script. + +Version 1.2.17rc4 [May 10, 2007] + Revised unknown chunk handling to avoid storing unknown critical chunks. + +Version 1.0.25 [May 15, 2007] +Version 1.2.17 [May 15, 2007] + Added "png_ptr->num_trans=0" before error return in png_handle_tRNS, + to eliminate a vulnerability (CVE-2007-2445, CERT VU#684664) + +Version 1.0.26 [May 15, 2007] +Version 1.2.18 [May 15, 2007] + Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script + +Version 1.2.19beta1 [May 18, 2007] + Changed "const static" to "static PNG_CONST" everywhere, mostly undoing + change of libpng-1.2.17beta2. Changed other "const" to "PNG_CONST" + Changed some handling of unused parameters, to avoid compiler warnings. + "if (unused == NULL) return;" becomes "unused = unused". + +Version 1.2.19beta2 [May 18, 2007] + Only use the valid bits of tRNS value in png_do_expand() (Brian Cartier) + +Version 1.2.19beta3 [May 19, 2007] + Add some "png_byte" typecasts in png_check_keyword() and write new_key + instead of key in zTXt chunk (Kevin Ryde). + +Version 1.2.19beta4 [May 21, 2007] + Add png_snprintf() function and use it in place of sprint() for improved + defense against buffer overflows. + +Version 1.2.19beta5 [May 21, 2007] + Fixed png_handle_tRNS() to only use the valid bits of tRNS value. + Changed handling of more unused parameters, to avoid compiler warnings. + Removed some PNG_CONST in pngwutil.c to avoid compiler warnings. + +Version 1.2.19beta6 [May 22, 2007] + Added some #ifdef PNG_MMX_CODE_SUPPORTED where needed in pngvcrd.c + Added a special "_MSC_VER" case that defines png_snprintf to _snprintf + +Version 1.2.19beta7 [May 22, 2007] + Squelched png_squelch_warnings() in pnggccrd.c and added + an #ifdef PNG_MMX_CODE_SUPPORTED block around the declarations that caused + the warnings that png_squelch_warnings was squelching. + +Version 1.2.19beta8 [May 22, 2007] + Removed __MMX__ from test in pngconf.h. + +Version 1.2.19beta9 [May 23, 2007] + Made png_squelch_warnings() available via PNG_SQUELCH_WARNINGS macro. + Revised png_squelch_warnings() so it might work. + Updated makefile.sgcc and makefile.solaris; added makefile.solaris-x86. + +Version 1.2.19beta10 [May 24, 2007] + Resquelched png_squelch_warnings(), use "__attribute__((used))" instead. + +Version 1.4.0beta1 [April 20, 2006] + Enabled iTXt support (changes png_struct, thus requires so-number change). + Cleaned up PNG_ASSEMBLER_CODE_SUPPORTED vs PNG_MMX_CODE_SUPPORTED + Eliminated PNG_1_0_X and PNG_1_2_X macros. + Removed deprecated functions png_read_init, png_write_init, png_info_init, + png_permit_empty_plte, png_set_gray_1_2_4_to_8, png_check_sig, and + removed the deprecated macro PNG_MAX_UINT. + Moved "PNG_INTERNAL" parts of png.h and pngconf.h into pngintrn.h + Removed many WIN32_WCE #ifdefs (Cosmin). + Reduced dependency on C-runtime library when on Windows (Simon-Pierre) + Replaced sprintf() with png_sprintf() (Simon-Pierre) + +Version 1.4.0beta2 [April 20, 2006] + Revised makefiles and configure to avoid making links to libpng.so.* + Moved some leftover MMX-related defines from pngconf.h to pngintrn.h + Updated scripts/pngos2.def, pngw32.def, and projects/wince/png32ce.def + +Version 1.4.0beta3 [May 10, 2006] + Updated scripts/pngw32.def to comment out MMX functions. + Added PNG_NO_GET_INT_32 and PNG_NO_SAVE_INT_32 macros. + Scripts/libpng.pc.in contained "configure" style version info and would + not work with makefiles. + Revised pngconf.h and added pngconf.h.in, so makefiles and configure can + pass defines to libpng and applications. + +Version 1.4.0beta4 [May 11, 2006] + Revised configure.ac, Makefile.am, and many of the makefiles to write + their defines in pngconf.h. + +Version 1.4.0beta5 [May 15, 2006] + Added a missing semicolon in Makefile.am and Makefile.in + Deleted extraneous square brackets from configure.ac + +Version 1.4.0beta6 [June 2, 2006] + Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid + buffer overflow. + Changed sonum from 0 to 1. + Removed unused prototype for png_check_sig() from png.h + +Version 1.4.0beta7 [June 16, 2006] + Exported png_write_sig (Cosmin). + Optimized buffer in png_handle_cHRM() (Cosmin). + Set pHYs = 2835 x 2835 pixels per meter, and added + sCAL = 0.352778e-3 x 0.352778e-3 meters, in pngtest.png (Cosmin). + Added png_set_benign_errors(), png_benign_error(), png_chunk_benign_error(). + Added typedef for png_int_32 and png_uint_32 on 64-bit systems. + Added "(unsigned long)" typecast on png_uint_32 variables in printf lists. + +Version 1.4.0beta8 [June 22, 2006] + Added demonstration of user chunk support in pngtest.c, to support the + public sTER chunk and a private vpAg chunk. + +Version 1.4.0beta9 [July 3, 2006] + Removed ordinals from scripts/pngw32.def and removed png_info_int and + png_set_gray_1_2_4_to_8 entries. + Inline call of png_get_uint_32() in png_get_uint_31(). + Use png_get_uint_31() to get vpAg width and height in pngtest.c + Removed WINCE and Netware projects. + Removed standalone Y2KINFO file. + +Version 1.4.0beta10 [July 12, 2006] + Eliminated automatic copy of pngconf.h to pngconf.h.in from configure and + some makefiles, because it was not working reliably. Instead, distribute + pngconf.h.in along with pngconf.h and cause configure and some of the + makefiles to update pngconf.h from pngconf.h.in. + Added pngconf.h to DEPENDENCIES in Makefile.am + +Version 1.4.0beta11 [August 19, 2006] + Removed AC_FUNC_MALLOC from configure.ac. + Added a warning when writing iCCP profile with mismatched profile length. + Patched pnggccrd.c to assemble on x86_64 platforms. + Moved chunk header reading into a separate function png_read_chunk_header() + in pngrutil.c. The chunk header (len+sig) is now serialized in a single + operation (Cosmin). + Implemented support for I/O states. Added png_ptr member io_state, and + functions png_get_io_chunk_name() and png_get_io_state() in pngget.c + (Cosmin). + Added png_get_io_chunk_name and png_get_io_state to scripts/*.def (Cosmin). + Renamed scripts/pngw32.* to scripts/pngwin.* (Cosmin). + Removed the include directories and libraries from CFLAGS and LDFLAGS + in scripts/makefile.gcc (Cosmin). + Used png_save_uint_32() to set vpAg width and height in pngtest.c (Cosmin). + Cast to proper type when getting/setting vpAg units in pngtest.c (Cosmin). + Added pngintrn.h to the Visual C++ projects (Cosmin). + Removed scripts/list (Cosmin). + Updated copyright year in scripts/pngwin.def (Cosmin). + Removed PNG_TYPECAST_NULL and used standard NULL consistently (Cosmin). + Disallowed the user to redefine png_size_t, and enforced a consistent use + of png_size_t across libpng (Cosmin). + Changed the type of png_ptr->rowbytes, PNG_ROWBYTES() and friends + to png_size_t (Cosmin). + Removed png_convert_size() and replaced png_sizeof with sizeof (Cosmin). + Removed some unnecessary type casts (Cosmin). + Changed prototype of png_get_compression_buffer_size() and + png_set_compression_buffer_size() to work with png_size_t instead of + png_uint_32 (Cosmin). + Removed png_memcpy_check() and png_memset_check() (Cosmin). + Fixed a typo (png_byte --> png_bytep) in libpng.3 and libpng.txt (Cosmin). + Clarified that png_zalloc() does not clear the allocated memory, + and png_zalloc() and png_zfree() cannot be PNGAPI (Cosmin). + Renamed png_mem_size_t to png_alloc_size_t, fixed its definition in + pngconf.h, and used it in all memory allocation functions (Cosmin). + Renamed pngintrn.h to pngpriv.h, added a comment at the top of the file + mentioning that the symbols declared in that file are private, and + updated the scripts and the Visual C++ projects accordingly (Cosmin). + Removed circular references between pngconf.h and pngconf.h.in in + scripts/makefile.vc*win32 (Cosmin). + Removing trailing '.' from the warning and error messages (Cosmin). + Added pngdefs.h that is built by makefile or configure, instead of + pngconf.h.in (Glenn). + Detect and fix attempt to write wrong iCCP profile length. + +Version 1.4.0beta12 [October 19, 2006] + Changed "logical" to "bitwise" in the documentation. + Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h + Add a typecast to stifle compiler warning in pngrutil.c + +Version 1.4.0beta13 [November 10, 2006] + Fix potential buffer overflow in sPLT chunk handler. + Fix Makefile.am to not try to link to noexistent files. + +Version 1.4.0beta14 [November 15, 2006] + Check all exported functions for NULL png_ptr. + +Version 1.4.0beta15 [November 17, 2006] + Relocated two misplaced tests for NULL png_ptr. + Built Makefile.in with automake-1.9.6 instead of 1.9.2. + Build configure with autoconf-2.60 instead of 2.59 + Add "install: all" in Makefile.am so "configure; make install" will work. + +Version 1.4.0beta16 [November 17, 2006] + Added a typecast in png_zalloc(). + +Version 1.4.0beta17 [December 4, 2006] + Changed "new_key[79] = '\0';" to "(*new_key)[79] = '\0';" in pngwutil.c + Add "png_bytep" typecast to profile while calculating length in pngwutil.c + +Version 1.4.0beta18 [December 7, 2006] + Added scripts/CMakeLists.txt + +Version 1.4.0beta19 [May 16, 2007] + Revised scripts/CMakeLists.txt + Rebuilt configure and Makefile.in with newer tools. + Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers. + Added scripts/makefile.nommx + +Version 1.4.0beta20 [July 9, 2008] + Moved several PNG_HAVE_* macros from pngpriv.h to png.h because applications + calling set_unknown_chunk_location() need them. + Moved several macro definitions from pngpriv.h to pngconf.h + Merge with changes to the 1.2.X branch, as of 1.2.30beta04. + Deleted all use of the MMX assembler code and Intel-licensed optimizations. + Revised makefile.mingw + +Version 1.4.0beta21 [July 21, 2008] + Moved local array "chunkdata" from pngrutil.c to the png_struct, so + it will be freed by png_read_destroy() in case of a read error (Kurt + Christensen). + +Version 1.4.0beta22 [July 21, 2008] + Change "purpose" and "buffer" to png_ptr->chunkdata to avoid memory leaking. + +Version 1.4.0beta23 [July 22, 2008] + Change "chunkdata = NULL" to "png_ptr->chunkdata = NULL" several places in + png_decompress_chunk(). + +Version 1.4.0beta24 [July 25, 2008] + Change all remaining "chunkdata" to "png_ptr->chunkdata" in + png_decompress_chunk(), and remove "chunkdata" from parameter list. + Put a call to png_check_chunk_name() in png_read_chunk_header(). + Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte. + Removed two calls to png_check_chunk_name() occurring later in the process. + Define PNG_NO_ERROR_NUMBERS by default in pngconf.h + +Version 1.4.0beta25 [July 30, 2008] + Added a call to png_check_chunk_name() in pngpread.c + Reverted png_check_chunk_name() to accept a name with a lowercase 3rd byte. + Added png_push_have_buffer() function to pngpread.c + Eliminated PNG_BIG_ENDIAN_SUPPORTED and associated png_get_* macros. + Made inline expansion of png_get_*() optional with PNG_USE_READ_MACROS. + Eliminated all PNG_USELESS_TESTS and PNG_CORRECT_PALETTE_SUPPORTED code. + Synced contrib directory and configure files with libpng-1.2.30beta06. + Eliminated no-longer-used pngdefs.h (but it's still built in the makefiles) + Relocated a misplaced "#endif /* PNG_NO_WRITE_FILTER */" in pngwutil.c + +Version 1.4.0beta26 [August 4, 2008] + Removed png_push_have_buffer() function in pngpread.c. It increased the + compiled library size slightly. + Changed "-Wall" to "-W -Wall" in the CFLAGS in all makefiles (Cosmin Truta) + Declared png_ptr "volatile" in pngread.c and pngwrite.c to avoid warnings. + Updated contrib/visupng/cexcept.h to version 2.0.1 + Added PNG_LITERAL_CHARACTER macros for #, [, and ]. + +Version 1.4.0beta27 [August 5, 2008] + Revised usage of PNG_LITERAL_SHARP in pngerror.c. + Moved newline character from individual png_debug messages into the + png_debug macros. + Allow user to #define their own png_debug, png_debug1, and png_debug2. + +Version 1.4.0beta28 [August 5, 2008] + Revised usage of PNG_LITERAL_SHARP in pngerror.c. + Added PNG_STRING_NEWLINE macro + +Version 1.4.0beta29 [August 9, 2008] + Revised usage of PNG_STRING_NEWLINE to work on non-ISO compilers. + Added PNG_STRING_COPYRIGHT macro. + Added non-ISO versions of png_debug macros. + +Version 1.4.0beta30 [August 14, 2008] + Added premultiplied alpha feature (Volker Wiendl). + +Version 1.4.0beta31 [August 18, 2008] + Moved png_set_premultiply_alpha from pngtrans.c to pngrtran.c + Removed extra crc check at the end of png_handle_cHRM(). Bug introduced + in libpng-1.4.0beta20. + +Version 1.4.0beta32 [August 19, 2008] + Added PNG_WRITE_FLUSH_SUPPORTED block around new png_flush() call. + Revised PNG_NO_STDIO version of png_write_flush() + +Version 1.4.0beta33 [August 20, 2008] + Added png_get|set_chunk_cache_max() to limit the total number of sPLT, + text, and unknown chunks that can be stored. + +Version 1.4.0beta34 [September 6, 2008] + Shortened tIME_string to 29 bytes in pngtest.c + Fixed off-by-one error introduced in png_push_read_zTXt() function in + libpng-1.2.30beta04/pngpread.c (Harald van Dijk) + +Version 1.4.0beta35 [October 6, 2008] + Changed "trans_values" to "trans_color". + Changed so-number from 0 to 14. Some OS do not like 0. + Revised makefile.darwin to fix shared library numbering. + Change png_set_gray_1_2_4_to_8() to png_set_expand_gray_1_2_4_to_8() + in example.c (debian bug report) + +Version 1.4.0beta36 [October 25, 2008] + Sync with tEXt vulnerability fix in libpng-1.2.33rc02. + +Version 1.4.0beta37 [November 13, 2008] + Added png_check_cHRM in png.c and moved checking from pngget.c, pngrutil.c, + and pngwrite.c + +Version 1.4.0beta38 [November 22, 2008] + Added check for zero-area RGB cHRM triangle in png_check_cHRM() and + png_check_cHRM_fixed(). + +Version 1.4.0beta39 [November 23, 2008] + Revised png_warning() to write its message on standard output by default + when warning_fn is NULL. + +Version 1.4.0beta40 [November 24, 2008] + Eliminated png_check_cHRM(). Instead, always use png_check_cHRM_fixed(). + In png_check_cHRM_fixed(), ensure white_y is > 0, and removed redundant + check for all-zero coordinates that is detected by the triangle check. + +Version 1.4.0beta41 [November 26, 2008] + Fixed string vs pointer-to-string error in png_check_keyword(). + Rearranged test expressions in png_check_cHRM_fixed() to avoid internal + overflows. + Added PNG_NO_CHECK_cHRM conditional. + +Version 1.4.0beta42, 43 [December 1, 2008] + Merge png_debug with version 1.2.34beta04. + +Version 1.4.0beta44 [December 6, 2008] + Removed redundant check for key==NULL before calling png_check_keyword() + to ensure that new_key gets initialized and removed extra warning + (Merge with version 1.2.34beta05 -- Arvan Pritchard). + +Version 1.4.0beta45 [December 9, 2008] + In png_write_png(), respect the placement of the filler bytes in an earlier + call to png_set_filler() (Jim Barry). + +Version 1.4.0beta46 [December 10, 2008] + Undid previous change and added PNG_TRANSFORM_STRIP_FILLER_BEFORE and + PNG_TRANSFORM_STRIP_FILLER_AFTER conditionals and deprecated + PNG_TRANSFORM_STRIP_FILLER (Jim Barry). + +Version 1.4.0beta47 [December 15, 2008] + Support for dithering was disabled by default, because it has never + been well tested and doesn't work very well. The code has not + been removed, however, and can be enabled by building libpng with + PNG_READ_DITHER_SUPPORTED defined. + +Version 1.4.0beta48 [February 14, 2009] + Added new exported function png_calloc(). + Combined several instances of png_malloc(); png_memset() into png_calloc(). + Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24 + but was never defined. + +Version 1.4.0beta49 [February 28, 2009] + Added png_fileno() macro to pngconf.h, used in pngwio.c + Corrected order of #ifdef's in png_debug definition in png.h + Fixed bug introduced in libpng-1.4.0beta48 with the memset arguments + for pcal_params. + Fixed order of #ifdef directives in the png_debug defines in png.h + (bug introduced in libpng-1.2.34/1.4.0beta29). + Revised comments in png_set_read_fn() and png_set_write_fn(). + +Version 1.4.0beta50 [March 18, 2009] + Use png_calloc() instead of png_malloc() to allocate big_row_buf when + reading an interlaced file, to avoid a possible UMR. + Undid revision of PNG_NO_STDIO version of png_write_flush(). Users + having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined + or supply their own flush_fn() replacement. + Revised libpng*.txt and png.h documentation about use of png_write_flush() + and png_set_write_fn(). + Removed fflush() from pngtest.c. + Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h + +Version 1.4.0beta51 [March 21, 2009] + Removed new png_fileno() macro from pngconf.h . + +Version 1.4.0beta52 [March 27, 2009] + Relocated png_do_chop() ahead of building gamma tables in pngrtran.c + This avoids building 16-bit gamma tables unnecessarily. + Removed fflush() from pngtest.c. + Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h + Added a section on differences between 1.0.x and 1.2.x to libpng.3/libpng.txt + +Version 1.4.0beta53 [April 1, 2009] + Removed some remaining MMX macros from pngpriv.h + Fixed potential memory leak of "new_name" in png_write_iCCP() (Ralph Giles) + +Version 1.4.0beta54 [April 13, 2009] + Added "ifndef PNG_SKIP_SETJMP_CHECK" block in pngconf.h to allow + application code writers to bypass the check for multiple inclusion + of setjmp.h when they know that it is safe to ignore the situation. + Eliminated internal use of setjmp() in pngread.c and pngwrite.c + Reordered ancillary chunks in pngtest.png to be the same as what + pngtest now produces, and made some cosmetic changes to pngtest output. + Eliminated deprecated png_read_init_3() and png_write_init_3() functions. + +Version 1.4.0beta55 [April 15, 2009] + Simplified error handling in pngread.c and pngwrite.c by putting + the new png_read_cleanup() and png_write_cleanup() functions inline. + +Version 1.4.0beta56 [April 25, 2009] + Renamed "user_chunk_data" to "my_user_chunk_data" in pngtest.c to suppress + "shadowed declaration" warning from gcc-4.3.3. + Renamed "gamma" to "png_gamma" in pngset.c to avoid "shadowed declaration" + warning about a global "gamma" variable in math.h on some platforms. + +Version 1.4.0beta57 [May 2, 2009] + Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24 + but was never defined (again). + Rebuilt configure scripts with autoconf-2.63 instead of 2.62 + Removed pngprefs.h and MMX from makefiles + +Version 1.4.0beta58 [May 14, 2009] + Changed pngw32.def to pngwin.def in makefile.mingw (typo was introduced + in beta57). + Clarified usage of sig_bit versus sig_bit_p in example.c (Vincent Torri) + +Version 1.4.0beta59 [May 15, 2009] + Reformated sources in libpng style (3-space intentation, comment format) + Fixed typo in libpng docs (PNG_FILTER_AVE should be PNG_FILTER_AVG) + Added sections about the git repository and our coding style to the + documentation + Relocated misplaced #endif in pngwrite.c, sCAL chunk handler. + +Version 1.4.0beta60 [May 19, 2009] + Conditionally compile png_read_finish_row() which is not used by + progressive readers. + Added contrib/pngminim/preader to demonstrate building minimal progressive + decoder, based on contrib/gregbook with embedded libpng and zlib. + +Version 1.4.0beta61 [May 20, 2009] + In contrib/pngminim/*, renamed "makefile.std" to "makefile", since there + is only one makefile in those directories, and revised the README files + accordingly. + More reformatting of comments, mostly to capitalize sentences. + +Version 1.4.0beta62 [June 2, 2009] + Added "#define PNG_NO_WRITE_SWAP" to contrib/pngminim/encoder/pngusr.h + and "define PNG_NO_READ_SWAP" to decoder/pngusr.h and preader/pngusr.h + Reformatted several remaining "else statement" into two lines. + Added a section to the libpng documentation about using png_get_io_ptr() + in configure scripts to detect the presence of libpng. + +Version 1.4.0beta63 [June 15, 2009] + Revised libpng*.txt and libpng.3 to mention calling png_set_IHDR() + multiple times and to specify the sample order in the tRNS chunk, + because the ISO PNG specification has a typo in the tRNS table. + Changed several PNG_UNKNOWN_CHUNK_SUPPORTED to + PNG_HANDLE_AS_UNKNOWN_SUPPORTED, to make the png_set_keep mechanism + available for ignoring known chunks even when not saving unknown chunks. + Adopted preference for consistent use of "#ifdef" and "#ifndef" versus + "#if defined()" and "if !defined()" where possible. + +Version 1.4.0beta64 [June 24, 2009] + Eliminated PNG_LEGACY_SUPPORTED code. + Moved the various unknown chunk macro definitions outside of the + PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks. + +Version 1.4.0beta65 [June 26, 2009] + Added a reference to the libpng license in each file. + +Version 1.4.0beta66 [June 27, 2009] + Refer to the libpng license instead of the libpng license in each file. + +Version 1.4.0beta67 [July 6, 2009] + Relocated INVERT_ALPHA within png_read_png() and png_write_png(). + Added high-level API transform PNG_TRANSFORM_GRAY_TO_RGB. + Added an "xcode" project to the projects directory (Alam Arias). + +Version 1.4.0beta68 [July 19, 2009] + Avoid some tests in filter selection in pngwutil.c + +Version 1.4.0beta69 [July 25, 2009] + Simplified the new filter-selection test. This runs faster in the + common "PNG_ALL_FILTERS" and PNG_FILTER_NONE cases. + Removed extraneous declaration from the new call to png_read_gray_to_rgb() + (bug introduced in libpng-1.4.0beta67). + Fixed up xcode project (Alam Arias) + Added a prototype for png_64bit_product() in png.c + +Version 1.4.0beta70 [July 27, 2009] + Avoid a possible NULL dereference in debug build, in png_set_text_2(). + (bug introduced in libpng-0.95, discovered by Evan Rouault) + +Version 1.4.0beta71 [July 29, 2009] + Rebuilt configure scripts with autoconf-2.64. + +Version 1.4.0beta72 [August 1, 2009] + Replaced *.tar.lzma with *.tar.xz in distribution. Get the xz codec + from . + +Version 1.4.0beta73 [August 1, 2009] + Reject attempt to write iCCP chunk with negative embedded profile length + (JD Chen) (CVE-2009-5063). + +Version 1.4.0beta74 [August 8, 2009] + Changed png_ptr and info_ptr member "trans" to "trans_alpha". + +Version 1.4.0beta75 [August 21, 2009] + Removed an extra png_debug() recently added to png_write_find_filter(). + Fixed incorrect #ifdef in pngset.c regarding unknown chunk support. + +Version 1.4.0beta76 [August 22, 2009] + Moved an incorrectly located test in png_read_row() in pngread.c + +Version 1.4.0beta77 [August 27, 2009] + Removed lpXYZ.tar.bz2 (with CRLF), KNOWNBUG, libpng-x.y.z-KNOWNBUG.txt, + and the "noconfig" files from the distribution. + Moved CMakeLists.txt from scripts into the main libpng directory. + Various bugfixes and improvements to CMakeLists.txt (Philip Lowman) + +Version 1.4.0beta78 [August 31, 2009] + Converted all PNG_NO_* tests to PNG_*_SUPPORTED everywhere except pngconf.h + Eliminated PNG_NO_FREE_ME and PNG_FREE_ME_SUPPORTED macros. + Use png_malloc plus a loop instead of png_calloc() to initialize + row_pointers in png_read_png(). + +Version 1.4.0beta79 [September 1, 2009] + Eliminated PNG_GLOBAL_ARRAYS and PNG_LOCAL_ARRAYS; always use local arrays. + Eliminated PNG_CALLOC_SUPPORTED macro and always provide png_calloc(). + +Version 1.4.0beta80 [September 17, 2009] + Removed scripts/libpng.icc + Changed typecast of filler from png_byte to png_uint_16 in png_set_filler(). + (Dennis Gustafsson) + Fixed typo introduced in beta78 in pngtest.c ("#if def " should be "#ifdef ") + +Version 1.4.0beta81 [September 23, 2009] + Eliminated unused PNG_FLAG_FREE_* defines from pngpriv.h + Expanded TAB characters in pngrtran.c + Removed PNG_CONST from all "PNG_CONST PNG_CHNK" declarations to avoid + compiler complaints about doubly declaring things "const". + Changed all "#if [!]defined(X)" to "if[n]def X" where possible. + Eliminated unused png_ptr->row_buf_size + +Version 1.4.0beta82 [September 25, 2009] + Moved redundant IHDR checking into new png_check_IHDR() in png.c + and report all errors found in the IHDR data. + Eliminated useless call to png_check_cHRM() from pngset.c + +Version 1.4.0beta83 [September 25, 2009] + Revised png_check_IHDR() to eliminate bogus complaint about filter_type. + +Version 1.4.0beta84 [September 30, 2009] + Fixed some inconsistent indentation in pngconf.h + Revised png_check_IHDR() to add a test for width variable less than 32-bit. + +Version 1.4.0beta85 [October 1, 2009] + Revised png_check_IHDR() again, to check info_ptr members instead of + the contents of the returned parameters. + +Version 1.4.0beta86 [October 9, 2009] + Updated the "xcode" project (Alam Arias). + Eliminated a shadowed declaration of "pp" in png_handle_sPLT(). + +Version 1.4.0rc01 [October 19, 2009] + Trivial cosmetic changes. + +Version 1.4.0beta87 [October 30, 2009] + Moved version 1.4.0 back into beta. + +Version 1.4.0beta88 [October 30, 2009] + Revised libpng*.txt section about differences between 1.2.x and 1.4.0 + because most of the new features have now been ported back to 1.2.41 + +Version 1.4.0beta89 [November 1, 2009] + More bugfixes and improvements to CMakeLists.txt (Philip Lowman) + Removed a harmless extra png_set_invert_alpha() from pngwrite.c + Apply png_user_chunk_cache_max within png_decompress_chunk(). + Merged libpng-1.2.41.txt with libpng-1.4.0.txt where appropriate. + +Version 1.4.0beta90 [November 2, 2009] + Removed all remaining WIN32_WCE #ifdefs except those involving the + time.h "tm" structure + +Version 1.4.0beta91 [November 3, 2009] + Updated scripts/pngw32.def and projects/wince/png32ce.def + Copied projects/wince/png32ce.def to the scripts directory. + Added scripts/makefile.wce + Patched ltmain.sh for wince support. + Added PNG_CONVERT_tIME_SUPPORTED macro. + +Version 1.4.0beta92 [November 4, 2009] + Make inclusion of time.h in pngconf.h depend on PNG_CONVERT_tIME_SUPPORTED + Make #define PNG_CONVERT_tIME_SUPPORTED depend on PNG_WRITE_tIME_SUPPORTED + Revised libpng*.txt to describe differences from 1.2.40 to 1.4.0 (instead + of differences from 1.2.41 to 1.4.0) + +Version 1.4.0beta93 [November 7, 2009] + Added PNG_DEPSTRUCT, PNG_DEPRECATED, PNG_USE_RESULT, PNG_NORETURN, and + PNG_ALLOCATED macros to detect deprecated direct access to the + png_struct or info_struct members and other deprecated usage in + applications (John Bowler). + Updated scripts/makefile* to add "-DPNG_CONFIGURE_LIBPNG" to CFLAGS, + to prevent warnings about direct access to png structs by libpng + functions while building libpng. They need to be tested, especially + those using compilers other than gcc. + Updated projects/visualc6 and visualc71 with "/d PNG_CONFIGURE_LIBPNG". + They should work but still need to be updated to remove + references to pnggccrd.c or pngvcrd.c and ASM building. + Added README.txt to the beos, cbuilder5, netware, and xcode projects warning + that they need to be updated, to remove references to pnggccrd.c and + pngvcrd.c and to depend on pngpriv.h + Removed three direct references to read_info_ptr members in pngtest.c + that were detected by the new PNG_DEPSTRUCT macro. + Moved the png_debug macro definitions and the png_read_destroy(), + png_write_destroy() and png_far_to_near() prototypes from png.h + to pngpriv.h (John Bowler) + Moved the synopsis lines for png_read_destroy(), png_write_destroy() + png_debug(), png_debug1(), and png_debug2() from libpng.3 to libpngpf.3. + +Version 1.4.0beta94 [November 9, 2009] + Removed the obsolete, unused pnggccrd.c and pngvcrd.c files. + Updated CMakeLists.txt to add "-DPNG_CONFIGURE_LIBPNG" to the definitions. + Removed dependency of pngtest.o on pngpriv.h in the makefiles. + Only #define PNG_DEPSTRUCT, etc. in pngconf.h if not already defined. + +Version 1.4.0beta95 [November 10, 2009] + Changed png_check_sig() to !png_sig_cmp() in contrib programs. + Added -DPNG_CONFIGURE_LIBPNG to contrib/pngminm/*/makefile + Changed png_check_sig() to !png_sig_cmp() in contrib programs. + Corrected the png_get_IHDR() call in contrib/gregbook/readpng2.c + Changed pngminim/*/gather.sh to stop trying to remove pnggccrd.c and pngvcrd.c + Added dependency on pngpriv.h in contrib/pngminim/*/makefile + +Version 1.4.0beta96 [November 12, 2009] + Renamed scripts/makefile.wce to scripts/makefile.cegcc + Revised Makefile.am to use libpng.sys while building libpng.so + so that only PNG_EXPORT functions are exported. + Removed the deprecated png_check_sig() function/macro. + Removed recently removed function names from scripts/*.def + Revised pngtest.png to put chunks in the same order written by pngtest + (evidently the same change made in libpng-1.0beta54 was lost). + Added PNG_PRIVATE macro definition in pngconf.h for possible future use. + +Version 1.4.0beta97 [November 13, 2009] + Restored pngtest.png to the libpng-1.4.0beta7 version. + Removed projects/beos and netware.txt; no one seems to be supporting them. + Revised Makefile.in + +Version 1.4.0beta98 [November 13, 2009] + Added the "xcode" project to zip distributions, + Fixed a typo in scripts/pngwin.def introduced in beta97. + +Version 1.4.0beta99 [November 14, 2009] + Moved libpng-config.in and libpng.pc-configure.in out of the scripts + directory, to libpng-config.in and libpng-pc.in, respectively, and + modified Makefile.am and configure.ac accordingly. Now "configure" + needs nothing from the "scripts" directory. + Avoid redefining PNG_CONST in pngconf.h + +Version 1.4.0beta100 [November 14, 2009] + Removed ASM builds from projects/visualc6 and projects/visualc71 + Removed scripts/makefile.nommx and makefile.vcawin32 + Revised CMakeLists.txt to account for new location of libpng-config.in + and libpng-pc.in + Updated INSTALL to reflect removal and relocation of files. + +Version 1.4.0beta101 [November 14, 2009] + Restored the binary files (*.jpg, *.png, some project files) that were + accidentally deleted from the zip and 7z distributions when the xcode + project was added. + +Version 1.4.0beta102 [November 18, 2009] + Added libpng-config.in and libpng-pc.in to the zip and 7z distributions. + Fixed a typo in projects/visualc6/pngtest.dsp, introduced in beta100. + Moved descriptions of makefiles and other scripts out of INSTALL into + scripts/README.txt + Updated the copyright year in scripts/pngwin.rc from 2006 to 2009. + +Version 1.4.0beta103 [November 21, 2009] + Removed obsolete comments about ASM from projects/visualc71/README_zlib.txt + Align row_buf on 16-byte boundary in memory. + Restored the PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED guard around the call + to png_flush() after png_write_IEND(). See 1.4.0beta32, 1.4.0beta50 + changes above and 1.2.30, 1.2.30rc01 and rc03 in 1.2.41 CHANGES. Someone + needs this feature. + Make the 'png_jmpbuf' macro expand to a call that records the correct + longjmp function as well as returning a pointer to the setjmp + jmp_buf buffer, and marked direct access to jmpbuf 'deprecated'. + (John Bowler) + +Version 1.4.0beta104 [November 22, 2009] + Removed png_longjmp_ptr from scripts/*.def and libpng.3 + Rebuilt configure scripts with autoconf-2.65 + +Version 1.4.0beta105 [November 25, 2009] + Use fast integer PNG_DIVIDE_BY_255() or PNG_DIVIDE_BY_65535() + to accomplish alpha premultiplication when + PNG_READ_COMPOSITE_NODIV_SUPPORTED is defined. + Changed "/255" to "/255.0" in background calculations to make it clear + that the 255 is used as a double. + +Version 1.4.0beta106 [November 27, 2009] + Removed premultiplied alpha feature. + +Version 1.4.0beta107 [December 4, 2009] + Updated README + Added "#define PNG_NO_PEDANTIC_WARNINGS" in the libpng source files. + Removed "-DPNG_CONFIGURE_LIBPNG" from the makefiles and projects. + Revised scripts/makefile.netbsd, makefile.openbsd, and makefile.sco + to put png.h and pngconf.h in $prefix/include, like the other scripts, + instead of in $prefix/include/libpng. Also revised makefile.sco + to put them in $prefix/include/libpng15 instead of in + $prefix/include/libpng/libpng15. + +Version 1.4.0beta108 [December 11, 2009] + Removed leftover "-DPNG_CONFIGURE_LIBPNG" from contrib/pngminim/*/makefile + Relocated png_do_chop() to its original position in pngrtran.c; the + change in version 1.2.41beta08 caused transparency to be handled wrong + in some 16-bit datastreams (Yusaku Sugai). + +Version 1.4.0beta109 [December 13, 2009] + Added "bit_depth" parameter to the private png_build_gamma_table() function. + Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16 but the + PNG_16_TO_8 transform has been set, to avoid unnecessary build of 16-bit + tables. + +Version 1.4.0rc02 [December 20, 2009] + Declared png_cleanup_needed "volatile" in pngread.c and pngwrite.c + +Version 1.4.0rc03 [December 22, 2009] + Renamed libpng-pc.in back to libpng.pc.in and revised CMakeLists.txt + (revising the change in 1.4.0beta99) + +Version 1.4.0rc04 [December 25, 2009] + Swapped PNG_UNKNOWN_CHUNKS_SUPPORTED and PNG_HANDLE_AS_UNKNOWN_SUPPORTED + in pngset.c to be consistent with other changes in version 1.2.38. + +Version 1.4.0rc05 [December 25, 2009] + Changed "libpng-pc.in" to "libpng.pc.in" in configure.ac, configure, and + Makefile.in to be consistent with changes in libpng-1.4.0rc03 + +Version 1.4.0rc06 [December 29, 2009] + Reverted the gamma_table changes from libpng-1.4.0beta109. + Fixed some indentation errors. + +Version 1.4.0rc07 [January 1, 2010] + Revised libpng*.txt and libpng.3 about 1.2.x->1.4.x differences. + Use png_calloc() instead of png_malloc(); png_memset() in pngrutil.c + Update copyright year to 2010. + +Version 1.4.0rc08 [January 2, 2010] + Avoid deprecated references to png_ptr-io_ptr and png_ptr->error_ptr + in pngtest.c + +Version 1.4.0 [January 3, 2010] + No changes. + +Version 1.4.1beta01 [January 8, 2010] + Updated CMakeLists.txt for consistent indentation and to avoid an + unclosed if-statement warning (Philip Lowman). + Revised Makefile.am and Makefile.in to remove references to Y2KINFO, + KNOWNBUG, and libpng.la (Robert Schwebel). + Revised the makefiles to install the same files and symbolic + links as configure, except for libpng.la and libpng14.la. + Make png_set|get_compression_buffer_size() available even when + PNG_WRITE_SUPPORTED is not enabled. + Revised Makefile.am and Makefile.in to simplify their maintenance. + Revised scripts/makefile.linux to install a link to libpng14.so.14.1 + +Version 1.4.1beta02 [January 9, 2010] + Revised the rest of the makefiles to install a link to libpng14.so.14.1 + +Version 1.4.1beta03 [January 10, 2010] + Removed png_set_premultiply_alpha() from scripts/*.def + +Version 1.4.1rc01 [January 16, 2010] + No changes. + +Version 1.4.1beta04 [January 23, 2010] + Revised png_decompress_chunk() to improve speed and memory usage when + decoding large chunks. + Added png_set|get_chunk_malloc_max() functions. + +Version 1.4.1beta05 [January 26, 2010] + Relocated "int k" declaration in pngtest.c to minimize its scope. + +Version 1.4.1beta06 [January 28, 2010] + Revised png_decompress_chunk() to use a two-pass method suggested by + John Bowler. + +Version 1.4.1beta07 [February 6, 2010] + Folded some long lines in the source files. + Added defineable PNG_USER_CHUNK_CACHE_MAX, PNG_USER_CHUNK_MALLOC_MAX, + and a PNG_USER_LIMITS_SUPPORTED flag. + Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as + png_ptr->png_user_chunk_malloc_max. + Revised png_push_save_buffer() to do fewer but larger png_malloc() calls. + +Version 1.4.1beta08 [February 6, 2010] + Minor cleanup and updating of dates and copyright year. + +Version 1.5.0beta01 [February 7, 2010] + Moved declaration of png_struct into private pngstruct.h and png_info + into pnginfo.h + +Version 1.4.1beta09 and 1.5.0beta02 [February 7, 2010] + Reverted to original png_push_save_buffer() code. + +Version 1.4.1beta10 and 1.5.0beta03 [February 8, 2010] + Return allocated "old_buffer" in png_push_save_buffer() before + calling png_error(), to avoid a potential memory leak. + Updated configure script to use SO number 15. + +Version 1.5.0beta04 [February 9, 2010] + Removed malformed "incomplete struct declaration" of png_info from png.h + +Version 1.5.0beta05 [February 12, 2010] + Removed PNG_DEPSTRUCT markup in pngstruct.h and pnginfo.h, and undid the + linewrapping that it entailed. + Revised comments in pngstruct.h and pnginfo.h and added pointers to + the libpng license. + Changed PNG_INTERNAL to PNG_EXPOSE_INTERNAL_STRUCTURES + Removed the cbuilder5 project, which has not been updated to 1.4.0. + +Version 1.4.1beta12 and 1.5.0beta06 [February 14, 2010] + Fixed type declaration of png_get_chunk_malloc_max() in pngget.c (Daisuke + Nishikawa) + +Version 1.5.0beta07 [omitted] + +Version 1.5.0beta08 [February 19, 2010] + Changed #ifdef PNG_NO_STDIO_SUPPORTED to #ifdef PNG_NO_CONSOLE_IO_SUPPORTED + wherever png_snprintf() is used to construct error and warning messages. + Noted in scripts/makefile.mingw that it expects to be run under MSYS. + Removed obsolete unused MMX-querying support from contrib/gregbook + Added exported png_longjmp() function. + Removed the AIX redefinition of jmpbuf in png.h + Added -D_ALLSOURCE in configure.ac, makefile.aix, and CMakeLists.txt + when building on AIX. + +Version 1.5.0beta09 [February 19, 2010] + Removed -D_ALLSOURCE from configure.ac, makefile.aix, and CMakeLists.txt. + Changed the name of png_ptr->jmpbuf to png_ptr->png_jmpbuf in pngstruct.h + +Version 1.5.0beta10 [February 25, 2010] + Removed unused gzio.c from contrib/pngminim gather and makefile scripts + Removed replacement error handlers from contrib/gregbook. Because of + the new png_longjmp() function they are no longer needed. + +Version 1.5.0beta11 [March 6, 2010] + Removed checking for already-included setjmp.h from pngconf.h + Fixed inconsistent indentations and made numerous cosmetic changes. + Revised the "SEE ALSO" style of libpng.3, libpngpf.3, and png.5 + +Version 1.5.0beta12 [March 9, 2010] + Moved "#include png.h" inside pngpriv.h and removed "#include png.h" from + the source files, along with "#define PNG_EXPOSE_INTERNAL_STRUCTURES" + and "#define PNG_NO_PEDANTIC_WARNINGS" (John Bowler). + Created new pngdebug.h and moved debug definitions there. + +Version 1.5.0beta13 [March 10, 2010] + Protect pngstruct.h, pnginfo.h, and pngdebug.h from being included twice. + Revise the "#ifdef" blocks in png_inflate() so it will compile when neither + PNG_USER_CHUNK_MALLOC_MAX nor PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED + is defined. + Removed unused png_measure_compressed_chunk() from pngpriv.h and libpngpf.3 + Moved the 'config.h' support from pngconf.h to pngpriv.h + Removed PNGAPI from the png_longjmp_ptr typedef. + Eliminated dependence of pngtest.c on the private pngdebug.h file. + Make all png_debug macros into *unterminated* statements or + expressions (i.e. a trailing ';' must always be added) and correct + the format statements in various png_debug messages. + +Version 1.5.0beta14 [March 14, 2010] + Removed direct access to png_ptr->io_ptr from the Windows code in pngtest.c + Revised Makefile.am to account for recent additions and replacements. + Corrected CE and OS/2 DEF files (scripts/png*def) for symbols removed and + added ordinal numbers to the Windows DEF file and corrected the duplicated + ordinal numbers on CE symbols that are commented out. + Added back in export symbols that can be present in the Windows build but + are disabled by default. + PNG_EXPORT changed to include an 'ordinal' field for DEF file generation. + PNG_CALLBACK added to make callback definitions uniform. PNGAPI split + into PNGCAPI (base C form), PNGAPI (exports) and PNGCBAPI (callbacks), + and appropriate changes made to all files. Cygwin builds re-hinged to + allow procedure call standard changes and to remove the need for the DEF + file (fixes build on Cygwin). + Enabled 'attribute' warnings that are relevant to library APIs and callbacks. + Changed rules for generation of the various symbol files and added a new + rule for a DEF file (which is also added to the distribution). + Updated the symbol file generation to stop it adding spurious spaces + to EOL (coming from preprocessor macro expansion). Added a facility + to join tokens in the output and rewrite *.dfn to use this. + Eliminated scripts/*.def in favor of libpng.def; updated projects/visualc71 + and removed scripts/makefile.cygwin. + Made PNG_BUILD_DLL safe: it can be set whenever a DLL is being built. + Removed the include of sys/types.h - apparently unnecessary now on the + platforms on which it happened (all but Mac OS and RISC OS). + Moved the Mac OS test into pngpriv.h (the only place it is used.) + +Version 1.5.0beta15 [March 17, 2010] + Added symbols.chk target to Makefile.am to validate the symbols in png.h + against the new DEF file scripts/symbols.def. + Changed the default DEF file back to pngwin.def. + Removed makefile.mingw. + Eliminated PNG_NO_EXTERN and PNG_ALL_EXTERN + +Version 1.5.0beta16 [April 1, 2010] + Make png_text_struct independent of PNG_iTXt_SUPPORTED, so that + fields are initialized in all configurations. The READ/WRITE + macros (PNG_(READ|WRITE)_iTXt_SUPPORTED) still function as + before to disable code to actually read or write iTXt chunks + and iTXt_SUPPORTED can be used to detect presence of either + read or write support (but it is probably better to check for + the one actually required - read or write.) + Combined multiple png_warning() calls for a single error. + Restored the macro definition of png_check_sig(). + +Version 1.5.0beta17 [April 17, 2010] + Added some "(long)" typecasts to printf calls in png_handle_cHRM(). + Documented the fact that png_set_dither() was disabled since libpng-1.4.0. + Reenabled png_set_dither() but renamed it to png_set_quantize() to reflect + more accurately what it actually does. At the same time, renamed + the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros to + PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS. + Added some "(long)" typecasts to printf calls in png_handle_cHRM(). + Freeze build-time only configuration in the build. + In all prior versions of libpng most configuration options + controlled by compiler #defines had to be repeated by the + application code that used libpng. This patch changes this + so that compilation options that can only be changed at build + time are frozen in the build. Options that are compiler + dependent (and those that are system dependent) are evaluated + each time - pngconf.h holds these. Options that can be changed + per-file in the application are in png.h. Frozen options are + in the new installed header file pnglibconf.h (John Bowler) + Removed the xcode project because it has not been updated to work + with libpng-1.5.0. + Removed the ability to include optional pngusr.h + +Version 1.5.0beta18 [April 17, 2010] + Restored the ability to include optional pngusr.h + Moved replacements for png_error() and png_warning() from the + contrib/pngminim project to pngerror.c, for use when warnings or + errors are disabled via PNG_NO_WARN or PNG_NO_ERROR_TEXT, to avoid + storing unneeded error/warning text. + Updated contrib/pngminim project to work with the new pnglibconf.h + Added some PNG_NO_* defines to contrib/pngminim/*/pngusr.h to save space. + +Version 1.5.0beta19 [April 24, 2010] + Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the functions + to read and write ints to be disabled independently of PNG_USE_READ_MACROS, + which allows libpng to be built with the functions even though the default + is to use the macros - this allows applications to choose at app build + time whether or not to use macros (previously impossible because the + functions weren't in the default build.) + Changed Windows calling convention back to __cdecl for API functions. + For Windows/x86 platforms only: + __stdcall is no longer needed for Visual Basic, so libpng-1.5.0 uses + __cdecl throughout (both API functions and callbacks) on Windows/x86 + platforms. + Replaced visualc6 and visualc71 projects with new vstudio project + Relaxed the overly-restrictive permissions of some files. + +Version 1.5.0beta20 [April 24, 2010] + Relaxed more overly-restrictive permissions of some files. + +Version 1.5.0beta21 [April 27, 2010] + Removed some unwanted binary bytes and changed CRLF to NEWLINE in the new + vstudio project files, and some trivial editing of some files in the + scripts directory. + Set PNG_NO_READ_BGR, PNG_NO_IO_STATE, and PNG_NO_TIME_RFC1123 in + contrib/pngminim/decoder/pngusr.h to make a smaller decoder application. + +Version 1.5.0beta22 [April 28, 2010] + Fixed dependencies of GET_INT_32 - it does not require READ_INT_FUNCTIONS + because it has a macro equivalent. + Improved the options.awk script; added an "everything off" option. + Revised contrib/pngminim to use the "everything off" option in pngusr.dfa. + +Version 1.5.0beta23 [April 29, 2010] + Corrected PNG_REMOVED macro to take five arguments. + The macro was documented with two arguments (name,ordinal), however + the symbol checking .dfn files assumed five arguments. The five + argument form seems more useful so it is changed to that. + Corrected PNG_UNKNOWN_CHUNKS_SUPPORTED to PNG_HANDLE_AS_UNKNOWN_SUPPORTED + in gregbook/readpng2.c + Corrected protection of png_get_user_transform_ptr. The API declaration in + png.h is removed if both READ and WRITE USER_TRANSFORM are turned off + but was left defined in pngtrans.c + Added logunsupported=1 to cause pnglibconf.h to document disabled options. + This makes the installed pnglibconf.h more readable but causes no + other change. The intention is that users of libpng will find it + easier to understand if an API they need is missing. + Include png_reset_zstream() in png.c only when PNG_READ_SUPPORTED is defined. + Removed dummy_inflate.c from contrib/pngminim/encoder + Removed contrib/pngminim/*/gather.sh; gathering is now done in the makefile. + +Version 1.5.0beta24 [May 7, 2010] + Use bitwise "&" instead of arithmetic mod in pngrutil.c calculation of the + offset of the png_ptr->rowbuf pointer into png_ptr->big_row_buf. + Added more blank lines for readability. + +Version 1.5.0beta25 [June 18, 2010] + In pngpread.c: png_push_have_row() add check for new_row > height + Removed the now-redundant check for out-of-bounds new_row from example.c + +Version 1.5.0beta26 [June 18, 2010] + In pngpread.c: png_push_process_row() add check for too many rows. + +Version 1.5.0beta27 [June 18, 2010] + Removed the check added in beta25 as it is now redundant. + +Version 1.5.0beta28 [June 20, 2010] + Rewrote png_process_IDAT_data to consistently treat extra data as warnings + and handle end conditions more cleanly. + Removed the new (beta26) check in png_push_process_row(). + +Version 1.5.0beta29 [June 21, 2010] + Revised scripts/options.awk to work on Sunos (but still doesn't work) + Added comment to options.awk and contrib/pngminim/*/makefile to try nawk. + +Version 1.5.0beta30 [June 22, 2010] + Stop memory leak when reading a malformed sCAL chunk. + +Version 1.5.0beta31 [June 26, 2010] + Revised pngpread.c patch of beta28 to avoid an endless loop. + Removed some trailing blanks. + +Version 1.5.0beta32 [June 26, 2010] + Removed leftover scripts/options.patch and scripts/options.rej + +Version 1.5.0beta33 [July 6, 3010] + Made FIXED and FLOATING options consistent in the APIs they enable and + disable. Corrected scripts/options.awk to handle both command line + options and options specified in the .dfa files. + Changed char *msg to PNG_CONST char *msg in pngrutil.c + Make png_set_sRGB_gAMA_and_cHRM set values using either the fixed or + floating point APIs, but not both. + Reversed patch to remove error handler when the jmp_buf is stored in the + main program structure, not the png_struct. + The error handler is needed because the default handler in libpng will + always use the jmp_buf in the library control structure; this is never + set. The gregbook code is a useful example because, even though it + uses setjmp/longjmp, it shows how error handling can be implemented + using control mechanisms not directly supported by libpng. The + technique will work correctly with mechanisms such as Microsoft + Structure Exceptions or C++ exceptions (compiler willing - note that gcc + does not by default support interworking of C and C++ error handling.) + Reverted changes to call png_longjmp in contrib/gregbook where it is not + appropriate. If mainprog->jmpbuf is used by setjmp, then png_longjmp + cannot be used. + Changed "extern PNG_EXPORT" to "PNG_EXPORT" in png.h (Jan Nijtmans) + Changed "extern" to "PNG_EXTERN" in pngpriv.h (except for the 'extern "C" {') + +Version 1.5.0beta34 [July 12, 2010] + Put #ifndef PNG_EXTERN, #endif around the define PNG_EXTERN in pngpriv.h + +Version 1.5.0beta35 [July 24, 2010] + Removed some newly-added TAB characters. + Added -DNO_PNG_SNPRINTF to CFLAGS in scripts/makefile.dj2 + Moved the definition of png_snprintf() outside of the enclosing + #ifdef blocks in pngconf.h + +Version 1.5.0beta36 [July 29, 2010] + Patches by John Bowler: + Fixed point APIs are now supported throughout (no missing APIs). + Internal fixed point arithmetic support exists for all internal floating + point operations. + sCAL validates the floating point strings it is passed. + Safe, albeit rudimentary, Watcom support is provided by PNG_API_RULE==2 + Two new APIs exist to get the number of passes without turning on the + PNG_INTERLACE transform and to get the number of rows in the current + pass. + A new test program, pngvalid.c, validates the gamma code. + Errors in the 16-bit gamma correction (overflows) have been corrected. + cHRM chunk testing is done consistently (previously the floating point + API bypassed it, because the test really didn't work on FP, now the test + is performed on the actual values to be stored in the PNG file so it + works in the FP case too.) + Most floating point APIs now simply call the fixed point APIs after + converting the values to the fixed point form used in the PNG file. + The standard headers no longer include zlib.h, which is currently only + required for pngstruct.h and can therefore be internal. + Revised png_get_int_32 to undo the PNG two's complement representation of + negative numbers. + +Version 1.5.0beta37 [July 30, 2010] + Added a typecast in png_get_int_32() in png.h and pngrutil.h to avoid + a compiler warning. + Replaced oFFs 0,0 with oFFs -10,20 in pngtest.png + +Version 1.5.0beta38 [July 31, 2010] + Implemented remaining "_fixed" functions. + Corrected a number of recently introduced warnings mostly resulting from + safe but uncast assignments to shorter integers. Also added a zlib + VStudio release library project because the latest zlib Official Windows + build does not include such a thing. + Revised png_get_int_16() to be similar to png_get_int_32(). + Restored projects/visualc71. + +Version 1.5.0beta39 [August 2, 2010] + VisualC/GCC warning fixes, VisualC build fixes + The changes include support for function attributes in VC in addition to + those already present in GCC - necessary because without these some + warnings are unavoidable. Fixes include signed/unsigned fixes in + pngvalid and checks with gcc -Wall -Wextra -Wunused. + VC requires function attributes on function definitions as well as + declarations, PNG_FUNCTION has been added to enable this and the + relevant function definitions changed. + +Version 1.5.0beta40 [August 6, 2010] + Correct use of _WINDOWS_ in pngconf.h + Removed png_mem_ #defines; they are no longer used. + Added the sRGB chunk to pngtest.png + +Version 1.5.0beta41 [August 11, 2010] + Added the cHRM chunk to pngtest.png + Don't try to use version-script with cygwin/mingw. + Revised contrib/gregbook to work under cygwin/mingw. + +Version 1.5.0beta42 [August 18, 2010] + Add .dll.a to the list of extensions to be symlinked by Makefile.am (Yaakov) + Made all API functions that have const arguments and constant string + literal pointers declare them (John Bowler). + +Version 1.5.0beta43 [August 20, 2010] + Removed spurious tabs, shorten long lines (no source change) + Also added scripts/chkfmt to validate the format of all the files that can + reasonably be validated (it is suggested to run "make distclean" before + checking, because some machine generated files have long lines.) + Reformatted the CHANGES file to be more consistent throughout. + Made changes to address various issues identified by GCC, mostly + signed/unsigned and shortening problems on assignment but also a few + difficult to optimize (for GCC) loops. + Fixed non-GCC fixed point builds. In png.c a declaration was misplaced + in an earlier update. Fixed to declare the auto variables at the head. + Use cexcept.h in pngvalid.c. + +Version 1.5.0beta44 [August 24, 2010] + Updated CMakeLists.txt to use CMAKE_INSTALL_LIBDIR variable; useful for + installing libpng in /usr/lib64 (Funda Wang). + Revised CMakeLists.txt to put the man pages in share/man/man* not man/man* + Revised CMakeLists.txt to make symlinks instead of copies when installing. + Changed PNG_LIB_NAME from pngNN to libpngNN in CMakeLists.txt (Philip Lowman) + Implemented memory checks within pngvalid + Reformatted/rearranged pngvalid.c to assist use of progressive reader. + Check interlaced images in pngvalid + Clarified pngusr.h comments in pnglibconf.dfa + Simplified the pngvalid error-handling code now that cexcept.h is in place. + Implemented progressive reader in pngvalid.c for standard tests + Implemented progressive read in pngvalid.c gamma tests + Turn on progressive reader in pngvalid.c by default and tidy code. + +Version 1.5.0beta45 [August 26, 2010] + Added an explicit make step to projects/vstudio for pnglibconf.h + Also corrected zlib.vcxproj into which Visual Studio had introduced + what it calls an "authoring error". The change to make pnglibconf.h + simply copies the file; in the future it may actually generate the + file from scripts/pnglibconf.dfa as the other build systems do. + Changed pngvalid to work when floating point APIs are disabled + Renamed the prebuilt scripts/pnglibconf.h to scripts/pnglibconf.h.prebuilt + Supply default values for PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX + in pngpriv.h in case the user neglected to define them in their pngusr.h + +Version 1.5.0beta46 [August 28, 2010] + Added new private header files to libpng_sources in CMakeLists.txt + Added PNG_READ_16BIT, PNG_WRITE_16BIT, and PNG_16BIT options. + Added reference to scripts/pnglibconf.h.prebuilt in the visualc71 project. + +Version 1.5.0beta47 [September 11, 2010] + Fixed a number of problems with 64-bit compilation reported by Visual + Studio 2010 (John Bowler). + +Version 1.5.0beta48 [October 4, 2010] + Updated CMakeLists.txt (Philip Lowman). + Revised autogen.sh to recognize and use $AUTOCONF, $AUTOMAKE, $AUTOHEADER, + $AUTOPOINT, $ACLOCAL and $LIBTOOLIZE + Fixed problem with symbols creation in Makefile.am which was assuming that + all versions of ccp write to standard output by default (Martin Banky). The + bug was introduced in libpng-1.2.9beta5. + Removed unused mkinstalldirs. + +Version 1.5.0beta49 [October 8, 2010] + Undid Makefile.am revision of 1.5.0beta48. + +Version 1.5.0beta50 [October 14, 2010] + Revised Makefile.in to account for mkinstalldirs being removed. + Added some "(unsigned long)" typecasts in printf statements in pngvalid.c. + Suppressed a compiler warning in png_handle_sPLT(). + Check for out-of-range text compression mode in png_set_text(). + +Version 1.5.0beta51 [October 15, 2010] + Changed embedded dates to "(PENDING RELEASE) in beta releases (and future + rc releases) to minimize the difference between releases. + +Version 1.5.0beta52 [October 16, 2010] + Restored some of the embedded dates (in png.h, png.c, documentation, etc.) + +Version 1.5.0beta53 [October 18, 2010] + Updated INSTALL to mention using "make maintainer-clean" and to remove + obsolete statement about a custom ltmain.sh + Disabled "color-tests" by default in Makefile.am so it will work with + automake versions earlier than 1.11.1 + Use document name "libpng-manual.txt" instead of "libpng-.txt" + to simplify version differences. + Removed obsolete remarks about setjmp handling from INSTALL. + Revised and renamed the typedef in png.h and png.c that was designed + to catch library and header mismatch. + +Version 1.5.0beta54 [November 10, 2010] + Require 48 bytes, not 64 bytes, for big_row_buf in overflow checks. + Used a consistent structure for the pngget.c functions. + +Version 1.5.0beta55 [November 21, 2010] + Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin) + Moved reading of file signature into png_read_sig (Cosmin) + Fixed atomicity of chunk header serialization (Cosmin) + Added test for io_state in pngtest.c (Cosmin) + Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts. + Changes to remove gcc warnings (John Bowler) + Certain optional gcc warning flags resulted in warnings in libpng code. + With these changes only -Wconversion and -Wcast-qual cannot be turned on. + Changes are trivial rearrangements of code. -Wconversion is not possible + for pngrutil.c (because of the widespread use of += et al on variables + smaller than (int) or (unsigned int)) and -Wcast-qual is not possible + with pngwio.c and pngwutil.c because the 'write' callback and zlib + compression both fail to declare their input buffers with 'const'. + +Version 1.5.0beta56 [December 7, 2010] + Added the private PNG_UNUSED() macro definition in pngpriv.h. + Added some commentary about PNG_EXPORT in png.h and pngconf.h + Revised PNG_EXPORT() macro and added PNG_EXPORTA() macro, with the + objective of simplifying and improving the cosmetic appearance of png.h. + Fixed some incorrect "=" macro names in pnglibconf.dfa + Included documentation of changes in 1.5.0 from 1.4.x in libpng-manual.txt + +Version 1.5.0beta57 [December 9, 2010] + Documented the pngvalid gamma error summary with additional comments and + print statements. + Improved missing symbol handling in checksym.awk; symbols missing in both + the old and new files can now be optionally ignored, treated as errors + or warnings. + Removed references to pngvcrd.c and pnggccrd.c from the vstudio project. + Updated "libpng14" to "libpng15" in the visualc71 project. + Enabled the strip16 tests in pngvalid.` + Don't display test results (except PASS/FAIL) when running "make test". + Instead put them in pngtest-log.txt + Added "--with-zprefix=" to configure.ac + Updated the prebuilt configuration files to autoconf version 2.68 + +Version 1.5.0beta58 [December 19, 2010] + Fixed interlace image handling and add test cases (John Bowler) + Fixed the clean rule in Makefile.am to remove pngtest-log.txt + Made minor changes to work around warnings in gcc 3.4 + +Version 1.5.0rc01 [December 27, 2010] + No changes. + +Version 1.5.0rc02 [December 27, 2010] + Eliminated references to the scripts/*.def files in project/visualc71. + +Version 1.5.0rc03 [December 28, 2010] + Eliminated scripts/*.def and revised Makefile.am accordingly + +Version 1.5.0rc04 [December 29, 2010] + Fixed bug in background transformation handling in pngrtran.c (it was + looking for the flag in png_ptr->transformations instead of in + png_ptr->flags) (David Raymond). + +Version 1.5.0rc05 [December 31, 2010] + Fixed typo in a comment in CMakeLists.txt (libpng14 => libpng15) (Cosmin) + +Version 1.5.0rc06 [January 4, 2011] + Changed the new configure option "zprefix=string" to "zlib-prefix=string" + +Version 1.5.0rc07 [January 4, 2011] + Updated copyright year. + +Version 1.5.0 [January 6, 2011] + No changes. + +version 1.5.1beta01 [January 8, 2011] + Added description of png_set_crc_action() to the manual. + Added a note in the manual that the type of the iCCP profile was changed + from png_charpp to png_bytepp in png_get_iCCP(). This change happened + in version 1.5.0beta36 but is not noted in the CHANGES. Similarly, + it was changed from png_charpp to png_const_bytepp in png_set_iCCP(). + Ensure that png_rgb_to_gray ignores palette mapped images, if libpng + internally happens to call it with one, and fixed a failure to handle + palette mapped images correctly. This fixes CVE-2690. + +Version 1.5.1beta02 [January 14, 2011] + Fixed a bug in handling of interlaced images (bero at arklinux.org). + Updated CMakeLists.txt (Clifford Yapp) + +Version 1.5.1beta03 [January 14, 2011] + Fixed typecasting of some png_debug() statements (Cosmin) + +Version 1.5.1beta04 [January 16, 2011] + Updated documentation of png_set|get_tRNS() (Thomas Klausner). + Mentioned in the documentation that applications must #include "zlib.h" + if they need access to anything in zlib.h, and that a number of + macros such as png_memset() are no longer accessible by applications. + Corrected pngvalid gamma test "sample" function to access all of the color + samples of each pixel, instead of sampling the red channel three times. + Prefixed variable names index, div, exp, gamma with "png_" to avoid "shadow" + warnings, and (mistakenly) changed png_exp() to exp(). + +Version 1.5.1beta05 [January 16, 2011] + Changed variable names png_index, png_div, png_exp, and png_gamma to + char_index, divisor, exp_b10, and gamma_val, respectively, and + changed exp() back to png_exp(). + +Version 1.5.1beta06 [January 20, 2011] + Prevent png_push_crc_skip() from hanging while reading an unknown chunk + or an over-large compressed zTXt chunk with the progressive reader. + Eliminated more GCC "shadow" warnings. + Revised png_fixed() in png.c to avoid compiler warning about reaching the + end without returning anything. + +Version 1.5.1beta07 [January 22, 2011] + In the manual, describe the png_get_IHDR() arguments in the correct order. + Added const_png_structp and const_png_infop types, and used them in + prototypes for most png_get_*() functions. + +Version 1.5.1beta08 [January 23, 2011] + Added png_get_io_chunk_type() and deprecated png_get_io_chunk_name() + Added synopses for the IO_STATE functions and other missing synopses + to the manual. Removed the synopses from libpngpf.3 because they + were out of date and no longer useful. Better information can be + obtained by reading the prototypes and comments in pngpriv.h + Attempted to fix cpp on Solaris with S. Studio 12 cc, fix build + Added a make macro DFNCPP that is a CPP that will accept the tokens in + a .dfn file and adds configure stuff to test for such a CPP. ./configure + should fail if one is not available. + Corrected const_png_ in png.h to png_const_ to avoid polluting the namespace. + Added png_get_current_row_number and png_get_current_pass_number for the + benefit of the user transform callback. + Added png_process_data_pause and png_process_data_skip for the benefit of + progressive readers that need to stop data processing or want to optimize + skipping of unread data (e.g., if the reader marks a chunk to be skipped.) + +Version 1.5.1beta09 [January 24, 2011] + Enhanced pngvalid, corrected an error in gray_to_rgb, corrected doc error. + pngvalid contains tests of transforms, which tests are currently disabled + because they are incompletely tested. gray_to_rgb was failing to expand + the bit depth for smaller bit depth images; this seems to be a long + standing error and resulted, apparently, in invalid output + (CVE-2011-0408, CERT VU#643140). The documentation did not accurately + describe what libpng really does when converting RGB to gray. + +Version 1.5.1beta10 [January 27, 2010] + Fixed incorrect examples of callback prototypes in the manual, that were + introduced in libpng-1.0.0. + In addition the order of the png_get_uint macros with respect to the + relevant function definitions has been reversed. This helps the + preprocessing of the symbol files be more robust. Furthermore, the + symbol file preprocessing now uses -DPNG_NO_USE_READ_MACROS even when + the library may actually be built with PNG_USE_READ_MACROS; this stops + the read macros interfering with the symbol file format. + Made the manual, synopses, and function prototypes use the function + argument names file_gamma, int_file_gamma, and srgb_intent consistently. + +Version 1.5.1beta11 [January 28, 2011] + Changed PNG_UNUSED from "param=param;" to "{if(param){}}". + Corrected local variable type in new API png_process_data_skip() + The type was self-evidently incorrect but only causes problems on 64-bit + architectures. + Added transform tests to pngvalid and simplified the arguments. + +Version 1.5.1rc01 [January 29, 2011] + No changes. + +Version 1.5.1rc02 [January 31, 2011] + Added a request in the manual that applications do not use "png_" or + "PNG_" to begin any of their own symbols. + Changed PNG_UNUSED to "(void)param;" and updated the commentary in pngpriv.h + +Version 1.5.1 [February 3, 2011] + No changes. + +Version 1.5.2beta01 [February 13, 2011] + More -Wshadow fixes for older gcc compilers. Older gcc versions apparently + check formal parameters names in function declarations (as well as + definitions) to see if they match a name in the global namespace. + Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the + old VisualC++ preprocessor. + Turned on interlace handling in png_read_png(). + Fixed gcc pendantic warnings. + Handle longjmp in Cygwin. + Fixed png_get_current_row_number() in the interlaced case. + Cleaned up ALPHA flags and transformations. + Implemented expansion to 16 bits. + +Version 1.5.2beta02 [February 19, 2011] + Fixed mistake in the descriptions of user read_transform and write_transform + function prototypes in the manual. The row_info struct is png_row_infop. + Reverted png_get_current_row_number() to previous (1.5.2beta01) behavior. + Corrected png_get_current_row_number documentation + Fixed the read/write row callback documentation. + This documents the current behavior, where the callback is called after + every row with information pertaining to the next row. + +Version 1.5.2beta03 [March 3, 2011] + Fixed scripts/makefile.vcwin32 + Updated contrib/pngsuite/README to add the word "modify". + Define PNG_ALLOCATED to blank when _MSC_VER<1300. + +Version 1.5.2rc01 [March 19, 2011] + Define remaining attributes to blank when MSC_VER<1300. + ifdef out mask arrays in pngread.c when interlacing is not supported. + +Version 1.5.2rc02 [March 22, 2011] + Added a hint to try CPP=/bin/cpp if "cpp -E" fails in scripts/pnglibconf.mak + and in contrib/pngminim/*/makefile, eg., on SunOS 5.10, and removed "strip" + from the makefiles. + Fixed a bug (present since libpng-1.0.7) that makes png_handle_sPLT() fail + to compile when PNG_NO_POINTER_INDEXING is defined (Chubanov Kirill) + +Version 1.5.2rc03 [March 24, 2011] + Don't include standard header files in png.h while building the symbol table, + to avoid cpp failure on SunOS (introduced PNG_BUILDING_SYMBOL_TABLE macro). + +Version 1.5.2 [March 31, 2011] + No changes. + +Version 1.5.3beta01 [April 1, 2011] + Re-initialize the zlib compressor before compressing non-IDAT chunks. + Added API functions (png_set_text_compression_level() and four others) to + set parameters for zlib compression of non-IDAT chunks. + +Version 1.5.3beta02 [April 3, 2011] + Updated scripts/symbols.def with new API functions. + Only compile the new zlib re-initializing code when text or iCCP is + supported, using PNG_WRITE_COMPRESSED_TEXT_SUPPORTED macro. + Improved the optimization of the zlib CMF byte (see libpng-1.2.6beta03). + Optimize the zlib CMF byte in non-IDAT compressed chunks + +Version 1.5.3beta03 [April 16, 2011] + Fixed gcc -ansi -pedantic compile. A strict ANSI system does not have + snprintf, and the "__STRICT_ANSI__" detects that condition more reliably + than __STDC__ (John Bowler). + Removed the PNG_PTR_NORETURN attribute because it too dangerous. It tells + the compiler that a user supplied callback (the error handler) does not + return, yet there is no guarantee in practice that the application code + will correctly implement the error handler because the compiler only + issues a warning if there is a mistake (John Bowler). + Removed the no-longer-used PNG_DEPSTRUCT macro. + Updated the zlib version to 1.2.5 in the VStudio project. + Fixed 64-bit builds where png_uint_32 is smaller than png_size_t in + pngwutil.c (John Bowler). + Fixed bug with stripping the filler or alpha channel when writing, that + was introduced in libpng-1.5.2beta01 (bug report by Andrew Church). + +Version 1.5.3beta04 [April 27, 2011] + Updated pngtest.png with the new zlib CMF optimization. + Cleaned up conditional compilation code and of background/gamma handling + Internal changes only except a new option to avoid compiling the + png_build_grayscale_palette API (which is not used at all internally.) + The main change is to move the transform tests (READ_TRANSFORMS, + WRITE_TRANSFORMS) up one level to the caller of the APIs. This avoids + calls to spurious functions if all transforms are disabled and slightly + simplifies those functions. Pngvalid modified to handle this. + A minor change is to stop the strip_16 and expand_16 interfaces from + disabling each other; this allows the future alpha premultiplication + code to use 16-bit intermediate values while still producing 8-bit output. + png_do_background and png_do_gamma have been simplified to take a single + pointer to the png_struct rather than pointers to every item required + from the png_struct. This makes no practical difference to the internal + code. + A serious bug in the pngvalid internal routine 'standard_display_init' has + been fixed - this failed to initialize the red channel and accidentally + initialized the alpha channel twice. + Changed png_struct jmp_buf member name from png_jmpbuf to tmp_jmpbuf to + avoid a possible clash with the png_jmpbuf macro on some platforms. + +Version 1.5.3beta05 [May 6, 2011] + Added the "_POSIX_SOURCE" feature test macro to ensure libpng sees the + correct API. _POSIX_SOURCE is defined in pngpriv.h, pngtest.c and + pngvalid.c to ensure that POSIX conformant systems disable non-POSIX APIs. + Removed png_snprintf and added formatted warning messages. This change adds + internal APIs to allow png_warning messages to have parameters without + requiring the host OS to implement snprintf. As a side effect the + dependency of the tIME-supporting RFC1132 code on stdio is removed and + PNG_NO_WARNINGS does actually work now. + Pass "" instead of '\0' to png_default_error() in png_err(). This mistake + was introduced in libpng-1.2.20beta01. This fixes CVE-2011-2691. + Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte + optimization configureable. + IDAT compression failed if preceded by a compressed text chunk (bug + introduced in libpng-1.5.3beta01-02). This was because the attempt to + reset the zlib stream in png_write_IDAT happened after the first IDAT + chunk had been deflated - much too late. In this change internal + functions were added to claim/release the z_stream and, hopefully, make + the code more robust. Also deflateEnd checking is added - previously + libpng would ignore an error at the end of the stream. + +Version 1.5.3beta06 [May 8, 2011] + Removed the -D_ALL_SOURCE from definitions for AIX in CMakeLists.txt + Implemented premultiplied alpha support: png_set_alpha_mode API + +Version 1.5.3beta07 [May 11, 2011] + Added expand_16 support to the high level interface. + Added named value and 'flag' gamma support to png_set_gamma. Made a minor + change from the previous (unreleased) ABI/API to hide the exact value used + for Macs - it's not a good idea to embed this in the ABI! + Moved macro definitions for PNG_HAVE_IHDR, PNG_HAVE_PLTE, and PNG_AFTER_IDAT + from pngpriv.h to png.h because they must be visible to applications + that call png_set_unknown_chunks(). + Check for up->location !PNG_AFTER_IDAT when writing unknown chunks + before IDAT. + +Version 1.5.3beta08 [May 16, 2011] + Improved "pngvalid --speed" to exclude more of pngvalid from the time. + Documented png_set_alpha_mode(), other changes in libpng.3/libpng-manual.txt + The cHRM chunk now sets the defaults for png_set_rgb_to_gray() (when negative + parameters are supplied by the caller), while in the absence of cHRM + sRGB/Rec 709 values are still used. This introduced a divide-by-zero + bug in png_handle_cHRM(). + The bKGD chunk no longer overwrites the background value set by + png_set_background(), allowing the latter to be used before the file + header is read. It never performed any useful function to override + the default anyway. + Added memory overwrite and palette image checks to pngvalid.c + Previously palette image code was poorly checked. Since the transformation + code has a special palette path in most cases this was a severe weakness. + Minor cleanup and some extra checking in pngrutil.c and pngrtran.c. When + expanding an indexed image, always expand to RGBA if transparency is + present. + +Version 1.5.3beta09 [May 17, 2011] + Reversed earlier 1.5.3 change of transformation order; move png_expand_16 + back where it was. The change doesn't work because it requires 16-bit + gamma tables when the code only generates 8-bit ones. This fails + silently; the libpng code just doesn't do any gamma correction. Moving + the tests back leaves the old, inaccurate, 8-bit gamma calculations, but + these are clearly better than none! + +Version 1.5.3beta10 [May 20, 2011] + + png_set_background() and png_expand_16() did not work together correctly. + This problem is present in 1.5.2; if png_set_background is called with + need_expand false and the matching 16 bit color libpng erroneously just + treats it as an 8-bit color because of where png_do_expand_16 is in the + transform list. This simple fix reduces the supplied colour to 8-bits, + so it gets smashed, but this is better than the current behavior. + Added tests for expand16, more fixes for palette image tests to pngvalid. + Corrects the code for palette image tests and disables attempts to + validate palette colors. + +Version 1.5.3rc01 [June 3, 2011] + No changes. + +Version 1.5.3rc02 [June 8, 2011] + Fixed uninitialized memory read in png_format_buffer() (Bug report by + Frank Busse, CVE-2011-2501, related to CVE-2004-0421). + +Version 1.5.3beta11 [June 11, 2011] + Fixed png_handle_sCAL which is broken in 1.5. This fixes CVE 2011-2692. + Added sCAL to pngtest.png + Revised documentation about png_set_user_limits() to say that it also affects + png writing. + Revised handling of png_set_user_limits() so that it can increase the + limit beyond the PNG_USER_WIDTH|HEIGHT_MAX; previously it could only + reduce it. + Make the 16-to-8 scaling accurate. Dividing by 256 with no rounding is + wrong (high by one) 25% of the time. Dividing by 257 with rounding is + wrong in 128 out of 65536 cases. Getting the right answer all the time + without division is easy. + Added "_SUPPORTED" to the PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION macro. + Added projects/owatcom, an IDE project for OpenWatcom to replace + scripts/makefile.watcom. This project works with OpenWatcom 1.9. The + IDE autogenerates appropriate makefiles (libpng.mk) for batch processing. + The project is configurable, unlike the Visual Studio project, so long + as the developer has an awk. + Changed png_set_gAMA to limit the gamma value range so that the inverse + of the stored value cannot overflow the fixed point representation, + and changed other things OpenWatcom warns about. + Revised pngvalid.c to test PNG_ALPHA_MODE_SUPPORTED correctly. This allows + pngvalid to build when ALPHA_MODE is not supported, which is required if + it is to build on libpng 1.4. + Removed string/memory macros that are no longer used and are not + necessarily fully supportable, particularly png_strncpy and png_snprintf. + Added log option to pngvalid.c and attempted to improve gamma messages. + +Version 1.5.3 [omitted] + People found the presence of a beta release following an rc release + to be confusing; therefore we bump the version to libpng-1.5.4beta01 + and there will be no libpng-1.5.3 release. + +Version 1.5.4beta01 [June 14, 2011] + Made it possible to undefine PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED + to get the same (inaccurate) output as libpng-1.5.2 and earlier. + Moved definitions of PNG_HAVE_IHDR, PNG_AFTER_IDAT, and PNG_HAVE_PLTE + outside of an unknown-chunk block in png.h because they are also + needed for other uses. + +Version 1.5.4beta02 [June 14, 2011] + Fixed and clarified LEGACY 16-to-8 scaling code. + Added png_set_chop_16() API, to match inaccurate results from previous + libpng versions. + Removed the ACCURATE and LEGACY options (they are no longer useable) + Use the old scaling method for background if png_set_chop_16() was + called. + Made png_set_chop_16() API removeable by disabling PNG_CHOP_16_TO_8_SUPPORTED + +Version 1.5.4beta03 [June 15, 2011] + Fixed a problem in png_do_expand_palette() exposed by optimization in + 1.5.3beta06 + Also removed a spurious and confusing "trans" member ("trans") from png_info. + The palette expand optimization prevented expansion to an intermediate RGBA + form if tRNS was present but alpha was marked to be stripped; this exposed + a check for tRNS in png_do_expand_palette() which is inconsistent with the + code elsewhere in libpng. + Correction to the expand_16 code; removed extra instance of + png_set_scale_16_to_8 from pngpriv.h + +Version 1.5.4beta04 [June 16, 2011] + Added a missing "#ifdef PNG_READ_BACKGROUND_SUPPORTED/#endif" in pngrtran.c + Added PNG_TRANSFORM_CHOP_16 to the high-level read transforms. + Made PNG_READ_16_TO_8_ACCURATE_SCALE configurable again. If this is + not enabled, png_set_strip_16() and png_do_scale_16_to_8() aren't built. + Revised contrib/visupng, gregbook, and pngminim to demonstrate chop_16_to_8 + +Version 1.5.4beta05 [June 16, 2011] + Renamed png_set_strip_16() to png_set_scale_16() and renamed + png_set_chop_16() to png_set_strip(16) in an attempt to minimize the + behavior changes between libpng14 and libpng15. + +Version 1.5.4beta06 [June 18, 2011] + Fixed new bug that was causing both strip_16 and scale_16 to be applied. + +Version 1.5.4beta07 [June 19, 2011] + Fixed pngvalid, simplified macros, added checking for 0 in sCAL. + The ACCURATE scale macro is no longer defined in 1.5 - call the + png_scale_16_to_8 API. Made sure that PNG_READ_16_TO_8 is still defined + if the png_strip_16_to_8 API is present. png_check_fp_number now + maintains some state so that positive, negative and zero values are + identified. sCAL uses these to be strictly spec conformant. + +Version 1.5.4beta08 [June 23, 2011] + Fixed pngvalid if ACCURATE_SCALE is defined. + Updated scripts/pnglibconf.h.prebuilt. + +Version 1.5.4rc01 [June 30, 2011] + Define PNG_ALLOCATED to "restrict" only if MSC_VER >= 1400. + +Version 1.5.4 [July 7, 2011] + No changes. + +Version 1.5.5beta01 [July 13, 2011] + Fixed some typos and made other minor changes in the manual. + Updated contrib/pngminus/makefile.std (Samuli Souminen) + +Version 1.5.5beta02 [July 14, 2011] + Revised Makefile.am and Makefile.in to look in the right directory for + pnglibconf.h.prebuilt + +Version 1.5.5beta03 [July 27, 2011] + Enabled compilation with g++ compiler. This compiler does not recognize + the file extension, so it always compiles with C++ rules. Made minor + changes to pngrutil.c to cast results where C++ expects it but C does not. + Minor editing of libpng.3 and libpng-manual.txt. + +Version 1.5.5beta04 [July 29, 2011] + Revised CMakeLists.txt (Clifford Yapp) + Updated commentary about the png_rgb_to_gray() default coefficients + in the manual and in pngrtran.c + +Version 1.5.5beta05 [August 17, 2011] + Prevent unexpected API exports from non-libpng DLLs on Windows. The "_DLL" + is removed from the test of whether a DLL is being built (this erroneously + caused the libpng APIs to be marked as DLL exports in static builds under + Microsoft Visual Studio). Almost all of the libpng building configuration + is moved from pngconf.h to pngpriv.h, but PNG_DLL_EXPORT remains in + pngconf.h, though, so that it is colocated with the import definition (it + is no longer used anywhere in the installed headers). The VStudio project + definitions have been cleaned up: "_USRDLL" has been removed from the + static library builds (this was incorrect), and PNG_USE_DLL has been added + to pngvalid to test the functionality (pngtest does not supply it, + deliberately). The spurious "_EXPORTS" has been removed from the + libpng build (all these errors were a result of copy/paste between project + configurations.) + Added new types and internal functions for CIE RGB end point handling to + pngpriv.h (functions yet to be implemented). + +Version 1.5.5beta06 [August 26, 2011] + Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set in CMakeLists.txt + (Clifford Yap) + Fixes to rgb_to_gray and cHRM XYZ APIs (John Bowler): + The rgb_to_gray code had errors when combined with gamma correction. + Some pixels were treated as true grey when they weren't and such pixels + and true grey ones were not gamma corrected (the original value of the + red component was used instead). APIs to get and set cHRM using color + space end points have been added and the rgb_to_gray code that defaults + based on cHRM, and the divide-by-zero bug in png_handle_cHRM (CERT + VU#477046, CVE-2011-3328, introduced in 1.5.4) have been corrected. + A considerable number of tests has been added to pngvalid for the + rgb_to_gray transform. + Arithmetic errors in rgb_to_gray whereby the calculated gray value was + truncated to the bit depth rather than rounded have been fixed except in + the 8-bit non-gamma-corrected case (where consistency seems more important + than correctness.) The code still has considerable inaccuracies in the + 8-bit case because 8-bit linear arithmetic is used. + +Version 1.5.5beta07 [September 7, 2011] + Added "$(ARCH)" option to makefile.darwin + Added SunOS support to configure.ac and Makefile.am + Changed png_chunk_benign_error() to png_warning() in png.c, in + png_XYZ_from_xy_checked(). + +Version 1.5.5beta08 [September 10, 2011] + Fixed 64-bit compilation errors (gcc). The errors fixed relate + to conditions where types that are 32 bits in the GCC 32-bit + world (uLong and png_size_t) become 64 bits in the 64-bit + world. This produces potential truncation errors which the + compiler correctly flags. + Relocated new HAVE_SOLARIS_LD definition in configure.ac + Constant changes for 64-bit compatibility (removal of L suffixes). The + 16-bit cases still use "L" as we don't have a 16-bit test system. + +Version 1.5.5rc01 [September 15, 2011] + Removed "L" suffixes in pngpriv.h + +Version 1.5.5 [September 22, 2011] + No changes. + +Version 1.5.6beta01 [September 22, 2011] + Fixed some 64-bit type conversion warnings in pngrtran.c + Moved row_info from png_struct to a local variable. + The various interlace mask arrays have been made into arrays of + bytes and made PNG_CONST and static (previously some arrays were + marked PNG_CONST and some weren't). + Additional checks have been added to the transform code to validate the + pixel depths after the transforms on both read and write. + Removed some redundant code from pngwrite.c, in png_destroy_write_struct(). + Changed chunk reading/writing code to use png_uint_32 instead of png_byte[4]. + This removes the need to allocate temporary strings for chunk names on + the stack in the read/write code. Unknown chunk handling still uses the + string form because this is exposed in the API. + +Version 1.5.6beta02 [September 26, 2011] + Added a note in the manual the png_read_update_info() must be called only + once with a particular info_ptr. + Fixed a typo in the definition of the new PNG_STRING_FROM_CHUNK(s,c) macro. + +Version 1.5.6beta03 [September 28, 2011] + Revised test-pngtest.sh to report FAIL when pngtest fails. + Added "--strict" option to pngtest, to report FAIL when the failure is + only because the resulting valid files are different. + Revised CMakeLists.txt to work with mingw and removed some material from + CMakeLists.txt that is no longer useful in libpng-1.5. + +Version 1.5.6beta04 [October 5, 2011] + Fixed typo in Makefile.in and Makefile.am ("-M Wl" should be "-M -Wl")." + +Version 1.5.6beta05 [October 12, 2011] + Speed up png_combine_row() for interlaced images. This reduces the generality + of the code, allowing it to be optimized for Adam7 interlace. The masks + passed to png_combine_row() are now generated internally, avoiding + some code duplication and localizing the interlace handling somewhat. + Align png_struct::row_buf - previously it was always unaligned, caused by + a bug in the code that attempted to align it; the code needs to subtract + one from the pointer to take account of the filter byte prepended to + each row. + Optimized png_combine_row() when rows are aligned. This gains a small + percentage for 16-bit and 32-bit pixels in the typical case where the + output row buffers are appropriately aligned. The optimization was not + previously possible because the png_struct buffer was always misaligned. + Fixed bug in png_write_chunk_header() debug print, introduced in 1.5.6beta01. + +Version 1.5.6beta06 [October 17, 2011] + Removed two redundant tests for unitialized row. + Fixed a relatively harmless memory overwrite in compressed text writing + with a 1 byte zlib buffer. + Add ability to call png_read_update_info multiple times to pngvalid.c. + Fixes for multiple calls to png_read_update_info. These fixes attend to + most of the errors revealed in pngvalid, however doing the gamma work + twice results in inaccuracies that can't be easily fixed. There is now + a warning in the code if this is going to happen. + Turned on multiple png_read_update_info in pngvalid transform tests. + Prevent libpng from overwriting unused bits at the end of the image when + it is not byte aligned, while reading. Prior to libpng-1.5.6 libpng would + overwrite the partial byte at the end of each row if the row width was not + an exact multiple of 8 bits and the image is not interlaced. + +Version 1.5.6beta07 [October 21, 2011] + Made png_ptr->prev_row an aligned pointer into png_ptr->big_prev_row + (Mans Rullgard). + +Version 1.5.6rc01 [October 26, 2011] + Changed misleading "Missing PLTE before cHRM" warning to "Out of place cHRM" + +Version 1.5.6rc02 [October 27, 2011] + Added LSR() macro to defend against buggy compilers that evaluate non-taken + code branches and complain about out-of-range shifts. + +Version 1.5.6rc03 [October 28, 2011] + Renamed the LSR() macro to PNG_LSR() and added PNG_LSL() macro. + Fixed compiler warnings with Intel and MSYS compilers. The logical shift + fix for Microsoft Visual C is required by other compilers, so this + enables that fix for all compilers when using compile-time constants. + Under MSYS 'byte' is a name declared in a system header file, so we + changed the name of a local variable to avoid the warnings that result. + Added #define PNG_ALIGN_TYPE PNG_ALIGN_NONE to contrib/pngminim/*/pngusr.h + +Version 1.5.6 [November 3, 2011] + No changes. + +Version 1.5.7beta01 [November 4, 2011] + Added support for ARM processor, when decoding all PNG up-filtered rows + and any other-filtered rows with 3 or 4 bytes per pixel (Mans Rullgard). + Fixed bug in pngvalid on early allocation failure; fixed type cast in + pngmem.c; pngvalid would attempt to call png_error() if the allocation + of a png_struct or png_info failed. This would probably have led to a + crash. The pngmem.c implementation of png_malloc() included a cast + to png_size_t which would fail on large allocations on 16-bit systems. + Fix for the preprocessor of the Intel C compiler. The preprocessor + splits adjacent @ signs with a space; this changes the concatentation + token from @-@-@ to PNG_JOIN; that should work with all compiler + preprocessors. + Paeth filter speed improvements from work by Siarhei Siamashka. This + changes the 'Paeth' reconstruction function to improve the GCC code + generation on x86. The changes are only part of the suggested ones; + just the changes that definitely improve speed and remain simple. + The changes also slightly increase the clarity of the code. + +Version 1.5.7beta02 [November 11, 2011] + Check compression_type parameter in png_get_iCCP and remove spurious + casts. The compression_type parameter is always assigned to, so must + be non-NULL. The cast of the profile length potentially truncated the + value unnecessarily on a 16-bit int system, so the cast of the (byte) + compression type to (int) is specified by ANSI-C anyway. + Fixed FP division by zero in pngvalid.c; the 'test_pixel' code left + the sBIT fields in the test pixel as 0, which resulted in a floating + point division by zero which was irrelevant but causes systems where + FP exceptions cause a crash. Added code to pngvalid to turn on FP + exceptions if the appropriate glibc support is there to ensure this is + tested in the future. + Updated scripts/pnglibconf.mak and scripts/makefile.std to handle the + new PNG_JOIN macro. + Added versioning to pnglibconf.h comments. + Simplified read/write API initial version; basic read/write tested on + a variety of images, limited documentation (in the header file.) + Installed more accurate linear to sRGB conversion tables. The slightly + modified tables reduce the number of 16-bit values that + convert to an off-by-one 8-bit value. The "makesRGB.c" code that was used + to generate the tables is now in a contrib/sRGBtables sub-directory. + +Version 1.5.7beta03 [November 17, 2011] + Removed PNG_CONST from the sRGB table declarations in pngpriv.h and png.c + Added run-time detection of NEON support. + Added contrib/libtests; includes simplified API test and timing test and + a color conversion utility for rapid checking of failed 'pngstest' results. + Multiple transform bug fixes plus a work-round for double gamma correction. + libpng does not support more than one transform that requires linear data + at once - if this is tried typically the results is double gamma + correction. Since the simplified APIs can need rgb to gray combined with + a compose operation it is necessary to do one of these outside the main + libpng transform code. This check-in also contains fixes to various bugs + in the simplified APIs themselves and to some bugs in compose and rgb to + gray (on palette) itself. + Fixes for C++ compilation using g++ When libpng source is compiled + using g++. The compiler imposes C++ rules on the C source; thus it + is desireable to make the source work with either C or C++ rules + without throwing away useful error information. This change adds + png_voidcast to allow C semantic (void*) cases or the corresponding + C++ static_cast operation, as appropriate. + Added --noexecstack to assembler file compilation. GCC does not set + this on assembler compilation, even though it does on C compilation. + This creates security issues if assembler code is enabled; the + work-around is to set it by default in the flags for $(CCAS) + Work around compilers that don't support declaration of const data. Some + compilers fault 'extern const' data declarations (because the data is + not initialized); this turns on const-ness only for compilers where + this is known to work. + +Version 1.5.7beta04 [November 17, 2011] + Since the gcc driver does not recognize the --noexecstack flag, we must + use the -Wa prefix to have it passed through to the assembler. + Also removed a duplicate setting of this flag. + Added files that were omitted from the libpng-1.5.7beta03 zip distribution. + +Version 1.5.7beta05 [November 25, 2011] + Removed "zTXt" from warning in generic chunk decompression function. + Validate time settings passed to png_set_tIME() and png_convert_to_rfc1123() + (Frank Busse). Note: This prevented CVE-2015-7981 from affecting + libpng-1.5.7 and later. + Added MINGW support to CMakeLists.txt + Reject invalid compression flag or method when reading the iTXt chunk. + Backed out 'simplified' API changes. The API seems too complex and there + is a lack of consensus or enthusiasm for the proposals. The API also + reveals significant bugs inside libpng (double gamma correction and the + known bug of being unable to retrieve a corrected palette). It seems + better to wait until the bugs, at least, are corrected. + Moved pngvalid.c into contrib/libtests + Rebuilt Makefile.in, configure, etc., with autoconf-2.68 + +Version 1.5.7rc01 [December 1, 2011] + Replaced an "#if" with "#ifdef" in pngrtran.c + Revised #if PNG_DO_BC block in png.c (use #ifdef and add #else) + +Version 1.5.7rc02 [December 5, 2011] + Revised project files and contrib/pngvalid/pngvalid.c to account for + the relocation of pngvalid into contrib/libtests. + Revised pngconf.h to use " __declspec(restrict)" only when MSC_VER >= 1400, + as in libpng-1.5.4. + Put CRLF line endings in the owatcom project files. + +Version 1.5.7rc03 [December 7, 2011] + Updated CMakeLists.txt to account for the relocation of pngvalid.c + +Version 1.5.7 [December 15, 2011] + Minor fixes to pngvalid.c for gcc 4.6.2 compatibility to remove warnings + reported by earlier versions. + Fixed minor memset/sizeof errors in pngvalid.c. + +Version 1.6.0beta01 [December 15, 2011] + Removed machine-generated configure files from the GIT repository (they will + continue to appear in the tarball distributions and in the libpng15 and + earlier GIT branches). + Restored the new 'simplified' API, which was started in libpng-1.5.7beta02 + but later deleted from libpng-1.5.7beta05. + Added example programs for the new 'simplified' API. + Added ANSI-C (C90) headers and require them, and take advantage of the + change. Also fixed some of the projects/* and contrib/* files that needed + updates for libpng16 and the move of pngvalid.c. + With this change the required ANSI-C header files are assumed to exist: the + implementation must provide float.h, limits.h, stdarg.h and stddef.h and + libpng relies on limits.h and stddef.h existing and behaving as defined + (the other two required headers aren't used). Non-ANSI systems that don't + have stddef.h or limits.h will have to provide an appropriate fake + containing the relevant types and #defines. + Dropped support for 16-bit platforms. The use of FAR/far has been eliminated + and the definition of png_alloc_size_t is now controlled by a flag so + that 'small size_t' systems can select it if necessary. Libpng 1.6 may + not currently work on such systems -- it seems likely that it will + ask 'malloc' for more than 65535 bytes with any image that has a + sufficiently large row size (rather than simply failing to read such + images). + New tools directory containing tools used to generate libpng code. + Fixed race conditions in parallel make builds. With higher degrees of + parallelism during 'make' the use of the same temporary file names such + as 'dfn*' can result in a race where a temporary file from one arm of the + build is deleted or overwritten in another arm. This changes the + temporary files for suffix rules to always use $* and ensures that the + non-suffix rules use unique file names. + +Version 1.6.0beta02 [December 21, 2011] + Correct configure builds where build and source directories are separate. + The include path of 'config.h' was erroneously made relative in pngvalid.c + in libpng 1.5.7. + +Version 1.6.0beta03 [December 22, 2011] + Start-up code size improvements, error handler flexibility. These changes + alter how the tricky allocation of the initial png_struct and png_info + structures are handled. png_info is now handled in pretty much the same + way as everything else, except that the allocations handle NULL return + silently. png_struct is changed in a similar way on allocation and on + deallocation a 'safety' error handler is put in place (which should never + be required). The error handler itself is changed to permit mismatches + in the application and libpng error buffer size; however, this means a + silent change to the API to return the jmp_buf if the size doesn't match + the size from the libpng compilation; libpng now allocates the memory and + this may fail. Overall these changes result in slight code size + reductions; however, this is a reduction in code that is always executed + so is particularly valuable. Overall on a 64-bit system the libpng DLL + decreases in code size by 1733 bytes. pngerror.o increases in size by + about 465 bytes because of the new functionality. + Added png_convert_to_rfc1123_buffer() and deprecated png_convert_to_rfc1123() + to avoid including a spurious buffer in the png_struct. + +Version 1.6.0beta04 [December 30, 2011] + Regenerated configure scripts with automake-1.11.2 + Eliminated png_info_destroy(). It is now used only in png.c and only calls + one other internal function and memset(). + Enabled png_get_sCAL_fixed() if floating point APIs are enabled. Previously + it was disabled whenever internal fixed point arithmetic was selected, + which meant it didn't exist even on systems where FP was available but not + preferred. + Added pngvalid.c compile time checks for const APIs. + Implemented 'restrict' for png_info and png_struct. Because of the way + libpng works both png_info and png_struct are always accessed via a + single pointer. This means adding C99 'restrict' to the pointer gives + the compiler some opportunity to optimize the code. This change allows + that. + Moved AC_MSG_CHECKING([if libraries can be versioned]) later to the proper + location in configure.ac (Gilles Espinasse). + Changed png_memcpy to C assignment where appropriate. Changed all those + uses of png_memcpy that were doing a simple assignment to assignments + (all those cases where the thing being copied is a non-array C L-value). + Added some error checking to png_set_*() routines. + Removed the reference to the non-exported function png_memcpy() from + example.c. + Fixed the Visual C 64-bit build - it requires jmp_buf to be aligned, but + it had become misaligned. + Revised contrib/pngminus/pnm2png.c to avoid warnings when png_uint_32 + and unsigned long are of different sizes. + +Version 1.6.0beta05 [January 15, 2012] + Updated manual with description of the simplified API (copied from png.h) + Fix bug in pngerror.c: some long warnings were being improperly truncated + (CVE-2011-3464, bug introduced in libpng-1.5.3beta05). + +Version 1.6.0beta06 [January 24, 2012] + Added palette support to the simplified APIs. This commit + changes some of the macro definitions in png.h, app code + may need corresponding changes. + Increased the formatted warning buffer to 192 bytes. + Added color-map support to simplified API. This is an initial version for + review; the documentation has not yet been updated. + Fixed Min/GW uninstall to remove libpng.dll.a + +Version 1.6.0beta07 [January 28, 2012] + Eliminated Intel icc/icl compiler warnings. The Intel (GCC derived) + compiler issues slightly different warnings from those issued by the + current vesions of GCC. This eliminates those warnings by + adding/removing casts and small code rewrites. + Updated configure.ac from autoupdate: added --enable-werror option. + Also some layout regularization and removal of introduced tab characters + (replaced with 3-character indentation). Obsolete macros identified by + autoupdate have been removed; the replacements are all in 2.59 so + the pre-req hasn't been changed. --enable-werror checks for support + for -Werror (or the given argument) in the compiler. This mimics the + gcc configure option by allowing -Werror to be turned on safely; without + the option the tests written in configure itself fail compilation because + they cause compiler warnings. + Rewrote autogen.sh to run autoreconf instead of running tools one-by-one. + Conditionalize the install rules for MINGW and CYGWIN in CMakeLists.txt and + set CMAKE_LIBRARY_OUTPUT_DIRECTORY to "lib" on all platforms (C. Yapp). + Freeze libtool files in the 'scripts' directory. This version of autogen.sh + attempts to dissuade people from running it when it is not, or should not, + be necessary. In fact, autogen.sh does not work when run in a libpng + directory extracted from a tar distribution anymore. You must run it in + a GIT clone instead. + Added two images to contrib/pngsuite (1-bit and 2-bit transparent grayscale), + and renamed three whose names were inconsistent with those in + pngsuite/README.txt. + +Version 1.6.0beta08 [February 1, 2012] + Fixed Image::colormap misalignment in pngstest.c + Check libtool/libtoolize version number (2.4.2) in configure.ac + Divide test-pngstest.sh into separate pngstest runs for basic and + transparent images. + Moved automake options to AM_INIT_AUTOMAKE in configure.ac + Added color-tests, silent-rules (Not yet implemented in Makefile.am) and + version checking to configure.ac + Improved pngstest speed by not doing redundant tests and add const to + the background parameter of png_image_finish_read. The --background + option is now done automagically only when required, so that commandline + option no longer exists. + Cleaned up pngpriv.h to consistently declare all functions and data. + Also eliminated PNG_CONST_DATA, which is apparently not needed but we + can't be sure until it is gone. + Added symbol prefixing that allows all the libpng external symbols + to be prefixed (suggested by Reuben Hawkins). + Updated "ftbb*.png" list in the owatcom and vstudio projects. + Fixed 'prefix' builds on clean systems. The generation of pngprefix.h + should not require itself. + Updated INSTALL to explain that autogen.sh must be run in a GIT clone, + not in a libpng directory extracted from a tar distribution. + +Version 1.6.0beta09 [February 1, 2012] + Reverted the prebuilt configure files to libpng-1.6.0beta05 condition. + +Version 1.6.0beta10 [February 3, 2012] + Added Z_SOLO for zlib-1.2.6+ and correct pngstest tests + Updated list of test images in CMakeLists.txt + Updated the prebuilt configure files to current condition. + Revised INSTALL information about autogen.sh; it works in tar distributions. + +Version 1.6.0beta11 [February 16, 2012] + Fix character count in pngstest command in projects/owatcom/pngstest.tgt + Revised test-pngstest.sh to report PASS/FAIL for each image. + Updated documentation about the simplified API. + Corrected estimate of error in libpng png_set_rgb_to_gray API. The API is + extremely inaccurate for sRGB conversions because it uses an 8-bit + intermediate linear value and it does not use the sRGB transform, so it + suffers from the known instability in gamma transforms for values close + to 0 (see Poynton). The net result is that the calculation has a maximum + error of 14.99/255; 0.5/255^(1/2.2). pngstest now uses 15 for the + permitted 8-bit error. This may still not be enough because of arithmetic + error. + Removed some unused arrays (with #ifdef) from png_read_push_finish_row(). + Fixed a memory overwrite bug in simplified read of RGB PNG with + non-linear gamma Also bugs in the error checking in pngread.c and changed + quite a lot of the checks in pngstest.c to be correct; either correctly + written or not over-optimistic. The pngstest changes are insufficient to + allow all possible RGB transforms to be passed; pngstest cmppixel needs + to be rewritten to make it clearer which errors it allows and then changed + to permit known inaccuracies. + Removed tests for no-longer-used *_EMPTY_PLTE_SUPPORTED from pngstruct.h + Fixed fixed/float API export conditionals. 1) If FIXED_POINT or + FLOATING_POINT options were switched off, png.h ended up with lone ';' + characters. This is not valid ANSI-C outside a function. The ';' + characters have been moved inside the definition of PNG_FP_EXPORT and + PNG_FIXED_EXPORT. 2) If either option was switched off, the declaration + of the corresponding functions were completely omitted, even though some + of them are still used internally. The result is still valid, but + produces warnings from gcc with some warning options (including -Wall). The + fix is to cause png.h to declare the functions with PNG_INTERNAL_FUNCTION + when png.h is included from pngpriv.h. + Check for invalid palette index while reading paletted PNG. When one is + found, issue a warning and increase png_ptr->num_palette accordingly. + Apps are responsible for checking to see if that happened. + +Version 1.6.0beta12 [February 18, 2012] + Do not increase num_palette on invalid_index. + Relocated check for invalid palette index to pngrtran.c, after unpacking + the sub-8-bit pixels. + Fixed CVE-2011-3026 buffer overrun bug. This bug was introduced when + iCCP chunk support was added at libpng-1.0.6. Deal more correctly with the + test on iCCP chunk length. Also removed spurious casts that may hide + problems on 16-bit systems. + +Version 1.6.0beta13 [February 24, 2012] + Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from + pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c; + now that png_ptr->buffer is inaccessible to applications, the special + handling is no longer useful. + Added PNG_SAFE_LIMITS feature to pnglibconf.dfa, pngpriv.h, and new + pngusr.dfa to reset the user limits to safe ones if PNG_SAFE_LIMITS is + defined. To enable, use "CPPFLAGS=-DPNG_SAFE_LIMITS_SUPPORTED=1" on the + configure command or put #define PNG_SAFE_LIMITS_SUPPORTED in + pnglibconf.h.prebuilt and pnglibconf.h. + +Version 1.6.0beta14 [February 27, 2012] + Added information about the new limits in the manual. + Updated Makefile.in + +Version 1.6.0beta15 [March 2, 2012] + Removed unused "current_text" members of png_struct and the png_free() + of png_ptr->current_text from pngread.c + Rewrote pngstest.c for substantial speed improvement. + Fixed transparent pixel and 16-bit rgb tests in pngstest and removed a + spurious check in pngwrite.c + Added PNG_IMAGE_FLAG_FAST for the benefit of applications that store + intermediate files, or intermediate in-memory data, while processing + image data with the simplified API. The option makes the files larger + but faster to write and read. pngstest now uses this by default; this + can be disabled with the --slow option. + Improved pngstest fine tuning of error numbers, new test file generator. + The generator generates images that test the full range of sample values, + allow the error numbers in pngstest to be tuned and checked. makepng + also allows generation of images with extra chunks, although this is + still work-in-progress. + Added check for invalid palette index while reading. + Fixed some bugs in ICC profile writing. The code should now accept + all potentially valid ICC profiles and reject obviously invalid ones. + It now uses png_error() to do so rather than casually writing a PNG + without the necessary color data. + Removed whitespace from the end of lines in all source files and scripts. + +Version 1.6.0beta16 [March 6, 2012] + Relocated palette-index checking function from pngrutil.c to pngtrans.c + Added palette-index checking while writing. + Changed png_inflate() and calling routines to avoid overflow problems. + This is an intermediate check-in that solves the immediate problems and + introduces one performance improvement (avoiding a copy via png_ptr->zbuf.) + Further changes will be made to make ICC profile handling more secure. + Fixed build warnings (MSVC, GCC, GCC v3). Cygwin GCC with default options + declares 'index' as a global, causing a warning if it is used as a local + variable. GCC 64-bit warns about assigning a (size_t) (unsigned 64-bit) + to an (int) (signed 32-bit). MSVC, however, warns about using the + unary '-' operator on an unsigned value (even though it is well defined + by ANSI-C to be ~x+1). The padding calculation was changed to use a + different method. Removed the tests on png_ptr->pass. + Added contrib/libtests/tarith.c to test internal arithmetic functions from + png.c. This is a libpng maintainer program used to validate changes to the + internal arithmetic functions. + Made read 'inflate' handling like write 'deflate' handling. The read + code now claims and releases png_ptr->zstream, like the write code. + The bug whereby the progressive reader failed to release the zstream + is now fixed, all initialization is delayed, and the code checks for + changed parameters on deflate rather than always calling + deflatedEnd/deflateInit. + Validate the zTXt strings in pngvalid. + Added code to validate the windowBits value passed to deflateInit2(). + If the call to deflateInit2() is wrong a png_warning will be issued + (in fact this is harmless, but the PNG data produced may be sub-optimal). + +Version 1.6.0beta17 [March 10, 2012] + Fixed PNG_LIBPNG_BUILD_BASE_TYPE definition. + Reject all iCCP chunks after the first, even if the first one is invalid. + Deflate/inflate was reworked to move common zlib calls into single + functions [rw]util.c. A new shared keyword check routine was also added + and the 'zbuf' is no longer allocated on progressive read. It is now + possible to call png_inflate() incrementally. A warning is no longer + issued if the language tag or translated keyword in the iTXt chunk + has zero length. + If benign errors are disabled use maximum window on ancilliary inflate. + This works round a bug introduced in 1.5.4 where compressed ancillary + chunks could end up with a too-small windowBits value in the deflate + header. + +Version 1.6.0beta18 [March 16, 2012] + Issue a png_benign_error() instead of png_warning() about bad palette index. + In pngtest, treat benign errors as errors if "-strict" is present. + Fixed an off-by-one error in the palette index checking function. + Fixed a compiler warning under Cygwin (Windows-7, 32-bit system) + Revised example.c to put text strings in a temporary character array + instead of directly assigning string constants to png_textp members. + This avoids compiler warnings when -Wwrite-strings is enabled. + Added output flushing to aid debugging under Visual Studio. Unfortunately + this is necessary because the VS2010 output window otherwise simply loses + the error messages on error (they weren't flushed to the window before + the process exited, apparently!) + Added configuration support for benign errors and changed the read + default. Also changed some warnings in the iCCP and sRGB handling + from to benign errors. Configuration now makes read benign + errors warnings and write benign errors to errors by default (thus + changing the behavior on read). The simplified API always forces + read benign errors to warnings (regardless of the system default, unless + this is disabled in which case the simplified API can't be built.) + +Version 1.6.0beta19 [March 18, 2012] + Work around for duplicate row start calls; added warning messages. + This turns on PNG_FLAG_DETECT_UNINITIALIZED to detect app code that + fails to call one of the 'start' routines (not enabled in libpng-1.5 + because it is technically an API change, since it did normally work + before.) It also makes duplicate calls to png_read_start_row (an + internal function called at the start of the image read) benign, as + they were before changes to use png_inflate_claim. Somehow webkit is + causing this to happen; this is probably a mis-feature in the zlib + changes so this commit is only a work-round. + Removed erroneous setting of DETECT_UNINITIALIZED and added more + checks. The code now does a png_error if an attempt is made to do the + row initialization twice; this is an application error and it has + serious consequences because the transform data in png_struct is + changed by each call. + Added application error reporting and added chunk names to read + benign errors; also added --strict to pngstest - not enabled + yet because a warning is produced. + Avoid the double gamma correction warning in the simplified API. + This allows the --strict option to pass in the pngstest checks + +Version 1.6.0beta20 [March 29, 2012] + Changed chunk handler warnings into benign errors, incrementally load iCCP + Added checksum-icc.c to contrib/tools + Prevent PNG_EXPAND+PNG_SHIFT doing the shift twice. + Recognize known sRGB ICC profiles while reading; prefer writing the + iCCP profile over writing the sRGB chunk, controlled by the + PNG_sRGB_PROFILE_CHECKS option. + Revised png_set_text_2() to avoid potential memory corruption (fixes + CVE-2011-3048, also known as CVE-2012-3425). + +Version 1.6.0beta21 [April 27, 2012] + Revised scripts/makefile.darwin: use system zlib; remove quotes around + architecture list; add missing ppc architecture; add architecture options + to shared library link; don't try to create a shared lib based on missing + RELEASE variable. + Enable png_set_check_for_invalid_index() for both read and write. + Removed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED in pngpriv.h around + declaration of png_handle_unknown(). + Added -lssp_nonshared in a comment in scripts/makefile.freebsd + and changed deprecated NOOBJ and NOPROFILE to NO_OBJ and NO_PROFILE. + +Version 1.6.0beta22 [May 23, 2012] + Removed need for -Wno-cast-align with clang. clang correctly warns on + alignment increasing pointer casts when -Wcast-align is passed. This + fixes the cases that clang warns about either by eliminating the + casts from png_bytep to png_uint_16p (pngread.c), or, for pngrutil.c + where the cast is previously verified or pngstest.c where it is OK, by + introducing new png_aligncast macros to do the cast in a way that clang + accepts. + +Version 1.6.0beta23 [June 6, 2012] + Revised CMakeLists.txt to not attempt to make a symlink under mingw. + Made fixes for new optimization warnings from gcc 4.7.0. The compiler + performs an optimization which is safe; however it then warns about it. + Changing the type of 'palette_number' in pngvalid.c removes the warning. + Do not depend upon a GCC feature macro being available for use in generating + the linker mapfile symbol prefix. + Improved performance of new do_check_palette_indexes() function (only + update the value when it actually increases, move test for whether + the check is wanted out of the function. + +Version 1.6.0beta24 [June 7, 2012] + Don't check palette indexes if num_palette is 0 (as it can be in MNG files). + +Version 1.6.0beta25 [June 16, 2012] + Revised png_set_keep_unknown_chunks() so num_chunks < 0 means ignore all + unknown chunks and all known chunks except for IHDR, PLTE, tRNS, IDAT, + and IEND. Previously it only meant ignore all unknown chunks, the + same as num_chunks == 0. Revised png_image_skip_unused_chunks() to + provide a list of chunks to be processed instead of a list of chunks to + ignore. Revised contrib/gregbook/readpng2.c accordingly. + +Version 1.6.0beta26 [July 10, 2012] + Removed scripts/makefile.cegcc from the *.zip and *.7z distributions; it + depends on configure, which is not included in those archives. + Moved scripts/chkfmt to contrib/tools. + Changed "a+w" to "u+w" in Makefile.in to fix CVE-2012-3386. + +Version 1.6.0beta27 [August 11, 2012] + Do not compile PNG_DEPRECATED, PNG_ALLOC and PNG_PRIVATE when __GNUC__ < 3. + Do not use __restrict when GNUC is <= 3.1 + Removed references to png_zalloc() and png_zfree() from the manual. + Fixed configurations where floating point is completely disabled. Because + of the changes to support symbol prefixing PNG_INTERNAL_FUNCTION declares + floating point APIs during libpng builds even if they are completely + disabled. This requires the png floating point types (png_double*) to be + declared even though the functions are never actually defined. This + change provides a dummy definition so that the declarations work, yet any + implementation will fail to compile because of an incomplete type. + Re-eliminated the use of strcpy() in pngtest.c. An unncessary use of + strcpy() was accidentally re-introduced in libpng16; this change replaces + it with strncpy(). + Eliminated use of png_sizeof(); use sizeof() instead. + Use a consistent style for (sizeof type) and (sizeof (array)) + Cleanup of png_set_filler(). This function does very different things on + read and write. In libpng 1.6 the two cases can be distinguished and + considerable code cleanup, and extra error checking, is possible. This + makes calls on the write side that have no effect be ignored with a + png_app_error(), which can be disabled in the app using + png_set_benign_errors(), and removes the spurious use of usr_channels + on the read side. + Insist on autotools 1.12.1 for git builds because there are security issues + with 1.12 and insisting on anything less would allow 1.12 to be used. + Removed info_ptr->signature[8] from WRITE-only builds. + Add some conditions for compiling png_fixed(). This is a small function + but it requires "-lm" on some platforms. + Cause pngtest --strict to fail on any warning from libpng (not just errors) + and cause it not to fail at the comparison step if libpng lacks support + for writing chunks that it reads from the input (currently only implemented + for compressed text chunks). + Make all three "make check" test programs work without READ or WRITE support. + Now "make check" will succeed even if libpng is compiled with -DPNG_NO_READ + or -DPNG_NO_WRITE. The tests performed are reduced, but the basic reading + and writing of a PNG file is always tested by one or more of the tests. + Consistently use strlen(), memset(), memcpy(), and memcmp() instead of the + png_strlen(), png_memset(), png_memcpy(), and png_memcmp() macros. + Removed the png_sizeof(), png_strlen(), png_memset(), png_memcpy(), and + png_memcmp() macros. + Work around gcc 3.x and Microsoft Visual Studio 2010 complaints. Both object + to the split initialization of num_chunks. + +Version 1.6.0beta28 [August 29, 2012] + Unknown handling fixes and clean up. This adds more correct option + control of the unknown handling, corrects the pre-existing bug where + the per-chunk 'keep' setting is ignored and makes it possible to skip + IDAT chunks in the sequential reader (broken in earlier 1.6 versions). + There is a new test program, test-unknown.c, which is a work in progress + (not currently part of the test suite). Comments in the header files now + explain how the unknown handling works. + Allow fine grain control of unknown chunk APIs. This change allows + png_set_keep_unknown_chunks() to be turned off if not required and causes + both read and write to behave appropriately (on read this is only possible + if the user callback is used to handle unknown chunks). The change + also removes the support for storing unknown chunks in the info_struct + if the only unknown handling enabled is via the callback, allowing libpng + to be configured with callback reading and none of the unnecessary code. + Corrected fix for unknown handling in pngtest. This reinstates the + libpng handling of unknown chunks other than vpAg and sTER (including + unsafe-to-copy chunks which were dropped before) and eliminates the + repositioning of vpAg and sTER in pngtest.png by changing pngtest.png + (so the chunks are where libpng would put them). + Added "tunknown" test and corrected a logic error in png_handle_unknown() + when SAVE support is absent. Moved the shell test scripts for + contrib/libtests from the libpng top directory to contrib/libtests. + png_handle_unknown() must always read or skip the chunk, if + SAVE_UNKNOWN_CHUNKS is turned off *and* the application does not set + a user callback an unknown chunk will not be read, leading to a read + error, which was revealed by the "tunknown" test. + Cleaned up and corrected ICC profile handling. + contrib/libtests/makepng: corrected 'rgb' and 'gray' cases. profile_error + messages could be truncated; made a correct buffer size calculation and + adjusted pngerror.c appropriately. png_icc_check_* checking improved; + changed the functions to receive the correct color type of the PNG on read + or write and check that it matches the color space of the profile (despite + what the comments said before, there is danger in assuming the app will + cope correctly with an RGB profile on a grayscale image and, since it + violates the PNG spec, allowing it is certain to produce inconsistent + app behavior and might even cause app crashes.) Check that profiles + contain the tags needed to process the PNG (tags all required by the ICC + spec). Removed unused PNG_STATIC from pngpriv.h. + +Version 1.6.0beta29 [September 4, 2012] + Fixed the simplified API example programs to add the *colormap parameter + to several of he API and improved the error message if the version field + is not set. + Added contrib/examples/* to the *.zip and *.7z distributions. + Updated simplified API synopses and description of the png_image structure + in the manual. + Made makepng and pngtest produce identical PNGs, add "--relaxed" option + to pngtest. The "--relaxed" option turns off the benign errors that are + enabled by default in pre-RC builds. makepng can now write ICC profiles + where the length has not been extended to a multiple of 4, and pngtest + now intercepts all libpng errors, allowing the previously-introduced + "--strict test" on no warnings to actually work. + Improved ICC profile handling including cHRM chunk generation and fixed + Cygwin+MSVC build errors. The ICC profile handling now includes more + checking. Several errors that caused rejection of the profile are now + handled with a warning in such a way that the invalid profiles will be + read by default in release (but not pre-RC) builds but will not be + written by default. The easy part of handling the cHRM chunk is written, + where the ICC profile contains the required data. The more difficult + part plus guessing a gAMA value requires code to pass selected RGB values + through the profile. + +Version 1.6.0beta30 [October 24, 2012] + Changed ICC profile matrix/vector types to not depend on array type rules. + By the ANSI-C standard the new types should be identical to the previous + versions, and all known versions of gcc tested with the previous versions + except for GCC-4.2.1 work with this version. The change makes the ANSI-C + rule that const applied to an array of elements applies instead to the + elements in the array moot by explicitly applying const to the base + elements of the png_icc_matrix and png_icc_vector types. The accidental + (harmless) 'const' previously applied to the parameters of two of the + functions have also been removed. + Added a work around for GCC 4.2 optimization bug. + Marked the broken (bad white point) original HP sRGB profiles correctly and + correct comments. + Added -DZ_SOLO to contrib/pngminim/*/makefile to work with zlib-1.2.7 + Use /MDd for vstudio debug builds. Also added pngunkown to the vstudio + builds, fixed build errors and corrected a minor exit code error in + pngvalid if the 'touch' file name is invalid. + Add updated WARNING file to projects/vstudio from libpng 1.5/vstudio + Fixed build when using #define PNG_NO_READ_GAMMA in png_do_compose() in + pngrtran.c (Domani Hannes). + +Version 1.6.0beta31 [November 1, 2012] + Undid the erroneous change to vstudio/pngvalid build in libpng-1.6.0beta30. + Made pngvalid so that it will build outside the libpng source tree. + Made builds -DPNG_NO_READ_GAMMA compile (the unit tests still fail). + Made PNG_NO_READ_GAMMA switch off interfaces that depend on READ_GAMMA. + Prior to 1.6.0 switching off READ_GAMMA did unpredictable things to the + interfaces that use it (specifically, png_do_background in 1.4 would + simply display composite for grayscale images but do composition + with the incorrect arithmetic for color ones). In 1.6 the semantic + of -DPNG_NO_READ_GAMMA is changed to simply disable any interface that + depends on it; this obliges people who set it to consider whether they + really want it off if they happen to use any of the interfaces in + question (typically most users who disable it won't). + Fixed GUIDs in projects/vstudio. Some were duplicated or missing, + resulting in VS2010 having to update the files. + Removed non-working ICC profile support code that was mostly added to + libpng-1.6.0beta29 and beta30. There was too much code for too little + gain; implementing full ICC color correction may be desireable but is left + up to applications. + +Version 1.6.0beta32 [November 25, 2012] + Fixed an intermittent SEGV in pngstest due to an uninitialized array element. + Added the ability for contrib/libtests/makepng.c to make a PNG with just one + color. This is useful for debugging pngstest color inaccuracy reports. + Fixed error checking in the simplified write API (Olaf van der Spek) + Made png_user_version_check() ok to use with libpng version 1.10.x and later. + +Version 1.6.0beta33 [December 15, 2012] + Fixed typo in png.c (PNG_SET_CHUNK_MALLOC_MAX should be PNG_CHUNK_MALLOC_MAX) + that causes the MALLOC_MAX limit not to work (John Bowler) + Change png_warning() to png_app_error() in pngwrite.c and comment the + fall-through condition. + Change png_warning() to png_app_warning() in png_write_tRNS(). + Rearranged the ARM-NEON optimizations: Isolated the machine specific code + to the hardware subdirectory and added comments to pngrutil.c so that + implementors of other optimizations know what to do. + Fixed cases of unquoted DESTDIR in Makefile.am + Rebuilt Makefile.in, etc., with autoconf-2.69 and automake-1.12.5. + +Version 1.6.0beta34 [December 19, 2012] + Cleaned up whitespace in the synopsis portion of the manpage "libpng.3" + Disassembled the version number in scripts/options.awk (necessary for + building on SunOs). + +Version 1.6.0beta35 [December 23, 2012] + Made default Zlib compression settings be configurable. This adds #defines to + pnglibconf.h to control the defaults. + Fixed Windows build issues, enabled ARM compilation. Various warnings issued + by earlier versions of GCC fixed for Cygwin and Min/GW (which both use old + GCCs.) ARM support is enabled by default in zlib.props (unsupported by + Microsoft) and ARM compilation is made possible by deleting the check for + x86. The test programs cannot be run because they are not signed. + +Version 1.6.0beta36 [January 2, 2013] + Discontinued distributing libpng-1.x.x.tar.bz2. + Discontinued distributing libpng-1.7.0-1.6.0-diff.txt and similar. + Rebuilt configure with autoconf-2.69 (inadvertently not done in beta33) + Fixed 'make distcheck' on SUN OS - libpng.so was not being removed + +Version 1.6.0beta37 [January 10, 2013] + Fixed conceivable but difficult to repro overflow. Also added two test + programs to generate and test a PNG which should have the problem. + +Version 1.6.0beta39 [January 19, 2013] + Again corrected attempt at overflow detection in png_set_unknown_chunks() + (CVE-2013-7353). Added overflow detection in png_set_sPLT() and + png_set_text_2() (CVE-2013-7354). + +Version 1.6.0beta40 [January 20, 2013] + Use consistent handling of overflows in text, sPLT and unknown png_set_* APIs + +Version 1.6.0rc01 [January 26, 2013] + No changes. + +Version 1.6.0rc02 [February 4, 2013] + Added png_get_palette_max() function. + +Version 1.6.0rc03 [February 5, 2013] + Fixed the png_get_palette_max API. + +Version 1.6.0rc04 [February 7, 2013] + Turn serial tests back on (recently turned off by autotools upgrade). + +Version 1.6.0rc05 [February 8, 2013] + Update manual about png_get_palette_max(). + +Version 1.6.0rc06 [February 9, 2013] + Fixed missing dependency in --prefix builds The intermediate + internal 'prefix.h' file can only be generated correctly after + pnglibconf.h, however the dependency was not in Makefile.am. The + symptoms are unpredictable depending on the order make chooses to + build pngprefix.h and pnglibconf.h, often the error goes unnoticed + because there is a system pnglibconf.h to use instead. + +Version 1.6.0rc07 [February 10, 2013] + Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED + block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly. + +Version 1.6.0rc08 [February 10, 2013] + Fix typo in png.h #ifdef + +Version 1.6.0 [February 14, 2013] + No changes. + +Version 1.6.1beta01 [February 16, 2013] + Made symbol prefixing work with the ARM neon optimizations. Also allow + pngpriv.h to be included for preprocessor definitions only, so it can + be used in non-C/C++ files. Back ported from libpng 1.7. + Made sRGB check numbers consistent. + Ported libpng 1.5 options.awk/dfn file handling to 1.6, fixed one bug. + Removed cc -E workround, corrected png_get_palette_max API Tested on + SUN OS cc 5.9, which demonstrates the tokenization problem previously + avoided by using /lib/cpp. Since all .dfn output is now protected in + double quotes unless it is to be macro substituted the fix should + work everywhere. + Enabled parallel tests - back ported from libpng-1.7. + scripts/pnglibconf.dfa formatting improvements back ported from libpng17. + Fixed a race condition in the creation of the build 'scripts' directory + while building with a parallel make. + Use approved/supported Android method to check for NEON, use Linux/POSIX + 1003.1 API to check /proc/self/auxv avoiding buffer allocation and other + library calls (ported from libpng15). + +Version 1.6.1beta02 [February 19, 2013] + Use parentheses more consistently in "#if defined(MACRO)" tests. + Folded long lines. + Reenabled code to allow zero length PLTE chunks for MNG. + +Version 1.6.1beta03 [February 22, 2013] + Fixed ALIGNED_MEMORY support. + Added a new configure option: + --enable-arm-neon=always will stop the run-time checks. New checks + within arm/arm_init.c will cause the code not to be compiled unless + __ARM_NEON__ is set. This should make it fail safe (if someone asks + for it on then the build will fail if it can't be done.) + Updated the INSTALL document. + +Version 1.6.1beta04 [February 27, 2013] + Revised INSTALL to recommend using CPPFLAGS instead of INCLUDES. + Revised scripts/makefile.freebsd to respect ZLIBLIB and ZLIBINC. + Revised scripts/dfn.awk to work with the buggy MSYS awk that has trouble + with CRLF line endings. + +Version 1.6.1beta05 [March 1, 2013] + Avoid a possible memory leak in contrib/gregbook/readpng.c + +Version 1.6.1beta06 [March 4, 2013] + Better documentation of unknown handling API interactions. + Corrected Android builds and corrected libpng.vers with symbol + prefixing. It also makes those tests compile and link on Android. + Added an API png_set_option() to set optimization options externally, + providing an alternative and general solution for the non-portable + run-time tests used by the ARM Neon code, using the PNG_ARM_NEON option. + The order of settings vs options in pnglibconf.h is reversed to allow + settings to depend on options and options can now set (or override) the + defaults for settings. + +Version 1.6.1beta07 [March 7, 2013] + Corrected simplified API default gamma for color-mapped output, added + a flag to change default. In 1.6.0 when the simplified API was used + to produce color-mapped output from an input image with no gamma + information the gamma assumed for the input could be different from + that assumed for non-color-mapped output. In particular 16-bit depth + input files were assumed to be sRGB encoded, whereas in the 'direct' + case they were assumed to have linear data. This was an error. The + fix makes the simplified API treat all input files the same way and + adds a new flag to the png_image::flags member to allow the + application/user to specify that 16-bit files contain sRGB data + rather than the default linear. + Fixed bugs in the pngpixel and makepng test programs. + +Version 1.6.1beta08 [March 7, 2013] + Fixed CMakelists.txt to allow building a single variant of the library + (Claudio Bley): + Introduced a PNG_LIB_TARGETS variable that lists all activated library + targets. It is an error if this variable ends up empty, ie. you have + to build at least one library variant. + Made the *_COPY targets only depend on library targets actually being build. + Use PNG_LIB_TARGETS to unify a code path. + Changed the CREATE_SYMLINK macro to expect the full path to a file as the + first argument. When symlinking the filename component of that path is + determined and used as the link target. + Use copy_if_different in the CREATE_SYMLINK macro. + +Version 1.6.1beta09 [March 13, 2013] + Eliminated two warnings from the Intel C compiler. The warnings are + technically valid, although a reasonable treatment of division would + show it to be incorrect. + +Version 1.6.1rc01 [March 21, 2013] + No changes. + +Version 1.6.1 [March 28, 2013] + No changes. + +Version 1.6.2beta01 [April 14, 2013] + Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk handling. + Fixed incorrect warning of excess deflate data. End condition - the + warning would be produced if the end of the deflate stream wasn't read + in the last row. The warning is harmless. + Corrected the test on user transform changes on read. It was in the + png_set of the transform function, but that doesn't matter unless the + transform function changes the rowbuf size, and that is only valid if + transform_info is called. + Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c + (Flavio Medeiros). + Corrected length written to uncompressed iTXt chunks (Samuli Suominen). + Bug was introduced in libpng-1.6.0. + +Version 1.6.2rc01 [April 18, 2013] + Added contrib/tools/fixitxt.c, to repair the erroneous iTXt chunk length + written by libpng-1.6.0 and 1.6.1. + Disallow storing sRGB information when the sRGB is not supported. + +Version 1.6.2rc02 [April 18, 2013] + Merge pngtest.c with libpng-1.7.0 + +Version 1.6.2rc03 [April 22, 2013] + Trivial spelling cleanup. + +Version 1.6.2rc04 and 1.6.2rc05 [omitted] + +Version 1.6.2rc06 [April 24, 2013] + Reverted to version 1.6.2rc03. Recent changes to arm/neon support + have been ported to libpng-1.7.0beta09 and will reappear in version + 1.6.3beta01. + +Version 1.6.2 [April 25, 2013] + No changes. + +Version 1.6.3beta01 [April 25, 2013] + Revised stack marking in arm/filter_neon.S and configure.ac. + Ensure that NEON filter stuff is completely disabled when switched 'off'. + Previously the ARM NEON specific files were still built if the option + was switched 'off' as opposed to being explicitly disabled. + +Version 1.6.3beta02 [April 26, 2013] + Test for 'arm*' not just 'arm' in the host_cpu configure variable. + Rebuilt the configure scripts. + +Version 1.6.3beta03 [April 30, 2013] + Expanded manual paragraph about writing private chunks, particularly + the need to call png_set_keep_unknown_chunks() when writing them. + Avoid dereferencing NULL pointer possibly returned from + png_create_write_struct() (Andrew Church). + +Version 1.6.3beta05 [May 9, 2013] + Calculate our own zlib windowBits when decoding rather than trusting the + CMF bytes in the PNG datastream. + Added an option to force maximum window size for inflating, which was + the behavior of libpng15 and earlier, via a new PNG_MAXIMUM_INFLATE_WINDOW + option for png_set_options(). + Added png-fix-itxt and png-fix-too-far-back to the built programs and + removed warnings from the source code and timepng that are revealed as + a result. + Detect wrong libpng versions linked to png-fix-too-far-back, which currently + only works with libpng versions that can be made to reliably fail when + the deflate data contains an out-of-window reference. This means only + 1.6 and later. + Fixed gnu issues: g++ needs a static_cast, gcc 4.4.7 has a broken warning + message which it is easier to work round than ignore. + Updated contrib/pngminus/pnm2png.c (Paul Stewart): + Check for EOF + Ignore "#" delimited comments in input file to pnm2png.c. + Fixed whitespace handling + Added a call to png_set_packing() + Initialize dimension values so if sscanf fails at least we have known + invalid values. + Attempt to detect configuration issues with png-fix-too-far-back, which + requires both the correct libpng and the correct zlib to function + correctly. + Check ZLIB_VERNUM for mismatches, enclose #error in quotes + Added information in the documentation about problems with and fixes for + the bad CRC and bad iTXt chunk situations. + +Version 1.6.3beta06 [May 12, 2013] + Allow contrib/pngminus/pnm2png.c to compile without WRITE_INVERT and + WRITE_PACK supported (writes error message that it can't read P1 or + P4 PBM files). + Improved png-fix-too-far-back usage message, added --suffix option. + Revised contrib/pngminim/*/makefile to generate pnglibconf.h with the + right zlib header files. + Separated CPPFLAGS and CFLAGS in contrib/pngminim/*/makefile + +Version 1.6.3beta07 [June 8, 2013] + Removed a redundant test in png_set_IHDR(). + Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt (Andrew Hundt) + Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt + Enclose the prototypes for the simplified write API in + #ifdef PNG_STDIO_SUPPORTED/#endif + Make ARM NEON support work at compile time (not just configure time). + This moves the test on __ARM_NEON__ into pngconf.h to avoid issues when + using a compiler that compiles for multiple architectures at one time. + Removed PNG_FILTER_OPTIMIZATIONS and PNG_ARM_NEON_SUPPORTED from + pnglibconf.h, allowing more of the decisions to be made internally + (pngpriv.h) during the compile. Without this, symbol prefixing is broken + under certain circumstances on ARM platforms. Now only the API parts of + the optimizations ('check' vs 'api') are exposed in the public header files + except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the + decision about whether or not to use the optimizations. + Protect symbol prefixing against CC/CPPFLAGS/CFLAGS useage. + Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test + on __ARM_NEON__ from configure time to compile time. This breaks symbol + prefixing because the definition of the special png_init_filter_functions + call was hidden at configure time if the relevant compiler arguments are + passed in CFLAGS as opposed to CC. This change attempts to avoid all + the confusion that would result by declaring the init function even when + it is not used, so that it will always get prefixed. + +Version 1.6.3beta08 [June 18, 2013] + Revised libpng.3 so that "doclifter" can process it. + +Version 1.6.3beta09 [June 27, 2013] + Revised example.c to illustrate use of PNG_DEFAULT_sRGB and PNG_GAMMA_MAC_18 + as parameters for png_set_gamma(). These have been available since + libpng-1.5.4. + Renamed contrib/tools/png-fix-too-far-back.c to pngfix.c and revised it + to check all compressed chunks known to libpng. + +Version 1.6.3beta10 [July 5, 2013] + Updated documentation to show default behavior of benign errors correctly. + Only compile ARM code when PNG_READ_SUPPORTED is defined. + Fixed undefined behavior in contrib/tools/pngfix.c and added new strip + option. pngfix relied on undefined behavior and even a simple change from + gcc to g++ caused it to fail. The new strip option 'unsafe' has been + implemented and is the default if --max is given. Option names have + been clarified, with --strip=transform now stripping the bKGD chunk, + which was stripped previously with --strip=unused. + Added all documented chunk types to pngpriv.h + Unified pngfix.c source with libpng17. + +Version 1.6.3rc01 [July 11, 2013] + No changes. + +Version 1.6.3 [July 18, 2013] + Revised manual about changes in iTXt chunk handling made in libpng-1.6.0. + Added "/* SAFE */" comments in pngrutil.c and pngrtran.c where warnings + may be erroneously issued by code-checking applications. + +Version 1.6.4beta01 [August 21, 2013] + Added information about png_set_options() to the manual. + Delay calling png_init_filter_functions() until a row with nonzero filter + is found. + +Version 1.6.4beta02 [August 30, 2013] + Fixed inconsistent conditional compilation of png_chunk_unknown_handling() + prototype, definition, and usage. Made it depend on + PNG_HANDLE_AS_UNKNOWN_SUPPORTED everywhere. + +Version 1.6.4rc01 [September 5, 2013] + No changes. + +Version 1.6.4 [September 12, 2013] + No changes. + +Version 1.6.5 [September 14, 2013] + Removed two stray lines of code from arm/arm_init.c. + +Version 1.6.6 [September 16, 2013] + Removed two stray lines of code from arm/arm_init.c, again. + +Version 1.6.7beta01 [September 30, 2013] + Revised unknown chunk code to correct several bugs in the NO_SAVE_/NO_WRITE + combination + Allow HANDLE_AS_UNKNOWN to work when other options are configured off. Also + fixed the pngminim makefiles to work when $(MAKEFLAGS) contains stuff + which terminates the make options (as by default in recent versions of + Gentoo). + Avoid up-cast warnings in pngvalid.c. On ARM the alignment requirements of + png_modifier are greater than that of png_store and as a consequence + compilation of pngvalid.c results in a warning about increased alignment + requirements because of the bare cast to (png_modifier*). The code is safe, + because the pointer is known to point to a stack allocated png_modifier, + but this change avoids the warning. + Fixed default behavior of ARM_NEON_API. If the ARM NEON API option was + compiled without the CHECK option it defaulted to on, not off. + Check user callback behavior in pngunknown.c. Previous versions compiled + if SAVE_UNKNOWN was not available but did nothing since the callback + was never implemented. + Merged pngunknown.c with 1.7 version and back ported 1.7 improvements/fixes + +Version 1.6.7beta02 [October 12, 2013] + Made changes for compatibility with automake 1.14: + 1) Added the 'compile' program to the list of programs that must be cleaned + in autogen.sh + 2) Added 'subdir-objects' which causes .c files in sub-directories to be + compiled such that the corresponding .o files are also in the + sub-directory. This is because automake 1.14 warns that the + current behavior of compiling to the top level directory may be removed + in the future. + 3) Updated dependencies on pnglibconf.h to match the new .o locations and + added all the files in contrib/libtests and contrib/tools that depend + on pnglibconf.h + 4) Added 'BUILD_SOURCES = pnglibconf.h'; this is the automake recommended + way of handling the dependencies of sources that are machine generated; + unfortunately it only works if the user does 'make all' or 'make check', + so the dependencies (3) are still required. + Cleaned up (char*) casts of zlib messages. The latest version of the Intel C + compiler complains about casting a string literal as (char*), so copied the + treatment of z_const from the library code into pngfix.c + Simplified error message code in pngunknown. The simplification has the + useful side effect of avoiding a bogus warning generated by the latest + version of the Intel C compiler (it objects to + condition ? string-literal : string-literal). + Make autogen.sh work with automake 1.13 as well as 1.14. Do this by always + removing the 1.14 'compile' script but never checking for it. + +Version 1.6.7beta03 [October 19, 2013] + Added ARMv8 support (James Yu ). Added file + arm/filter_neon_intrinsics.c; enable with -mfpu=neon. + Revised pngvalid to generate size images with as many filters as it can + manage, limited by the number of rows. + Cleaned up ARM NEON compilation handling. The tests are now in pngpriv.h + and detect the broken GCC compilers. + +Version 1.6.7beta04 [October 26, 2013] + Allow clang derived from older GCC versions to use ARM intrinsics. This + causes all clang builds that use -mfpu=neon to use the intrinsics code, + not the assembler code. This has only been tested on iOS 7. It may be + necessary to exclude some earlier clang versions but this seems unlikely. + Changed NEON implementation selection mechanism. This allows assembler + or intrinsics to be turned on at compile time during the build by defining + PNG_ARM_NEON_IMPLEMENTATION to the correct value (2 or 1). This macro + is undefined by default and the build type is selected in pngpriv.h. + +Version 1.6.7rc01 [November 2, 2013] + No changes. + +Version 1.6.7rc02 [November 7, 2013] + Fixed #include in filter_neon_intrinsics.c and ctype macros. The ctype char + checking macros take an unsigned char argument, not a signed char. + +Version 1.6.7 [November 14, 2013] + No changes. + +Version 1.6.8beta01 [November 24, 2013] + Moved prototype for png_handle_unknown() in pngpriv.h outside of + the #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED/#endif block. + Added "-Wall" to CFLAGS in contrib/pngminim/*/makefile + Conditionally compile some unused functions reported by -Wall in + pngminim. + Fixed 'minimal' builds. Various obviously useful minimal configurations + don't build because of missing contrib/libtests test programs and + overly complex dependencies in scripts/pnglibconf.dfa. This change + adds contrib/conftest/*.dfa files that can be used in automatic build + scripts to ensure that these configurations continue to build. + Enabled WRITE_INVERT and WRITE_PACK in contrib/pngminim/encoder. + Fixed pngvalid 'fail' function declaration on the Intel C Compiler. + This reverts to the previous 'static' implementation and works round + the 'unused static function' warning by using PNG_UNUSED(). + +Version 1.6.8beta02 [November 30, 2013] + Removed or marked PNG_UNUSED some harmless "dead assignments" reported + by clang scan-build. + Changed tabs to 3 spaces in png_debug macros and changed '"%s"m' + to '"%s" m' to improve portability among compilers. + Changed png_free_default() to free() in pngtest.c + +Version 1.6.8rc01 [December 12, 2013] + Tidied up pngfix inits and fixed pngtest no-write builds. + +Version 1.6.8rc02 [December 14, 2013] + Handle zero-length PLTE chunk or NULL palette with png_error() + instead of png_chunk_report(), which by default issues a warning + rather than an error, leading to later reading from a NULL pointer + (png_ptr->palette) in png_do_expand_palette(). This is CVE-2013-6954 + and VU#650142. Libpng-1.6.1 through 1.6.7 are vulnerable. + Libpng-1.6.0 and earlier do not have this bug. + +Version 1.6.8 [December 19, 2013] + No changes. + +Version 1.6.9beta01 [December 26, 2013] + Bookkeeping: Moved functions around (no changes). Moved transform + function definitions before the place where they are called so that + they can be made static. Move the intrapixel functions and the + grayscale palette builder out of the png?tran.c files. The latter + isn't a transform function and is no longer used internally, and the + former MNG specific functions are better placed in pngread/pngwrite.c + Made transform implementation functions static. This makes the internal + functions called by png_do_{read|write}_transformations static. On an + x86-64 DLL build (Gentoo Linux) this reduces the size of the text + segment of the DLL by 1208 bytes, about 0.6%. It also simplifies + maintenance by removing the declarations from pngpriv.h and allowing + easier changes to the internal interfaces. + Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69 + in the tar distributions. + +Version 1.6.9beta02 [January 1, 2014] + Added checks for libpng 1.5 to pngvalid.c. This supports the use of + this version of pngvalid in libpng 1.5 + Merged with pngvalid.c from libpng-1.7 changes to create a single + pngvalid.c + Removed #error macro from contrib/tools/pngfix.c (Thomas Klausner). + Merged pngrio.c, pngtrans.c, pngwio.c, and pngerror.c with libpng-1.7.0 + Merged libpng-1.7.0 changes to make no-interlace configurations work + with test programs. + Revised pngvalid.c to support libpng 1.5, which does not support the + PNG_MAXIMUM_INFLATE_WINDOW option, so #define it out when appropriate in + pngvalid.c + Allow unversioned links created on install to be disabled in configure. + In configure builds 'make install' changes/adds links like png.h + and libpng.a to point to the newly installed, versioned, files (e.g. + libpng17/png.h and libpng17.a). Three new configure options and some + rearrangement of Makefile.am allow creation of these links to be disabled. + +Version 1.6.9beta03 [January 10, 2014] + Removed potentially misleading warning from png_check_IHDR(). + +Version 1.6.9beta04 [January 20, 2014] + Updated scripts/makefile.* to use CPPFLAGS (Cosmin). + Added clang attribute support (Cosmin). + +Version 1.6.9rc01 [January 28, 2014] + No changes. + +Version 1.6.9rc02 [January 30, 2014] + Quiet an uninitialized memory warning from VC2013 in png_get_png(). + +Version 1.6.9 [February 6, 2014] + +Version 1.6.10beta01 [February 9, 2014] + Backported changes from libpng-1.7.0beta30 and beta31: + Fixed a large number of instances where PNGCBAPI was omitted from + function definitions. + Added pngimage test program for png_read_png() and png_write_png() + with two new test scripts. + Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling + png_set_packing() in png_read_png(). + Fixed combination of ~alpha with shift. On read invert alpha, processing + occurred after shift processing, which causes the final values to be + outside the range that should be produced by the shift. Reversing the + order on read makes the two transforms work together correctly and mirrors + the order used on write. + Do not read invalid sBIT chunks. Previously libpng only checked sBIT + values on write, so a malicious PNG writer could therefore cause + the read code to return an invalid sBIT chunk, which might lead to + application errors or crashes. Such chunks are now skipped (with + chunk_benign_error). + Make png_read_png() and png_write_png() prototypes in png.h depend + upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED. + Support builds with unsupported PNG_TRANSFORM_* values. All of the + PNG_TRANSFORM_* values are always defined in png.h and, because they + are used for both read and write in some cases, it is not reliable + to #if out ones that are totally unsupported. This change adds error + detection in png_read_image() and png_write_image() to do a + png_app_error() if the app requests something that cannot be done + and it adds corresponding code to pngimage.c to handle such options + by not attempting to test them. + +Version 1.6.10beta02 [February 23, 2014] + Moved redefines of png_error(), png_warning(), png_chunk_error(), + and png_chunk_warning() from pngpriv.h to png.h to make them visible + to libpng-calling applications. + Moved OS dependent code from arm/arm_init.c, to allow the included + implementation of the ARM NEON discovery function to be set at + build-time and provide sample implementations from the current code in the + contrib/arm-neon subdirectory. The __linux__ code has also been changed to + compile and link on Android by using /proc/cpuinfo, and the old linux code + is in contrib/arm-neon/linux-auxv.c. The new code avoids POSIX and Linux + dependencies apart from opening /proc/cpuinfo and is C90 compliant. + Check for info_ptr == NULL early in png_read_end() so we don't need to + run all the png_handle_*() and depend on them to return if info_ptr == NULL. + This improves the performance of png_read_end(png_ptr, NULL) and makes + it more robust against future programming errors. + Check for __has_extension before using it in pngconf.h, to + support older Clang versions (Jeremy Sequoia). + Treat CRC error handling with png_set_crc_action(), instead of with + png_set_benign_errors(), which has been the case since libpng-1.6.0beta18. + Use a user warning handler in contrib/gregbook/readpng2.c instead of default, + so warnings will be put on stderr even if libpng has CONSOLE_IO disabled. + Added png_ptr->process_mode = PNG_READ_IDAT_MODE in png_push_read_chunk + after recognizing the IDAT chunk, which avoids an infinite loop while + reading a datastream whose first IDAT chunk is of zero-length. + This fixes CERT VU#684412 and CVE-2014-0333. + Don't recognize known sRGB profiles as sRGB if they have been hacked, + but don't reject them and don't issue a copyright violation warning. + +Version 1.6.10beta03 [February 25, 2014] + Moved some documentation from png.h to libpng.3 and libpng-manual.txt + Minor editing of contrib/arm-neon/README and contrib/examples/*.c + +Version 1.6.10rc01 [February 27, 2014] + Fixed typos in the manual and in scripts/pnglibconf.dfa (CFLAGS -> CPPFLAGS + and PNG_USR_CONFIG -> PNG_USER_CONFIG). + +Version 1.6.10rc02 [February 28, 2014] + Removed unreachable return statement after png_chunk_error() + in pngrutil.c + +Version 1.6.10rc03 [March 4, 2014] + Un-deprecated png_data_freer(). + +Version 1.6.10 [March 6, 2014] + No changes. + +Version 1.6.11beta01 [March 17, 2014] + Use "if (value != 0)" instead of "if (value)" consistently. + Changed ZlibSrcDir from 1.2.5 to 1.2.8 in projects/vstudio. + Moved configuration information from the manual to the INSTALL file. + +Version 1.6.11beta02 [April 6, 2014] + Removed #if/#else/#endif from inside two pow() calls in pngvalid.c because + they were handled improperly by Portland Group's PGI-14.1 - PGI-14.3 + when using its "__builtin_pow()" function. + Silence 'unused parameter' build warnings (Cosmin Truta). + $(CP) is now used alongside $(RM_F). Also, use 'copy' instead of 'cp' + where applicable, and applied other minor makefile changes (Cosmin). + Don't warn about invalid dimensions exceeding user limits (Cosmin). + Allow an easy replacement of the default pre-built configuration + header with a custom header, via the make PNGLIBCONF_H_PREBUILT + macro (Cosmin). + +Version 1.6.11beta03 [April 6, 2014] + Fixed a typo in pngrutil.c, introduced in libpng-1.5.6, that interferes + with "blocky" expansion of sub-8-bit interlaced PNG files (Eric Huss). + Optionally use __builtin_bswap16() in png_do_swap(). + +Version 1.6.11beta04 [April 19, 2014] + Made progressive reading of interlaced images consistent with the + behavior of the sequential reader and consistent with the manual, by + moving some code out of the PNG_READ_INTERLACING_SUPPORTED blocks. The + row_callback now receives the proper pass number and unexpanded rows, when + png_combine_row() isn't built or used, and png_set_interlace_handling() + is not called. + Allow PNG_sRGB_PROFILE_CHECKING = (-1) to mean no sRGB profile checking. + +Version 1.6.11beta05 [April 26, 2014] + Do not reject ICC V2 profiles that lack padding (Kai-Uwe Behrmann). + Relocated closing bracket of the sRGB profile test loop to avoid getting + "Not recognizing known sRGB profile that has been edited" warning for + ICC V2 profiles that lack the MD5 signature in the profile header. + +Version 1.6.11beta06 [May 19, 2014] + Added PNG_SKIP_sRGB_CHECK_PROFILE choice for png_set_option(). + +Version 1.6.11rc01 [May 27, 2014] + No changes. + +Version 1.6.11rc02 [June 3, 2014] + Test ZLIB_VERNUM instead of PNG_ZLIB_VERNUM in contrib/tools/pngfix.c + +Version 1.6.11 [June 5, 2014] + No changes. + +Version 1.6.12rc01 [June 6, 2014] + Relocated new code from 1.6.11beta06 in png.c to a point after the + declarations (Max Stepin). + +Version 1.6.12rc02 [June 7, 2014] + Changed file permissions of contrib/tools/intgamma.sh, + test-driver, and compile from 0644 to 0755 (Cosmin). + +Version 1.6.12rc03 [June 8, 2014] + Ensure "__has_attribute()" macro exists before trying to use it with + old clang compilers (MacPorts Ticket #43939). + +Version 1.6.12 [June 12, 2014] + No changes. + +Version 1.6.13beta01 [July 4, 2014] + Quieted -Wsign-compare and -Wclobber compiler warnings in + contrib/pngminus/*.c + Added "(void) png_ptr;" where needed in contrib/gregbook to quiet + compiler complaints about unused pointers. + Split a long output string in contrib/gregbook/rpng2-x.c. + Added "PNG_SET_OPTION" requirement for sRGB chunk support to pnglibconf.dfa, + Needed for write-only support (John Bowler). + Changed "if defined(__ARM_NEON__)" to + "if (defined(__ARM_NEON__) || defined(__ARM_NEON))" (James Wu). + Fixed clang no-warning builds: png_digit was defined but never used. + +Version 1.6.13beta02 [July 21, 2014] + Fixed an incorrect separator ("/" should be "\") in scripts/makefile.vcwin32 + (bug report from Wolfgang S. Kechel). Bug was introduced in libpng-1.6.11. + Also fixed makefile.bc32, makefile.bor, makefile.msc, makefile.intel, and + makefile.tc3 similarly. + +Version 1.6.13beta03 [August 3, 2014] + Removed scripts/makefile.elf. It has not worked since libpng-1.5.0beta14 + due to elimination of the PNG_FUNCTION_EXPORT and PNG_DATA_EXPORT + definitions from pngconf.h. + Ensure that CMakeLists.txt makes the target "lib" directory before making + symbolic link into it (SourceForge bug report #226 by Rolf Timmermans). + +Version 1.6.13beta04 [August 8, 2014] + Added opinion that the ECCN (Export Control Classification Number) for + libpng is EAR99 to the README file. + Eliminated use of "$<" in makefile explicit rules, when copying + $PNGLIBCONF_H_PREBUILT. This does not work on some versions of make; + bug introduced in libpng version 1.6.11. + +Version 1.6.13rc01 [August 14, 2014] + Made "ccopts" agree with "CFLAGS" in scripts/makefile.hp* and makefile.*sunu + +Version 1.6.13 [August 21, 2014] + No changes. + +Version 1.6.14beta01 [September 14, 2014] + Guard usage of png_ptr->options with #ifdef PNG_SET_OPTION_SUPPORTED. + Do not build contrib/tools/pngfix.c when PNG_SETJMP_NOT_SUPPORTED, + to allow "make" to complete without setjmp support (bug report by + Claudio Fontana) + Add "#include " to contrib/tools/pngfix.c (John Bowler) + +Version 1.6.14beta02 [September 18, 2014] + Use nanosleep() instead of usleep() in contrib/gregbook/rpng2-x.c + because usleep() is deprecated. + Define usleep() in contrib/gregbook/rpng2-x.c if not already defined + in unistd.h and nanosleep() is not available; fixes error introduced + in libpng-1.6.13. + Disable floating point exception handling in pngvalid.c when + PNG_FLOATING_ARITHMETIC is not supported (bug report by "zootus + at users.sourceforge.net"). + +Version 1.6.14beta03 [September 19, 2014] + Define FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in pngvalid.c if not + already defined. Revert floating point exception handling in pngvalid.c + to version 1.6.14beta01 behavior. + +Version 1.6.14beta04 [September 27, 2014] + Fixed incorrect handling of the iTXt compression flag in pngrutil.c + (bug report by Shunsaku Hirata). Bug was introduced in libpng-1.6.0. + +Version 1.6.14beta05 [October 1, 2014] + Added "option READ_iCCP enables READ_COMPRESSED_TEXT" to pnglibconf.dfa + +Version 1.6.14beta06 [October 5, 2014] + Removed unused "text_len" parameter from private function png_write_zTXt(). + Conditionally compile some code in png_deflate_claim(), when + PNG_WARNINGS_SUPPORTED and PNG_ERROR_TEXT_SUPPORTED are disabled. + Replaced repeated code in pngpread.c with PNG_PUSH_SAVE_BUFFER_IF_FULL. + Added "chunk iTXt enables TEXT" and "chunk zTXt enables TEXT" + to pnglibconf.dfa. + Removed "option READ_COMPRESSED_TEXT enables READ_TEXT" from pnglibconf.dfa, + to make it possible to configure a libpng that supports iCCP but not TEXT. + +Version 1.6.14beta07 [October 7, 2014] + Removed "option WRITE_COMPRESSED_TEXT enables WRITE_TEXT" from pnglibconf.dfa + Only mark text chunks as written after successfully writing them. + +Version 1.6.14rc01 [October 15, 2014] + Fixed some typos in comments. + +Version 1.6.14rc02 [October 17, 2014] + Changed png_convert_to_rfc_1123() to png_convert_to_rfc_1123_buffer() + in the manual, to reflect the change made in libpng-1.6.0. + Updated README file to explain that direct access to the png_struct + and info_struct members has not been permitted since libpng-1.5.0. + +Version 1.6.14 [October 23, 2014] + No changes. + +Version 1.6.15beta01 [October 29, 2014] + Changed "if (!x)" to "if (x == 0)" and "if (x)" to "if (x != 0)" + Simplified png_free_data(). + Added missing "ptr = NULL" after some instances of png_free(). + +Version 1.6.15beta02 [November 1, 2014] + Changed remaining "if (!x)" to "if (x == 0)" and "if (x)" to "if (x != 0)" + +Version 1.6.15beta03 [November 3, 2014] + Added PNG_USE_ARM_NEON configuration flag (Marcin Juszkiewicz). + +Version 1.6.15beta04 [November 4, 2014] + Removed new PNG_USE_ARM_NEON configuration flag and made a one-line + revision to configure.ac to support ARM on aarch64 instead (John Bowler). + +Version 1.6.15beta05 [November 5, 2014] + Use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING in + example.c, pngtest.c, and applications in the contrib directory. + Avoid out-of-bounds memory access in png_user_version_check(). + Simplified and future-proofed png_user_version_check(). + Fixed GCC unsigned int->float warnings. Various versions of GCC + seem to generate warnings when an unsigned value is implicitly + converted to double. This is probably a GCC bug but this change + avoids the issue by explicitly converting to (int) where safe. + Free all allocated memory in pngimage. The file buffer cache was left + allocated at the end of the program, harmless but it causes memory + leak reports from clang. + Fixed array size calculations to avoid warnings. At various points + in the code the number of elements in an array is calculated using + sizeof. This generates a compile time constant of type (size_t) which + is then typically assigned to an (unsigned int) or (int). Some versions + of GCC on 64-bit systems warn about the apparent narrowing, even though + the same compiler does apparently generate the correct, in-range, + numeric constant. This adds appropriate, safe, casts to make the + warnings go away. + +Version 1.6.15beta06 [November 6, 2014] + Reverted use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING + in the manual, example.c, pngtest.c, and applications in the contrib + directory. It was incorrect advice. + +Version 1.6.15beta07 [November 7, 2014] + Removed #ifdef PNG_16BIT_SUPPORTED/#endif around png_product2(); it is + needed by png_reciprocal2(). + Added #ifdef PNG_16BIT_SUPPORTED/#endif around png_log16bit() and + png_do_swap(). + Changed all "#endif /* PNG_FEATURE_SUPPORTED */" to "#endif /* FEATURE */" + +Version 1.6.15beta08 [November 8, 2014] + More housecleaning in *.h + +Version 1.6.15rc01 [November 13, 2014] + +Version 1.6.15rc02 [November 14, 2014] + The macros passed in the command line to Borland make were ignored if + similarly-named macros were already defined in makefiles. This behavior + is different from POSIX make and other make programs. Surround the + macro definitions with ifndef guards (Cosmin). + +Version 1.6.15rc03 [November 16, 2014] + Added "-D_CRT_SECURE_NO_WARNINGS" to CFLAGS in scripts/makefile.vcwin32. + Removed the obsolete $ARCH variable from scripts/makefile.darwin. + +Version 1.6.15 [November 20, 2014] + No changes. + +Version 1.6.16beta01 [December 14, 2014] + Added ".align 2" to arm/filter_neon.S to support old GAS assemblers that + don't do alignment correctly. + Revised Makefile.am and scripts/symbols.dfn to work with MinGW/MSYS + (Bob Friesenhahn). + +Version 1.6.16beta02 [December 15, 2014] + Revised Makefile.am and scripts/*.dfn again to work with MinGW/MSYS; + renamed scripts/*.dfn to scripts/*.c (John Bowler). + +Version 1.6.16beta03 [December 21, 2014] + Quiet a "comparison always true" warning in pngstest.c (John Bowler). + +Version 1.6.16rc01 [December 21, 2014] + Restored a test on width that was removed from png.c at libpng-1.6.9 + (Bug report by Alex Eubanks, CVE-2015-0973). + +Version 1.6.16rc02 [December 21, 2014] + Undid the update to pngrutil.c in 1.6.16rc01. + +Version 1.6.16rc03 [December 21, 2014] + Fixed an overflow in png_combine_row() with very wide interlaced images + (Bug report and fix by John Bowler, CVE-2014-9495). + +Version 1.6.16 [December 22, 2014] + No changes. + +Version 1.6.17beta01 [January 29, 2015] + Removed duplicate PNG_SAFE_LIMITS_SUPPORTED handling from pngconf.h + Corrected the width limit calculation in png_check_IHDR(). + Removed user limits from pngfix. Also pass NULL pointers to + png_read_row to skip the unnecessary row de-interlace stuff. + Added testing of png_set_packing() to pngvalid.c + Regenerated configure scripts in the *.tar distributions with libtool-2.4.4 + Implement previously untested cases of libpng transforms in pngvalid.c + Fixed byte order in png_do_read_filler() with 16-bit input. Previously + the high and low bytes of the filler, from png_set_filler() or from + png_set_add_alpha(), were read in the wrong order. + Made the check for out-of-range values in png_set_tRNS() detect + values that are exactly 2^bit_depth, and work on 16-bit platforms. + Merged some parts of libpng-1.6.17beta01 and libpng-1.7.0beta47. + Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and + pngset.c to avoid warnings about dead code. + Added "& 0xff" to many instances of expressions that are typecast + to (png_byte), to avoid Coverity warnings. + +Version 1.6.17beta02 [February 7, 2015] + Work around one more Coverity-scan dead-code warning. + Do not build png_product2() when it is unused. + +Version 1.6.17beta03 [February 17, 2015] + Display user limits in the output from pngtest. + Eliminated the PNG_SAFE_LIMITS macro and restored the 1-million-column + and 1-million-row default limits in pnglibconf.dfa, that can be reset + by the user at build time or run time. This provides a more robust + defense against DOS and as-yet undiscovered overflows. + +Version 1.6.17beta04 [February 21, 2015] + Added PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED macro, on by default. + Allow user to call png_get_IHDR() with NULL arguments (Reuben Hawkins). + Rebuilt configure scripts with automake-1.15 and libtool-2.4.6 + +Version 1.6.17beta05 [February 25, 2015] + Restored compiling of png_reciprocal2 with PNG_NO_16BIT. + +Version 1.6.17beta06 [February 27, 2015] + Moved png_set_filter() prototype into a PNG_WRITE_SUPPORTED block + of png.h. + Avoid runtime checks when converting integer to png_byte with + Visual Studio (Sergey Kosarevsky) + +Version 1.6.17rc01 [March 4, 2015] + No changes. + +Version 1.6.17rc02 [March 9, 2015] + Removed some comments that the configure script did not handle + properly from scripts/pnglibconf.dfa and pnglibconf.h.prebuilt. + Free the unknown_chunks structure even when it contains no data. + +Version 1.6.17rc03 [March 12, 2015] + Updated CMakeLists.txt to add OSX framework, change YES/NO to ON/OFF + for consistency, and remove some useless tests (Alexey Petruchik). + +Version 1.6.17rc04 [March 16, 2015] + Remove pnglibconf.h, pnglibconf.c, and pnglibconf.out instead of + pnglibconf.* in "make clean" (Cosmin). + Fix bug in calculation of maxbits, in png_write_sBIT, introduced + in libpng-1.6.17beta01 (John Bowler). + +Version 1.6.17rc05 [March 21, 2015] + Define PNG_FILTER_* and PNG_FILTER_VALUE_* in png.h even when WRITE + is not supported (John Bowler). This fixes an error introduced in + libpng-1.6.17beta06. + Reverted "& 0xff" additions of version 1.6.17beta01. Libpng passes + the Coverity scan without them. + +Version 1.6.17rc06 [March 23, 2015] + Remove pnglibconf.dfn and pnglibconf.pre with "make clean". + Reformatted some "&0xff" instances to "& 0xff". + Fixed simplified 8-bit-linear to sRGB alpha. The calculated alpha + value was wrong. It's not clear if this affected the final stored + value; in the obvious code path the upper and lower 8-bits of the + alpha value were identical and the alpha was truncated to 8-bits + rather than dividing by 257 (John Bowler). + +Version 1.6.17 [March 26, 2015] + No changes. + +Version 1.6.18beta01 [April 1, 2015] + Removed PNG_SET_CHUNK_[CACHE|MALLOC]_LIMIT_SUPPORTED macros. They + have been combined with PNG_SET_USER_LIMITS_SUPPORTED (resolves + bug report by Andrew Church). + Fixed rgb_to_gray checks and added tRNS checks to pngvalid.c. This + fixes some arithmetic errors that caused some tests to fail on + some 32-bit platforms (Bug reports by Peter Breitenlohner [i686] + and Petr Gajdos [i586]). + +Version 1.6.18beta02 [April 26, 2015] + Suppressed some warnings from the Borland C++ 5.5.1/5.82 compiler + (Bug report by Viktor Szakats). + +Version 1.6.18beta03 [May 6, 2015] + Replaced "unexpected" with an integer (0xabadca11) in pngset.c + where a long was expected, to avoid a compiler warning when PNG_DEBUG > 1. + Added contrib/examples/simpleover.c, to demonstrate how to handle + alpha compositing of multiple images, using the "simplified API" + and an example PNG generation tool, contrib/examples/genpng.c + (John Bowler). + +Version 1.6.18beta04 [May 20, 2015] + PNG_RELEASE_BUILD replaces tests where the code depended on the build base + type and can be defined on the command line, allowing testing in beta + builds (John Bowler). + Avoid Coverity issue 80858 (REVERSE NULL) in pngtest.c PNG_DEBUG builds. + Avoid a harmless potential integer overflow in png_XYZ_from_xy() (Bug + report from Christopher Ferris). + +Version 1.6.18beta05 [May 31, 2015] + Backport filter selection code from libpng-1.7.0beta51, to combine + sub_row, up_row, avg_row, and paeth_row into try_row and tst_row. + Changed png_voidcast(), etc., to voidcast(), etc., in contrib/tools/pngfix.c + to avoid confusion with the libpng private macros. + Fixed old cut&paste bug in the weighted filter selection code in + pngwutil.c, introduced in libpng-0.95, March 1997. + +Version 1.6.18beta06 [June 1, 2015] + Removed WRITE_WEIGHTED_FILTERED code, to save a few kbytes of the + compiled library size. It never worked properly and as far as we can + tell, no one uses it. The png_set_filter_heuristics() and + png_set_filter_heuristics_fixed() APIs are retained but deprecated + and do nothing. + +Version 1.6.18beta07 [June 6, 2015] + Removed non-working progressive reader 'skip' function. This + function has apparently never been used. It was implemented + to support back-door modification of png_struct in libpng-1.4.x + but (because it does nothing and cannot do anything) was apparently + never tested (John Bowler). + Fixed cexcept.h in which GCC 5 now reports that one of the auto + variables in the Try macro needs to be volatile to prevent value + being lost over the setjmp (John Bowler). + Fixed NO_WRITE_FILTER and -Wconversion build breaks (John Bowler). + Fix g++ build breaks (John Bowler). + Quieted some Coverity issues in pngfix.c, png-fix-itxt.c, pngvalid.c, + pngstest.c, and pngimage.c. Most seem harmless, but png-fix-itxt + would only work with iTXt chunks with length 255 or less. + Added #ifdef's to contrib/examples programs so people don't try + to compile them without the minimum required support enabled + (suggested by Flavio Medeiros). + +Version 1.6.18beta08 [June 30, 2015] + Eliminated the final two Coverity defects (insecure temporary file + handling in contrib/libtests/pngstest.c; possible overflow of + unsigned char in contrib/tools/png-fix-itxt.c). To use the "secure" + file handling, define PNG_USE_MKSTEMP, otherwise "tmpfile()" will + be used. + Removed some unused WEIGHTED_FILTER macros from png.h and pngstruct.h + +Version 1.6.18beta09 [July 5, 2015] + Removed some useless typecasts from contrib/tools/png-fix-itxt.c + Fixed a new signed-unsigned comparison in pngrtran.c (Max Stepin). + Replaced arbitrary use of 'extern' with #define PNG_LINKAGE_*. To + preserve API compatibility, the new defines all default to "extern" + (requested by Jan Nijtmans). + +Version 1.6.18rc01 [July 9, 2015] + Belatedly added Mans Rullgard and James Yu to the list of Contributing + Authors. + +Version 1.6.18rc02 [July 12, 2015] + Restored unused FILTER_HEURISTIC macros removed at libpng-1.6.18beta08 + to png.h to avoid compatibility warnings. + +Version 1.6.18rc03 [July 15, 2015] + Minor changes to the man page + +Version 1.6.18 [July 23, 2015] + No changes. + +Version 1.6.19beta01 [July 30, 2015] + Updated obsolete information about the simplified API macros in the + manual pages (Bug report by Arc Riley). + Avoid potentially dereferencing NULL info_ptr in png_info_init_3(). + Rearranged png.h to put the major sections in the same order as + in libpng17. + Eliminated unused PNG_COST_SHIFT, PNG_WEIGHT_SHIFT, PNG_COST_FACTOR, and + PNG_WEIGHT_FACTOR macros. + Suppressed some warnings from the Borland C++ 5.5.1/5.82 compiler + (Bug report by Viktor Szakats). Several warnings remain and are + unavoidable, where we test for overflow. + Fixed potential leak of png_pixels in contrib/pngminus/pnm2png.c + Fixed uninitialized variable in contrib/gregbook/rpng2-x.c + +Version 1.6.19beta02 [August 19, 2015] + Moved config.h.in~ from the "libpng_autotools_files" list to the + "libpng_autotools_extra" list in autogen.sh because it was causing a + false positive for missing files (bug report by Robert C. Seacord). + Removed unreachable "break" statements in png.c, pngread.c, and pngrtran.c + to suppress clang warnings (Bug report by Viktor Szakats). + Fixed some bad links in the man page. + Changed "n bit" to "n-bit" in comments. + Added signed/unsigned 16-bit safety net. This removes the dubious + 0x8000 flag definitions on 16-bit systems. They aren't supported + yet the defs *probably* work, however it seems much safer to do this + and be advised if anyone, contrary to advice, is building libpng 1.6 + on a 16-bit system. It also adds back various switch default clauses + for GCC; GCC errors out if they are not present (with an appropriately + high level of warnings). + Safely convert num_bytes to a png_byte in png_set_sig_bytes() (Robert + Seacord). + Fixed the recently reported 1's complement security issue by replacing + the value that is illegal in the PNG spec, in both signed and unsigned + values, with 0. Illegal unsigned values (anything greater than or equal + to 0x80000000) can still pass through, but since these are not illegal + in ANSI-C (unlike 0x80000000 in the signed case) the checking that + occurs later can catch them (John Bowler). + +Version 1.6.19beta03 [September 26, 2015] + Fixed png_save_int_32 when int is not 2's complement (John Bowler). + Updated libpng16 with all the recent test changes from libpng17, + including changes to pngvalid.c to ensure that the original, + distributed, version of contrib/visupng/cexcept.h can be used + (John Bowler). + pngvalid contains the correction to the use of SAVE/STORE_ + UNKNOWN_CHUNKS; a bug revealed by changes in libpng 1.7. More + tests contain the --strict option to detect warnings and the + pngvalid-standard test has been corrected so that it does not + turn on progressive-read. There is a separate test which does + that. (John Bowler) + Also made some signed/unsigned fixes. + Make pngstest error limits version specific. Splitting the machine + generated error structs out to a file allows the values to be updated + without changing pngstest.c itself. Since libpng 1.6 and 1.7 have + slightly different error limits this simplifies maintenance. The + makepngs.sh script has also been updated to more accurately reflect + current problems in libpng 1.7 (John Bowler). + Incorporated new test PNG files into make check. tests/pngstest-* + are changed so that the new test files are divided into 8 groups by + gamma and alpha channel. These tests have considerably better code + and pixel-value coverage than contrib/pngsuite; however,coverage is + still incomplete (John Bowler). + Removed the '--strict' in 1.6 because of the double-gamma-correction + warning, updated pngstest-errors.h for the errors detected with the + new contrib/testspngs PNG test files (John Bowler). + +Version 1.6.19beta04 [October 15, 2015] + Worked around rgb-to-gray issues in libpng 1.6. The previous + attempts to ignore the errors in the code aren't quite enough to + deal with the 'channel selection' encoding added to libpng 1.7; abort. + pngvalid.c is changed to drop this encoding in prior versions. + Fixed 'pow' macros in pngvalid.c. It is legal for 'pow' to be a + macro, therefore the argument list cannot contain preprocessing + directives. Make sure pow is a function where this happens. This is + a minimal safe fix, the issue only arises in non-performance-critical + code (bug report by Curtis Leach, fix by John Bowler). + Added sPLT support to pngtest.c + +Version 1.6.19rc01 [October 23, 2015] + No changes. + +Version 1.6.19rc02 [October 31, 2015] + Prevent setting or writing over-length PLTE chunk (Cosmin Truta). + Silently truncate over-length PLTE chunk while reading. + Libpng incorrectly calculated the output rowbytes when the application + decreased either the number of channels or the bit depth (or both) in + a user transform. This was safe; libpng overallocated buffer space + (potentially by quite a lot; up to 4 times the amount required) but, + from 1.5.4 on, resulted in a png_error (John Bowler). + +Version 1.6.19rc03 [November 3, 2015] + Fixed some inconsequential cut-and-paste typos in png_set_cHRM_XYZ_fixed(). + Clarified COPYRIGHT information to state explicitly that versions + are derived from previous versions. + Removed much of the long list of previous versions from png.h and + libpng.3. + +Version 1.6.19rc04 [November 5, 2015] + Fixed new bug with CRC error after reading an over-length palette + (bug report by Cosmin Truta). + +Version 1.6.19 [November 12, 2015] + Cleaned up coding style in png_handle_PLTE(). + +Send comments/corrections/commendations to png-mng-implement at lists.sf.net +(subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe) +or to glennrp at users.sourceforge.net + +Glenn R-P +#endif diff --git a/extern/libpng/CMakeLists.txt b/extern/libpng/CMakeLists.txt new file mode 100644 index 000000000..d3ba5e867 --- /dev/null +++ b/extern/libpng/CMakeLists.txt @@ -0,0 +1,53 @@ +if(NOT WIN32 AND NOT APPLE AND NOT NX) # remove WIN32 when specter/freetype is gone +find_library(PNG_LIB NAMES png libpng) +endif() +if(NOT PNG_LIB) +message(STATUS "Using HECL's built-in libpng") +if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm(64)?") +set(INTRINSICS + arm/arm_init.c + arm/filter_neon.S + arm/filter_neon_intrinsics.c + arm/palette_neon_intrinsics.c) +elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL x86_64) +set(INTRINSICS + intel/filter_sse2_intrinsics.c + intel/intel_init.c) +endif() +add_library(png + png.h + pngconf.h + pngdebug.h + pnginfo.h + pngpriv.h + pngstruct.h + pnglibconf.h + + png.c + pngerror.c + pngget.c + pngmem.c + pngpread.c + pngread.c + pngrio.c + pngrtran.c + pngrutil.c + pngset.c + pngtrans.c + pngwio.c + pngwrite.c + pngwtran.c + pngwutil.c + ${INTRINSICS}) +if(APPLE) + target_compile_options(png PRIVATE -Wno-implicit-fallthrough) +endif() +target_link_libraries(png PUBLIC ${ZLIB_LIBRARIES}) +target_include_directories(png PUBLIC ${ZLIB_INCLUDE_DIR}) +set(PNG_LIBRARIES png CACHE PATH "PNG libraries" FORCE) +set(PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "PNG include path" FORCE) +else() +set(PNG_LIBRARIES ${PNG_LIB} CACHE PATH "PNG libraries" FORCE) +find_path(PNG_INCLUDE_DIR png.h) +set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIR} CACHE PATH "PNG include path" FORCE) +endif() diff --git a/extern/libpng/README b/extern/libpng/README new file mode 100644 index 000000000..cfc1f0e3d --- /dev/null +++ b/extern/libpng/README @@ -0,0 +1,183 @@ +README for libpng version 1.6.37 - April 14, 2019 +================================================= + +See the note about version numbers near the top of png.h. +See INSTALL for instructions on how to install libpng. + +Libpng comes in several distribution formats. Get libpng-*.tar.gz or +libpng-*.tar.xz or if you want UNIX-style line endings in the text +files, or lpng*.7z or lpng*.zip if you want DOS-style line endings. + +Version 0.89 was the first official release of libpng. Don't let the +fact that it's the first release fool you. The libpng library has been +in extensive use and testing since mid-1995. By late 1997 it had +finally gotten to the stage where there hadn't been significant +changes to the API in some time, and people have a bad feeling about +libraries with versions < 1.0. Version 1.0.0 was released in +March 1998. + +**** +Note that some of the changes to the png_info structure render this +version of the library binary incompatible with libpng-0.89 or +earlier versions if you are using a shared library. The type of the +"filler" parameter for png_set_filler() has changed from png_byte to +png_uint_32, which will affect shared-library applications that use +this function. + +To avoid problems with changes to the internals of the png info_struct, +new APIs have been made available in 0.95 to avoid direct application +access to info_ptr. These functions are the png_set_ and +png_get_ functions. These functions should be used when +accessing/storing the info_struct data, rather than manipulating it +directly, to avoid such problems in the future. + +It is important to note that the APIs did not make current programs +that access the info struct directly incompatible with the new +library, through libpng-1.2.x. In libpng-1.4.x, which was meant to +be a transitional release, members of the png_struct and the +info_struct can still be accessed, but the compiler will issue a +warning about deprecated usage. Since libpng-1.5.0, direct access +to these structs is not allowed, and the definitions of the structs +reside in private pngstruct.h and pnginfo.h header files that are not +accessible to applications. It is strongly suggested that new +programs use the new APIs (as shown in example.c and pngtest.c), and +older programs be converted to the new format, to facilitate upgrades +in the future. +**** + +Additions since 0.90 include the ability to compile libpng as a +Windows DLL, and new APIs for accessing data in the info struct. +Experimental functions include the ability to set weighting and cost +factors for row filter selection, direct reads of integers from buffers +on big-endian processors that support misaligned data access, faster +methods of doing alpha composition, and more accurate 16->8 bit color +conversion. + +The additions since 0.89 include the ability to read from a PNG stream +which has had some (or all) of the signature bytes read by the calling +application. This also allows the reading of embedded PNG streams that +do not have the PNG file signature. As well, it is now possible to set +the library action on the detection of chunk CRC errors. It is possible +to set different actions based on whether the CRC error occurred in a +critical or an ancillary chunk. + +For a detailed description on using libpng, read libpng-manual.txt. +For examples of libpng in a program, see example.c and pngtest.c. For +usage information and restrictions (what little they are) on libpng, +see png.h. For a description on using zlib (the compression library +used by libpng) and zlib's restrictions, see zlib.h + +I have included a general makefile, as well as several machine and +compiler specific ones, but you may have to modify one for your own +needs. + +You should use zlib 1.0.4 or later to run this, but it MAY work with +versions as old as zlib 0.95. Even so, there are bugs in older zlib +versions which can cause the output of invalid compression streams for +some images. + +You should also note that zlib is a compression library that is useful +for more things than just PNG files. You can use zlib as a drop-in +replacement for fread() and fwrite(), if you are so inclined. + +zlib should be available at the same place that libpng is, or at +https://zlib.net. + +You may also want a copy of the PNG specification. It is available +as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find +these at http://www.libpng.org/pub/png/pngdocs.html . + +This code is currently being archived at libpng.sourceforge.io in the +[DOWNLOAD] area, and at http://libpng.download/src . + +This release, based in a large way on Glenn's, Guy's and Andreas' +earlier work, was created and will be supported by myself and the PNG +development group. + +Send comments/corrections/commendations to png-mng-implement at +lists.sourceforge.net (subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe). + +Send general questions about the PNG specification to png-mng-misc +at lists.sourceforge.net (subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-misc to +subscribe). + +Files in this distribution: + + ANNOUNCE => Announcement of this version, with recent changes + AUTHORS => List of contributing authors + CHANGES => Description of changes between libpng versions + KNOWNBUG => List of known bugs and deficiencies + LICENSE => License to use and redistribute libpng + README => This file + TODO => Things not implemented in the current library + TRADEMARK => Trademark information + example.c => Example code for using libpng functions + libpng.3 => manual page for libpng (includes libpng-manual.txt) + libpng-manual.txt => Description of libpng and its functions + libpngpf.3 => manual page for libpng's private functions + png.5 => manual page for the PNG format + png.c => Basic interface functions common to library + png.h => Library function and interface declarations (public) + pngpriv.h => Library function and interface declarations (private) + pngconf.h => System specific library configuration (public) + pngstruct.h => png_struct declaration (private) + pnginfo.h => png_info struct declaration (private) + pngdebug.h => debugging macros (private) + pngerror.c => Error/warning message I/O functions + pngget.c => Functions for retrieving info from struct + pngmem.c => Memory handling functions + pngbar.png => PNG logo, 88x31 + pngnow.png => PNG logo, 98x31 + pngpread.c => Progressive reading functions + pngread.c => Read data/helper high-level functions + pngrio.c => Lowest-level data read I/O functions + pngrtran.c => Read data transformation functions + pngrutil.c => Read data utility functions + pngset.c => Functions for storing data into the info_struct + pngtest.c => Library test program + pngtest.png => Library test sample image + pngtrans.c => Common data transformation functions + pngwio.c => Lowest-level write I/O functions + pngwrite.c => High-level write functions + pngwtran.c => Write data transformations + pngwutil.c => Write utility functions + arm => Contains optimized code for the ARM platform + powerpc => Contains optimized code for the PowerPC platform + contrib => Contributions + arm-neon => Optimized code for ARM-NEON platform + powerpc-vsx => Optimized code for POWERPC-VSX platform + examples => Example programs + gregbook => source code for PNG reading and writing, from + Greg Roelofs' "PNG: The Definitive Guide", + O'Reilly, 1999 + libtests => Test programs + mips-msa => Optimized code for MIPS-MSA platform + pngminim => Minimal decoder, encoder, and progressive decoder + programs demonstrating use of pngusr.dfa + pngminus => Simple pnm2png and png2pnm programs + pngsuite => Test images + testpngs + tools => Various tools + visupng => Contains a MSVC workspace for VisualPng + intel => Optimized code for INTEL-SSE2 platform + mips => Optimized code for MIPS platform + projects => Contains project files and workspaces for + building a DLL + owatcom => Contains a WATCOM project for building libpng + visualc71 => Contains a Microsoft Visual C++ (MSVC) + workspace for building libpng and zlib + vstudio => Contains a Microsoft Visual C++ (MSVC) + workspace for building libpng and zlib + scripts => Directory containing scripts for building libpng: + (see scripts/README.txt for the list of scripts) + +Good luck, and happy coding! + + * Cosmin Truta (current maintainer, since 2018) + * Glenn Randers-Pehrson (former maintainer, 1998-2018) + * Andreas Eric Dilger (former maintainer, 1996-1997) + * Guy Eric Schalnat (original author and former maintainer, 1995-1996) + (formerly of Group 42, Inc.) diff --git a/extern/libpng/TODO b/extern/libpng/TODO new file mode 100644 index 000000000..72633774f --- /dev/null +++ b/extern/libpng/TODO @@ -0,0 +1,29 @@ +/* +TODO - list of things to do for libpng: + +Final bug fixes. +Better C++ wrapper/full C++ implementation? +Fix problem with C++ and EXTERN "C". +cHRM transformation. +Remove setjmp/longjmp usage in favor of returning error codes. +Palette creation. +Add "grayscale->palette" transformation and "palette->grayscale" detection. +Improved dithering. +Multi-lingual error and warning message support. +Complete sRGB transformation (presently it simply uses gamma=0.45455). +Make profile checking optional via a png_set_something() call. +Man pages for function calls. +Better documentation. +Better filter selection + (counting huffman bits/precompression? filter inertia? filter costs?). +Histogram creation. +Text conversion between different code pages (Latin-1 -> Mac and DOS). +Avoid building gamma tables whenever possible. +Use greater precision when changing to linear gamma for compositing against + background and doing rgb-to-gray transformation. +Investigate pre-incremented loop counters and other loop constructions. +Add interpolated method of handling interlacing. +Switch to the simpler zlib (zlib/libpng) license if legally possible. +Extend pngvalid.c to validate more of the libpng transformations. + +*/ diff --git a/extern/libpng/arm/arm_init.c b/extern/libpng/arm/arm_init.c new file mode 100644 index 000000000..a34ecdbef --- /dev/null +++ b/extern/libpng/arm/arm_init.c @@ -0,0 +1,136 @@ + +/* arm_init.c - NEON optimised filter functions + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 2014,2016 Glenn Randers-Pehrson + * Written by Mans Rullgard, 2011. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are + * called. + */ +#define _POSIX_SOURCE 1 + +#include "../pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +#if PNG_ARM_NEON_OPT > 0 +#ifdef PNG_ARM_NEON_CHECK_SUPPORTED /* Do run-time checks */ +/* WARNING: it is strongly recommended that you do not build libpng with + * run-time checks for CPU features if at all possible. In the case of the ARM + * NEON instructions there is no processor-specific way of detecting the + * presence of the required support, therefore run-time detection is extremely + * OS specific. + * + * You may set the macro PNG_ARM_NEON_FILE to the file name of file containing + * a fragment of C source code which defines the png_have_neon function. There + * are a number of implementations in contrib/arm-neon, but the only one that + * has partial support is contrib/arm-neon/linux.c - a generic Linux + * implementation which reads /proc/cpufino. + */ +#ifndef PNG_ARM_NEON_FILE +# ifdef __linux__ +# define PNG_ARM_NEON_FILE "contrib/arm-neon/linux.c" +# endif +#endif + +#ifdef PNG_ARM_NEON_FILE + +#include /* for sig_atomic_t */ +static int png_have_neon(png_structp png_ptr); +#include PNG_ARM_NEON_FILE + +#else /* PNG_ARM_NEON_FILE */ +# error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks" +#endif /* PNG_ARM_NEON_FILE */ +#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */ + +#ifndef PNG_ALIGNED_MEMORY_SUPPORTED +# error "ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED" +#endif + +void +png_init_filter_functions_neon(png_structp pp, unsigned int bpp) +{ + /* The switch statement is compiled in for ARM_NEON_API, the call to + * png_have_neon is compiled in for ARM_NEON_CHECK. If both are defined + * the check is only performed if the API has not set the NEON option on + * or off explicitly. In this case the check controls what happens. + * + * If the CHECK is not compiled in and the option is UNSET the behavior prior + * to 1.6.7 was to use the NEON code - this was a bug caused by having the + * wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF, + * as documented in png.h + */ + png_debug(1, "in png_init_filter_functions_neon"); +#ifdef PNG_ARM_NEON_API_SUPPORTED + switch ((pp->options >> PNG_ARM_NEON) & 3) + { + case PNG_OPTION_UNSET: + /* Allow the run-time check to execute if it has been enabled - + * thus both API and CHECK can be turned on. If it isn't supported + * this case will fall through to the 'default' below, which just + * returns. + */ +#endif /* PNG_ARM_NEON_API_SUPPORTED */ +#ifdef PNG_ARM_NEON_CHECK_SUPPORTED + { + static volatile sig_atomic_t no_neon = -1; /* not checked */ + + if (no_neon < 0) + no_neon = !png_have_neon(pp); + + if (no_neon) + return; + } +#ifdef PNG_ARM_NEON_API_SUPPORTED + break; +#endif +#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */ + +#ifdef PNG_ARM_NEON_API_SUPPORTED + default: /* OFF or INVALID */ + return; + + case PNG_OPTION_ON: + /* Option turned on */ + break; + } +#endif + + /* IMPORTANT: any new external functions used here must be declared using + * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the + * 'prefix' option to configure works: + * + * ./configure --with-libpng-prefix=foobar_ + * + * Verify you have got this right by running the above command, doing a build + * and examining pngprefix.h; it must contain a #define for every external + * function you add. (Notice that this happens automatically for the + * initialization function.) + */ + pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon; + + if (bpp == 3) + { + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon; + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth3_neon; + } + + else if (bpp == 4) + { + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon; + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth4_neon; + } +} +#endif /* PNG_ARM_NEON_OPT > 0 */ +#endif /* READ */ diff --git a/extern/libpng/arm/filter_neon.S b/extern/libpng/arm/filter_neon.S new file mode 100644 index 000000000..2308aad13 --- /dev/null +++ b/extern/libpng/arm/filter_neon.S @@ -0,0 +1,253 @@ + +/* filter_neon.S - NEON optimised filter functions + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 2014,2017 Glenn Randers-Pehrson + * Written by Mans Rullgard, 2011. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* This is required to get the symbol renames, which are #defines, and the + * definitions (or not) of PNG_ARM_NEON_OPT and PNG_ARM_NEON_IMPLEMENTATION. + */ +#define PNG_VERSION_INFO_ONLY +#include "../pngpriv.h" + +#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__ELF__) +.section .note.GNU-stack,"",%progbits /* mark stack as non-executable */ +#endif + +#ifdef PNG_READ_SUPPORTED + +/* Assembler NEON support - only works for 32-bit ARM (i.e. it does not work for + * ARM64). The code in arm/filter_neon_intrinsics.c supports ARM64, however it + * only works if -mfpu=neon is specified on the GCC command line. See pngpriv.h + * for the logic which sets PNG_USE_ARM_NEON_ASM: + */ +#if PNG_ARM_NEON_IMPLEMENTATION == 2 /* hand-coded assembler */ + +#if PNG_ARM_NEON_OPT > 0 + +#ifdef __ELF__ +# define ELF +#else +# define ELF @ +#endif + + .arch armv7-a + .fpu neon + +.macro func name, export=0 + .macro endfunc +ELF .size \name, . - \name + .endfunc + .purgem endfunc + .endm + .text + + /* Explicitly specifying alignment here because some versions of + * GAS don't align code correctly. This is harmless in correctly + * written versions of GAS. + */ + .align 2 + + .if \export + .global \name + .endif +ELF .type \name, STT_FUNC + .func \name +\name: +.endm + +func png_read_filter_row_sub4_neon, export=1 + ldr r3, [r0, #4] @ rowbytes + vmov.i8 d3, #0 +1: + vld4.32 {d4[],d5[],d6[],d7[]}, [r1,:128] + vadd.u8 d0, d3, d4 + vadd.u8 d1, d0, d5 + vadd.u8 d2, d1, d6 + vadd.u8 d3, d2, d7 + vst4.32 {d0[0],d1[0],d2[0],d3[0]},[r1,:128]! + subs r3, r3, #16 + bgt 1b + + bx lr +endfunc + +func png_read_filter_row_sub3_neon, export=1 + ldr r3, [r0, #4] @ rowbytes + vmov.i8 d3, #0 + mov r0, r1 + mov r2, #3 + mov r12, #12 + vld1.8 {q11}, [r0], r12 +1: + vext.8 d5, d22, d23, #3 + vadd.u8 d0, d3, d22 + vext.8 d6, d22, d23, #6 + vadd.u8 d1, d0, d5 + vext.8 d7, d23, d23, #1 + vld1.8 {q11}, [r0], r12 + vst1.32 {d0[0]}, [r1,:32], r2 + vadd.u8 d2, d1, d6 + vst1.32 {d1[0]}, [r1], r2 + vadd.u8 d3, d2, d7 + vst1.32 {d2[0]}, [r1], r2 + vst1.32 {d3[0]}, [r1], r2 + subs r3, r3, #12 + bgt 1b + + bx lr +endfunc + +func png_read_filter_row_up_neon, export=1 + ldr r3, [r0, #4] @ rowbytes +1: + vld1.8 {q0}, [r1,:128] + vld1.8 {q1}, [r2,:128]! + vadd.u8 q0, q0, q1 + vst1.8 {q0}, [r1,:128]! + subs r3, r3, #16 + bgt 1b + + bx lr +endfunc + +func png_read_filter_row_avg4_neon, export=1 + ldr r12, [r0, #4] @ rowbytes + vmov.i8 d3, #0 +1: + vld4.32 {d4[],d5[],d6[],d7[]}, [r1,:128] + vld4.32 {d16[],d17[],d18[],d19[]},[r2,:128]! + vhadd.u8 d0, d3, d16 + vadd.u8 d0, d0, d4 + vhadd.u8 d1, d0, d17 + vadd.u8 d1, d1, d5 + vhadd.u8 d2, d1, d18 + vadd.u8 d2, d2, d6 + vhadd.u8 d3, d2, d19 + vadd.u8 d3, d3, d7 + vst4.32 {d0[0],d1[0],d2[0],d3[0]},[r1,:128]! + subs r12, r12, #16 + bgt 1b + + bx lr +endfunc + +func png_read_filter_row_avg3_neon, export=1 + push {r4,lr} + ldr r12, [r0, #4] @ rowbytes + vmov.i8 d3, #0 + mov r0, r1 + mov r4, #3 + mov lr, #12 + vld1.8 {q11}, [r0], lr +1: + vld1.8 {q10}, [r2], lr + vext.8 d5, d22, d23, #3 + vhadd.u8 d0, d3, d20 + vext.8 d17, d20, d21, #3 + vadd.u8 d0, d0, d22 + vext.8 d6, d22, d23, #6 + vhadd.u8 d1, d0, d17 + vext.8 d18, d20, d21, #6 + vadd.u8 d1, d1, d5 + vext.8 d7, d23, d23, #1 + vld1.8 {q11}, [r0], lr + vst1.32 {d0[0]}, [r1,:32], r4 + vhadd.u8 d2, d1, d18 + vst1.32 {d1[0]}, [r1], r4 + vext.8 d19, d21, d21, #1 + vadd.u8 d2, d2, d6 + vhadd.u8 d3, d2, d19 + vst1.32 {d2[0]}, [r1], r4 + vadd.u8 d3, d3, d7 + vst1.32 {d3[0]}, [r1], r4 + subs r12, r12, #12 + bgt 1b + + pop {r4,pc} +endfunc + +.macro paeth rx, ra, rb, rc + vaddl.u8 q12, \ra, \rb @ a + b + vaddl.u8 q15, \rc, \rc @ 2*c + vabdl.u8 q13, \rb, \rc @ pa + vabdl.u8 q14, \ra, \rc @ pb + vabd.u16 q15, q12, q15 @ pc + vcle.u16 q12, q13, q14 @ pa <= pb + vcle.u16 q13, q13, q15 @ pa <= pc + vcle.u16 q14, q14, q15 @ pb <= pc + vand q12, q12, q13 @ pa <= pb && pa <= pc + vmovn.u16 d28, q14 + vmovn.u16 \rx, q12 + vbsl d28, \rb, \rc + vbsl \rx, \ra, d28 +.endm + +func png_read_filter_row_paeth4_neon, export=1 + ldr r12, [r0, #4] @ rowbytes + vmov.i8 d3, #0 + vmov.i8 d20, #0 +1: + vld4.32 {d4[],d5[],d6[],d7[]}, [r1,:128] + vld4.32 {d16[],d17[],d18[],d19[]},[r2,:128]! + paeth d0, d3, d16, d20 + vadd.u8 d0, d0, d4 + paeth d1, d0, d17, d16 + vadd.u8 d1, d1, d5 + paeth d2, d1, d18, d17 + vadd.u8 d2, d2, d6 + paeth d3, d2, d19, d18 + vmov d20, d19 + vadd.u8 d3, d3, d7 + vst4.32 {d0[0],d1[0],d2[0],d3[0]},[r1,:128]! + subs r12, r12, #16 + bgt 1b + + bx lr +endfunc + +func png_read_filter_row_paeth3_neon, export=1 + push {r4,lr} + ldr r12, [r0, #4] @ rowbytes + vmov.i8 d3, #0 + vmov.i8 d4, #0 + mov r0, r1 + mov r4, #3 + mov lr, #12 + vld1.8 {q11}, [r0], lr +1: + vld1.8 {q10}, [r2], lr + paeth d0, d3, d20, d4 + vext.8 d5, d22, d23, #3 + vadd.u8 d0, d0, d22 + vext.8 d17, d20, d21, #3 + paeth d1, d0, d17, d20 + vst1.32 {d0[0]}, [r1,:32], r4 + vext.8 d6, d22, d23, #6 + vadd.u8 d1, d1, d5 + vext.8 d18, d20, d21, #6 + paeth d2, d1, d18, d17 + vext.8 d7, d23, d23, #1 + vld1.8 {q11}, [r0], lr + vst1.32 {d1[0]}, [r1], r4 + vadd.u8 d2, d2, d6 + vext.8 d19, d21, d21, #1 + paeth d3, d2, d19, d18 + vst1.32 {d2[0]}, [r1], r4 + vmov d4, d19 + vadd.u8 d3, d3, d7 + vst1.32 {d3[0]}, [r1], r4 + subs r12, r12, #12 + bgt 1b + + pop {r4,pc} +endfunc +#endif /* PNG_ARM_NEON_OPT > 0 */ +#endif /* PNG_ARM_NEON_IMPLEMENTATION == 2 (assembler) */ +#endif /* READ */ diff --git a/extern/libpng/arm/filter_neon_intrinsics.c b/extern/libpng/arm/filter_neon_intrinsics.c new file mode 100644 index 000000000..553c0be21 --- /dev/null +++ b/extern/libpng/arm/filter_neon_intrinsics.c @@ -0,0 +1,402 @@ + +/* filter_neon_intrinsics.c - NEON optimised filter functions + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 2014,2016 Glenn Randers-Pehrson + * Written by James Yu , October 2013. + * Based on filter_neon.S, written by Mans Rullgard, 2011. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "../pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +/* This code requires -mfpu=neon on the command line: */ +#if PNG_ARM_NEON_IMPLEMENTATION == 1 /* intrinsics code from pngpriv.h */ + +#if defined(_MSC_VER) && defined(_M_ARM64) +# include +#else +# include +#endif + +/* libpng row pointers are not necessarily aligned to any particular boundary, + * however this code will only work with appropriate alignment. arm/arm_init.c + * checks for this (and will not compile unless it is done). This code uses + * variants of png_aligncast to avoid compiler warnings. + */ +#define png_ptr(type,pointer) png_aligncast(type *,pointer) +#define png_ptrc(type,pointer) png_aligncastconst(const type *,pointer) + +/* The following relies on a variable 'temp_pointer' being declared with type + * 'type'. This is written this way just to hide the GCC strict aliasing + * warning; note that the code is safe because there never is an alias between + * the input and output pointers. + * + * When compiling with MSVC ARM64, the png_ldr macro can't be passed directly + * to vst4_lane_u32, because of an internal compiler error inside MSVC. + * To avoid this compiler bug, we use a temporary variable (vdest_val) to store + * the result of png_ldr. + */ +#define png_ldr(type,pointer)\ + (temp_pointer = png_ptr(type,pointer), *temp_pointer) + +#if PNG_ARM_NEON_OPT > 0 + +void +png_read_filter_row_up_neon(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp = row; + png_bytep rp_stop = row + row_info->rowbytes; + png_const_bytep pp = prev_row; + + png_debug(1, "in png_read_filter_row_up_neon"); + + for (; rp < rp_stop; rp += 16, pp += 16) + { + uint8x16_t qrp, qpp; + + qrp = vld1q_u8(rp); + qpp = vld1q_u8(pp); + qrp = vaddq_u8(qrp, qpp); + vst1q_u8(rp, qrp); + } +} + +void +png_read_filter_row_sub3_neon(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp = row; + png_bytep rp_stop = row + row_info->rowbytes; + + uint8x16_t vtmp = vld1q_u8(rp); + uint8x8x2_t *vrpt = png_ptr(uint8x8x2_t, &vtmp); + uint8x8x2_t vrp = *vrpt; + + uint8x8x4_t vdest; + vdest.val[3] = vdup_n_u8(0); + + png_debug(1, "in png_read_filter_row_sub3_neon"); + + for (; rp < rp_stop;) + { + uint8x8_t vtmp1, vtmp2; + uint32x2_t *temp_pointer; + + vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3); + vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]); + vtmp2 = vext_u8(vrp.val[0], vrp.val[1], 6); + vdest.val[1] = vadd_u8(vdest.val[0], vtmp1); + + vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1); + vdest.val[2] = vadd_u8(vdest.val[1], vtmp2); + vdest.val[3] = vadd_u8(vdest.val[2], vtmp1); + + vtmp = vld1q_u8(rp + 12); + vrpt = png_ptr(uint8x8x2_t, &vtmp); + vrp = *vrpt; + + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0); + rp += 3; + } + + PNG_UNUSED(prev_row) +} + +void +png_read_filter_row_sub4_neon(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp = row; + png_bytep rp_stop = row + row_info->rowbytes; + + uint8x8x4_t vdest; + vdest.val[3] = vdup_n_u8(0); + + png_debug(1, "in png_read_filter_row_sub4_neon"); + + for (; rp < rp_stop; rp += 16) + { + uint32x2x4_t vtmp = vld4_u32(png_ptr(uint32_t,rp)); + uint8x8x4_t *vrpt = png_ptr(uint8x8x4_t,&vtmp); + uint8x8x4_t vrp = *vrpt; + uint32x2x4_t *temp_pointer; + uint32x2x4_t vdest_val; + + vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]); + vdest.val[1] = vadd_u8(vdest.val[0], vrp.val[1]); + vdest.val[2] = vadd_u8(vdest.val[1], vrp.val[2]); + vdest.val[3] = vadd_u8(vdest.val[2], vrp.val[3]); + + vdest_val = png_ldr(uint32x2x4_t, &vdest); + vst4_lane_u32(png_ptr(uint32_t,rp), vdest_val, 0); + } + + PNG_UNUSED(prev_row) +} + +void +png_read_filter_row_avg3_neon(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp = row; + png_const_bytep pp = prev_row; + png_bytep rp_stop = row + row_info->rowbytes; + + uint8x16_t vtmp; + uint8x8x2_t *vrpt; + uint8x8x2_t vrp; + uint8x8x4_t vdest; + vdest.val[3] = vdup_n_u8(0); + + vtmp = vld1q_u8(rp); + vrpt = png_ptr(uint8x8x2_t,&vtmp); + vrp = *vrpt; + + png_debug(1, "in png_read_filter_row_avg3_neon"); + + for (; rp < rp_stop; pp += 12) + { + uint8x8_t vtmp1, vtmp2, vtmp3; + + uint8x8x2_t *vppt; + uint8x8x2_t vpp; + + uint32x2_t *temp_pointer; + + vtmp = vld1q_u8(pp); + vppt = png_ptr(uint8x8x2_t,&vtmp); + vpp = *vppt; + + vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3); + vdest.val[0] = vhadd_u8(vdest.val[3], vpp.val[0]); + vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]); + + vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 3); + vtmp3 = vext_u8(vrp.val[0], vrp.val[1], 6); + vdest.val[1] = vhadd_u8(vdest.val[0], vtmp2); + vdest.val[1] = vadd_u8(vdest.val[1], vtmp1); + + vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 6); + vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1); + + vtmp = vld1q_u8(rp + 12); + vrpt = png_ptr(uint8x8x2_t,&vtmp); + vrp = *vrpt; + + vdest.val[2] = vhadd_u8(vdest.val[1], vtmp2); + vdest.val[2] = vadd_u8(vdest.val[2], vtmp3); + + vtmp2 = vext_u8(vpp.val[1], vpp.val[1], 1); + + vdest.val[3] = vhadd_u8(vdest.val[2], vtmp2); + vdest.val[3] = vadd_u8(vdest.val[3], vtmp1); + + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0); + rp += 3; + } +} + +void +png_read_filter_row_avg4_neon(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp = row; + png_bytep rp_stop = row + row_info->rowbytes; + png_const_bytep pp = prev_row; + + uint8x8x4_t vdest; + vdest.val[3] = vdup_n_u8(0); + + png_debug(1, "in png_read_filter_row_avg4_neon"); + + for (; rp < rp_stop; rp += 16, pp += 16) + { + uint32x2x4_t vtmp; + uint8x8x4_t *vrpt, *vppt; + uint8x8x4_t vrp, vpp; + uint32x2x4_t *temp_pointer; + uint32x2x4_t vdest_val; + + vtmp = vld4_u32(png_ptr(uint32_t,rp)); + vrpt = png_ptr(uint8x8x4_t,&vtmp); + vrp = *vrpt; + vtmp = vld4_u32(png_ptrc(uint32_t,pp)); + vppt = png_ptr(uint8x8x4_t,&vtmp); + vpp = *vppt; + + vdest.val[0] = vhadd_u8(vdest.val[3], vpp.val[0]); + vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]); + vdest.val[1] = vhadd_u8(vdest.val[0], vpp.val[1]); + vdest.val[1] = vadd_u8(vdest.val[1], vrp.val[1]); + vdest.val[2] = vhadd_u8(vdest.val[1], vpp.val[2]); + vdest.val[2] = vadd_u8(vdest.val[2], vrp.val[2]); + vdest.val[3] = vhadd_u8(vdest.val[2], vpp.val[3]); + vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]); + + vdest_val = png_ldr(uint32x2x4_t, &vdest); + vst4_lane_u32(png_ptr(uint32_t,rp), vdest_val, 0); + } +} + +static uint8x8_t +paeth(uint8x8_t a, uint8x8_t b, uint8x8_t c) +{ + uint8x8_t d, e; + uint16x8_t p1, pa, pb, pc; + + p1 = vaddl_u8(a, b); /* a + b */ + pc = vaddl_u8(c, c); /* c * 2 */ + pa = vabdl_u8(b, c); /* pa */ + pb = vabdl_u8(a, c); /* pb */ + pc = vabdq_u16(p1, pc); /* pc */ + + p1 = vcleq_u16(pa, pb); /* pa <= pb */ + pa = vcleq_u16(pa, pc); /* pa <= pc */ + pb = vcleq_u16(pb, pc); /* pb <= pc */ + + p1 = vandq_u16(p1, pa); /* pa <= pb && pa <= pc */ + + d = vmovn_u16(pb); + e = vmovn_u16(p1); + + d = vbsl_u8(d, b, c); + e = vbsl_u8(e, a, d); + + return e; +} + +void +png_read_filter_row_paeth3_neon(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp = row; + png_const_bytep pp = prev_row; + png_bytep rp_stop = row + row_info->rowbytes; + + uint8x16_t vtmp; + uint8x8x2_t *vrpt; + uint8x8x2_t vrp; + uint8x8_t vlast = vdup_n_u8(0); + uint8x8x4_t vdest; + vdest.val[3] = vdup_n_u8(0); + + vtmp = vld1q_u8(rp); + vrpt = png_ptr(uint8x8x2_t,&vtmp); + vrp = *vrpt; + + png_debug(1, "in png_read_filter_row_paeth3_neon"); + + for (; rp < rp_stop; pp += 12) + { + uint8x8x2_t *vppt; + uint8x8x2_t vpp; + uint8x8_t vtmp1, vtmp2, vtmp3; + uint32x2_t *temp_pointer; + + vtmp = vld1q_u8(pp); + vppt = png_ptr(uint8x8x2_t,&vtmp); + vpp = *vppt; + + vdest.val[0] = paeth(vdest.val[3], vpp.val[0], vlast); + vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]); + + vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3); + vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 3); + vdest.val[1] = paeth(vdest.val[0], vtmp2, vpp.val[0]); + vdest.val[1] = vadd_u8(vdest.val[1], vtmp1); + + vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 6); + vtmp3 = vext_u8(vpp.val[0], vpp.val[1], 6); + vdest.val[2] = paeth(vdest.val[1], vtmp3, vtmp2); + vdest.val[2] = vadd_u8(vdest.val[2], vtmp1); + + vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1); + vtmp2 = vext_u8(vpp.val[1], vpp.val[1], 1); + + vtmp = vld1q_u8(rp + 12); + vrpt = png_ptr(uint8x8x2_t,&vtmp); + vrp = *vrpt; + + vdest.val[3] = paeth(vdest.val[2], vtmp2, vtmp3); + vdest.val[3] = vadd_u8(vdest.val[3], vtmp1); + + vlast = vtmp2; + + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0); + rp += 3; + vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0); + rp += 3; + } +} + +void +png_read_filter_row_paeth4_neon(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp = row; + png_bytep rp_stop = row + row_info->rowbytes; + png_const_bytep pp = prev_row; + + uint8x8_t vlast = vdup_n_u8(0); + uint8x8x4_t vdest; + vdest.val[3] = vdup_n_u8(0); + + png_debug(1, "in png_read_filter_row_paeth4_neon"); + + for (; rp < rp_stop; rp += 16, pp += 16) + { + uint32x2x4_t vtmp; + uint8x8x4_t *vrpt, *vppt; + uint8x8x4_t vrp, vpp; + uint32x2x4_t *temp_pointer; + uint32x2x4_t vdest_val; + + vtmp = vld4_u32(png_ptr(uint32_t,rp)); + vrpt = png_ptr(uint8x8x4_t,&vtmp); + vrp = *vrpt; + vtmp = vld4_u32(png_ptrc(uint32_t,pp)); + vppt = png_ptr(uint8x8x4_t,&vtmp); + vpp = *vppt; + + vdest.val[0] = paeth(vdest.val[3], vpp.val[0], vlast); + vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]); + vdest.val[1] = paeth(vdest.val[0], vpp.val[1], vpp.val[0]); + vdest.val[1] = vadd_u8(vdest.val[1], vrp.val[1]); + vdest.val[2] = paeth(vdest.val[1], vpp.val[2], vpp.val[1]); + vdest.val[2] = vadd_u8(vdest.val[2], vrp.val[2]); + vdest.val[3] = paeth(vdest.val[2], vpp.val[3], vpp.val[2]); + vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]); + + vlast = vpp.val[3]; + + vdest_val = png_ldr(uint32x2x4_t, &vdest); + vst4_lane_u32(png_ptr(uint32_t,rp), vdest_val, 0); + } +} + +#endif /* PNG_ARM_NEON_OPT > 0 */ +#endif /* PNG_ARM_NEON_IMPLEMENTATION == 1 (intrinsics) */ +#endif /* READ */ diff --git a/extern/libpng/arm/palette_neon_intrinsics.c b/extern/libpng/arm/palette_neon_intrinsics.c new file mode 100644 index 000000000..b4d1fd2ab --- /dev/null +++ b/extern/libpng/arm/palette_neon_intrinsics.c @@ -0,0 +1,149 @@ + +/* palette_neon_intrinsics.c - NEON optimised palette expansion functions + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 2017-2018 Arm Holdings. All rights reserved. + * Written by Richard Townsend , February 2017. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "../pngpriv.h" + +#if PNG_ARM_NEON_IMPLEMENTATION == 1 + +#if defined(_MSC_VER) && defined(_M_ARM64) +# include +#else +# include +#endif + +/* Build an RGBA8 palette from the separate RGB and alpha palettes. */ +void +png_riffle_palette_neon(png_structrp png_ptr) +{ + png_const_colorp palette = png_ptr->palette; + png_bytep riffled_palette = png_ptr->riffled_palette; + png_const_bytep trans_alpha = png_ptr->trans_alpha; + int num_trans = png_ptr->num_trans; + int i; + + png_debug(1, "in png_riffle_palette_neon"); + + /* Initially black, opaque. */ + uint8x16x4_t w = {{ + vdupq_n_u8(0x00), + vdupq_n_u8(0x00), + vdupq_n_u8(0x00), + vdupq_n_u8(0xff), + }}; + + /* First, riffle the RGB colours into an RGBA8 palette. + * The alpha component is set to opaque for now. + */ + for (i = 0; i < 256; i += 16) + { + uint8x16x3_t v = vld3q_u8((png_const_bytep)(palette + i)); + w.val[0] = v.val[0]; + w.val[1] = v.val[1]; + w.val[2] = v.val[2]; + vst4q_u8(riffled_palette + (i << 2), w); + } + + /* Fix up the missing transparency values. */ + for (i = 0; i < num_trans; i++) + riffled_palette[(i << 2) + 3] = trans_alpha[i]; +} + +/* Expands a palettized row into RGBA8. */ +int +png_do_expand_palette_rgba8_neon(png_structrp png_ptr, png_row_infop row_info, + png_const_bytep row, png_bytepp ssp, png_bytepp ddp) +{ + png_uint_32 row_width = row_info->width; + const png_uint_32 *riffled_palette = + (const png_uint_32 *)png_ptr->riffled_palette; + const png_int_32 pixels_per_chunk = 4; + int i; + + png_debug(1, "in png_do_expand_palette_rgba8_neon"); + + if (row_width < pixels_per_chunk) + return 0; + + /* This function originally gets the last byte of the output row. + * The NEON part writes forward from a given position, so we have + * to seek this back by 4 pixels x 4 bytes. + */ + *ddp = *ddp - ((pixels_per_chunk * sizeof(png_uint_32)) - 1); + + for (i = 0; i < row_width; i += pixels_per_chunk) + { + uint32x4_t cur; + png_bytep sp = *ssp - i, dp = *ddp - (i << 2); + cur = vld1q_dup_u32 (riffled_palette + *(sp - 3)); + cur = vld1q_lane_u32(riffled_palette + *(sp - 2), cur, 1); + cur = vld1q_lane_u32(riffled_palette + *(sp - 1), cur, 2); + cur = vld1q_lane_u32(riffled_palette + *(sp - 0), cur, 3); + vst1q_u32((void *)dp, cur); + } + if (i != row_width) + { + /* Remove the amount that wasn't processed. */ + i -= pixels_per_chunk; + } + + /* Decrement output pointers. */ + *ssp = *ssp - i; + *ddp = *ddp - (i << 2); + return i; +} + +/* Expands a palettized row into RGB8. */ +int +png_do_expand_palette_rgb8_neon(png_structrp png_ptr, png_row_infop row_info, + png_const_bytep row, png_bytepp ssp, png_bytepp ddp) +{ + png_uint_32 row_width = row_info->width; + png_const_bytep palette = (png_const_bytep)png_ptr->palette; + const png_uint_32 pixels_per_chunk = 8; + int i; + + png_debug(1, "in png_do_expand_palette_rgb8_neon"); + + if (row_width <= pixels_per_chunk) + return 0; + + /* Seeking this back by 8 pixels x 3 bytes. */ + *ddp = *ddp - ((pixels_per_chunk * sizeof(png_color)) - 1); + + for (i = 0; i < row_width; i += pixels_per_chunk) + { + uint8x8x3_t cur; + png_bytep sp = *ssp - i, dp = *ddp - ((i << 1) + i); + cur = vld3_dup_u8(palette + sizeof(png_color) * (*(sp - 7))); + cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 6)), cur, 1); + cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 5)), cur, 2); + cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 4)), cur, 3); + cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 3)), cur, 4); + cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 2)), cur, 5); + cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 1)), cur, 6); + cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 0)), cur, 7); + vst3_u8((void *)dp, cur); + } + + if (i != row_width) + { + /* Remove the amount that wasn't processed. */ + i -= pixels_per_chunk; + } + + /* Decrement output pointers. */ + *ssp = *ssp - i; + *ddp = *ddp - ((i << 1) + i); + return i; +} + +#endif /* PNG_ARM_NEON_IMPLEMENTATION */ diff --git a/extern/libpng/intel/filter_sse2_intrinsics.c b/extern/libpng/intel/filter_sse2_intrinsics.c new file mode 100644 index 000000000..f52aaa800 --- /dev/null +++ b/extern/libpng/intel/filter_sse2_intrinsics.c @@ -0,0 +1,391 @@ + +/* filter_sse2_intrinsics.c - SSE2 optimized filter functions + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 2016-2017 Glenn Randers-Pehrson + * Written by Mike Klein and Matt Sarett + * Derived from arm/filter_neon_intrinsics.c + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "../pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +#if PNG_INTEL_SSE_IMPLEMENTATION > 0 + +#include + +/* Functions in this file look at most 3 pixels (a,b,c) to predict the 4th (d). + * They're positioned like this: + * prev: c b + * row: a d + * The Sub filter predicts d=a, Avg d=(a+b)/2, and Paeth predicts d to be + * whichever of a, b, or c is closest to p=a+b-c. + */ + +static __m128i load4(const void* p) { + int tmp; + memcpy(&tmp, p, sizeof(tmp)); + return _mm_cvtsi32_si128(tmp); +} + +static void store4(void* p, __m128i v) { + int tmp = _mm_cvtsi128_si32(v); + memcpy(p, &tmp, sizeof(int)); +} + +static __m128i load3(const void* p) { + png_uint_32 tmp = 0; + memcpy(&tmp, p, 3); + return _mm_cvtsi32_si128(tmp); +} + +static void store3(void* p, __m128i v) { + int tmp = _mm_cvtsi128_si32(v); + memcpy(p, &tmp, 3); +} + +void png_read_filter_row_sub3_sse2(png_row_infop row_info, png_bytep row, + png_const_bytep prev) +{ + /* The Sub filter predicts each pixel as the previous pixel, a. + * There is no pixel to the left of the first pixel. It's encoded directly. + * That works with our main loop if we just say that left pixel was zero. + */ + size_t rb; + + __m128i a, d = _mm_setzero_si128(); + + png_debug(1, "in png_read_filter_row_sub3_sse2"); + + rb = row_info->rowbytes; + while (rb >= 4) { + a = d; d = load4(row); + d = _mm_add_epi8(d, a); + store3(row, d); + + row += 3; + rb -= 3; + } + if (rb > 0) { + a = d; d = load3(row); + d = _mm_add_epi8(d, a); + store3(row, d); + + row += 3; + rb -= 3; + } + PNG_UNUSED(prev) +} + +void png_read_filter_row_sub4_sse2(png_row_infop row_info, png_bytep row, + png_const_bytep prev) +{ + /* The Sub filter predicts each pixel as the previous pixel, a. + * There is no pixel to the left of the first pixel. It's encoded directly. + * That works with our main loop if we just say that left pixel was zero. + */ + size_t rb; + + __m128i a, d = _mm_setzero_si128(); + + png_debug(1, "in png_read_filter_row_sub4_sse2"); + + rb = row_info->rowbytes+4; + while (rb > 4) { + a = d; d = load4(row); + d = _mm_add_epi8(d, a); + store4(row, d); + + row += 4; + rb -= 4; + } + PNG_UNUSED(prev) +} + +void png_read_filter_row_avg3_sse2(png_row_infop row_info, png_bytep row, + png_const_bytep prev) +{ + /* The Avg filter predicts each pixel as the (truncated) average of a and b. + * There's no pixel to the left of the first pixel. Luckily, it's + * predicted to be half of the pixel above it. So again, this works + * perfectly with our loop if we make sure a starts at zero. + */ + + size_t rb; + + const __m128i zero = _mm_setzero_si128(); + + __m128i b; + __m128i a, d = zero; + + png_debug(1, "in png_read_filter_row_avg3_sse2"); + rb = row_info->rowbytes; + while (rb >= 4) { + __m128i avg; + b = load4(prev); + a = d; d = load4(row ); + + /* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */ + avg = _mm_avg_epu8(a,b); + /* ...but we can fix it up by subtracting off 1 if it rounded up. */ + avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b), + _mm_set1_epi8(1))); + d = _mm_add_epi8(d, avg); + store3(row, d); + + prev += 3; + row += 3; + rb -= 3; + } + if (rb > 0) { + __m128i avg; + b = load3(prev); + a = d; d = load3(row ); + + /* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */ + avg = _mm_avg_epu8(a,b); + /* ...but we can fix it up by subtracting off 1 if it rounded up. */ + avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b), + _mm_set1_epi8(1))); + + d = _mm_add_epi8(d, avg); + store3(row, d); + + prev += 3; + row += 3; + rb -= 3; + } +} + +void png_read_filter_row_avg4_sse2(png_row_infop row_info, png_bytep row, + png_const_bytep prev) +{ + /* The Avg filter predicts each pixel as the (truncated) average of a and b. + * There's no pixel to the left of the first pixel. Luckily, it's + * predicted to be half of the pixel above it. So again, this works + * perfectly with our loop if we make sure a starts at zero. + */ + size_t rb; + const __m128i zero = _mm_setzero_si128(); + __m128i b; + __m128i a, d = zero; + + png_debug(1, "in png_read_filter_row_avg4_sse2"); + + rb = row_info->rowbytes+4; + while (rb > 4) { + __m128i avg; + b = load4(prev); + a = d; d = load4(row ); + + /* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */ + avg = _mm_avg_epu8(a,b); + /* ...but we can fix it up by subtracting off 1 if it rounded up. */ + avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b), + _mm_set1_epi8(1))); + + d = _mm_add_epi8(d, avg); + store4(row, d); + + prev += 4; + row += 4; + rb -= 4; + } +} + +/* Returns |x| for 16-bit lanes. */ +static __m128i abs_i16(__m128i x) { +#if PNG_INTEL_SSE_IMPLEMENTATION >= 2 + return _mm_abs_epi16(x); +#else + /* Read this all as, return x<0 ? -x : x. + * To negate two's complement, you flip all the bits then add 1. + */ + __m128i is_negative = _mm_cmplt_epi16(x, _mm_setzero_si128()); + + /* Flip negative lanes. */ + x = _mm_xor_si128(x, is_negative); + + /* +1 to negative lanes, else +0. */ + x = _mm_sub_epi16(x, is_negative); + return x; +#endif +} + +/* Bytewise c ? t : e. */ +static __m128i if_then_else(__m128i c, __m128i t, __m128i e) { +#if PNG_INTEL_SSE_IMPLEMENTATION >= 3 + return _mm_blendv_epi8(e,t,c); +#else + return _mm_or_si128(_mm_and_si128(c, t), _mm_andnot_si128(c, e)); +#endif +} + +void png_read_filter_row_paeth3_sse2(png_row_infop row_info, png_bytep row, + png_const_bytep prev) +{ + /* Paeth tries to predict pixel d using the pixel to the left of it, a, + * and two pixels from the previous row, b and c: + * prev: c b + * row: a d + * The Paeth function predicts d to be whichever of a, b, or c is nearest to + * p=a+b-c. + * + * The first pixel has no left context, and so uses an Up filter, p = b. + * This works naturally with our main loop's p = a+b-c if we force a and c + * to zero. + * Here we zero b and d, which become c and a respectively at the start of + * the loop. + */ + size_t rb; + const __m128i zero = _mm_setzero_si128(); + __m128i c, b = zero, + a, d = zero; + + png_debug(1, "in png_read_filter_row_paeth3_sse2"); + + rb = row_info->rowbytes; + while (rb >= 4) { + /* It's easiest to do this math (particularly, deal with pc) with 16-bit + * intermediates. + */ + __m128i pa,pb,pc,smallest,nearest; + c = b; b = _mm_unpacklo_epi8(load4(prev), zero); + a = d; d = _mm_unpacklo_epi8(load4(row ), zero); + + /* (p-a) == (a+b-c - a) == (b-c) */ + + pa = _mm_sub_epi16(b,c); + + /* (p-b) == (a+b-c - b) == (a-c) */ + pb = _mm_sub_epi16(a,c); + + /* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */ + pc = _mm_add_epi16(pa,pb); + + pa = abs_i16(pa); /* |p-a| */ + pb = abs_i16(pb); /* |p-b| */ + pc = abs_i16(pc); /* |p-c| */ + + smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb)); + + /* Paeth breaks ties favoring a over b over c. */ + nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a, + if_then_else(_mm_cmpeq_epi16(smallest, pb), b, + c)); + + /* Note `_epi8`: we need addition to wrap modulo 255. */ + d = _mm_add_epi8(d, nearest); + store3(row, _mm_packus_epi16(d,d)); + + prev += 3; + row += 3; + rb -= 3; + } + if (rb > 0) { + /* It's easiest to do this math (particularly, deal with pc) with 16-bit + * intermediates. + */ + __m128i pa,pb,pc,smallest,nearest; + c = b; b = _mm_unpacklo_epi8(load3(prev), zero); + a = d; d = _mm_unpacklo_epi8(load3(row ), zero); + + /* (p-a) == (a+b-c - a) == (b-c) */ + pa = _mm_sub_epi16(b,c); + + /* (p-b) == (a+b-c - b) == (a-c) */ + pb = _mm_sub_epi16(a,c); + + /* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */ + pc = _mm_add_epi16(pa,pb); + + pa = abs_i16(pa); /* |p-a| */ + pb = abs_i16(pb); /* |p-b| */ + pc = abs_i16(pc); /* |p-c| */ + + smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb)); + + /* Paeth breaks ties favoring a over b over c. */ + nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a, + if_then_else(_mm_cmpeq_epi16(smallest, pb), b, + c)); + + /* Note `_epi8`: we need addition to wrap modulo 255. */ + d = _mm_add_epi8(d, nearest); + store3(row, _mm_packus_epi16(d,d)); + + prev += 3; + row += 3; + rb -= 3; + } +} + +void png_read_filter_row_paeth4_sse2(png_row_infop row_info, png_bytep row, + png_const_bytep prev) +{ + /* Paeth tries to predict pixel d using the pixel to the left of it, a, + * and two pixels from the previous row, b and c: + * prev: c b + * row: a d + * The Paeth function predicts d to be whichever of a, b, or c is nearest to + * p=a+b-c. + * + * The first pixel has no left context, and so uses an Up filter, p = b. + * This works naturally with our main loop's p = a+b-c if we force a and c + * to zero. + * Here we zero b and d, which become c and a respectively at the start of + * the loop. + */ + size_t rb; + const __m128i zero = _mm_setzero_si128(); + __m128i pa,pb,pc,smallest,nearest; + __m128i c, b = zero, + a, d = zero; + + png_debug(1, "in png_read_filter_row_paeth4_sse2"); + + rb = row_info->rowbytes+4; + while (rb > 4) { + /* It's easiest to do this math (particularly, deal with pc) with 16-bit + * intermediates. + */ + c = b; b = _mm_unpacklo_epi8(load4(prev), zero); + a = d; d = _mm_unpacklo_epi8(load4(row ), zero); + + /* (p-a) == (a+b-c - a) == (b-c) */ + pa = _mm_sub_epi16(b,c); + + /* (p-b) == (a+b-c - b) == (a-c) */ + pb = _mm_sub_epi16(a,c); + + /* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */ + pc = _mm_add_epi16(pa,pb); + + pa = abs_i16(pa); /* |p-a| */ + pb = abs_i16(pb); /* |p-b| */ + pc = abs_i16(pc); /* |p-c| */ + + smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb)); + + /* Paeth breaks ties favoring a over b over c. */ + nearest = if_then_else(_mm_cmpeq_epi16(smallest, pa), a, + if_then_else(_mm_cmpeq_epi16(smallest, pb), b, + c)); + + /* Note `_epi8`: we need addition to wrap modulo 255. */ + d = _mm_add_epi8(d, nearest); + store4(row, _mm_packus_epi16(d,d)); + + prev += 4; + row += 4; + rb -= 4; + } +} + +#endif /* PNG_INTEL_SSE_IMPLEMENTATION > 0 */ +#endif /* READ */ diff --git a/extern/libpng/intel/intel_init.c b/extern/libpng/intel/intel_init.c new file mode 100644 index 000000000..2f8168b7c --- /dev/null +++ b/extern/libpng/intel/intel_init.c @@ -0,0 +1,52 @@ + +/* intel_init.c - SSE2 optimized filter functions + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 2016-2017 Glenn Randers-Pehrson + * Written by Mike Klein and Matt Sarett, Google, Inc. + * Derived from arm/arm_init.c + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "../pngpriv.h" + +#ifdef PNG_READ_SUPPORTED +#if PNG_INTEL_SSE_IMPLEMENTATION > 0 + +void +png_init_filter_functions_sse2(png_structp pp, unsigned int bpp) +{ + /* The techniques used to implement each of these filters in SSE operate on + * one pixel at a time. + * So they generally speed up 3bpp images about 3x, 4bpp images about 4x. + * They can scale up to 6 and 8 bpp images and down to 2 bpp images, + * but they'd not likely have any benefit for 1bpp images. + * Most of these can be implemented using only MMX and 64-bit registers, + * but they end up a bit slower than using the equally-ubiquitous SSE2. + */ + png_debug(1, "in png_init_filter_functions_sse2"); + if (bpp == 3) + { + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_sse2; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_sse2; + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth3_sse2; + } + else if (bpp == 4) + { + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_sse2; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_sse2; + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth4_sse2; + } + + /* No need optimize PNG_FILTER_VALUE_UP. The compiler should + * autovectorize. + */ +} + +#endif /* PNG_INTEL_SSE_IMPLEMENTATION > 0 */ +#endif /* PNG_READ_SUPPORTED */ diff --git a/extern/libpng/png.c b/extern/libpng/png.c new file mode 100644 index 000000000..38b09246e --- /dev/null +++ b/extern/libpng/png.c @@ -0,0 +1,4627 @@ + +/* png.c - location for general purpose libpng functions + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +/* Generate a compiler error if there is an old png.h in the search path. */ +typedef png_libpng_version_1_6_37 Your_png_h_is_not_version_1_6_37; + +#ifdef __GNUC__ +/* The version tests may need to be added to, but the problem warning has + * consistently been fixed in GCC versions which obtain wide-spread release. + * The problem is that many versions of GCC rearrange comparison expressions in + * the optimizer in such a way that the results of the comparison will change + * if signed integer overflow occurs. Such comparisons are not permitted in + * ANSI C90, however GCC isn't clever enough to work out that that do not occur + * below in png_ascii_from_fp and png_muldiv, so it produces a warning with + * -Wextra. Unfortunately this is highly dependent on the optimizer and the + * machine architecture so the warning comes and goes unpredictably and is + * impossible to "fix", even were that a good idea. + */ +#if __GNUC__ == 7 && __GNUC_MINOR__ == 1 +#define GCC_STRICT_OVERFLOW 1 +#endif /* GNU 7.1.x */ +#endif /* GNU */ +#ifndef GCC_STRICT_OVERFLOW +#define GCC_STRICT_OVERFLOW 0 +#endif + +/* Tells libpng that we have already handled the first "num_bytes" bytes + * of the PNG file signature. If the PNG data is embedded into another + * stream we can set num_bytes = 8 so that libpng will not attempt to read + * or write any of the magic bytes before it starts on the IHDR. + */ + +#ifdef PNG_READ_SUPPORTED +void PNGAPI +png_set_sig_bytes(png_structrp png_ptr, int num_bytes) +{ + unsigned int nb = (unsigned int)num_bytes; + + png_debug(1, "in png_set_sig_bytes"); + + if (png_ptr == NULL) + return; + + if (num_bytes < 0) + nb = 0; + + if (nb > 8) + png_error(png_ptr, "Too many bytes for PNG signature"); + + png_ptr->sig_bytes = (png_byte)nb; +} + +/* Checks whether the supplied bytes match the PNG signature. We allow + * checking less than the full 8-byte signature so that those apps that + * already read the first few bytes of a file to determine the file type + * can simply check the remaining bytes for extra assurance. Returns + * an integer less than, equal to, or greater than zero if sig is found, + * respectively, to be less than, to match, or be greater than the correct + * PNG signature (this is the same behavior as strcmp, memcmp, etc). + */ +int PNGAPI +png_sig_cmp(png_const_bytep sig, size_t start, size_t num_to_check) +{ + png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + + if (num_to_check > 8) + num_to_check = 8; + + else if (num_to_check < 1) + return (-1); + + if (start > 7) + return (-1); + + if (start + num_to_check > 8) + num_to_check = 8 - start; + + return ((int)(memcmp(&sig[start], &png_signature[start], num_to_check))); +} + +#endif /* READ */ + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +/* Function to allocate memory for zlib */ +PNG_FUNCTION(voidpf /* PRIVATE */, +png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED) +{ + png_alloc_size_t num_bytes = size; + + if (png_ptr == NULL) + return NULL; + + if (items >= (~(png_alloc_size_t)0)/size) + { + png_warning (png_voidcast(png_structrp, png_ptr), + "Potential overflow in png_zalloc()"); + return NULL; + } + + num_bytes *= items; + return png_malloc_warn(png_voidcast(png_structrp, png_ptr), num_bytes); +} + +/* Function to free memory for zlib */ +void /* PRIVATE */ +png_zfree(voidpf png_ptr, voidpf ptr) +{ + png_free(png_voidcast(png_const_structrp,png_ptr), ptr); +} + +/* Reset the CRC variable to 32 bits of 1's. Care must be taken + * in case CRC is > 32 bits to leave the top bits 0. + */ +void /* PRIVATE */ +png_reset_crc(png_structrp png_ptr) +{ + /* The cast is safe because the crc is a 32-bit value. */ + png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0); +} + +/* Calculate the CRC over a section of data. We can only pass as + * much data to this routine as the largest single buffer size. We + * also check that this data will actually be used before going to the + * trouble of calculating it. + */ +void /* PRIVATE */ +png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, size_t length) +{ + int need_crc = 1; + + if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0) + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == + (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) + need_crc = 0; + } + + else /* critical */ + { + if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0) + need_crc = 0; + } + + /* 'uLong' is defined in zlib.h as unsigned long; this means that on some + * systems it is a 64-bit value. crc32, however, returns 32 bits so the + * following cast is safe. 'uInt' may be no more than 16 bits, so it is + * necessary to perform a loop here. + */ + if (need_crc != 0 && length > 0) + { + uLong crc = png_ptr->crc; /* Should never issue a warning */ + + do + { + uInt safe_length = (uInt)length; +#ifndef __COVERITY__ + if (safe_length == 0) + safe_length = (uInt)-1; /* evil, but safe */ +#endif + + crc = crc32(crc, ptr, safe_length); + + /* The following should never issue compiler warnings; if they do the + * target system has characteristics that will probably violate other + * assumptions within the libpng code. + */ + ptr += safe_length; + length -= safe_length; + } + while (length > 0); + + /* And the following is always safe because the crc is only 32 bits. */ + png_ptr->crc = (png_uint_32)crc; + } +} + +/* Check a user supplied version number, called from both read and write + * functions that create a png_struct. + */ +int +png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver) +{ + /* Libpng versions 1.0.0 and later are binary compatible if the version + * string matches through the second '.'; we must recompile any + * applications that use any older library version. + */ + + if (user_png_ver != NULL) + { + int i = -1; + int found_dots = 0; + + do + { + i++; + if (user_png_ver[i] != PNG_LIBPNG_VER_STRING[i]) + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + if (user_png_ver[i] == '.') + found_dots++; + } while (found_dots < 2 && user_png_ver[i] != 0 && + PNG_LIBPNG_VER_STRING[i] != 0); + } + + else + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + + if ((png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) != 0) + { +#ifdef PNG_WARNINGS_SUPPORTED + size_t pos = 0; + char m[128]; + + pos = png_safecat(m, (sizeof m), pos, + "Application built with libpng-"); + pos = png_safecat(m, (sizeof m), pos, user_png_ver); + pos = png_safecat(m, (sizeof m), pos, " but running with "); + pos = png_safecat(m, (sizeof m), pos, PNG_LIBPNG_VER_STRING); + PNG_UNUSED(pos) + + png_warning(png_ptr, m); +#endif + +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + + return 0; + } + + /* Success return. */ + return 1; +} + +/* Generic function to create a png_struct for either read or write - this + * contains the common initialization. + */ +PNG_FUNCTION(png_structp /* PRIVATE */, +png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) +{ + png_struct create_struct; +# ifdef PNG_SETJMP_SUPPORTED + jmp_buf create_jmp_buf; +# endif + + /* This temporary stack-allocated structure is used to provide a place to + * build enough context to allow the user provided memory allocator (if any) + * to be called. + */ + memset(&create_struct, 0, (sizeof create_struct)); + + /* Added at libpng-1.2.6 */ +# ifdef PNG_USER_LIMITS_SUPPORTED + create_struct.user_width_max = PNG_USER_WIDTH_MAX; + create_struct.user_height_max = PNG_USER_HEIGHT_MAX; + +# ifdef PNG_USER_CHUNK_CACHE_MAX + /* Added at libpng-1.2.43 and 1.4.0 */ + create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; +# endif + +# ifdef PNG_USER_CHUNK_MALLOC_MAX + /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists + * in png_struct regardless. + */ + create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; +# endif +# endif + + /* The following two API calls simply set fields in png_struct, so it is safe + * to do them now even though error handling is not yet set up. + */ +# ifdef PNG_USER_MEM_SUPPORTED + png_set_mem_fn(&create_struct, mem_ptr, malloc_fn, free_fn); +# else + PNG_UNUSED(mem_ptr) + PNG_UNUSED(malloc_fn) + PNG_UNUSED(free_fn) +# endif + + /* (*error_fn) can return control to the caller after the error_ptr is set, + * this will result in a memory leak unless the error_fn does something + * extremely sophisticated. The design lacks merit but is implicit in the + * API. + */ + png_set_error_fn(&create_struct, error_ptr, error_fn, warn_fn); + +# ifdef PNG_SETJMP_SUPPORTED + if (!setjmp(create_jmp_buf)) +# endif + { +# ifdef PNG_SETJMP_SUPPORTED + /* Temporarily fake out the longjmp information until we have + * successfully completed this function. This only works if we have + * setjmp() support compiled in, but it is safe - this stuff should + * never happen. + */ + create_struct.jmp_buf_ptr = &create_jmp_buf; + create_struct.jmp_buf_size = 0; /*stack allocation*/ + create_struct.longjmp_fn = longjmp; +# endif + /* Call the general version checker (shared with read and write code): + */ + if (png_user_version_check(&create_struct, user_png_ver) != 0) + { + png_structrp png_ptr = png_voidcast(png_structrp, + png_malloc_warn(&create_struct, (sizeof *png_ptr))); + + if (png_ptr != NULL) + { + /* png_ptr->zstream holds a back-pointer to the png_struct, so + * this can only be done now: + */ + create_struct.zstream.zalloc = png_zalloc; + create_struct.zstream.zfree = png_zfree; + create_struct.zstream.opaque = png_ptr; + +# ifdef PNG_SETJMP_SUPPORTED + /* Eliminate the local error handling: */ + create_struct.jmp_buf_ptr = NULL; + create_struct.jmp_buf_size = 0; + create_struct.longjmp_fn = 0; +# endif + + *png_ptr = create_struct; + + /* This is the successful return point */ + return png_ptr; + } + } + } + + /* A longjmp because of a bug in the application storage allocator or a + * simple failure to allocate the png_struct. + */ + return NULL; +} + +/* Allocate the memory for an info_struct for the application. */ +PNG_FUNCTION(png_infop,PNGAPI +png_create_info_struct,(png_const_structrp png_ptr),PNG_ALLOCATED) +{ + png_inforp info_ptr; + + png_debug(1, "in png_create_info_struct"); + + if (png_ptr == NULL) + return NULL; + + /* Use the internal API that does not (or at least should not) error out, so + * that this call always returns ok. The application typically sets up the + * error handling *after* creating the info_struct because this is the way it + * has always been done in 'example.c'. + */ + info_ptr = png_voidcast(png_inforp, png_malloc_base(png_ptr, + (sizeof *info_ptr))); + + if (info_ptr != NULL) + memset(info_ptr, 0, (sizeof *info_ptr)); + + return info_ptr; +} + +/* This function frees the memory associated with a single info struct. + * Normally, one would use either png_destroy_read_struct() or + * png_destroy_write_struct() to free an info struct, but this may be + * useful for some applications. From libpng 1.6.0 this function is also used + * internally to implement the png_info release part of the 'struct' destroy + * APIs. This ensures that all possible approaches free the same data (all of + * it). + */ +void PNGAPI +png_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr) +{ + png_inforp info_ptr = NULL; + + png_debug(1, "in png_destroy_info_struct"); + + if (png_ptr == NULL) + return; + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (info_ptr != NULL) + { + /* Do this first in case of an error below; if the app implements its own + * memory management this can lead to png_free calling png_error, which + * will abort this routine and return control to the app error handler. + * An infinite loop may result if it then tries to free the same info + * ptr. + */ + *info_ptr_ptr = NULL; + + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + memset(info_ptr, 0, (sizeof *info_ptr)); + png_free(png_ptr, info_ptr); + } +} + +/* Initialize the info structure. This is now an internal function (0.89) + * and applications using it are urged to use png_create_info_struct() + * instead. Use deprecated in 1.6.0, internal use removed (used internally it + * is just a memset). + * + * NOTE: it is almost inconceivable that this API is used because it bypasses + * the user-memory mechanism and the user error handling/warning mechanisms in + * those cases where it does anything other than a memset. + */ +PNG_FUNCTION(void,PNGAPI +png_info_init_3,(png_infopp ptr_ptr, size_t png_info_struct_size), + PNG_DEPRECATED) +{ + png_inforp info_ptr = *ptr_ptr; + + png_debug(1, "in png_info_init_3"); + + if (info_ptr == NULL) + return; + + if ((sizeof (png_info)) > png_info_struct_size) + { + *ptr_ptr = NULL; + /* The following line is why this API should not be used: */ + free(info_ptr); + info_ptr = png_voidcast(png_inforp, png_malloc_base(NULL, + (sizeof *info_ptr))); + if (info_ptr == NULL) + return; + *ptr_ptr = info_ptr; + } + + /* Set everything to 0 */ + memset(info_ptr, 0, (sizeof *info_ptr)); +} + +/* The following API is not called internally */ +void PNGAPI +png_data_freer(png_const_structrp png_ptr, png_inforp info_ptr, + int freer, png_uint_32 mask) +{ + png_debug(1, "in png_data_freer"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (freer == PNG_DESTROY_WILL_FREE_DATA) + info_ptr->free_me |= mask; + + else if (freer == PNG_USER_WILL_FREE_DATA) + info_ptr->free_me &= ~mask; + + else + png_error(png_ptr, "Unknown freer parameter in png_data_freer"); +} + +void PNGAPI +png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, + int num) +{ + png_debug(1, "in png_free_data"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + +#ifdef PNG_TEXT_SUPPORTED + /* Free text item num or (if num == -1) all text items */ + if (info_ptr->text != NULL && + ((mask & PNG_FREE_TEXT) & info_ptr->free_me) != 0) + { + if (num != -1) + { + png_free(png_ptr, info_ptr->text[num].key); + info_ptr->text[num].key = NULL; + } + + else + { + int i; + + for (i = 0; i < info_ptr->num_text; i++) + png_free(png_ptr, info_ptr->text[i].key); + + png_free(png_ptr, info_ptr->text); + info_ptr->text = NULL; + info_ptr->num_text = 0; + info_ptr->max_text = 0; + } + } +#endif + +#ifdef PNG_tRNS_SUPPORTED + /* Free any tRNS entry */ + if (((mask & PNG_FREE_TRNS) & info_ptr->free_me) != 0) + { + info_ptr->valid &= ~PNG_INFO_tRNS; + png_free(png_ptr, info_ptr->trans_alpha); + info_ptr->trans_alpha = NULL; + info_ptr->num_trans = 0; + } +#endif + +#ifdef PNG_sCAL_SUPPORTED + /* Free any sCAL entry */ + if (((mask & PNG_FREE_SCAL) & info_ptr->free_me) != 0) + { + png_free(png_ptr, info_ptr->scal_s_width); + png_free(png_ptr, info_ptr->scal_s_height); + info_ptr->scal_s_width = NULL; + info_ptr->scal_s_height = NULL; + info_ptr->valid &= ~PNG_INFO_sCAL; + } +#endif + +#ifdef PNG_pCAL_SUPPORTED + /* Free any pCAL entry */ + if (((mask & PNG_FREE_PCAL) & info_ptr->free_me) != 0) + { + png_free(png_ptr, info_ptr->pcal_purpose); + png_free(png_ptr, info_ptr->pcal_units); + info_ptr->pcal_purpose = NULL; + info_ptr->pcal_units = NULL; + + if (info_ptr->pcal_params != NULL) + { + int i; + + for (i = 0; i < info_ptr->pcal_nparams; i++) + png_free(png_ptr, info_ptr->pcal_params[i]); + + png_free(png_ptr, info_ptr->pcal_params); + info_ptr->pcal_params = NULL; + } + info_ptr->valid &= ~PNG_INFO_pCAL; + } +#endif + +#ifdef PNG_iCCP_SUPPORTED + /* Free any profile entry */ + if (((mask & PNG_FREE_ICCP) & info_ptr->free_me) != 0) + { + png_free(png_ptr, info_ptr->iccp_name); + png_free(png_ptr, info_ptr->iccp_profile); + info_ptr->iccp_name = NULL; + info_ptr->iccp_profile = NULL; + info_ptr->valid &= ~PNG_INFO_iCCP; + } +#endif + +#ifdef PNG_sPLT_SUPPORTED + /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ + if (info_ptr->splt_palettes != NULL && + ((mask & PNG_FREE_SPLT) & info_ptr->free_me) != 0) + { + if (num != -1) + { + png_free(png_ptr, info_ptr->splt_palettes[num].name); + png_free(png_ptr, info_ptr->splt_palettes[num].entries); + info_ptr->splt_palettes[num].name = NULL; + info_ptr->splt_palettes[num].entries = NULL; + } + + else + { + int i; + + for (i = 0; i < info_ptr->splt_palettes_num; i++) + { + png_free(png_ptr, info_ptr->splt_palettes[i].name); + png_free(png_ptr, info_ptr->splt_palettes[i].entries); + } + + png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes = NULL; + info_ptr->splt_palettes_num = 0; + info_ptr->valid &= ~PNG_INFO_sPLT; + } + } +#endif + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED + if (info_ptr->unknown_chunks != NULL && + ((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0) + { + if (num != -1) + { + png_free(png_ptr, info_ptr->unknown_chunks[num].data); + info_ptr->unknown_chunks[num].data = NULL; + } + + else + { + int i; + + for (i = 0; i < info_ptr->unknown_chunks_num; i++) + png_free(png_ptr, info_ptr->unknown_chunks[i].data); + + png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks = NULL; + info_ptr->unknown_chunks_num = 0; + } + } +#endif + +#ifdef PNG_eXIf_SUPPORTED + /* Free any eXIf entry */ + if (((mask & PNG_FREE_EXIF) & info_ptr->free_me) != 0) + { +# ifdef PNG_READ_eXIf_SUPPORTED + if (info_ptr->eXIf_buf) + { + png_free(png_ptr, info_ptr->eXIf_buf); + info_ptr->eXIf_buf = NULL; + } +# endif + if (info_ptr->exif) + { + png_free(png_ptr, info_ptr->exif); + info_ptr->exif = NULL; + } + info_ptr->valid &= ~PNG_INFO_eXIf; + } +#endif + +#ifdef PNG_eXIf_SUPPORTED + /* Free any eXIf entry */ + if (((mask & PNG_FREE_EXIF) & info_ptr->free_me) != 0) + { +# ifdef PNG_READ_eXIf_SUPPORTED + if (info_ptr->eXIf_buf) + { + png_free(png_ptr, info_ptr->eXIf_buf); + info_ptr->eXIf_buf = NULL; + } +# endif + if (info_ptr->exif) + { + png_free(png_ptr, info_ptr->exif); + info_ptr->exif = NULL; + } + info_ptr->valid &= ~PNG_INFO_eXIf; + } +#endif + +#ifdef PNG_hIST_SUPPORTED + /* Free any hIST entry */ + if (((mask & PNG_FREE_HIST) & info_ptr->free_me) != 0) + { + png_free(png_ptr, info_ptr->hist); + info_ptr->hist = NULL; + info_ptr->valid &= ~PNG_INFO_hIST; + } +#endif + + /* Free any PLTE entry that was internally allocated */ + if (((mask & PNG_FREE_PLTE) & info_ptr->free_me) != 0) + { + png_free(png_ptr, info_ptr->palette); + info_ptr->palette = NULL; + info_ptr->valid &= ~PNG_INFO_PLTE; + info_ptr->num_palette = 0; + } + +#ifdef PNG_INFO_IMAGE_SUPPORTED + /* Free any image bits attached to the info structure */ + if (((mask & PNG_FREE_ROWS) & info_ptr->free_me) != 0) + { + if (info_ptr->row_pointers != NULL) + { + png_uint_32 row; + for (row = 0; row < info_ptr->height; row++) + png_free(png_ptr, info_ptr->row_pointers[row]); + + png_free(png_ptr, info_ptr->row_pointers); + info_ptr->row_pointers = NULL; + } + info_ptr->valid &= ~PNG_INFO_IDAT; + } +#endif + + if (num != -1) + mask &= ~PNG_FREE_MUL; + + info_ptr->free_me &= ~mask; +} +#endif /* READ || WRITE */ + +/* This function returns a pointer to the io_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy() or png_read_destroy() are called. + */ +png_voidp PNGAPI +png_get_io_ptr(png_const_structrp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + + return (png_ptr->io_ptr); +} + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +# ifdef PNG_STDIO_SUPPORTED +/* Initialize the default input/output functions for the PNG file. If you + * use your own read or write routines, you can call either png_set_read_fn() + * or png_set_write_fn() instead of png_init_io(). If you have defined + * PNG_NO_STDIO or otherwise disabled PNG_STDIO_SUPPORTED, you must use a + * function of your own because "FILE *" isn't necessarily available. + */ +void PNGAPI +png_init_io(png_structrp png_ptr, png_FILE_p fp) +{ + png_debug(1, "in png_init_io"); + + if (png_ptr == NULL) + return; + + png_ptr->io_ptr = (png_voidp)fp; +} +# endif + +# ifdef PNG_SAVE_INT_32_SUPPORTED +/* PNG signed integers are saved in 32-bit 2's complement format. ANSI C-90 + * defines a cast of a signed integer to an unsigned integer either to preserve + * the value, if it is positive, or to calculate: + * + * (UNSIGNED_MAX+1) + integer + * + * Where UNSIGNED_MAX is the appropriate maximum unsigned value, so when the + * negative integral value is added the result will be an unsigned value + * correspnding to the 2's complement representation. + */ +void PNGAPI +png_save_int_32(png_bytep buf, png_int_32 i) +{ + png_save_uint_32(buf, (png_uint_32)i); +} +# endif + +# ifdef PNG_TIME_RFC1123_SUPPORTED +/* Convert the supplied time into an RFC 1123 string suitable for use in + * a "Creation Time" or other text-based time string. + */ +int PNGAPI +png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime) +{ + static const char short_months[12][4] = + {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + + if (out == NULL) + return 0; + + if (ptime->year > 9999 /* RFC1123 limitation */ || + ptime->month == 0 || ptime->month > 12 || + ptime->day == 0 || ptime->day > 31 || + ptime->hour > 23 || ptime->minute > 59 || + ptime->second > 60) + return 0; + + { + size_t pos = 0; + char number_buf[5]; /* enough for a four-digit year */ + +# define APPEND_STRING(string) pos = png_safecat(out, 29, pos, (string)) +# define APPEND_NUMBER(format, value)\ + APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value))) +# define APPEND(ch) if (pos < 28) out[pos++] = (ch) + + APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day); + APPEND(' '); + APPEND_STRING(short_months[(ptime->month - 1)]); + APPEND(' '); + APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year); + APPEND(' '); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour); + APPEND(':'); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute); + APPEND(':'); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second); + APPEND_STRING(" +0000"); /* This reliably terminates the buffer */ + PNG_UNUSED (pos) + +# undef APPEND +# undef APPEND_NUMBER +# undef APPEND_STRING + } + + return 1; +} + +# if PNG_LIBPNG_VER < 10700 +/* To do: remove the following from libpng-1.7 */ +/* Original API that uses a private buffer in png_struct. + * Deprecated because it causes png_struct to carry a spurious temporary + * buffer (png_struct::time_buffer), better to have the caller pass this in. + */ +png_const_charp PNGAPI +png_convert_to_rfc1123(png_structrp png_ptr, png_const_timep ptime) +{ + if (png_ptr != NULL) + { + /* The only failure above if png_ptr != NULL is from an invalid ptime */ + if (png_convert_to_rfc1123_buffer(png_ptr->time_buffer, ptime) == 0) + png_warning(png_ptr, "Ignoring invalid time value"); + + else + return png_ptr->time_buffer; + } + + return NULL; +} +# endif /* LIBPNG_VER < 10700 */ +# endif /* TIME_RFC1123 */ + +#endif /* READ || WRITE */ + +png_const_charp PNGAPI +png_get_copyright(png_const_structrp png_ptr) +{ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ +#ifdef PNG_STRING_COPYRIGHT + return PNG_STRING_COPYRIGHT +#else + return PNG_STRING_NEWLINE \ + "libpng version 1.6.37" PNG_STRING_NEWLINE \ + "Copyright (c) 2018-2019 Cosmin Truta" PNG_STRING_NEWLINE \ + "Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson" \ + PNG_STRING_NEWLINE \ + "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ + "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ + PNG_STRING_NEWLINE; +#endif +} + +/* The following return the library version as a short string in the + * format 1.0.0 through 99.99.99zz. To get the version of *.h files + * used with your application, print out PNG_LIBPNG_VER_STRING, which + * is defined in png.h. + * Note: now there is no difference between png_get_libpng_ver() and + * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, + * it is guaranteed that png.c uses the correct version of png.h. + */ +png_const_charp PNGAPI +png_get_libpng_ver(png_const_structrp png_ptr) +{ + /* Version of *.c files used when building libpng */ + return png_get_header_ver(png_ptr); +} + +png_const_charp PNGAPI +png_get_header_ver(png_const_structrp png_ptr) +{ + /* Version of *.h files used when building libpng */ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ + return PNG_LIBPNG_VER_STRING; +} + +png_const_charp PNGAPI +png_get_header_version(png_const_structrp png_ptr) +{ + /* Returns longer string containing both version and date */ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ +#ifdef __STDC__ + return PNG_HEADER_VERSION_STRING +# ifndef PNG_READ_SUPPORTED + " (NO READ SUPPORT)" +# endif + PNG_STRING_NEWLINE; +#else + return PNG_HEADER_VERSION_STRING; +#endif +} + +#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +/* NOTE: this routine is not used internally! */ +/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth + * large of png_color. This lets grayscale images be treated as + * paletted. Most useful for gamma correction and simplification + * of code. This API is not used internally. + */ +void PNGAPI +png_build_grayscale_palette(int bit_depth, png_colorp palette) +{ + int num_palette; + int color_inc; + int i; + int v; + + png_debug(1, "in png_do_build_grayscale_palette"); + + if (palette == NULL) + return; + + switch (bit_depth) + { + case 1: + num_palette = 2; + color_inc = 0xff; + break; + + case 2: + num_palette = 4; + color_inc = 0x55; + break; + + case 4: + num_palette = 16; + color_inc = 0x11; + break; + + case 8: + num_palette = 256; + color_inc = 1; + break; + + default: + num_palette = 0; + color_inc = 0; + break; + } + + for (i = 0, v = 0; i < num_palette; i++, v += color_inc) + { + palette[i].red = (png_byte)(v & 0xff); + palette[i].green = (png_byte)(v & 0xff); + palette[i].blue = (png_byte)(v & 0xff); + } +} +#endif + +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED +int PNGAPI +png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name) +{ + /* Check chunk_name and return "keep" value if it's on the list, else 0 */ + png_const_bytep p, p_end; + + if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list == 0) + return PNG_HANDLE_CHUNK_AS_DEFAULT; + + p_end = png_ptr->chunk_list; + p = p_end + png_ptr->num_chunk_list*5; /* beyond end */ + + /* The code is the fifth byte after each four byte string. Historically this + * code was always searched from the end of the list, this is no longer + * necessary because the 'set' routine handles duplicate entries correctly. + */ + do /* num_chunk_list > 0, so at least one */ + { + p -= 5; + + if (memcmp(chunk_name, p, 4) == 0) + return p[4]; + } + while (p > p_end); + + /* This means that known chunks should be processed and unknown chunks should + * be handled according to the value of png_ptr->unknown_default; this can be + * confusing because, as a result, there are two levels of defaulting for + * unknown chunks. + */ + return PNG_HANDLE_CHUNK_AS_DEFAULT; +} + +#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\ + defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) +int /* PRIVATE */ +png_chunk_unknown_handling(png_const_structrp png_ptr, png_uint_32 chunk_name) +{ + png_byte chunk_string[5]; + + PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name); + return png_handle_as_unknown(png_ptr, chunk_string); +} +#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */ +#endif /* SET_UNKNOWN_CHUNKS */ + +#ifdef PNG_READ_SUPPORTED +/* This function, added to libpng-1.0.6g, is untested. */ +int PNGAPI +png_reset_zstream(png_structrp png_ptr) +{ + if (png_ptr == NULL) + return Z_STREAM_ERROR; + + /* WARNING: this resets the window bits to the maximum! */ + return (inflateReset(&png_ptr->zstream)); +} +#endif /* READ */ + +/* This function was added to libpng-1.0.7 */ +png_uint_32 PNGAPI +png_access_version_number(void) +{ + /* Version of *.c files used when building libpng */ + return((png_uint_32)PNG_LIBPNG_VER); +} + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +/* Ensure that png_ptr->zstream.msg holds some appropriate error message string. + * If it doesn't 'ret' is used to set it to something appropriate, even in cases + * like Z_OK or Z_STREAM_END where the error code is apparently a success code. + */ +void /* PRIVATE */ +png_zstream_error(png_structrp png_ptr, int ret) +{ + /* Translate 'ret' into an appropriate error string, priority is given to the + * one in zstream if set. This always returns a string, even in cases like + * Z_OK or Z_STREAM_END where the error code is a success code. + */ + if (png_ptr->zstream.msg == NULL) switch (ret) + { + default: + case Z_OK: + png_ptr->zstream.msg = PNGZ_MSG_CAST("unexpected zlib return code"); + break; + + case Z_STREAM_END: + /* Normal exit */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("unexpected end of LZ stream"); + break; + + case Z_NEED_DICT: + /* This means the deflate stream did not have a dictionary; this + * indicates a bogus PNG. + */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("missing LZ dictionary"); + break; + + case Z_ERRNO: + /* gz APIs only: should not happen */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("zlib IO error"); + break; + + case Z_STREAM_ERROR: + /* internal libpng error */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("bad parameters to zlib"); + break; + + case Z_DATA_ERROR: + png_ptr->zstream.msg = PNGZ_MSG_CAST("damaged LZ stream"); + break; + + case Z_MEM_ERROR: + png_ptr->zstream.msg = PNGZ_MSG_CAST("insufficient memory"); + break; + + case Z_BUF_ERROR: + /* End of input or output; not a problem if the caller is doing + * incremental read or write. + */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("truncated"); + break; + + case Z_VERSION_ERROR: + png_ptr->zstream.msg = PNGZ_MSG_CAST("unsupported zlib version"); + break; + + case PNG_UNEXPECTED_ZLIB_RETURN: + /* Compile errors here mean that zlib now uses the value co-opted in + * pngpriv.h for PNG_UNEXPECTED_ZLIB_RETURN; update the switch above + * and change pngpriv.h. Note that this message is "... return", + * whereas the default/Z_OK one is "... return code". + */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("unexpected zlib return"); + break; + } +} + +/* png_convert_size: a PNGAPI but no longer in png.h, so deleted + * at libpng 1.5.5! + */ + +/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ +#ifdef PNG_GAMMA_SUPPORTED /* always set if COLORSPACE */ +static int +png_colorspace_check_gamma(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_fixed_point gAMA, int from) + /* This is called to check a new gamma value against an existing one. The + * routine returns false if the new gamma value should not be written. + * + * 'from' says where the new gamma value comes from: + * + * 0: the new gamma value is the libpng estimate for an ICC profile + * 1: the new gamma value comes from a gAMA chunk + * 2: the new gamma value comes from an sRGB chunk + */ +{ + png_fixed_point gtest; + + if ((colorspace->flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && + (png_muldiv(>est, colorspace->gamma, PNG_FP_1, gAMA) == 0 || + png_gamma_significant(gtest) != 0)) + { + /* Either this is an sRGB image, in which case the calculated gamma + * approximation should match, or this is an image with a profile and the + * value libpng calculates for the gamma of the profile does not match the + * value recorded in the file. The former, sRGB, case is an error, the + * latter is just a warning. + */ + if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0 || from == 2) + { + png_chunk_report(png_ptr, "gamma value does not match sRGB", + PNG_CHUNK_ERROR); + /* Do not overwrite an sRGB value */ + return from == 2; + } + + else /* sRGB tag not involved */ + { + png_chunk_report(png_ptr, "gamma value does not match libpng estimate", + PNG_CHUNK_WARNING); + return from == 1; + } + } + + return 1; +} + +void /* PRIVATE */ +png_colorspace_set_gamma(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_fixed_point gAMA) +{ + /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't + * occur. Since the fixed point representation is asymmetrical it is + * possible for 1/gamma to overflow the limit of 21474 and this means the + * gamma value must be at least 5/100000 and hence at most 20000.0. For + * safety the limits here are a little narrower. The values are 0.00016 to + * 6250.0, which are truly ridiculous gamma values (and will produce + * displays that are all black or all white.) + * + * In 1.6.0 this test replaces the ones in pngrutil.c, in the gAMA chunk + * handling code, which only required the value to be >0. + */ + png_const_charp errmsg; + + if (gAMA < 16 || gAMA > 625000000) + errmsg = "gamma value out of range"; + +# ifdef PNG_READ_gAMA_SUPPORTED + /* Allow the application to set the gamma value more than once */ + else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0) + errmsg = "duplicate"; +# endif + + /* Do nothing if the colorspace is already invalid */ + else if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) + return; + + else + { + if (png_colorspace_check_gamma(png_ptr, colorspace, gAMA, + 1/*from gAMA*/) != 0) + { + /* Store this gamma value. */ + colorspace->gamma = gAMA; + colorspace->flags |= + (PNG_COLORSPACE_HAVE_GAMMA | PNG_COLORSPACE_FROM_gAMA); + } + + /* At present if the check_gamma test fails the gamma of the colorspace is + * not updated however the colorspace is not invalidated. This + * corresponds to the case where the existing gamma comes from an sRGB + * chunk or profile. An error message has already been output. + */ + return; + } + + /* Error exit - errmsg has been set. */ + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_chunk_report(png_ptr, errmsg, PNG_CHUNK_WRITE_ERROR); +} + +void /* PRIVATE */ +png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr) +{ + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0) + { + /* Everything is invalid */ + info_ptr->valid &= ~(PNG_INFO_gAMA|PNG_INFO_cHRM|PNG_INFO_sRGB| + PNG_INFO_iCCP); + +# ifdef PNG_COLORSPACE_SUPPORTED + /* Clean up the iCCP profile now if it won't be used. */ + png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/); +# else + PNG_UNUSED(png_ptr) +# endif + } + + else + { +# ifdef PNG_COLORSPACE_SUPPORTED + /* Leave the INFO_iCCP flag set if the pngset.c code has already set + * it; this allows a PNG to contain a profile which matches sRGB and + * yet still have that profile retrievable by the application. + */ + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB) != 0) + info_ptr->valid |= PNG_INFO_sRGB; + + else + info_ptr->valid &= ~PNG_INFO_sRGB; + + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + info_ptr->valid |= PNG_INFO_cHRM; + + else + info_ptr->valid &= ~PNG_INFO_cHRM; +# endif + + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0) + info_ptr->valid |= PNG_INFO_gAMA; + + else + info_ptr->valid &= ~PNG_INFO_gAMA; + } +} + +#ifdef PNG_READ_SUPPORTED +void /* PRIVATE */ +png_colorspace_sync(png_const_structrp png_ptr, png_inforp info_ptr) +{ + if (info_ptr == NULL) /* reduce code size; check here not in the caller */ + return; + + info_ptr->colorspace = png_ptr->colorspace; + png_colorspace_sync_info(png_ptr, info_ptr); +} +#endif +#endif /* GAMMA */ + +#ifdef PNG_COLORSPACE_SUPPORTED +/* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for + * cHRM, as opposed to using chromaticities. These internal APIs return + * non-zero on a parameter error. The X, Y and Z values are required to be + * positive and less than 1.0. + */ +static int +png_xy_from_XYZ(png_xy *xy, const png_XYZ *XYZ) +{ + png_int_32 d, dwhite, whiteX, whiteY; + + d = XYZ->red_X + XYZ->red_Y + XYZ->red_Z; + if (png_muldiv(&xy->redx, XYZ->red_X, PNG_FP_1, d) == 0) + return 1; + if (png_muldiv(&xy->redy, XYZ->red_Y, PNG_FP_1, d) == 0) + return 1; + dwhite = d; + whiteX = XYZ->red_X; + whiteY = XYZ->red_Y; + + d = XYZ->green_X + XYZ->green_Y + XYZ->green_Z; + if (png_muldiv(&xy->greenx, XYZ->green_X, PNG_FP_1, d) == 0) + return 1; + if (png_muldiv(&xy->greeny, XYZ->green_Y, PNG_FP_1, d) == 0) + return 1; + dwhite += d; + whiteX += XYZ->green_X; + whiteY += XYZ->green_Y; + + d = XYZ->blue_X + XYZ->blue_Y + XYZ->blue_Z; + if (png_muldiv(&xy->bluex, XYZ->blue_X, PNG_FP_1, d) == 0) + return 1; + if (png_muldiv(&xy->bluey, XYZ->blue_Y, PNG_FP_1, d) == 0) + return 1; + dwhite += d; + whiteX += XYZ->blue_X; + whiteY += XYZ->blue_Y; + + /* The reference white is simply the sum of the end-point (X,Y,Z) vectors, + * thus: + */ + if (png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite) == 0) + return 1; + if (png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite) == 0) + return 1; + + return 0; +} + +static int +png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy) +{ + png_fixed_point red_inverse, green_inverse, blue_scale; + png_fixed_point left, right, denominator; + + /* Check xy and, implicitly, z. Note that wide gamut color spaces typically + * have end points with 0 tristimulus values (these are impossible end + * points, but they are used to cover the possible colors). We check + * xy->whitey against 5, not 0, to avoid a possible integer overflow. + */ + if (xy->redx < 0 || xy->redx > PNG_FP_1) return 1; + if (xy->redy < 0 || xy->redy > PNG_FP_1-xy->redx) return 1; + if (xy->greenx < 0 || xy->greenx > PNG_FP_1) return 1; + if (xy->greeny < 0 || xy->greeny > PNG_FP_1-xy->greenx) return 1; + if (xy->bluex < 0 || xy->bluex > PNG_FP_1) return 1; + if (xy->bluey < 0 || xy->bluey > PNG_FP_1-xy->bluex) return 1; + if (xy->whitex < 0 || xy->whitex > PNG_FP_1) return 1; + if (xy->whitey < 5 || xy->whitey > PNG_FP_1-xy->whitex) return 1; + + /* The reverse calculation is more difficult because the original tristimulus + * value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8 + * derived values were recorded in the cHRM chunk; + * (red,green,blue,white)x(x,y). This loses one degree of freedom and + * therefore an arbitrary ninth value has to be introduced to undo the + * original transformations. + * + * Think of the original end-points as points in (X,Y,Z) space. The + * chromaticity values (c) have the property: + * + * C + * c = --------- + * X + Y + Z + * + * For each c (x,y,z) from the corresponding original C (X,Y,Z). Thus the + * three chromaticity values (x,y,z) for each end-point obey the + * relationship: + * + * x + y + z = 1 + * + * This describes the plane in (X,Y,Z) space that intersects each axis at the + * value 1.0; call this the chromaticity plane. Thus the chromaticity + * calculation has scaled each end-point so that it is on the x+y+z=1 plane + * and chromaticity is the intersection of the vector from the origin to the + * (X,Y,Z) value with the chromaticity plane. + * + * To fully invert the chromaticity calculation we would need the three + * end-point scale factors, (red-scale, green-scale, blue-scale), but these + * were not recorded. Instead we calculated the reference white (X,Y,Z) and + * recorded the chromaticity of this. The reference white (X,Y,Z) would have + * given all three of the scale factors since: + * + * color-C = color-c * color-scale + * white-C = red-C + green-C + blue-C + * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale + * + * But cHRM records only white-x and white-y, so we have lost the white scale + * factor: + * + * white-C = white-c*white-scale + * + * To handle this the inverse transformation makes an arbitrary assumption + * about white-scale: + * + * Assume: white-Y = 1.0 + * Hence: white-scale = 1/white-y + * Or: red-Y + green-Y + blue-Y = 1.0 + * + * Notice the last statement of the assumption gives an equation in three of + * the nine values we want to calculate. 8 more equations come from the + * above routine as summarised at the top above (the chromaticity + * calculation): + * + * Given: color-x = color-X / (color-X + color-Y + color-Z) + * Hence: (color-x - 1)*color-X + color.x*color-Y + color.x*color-Z = 0 + * + * This is 9 simultaneous equations in the 9 variables "color-C" and can be + * solved by Cramer's rule. Cramer's rule requires calculating 10 9x9 matrix + * determinants, however this is not as bad as it seems because only 28 of + * the total of 90 terms in the various matrices are non-zero. Nevertheless + * Cramer's rule is notoriously numerically unstable because the determinant + * calculation involves the difference of large, but similar, numbers. It is + * difficult to be sure that the calculation is stable for real world values + * and it is certain that it becomes unstable where the end points are close + * together. + * + * So this code uses the perhaps slightly less optimal but more + * understandable and totally obvious approach of calculating color-scale. + * + * This algorithm depends on the precision in white-scale and that is + * (1/white-y), so we can immediately see that as white-y approaches 0 the + * accuracy inherent in the cHRM chunk drops off substantially. + * + * libpng arithmetic: a simple inversion of the above equations + * ------------------------------------------------------------ + * + * white_scale = 1/white-y + * white-X = white-x * white-scale + * white-Y = 1.0 + * white-Z = (1 - white-x - white-y) * white_scale + * + * white-C = red-C + green-C + blue-C + * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale + * + * This gives us three equations in (red-scale,green-scale,blue-scale) where + * all the coefficients are now known: + * + * red-x*red-scale + green-x*green-scale + blue-x*blue-scale + * = white-x/white-y + * red-y*red-scale + green-y*green-scale + blue-y*blue-scale = 1 + * red-z*red-scale + green-z*green-scale + blue-z*blue-scale + * = (1 - white-x - white-y)/white-y + * + * In the last equation color-z is (1 - color-x - color-y) so we can add all + * three equations together to get an alternative third: + * + * red-scale + green-scale + blue-scale = 1/white-y = white-scale + * + * So now we have a Cramer's rule solution where the determinants are just + * 3x3 - far more tractible. Unfortunately 3x3 determinants still involve + * multiplication of three coefficients so we can't guarantee to avoid + * overflow in the libpng fixed point representation. Using Cramer's rule in + * floating point is probably a good choice here, but it's not an option for + * fixed point. Instead proceed to simplify the first two equations by + * eliminating what is likely to be the largest value, blue-scale: + * + * blue-scale = white-scale - red-scale - green-scale + * + * Hence: + * + * (red-x - blue-x)*red-scale + (green-x - blue-x)*green-scale = + * (white-x - blue-x)*white-scale + * + * (red-y - blue-y)*red-scale + (green-y - blue-y)*green-scale = + * 1 - blue-y*white-scale + * + * And now we can trivially solve for (red-scale,green-scale): + * + * green-scale = + * (white-x - blue-x)*white-scale - (red-x - blue-x)*red-scale + * ----------------------------------------------------------- + * green-x - blue-x + * + * red-scale = + * 1 - blue-y*white-scale - (green-y - blue-y) * green-scale + * --------------------------------------------------------- + * red-y - blue-y + * + * Hence: + * + * red-scale = + * ( (green-x - blue-x) * (white-y - blue-y) - + * (green-y - blue-y) * (white-x - blue-x) ) / white-y + * ------------------------------------------------------------------------- + * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x) + * + * green-scale = + * ( (red-y - blue-y) * (white-x - blue-x) - + * (red-x - blue-x) * (white-y - blue-y) ) / white-y + * ------------------------------------------------------------------------- + * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x) + * + * Accuracy: + * The input values have 5 decimal digits of accuracy. The values are all in + * the range 0 < value < 1, so simple products are in the same range but may + * need up to 10 decimal digits to preserve the original precision and avoid + * underflow. Because we are using a 32-bit signed representation we cannot + * match this; the best is a little over 9 decimal digits, less than 10. + * + * The approach used here is to preserve the maximum precision within the + * signed representation. Because the red-scale calculation above uses the + * difference between two products of values that must be in the range -1..+1 + * it is sufficient to divide the product by 7; ceil(100,000/32767*2). The + * factor is irrelevant in the calculation because it is applied to both + * numerator and denominator. + * + * Note that the values of the differences of the products of the + * chromaticities in the above equations tend to be small, for example for + * the sRGB chromaticities they are: + * + * red numerator: -0.04751 + * green numerator: -0.08788 + * denominator: -0.2241 (without white-y multiplication) + * + * The resultant Y coefficients from the chromaticities of some widely used + * color space definitions are (to 15 decimal places): + * + * sRGB + * 0.212639005871510 0.715168678767756 0.072192315360734 + * Kodak ProPhoto + * 0.288071128229293 0.711843217810102 0.000085653960605 + * Adobe RGB + * 0.297344975250536 0.627363566255466 0.075291458493998 + * Adobe Wide Gamut RGB + * 0.258728243040113 0.724682314948566 0.016589442011321 + */ + /* By the argument, above overflow should be impossible here. The return + * value of 2 indicates an internal error to the caller. + */ + if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 7) == 0) + return 2; + if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 7) == 0) + return 2; + denominator = left - right; + + /* Now find the red numerator. */ + if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 7) == 0) + return 2; + if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 7) == 0) + return 2; + + /* Overflow is possible here and it indicates an extreme set of PNG cHRM + * chunk values. This calculation actually returns the reciprocal of the + * scale value because this allows us to delay the multiplication of white-y + * into the denominator, which tends to produce a small number. + */ + if (png_muldiv(&red_inverse, xy->whitey, denominator, left-right) == 0 || + red_inverse <= xy->whitey /* r+g+b scales = white scale */) + return 1; + + /* Similarly for green_inverse: */ + if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 7) == 0) + return 2; + if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 7) == 0) + return 2; + if (png_muldiv(&green_inverse, xy->whitey, denominator, left-right) == 0 || + green_inverse <= xy->whitey) + return 1; + + /* And the blue scale, the checks above guarantee this can't overflow but it + * can still produce 0 for extreme cHRM values. + */ + blue_scale = png_reciprocal(xy->whitey) - png_reciprocal(red_inverse) - + png_reciprocal(green_inverse); + if (blue_scale <= 0) + return 1; + + + /* And fill in the png_XYZ: */ + if (png_muldiv(&XYZ->red_X, xy->redx, PNG_FP_1, red_inverse) == 0) + return 1; + if (png_muldiv(&XYZ->red_Y, xy->redy, PNG_FP_1, red_inverse) == 0) + return 1; + if (png_muldiv(&XYZ->red_Z, PNG_FP_1 - xy->redx - xy->redy, PNG_FP_1, + red_inverse) == 0) + return 1; + + if (png_muldiv(&XYZ->green_X, xy->greenx, PNG_FP_1, green_inverse) == 0) + return 1; + if (png_muldiv(&XYZ->green_Y, xy->greeny, PNG_FP_1, green_inverse) == 0) + return 1; + if (png_muldiv(&XYZ->green_Z, PNG_FP_1 - xy->greenx - xy->greeny, PNG_FP_1, + green_inverse) == 0) + return 1; + + if (png_muldiv(&XYZ->blue_X, xy->bluex, blue_scale, PNG_FP_1) == 0) + return 1; + if (png_muldiv(&XYZ->blue_Y, xy->bluey, blue_scale, PNG_FP_1) == 0) + return 1; + if (png_muldiv(&XYZ->blue_Z, PNG_FP_1 - xy->bluex - xy->bluey, blue_scale, + PNG_FP_1) == 0) + return 1; + + return 0; /*success*/ +} + +static int +png_XYZ_normalize(png_XYZ *XYZ) +{ + png_int_32 Y; + + if (XYZ->red_Y < 0 || XYZ->green_Y < 0 || XYZ->blue_Y < 0 || + XYZ->red_X < 0 || XYZ->green_X < 0 || XYZ->blue_X < 0 || + XYZ->red_Z < 0 || XYZ->green_Z < 0 || XYZ->blue_Z < 0) + return 1; + + /* Normalize by scaling so the sum of the end-point Y values is PNG_FP_1. + * IMPLEMENTATION NOTE: ANSI requires signed overflow not to occur, therefore + * relying on addition of two positive values producing a negative one is not + * safe. + */ + Y = XYZ->red_Y; + if (0x7fffffff - Y < XYZ->green_X) + return 1; + Y += XYZ->green_Y; + if (0x7fffffff - Y < XYZ->blue_X) + return 1; + Y += XYZ->blue_Y; + + if (Y != PNG_FP_1) + { + if (png_muldiv(&XYZ->red_X, XYZ->red_X, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->red_Y, XYZ->red_Y, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->red_Z, XYZ->red_Z, PNG_FP_1, Y) == 0) + return 1; + + if (png_muldiv(&XYZ->green_X, XYZ->green_X, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->green_Y, XYZ->green_Y, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->green_Z, XYZ->green_Z, PNG_FP_1, Y) == 0) + return 1; + + if (png_muldiv(&XYZ->blue_X, XYZ->blue_X, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->blue_Y, XYZ->blue_Y, PNG_FP_1, Y) == 0) + return 1; + if (png_muldiv(&XYZ->blue_Z, XYZ->blue_Z, PNG_FP_1, Y) == 0) + return 1; + } + + return 0; +} + +static int +png_colorspace_endpoints_match(const png_xy *xy1, const png_xy *xy2, int delta) +{ + /* Allow an error of +/-0.01 (absolute value) on each chromaticity */ + if (PNG_OUT_OF_RANGE(xy1->whitex, xy2->whitex,delta) || + PNG_OUT_OF_RANGE(xy1->whitey, xy2->whitey,delta) || + PNG_OUT_OF_RANGE(xy1->redx, xy2->redx, delta) || + PNG_OUT_OF_RANGE(xy1->redy, xy2->redy, delta) || + PNG_OUT_OF_RANGE(xy1->greenx, xy2->greenx,delta) || + PNG_OUT_OF_RANGE(xy1->greeny, xy2->greeny,delta) || + PNG_OUT_OF_RANGE(xy1->bluex, xy2->bluex, delta) || + PNG_OUT_OF_RANGE(xy1->bluey, xy2->bluey, delta)) + return 0; + return 1; +} + +/* Added in libpng-1.6.0, a different check for the validity of a set of cHRM + * chunk chromaticities. Earlier checks used to simply look for the overflow + * condition (where the determinant of the matrix to solve for XYZ ends up zero + * because the chromaticity values are not all distinct.) Despite this it is + * theoretically possible to produce chromaticities that are apparently valid + * but that rapidly degrade to invalid, potentially crashing, sets because of + * arithmetic inaccuracies when calculations are performed on them. The new + * check is to round-trip xy -> XYZ -> xy and then check that the result is + * within a small percentage of the original. + */ +static int +png_colorspace_check_xy(png_XYZ *XYZ, const png_xy *xy) +{ + int result; + png_xy xy_test; + + /* As a side-effect this routine also returns the XYZ endpoints. */ + result = png_XYZ_from_xy(XYZ, xy); + if (result != 0) + return result; + + result = png_xy_from_XYZ(&xy_test, XYZ); + if (result != 0) + return result; + + if (png_colorspace_endpoints_match(xy, &xy_test, + 5/*actually, the math is pretty accurate*/) != 0) + return 0; + + /* Too much slip */ + return 1; +} + +/* This is the check going the other way. The XYZ is modified to normalize it + * (another side-effect) and the xy chromaticities are returned. + */ +static int +png_colorspace_check_XYZ(png_xy *xy, png_XYZ *XYZ) +{ + int result; + png_XYZ XYZtemp; + + result = png_XYZ_normalize(XYZ); + if (result != 0) + return result; + + result = png_xy_from_XYZ(xy, XYZ); + if (result != 0) + return result; + + XYZtemp = *XYZ; + return png_colorspace_check_xy(&XYZtemp, xy); +} + +/* Used to check for an endpoint match against sRGB */ +static const png_xy sRGB_xy = /* From ITU-R BT.709-3 */ +{ + /* color x y */ + /* red */ 64000, 33000, + /* green */ 30000, 60000, + /* blue */ 15000, 6000, + /* white */ 31270, 32900 +}; + +static int +png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr, + png_colorspacerp colorspace, const png_xy *xy, const png_XYZ *XYZ, + int preferred) +{ + if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) + return 0; + + /* The consistency check is performed on the chromaticities; this factors out + * variations because of the normalization (or not) of the end point Y + * values. + */ + if (preferred < 2 && + (colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + /* The end points must be reasonably close to any we already have. The + * following allows an error of up to +/-.001 + */ + if (png_colorspace_endpoints_match(xy, &colorspace->end_points_xy, + 100) == 0) + { + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_benign_error(png_ptr, "inconsistent chromaticities"); + return 0; /* failed */ + } + + /* Only overwrite with preferred values */ + if (preferred == 0) + return 1; /* ok, but no change */ + } + + colorspace->end_points_xy = *xy; + colorspace->end_points_XYZ = *XYZ; + colorspace->flags |= PNG_COLORSPACE_HAVE_ENDPOINTS; + + /* The end points are normally quoted to two decimal digits, so allow +/-0.01 + * on this test. + */ + if (png_colorspace_endpoints_match(xy, &sRGB_xy, 1000) != 0) + colorspace->flags |= PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB; + + else + colorspace->flags &= PNG_COLORSPACE_CANCEL( + PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB); + + return 2; /* ok and changed */ +} + +int /* PRIVATE */ +png_colorspace_set_chromaticities(png_const_structrp png_ptr, + png_colorspacerp colorspace, const png_xy *xy, int preferred) +{ + /* We must check the end points to ensure they are reasonable - in the past + * color management systems have crashed as a result of getting bogus + * colorant values, while this isn't the fault of libpng it is the + * responsibility of libpng because PNG carries the bomb and libpng is in a + * position to protect against it. + */ + png_XYZ XYZ; + + switch (png_colorspace_check_xy(&XYZ, xy)) + { + case 0: /* success */ + return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, xy, &XYZ, + preferred); + + case 1: + /* We can't invert the chromaticities so we can't produce value XYZ + * values. Likely as not a color management system will fail too. + */ + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_benign_error(png_ptr, "invalid chromaticities"); + break; + + default: + /* libpng is broken; this should be a warning but if it happens we + * want error reports so for the moment it is an error. + */ + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_error(png_ptr, "internal error checking chromaticities"); + } + + return 0; /* failed */ +} + +int /* PRIVATE */ +png_colorspace_set_endpoints(png_const_structrp png_ptr, + png_colorspacerp colorspace, const png_XYZ *XYZ_in, int preferred) +{ + png_XYZ XYZ = *XYZ_in; + png_xy xy; + + switch (png_colorspace_check_XYZ(&xy, &XYZ)) + { + case 0: + return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, &xy, &XYZ, + preferred); + + case 1: + /* End points are invalid. */ + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_benign_error(png_ptr, "invalid end points"); + break; + + default: + colorspace->flags |= PNG_COLORSPACE_INVALID; + png_error(png_ptr, "internal error checking chromaticities"); + } + + return 0; /* failed */ +} + +#if defined(PNG_sRGB_SUPPORTED) || defined(PNG_iCCP_SUPPORTED) +/* Error message generation */ +static char +png_icc_tag_char(png_uint_32 byte) +{ + byte &= 0xff; + if (byte >= 32 && byte <= 126) + return (char)byte; + else + return '?'; +} + +static void +png_icc_tag_name(char *name, png_uint_32 tag) +{ + name[0] = '\''; + name[1] = png_icc_tag_char(tag >> 24); + name[2] = png_icc_tag_char(tag >> 16); + name[3] = png_icc_tag_char(tag >> 8); + name[4] = png_icc_tag_char(tag ); + name[5] = '\''; +} + +static int +is_ICC_signature_char(png_alloc_size_t it) +{ + return it == 32 || (it >= 48 && it <= 57) || (it >= 65 && it <= 90) || + (it >= 97 && it <= 122); +} + +static int +is_ICC_signature(png_alloc_size_t it) +{ + return is_ICC_signature_char(it >> 24) /* checks all the top bits */ && + is_ICC_signature_char((it >> 16) & 0xff) && + is_ICC_signature_char((it >> 8) & 0xff) && + is_ICC_signature_char(it & 0xff); +} + +static int +png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_alloc_size_t value, png_const_charp reason) +{ + size_t pos; + char message[196]; /* see below for calculation */ + + if (colorspace != NULL) + colorspace->flags |= PNG_COLORSPACE_INVALID; + + pos = png_safecat(message, (sizeof message), 0, "profile '"); /* 9 chars */ + pos = png_safecat(message, pos+79, pos, name); /* Truncate to 79 chars */ + pos = png_safecat(message, (sizeof message), pos, "': "); /* +2 = 90 */ + if (is_ICC_signature(value) != 0) + { + /* So 'value' is at most 4 bytes and the following cast is safe */ + png_icc_tag_name(message+pos, (png_uint_32)value); + pos += 6; /* total +8; less than the else clause */ + message[pos++] = ':'; + message[pos++] = ' '; + } +# ifdef PNG_WARNINGS_SUPPORTED + else + { + char number[PNG_NUMBER_BUFFER_SIZE]; /* +24 = 114*/ + + pos = png_safecat(message, (sizeof message), pos, + png_format_number(number, number+(sizeof number), + PNG_NUMBER_FORMAT_x, value)); + pos = png_safecat(message, (sizeof message), pos, "h: "); /*+2 = 116*/ + } +# endif + /* The 'reason' is an arbitrary message, allow +79 maximum 195 */ + pos = png_safecat(message, (sizeof message), pos, reason); + PNG_UNUSED(pos) + + /* This is recoverable, but make it unconditionally an app_error on write to + * avoid writing invalid ICC profiles into PNG files (i.e., we handle them + * on read, with a warning, but on write unless the app turns off + * application errors the PNG won't be written.) + */ + png_chunk_report(png_ptr, message, + (colorspace != NULL) ? PNG_CHUNK_ERROR : PNG_CHUNK_WRITE_ERROR); + + return 0; +} +#endif /* sRGB || iCCP */ + +#ifdef PNG_sRGB_SUPPORTED +int /* PRIVATE */ +png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace, + int intent) +{ + /* sRGB sets known gamma, end points and (from the chunk) intent. */ + /* IMPORTANT: these are not necessarily the values found in an ICC profile + * because ICC profiles store values adapted to a D50 environment; it is + * expected that the ICC profile mediaWhitePointTag will be D50; see the + * checks and code elsewhere to understand this better. + * + * These XYZ values, which are accurate to 5dp, produce rgb to gray + * coefficients of (6968,23435,2366), which are reduced (because they add up + * to 32769 not 32768) to (6968,23434,2366). These are the values that + * libpng has traditionally used (and are the best values given the 15bit + * algorithm used by the rgb to gray code.) + */ + static const png_XYZ sRGB_XYZ = /* D65 XYZ (*not* the D50 adapted values!) */ + { + /* color X Y Z */ + /* red */ 41239, 21264, 1933, + /* green */ 35758, 71517, 11919, + /* blue */ 18048, 7219, 95053 + }; + + /* Do nothing if the colorspace is already invalidated. */ + if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) + return 0; + + /* Check the intent, then check for existing settings. It is valid for the + * PNG file to have cHRM or gAMA chunks along with sRGB, but the values must + * be consistent with the correct values. If, however, this function is + * called below because an iCCP chunk matches sRGB then it is quite + * conceivable that an older app recorded incorrect gAMA and cHRM because of + * an incorrect calculation based on the values in the profile - this does + * *not* invalidate the profile (though it still produces an error, which can + * be ignored.) + */ + if (intent < 0 || intent >= PNG_sRGB_INTENT_LAST) + return png_icc_profile_error(png_ptr, colorspace, "sRGB", + (png_alloc_size_t)intent, "invalid sRGB rendering intent"); + + if ((colorspace->flags & PNG_COLORSPACE_HAVE_INTENT) != 0 && + colorspace->rendering_intent != intent) + return png_icc_profile_error(png_ptr, colorspace, "sRGB", + (png_alloc_size_t)intent, "inconsistent rendering intents"); + + if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0) + { + png_benign_error(png_ptr, "duplicate sRGB information ignored"); + return 0; + } + + /* If the standard sRGB cHRM chunk does not match the one from the PNG file + * warn but overwrite the value with the correct one. + */ + if ((colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0 && + !png_colorspace_endpoints_match(&sRGB_xy, &colorspace->end_points_xy, + 100)) + png_chunk_report(png_ptr, "cHRM chunk does not match sRGB", + PNG_CHUNK_ERROR); + + /* This check is just done for the error reporting - the routine always + * returns true when the 'from' argument corresponds to sRGB (2). + */ + (void)png_colorspace_check_gamma(png_ptr, colorspace, PNG_GAMMA_sRGB_INVERSE, + 2/*from sRGB*/); + + /* intent: bugs in GCC force 'int' to be used as the parameter type. */ + colorspace->rendering_intent = (png_uint_16)intent; + colorspace->flags |= PNG_COLORSPACE_HAVE_INTENT; + + /* endpoints */ + colorspace->end_points_xy = sRGB_xy; + colorspace->end_points_XYZ = sRGB_XYZ; + colorspace->flags |= + (PNG_COLORSPACE_HAVE_ENDPOINTS|PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB); + + /* gamma */ + colorspace->gamma = PNG_GAMMA_sRGB_INVERSE; + colorspace->flags |= PNG_COLORSPACE_HAVE_GAMMA; + + /* Finally record that we have an sRGB profile */ + colorspace->flags |= + (PNG_COLORSPACE_MATCHES_sRGB|PNG_COLORSPACE_FROM_sRGB); + + return 1; /* set */ +} +#endif /* sRGB */ + +#ifdef PNG_iCCP_SUPPORTED +/* Encoded value of D50 as an ICC XYZNumber. From the ICC 2010 spec the value + * is XYZ(0.9642,1.0,0.8249), which scales to: + * + * (63189.8112, 65536, 54060.6464) + */ +static const png_byte D50_nCIEXYZ[12] = + { 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d }; + +static int /* bool */ +icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length) +{ + if (profile_length < 132) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "too short"); + return 1; +} + +#ifdef PNG_READ_iCCP_SUPPORTED +int /* PRIVATE */ +png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length) +{ + if (!icc_check_length(png_ptr, colorspace, name, profile_length)) + return 0; + + /* This needs to be here because the 'normal' check is in + * png_decompress_chunk, yet this happens after the attempt to + * png_malloc_base the required data. We only need this on read; on write + * the caller supplies the profile buffer so libpng doesn't allocate it. See + * the call to icc_check_length below (the write case). + */ +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + else if (png_ptr->user_chunk_malloc_max > 0 && + png_ptr->user_chunk_malloc_max < profile_length) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "exceeds application limits"); +# elif PNG_USER_CHUNK_MALLOC_MAX > 0 + else if (PNG_USER_CHUNK_MALLOC_MAX < profile_length) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "exceeds libpng limits"); +# else /* !SET_USER_LIMITS */ + /* This will get compiled out on all 32-bit and better systems. */ + else if (PNG_SIZE_MAX < profile_length) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "exceeds system limits"); +# endif /* !SET_USER_LIMITS */ + + return 1; +} +#endif /* READ_iCCP */ + +int /* PRIVATE */ +png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length, + png_const_bytep profile/* first 132 bytes only */, int color_type) +{ + png_uint_32 temp; + + /* Length check; this cannot be ignored in this code because profile_length + * is used later to check the tag table, so even if the profile seems over + * long profile_length from the caller must be correct. The caller can fix + * this up on read or write by just passing in the profile header length. + */ + temp = png_get_uint_32(profile); + if (temp != profile_length) + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "length does not match profile"); + + temp = (png_uint_32) (*(profile+8)); + if (temp > 3 && (profile_length & 3)) + return png_icc_profile_error(png_ptr, colorspace, name, profile_length, + "invalid length"); + + temp = png_get_uint_32(profile+128); /* tag count: 12 bytes/tag */ + if (temp > 357913930 || /* (2^32-4-132)/12: maximum possible tag count */ + profile_length < 132+12*temp) /* truncated tag table */ + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "tag count too large"); + + /* The 'intent' must be valid or we can't store it, ICC limits the intent to + * 16 bits. + */ + temp = png_get_uint_32(profile+64); + if (temp >= 0xffff) /* The ICC limit */ + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "invalid rendering intent"); + + /* This is just a warning because the profile may be valid in future + * versions. + */ + if (temp >= PNG_sRGB_INTENT_LAST) + (void)png_icc_profile_error(png_ptr, NULL, name, temp, + "intent outside defined range"); + + /* At this point the tag table can't be checked because it hasn't necessarily + * been loaded; however, various header fields can be checked. These checks + * are for values permitted by the PNG spec in an ICC profile; the PNG spec + * restricts the profiles that can be passed in an iCCP chunk (they must be + * appropriate to processing PNG data!) + */ + + /* Data checks (could be skipped). These checks must be independent of the + * version number; however, the version number doesn't accommodate changes in + * the header fields (just the known tags and the interpretation of the + * data.) + */ + temp = png_get_uint_32(profile+36); /* signature 'ascp' */ + if (temp != 0x61637370) + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "invalid signature"); + + /* Currently the PCS illuminant/adopted white point (the computational + * white point) are required to be D50, + * however the profile contains a record of the illuminant so perhaps ICC + * expects to be able to change this in the future (despite the rationale in + * the introduction for using a fixed PCS adopted white.) Consequently the + * following is just a warning. + */ + if (memcmp(profile+68, D50_nCIEXYZ, 12) != 0) + (void)png_icc_profile_error(png_ptr, NULL, name, 0/*no tag value*/, + "PCS illuminant is not D50"); + + /* The PNG spec requires this: + * "If the iCCP chunk is present, the image samples conform to the colour + * space represented by the embedded ICC profile as defined by the + * International Color Consortium [ICC]. The colour space of the ICC profile + * shall be an RGB colour space for colour images (PNG colour types 2, 3, and + * 6), or a greyscale colour space for greyscale images (PNG colour types 0 + * and 4)." + * + * This checking code ensures the embedded profile (on either read or write) + * conforms to the specification requirements. Notice that an ICC 'gray' + * color-space profile contains the information to transform the monochrome + * data to XYZ or L*a*b (according to which PCS the profile uses) and this + * should be used in preference to the standard libpng K channel replication + * into R, G and B channels. + * + * Previously it was suggested that an RGB profile on grayscale data could be + * handled. However it it is clear that using an RGB profile in this context + * must be an error - there is no specification of what it means. Thus it is + * almost certainly more correct to ignore the profile. + */ + temp = png_get_uint_32(profile+16); /* data colour space field */ + switch (temp) + { + case 0x52474220: /* 'RGB ' */ + if ((color_type & PNG_COLOR_MASK_COLOR) == 0) + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "RGB color space not permitted on grayscale PNG"); + break; + + case 0x47524159: /* 'GRAY' */ + if ((color_type & PNG_COLOR_MASK_COLOR) != 0) + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "Gray color space not permitted on RGB PNG"); + break; + + default: + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "invalid ICC profile color space"); + } + + /* It is up to the application to check that the profile class matches the + * application requirements; the spec provides no guidance, but it's pretty + * weird if the profile is not scanner ('scnr'), monitor ('mntr'), printer + * ('prtr') or 'spac' (for generic color spaces). Issue a warning in these + * cases. Issue an error for device link or abstract profiles - these don't + * contain the records necessary to transform the color-space to anything + * other than the target device (and not even that for an abstract profile). + * Profiles of these classes may not be embedded in images. + */ + temp = png_get_uint_32(profile+12); /* profile/device class */ + switch (temp) + { + case 0x73636e72: /* 'scnr' */ + case 0x6d6e7472: /* 'mntr' */ + case 0x70727472: /* 'prtr' */ + case 0x73706163: /* 'spac' */ + /* All supported */ + break; + + case 0x61627374: /* 'abst' */ + /* May not be embedded in an image */ + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "invalid embedded Abstract ICC profile"); + + case 0x6c696e6b: /* 'link' */ + /* DeviceLink profiles cannot be interpreted in a non-device specific + * fashion, if an app uses the AToB0Tag in the profile the results are + * undefined unless the result is sent to the intended device, + * therefore a DeviceLink profile should not be found embedded in a + * PNG. + */ + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "unexpected DeviceLink ICC profile class"); + + case 0x6e6d636c: /* 'nmcl' */ + /* A NamedColor profile is also device specific, however it doesn't + * contain an AToB0 tag that is open to misinterpretation. Almost + * certainly it will fail the tests below. + */ + (void)png_icc_profile_error(png_ptr, NULL, name, temp, + "unexpected NamedColor ICC profile class"); + break; + + default: + /* To allow for future enhancements to the profile accept unrecognized + * profile classes with a warning, these then hit the test below on the + * tag content to ensure they are backward compatible with one of the + * understood profiles. + */ + (void)png_icc_profile_error(png_ptr, NULL, name, temp, + "unrecognized ICC profile class"); + break; + } + + /* For any profile other than a device link one the PCS must be encoded + * either in XYZ or Lab. + */ + temp = png_get_uint_32(profile+20); + switch (temp) + { + case 0x58595a20: /* 'XYZ ' */ + case 0x4c616220: /* 'Lab ' */ + break; + + default: + return png_icc_profile_error(png_ptr, colorspace, name, temp, + "unexpected ICC PCS encoding"); + } + + return 1; +} + +int /* PRIVATE */ +png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length, + png_const_bytep profile /* header plus whole tag table */) +{ + png_uint_32 tag_count = png_get_uint_32(profile+128); + png_uint_32 itag; + png_const_bytep tag = profile+132; /* The first tag */ + + /* First scan all the tags in the table and add bits to the icc_info value + * (temporarily in 'tags'). + */ + for (itag=0; itag < tag_count; ++itag, tag += 12) + { + png_uint_32 tag_id = png_get_uint_32(tag+0); + png_uint_32 tag_start = png_get_uint_32(tag+4); /* must be aligned */ + png_uint_32 tag_length = png_get_uint_32(tag+8);/* not padded */ + + /* The ICC specification does not exclude zero length tags, therefore the + * start might actually be anywhere if there is no data, but this would be + * a clear abuse of the intent of the standard so the start is checked for + * being in range. All defined tag types have an 8 byte header - a 4 byte + * type signature then 0. + */ + + /* This is a hard error; potentially it can cause read outside the + * profile. + */ + if (tag_start > profile_length || tag_length > profile_length - tag_start) + return png_icc_profile_error(png_ptr, colorspace, name, tag_id, + "ICC profile tag outside profile"); + + if ((tag_start & 3) != 0) + { + /* CNHP730S.icc shipped with Microsoft Windows 64 violates this; it is + * only a warning here because libpng does not care about the + * alignment. + */ + (void)png_icc_profile_error(png_ptr, NULL, name, tag_id, + "ICC profile tag start not a multiple of 4"); + } + } + + return 1; /* success, maybe with warnings */ +} + +#ifdef PNG_sRGB_SUPPORTED +#if PNG_sRGB_PROFILE_CHECKS >= 0 +/* Information about the known ICC sRGB profiles */ +static const struct +{ + png_uint_32 adler, crc, length; + png_uint_32 md5[4]; + png_byte have_md5; + png_byte is_broken; + png_uint_16 intent; + +# define PNG_MD5(a,b,c,d) { a, b, c, d }, (a!=0)||(b!=0)||(c!=0)||(d!=0) +# define PNG_ICC_CHECKSUM(adler, crc, md5, intent, broke, date, length, fname)\ + { adler, crc, length, md5, broke, intent }, + +} png_sRGB_checks[] = +{ + /* This data comes from contrib/tools/checksum-icc run on downloads of + * all four ICC sRGB profiles from www.color.org. + */ + /* adler32, crc32, MD5[4], intent, date, length, file-name */ + PNG_ICC_CHECKSUM(0x0a3fd9f6, 0x3b8772b9, + PNG_MD5(0x29f83dde, 0xaff255ae, 0x7842fae4, 0xca83390d), 0, 0, + "2009/03/27 21:36:31", 3048, "sRGB_IEC61966-2-1_black_scaled.icc") + + /* ICC sRGB v2 perceptual no black-compensation: */ + PNG_ICC_CHECKSUM(0x4909e5e1, 0x427ebb21, + PNG_MD5(0xc95bd637, 0xe95d8a3b, 0x0df38f99, 0xc1320389), 1, 0, + "2009/03/27 21:37:45", 3052, "sRGB_IEC61966-2-1_no_black_scaling.icc") + + PNG_ICC_CHECKSUM(0xfd2144a1, 0x306fd8ae, + PNG_MD5(0xfc663378, 0x37e2886b, 0xfd72e983, 0x8228f1b8), 0, 0, + "2009/08/10 17:28:01", 60988, "sRGB_v4_ICC_preference_displayclass.icc") + + /* ICC sRGB v4 perceptual */ + PNG_ICC_CHECKSUM(0x209c35d2, 0xbbef7812, + PNG_MD5(0x34562abf, 0x994ccd06, 0x6d2c5721, 0xd0d68c5d), 0, 0, + "2007/07/25 00:05:37", 60960, "sRGB_v4_ICC_preference.icc") + + /* The following profiles have no known MD5 checksum. If there is a match + * on the (empty) MD5 the other fields are used to attempt a match and + * a warning is produced. The first two of these profiles have a 'cprt' tag + * which suggests that they were also made by Hewlett Packard. + */ + PNG_ICC_CHECKSUM(0xa054d762, 0x5d5129ce, + PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 0, + "2004/07/21 18:57:42", 3024, "sRGB_IEC61966-2-1_noBPC.icc") + + /* This is a 'mntr' (display) profile with a mediaWhitePointTag that does not + * match the D50 PCS illuminant in the header (it is in fact the D65 values, + * so the white point is recorded as the un-adapted value.) The profiles + * below only differ in one byte - the intent - and are basically the same as + * the previous profile except for the mediaWhitePointTag error and a missing + * chromaticAdaptationTag. + */ + PNG_ICC_CHECKSUM(0xf784f3fb, 0x182ea552, + PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 0, 1/*broken*/, + "1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 perceptual") + + PNG_ICC_CHECKSUM(0x0398f3fc, 0xf29e526d, + PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 1/*broken*/, + "1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 media-relative") +}; + +static int +png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr, + png_const_bytep profile, uLong adler) +{ + /* The quick check is to verify just the MD5 signature and trust the + * rest of the data. Because the profile has already been verified for + * correctness this is safe. png_colorspace_set_sRGB will check the 'intent' + * field too, so if the profile has been edited with an intent not defined + * by sRGB (but maybe defined by a later ICC specification) the read of + * the profile will fail at that point. + */ + + png_uint_32 length = 0; + png_uint_32 intent = 0x10000; /* invalid */ +#if PNG_sRGB_PROFILE_CHECKS > 1 + uLong crc = 0; /* the value for 0 length data */ +#endif + unsigned int i; + +#ifdef PNG_SET_OPTION_SUPPORTED + /* First see if PNG_SKIP_sRGB_CHECK_PROFILE has been set to "on" */ + if (((png_ptr->options >> PNG_SKIP_sRGB_CHECK_PROFILE) & 3) == + PNG_OPTION_ON) + return 0; +#endif + + for (i=0; i < (sizeof png_sRGB_checks) / (sizeof png_sRGB_checks[0]); ++i) + { + if (png_get_uint_32(profile+84) == png_sRGB_checks[i].md5[0] && + png_get_uint_32(profile+88) == png_sRGB_checks[i].md5[1] && + png_get_uint_32(profile+92) == png_sRGB_checks[i].md5[2] && + png_get_uint_32(profile+96) == png_sRGB_checks[i].md5[3]) + { + /* This may be one of the old HP profiles without an MD5, in that + * case we can only use the length and Adler32 (note that these + * are not used by default if there is an MD5!) + */ +# if PNG_sRGB_PROFILE_CHECKS == 0 + if (png_sRGB_checks[i].have_md5 != 0) + return 1+png_sRGB_checks[i].is_broken; +# endif + + /* Profile is unsigned or more checks have been configured in. */ + if (length == 0) + { + length = png_get_uint_32(profile); + intent = png_get_uint_32(profile+64); + } + + /* Length *and* intent must match */ + if (length == (png_uint_32) png_sRGB_checks[i].length && + intent == (png_uint_32) png_sRGB_checks[i].intent) + { + /* Now calculate the adler32 if not done already. */ + if (adler == 0) + { + adler = adler32(0, NULL, 0); + adler = adler32(adler, profile, length); + } + + if (adler == png_sRGB_checks[i].adler) + { + /* These basic checks suggest that the data has not been + * modified, but if the check level is more than 1 perform + * our own crc32 checksum on the data. + */ +# if PNG_sRGB_PROFILE_CHECKS > 1 + if (crc == 0) + { + crc = crc32(0, NULL, 0); + crc = crc32(crc, profile, length); + } + + /* So this check must pass for the 'return' below to happen. + */ + if (crc == png_sRGB_checks[i].crc) +# endif + { + if (png_sRGB_checks[i].is_broken != 0) + { + /* These profiles are known to have bad data that may cause + * problems if they are used, therefore attempt to + * discourage their use, skip the 'have_md5' warning below, + * which is made irrelevant by this error. + */ + png_chunk_report(png_ptr, "known incorrect sRGB profile", + PNG_CHUNK_ERROR); + } + + /* Warn that this being done; this isn't even an error since + * the profile is perfectly valid, but it would be nice if + * people used the up-to-date ones. + */ + else if (png_sRGB_checks[i].have_md5 == 0) + { + png_chunk_report(png_ptr, + "out-of-date sRGB profile with no signature", + PNG_CHUNK_WARNING); + } + + return 1+png_sRGB_checks[i].is_broken; + } + } + +# if PNG_sRGB_PROFILE_CHECKS > 0 + /* The signature matched, but the profile had been changed in some + * way. This probably indicates a data error or uninformed hacking. + * Fall through to "no match". + */ + png_chunk_report(png_ptr, + "Not recognizing known sRGB profile that has been edited", + PNG_CHUNK_WARNING); + break; +# endif + } + } + } + + return 0; /* no match */ +} + +void /* PRIVATE */ +png_icc_set_sRGB(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_bytep profile, uLong adler) +{ + /* Is this profile one of the known ICC sRGB profiles? If it is, just set + * the sRGB information. + */ + if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler) != 0) + (void)png_colorspace_set_sRGB(png_ptr, colorspace, + (int)/*already checked*/png_get_uint_32(profile+64)); +} +#endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */ +#endif /* sRGB */ + +int /* PRIVATE */ +png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_charp name, png_uint_32 profile_length, png_const_bytep profile, + int color_type) +{ + if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0) + return 0; + + if (icc_check_length(png_ptr, colorspace, name, profile_length) != 0 && + png_icc_check_header(png_ptr, colorspace, name, profile_length, profile, + color_type) != 0 && + png_icc_check_tag_table(png_ptr, colorspace, name, profile_length, + profile) != 0) + { +# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0 + /* If no sRGB support, don't try storing sRGB information */ + png_icc_set_sRGB(png_ptr, colorspace, profile, 0); +# endif + return 1; + } + + /* Failure case */ + return 0; +} +#endif /* iCCP */ + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +void /* PRIVATE */ +png_colorspace_set_rgb_coefficients(png_structrp png_ptr) +{ + /* Set the rgb_to_gray coefficients from the colorspace. */ + if (png_ptr->rgb_to_gray_coefficients_set == 0 && + (png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + /* png_set_background has not been called, get the coefficients from the Y + * values of the colorspace colorants. + */ + png_fixed_point r = png_ptr->colorspace.end_points_XYZ.red_Y; + png_fixed_point g = png_ptr->colorspace.end_points_XYZ.green_Y; + png_fixed_point b = png_ptr->colorspace.end_points_XYZ.blue_Y; + png_fixed_point total = r+g+b; + + if (total > 0 && + r >= 0 && png_muldiv(&r, r, 32768, total) && r >= 0 && r <= 32768 && + g >= 0 && png_muldiv(&g, g, 32768, total) && g >= 0 && g <= 32768 && + b >= 0 && png_muldiv(&b, b, 32768, total) && b >= 0 && b <= 32768 && + r+g+b <= 32769) + { + /* We allow 0 coefficients here. r+g+b may be 32769 if two or + * all of the coefficients were rounded up. Handle this by + * reducing the *largest* coefficient by 1; this matches the + * approach used for the default coefficients in pngrtran.c + */ + int add = 0; + + if (r+g+b > 32768) + add = -1; + else if (r+g+b < 32768) + add = 1; + + if (add != 0) + { + if (g >= r && g >= b) + g += add; + else if (r >= g && r >= b) + r += add; + else + b += add; + } + + /* Check for an internal error. */ + if (r+g+b != 32768) + png_error(png_ptr, + "internal error handling cHRM coefficients"); + + else + { + png_ptr->rgb_to_gray_red_coeff = (png_uint_16)r; + png_ptr->rgb_to_gray_green_coeff = (png_uint_16)g; + } + } + + /* This is a png_error at present even though it could be ignored - + * it should never happen, but it is important that if it does, the + * bug is fixed. + */ + else + png_error(png_ptr, "internal error handling cHRM->XYZ"); + } +} +#endif /* READ_RGB_TO_GRAY */ + +#endif /* COLORSPACE */ + +#ifdef __GNUC__ +/* This exists solely to work round a warning from GNU C. */ +static int /* PRIVATE */ +png_gt(size_t a, size_t b) +{ + return a > b; +} +#else +# define png_gt(a,b) ((a) > (b)) +#endif + +void /* PRIVATE */ +png_check_IHDR(png_const_structrp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type) +{ + int error = 0; + + /* Check for width and height valid values */ + if (width == 0) + { + png_warning(png_ptr, "Image width is zero in IHDR"); + error = 1; + } + + if (width > PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Invalid image width in IHDR"); + error = 1; + } + + if (png_gt(((width + 7) & (~7U)), + ((PNG_SIZE_MAX + - 48 /* big_row_buf hack */ + - 1) /* filter byte */ + / 8) /* 8-byte RGBA pixels */ + - 1)) /* extra max_pixel_depth pad */ + { + /* The size of the row must be within the limits of this architecture. + * Because the read code can perform arbitrary transformations the + * maximum size is checked here. Because the code in png_read_start_row + * adds extra space "for safety's sake" in several places a conservative + * limit is used here. + * + * NOTE: it would be far better to check the size that is actually used, + * but the effect in the real world is minor and the changes are more + * extensive, therefore much more dangerous and much more difficult to + * write in a way that avoids compiler warnings. + */ + png_warning(png_ptr, "Image width is too large for this architecture"); + error = 1; + } + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (width > png_ptr->user_width_max) +#else + if (width > PNG_USER_WIDTH_MAX) +#endif + { + png_warning(png_ptr, "Image width exceeds user limit in IHDR"); + error = 1; + } + + if (height == 0) + { + png_warning(png_ptr, "Image height is zero in IHDR"); + error = 1; + } + + if (height > PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Invalid image height in IHDR"); + error = 1; + } + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (height > png_ptr->user_height_max) +#else + if (height > PNG_USER_HEIGHT_MAX) +#endif + { + png_warning(png_ptr, "Image height exceeds user limit in IHDR"); + error = 1; + } + + /* Check other values */ + if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && + bit_depth != 8 && bit_depth != 16) + { + png_warning(png_ptr, "Invalid bit depth in IHDR"); + error = 1; + } + + if (color_type < 0 || color_type == 1 || + color_type == 5 || color_type > 6) + { + png_warning(png_ptr, "Invalid color type in IHDR"); + error = 1; + } + + if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || + ((color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) + { + png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR"); + error = 1; + } + + if (interlace_type >= PNG_INTERLACE_LAST) + { + png_warning(png_ptr, "Unknown interlace method in IHDR"); + error = 1; + } + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + { + png_warning(png_ptr, "Unknown compression method in IHDR"); + error = 1; + } + +#ifdef PNG_MNG_FEATURES_SUPPORTED + /* Accept filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not read a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && + png_ptr->mng_features_permitted != 0) + png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); + + if (filter_type != PNG_FILTER_TYPE_BASE) + { + if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && + ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA))) + { + png_warning(png_ptr, "Unknown filter method in IHDR"); + error = 1; + } + + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0) + { + png_warning(png_ptr, "Invalid filter method in IHDR"); + error = 1; + } + } + +#else + if (filter_type != PNG_FILTER_TYPE_BASE) + { + png_warning(png_ptr, "Unknown filter method in IHDR"); + error = 1; + } +#endif + + if (error == 1) + png_error(png_ptr, "Invalid IHDR data"); +} + +#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) +/* ASCII to fp functions */ +/* Check an ASCII formatted floating point value, see the more detailed + * comments in pngpriv.h + */ +/* The following is used internally to preserve the sticky flags */ +#define png_fp_add(state, flags) ((state) |= (flags)) +#define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY)) + +int /* PRIVATE */ +png_check_fp_number(png_const_charp string, size_t size, int *statep, + png_size_tp whereami) +{ + int state = *statep; + size_t i = *whereami; + + while (i < size) + { + int type; + /* First find the type of the next character */ + switch (string[i]) + { + case 43: type = PNG_FP_SAW_SIGN; break; + case 45: type = PNG_FP_SAW_SIGN + PNG_FP_NEGATIVE; break; + case 46: type = PNG_FP_SAW_DOT; break; + case 48: type = PNG_FP_SAW_DIGIT; break; + case 49: case 50: case 51: case 52: + case 53: case 54: case 55: case 56: + case 57: type = PNG_FP_SAW_DIGIT + PNG_FP_NONZERO; break; + case 69: + case 101: type = PNG_FP_SAW_E; break; + default: goto PNG_FP_End; + } + + /* Now deal with this type according to the current + * state, the type is arranged to not overlap the + * bits of the PNG_FP_STATE. + */ + switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY)) + { + case PNG_FP_INTEGER + PNG_FP_SAW_SIGN: + if ((state & PNG_FP_SAW_ANY) != 0) + goto PNG_FP_End; /* not a part of the number */ + + png_fp_add(state, type); + break; + + case PNG_FP_INTEGER + PNG_FP_SAW_DOT: + /* Ok as trailer, ok as lead of fraction. */ + if ((state & PNG_FP_SAW_DOT) != 0) /* two dots */ + goto PNG_FP_End; + + else if ((state & PNG_FP_SAW_DIGIT) != 0) /* trailing dot? */ + png_fp_add(state, type); + + else + png_fp_set(state, PNG_FP_FRACTION | type); + + break; + + case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT: + if ((state & PNG_FP_SAW_DOT) != 0) /* delayed fraction */ + png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT); + + png_fp_add(state, type | PNG_FP_WAS_VALID); + + break; + + case PNG_FP_INTEGER + PNG_FP_SAW_E: + if ((state & PNG_FP_SAW_DIGIT) == 0) + goto PNG_FP_End; + + png_fp_set(state, PNG_FP_EXPONENT); + + break; + + /* case PNG_FP_FRACTION + PNG_FP_SAW_SIGN: + goto PNG_FP_End; ** no sign in fraction */ + + /* case PNG_FP_FRACTION + PNG_FP_SAW_DOT: + goto PNG_FP_End; ** Because SAW_DOT is always set */ + + case PNG_FP_FRACTION + PNG_FP_SAW_DIGIT: + png_fp_add(state, type | PNG_FP_WAS_VALID); + break; + + case PNG_FP_FRACTION + PNG_FP_SAW_E: + /* This is correct because the trailing '.' on an + * integer is handled above - so we can only get here + * with the sequence ".E" (with no preceding digits). + */ + if ((state & PNG_FP_SAW_DIGIT) == 0) + goto PNG_FP_End; + + png_fp_set(state, PNG_FP_EXPONENT); + + break; + + case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN: + if ((state & PNG_FP_SAW_ANY) != 0) + goto PNG_FP_End; /* not a part of the number */ + + png_fp_add(state, PNG_FP_SAW_SIGN); + + break; + + /* case PNG_FP_EXPONENT + PNG_FP_SAW_DOT: + goto PNG_FP_End; */ + + case PNG_FP_EXPONENT + PNG_FP_SAW_DIGIT: + png_fp_add(state, PNG_FP_SAW_DIGIT | PNG_FP_WAS_VALID); + + break; + + /* case PNG_FP_EXPONEXT + PNG_FP_SAW_E: + goto PNG_FP_End; */ + + default: goto PNG_FP_End; /* I.e. break 2 */ + } + + /* The character seems ok, continue. */ + ++i; + } + +PNG_FP_End: + /* Here at the end, update the state and return the correct + * return code. + */ + *statep = state; + *whereami = i; + + return (state & PNG_FP_SAW_DIGIT) != 0; +} + + +/* The same but for a complete string. */ +int +png_check_fp_string(png_const_charp string, size_t size) +{ + int state=0; + size_t char_index=0; + + if (png_check_fp_number(string, size, &state, &char_index) != 0 && + (char_index == size || string[char_index] == 0)) + return state /* must be non-zero - see above */; + + return 0; /* i.e. fail */ +} +#endif /* pCAL || sCAL */ + +#ifdef PNG_sCAL_SUPPORTED +# ifdef PNG_FLOATING_POINT_SUPPORTED +/* Utility used below - a simple accurate power of ten from an integral + * exponent. + */ +static double +png_pow10(int power) +{ + int recip = 0; + double d = 1; + + /* Handle negative exponent with a reciprocal at the end because + * 10 is exact whereas .1 is inexact in base 2 + */ + if (power < 0) + { + if (power < DBL_MIN_10_EXP) return 0; + recip = 1; power = -power; + } + + if (power > 0) + { + /* Decompose power bitwise. */ + double mult = 10; + do + { + if (power & 1) d *= mult; + mult *= mult; + power >>= 1; + } + while (power > 0); + + if (recip != 0) d = 1/d; + } + /* else power is 0 and d is 1 */ + + return d; +} + +/* Function to format a floating point value in ASCII with a given + * precision. + */ +#if GCC_STRICT_OVERFLOW +#pragma GCC diagnostic push +/* The problem arises below with exp_b10, which can never overflow because it + * comes, originally, from frexp and is therefore limited to a range which is + * typically +/-710 (log2(DBL_MAX)/log2(DBL_MIN)). + */ +#pragma GCC diagnostic warning "-Wstrict-overflow=2" +#endif /* GCC_STRICT_OVERFLOW */ +void /* PRIVATE */ +png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, size_t size, + double fp, unsigned int precision) +{ + /* We use standard functions from math.h, but not printf because + * that would require stdio. The caller must supply a buffer of + * sufficient size or we will png_error. The tests on size and + * the space in ascii[] consumed are indicated below. + */ + if (precision < 1) + precision = DBL_DIG; + + /* Enforce the limit of the implementation precision too. */ + if (precision > DBL_DIG+1) + precision = DBL_DIG+1; + + /* Basic sanity checks */ + if (size >= precision+5) /* See the requirements below. */ + { + if (fp < 0) + { + fp = -fp; + *ascii++ = 45; /* '-' PLUS 1 TOTAL 1 */ + --size; + } + + if (fp >= DBL_MIN && fp <= DBL_MAX) + { + int exp_b10; /* A base 10 exponent */ + double base; /* 10^exp_b10 */ + + /* First extract a base 10 exponent of the number, + * the calculation below rounds down when converting + * from base 2 to base 10 (multiply by log10(2) - + * 0.3010, but 77/256 is 0.3008, so exp_b10 needs to + * be increased. Note that the arithmetic shift + * performs a floor() unlike C arithmetic - using a + * C multiply would break the following for negative + * exponents. + */ + (void)frexp(fp, &exp_b10); /* exponent to base 2 */ + + exp_b10 = (exp_b10 * 77) >> 8; /* <= exponent to base 10 */ + + /* Avoid underflow here. */ + base = png_pow10(exp_b10); /* May underflow */ + + while (base < DBL_MIN || base < fp) + { + /* And this may overflow. */ + double test = png_pow10(exp_b10+1); + + if (test <= DBL_MAX) + { + ++exp_b10; base = test; + } + + else + break; + } + + /* Normalize fp and correct exp_b10, after this fp is in the + * range [.1,1) and exp_b10 is both the exponent and the digit + * *before* which the decimal point should be inserted + * (starting with 0 for the first digit). Note that this + * works even if 10^exp_b10 is out of range because of the + * test on DBL_MAX above. + */ + fp /= base; + while (fp >= 1) + { + fp /= 10; ++exp_b10; + } + + /* Because of the code above fp may, at this point, be + * less than .1, this is ok because the code below can + * handle the leading zeros this generates, so no attempt + * is made to correct that here. + */ + + { + unsigned int czero, clead, cdigits; + char exponent[10]; + + /* Allow up to two leading zeros - this will not lengthen + * the number compared to using E-n. + */ + if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */ + { + czero = 0U-exp_b10; /* PLUS 2 digits: TOTAL 3 */ + exp_b10 = 0; /* Dot added below before first output. */ + } + else + czero = 0; /* No zeros to add */ + + /* Generate the digit list, stripping trailing zeros and + * inserting a '.' before a digit if the exponent is 0. + */ + clead = czero; /* Count of leading zeros */ + cdigits = 0; /* Count of digits in list. */ + + do + { + double d; + + fp *= 10; + /* Use modf here, not floor and subtract, so that + * the separation is done in one step. At the end + * of the loop don't break the number into parts so + * that the final digit is rounded. + */ + if (cdigits+czero+1 < precision+clead) + fp = modf(fp, &d); + + else + { + d = floor(fp + .5); + + if (d > 9) + { + /* Rounding up to 10, handle that here. */ + if (czero > 0) + { + --czero; d = 1; + if (cdigits == 0) --clead; + } + else + { + while (cdigits > 0 && d > 9) + { + int ch = *--ascii; + + if (exp_b10 != (-1)) + ++exp_b10; + + else if (ch == 46) + { + ch = *--ascii; ++size; + /* Advance exp_b10 to '1', so that the + * decimal point happens after the + * previous digit. + */ + exp_b10 = 1; + } + + --cdigits; + d = ch - 47; /* I.e. 1+(ch-48) */ + } + + /* Did we reach the beginning? If so adjust the + * exponent but take into account the leading + * decimal point. + */ + if (d > 9) /* cdigits == 0 */ + { + if (exp_b10 == (-1)) + { + /* Leading decimal point (plus zeros?), if + * we lose the decimal point here it must + * be reentered below. + */ + int ch = *--ascii; + + if (ch == 46) + { + ++size; exp_b10 = 1; + } + + /* Else lost a leading zero, so 'exp_b10' is + * still ok at (-1) + */ + } + else + ++exp_b10; + + /* In all cases we output a '1' */ + d = 1; + } + } + } + fp = 0; /* Guarantees termination below. */ + } + + if (d == 0) + { + ++czero; + if (cdigits == 0) ++clead; + } + else + { + /* Included embedded zeros in the digit count. */ + cdigits += czero - clead; + clead = 0; + + while (czero > 0) + { + /* exp_b10 == (-1) means we just output the decimal + * place - after the DP don't adjust 'exp_b10' any + * more! + */ + if (exp_b10 != (-1)) + { + if (exp_b10 == 0) + { + *ascii++ = 46; --size; + } + /* PLUS 1: TOTAL 4 */ + --exp_b10; + } + *ascii++ = 48; --czero; + } + + if (exp_b10 != (-1)) + { + if (exp_b10 == 0) + { + *ascii++ = 46; --size; /* counted above */ + } + + --exp_b10; + } + *ascii++ = (char)(48 + (int)d); ++cdigits; + } + } + while (cdigits+czero < precision+clead && fp > DBL_MIN); + + /* The total output count (max) is now 4+precision */ + + /* Check for an exponent, if we don't need one we are + * done and just need to terminate the string. At this + * point, exp_b10==(-1) is effectively a flag: it got + * to '-1' because of the decrement, after outputting + * the decimal point above. (The exponent required is + * *not* -1.) + */ + if (exp_b10 >= (-1) && exp_b10 <= 2) + { + /* The following only happens if we didn't output the + * leading zeros above for negative exponent, so this + * doesn't add to the digit requirement. Note that the + * two zeros here can only be output if the two leading + * zeros were *not* output, so this doesn't increase + * the output count. + */ + while (exp_b10-- > 0) *ascii++ = 48; + + *ascii = 0; + + /* Total buffer requirement (including the '\0') is + * 5+precision - see check at the start. + */ + return; + } + + /* Here if an exponent is required, adjust size for + * the digits we output but did not count. The total + * digit output here so far is at most 1+precision - no + * decimal point and no leading or trailing zeros have + * been output. + */ + size -= cdigits; + + *ascii++ = 69; --size; /* 'E': PLUS 1 TOTAL 2+precision */ + + /* The following use of an unsigned temporary avoids ambiguities in + * the signed arithmetic on exp_b10 and permits GCC at least to do + * better optimization. + */ + { + unsigned int uexp_b10; + + if (exp_b10 < 0) + { + *ascii++ = 45; --size; /* '-': PLUS 1 TOTAL 3+precision */ + uexp_b10 = 0U-exp_b10; + } + + else + uexp_b10 = 0U+exp_b10; + + cdigits = 0; + + while (uexp_b10 > 0) + { + exponent[cdigits++] = (char)(48 + uexp_b10 % 10); + uexp_b10 /= 10; + } + } + + /* Need another size check here for the exponent digits, so + * this need not be considered above. + */ + if (size > cdigits) + { + while (cdigits > 0) *ascii++ = exponent[--cdigits]; + + *ascii = 0; + + return; + } + } + } + else if (!(fp >= DBL_MIN)) + { + *ascii++ = 48; /* '0' */ + *ascii = 0; + return; + } + else + { + *ascii++ = 105; /* 'i' */ + *ascii++ = 110; /* 'n' */ + *ascii++ = 102; /* 'f' */ + *ascii = 0; + return; + } + } + + /* Here on buffer too small. */ + png_error(png_ptr, "ASCII conversion buffer too small"); +} +#if GCC_STRICT_OVERFLOW +#pragma GCC diagnostic pop +#endif /* GCC_STRICT_OVERFLOW */ + +# endif /* FLOATING_POINT */ + +# ifdef PNG_FIXED_POINT_SUPPORTED +/* Function to format a fixed point value in ASCII. + */ +void /* PRIVATE */ +png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, + size_t size, png_fixed_point fp) +{ + /* Require space for 10 decimal digits, a decimal point, a minus sign and a + * trailing \0, 13 characters: + */ + if (size > 12) + { + png_uint_32 num; + + /* Avoid overflow here on the minimum integer. */ + if (fp < 0) + { + *ascii++ = 45; num = (png_uint_32)(-fp); + } + else + num = (png_uint_32)fp; + + if (num <= 0x80000000) /* else overflowed */ + { + unsigned int ndigits = 0, first = 16 /* flag value */; + char digits[10]; + + while (num) + { + /* Split the low digit off num: */ + unsigned int tmp = num/10; + num -= tmp*10; + digits[ndigits++] = (char)(48 + num); + /* Record the first non-zero digit, note that this is a number + * starting at 1, it's not actually the array index. + */ + if (first == 16 && num > 0) + first = ndigits; + num = tmp; + } + + if (ndigits > 0) + { + while (ndigits > 5) *ascii++ = digits[--ndigits]; + /* The remaining digits are fractional digits, ndigits is '5' or + * smaller at this point. It is certainly not zero. Check for a + * non-zero fractional digit: + */ + if (first <= 5) + { + unsigned int i; + *ascii++ = 46; /* decimal point */ + /* ndigits may be <5 for small numbers, output leading zeros + * then ndigits digits to first: + */ + i = 5; + while (ndigits < i) + { + *ascii++ = 48; --i; + } + while (ndigits >= first) *ascii++ = digits[--ndigits]; + /* Don't output the trailing zeros! */ + } + } + else + *ascii++ = 48; + + /* And null terminate the string: */ + *ascii = 0; + return; + } + } + + /* Here on buffer too small. */ + png_error(png_ptr, "ASCII conversion buffer too small"); +} +# endif /* FIXED_POINT */ +#endif /* SCAL */ + +#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ + !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \ + (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \ + defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \ + (defined(PNG_sCAL_SUPPORTED) && \ + defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)) +png_fixed_point +png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text) +{ + double r = floor(100000 * fp + .5); + + if (r > 2147483647. || r < -2147483648.) + png_fixed_error(png_ptr, text); + +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(text) +# endif + + return (png_fixed_point)r; +} +#endif + +#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_COLORSPACE_SUPPORTED) ||\ + defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED) +/* muldiv functions */ +/* This API takes signed arguments and rounds the result to the nearest + * integer (or, for a fixed point number - the standard argument - to + * the nearest .00001). Overflow and divide by zero are signalled in + * the result, a boolean - true on success, false on overflow. + */ +#if GCC_STRICT_OVERFLOW /* from above */ +/* It is not obvious which comparison below gets optimized in such a way that + * signed overflow would change the result; looking through the code does not + * reveal any tests which have the form GCC complains about, so presumably the + * optimizer is moving an add or subtract into the 'if' somewhere. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic warning "-Wstrict-overflow=2" +#endif /* GCC_STRICT_OVERFLOW */ +int +png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, + png_int_32 divisor) +{ + /* Return a * times / divisor, rounded. */ + if (divisor != 0) + { + if (a == 0 || times == 0) + { + *res = 0; + return 1; + } + else + { +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = a; + r *= times; + r /= divisor; + r = floor(r+.5); + + /* A png_fixed_point is a 32-bit integer. */ + if (r <= 2147483647. && r >= -2147483648.) + { + *res = (png_fixed_point)r; + return 1; + } +#else + int negative = 0; + png_uint_32 A, T, D; + png_uint_32 s16, s32, s00; + + if (a < 0) + negative = 1, A = -a; + else + A = a; + + if (times < 0) + negative = !negative, T = -times; + else + T = times; + + if (divisor < 0) + negative = !negative, D = -divisor; + else + D = divisor; + + /* Following can't overflow because the arguments only + * have 31 bits each, however the result may be 32 bits. + */ + s16 = (A >> 16) * (T & 0xffff) + + (A & 0xffff) * (T >> 16); + /* Can't overflow because the a*times bit is only 30 + * bits at most. + */ + s32 = (A >> 16) * (T >> 16) + (s16 >> 16); + s00 = (A & 0xffff) * (T & 0xffff); + + s16 = (s16 & 0xffff) << 16; + s00 += s16; + + if (s00 < s16) + ++s32; /* carry */ + + if (s32 < D) /* else overflow */ + { + /* s32.s00 is now the 64-bit product, do a standard + * division, we know that s32 < D, so the maximum + * required shift is 31. + */ + int bitshift = 32; + png_fixed_point result = 0; /* NOTE: signed */ + + while (--bitshift >= 0) + { + png_uint_32 d32, d00; + + if (bitshift > 0) + d32 = D >> (32-bitshift), d00 = D << bitshift; + + else + d32 = 0, d00 = D; + + if (s32 > d32) + { + if (s00 < d00) --s32; /* carry */ + s32 -= d32, s00 -= d00, result += 1<= d00) + s32 = 0, s00 -= d00, result += 1<= (D >> 1)) + ++result; + + if (negative != 0) + result = -result; + + /* Check for overflow. */ + if ((negative != 0 && result <= 0) || + (negative == 0 && result >= 0)) + { + *res = result; + return 1; + } + } +#endif + } + } + + return 0; +} +#if GCC_STRICT_OVERFLOW +#pragma GCC diagnostic pop +#endif /* GCC_STRICT_OVERFLOW */ +#endif /* READ_GAMMA || INCH_CONVERSIONS */ + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) +/* The following is for when the caller doesn't much care about the + * result. + */ +png_fixed_point +png_muldiv_warn(png_const_structrp png_ptr, png_fixed_point a, png_int_32 times, + png_int_32 divisor) +{ + png_fixed_point result; + + if (png_muldiv(&result, a, times, divisor) != 0) + return result; + + png_warning(png_ptr, "fixed point overflow ignored"); + return 0; +} +#endif + +#ifdef PNG_GAMMA_SUPPORTED /* more fixed point functions for gamma */ +/* Calculate a reciprocal, return 0 on div-by-zero or overflow. */ +png_fixed_point +png_reciprocal(png_fixed_point a) +{ +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = floor(1E10/a+.5); + + if (r <= 2147483647. && r >= -2147483648.) + return (png_fixed_point)r; +#else + png_fixed_point res; + + if (png_muldiv(&res, 100000, 100000, a) != 0) + return res; +#endif + + return 0; /* error/overflow */ +} + +/* This is the shared test on whether a gamma value is 'significant' - whether + * it is worth doing gamma correction. + */ +int /* PRIVATE */ +png_gamma_significant(png_fixed_point gamma_val) +{ + return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED || + gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED; +} +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +#ifdef PNG_16BIT_SUPPORTED +/* A local convenience routine. */ +static png_fixed_point +png_product2(png_fixed_point a, png_fixed_point b) +{ + /* The required result is 1/a * 1/b; the following preserves accuracy. */ +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = a * 1E-5; + r *= b; + r = floor(r+.5); + + if (r <= 2147483647. && r >= -2147483648.) + return (png_fixed_point)r; +#else + png_fixed_point res; + + if (png_muldiv(&res, a, b, 100000) != 0) + return res; +#endif + + return 0; /* overflow */ +} +#endif /* 16BIT */ + +/* The inverse of the above. */ +png_fixed_point +png_reciprocal2(png_fixed_point a, png_fixed_point b) +{ + /* The required result is 1/a * 1/b; the following preserves accuracy. */ +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + if (a != 0 && b != 0) + { + double r = 1E15/a; + r /= b; + r = floor(r+.5); + + if (r <= 2147483647. && r >= -2147483648.) + return (png_fixed_point)r; + } +#else + /* This may overflow because the range of png_fixed_point isn't symmetric, + * but this API is only used for the product of file and screen gamma so it + * doesn't matter that the smallest number it can produce is 1/21474, not + * 1/100000 + */ + png_fixed_point res = png_product2(a, b); + + if (res != 0) + return png_reciprocal(res); +#endif + + return 0; /* overflow */ +} +#endif /* READ_GAMMA */ + +#ifdef PNG_READ_GAMMA_SUPPORTED /* gamma table code */ +#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED +/* Fixed point gamma. + * + * The code to calculate the tables used below can be found in the shell script + * contrib/tools/intgamma.sh + * + * To calculate gamma this code implements fast log() and exp() calls using only + * fixed point arithmetic. This code has sufficient precision for either 8-bit + * or 16-bit sample values. + * + * The tables used here were calculated using simple 'bc' programs, but C double + * precision floating point arithmetic would work fine. + * + * 8-bit log table + * This is a table of -log(value/255)/log(2) for 'value' in the range 128 to + * 255, so it's the base 2 logarithm of a normalized 8-bit floating point + * mantissa. The numbers are 32-bit fractions. + */ +static const png_uint_32 +png_8bit_l2[128] = +{ + 4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U, + 3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U, + 3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U, + 3455425220U, 3413129301U, 3371120137U, 3329393864U, 3287946700U, 3246774933U, + 3205874930U, 3165243125U, 3124876025U, 3084770202U, 3044922296U, 3005329011U, + 2965987113U, 2926893432U, 2888044853U, 2849438323U, 2811070844U, 2772939474U, + 2735041326U, 2697373562U, 2659933400U, 2622718104U, 2585724991U, 2548951424U, + 2512394810U, 2476052606U, 2439922311U, 2404001468U, 2368287663U, 2332778523U, + 2297471715U, 2262364947U, 2227455964U, 2192742551U, 2158222529U, 2123893754U, + 2089754119U, 2055801552U, 2022034013U, 1988449497U, 1955046031U, 1921821672U, + 1888774511U, 1855902668U, 1823204291U, 1790677560U, 1758320682U, 1726131893U, + 1694109454U, 1662251657U, 1630556815U, 1599023271U, 1567649391U, 1536433567U, + 1505374214U, 1474469770U, 1443718700U, 1413119487U, 1382670639U, 1352370686U, + 1322218179U, 1292211689U, 1262349810U, 1232631153U, 1203054352U, 1173618059U, + 1144320946U, 1115161701U, 1086139034U, 1057251672U, 1028498358U, 999877854U, + 971388940U, 943030410U, 914801076U, 886699767U, 858725327U, 830876614U, + 803152505U, 775551890U, 748073672U, 720716771U, 693480120U, 666362667U, + 639363374U, 612481215U, 585715177U, 559064263U, 532527486U, 506103872U, + 479792461U, 453592303U, 427502463U, 401522014U, 375650043U, 349885648U, + 324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U, + 172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U, + 24347096U, 0U + +#if 0 + /* The following are the values for 16-bit tables - these work fine for the + * 8-bit conversions but produce very slightly larger errors in the 16-bit + * log (about 1.2 as opposed to 0.7 absolute error in the final value). To + * use these all the shifts below must be adjusted appropriately. + */ + 65166, 64430, 63700, 62976, 62257, 61543, 60835, 60132, 59434, 58741, 58054, + 57371, 56693, 56020, 55352, 54689, 54030, 53375, 52726, 52080, 51439, 50803, + 50170, 49542, 48918, 48298, 47682, 47070, 46462, 45858, 45257, 44661, 44068, + 43479, 42894, 42312, 41733, 41159, 40587, 40020, 39455, 38894, 38336, 37782, + 37230, 36682, 36137, 35595, 35057, 34521, 33988, 33459, 32932, 32408, 31887, + 31369, 30854, 30341, 29832, 29325, 28820, 28319, 27820, 27324, 26830, 26339, + 25850, 25364, 24880, 24399, 23920, 23444, 22970, 22499, 22029, 21562, 21098, + 20636, 20175, 19718, 19262, 18808, 18357, 17908, 17461, 17016, 16573, 16132, + 15694, 15257, 14822, 14390, 13959, 13530, 13103, 12678, 12255, 11834, 11415, + 10997, 10582, 10168, 9756, 9346, 8937, 8531, 8126, 7723, 7321, 6921, 6523, + 6127, 5732, 5339, 4947, 4557, 4169, 3782, 3397, 3014, 2632, 2251, 1872, 1495, + 1119, 744, 372 +#endif +}; + +static png_int_32 +png_log8bit(unsigned int x) +{ + unsigned int lg2 = 0; + /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log, + * because the log is actually negate that means adding 1. The final + * returned value thus has the range 0 (for 255 input) to 7.994 (for 1 + * input), return -1 for the overflow (log 0) case, - so the result is + * always at most 19 bits. + */ + if ((x &= 0xff) == 0) + return -1; + + if ((x & 0xf0) == 0) + lg2 = 4, x <<= 4; + + if ((x & 0xc0) == 0) + lg2 += 2, x <<= 2; + + if ((x & 0x80) == 0) + lg2 += 1, x <<= 1; + + /* result is at most 19 bits, so this cast is safe: */ + return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16)); +} + +/* The above gives exact (to 16 binary places) log2 values for 8-bit images, + * for 16-bit images we use the most significant 8 bits of the 16-bit value to + * get an approximation then multiply the approximation by a correction factor + * determined by the remaining up to 8 bits. This requires an additional step + * in the 16-bit case. + * + * We want log2(value/65535), we have log2(v'/255), where: + * + * value = v' * 256 + v'' + * = v' * f + * + * So f is value/v', which is equal to (256+v''/v') since v' is in the range 128 + * to 255 and v'' is in the range 0 to 255 f will be in the range 256 to less + * than 258. The final factor also needs to correct for the fact that our 8-bit + * value is scaled by 255, whereas the 16-bit values must be scaled by 65535. + * + * This gives a final formula using a calculated value 'x' which is value/v' and + * scaling by 65536 to match the above table: + * + * log2(x/257) * 65536 + * + * Since these numbers are so close to '1' we can use simple linear + * interpolation between the two end values 256/257 (result -368.61) and 258/257 + * (result 367.179). The values used below are scaled by a further 64 to give + * 16-bit precision in the interpolation: + * + * Start (256): -23591 + * Zero (257): 0 + * End (258): 23499 + */ +#ifdef PNG_16BIT_SUPPORTED +static png_int_32 +png_log16bit(png_uint_32 x) +{ + unsigned int lg2 = 0; + + /* As above, but now the input has 16 bits. */ + if ((x &= 0xffff) == 0) + return -1; + + if ((x & 0xff00) == 0) + lg2 = 8, x <<= 8; + + if ((x & 0xf000) == 0) + lg2 += 4, x <<= 4; + + if ((x & 0xc000) == 0) + lg2 += 2, x <<= 2; + + if ((x & 0x8000) == 0) + lg2 += 1, x <<= 1; + + /* Calculate the base logarithm from the top 8 bits as a 28-bit fractional + * value. + */ + lg2 <<= 28; + lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4; + + /* Now we need to interpolate the factor, this requires a division by the top + * 8 bits. Do this with maximum precision. + */ + x = ((x << 16) + (x >> 9)) / (x >> 8); + + /* Since we divided by the top 8 bits of 'x' there will be a '1' at 1<<24, + * the value at 1<<16 (ignoring this) will be 0 or 1; this gives us exactly + * 16 bits to interpolate to get the low bits of the result. Round the + * answer. Note that the end point values are scaled by 64 to retain overall + * precision and that 'lg2' is current scaled by an extra 12 bits, so adjust + * the overall scaling by 6-12. Round at every step. + */ + x -= 1U << 24; + + if (x <= 65536U) /* <= '257' */ + lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12); + + else + lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12); + + /* Safe, because the result can't have more than 20 bits: */ + return (png_int_32)((lg2 + 2048) >> 12); +} +#endif /* 16BIT */ + +/* The 'exp()' case must invert the above, taking a 20-bit fixed point + * logarithmic value and returning a 16 or 8-bit number as appropriate. In + * each case only the low 16 bits are relevant - the fraction - since the + * integer bits (the top 4) simply determine a shift. + * + * The worst case is the 16-bit distinction between 65535 and 65534. This + * requires perhaps spurious accuracy in the decoding of the logarithm to + * distinguish log2(65535/65534.5) - 10^-5 or 17 bits. There is little chance + * of getting this accuracy in practice. + * + * To deal with this the following exp() function works out the exponent of the + * fractional part of the logarithm by using an accurate 32-bit value from the + * top four fractional bits then multiplying in the remaining bits. + */ +static const png_uint_32 +png_32bit_exp[16] = +{ + /* NOTE: the first entry is deliberately set to the maximum 32-bit value. */ + 4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U, + 3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U, + 2553802834U, 2445529972U, 2341847524U, 2242560872U +}; + +/* Adjustment table; provided to explain the numbers in the code below. */ +#if 0 +for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"} + 11 44937.64284865548751208448 + 10 45180.98734845585101160448 + 9 45303.31936980687359311872 + 8 45364.65110595323018870784 + 7 45395.35850361789624614912 + 6 45410.72259715102037508096 + 5 45418.40724413220722311168 + 4 45422.25021786898173001728 + 3 45424.17186732298419044352 + 2 45425.13273269940811464704 + 1 45425.61317555035558641664 + 0 45425.85339951654943850496 +#endif + +static png_uint_32 +png_exp(png_fixed_point x) +{ + if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */ + { + /* Obtain a 4-bit approximation */ + png_uint_32 e = png_32bit_exp[(x >> 12) & 0x0f]; + + /* Incorporate the low 12 bits - these decrease the returned value by + * multiplying by a number less than 1 if the bit is set. The multiplier + * is determined by the above table and the shift. Notice that the values + * converge on 45426 and this is used to allow linear interpolation of the + * low bits. + */ + if (x & 0x800) + e -= (((e >> 16) * 44938U) + 16U) >> 5; + + if (x & 0x400) + e -= (((e >> 16) * 45181U) + 32U) >> 6; + + if (x & 0x200) + e -= (((e >> 16) * 45303U) + 64U) >> 7; + + if (x & 0x100) + e -= (((e >> 16) * 45365U) + 128U) >> 8; + + if (x & 0x080) + e -= (((e >> 16) * 45395U) + 256U) >> 9; + + if (x & 0x040) + e -= (((e >> 16) * 45410U) + 512U) >> 10; + + /* And handle the low 6 bits in a single block. */ + e -= (((e >> 16) * 355U * (x & 0x3fU)) + 256U) >> 9; + + /* Handle the upper bits of x. */ + e >>= x >> 16; + return e; + } + + /* Check for overflow */ + if (x <= 0) + return png_32bit_exp[0]; + + /* Else underflow */ + return 0; +} + +static png_byte +png_exp8bit(png_fixed_point lg2) +{ + /* Get a 32-bit value: */ + png_uint_32 x = png_exp(lg2); + + /* Convert the 32-bit value to 0..255 by multiplying by 256-1. Note that the + * second, rounding, step can't overflow because of the first, subtraction, + * step. + */ + x -= x >> 8; + return (png_byte)(((x + 0x7fffffU) >> 24) & 0xff); +} + +#ifdef PNG_16BIT_SUPPORTED +static png_uint_16 +png_exp16bit(png_fixed_point lg2) +{ + /* Get a 32-bit value: */ + png_uint_32 x = png_exp(lg2); + + /* Convert the 32-bit value to 0..65535 by multiplying by 65536-1: */ + x -= x >> 16; + return (png_uint_16)((x + 32767U) >> 16); +} +#endif /* 16BIT */ +#endif /* FLOATING_ARITHMETIC */ + +png_byte +png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val) +{ + if (value > 0 && value < 255) + { +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + /* 'value' is unsigned, ANSI-C90 requires the compiler to correctly + * convert this to a floating point value. This includes values that + * would overflow if 'value' were to be converted to 'int'. + * + * Apparently GCC, however, does an intermediate conversion to (int) + * on some (ARM) but not all (x86) platforms, possibly because of + * hardware FP limitations. (E.g. if the hardware conversion always + * assumes the integer register contains a signed value.) This results + * in ANSI-C undefined behavior for large values. + * + * Other implementations on the same machine might actually be ANSI-C90 + * conformant and therefore compile spurious extra code for the large + * values. + * + * We can be reasonably sure that an unsigned to float conversion + * won't be faster than an int to float one. Therefore this code + * assumes responsibility for the undefined behavior, which it knows + * can't happen because of the check above. + * + * Note the argument to this routine is an (unsigned int) because, on + * 16-bit platforms, it is assigned a value which might be out of + * range for an (int); that would result in undefined behavior in the + * caller if the *argument* ('value') were to be declared (int). + */ + double r = floor(255*pow((int)/*SAFE*/value/255.,gamma_val*.00001)+.5); + return (png_byte)r; +# else + png_int_32 lg2 = png_log8bit(value); + png_fixed_point res; + + if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0) + return png_exp8bit(res); + + /* Overflow. */ + value = 0; +# endif + } + + return (png_byte)(value & 0xff); +} + +#ifdef PNG_16BIT_SUPPORTED +png_uint_16 +png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val) +{ + if (value > 0 && value < 65535) + { +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + /* The same (unsigned int)->(double) constraints apply here as above, + * however in this case the (unsigned int) to (int) conversion can + * overflow on an ANSI-C90 compliant system so the cast needs to ensure + * that this is not possible. + */ + double r = floor(65535*pow((png_int_32)value/65535., + gamma_val*.00001)+.5); + return (png_uint_16)r; +# else + png_int_32 lg2 = png_log16bit(value); + png_fixed_point res; + + if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0) + return png_exp16bit(res); + + /* Overflow. */ + value = 0; +# endif + } + + return (png_uint_16)value; +} +#endif /* 16BIT */ + +/* This does the right thing based on the bit_depth field of the + * png_struct, interpreting values as 8-bit or 16-bit. While the result + * is nominally a 16-bit value if bit depth is 8 then the result is + * 8-bit (as are the arguments.) + */ +png_uint_16 /* PRIVATE */ +png_gamma_correct(png_structrp png_ptr, unsigned int value, + png_fixed_point gamma_val) +{ + if (png_ptr->bit_depth == 8) + return png_gamma_8bit_correct(value, gamma_val); + +#ifdef PNG_16BIT_SUPPORTED + else + return png_gamma_16bit_correct(value, gamma_val); +#else + /* should not reach this */ + return 0; +#endif /* 16BIT */ +} + +#ifdef PNG_16BIT_SUPPORTED +/* Internal function to build a single 16-bit table - the table consists of + * 'num' 256 entry subtables, where 'num' is determined by 'shift' - the amount + * to shift the input values right (or 16-number_of_signifiant_bits). + * + * The caller is responsible for ensuring that the table gets cleaned up on + * png_error (i.e. if one of the mallocs below fails) - i.e. the *table argument + * should be somewhere that will be cleaned. + */ +static void +png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable, + unsigned int shift, png_fixed_point gamma_val) +{ + /* Various values derived from 'shift': */ + unsigned int num = 1U << (8U - shift); +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + /* CSE the division and work round wacky GCC warnings (see the comments + * in png_gamma_8bit_correct for where these come from.) + */ + double fmax = 1.0 / (((png_int_32)1 << (16U - shift)) - 1); +#endif + unsigned int max = (1U << (16U - shift)) - 1U; + unsigned int max_by_2 = 1U << (15U - shift); + unsigned int i; + + png_uint_16pp table = *ptable = + (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p))); + + for (i = 0; i < num; i++) + { + png_uint_16p sub_table = table[i] = + (png_uint_16p)png_malloc(png_ptr, 256 * (sizeof (png_uint_16))); + + /* The 'threshold' test is repeated here because it can arise for one of + * the 16-bit tables even if the others don't hit it. + */ + if (png_gamma_significant(gamma_val) != 0) + { + /* The old code would overflow at the end and this would cause the + * 'pow' function to return a result >1, resulting in an + * arithmetic error. This code follows the spec exactly; ig is + * the recovered input sample, it always has 8-16 bits. + * + * We want input * 65535/max, rounded, the arithmetic fits in 32 + * bits (unsigned) so long as max <= 32767. + */ + unsigned int j; + for (j = 0; j < 256; j++) + { + png_uint_32 ig = (j << (8-shift)) + i; +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + /* Inline the 'max' scaling operation: */ + /* See png_gamma_8bit_correct for why the cast to (int) is + * required here. + */ + double d = floor(65535.*pow(ig*fmax, gamma_val*.00001)+.5); + sub_table[j] = (png_uint_16)d; +# else + if (shift != 0) + ig = (ig * 65535U + max_by_2)/max; + + sub_table[j] = png_gamma_16bit_correct(ig, gamma_val); +# endif + } + } + else + { + /* We must still build a table, but do it the fast way. */ + unsigned int j; + + for (j = 0; j < 256; j++) + { + png_uint_32 ig = (j << (8-shift)) + i; + + if (shift != 0) + ig = (ig * 65535U + max_by_2)/max; + + sub_table[j] = (png_uint_16)ig; + } + } + } +} + +/* NOTE: this function expects the *inverse* of the overall gamma transformation + * required. + */ +static void +png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable, + unsigned int shift, png_fixed_point gamma_val) +{ + unsigned int num = 1U << (8U - shift); + unsigned int max = (1U << (16U - shift))-1U; + unsigned int i; + png_uint_32 last; + + png_uint_16pp table = *ptable = + (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p))); + + /* 'num' is the number of tables and also the number of low bits of low + * bits of the input 16-bit value used to select a table. Each table is + * itself indexed by the high 8 bits of the value. + */ + for (i = 0; i < num; i++) + table[i] = (png_uint_16p)png_malloc(png_ptr, + 256 * (sizeof (png_uint_16))); + + /* 'gamma_val' is set to the reciprocal of the value calculated above, so + * pow(out,g) is an *input* value. 'last' is the last input value set. + * + * In the loop 'i' is used to find output values. Since the output is + * 8-bit there are only 256 possible values. The tables are set up to + * select the closest possible output value for each input by finding + * the input value at the boundary between each pair of output values + * and filling the table up to that boundary with the lower output + * value. + * + * The boundary values are 0.5,1.5..253.5,254.5. Since these are 9-bit + * values the code below uses a 16-bit value in i; the values start at + * 128.5 (for 0.5) and step by 257, for a total of 254 values (the last + * entries are filled with 255). Start i at 128 and fill all 'last' + * table entries <= 'max' + */ + last = 0; + for (i = 0; i < 255; ++i) /* 8-bit output value */ + { + /* Find the corresponding maximum input value */ + png_uint_16 out = (png_uint_16)(i * 257U); /* 16-bit output value */ + + /* Find the boundary value in 16 bits: */ + png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val); + + /* Adjust (round) to (16-shift) bits: */ + bound = (bound * max + 32768U)/65535U + 1U; + + while (last < bound) + { + table[last & (0xffU >> shift)][last >> (8U - shift)] = out; + last++; + } + } + + /* And fill in the final entries. */ + while (last < (num << 8)) + { + table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U; + last++; + } +} +#endif /* 16BIT */ + +/* Build a single 8-bit table: same as the 16-bit case but much simpler (and + * typically much faster). Note that libpng currently does no sBIT processing + * (apparently contrary to the spec) so a 256-entry table is always generated. + */ +static void +png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable, + png_fixed_point gamma_val) +{ + unsigned int i; + png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256); + + if (png_gamma_significant(gamma_val) != 0) + for (i=0; i<256; i++) + table[i] = png_gamma_8bit_correct(i, gamma_val); + + else + for (i=0; i<256; ++i) + table[i] = (png_byte)(i & 0xff); +} + +/* Used from png_read_destroy and below to release the memory used by the gamma + * tables. + */ +void /* PRIVATE */ +png_destroy_gamma_table(png_structrp png_ptr) +{ + png_free(png_ptr, png_ptr->gamma_table); + png_ptr->gamma_table = NULL; + +#ifdef PNG_16BIT_SUPPORTED + if (png_ptr->gamma_16_table != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_table[i]); + } + png_free(png_ptr, png_ptr->gamma_16_table); + png_ptr->gamma_16_table = NULL; + } +#endif /* 16BIT */ + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + png_free(png_ptr, png_ptr->gamma_from_1); + png_ptr->gamma_from_1 = NULL; + png_free(png_ptr, png_ptr->gamma_to_1); + png_ptr->gamma_to_1 = NULL; + +#ifdef PNG_16BIT_SUPPORTED + if (png_ptr->gamma_16_from_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_from_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_from_1); + png_ptr->gamma_16_from_1 = NULL; + } + if (png_ptr->gamma_16_to_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_to_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_to_1); + png_ptr->gamma_16_to_1 = NULL; + } +#endif /* 16BIT */ +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ +} + +/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit + * tables, we don't make a full table if we are reducing to 8-bit in + * the future. Note also how the gamma_16 tables are segmented so that + * we don't need to allocate > 64K chunks for a full 16-bit table. + */ +void /* PRIVATE */ +png_build_gamma_table(png_structrp png_ptr, int bit_depth) +{ + png_debug(1, "in png_build_gamma_table"); + + /* Remove any existing table; this copes with multiple calls to + * png_read_update_info. The warning is because building the gamma tables + * multiple times is a performance hit - it's harmless but the ability to + * call png_read_update_info() multiple times is new in 1.5.6 so it seems + * sensible to warn if the app introduces such a hit. + */ + if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL) + { + png_warning(png_ptr, "gamma table being rebuilt"); + png_destroy_gamma_table(png_ptr); + } + + if (bit_depth <= 8) + { + png_build_8bit_table(png_ptr, &png_ptr->gamma_table, + png_ptr->screen_gamma > 0 ? + png_reciprocal2(png_ptr->colorspace.gamma, + png_ptr->screen_gamma) : PNG_FP_1); + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0) + { + png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1, + png_reciprocal(png_ptr->colorspace.gamma)); + + png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1, + png_ptr->screen_gamma > 0 ? + png_reciprocal(png_ptr->screen_gamma) : + png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */); + } +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ + } +#ifdef PNG_16BIT_SUPPORTED + else + { + png_byte shift, sig_bit; + + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + sig_bit = png_ptr->sig_bit.red; + + if (png_ptr->sig_bit.green > sig_bit) + sig_bit = png_ptr->sig_bit.green; + + if (png_ptr->sig_bit.blue > sig_bit) + sig_bit = png_ptr->sig_bit.blue; + } + else + sig_bit = png_ptr->sig_bit.gray; + + /* 16-bit gamma code uses this equation: + * + * ov = table[(iv & 0xff) >> gamma_shift][iv >> 8] + * + * Where 'iv' is the input color value and 'ov' is the output value - + * pow(iv, gamma). + * + * Thus the gamma table consists of up to 256 256-entry tables. The table + * is selected by the (8-gamma_shift) most significant of the low 8 bits + * of the color value then indexed by the upper 8 bits: + * + * table[low bits][high 8 bits] + * + * So the table 'n' corresponds to all those 'iv' of: + * + * ..<(n+1 << gamma_shift)-1> + * + */ + if (sig_bit > 0 && sig_bit < 16U) + /* shift == insignificant bits */ + shift = (png_byte)((16U - sig_bit) & 0xff); + + else + shift = 0; /* keep all 16 bits */ + + if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0) + { + /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively + * the significant bits in the *input* when the output will + * eventually be 8 bits. By default it is 11. + */ + if (shift < (16U - PNG_MAX_GAMMA_8)) + shift = (16U - PNG_MAX_GAMMA_8); + } + + if (shift > 8U) + shift = 8U; /* Guarantees at least one table! */ + + png_ptr->gamma_shift = shift; + + /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now + * PNG_COMPOSE). This effectively smashed the background calculation for + * 16-bit output because the 8-bit table assumes the result will be + * reduced to 8 bits. + */ + if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0) + png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift, + png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma, + png_ptr->screen_gamma) : PNG_FP_1); + + else + png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift, + png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma, + png_ptr->screen_gamma) : PNG_FP_1); + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0) + { + png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift, + png_reciprocal(png_ptr->colorspace.gamma)); + + /* Notice that the '16 from 1' table should be full precision, however + * the lookup on this table still uses gamma_shift, so it can't be. + * TODO: fix this. + */ + png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift, + png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : + png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */); + } +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ + } +#endif /* 16BIT */ +} +#endif /* READ_GAMMA */ + +/* HARDWARE OR SOFTWARE OPTION SUPPORT */ +#ifdef PNG_SET_OPTION_SUPPORTED +int PNGAPI +png_set_option(png_structrp png_ptr, int option, int onoff) +{ + if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT && + (option & 1) == 0) + { + png_uint_32 mask = 3U << option; + png_uint_32 setting = (2U + (onoff != 0)) << option; + png_uint_32 current = png_ptr->options; + + png_ptr->options = (png_uint_32)((current & ~mask) | setting); + + return (int)(current & mask) >> option; + } + + return PNG_OPTION_INVALID; +} +#endif + +/* sRGB support */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +/* sRGB conversion tables; these are machine generated with the code in + * contrib/tools/makesRGB.c. The actual sRGB transfer curve defined in the + * specification (see the article at https://en.wikipedia.org/wiki/SRGB) + * is used, not the gamma=1/2.2 approximation use elsewhere in libpng. + * The sRGB to linear table is exact (to the nearest 16-bit linear fraction). + * The inverse (linear to sRGB) table has accuracies as follows: + * + * For all possible (255*65535+1) input values: + * + * error: -0.515566 - 0.625971, 79441 (0.475369%) of readings inexact + * + * For the input values corresponding to the 65536 16-bit values: + * + * error: -0.513727 - 0.607759, 308 (0.469978%) of readings inexact + * + * In all cases the inexact readings are only off by one. + */ + +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +/* The convert-to-sRGB table is only currently required for read. */ +const png_uint_16 png_sRGB_table[256] = +{ + 0,20,40,60,80,99,119,139, + 159,179,199,219,241,264,288,313, + 340,367,396,427,458,491,526,562, + 599,637,677,718,761,805,851,898, + 947,997,1048,1101,1156,1212,1270,1330, + 1391,1453,1517,1583,1651,1720,1790,1863, + 1937,2013,2090,2170,2250,2333,2418,2504, + 2592,2681,2773,2866,2961,3058,3157,3258, + 3360,3464,3570,3678,3788,3900,4014,4129, + 4247,4366,4488,4611,4736,4864,4993,5124, + 5257,5392,5530,5669,5810,5953,6099,6246, + 6395,6547,6700,6856,7014,7174,7335,7500, + 7666,7834,8004,8177,8352,8528,8708,8889, + 9072,9258,9445,9635,9828,10022,10219,10417, + 10619,10822,11028,11235,11446,11658,11873,12090, + 12309,12530,12754,12980,13209,13440,13673,13909, + 14146,14387,14629,14874,15122,15371,15623,15878, + 16135,16394,16656,16920,17187,17456,17727,18001, + 18277,18556,18837,19121,19407,19696,19987,20281, + 20577,20876,21177,21481,21787,22096,22407,22721, + 23038,23357,23678,24002,24329,24658,24990,25325, + 25662,26001,26344,26688,27036,27386,27739,28094, + 28452,28813,29176,29542,29911,30282,30656,31033, + 31412,31794,32179,32567,32957,33350,33745,34143, + 34544,34948,35355,35764,36176,36591,37008,37429, + 37852,38278,38706,39138,39572,40009,40449,40891, + 41337,41785,42236,42690,43147,43606,44069,44534, + 45002,45473,45947,46423,46903,47385,47871,48359, + 48850,49344,49841,50341,50844,51349,51858,52369, + 52884,53401,53921,54445,54971,55500,56032,56567, + 57105,57646,58190,58737,59287,59840,60396,60955, + 61517,62082,62650,63221,63795,64372,64952,65535 +}; +#endif /* SIMPLIFIED_READ */ + +/* The base/delta tables are required for both read and write (but currently + * only the simplified versions.) + */ +const png_uint_16 png_sRGB_base[512] = +{ + 128,1782,3383,4644,5675,6564,7357,8074, + 8732,9346,9921,10463,10977,11466,11935,12384, + 12816,13233,13634,14024,14402,14769,15125,15473, + 15812,16142,16466,16781,17090,17393,17690,17981, + 18266,18546,18822,19093,19359,19621,19879,20133, + 20383,20630,20873,21113,21349,21583,21813,22041, + 22265,22487,22707,22923,23138,23350,23559,23767, + 23972,24175,24376,24575,24772,24967,25160,25352, + 25542,25730,25916,26101,26284,26465,26645,26823, + 27000,27176,27350,27523,27695,27865,28034,28201, + 28368,28533,28697,28860,29021,29182,29341,29500, + 29657,29813,29969,30123,30276,30429,30580,30730, + 30880,31028,31176,31323,31469,31614,31758,31902, + 32045,32186,32327,32468,32607,32746,32884,33021, + 33158,33294,33429,33564,33697,33831,33963,34095, + 34226,34357,34486,34616,34744,34873,35000,35127, + 35253,35379,35504,35629,35753,35876,35999,36122, + 36244,36365,36486,36606,36726,36845,36964,37083, + 37201,37318,37435,37551,37668,37783,37898,38013, + 38127,38241,38354,38467,38580,38692,38803,38915, + 39026,39136,39246,39356,39465,39574,39682,39790, + 39898,40005,40112,40219,40325,40431,40537,40642, + 40747,40851,40955,41059,41163,41266,41369,41471, + 41573,41675,41777,41878,41979,42079,42179,42279, + 42379,42478,42577,42676,42775,42873,42971,43068, + 43165,43262,43359,43456,43552,43648,43743,43839, + 43934,44028,44123,44217,44311,44405,44499,44592, + 44685,44778,44870,44962,45054,45146,45238,45329, + 45420,45511,45601,45692,45782,45872,45961,46051, + 46140,46229,46318,46406,46494,46583,46670,46758, + 46846,46933,47020,47107,47193,47280,47366,47452, + 47538,47623,47709,47794,47879,47964,48048,48133, + 48217,48301,48385,48468,48552,48635,48718,48801, + 48884,48966,49048,49131,49213,49294,49376,49458, + 49539,49620,49701,49782,49862,49943,50023,50103, + 50183,50263,50342,50422,50501,50580,50659,50738, + 50816,50895,50973,51051,51129,51207,51285,51362, + 51439,51517,51594,51671,51747,51824,51900,51977, + 52053,52129,52205,52280,52356,52432,52507,52582, + 52657,52732,52807,52881,52956,53030,53104,53178, + 53252,53326,53400,53473,53546,53620,53693,53766, + 53839,53911,53984,54056,54129,54201,54273,54345, + 54417,54489,54560,54632,54703,54774,54845,54916, + 54987,55058,55129,55199,55269,55340,55410,55480, + 55550,55620,55689,55759,55828,55898,55967,56036, + 56105,56174,56243,56311,56380,56448,56517,56585, + 56653,56721,56789,56857,56924,56992,57059,57127, + 57194,57261,57328,57395,57462,57529,57595,57662, + 57728,57795,57861,57927,57993,58059,58125,58191, + 58256,58322,58387,58453,58518,58583,58648,58713, + 58778,58843,58908,58972,59037,59101,59165,59230, + 59294,59358,59422,59486,59549,59613,59677,59740, + 59804,59867,59930,59993,60056,60119,60182,60245, + 60308,60370,60433,60495,60558,60620,60682,60744, + 60806,60868,60930,60992,61054,61115,61177,61238, + 61300,61361,61422,61483,61544,61605,61666,61727, + 61788,61848,61909,61969,62030,62090,62150,62211, + 62271,62331,62391,62450,62510,62570,62630,62689, + 62749,62808,62867,62927,62986,63045,63104,63163, + 63222,63281,63340,63398,63457,63515,63574,63632, + 63691,63749,63807,63865,63923,63981,64039,64097, + 64155,64212,64270,64328,64385,64443,64500,64557, + 64614,64672,64729,64786,64843,64900,64956,65013, + 65070,65126,65183,65239,65296,65352,65409,65465 +}; + +const png_byte png_sRGB_delta[512] = +{ + 207,201,158,129,113,100,90,82,77,72,68,64,61,59,56,54, + 52,50,49,47,46,45,43,42,41,40,39,39,38,37,36,36, + 35,34,34,33,33,32,32,31,31,30,30,30,29,29,28,28, + 28,27,27,27,27,26,26,26,25,25,25,25,24,24,24,24, + 23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21, + 21,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19, + 19,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17, + 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16, + 16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15, + 15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14, + 14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13, + 13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12, + 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11, + 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, + 11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, + 10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 +}; +#endif /* SIMPLIFIED READ/WRITE sRGB support */ + +/* SIMPLIFIED READ/WRITE SUPPORT */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +static int +png_image_free_function(png_voidp argument) +{ + png_imagep image = png_voidcast(png_imagep, argument); + png_controlp cp = image->opaque; + png_control c; + + /* Double check that we have a png_ptr - it should be impossible to get here + * without one. + */ + if (cp->png_ptr == NULL) + return 0; + + /* First free any data held in the control structure. */ +# ifdef PNG_STDIO_SUPPORTED + if (cp->owned_file != 0) + { + FILE *fp = png_voidcast(FILE*, cp->png_ptr->io_ptr); + cp->owned_file = 0; + + /* Ignore errors here. */ + if (fp != NULL) + { + cp->png_ptr->io_ptr = NULL; + (void)fclose(fp); + } + } +# endif + + /* Copy the control structure so that the original, allocated, version can be + * safely freed. Notice that a png_error here stops the remainder of the + * cleanup, but this is probably fine because that would indicate bad memory + * problems anyway. + */ + c = *cp; + image->opaque = &c; + png_free(c.png_ptr, cp); + + /* Then the structures, calling the correct API. */ + if (c.for_write != 0) + { +# ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED + png_destroy_write_struct(&c.png_ptr, &c.info_ptr); +# else + png_error(c.png_ptr, "simplified write not supported"); +# endif + } + else + { +# ifdef PNG_SIMPLIFIED_READ_SUPPORTED + png_destroy_read_struct(&c.png_ptr, &c.info_ptr, NULL); +# else + png_error(c.png_ptr, "simplified read not supported"); +# endif + } + + /* Success. */ + return 1; +} + +void PNGAPI +png_image_free(png_imagep image) +{ + /* Safely call the real function, but only if doing so is safe at this point + * (if not inside an error handling context). Otherwise assume + * png_safe_execute will call this API after the return. + */ + if (image != NULL && image->opaque != NULL && + image->opaque->error_buf == NULL) + { + png_image_free_function(image); + image->opaque = NULL; + } +} + +int /* PRIVATE */ +png_image_error(png_imagep image, png_const_charp error_message) +{ + /* Utility to log an error. */ + png_safecat(image->message, (sizeof image->message), 0, error_message); + image->warning_or_error |= PNG_IMAGE_ERROR; + png_image_free(image); + return 0; +} + +#endif /* SIMPLIFIED READ/WRITE */ +#endif /* READ || WRITE */ diff --git a/extern/libpng/png.h b/extern/libpng/png.h new file mode 100644 index 000000000..139eb0dc0 --- /dev/null +++ b/extern/libpng/png.h @@ -0,0 +1,3247 @@ + +/* png.h - header file for PNG reference library + * + * libpng version 1.6.37 - April 14, 2019 + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. (See LICENSE, below.) + * + * Authors and maintainers: + * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat + * libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger + * libpng versions 0.97, January 1998, through 1.6.35, July 2018: + * Glenn Randers-Pehrson + * libpng versions 1.6.36, December 2018, through 1.6.37, April 2019: + * Cosmin Truta + * See also "Contributing Authors", below. + */ + +/* + * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE + * ========================================= + * + * PNG Reference Library License version 2 + * --------------------------------------- + * + * * Copyright (c) 1995-2019 The PNG Reference Library Authors. + * * Copyright (c) 2018-2019 Cosmin Truta. + * * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson. + * * Copyright (c) 1996-1997 Andreas Dilger. + * * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * The software is supplied "as is", without warranty of any kind, + * express or implied, including, without limitation, the warranties + * of merchantability, fitness for a particular purpose, title, and + * non-infringement. In no event shall the Copyright owners, or + * anyone distributing the software, be liable for any damages or + * other liability, whether in contract, tort or otherwise, arising + * from, out of, or in connection with the software, or the use or + * other dealings in the software, even if advised of the possibility + * of such damage. + * + * Permission is hereby granted to use, copy, modify, and distribute + * this software, or portions hereof, for any purpose, without fee, + * subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you + * must not claim that you wrote the original software. If you + * use this software in a product, an acknowledgment in the product + * documentation would be appreciated, but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must + * not be misrepresented as being the original software. + * + * 3. This Copyright notice may not be removed or altered from any + * source or altered source distribution. + * + * + * PNG Reference Library License version 1 (for libpng 0.5 through 1.6.35) + * ----------------------------------------------------------------------- + * + * libpng versions 1.0.7, July 1, 2000, through 1.6.35, July 15, 2018 are + * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are + * derived from libpng-1.0.6, and are distributed according to the same + * disclaimer and license as libpng-1.0.6 with the following individuals + * added to the list of Contributing Authors: + * + * Simon-Pierre Cadieux + * Eric S. Raymond + * Mans Rullgard + * Cosmin Truta + * Gilles Vollant + * James Yu + * Mandar Sahastrabuddhe + * Google Inc. + * Vadim Barkov + * + * and with the following additions to the disclaimer: + * + * There is no warranty against interference with your enjoyment of + * the library or against infringement. There is no warranty that our + * efforts or the library will fulfill any of your particular purposes + * or needs. This library is provided with all faults, and the entire + * risk of satisfactory quality, performance, accuracy, and effort is + * with the user. + * + * Some files in the "contrib" directory and some configure-generated + * files that are distributed with libpng have other copyright owners, and + * are released under other open source licenses. + * + * libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are + * Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from + * libpng-0.96, and are distributed according to the same disclaimer and + * license as libpng-0.96, with the following individuals added to the + * list of Contributing Authors: + * + * Tom Lane + * Glenn Randers-Pehrson + * Willem van Schaik + * + * libpng versions 0.89, June 1996, through 0.96, May 1997, are + * Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88, + * and are distributed according to the same disclaimer and license as + * libpng-0.88, with the following individuals added to the list of + * Contributing Authors: + * + * John Bowler + * Kevin Bracey + * Sam Bushell + * Magnus Holmgren + * Greg Roelofs + * Tom Tanner + * + * Some files in the "scripts" directory have other copyright owners, + * but are released under this license. + * + * libpng versions 0.5, May 1995, through 0.88, January 1996, are + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * For the purposes of this copyright and license, "Contributing Authors" + * is defined as the following set of individuals: + * + * Andreas Dilger + * Dave Martindale + * Guy Eric Schalnat + * Paul Schmidt + * Tim Wegner + * + * The PNG Reference Library is supplied "AS IS". The Contributing + * Authors and Group 42, Inc. disclaim all warranties, expressed or + * implied, including, without limitation, the warranties of + * merchantability and of fitness for any purpose. The Contributing + * Authors and Group 42, Inc. assume no liability for direct, indirect, + * incidental, special, exemplary, or consequential damages, which may + * result from the use of the PNG Reference Library, even if advised of + * the possibility of such damage. + * + * Permission is hereby granted to use, copy, modify, and distribute this + * source code, or portions hereof, for any purpose, without fee, subject + * to the following restrictions: + * + * 1. The origin of this source code must not be misrepresented. + * + * 2. Altered versions must be plainly marked as such and must not + * be misrepresented as being the original source. + * + * 3. This Copyright notice may not be removed or altered from any + * source or altered source distribution. + * + * The Contributing Authors and Group 42, Inc. specifically permit, + * without fee, and encourage the use of this source code as a component + * to supporting the PNG file format in commercial products. If you use + * this source code in a product, acknowledgment is not required but would + * be appreciated. + * + * END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE. + * + * TRADEMARK + * ========= + * + * The name "libpng" has not been registered by the Copyright owners + * as a trademark in any jurisdiction. However, because libpng has + * been distributed and maintained world-wide, continually since 1995, + * the Copyright owners claim "common-law trademark protection" in any + * jurisdiction where common-law trademark is recognized. + */ + +/* + * A "png_get_copyright" function is available, for convenient use in "about" + * boxes and the like: + * + * printf("%s", png_get_copyright(NULL)); + * + * Also, the PNG logo (in PNG format, of course) is supplied in the + * files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). + */ + +/* + * The contributing authors would like to thank all those who helped + * with testing, bug fixes, and patience. This wouldn't have been + * possible without all of you. + * + * Thanks to Frank J. T. Wojcik for helping with the documentation. + */ + +/* Note about libpng version numbers: + * + * Due to various miscommunications, unforeseen code incompatibilities + * and occasional factors outside the authors' control, version numbering + * on the library has not always been consistent and straightforward. + * The following table summarizes matters since version 0.89c, which was + * the first widely used release: + * + * source png.h png.h shared-lib + * version string int version + * ------- ------ ----- ---------- + * 0.89c "1.0 beta 3" 0.89 89 1.0.89 + * 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90] + * 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95] + * 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96] + * 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97] + * 0.97c 0.97 97 2.0.97 + * 0.98 0.98 98 2.0.98 + * 0.99 0.99 98 2.0.99 + * 0.99a-m 0.99 99 2.0.99 + * 1.00 1.00 100 2.1.0 [100 should be 10000] + * 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000] + * 1.0.1 png.h string is 10001 2.1.0 + * 1.0.1a-e identical to the 10002 from here on, the shared library + * 1.0.2 source version) 10002 is 2.V where V is the source code + * 1.0.2a-b 10003 version, except as noted. + * 1.0.3 10003 + * 1.0.3a-d 10004 + * 1.0.4 10004 + * 1.0.4a-f 10005 + * 1.0.5 (+ 2 patches) 10005 + * 1.0.5a-d 10006 + * 1.0.5e-r 10100 (not source compatible) + * 1.0.5s-v 10006 (not binary compatible) + * 1.0.6 (+ 3 patches) 10006 (still binary incompatible) + * 1.0.6d-f 10007 (still binary incompatible) + * 1.0.6g 10007 + * 1.0.6h 10007 10.6h (testing xy.z so-numbering) + * 1.0.6i 10007 10.6i + * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0) + * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible) + * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) + * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) + * 1.0.7 1 10007 (still compatible) + * ... + * 1.0.69 10 10069 10.so.0.69[.0] + * ... + * 1.2.59 13 10259 12.so.0.59[.0] + * ... + * 1.4.20 14 10420 14.so.0.20[.0] + * ... + * 1.5.30 15 10530 15.so.15.30[.0] + * ... + * 1.6.37 16 10637 16.so.16.37[.0] + * + * Henceforth the source version will match the shared-library major and + * minor numbers; the shared-library major version number will be used for + * changes in backward compatibility, as it is intended. + * The PNG_LIBPNG_VER macro, which is not used within libpng but is + * available for applications, is an unsigned integer of the form XYYZZ + * corresponding to the source version X.Y.Z (leading zeros in Y and Z). + * Beta versions were given the previous public release number plus a + * letter, until version 1.0.6j; from then on they were given the upcoming + * public release number plus "betaNN" or "rcNN". + * + * Binary incompatibility exists only when applications make direct access + * to the info_ptr or png_ptr members through png.h, and the compiled + * application is loaded with a different version of the library. + * + * DLLNUM will change each time there are forward or backward changes + * in binary compatibility (e.g., when a new feature is added). + * + * See libpng.txt or libpng.3 for more information. The PNG specification + * is available as a W3C Recommendation and as an ISO/IEC Standard; see + * + */ + +#ifndef PNG_H +#define PNG_H + +/* This is not the place to learn how to use libpng. The file libpng-manual.txt + * describes how to use libpng, and the file example.c summarizes it + * with some code on which to build. This file is useful for looking + * at the actual function definitions and structure components. If that + * file has been stripped from your copy of libpng, you can find it at + * + * + * If you just need to read a PNG file and don't want to read the documentation + * skip to the end of this file and read the section entitled 'simplified API'. + */ + +/* Version information for png.h - this should match the version in png.c */ +#define PNG_LIBPNG_VER_STRING "1.6.37" +#define PNG_HEADER_VERSION_STRING " libpng version 1.6.37 - April 14, 2019\n" + +#define PNG_LIBPNG_VER_SONUM 16 +#define PNG_LIBPNG_VER_DLLNUM 16 + +/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ +#define PNG_LIBPNG_VER_MAJOR 1 +#define PNG_LIBPNG_VER_MINOR 6 +#define PNG_LIBPNG_VER_RELEASE 37 + +/* This should be zero for a public release, or non-zero for a + * development version. [Deprecated] + */ +#define PNG_LIBPNG_VER_BUILD 0 + +/* Release Status */ +#define PNG_LIBPNG_BUILD_ALPHA 1 +#define PNG_LIBPNG_BUILD_BETA 2 +#define PNG_LIBPNG_BUILD_RC 3 +#define PNG_LIBPNG_BUILD_STABLE 4 +#define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7 + +/* Release-Specific Flags */ +#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with + PNG_LIBPNG_BUILD_STABLE only */ +#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with + PNG_LIBPNG_BUILD_SPECIAL */ +#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with + PNG_LIBPNG_BUILD_PRIVATE */ + +#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE + +/* Careful here. At one time, Guy wanted to use 082, but that + * would be octal. We must not include leading zeros. + * Versions 0.7 through 1.0.0 were in the range 0 to 100 here + * (only version 1.0.0 was mis-numbered 100 instead of 10000). + * From version 1.0.1 it is: + * XXYYZZ, where XX=major, YY=minor, ZZ=release + */ +#define PNG_LIBPNG_VER 10637 /* 1.6.37 */ + +/* Library configuration: these options cannot be changed after + * the library has been built. + */ +#ifndef PNGLCONF_H +/* If pnglibconf.h is missing, you can + * copy scripts/pnglibconf.h.prebuilt to pnglibconf.h + */ +# include "pnglibconf.h" +#endif + +#ifndef PNG_VERSION_INFO_ONLY +/* Machine specific configuration. */ +# include "pngconf.h" +#endif + +/* + * Added at libpng-1.2.8 + * + * Ref MSDN: Private as priority over Special + * VS_FF_PRIVATEBUILD File *was not* built using standard release + * procedures. If this value is given, the StringFileInfo block must + * contain a PrivateBuild string. + * + * VS_FF_SPECIALBUILD File *was* built by the original company using + * standard release procedures but is a variation of the standard + * file of the same version number. If this value is given, the + * StringFileInfo block must contain a SpecialBuild string. + */ + +#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */ +# define PNG_LIBPNG_BUILD_TYPE \ + (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE) +#else +# ifdef PNG_LIBPNG_SPECIALBUILD +# define PNG_LIBPNG_BUILD_TYPE \ + (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL) +# else +# define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE) +# endif +#endif + +#ifndef PNG_VERSION_INFO_ONLY + +/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Version information for C files, stored in png.c. This had better match + * the version above. + */ +#define png_libpng_ver png_get_header_ver(NULL) + +/* This file is arranged in several sections: + * + * 1. [omitted] + * 2. Any configuration options that can be specified by for the application + * code when it is built. (Build time configuration is in pnglibconf.h) + * 3. Type definitions (base types are defined in pngconf.h), structure + * definitions. + * 4. Exported library functions. + * 5. Simplified API. + * 6. Implementation options. + * + * The library source code has additional files (principally pngpriv.h) that + * allow configuration of the library. + */ + +/* Section 1: [omitted] */ + +/* Section 2: run time configuration + * See pnglibconf.h for build time configuration + * + * Run time configuration allows the application to choose between + * implementations of certain arithmetic APIs. The default is set + * at build time and recorded in pnglibconf.h, but it is safe to + * override these (and only these) settings. Note that this won't + * change what the library does, only application code, and the + * settings can (and probably should) be made on a per-file basis + * by setting the #defines before including png.h + * + * Use macros to read integers from PNG data or use the exported + * functions? + * PNG_USE_READ_MACROS: use the macros (see below) Note that + * the macros evaluate their argument multiple times. + * PNG_NO_USE_READ_MACROS: call the relevant library function. + * + * Use the alternative algorithm for compositing alpha samples that + * does not use division? + * PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division' + * algorithm. + * PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm. + * + * How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is + * false? + * PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error + * APIs to png_warning. + * Otherwise the calls are mapped to png_error. + */ + +/* Section 3: type definitions, including structures and compile time + * constants. + * See pngconf.h for base types that vary by machine/system + */ + +/* This triggers a compiler error in png.c, if png.c and png.h + * do not agree upon the version number. + */ +typedef char* png_libpng_version_1_6_37; + +/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info. + * + * png_struct is the cache of information used while reading or writing a single + * PNG file. One of these is always required, although the simplified API + * (below) hides the creation and destruction of it. + */ +typedef struct png_struct_def png_struct; +typedef const png_struct * png_const_structp; +typedef png_struct * png_structp; +typedef png_struct * * png_structpp; + +/* png_info contains information read from or to be written to a PNG file. One + * or more of these must exist while reading or creating a PNG file. The + * information is not used by libpng during read but is used to control what + * gets written when a PNG file is created. "png_get_" function calls read + * information during read and "png_set_" functions calls write information + * when creating a PNG. + * been moved into a separate header file that is not accessible to + * applications. Read libpng-manual.txt or libpng.3 for more info. + */ +typedef struct png_info_def png_info; +typedef png_info * png_infop; +typedef const png_info * png_const_infop; +typedef png_info * * png_infopp; + +/* Types with names ending 'p' are pointer types. The corresponding types with + * names ending 'rp' are identical pointer types except that the pointer is + * marked 'restrict', which means that it is the only pointer to the object + * passed to the function. Applications should not use the 'restrict' types; + * it is always valid to pass 'p' to a pointer with a function argument of the + * corresponding 'rp' type. Different compilers have different rules with + * regard to type matching in the presence of 'restrict'. For backward + * compatibility libpng callbacks never have 'restrict' in their parameters and, + * consequentially, writing portable application code is extremely difficult if + * an attempt is made to use 'restrict'. + */ +typedef png_struct * PNG_RESTRICT png_structrp; +typedef const png_struct * PNG_RESTRICT png_const_structrp; +typedef png_info * PNG_RESTRICT png_inforp; +typedef const png_info * PNG_RESTRICT png_const_inforp; + +/* Three color definitions. The order of the red, green, and blue, (and the + * exact size) is not important, although the size of the fields need to + * be png_byte or png_uint_16 (as defined below). + */ +typedef struct png_color_struct +{ + png_byte red; + png_byte green; + png_byte blue; +} png_color; +typedef png_color * png_colorp; +typedef const png_color * png_const_colorp; +typedef png_color * * png_colorpp; + +typedef struct png_color_16_struct +{ + png_byte index; /* used for palette files */ + png_uint_16 red; /* for use in red green blue files */ + png_uint_16 green; + png_uint_16 blue; + png_uint_16 gray; /* for use in grayscale files */ +} png_color_16; +typedef png_color_16 * png_color_16p; +typedef const png_color_16 * png_const_color_16p; +typedef png_color_16 * * png_color_16pp; + +typedef struct png_color_8_struct +{ + png_byte red; /* for use in red green blue files */ + png_byte green; + png_byte blue; + png_byte gray; /* for use in grayscale files */ + png_byte alpha; /* for alpha channel files */ +} png_color_8; +typedef png_color_8 * png_color_8p; +typedef const png_color_8 * png_const_color_8p; +typedef png_color_8 * * png_color_8pp; + +/* + * The following two structures are used for the in-core representation + * of sPLT chunks. + */ +typedef struct png_sPLT_entry_struct +{ + png_uint_16 red; + png_uint_16 green; + png_uint_16 blue; + png_uint_16 alpha; + png_uint_16 frequency; +} png_sPLT_entry; +typedef png_sPLT_entry * png_sPLT_entryp; +typedef const png_sPLT_entry * png_const_sPLT_entryp; +typedef png_sPLT_entry * * png_sPLT_entrypp; + +/* When the depth of the sPLT palette is 8 bits, the color and alpha samples + * occupy the LSB of their respective members, and the MSB of each member + * is zero-filled. The frequency member always occupies the full 16 bits. + */ + +typedef struct png_sPLT_struct +{ + png_charp name; /* palette name */ + png_byte depth; /* depth of palette samples */ + png_sPLT_entryp entries; /* palette entries */ + png_int_32 nentries; /* number of palette entries */ +} png_sPLT_t; +typedef png_sPLT_t * png_sPLT_tp; +typedef const png_sPLT_t * png_const_sPLT_tp; +typedef png_sPLT_t * * png_sPLT_tpp; + +#ifdef PNG_TEXT_SUPPORTED +/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file, + * and whether that contents is compressed or not. The "key" field + * points to a regular zero-terminated C string. The "text" fields can be a + * regular C string, an empty string, or a NULL pointer. + * However, the structure returned by png_get_text() will always contain + * the "text" field as a regular zero-terminated C string (possibly + * empty), never a NULL pointer, so it can be safely used in printf() and + * other string-handling functions. Note that the "itxt_length", "lang", and + * "lang_key" members of the structure only exist when the library is built + * with iTXt chunk support. Prior to libpng-1.4.0 the library was built by + * default without iTXt support. Also note that when iTXt *is* supported, + * the "lang" and "lang_key" fields contain NULL pointers when the + * "compression" field contains * PNG_TEXT_COMPRESSION_NONE or + * PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the + * same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag" + * which is always 0 or 1, or its "compression method" which is always 0. + */ +typedef struct png_text_struct +{ + int compression; /* compression value: + -1: tEXt, none + 0: zTXt, deflate + 1: iTXt, none + 2: iTXt, deflate */ + png_charp key; /* keyword, 1-79 character description of "text" */ + png_charp text; /* comment, may be an empty string (ie "") + or a NULL pointer */ + size_t text_length; /* length of the text string */ + size_t itxt_length; /* length of the itxt string */ + png_charp lang; /* language code, 0-79 characters + or a NULL pointer */ + png_charp lang_key; /* keyword translated UTF-8 string, 0 or more + chars or a NULL pointer */ +} png_text; +typedef png_text * png_textp; +typedef const png_text * png_const_textp; +typedef png_text * * png_textpp; +#endif + +/* Supported compression types for text in PNG files (tEXt, and zTXt). + * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */ +#define PNG_TEXT_COMPRESSION_NONE_WR -3 +#define PNG_TEXT_COMPRESSION_zTXt_WR -2 +#define PNG_TEXT_COMPRESSION_NONE -1 +#define PNG_TEXT_COMPRESSION_zTXt 0 +#define PNG_ITXT_COMPRESSION_NONE 1 +#define PNG_ITXT_COMPRESSION_zTXt 2 +#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */ + +/* png_time is a way to hold the time in an machine independent way. + * Two conversions are provided, both from time_t and struct tm. There + * is no portable way to convert to either of these structures, as far + * as I know. If you know of a portable way, send it to me. As a side + * note - PNG has always been Year 2000 compliant! + */ +typedef struct png_time_struct +{ + png_uint_16 year; /* full year, as in, 1995 */ + png_byte month; /* month of year, 1 - 12 */ + png_byte day; /* day of month, 1 - 31 */ + png_byte hour; /* hour of day, 0 - 23 */ + png_byte minute; /* minute of hour, 0 - 59 */ + png_byte second; /* second of minute, 0 - 60 (for leap seconds) */ +} png_time; +typedef png_time * png_timep; +typedef const png_time * png_const_timep; +typedef png_time * * png_timepp; + +#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) ||\ + defined(PNG_USER_CHUNKS_SUPPORTED) +/* png_unknown_chunk is a structure to hold queued chunks for which there is + * no specific support. The idea is that we can use this to queue + * up private chunks for output even though the library doesn't actually + * know about their semantics. + * + * The data in the structure is set by libpng on read and used on write. + */ +typedef struct png_unknown_chunk_t +{ + png_byte name[5]; /* Textual chunk name with '\0' terminator */ + png_byte *data; /* Data, should not be modified on read! */ + size_t size; + + /* On write 'location' must be set using the flag values listed below. + * Notice that on read it is set by libpng however the values stored have + * more bits set than are listed below. Always treat the value as a + * bitmask. On write set only one bit - setting multiple bits may cause the + * chunk to be written in multiple places. + */ + png_byte location; /* mode of operation at read time */ +} +png_unknown_chunk; + +typedef png_unknown_chunk * png_unknown_chunkp; +typedef const png_unknown_chunk * png_const_unknown_chunkp; +typedef png_unknown_chunk * * png_unknown_chunkpp; +#endif + +/* Flag values for the unknown chunk location byte. */ +#define PNG_HAVE_IHDR 0x01 +#define PNG_HAVE_PLTE 0x02 +#define PNG_AFTER_IDAT 0x08 + +/* Maximum positive integer used in PNG is (2^31)-1 */ +#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) +#define PNG_UINT_32_MAX ((png_uint_32)(-1)) +#define PNG_SIZE_MAX ((size_t)(-1)) + +/* These are constants for fixed point values encoded in the + * PNG specification manner (x100000) + */ +#define PNG_FP_1 100000 +#define PNG_FP_HALF 50000 +#define PNG_FP_MAX ((png_fixed_point)0x7fffffffL) +#define PNG_FP_MIN (-PNG_FP_MAX) + +/* These describe the color_type field in png_info. */ +/* color type masks */ +#define PNG_COLOR_MASK_PALETTE 1 +#define PNG_COLOR_MASK_COLOR 2 +#define PNG_COLOR_MASK_ALPHA 4 + +/* color types. Note that not all combinations are legal */ +#define PNG_COLOR_TYPE_GRAY 0 +#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE) +#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR) +#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA) +#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA) +/* aliases */ +#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA +#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA + +/* This is for compression type. PNG 1.0-1.2 only define the single type. */ +#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */ +#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE + +/* This is for filter type. PNG 1.0-1.2 only define the single type. */ +#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */ +#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */ +#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE + +/* These are for the interlacing type. These values should NOT be changed. */ +#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */ +#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */ +#define PNG_INTERLACE_LAST 2 /* Not a valid value */ + +/* These are for the oFFs chunk. These values should NOT be changed. */ +#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */ +#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */ +#define PNG_OFFSET_LAST 2 /* Not a valid value */ + +/* These are for the pCAL chunk. These values should NOT be changed. */ +#define PNG_EQUATION_LINEAR 0 /* Linear transformation */ +#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */ +#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */ +#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */ +#define PNG_EQUATION_LAST 4 /* Not a valid value */ + +/* These are for the sCAL chunk. These values should NOT be changed. */ +#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */ +#define PNG_SCALE_METER 1 /* meters per pixel */ +#define PNG_SCALE_RADIAN 2 /* radians per pixel */ +#define PNG_SCALE_LAST 3 /* Not a valid value */ + +/* These are for the pHYs chunk. These values should NOT be changed. */ +#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */ +#define PNG_RESOLUTION_METER 1 /* pixels/meter */ +#define PNG_RESOLUTION_LAST 2 /* Not a valid value */ + +/* These are for the sRGB chunk. These values should NOT be changed. */ +#define PNG_sRGB_INTENT_PERCEPTUAL 0 +#define PNG_sRGB_INTENT_RELATIVE 1 +#define PNG_sRGB_INTENT_SATURATION 2 +#define PNG_sRGB_INTENT_ABSOLUTE 3 +#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */ + +/* This is for text chunks */ +#define PNG_KEYWORD_MAX_LENGTH 79 + +/* Maximum number of entries in PLTE/sPLT/tRNS arrays */ +#define PNG_MAX_PALETTE_LENGTH 256 + +/* These determine if an ancillary chunk's data has been successfully read + * from the PNG header, or if the application has filled in the corresponding + * data in the info_struct to be written into the output file. The values + * of the PNG_INFO_ defines should NOT be changed. + */ +#define PNG_INFO_gAMA 0x0001U +#define PNG_INFO_sBIT 0x0002U +#define PNG_INFO_cHRM 0x0004U +#define PNG_INFO_PLTE 0x0008U +#define PNG_INFO_tRNS 0x0010U +#define PNG_INFO_bKGD 0x0020U +#define PNG_INFO_hIST 0x0040U +#define PNG_INFO_pHYs 0x0080U +#define PNG_INFO_oFFs 0x0100U +#define PNG_INFO_tIME 0x0200U +#define PNG_INFO_pCAL 0x0400U +#define PNG_INFO_sRGB 0x0800U /* GR-P, 0.96a */ +#define PNG_INFO_iCCP 0x1000U /* ESR, 1.0.6 */ +#define PNG_INFO_sPLT 0x2000U /* ESR, 1.0.6 */ +#define PNG_INFO_sCAL 0x4000U /* ESR, 1.0.6 */ +#define PNG_INFO_IDAT 0x8000U /* ESR, 1.0.6 */ +#define PNG_INFO_eXIf 0x10000U /* GR-P, 1.6.31 */ + +/* This is used for the transformation routines, as some of them + * change these values for the row. It also should enable using + * the routines for other purposes. + */ +typedef struct png_row_info_struct +{ + png_uint_32 width; /* width of row */ + size_t rowbytes; /* number of bytes in row */ + png_byte color_type; /* color type of row */ + png_byte bit_depth; /* bit depth of row */ + png_byte channels; /* number of channels (1, 2, 3, or 4) */ + png_byte pixel_depth; /* bits per pixel (depth * channels) */ +} png_row_info; + +typedef png_row_info * png_row_infop; +typedef png_row_info * * png_row_infopp; + +/* These are the function types for the I/O functions and for the functions + * that allow the user to override the default I/O functions with his or her + * own. The png_error_ptr type should match that of user-supplied warning + * and error functions, while the png_rw_ptr type should match that of the + * user read/write data functions. Note that the 'write' function must not + * modify the buffer it is passed. The 'read' function, on the other hand, is + * expected to return the read data in the buffer. + */ +typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp)); +typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, size_t)); +typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp)); +typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32, + int)); +typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32, + int)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop)); +typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop)); + +/* The following callback receives png_uint_32 row_number, int pass for the + * png_bytep data of the row. When transforming an interlaced image the + * row number is the row number within the sub-image of the interlace pass, so + * the value will increase to the height of the sub-image (not the full image) + * then reset to 0 for the next pass. + * + * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to + * find the output pixel (x,y) given an interlaced sub-image pixel + * (row,col,pass). (See below for these macros.) + */ +typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp, png_bytep, + png_uint_32, int)); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop, + png_bytep)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp, + png_unknown_chunkp)); +#endif +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +/* not used anywhere */ +/* typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); */ +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* This must match the function definition in , and the application + * must include this before png.h to obtain the definition of jmp_buf. The + * function is required to be PNG_NORETURN, but this is not checked. If the + * function does return the application will crash via an abort() or similar + * system level call. + * + * If you get a warning here while building the library you may need to make + * changes to ensure that pnglibconf.h records the calling convention used by + * your compiler. This may be very difficult - try using a different compiler + * to build the library! + */ +PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef); +#endif + +/* Transform masks for the high-level interface */ +#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */ +#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */ +#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */ +#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */ +#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */ +#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */ +#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */ +#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */ +#define PNG_TRANSFORM_BGR 0x0080 /* read and write */ +#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ +#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ +#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ +#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */ +/* Added to libpng-1.2.34 */ +#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER +#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */ +/* Added to libpng-1.4.0 */ +#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */ +/* Added to libpng-1.5.4 */ +#define PNG_TRANSFORM_EXPAND_16 0x4000 /* read only */ +#if INT_MAX >= 0x8000 /* else this might break */ +#define PNG_TRANSFORM_SCALE_16 0x8000 /* read only */ +#endif + +/* Flags for MNG supported features */ +#define PNG_FLAG_MNG_EMPTY_PLTE 0x01 +#define PNG_FLAG_MNG_FILTER_64 0x04 +#define PNG_ALL_MNG_FEATURES 0x05 + +/* NOTE: prior to 1.5 these functions had no 'API' style declaration, + * this allowed the zlib default functions to be used on Windows + * platforms. In 1.5 the zlib default malloc (which just calls malloc and + * ignores the first argument) should be completely compatible with the + * following. + */ +typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp, + png_alloc_size_t)); +typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp)); + +/* Section 4: exported functions + * Here are the function definitions most commonly used. This is not + * the place to find out how to use libpng. See libpng-manual.txt for the + * full explanation, see example.c for the summary. This just provides + * a simple one line description of the use of each function. + * + * The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in + * pngconf.h and in the *.dfn files in the scripts directory. + * + * PNG_EXPORT(ordinal, type, name, (args)); + * + * ordinal: ordinal that is used while building + * *.def files. The ordinal value is only + * relevant when preprocessing png.h with + * the *.dfn files for building symbol table + * entries, and are removed by pngconf.h. + * type: return type of the function + * name: function name + * args: function arguments, with types + * + * When we wish to append attributes to a function prototype we use + * the PNG_EXPORTA() macro instead. + * + * PNG_EXPORTA(ordinal, type, name, (args), attributes); + * + * ordinal, type, name, and args: same as in PNG_EXPORT(). + * attributes: function attributes + */ + +/* Returns the version number of the library */ +PNG_EXPORT(1, png_uint_32, png_access_version_number, (void)); + +/* Tell lib we have already handled the first magic bytes. + * Handling more than 8 bytes from the beginning of the file is an error. + */ +PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes)); + +/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a + * PNG file. Returns zero if the supplied bytes match the 8-byte PNG + * signature, and non-zero otherwise. Having num_to_check == 0 or + * start > 7 will always fail (ie return non-zero). + */ +PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, size_t start, + size_t num_to_check)); + +/* Simple signature checking function. This is the same as calling + * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). + */ +#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n)) + +/* Allocate and initialize png_ptr struct for reading, and any other memory. */ +PNG_EXPORTA(4, png_structp, png_create_read_struct, + (png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn), + PNG_ALLOCATED); + +/* Allocate and initialize png_ptr struct for writing, and any other memory */ +PNG_EXPORTA(5, png_structp, png_create_write_struct, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn), + PNG_ALLOCATED); + +PNG_EXPORT(6, size_t, png_get_compression_buffer_size, + (png_const_structrp png_ptr)); + +PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structrp png_ptr, + size_t size)); + +/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp + * match up. + */ +#ifdef PNG_SETJMP_SUPPORTED +/* This function returns the jmp_buf built in to *png_ptr. It must be + * supplied with an appropriate 'longjmp' function to use on that jmp_buf + * unless the default error function is overridden in which case NULL is + * acceptable. The size of the jmp_buf is checked against the actual size + * allocated by the library - the call will return NULL on a mismatch + * indicating an ABI mismatch. + */ +PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structrp png_ptr, + png_longjmp_ptr longjmp_fn, size_t jmp_buf_size)); +# define png_jmpbuf(png_ptr) \ + (*png_set_longjmp_fn((png_ptr), longjmp, (sizeof (jmp_buf)))) +#else +# define png_jmpbuf(png_ptr) \ + (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP) +#endif +/* This function should be used by libpng applications in place of + * longjmp(png_ptr->jmpbuf, val). If longjmp_fn() has been set, it + * will use it; otherwise it will call PNG_ABORT(). This function was + * added in libpng-1.5.0. + */ +PNG_EXPORTA(9, void, png_longjmp, (png_const_structrp png_ptr, int val), + PNG_NORETURN); + +#ifdef PNG_READ_SUPPORTED +/* Reset the compression stream */ +PNG_EXPORTA(10, int, png_reset_zstream, (png_structrp png_ptr), PNG_DEPRECATED); +#endif + +/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ +#ifdef PNG_USER_MEM_SUPPORTED +PNG_EXPORTA(11, png_structp, png_create_read_struct_2, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn, + png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), + PNG_ALLOCATED); +PNG_EXPORTA(12, png_structp, png_create_write_struct_2, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn, + png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), + PNG_ALLOCATED); +#endif + +/* Write the PNG file signature. */ +PNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr)); + +/* Write a PNG chunk - size, type, (optional) data, CRC. */ +PNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr, png_const_bytep + chunk_name, png_const_bytep data, size_t length)); + +/* Write the start of a PNG chunk - length and chunk name. */ +PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr, + png_const_bytep chunk_name, png_uint_32 length)); + +/* Write the data of a PNG chunk started with png_write_chunk_start(). */ +PNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr, + png_const_bytep data, size_t length)); + +/* Finish a chunk started with png_write_chunk_start() (includes CRC). */ +PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr)); + +/* Allocate and initialize the info structure */ +PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr), + PNG_ALLOCATED); + +/* DEPRECATED: this function allowed init structures to be created using the + * default allocation method (typically malloc). Use is deprecated in 1.6.0 and + * the API will be removed in the future. + */ +PNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr, + size_t png_info_struct_size), PNG_DEPRECATED); + +/* Writes all the PNG information before the image. */ +PNG_EXPORT(20, void, png_write_info_before_PLTE, + (png_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(21, void, png_write_info, + (png_structrp png_ptr, png_const_inforp info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the information before the actual image data. */ +PNG_EXPORT(22, void, png_read_info, + (png_structrp png_ptr, png_inforp info_ptr)); +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED + /* Convert to a US string format: there is no localization support in this + * routine. The original implementation used a 29 character buffer in + * png_struct, this will be removed in future versions. + */ +#if PNG_LIBPNG_VER < 10700 +/* To do: remove this from libpng17 (and from libpng17/png.c and pngstruct.h) */ +PNG_EXPORTA(23, png_const_charp, png_convert_to_rfc1123, (png_structrp png_ptr, + png_const_timep ptime),PNG_DEPRECATED); +#endif +PNG_EXPORT(241, int, png_convert_to_rfc1123_buffer, (char out[29], + png_const_timep ptime)); +#endif + +#ifdef PNG_CONVERT_tIME_SUPPORTED +/* Convert from a struct tm to png_time */ +PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime, + const struct tm * ttime)); + +/* Convert from time_t to png_time. Uses gmtime() */ +PNG_EXPORT(25, void, png_convert_from_time_t, (png_timep ptime, time_t ttime)); +#endif /* CONVERT_tIME */ + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ +PNG_EXPORT(26, void, png_set_expand, (png_structrp png_ptr)); +PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structrp png_ptr)); +PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structrp png_ptr)); +PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED +/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion + * of a tRNS chunk if present. + */ +PNG_EXPORT(221, void, png_set_expand_16, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Use blue, green, red order for pixels. */ +PNG_EXPORT(30, void, png_set_bgr, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +/* Expand the grayscale to 24-bit RGB if necessary. */ +PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +/* Reduce RGB to grayscale. */ +#define PNG_ERROR_ACTION_NONE 1 +#define PNG_ERROR_ACTION_WARN 2 +#define PNG_ERROR_ACTION_ERROR 3 +#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/ + +PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structrp png_ptr, + int error_action, double red, double green)) +PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structrp png_ptr, + int error_action, png_fixed_point red, png_fixed_point green)) + +PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structrp + png_ptr)); +#endif + +#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, + png_colorp palette)); +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED +/* How the alpha channel is interpreted - this affects how the color channels + * of a PNG file are returned to the calling application when an alpha channel, + * or a tRNS chunk in a palette file, is present. + * + * This has no effect on the way pixels are written into a PNG output + * datastream. The color samples in a PNG datastream are never premultiplied + * with the alpha samples. + * + * The default is to return data according to the PNG specification: the alpha + * channel is a linear measure of the contribution of the pixel to the + * corresponding composited pixel, and the color channels are unassociated + * (not premultiplied). The gamma encoded color channels must be scaled + * according to the contribution and to do this it is necessary to undo + * the encoding, scale the color values, perform the composition and re-encode + * the values. This is the 'PNG' mode. + * + * The alternative is to 'associate' the alpha with the color information by + * storing color channel values that have been scaled by the alpha. + * image. These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes + * (the latter being the two common names for associated alpha color channels). + * + * For the 'OPTIMIZED' mode, a pixel is treated as opaque only if the alpha + * value is equal to the maximum value. + * + * The final choice is to gamma encode the alpha channel as well. This is + * broken because, in practice, no implementation that uses this choice + * correctly undoes the encoding before handling alpha composition. Use this + * choice only if other serious errors in the software or hardware you use + * mandate it; the typical serious error is for dark halos to appear around + * opaque areas of the composited PNG image because of arithmetic overflow. + * + * The API function png_set_alpha_mode specifies which of these choices to use + * with an enumerated 'mode' value and the gamma of the required output: + */ +#define PNG_ALPHA_PNG 0 /* according to the PNG standard */ +#define PNG_ALPHA_STANDARD 1 /* according to Porter/Duff */ +#define PNG_ALPHA_ASSOCIATED 1 /* as above; this is the normal practice */ +#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */ +#define PNG_ALPHA_OPTIMIZED 2 /* 'PNG' for opaque pixels, else 'STANDARD' */ +#define PNG_ALPHA_BROKEN 3 /* the alpha channel is gamma encoded */ + +PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structrp png_ptr, int mode, + double output_gamma)) +PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr, + int mode, png_fixed_point output_gamma)) +#endif + +#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED) +/* The output_gamma value is a screen gamma in libpng terminology: it expresses + * how to decode the output values, not how they are encoded. + */ +#define PNG_DEFAULT_sRGB -1 /* sRGB gamma and color space */ +#define PNG_GAMMA_MAC_18 -2 /* Old Mac '1.8' gamma and color space */ +#define PNG_GAMMA_sRGB 220000 /* Television standards--matches sRGB gamma */ +#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */ +#endif + +/* The following are examples of calls to png_set_alpha_mode to achieve the + * required overall gamma correction and, where necessary, alpha + * premultiplication. + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB); + * This is the default libpng handling of the alpha channel - it is not + * pre-multiplied into the color components. In addition the call states + * that the output is for a sRGB system and causes all PNG files without gAMA + * chunks to be assumed to be encoded using sRGB. + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); + * In this case the output is assumed to be something like an sRGB conformant + * display preceded by a power-law lookup table of power 1.45. This is how + * early Mac systems behaved. + * + * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR); + * This is the classic Jim Blinn approach and will work in academic + * environments where everything is done by the book. It has the shortcoming + * of assuming that input PNG data with no gamma information is linear - this + * is unlikely to be correct unless the PNG files where generated locally. + * Most of the time the output precision will be so low as to show + * significant banding in dark areas of the image. + * + * png_set_expand_16(pp); + * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB); + * This is a somewhat more realistic Jim Blinn inspired approach. PNG files + * are assumed to have the sRGB encoding if not marked with a gamma value and + * the output is always 16 bits per component. This permits accurate scaling + * and processing of the data. If you know that your input PNG files were + * generated locally you might need to replace PNG_DEFAULT_sRGB with the + * correct value for your system. + * + * png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB); + * If you just need to composite the PNG image onto an existing background + * and if you control the code that does this you can use the optimization + * setting. In this case you just copy completely opaque pixels to the + * output. For pixels that are not completely transparent (you just skip + * those) you do the composition math using png_composite or png_composite_16 + * below then encode the resultant 8-bit or 16-bit values to match the output + * encoding. + * + * Other cases + * If neither the PNG nor the standard linear encoding work for you because + * of the software or hardware you use then you have a big problem. The PNG + * case will probably result in halos around the image. The linear encoding + * will probably result in a washed out, too bright, image (it's actually too + * contrasty.) Try the ALPHA_OPTIMIZED mode above - this will probably + * substantially reduce the halos. Alternatively try: + * + * png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB); + * This option will also reduce the halos, but there will be slight dark + * halos round the opaque parts of the image where the background is light. + * In the OPTIMIZED mode the halos will be light halos where the background + * is dark. Take your pick - the halos are unavoidable unless you can get + * your hardware/software fixed! (The OPTIMIZED approach is slightly + * faster.) + * + * When the default gamma of PNG files doesn't match the output gamma. + * If you have PNG files with no gamma information png_set_alpha_mode allows + * you to provide a default gamma, but it also sets the output gamma to the + * matching value. If you know your PNG files have a gamma that doesn't + * match the output you can take advantage of the fact that + * png_set_alpha_mode always sets the output gamma but only sets the PNG + * default if it is not already set: + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB); + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); + * The first call sets both the default and the output gamma values, the + * second call overrides the output gamma without changing the default. This + * is easier than achieving the same effect with png_set_gamma. You must use + * PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will + * fire if more than one call to png_set_alpha_mode and png_set_background is + * made in the same read operation, however multiple calls with PNG_ALPHA_PNG + * are ignored. + */ + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED +PNG_EXPORT(36, void, png_set_strip_alpha, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +PNG_EXPORT(37, void, png_set_swap_alpha, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +PNG_EXPORT(38, void, png_set_invert_alpha, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte to 8-bit or 16-bit Gray or 24-bit or 48-bit RGB images. */ +PNG_EXPORT(39, void, png_set_filler, (png_structrp png_ptr, png_uint_32 filler, + int flags)); +/* The values of the PNG_FILLER_ defines should NOT be changed */ +# define PNG_FILLER_BEFORE 0 +# define PNG_FILLER_AFTER 1 +/* Add an alpha byte to 8-bit or 16-bit Gray or 24-bit or 48-bit RGB images. */ +PNG_EXPORT(40, void, png_set_add_alpha, (png_structrp png_ptr, + png_uint_32 filler, int flags)); +#endif /* READ_FILLER || WRITE_FILLER */ + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Swap bytes in 16-bit depth files. */ +PNG_EXPORT(41, void, png_set_swap, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ +PNG_EXPORT(42, void, png_set_packing, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ + defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* Swap packing order of pixels in bytes. */ +PNG_EXPORT(43, void, png_set_packswap, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +/* Converts files to legal bit depths. */ +PNG_EXPORT(44, void, png_set_shift, (png_structrp png_ptr, png_const_color_8p + true_bits)); +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +/* Have the code handle the interlacing. Returns the number of passes. + * MUST be called before png_read_update_info or png_start_read_image, + * otherwise it will not have the desired effect. Note that it is still + * necessary to call png_read_row or png_read_rows png_get_image_height + * times for each pass. +*/ +PNG_EXPORT(45, int, png_set_interlace_handling, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +/* Invert monochrome files */ +PNG_EXPORT(46, void, png_set_invert_mono, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +/* Handle alpha and tRNS by replacing with a background color. Prior to + * libpng-1.5.4 this API must not be called before the PNG file header has been + * read. Doing so will result in unexpected behavior and possible warnings or + * errors if the PNG file contains a bKGD chunk. + */ +PNG_FP_EXPORT(47, void, png_set_background, (png_structrp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma)) +PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structrp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, png_fixed_point background_gamma)) +#endif +#ifdef PNG_READ_BACKGROUND_SUPPORTED +# define PNG_BACKGROUND_GAMMA_UNKNOWN 0 +# define PNG_BACKGROUND_GAMMA_SCREEN 1 +# define PNG_BACKGROUND_GAMMA_FILE 2 +# define PNG_BACKGROUND_GAMMA_UNIQUE 3 +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED +/* Scale a 16-bit depth file down to 8-bit, accurately. */ +PNG_EXPORT(229, void, png_set_scale_16, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED +#define PNG_READ_16_TO_8_SUPPORTED /* Name prior to 1.5.4 */ +/* Strip the second byte of information from a 16-bit depth file. */ +PNG_EXPORT(48, void, png_set_strip_16, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +/* Turn on quantizing, and reduce the palette to the number of colors + * available. + */ +PNG_EXPORT(49, void, png_set_quantize, (png_structrp png_ptr, + png_colorp palette, int num_palette, int maximum_colors, + png_const_uint_16p histogram, int full_quantize)); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* The threshold on gamma processing is configurable but hard-wired into the + * library. The following is the floating point variant. + */ +#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001) + +/* Handle gamma correction. Screen_gamma=(display_exponent). + * NOTE: this API simply sets the screen and file gamma values. It will + * therefore override the value for gamma in a PNG file if it is called after + * the file header has been read - use with care - call before reading the PNG + * file for best results! + * + * These routines accept the same gamma values as png_set_alpha_mode (described + * above). The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either + * API (floating point or fixed.) Notice, however, that the 'file_gamma' value + * is the inverse of a 'screen gamma' value. + */ +PNG_FP_EXPORT(50, void, png_set_gamma, (png_structrp png_ptr, + double screen_gamma, double override_file_gamma)) +PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structrp png_ptr, + png_fixed_point screen_gamma, png_fixed_point override_file_gamma)) +#endif + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +/* Set how many lines between output flushes - 0 for no flushing */ +PNG_EXPORT(51, void, png_set_flush, (png_structrp png_ptr, int nrows)); +/* Flush the current PNG output buffer */ +PNG_EXPORT(52, void, png_write_flush, (png_structrp png_ptr)); +#endif + +/* Optional update palette with requested transformations */ +PNG_EXPORT(53, void, png_start_read_image, (png_structrp png_ptr)); + +/* Optional call to update the users info structure */ +PNG_EXPORT(54, void, png_read_update_info, (png_structrp png_ptr, + png_inforp info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read one or more rows of image data. */ +PNG_EXPORT(55, void, png_read_rows, (png_structrp png_ptr, png_bytepp row, + png_bytepp display_row, png_uint_32 num_rows)); +#endif + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read a row of data. */ +PNG_EXPORT(56, void, png_read_row, (png_structrp png_ptr, png_bytep row, + png_bytep display_row)); +#endif + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the whole image into memory at once. */ +PNG_EXPORT(57, void, png_read_image, (png_structrp png_ptr, png_bytepp image)); +#endif + +/* Write a row of image data */ +PNG_EXPORT(58, void, png_write_row, (png_structrp png_ptr, + png_const_bytep row)); + +/* Write a few rows of image data: (*row) is not written; however, the type + * is declared as writeable to maintain compatibility with previous versions + * of libpng and to allow the 'display_row' array from read_rows to be passed + * unchanged to write_rows. + */ +PNG_EXPORT(59, void, png_write_rows, (png_structrp png_ptr, png_bytepp row, + png_uint_32 num_rows)); + +/* Write the image data */ +PNG_EXPORT(60, void, png_write_image, (png_structrp png_ptr, png_bytepp image)); + +/* Write the end of the PNG file. */ +PNG_EXPORT(61, void, png_write_end, (png_structrp png_ptr, + png_inforp info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the end of the PNG file. */ +PNG_EXPORT(62, void, png_read_end, (png_structrp png_ptr, png_inforp info_ptr)); +#endif + +/* Free any memory associated with the png_info_struct */ +PNG_EXPORT(63, void, png_destroy_info_struct, (png_const_structrp png_ptr, + png_infopp info_ptr_ptr)); + +/* Free any memory associated with the png_struct and the png_info_structs */ +PNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr, + png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)); + +/* Free any memory associated with the png_struct and the png_info_structs */ +PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr, + png_infopp info_ptr_ptr)); + +/* Set the libpng method of handling chunk CRC errors */ +PNG_EXPORT(66, void, png_set_crc_action, (png_structrp png_ptr, int crit_action, + int ancil_action)); + +/* Values for png_set_crc_action() say how to handle CRC errors in + * ancillary and critical chunks, and whether to use the data contained + * therein. Note that it is impossible to "discard" data in a critical + * chunk. For versions prior to 0.90, the action was always error/quit, + * whereas in version 0.90 and later, the action for CRC errors in ancillary + * chunks is warn/discard. These values should NOT be changed. + * + * value action:critical action:ancillary + */ +#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */ +#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */ +#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */ +#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */ +#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */ +#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */ + +#ifdef PNG_WRITE_SUPPORTED +/* These functions give the user control over the scan-line filtering in + * libpng and the compression methods used by zlib. These functions are + * mainly useful for testing, as the defaults should work with most users. + * Those users who are tight on memory or want faster performance at the + * expense of compression can modify them. See the compression library + * header file (zlib.h) for an explination of the compression functions. + */ + +/* Set the filtering method(s) used by libpng. Currently, the only valid + * value for "method" is 0. + */ +PNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method, + int filters)); +#endif /* WRITE */ + +/* Flags for png_set_filter() to say which filters to use. The flags + * are chosen so that they don't conflict with real filter types + * below, in case they are supplied instead of the #defined constants. + * These values should NOT be changed. + */ +#define PNG_NO_FILTERS 0x00 +#define PNG_FILTER_NONE 0x08 +#define PNG_FILTER_SUB 0x10 +#define PNG_FILTER_UP 0x20 +#define PNG_FILTER_AVG 0x40 +#define PNG_FILTER_PAETH 0x80 +#define PNG_FAST_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP) +#define PNG_ALL_FILTERS (PNG_FAST_FILTERS | PNG_FILTER_AVG | PNG_FILTER_PAETH) + +/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now. + * These defines should NOT be changed. + */ +#define PNG_FILTER_VALUE_NONE 0 +#define PNG_FILTER_VALUE_SUB 1 +#define PNG_FILTER_VALUE_UP 2 +#define PNG_FILTER_VALUE_AVG 3 +#define PNG_FILTER_VALUE_PAETH 4 +#define PNG_FILTER_VALUE_LAST 5 + +#ifdef PNG_WRITE_SUPPORTED +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */ +PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structrp png_ptr, + int heuristic_method, int num_weights, png_const_doublep filter_weights, + png_const_doublep filter_costs)) +PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, + (png_structrp png_ptr, int heuristic_method, int num_weights, + png_const_fixed_point_p filter_weights, + png_const_fixed_point_p filter_costs)) +#endif /* WRITE_WEIGHTED_FILTER */ + +/* The following are no longer used and will be removed from libpng-1.7: */ +#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */ +#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */ +#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */ +#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */ + +/* Set the library compression level. Currently, valid values range from + * 0 - 9, corresponding directly to the zlib compression levels 0 - 9 + * (0 - no compression, 9 - "maximal" compression). Note that tests have + * shown that zlib compression levels 3-6 usually perform as well as level 9 + * for PNG images, and do considerably fewer caclulations. In the future, + * these values may not correspond directly to the zlib compression levels. + */ +#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED +PNG_EXPORT(69, void, png_set_compression_level, (png_structrp png_ptr, + int level)); + +PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structrp png_ptr, + int mem_level)); + +PNG_EXPORT(71, void, png_set_compression_strategy, (png_structrp png_ptr, + int strategy)); + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +PNG_EXPORT(72, void, png_set_compression_window_bits, (png_structrp png_ptr, + int window_bits)); + +PNG_EXPORT(73, void, png_set_compression_method, (png_structrp png_ptr, + int method)); +#endif /* WRITE_CUSTOMIZE_COMPRESSION */ + +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +/* Also set zlib parameters for compressing non-IDAT chunks */ +PNG_EXPORT(222, void, png_set_text_compression_level, (png_structrp png_ptr, + int level)); + +PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structrp png_ptr, + int mem_level)); + +PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structrp png_ptr, + int strategy)); + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +PNG_EXPORT(225, void, png_set_text_compression_window_bits, + (png_structrp png_ptr, int window_bits)); + +PNG_EXPORT(226, void, png_set_text_compression_method, (png_structrp png_ptr, + int method)); +#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */ +#endif /* WRITE */ + +/* These next functions are called for input/output, memory, and error + * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, + * and call standard C I/O routines such as fread(), fwrite(), and + * fprintf(). These functions can be made to use other I/O routines + * at run time for those applications that need to handle I/O in a + * different manner by calling png_set_???_fn(). See libpng-manual.txt for + * more information. + */ + +#ifdef PNG_STDIO_SUPPORTED +/* Initialize the input/output for the PNG file to the default functions. */ +PNG_EXPORT(74, void, png_init_io, (png_structrp png_ptr, png_FILE_p fp)); +#endif + +/* Replace the (error and abort), and warning functions with user + * supplied functions. If no messages are to be printed you must still + * write and use replacement functions. The replacement error_fn should + * still do a longjmp to the last setjmp location if you are using this + * method of error handling. If error_fn or warning_fn is NULL, the + * default function will be used. + */ + +PNG_EXPORT(75, void, png_set_error_fn, (png_structrp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); + +/* Return the user pointer associated with the error functions */ +PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structrp png_ptr)); + +/* Replace the default data output functions with a user supplied one(s). + * If buffered output is not used, then output_flush_fn can be set to NULL. + * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time + * output_flush_fn will be ignored (and thus can be NULL). + * It is probably a mistake to use NULL for output_flush_fn if + * write_data_fn is not also NULL unless you have built libpng with + * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's + * default flush function, which uses the standard *FILE structure, will + * be used. + */ +PNG_EXPORT(77, void, png_set_write_fn, (png_structrp png_ptr, png_voidp io_ptr, + png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); + +/* Replace the default data input function with a user supplied one. */ +PNG_EXPORT(78, void, png_set_read_fn, (png_structrp png_ptr, png_voidp io_ptr, + png_rw_ptr read_data_fn)); + +/* Return the user pointer associated with the I/O functions */ +PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_const_structrp png_ptr)); + +PNG_EXPORT(80, void, png_set_read_status_fn, (png_structrp png_ptr, + png_read_status_ptr read_row_fn)); + +PNG_EXPORT(81, void, png_set_write_status_fn, (png_structrp png_ptr, + png_write_status_ptr write_row_fn)); + +#ifdef PNG_USER_MEM_SUPPORTED +/* Replace the default memory allocation functions with user supplied one(s). */ +PNG_EXPORT(82, void, png_set_mem_fn, (png_structrp png_ptr, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn)); +/* Return the user pointer associated with the memory functions */ +PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structrp png_ptr)); +#endif + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED +PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structrp png_ptr, + png_user_transform_ptr read_user_transform_fn)); +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structrp png_ptr, + png_user_transform_ptr write_user_transform_fn)); +#endif + +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +PNG_EXPORT(86, void, png_set_user_transform_info, (png_structrp png_ptr, + png_voidp user_transform_ptr, int user_transform_depth, + int user_transform_channels)); +/* Return the user pointer associated with the user transform functions */ +PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr, + (png_const_structrp png_ptr)); +#endif + +#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED +/* Return information about the row currently being processed. Note that these + * APIs do not fail but will return unexpected results if called outside a user + * transform callback. Also note that when transforming an interlaced image the + * row number is the row number within the sub-image of the interlace pass, so + * the value will increase to the height of the sub-image (not the full image) + * then reset to 0 for the next pass. + * + * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to + * find the output pixel (x,y) given an interlaced sub-image pixel + * (row,col,pass). (See below for these macros.) + */ +PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structrp)); +PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp)); +#endif + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED +/* This callback is called only for *unknown* chunks. If + * PNG_HANDLE_AS_UNKNOWN_SUPPORTED is set then it is possible to set known + * chunks to be treated as unknown, however in this case the callback must do + * any processing required by the chunk (e.g. by calling the appropriate + * png_set_ APIs.) + * + * There is no write support - on write, by default, all the chunks in the + * 'unknown' list are written in the specified position. + * + * The integer return from the callback function is interpreted thus: + * + * negative: An error occurred; png_chunk_error will be called. + * zero: The chunk was not handled, the chunk will be saved. A critical + * chunk will cause an error at this point unless it is to be saved. + * positive: The chunk was handled, libpng will ignore/discard it. + * + * See "INTERACTION WITH USER CHUNK CALLBACKS" below for important notes about + * how this behavior will change in libpng 1.7 + */ +PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr, + png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structrp png_ptr)); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +/* Sets the function callbacks for the push reader, and a pointer to a + * user-defined structure available to the callback functions. + */ +PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structrp png_ptr, + png_voidp progressive_ptr, png_progressive_info_ptr info_fn, + png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn)); + +/* Returns the user pointer associated with the push read functions */ +PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, + (png_const_structrp png_ptr)); + +/* Function to be called when data becomes available */ +PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr, + png_inforp info_ptr, png_bytep buffer, size_t buffer_size)); + +/* A function which may be called *only* within png_process_data to stop the + * processing of any more data. The function returns the number of bytes + * remaining, excluding any that libpng has cached internally. A subsequent + * call to png_process_data must supply these bytes again. If the argument + * 'save' is set to true the routine will first save all the pending data and + * will always return 0. + */ +PNG_EXPORT(219, size_t, png_process_data_pause, (png_structrp, int save)); + +/* A function which may be called *only* outside (after) a call to + * png_process_data. It returns the number of bytes of data to skip in the + * input. Normally it will return 0, but if it returns a non-zero value the + * application must skip than number of bytes of input data and pass the + * following data to the next call to png_process_data. + */ +PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structrp)); + +/* Function that combines rows. 'new_row' is a flag that should come from + * the callback and be non-NULL if anything needs to be done; the library + * stores its own version of the new data internally and ignores the passed + * in value. + */ +PNG_EXPORT(93, void, png_progressive_combine_row, (png_const_structrp png_ptr, + png_bytep old_row, png_const_bytep new_row)); +#endif /* PROGRESSIVE_READ */ + +PNG_EXPORTA(94, png_voidp, png_malloc, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); +/* Added at libpng version 1.4.0 */ +PNG_EXPORTA(95, png_voidp, png_calloc, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); + +/* Added at libpng version 1.2.4 */ +PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); + +/* Frees a pointer allocated by png_malloc() */ +PNG_EXPORT(97, void, png_free, (png_const_structrp png_ptr, png_voidp ptr)); + +/* Free data that was allocated internally */ +PNG_EXPORT(98, void, png_free_data, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 free_me, int num)); + +/* Reassign responsibility for freeing existing data, whether allocated + * by libpng or by the application; this works on the png_info structure passed + * in, it does not change the state for other png_info structures. + * + * It is unlikely that this function works correctly as of 1.6.0 and using it + * may result either in memory leaks or double free of allocated data. + */ +PNG_EXPORT(99, void, png_data_freer, (png_const_structrp png_ptr, + png_inforp info_ptr, int freer, png_uint_32 mask)); + +/* Assignments for png_data_freer */ +#define PNG_DESTROY_WILL_FREE_DATA 1 +#define PNG_SET_WILL_FREE_DATA 1 +#define PNG_USER_WILL_FREE_DATA 2 +/* Flags for png_ptr->free_me and info_ptr->free_me */ +#define PNG_FREE_HIST 0x0008U +#define PNG_FREE_ICCP 0x0010U +#define PNG_FREE_SPLT 0x0020U +#define PNG_FREE_ROWS 0x0040U +#define PNG_FREE_PCAL 0x0080U +#define PNG_FREE_SCAL 0x0100U +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +# define PNG_FREE_UNKN 0x0200U +#endif +/* PNG_FREE_LIST 0x0400U removed in 1.6.0 because it is ignored */ +#define PNG_FREE_PLTE 0x1000U +#define PNG_FREE_TRNS 0x2000U +#define PNG_FREE_TEXT 0x4000U +#define PNG_FREE_EXIF 0x8000U /* Added at libpng-1.6.31 */ +#define PNG_FREE_ALL 0xffffU +#define PNG_FREE_MUL 0x4220U /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ + +#ifdef PNG_USER_MEM_SUPPORTED +PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED); +PNG_EXPORTA(101, void, png_free_default, (png_const_structrp png_ptr, + png_voidp ptr), PNG_DEPRECATED); +#endif + +#ifdef PNG_ERROR_TEXT_SUPPORTED +/* Fatal error in PNG image of libpng - can't continue */ +PNG_EXPORTA(102, void, png_error, (png_const_structrp png_ptr, + png_const_charp error_message), PNG_NORETURN); + +/* The same, but the chunk name is prepended to the error string. */ +PNG_EXPORTA(103, void, png_chunk_error, (png_const_structrp png_ptr, + png_const_charp error_message), PNG_NORETURN); + +#else +/* Fatal error in PNG image of libpng - can't continue */ +PNG_EXPORTA(104, void, png_err, (png_const_structrp png_ptr), PNG_NORETURN); +# define png_error(s1,s2) png_err(s1) +# define png_chunk_error(s1,s2) png_err(s1) +#endif + +#ifdef PNG_WARNINGS_SUPPORTED +/* Non-fatal error in libpng. Can continue, but may have a problem. */ +PNG_EXPORT(105, void, png_warning, (png_const_structrp png_ptr, + png_const_charp warning_message)); + +/* Non-fatal error in libpng, chunk name is prepended to message. */ +PNG_EXPORT(106, void, png_chunk_warning, (png_const_structrp png_ptr, + png_const_charp warning_message)); +#else +# define png_warning(s1,s2) ((void)(s1)) +# define png_chunk_warning(s1,s2) ((void)(s1)) +#endif + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +/* Benign error in libpng. Can continue, but may have a problem. + * User can choose whether to handle as a fatal error or as a warning. */ +PNG_EXPORT(107, void, png_benign_error, (png_const_structrp png_ptr, + png_const_charp warning_message)); + +#ifdef PNG_READ_SUPPORTED +/* Same, chunk name is prepended to message (only during read) */ +PNG_EXPORT(108, void, png_chunk_benign_error, (png_const_structrp png_ptr, + png_const_charp warning_message)); +#endif + +PNG_EXPORT(109, void, png_set_benign_errors, + (png_structrp png_ptr, int allowed)); +#else +# ifdef PNG_ALLOW_BENIGN_ERRORS +# define png_benign_error png_warning +# define png_chunk_benign_error png_chunk_warning +# else +# define png_benign_error png_error +# define png_chunk_benign_error png_chunk_error +# endif +#endif + +/* The png_set_ functions are for storing values in the png_info_struct. + * Similarly, the png_get_ calls are used to read values from the + * png_info_struct, either storing the parameters in the passed variables, or + * setting pointers into the png_info_struct where the data is stored. The + * png_get_ functions return a non-zero value if the data was available + * in info_ptr, or return zero and do not change any of the parameters if the + * data was not available. + * + * These functions should be used instead of directly accessing png_info + * to avoid problems with future changes in the size and internal layout of + * png_info_struct. + */ +/* Returns "flag" if chunk data is valid in info_ptr. */ +PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 flag)); + +/* Returns number of bytes needed to hold a transformed row. */ +PNG_EXPORT(111, size_t, png_get_rowbytes, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +#ifdef PNG_INFO_IMAGE_SUPPORTED +/* Returns row_pointers, which is an array of pointers to scanlines that was + * returned from png_read_png(). + */ +PNG_EXPORT(112, png_bytepp, png_get_rows, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Set row_pointers, which is an array of pointers to scanlines for use + * by png_write_png(). + */ +PNG_EXPORT(113, void, png_set_rows, (png_const_structrp png_ptr, + png_inforp info_ptr, png_bytepp row_pointers)); +#endif + +/* Returns number of color channels in image. */ +PNG_EXPORT(114, png_byte, png_get_channels, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* Returns image width in pixels. */ +PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image height in pixels. */ +PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image bit_depth. */ +PNG_EXPORT(117, png_byte, png_get_bit_depth, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image color_type. */ +PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image filter_type. */ +PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image interlace_type. */ +PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image compression_type. */ +PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image resolution in pixels per meter, from pHYs chunk data. */ +PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +/* Returns pixel aspect ratio, computed from pHYs chunk data. */ +PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) +PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) + +/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ +PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(128, png_int_32, png_get_x_offset_microns, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +#endif /* EASY_ACCESS */ + +#ifdef PNG_READ_SUPPORTED +/* Returns pointer to signature string read from PNG header */ +PNG_EXPORT(130, png_const_bytep, png_get_signature, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); +#endif + +#ifdef PNG_bKGD_SUPPORTED +PNG_EXPORT(131, png_uint_32, png_get_bKGD, (png_const_structrp png_ptr, + png_inforp info_ptr, png_color_16p *background)); +#endif + +#ifdef PNG_bKGD_SUPPORTED +PNG_EXPORT(132, void, png_set_bKGD, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_color_16p background)); +#endif + +#ifdef PNG_cHRM_SUPPORTED +PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *white_x, double *white_y, double *red_x, + double *red_y, double *green_x, double *green_y, double *blue_x, + double *blue_y)) +PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *red_X, double *red_Y, double *red_Z, + double *green_X, double *green_Y, double *green_Z, double *blue_X, + double *blue_Y, double *blue_Z)) +PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_white_x, png_fixed_point *int_white_y, + png_fixed_point *int_red_x, png_fixed_point *int_red_y, + png_fixed_point *int_green_x, png_fixed_point *int_green_y, + png_fixed_point *int_blue_x, png_fixed_point *int_blue_y)) +PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_red_X, png_fixed_point *int_red_Y, + png_fixed_point *int_red_Z, png_fixed_point *int_green_X, + png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, + png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, + png_fixed_point *int_blue_Z)) +#endif + +#ifdef PNG_cHRM_SUPPORTED +PNG_FP_EXPORT(135, void, png_set_cHRM, (png_const_structrp png_ptr, + png_inforp info_ptr, + double white_x, double white_y, double red_x, double red_y, double green_x, + double green_y, double blue_x, double blue_y)) +PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_const_structrp png_ptr, + png_inforp info_ptr, double red_X, double red_Y, double red_Z, + double green_X, double green_Y, double green_Z, double blue_X, + double blue_Y, double blue_Z)) +PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_white_x, + png_fixed_point int_white_y, png_fixed_point int_red_x, + png_fixed_point int_red_y, png_fixed_point int_green_x, + png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)) +PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y, + png_fixed_point int_red_Z, png_fixed_point int_green_X, + png_fixed_point int_green_Y, png_fixed_point int_green_Z, + png_fixed_point int_blue_X, png_fixed_point int_blue_Y, + png_fixed_point int_blue_Z)) +#endif + +#ifdef PNG_eXIf_SUPPORTED +PNG_EXPORT(246, png_uint_32, png_get_eXIf, (png_const_structrp png_ptr, + png_inforp info_ptr, png_bytep *exif)); +PNG_EXPORT(247, void, png_set_eXIf, (png_const_structrp png_ptr, + png_inforp info_ptr, png_bytep exif)); + +PNG_EXPORT(248, png_uint_32, png_get_eXIf_1, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *num_exif, png_bytep *exif)); +PNG_EXPORT(249, void, png_set_eXIf_1, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 num_exif, png_bytep exif)); +#endif + +#ifdef PNG_gAMA_SUPPORTED +PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *file_gamma)) +PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_file_gamma)) +#endif + +#ifdef PNG_gAMA_SUPPORTED +PNG_FP_EXPORT(139, void, png_set_gAMA, (png_const_structrp png_ptr, + png_inforp info_ptr, double file_gamma)) +PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_file_gamma)) +#endif + +#ifdef PNG_hIST_SUPPORTED +PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_16p *hist)); +PNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_uint_16p hist)); +#endif + +PNG_EXPORT(143, png_uint_32, png_get_IHDR, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *width, png_uint_32 *height, + int *bit_depth, int *color_type, int *interlace_method, + int *compression_method, int *filter_method)); + +PNG_EXPORT(144, void, png_set_IHDR, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_method, int compression_method, + int filter_method)); + +#ifdef PNG_oFFs_SUPPORTED +PNG_EXPORT(145, png_uint_32, png_get_oFFs, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, + int *unit_type)); +#endif + +#ifdef PNG_oFFs_SUPPORTED +PNG_EXPORT(146, void, png_set_oFFs, (png_const_structrp png_ptr, + png_inforp info_ptr, png_int_32 offset_x, png_int_32 offset_y, + int unit_type)); +#endif + +#ifdef PNG_pCAL_SUPPORTED +PNG_EXPORT(147, png_uint_32, png_get_pCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, png_charp *purpose, png_int_32 *X0, + png_int_32 *X1, int *type, int *nparams, png_charp *units, + png_charpp *params)); +#endif + +#ifdef PNG_pCAL_SUPPORTED +PNG_EXPORT(148, void, png_set_pCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1, + int type, int nparams, png_const_charp units, png_charpp params)); +#endif + +#ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(149, png_uint_32, png_get_pHYs, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, + int *unit_type)); +#endif + +#ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(150, void, png_set_pHYs, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)); +#endif + +PNG_EXPORT(151, png_uint_32, png_get_PLTE, (png_const_structrp png_ptr, + png_inforp info_ptr, png_colorp *palette, int *num_palette)); + +PNG_EXPORT(152, void, png_set_PLTE, (png_structrp png_ptr, + png_inforp info_ptr, png_const_colorp palette, int num_palette)); + +#ifdef PNG_sBIT_SUPPORTED +PNG_EXPORT(153, png_uint_32, png_get_sBIT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_color_8p *sig_bit)); +#endif + +#ifdef PNG_sBIT_SUPPORTED +PNG_EXPORT(154, void, png_set_sBIT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_color_8p sig_bit)); +#endif + +#ifdef PNG_sRGB_SUPPORTED +PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structrp png_ptr, + png_const_inforp info_ptr, int *file_srgb_intent)); +#endif + +#ifdef PNG_sRGB_SUPPORTED +PNG_EXPORT(156, void, png_set_sRGB, (png_const_structrp png_ptr, + png_inforp info_ptr, int srgb_intent)); +PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_const_structrp png_ptr, + png_inforp info_ptr, int srgb_intent)); +#endif + +#ifdef PNG_iCCP_SUPPORTED +PNG_EXPORT(158, png_uint_32, png_get_iCCP, (png_const_structrp png_ptr, + png_inforp info_ptr, png_charpp name, int *compression_type, + png_bytepp profile, png_uint_32 *proflen)); +#endif + +#ifdef PNG_iCCP_SUPPORTED +PNG_EXPORT(159, void, png_set_iCCP, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_charp name, int compression_type, + png_const_bytep profile, png_uint_32 proflen)); +#endif + +#ifdef PNG_sPLT_SUPPORTED +PNG_EXPORT(160, int, png_get_sPLT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_sPLT_tpp entries)); +#endif + +#ifdef PNG_sPLT_SUPPORTED +PNG_EXPORT(161, void, png_set_sPLT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_sPLT_tp entries, int nentries)); +#endif + +#ifdef PNG_TEXT_SUPPORTED +/* png_get_text also returns the number of text chunks in *num_text */ +PNG_EXPORT(162, int, png_get_text, (png_const_structrp png_ptr, + png_inforp info_ptr, png_textp *text_ptr, int *num_text)); +#endif + +/* Note while png_set_text() will accept a structure whose text, + * language, and translated keywords are NULL pointers, the structure + * returned by png_get_text will always contain regular + * zero-terminated C strings. They might be empty strings but + * they will never be NULL pointers. + */ + +#ifdef PNG_TEXT_SUPPORTED +PNG_EXPORT(163, void, png_set_text, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_textp text_ptr, int num_text)); +#endif + +#ifdef PNG_tIME_SUPPORTED +PNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structrp png_ptr, + png_inforp info_ptr, png_timep *mod_time)); +#endif + +#ifdef PNG_tIME_SUPPORTED +PNG_EXPORT(165, void, png_set_tIME, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_timep mod_time)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +PNG_EXPORT(166, png_uint_32, png_get_tRNS, (png_const_structrp png_ptr, + png_inforp info_ptr, png_bytep *trans_alpha, int *num_trans, + png_color_16p *trans_color)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +PNG_EXPORT(167, void, png_set_tRNS, (png_structrp png_ptr, + png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans, + png_const_color_16p trans_color)); +#endif + +#ifdef PNG_sCAL_SUPPORTED +PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr, + png_const_inforp info_ptr, int *unit, double *width, double *height)) +#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ + defined(PNG_FLOATING_POINT_SUPPORTED) +/* NOTE: this API is currently implemented using floating point arithmetic, + * consequently it can only be used on systems with floating point support. + * In any case the range of values supported by png_fixed_point is small and it + * is highly recommended that png_get_sCAL_s be used instead. + */ +PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, + png_fixed_point *width, png_fixed_point *height)) +#endif +PNG_EXPORT(169, png_uint_32, png_get_sCAL_s, + (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, + png_charpp swidth, png_charpp sheight)); + +PNG_FP_EXPORT(170, void, png_set_sCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, double width, double height)) +PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, png_fixed_point width, + png_fixed_point height)) +PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, + png_const_charp swidth, png_const_charp sheight)); +#endif /* sCAL */ + +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED +/* Provide the default handling for all unknown chunks or, optionally, for + * specific unknown chunks. + * + * NOTE: prior to 1.6.0 the handling specified for particular chunks on read was + * ignored and the default was used, the per-chunk setting only had an effect on + * write. If you wish to have chunk-specific handling on read in code that must + * work on earlier versions you must use a user chunk callback to specify the + * desired handling (keep or discard.) + * + * The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below. The + * parameter is interpreted as follows: + * + * READ: + * PNG_HANDLE_CHUNK_AS_DEFAULT: + * Known chunks: do normal libpng processing, do not keep the chunk (but + * see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED) + * Unknown chunks: for a specific chunk use the global default, when used + * as the default discard the chunk data. + * PNG_HANDLE_CHUNK_NEVER: + * Discard the chunk data. + * PNG_HANDLE_CHUNK_IF_SAFE: + * Keep the chunk data if the chunk is not critical else raise a chunk + * error. + * PNG_HANDLE_CHUNK_ALWAYS: + * Keep the chunk data. + * + * If the chunk data is saved it can be retrieved using png_get_unknown_chunks, + * below. Notice that specifying "AS_DEFAULT" as a global default is equivalent + * to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks + * it simply resets the behavior to the libpng default. + * + * INTERACTION WITH USER CHUNK CALLBACKS: + * The per-chunk handling is always used when there is a png_user_chunk_ptr + * callback and the callback returns 0; the chunk is then always stored *unless* + * it is critical and the per-chunk setting is other than ALWAYS. Notice that + * the global default is *not* used in this case. (In effect the per-chunk + * value is incremented to at least IF_SAFE.) + * + * IMPORTANT NOTE: this behavior will change in libpng 1.7 - the global and + * per-chunk defaults will be honored. If you want to preserve the current + * behavior when your callback returns 0 you must set PNG_HANDLE_CHUNK_IF_SAFE + * as the default - if you don't do this libpng 1.6 will issue a warning. + * + * If you want unhandled unknown chunks to be discarded in libpng 1.6 and + * earlier simply return '1' (handled). + * + * PNG_HANDLE_AS_UNKNOWN_SUPPORTED: + * If this is *not* set known chunks will always be handled by libpng and + * will never be stored in the unknown chunk list. Known chunks listed to + * png_set_keep_unknown_chunks will have no effect. If it is set then known + * chunks listed with a keep other than AS_DEFAULT will *never* be processed + * by libpng, in addition critical chunks must either be processed by the + * callback or saved. + * + * The IHDR and IEND chunks must not be listed. Because this turns off the + * default handling for chunks that would otherwise be recognized the + * behavior of libpng transformations may well become incorrect! + * + * WRITE: + * When writing chunks the options only apply to the chunks specified by + * png_set_unknown_chunks (below), libpng will *always* write known chunks + * required by png_set_ calls and will always write the core critical chunks + * (as required for PLTE). + * + * Each chunk in the png_set_unknown_chunks list is looked up in the + * png_set_keep_unknown_chunks list to find the keep setting, this is then + * interpreted as follows: + * + * PNG_HANDLE_CHUNK_AS_DEFAULT: + * Write safe-to-copy chunks and write other chunks if the global + * default is set to _ALWAYS, otherwise don't write this chunk. + * PNG_HANDLE_CHUNK_NEVER: + * Do not write the chunk. + * PNG_HANDLE_CHUNK_IF_SAFE: + * Write the chunk if it is safe-to-copy, otherwise do not write it. + * PNG_HANDLE_CHUNK_ALWAYS: + * Write the chunk. + * + * Note that the default behavior is effectively the opposite of the read case - + * in read unknown chunks are not stored by default, in write they are written + * by default. Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different + * - on write the safe-to-copy bit is checked, on read the critical bit is + * checked and on read if the chunk is critical an error will be raised. + * + * num_chunks: + * =========== + * If num_chunks is positive, then the "keep" parameter specifies the manner + * for handling only those chunks appearing in the chunk_list array, + * otherwise the chunk list array is ignored. + * + * If num_chunks is 0 the "keep" parameter specifies the default behavior for + * unknown chunks, as described above. + * + * If num_chunks is negative, then the "keep" parameter specifies the manner + * for handling all unknown chunks plus all chunks recognized by libpng + * except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to + * be processed by libpng. + */ +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr, + int keep, png_const_bytep chunk_list, int num_chunks)); +#endif /* HANDLE_AS_UNKNOWN */ + +/* The "keep" PNG_HANDLE_CHUNK_ parameter for the specified chunk is returned; + * the result is therefore true (non-zero) if special handling is required, + * false for the default handling. + */ +PNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr, + png_const_bytep chunk_name)); +#endif /* SET_UNKNOWN_CHUNKS */ + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +PNG_EXPORT(174, void, png_set_unknown_chunks, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_unknown_chunkp unknowns, + int num_unknowns)); + /* NOTE: prior to 1.6.0 this routine set the 'location' field of the added + * unknowns to the location currently stored in the png_struct. This is + * invariably the wrong value on write. To fix this call the following API + * for each chunk in the list with the correct location. If you know your + * code won't be compiled on earlier versions you can rely on + * png_set_unknown_chunks(write-ptr, png_get_unknown_chunks(read-ptr)) doing + * the correct thing. + */ + +PNG_EXPORT(175, void, png_set_unknown_chunk_location, + (png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location)); + +PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structrp png_ptr, + png_inforp info_ptr, png_unknown_chunkpp entries)); +#endif + +/* Png_free_data() will turn off the "valid" flag for anything it frees. + * If you need to turn it off for a chunk that your application has freed, + * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); + */ +PNG_EXPORT(177, void, png_set_invalid, (png_const_structrp png_ptr, + png_inforp info_ptr, int mask)); + +#ifdef PNG_INFO_IMAGE_SUPPORTED +/* The "params" pointer is currently not used and is for future expansion. */ +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +PNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr, + int transforms, png_voidp params)); +#endif +#ifdef PNG_WRITE_SUPPORTED +PNG_EXPORT(179, void, png_write_png, (png_structrp png_ptr, png_inforp info_ptr, + int transforms, png_voidp params)); +#endif +#endif + +PNG_EXPORT(180, png_const_charp, png_get_copyright, + (png_const_structrp png_ptr)); +PNG_EXPORT(181, png_const_charp, png_get_header_ver, + (png_const_structrp png_ptr)); +PNG_EXPORT(182, png_const_charp, png_get_header_version, + (png_const_structrp png_ptr)); +PNG_EXPORT(183, png_const_charp, png_get_libpng_ver, + (png_const_structrp png_ptr)); + +#ifdef PNG_MNG_FEATURES_SUPPORTED +PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structrp png_ptr, + png_uint_32 mng_features_permitted)); +#endif + +/* For use in png_set_keep_unknown, added to version 1.2.6 */ +#define PNG_HANDLE_CHUNK_AS_DEFAULT 0 +#define PNG_HANDLE_CHUNK_NEVER 1 +#define PNG_HANDLE_CHUNK_IF_SAFE 2 +#define PNG_HANDLE_CHUNK_ALWAYS 3 +#define PNG_HANDLE_CHUNK_LAST 4 + +/* Strip the prepended error numbers ("#nnn ") from error and warning + * messages before passing them to the error or warning handler. + */ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +PNG_EXPORT(185, void, png_set_strip_error_numbers, (png_structrp png_ptr, + png_uint_32 strip_mode)); +#endif + +/* Added in libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +PNG_EXPORT(186, void, png_set_user_limits, (png_structrp png_ptr, + png_uint_32 user_width_max, png_uint_32 user_height_max)); +PNG_EXPORT(187, png_uint_32, png_get_user_width_max, + (png_const_structrp png_ptr)); +PNG_EXPORT(188, png_uint_32, png_get_user_height_max, + (png_const_structrp png_ptr)); +/* Added in libpng-1.4.0 */ +PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structrp png_ptr, + png_uint_32 user_chunk_cache_max)); +PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max, + (png_const_structrp png_ptr)); +/* Added in libpng-1.4.1 */ +PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structrp png_ptr, + png_alloc_size_t user_chunk_cache_max)); +PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max, + (png_const_structrp png_ptr)); +#endif + +#if defined(PNG_INCH_CONVERSIONS_SUPPORTED) +PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +PNG_FP_EXPORT(196, float, png_get_x_offset_inches, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) +#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ +PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) +#endif + +PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structrp png_ptr, + png_const_inforp info_ptr)) +#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ +PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) +#endif + +# ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, + int *unit_type)); +# endif /* pHYs */ +#endif /* INCH_CONVERSIONS */ + +/* Added in libpng-1.4.0 */ +#ifdef PNG_IO_STATE_SUPPORTED +PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_const_structrp png_ptr)); + +/* Removed from libpng 1.6; use png_get_io_chunk_type. */ +PNG_REMOVED(200, png_const_bytep, png_get_io_chunk_name, (png_structrp png_ptr), + PNG_DEPRECATED) + +PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, + (png_const_structrp png_ptr)); + +/* The flags returned by png_get_io_state() are the following: */ +# define PNG_IO_NONE 0x0000 /* no I/O at this moment */ +# define PNG_IO_READING 0x0001 /* currently reading */ +# define PNG_IO_WRITING 0x0002 /* currently writing */ +# define PNG_IO_SIGNATURE 0x0010 /* currently at the file signature */ +# define PNG_IO_CHUNK_HDR 0x0020 /* currently at the chunk header */ +# define PNG_IO_CHUNK_DATA 0x0040 /* currently at the chunk data */ +# define PNG_IO_CHUNK_CRC 0x0080 /* currently at the chunk crc */ +# define PNG_IO_MASK_OP 0x000f /* current operation: reading/writing */ +# define PNG_IO_MASK_LOC 0x00f0 /* current location: sig/hdr/data/crc */ +#endif /* IO_STATE */ + +/* Interlace support. The following macros are always defined so that if + * libpng interlace handling is turned off the macros may be used to handle + * interlaced images within the application. + */ +#define PNG_INTERLACE_ADAM7_PASSES 7 + +/* Two macros to return the first row and first column of the original, + * full, image which appears in a given pass. 'pass' is in the range 0 + * to 6 and the result is in the range 0 to 7. + */ +#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7) +#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7) + +/* A macro to return the offset between pixels in the output row for a pair of + * pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that + * follows. Note that ROW_OFFSET is the offset from one row to the next whereas + * COL_OFFSET is from one column to the next, within a row. + */ +#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8) +#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1)) + +/* Two macros to help evaluate the number of rows or columns in each + * pass. This is expressed as a shift - effectively log2 of the number or + * rows or columns in each 8x8 tile of the original image. + */ +#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3) +#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3) + +/* Hence two macros to determine the number of rows or columns in a given + * pass of an image given its height or width. In fact these macros may + * return non-zero even though the sub-image is empty, because the other + * dimension may be empty for a small image. + */ +#define PNG_PASS_ROWS(height, pass) (((height)+(((1<>PNG_PASS_ROW_SHIFT(pass)) +#define PNG_PASS_COLS(width, pass) (((width)+(((1<>PNG_PASS_COL_SHIFT(pass)) + +/* For the reader row callbacks (both progressive and sequential) it is + * necessary to find the row in the output image given a row in an interlaced + * image, so two more macros: + */ +#define PNG_ROW_FROM_PASS_ROW(y_in, pass) \ + (((y_in)<>(((7-(off))-(pass))<<2)) & 0xF) | \ + ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0)) + +#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \ + ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1) +#define PNG_COL_IN_INTERLACE_PASS(x, pass) \ + ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1) + +#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED +/* With these routines we avoid an integer divide, which will be slower on + * most machines. However, it does take more operations than the corresponding + * divide method, so it may be slower on a few RISC systems. There are two + * shifts (by 8 or 16 bits) and an addition, versus a single integer divide. + * + * Note that the rounding factors are NOT supposed to be the same! 128 and + * 32768 are correct for the NODIV code; 127 and 32767 are correct for the + * standard method. + * + * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ] + */ + + /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ + +# define png_composite(composite, fg, alpha, bg) \ + { \ + png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \ + * (png_uint_16)(alpha) \ + + (png_uint_16)(bg)*(png_uint_16)(255 \ + - (png_uint_16)(alpha)) + 128); \ + (composite) = (png_byte)(((temp + (temp >> 8)) >> 8) & 0xff); \ + } + +# define png_composite_16(composite, fg, alpha, bg) \ + { \ + png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \ + * (png_uint_32)(alpha) \ + + (png_uint_32)(bg)*(65535 \ + - (png_uint_32)(alpha)) + 32768); \ + (composite) = (png_uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); \ + } + +#else /* Standard method using integer division */ + +# define png_composite(composite, fg, alpha, bg) \ + (composite) = \ + (png_byte)(0xff & (((png_uint_16)(fg) * (png_uint_16)(alpha) + \ + (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ + 127) / 255)) + +# define png_composite_16(composite, fg, alpha, bg) \ + (composite) = \ + (png_uint_16)(0xffff & (((png_uint_32)(fg) * (png_uint_32)(alpha) + \ + (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \ + 32767) / 65535)) +#endif /* READ_COMPOSITE_NODIV */ + +#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf)); +PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf)); +PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf)); +#endif + +PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_const_structrp png_ptr, + png_const_bytep buf)); +/* No png_get_int_16 -- may be added if there's a real need for it. */ + +/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */ +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i)); +#endif +#ifdef PNG_SAVE_INT_32_SUPPORTED +PNG_EXPORT(206, void, png_save_int_32, (png_bytep buf, png_int_32 i)); +#endif + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); +/* No png_save_int_16 -- may be added if there's a real need for it. */ +#endif + +#ifdef PNG_USE_READ_MACROS +/* Inline macros to do direct reads of bytes from the input buffer. + * The png_get_int_32() routine assumes we are using two's complement + * format for negative values, which is almost certainly true. + */ +# define PNG_get_uint_32(buf) \ + (((png_uint_32)(*(buf)) << 24) + \ + ((png_uint_32)(*((buf) + 1)) << 16) + \ + ((png_uint_32)(*((buf) + 2)) << 8) + \ + ((png_uint_32)(*((buf) + 3)))) + + /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the + * function) incorrectly returned a value of type png_uint_32. + */ +# define PNG_get_uint_16(buf) \ + ((png_uint_16) \ + (((unsigned int)(*(buf)) << 8) + \ + ((unsigned int)(*((buf) + 1))))) + +# define PNG_get_int_32(buf) \ + ((png_int_32)((*(buf) & 0x80) \ + ? -((png_int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \ + : (png_int_32)png_get_uint_32(buf))) + +/* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h, + * but defining a macro name prefixed with PNG_PREFIX. + */ +# ifndef PNG_PREFIX +# define png_get_uint_32(buf) PNG_get_uint_32(buf) +# define png_get_uint_16(buf) PNG_get_uint_16(buf) +# define png_get_int_32(buf) PNG_get_int_32(buf) +# endif +#else +# ifdef PNG_PREFIX + /* No macros; revert to the (redefined) function */ +# define PNG_get_uint_32 (png_get_uint_32) +# define PNG_get_uint_16 (png_get_uint_16) +# define PNG_get_int_32 (png_get_int_32) +# endif +#endif + +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +PNG_EXPORT(242, void, png_set_check_for_invalid_index, + (png_structrp png_ptr, int allowed)); +# ifdef PNG_GET_PALETTE_MAX_SUPPORTED +PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr, + png_const_infop info_ptr)); +# endif +#endif /* CHECK_FOR_INVALID_INDEX */ + +/******************************************************************************* + * Section 5: SIMPLIFIED API + ******************************************************************************* + * + * Please read the documentation in libpng-manual.txt (TODO: write said + * documentation) if you don't understand what follows. + * + * The simplified API hides the details of both libpng and the PNG file format + * itself. It allows PNG files to be read into a very limited number of + * in-memory bitmap formats or to be written from the same formats. If these + * formats do not accommodate your needs then you can, and should, use the more + * sophisticated APIs above - these support a wide variety of in-memory formats + * and a wide variety of sophisticated transformations to those formats as well + * as a wide variety of APIs to manipulate ancillary information. + * + * To read a PNG file using the simplified API: + * + * 1) Declare a 'png_image' structure (see below) on the stack, set the + * version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL + * (this is REQUIRED, your program may crash if you don't do it.) + * 2) Call the appropriate png_image_begin_read... function. + * 3) Set the png_image 'format' member to the required sample format. + * 4) Allocate a buffer for the image and, if required, the color-map. + * 5) Call png_image_finish_read to read the image and, if required, the + * color-map into your buffers. + * + * There are no restrictions on the format of the PNG input itself; all valid + * color types, bit depths, and interlace methods are acceptable, and the + * input image is transformed as necessary to the requested in-memory format + * during the png_image_finish_read() step. The only caveat is that if you + * request a color-mapped image from a PNG that is full-color or makes + * complex use of an alpha channel the transformation is extremely lossy and the + * result may look terrible. + * + * To write a PNG file using the simplified API: + * + * 1) Declare a 'png_image' structure on the stack and memset() it to all zero. + * 2) Initialize the members of the structure that describe the image, setting + * the 'format' member to the format of the image samples. + * 3) Call the appropriate png_image_write... function with a pointer to the + * image and, if necessary, the color-map to write the PNG data. + * + * png_image is a structure that describes the in-memory format of an image + * when it is being read or defines the in-memory format of an image that you + * need to write: + */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) || \ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) + +#define PNG_IMAGE_VERSION 1 + +typedef struct png_control *png_controlp; +typedef struct +{ + png_controlp opaque; /* Initialize to NULL, free with png_image_free */ + png_uint_32 version; /* Set to PNG_IMAGE_VERSION */ + png_uint_32 width; /* Image width in pixels (columns) */ + png_uint_32 height; /* Image height in pixels (rows) */ + png_uint_32 format; /* Image format as defined below */ + png_uint_32 flags; /* A bit mask containing informational flags */ + png_uint_32 colormap_entries; + /* Number of entries in the color-map */ + + /* In the event of an error or warning the following field will be set to a + * non-zero value and the 'message' field will contain a '\0' terminated + * string with the libpng error or warning message. If both warnings and + * an error were encountered, only the error is recorded. If there + * are multiple warnings, only the first one is recorded. + * + * The upper 30 bits of this value are reserved, the low two bits contain + * a value as follows: + */ +# define PNG_IMAGE_WARNING 1 +# define PNG_IMAGE_ERROR 2 + /* + * The result is a two-bit code such that a value more than 1 indicates + * a failure in the API just called: + * + * 0 - no warning or error + * 1 - warning + * 2 - error + * 3 - error preceded by warning + */ +# define PNG_IMAGE_FAILED(png_cntrl) ((((png_cntrl).warning_or_error)&0x03)>1) + + png_uint_32 warning_or_error; + + char message[64]; +} png_image, *png_imagep; + +/* The samples of the image have one to four channels whose components have + * original values in the range 0 to 1.0: + * + * 1: A single gray or luminance channel (G). + * 2: A gray/luminance channel and an alpha channel (GA). + * 3: Three red, green, blue color channels (RGB). + * 4: Three color channels and an alpha channel (RGBA). + * + * The components are encoded in one of two ways: + * + * a) As a small integer, value 0..255, contained in a single byte. For the + * alpha channel the original value is simply value/255. For the color or + * luminance channels the value is encoded according to the sRGB specification + * and matches the 8-bit format expected by typical display devices. + * + * The color/gray channels are not scaled (pre-multiplied) by the alpha + * channel and are suitable for passing to color management software. + * + * b) As a value in the range 0..65535, contained in a 2-byte integer. All + * channels can be converted to the original value by dividing by 65535; all + * channels are linear. Color channels use the RGB encoding (RGB end-points) of + * the sRGB specification. This encoding is identified by the + * PNG_FORMAT_FLAG_LINEAR flag below. + * + * When the simplified API needs to convert between sRGB and linear colorspaces, + * the actual sRGB transfer curve defined in the sRGB specification (see the + * article at ) is used, not the gamma=1/2.2 + * approximation used elsewhere in libpng. + * + * When an alpha channel is present it is expected to denote pixel coverage + * of the color or luminance channels and is returned as an associated alpha + * channel: the color/gray channels are scaled (pre-multiplied) by the alpha + * value. + * + * The samples are either contained directly in the image data, between 1 and 8 + * bytes per pixel according to the encoding, or are held in a color-map indexed + * by bytes in the image data. In the case of a color-map the color-map entries + * are individual samples, encoded as above, and the image data has one byte per + * pixel to select the relevant sample from the color-map. + */ + +/* PNG_FORMAT_* + * + * #defines to be used in png_image::format. Each #define identifies a + * particular layout of sample data and, if present, alpha values. There are + * separate defines for each of the two component encodings. + * + * A format is built up using single bit flag values. All combinations are + * valid. Formats can be built up from the flag values or you can use one of + * the predefined values below. When testing formats always use the FORMAT_FLAG + * macros to test for individual features - future versions of the library may + * add new flags. + * + * When reading or writing color-mapped images the format should be set to the + * format of the entries in the color-map then png_image_{read,write}_colormap + * called to read or write the color-map and set the format correctly for the + * image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly! + * + * NOTE: libpng can be built with particular features disabled. If you see + * compiler errors because the definition of one of the following flags has been + * compiled out it is because libpng does not have the required support. It is + * possible, however, for the libpng configuration to enable the format on just + * read or just write; in that case you may see an error at run time. You can + * guard against this by checking for the definition of the appropriate + * "_SUPPORTED" macro, one of: + * + * PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED + */ +#define PNG_FORMAT_FLAG_ALPHA 0x01U /* format with an alpha channel */ +#define PNG_FORMAT_FLAG_COLOR 0x02U /* color format: otherwise grayscale */ +#define PNG_FORMAT_FLAG_LINEAR 0x04U /* 2-byte channels else 1-byte */ +#define PNG_FORMAT_FLAG_COLORMAP 0x08U /* image data is color-mapped */ + +#ifdef PNG_FORMAT_BGR_SUPPORTED +# define PNG_FORMAT_FLAG_BGR 0x10U /* BGR colors, else order is RGB */ +#endif + +#ifdef PNG_FORMAT_AFIRST_SUPPORTED +# define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */ +#endif + +#define PNG_FORMAT_FLAG_ASSOCIATED_ALPHA 0x40U /* alpha channel is associated */ + +/* Commonly used formats have predefined macros. + * + * First the single byte (sRGB) formats: + */ +#define PNG_FORMAT_GRAY 0 +#define PNG_FORMAT_GA PNG_FORMAT_FLAG_ALPHA +#define PNG_FORMAT_AG (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST) +#define PNG_FORMAT_RGB PNG_FORMAT_FLAG_COLOR +#define PNG_FORMAT_BGR (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR) +#define PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST) +#define PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST) + +/* Then the linear 2-byte formats. When naming these "Y" is used to + * indicate a luminance (gray) channel. + */ +#define PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR +#define PNG_FORMAT_LINEAR_Y_ALPHA (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_LINEAR_RGB (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR) +#define PNG_FORMAT_LINEAR_RGB_ALPHA \ + (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA) + +/* With color-mapped formats the image data is one byte for each pixel, the byte + * is an index into the color-map which is formatted as above. To obtain a + * color-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP + * to one of the above definitions, or you can use one of the definitions below. + */ +#define PNG_FORMAT_RGB_COLORMAP (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_BGR_COLORMAP (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_RGBA_COLORMAP (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_ARGB_COLORMAP (PNG_FORMAT_ARGB|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_BGRA_COLORMAP (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_ABGR_COLORMAP (PNG_FORMAT_ABGR|PNG_FORMAT_FLAG_COLORMAP) + +/* PNG_IMAGE macros + * + * These are convenience macros to derive information from a png_image + * structure. The PNG_IMAGE_SAMPLE_ macros return values appropriate to the + * actual image sample values - either the entries in the color-map or the + * pixels in the image. The PNG_IMAGE_PIXEL_ macros return corresponding values + * for the pixels and will always return 1 for color-mapped formats. The + * remaining macros return information about the rows in the image and the + * complete image. + * + * NOTE: All the macros that take a png_image::format parameter are compile time + * constants if the format parameter is, itself, a constant. Therefore these + * macros can be used in array declarations and case labels where required. + * Similarly the macros are also pre-processor constants (sizeof is not used) so + * they can be used in #if tests. + * + * First the information about the samples. + */ +#define PNG_IMAGE_SAMPLE_CHANNELS(fmt)\ + (((fmt)&(PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA))+1) + /* Return the total number of channels in a given format: 1..4 */ + +#define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\ + ((((fmt) & PNG_FORMAT_FLAG_LINEAR) >> 2)+1) + /* Return the size in bytes of a single component of a pixel or color-map + * entry (as appropriate) in the image: 1 or 2. + */ + +#define PNG_IMAGE_SAMPLE_SIZE(fmt)\ + (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)) + /* This is the size of the sample data for one sample. If the image is + * color-mapped it is the size of one color-map entry (and image pixels are + * one byte in size), otherwise it is the size of one image pixel. + */ + +#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\ + (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256) + /* The maximum size of the color-map required by the format expressed in a + * count of components. This can be used to compile-time allocate a + * color-map: + * + * png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)]; + * + * png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)]; + * + * Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the + * information from one of the png_image_begin_read_ APIs and dynamically + * allocate the required memory. + */ + +/* Corresponding information about the pixels */ +#define PNG_IMAGE_PIXEL_(test,fmt)\ + (((fmt)&PNG_FORMAT_FLAG_COLORMAP)?1:test(fmt)) + +#define PNG_IMAGE_PIXEL_CHANNELS(fmt)\ + PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_CHANNELS,fmt) + /* The number of separate channels (components) in a pixel; 1 for a + * color-mapped image. + */ + +#define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\ + PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE,fmt) + /* The size, in bytes, of each component in a pixel; 1 for a color-mapped + * image. + */ + +#define PNG_IMAGE_PIXEL_SIZE(fmt) PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_SIZE,fmt) + /* The size, in bytes, of a complete pixel; 1 for a color-mapped image. */ + +/* Information about the whole row, or whole image */ +#define PNG_IMAGE_ROW_STRIDE(image)\ + (PNG_IMAGE_PIXEL_CHANNELS((image).format) * (image).width) + /* Return the total number of components in a single row of the image; this + * is the minimum 'row stride', the minimum count of components between each + * row. For a color-mapped image this is the minimum number of bytes in a + * row. + * + * WARNING: this macro overflows for some images with more than one component + * and very large image widths. libpng will refuse to process an image where + * this macro would overflow. + */ + +#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\ + (PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format)*(image).height*(row_stride)) + /* Return the size, in bytes, of an image buffer given a png_image and a row + * stride - the number of components to leave space for in each row. + * + * WARNING: this macro overflows a 32-bit integer for some large PNG images, + * libpng will refuse to process an image where such an overflow would occur. + */ + +#define PNG_IMAGE_SIZE(image)\ + PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image)) + /* Return the size, in bytes, of the image in memory given just a png_image; + * the row stride is the minimum stride required for the image. + */ + +#define PNG_IMAGE_COLORMAP_SIZE(image)\ + (PNG_IMAGE_SAMPLE_SIZE((image).format) * (image).colormap_entries) + /* Return the size, in bytes, of the color-map of this image. If the image + * format is not a color-map format this will return a size sufficient for + * 256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if + * you don't want to allocate a color-map in this case. + */ + +/* PNG_IMAGE_FLAG_* + * + * Flags containing additional information about the image are held in the + * 'flags' field of png_image. + */ +#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB 0x01 + /* This indicates that the RGB values of the in-memory bitmap do not + * correspond to the red, green and blue end-points defined by sRGB. + */ + +#define PNG_IMAGE_FLAG_FAST 0x02 + /* On write emphasise speed over compression; the resultant PNG file will be + * larger but will be produced significantly faster, particular for large + * images. Do not use this option for images which will be distributed, only + * used it when producing intermediate files that will be read back in + * repeatedly. For a typical 24-bit image the option will double the read + * speed at the cost of increasing the image size by 25%, however for many + * more compressible images the PNG file can be 10 times larger with only a + * slight speed gain. + */ + +#define PNG_IMAGE_FLAG_16BIT_sRGB 0x04 + /* On read if the image is a 16-bit per component image and there is no gAMA + * or sRGB chunk assume that the components are sRGB encoded. Notice that + * images output by the simplified API always have gamma information; setting + * this flag only affects the interpretation of 16-bit images from an + * external source. It is recommended that the application expose this flag + * to the user; the user can normally easily recognize the difference between + * linear and sRGB encoding. This flag has no effect on write - the data + * passed to the write APIs must have the correct encoding (as defined + * above.) + * + * If the flag is not set (the default) input 16-bit per component data is + * assumed to be linear. + * + * NOTE: the flag can only be set after the png_image_begin_read_ call, + * because that call initializes the 'flags' field. + */ + +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +/* READ APIs + * --------- + * + * The png_image passed to the read APIs must have been initialized by setting + * the png_controlp field 'opaque' to NULL (or, safer, memset the whole thing.) + */ +#ifdef PNG_STDIO_SUPPORTED +PNG_EXPORT(234, int, png_image_begin_read_from_file, (png_imagep image, + const char *file_name)); + /* The named file is opened for read and the image header is filled in + * from the PNG header in the file. + */ + +PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image, + FILE* file)); + /* The PNG header is read from the stdio FILE object. */ +#endif /* STDIO */ + +PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image, + png_const_voidp memory, size_t size)); + /* The PNG header is read from the given memory buffer. */ + +PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image, + png_const_colorp background, void *buffer, png_int_32 row_stride, + void *colormap)); + /* Finish reading the image into the supplied buffer and clean up the + * png_image structure. + * + * row_stride is the step, in byte or 2-byte units as appropriate, + * between adjacent rows. A positive stride indicates that the top-most row + * is first in the buffer - the normal top-down arrangement. A negative + * stride indicates that the bottom-most row is first in the buffer. + * + * background need only be supplied if an alpha channel must be removed from + * a png_byte format and the removal is to be done by compositing on a solid + * color; otherwise it may be NULL and any composition will be done directly + * onto the buffer. The value is an sRGB color to use for the background, + * for grayscale output the green channel is used. + * + * background must be supplied when an alpha channel must be removed from a + * single byte color-mapped output format, in other words if: + * + * 1) The original format from png_image_begin_read_from_* had + * PNG_FORMAT_FLAG_ALPHA set. + * 2) The format set by the application does not. + * 3) The format set by the application has PNG_FORMAT_FLAG_COLORMAP set and + * PNG_FORMAT_FLAG_LINEAR *not* set. + * + * For linear output removing the alpha channel is always done by compositing + * on black and background is ignored. + * + * colormap must be supplied when PNG_FORMAT_FLAG_COLORMAP is set. It must + * be at least the size (in bytes) returned by PNG_IMAGE_COLORMAP_SIZE. + * image->colormap_entries will be updated to the actual number of entries + * written to the colormap; this may be less than the original value. + */ + +PNG_EXPORT(238, void, png_image_free, (png_imagep image)); + /* Free any data allocated by libpng in image->opaque, setting the pointer to + * NULL. May be called at any time after the structure is initialized. + */ +#endif /* SIMPLIFIED_READ */ + +#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED +/* WRITE APIS + * ---------- + * For write you must initialize a png_image structure to describe the image to + * be written. To do this use memset to set the whole structure to 0 then + * initialize fields describing your image. + * + * version: must be set to PNG_IMAGE_VERSION + * opaque: must be initialized to NULL + * width: image width in pixels + * height: image height in rows + * format: the format of the data (image and color-map) you wish to write + * flags: set to 0 unless one of the defined flags applies; set + * PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB + * values do not correspond to the colors in sRGB. + * colormap_entries: set to the number of entries in the color-map (0 to 256) + */ +#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED +PNG_EXPORT(239, int, png_image_write_to_file, (png_imagep image, + const char *file, int convert_to_8bit, const void *buffer, + png_int_32 row_stride, const void *colormap)); + /* Write the image to the named file. */ + +PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file, + int convert_to_8_bit, const void *buffer, png_int_32 row_stride, + const void *colormap)); + /* Write the image to the given (FILE*). */ +#endif /* SIMPLIFIED_WRITE_STDIO */ + +/* With all write APIs if image is in one of the linear formats with 16-bit + * data then setting convert_to_8_bit will cause the output to be an 8-bit PNG + * gamma encoded according to the sRGB specification, otherwise a 16-bit linear + * encoded PNG file is written. + * + * With color-mapped data formats the colormap parameter point to a color-map + * with at least image->colormap_entries encoded in the specified format. If + * the format is linear the written PNG color-map will be converted to sRGB + * regardless of the convert_to_8_bit flag. + * + * With all APIs row_stride is handled as in the read APIs - it is the spacing + * from one row to the next in component sized units (1 or 2 bytes) and if + * negative indicates a bottom-up row layout in the buffer. If row_stride is + * zero, libpng will calculate it for you from the image width and number of + * channels. + * + * Note that the write API does not support interlacing, sub-8-bit pixels or + * most ancillary chunks. If you need to write text chunks (e.g. for copyright + * notices) you need to use one of the other APIs. + */ + +PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory, + png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8_bit, + const void *buffer, png_int_32 row_stride, const void *colormap)); + /* Write the image to the given memory buffer. The function both writes the + * whole PNG data stream to *memory and updates *memory_bytes with the count + * of bytes written. + * + * 'memory' may be NULL. In this case *memory_bytes is not read however on + * success the number of bytes which would have been written will still be + * stored in *memory_bytes. On failure *memory_bytes will contain 0. + * + * If 'memory' is not NULL it must point to memory[*memory_bytes] of + * writeable memory. + * + * If the function returns success memory[*memory_bytes] (if 'memory' is not + * NULL) contains the written PNG data. *memory_bytes will always be less + * than or equal to the original value. + * + * If the function returns false and *memory_bytes was not changed an error + * occurred during write. If *memory_bytes was changed, or is not 0 if + * 'memory' was NULL, the write would have succeeded but for the memory + * buffer being too small. *memory_bytes contains the required number of + * bytes and will be bigger that the original value. + */ + +#define png_image_write_get_memory_size(image, size, convert_to_8_bit, buffer,\ + row_stride, colormap)\ + png_image_write_to_memory(&(image), 0, &(size), convert_to_8_bit, buffer,\ + row_stride, colormap) + /* Return the amount of memory in 'size' required to compress this image. + * The png_image structure 'image' must be filled in as in the above + * function and must not be changed before the actual write call, the buffer + * and all other parameters must also be identical to that in the final + * write call. The 'size' variable need not be initialized. + * + * NOTE: the macro returns true/false, if false is returned 'size' will be + * set to zero and the write failed and probably will fail if tried again. + */ + +/* You can pre-allocate the buffer by making sure it is of sufficient size + * regardless of the amount of compression achieved. The buffer size will + * always be bigger than the original image and it will never be filled. The + * following macros are provided to assist in allocating the buffer. + */ +#define PNG_IMAGE_DATA_SIZE(image) (PNG_IMAGE_SIZE(image)+(image).height) + /* The number of uncompressed bytes in the PNG byte encoding of the image; + * uncompressing the PNG IDAT data will give this number of bytes. + * + * NOTE: while PNG_IMAGE_SIZE cannot overflow for an image in memory this + * macro can because of the extra bytes used in the PNG byte encoding. You + * need to avoid this macro if your image size approaches 2^30 in width or + * height. The same goes for the remainder of these macros; they all produce + * bigger numbers than the actual in-memory image size. + */ +#ifndef PNG_ZLIB_MAX_SIZE +# define PNG_ZLIB_MAX_SIZE(b) ((b)+(((b)+7U)>>3)+(((b)+63U)>>6)+11U) + /* An upper bound on the number of compressed bytes given 'b' uncompressed + * bytes. This is based on deflateBounds() in zlib; different + * implementations of zlib compression may conceivably produce more data so + * if your zlib implementation is not zlib itself redefine this macro + * appropriately. + */ +#endif + +#define PNG_IMAGE_COMPRESSED_SIZE_MAX(image)\ + PNG_ZLIB_MAX_SIZE((png_alloc_size_t)PNG_IMAGE_DATA_SIZE(image)) + /* An upper bound on the size of the data in the PNG IDAT chunks. */ + +#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\ + ((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\ + (((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\ + 12U+3U*(image).colormap_entries/*PLTE data*/+\ + (((image).format&PNG_FORMAT_FLAG_ALPHA)?\ + 12U/*tRNS*/+(image).colormap_entries:0U):0U)+\ + 12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size)) + /* A helper for the following macro; if your compiler cannot handle the + * following macro use this one with the result of + * PNG_IMAGE_COMPRESSED_SIZE_MAX(image) as the second argument (most + * compilers should handle this just fine.) + */ + +#define PNG_IMAGE_PNG_SIZE_MAX(image)\ + PNG_IMAGE_PNG_SIZE_MAX_(image, PNG_IMAGE_COMPRESSED_SIZE_MAX(image)) + /* An upper bound on the total length of the PNG data stream for 'image'. + * The result is of type png_alloc_size_t, on 32-bit systems this may + * overflow even though PNG_IMAGE_DATA_SIZE does not overflow; the write will + * run out of buffer space but return a corrected size which should work. + */ +#endif /* SIMPLIFIED_WRITE */ +/******************************************************************************* + * END OF SIMPLIFIED API + ******************************************************************************/ +#endif /* SIMPLIFIED_{READ|WRITE} */ + +/******************************************************************************* + * Section 6: IMPLEMENTATION OPTIONS + ******************************************************************************* + * + * Support for arbitrary implementation-specific optimizations. The API allows + * particular options to be turned on or off. 'Option' is the number of the + * option and 'onoff' is 0 (off) or non-0 (on). The value returned is given + * by the PNG_OPTION_ defines below. + * + * HARDWARE: normally hardware capabilities, such as the Intel SSE instructions, + * are detected at run time, however sometimes it may be impossible + * to do this in user mode, in which case it is necessary to discover + * the capabilities in an OS specific way. Such capabilities are + * listed here when libpng has support for them and must be turned + * ON by the application if present. + * + * SOFTWARE: sometimes software optimizations actually result in performance + * decrease on some architectures or systems, or with some sets of + * PNG images. 'Software' options allow such optimizations to be + * selected at run time. + */ +#ifdef PNG_SET_OPTION_SUPPORTED +#ifdef PNG_ARM_NEON_API_SUPPORTED +# define PNG_ARM_NEON 0 /* HARDWARE: ARM Neon SIMD instructions supported */ +#endif +#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */ +#define PNG_SKIP_sRGB_CHECK_PROFILE 4 /* SOFTWARE: Check ICC profile for sRGB */ +#ifdef PNG_MIPS_MSA_API_SUPPORTED +# define PNG_MIPS_MSA 6 /* HARDWARE: MIPS Msa SIMD instructions supported */ +#endif +#define PNG_IGNORE_ADLER32 8 +#ifdef PNG_POWERPC_VSX_API_SUPPORTED +# define PNG_POWERPC_VSX 10 /* HARDWARE: PowerPC VSX SIMD instructions supported */ +#endif +#define PNG_OPTION_NEXT 12 /* Next option - numbers must be even */ + +/* Return values: NOTE: there are four values and 'off' is *not* zero */ +#define PNG_OPTION_UNSET 0 /* Unset - defaults to off */ +#define PNG_OPTION_INVALID 1 /* Option number out of range */ +#define PNG_OPTION_OFF 2 +#define PNG_OPTION_ON 3 + +PNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option, + int onoff)); +#endif /* SET_OPTION */ + +/******************************************************************************* + * END OF HARDWARE AND SOFTWARE OPTIONS + ******************************************************************************/ + +/* Maintainer: Put new public prototypes here ^, in libpng.3, in project + * defs, and in scripts/symbols.def. + */ + +/* The last ordinal number (this is the *last* one already used; the next + * one to use is one more than this.) + */ +#ifdef PNG_EXPORT_LAST_ORDINAL + PNG_EXPORT_LAST_ORDINAL(249); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PNG_VERSION_INFO_ONLY */ +/* Do not put anything past this line */ +#endif /* PNG_H */ diff --git a/extern/libpng/pngconf.h b/extern/libpng/pngconf.h new file mode 100644 index 000000000..927a769db --- /dev/null +++ b/extern/libpng/pngconf.h @@ -0,0 +1,623 @@ + +/* pngconf.h - machine-configurable file for libpng + * + * libpng version 1.6.37 + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * Any machine specific code is near the front of this file, so if you + * are configuring libpng for a machine, you may want to read the section + * starting here down to where it starts to typedef png_color, png_text, + * and png_info. + */ + +#ifndef PNGCONF_H +#define PNGCONF_H + +#ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */ + +/* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 ("ISOC90") compliant C + * compiler for correct compilation. The following header files are required by + * the standard. If your compiler doesn't provide these header files, or they + * do not match the standard, you will need to provide/improve them. + */ +#include +#include + +/* Library header files. These header files are all defined by ISOC90; libpng + * expects conformant implementations, however, an ISOC90 conformant system need + * not provide these header files if the functionality cannot be implemented. + * In this case it will be necessary to disable the relevant parts of libpng in + * the build of pnglibconf.h. + * + * Prior to 1.6.0 string.h was included here; the API changes in 1.6.0 to not + * include this unnecessary header file. + */ + +#ifdef PNG_STDIO_SUPPORTED + /* Required for the definition of FILE: */ +# include +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Required for the definition of jmp_buf and the declaration of longjmp: */ +# include +#endif + +#ifdef PNG_CONVERT_tIME_SUPPORTED + /* Required for struct tm: */ +# include +#endif + +#endif /* PNG_BUILDING_SYMBOL_TABLE */ + +/* Prior to 1.6.0, it was possible to turn off 'const' in declarations, + * using PNG_NO_CONST. This is no longer supported. + */ +#define PNG_CONST const /* backward compatibility only */ + +/* This controls optimization of the reading of 16-bit and 32-bit + * values from PNG files. It can be set on a per-app-file basis: it + * just changes whether a macro is used when the function is called. + * The library builder sets the default; if read functions are not + * built into the library the macro implementation is forced on. + */ +#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED +# define PNG_USE_READ_MACROS +#endif +#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS) +# if PNG_DEFAULT_READ_MACROS +# define PNG_USE_READ_MACROS +# endif +#endif + +/* COMPILER SPECIFIC OPTIONS. + * + * These options are provided so that a variety of difficult compilers + * can be used. Some are fixed at build time (e.g. PNG_API_RULE + * below) but still have compiler specific implementations, others + * may be changed on a per-file basis when compiling against libpng. + */ + +/* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect + * against legacy (pre ISOC90) compilers that did not understand function + * prototypes. It is not required for modern C compilers. + */ +#ifndef PNGARG +# define PNGARG(arglist) arglist +#endif + +/* Function calling conventions. + * ============================= + * Normally it is not necessary to specify to the compiler how to call + * a function - it just does it - however on x86 systems derived from + * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems + * and some others) there are multiple ways to call a function and the + * default can be changed on the compiler command line. For this reason + * libpng specifies the calling convention of every exported function and + * every function called via a user supplied function pointer. This is + * done in this file by defining the following macros: + * + * PNGAPI Calling convention for exported functions. + * PNGCBAPI Calling convention for user provided (callback) functions. + * PNGCAPI Calling convention used by the ANSI-C library (required + * for longjmp callbacks and sometimes used internally to + * specify the calling convention for zlib). + * + * These macros should never be overridden. If it is necessary to + * change calling convention in a private build this can be done + * by setting PNG_API_RULE (which defaults to 0) to one of the values + * below to select the correct 'API' variants. + * + * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout. + * This is correct in every known environment. + * PNG_API_RULE=1 Use the operating system convention for PNGAPI and + * the 'C' calling convention (from PNGCAPI) for + * callbacks (PNGCBAPI). This is no longer required + * in any known environment - if it has to be used + * please post an explanation of the problem to the + * libpng mailing list. + * + * These cases only differ if the operating system does not use the C + * calling convention, at present this just means the above cases + * (x86 DOS/Windows systems) and, even then, this does not apply to + * Cygwin running on those systems. + * + * Note that the value must be defined in pnglibconf.h so that what + * the application uses to call the library matches the conventions + * set when building the library. + */ + +/* Symbol export + * ============= + * When building a shared library it is almost always necessary to tell + * the compiler which symbols to export. The png.h macro 'PNG_EXPORT' + * is used to mark the symbols. On some systems these symbols can be + * extracted at link time and need no special processing by the compiler, + * on other systems the symbols are flagged by the compiler and just + * the declaration requires a special tag applied (unfortunately) in a + * compiler dependent way. Some systems can do either. + * + * A small number of older systems also require a symbol from a DLL to + * be flagged to the program that calls it. This is a problem because + * we do not know in the header file included by application code that + * the symbol will come from a shared library, as opposed to a statically + * linked one. For this reason the application must tell us by setting + * the magic flag PNG_USE_DLL to turn on the special processing before + * it includes png.h. + * + * Four additional macros are used to make this happen: + * + * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from + * the build or imported if PNG_USE_DLL is set - compiler + * and system specific. + * + * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to + * 'type', compiler specific. + * + * PNG_DLL_EXPORT Set to the magic to use during a libpng build to + * make a symbol exported from the DLL. Not used in the + * public header files; see pngpriv.h for how it is used + * in the libpng build. + * + * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come + * from a DLL - used to define PNG_IMPEXP when + * PNG_USE_DLL is set. + */ + +/* System specific discovery. + * ========================== + * This code is used at build time to find PNG_IMPEXP, the API settings + * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL + * import processing is possible. On Windows systems it also sets + * compiler-specific macros to the values required to change the calling + * conventions of the various functions. + */ +#if defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\ + defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) + /* Windows system (DOS doesn't support DLLs). Includes builds under Cygwin or + * MinGW on any architecture currently supported by Windows. Also includes + * Watcom builds but these need special treatment because they are not + * compatible with GCC or Visual C because of different calling conventions. + */ +# if PNG_API_RULE == 2 + /* If this line results in an error, either because __watcall is not + * understood or because of a redefine just below you cannot use *this* + * build of the library with the compiler you are using. *This* build was + * build using Watcom and applications must also be built using Watcom! + */ +# define PNGCAPI __watcall +# endif + +# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800)) +# define PNGCAPI __cdecl +# if PNG_API_RULE == 1 + /* If this line results in an error __stdcall is not understood and + * PNG_API_RULE should not have been set to '1'. + */ +# define PNGAPI __stdcall +# endif +# else + /* An older compiler, or one not detected (erroneously) above, + * if necessary override on the command line to get the correct + * variants for the compiler. + */ +# ifndef PNGCAPI +# define PNGCAPI _cdecl +# endif +# if PNG_API_RULE == 1 && !defined(PNGAPI) +# define PNGAPI _stdcall +# endif +# endif /* compiler/api */ + + /* NOTE: PNGCBAPI always defaults to PNGCAPI. */ + +# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD) +# error "PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed" +# endif + +# if (defined(_MSC_VER) && _MSC_VER < 800) ||\ + (defined(__BORLANDC__) && __BORLANDC__ < 0x500) + /* older Borland and MSC + * compilers used '__export' and required this to be after + * the type. + */ +# ifndef PNG_EXPORT_TYPE +# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP +# endif +# define PNG_DLL_EXPORT __export +# else /* newer compiler */ +# define PNG_DLL_EXPORT __declspec(dllexport) +# ifndef PNG_DLL_IMPORT +# define PNG_DLL_IMPORT __declspec(dllimport) +# endif +# endif /* compiler */ + +#else /* !Windows */ +# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) +# define PNGAPI _System +# else /* !Windows/x86 && !OS/2 */ + /* Use the defaults, or define PNG*API on the command line (but + * this will have to be done for every compile!) + */ +# endif /* other system, !OS/2 */ +#endif /* !Windows/x86 */ + +/* Now do all the defaulting . */ +#ifndef PNGCAPI +# define PNGCAPI +#endif +#ifndef PNGCBAPI +# define PNGCBAPI PNGCAPI +#endif +#ifndef PNGAPI +# define PNGAPI PNGCAPI +#endif + +/* PNG_IMPEXP may be set on the compilation system command line or (if not set) + * then in an internal header file when building the library, otherwise (when + * using the library) it is set here. + */ +#ifndef PNG_IMPEXP +# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) + /* This forces use of a DLL, disallowing static linking */ +# define PNG_IMPEXP PNG_DLL_IMPORT +# endif + +# ifndef PNG_IMPEXP +# define PNG_IMPEXP +# endif +#endif + +/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat + * 'attributes' as a storage class - the attributes go at the start of the + * function definition, and attributes are always appended regardless of the + * compiler. This considerably simplifies these macros but may cause problems + * if any compilers both need function attributes and fail to handle them as + * a storage class (this is unlikely.) + */ +#ifndef PNG_FUNCTION +# define PNG_FUNCTION(type, name, args, attributes) attributes type name args +#endif + +#ifndef PNG_EXPORT_TYPE +# define PNG_EXPORT_TYPE(type) PNG_IMPEXP type +#endif + + /* The ordinal value is only relevant when preprocessing png.h for symbol + * table entries, so we discard it here. See the .dfn files in the + * scripts directory. + */ + +#ifndef PNG_EXPORTA +# define PNG_EXPORTA(ordinal, type, name, args, attributes) \ + PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), PNGARG(args), \ + PNG_LINKAGE_API attributes) +#endif + +/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument, + * so make something non-empty to satisfy the requirement: + */ +#define PNG_EMPTY /*empty list*/ + +#define PNG_EXPORT(ordinal, type, name, args) \ + PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY) + +/* Use PNG_REMOVED to comment out a removed interface. */ +#ifndef PNG_REMOVED +# define PNG_REMOVED(ordinal, type, name, args, attributes) +#endif + +#ifndef PNG_CALLBACK +# define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args) +#endif + +/* Support for compiler specific function attributes. These are used + * so that where compiler support is available incorrect use of API + * functions in png.h will generate compiler warnings. + * + * Added at libpng-1.2.41. + */ + +#ifndef PNG_NO_PEDANTIC_WARNINGS +# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED +# define PNG_PEDANTIC_WARNINGS_SUPPORTED +# endif +#endif + +#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED + /* Support for compiler specific function attributes. These are used + * so that where compiler support is available, incorrect use of API + * functions in png.h will generate compiler warnings. Added at libpng + * version 1.2.41. Disabling these removes the warnings but may also produce + * less efficient code. + */ +# if defined(__clang__) && defined(__has_attribute) + /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */ +# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__) +# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) +# endif +# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__) +# define PNG_NORETURN __attribute__((__noreturn__)) +# endif +# if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__) +# define PNG_ALLOCATED __attribute__((__malloc__)) +# endif +# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__) +# define PNG_DEPRECATED __attribute__((__deprecated__)) +# endif +# if !defined(PNG_PRIVATE) +# ifdef __has_extension +# if __has_extension(attribute_unavailable_with_message) +# define PNG_PRIVATE __attribute__((__unavailable__(\ + "This function is not exported by libpng."))) +# endif +# endif +# endif +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif + +# elif defined(__GNUC__) +# ifndef PNG_USE_RESULT +# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) +# endif +# ifndef PNG_NORETURN +# define PNG_NORETURN __attribute__((__noreturn__)) +# endif +# if __GNUC__ >= 3 +# ifndef PNG_ALLOCATED +# define PNG_ALLOCATED __attribute__((__malloc__)) +# endif +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __attribute__((__deprecated__)) +# endif +# ifndef PNG_PRIVATE +# if 0 /* Doesn't work so we use deprecated instead*/ +# define PNG_PRIVATE \ + __attribute__((warning("This function is not exported by libpng."))) +# else +# define PNG_PRIVATE \ + __attribute__((__deprecated__)) +# endif +# endif +# if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1)) +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif +# endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */ +# endif /* __GNUC__ >= 3 */ + +# elif defined(_MSC_VER) && (_MSC_VER >= 1300) +# ifndef PNG_USE_RESULT +# define PNG_USE_RESULT /* not supported */ +# endif +# ifndef PNG_NORETURN +# define PNG_NORETURN __declspec(noreturn) +# endif +# ifndef PNG_ALLOCATED +# if (_MSC_VER >= 1400) +# define PNG_ALLOCATED __declspec(restrict) +# endif +# endif +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __declspec(deprecated) +# endif +# ifndef PNG_PRIVATE +# define PNG_PRIVATE __declspec(deprecated) +# endif +# ifndef PNG_RESTRICT +# if (_MSC_VER >= 1400) +# define PNG_RESTRICT __restrict +# endif +# endif + +# elif defined(__WATCOMC__) +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif +# endif +#endif /* PNG_PEDANTIC_WARNINGS */ + +#ifndef PNG_DEPRECATED +# define PNG_DEPRECATED /* Use of this function is deprecated */ +#endif +#ifndef PNG_USE_RESULT +# define PNG_USE_RESULT /* The result of this function must be checked */ +#endif +#ifndef PNG_NORETURN +# define PNG_NORETURN /* This function does not return */ +#endif +#ifndef PNG_ALLOCATED +# define PNG_ALLOCATED /* The result of the function is new memory */ +#endif +#ifndef PNG_PRIVATE +# define PNG_PRIVATE /* This is a private libpng function */ +#endif +#ifndef PNG_RESTRICT +# define PNG_RESTRICT /* The C99 "restrict" feature */ +#endif + +#ifndef PNG_FP_EXPORT /* A floating point API. */ +# ifdef PNG_FLOATING_POINT_SUPPORTED +# define PNG_FP_EXPORT(ordinal, type, name, args)\ + PNG_EXPORT(ordinal, type, name, args); +# else /* No floating point APIs */ +# define PNG_FP_EXPORT(ordinal, type, name, args) +# endif +#endif +#ifndef PNG_FIXED_EXPORT /* A fixed point API. */ +# ifdef PNG_FIXED_POINT_SUPPORTED +# define PNG_FIXED_EXPORT(ordinal, type, name, args)\ + PNG_EXPORT(ordinal, type, name, args); +# else /* No fixed point APIs */ +# define PNG_FIXED_EXPORT(ordinal, type, name, args) +# endif +#endif + +#ifndef PNG_BUILDING_SYMBOL_TABLE +/* Some typedefs to get us started. These should be safe on most of the common + * platforms. + * + * png_uint_32 and png_int_32 may, currently, be larger than required to hold a + * 32-bit value however this is not normally advisable. + * + * png_uint_16 and png_int_16 should always be two bytes in size - this is + * verified at library build time. + * + * png_byte must always be one byte in size. + * + * The checks below use constants from limits.h, as defined by the ISOC90 + * standard. + */ +#if CHAR_BIT == 8 && UCHAR_MAX == 255 + typedef unsigned char png_byte; +#else +# error "libpng requires 8-bit bytes" +#endif + +#if INT_MIN == -32768 && INT_MAX == 32767 + typedef int png_int_16; +#elif SHRT_MIN == -32768 && SHRT_MAX == 32767 + typedef short png_int_16; +#else +# error "libpng requires a signed 16-bit type" +#endif + +#if UINT_MAX == 65535 + typedef unsigned int png_uint_16; +#elif USHRT_MAX == 65535 + typedef unsigned short png_uint_16; +#else +# error "libpng requires an unsigned 16-bit type" +#endif + +#if INT_MIN < -2147483646 && INT_MAX > 2147483646 + typedef int png_int_32; +#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646 + typedef long int png_int_32; +#else +# error "libpng requires a signed 32-bit (or more) type" +#endif + +#if UINT_MAX > 4294967294U + typedef unsigned int png_uint_32; +#elif ULONG_MAX > 4294967294U + typedef unsigned long int png_uint_32; +#else +# error "libpng requires an unsigned 32-bit (or more) type" +#endif + +/* Prior to 1.6.0, it was possible to disable the use of size_t and ptrdiff_t. + * From 1.6.0 onwards, an ISO C90 compiler, as well as a standard-compliant + * behavior of sizeof and ptrdiff_t are required. + * The legacy typedefs are provided here for backwards compatibility. + */ +typedef size_t png_size_t; +typedef ptrdiff_t png_ptrdiff_t; + +/* libpng needs to know the maximum value of 'size_t' and this controls the + * definition of png_alloc_size_t, below. This maximum value of size_t limits + * but does not control the maximum allocations the library makes - there is + * direct application control of this through png_set_user_limits(). + */ +#ifndef PNG_SMALL_SIZE_T + /* Compiler specific tests for systems where size_t is known to be less than + * 32 bits (some of these systems may no longer work because of the lack of + * 'far' support; see above.) + */ +# if (defined(__TURBOC__) && !defined(__FLAT__)) ||\ + (defined(_MSC_VER) && defined(MAXSEG_64K)) +# define PNG_SMALL_SIZE_T +# endif +#endif + +/* png_alloc_size_t is guaranteed to be no smaller than size_t, and no smaller + * than png_uint_32. Casts from size_t or png_uint_32 to png_alloc_size_t are + * not necessary; in fact, it is recommended not to use them at all, so that + * the compiler can complain when something turns out to be problematic. + * + * Casts in the other direction (from png_alloc_size_t to size_t or + * png_uint_32) should be explicitly applied; however, we do not expect to + * encounter practical situations that require such conversions. + * + * PNG_SMALL_SIZE_T must be defined if the maximum value of size_t is less than + * 4294967295 - i.e. less than the maximum value of png_uint_32. + */ +#ifdef PNG_SMALL_SIZE_T + typedef png_uint_32 png_alloc_size_t; +#else + typedef size_t png_alloc_size_t; +#endif + +/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler + * implementations of Intel CPU specific support of user-mode segmented address + * spaces, where 16-bit pointers address more than 65536 bytes of memory using + * separate 'segment' registers. The implementation requires two different + * types of pointer (only one of which includes the segment value.) + * + * If required this support is available in version 1.2 of libpng and may be + * available in versions through 1.5, although the correctness of the code has + * not been verified recently. + */ + +/* Typedef for floating-point numbers that are converted to fixed-point with a + * multiple of 100,000, e.g., gamma + */ +typedef png_int_32 png_fixed_point; + +/* Add typedefs for pointers */ +typedef void * png_voidp; +typedef const void * png_const_voidp; +typedef png_byte * png_bytep; +typedef const png_byte * png_const_bytep; +typedef png_uint_32 * png_uint_32p; +typedef const png_uint_32 * png_const_uint_32p; +typedef png_int_32 * png_int_32p; +typedef const png_int_32 * png_const_int_32p; +typedef png_uint_16 * png_uint_16p; +typedef const png_uint_16 * png_const_uint_16p; +typedef png_int_16 * png_int_16p; +typedef const png_int_16 * png_const_int_16p; +typedef char * png_charp; +typedef const char * png_const_charp; +typedef png_fixed_point * png_fixed_point_p; +typedef const png_fixed_point * png_const_fixed_point_p; +typedef size_t * png_size_tp; +typedef const size_t * png_const_size_tp; + +#ifdef PNG_STDIO_SUPPORTED +typedef FILE * png_FILE_p; +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double * png_doublep; +typedef const double * png_const_doublep; +#endif + +/* Pointers to pointers; i.e. arrays */ +typedef png_byte * * png_bytepp; +typedef png_uint_32 * * png_uint_32pp; +typedef png_int_32 * * png_int_32pp; +typedef png_uint_16 * * png_uint_16pp; +typedef png_int_16 * * png_int_16pp; +typedef const char * * png_const_charpp; +typedef char * * png_charpp; +typedef png_fixed_point * * png_fixed_point_pp; +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double * * png_doublepp; +#endif + +/* Pointers to pointers to pointers; i.e., pointer to array */ +typedef char * * * png_charppp; + +#endif /* PNG_BUILDING_SYMBOL_TABLE */ + +#endif /* PNGCONF_H */ diff --git a/extern/libpng/pngdebug.h b/extern/libpng/pngdebug.h new file mode 100644 index 000000000..00d5a4569 --- /dev/null +++ b/extern/libpng/pngdebug.h @@ -0,0 +1,153 @@ + +/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* Define PNG_DEBUG at compile time for debugging information. Higher + * numbers for PNG_DEBUG mean more debugging information. This has + * only been added since version 0.95 so it is not implemented throughout + * libpng yet, but more support will be added as needed. + * + * png_debug[1-2]?(level, message ,arg{0-2}) + * Expands to a statement (either a simple expression or a compound + * do..while(0) statement) that outputs a message with parameter + * substitution if PNG_DEBUG is defined to 2 or more. If PNG_DEBUG + * is undefined, 0 or 1 every png_debug expands to a simple expression + * (actually ((void)0)). + * + * level: level of detail of message, starting at 0. A level 'n' + * message is preceded by 'n' 3-space indentations (not implemented + * on Microsoft compilers unless PNG_DEBUG_FILE is also + * defined, to allow debug DLL compilation with no standard IO). + * message: a printf(3) style text string. A trailing '\n' is added + * to the message. + * arg: 0 to 2 arguments for printf(3) style substitution in message. + */ +#ifndef PNGDEBUG_H +#define PNGDEBUG_H +/* These settings control the formatting of messages in png.c and pngerror.c */ +/* Moved to pngdebug.h at 1.5.0 */ +# ifndef PNG_LITERAL_SHARP +# define PNG_LITERAL_SHARP 0x23 +# endif +# ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET +# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b +# endif +# ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET +# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d +# endif +# ifndef PNG_STRING_NEWLINE +# define PNG_STRING_NEWLINE "\n" +# endif + +#ifdef PNG_DEBUG +# if (PNG_DEBUG > 0) +# if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) +# include +# if (PNG_DEBUG > 1) +# ifndef _DEBUG +# define _DEBUG +# endif +# ifndef png_debug +# define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE) +# endif +# ifndef png_debug1 +# define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1) +# endif +# ifndef png_debug2 +# define png_debug2(l,m,p1,p2) \ + _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2) +# endif +# endif +# else /* PNG_DEBUG_FILE || !_MSC_VER */ +# ifndef PNG_STDIO_SUPPORTED +# include /* not included yet */ +# endif +# ifndef PNG_DEBUG_FILE +# define PNG_DEBUG_FILE stderr +# endif /* PNG_DEBUG_FILE */ + +# if (PNG_DEBUG > 1) +# ifdef __STDC__ +# ifndef png_debug +# define png_debug(l,m) \ + do { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ + (num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \ + } while (0) +# endif +# ifndef png_debug1 +# define png_debug1(l,m,p1) \ + do { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ + (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \ + } while (0) +# endif +# ifndef png_debug2 +# define png_debug2(l,m,p1,p2) \ + do { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ + (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\ + } while (0) +# endif +# else /* __STDC __ */ +# ifndef png_debug +# define png_debug(l,m) \ + do { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format); \ + } while (0) +# endif +# ifndef png_debug1 +# define png_debug1(l,m,p1) \ + do { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format,p1); \ + } while (0) +# endif +# ifndef png_debug2 +# define png_debug2(l,m,p1,p2) \ + do { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format,p1,p2); \ + } while (0) +# endif +# endif /* __STDC __ */ +# endif /* (PNG_DEBUG > 1) */ + +# endif /* _MSC_VER */ +# endif /* (PNG_DEBUG > 0) */ +#endif /* PNG_DEBUG */ +#ifndef png_debug +# define png_debug(l, m) ((void)0) +#endif +#ifndef png_debug1 +# define png_debug1(l, m, p1) ((void)0) +#endif +#ifndef png_debug2 +# define png_debug2(l, m, p1, p2) ((void)0) +#endif +#endif /* PNGDEBUG_H */ diff --git a/extern/libpng/pngerror.c b/extern/libpng/pngerror.c new file mode 100644 index 000000000..ec3a709b9 --- /dev/null +++ b/extern/libpng/pngerror.c @@ -0,0 +1,963 @@ + +/* pngerror.c - stub functions for i/o and memory allocation + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all error handling. Users who + * need special error handling are expected to write replacement functions + * and use png_set_error_fn() to use those functions. See the instructions + * at each function. + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr, + png_const_charp error_message)),PNG_NORETURN); + +#ifdef PNG_WARNINGS_SUPPORTED +static void /* PRIVATE */ +png_default_warning PNGARG((png_const_structrp png_ptr, + png_const_charp warning_message)); +#endif /* WARNINGS */ + +/* This function is called whenever there is a fatal error. This function + * should not be changed. If there is a need to handle errors differently, + * you should supply a replacement error function and use png_set_error_fn() + * to replace the error function at run-time. + */ +#ifdef PNG_ERROR_TEXT_SUPPORTED +PNG_FUNCTION(void,PNGAPI +png_error,(png_const_structrp png_ptr, png_const_charp error_message), + PNG_NORETURN) +{ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + char msg[16]; + if (png_ptr != NULL) + { + if ((png_ptr->flags & + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0) + { + if (*error_message == PNG_LITERAL_SHARP) + { + /* Strip "#nnnn " from beginning of error message. */ + int offset; + for (offset = 1; offset<15; offset++) + if (error_message[offset] == ' ') + break; + + if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0) + { + int i; + for (i = 0; i < offset - 1; i++) + msg[i] = error_message[i + 1]; + msg[i - 1] = '\0'; + error_message = msg; + } + + else + error_message += offset; + } + + else + { + if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0) + { + msg[0] = '0'; + msg[1] = '\0'; + error_message = msg; + } + } + } + } +#endif + if (png_ptr != NULL && png_ptr->error_fn != NULL) + (*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), + error_message); + + /* If the custom handler doesn't exist, or if it returns, + use the default handler, which will not return. */ + png_default_error(png_ptr, error_message); +} +#else +PNG_FUNCTION(void,PNGAPI +png_err,(png_const_structrp png_ptr),PNG_NORETURN) +{ + /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed + * erroneously as '\0', instead of the empty string "". This was + * apparently an error, introduced in libpng-1.2.20, and png_default_error + * will crash in this case. + */ + if (png_ptr != NULL && png_ptr->error_fn != NULL) + (*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), ""); + + /* If the custom handler doesn't exist, or if it returns, + use the default handler, which will not return. */ + png_default_error(png_ptr, ""); +} +#endif /* ERROR_TEXT */ + +/* Utility to safely appends strings to a buffer. This never errors out so + * error checking is not required in the caller. + */ +size_t +png_safecat(png_charp buffer, size_t bufsize, size_t pos, + png_const_charp string) +{ + if (buffer != NULL && pos < bufsize) + { + if (string != NULL) + while (*string != '\0' && pos < bufsize-1) + buffer[pos++] = *string++; + + buffer[pos] = '\0'; + } + + return pos; +} + +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED) +/* Utility to dump an unsigned value into a buffer, given a start pointer and + * and end pointer (which should point just *beyond* the end of the buffer!) + * Returns the pointer to the start of the formatted string. + */ +png_charp +png_format_number(png_const_charp start, png_charp end, int format, + png_alloc_size_t number) +{ + int count = 0; /* number of digits output */ + int mincount = 1; /* minimum number required */ + int output = 0; /* digit output (for the fixed point format) */ + + *--end = '\0'; + + /* This is written so that the loop always runs at least once, even with + * number zero. + */ + while (end > start && (number != 0 || count < mincount)) + { + + static const char digits[] = "0123456789ABCDEF"; + + switch (format) + { + case PNG_NUMBER_FORMAT_fixed: + /* Needs five digits (the fraction) */ + mincount = 5; + if (output != 0 || number % 10 != 0) + { + *--end = digits[number % 10]; + output = 1; + } + number /= 10; + break; + + case PNG_NUMBER_FORMAT_02u: + /* Expects at least 2 digits. */ + mincount = 2; + /* FALLTHROUGH */ + + case PNG_NUMBER_FORMAT_u: + *--end = digits[number % 10]; + number /= 10; + break; + + case PNG_NUMBER_FORMAT_02x: + /* This format expects at least two digits */ + mincount = 2; + /* FALLTHROUGH */ + + case PNG_NUMBER_FORMAT_x: + *--end = digits[number & 0xf]; + number >>= 4; + break; + + default: /* an error */ + number = 0; + break; + } + + /* Keep track of the number of digits added */ + ++count; + + /* Float a fixed number here: */ + if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start)) + { + /* End of the fraction, but maybe nothing was output? In that case + * drop the decimal point. If the number is a true zero handle that + * here. + */ + if (output != 0) + *--end = '.'; + else if (number == 0) /* and !output */ + *--end = '0'; + } + } + + return end; +} +#endif + +#ifdef PNG_WARNINGS_SUPPORTED +/* This function is called whenever there is a non-fatal error. This function + * should not be changed. If there is a need to handle warnings differently, + * you should supply a replacement warning function and use + * png_set_error_fn() to replace the warning function at run-time. + */ +void PNGAPI +png_warning(png_const_structrp png_ptr, png_const_charp warning_message) +{ + int offset = 0; + if (png_ptr != NULL) + { +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + if ((png_ptr->flags & + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0) +#endif + { + if (*warning_message == PNG_LITERAL_SHARP) + { + for (offset = 1; offset < 15; offset++) + if (warning_message[offset] == ' ') + break; + } + } + } + if (png_ptr != NULL && png_ptr->warning_fn != NULL) + (*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr), + warning_message + offset); + else + png_default_warning(png_ptr, warning_message + offset); +} + +/* These functions support 'formatted' warning messages with up to + * PNG_WARNING_PARAMETER_COUNT parameters. In the format string the parameter + * is introduced by @, where 'number' starts at 1. This follows the + * standard established by X/Open for internationalizable error messages. + */ +void +png_warning_parameter(png_warning_parameters p, int number, + png_const_charp string) +{ + if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT) + (void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string); +} + +void +png_warning_parameter_unsigned(png_warning_parameters p, int number, int format, + png_alloc_size_t value) +{ + char buffer[PNG_NUMBER_BUFFER_SIZE]; + png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value)); +} + +void +png_warning_parameter_signed(png_warning_parameters p, int number, int format, + png_int_32 value) +{ + png_alloc_size_t u; + png_charp str; + char buffer[PNG_NUMBER_BUFFER_SIZE]; + + /* Avoid overflow by doing the negate in a png_alloc_size_t: */ + u = (png_alloc_size_t)value; + if (value < 0) + u = ~u + 1; + + str = PNG_FORMAT_NUMBER(buffer, format, u); + + if (value < 0 && str > buffer) + *--str = '-'; + + png_warning_parameter(p, number, str); +} + +void +png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p, + png_const_charp message) +{ + /* The internal buffer is just 192 bytes - enough for all our messages, + * overflow doesn't happen because this code checks! If someone figures + * out how to send us a message longer than 192 bytes, all that will + * happen is that the message will be truncated appropriately. + */ + size_t i = 0; /* Index in the msg[] buffer: */ + char msg[192]; + + /* Each iteration through the following loop writes at most one character + * to msg[i++] then returns here to validate that there is still space for + * the trailing '\0'. It may (in the case of a parameter) read more than + * one character from message[]; it must check for '\0' and continue to the + * test if it finds the end of string. + */ + while (i<(sizeof msg)-1 && *message != '\0') + { + /* '@' at end of string is now just printed (previously it was skipped); + * it is an error in the calling code to terminate the string with @. + */ + if (p != NULL && *message == '@' && message[1] != '\0') + { + int parameter_char = *++message; /* Consume the '@' */ + static const char valid_parameters[] = "123456789"; + int parameter = 0; + + /* Search for the parameter digit, the index in the string is the + * parameter to use. + */ + while (valid_parameters[parameter] != parameter_char && + valid_parameters[parameter] != '\0') + ++parameter; + + /* If the parameter digit is out of range it will just get printed. */ + if (parameter < PNG_WARNING_PARAMETER_COUNT) + { + /* Append this parameter */ + png_const_charp parm = p[parameter]; + png_const_charp pend = p[parameter] + (sizeof p[parameter]); + + /* No need to copy the trailing '\0' here, but there is no guarantee + * that parm[] has been initialized, so there is no guarantee of a + * trailing '\0': + */ + while (i<(sizeof msg)-1 && *parm != '\0' && parm < pend) + msg[i++] = *parm++; + + /* Consume the parameter digit too: */ + ++message; + continue; + } + + /* else not a parameter and there is a character after the @ sign; just + * copy that. This is known not to be '\0' because of the test above. + */ + } + + /* At this point *message can't be '\0', even in the bad parameter case + * above where there is a lone '@' at the end of the message string. + */ + msg[i++] = *message++; + } + + /* i is always less than (sizeof msg), so: */ + msg[i] = '\0'; + + /* And this is the formatted message. It may be larger than + * PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these + * are not (currently) formatted. + */ + png_warning(png_ptr, msg); +} +#endif /* WARNINGS */ + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_benign_error(png_const_structrp png_ptr, png_const_charp error_message) +{ + if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0) + { +# ifdef PNG_READ_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + png_ptr->chunk_name != 0) + png_chunk_warning(png_ptr, error_message); + else +# endif + png_warning(png_ptr, error_message); + } + + else + { +# ifdef PNG_READ_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + png_ptr->chunk_name != 0) + png_chunk_error(png_ptr, error_message); + else +# endif + png_error(png_ptr, error_message); + } + +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(error_message) +# endif +} + +void /* PRIVATE */ +png_app_warning(png_const_structrp png_ptr, png_const_charp error_message) +{ + if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0) + png_warning(png_ptr, error_message); + else + png_error(png_ptr, error_message); + +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(error_message) +# endif +} + +void /* PRIVATE */ +png_app_error(png_const_structrp png_ptr, png_const_charp error_message) +{ + if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0) + png_warning(png_ptr, error_message); + else + png_error(png_ptr, error_message); + +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(error_message) +# endif +} +#endif /* BENIGN_ERRORS */ + +#define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */ +#if defined(PNG_WARNINGS_SUPPORTED) || \ + (defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)) +/* These utilities are used internally to build an error message that relates + * to the current chunk. The chunk name comes from png_ptr->chunk_name, + * which is used to prefix the message. The message is limited in length + * to 63 bytes. The name characters are output as hex digits wrapped in [] + * if the character is invalid. + */ +#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) +static const char png_digit[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F' +}; + +static void /* PRIVATE */ +png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp + error_message) +{ + png_uint_32 chunk_name = png_ptr->chunk_name; + int iout = 0, ishift = 24; + + while (ishift >= 0) + { + int c = (int)(chunk_name >> ishift) & 0xff; + + ishift -= 8; + if (isnonalpha(c) != 0) + { + buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET; + buffer[iout++] = png_digit[(c & 0xf0) >> 4]; + buffer[iout++] = png_digit[c & 0x0f]; + buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET; + } + + else + { + buffer[iout++] = (char)c; + } + } + + if (error_message == NULL) + buffer[iout] = '\0'; + + else + { + int iin = 0; + + buffer[iout++] = ':'; + buffer[iout++] = ' '; + + while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0') + buffer[iout++] = error_message[iin++]; + + /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */ + buffer[iout] = '\0'; + } +} +#endif /* WARNINGS || ERROR_TEXT */ + +#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) +PNG_FUNCTION(void,PNGAPI +png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message), + PNG_NORETURN) +{ + char msg[18+PNG_MAX_ERROR_TEXT]; + if (png_ptr == NULL) + png_error(png_ptr, error_message); + + else + { + png_format_buffer(png_ptr, msg, error_message); + png_error(png_ptr, msg); + } +} +#endif /* READ && ERROR_TEXT */ + +#ifdef PNG_WARNINGS_SUPPORTED +void PNGAPI +png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message) +{ + char msg[18+PNG_MAX_ERROR_TEXT]; + if (png_ptr == NULL) + png_warning(png_ptr, warning_message); + + else + { + png_format_buffer(png_ptr, msg, warning_message); + png_warning(png_ptr, msg); + } +} +#endif /* WARNINGS */ + +#ifdef PNG_READ_SUPPORTED +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp + error_message) +{ + if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0) + png_chunk_warning(png_ptr, error_message); + + else + png_chunk_error(png_ptr, error_message); + +# ifndef PNG_ERROR_TEXT_SUPPORTED + PNG_UNUSED(error_message) +# endif +} +#endif +#endif /* READ */ + +void /* PRIVATE */ +png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error) +{ +# ifndef PNG_WARNINGS_SUPPORTED + PNG_UNUSED(message) +# endif + + /* This is always supported, but for just read or just write it + * unconditionally does the right thing. + */ +# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED) + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) +# endif + +# ifdef PNG_READ_SUPPORTED + { + if (error < PNG_CHUNK_ERROR) + png_chunk_warning(png_ptr, message); + + else + png_chunk_benign_error(png_ptr, message); + } +# endif + +# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED) + else if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) +# endif + +# ifdef PNG_WRITE_SUPPORTED + { + if (error < PNG_CHUNK_WRITE_ERROR) + png_app_warning(png_ptr, message); + + else + png_app_error(png_ptr, message); + } +# endif +} + +#ifdef PNG_ERROR_TEXT_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_FUNCTION(void, +png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN) +{ +# define fixed_message "fixed point overflow in " +# define fixed_message_ln ((sizeof fixed_message)-1) + unsigned int iin; + char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT]; + memcpy(msg, fixed_message, fixed_message_ln); + iin = 0; + if (name != NULL) + while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0) + { + msg[fixed_message_ln + iin] = name[iin]; + ++iin; + } + msg[fixed_message_ln + iin] = 0; + png_error(png_ptr, msg); +} +#endif +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* This API only exists if ANSI-C style error handling is used, + * otherwise it is necessary for png_default_error to be overridden. + */ +jmp_buf* PNGAPI +png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn, + size_t jmp_buf_size) +{ + /* From libpng 1.6.0 the app gets one chance to set a 'jmpbuf_size' value + * and it must not change after that. Libpng doesn't care how big the + * buffer is, just that it doesn't change. + * + * If the buffer size is no *larger* than the size of jmp_buf when libpng is + * compiled a built in jmp_buf is returned; this preserves the pre-1.6.0 + * semantics that this call will not fail. If the size is larger, however, + * the buffer is allocated and this may fail, causing the function to return + * NULL. + */ + if (png_ptr == NULL) + return NULL; + + if (png_ptr->jmp_buf_ptr == NULL) + { + png_ptr->jmp_buf_size = 0; /* not allocated */ + + if (jmp_buf_size <= (sizeof png_ptr->jmp_buf_local)) + png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local; + + else + { + png_ptr->jmp_buf_ptr = png_voidcast(jmp_buf *, + png_malloc_warn(png_ptr, jmp_buf_size)); + + if (png_ptr->jmp_buf_ptr == NULL) + return NULL; /* new NULL return on OOM */ + + png_ptr->jmp_buf_size = jmp_buf_size; + } + } + + else /* Already allocated: check the size */ + { + size_t size = png_ptr->jmp_buf_size; + + if (size == 0) + { + size = (sizeof png_ptr->jmp_buf_local); + if (png_ptr->jmp_buf_ptr != &png_ptr->jmp_buf_local) + { + /* This is an internal error in libpng: somehow we have been left + * with a stack allocated jmp_buf when the application regained + * control. It's always possible to fix this up, but for the moment + * this is a png_error because that makes it easy to detect. + */ + png_error(png_ptr, "Libpng jmp_buf still allocated"); + /* png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local; */ + } + } + + if (size != jmp_buf_size) + { + png_warning(png_ptr, "Application jmp_buf size changed"); + return NULL; /* caller will probably crash: no choice here */ + } + } + + /* Finally fill in the function, now we have a satisfactory buffer. It is + * valid to change the function on every call. + */ + png_ptr->longjmp_fn = longjmp_fn; + return png_ptr->jmp_buf_ptr; +} + +void /* PRIVATE */ +png_free_jmpbuf(png_structrp png_ptr) +{ + if (png_ptr != NULL) + { + jmp_buf *jb = png_ptr->jmp_buf_ptr; + + /* A size of 0 is used to indicate a local, stack, allocation of the + * pointer; used here and in png.c + */ + if (jb != NULL && png_ptr->jmp_buf_size > 0) + { + + /* This stuff is so that a failure to free the error control structure + * does not leave libpng in a state with no valid error handling: the + * free always succeeds, if there is an error it gets ignored. + */ + if (jb != &png_ptr->jmp_buf_local) + { + /* Make an internal, libpng, jmp_buf to return here */ + jmp_buf free_jmp_buf; + + if (!setjmp(free_jmp_buf)) + { + png_ptr->jmp_buf_ptr = &free_jmp_buf; /* come back here */ + png_ptr->jmp_buf_size = 0; /* stack allocation */ + png_ptr->longjmp_fn = longjmp; + png_free(png_ptr, jb); /* Return to setjmp on error */ + } + } + } + + /* *Always* cancel everything out: */ + png_ptr->jmp_buf_size = 0; + png_ptr->jmp_buf_ptr = NULL; + png_ptr->longjmp_fn = 0; + } +} +#endif + +/* This is the default error handling function. Note that replacements for + * this function MUST NOT RETURN, or the program will likely crash. This + * function is used by default, or if the program supplies NULL for the + * error function pointer in png_set_error_fn(). + */ +static PNG_FUNCTION(void /* PRIVATE */, +png_default_error,(png_const_structrp png_ptr, png_const_charp error_message), + PNG_NORETURN) +{ +#ifdef PNG_CONSOLE_IO_SUPPORTED +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + /* Check on NULL only added in 1.5.4 */ + if (error_message != NULL && *error_message == PNG_LITERAL_SHARP) + { + /* Strip "#nnnn " from beginning of error message. */ + int offset; + char error_number[16]; + for (offset = 0; offset<15; offset++) + { + error_number[offset] = error_message[offset + 1]; + if (error_message[offset] == ' ') + break; + } + + if ((offset > 1) && (offset < 15)) + { + error_number[offset - 1] = '\0'; + fprintf(stderr, "libpng error no. %s: %s", + error_number, error_message + offset + 1); + fprintf(stderr, PNG_STRING_NEWLINE); + } + + else + { + fprintf(stderr, "libpng error: %s, offset=%d", + error_message, offset); + fprintf(stderr, PNG_STRING_NEWLINE); + } + } + else +#endif + { + fprintf(stderr, "libpng error: %s", error_message ? error_message : + "undefined"); + fprintf(stderr, PNG_STRING_NEWLINE); + } +#else + PNG_UNUSED(error_message) /* Make compiler happy */ +#endif + png_longjmp(png_ptr, 1); +} + +PNG_FUNCTION(void,PNGAPI +png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN) +{ +#ifdef PNG_SETJMP_SUPPORTED + if (png_ptr != NULL && png_ptr->longjmp_fn != NULL && + png_ptr->jmp_buf_ptr != NULL) + png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val); +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(val) +#endif + + /* If control reaches this point, png_longjmp() must not return. The only + * choice is to terminate the whole process (or maybe the thread); to do + * this the ANSI-C abort() function is used unless a different method is + * implemented by overriding the default configuration setting for + * PNG_ABORT(). + */ + PNG_ABORT(); +} + +#ifdef PNG_WARNINGS_SUPPORTED +/* This function is called when there is a warning, but the library thinks + * it can continue anyway. Replacement functions don't have to do anything + * here if you don't want them to. In the default configuration, png_ptr is + * not used, but it is passed in case it may be useful. + */ +static void /* PRIVATE */ +png_default_warning(png_const_structrp png_ptr, png_const_charp warning_message) +{ +#ifdef PNG_CONSOLE_IO_SUPPORTED +# ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (*warning_message == PNG_LITERAL_SHARP) + { + int offset; + char warning_number[16]; + for (offset = 0; offset < 15; offset++) + { + warning_number[offset] = warning_message[offset + 1]; + if (warning_message[offset] == ' ') + break; + } + + if ((offset > 1) && (offset < 15)) + { + warning_number[offset + 1] = '\0'; + fprintf(stderr, "libpng warning no. %s: %s", + warning_number, warning_message + offset); + fprintf(stderr, PNG_STRING_NEWLINE); + } + + else + { + fprintf(stderr, "libpng warning: %s", + warning_message); + fprintf(stderr, PNG_STRING_NEWLINE); + } + } + else +# endif + + { + fprintf(stderr, "libpng warning: %s", warning_message); + fprintf(stderr, PNG_STRING_NEWLINE); + } +#else + PNG_UNUSED(warning_message) /* Make compiler happy */ +#endif + PNG_UNUSED(png_ptr) /* Make compiler happy */ +} +#endif /* WARNINGS */ + +/* This function is called when the application wants to use another method + * of handling errors and warnings. Note that the error function MUST NOT + * return to the calling routine or serious problems will occur. The return + * method used in the default routine calls longjmp(png_ptr->jmp_buf_ptr, 1) + */ +void PNGAPI +png_set_error_fn(png_structrp png_ptr, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warning_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->error_ptr = error_ptr; + png_ptr->error_fn = error_fn; +#ifdef PNG_WARNINGS_SUPPORTED + png_ptr->warning_fn = warning_fn; +#else + PNG_UNUSED(warning_fn) +#endif +} + + +/* This function returns a pointer to the error_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy and png_read_destroy are called. + */ +png_voidp PNGAPI +png_get_error_ptr(png_const_structrp png_ptr) +{ + if (png_ptr == NULL) + return NULL; + + return ((png_voidp)png_ptr->error_ptr); +} + + +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +void PNGAPI +png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode) +{ + if (png_ptr != NULL) + { + png_ptr->flags &= + ((~(PNG_FLAG_STRIP_ERROR_NUMBERS | + PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode); + } +} +#endif + +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) + /* Currently the above both depend on SETJMP_SUPPORTED, however it would be + * possible to implement without setjmp support just so long as there is some + * way to handle the error return here: + */ +PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI +png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message), + PNG_NORETURN) +{ + png_const_structrp png_ptr = png_nonconst_ptr; + png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); + + /* An error is always logged here, overwriting anything (typically a warning) + * that is already there: + */ + if (image != NULL) + { + png_safecat(image->message, (sizeof image->message), 0, error_message); + image->warning_or_error |= PNG_IMAGE_ERROR; + + /* Retrieve the jmp_buf from within the png_control, making this work for + * C++ compilation too is pretty tricky: C++ wants a pointer to the first + * element of a jmp_buf, but C doesn't tell us the type of that. + */ + if (image->opaque != NULL && image->opaque->error_buf != NULL) + longjmp(png_control_jmp_buf(image->opaque), 1); + + /* Missing longjmp buffer, the following is to help debugging: */ + { + size_t pos = png_safecat(image->message, (sizeof image->message), 0, + "bad longjmp: "); + png_safecat(image->message, (sizeof image->message), pos, + error_message); + } + } + + /* Here on an internal programming error. */ + abort(); +} + +#ifdef PNG_WARNINGS_SUPPORTED +void /* PRIVATE */ PNGCBAPI +png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message) +{ + png_const_structrp png_ptr = png_nonconst_ptr; + png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); + + /* A warning is only logged if there is no prior warning or error. */ + if (image->warning_or_error == 0) + { + png_safecat(image->message, (sizeof image->message), 0, warning_message); + image->warning_or_error |= PNG_IMAGE_WARNING; + } +} +#endif + +int /* PRIVATE */ +png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg) +{ + volatile png_imagep image = image_in; + volatile int result; + volatile png_voidp saved_error_buf; + jmp_buf safe_jmpbuf; + + /* Safely execute function(arg) with png_error returning to this function. */ + saved_error_buf = image->opaque->error_buf; + result = setjmp(safe_jmpbuf) == 0; + + if (result != 0) + { + + image->opaque->error_buf = safe_jmpbuf; + result = function(arg); + } + + image->opaque->error_buf = saved_error_buf; + + /* And do the cleanup prior to any failure return. */ + if (result == 0) + png_image_free(image); + + return result; +} +#endif /* SIMPLIFIED READ || SIMPLIFIED_WRITE */ +#endif /* READ || WRITE */ diff --git a/extern/libpng/pngget.c b/extern/libpng/pngget.c new file mode 100644 index 000000000..8f16da9bc --- /dev/null +++ b/extern/libpng/pngget.c @@ -0,0 +1,1278 @@ + +/* pngget.c - retrieval of values from info struct + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +png_uint_32 PNGAPI +png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_uint_32 flag) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->valid & flag); + + return(0); +} + +size_t PNGAPI +png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->rowbytes); + + return(0); +} + +#ifdef PNG_INFO_IMAGE_SUPPORTED +png_bytepp PNGAPI +png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->row_pointers); + + return(0); +} +#endif + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* Easy access to info, added in libpng-0.99 */ +png_uint_32 PNGAPI +png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->width; + + return (0); +} + +png_uint_32 PNGAPI +png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->height; + + return (0); +} + +png_byte PNGAPI +png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->bit_depth; + + return (0); +} + +png_byte PNGAPI +png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->color_type; + + return (0); +} + +png_byte PNGAPI +png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->filter_type; + + return (0); +} + +png_byte PNGAPI +png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->interlace_type; + + return (0); +} + +png_byte PNGAPI +png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->compression_type; + + return (0); +} + +png_uint_32 PNGAPI +png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp + info_ptr) +{ +#ifdef PNG_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) + { + png_debug1(1, "in %s retrieval function", + "png_get_x_pixels_per_meter"); + + if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) + return (info_ptr->x_pixels_per_unit); + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return (0); +} + +png_uint_32 PNGAPI +png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp + info_ptr) +{ +#ifdef PNG_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) + { + png_debug1(1, "in %s retrieval function", + "png_get_y_pixels_per_meter"); + + if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) + return (info_ptr->y_pixels_per_unit); + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return (0); +} + +png_uint_32 PNGAPI +png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ +#ifdef PNG_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) + { + png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); + + if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER && + info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit) + return (info_ptr->x_pixels_per_unit); + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return (0); +} + +#ifdef PNG_FLOATING_POINT_SUPPORTED +float PNGAPI +png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp + info_ptr) +{ +#ifdef PNG_READ_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) + { + png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); + + if (info_ptr->x_pixels_per_unit != 0) + return ((float)((float)info_ptr->y_pixels_per_unit + /(float)info_ptr->x_pixels_per_unit)); + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return ((float)0.0); +} +#endif + +#ifdef PNG_FIXED_POINT_SUPPORTED +png_fixed_point PNGAPI +png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr, + png_const_inforp info_ptr) +{ +#ifdef PNG_READ_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0 && + info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 && + info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX && + info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX) + { + png_fixed_point res; + + png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed"); + + /* The following casts work because a PNG 4 byte integer only has a valid + * range of 0..2^31-1; otherwise the cast might overflow. + */ + if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1, + (png_int_32)info_ptr->x_pixels_per_unit) != 0) + return res; + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return 0; +} +#endif + +png_int_32 PNGAPI +png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ +#ifdef PNG_oFFs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0) + { + png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); + + if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) + return (info_ptr->x_offset); + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return (0); +} + +png_int_32 PNGAPI +png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ +#ifdef PNG_oFFs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0) + { + png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); + + if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) + return (info_ptr->y_offset); + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return (0); +} + +png_int_32 PNGAPI +png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ +#ifdef PNG_oFFs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0) + { + png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels"); + + if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) + return (info_ptr->x_offset); + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return (0); +} + +png_int_32 PNGAPI +png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ +#ifdef PNG_oFFs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0) + { + png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels"); + + if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) + return (info_ptr->y_offset); + } +#else + PNG_UNUSED(png_ptr) + PNG_UNUSED(info_ptr) +#endif + + return (0); +} + +#ifdef PNG_INCH_CONVERSIONS_SUPPORTED +static png_uint_32 +ppi_from_ppm(png_uint_32 ppm) +{ +#if 0 + /* The conversion is *(2.54/100), in binary (32 digits): + * .00000110100000001001110101001001 + */ + png_uint_32 t1001, t1101; + ppm >>= 1; /* .1 */ + t1001 = ppm + (ppm >> 3); /* .1001 */ + t1101 = t1001 + (ppm >> 1); /* .1101 */ + ppm >>= 20; /* .000000000000000000001 */ + t1101 += t1101 >> 15; /* .1101000000000001101 */ + t1001 >>= 11; /* .000000000001001 */ + t1001 += t1001 >> 12; /* .000000000001001000000001001 */ + ppm += t1001; /* .000000000001001000001001001 */ + ppm += t1101; /* .110100000001001110101001001 */ + return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */ +#else + /* The argument is a PNG unsigned integer, so it is not permitted + * to be bigger than 2^31. + */ + png_fixed_point result; + if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, + 5000) != 0) + return (png_uint_32)result; + + /* Overflow. */ + return 0; +#endif +} + +png_uint_32 PNGAPI +png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); +} + +png_uint_32 PNGAPI +png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); +} + +png_uint_32 PNGAPI +png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); +} + +#ifdef PNG_FIXED_POINT_SUPPORTED +static png_fixed_point +png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns) +{ + /* Convert from meters * 1,000,000 to inches * 100,000, meters to + * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. + * Notice that this can overflow - a warning is output and 0 is + * returned. + */ + return png_muldiv_warn(png_ptr, microns, 500, 127); +} + +png_fixed_point PNGAPI +png_get_x_offset_inches_fixed(png_const_structrp png_ptr, + png_const_inforp info_ptr) +{ + return png_fixed_inches_from_microns(png_ptr, + png_get_x_offset_microns(png_ptr, info_ptr)); +} +#endif + +#ifdef PNG_FIXED_POINT_SUPPORTED +png_fixed_point PNGAPI +png_get_y_offset_inches_fixed(png_const_structrp png_ptr, + png_const_inforp info_ptr) +{ + return png_fixed_inches_from_microns(png_ptr, + png_get_y_offset_microns(png_ptr, info_ptr)); +} +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +float PNGAPI +png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + /* To avoid the overflow do the conversion directly in floating + * point. + */ + return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937); +} +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +float PNGAPI +png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + /* To avoid the overflow do the conversion directly in floating + * point. + */ + return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937); +} +#endif + +#ifdef PNG_pHYs_SUPPORTED +png_uint_32 PNGAPI +png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) +{ + png_uint_32 retval = 0; + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) + { + png_debug1(1, "in %s retrieval function", "pHYs"); + + if (res_x != NULL) + { + *res_x = info_ptr->x_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (res_y != NULL) + { + *res_y = info_ptr->y_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (unit_type != NULL) + { + *unit_type = (int)info_ptr->phys_unit_type; + retval |= PNG_INFO_pHYs; + + if (*unit_type == 1) + { + if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); + if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); + } + } + } + + return (retval); +} +#endif /* pHYs */ +#endif /* INCH_CONVERSIONS */ + +/* png_get_channels really belongs in here, too, but it's been around longer */ + +#endif /* EASY_ACCESS */ + + +png_byte PNGAPI +png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->channels); + + return (0); +} + +#ifdef PNG_READ_SUPPORTED +png_const_bytep PNGAPI +png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->signature); + + return (NULL); +} +#endif + +#ifdef PNG_bKGD_SUPPORTED +png_uint_32 PNGAPI +png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, + png_color_16p *background) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_bKGD) != 0 && + background != NULL) + { + png_debug1(1, "in %s retrieval function", "bKGD"); + + *background = &(info_ptr->background); + return (PNG_INFO_bKGD); + } + + return (0); +} +#endif + +#ifdef PNG_cHRM_SUPPORTED +/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the + * same time to correct the rgb grayscale coefficient defaults obtained from the + * cHRM chunk in 1.5.4 + */ +# ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr, + double *white_x, double *white_y, double *red_x, double *red_y, + double *green_x, double *green_y, double *blue_x, double *blue_y) +{ + /* Quiet API change: this code used to only return the end points if a cHRM + * chunk was present, but the end points can also come from iCCP or sRGB + * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and + * the png_set_ APIs merely check that set end points are mutually + * consistent. + */ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + png_debug1(1, "in %s retrieval function", "cHRM"); + + if (white_x != NULL) + *white_x = png_float(png_ptr, + info_ptr->colorspace.end_points_xy.whitex, "cHRM white X"); + if (white_y != NULL) + *white_y = png_float(png_ptr, + info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y"); + if (red_x != NULL) + *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx, + "cHRM red X"); + if (red_y != NULL) + *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy, + "cHRM red Y"); + if (green_x != NULL) + *green_x = png_float(png_ptr, + info_ptr->colorspace.end_points_xy.greenx, "cHRM green X"); + if (green_y != NULL) + *green_y = png_float(png_ptr, + info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y"); + if (blue_x != NULL) + *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex, + "cHRM blue X"); + if (blue_y != NULL) + *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey, + "cHRM blue Y"); + return (PNG_INFO_cHRM); + } + + return (0); +} + +png_uint_32 PNGAPI +png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr, + double *red_X, double *red_Y, double *red_Z, double *green_X, + double *green_Y, double *green_Z, double *blue_X, double *blue_Y, + double *blue_Z) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)"); + + if (red_X != NULL) + *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X, + "cHRM red X"); + if (red_Y != NULL) + *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y, + "cHRM red Y"); + if (red_Z != NULL) + *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z, + "cHRM red Z"); + if (green_X != NULL) + *green_X = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X"); + if (green_Y != NULL) + *green_Y = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y"); + if (green_Z != NULL) + *green_Z = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z"); + if (blue_X != NULL) + *blue_X = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X"); + if (blue_Y != NULL) + *blue_Y = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y"); + if (blue_Z != NULL) + *blue_Z = png_float(png_ptr, + info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z"); + return (PNG_INFO_cHRM); + } + + return (0); +} +# endif + +# ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_red_X, png_fixed_point *int_red_Y, + png_fixed_point *int_red_Z, png_fixed_point *int_green_X, + png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, + png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, + png_fixed_point *int_blue_Z) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + png_debug1(1, "in %s retrieval function", "cHRM_XYZ"); + + if (int_red_X != NULL) + *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X; + if (int_red_Y != NULL) + *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y; + if (int_red_Z != NULL) + *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z; + if (int_green_X != NULL) + *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X; + if (int_green_Y != NULL) + *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y; + if (int_green_Z != NULL) + *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z; + if (int_blue_X != NULL) + *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X; + if (int_blue_Y != NULL) + *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y; + if (int_blue_Z != NULL) + *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z; + return (PNG_INFO_cHRM); + } + + return (0); +} + +png_uint_32 PNGAPI +png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, + png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, + png_fixed_point *blue_x, png_fixed_point *blue_y) +{ + png_debug1(1, "in %s retrieval function", "cHRM"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + { + if (white_x != NULL) + *white_x = info_ptr->colorspace.end_points_xy.whitex; + if (white_y != NULL) + *white_y = info_ptr->colorspace.end_points_xy.whitey; + if (red_x != NULL) + *red_x = info_ptr->colorspace.end_points_xy.redx; + if (red_y != NULL) + *red_y = info_ptr->colorspace.end_points_xy.redy; + if (green_x != NULL) + *green_x = info_ptr->colorspace.end_points_xy.greenx; + if (green_y != NULL) + *green_y = info_ptr->colorspace.end_points_xy.greeny; + if (blue_x != NULL) + *blue_x = info_ptr->colorspace.end_points_xy.bluex; + if (blue_y != NULL) + *blue_y = info_ptr->colorspace.end_points_xy.bluey; + return (PNG_INFO_cHRM); + } + + return (0); +} +# endif +#endif + +#ifdef PNG_gAMA_SUPPORTED +# ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *file_gamma) +{ + png_debug1(1, "in %s retrieval function", "gAMA"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && + file_gamma != NULL) + { + *file_gamma = info_ptr->colorspace.gamma; + return (PNG_INFO_gAMA); + } + + return (0); +} +# endif + +# ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr, + double *file_gamma) +{ + png_debug1(1, "in %s retrieval function", "gAMA(float)"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && + file_gamma != NULL) + { + *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma, + "png_get_gAMA"); + return (PNG_INFO_gAMA); + } + + return (0); +} +# endif +#endif + +#ifdef PNG_sRGB_SUPPORTED +png_uint_32 PNGAPI +png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr, + int *file_srgb_intent) +{ + png_debug1(1, "in %s retrieval function", "sRGB"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL) + { + *file_srgb_intent = info_ptr->colorspace.rendering_intent; + return (PNG_INFO_sRGB); + } + + return (0); +} +#endif + +#ifdef PNG_iCCP_SUPPORTED +png_uint_32 PNGAPI +png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, + png_charpp name, int *compression_type, + png_bytepp profile, png_uint_32 *proflen) +{ + png_debug1(1, "in %s retrieval function", "iCCP"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_iCCP) != 0 && + name != NULL && profile != NULL && proflen != NULL) + { + *name = info_ptr->iccp_name; + *profile = info_ptr->iccp_profile; + *proflen = png_get_uint_32(info_ptr->iccp_profile); + /* This is somewhat irrelevant since the profile data returned has + * actually been uncompressed. + */ + if (compression_type != NULL) + *compression_type = PNG_COMPRESSION_TYPE_BASE; + return (PNG_INFO_iCCP); + } + + return (0); + +} +#endif + +#ifdef PNG_sPLT_SUPPORTED +int PNGAPI +png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr, + png_sPLT_tpp spalettes) +{ + if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) + { + *spalettes = info_ptr->splt_palettes; + return info_ptr->splt_palettes_num; + } + + return (0); +} +#endif + +#ifdef PNG_eXIf_SUPPORTED +png_uint_32 PNGAPI +png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr, + png_bytep *exif) +{ + png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1"); + PNG_UNUSED(info_ptr) + PNG_UNUSED(exif) + return 0; +} + +png_uint_32 PNGAPI +png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_uint_32 *num_exif, png_bytep *exif) +{ + png_debug1(1, "in %s retrieval function", "eXIf"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL) + { + *num_exif = info_ptr->num_exif; + *exif = info_ptr->exif; + return (PNG_INFO_eXIf); + } + + return (0); +} +#endif + +#ifdef PNG_eXIf_SUPPORTED +png_uint_32 PNGAPI +png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr, + png_bytep *exif) +{ + png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1"); + PNG_UNUSED(info_ptr) + PNG_UNUSED(exif) + return 0; +} + +png_uint_32 PNGAPI +png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_uint_32 *num_exif, png_bytep *exif) +{ + png_debug1(1, "in %s retrieval function", "eXIf"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL) + { + *num_exif = info_ptr->num_exif; + *exif = info_ptr->exif; + return (PNG_INFO_eXIf); + } + + return (0); +} +#endif + +#ifdef PNG_hIST_SUPPORTED +png_uint_32 PNGAPI +png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr, + png_uint_16p *hist) +{ + png_debug1(1, "in %s retrieval function", "hIST"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL) + { + *hist = info_ptr->hist; + return (PNG_INFO_hIST); + } + + return (0); +} +#endif + +png_uint_32 PNGAPI +png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_uint_32 *width, png_uint_32 *height, int *bit_depth, + int *color_type, int *interlace_type, int *compression_type, + int *filter_type) +{ + png_debug1(1, "in %s retrieval function", "IHDR"); + + if (png_ptr == NULL || info_ptr == NULL) + return (0); + + if (width != NULL) + *width = info_ptr->width; + + if (height != NULL) + *height = info_ptr->height; + + if (bit_depth != NULL) + *bit_depth = info_ptr->bit_depth; + + if (color_type != NULL) + *color_type = info_ptr->color_type; + + if (compression_type != NULL) + *compression_type = info_ptr->compression_type; + + if (filter_type != NULL) + *filter_type = info_ptr->filter_type; + + if (interlace_type != NULL) + *interlace_type = info_ptr->interlace_type; + + /* This is redundant if we can be sure that the info_ptr values were all + * assigned in png_set_IHDR(). We do the check anyhow in case an + * application has ignored our advice not to mess with the members + * of info_ptr directly. + */ + png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, + info_ptr->compression_type, info_ptr->filter_type); + + return (1); +} + +#ifdef PNG_oFFs_SUPPORTED +png_uint_32 PNGAPI +png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) +{ + png_debug1(1, "in %s retrieval function", "oFFs"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_oFFs) != 0 && + offset_x != NULL && offset_y != NULL && unit_type != NULL) + { + *offset_x = info_ptr->x_offset; + *offset_y = info_ptr->y_offset; + *unit_type = (int)info_ptr->offset_unit_type; + return (PNG_INFO_oFFs); + } + + return (0); +} +#endif + +#ifdef PNG_pCAL_SUPPORTED +png_uint_32 PNGAPI +png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, + png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, + png_charp *units, png_charpp *params) +{ + png_debug1(1, "in %s retrieval function", "pCAL"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pCAL) != 0 && + purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && + nparams != NULL && units != NULL && params != NULL) + { + *purpose = info_ptr->pcal_purpose; + *X0 = info_ptr->pcal_X0; + *X1 = info_ptr->pcal_X1; + *type = (int)info_ptr->pcal_type; + *nparams = (int)info_ptr->pcal_nparams; + *units = info_ptr->pcal_units; + *params = info_ptr->pcal_params; + return (PNG_INFO_pCAL); + } + + return (0); +} +#endif + +#ifdef PNG_sCAL_SUPPORTED +# ifdef PNG_FIXED_POINT_SUPPORTED +# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ + defined(PNG_FLOATING_POINT_SUPPORTED) +png_uint_32 PNGAPI +png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, + int *unit, png_fixed_point *width, png_fixed_point *height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL) != 0) + { + *unit = info_ptr->scal_unit; + /*TODO: make this work without FP support; the API is currently eliminated + * if neither floating point APIs nor internal floating point arithmetic + * are enabled. + */ + *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width"); + *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height), + "sCAL height"); + return (PNG_INFO_sCAL); + } + + return(0); +} +# endif /* FLOATING_ARITHMETIC */ +# endif /* FIXED_POINT */ +# ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr, + int *unit, double *width, double *height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL) != 0) + { + *unit = info_ptr->scal_unit; + *width = atof(info_ptr->scal_s_width); + *height = atof(info_ptr->scal_s_height); + return (PNG_INFO_sCAL); + } + + return(0); +} +# endif /* FLOATING POINT */ +png_uint_32 PNGAPI +png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr, + int *unit, png_charpp width, png_charpp height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL) != 0) + { + *unit = info_ptr->scal_unit; + *width = info_ptr->scal_s_width; + *height = info_ptr->scal_s_height; + return (PNG_INFO_sCAL); + } + + return(0); +} +#endif /* sCAL */ + +#ifdef PNG_pHYs_SUPPORTED +png_uint_32 PNGAPI +png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) +{ + png_uint_32 retval = 0; + + png_debug1(1, "in %s retrieval function", "pHYs"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs) != 0) + { + if (res_x != NULL) + { + *res_x = info_ptr->x_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (res_y != NULL) + { + *res_y = info_ptr->y_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (unit_type != NULL) + { + *unit_type = (int)info_ptr->phys_unit_type; + retval |= PNG_INFO_pHYs; + } + } + + return (retval); +} +#endif /* pHYs */ + +png_uint_32 PNGAPI +png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr, + png_colorp *palette, int *num_palette) +{ + png_debug1(1, "in %s retrieval function", "PLTE"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL) + { + *palette = info_ptr->palette; + *num_palette = info_ptr->num_palette; + png_debug1(3, "num_palette = %d", *num_palette); + return (PNG_INFO_PLTE); + } + + return (0); +} + +#ifdef PNG_sBIT_SUPPORTED +png_uint_32 PNGAPI +png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, + png_color_8p *sig_bit) +{ + png_debug1(1, "in %s retrieval function", "sBIT"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL) + { + *sig_bit = &(info_ptr->sig_bit); + return (PNG_INFO_sBIT); + } + + return (0); +} +#endif + +#ifdef PNG_TEXT_SUPPORTED +int PNGAPI +png_get_text(png_const_structrp png_ptr, png_inforp info_ptr, + png_textp *text_ptr, int *num_text) +{ + if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) + { + png_debug1(1, "in 0x%lx retrieval function", + (unsigned long)png_ptr->chunk_name); + + if (text_ptr != NULL) + *text_ptr = info_ptr->text; + + if (num_text != NULL) + *num_text = info_ptr->num_text; + + return info_ptr->num_text; + } + + if (num_text != NULL) + *num_text = 0; + + return(0); +} +#endif + +#ifdef PNG_tIME_SUPPORTED +png_uint_32 PNGAPI +png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr, + png_timep *mod_time) +{ + png_debug1(1, "in %s retrieval function", "tIME"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL) + { + *mod_time = &(info_ptr->mod_time); + return (PNG_INFO_tIME); + } + + return (0); +} +#endif + +#ifdef PNG_tRNS_SUPPORTED +png_uint_32 PNGAPI +png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr, + png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) +{ + png_uint_32 retval = 0; + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_tRNS) != 0) + { + png_debug1(1, "in %s retrieval function", "tRNS"); + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (trans_alpha != NULL) + { + *trans_alpha = info_ptr->trans_alpha; + retval |= PNG_INFO_tRNS; + } + + if (trans_color != NULL) + *trans_color = &(info_ptr->trans_color); + } + + else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ + { + if (trans_color != NULL) + { + *trans_color = &(info_ptr->trans_color); + retval |= PNG_INFO_tRNS; + } + + if (trans_alpha != NULL) + *trans_alpha = NULL; + } + + if (num_trans != NULL) + { + *num_trans = info_ptr->num_trans; + retval |= PNG_INFO_tRNS; + } + } + + return (retval); +} +#endif + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +int PNGAPI +png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr, + png_unknown_chunkpp unknowns) +{ + if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) + { + *unknowns = info_ptr->unknown_chunks; + return info_ptr->unknown_chunks_num; + } + + return (0); +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +png_byte PNGAPI +png_get_rgb_to_gray_status (png_const_structrp png_ptr) +{ + return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); +} +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +png_voidp PNGAPI +png_get_user_chunk_ptr(png_const_structrp png_ptr) +{ + return (png_ptr ? png_ptr->user_chunk_ptr : NULL); +} +#endif + +size_t PNGAPI +png_get_compression_buffer_size(png_const_structrp png_ptr) +{ + if (png_ptr == NULL) + return 0; + +#ifdef PNG_WRITE_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) +#endif + { +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED + return png_ptr->IDAT_read_size; +#else + return PNG_IDAT_READ_SIZE; +#endif + } + +#ifdef PNG_WRITE_SUPPORTED + else + return png_ptr->zbuffer_size; +#endif +} + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +/* These functions were added to libpng 1.2.6 and were enabled + * by default in libpng-1.4.0 */ +png_uint_32 PNGAPI +png_get_user_width_max (png_const_structrp png_ptr) +{ + return (png_ptr ? png_ptr->user_width_max : 0); +} + +png_uint_32 PNGAPI +png_get_user_height_max (png_const_structrp png_ptr) +{ + return (png_ptr ? png_ptr->user_height_max : 0); +} + +/* This function was added to libpng 1.4.0 */ +png_uint_32 PNGAPI +png_get_chunk_cache_max (png_const_structrp png_ptr) +{ + return (png_ptr ? png_ptr->user_chunk_cache_max : 0); +} + +/* This function was added to libpng 1.4.1 */ +png_alloc_size_t PNGAPI +png_get_chunk_malloc_max (png_const_structrp png_ptr) +{ + return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); +} +#endif /* SET_USER_LIMITS */ + +/* These functions were added to libpng 1.4.0 */ +#ifdef PNG_IO_STATE_SUPPORTED +png_uint_32 PNGAPI +png_get_io_state (png_const_structrp png_ptr) +{ + return png_ptr->io_state; +} + +png_uint_32 PNGAPI +png_get_io_chunk_type (png_const_structrp png_ptr) +{ + return png_ptr->chunk_name; +} +#endif /* IO_STATE */ + +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +# ifdef PNG_GET_PALETTE_MAX_SUPPORTED +int PNGAPI +png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return png_ptr->num_palette_max; + + return (-1); +} +# endif +#endif + +#endif /* READ || WRITE */ diff --git a/extern/libpng/pnginfo.h b/extern/libpng/pnginfo.h new file mode 100644 index 000000000..1f98dedc4 --- /dev/null +++ b/extern/libpng/pnginfo.h @@ -0,0 +1,267 @@ + +/* pnginfo.h - header file for PNG reference library + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2013,2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + + /* png_info is a structure that holds the information in a PNG file so + * that the application can find out the characteristics of the image. + * If you are reading the file, this structure will tell you what is + * in the PNG file. If you are writing the file, fill in the information + * you want to put into the PNG file, using png_set_*() functions, then + * call png_write_info(). + * + * The names chosen should be very close to the PNG specification, so + * consult that document for information about the meaning of each field. + * + * With libpng < 0.95, it was only possible to directly set and read the + * the values in the png_info_struct, which meant that the contents and + * order of the values had to remain fixed. With libpng 0.95 and later, + * however, there are now functions that abstract the contents of + * png_info_struct from the application, so this makes it easier to use + * libpng with dynamic libraries, and even makes it possible to use + * libraries that don't have all of the libpng ancillary chunk-handing + * functionality. In libpng-1.5.0 this was moved into a separate private + * file that is not visible to applications. + * + * The following members may have allocated storage attached that should be + * cleaned up before the structure is discarded: palette, trans, text, + * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile, + * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these + * are automatically freed when the info structure is deallocated, if they were + * allocated internally by libpng. This behavior can be changed by means + * of the png_data_freer() function. + * + * More allocation details: all the chunk-reading functions that + * change these members go through the corresponding png_set_* + * functions. A function to clear these members is available: see + * png_free_data(). The png_set_* functions do not depend on being + * able to point info structure members to any of the storage they are + * passed (they make their own copies), EXCEPT that the png_set_text + * functions use the same storage passed to them in the text_ptr or + * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns + * functions do not make their own copies. + */ +#ifndef PNGINFO_H +#define PNGINFO_H + +struct png_info_def +{ + /* The following are necessary for every PNG file */ + png_uint_32 width; /* width of image in pixels (from IHDR) */ + png_uint_32 height; /* height of image in pixels (from IHDR) */ + png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ + size_t rowbytes; /* bytes needed to hold an untransformed row */ + png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */ + png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */ + png_uint_16 num_trans; /* number of transparent palette color (tRNS) */ + png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */ + png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */ + /* The following three should have been named *_method not *_type */ + png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */ + png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */ + png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ + + /* The following are set by png_set_IHDR, called from the application on + * write, but the are never actually used by the write code. + */ + png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */ + png_byte pixel_depth; /* number of bits per pixel */ + png_byte spare_byte; /* to align the data, and for future use */ + +#ifdef PNG_READ_SUPPORTED + /* This is never set during write */ + png_byte signature[8]; /* magic bytes read by libpng from start of file */ +#endif + + /* The rest of the data is optional. If you are reading, check the + * valid field to see if the information in these are valid. If you + * are writing, set the valid field to those chunks you want written, + * and initialize the appropriate fields below. + */ + +#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) + /* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are + * defined. When COLORSPACE is switched on all the colorspace-defining + * chunks should be enabled, when GAMMA is switched on all the gamma-defining + * chunks should be enabled. If this is not done it becomes possible to read + * inconsistent PNG files and assign a probably incorrect interpretation to + * the information. (In other words, by carefully choosing which chunks to + * recognize the system configuration can select an interpretation for PNG + * files containing ambiguous data and this will result in inconsistent + * behavior between different libpng builds!) + */ + png_colorspace colorspace; +#endif + +#ifdef PNG_iCCP_SUPPORTED + /* iCCP chunk data. */ + png_charp iccp_name; /* profile name */ + png_bytep iccp_profile; /* International Color Consortium profile data */ + png_uint_32 iccp_proflen; /* ICC profile data length */ +#endif + +#ifdef PNG_TEXT_SUPPORTED + /* The tEXt, and zTXt chunks contain human-readable textual data in + * uncompressed, compressed, and optionally compressed forms, respectively. + * The data in "text" is an array of pointers to uncompressed, + * null-terminated C strings. Each chunk has a keyword that describes the + * textual data contained in that chunk. Keywords are not required to be + * unique, and the text string may be empty. Any number of text chunks may + * be in an image. + */ + int num_text; /* number of comments read or comments to write */ + int max_text; /* current size of text array */ + png_textp text; /* array of comments read or comments to write */ +#endif /* TEXT */ + +#ifdef PNG_tIME_SUPPORTED + /* The tIME chunk holds the last time the displayed image data was + * modified. See the png_time struct for the contents of this struct. + */ + png_time mod_time; +#endif + +#ifdef PNG_sBIT_SUPPORTED + /* The sBIT chunk specifies the number of significant high-order bits + * in the pixel data. Values are in the range [1, bit_depth], and are + * only specified for the channels in the pixel data. The contents of + * the low-order bits is not specified. Data is valid if + * (valid & PNG_INFO_sBIT) is non-zero. + */ + png_color_8 sig_bit; /* significant bits in color channels */ +#endif + +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \ +defined(PNG_READ_BACKGROUND_SUPPORTED) + /* The tRNS chunk supplies transparency data for paletted images and + * other image types that don't need a full alpha channel. There are + * "num_trans" transparency values for a paletted image, stored in the + * same order as the palette colors, starting from index 0. Values + * for the data are in the range [0, 255], ranging from fully transparent + * to fully opaque, respectively. For non-paletted images, there is a + * single color specified that should be treated as fully transparent. + * Data is valid if (valid & PNG_INFO_tRNS) is non-zero. + */ + png_bytep trans_alpha; /* alpha values for paletted image */ + png_color_16 trans_color; /* transparent color for non-palette image */ +#endif + +#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + /* The bKGD chunk gives the suggested image background color if the + * display program does not have its own background color and the image + * is needs to composited onto a background before display. The colors + * in "background" are normally in the same color space/depth as the + * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero. + */ + png_color_16 background; +#endif + +#ifdef PNG_oFFs_SUPPORTED + /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards + * and downwards from the top-left corner of the display, page, or other + * application-specific co-ordinate space. See the PNG_OFFSET_ defines + * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero. + */ + png_int_32 x_offset; /* x offset on page */ + png_int_32 y_offset; /* y offset on page */ + png_byte offset_unit_type; /* offset units type */ +#endif + +#ifdef PNG_pHYs_SUPPORTED + /* The pHYs chunk gives the physical pixel density of the image for + * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_ + * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero. + */ + png_uint_32 x_pixels_per_unit; /* horizontal pixel density */ + png_uint_32 y_pixels_per_unit; /* vertical pixel density */ + png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */ +#endif + +#ifdef PNG_eXIf_SUPPORTED + int num_exif; /* Added at libpng-1.6.31 */ + png_bytep exif; +# ifdef PNG_READ_eXIf_SUPPORTED + png_bytep eXIf_buf; /* Added at libpng-1.6.32 */ +# endif +#endif + +#ifdef PNG_hIST_SUPPORTED + /* The hIST chunk contains the relative frequency or importance of the + * various palette entries, so that a viewer can intelligently select a + * reduced-color palette, if required. Data is an array of "num_palette" + * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST) + * is non-zero. + */ + png_uint_16p hist; +#endif + +#ifdef PNG_pCAL_SUPPORTED + /* The pCAL chunk describes a transformation between the stored pixel + * values and original physical data values used to create the image. + * The integer range [0, 2^bit_depth - 1] maps to the floating-point + * range given by [pcal_X0, pcal_X1], and are further transformed by a + * (possibly non-linear) transformation function given by "pcal_type" + * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_ + * defines below, and the PNG-Group's PNG extensions document for a + * complete description of the transformations and how they should be + * implemented, and for a description of the ASCII parameter strings. + * Data values are valid if (valid & PNG_INFO_pCAL) non-zero. + */ + png_charp pcal_purpose; /* pCAL chunk description string */ + png_int_32 pcal_X0; /* minimum value */ + png_int_32 pcal_X1; /* maximum value */ + png_charp pcal_units; /* Latin-1 string giving physical units */ + png_charpp pcal_params; /* ASCII strings containing parameter values */ + png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */ + png_byte pcal_nparams; /* number of parameters given in pcal_params */ +#endif + +/* New members added in libpng-1.0.6 */ + png_uint_32 free_me; /* flags items libpng is responsible for freeing */ + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED + /* Storage for unknown chunks that the library doesn't recognize. */ + png_unknown_chunkp unknown_chunks; + + /* The type of this field is limited by the type of + * png_struct::user_chunk_cache_max, else overflow can occur. + */ + int unknown_chunks_num; +#endif + +#ifdef PNG_sPLT_SUPPORTED + /* Data on sPLT chunks (there may be more than one). */ + png_sPLT_tp splt_palettes; + int splt_palettes_num; /* Match type returned by png_get API */ +#endif + +#ifdef PNG_sCAL_SUPPORTED + /* The sCAL chunk describes the actual physical dimensions of the + * subject matter of the graphic. The chunk contains a unit specification + * a byte value, and two ASCII strings representing floating-point + * values. The values are width and height corresponding to one pixel + * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is + * non-zero. + */ + png_byte scal_unit; /* unit of physical scale */ + png_charp scal_s_width; /* string containing height */ + png_charp scal_s_height; /* string containing width */ +#endif + +#ifdef PNG_INFO_IMAGE_SUPPORTED + /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) + non-zero */ + /* Data valid if (valid & PNG_INFO_IDAT) non-zero */ + png_bytepp row_pointers; /* the image bits */ +#endif + +}; +#endif /* PNGINFO_H */ diff --git a/extern/libpng/pnglibconf.h b/extern/libpng/pnglibconf.h new file mode 100644 index 000000000..e1e27e957 --- /dev/null +++ b/extern/libpng/pnglibconf.h @@ -0,0 +1,219 @@ +/* pnglibconf.h - library build configuration */ + +/* libpng version 1.6.37 */ + +/* Copyright (c) 2018-2019 Cosmin Truta */ +/* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson */ + +/* This code is released under the libpng license. */ +/* For conditions of distribution and use, see the disclaimer */ +/* and license in png.h */ + +/* pnglibconf.h */ +/* Machine generated file: DO NOT EDIT */ +/* Derived from: scripts/pnglibconf.dfa */ +#ifndef PNGLCONF_H +#define PNGLCONF_H +/* options */ +#define PNG_16BIT_SUPPORTED +#define PNG_ALIGNED_MEMORY_SUPPORTED +/*#undef PNG_ARM_NEON_API_SUPPORTED*/ +/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/ +#define PNG_BENIGN_ERRORS_SUPPORTED +#define PNG_BENIGN_READ_ERRORS_SUPPORTED +/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/ +#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_COLORSPACE_SUPPORTED +#define PNG_CONSOLE_IO_SUPPORTED +#define PNG_CONVERT_tIME_SUPPORTED +#define PNG_EASY_ACCESS_SUPPORTED +/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/ +#define PNG_ERROR_TEXT_SUPPORTED +#define PNG_FIXED_POINT_SUPPORTED +#define PNG_FLOATING_ARITHMETIC_SUPPORTED +#define PNG_FLOATING_POINT_SUPPORTED +#define PNG_FORMAT_AFIRST_SUPPORTED +#define PNG_FORMAT_BGR_SUPPORTED +#define PNG_GAMMA_SUPPORTED +#define PNG_GET_PALETTE_MAX_SUPPORTED +#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +#define PNG_INCH_CONVERSIONS_SUPPORTED +#define PNG_INFO_IMAGE_SUPPORTED +#define PNG_IO_STATE_SUPPORTED +#define PNG_MNG_FEATURES_SUPPORTED +#define PNG_POINTER_INDEXING_SUPPORTED +/*#undef PNG_POWERPC_VSX_API_SUPPORTED*/ +/*#undef PNG_POWERPC_VSX_CHECK_SUPPORTED*/ +#define PNG_PROGRESSIVE_READ_SUPPORTED +#define PNG_READ_16BIT_SUPPORTED +#define PNG_READ_ALPHA_MODE_SUPPORTED +#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED +#define PNG_READ_BACKGROUND_SUPPORTED +#define PNG_READ_BGR_SUPPORTED +#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_READ_COMPOSITE_NODIV_SUPPORTED +#define PNG_READ_COMPRESSED_TEXT_SUPPORTED +#define PNG_READ_EXPAND_16_SUPPORTED +#define PNG_READ_EXPAND_SUPPORTED +#define PNG_READ_FILLER_SUPPORTED +#define PNG_READ_GAMMA_SUPPORTED +#define PNG_READ_GET_PALETTE_MAX_SUPPORTED +#define PNG_READ_GRAY_TO_RGB_SUPPORTED +#define PNG_READ_INTERLACING_SUPPORTED +#define PNG_READ_INT_FUNCTIONS_SUPPORTED +#define PNG_READ_INVERT_ALPHA_SUPPORTED +#define PNG_READ_INVERT_SUPPORTED +#define PNG_READ_OPT_PLTE_SUPPORTED +#define PNG_READ_PACKSWAP_SUPPORTED +#define PNG_READ_PACK_SUPPORTED +#define PNG_READ_QUANTIZE_SUPPORTED +#define PNG_READ_RGB_TO_GRAY_SUPPORTED +#define PNG_READ_SCALE_16_TO_8_SUPPORTED +#define PNG_READ_SHIFT_SUPPORTED +#define PNG_READ_STRIP_16_TO_8_SUPPORTED +#define PNG_READ_STRIP_ALPHA_SUPPORTED +#define PNG_READ_SUPPORTED +#define PNG_READ_SWAP_ALPHA_SUPPORTED +#define PNG_READ_SWAP_SUPPORTED +#define PNG_READ_TEXT_SUPPORTED +#define PNG_READ_TRANSFORMS_SUPPORTED +#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_READ_USER_CHUNKS_SUPPORTED +#define PNG_READ_USER_TRANSFORM_SUPPORTED +#define PNG_READ_bKGD_SUPPORTED +#define PNG_READ_cHRM_SUPPORTED +#define PNG_READ_eXIf_SUPPORTED +#define PNG_READ_gAMA_SUPPORTED +#define PNG_READ_hIST_SUPPORTED +#define PNG_READ_iCCP_SUPPORTED +#define PNG_READ_iTXt_SUPPORTED +#define PNG_READ_oFFs_SUPPORTED +#define PNG_READ_pCAL_SUPPORTED +#define PNG_READ_pHYs_SUPPORTED +#define PNG_READ_sBIT_SUPPORTED +#define PNG_READ_sCAL_SUPPORTED +#define PNG_READ_sPLT_SUPPORTED +#define PNG_READ_sRGB_SUPPORTED +#define PNG_READ_tEXt_SUPPORTED +#define PNG_READ_tIME_SUPPORTED +#define PNG_READ_tRNS_SUPPORTED +#define PNG_READ_zTXt_SUPPORTED +#define PNG_SAVE_INT_32_SUPPORTED +#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_SEQUENTIAL_READ_SUPPORTED +#define PNG_SETJMP_SUPPORTED +#define PNG_SET_OPTION_SUPPORTED +#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_SET_USER_LIMITS_SUPPORTED +#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED +#define PNG_SIMPLIFIED_READ_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_SUPPORTED +#define PNG_STDIO_SUPPORTED +#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_TEXT_SUPPORTED +#define PNG_TIME_RFC1123_SUPPORTED +#define PNG_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_USER_CHUNKS_SUPPORTED +#define PNG_USER_LIMITS_SUPPORTED +#define PNG_USER_MEM_SUPPORTED +#define PNG_USER_TRANSFORM_INFO_SUPPORTED +#define PNG_USER_TRANSFORM_PTR_SUPPORTED +#define PNG_WARNINGS_SUPPORTED +#define PNG_WRITE_16BIT_SUPPORTED +#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED +#define PNG_WRITE_BGR_SUPPORTED +#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED +#define PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED +#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +#define PNG_WRITE_FILLER_SUPPORTED +#define PNG_WRITE_FILTER_SUPPORTED +#define PNG_WRITE_FLUSH_SUPPORTED +#define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED +#define PNG_WRITE_INTERLACING_SUPPORTED +#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED +#define PNG_WRITE_INVERT_ALPHA_SUPPORTED +#define PNG_WRITE_INVERT_SUPPORTED +#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED +#define PNG_WRITE_PACKSWAP_SUPPORTED +#define PNG_WRITE_PACK_SUPPORTED +#define PNG_WRITE_SHIFT_SUPPORTED +#define PNG_WRITE_SUPPORTED +#define PNG_WRITE_SWAP_ALPHA_SUPPORTED +#define PNG_WRITE_SWAP_SUPPORTED +#define PNG_WRITE_TEXT_SUPPORTED +#define PNG_WRITE_TRANSFORMS_SUPPORTED +#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_WRITE_USER_TRANSFORM_SUPPORTED +#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED +#define PNG_WRITE_bKGD_SUPPORTED +#define PNG_WRITE_cHRM_SUPPORTED +#define PNG_WRITE_eXIf_SUPPORTED +#define PNG_WRITE_gAMA_SUPPORTED +#define PNG_WRITE_hIST_SUPPORTED +#define PNG_WRITE_iCCP_SUPPORTED +#define PNG_WRITE_iTXt_SUPPORTED +#define PNG_WRITE_oFFs_SUPPORTED +#define PNG_WRITE_pCAL_SUPPORTED +#define PNG_WRITE_pHYs_SUPPORTED +#define PNG_WRITE_sBIT_SUPPORTED +#define PNG_WRITE_sCAL_SUPPORTED +#define PNG_WRITE_sPLT_SUPPORTED +#define PNG_WRITE_sRGB_SUPPORTED +#define PNG_WRITE_tEXt_SUPPORTED +#define PNG_WRITE_tIME_SUPPORTED +#define PNG_WRITE_tRNS_SUPPORTED +#define PNG_WRITE_zTXt_SUPPORTED +#define PNG_bKGD_SUPPORTED +#define PNG_cHRM_SUPPORTED +#define PNG_eXIf_SUPPORTED +#define PNG_gAMA_SUPPORTED +#define PNG_hIST_SUPPORTED +#define PNG_iCCP_SUPPORTED +#define PNG_iTXt_SUPPORTED +#define PNG_oFFs_SUPPORTED +#define PNG_pCAL_SUPPORTED +#define PNG_pHYs_SUPPORTED +#define PNG_sBIT_SUPPORTED +#define PNG_sCAL_SUPPORTED +#define PNG_sPLT_SUPPORTED +#define PNG_sRGB_SUPPORTED +#define PNG_tEXt_SUPPORTED +#define PNG_tIME_SUPPORTED +#define PNG_tRNS_SUPPORTED +#define PNG_zTXt_SUPPORTED +/* end of options */ +/* settings */ +#define PNG_API_RULE 0 +#define PNG_DEFAULT_READ_MACROS 1 +#define PNG_GAMMA_THRESHOLD_FIXED 5000 +#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE +#define PNG_INFLATE_BUF_SIZE 1024 +#define PNG_LINKAGE_API extern +#define PNG_LINKAGE_CALLBACK extern +#define PNG_LINKAGE_DATA extern +#define PNG_LINKAGE_FUNCTION extern +#define PNG_MAX_GAMMA_8 11 +#define PNG_QUANTIZE_BLUE_BITS 5 +#define PNG_QUANTIZE_GREEN_BITS 5 +#define PNG_QUANTIZE_RED_BITS 5 +#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1) +#define PNG_TEXT_Z_DEFAULT_STRATEGY 0 +#define PNG_USER_CHUNK_CACHE_MAX 1000 +#define PNG_USER_CHUNK_MALLOC_MAX 8000000 +#define PNG_USER_HEIGHT_MAX 1000000 +#define PNG_USER_WIDTH_MAX 1000000 +#define PNG_ZBUF_SIZE 8192 +#define PNG_ZLIB_VERNUM 0 /* unknown */ +#define PNG_Z_DEFAULT_COMPRESSION (-1) +#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0 +#define PNG_Z_DEFAULT_STRATEGY 1 +#define PNG_sCAL_PRECISION 5 +#define PNG_sRGB_PROFILE_CHECKS 2 +/* end of settings */ +#endif /* PNGLCONF_H */ diff --git a/extern/libpng/pngmem.c b/extern/libpng/pngmem.c new file mode 100644 index 000000000..09ed9c1c9 --- /dev/null +++ b/extern/libpng/pngmem.c @@ -0,0 +1,284 @@ + +/* pngmem.c - stub functions for memory allocation + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all memory allocation. Users who + * need special memory handling are expected to supply replacement + * functions for png_malloc() and png_free(), and to use + * png_create_read_struct_2() and png_create_write_struct_2() to + * identify the replacement functions. + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +/* Free a png_struct */ +void /* PRIVATE */ +png_destroy_png_struct(png_structrp png_ptr) +{ + if (png_ptr != NULL) + { + /* png_free might call png_error and may certainly call + * png_get_mem_ptr, so fake a temporary png_struct to support this. + */ + png_struct dummy_struct = *png_ptr; + memset(png_ptr, 0, (sizeof *png_ptr)); + png_free(&dummy_struct, png_ptr); + +# ifdef PNG_SETJMP_SUPPORTED + /* We may have a jmp_buf left to deallocate. */ + png_free_jmpbuf(&dummy_struct); +# endif + } +} + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more than 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + */ +PNG_FUNCTION(png_voidp,PNGAPI +png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; + + ret = png_malloc(png_ptr, size); + + if (ret != NULL) + memset(ret, 0, size); + + return ret; +} + +/* png_malloc_base, an internal function added at libpng 1.6.0, does the work of + * allocating memory, taking into account limits and PNG_USER_MEM_SUPPORTED. + * Checking and error handling must happen outside this routine; it returns NULL + * if the allocation cannot be done (for any reason.) + */ +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size), + PNG_ALLOCATED) +{ + /* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS + * allocators have also been removed in 1.6.0, so any 16-bit system now has + * to implement a user memory handler. This checks to be sure it isn't + * called with big numbers. + */ +#ifndef PNG_USER_MEM_SUPPORTED + PNG_UNUSED(png_ptr) +#endif + + /* Some compilers complain that this is always true. However, it + * can be false when integer overflow happens. + */ + if (size > 0 && size <= PNG_SIZE_MAX +# ifdef PNG_MAX_MALLOC_64K + && size <= 65536U +# endif + ) + { +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr != NULL && png_ptr->malloc_fn != NULL) + return png_ptr->malloc_fn(png_constcast(png_structrp,png_ptr), size); + + else +#endif + return malloc((size_t)size); /* checked for truncation above */ + } + + else + return NULL; +} + +#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\ + defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) +/* This is really here only to work round a spurious warning in GCC 4.6 and 4.7 + * that arises because of the checks in png_realloc_array that are repeated in + * png_malloc_array. + */ +static png_voidp +png_malloc_array_checked(png_const_structrp png_ptr, int nelements, + size_t element_size) +{ + png_alloc_size_t req = (png_alloc_size_t)nelements; /* known to be > 0 */ + + if (req <= PNG_SIZE_MAX/element_size) + return png_malloc_base(png_ptr, req * element_size); + + /* The failure case when the request is too large */ + return NULL; +} + +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_malloc_array,(png_const_structrp png_ptr, int nelements, + size_t element_size),PNG_ALLOCATED) +{ + if (nelements <= 0 || element_size == 0) + png_error(png_ptr, "internal error: array alloc"); + + return png_malloc_array_checked(png_ptr, nelements, element_size); +} + +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array, + int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED) +{ + /* These are internal errors: */ + if (add_elements <= 0 || element_size == 0 || old_elements < 0 || + (old_array == NULL && old_elements > 0)) + png_error(png_ptr, "internal error: array realloc"); + + /* Check for overflow on the elements count (so the caller does not have to + * check.) + */ + if (add_elements <= INT_MAX - old_elements) + { + png_voidp new_array = png_malloc_array_checked(png_ptr, + old_elements+add_elements, element_size); + + if (new_array != NULL) + { + /* Because png_malloc_array worked the size calculations below cannot + * overflow. + */ + if (old_elements > 0) + memcpy(new_array, old_array, element_size*(unsigned)old_elements); + + memset((char*)new_array + element_size*(unsigned)old_elements, 0, + element_size*(unsigned)add_elements); + + return new_array; + } + } + + return NULL; /* error */ +} +#endif /* TEXT || sPLT || STORE_UNKNOWN_CHUNKS */ + +/* Various functions that have different error handling are derived from this. + * png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate + * function png_malloc_default is also provided. + */ +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; + + if (png_ptr == NULL) + return NULL; + + ret = png_malloc_base(png_ptr, size); + + if (ret == NULL) + png_error(png_ptr, "Out of memory"); /* 'm' means png_malloc */ + + return ret; +} + +#ifdef PNG_USER_MEM_SUPPORTED +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size), + PNG_ALLOCATED PNG_DEPRECATED) +{ + png_voidp ret; + + if (png_ptr == NULL) + return NULL; + + /* Passing 'NULL' here bypasses the application provided memory handler. */ + ret = png_malloc_base(NULL/*use malloc*/, size); + + if (ret == NULL) + png_error(png_ptr, "Out of Memory"); /* 'M' means png_malloc_default */ + + return ret; +} +#endif /* USER_MEM */ + +/* This function was added at libpng version 1.2.3. The png_malloc_warn() + * function will issue a png_warning and return NULL instead of issuing a + * png_error, if it fails to allocate the requested memory. + */ +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size), + PNG_ALLOCATED) +{ + if (png_ptr != NULL) + { + png_voidp ret = png_malloc_base(png_ptr, size); + + if (ret != NULL) + return ret; + + png_warning(png_ptr, "Out of memory"); + } + + return NULL; +} + +/* Free a pointer allocated by png_malloc(). If ptr is NULL, return + * without taking any action. + */ +void PNGAPI +png_free(png_const_structrp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->free_fn != NULL) + png_ptr->free_fn(png_constcast(png_structrp,png_ptr), ptr); + + else + png_free_default(png_ptr, ptr); +} + +PNG_FUNCTION(void,PNGAPI +png_free_default,(png_const_structrp png_ptr, png_voidp ptr),PNG_DEPRECATED) +{ + if (png_ptr == NULL || ptr == NULL) + return; +#endif /* USER_MEM */ + + free(ptr); +} + +#ifdef PNG_USER_MEM_SUPPORTED +/* This function is called when the application wants to use another method + * of allocating and freeing memory. + */ +void PNGAPI +png_set_mem_fn(png_structrp png_ptr, png_voidp mem_ptr, png_malloc_ptr + malloc_fn, png_free_ptr free_fn) +{ + if (png_ptr != NULL) + { + png_ptr->mem_ptr = mem_ptr; + png_ptr->malloc_fn = malloc_fn; + png_ptr->free_fn = free_fn; + } +} + +/* This function returns a pointer to the mem_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy and png_read_destroy are called. + */ +png_voidp PNGAPI +png_get_mem_ptr(png_const_structrp png_ptr) +{ + if (png_ptr == NULL) + return NULL; + + return png_ptr->mem_ptr; +} +#endif /* USER_MEM */ +#endif /* READ || WRITE */ diff --git a/extern/libpng/pngpread.c b/extern/libpng/pngpread.c new file mode 100644 index 000000000..e283627b7 --- /dev/null +++ b/extern/libpng/pngpread.c @@ -0,0 +1,1096 @@ + +/* pngpread.c - read a png file in push mode + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + +/* Push model modes */ +#define PNG_READ_SIG_MODE 0 +#define PNG_READ_CHUNK_MODE 1 +#define PNG_READ_IDAT_MODE 2 +#define PNG_READ_tEXt_MODE 4 +#define PNG_READ_zTXt_MODE 5 +#define PNG_READ_DONE_MODE 6 +#define PNG_READ_iTXt_MODE 7 +#define PNG_ERROR_MODE 8 + +#define PNG_PUSH_SAVE_BUFFER_IF_FULL \ +if (png_ptr->push_length + 4 > png_ptr->buffer_size) \ + { png_push_save_buffer(png_ptr); return; } +#define PNG_PUSH_SAVE_BUFFER_IF_LT(N) \ +if (png_ptr->buffer_size < N) \ + { png_push_save_buffer(png_ptr); return; } + +void PNGAPI +png_process_data(png_structrp png_ptr, png_inforp info_ptr, + png_bytep buffer, size_t buffer_size) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_push_restore_buffer(png_ptr, buffer, buffer_size); + + while (png_ptr->buffer_size) + { + png_process_some_data(png_ptr, info_ptr); + } +} + +size_t PNGAPI +png_process_data_pause(png_structrp png_ptr, int save) +{ + if (png_ptr != NULL) + { + /* It's easiest for the caller if we do the save; then the caller doesn't + * have to supply the same data again: + */ + if (save != 0) + png_push_save_buffer(png_ptr); + else + { + /* This includes any pending saved bytes: */ + size_t remaining = png_ptr->buffer_size; + png_ptr->buffer_size = 0; + + /* So subtract the saved buffer size, unless all the data + * is actually 'saved', in which case we just return 0 + */ + if (png_ptr->save_buffer_size < remaining) + return remaining - png_ptr->save_buffer_size; + } + } + + return 0; +} + +png_uint_32 PNGAPI +png_process_data_skip(png_structrp png_ptr) +{ +/* TODO: Deprecate and remove this API. + * Somewhere the implementation of this seems to have been lost, + * or abandoned. It was only to support some internal back-door access + * to png_struct) in libpng-1.4.x. + */ + png_app_warning(png_ptr, +"png_process_data_skip is not implemented in any current version of libpng"); + return 0; +} + +/* What we do with the incoming data depends on what we were previously + * doing before we ran out of data... + */ +void /* PRIVATE */ +png_process_some_data(png_structrp png_ptr, png_inforp info_ptr) +{ + if (png_ptr == NULL) + return; + + switch (png_ptr->process_mode) + { + case PNG_READ_SIG_MODE: + { + png_push_read_sig(png_ptr, info_ptr); + break; + } + + case PNG_READ_CHUNK_MODE: + { + png_push_read_chunk(png_ptr, info_ptr); + break; + } + + case PNG_READ_IDAT_MODE: + { + png_push_read_IDAT(png_ptr); + break; + } + + default: + { + png_ptr->buffer_size = 0; + break; + } + } +} + +/* Read any remaining signature bytes from the stream and compare them with + * the correct PNG signature. It is possible that this routine is called + * with bytes already read from the signature, either because they have been + * checked by the calling application, or because of multiple calls to this + * routine. + */ +void /* PRIVATE */ +png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr) +{ + size_t num_checked = png_ptr->sig_bytes; /* SAFE, does not exceed 8 */ + size_t num_to_check = 8 - num_checked; + + if (png_ptr->buffer_size < num_to_check) + { + num_to_check = png_ptr->buffer_size; + } + + png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), + num_to_check); + png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check); + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + else + { + if (png_ptr->sig_bytes >= 8) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } + } +} + +void /* PRIVATE */ +png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr) +{ + png_uint_32 chunk_name; +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + int keep; /* unknown handling method */ +#endif + + /* First we make sure we have enough data for the 4-byte chunk name + * and the 4-byte chunk length before proceeding with decoding the + * chunk data. To fully decode each of these chunks, we also make + * sure we have enough data in the buffer for the 4-byte CRC at the + * end of every chunk (except IDAT, which is handled separately). + */ + if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0) + { + png_byte chunk_length[4]; + png_byte chunk_tag[4]; + + PNG_PUSH_SAVE_BUFFER_IF_LT(8) + png_push_fill_buffer(png_ptr, chunk_length, 4); + png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, chunk_tag, 4); + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); + png_check_chunk_name(png_ptr, png_ptr->chunk_name); + png_check_chunk_length(png_ptr, png_ptr->push_length); + png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; + } + + chunk_name = png_ptr->chunk_name; + + if (chunk_name == png_IDAT) + { + if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + + /* If we reach an IDAT chunk, this means we have read all of the + * header chunks, and we can start reading the image (or if this + * is called after the image has been read - we have an error). + */ + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + (png_ptr->mode & PNG_HAVE_PLTE) == 0) + png_error(png_ptr, "Missing PLTE before IDAT"); + + png_ptr->process_mode = PNG_READ_IDAT_MODE; + + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0) + if (png_ptr->push_length == 0) + return; + + png_ptr->mode |= PNG_HAVE_IDAT; + + if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) + png_benign_error(png_ptr, "Too many IDATs found"); + } + + if (chunk_name == png_IHDR) + { + if (png_ptr->push_length != 13) + png_error(png_ptr, "Invalid IHDR length"); + + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); + } + + else if (chunk_name == png_IEND) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); + + png_ptr->process_mode = PNG_READ_DONE_MODE; + png_push_have_end(png_ptr, info_ptr); + } + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep); + + if (chunk_name == png_PLTE) + png_ptr->mode |= PNG_HAVE_PLTE; + } +#endif + + else if (chunk_name == png_PLTE) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); + } + + else if (chunk_name == png_IDAT) + { + png_ptr->idat_size = png_ptr->push_length; + png_ptr->process_mode = PNG_READ_IDAT_MODE; + png_push_have_info(png_ptr, info_ptr); + png_ptr->zstream.avail_out = + (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1; + png_ptr->zstream.next_out = png_ptr->row_buf; + return; + } + +#ifdef PNG_READ_gAMA_SUPPORTED + else if (png_ptr->chunk_name == png_gAMA) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sBIT_SUPPORTED + else if (png_ptr->chunk_name == png_sBIT) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_cHRM_SUPPORTED + else if (png_ptr->chunk_name == png_cHRM) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sRGB_SUPPORTED + else if (chunk_name == png_sRGB) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_iCCP_SUPPORTED + else if (png_ptr->chunk_name == png_iCCP) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sPLT_SUPPORTED + else if (chunk_name == png_sPLT) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tRNS_SUPPORTED + else if (chunk_name == png_tRNS) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_bKGD_SUPPORTED + else if (chunk_name == png_bKGD) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_hIST_SUPPORTED + else if (chunk_name == png_hIST) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_pHYs_SUPPORTED + else if (chunk_name == png_pHYs) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_oFFs_SUPPORTED + else if (chunk_name == png_oFFs) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); + } +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED + else if (chunk_name == png_pCAL) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sCAL_SUPPORTED + else if (chunk_name == png_sCAL) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tIME_SUPPORTED + else if (chunk_name == png_tIME) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tEXt_SUPPORTED + else if (chunk_name == png_tEXt) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + else if (chunk_name == png_zTXt) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + else if (chunk_name == png_iTXt) + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); + } +#endif + + else + { + PNG_PUSH_SAVE_BUFFER_IF_FULL + png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, + PNG_HANDLE_CHUNK_AS_DEFAULT); + } + + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; +} + +void PNGCBAPI +png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, size_t length) +{ + png_bytep ptr; + + if (png_ptr == NULL) + return; + + ptr = buffer; + if (png_ptr->save_buffer_size != 0) + { + size_t save_size; + + if (length < png_ptr->save_buffer_size) + save_size = length; + + else + save_size = png_ptr->save_buffer_size; + + memcpy(ptr, png_ptr->save_buffer_ptr, save_size); + length -= save_size; + ptr += save_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + if (length != 0 && png_ptr->current_buffer_size != 0) + { + size_t save_size; + + if (length < png_ptr->current_buffer_size) + save_size = length; + + else + save_size = png_ptr->current_buffer_size; + + memcpy(ptr, png_ptr->current_buffer_ptr, save_size); + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } +} + +void /* PRIVATE */ +png_push_save_buffer(png_structrp png_ptr) +{ + if (png_ptr->save_buffer_size != 0) + { + if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) + { + size_t i, istop; + png_bytep sp; + png_bytep dp; + + istop = png_ptr->save_buffer_size; + for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; + i < istop; i++, sp++, dp++) + { + *dp = *sp; + } + } + } + if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > + png_ptr->save_buffer_max) + { + size_t new_max; + png_bytep old_buffer; + + if (png_ptr->save_buffer_size > PNG_SIZE_MAX - + (png_ptr->current_buffer_size + 256)) + { + png_error(png_ptr, "Potential overflow of save_buffer"); + } + + new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; + old_buffer = png_ptr->save_buffer; + png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, + (size_t)new_max); + + if (png_ptr->save_buffer == NULL) + { + png_free(png_ptr, old_buffer); + png_error(png_ptr, "Insufficient memory for save_buffer"); + } + + if (old_buffer) + memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); + else if (png_ptr->save_buffer_size) + png_error(png_ptr, "save_buffer error"); + png_free(png_ptr, old_buffer); + png_ptr->save_buffer_max = new_max; + } + if (png_ptr->current_buffer_size) + { + memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, + png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); + png_ptr->save_buffer_size += png_ptr->current_buffer_size; + png_ptr->current_buffer_size = 0; + } + png_ptr->save_buffer_ptr = png_ptr->save_buffer; + png_ptr->buffer_size = 0; +} + +void /* PRIVATE */ +png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer, + size_t buffer_length) +{ + png_ptr->current_buffer = buffer; + png_ptr->current_buffer_size = buffer_length; + png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; + png_ptr->current_buffer_ptr = png_ptr->current_buffer; +} + +void /* PRIVATE */ +png_push_read_IDAT(png_structrp png_ptr) +{ + if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0) + { + png_byte chunk_length[4]; + png_byte chunk_tag[4]; + + /* TODO: this code can be commoned up with the same code in push_read */ + PNG_PUSH_SAVE_BUFFER_IF_LT(8) + png_push_fill_buffer(png_ptr, chunk_length, 4); + png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, chunk_tag, 4); + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); + png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; + + if (png_ptr->chunk_name != png_IDAT) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) + png_error(png_ptr, "Not enough compressed data"); + + return; + } + + png_ptr->idat_size = png_ptr->push_length; + } + + if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0) + { + size_t save_size = png_ptr->save_buffer_size; + png_uint_32 idat_size = png_ptr->idat_size; + + /* We want the smaller of 'idat_size' and 'current_buffer_size', but they + * are of different types and we don't know which variable has the fewest + * bits. Carefully select the smaller and cast it to the type of the + * larger - this cannot overflow. Do not cast in the following test - it + * will break on either 16-bit or 64-bit platforms. + */ + if (idat_size < save_size) + save_size = (size_t)idat_size; + + else + idat_size = (png_uint_32)save_size; + + png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_ptr->idat_size -= idat_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + + if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0) + { + size_t save_size = png_ptr->current_buffer_size; + png_uint_32 idat_size = png_ptr->idat_size; + + /* We want the smaller of 'idat_size' and 'current_buffer_size', but they + * are of different types and we don't know which variable has the fewest + * bits. Carefully select the smaller and cast it to the type of the + * larger - this cannot overflow. + */ + if (idat_size < save_size) + save_size = (size_t)idat_size; + + else + idat_size = (png_uint_32)save_size; + + png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_ptr->idat_size -= idat_size; + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } + + if (png_ptr->idat_size == 0) + { + PNG_PUSH_SAVE_BUFFER_IF_LT(4) + png_crc_finish(png_ptr, 0); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->zowner = 0; + } +} + +void /* PRIVATE */ +png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer, + size_t buffer_length) +{ + /* The caller checks for a non-zero buffer length. */ + if (!(buffer_length > 0) || buffer == NULL) + png_error(png_ptr, "No IDAT data (internal error)"); + + /* This routine must process all the data it has been given + * before returning, calling the row callback as required to + * handle the uncompressed results. + */ + png_ptr->zstream.next_in = buffer; + /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */ + png_ptr->zstream.avail_in = (uInt)buffer_length; + + /* Keep going until the decompressed data is all processed + * or the stream marked as finished. + */ + while (png_ptr->zstream.avail_in > 0 && + (png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) + { + int ret; + + /* We have data for zlib, but we must check that zlib + * has someplace to put the results. It doesn't matter + * if we don't expect any results -- it may be the input + * data is just the LZ end code. + */ + if (!(png_ptr->zstream.avail_out > 0)) + { + /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */ + png_ptr->zstream.avail_out = (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1); + + png_ptr->zstream.next_out = png_ptr->row_buf; + } + + /* Using Z_SYNC_FLUSH here means that an unterminated + * LZ stream (a stream with a missing end code) can still + * be handled, otherwise (Z_NO_FLUSH) a future zlib + * implementation might defer output and therefore + * change the current behavior (see comments in inflate.c + * for why this doesn't happen at present with zlib 1.2.5). + */ + ret = PNG_INFLATE(png_ptr, Z_SYNC_FLUSH); + + /* Check for any failure before proceeding. */ + if (ret != Z_OK && ret != Z_STREAM_END) + { + /* Terminate the decompression. */ + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + png_ptr->zowner = 0; + + /* This may be a truncated stream (missing or + * damaged end code). Treat that as a warning. + */ + if (png_ptr->row_number >= png_ptr->num_rows || + png_ptr->pass > 6) + png_warning(png_ptr, "Truncated compressed data in IDAT"); + + else + { + if (ret == Z_DATA_ERROR) + png_benign_error(png_ptr, "IDAT: ADLER32 checksum mismatch"); + else + png_error(png_ptr, "Decompression error in IDAT"); + } + + /* Skip the check on unprocessed input */ + return; + } + + /* Did inflate output any data? */ + if (png_ptr->zstream.next_out != png_ptr->row_buf) + { + /* Is this unexpected data after the last row? + * If it is, artificially terminate the LZ output + * here. + */ + if (png_ptr->row_number >= png_ptr->num_rows || + png_ptr->pass > 6) + { + /* Extra data. */ + png_warning(png_ptr, "Extra compressed data in IDAT"); + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + png_ptr->zowner = 0; + + /* Do no more processing; skip the unprocessed + * input check below. + */ + return; + } + + /* Do we have a complete row? */ + if (png_ptr->zstream.avail_out == 0) + png_push_process_row(png_ptr); + } + + /* And check for the end of the stream. */ + if (ret == Z_STREAM_END) + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + } + + /* All the data should have been processed, if anything + * is left at this point we have bytes of IDAT data + * after the zlib end code. + */ + if (png_ptr->zstream.avail_in > 0) + png_warning(png_ptr, "Extra compression data in IDAT"); +} + +void /* PRIVATE */ +png_push_process_row(png_structrp png_ptr) +{ + /* 1.5.6: row_info moved out of png_struct to a local here. */ + png_row_info row_info; + + row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ + row_info.color_type = png_ptr->color_type; + row_info.bit_depth = png_ptr->bit_depth; + row_info.channels = png_ptr->channels; + row_info.pixel_depth = png_ptr->pixel_depth; + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); + + if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) + { + if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) + png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, + png_ptr->prev_row + 1, png_ptr->row_buf[0]); + else + png_error(png_ptr, "bad adaptive filter value"); + } + + /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before + * 1.5.6, while the buffer really is this big in current versions of libpng + * it may not be in the future, so this was changed just to copy the + * interlaced row count: + */ + memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED + if (png_ptr->transformations != 0) + png_do_read_transformations(png_ptr, &row_info); +#endif + + /* The transformed pixel depth should match the depth now in row_info. */ + if (png_ptr->transformed_pixel_depth == 0) + { + png_ptr->transformed_pixel_depth = row_info.pixel_depth; + if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) + png_error(png_ptr, "progressive row overflow"); + } + + else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) + png_error(png_ptr, "internal progressive row size calculation error"); + + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Expand interlaced rows to full size */ + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0) + { + if (png_ptr->pass < 6) + png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, + png_ptr->transformations); + + switch (png_ptr->pass) + { + case 0: + { + int i; + for (i = 0; i < 8 && png_ptr->pass == 0; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */ + } + + if (png_ptr->pass == 2) /* Pass 1 might be empty */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + if (png_ptr->pass == 4 && png_ptr->height <= 4) + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + if (png_ptr->pass == 6 && png_ptr->height <= 4) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + + case 1: + { + int i; + for (i = 0; i < 8 && png_ptr->pass == 1; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 2) /* Skip top 4 generated rows */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 2: + { + int i; + + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 4) /* Pass 3 might be empty */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 3: + { + int i; + + for (i = 0; i < 4 && png_ptr->pass == 3; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 4) /* Skip top two generated rows */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 4: + { + int i; + + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 6) /* Pass 5 might be empty */ + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + + case 5: + { + int i; + + for (i = 0; i < 2 && png_ptr->pass == 5; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 6) /* Skip top generated row */ + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + + default: + case 6: + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + + if (png_ptr->pass != 6) + break; + + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + } + else +#endif + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } +} + +void /* PRIVATE */ +png_read_push_finish_row(png_structrp png_ptr) +{ +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static const png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static const png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static const png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static const png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; + + /* Height of interlace block. This is not currently used - if you need + * it, uncomment it here and in png.h + static const png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; + */ +#endif + + png_ptr->row_number++; + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced != 0) + { + png_ptr->row_number = 0; + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + + do + { + png_ptr->pass++; + if ((png_ptr->pass == 1 && png_ptr->width < 5) || + (png_ptr->pass == 3 && png_ptr->width < 3) || + (png_ptr->pass == 5 && png_ptr->width < 2)) + png_ptr->pass++; + + if (png_ptr->pass > 7) + png_ptr->pass--; + + if (png_ptr->pass >= 7) + break; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + if ((png_ptr->transformations & PNG_INTERLACE) != 0) + break; + + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + + } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); + } +#endif /* READ_INTERLACING */ +} + +void /* PRIVATE */ +png_push_have_info(png_structrp png_ptr, png_inforp info_ptr) +{ + if (png_ptr->info_fn != NULL) + (*(png_ptr->info_fn))(png_ptr, info_ptr); +} + +void /* PRIVATE */ +png_push_have_end(png_structrp png_ptr, png_inforp info_ptr) +{ + if (png_ptr->end_fn != NULL) + (*(png_ptr->end_fn))(png_ptr, info_ptr); +} + +void /* PRIVATE */ +png_push_have_row(png_structrp png_ptr, png_bytep row) +{ + if (png_ptr->row_fn != NULL) + (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, + (int)png_ptr->pass); +} + +#ifdef PNG_READ_INTERLACING_SUPPORTED +void PNGAPI +png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row, + png_const_bytep new_row) +{ + if (png_ptr == NULL) + return; + + /* new_row is a flag here - if it is NULL then the app callback was called + * from an empty row (see the calls to png_struct::row_fn below), otherwise + * it must be png_ptr->row_buf+1 + */ + if (new_row != NULL) + png_combine_row(png_ptr, old_row, 1/*blocky display*/); +} +#endif /* READ_INTERLACING */ + +void PNGAPI +png_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr, + png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, + png_progressive_end_ptr end_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->info_fn = info_fn; + png_ptr->row_fn = row_fn; + png_ptr->end_fn = end_fn; + + png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); +} + +png_voidp PNGAPI +png_get_progressive_ptr(png_const_structrp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + + return png_ptr->io_ptr; +} +#endif /* PROGRESSIVE_READ */ diff --git a/extern/libpng/pngpriv.h b/extern/libpng/pngpriv.h new file mode 100644 index 000000000..675ede327 --- /dev/null +++ b/extern/libpng/pngpriv.h @@ -0,0 +1,2157 @@ + +/* pngpriv.h - private declarations for use inside libpng + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* The symbols declared in this file (including the functions declared + * as extern) are PRIVATE. They are not part of the libpng public + * interface, and are not recommended for use by regular applications. + * Some of them may become public in the future; others may stay private, + * change in an incompatible way, or even disappear. + * Although the libpng users are not forbidden to include this header, + * they should be well aware of the issues that may arise from doing so. + */ + +#ifndef PNGPRIV_H +#define PNGPRIV_H + +/* Feature Test Macros. The following are defined here to ensure that correctly + * implemented libraries reveal the APIs libpng needs to build and hide those + * that are not needed and potentially damaging to the compilation. + * + * Feature Test Macros must be defined before any system header is included (see + * POSIX 1003.1 2.8.2 "POSIX Symbols." + * + * These macros only have an effect if the operating system supports either + * POSIX 1003.1 or C99, or both. On other operating systems (particularly + * Windows/Visual Studio) there is no effect; the OS specific tests below are + * still required (as of 2011-05-02.) + */ +#ifndef _POSIX_SOURCE +# define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */ +#endif + +#ifndef PNG_VERSION_INFO_ONLY +/* Standard library headers not required by png.h: */ +# include +# include +#endif + +#define PNGLIB_BUILD /*libpng is being built, not used*/ + +/* If HAVE_CONFIG_H is defined during the build then the build system must + * provide an appropriate "config.h" file on the include path. The header file + * must provide definitions as required below (search for "HAVE_CONFIG_H"); + * see configure.ac for more details of the requirements. The macro + * "PNG_NO_CONFIG_H" is provided for maintainers to test for dependencies on + * 'configure'; define this macro to prevent the configure build including the + * configure generated config.h. Libpng is expected to compile without *any* + * special build system support on a reasonably ANSI-C compliant system. + */ +#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H) +# include + + /* Pick up the definition of 'restrict' from config.h if it was read: */ +# define PNG_RESTRICT restrict +#endif + +/* To support symbol prefixing it is necessary to know *before* including png.h + * whether the fixed point (and maybe other) APIs are exported, because if they + * are not internal definitions may be required. This is handled below just + * before png.h is included, but load the configuration now if it is available. + */ +#ifndef PNGLCONF_H +# include "pnglibconf.h" +#endif + +/* Local renames may change non-exported API functions from png.h */ +#if defined(PNG_PREFIX) && !defined(PNGPREFIX_H) +# include "pngprefix.h" +#endif + +#ifdef PNG_USER_CONFIG +# include "pngusr.h" + /* These should have been defined in pngusr.h */ +# ifndef PNG_USER_PRIVATEBUILD +# define PNG_USER_PRIVATEBUILD "Custom libpng build" +# endif +# ifndef PNG_USER_DLLFNAME_POSTFIX +# define PNG_USER_DLLFNAME_POSTFIX "Cb" +# endif +#endif + +/* Compile time options. + * ===================== + * In a multi-arch build the compiler may compile the code several times for the + * same object module, producing different binaries for different architectures. + * When this happens configure-time setting of the target host options cannot be + * done and this interferes with the handling of the ARM NEON optimizations, and + * possibly other similar optimizations. Put additional tests here; in general + * this is needed when the same option can be changed at both compile time and + * run time depending on the target OS (i.e. iOS vs Android.) + * + * NOTE: symbol prefixing does not pass $(CFLAGS) to the preprocessor, because + * this is not possible with certain compilers (Oracle SUN OS CC), as a result + * it is necessary to ensure that all extern functions that *might* be used + * regardless of $(CFLAGS) get declared in this file. The test on __ARM_NEON__ + * below is one example of this behavior because it is controlled by the + * presence or not of -mfpu=neon on the GCC command line, it is possible to do + * this in $(CC), e.g. "CC=gcc -mfpu=neon", but people who build libpng rarely + * do this. + */ +#ifndef PNG_ARM_NEON_OPT + /* ARM NEON optimizations are being controlled by the compiler settings, + * typically the target FPU. If the FPU has been set to NEON (-mfpu=neon + * with GCC) then the compiler will define __ARM_NEON__ and we can rely + * unconditionally on NEON instructions not crashing, otherwise we must + * disable use of NEON instructions. + * + * NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they + * can only be turned on automatically if that is supported too. If + * PNG_ARM_NEON_OPT is set in CPPFLAGS (to >0) then arm/arm_init.c will fail + * to compile with an appropriate #error if ALIGNED_MEMORY has been turned + * off. + * + * Note that gcc-4.9 defines __ARM_NEON instead of the deprecated + * __ARM_NEON__, so we check both variants. + * + * To disable ARM_NEON optimizations entirely, and skip compiling the + * associated assembler code, pass --enable-arm-neon=no to configure + * or put -DPNG_ARM_NEON_OPT=0 in CPPFLAGS. + */ +# if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \ + defined(PNG_ALIGNED_MEMORY_SUPPORTED) +# define PNG_ARM_NEON_OPT 2 +# else +# define PNG_ARM_NEON_OPT 0 +# endif +#endif + +#if PNG_ARM_NEON_OPT > 0 + /* NEON optimizations are to be at least considered by libpng, so enable the + * callbacks to do this. + */ +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon + + /* By default the 'intrinsics' code in arm/filter_neon_intrinsics.c is used + * if possible - if __ARM_NEON__ is set and the compiler version is not known + * to be broken. This is controlled by PNG_ARM_NEON_IMPLEMENTATION which can + * be: + * + * 1 The intrinsics code (the default with __ARM_NEON__) + * 2 The hand coded assembler (the default without __ARM_NEON__) + * + * It is possible to set PNG_ARM_NEON_IMPLEMENTATION in CPPFLAGS, however + * this is *NOT* supported and may cease to work even after a minor revision + * to libpng. It *is* valid to do this for testing purposes, e.g. speed + * testing or a new compiler, but the results should be communicated to the + * libpng implementation list for incorporation in the next minor release. + */ +# ifndef PNG_ARM_NEON_IMPLEMENTATION +# if defined(__ARM_NEON__) || defined(__ARM_NEON) +# if defined(__clang__) + /* At present it is unknown by the libpng developers which versions + * of clang support the intrinsics, however some or perhaps all + * versions do not work with the assembler so this may be + * irrelevant, so just use the default (do nothing here.) + */ +# elif defined(__GNUC__) + /* GCC 4.5.4 NEON support is known to be broken. 4.6.3 is known to + * work, so if this *is* GCC, or G++, look for a version >4.5 + */ +# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6) +# define PNG_ARM_NEON_IMPLEMENTATION 2 +# endif /* no GNUC support */ +# endif /* __GNUC__ */ +# else /* !defined __ARM_NEON__ */ + /* The 'intrinsics' code simply won't compile without this -mfpu=neon: + */ +# if !defined(__aarch64__) + /* The assembler code currently does not work on ARM64 */ +# define PNG_ARM_NEON_IMPLEMENTATION 2 +# endif /* __aarch64__ */ +# endif /* __ARM_NEON__ */ +# endif /* !PNG_ARM_NEON_IMPLEMENTATION */ + +# ifndef PNG_ARM_NEON_IMPLEMENTATION + /* Use the intrinsics code by default. */ +# define PNG_ARM_NEON_IMPLEMENTATION 1 +# endif +#endif /* PNG_ARM_NEON_OPT > 0 */ + +#ifndef PNG_MIPS_MSA_OPT +# if defined(__mips_msa) && (__mips_isa_rev >= 5) && defined(PNG_ALIGNED_MEMORY_SUPPORTED) +# define PNG_MIPS_MSA_OPT 2 +# else +# define PNG_MIPS_MSA_OPT 0 +# endif +#endif + +#ifndef PNG_POWERPC_VSX_OPT +# if defined(__PPC64__) && defined(__ALTIVEC__) && defined(__VSX__) +# define PNG_POWERPC_VSX_OPT 2 +# else +# define PNG_POWERPC_VSX_OPT 0 +# endif +#endif + +#ifndef PNG_INTEL_SSE_OPT +# ifdef PNG_INTEL_SSE + /* Only check for SSE if the build configuration has been modified to + * enable SSE optimizations. This means that these optimizations will + * be off by default. See contrib/intel for more details. + */ +# if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \ + defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ + (defined(_M_IX86_FP) && _M_IX86_FP >= 2) +# define PNG_INTEL_SSE_OPT 1 +# else +# define PNG_INTEL_SSE_OPT 0 +# endif +# else +# define PNG_INTEL_SSE_OPT 0 +# endif +#endif + +#if PNG_INTEL_SSE_OPT > 0 +# ifndef PNG_INTEL_SSE_IMPLEMENTATION +# if defined(__SSE4_1__) || defined(__AVX__) + /* We are not actually using AVX, but checking for AVX is the best + way we can detect SSE4.1 and SSSE3 on MSVC. + */ +# define PNG_INTEL_SSE_IMPLEMENTATION 3 +# elif defined(__SSSE3__) +# define PNG_INTEL_SSE_IMPLEMENTATION 2 +# elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ + (defined(_M_IX86_FP) && _M_IX86_FP >= 2) +# define PNG_INTEL_SSE_IMPLEMENTATION 1 +# else +# define PNG_INTEL_SSE_IMPLEMENTATION 0 +# endif +# endif + +# if PNG_INTEL_SSE_IMPLEMENTATION > 0 +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2 +# endif +#else +# define PNG_INTEL_SSE_IMPLEMENTATION 0 +#endif + +#if PNG_MIPS_MSA_OPT > 0 +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_msa +# ifndef PNG_MIPS_MSA_IMPLEMENTATION +# if defined(__mips_msa) +# if defined(__clang__) +# elif defined(__GNUC__) +# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7) +# define PNG_MIPS_MSA_IMPLEMENTATION 2 +# endif /* no GNUC support */ +# endif /* __GNUC__ */ +# else /* !defined __mips_msa */ +# define PNG_MIPS_MSA_IMPLEMENTATION 2 +# endif /* __mips_msa */ +# endif /* !PNG_MIPS_MSA_IMPLEMENTATION */ + +# ifndef PNG_MIPS_MSA_IMPLEMENTATION +# define PNG_MIPS_MSA_IMPLEMENTATION 1 +# endif +#endif /* PNG_MIPS_MSA_OPT > 0 */ + +#if PNG_POWERPC_VSX_OPT > 0 +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_vsx +# define PNG_POWERPC_VSX_IMPLEMENTATION 1 +#endif + + +/* Is this a build of a DLL where compilation of the object modules requires + * different preprocessor settings to those required for a simple library? If + * so PNG_BUILD_DLL must be set. + * + * If libpng is used inside a DLL but that DLL does not export the libpng APIs + * PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a + * static library of libpng then link the DLL against that. + */ +#ifndef PNG_BUILD_DLL +# ifdef DLL_EXPORT + /* This is set by libtool when files are compiled for a DLL; libtool + * always compiles twice, even on systems where it isn't necessary. Set + * PNG_BUILD_DLL in case it is necessary: + */ +# define PNG_BUILD_DLL +# else +# ifdef _WINDLL + /* This is set by the Microsoft Visual Studio IDE in projects that + * build a DLL. It can't easily be removed from those projects (it + * isn't visible in the Visual Studio UI) so it is a fairly reliable + * indication that PNG_IMPEXP needs to be set to the DLL export + * attributes. + */ +# define PNG_BUILD_DLL +# else +# ifdef __DLL__ + /* This is set by the Borland C system when compiling for a DLL + * (as above.) + */ +# define PNG_BUILD_DLL +# else + /* Add additional compiler cases here. */ +# endif +# endif +# endif +#endif /* Setting PNG_BUILD_DLL if required */ + +/* See pngconf.h for more details: the builder of the library may set this on + * the command line to the right thing for the specific compilation system or it + * may be automagically set above (at present we know of no system where it does + * need to be set on the command line.) + * + * PNG_IMPEXP must be set here when building the library to prevent pngconf.h + * setting it to the "import" setting for a DLL build. + */ +#ifndef PNG_IMPEXP +# ifdef PNG_BUILD_DLL +# define PNG_IMPEXP PNG_DLL_EXPORT +# else + /* Not building a DLL, or the DLL doesn't require specific export + * definitions. + */ +# define PNG_IMPEXP +# endif +#endif + +/* No warnings for private or deprecated functions in the build: */ +#ifndef PNG_DEPRECATED +# define PNG_DEPRECATED +#endif +#ifndef PNG_PRIVATE +# define PNG_PRIVATE +#endif + +/* Symbol preprocessing support. + * + * To enable listing global, but internal, symbols the following macros should + * always be used to declare an extern data or function object in this file. + */ +#ifndef PNG_INTERNAL_DATA +# define PNG_INTERNAL_DATA(type, name, array) PNG_LINKAGE_DATA type name array +#endif + +#ifndef PNG_INTERNAL_FUNCTION +# define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\ + PNG_LINKAGE_FUNCTION PNG_FUNCTION(type, name, args, PNG_EMPTY attributes) +#endif + +#ifndef PNG_INTERNAL_CALLBACK +# define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\ + PNG_LINKAGE_CALLBACK PNG_FUNCTION(type, (PNGCBAPI name), args,\ + PNG_EMPTY attributes) +#endif + +/* If floating or fixed point APIs are disabled they may still be compiled + * internally. To handle this make sure they are declared as the appropriate + * internal extern function (otherwise the symbol prefixing stuff won't work and + * the functions will be used without definitions.) + * + * NOTE: although all the API functions are declared here they are not all + * actually built! Because the declarations are still made it is necessary to + * fake out types that they depend on. + */ +#ifndef PNG_FP_EXPORT +# ifndef PNG_FLOATING_POINT_SUPPORTED +# define PNG_FP_EXPORT(ordinal, type, name, args)\ + PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY); +# ifndef PNG_VERSION_INFO_ONLY + typedef struct png_incomplete png_double; + typedef png_double* png_doublep; + typedef const png_double* png_const_doublep; + typedef png_double** png_doublepp; +# endif +# endif +#endif +#ifndef PNG_FIXED_EXPORT +# ifndef PNG_FIXED_POINT_SUPPORTED +# define PNG_FIXED_EXPORT(ordinal, type, name, args)\ + PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY); +# endif +#endif + +#include "png.h" + +/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */ +#ifndef PNG_DLL_EXPORT +# define PNG_DLL_EXPORT +#endif + +/* This is a global switch to set the compilation for an installed system + * (a release build). It can be set for testing debug builds to ensure that + * they will compile when the build type is switched to RC or STABLE, the + * default is just to use PNG_LIBPNG_BUILD_BASE_TYPE. Set this in CPPFLAGS + * with either: + * + * -DPNG_RELEASE_BUILD Turns on the release compile path + * -DPNG_RELEASE_BUILD=0 Turns it off + * or in your pngusr.h with + * #define PNG_RELEASE_BUILD=1 Turns on the release compile path + * #define PNG_RELEASE_BUILD=0 Turns it off + */ +#ifndef PNG_RELEASE_BUILD +# define PNG_RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC) +#endif + +/* SECURITY and SAFETY: + * + * libpng is built with support for internal limits on image dimensions and + * memory usage. These are documented in scripts/pnglibconf.dfa of the + * source and recorded in the machine generated header file pnglibconf.h. + */ + +/* If you are running on a machine where you cannot allocate more + * than 64K of memory at once, uncomment this. While libpng will not + * normally need that much memory in a chunk (unless you load up a very + * large file), zlib needs to know how big of a chunk it can use, and + * libpng thus makes sure to check any memory allocation to verify it + * will fit into memory. + * + * zlib provides 'MAXSEG_64K' which, if defined, indicates the + * same limit and pngconf.h (already included) sets the limit + * if certain operating systems are detected. + */ +#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) +# define PNG_MAX_MALLOC_64K +#endif + +#ifndef PNG_UNUSED +/* Unused formal parameter warnings are silenced using the following macro + * which is expected to have no bad effects on performance (optimizing + * compilers will probably remove it entirely). Note that if you replace + * it with something other than whitespace, you must include the terminating + * semicolon. + */ +# define PNG_UNUSED(param) (void)param; +#endif + +/* Just a little check that someone hasn't tried to define something + * contradictory. + */ +#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K) +# undef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 65536L +#endif + +/* If warnings or errors are turned off the code is disabled or redirected here. + * From 1.5.4 functions have been added to allow very limited formatting of + * error and warning messages - this code will also be disabled here. + */ +#ifdef PNG_WARNINGS_SUPPORTED +# define PNG_WARNING_PARAMETERS(p) png_warning_parameters p; +#else +# define png_warning_parameter(p,number,string) ((void)0) +# define png_warning_parameter_unsigned(p,number,format,value) ((void)0) +# define png_warning_parameter_signed(p,number,format,value) ((void)0) +# define png_formatted_warning(pp,p,message) ((void)(pp)) +# define PNG_WARNING_PARAMETERS(p) +#endif +#ifndef PNG_ERROR_TEXT_SUPPORTED +# define png_fixed_error(s1,s2) png_err(s1) +#endif + +/* Some fixed point APIs are still required even if not exported because + * they get used by the corresponding floating point APIs. This magic + * deals with this: + */ +#ifdef PNG_FIXED_POINT_SUPPORTED +# define PNGFAPI PNGAPI +#else +# define PNGFAPI /* PRIVATE */ +#endif + +#ifndef PNG_VERSION_INFO_ONLY +/* Other defines specific to compilers can go here. Try to keep + * them inside an appropriate ifdef/endif pair for portability. + */ + +/* C allows up-casts from (void*) to any pointer and (const void*) to any + * pointer to a const object. C++ regards this as a type error and requires an + * explicit, static, cast and provides the static_cast<> rune to ensure that + * const is not cast away. + */ +#ifdef __cplusplus +# define png_voidcast(type, value) static_cast(value) +# define png_constcast(type, value) const_cast(value) +# define png_aligncast(type, value) \ + static_cast(static_cast(value)) +# define png_aligncastconst(type, value) \ + static_cast(static_cast(value)) +#else +# define png_voidcast(type, value) (value) +# ifdef _WIN64 +# ifdef __GNUC__ + typedef unsigned long long png_ptruint; +# else + typedef unsigned __int64 png_ptruint; +# endif +# else + typedef unsigned long png_ptruint; +# endif +# define png_constcast(type, value) ((type)(png_ptruint)(const void*)(value)) +# define png_aligncast(type, value) ((void*)(value)) +# define png_aligncastconst(type, value) ((const void*)(value)) +#endif /* __cplusplus */ + +#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\ + defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) + /* png.c requires the following ANSI-C constants if the conversion of + * floating point to ASCII is implemented therein: + * + * DBL_DIG Maximum number of decimal digits (can be set to any constant) + * DBL_MIN Smallest normalized fp number (can be set to an arbitrary value) + * DBL_MAX Maximum floating point number (can be set to an arbitrary value) + */ +# include + +# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ + defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) + /* We need to check that hasn't already been included earlier + * as it seems it doesn't agree with , yet we should really use + * if possible. + */ +# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) +# include +# endif +# else +# include +# endif +# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) + /* Amiga SAS/C: We must include builtin FPU functions when compiling using + * MATH=68881 + */ +# include +# endif +#endif + +/* This provides the non-ANSI (far) memory allocation routines. */ +#if defined(__TURBOC__) && defined(__MSDOS__) +# include +# include +#endif + +#if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \ + defined(_WIN32) || defined(__WIN32__) +# include /* defines _WINDOWS_ macro */ +#endif +#endif /* PNG_VERSION_INFO_ONLY */ + +/* Moved here around 1.5.0beta36 from pngconf.h */ +/* Users may want to use these so they are not private. Any library + * functions that are passed far data must be model-independent. + */ + +/* Memory model/platform independent fns */ +#ifndef PNG_ABORT +# ifdef _WINDOWS_ +# define PNG_ABORT() ExitProcess(0) +# else +# define PNG_ABORT() abort() +# endif +#endif + +/* These macros may need to be architecture dependent. */ +#define PNG_ALIGN_NONE 0 /* do not use data alignment */ +#define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */ +#ifdef offsetof +# define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */ +#else +# define PNG_ALIGN_OFFSET -1 /* prevent the use of this */ +#endif +#define PNG_ALIGN_SIZE 3 /* use sizeof to determine alignment */ + +#ifndef PNG_ALIGN_TYPE + /* Default to using aligned access optimizations and requiring alignment to a + * multiple of the data type size. Override in a compiler specific fashion + * if necessary by inserting tests here: + */ +# define PNG_ALIGN_TYPE PNG_ALIGN_SIZE +#endif + +#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE + /* This is used because in some compiler implementations non-aligned + * structure members are supported, so the offsetof approach below fails. + * Set PNG_ALIGN_SIZE=0 for compiler combinations where unaligned access + * is good for performance. Do not do this unless you have tested the result + * and understand it. + */ +# define png_alignof(type) (sizeof (type)) +#else +# if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET +# define png_alignof(type) offsetof(struct{char c; type t;}, t) +# else +# if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS +# define png_alignof(type) (1) +# endif + /* Else leave png_alignof undefined to prevent use thereof */ +# endif +#endif + +/* This implicitly assumes alignment is always to a power of 2. */ +#ifdef png_alignof +# define png_isaligned(ptr, type)\ + (((type)((const char*)ptr-(const char*)0) & \ + (type)(png_alignof(type)-1)) == 0) +#else +# define png_isaligned(ptr, type) 0 +#endif + +/* End of memory model/platform independent support */ +/* End of 1.5.0beta36 move from pngconf.h */ + +/* CONSTANTS and UTILITY MACROS + * These are used internally by libpng and not exposed in the API + */ + +/* Various modes of operation. Note that after an init, mode is set to + * zero automatically when the structure is created. Three of these + * are defined in png.h because they need to be visible to applications + * that call png_set_unknown_chunk(). + */ +/* #define PNG_HAVE_IHDR 0x01U (defined in png.h) */ +/* #define PNG_HAVE_PLTE 0x02U (defined in png.h) */ +#define PNG_HAVE_IDAT 0x04U +/* #define PNG_AFTER_IDAT 0x08U (defined in png.h) */ +#define PNG_HAVE_IEND 0x10U + /* 0x20U (unused) */ + /* 0x40U (unused) */ + /* 0x80U (unused) */ +#define PNG_HAVE_CHUNK_HEADER 0x100U +#define PNG_WROTE_tIME 0x200U +#define PNG_WROTE_INFO_BEFORE_PLTE 0x400U +#define PNG_BACKGROUND_IS_GRAY 0x800U +#define PNG_HAVE_PNG_SIGNATURE 0x1000U +#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */ + /* 0x4000U (unused) */ +#define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */ + +/* Flags for the transformations the PNG library does on the image data */ +#define PNG_BGR 0x0001U +#define PNG_INTERLACE 0x0002U +#define PNG_PACK 0x0004U +#define PNG_SHIFT 0x0008U +#define PNG_SWAP_BYTES 0x0010U +#define PNG_INVERT_MONO 0x0020U +#define PNG_QUANTIZE 0x0040U +#define PNG_COMPOSE 0x0080U /* Was PNG_BACKGROUND */ +#define PNG_BACKGROUND_EXPAND 0x0100U +#define PNG_EXPAND_16 0x0200U /* Added to libpng 1.5.2 */ +#define PNG_16_TO_8 0x0400U /* Becomes 'chop' in 1.5.4 */ +#define PNG_RGBA 0x0800U +#define PNG_EXPAND 0x1000U +#define PNG_GAMMA 0x2000U +#define PNG_GRAY_TO_RGB 0x4000U +#define PNG_FILLER 0x8000U +#define PNG_PACKSWAP 0x10000U +#define PNG_SWAP_ALPHA 0x20000U +#define PNG_STRIP_ALPHA 0x40000U +#define PNG_INVERT_ALPHA 0x80000U +#define PNG_USER_TRANSFORM 0x100000U +#define PNG_RGB_TO_GRAY_ERR 0x200000U +#define PNG_RGB_TO_GRAY_WARN 0x400000U +#define PNG_RGB_TO_GRAY 0x600000U /* two bits, RGB_TO_GRAY_ERR|WARN */ +#define PNG_ENCODE_ALPHA 0x800000U /* Added to libpng-1.5.4 */ +#define PNG_ADD_ALPHA 0x1000000U /* Added to libpng-1.2.7 */ +#define PNG_EXPAND_tRNS 0x2000000U /* Added to libpng-1.2.9 */ +#define PNG_SCALE_16_TO_8 0x4000000U /* Added to libpng-1.5.4 */ + /* 0x8000000U unused */ + /* 0x10000000U unused */ + /* 0x20000000U unused */ + /* 0x40000000U unused */ +/* Flags for png_create_struct */ +#define PNG_STRUCT_PNG 0x0001U +#define PNG_STRUCT_INFO 0x0002U + +/* Flags for the png_ptr->flags rather than declaring a byte for each one */ +#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001U +#define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002U /* Added to libpng-1.6.0 */ + /* 0x0004U unused */ +#define PNG_FLAG_ZSTREAM_ENDED 0x0008U /* Added to libpng-1.6.0 */ + /* 0x0010U unused */ + /* 0x0020U unused */ +#define PNG_FLAG_ROW_INIT 0x0040U +#define PNG_FLAG_FILLER_AFTER 0x0080U +#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100U +#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200U +#define PNG_FLAG_CRC_CRITICAL_USE 0x0400U +#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800U +#define PNG_FLAG_ASSUME_sRGB 0x1000U /* Added to libpng-1.5.4 */ +#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000U /* Added to libpng-1.5.4 */ +#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000U /* Added to libpng-1.5.4 */ +/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000U */ +/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000U */ +#define PNG_FLAG_LIBRARY_MISMATCH 0x20000U +#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000U +#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000U +#define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000U /* Added to libpng-1.4.0 */ +#define PNG_FLAG_APP_WARNINGS_WARN 0x200000U /* Added to libpng-1.6.0 */ +#define PNG_FLAG_APP_ERRORS_WARN 0x400000U /* Added to libpng-1.6.0 */ + /* 0x800000U unused */ + /* 0x1000000U unused */ + /* 0x2000000U unused */ + /* 0x4000000U unused */ + /* 0x8000000U unused */ + /* 0x10000000U unused */ + /* 0x20000000U unused */ + /* 0x40000000U unused */ + +#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ + PNG_FLAG_CRC_ANCILLARY_NOWARN) + +#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ + PNG_FLAG_CRC_CRITICAL_IGNORE) + +#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ + PNG_FLAG_CRC_CRITICAL_MASK) + +/* Save typing and make code easier to understand */ + +#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ + abs((int)((c1).green) - (int)((c2).green)) + \ + abs((int)((c1).blue) - (int)((c2).blue))) + +/* Added to libpng-1.6.0: scale a 16-bit value in the range 0..65535 to 0..255 + * by dividing by 257 *with rounding*. This macro is exact for the given range. + * See the discourse in pngrtran.c png_do_scale_16_to_8. The values in the + * macro were established by experiment (modifying the added value). The macro + * has a second variant that takes a value already scaled by 255 and divides by + * 65535 - this has a maximum error of .502. Over the range 0..65535*65535 it + * only gives off-by-one errors and only for 0.5% (1 in 200) of the values. + */ +#define PNG_DIV65535(v24) (((v24) + 32895) >> 16) +#define PNG_DIV257(v16) PNG_DIV65535((png_uint_32)(v16) * 255) + +/* Added to libpng-1.2.6 JB */ +#define PNG_ROWBYTES(pixel_bits, width) \ + ((pixel_bits) >= 8 ? \ + ((size_t)(width) * (((size_t)(pixel_bits)) >> 3)) : \ + (( ((size_t)(width) * ((size_t)(pixel_bits))) + 7) >> 3) ) + +/* This returns the number of trailing bits in the last byte of a row, 0 if the + * last byte is completely full of pixels. It is, in principle, (pixel_bits x + * width) % 8, but that would overflow for large 'width'. The second macro is + * the same except that it returns the number of unused bits in the last byte; + * (8-TRAILBITS), but 0 when TRAILBITS is 0. + * + * NOTE: these macros are intended to be self-evidently correct and never + * overflow on the assumption that pixel_bits is in the range 0..255. The + * arguments are evaluated only once and they can be signed (e.g. as a result of + * the integral promotions). The result of the expression always has type + * (png_uint_32), however the compiler always knows it is in the range 0..7. + */ +#define PNG_TRAILBITS(pixel_bits, width) \ + (((pixel_bits) * ((width) % (png_uint_32)8)) % 8) + +#define PNG_PADBITS(pixel_bits, width) \ + ((8 - PNG_TRAILBITS(pixel_bits, width)) % 8) + +/* PNG_OUT_OF_RANGE returns true if value is outside the range + * ideal-delta..ideal+delta. Each argument is evaluated twice. + * "ideal" and "delta" should be constants, normally simple + * integers, "value" a variable. Added to libpng-1.2.6 JB + */ +#define PNG_OUT_OF_RANGE(value, ideal, delta) \ + ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) ) + +/* Conversions between fixed and floating point, only defined if + * required (to make sure the code doesn't accidentally use float + * when it is supposedly disabled.) + */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +/* The floating point conversion can't overflow, though it can and + * does lose accuracy relative to the original fixed point value. + * In practice this doesn't matter because png_fixed_point only + * stores numbers with very low precision. The png_ptr and s + * arguments are unused by default but are there in case error + * checking becomes a requirement. + */ +#define png_float(png_ptr, fixed, s) (.00001 * (fixed)) + +/* The fixed point conversion performs range checking and evaluates + * its argument multiple times, so must be used with care. The + * range checking uses the PNG specification values for a signed + * 32-bit fixed point value except that the values are deliberately + * rounded-to-zero to an integral value - 21474 (21474.83 is roughly + * (2^31-1) * 100000). 's' is a string that describes the value being + * converted. + * + * NOTE: this macro will raise a png_error if the range check fails, + * therefore it is normally only appropriate to use this on values + * that come from API calls or other sources where an out of range + * error indicates a programming error, not a data error! + * + * NOTE: by default this is off - the macro is not used - because the + * function call saves a lot of code. + */ +#ifdef PNG_FIXED_POINT_MACRO_SUPPORTED +#define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\ + ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0)) +#endif +/* else the corresponding function is defined below, inside the scope of the + * cplusplus test. + */ +#endif + +/* Constants for known chunk types. If you need to add a chunk, define the name + * here. For historical reasons these constants have the form png_; i.e. + * the prefix is lower case. Please use decimal values as the parameters to + * match the ISO PNG specification and to avoid relying on the C locale + * interpretation of character values. + * + * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values + * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string + * to be generated if required. + * + * PNG_32b correctly produces a value shifted by up to 24 bits, even on + * architectures where (int) is only 16 bits. + */ +#define PNG_32b(b,s) ((png_uint_32)(b) << (s)) +#define PNG_U32(b1,b2,b3,b4) \ + (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0)) + +/* Constants for known chunk types. + * + * MAINTAINERS: If you need to add a chunk, define the name here. + * For historical reasons these constants have the form png_; i.e. + * the prefix is lower case. Please use decimal values as the parameters to + * match the ISO PNG specification and to avoid relying on the C locale + * interpretation of character values. Please keep the list sorted. + * + * Notice that PNG_U32 is used to define a 32-bit value for the 4 byte chunk + * type. In fact the specification does not express chunk types this way, + * however using a 32-bit value means that the chunk type can be read from the + * stream using exactly the same code as used for a 32-bit unsigned value and + * can be examined far more efficiently (using one arithmetic compare). + * + * Prior to 1.5.6 the chunk type constants were expressed as C strings. The + * libpng API still uses strings for 'unknown' chunks and a macro, + * PNG_STRING_FROM_CHUNK, allows a string to be generated if required. Notice + * that for portable code numeric values must still be used; the string "IHDR" + * is not portable and neither is PNG_U32('I', 'H', 'D', 'R'). + * + * In 1.7.0 the definitions will be made public in png.h to avoid having to + * duplicate the same definitions in application code. + */ +#define png_IDAT PNG_U32( 73, 68, 65, 84) +#define png_IEND PNG_U32( 73, 69, 78, 68) +#define png_IHDR PNG_U32( 73, 72, 68, 82) +#define png_PLTE PNG_U32( 80, 76, 84, 69) +#define png_bKGD PNG_U32( 98, 75, 71, 68) +#define png_cHRM PNG_U32( 99, 72, 82, 77) +#define png_eXIf PNG_U32(101, 88, 73, 102) /* registered July 2017 */ +#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */ +#define png_gAMA PNG_U32(103, 65, 77, 65) +#define png_gIFg PNG_U32(103, 73, 70, 103) +#define png_gIFt PNG_U32(103, 73, 70, 116) /* deprecated */ +#define png_gIFx PNG_U32(103, 73, 70, 120) +#define png_hIST PNG_U32(104, 73, 83, 84) +#define png_iCCP PNG_U32(105, 67, 67, 80) +#define png_iTXt PNG_U32(105, 84, 88, 116) +#define png_oFFs PNG_U32(111, 70, 70, 115) +#define png_pCAL PNG_U32(112, 67, 65, 76) +#define png_pHYs PNG_U32(112, 72, 89, 115) +#define png_sBIT PNG_U32(115, 66, 73, 84) +#define png_sCAL PNG_U32(115, 67, 65, 76) +#define png_sPLT PNG_U32(115, 80, 76, 84) +#define png_sRGB PNG_U32(115, 82, 71, 66) +#define png_sTER PNG_U32(115, 84, 69, 82) +#define png_tEXt PNG_U32(116, 69, 88, 116) +#define png_tIME PNG_U32(116, 73, 77, 69) +#define png_tRNS PNG_U32(116, 82, 78, 83) +#define png_zTXt PNG_U32(122, 84, 88, 116) + +/* The following will work on (signed char*) strings, whereas the get_uint_32 + * macro will fail on top-bit-set values because of the sign extension. + */ +#define PNG_CHUNK_FROM_STRING(s)\ + PNG_U32(0xff & (s)[0], 0xff & (s)[1], 0xff & (s)[2], 0xff & (s)[3]) + +/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is + * signed and the argument is a (char[]) This macro will fail miserably on + * systems where (char) is more than 8 bits. + */ +#define PNG_STRING_FROM_CHUNK(s,c)\ + (void)(((char*)(s))[0]=(char)(((c)>>24) & 0xff), \ + ((char*)(s))[1]=(char)(((c)>>16) & 0xff),\ + ((char*)(s))[2]=(char)(((c)>>8) & 0xff), \ + ((char*)(s))[3]=(char)((c & 0xff))) + +/* Do the same but terminate with a null character. */ +#define PNG_CSTRING_FROM_CHUNK(s,c)\ + (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0) + +/* Test on flag values as defined in the spec (section 5.4): */ +#define PNG_CHUNK_ANCILLARY(c) (1 & ((c) >> 29)) +#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c)) +#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21)) +#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13)) +#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5)) + +/* Gamma values (new at libpng-1.5.4): */ +#define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */ +#define PNG_GAMMA_MAC_INVERSE 65909 +#define PNG_GAMMA_sRGB_INVERSE 45455 + +/* Almost everything below is C specific; the #defines above can be used in + * non-C code (so long as it is C-preprocessed) the rest of this stuff cannot. + */ +#ifndef PNG_VERSION_INFO_ONLY + +#include "pngstruct.h" +#include "pnginfo.h" + +/* Validate the include paths - the include path used to generate pnglibconf.h + * must match that used in the build, or we must be using pnglibconf.h.prebuilt: + */ +#if PNG_ZLIB_VERNUM != 0 && PNG_ZLIB_VERNUM != ZLIB_VERNUM +# error ZLIB_VERNUM != PNG_ZLIB_VERNUM \ + "-I (include path) error: see the notes in pngpriv.h" + /* This means that when pnglibconf.h was built the copy of zlib.h that it + * used is not the same as the one being used here. Because the build of + * libpng makes decisions to use inflateInit2 and inflateReset2 based on the + * zlib version number and because this affects handling of certain broken + * PNG files the -I directives must match. + * + * The most likely explanation is that you passed a -I in CFLAGS. This will + * not work; all the preprocessor directives and in particular all the -I + * directives must be in CPPFLAGS. + */ +#endif + +/* This is used for 16-bit gamma tables -- only the top level pointers are + * const; this could be changed: + */ +typedef const png_uint_16p * png_const_uint_16pp; + +/* Added to libpng-1.5.7: sRGB conversion tables */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_table, [256]); + /* Convert from an sRGB encoded value 0..255 to a 16-bit linear value, + * 0..65535. This table gives the closest 16-bit answers (no errors). + */ +#endif + +PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_base, [512]); +PNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]); + +#define PNG_sRGB_FROM_LINEAR(linear) \ + ((png_byte)(0xff & ((png_sRGB_base[(linear)>>15] \ + + ((((linear) & 0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8))) + /* Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB + * encoded value with maximum error 0.646365. Note that the input is not a + * 16-bit value; it has been multiplied by 255! */ +#endif /* SIMPLIFIED_READ/WRITE */ + + +/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Internal functions; these are not exported from a DLL however because they + * are used within several of the C source files they have to be C extern. + * + * All of these functions must be declared with PNG_INTERNAL_FUNCTION. + */ + +/* Zlib support */ +#define PNG_UNEXPECTED_ZLIB_RETURN (-7) +PNG_INTERNAL_FUNCTION(void, png_zstream_error,(png_structrp png_ptr, int ret), + PNG_EMPTY); + /* Used by the zlib handling functions to ensure that z_stream::msg is always + * set before they return. + */ + +#ifdef PNG_WRITE_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_free_buffer_list,(png_structrp png_ptr, + png_compression_bufferp *list),PNG_EMPTY); + /* Free the buffer list used by the compressed write code. */ +#endif + +#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ + !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \ + (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \ + defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \ + (defined(PNG_sCAL_SUPPORTED) && \ + defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)) +PNG_INTERNAL_FUNCTION(png_fixed_point,png_fixed,(png_const_structrp png_ptr, + double fp, png_const_charp text),PNG_EMPTY); +#endif + +/* Check the user version string for compatibility, returns false if the version + * numbers aren't compatible. + */ +PNG_INTERNAL_FUNCTION(int,png_user_version_check,(png_structrp png_ptr, + png_const_charp user_png_ver),PNG_EMPTY); + +/* Internal base allocator - no messages, NULL on failure to allocate. This + * does, however, call the application provided allocator and that could call + * png_error (although that would be a bug in the application implementation.) + */ +PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_base,(png_const_structrp png_ptr, + png_alloc_size_t size),PNG_ALLOCATED); + +#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\ + defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) +/* Internal array allocator, outputs no error or warning messages on failure, + * just returns NULL. + */ +PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_array,(png_const_structrp png_ptr, + int nelements, size_t element_size),PNG_ALLOCATED); + +/* The same but an existing array is extended by add_elements. This function + * also memsets the new elements to 0 and copies the old elements. The old + * array is not freed or altered. + */ +PNG_INTERNAL_FUNCTION(png_voidp,png_realloc_array,(png_const_structrp png_ptr, + png_const_voidp array, int old_elements, int add_elements, + size_t element_size),PNG_ALLOCATED); +#endif /* text, sPLT or unknown chunks */ + +/* Magic to create a struct when there is no struct to call the user supplied + * memory allocators. Because error handling has not been set up the memory + * handlers can't safely call png_error, but this is an obscure and undocumented + * restriction so libpng has to assume that the 'free' handler, at least, might + * call png_error. + */ +PNG_INTERNAL_FUNCTION(png_structp,png_create_png_struct, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, + png_free_ptr free_fn),PNG_ALLOCATED); + +/* Free memory from internal libpng struct */ +PNG_INTERNAL_FUNCTION(void,png_destroy_png_struct,(png_structrp png_ptr), + PNG_EMPTY); + +/* Free an allocated jmp_buf (always succeeds) */ +PNG_INTERNAL_FUNCTION(void,png_free_jmpbuf,(png_structrp png_ptr),PNG_EMPTY); + +/* Function to allocate memory for zlib. PNGAPI is disallowed. */ +PNG_INTERNAL_FUNCTION(voidpf,png_zalloc,(voidpf png_ptr, uInt items, uInt size), + PNG_ALLOCATED); + +/* Function to free memory for zlib. PNGAPI is disallowed. */ +PNG_INTERNAL_FUNCTION(void,png_zfree,(voidpf png_ptr, voidpf ptr),PNG_EMPTY); + +/* Next four functions are used internally as callbacks. PNGCBAPI is required + * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3, changed to + * PNGCBAPI at 1.5.0 + */ + +PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_read_data,(png_structp png_ptr, + png_bytep data, size_t length),PNG_EMPTY); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_push_fill_buffer,(png_structp png_ptr, + png_bytep buffer, size_t length),PNG_EMPTY); +#endif + +PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_write_data,(png_structp png_ptr, + png_bytep data, size_t length),PNG_EMPTY); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +# ifdef PNG_STDIO_SUPPORTED +PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_flush,(png_structp png_ptr), + PNG_EMPTY); +# endif +#endif + +/* Reset the CRC variable */ +PNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr),PNG_EMPTY); + +/* Write the "data" buffer to whatever output you are using */ +PNG_INTERNAL_FUNCTION(void,png_write_data,(png_structrp png_ptr, + png_const_bytep data, size_t length),PNG_EMPTY); + +/* Read and check the PNG file signature */ +PNG_INTERNAL_FUNCTION(void,png_read_sig,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); + +/* Read the chunk header (length + type name) */ +PNG_INTERNAL_FUNCTION(png_uint_32,png_read_chunk_header,(png_structrp png_ptr), + PNG_EMPTY); + +/* Read data from whatever input you are using into the "data" buffer */ +PNG_INTERNAL_FUNCTION(void,png_read_data,(png_structrp png_ptr, png_bytep data, + size_t length),PNG_EMPTY); + +/* Read bytes into buf, and update png_ptr->crc */ +PNG_INTERNAL_FUNCTION(void,png_crc_read,(png_structrp png_ptr, png_bytep buf, + png_uint_32 length),PNG_EMPTY); + +/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ +PNG_INTERNAL_FUNCTION(int,png_crc_finish,(png_structrp png_ptr, + png_uint_32 skip),PNG_EMPTY); + +/* Read the CRC from the file and compare it to the libpng calculated CRC */ +PNG_INTERNAL_FUNCTION(int,png_crc_error,(png_structrp png_ptr),PNG_EMPTY); + +/* Calculate the CRC over a section of data. Note that we are only + * passing a maximum of 64K on systems that have this as a memory limit, + * since this is the maximum buffer size we can specify. + */ +PNG_INTERNAL_FUNCTION(void,png_calculate_crc,(png_structrp png_ptr, + png_const_bytep ptr, size_t length),PNG_EMPTY); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_flush,(png_structrp png_ptr),PNG_EMPTY); +#endif + +/* Write various chunks */ + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. + */ +PNG_INTERNAL_FUNCTION(void,png_write_IHDR,(png_structrp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, + int compression_method, int filter_method, int interlace_method),PNG_EMPTY); + +PNG_INTERNAL_FUNCTION(void,png_write_PLTE,(png_structrp png_ptr, + png_const_colorp palette, png_uint_32 num_pal),PNG_EMPTY); + +PNG_INTERNAL_FUNCTION(void,png_compress_IDAT,(png_structrp png_ptr, + png_const_bytep row_data, png_alloc_size_t row_data_length, int flush), + PNG_EMPTY); + +PNG_INTERNAL_FUNCTION(void,png_write_IEND,(png_structrp png_ptr),PNG_EMPTY); + +#ifdef PNG_WRITE_gAMA_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_gAMA_fixed,(png_structrp png_ptr, + png_fixed_point file_gamma),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_sBIT_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr, + png_const_color_8p sbit, int color_type),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_cHRM_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr, + const png_xy *xy), PNG_EMPTY); + /* The xy value must have been previously validated */ +#endif + +#ifdef PNG_WRITE_sRGB_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr, + int intent),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_eXIf_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_eXIf,(png_structrp png_ptr, + png_bytep exif, int num_exif),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_iCCP_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr, + png_const_charp name, png_const_bytep profile), PNG_EMPTY); + /* The profile must have been previously validated for correctness, the + * length comes from the first four bytes. Only the base, deflate, + * compression is supported. + */ +#endif + +#ifdef PNG_WRITE_sPLT_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_sPLT,(png_structrp png_ptr, + png_const_sPLT_tp palette),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_tRNS_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_tRNS,(png_structrp png_ptr, + png_const_bytep trans, png_const_color_16p values, int number, + int color_type),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_bKGD_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_bKGD,(png_structrp png_ptr, + png_const_color_16p values, int color_type),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_hIST,(png_structrp png_ptr, + png_const_uint_16p hist, int num_hist),PNG_EMPTY); +#endif + +/* Chunks that have keywords */ +#ifdef PNG_WRITE_tEXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_tEXt,(png_structrp png_ptr, + png_const_charp key, png_const_charp text, size_t text_len),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_zTXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_zTXt,(png_structrp png_ptr, png_const_charp + key, png_const_charp text, int compression),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_iTXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_iTXt,(png_structrp png_ptr, + int compression, png_const_charp key, png_const_charp lang, + png_const_charp lang_key, png_const_charp text),PNG_EMPTY); +#endif + +#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */ +PNG_INTERNAL_FUNCTION(int,png_set_text_2,(png_const_structrp png_ptr, + png_inforp info_ptr, png_const_textp text_ptr, int num_text),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_oFFs,(png_structrp png_ptr, + png_int_32 x_offset, png_int_32 y_offset, int unit_type),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_pCAL_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_pCAL,(png_structrp png_ptr, + png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, + png_const_charp units, png_charpp params),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_pHYs_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_pHYs,(png_structrp png_ptr, + png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, + int unit_type),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_tIME_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_tIME,(png_structrp png_ptr, + png_const_timep mod_time),PNG_EMPTY); +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_write_sCAL_s,(png_structrp png_ptr, + int unit, png_const_charp width, png_const_charp height),PNG_EMPTY); +#endif + +/* Called when finished processing a row of data */ +PNG_INTERNAL_FUNCTION(void,png_write_finish_row,(png_structrp png_ptr), + PNG_EMPTY); + +/* Internal use only. Called before first row of data */ +PNG_INTERNAL_FUNCTION(void,png_write_start_row,(png_structrp png_ptr), + PNG_EMPTY); + +/* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an + * array of png_ptr->width pixels. If the image is not interlaced or this + * is the final pass this just does a memcpy, otherwise the "display" flag + * is used to determine whether to copy pixels that are not in the current pass. + * + * Because 'png_do_read_interlace' (below) replicates pixels this allows this + * function to achieve the documented 'blocky' appearance during interlaced read + * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row' + * are not changed if they are not in the current pass, when display is 0. + * + * 'display' must be 0 or 1, otherwise the memcpy will be done regardless. + * + * The API always reads from the png_struct row buffer and always assumes that + * it is full width (png_do_read_interlace has already been called.) + * + * This function is only ever used to write to row buffers provided by the + * caller of the relevant libpng API and the row must have already been + * transformed by the read transformations. + * + * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed + * bitmasks for use within the code, otherwise runtime generated masks are used. + * The default is compile time masks. + */ +#ifndef PNG_USE_COMPILE_TIME_MASKS +# define PNG_USE_COMPILE_TIME_MASKS 1 +#endif +PNG_INTERNAL_FUNCTION(void,png_combine_row,(png_const_structrp png_ptr, + png_bytep row, int display),PNG_EMPTY); + +#ifdef PNG_READ_INTERLACING_SUPPORTED +/* Expand an interlaced row: the 'row_info' describes the pass data that has + * been read in and must correspond to the pixels in 'row', the pixels are + * expanded (moved apart) in 'row' to match the final layout, when doing this + * the pixels are *replicated* to the intervening space. This is essential for + * the correct operation of png_combine_row, above. + */ +PNG_INTERNAL_FUNCTION(void,png_do_read_interlace,(png_row_infop row_info, + png_bytep row, int pass, png_uint_32 transformations),PNG_EMPTY); +#endif + +/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED +/* Grab pixels out of a row for an interlaced pass */ +PNG_INTERNAL_FUNCTION(void,png_do_write_interlace,(png_row_infop row_info, + png_bytep row, int pass),PNG_EMPTY); +#endif + +/* Unfilter a row: check the filter value before calling this, there is no point + * calling it for PNG_FILTER_VALUE_NONE. + */ +PNG_INTERNAL_FUNCTION(void,png_read_filter_row,(png_structrp pp, png_row_infop + row_info, png_bytep row, png_const_bytep prev_row, int filter),PNG_EMPTY); + +#if PNG_ARM_NEON_OPT > 0 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon,(png_row_infop row_info, + png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +#endif + +#if PNG_MIPS_MSA_OPT > 0 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_msa,(png_row_infop row_info, + png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_msa,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_msa,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_msa,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_msa,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_msa,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +#endif + +#if PNG_POWERPC_VSX_OPT > 0 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_vsx,(png_row_infop row_info, + png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_vsx,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_vsx,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_vsx,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_vsx,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_vsx,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_vsx,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +#endif + +#if PNG_INTEL_SSE_IMPLEMENTATION > 0 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); +#endif + +/* Choose the best filter to use and filter the row data */ +PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr, + png_row_infop row_info),PNG_EMPTY); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_read_IDAT_data,(png_structrp png_ptr, + png_bytep output, png_alloc_size_t avail_out),PNG_EMPTY); + /* Read 'avail_out' bytes of data from the IDAT stream. If the output buffer + * is NULL the function checks, instead, for the end of the stream. In this + * case a benign error will be issued if the stream end is not found or if + * extra data has to be consumed. + */ +PNG_INTERNAL_FUNCTION(void,png_read_finish_IDAT,(png_structrp png_ptr), + PNG_EMPTY); + /* This cleans up when the IDAT LZ stream does not end when the last image + * byte is read; there is still some pending input. + */ + +PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr), + PNG_EMPTY); + /* Finish a row while reading, dealing with interlacing passes, etc. */ +#endif /* SEQUENTIAL_READ */ + +/* Initialize the row buffers, etc. */ +PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY); + +#if ZLIB_VERNUM >= 0x1240 +PNG_INTERNAL_FUNCTION(int,png_zlib_inflate,(png_structrp png_ptr, int flush), + PNG_EMPTY); +# define PNG_INFLATE(pp, flush) png_zlib_inflate(pp, flush) +#else /* Zlib < 1.2.4 */ +# define PNG_INFLATE(pp, flush) inflate(&(pp)->zstream, flush) +#endif /* Zlib < 1.2.4 */ + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +/* Optional call to update the users info structure */ +PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +#endif + +/* Shared transform functions, defined in pngtran.c */ +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +PNG_INTERNAL_FUNCTION(void,png_do_strip_channel,(png_row_infop row_info, + png_bytep row, int at_start),PNG_EMPTY); +#endif + +#ifdef PNG_16BIT_SUPPORTED +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +PNG_INTERNAL_FUNCTION(void,png_do_swap,(png_row_infop row_info, + png_bytep row),PNG_EMPTY); +#endif +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ + defined(PNG_WRITE_PACKSWAP_SUPPORTED) +PNG_INTERNAL_FUNCTION(void,png_do_packswap,(png_row_infop row_info, + png_bytep row),PNG_EMPTY); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +PNG_INTERNAL_FUNCTION(void,png_do_invert,(png_row_infop row_info, + png_bytep row),PNG_EMPTY); +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +PNG_INTERNAL_FUNCTION(void,png_do_bgr,(png_row_infop row_info, + png_bytep row),PNG_EMPTY); +#endif + +/* The following decodes the appropriate chunks, and does error correction, + * then calls the appropriate callback for the chunk if it is valid. + */ + +/* Decode the IHDR chunk */ +PNG_INTERNAL_FUNCTION(void,png_handle_IHDR,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_handle_PLTE,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_handle_IEND,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); + +#ifdef PNG_READ_bKGD_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_bKGD,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_eXIf_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_eXIf,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_eXIf_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_eXIf,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_gAMA_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_hIST_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_hIST,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_iCCP_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_iCCP,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif /* READ_iCCP */ + +#ifdef PNG_READ_iTXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_iTXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_oFFs,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_pCAL,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_pHYs,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_sBIT,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_sCAL,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_sPLT_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_sPLT,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif /* READ_sPLT */ + +#ifdef PNG_READ_sRGB_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_sRGB,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_tEXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_tIME_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_tIME,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_tRNS_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_tRNS,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +#endif + +PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_const_structrp png_ptr, + png_uint_32 chunk_name),PNG_EMPTY); + +PNG_INTERNAL_FUNCTION(void,png_check_chunk_length,(png_const_structrp png_ptr, + png_uint_32 chunk_length),PNG_EMPTY); + +PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY); + /* This is the function that gets called for unknown chunks. The 'keep' + * argument is either non-zero for a known chunk that has been set to be + * handled as unknown or zero for an unknown chunk. By default the function + * just skips the chunk or errors out if it is critical. + */ + +#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\ + defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) +PNG_INTERNAL_FUNCTION(int,png_chunk_unknown_handling, + (png_const_structrp png_ptr, png_uint_32 chunk_name),PNG_EMPTY); + /* Exactly as the API png_handle_as_unknown() except that the argument is a + * 32-bit chunk name, not a string. + */ +#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */ + +/* Handle the transformations for reading and writing */ +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_do_read_transformations,(png_structrp png_ptr, + png_row_infop row_info),PNG_EMPTY); +#endif +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_do_write_transformations,(png_structrp png_ptr, + png_row_infop row_info),PNG_EMPTY); +#endif + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_init_read_transformations,(png_structrp png_ptr), + PNG_EMPTY); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_push_read_chunk,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_sig,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_check_crc,(png_structrp png_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_restore_buffer,(png_structrp png_ptr, + png_bytep buffer, size_t buffer_length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_IDAT,(png_structrp png_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_process_IDAT_data,(png_structrp png_ptr, + png_bytep buffer, size_t buffer_length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_process_row,(png_structrp png_ptr), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_handle_unknown,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr, + png_bytep row),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_read_push_finish_row,(png_structrp png_ptr), + PNG_EMPTY); +# ifdef PNG_READ_tEXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_push_handle_tEXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_tEXt,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +# endif +# ifdef PNG_READ_zTXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_push_handle_zTXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_zTXt,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +# endif +# ifdef PNG_READ_iTXt_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_push_handle_iTXt,(png_structrp png_ptr, + png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_push_read_iTXt,(png_structrp png_ptr, + png_inforp info_ptr),PNG_EMPTY); +# endif + +#endif /* PROGRESSIVE_READ */ + +/* Added at libpng version 1.6.0 */ +#ifdef PNG_GAMMA_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_fixed_point gAMA), PNG_EMPTY); + /* Set the colorspace gamma with a value provided by the application or by + * the gAMA chunk on read. The value will override anything set by an ICC + * profile. + */ + +PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr, + png_inforp info_ptr), PNG_EMPTY); + /* Synchronize the info 'valid' flags with the colorspace */ + +PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr, + png_inforp info_ptr), PNG_EMPTY); + /* Copy the png_struct colorspace to the info_struct and call the above to + * synchronize the flags. Checks for NULL info_ptr and does nothing. + */ +#endif + +/* Added at libpng version 1.4.0 */ +#ifdef PNG_COLORSPACE_SUPPORTED +/* These internal functions are for maintaining the colorspace structure within + * a png_info or png_struct (or, indeed, both). + */ +PNG_INTERNAL_FUNCTION(int,png_colorspace_set_chromaticities, + (png_const_structrp png_ptr, png_colorspacerp colorspace, const png_xy *xy, + int preferred), PNG_EMPTY); + +PNG_INTERNAL_FUNCTION(int,png_colorspace_set_endpoints, + (png_const_structrp png_ptr, png_colorspacerp colorspace, const png_XYZ *XYZ, + int preferred), PNG_EMPTY); + +#ifdef PNG_sRGB_SUPPORTED +PNG_INTERNAL_FUNCTION(int,png_colorspace_set_sRGB,(png_const_structrp png_ptr, + png_colorspacerp colorspace, int intent), PNG_EMPTY); + /* This does set the colorspace gAMA and cHRM values too, but doesn't set the + * flags to write them, if it returns false there was a problem and an error + * message has already been output (but the colorspace may still need to be + * synced to record the invalid flag). + */ +#endif /* sRGB */ + +#ifdef PNG_iCCP_SUPPORTED +PNG_INTERNAL_FUNCTION(int,png_colorspace_set_ICC,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_charp name, + png_uint_32 profile_length, png_const_bytep profile, int color_type), + PNG_EMPTY); + /* The 'name' is used for information only */ + +/* Routines for checking parts of an ICC profile. */ +#ifdef PNG_READ_iCCP_SUPPORTED +PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_charp name, + png_uint_32 profile_length), PNG_EMPTY); +#endif /* READ_iCCP */ +PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_charp name, + png_uint_32 profile_length, + png_const_bytep profile /* first 132 bytes only */, int color_type), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(int,png_icc_check_tag_table,(png_const_structrp png_ptr, + png_colorspacerp colorspace, png_const_charp name, + png_uint_32 profile_length, + png_const_bytep profile /* header plus whole tag table */), PNG_EMPTY); +#ifdef PNG_sRGB_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_icc_set_sRGB,( + png_const_structrp png_ptr, png_colorspacerp colorspace, + png_const_bytep profile, uLong adler), PNG_EMPTY); + /* 'adler' is the Adler32 checksum of the uncompressed profile data. It may + * be zero to indicate that it is not available. It is used, if provided, + * as a fast check on the profile when checking to see if it is sRGB. + */ +#endif +#endif /* iCCP */ + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_colorspace_set_rgb_coefficients, + (png_structrp png_ptr), PNG_EMPTY); + /* Set the rgb_to_gray coefficients from the colorspace Y values */ +#endif /* READ_RGB_TO_GRAY */ +#endif /* COLORSPACE */ + +/* Added at libpng version 1.4.0 */ +PNG_INTERNAL_FUNCTION(void,png_check_IHDR,(png_const_structrp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type),PNG_EMPTY); + +/* Added at libpng version 1.5.10 */ +#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ + defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) +PNG_INTERNAL_FUNCTION(void,png_do_check_palette_indexes, + (png_structrp png_ptr, png_row_infop row_info),PNG_EMPTY); +#endif + +#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) +PNG_INTERNAL_FUNCTION(void,png_fixed_error,(png_const_structrp png_ptr, + png_const_charp name),PNG_NORETURN); +#endif + +/* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite + * the end. Always leaves the buffer nul terminated. Never errors out (and + * there is no error code.) + */ +PNG_INTERNAL_FUNCTION(size_t,png_safecat,(png_charp buffer, size_t bufsize, + size_t pos, png_const_charp string),PNG_EMPTY); + +/* Various internal functions to handle formatted warning messages, currently + * only implemented for warnings. + */ +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED) +/* Utility to dump an unsigned value into a buffer, given a start pointer and + * and end pointer (which should point just *beyond* the end of the buffer!) + * Returns the pointer to the start of the formatted string. This utility only + * does unsigned values. + */ +PNG_INTERNAL_FUNCTION(png_charp,png_format_number,(png_const_charp start, + png_charp end, int format, png_alloc_size_t number),PNG_EMPTY); + +/* Convenience macro that takes an array: */ +#define PNG_FORMAT_NUMBER(buffer,format,number) \ + png_format_number(buffer, buffer + (sizeof buffer), format, number) + +/* Suggested size for a number buffer (enough for 64 bits and a sign!) */ +#define PNG_NUMBER_BUFFER_SIZE 24 + +/* These are the integer formats currently supported, the name is formed from + * the standard printf(3) format string. + */ +#define PNG_NUMBER_FORMAT_u 1 /* chose unsigned API! */ +#define PNG_NUMBER_FORMAT_02u 2 +#define PNG_NUMBER_FORMAT_d 1 /* chose signed API! */ +#define PNG_NUMBER_FORMAT_02d 2 +#define PNG_NUMBER_FORMAT_x 3 +#define PNG_NUMBER_FORMAT_02x 4 +#define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */ +#endif + +#ifdef PNG_WARNINGS_SUPPORTED +/* New defines and members adding in libpng-1.5.4 */ +# define PNG_WARNING_PARAMETER_SIZE 32 +# define PNG_WARNING_PARAMETER_COUNT 8 /* Maximum 9; see pngerror.c */ + +/* An l-value of this type has to be passed to the APIs below to cache the + * values of the parameters to a formatted warning message. + */ +typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][ + PNG_WARNING_PARAMETER_SIZE]; + +PNG_INTERNAL_FUNCTION(void,png_warning_parameter,(png_warning_parameters p, + int number, png_const_charp string),PNG_EMPTY); + /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters, + * including the trailing '\0'. + */ +PNG_INTERNAL_FUNCTION(void,png_warning_parameter_unsigned, + (png_warning_parameters p, int number, int format, png_alloc_size_t value), + PNG_EMPTY); + /* Use png_alloc_size_t because it is an unsigned type as big as any we + * need to output. Use the following for a signed value. + */ +PNG_INTERNAL_FUNCTION(void,png_warning_parameter_signed, + (png_warning_parameters p, int number, int format, png_int_32 value), + PNG_EMPTY); + +PNG_INTERNAL_FUNCTION(void,png_formatted_warning,(png_const_structrp png_ptr, + png_warning_parameters p, png_const_charp message),PNG_EMPTY); + /* 'message' follows the X/Open approach of using @1, @2 to insert + * parameters previously supplied using the above functions. Errors in + * specifying the parameters will simply result in garbage substitutions. + */ +#endif + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +/* Application errors (new in 1.6); use these functions (declared below) for + * errors in the parameters or order of API function calls on read. The + * 'warning' should be used for an error that can be handled completely; the + * 'error' for one which can be handled safely but which may lose application + * information or settings. + * + * By default these both result in a png_error call prior to release, while in a + * released version the 'warning' is just a warning. However if the application + * explicitly disables benign errors (explicitly permitting the code to lose + * information) they both turn into warnings. + * + * If benign errors aren't supported they end up as the corresponding base call + * (png_warning or png_error.) + */ +PNG_INTERNAL_FUNCTION(void,png_app_warning,(png_const_structrp png_ptr, + png_const_charp message),PNG_EMPTY); + /* The application provided invalid parameters to an API function or called + * an API function at the wrong time, libpng can completely recover. + */ + +PNG_INTERNAL_FUNCTION(void,png_app_error,(png_const_structrp png_ptr, + png_const_charp message),PNG_EMPTY); + /* As above but libpng will ignore the call, or attempt some other partial + * recovery from the error. + */ +#else +# define png_app_warning(pp,s) png_warning(pp,s) +# define png_app_error(pp,s) png_error(pp,s) +#endif + +PNG_INTERNAL_FUNCTION(void,png_chunk_report,(png_const_structrp png_ptr, + png_const_charp message, int error),PNG_EMPTY); + /* Report a recoverable issue in chunk data. On read this is used to report + * a problem found while reading a particular chunk and the + * png_chunk_benign_error or png_chunk_warning function is used as + * appropriate. On write this is used to report an error that comes from + * data set via an application call to a png_set_ API and png_app_error or + * png_app_warning is used as appropriate. + * + * The 'error' parameter must have one of the following values: + */ +#define PNG_CHUNK_WARNING 0 /* never an error */ +#define PNG_CHUNK_WRITE_ERROR 1 /* an error only on write */ +#define PNG_CHUNK_ERROR 2 /* always an error */ + +/* ASCII to FP interfaces, currently only implemented if sCAL + * support is required. + */ +#if defined(PNG_sCAL_SUPPORTED) +/* MAX_DIGITS is actually the maximum number of characters in an sCAL + * width or height, derived from the precision (number of significant + * digits - a build time settable option) and assumptions about the + * maximum ridiculous exponent. + */ +#define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/) + +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_ascii_from_fp,(png_const_structrp png_ptr, + png_charp ascii, size_t size, double fp, unsigned int precision), + PNG_EMPTY); +#endif /* FLOATING_POINT */ + +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr, + png_charp ascii, size_t size, png_fixed_point fp),PNG_EMPTY); +#endif /* FIXED_POINT */ +#endif /* sCAL */ + +#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) +/* An internal API to validate the format of a floating point number. + * The result is the index of the next character. If the number is + * not valid it will be the index of a character in the supposed number. + * + * The format of a number is defined in the PNG extensions specification + * and this API is strictly conformant to that spec, not anyone elses! + * + * The format as a regular expression is: + * + * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)? + * + * or: + * + * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)? + * + * The complexity is that either integer or fraction must be present and the + * fraction is permitted to have no digits only if the integer is present. + * + * NOTE: The dangling E problem. + * There is a PNG valid floating point number in the following: + * + * PNG floating point numbers are not greedy. + * + * Working this out requires *TWO* character lookahead (because of the + * sign), the parser does not do this - it will fail at the 'r' - this + * doesn't matter for PNG sCAL chunk values, but it requires more care + * if the value were ever to be embedded in something more complex. Use + * ANSI-C strtod if you need the lookahead. + */ +/* State table for the parser. */ +#define PNG_FP_INTEGER 0 /* before or in integer */ +#define PNG_FP_FRACTION 1 /* before or in fraction */ +#define PNG_FP_EXPONENT 2 /* before or in exponent */ +#define PNG_FP_STATE 3 /* mask for the above */ +#define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */ +#define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */ +#define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */ +#define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */ +#define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */ + +/* These three values don't affect the parser. They are set but not used. + */ +#define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */ +#define PNG_FP_NEGATIVE 128 /* A negative number, including "-0" */ +#define PNG_FP_NONZERO 256 /* A non-zero value */ +#define PNG_FP_STICKY 448 /* The above three flags */ + +/* This is available for the caller to store in 'state' if required. Do not + * call the parser after setting it (the parser sometimes clears it.) + */ +#define PNG_FP_INVALID 512 /* Available for callers as a distinct value */ + +/* Result codes for the parser (boolean - true meants ok, false means + * not ok yet.) + */ +#define PNG_FP_MAYBE 0 /* The number may be valid in the future */ +#define PNG_FP_OK 1 /* The number is valid */ + +/* Tests on the sticky non-zero and negative flags. To pass these checks + * the state must also indicate that the whole number is valid - this is + * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this + * is equivalent to PNG_FP_OK above.) + */ +#define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO) + /* NZ_MASK: the string is valid and a non-zero negative value */ +#define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO) + /* Z MASK: the string is valid and a non-zero value. */ + /* PNG_FP_SAW_DIGIT: the string is valid. */ +#define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT) +#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK) +#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK) + +/* The actual parser. This can be called repeatedly. It updates + * the index into the string and the state variable (which must + * be initialized to 0). It returns a result code, as above. There + * is no point calling the parser any more if it fails to advance to + * the end of the string - it is stuck on an invalid character (or + * terminated by '\0'). + * + * Note that the pointer will consume an E or even an E+ and then leave + * a 'maybe' state even though a preceding integer.fraction is valid. + * The PNG_FP_WAS_VALID flag indicates that a preceding substring was + * a valid number. It's possible to recover from this by calling + * the parser again (from the start, with state 0) but with a string + * that omits the last character (i.e. set the size to the index of + * the problem character.) This has not been tested within libpng. + */ +PNG_INTERNAL_FUNCTION(int,png_check_fp_number,(png_const_charp string, + size_t size, int *statep, png_size_tp whereami),PNG_EMPTY); + +/* This is the same but it checks a complete string and returns true + * only if it just contains a floating point number. As of 1.5.4 this + * function also returns the state at the end of parsing the number if + * it was valid (otherwise it returns 0.) This can be used for testing + * for negative or zero values using the sticky flag. + */ +PNG_INTERNAL_FUNCTION(int,png_check_fp_string,(png_const_charp string, + size_t size),PNG_EMPTY); +#endif /* pCAL || sCAL */ + +#if defined(PNG_GAMMA_SUPPORTED) ||\ + defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED) +/* Added at libpng version 1.5.0 */ +/* This is a utility to provide a*times/div (rounded) and indicate + * if there is an overflow. The result is a boolean - false (0) + * for overflow, true (1) if no overflow, in which case *res + * holds the result. + */ +PNG_INTERNAL_FUNCTION(int,png_muldiv,(png_fixed_point_p res, png_fixed_point a, + png_int_32 multiplied_by, png_int_32 divided_by),PNG_EMPTY); +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) +/* Same deal, but issue a warning on overflow and return 0. */ +PNG_INTERNAL_FUNCTION(png_fixed_point,png_muldiv_warn, + (png_const_structrp png_ptr, png_fixed_point a, png_int_32 multiplied_by, + png_int_32 divided_by),PNG_EMPTY); +#endif + +#ifdef PNG_GAMMA_SUPPORTED +/* Calculate a reciprocal - used for gamma values. This returns + * 0 if the argument is 0 in order to maintain an undefined value; + * there are no warnings. + */ +PNG_INTERNAL_FUNCTION(png_fixed_point,png_reciprocal,(png_fixed_point a), + PNG_EMPTY); + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* The same but gives a reciprocal of the product of two fixed point + * values. Accuracy is suitable for gamma calculations but this is + * not exact - use png_muldiv for that. Only required at present on read. + */ +PNG_INTERNAL_FUNCTION(png_fixed_point,png_reciprocal2,(png_fixed_point a, + png_fixed_point b),PNG_EMPTY); +#endif + +/* Return true if the gamma value is significantly different from 1.0 */ +PNG_INTERNAL_FUNCTION(int,png_gamma_significant,(png_fixed_point gamma_value), + PNG_EMPTY); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* Internal fixed point gamma correction. These APIs are called as + * required to convert single values - they don't need to be fast, + * they are not used when processing image pixel values. + * + * While the input is an 'unsigned' value it must actually be the + * correct bit value - 0..255 or 0..65535 as required. + */ +PNG_INTERNAL_FUNCTION(png_uint_16,png_gamma_correct,(png_structrp png_ptr, + unsigned int value, png_fixed_point gamma_value),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(png_uint_16,png_gamma_16bit_correct,(unsigned int value, + png_fixed_point gamma_value),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(png_byte,png_gamma_8bit_correct,(unsigned int value, + png_fixed_point gamma_value),PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_destroy_gamma_table,(png_structrp png_ptr), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(void,png_build_gamma_table,(png_structrp png_ptr, + int bit_depth),PNG_EMPTY); +#endif + +/* SIMPLIFIED READ/WRITE SUPPORT */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +/* The internal structure that png_image::opaque points to. */ +typedef struct png_control +{ + png_structp png_ptr; + png_infop info_ptr; + png_voidp error_buf; /* Always a jmp_buf at present. */ + + png_const_bytep memory; /* Memory buffer. */ + size_t size; /* Size of the memory buffer. */ + + unsigned int for_write :1; /* Otherwise it is a read structure */ + unsigned int owned_file :1; /* We own the file in io_ptr */ +} png_control; + +/* Return the pointer to the jmp_buf from a png_control: necessary because C + * does not reveal the type of the elements of jmp_buf. + */ +#ifdef __cplusplus +# define png_control_jmp_buf(pc) (((jmp_buf*)((pc)->error_buf))[0]) +#else +# define png_control_jmp_buf(pc) ((pc)->error_buf) +#endif + +/* Utility to safely execute a piece of libpng code catching and logging any + * errors that might occur. Returns true on success, false on failure (either + * of the function or as a result of a png_error.) + */ +PNG_INTERNAL_CALLBACK(void,png_safe_error,(png_structp png_ptr, + png_const_charp error_message),PNG_NORETURN); + +#ifdef PNG_WARNINGS_SUPPORTED +PNG_INTERNAL_CALLBACK(void,png_safe_warning,(png_structp png_ptr, + png_const_charp warning_message),PNG_EMPTY); +#else +# define png_safe_warning 0/*dummy argument*/ +#endif + +PNG_INTERNAL_FUNCTION(int,png_safe_execute,(png_imagep image, + int (*function)(png_voidp), png_voidp arg),PNG_EMPTY); + +/* Utility to log an error; this also cleans up the png_image; the function + * always returns 0 (false). + */ +PNG_INTERNAL_FUNCTION(int,png_image_error,(png_imagep image, + png_const_charp error_message),PNG_EMPTY); + +#ifndef PNG_SIMPLIFIED_READ_SUPPORTED +/* png_image_free is used by the write code but not exported */ +PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY); +#endif /* !SIMPLIFIED_READ */ + +#endif /* SIMPLIFIED READ/WRITE */ + +/* These are initialization functions for hardware specific PNG filter + * optimizations; list these here then select the appropriate one at compile + * time using the macro PNG_FILTER_OPTIMIZATIONS. If the macro is not defined + * the generic code is used. + */ +#ifdef PNG_FILTER_OPTIMIZATIONS +PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structp png_ptr, + unsigned int bpp), PNG_EMPTY); + /* Just declare the optimization that will be used */ +#else + /* List *all* the possible optimizations here - this branch is required if + * the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in + * CFLAGS in place of CPPFLAGS *and* uses symbol prefixing. + */ +# if PNG_ARM_NEON_OPT > 0 +PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon, + (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); +#endif + +#if PNG_MIPS_MSA_OPT > 0 +PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa, + (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); +#endif + +# if PNG_INTEL_SSE_IMPLEMENTATION > 0 +PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_sse2, + (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); +# endif +#endif + +PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr, + png_const_charp key, png_bytep new_key), PNG_EMPTY); + +#if PNG_ARM_NEON_IMPLEMENTATION == 1 +PNG_INTERNAL_FUNCTION(void, + png_riffle_palette_neon, + (png_structrp), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(int, + png_do_expand_palette_rgba8_neon, + (png_structrp, + png_row_infop, + png_const_bytep, + const png_bytepp, + const png_bytepp), + PNG_EMPTY); +PNG_INTERNAL_FUNCTION(int, + png_do_expand_palette_rgb8_neon, + (png_structrp, + png_row_infop, + png_const_bytep, + const png_bytepp, + const png_bytepp), + PNG_EMPTY); +#endif + +/* Maintainer: Put new private prototypes here ^ */ + +#include "pngdebug.h" + +#ifdef __cplusplus +} +#endif + +#endif /* PNG_VERSION_INFO_ONLY */ +#endif /* PNGPRIV_H */ diff --git a/extern/libpng/pngread.c b/extern/libpng/pngread.c new file mode 100644 index 000000000..8fa7d9f16 --- /dev/null +++ b/extern/libpng/pngread.c @@ -0,0 +1,4225 @@ + +/* pngread.c - read a PNG file + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains routines that an application calls directly to + * read a PNG file or stream. + */ + +#include "pngpriv.h" +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) +# include +#endif + +#ifdef PNG_READ_SUPPORTED + +/* Create a PNG structure for reading, and allocate any memory needed. */ +PNG_FUNCTION(png_structp,PNGAPI +png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) +{ +#ifndef PNG_USER_MEM_SUPPORTED + png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr, + error_fn, warn_fn, NULL, NULL, NULL); +#else + return png_create_read_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, NULL, NULL, NULL); +} + +/* Alternate create PNG structure for reading, and allocate any memory + * needed. + */ +PNG_FUNCTION(png_structp,PNGAPI +png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) +{ + png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr, + error_fn, warn_fn, mem_ptr, malloc_fn, free_fn); +#endif /* USER_MEM */ + + if (png_ptr != NULL) + { + png_ptr->mode = PNG_IS_READ_STRUCT; + + /* Added in libpng-1.6.0; this can be used to detect a read structure if + * required (it will be zero in a write structure.) + */ +# ifdef PNG_SEQUENTIAL_READ_SUPPORTED + png_ptr->IDAT_read_size = PNG_IDAT_READ_SIZE; +# endif + +# ifdef PNG_BENIGN_READ_ERRORS_SUPPORTED + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; + + /* In stable builds only warn if an application error can be completely + * handled. + */ +# if PNG_RELEASE_BUILD + png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN; +# endif +# endif + + /* TODO: delay this, it can be done in png_init_io (if the app doesn't + * do it itself) avoiding setting the default function if it is not + * required. + */ + png_set_read_fn(png_ptr, NULL, NULL); + } + + return png_ptr; +} + + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the information before the actual image data. This has been + * changed in v0.90 to allow reading a file that already has the magic + * bytes read from the stream. You can tell libpng how many bytes have + * been read from the beginning of the stream (up to the maximum of 8) + * via png_set_sig_bytes(), and we will only check the remaining bytes + * here. The application can then have access to the signature bytes we + * read if it is determined that this isn't a valid PNG file. + */ +void PNGAPI +png_read_info(png_structrp png_ptr, png_inforp info_ptr) +{ +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + int keep; +#endif + + png_debug(1, "in png_read_info"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Read and check the PNG file signature. */ + png_read_sig(png_ptr, info_ptr); + + for (;;) + { + png_uint_32 length = png_read_chunk_header(png_ptr); + png_uint_32 chunk_name = png_ptr->chunk_name; + + /* IDAT logic needs to happen here to simplify getting the two flags + * right. + */ + if (chunk_name == png_IDAT) + { + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + (png_ptr->mode & PNG_HAVE_PLTE) == 0) + png_chunk_error(png_ptr, "Missing PLTE before IDAT"); + + else if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) + png_chunk_benign_error(png_ptr, "Too many IDATs found"); + + png_ptr->mode |= PNG_HAVE_IDAT; + } + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + png_ptr->mode |= PNG_AFTER_IDAT; + } + + /* This should be a binary subdivision search or a hash for + * matching the chunk name rather than a linear search. + */ + if (chunk_name == png_IHDR) + png_handle_IHDR(png_ptr, info_ptr, length); + + else if (chunk_name == png_IEND) + png_handle_IEND(png_ptr, info_ptr, length); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0) + { + png_handle_unknown(png_ptr, info_ptr, length, keep); + + if (chunk_name == png_PLTE) + png_ptr->mode |= PNG_HAVE_PLTE; + + else if (chunk_name == png_IDAT) + { + png_ptr->idat_size = 0; /* It has been consumed */ + break; + } + } +#endif + else if (chunk_name == png_PLTE) + png_handle_PLTE(png_ptr, info_ptr, length); + + else if (chunk_name == png_IDAT) + { + png_ptr->idat_size = length; + break; + } + +#ifdef PNG_READ_bKGD_SUPPORTED + else if (chunk_name == png_bKGD) + png_handle_bKGD(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED + else if (chunk_name == png_cHRM) + png_handle_cHRM(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_eXIf_SUPPORTED + else if (chunk_name == png_eXIf) + png_handle_eXIf(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_gAMA_SUPPORTED + else if (chunk_name == png_gAMA) + png_handle_gAMA(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_hIST_SUPPORTED + else if (chunk_name == png_hIST) + png_handle_hIST(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED + else if (chunk_name == png_oFFs) + png_handle_oFFs(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED + else if (chunk_name == png_pCAL) + png_handle_pCAL(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED + else if (chunk_name == png_sCAL) + png_handle_sCAL(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED + else if (chunk_name == png_pHYs) + png_handle_pHYs(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED + else if (chunk_name == png_sBIT) + png_handle_sBIT(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED + else if (chunk_name == png_sRGB) + png_handle_sRGB(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_iCCP_SUPPORTED + else if (chunk_name == png_iCCP) + png_handle_iCCP(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sPLT_SUPPORTED + else if (chunk_name == png_sPLT) + png_handle_sPLT(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED + else if (chunk_name == png_tEXt) + png_handle_tEXt(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tIME_SUPPORTED + else if (chunk_name == png_tIME) + png_handle_tIME(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tRNS_SUPPORTED + else if (chunk_name == png_tRNS) + png_handle_tRNS(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED + else if (chunk_name == png_zTXt) + png_handle_zTXt(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_iTXt_SUPPORTED + else if (chunk_name == png_iTXt) + png_handle_iTXt(png_ptr, info_ptr, length); +#endif + + else + png_handle_unknown(png_ptr, info_ptr, length, + PNG_HANDLE_CHUNK_AS_DEFAULT); + } +} +#endif /* SEQUENTIAL_READ */ + +/* Optional call to update the users info_ptr structure */ +void PNGAPI +png_read_update_info(png_structrp png_ptr, png_inforp info_ptr) +{ + png_debug(1, "in png_read_update_info"); + + if (png_ptr != NULL) + { + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) + { + png_read_start_row(png_ptr); + +# ifdef PNG_READ_TRANSFORMS_SUPPORTED + png_read_transform_info(png_ptr, info_ptr); +# else + PNG_UNUSED(info_ptr) +# endif + } + + /* New in 1.6.0 this avoids the bug of doing the initializations twice */ + else + png_app_error(png_ptr, + "png_read_update_info/png_start_read_image: duplicate call"); + } +} + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Initialize palette, background, etc, after transformations + * are set, but before any reading takes place. This allows + * the user to obtain a gamma-corrected palette, for example. + * If the user doesn't call this, we will do it ourselves. + */ +void PNGAPI +png_start_read_image(png_structrp png_ptr) +{ + png_debug(1, "in png_start_read_image"); + + if (png_ptr != NULL) + { + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) + png_read_start_row(png_ptr); + + /* New in 1.6.0 this avoids the bug of doing the initializations twice */ + else + png_app_error(png_ptr, + "png_start_read_image/png_read_update_info: duplicate call"); + } +} +#endif /* SEQUENTIAL_READ */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +#ifdef PNG_MNG_FEATURES_SUPPORTED +/* Undoes intrapixel differencing, + * NOTE: this is apparently only supported in the 'sequential' reader. + */ +static void +png_do_read_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_intrapixel"); + + if ( + (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff); + *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff); + } + } + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (png_uint_32)(*(rp ) << 8) | *(rp + 1); + png_uint_32 s1 = (png_uint_32)(*(rp + 2) << 8) | *(rp + 3); + png_uint_32 s2 = (png_uint_32)(*(rp + 4) << 8) | *(rp + 5); + png_uint_32 red = (s0 + s1 + 65536) & 0xffff; + png_uint_32 blue = (s2 + s1 + 65536) & 0xffff; + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp + 1) = (png_byte)(red & 0xff); + *(rp + 4) = (png_byte)((blue >> 8) & 0xff); + *(rp + 5) = (png_byte)(blue & 0xff); + } + } + } +} +#endif /* MNG_FEATURES */ + +void PNGAPI +png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row) +{ + png_row_info row_info; + + if (png_ptr == NULL) + return; + + png_debug2(1, "in png_read_row (row %lu, pass %d)", + (unsigned long)png_ptr->row_number, png_ptr->pass); + + /* png_read_start_row sets the information (in particular iwidth) for this + * interlace pass. + */ + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) + png_read_start_row(png_ptr); + + /* 1.5.6: row_info moved out of png_struct to a local here. */ + row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ + row_info.color_type = png_ptr->color_type; + row_info.bit_depth = png_ptr->bit_depth; + row_info.channels = png_ptr->channels; + row_info.pixel_depth = png_ptr->pixel_depth; + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); + +#ifdef PNG_WARNINGS_SUPPORTED + if (png_ptr->row_number == 0 && png_ptr->pass == 0) + { + /* Check for transforms that have been set but were defined out */ +#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) + if ((png_ptr->transformations & PNG_INVERT_MONO) != 0) + png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) + if ((png_ptr->transformations & PNG_FILLER) != 0) + png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ + !defined(PNG_READ_PACKSWAP_SUPPORTED) + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) + if ((png_ptr->transformations & PNG_PACK) != 0) + png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) + if ((png_ptr->transformations & PNG_SHIFT) != 0) + png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) + if ((png_ptr->transformations & PNG_BGR) != 0) + png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) + if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0) + png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); +#endif + } +#endif /* WARNINGS */ + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* If interlaced and we do not need a new row, combine row and return. + * Notice that the pixels we have from previous rows have been transformed + * already; we can only combine like with like (transformed or + * untransformed) and, because of the libpng API for interlaced images, this + * means we must transform before de-interlacing. + */ + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0) + { + switch (png_ptr->pass) + { + case 0: + if (png_ptr->row_number & 0x07) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + png_read_finish_row(png_ptr); + return; + } + break; + + case 1: + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + case 2: + if ((png_ptr->row_number & 0x07) != 4) + { + if (dsp_row != NULL && (png_ptr->row_number & 4)) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + case 3: + if ((png_ptr->row_number & 3) || png_ptr->width < 3) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + case 4: + if ((png_ptr->row_number & 3) != 2) + { + if (dsp_row != NULL && (png_ptr->row_number & 2)) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + case 5: + if ((png_ptr->row_number & 1) || png_ptr->width < 2) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + default: + case 6: + if ((png_ptr->row_number & 1) == 0) + { + png_read_finish_row(png_ptr); + return; + } + break; + } + } +#endif + + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0) + png_error(png_ptr, "Invalid attempt to read row data"); + + /* Fill the row with IDAT data: */ + png_ptr->row_buf[0]=255; /* to force error if no data was found */ + png_read_IDAT_data(png_ptr, png_ptr->row_buf, row_info.rowbytes + 1); + + if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) + { + if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) + png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, + png_ptr->prev_row + 1, png_ptr->row_buf[0]); + else + png_error(png_ptr, "bad adaptive filter value"); + } + + /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before + * 1.5.6, while the buffer really is this big in current versions of libpng + * it may not be in the future, so this was changed just to copy the + * interlaced count: + */ + memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); + +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && + (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) + { + /* Intrapixel differencing */ + png_do_read_intrapixel(&row_info, png_ptr->row_buf + 1); + } +#endif + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED + if (png_ptr->transformations) + png_do_read_transformations(png_ptr, &row_info); +#endif + + /* The transformed pixel depth should match the depth now in row_info. */ + if (png_ptr->transformed_pixel_depth == 0) + { + png_ptr->transformed_pixel_depth = row_info.pixel_depth; + if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) + png_error(png_ptr, "sequential row overflow"); + } + + else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) + png_error(png_ptr, "internal sequential row size calculation error"); + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Expand interlaced rows to full size */ + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0) + { + if (png_ptr->pass < 6) + png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, + png_ptr->transformations); + + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + if (row != NULL) + png_combine_row(png_ptr, row, 0/*row*/); + } + + else +#endif + { + if (row != NULL) + png_combine_row(png_ptr, row, -1/*ignored*/); + + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, -1/*ignored*/); + } + png_read_finish_row(png_ptr); + + if (png_ptr->read_row_fn != NULL) + (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); + +} +#endif /* SEQUENTIAL_READ */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read one or more rows of image data. If the image is interlaced, + * and png_set_interlace_handling() has been called, the rows need to + * contain the contents of the rows from the previous pass. If the + * image has alpha or transparency, and png_handle_alpha()[*] has been + * called, the rows contents must be initialized to the contents of the + * screen. + * + * "row" holds the actual image, and pixels are placed in it + * as they arrive. If the image is displayed after each pass, it will + * appear to "sparkle" in. "display_row" can be used to display a + * "chunky" progressive image, with finer detail added as it becomes + * available. If you do not want this "chunky" display, you may pass + * NULL for display_row. If you do not want the sparkle display, and + * you have not called png_handle_alpha(), you may pass NULL for rows. + * If you have called png_handle_alpha(), and the image has either an + * alpha channel or a transparency chunk, you must provide a buffer for + * rows. In this case, you do not have to provide a display_row buffer + * also, but you may. If the image is not interlaced, or if you have + * not called png_set_interlace_handling(), the display_row buffer will + * be ignored, so pass NULL to it. + * + * [*] png_handle_alpha() does not exist yet, as of this version of libpng + */ + +void PNGAPI +png_read_rows(png_structrp png_ptr, png_bytepp row, + png_bytepp display_row, png_uint_32 num_rows) +{ + png_uint_32 i; + png_bytepp rp; + png_bytepp dp; + + png_debug(1, "in png_read_rows"); + + if (png_ptr == NULL) + return; + + rp = row; + dp = display_row; + if (rp != NULL && dp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep rptr = *rp++; + png_bytep dptr = *dp++; + + png_read_row(png_ptr, rptr, dptr); + } + + else if (rp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep rptr = *rp; + png_read_row(png_ptr, rptr, NULL); + rp++; + } + + else if (dp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep dptr = *dp; + png_read_row(png_ptr, NULL, dptr); + dp++; + } +} +#endif /* SEQUENTIAL_READ */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the entire image. If the image has an alpha channel or a tRNS + * chunk, and you have called png_handle_alpha()[*], you will need to + * initialize the image to the current image that PNG will be overlaying. + * We set the num_rows again here, in case it was incorrectly set in + * png_read_start_row() by a call to png_read_update_info() or + * png_start_read_image() if png_set_interlace_handling() wasn't called + * prior to either of these functions like it should have been. You can + * only call this function once. If you desire to have an image for + * each pass of a interlaced image, use png_read_rows() instead. + * + * [*] png_handle_alpha() does not exist yet, as of this version of libpng + */ +void PNGAPI +png_read_image(png_structrp png_ptr, png_bytepp image) +{ + png_uint_32 i, image_height; + int pass, j; + png_bytepp rp; + + png_debug(1, "in png_read_image"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) + { + pass = png_set_interlace_handling(png_ptr); + /* And make sure transforms are initialized. */ + png_start_read_image(png_ptr); + } + else + { + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) == 0) + { + /* Caller called png_start_read_image or png_read_update_info without + * first turning on the PNG_INTERLACE transform. We can fix this here, + * but the caller should do it! + */ + png_warning(png_ptr, "Interlace handling should be turned on when " + "using png_read_image"); + /* Make sure this is set correctly */ + png_ptr->num_rows = png_ptr->height; + } + + /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in + * the above error case. + */ + pass = png_set_interlace_handling(png_ptr); + } +#else + if (png_ptr->interlaced) + png_error(png_ptr, + "Cannot read interlaced image -- interlace handler disabled"); + + pass = 1; +#endif + + image_height=png_ptr->height; + + for (j = 0; j < pass; j++) + { + rp = image; + for (i = 0; i < image_height; i++) + { + png_read_row(png_ptr, *rp, NULL); + rp++; + } + } +} +#endif /* SEQUENTIAL_READ */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the end of the PNG file. Will not read past the end of the + * file, will verify the end is accurate, and will read any comments + * or time information at the end of the file, if info is not NULL. + */ +void PNGAPI +png_read_end(png_structrp png_ptr, png_inforp info_ptr) +{ +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + int keep; +#endif + + png_debug(1, "in png_read_end"); + + if (png_ptr == NULL) + return; + + /* If png_read_end is called in the middle of reading the rows there may + * still be pending IDAT data and an owned zstream. Deal with this here. + */ +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_chunk_unknown_handling(png_ptr, png_IDAT) == 0) +#endif + png_read_finish_IDAT(png_ptr); + +#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Report invalid palette index; added at libng-1.5.10 */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max > png_ptr->num_palette) + png_benign_error(png_ptr, "Read palette index exceeding num_palette"); +#endif + + do + { + png_uint_32 length = png_read_chunk_header(png_ptr); + png_uint_32 chunk_name = png_ptr->chunk_name; + + if (chunk_name != png_IDAT) + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + + if (chunk_name == png_IEND) + png_handle_IEND(png_ptr, info_ptr, length); + + else if (chunk_name == png_IHDR) + png_handle_IHDR(png_ptr, info_ptr, length); + + else if (info_ptr == NULL) + png_crc_finish(png_ptr, length); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0) + { + if (chunk_name == png_IDAT) + { + if ((length > 0 && !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED)) + || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0) + png_benign_error(png_ptr, ".Too many IDATs found"); + } + png_handle_unknown(png_ptr, info_ptr, length, keep); + if (chunk_name == png_PLTE) + png_ptr->mode |= PNG_HAVE_PLTE; + } +#endif + + else if (chunk_name == png_IDAT) + { + /* Zero length IDATs are legal after the last IDAT has been + * read, but not after other chunks have been read. 1.6 does not + * always read all the deflate data; specifically it cannot be relied + * upon to read the Adler32 at the end. If it doesn't ignore IDAT + * chunks which are longer than zero as well: + */ + if ((length > 0 && !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED)) + || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0) + png_benign_error(png_ptr, "..Too many IDATs found"); + + png_crc_finish(png_ptr, length); + } + else if (chunk_name == png_PLTE) + png_handle_PLTE(png_ptr, info_ptr, length); + +#ifdef PNG_READ_bKGD_SUPPORTED + else if (chunk_name == png_bKGD) + png_handle_bKGD(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED + else if (chunk_name == png_cHRM) + png_handle_cHRM(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_eXIf_SUPPORTED + else if (chunk_name == png_eXIf) + png_handle_eXIf(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_gAMA_SUPPORTED + else if (chunk_name == png_gAMA) + png_handle_gAMA(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_hIST_SUPPORTED + else if (chunk_name == png_hIST) + png_handle_hIST(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED + else if (chunk_name == png_oFFs) + png_handle_oFFs(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED + else if (chunk_name == png_pCAL) + png_handle_pCAL(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED + else if (chunk_name == png_sCAL) + png_handle_sCAL(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED + else if (chunk_name == png_pHYs) + png_handle_pHYs(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED + else if (chunk_name == png_sBIT) + png_handle_sBIT(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED + else if (chunk_name == png_sRGB) + png_handle_sRGB(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_iCCP_SUPPORTED + else if (chunk_name == png_iCCP) + png_handle_iCCP(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sPLT_SUPPORTED + else if (chunk_name == png_sPLT) + png_handle_sPLT(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED + else if (chunk_name == png_tEXt) + png_handle_tEXt(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tIME_SUPPORTED + else if (chunk_name == png_tIME) + png_handle_tIME(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tRNS_SUPPORTED + else if (chunk_name == png_tRNS) + png_handle_tRNS(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED + else if (chunk_name == png_zTXt) + png_handle_zTXt(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_iTXt_SUPPORTED + else if (chunk_name == png_iTXt) + png_handle_iTXt(png_ptr, info_ptr, length); +#endif + + else + png_handle_unknown(png_ptr, info_ptr, length, + PNG_HANDLE_CHUNK_AS_DEFAULT); + } while ((png_ptr->mode & PNG_HAVE_IEND) == 0); +} +#endif /* SEQUENTIAL_READ */ + +/* Free all memory used in the read struct */ +static void +png_read_destroy(png_structrp png_ptr) +{ + png_debug(1, "in png_read_destroy"); + +#ifdef PNG_READ_GAMMA_SUPPORTED + png_destroy_gamma_table(png_ptr); +#endif + + png_free(png_ptr, png_ptr->big_row_buf); + png_ptr->big_row_buf = NULL; + png_free(png_ptr, png_ptr->big_prev_row); + png_ptr->big_prev_row = NULL; + png_free(png_ptr, png_ptr->read_buffer); + png_ptr->read_buffer = NULL; + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + png_free(png_ptr, png_ptr->palette_lookup); + png_ptr->palette_lookup = NULL; + png_free(png_ptr, png_ptr->quantize_index); + png_ptr->quantize_index = NULL; +#endif + + if ((png_ptr->free_me & PNG_FREE_PLTE) != 0) + { + png_zfree(png_ptr, png_ptr->palette); + png_ptr->palette = NULL; + } + png_ptr->free_me &= ~PNG_FREE_PLTE; + +#if defined(PNG_tRNS_SUPPORTED) || \ + defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if ((png_ptr->free_me & PNG_FREE_TRNS) != 0) + { + png_free(png_ptr, png_ptr->trans_alpha); + png_ptr->trans_alpha = NULL; + } + png_ptr->free_me &= ~PNG_FREE_TRNS; +#endif + + inflateEnd(&png_ptr->zstream); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_free(png_ptr, png_ptr->save_buffer); + png_ptr->save_buffer = NULL; +#endif + +#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) && \ + defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; +#endif + +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list = NULL; +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) && \ + defined(PNG_ARM_NEON_IMPLEMENTATION) + png_free(png_ptr, png_ptr->riffled_palette); + png_ptr->riffled_palette = NULL; +#endif + + /* NOTE: the 'setjmp' buffer may still be allocated and the memory and error + * callbacks are still set at this point. They are required to complete the + * destruction of the png_struct itself. + */ +} + +/* Free all memory used by the read */ +void PNGAPI +png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, + png_infopp end_info_ptr_ptr) +{ + png_structrp png_ptr = NULL; + + png_debug(1, "in png_destroy_read_struct"); + + if (png_ptr_ptr != NULL) + png_ptr = *png_ptr_ptr; + + if (png_ptr == NULL) + return; + + /* libpng 1.6.0: use the API to destroy info structs to ensure consistent + * behavior. Prior to 1.6.0 libpng did extra 'info' destruction in this API. + * The extra was, apparently, unnecessary yet this hides memory leak bugs. + */ + png_destroy_info_struct(png_ptr, end_info_ptr_ptr); + png_destroy_info_struct(png_ptr, info_ptr_ptr); + + *png_ptr_ptr = NULL; + png_read_destroy(png_ptr); + png_destroy_png_struct(png_ptr); +} + +void PNGAPI +png_set_read_status_fn(png_structrp png_ptr, png_read_status_ptr read_row_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->read_row_fn = read_row_fn; +} + + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_read_png(png_structrp png_ptr, png_inforp info_ptr, + int transforms, voidp params) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* png_read_info() gives us all of the information from the + * PNG file before the first IDAT (image data chunk). + */ + png_read_info(png_ptr, info_ptr); + if (info_ptr->height > PNG_UINT_32_MAX/(sizeof (png_bytep))) + png_error(png_ptr, "Image is too high to process with png_read_png()"); + + /* -------------- image transformations start here ------------------- */ + /* libpng 1.6.10: add code to cause a png_app_error if a selected TRANSFORM + * is not implemented. This will only happen in de-configured (non-default) + * libpng builds. The results can be unexpected - png_read_png may return + * short or mal-formed rows because the transform is skipped. + */ + + /* Tell libpng to strip 16-bit/color files down to 8 bits per color. + */ + if ((transforms & PNG_TRANSFORM_SCALE_16) != 0) + /* Added at libpng-1.5.4. "strip_16" produces the same result that it + * did in earlier versions, while "scale_16" is now more accurate. + */ +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + png_set_scale_16(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SCALE_16 not supported"); +#endif + + /* If both SCALE and STRIP are required pngrtran will effectively cancel the + * latter by doing SCALE first. This is ok and allows apps not to check for + * which is supported to get the right answer. + */ + if ((transforms & PNG_TRANSFORM_STRIP_16) != 0) +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + png_set_strip_16(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_16 not supported"); +#endif + + /* Strip alpha bytes from the input data without combining with + * the background (not recommended). + */ + if ((transforms & PNG_TRANSFORM_STRIP_ALPHA) != 0) +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + png_set_strip_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_ALPHA not supported"); +#endif + + /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single + * byte into separate bytes (useful for paletted and grayscale images). + */ + if ((transforms & PNG_TRANSFORM_PACKING) != 0) +#ifdef PNG_READ_PACK_SUPPORTED + png_set_packing(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported"); +#endif + + /* Change the order of packed pixels to least significant bit first + * (not useful if you are using png_set_packing). + */ + if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0) +#ifdef PNG_READ_PACKSWAP_SUPPORTED + png_set_packswap(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported"); +#endif + + /* Expand paletted colors into true RGB triplets + * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel + * Expand paletted or RGB images with transparency to full alpha + * channels so the data will be available as RGBA quartets. + */ + if ((transforms & PNG_TRANSFORM_EXPAND) != 0) +#ifdef PNG_READ_EXPAND_SUPPORTED + png_set_expand(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND not supported"); +#endif + + /* We don't handle background color or gamma transformation or quantizing. + */ + + /* Invert monochrome files to have 0 as white and 1 as black + */ + if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0) +#ifdef PNG_READ_INVERT_SUPPORTED + png_set_invert_mono(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported"); +#endif + + /* If you want to shift the pixel values from the range [0,255] or + * [0,65535] to the original [0,7] or [0,31], or whatever range the + * colors were originally in: + */ + if ((transforms & PNG_TRANSFORM_SHIFT) != 0) +#ifdef PNG_READ_SHIFT_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sBIT) != 0) + png_set_shift(png_ptr, &info_ptr->sig_bit); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported"); +#endif + + /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ + if ((transforms & PNG_TRANSFORM_BGR) != 0) +#ifdef PNG_READ_BGR_SUPPORTED + png_set_bgr(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported"); +#endif + + /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ + if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0) +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED + png_set_swap_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported"); +#endif + + /* Swap bytes of 16-bit files to least significant byte first */ + if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0) +#ifdef PNG_READ_SWAP_SUPPORTED + png_set_swap(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported"); +#endif + +/* Added at libpng-1.2.41 */ + /* Invert the alpha channel from opacity to transparency */ + if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0) +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + png_set_invert_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported"); +#endif + +/* Added at libpng-1.2.41 */ + /* Expand grayscale image to RGB */ + if ((transforms & PNG_TRANSFORM_GRAY_TO_RGB) != 0) +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + png_set_gray_to_rgb(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_GRAY_TO_RGB not supported"); +#endif + +/* Added at libpng-1.5.4 */ + if ((transforms & PNG_TRANSFORM_EXPAND_16) != 0) +#ifdef PNG_READ_EXPAND_16_SUPPORTED + png_set_expand_16(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND_16 not supported"); +#endif + + /* We don't handle adding filler bytes */ + + /* We use png_read_image and rely on that for interlace handling, but we also + * call png_read_update_info therefore must turn on interlace handling now: + */ + (void)png_set_interlace_handling(png_ptr); + + /* Optional call to gamma correct and add the background to the palette + * and update info structure. REQUIRED if you are expecting libpng to + * update the palette for you (i.e., you selected such a transform above). + */ + png_read_update_info(png_ptr, info_ptr); + + /* -------------- image transformations end here ------------------- */ + + png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); + if (info_ptr->row_pointers == NULL) + { + png_uint_32 iptr; + + info_ptr->row_pointers = png_voidcast(png_bytepp, png_malloc(png_ptr, + info_ptr->height * (sizeof (png_bytep)))); + + for (iptr=0; iptrheight; iptr++) + info_ptr->row_pointers[iptr] = NULL; + + info_ptr->free_me |= PNG_FREE_ROWS; + + for (iptr = 0; iptr < info_ptr->height; iptr++) + info_ptr->row_pointers[iptr] = png_voidcast(png_bytep, + png_malloc(png_ptr, info_ptr->rowbytes)); + } + + png_read_image(png_ptr, info_ptr->row_pointers); + info_ptr->valid |= PNG_INFO_IDAT; + + /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ + png_read_end(png_ptr, info_ptr); + + PNG_UNUSED(params) +} +#endif /* INFO_IMAGE */ +#endif /* SEQUENTIAL_READ */ + +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +/* SIMPLIFIED READ + * + * This code currently relies on the sequential reader, though it could easily + * be made to work with the progressive one. + */ +/* Arguments to png_image_finish_read: */ + +/* Encoding of PNG data (used by the color-map code) */ +# define P_NOTSET 0 /* File encoding not yet known */ +# define P_sRGB 1 /* 8-bit encoded to sRGB gamma */ +# define P_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */ +# define P_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */ +# define P_LINEAR8 4 /* 8-bit linear: only from a file value */ + +/* Color-map processing: after libpng has run on the PNG image further + * processing may be needed to convert the data to color-map indices. + */ +#define PNG_CMAP_NONE 0 +#define PNG_CMAP_GA 1 /* Process GA data to a color-map with alpha */ +#define PNG_CMAP_TRANS 2 /* Process GA data to a background index */ +#define PNG_CMAP_RGB 3 /* Process RGB data */ +#define PNG_CMAP_RGB_ALPHA 4 /* Process RGBA data */ + +/* The following document where the background is for each processing case. */ +#define PNG_CMAP_NONE_BACKGROUND 256 +#define PNG_CMAP_GA_BACKGROUND 231 +#define PNG_CMAP_TRANS_BACKGROUND 254 +#define PNG_CMAP_RGB_BACKGROUND 256 +#define PNG_CMAP_RGB_ALPHA_BACKGROUND 216 + +typedef struct +{ + /* Arguments: */ + png_imagep image; + png_voidp buffer; + png_int_32 row_stride; + png_voidp colormap; + png_const_colorp background; + /* Local variables: */ + png_voidp local_row; + png_voidp first_row; + ptrdiff_t row_bytes; /* step between rows */ + int file_encoding; /* E_ values above */ + png_fixed_point gamma_to_linear; /* For P_FILE, reciprocal of gamma */ + int colormap_processing; /* PNG_CMAP_ values above */ +} png_image_read_control; + +/* Do all the *safe* initialization - 'safe' means that png_error won't be + * called, so setting up the jmp_buf is not required. This means that anything + * called from here must *not* call png_malloc - it has to call png_malloc_warn + * instead so that control is returned safely back to this routine. + */ +static int +png_image_read_init(png_imagep image) +{ + if (image->opaque == NULL) + { + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, image, + png_safe_error, png_safe_warning); + + /* And set the rest of the structure to NULL to ensure that the various + * fields are consistent. + */ + memset(image, 0, (sizeof *image)); + image->version = PNG_IMAGE_VERSION; + + if (png_ptr != NULL) + { + png_infop info_ptr = png_create_info_struct(png_ptr); + + if (info_ptr != NULL) + { + png_controlp control = png_voidcast(png_controlp, + png_malloc_warn(png_ptr, (sizeof *control))); + + if (control != NULL) + { + memset(control, 0, (sizeof *control)); + + control->png_ptr = png_ptr; + control->info_ptr = info_ptr; + control->for_write = 0; + + image->opaque = control; + return 1; + } + + /* Error clean up */ + png_destroy_info_struct(png_ptr, &info_ptr); + } + + png_destroy_read_struct(&png_ptr, NULL, NULL); + } + + return png_image_error(image, "png_image_read: out of memory"); + } + + return png_image_error(image, "png_image_read: opaque pointer not NULL"); +} + +/* Utility to find the base format of a PNG file from a png_struct. */ +static png_uint_32 +png_image_format(png_structrp png_ptr) +{ + png_uint_32 format = 0; + + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + format |= PNG_FORMAT_FLAG_COLOR; + + if ((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) + format |= PNG_FORMAT_FLAG_ALPHA; + + /* Use png_ptr here, not info_ptr, because by examination png_handle_tRNS + * sets the png_struct fields; that's all we are interested in here. The + * precise interaction with an app call to png_set_tRNS and PNG file reading + * is unclear. + */ + else if (png_ptr->num_trans > 0) + format |= PNG_FORMAT_FLAG_ALPHA; + + if (png_ptr->bit_depth == 16) + format |= PNG_FORMAT_FLAG_LINEAR; + + if ((png_ptr->color_type & PNG_COLOR_MASK_PALETTE) != 0) + format |= PNG_FORMAT_FLAG_COLORMAP; + + return format; +} + +/* Is the given gamma significantly different from sRGB? The test is the same + * one used in pngrtran.c when deciding whether to do gamma correction. The + * arithmetic optimizes the division by using the fact that the inverse of the + * file sRGB gamma is 2.2 + */ +static int +png_gamma_not_sRGB(png_fixed_point g) +{ + if (g < PNG_FP_1) + { + /* An uninitialized gamma is assumed to be sRGB for the simplified API. */ + if (g == 0) + return 0; + + return png_gamma_significant((g * 11 + 2)/5 /* i.e. *2.2, rounded */); + } + + return 1; +} + +/* Do the main body of a 'png_image_begin_read' function; read the PNG file + * header and fill in all the information. This is executed in a safe context, + * unlike the init routine above. + */ +static int +png_image_read_header(png_voidp argument) +{ + png_imagep image = png_voidcast(png_imagep, argument); + png_structrp png_ptr = image->opaque->png_ptr; + png_inforp info_ptr = image->opaque->info_ptr; + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED + png_set_benign_errors(png_ptr, 1/*warn*/); +#endif + png_read_info(png_ptr, info_ptr); + + /* Do this the fast way; just read directly out of png_struct. */ + image->width = png_ptr->width; + image->height = png_ptr->height; + + { + png_uint_32 format = png_image_format(png_ptr); + + image->format = format; + +#ifdef PNG_COLORSPACE_SUPPORTED + /* Does the colorspace match sRGB? If there is no color endpoint + * (colorant) information assume yes, otherwise require the + * 'ENDPOINTS_MATCHP_sRGB' colorspace flag to have been set. If the + * colorspace has been determined to be invalid ignore it. + */ + if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && ((png_ptr->colorspace.flags + & (PNG_COLORSPACE_HAVE_ENDPOINTS|PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB| + PNG_COLORSPACE_INVALID)) == PNG_COLORSPACE_HAVE_ENDPOINTS)) + image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB; +#endif + } + + /* We need the maximum number of entries regardless of the format the + * application sets here. + */ + { + png_uint_32 cmap_entries; + + switch (png_ptr->color_type) + { + case PNG_COLOR_TYPE_GRAY: + cmap_entries = 1U << png_ptr->bit_depth; + break; + + case PNG_COLOR_TYPE_PALETTE: + cmap_entries = (png_uint_32)png_ptr->num_palette; + break; + + default: + cmap_entries = 256; + break; + } + + if (cmap_entries > 256) + cmap_entries = 256; + + image->colormap_entries = cmap_entries; + } + + return 1; +} + +#ifdef PNG_STDIO_SUPPORTED +int PNGAPI +png_image_begin_read_from_stdio(png_imagep image, FILE* file) +{ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (file != NULL) + { + if (png_image_read_init(image) != 0) + { + /* This is slightly evil, but png_init_io doesn't do anything other + * than this and we haven't changed the standard IO functions so + * this saves a 'safe' function. + */ + image->opaque->png_ptr->io_ptr = file; + return png_safe_execute(image, png_image_read_header, image); + } + } + + else + return png_image_error(image, + "png_image_begin_read_from_stdio: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION"); + + return 0; +} + +int PNGAPI +png_image_begin_read_from_file(png_imagep image, const char *file_name) +{ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (file_name != NULL) + { + FILE *fp = fopen(file_name, "rb"); + + if (fp != NULL) + { + if (png_image_read_init(image) != 0) + { + image->opaque->png_ptr->io_ptr = fp; + image->opaque->owned_file = 1; + return png_safe_execute(image, png_image_read_header, image); + } + + /* Clean up: just the opened file. */ + (void)fclose(fp); + } + + else + return png_image_error(image, strerror(errno)); + } + + else + return png_image_error(image, + "png_image_begin_read_from_file: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION"); + + return 0; +} +#endif /* STDIO */ + +static void PNGCBAPI +png_image_memory_read(png_structp png_ptr, png_bytep out, size_t need) +{ + if (png_ptr != NULL) + { + png_imagep image = png_voidcast(png_imagep, png_ptr->io_ptr); + if (image != NULL) + { + png_controlp cp = image->opaque; + if (cp != NULL) + { + png_const_bytep memory = cp->memory; + size_t size = cp->size; + + if (memory != NULL && size >= need) + { + memcpy(out, memory, need); + cp->memory = memory + need; + cp->size = size - need; + return; + } + + png_error(png_ptr, "read beyond end of data"); + } + } + + png_error(png_ptr, "invalid memory read"); + } +} + +int PNGAPI png_image_begin_read_from_memory(png_imagep image, + png_const_voidp memory, size_t size) +{ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (memory != NULL && size > 0) + { + if (png_image_read_init(image) != 0) + { + /* Now set the IO functions to read from the memory buffer and + * store it into io_ptr. Again do this in-place to avoid calling a + * libpng function that requires error handling. + */ + image->opaque->memory = png_voidcast(png_const_bytep, memory); + image->opaque->size = size; + image->opaque->png_ptr->io_ptr = image; + image->opaque->png_ptr->read_data_fn = png_image_memory_read; + + return png_safe_execute(image, png_image_read_header, image); + } + } + + else + return png_image_error(image, + "png_image_begin_read_from_memory: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION"); + + return 0; +} + +/* Utility function to skip chunks that are not used by the simplified image + * read functions and an appropriate macro to call it. + */ +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +static void +png_image_skip_unused_chunks(png_structrp png_ptr) +{ + /* Prepare the reader to ignore all recognized chunks whose data will not + * be used, i.e., all chunks recognized by libpng except for those + * involved in basic image reading: + * + * IHDR, PLTE, IDAT, IEND + * + * Or image data handling: + * + * tRNS, bKGD, gAMA, cHRM, sRGB, [iCCP] and sBIT. + * + * This provides a small performance improvement and eliminates any + * potential vulnerability to security problems in the unused chunks. + * + * At present the iCCP chunk data isn't used, so iCCP chunk can be ignored + * too. This allows the simplified API to be compiled without iCCP support, + * however if the support is there the chunk is still checked to detect + * errors (which are unfortunately quite common.) + */ + { + static const png_byte chunks_to_process[] = { + 98, 75, 71, 68, '\0', /* bKGD */ + 99, 72, 82, 77, '\0', /* cHRM */ + 103, 65, 77, 65, '\0', /* gAMA */ +# ifdef PNG_READ_iCCP_SUPPORTED + 105, 67, 67, 80, '\0', /* iCCP */ +# endif + 115, 66, 73, 84, '\0', /* sBIT */ + 115, 82, 71, 66, '\0', /* sRGB */ + }; + + /* Ignore unknown chunks and all other chunks except for the + * IHDR, PLTE, tRNS, IDAT, and IEND chunks. + */ + png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_NEVER, + NULL, -1); + + /* But do not ignore image data handling chunks */ + png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT, + chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5); + } +} + +# define PNG_SKIP_CHUNKS(p) png_image_skip_unused_chunks(p) +#else +# define PNG_SKIP_CHUNKS(p) ((void)0) +#endif /* HANDLE_AS_UNKNOWN */ + +/* The following macro gives the exact rounded answer for all values in the + * range 0..255 (it actually divides by 51.2, but the rounding still generates + * the correct numbers 0..5 + */ +#define PNG_DIV51(v8) (((v8) * 5 + 130) >> 8) + +/* Utility functions to make particular color-maps */ +static void +set_file_encoding(png_image_read_control *display) +{ + png_fixed_point g = display->image->opaque->png_ptr->colorspace.gamma; + if (png_gamma_significant(g) != 0) + { + if (png_gamma_not_sRGB(g) != 0) + { + display->file_encoding = P_FILE; + display->gamma_to_linear = png_reciprocal(g); + } + + else + display->file_encoding = P_sRGB; + } + + else + display->file_encoding = P_LINEAR8; +} + +static unsigned int +decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding) +{ + if (encoding == P_FILE) /* double check */ + encoding = display->file_encoding; + + if (encoding == P_NOTSET) /* must be the file encoding */ + { + set_file_encoding(display); + encoding = display->file_encoding; + } + + switch (encoding) + { + case P_FILE: + value = png_gamma_16bit_correct(value*257, display->gamma_to_linear); + break; + + case P_sRGB: + value = png_sRGB_table[value]; + break; + + case P_LINEAR: + break; + + case P_LINEAR8: + value *= 257; + break; + +#ifdef __GNUC__ + default: + png_error(display->image->opaque->png_ptr, + "unexpected encoding (internal error)"); +#endif + } + + return value; +} + +static png_uint_32 +png_colormap_compose(png_image_read_control *display, + png_uint_32 foreground, int foreground_encoding, png_uint_32 alpha, + png_uint_32 background, int encoding) +{ + /* The file value is composed on the background, the background has the given + * encoding and so does the result, the file is encoded with P_FILE and the + * file and alpha are 8-bit values. The (output) encoding will always be + * P_LINEAR or P_sRGB. + */ + png_uint_32 f = decode_gamma(display, foreground, foreground_encoding); + png_uint_32 b = decode_gamma(display, background, encoding); + + /* The alpha is always an 8-bit value (it comes from the palette), the value + * scaled by 255 is what PNG_sRGB_FROM_LINEAR requires. + */ + f = f * alpha + b * (255-alpha); + + if (encoding == P_LINEAR) + { + /* Scale to 65535; divide by 255, approximately (in fact this is extremely + * accurate, it divides by 255.00000005937181414556, with no overflow.) + */ + f *= 257; /* Now scaled by 65535 */ + f += f >> 16; + f = (f+32768) >> 16; + } + + else /* P_sRGB */ + f = PNG_sRGB_FROM_LINEAR(f); + + return f; +} + +/* NOTE: P_LINEAR values to this routine must be 16-bit, but P_FILE values must + * be 8-bit. + */ +static void +png_create_colormap_entry(png_image_read_control *display, + png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue, + png_uint_32 alpha, int encoding) +{ + png_imagep image = display->image; + int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ? + P_LINEAR : P_sRGB; + int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 && + (red != green || green != blue); + + if (ip > 255) + png_error(image->opaque->png_ptr, "color-map index out of range"); + + /* Update the cache with whether the file gamma is significantly different + * from sRGB. + */ + if (encoding == P_FILE) + { + if (display->file_encoding == P_NOTSET) + set_file_encoding(display); + + /* Note that the cached value may be P_FILE too, but if it is then the + * gamma_to_linear member has been set. + */ + encoding = display->file_encoding; + } + + if (encoding == P_FILE) + { + png_fixed_point g = display->gamma_to_linear; + + red = png_gamma_16bit_correct(red*257, g); + green = png_gamma_16bit_correct(green*257, g); + blue = png_gamma_16bit_correct(blue*257, g); + + if (convert_to_Y != 0 || output_encoding == P_LINEAR) + { + alpha *= 257; + encoding = P_LINEAR; + } + + else + { + red = PNG_sRGB_FROM_LINEAR(red * 255); + green = PNG_sRGB_FROM_LINEAR(green * 255); + blue = PNG_sRGB_FROM_LINEAR(blue * 255); + encoding = P_sRGB; + } + } + + else if (encoding == P_LINEAR8) + { + /* This encoding occurs quite frequently in test cases because PngSuite + * includes a gAMA 1.0 chunk with most images. + */ + red *= 257; + green *= 257; + blue *= 257; + alpha *= 257; + encoding = P_LINEAR; + } + + else if (encoding == P_sRGB && + (convert_to_Y != 0 || output_encoding == P_LINEAR)) + { + /* The values are 8-bit sRGB values, but must be converted to 16-bit + * linear. + */ + red = png_sRGB_table[red]; + green = png_sRGB_table[green]; + blue = png_sRGB_table[blue]; + alpha *= 257; + encoding = P_LINEAR; + } + + /* This is set if the color isn't gray but the output is. */ + if (encoding == P_LINEAR) + { + if (convert_to_Y != 0) + { + /* NOTE: these values are copied from png_do_rgb_to_gray */ + png_uint_32 y = (png_uint_32)6968 * red + (png_uint_32)23434 * green + + (png_uint_32)2366 * blue; + + if (output_encoding == P_LINEAR) + y = (y + 16384) >> 15; + + else + { + /* y is scaled by 32768, we need it scaled by 255: */ + y = (y + 128) >> 8; + y *= 255; + y = PNG_sRGB_FROM_LINEAR((y + 64) >> 7); + alpha = PNG_DIV257(alpha); + encoding = P_sRGB; + } + + blue = red = green = y; + } + + else if (output_encoding == P_sRGB) + { + red = PNG_sRGB_FROM_LINEAR(red * 255); + green = PNG_sRGB_FROM_LINEAR(green * 255); + blue = PNG_sRGB_FROM_LINEAR(blue * 255); + alpha = PNG_DIV257(alpha); + encoding = P_sRGB; + } + } + + if (encoding != output_encoding) + png_error(image->opaque->png_ptr, "bad encoding (internal error)"); + + /* Store the value. */ + { +# ifdef PNG_FORMAT_AFIRST_SUPPORTED + int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 && + (image->format & PNG_FORMAT_FLAG_ALPHA) != 0; +# else +# define afirst 0 +# endif +# ifdef PNG_FORMAT_BGR_SUPPORTED + int bgr = (image->format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0; +# else +# define bgr 0 +# endif + + if (output_encoding == P_LINEAR) + { + png_uint_16p entry = png_voidcast(png_uint_16p, display->colormap); + + entry += ip * PNG_IMAGE_SAMPLE_CHANNELS(image->format); + + /* The linear 16-bit values must be pre-multiplied by the alpha channel + * value, if less than 65535 (this is, effectively, composite on black + * if the alpha channel is removed.) + */ + switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format)) + { + case 4: + entry[afirst ? 0 : 3] = (png_uint_16)alpha; + /* FALLTHROUGH */ + + case 3: + if (alpha < 65535) + { + if (alpha > 0) + { + blue = (blue * alpha + 32767U)/65535U; + green = (green * alpha + 32767U)/65535U; + red = (red * alpha + 32767U)/65535U; + } + + else + red = green = blue = 0; + } + entry[afirst + (2 ^ bgr)] = (png_uint_16)blue; + entry[afirst + 1] = (png_uint_16)green; + entry[afirst + bgr] = (png_uint_16)red; + break; + + case 2: + entry[1 ^ afirst] = (png_uint_16)alpha; + /* FALLTHROUGH */ + + case 1: + if (alpha < 65535) + { + if (alpha > 0) + green = (green * alpha + 32767U)/65535U; + + else + green = 0; + } + entry[afirst] = (png_uint_16)green; + break; + + default: + break; + } + } + + else /* output encoding is P_sRGB */ + { + png_bytep entry = png_voidcast(png_bytep, display->colormap); + + entry += ip * PNG_IMAGE_SAMPLE_CHANNELS(image->format); + + switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format)) + { + case 4: + entry[afirst ? 0 : 3] = (png_byte)alpha; + /* FALLTHROUGH */ + case 3: + entry[afirst + (2 ^ bgr)] = (png_byte)blue; + entry[afirst + 1] = (png_byte)green; + entry[afirst + bgr] = (png_byte)red; + break; + + case 2: + entry[1 ^ afirst] = (png_byte)alpha; + /* FALLTHROUGH */ + case 1: + entry[afirst] = (png_byte)green; + break; + + default: + break; + } + } + +# ifdef afirst +# undef afirst +# endif +# ifdef bgr +# undef bgr +# endif + } +} + +static int +make_gray_file_colormap(png_image_read_control *display) +{ + unsigned int i; + + for (i=0; i<256; ++i) + png_create_colormap_entry(display, i, i, i, i, 255, P_FILE); + + return (int)i; +} + +static int +make_gray_colormap(png_image_read_control *display) +{ + unsigned int i; + + for (i=0; i<256; ++i) + png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB); + + return (int)i; +} +#define PNG_GRAY_COLORMAP_ENTRIES 256 + +static int +make_ga_colormap(png_image_read_control *display) +{ + unsigned int i, a; + + /* Alpha is retained, the output will be a color-map with entries + * selected by six levels of alpha. One transparent entry, 6 gray + * levels for all the intermediate alpha values, leaving 230 entries + * for the opaque grays. The color-map entries are the six values + * [0..5]*51, the GA processing uses PNG_DIV51(value) to find the + * relevant entry. + * + * if (alpha > 229) // opaque + * { + * // The 231 entries are selected to make the math below work: + * base = 0; + * entry = (231 * gray + 128) >> 8; + * } + * else if (alpha < 26) // transparent + * { + * base = 231; + * entry = 0; + * } + * else // partially opaque + * { + * base = 226 + 6 * PNG_DIV51(alpha); + * entry = PNG_DIV51(gray); + * } + */ + i = 0; + while (i < 231) + { + unsigned int gray = (i * 256 + 115) / 231; + png_create_colormap_entry(display, i++, gray, gray, gray, 255, P_sRGB); + } + + /* 255 is used here for the component values for consistency with the code + * that undoes premultiplication in pngwrite.c. + */ + png_create_colormap_entry(display, i++, 255, 255, 255, 0, P_sRGB); + + for (a=1; a<5; ++a) + { + unsigned int g; + + for (g=0; g<6; ++g) + png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51, + P_sRGB); + } + + return (int)i; +} + +#define PNG_GA_COLORMAP_ENTRIES 256 + +static int +make_rgb_colormap(png_image_read_control *display) +{ + unsigned int i, r; + + /* Build a 6x6x6 opaque RGB cube */ + for (i=r=0; r<6; ++r) + { + unsigned int g; + + for (g=0; g<6; ++g) + { + unsigned int b; + + for (b=0; b<6; ++b) + png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255, + P_sRGB); + } + } + + return (int)i; +} + +#define PNG_RGB_COLORMAP_ENTRIES 216 + +/* Return a palette index to the above palette given three 8-bit sRGB values. */ +#define PNG_RGB_INDEX(r,g,b) \ + ((png_byte)(6 * (6 * PNG_DIV51(r) + PNG_DIV51(g)) + PNG_DIV51(b))) + +static int +png_image_read_colormap(png_voidp argument) +{ + png_image_read_control *display = + png_voidcast(png_image_read_control*, argument); + png_imagep image = display->image; + + png_structrp png_ptr = image->opaque->png_ptr; + png_uint_32 output_format = image->format; + int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) != 0 ? + P_LINEAR : P_sRGB; + + unsigned int cmap_entries; + unsigned int output_processing; /* Output processing option */ + unsigned int data_encoding = P_NOTSET; /* Encoding libpng must produce */ + + /* Background information; the background color and the index of this color + * in the color-map if it exists (else 256). + */ + unsigned int background_index = 256; + png_uint_32 back_r, back_g, back_b; + + /* Flags to accumulate things that need to be done to the input. */ + int expand_tRNS = 0; + + /* Exclude the NYI feature of compositing onto a color-mapped buffer; it is + * very difficult to do, the results look awful, and it is difficult to see + * what possible use it is because the application can't control the + * color-map. + */ + if (((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0 || + png_ptr->num_trans > 0) /* alpha in input */ && + ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) /* no alpha in output */) + { + if (output_encoding == P_LINEAR) /* compose on black */ + back_b = back_g = back_r = 0; + + else if (display->background == NULL /* no way to remove it */) + png_error(png_ptr, + "background color must be supplied to remove alpha/transparency"); + + /* Get a copy of the background color (this avoids repeating the checks + * below.) The encoding is 8-bit sRGB or 16-bit linear, depending on the + * output format. + */ + else + { + back_g = display->background->green; + if ((output_format & PNG_FORMAT_FLAG_COLOR) != 0) + { + back_r = display->background->red; + back_b = display->background->blue; + } + else + back_b = back_r = back_g; + } + } + + else if (output_encoding == P_LINEAR) + back_b = back_r = back_g = 65535; + + else + back_b = back_r = back_g = 255; + + /* Default the input file gamma if required - this is necessary because + * libpng assumes that if no gamma information is present the data is in the + * output format, but the simplified API deduces the gamma from the input + * format. + */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) == 0) + { + /* Do this directly, not using the png_colorspace functions, to ensure + * that it happens even if the colorspace is invalid (though probably if + * it is the setting will be ignored) Note that the same thing can be + * achieved at the application interface with png_set_gAMA. + */ + if (png_ptr->bit_depth == 16 && + (image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0) + png_ptr->colorspace.gamma = PNG_GAMMA_LINEAR; + + else + png_ptr->colorspace.gamma = PNG_GAMMA_sRGB_INVERSE; + + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; + } + + /* Decide what to do based on the PNG color type of the input data. The + * utility function png_create_colormap_entry deals with most aspects of the + * output transformations; this code works out how to produce bytes of + * color-map entries from the original format. + */ + switch (png_ptr->color_type) + { + case PNG_COLOR_TYPE_GRAY: + if (png_ptr->bit_depth <= 8) + { + /* There at most 256 colors in the output, regardless of + * transparency. + */ + unsigned int step, i, val, trans = 256/*ignore*/, back_alpha = 0; + + cmap_entries = 1U << png_ptr->bit_depth; + if (cmap_entries > image->colormap_entries) + png_error(png_ptr, "gray[8] color-map: too few entries"); + + step = 255 / (cmap_entries - 1); + output_processing = PNG_CMAP_NONE; + + /* If there is a tRNS chunk then this either selects a transparent + * value or, if the output has no alpha, the background color. + */ + if (png_ptr->num_trans > 0) + { + trans = png_ptr->trans_color.gray; + + if ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) + back_alpha = output_encoding == P_LINEAR ? 65535 : 255; + } + + /* png_create_colormap_entry just takes an RGBA and writes the + * corresponding color-map entry using the format from 'image', + * including the required conversion to sRGB or linear as + * appropriate. The input values are always either sRGB (if the + * gamma correction flag is 0) or 0..255 scaled file encoded values + * (if the function must gamma correct them). + */ + for (i=val=0; ibit_depth < 8) + png_set_packing(png_ptr); + } + + else /* bit depth is 16 */ + { + /* The 16-bit input values can be converted directly to 8-bit gamma + * encoded values; however, if a tRNS chunk is present 257 color-map + * entries are required. This means that the extra entry requires + * special processing; add an alpha channel, sacrifice gray level + * 254 and convert transparent (alpha==0) entries to that. + * + * Use libpng to chop the data to 8 bits. Convert it to sRGB at the + * same time to minimize quality loss. If a tRNS chunk is present + * this means libpng must handle it too; otherwise it is impossible + * to do the exact match on the 16-bit value. + * + * If the output has no alpha channel *and* the background color is + * gray then it is possible to let libpng handle the substitution by + * ensuring that the corresponding gray level matches the background + * color exactly. + */ + data_encoding = P_sRGB; + + if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "gray[16] color-map: too few entries"); + + cmap_entries = (unsigned int)make_gray_colormap(display); + + if (png_ptr->num_trans > 0) + { + unsigned int back_alpha; + + if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0) + back_alpha = 0; + + else + { + if (back_r == back_g && back_g == back_b) + { + /* Background is gray; no special processing will be + * required. + */ + png_color_16 c; + png_uint_32 gray = back_g; + + if (output_encoding == P_LINEAR) + { + gray = PNG_sRGB_FROM_LINEAR(gray * 255); + + /* And make sure the corresponding palette entry + * matches. + */ + png_create_colormap_entry(display, gray, back_g, back_g, + back_g, 65535, P_LINEAR); + } + + /* The background passed to libpng, however, must be the + * sRGB value. + */ + c.index = 0; /*unused*/ + c.gray = c.red = c.green = c.blue = (png_uint_16)gray; + + /* NOTE: does this work without expanding tRNS to alpha? + * It should be the color->gray case below apparently + * doesn't. + */ + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + + output_processing = PNG_CMAP_NONE; + break; + } +#ifdef __COVERITY__ + /* Coverity claims that output_encoding cannot be 2 (P_LINEAR) + * here. + */ + back_alpha = 255; +#else + back_alpha = output_encoding == P_LINEAR ? 65535 : 255; +#endif + } + + /* output_processing means that the libpng-processed row will be + * 8-bit GA and it has to be processing to single byte color-map + * values. Entry 254 is replaced by either a completely + * transparent entry or by the background color at full + * precision (and the background color is not a simple gray + * level in this case.) + */ + expand_tRNS = 1; + output_processing = PNG_CMAP_TRANS; + background_index = 254; + + /* And set (overwrite) color-map entry 254 to the actual + * background color at full precision. + */ + png_create_colormap_entry(display, 254, back_r, back_g, back_b, + back_alpha, output_encoding); + } + + else + output_processing = PNG_CMAP_NONE; + } + break; + + case PNG_COLOR_TYPE_GRAY_ALPHA: + /* 8-bit or 16-bit PNG with two channels - gray and alpha. A minimum + * of 65536 combinations. If, however, the alpha channel is to be + * removed there are only 256 possibilities if the background is gray. + * (Otherwise there is a subset of the 65536 possibilities defined by + * the triangle between black, white and the background color.) + * + * Reduce 16-bit files to 8-bit and sRGB encode the result. No need to + * worry about tRNS matching - tRNS is ignored if there is an alpha + * channel. + */ + data_encoding = P_sRGB; + + if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "gray+alpha color-map: too few entries"); + + cmap_entries = (unsigned int)make_ga_colormap(display); + + background_index = PNG_CMAP_GA_BACKGROUND; + output_processing = PNG_CMAP_GA; + } + + else /* alpha is removed */ + { + /* Alpha must be removed as the PNG data is processed when the + * background is a color because the G and A channels are + * independent and the vector addition (non-parallel vectors) is a + * 2-D problem. + * + * This can be reduced to the same algorithm as above by making a + * colormap containing gray levels (for the opaque grays), a + * background entry (for a transparent pixel) and a set of four six + * level color values, one set for each intermediate alpha value. + * See the comments in make_ga_colormap for how this works in the + * per-pixel processing. + * + * If the background is gray, however, we only need a 256 entry gray + * level color map. It is sufficient to make the entry generated + * for the background color be exactly the color specified. + */ + if ((output_format & PNG_FORMAT_FLAG_COLOR) == 0 || + (back_r == back_g && back_g == back_b)) + { + /* Background is gray; no special processing will be required. */ + png_color_16 c; + png_uint_32 gray = back_g; + + if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "gray-alpha color-map: too few entries"); + + cmap_entries = (unsigned int)make_gray_colormap(display); + + if (output_encoding == P_LINEAR) + { + gray = PNG_sRGB_FROM_LINEAR(gray * 255); + + /* And make sure the corresponding palette entry matches. */ + png_create_colormap_entry(display, gray, back_g, back_g, + back_g, 65535, P_LINEAR); + } + + /* The background passed to libpng, however, must be the sRGB + * value. + */ + c.index = 0; /*unused*/ + c.gray = c.red = c.green = c.blue = (png_uint_16)gray; + + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + + output_processing = PNG_CMAP_NONE; + } + + else + { + png_uint_32 i, a; + + /* This is the same as png_make_ga_colormap, above, except that + * the entries are all opaque. + */ + if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "ga-alpha color-map: too few entries"); + + i = 0; + while (i < 231) + { + png_uint_32 gray = (i * 256 + 115) / 231; + png_create_colormap_entry(display, i++, gray, gray, gray, + 255, P_sRGB); + } + + /* NOTE: this preserves the full precision of the application + * background color. + */ + background_index = i; + png_create_colormap_entry(display, i++, back_r, back_g, back_b, +#ifdef __COVERITY__ + /* Coverity claims that output_encoding + * cannot be 2 (P_LINEAR) here. + */ 255U, +#else + output_encoding == P_LINEAR ? 65535U : 255U, +#endif + output_encoding); + + /* For non-opaque input composite on the sRGB background - this + * requires inverting the encoding for each component. The input + * is still converted to the sRGB encoding because this is a + * reasonable approximate to the logarithmic curve of human + * visual sensitivity, at least over the narrow range which PNG + * represents. Consequently 'G' is always sRGB encoded, while + * 'A' is linear. We need the linear background colors. + */ + if (output_encoding == P_sRGB) /* else already linear */ + { + /* This may produce a value not exactly matching the + * background, but that's ok because these numbers are only + * used when alpha != 0 + */ + back_r = png_sRGB_table[back_r]; + back_g = png_sRGB_table[back_g]; + back_b = png_sRGB_table[back_b]; + } + + for (a=1; a<5; ++a) + { + unsigned int g; + + /* PNG_sRGB_FROM_LINEAR expects a 16-bit linear value scaled + * by an 8-bit alpha value (0..255). + */ + png_uint_32 alpha = 51 * a; + png_uint_32 back_rx = (255-alpha) * back_r; + png_uint_32 back_gx = (255-alpha) * back_g; + png_uint_32 back_bx = (255-alpha) * back_b; + + for (g=0; g<6; ++g) + { + png_uint_32 gray = png_sRGB_table[g*51] * alpha; + + png_create_colormap_entry(display, i++, + PNG_sRGB_FROM_LINEAR(gray + back_rx), + PNG_sRGB_FROM_LINEAR(gray + back_gx), + PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB); + } + } + + cmap_entries = i; + output_processing = PNG_CMAP_GA; + } + } + break; + + case PNG_COLOR_TYPE_RGB: + case PNG_COLOR_TYPE_RGB_ALPHA: + /* Exclude the case where the output is gray; we can always handle this + * with the cases above. + */ + if ((output_format & PNG_FORMAT_FLAG_COLOR) == 0) + { + /* The color-map will be grayscale, so we may as well convert the + * input RGB values to a simple grayscale and use the grayscale + * code above. + * + * NOTE: calling this apparently damages the recognition of the + * transparent color in background color handling; call + * png_set_tRNS_to_alpha before png_set_background_fixed. + */ + png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1, + -1); + data_encoding = P_sRGB; + + /* The output will now be one or two 8-bit gray or gray+alpha + * channels. The more complex case arises when the input has alpha. + */ + if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + png_ptr->num_trans > 0) && + (output_format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + /* Both input and output have an alpha channel, so no background + * processing is required; just map the GA bytes to the right + * color-map entry. + */ + expand_tRNS = 1; + + if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "rgb[ga] color-map: too few entries"); + + cmap_entries = (unsigned int)make_ga_colormap(display); + background_index = PNG_CMAP_GA_BACKGROUND; + output_processing = PNG_CMAP_GA; + } + + else + { + /* Either the input or the output has no alpha channel, so there + * will be no non-opaque pixels in the color-map; it will just be + * grayscale. + */ + if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "rgb[gray] color-map: too few entries"); + + /* Ideally this code would use libpng to do the gamma correction, + * but if an input alpha channel is to be removed we will hit the + * libpng bug in gamma+compose+rgb-to-gray (the double gamma + * correction bug). Fix this by dropping the gamma correction in + * this case and doing it in the palette; this will result in + * duplicate palette entries, but that's better than the + * alternative of double gamma correction. + */ + if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + png_ptr->num_trans > 0) && + png_gamma_not_sRGB(png_ptr->colorspace.gamma) != 0) + { + cmap_entries = (unsigned int)make_gray_file_colormap(display); + data_encoding = P_FILE; + } + + else + cmap_entries = (unsigned int)make_gray_colormap(display); + + /* But if the input has alpha or transparency it must be removed + */ + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + png_ptr->num_trans > 0) + { + png_color_16 c; + png_uint_32 gray = back_g; + + /* We need to ensure that the application background exists in + * the colormap and that completely transparent pixels map to + * it. Achieve this simply by ensuring that the entry + * selected for the background really is the background color. + */ + if (data_encoding == P_FILE) /* from the fixup above */ + { + /* The app supplied a gray which is in output_encoding, we + * need to convert it to a value of the input (P_FILE) + * encoding then set this palette entry to the required + * output encoding. + */ + if (output_encoding == P_sRGB) + gray = png_sRGB_table[gray]; /* now P_LINEAR */ + + gray = PNG_DIV257(png_gamma_16bit_correct(gray, + png_ptr->colorspace.gamma)); /* now P_FILE */ + + /* And make sure the corresponding palette entry contains + * exactly the required sRGB value. + */ + png_create_colormap_entry(display, gray, back_g, back_g, + back_g, 0/*unused*/, output_encoding); + } + + else if (output_encoding == P_LINEAR) + { + gray = PNG_sRGB_FROM_LINEAR(gray * 255); + + /* And make sure the corresponding palette entry matches. + */ + png_create_colormap_entry(display, gray, back_g, back_g, + back_g, 0/*unused*/, P_LINEAR); + } + + /* The background passed to libpng, however, must be the + * output (normally sRGB) value. + */ + c.index = 0; /*unused*/ + c.gray = c.red = c.green = c.blue = (png_uint_16)gray; + + /* NOTE: the following is apparently a bug in libpng. Without + * it the transparent color recognition in + * png_set_background_fixed seems to go wrong. + */ + expand_tRNS = 1; + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + } + + output_processing = PNG_CMAP_NONE; + } + } + + else /* output is color */ + { + /* We could use png_quantize here so long as there is no transparent + * color or alpha; png_quantize ignores alpha. Easier overall just + * to do it once and using PNG_DIV51 on the 6x6x6 reduced RGB cube. + * Consequently we always want libpng to produce sRGB data. + */ + data_encoding = P_sRGB; + + /* Is there any transparency or alpha? */ + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + png_ptr->num_trans > 0) + { + /* Is there alpha in the output too? If so all four channels are + * processed into a special RGB cube with alpha support. + */ + if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + png_uint_32 r; + + if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries) + png_error(png_ptr, "rgb+alpha color-map: too few entries"); + + cmap_entries = (unsigned int)make_rgb_colormap(display); + + /* Add a transparent entry. */ + png_create_colormap_entry(display, cmap_entries, 255, 255, + 255, 0, P_sRGB); + + /* This is stored as the background index for the processing + * algorithm. + */ + background_index = cmap_entries++; + + /* Add 27 r,g,b entries each with alpha 0.5. */ + for (r=0; r<256; r = (r << 1) | 0x7f) + { + png_uint_32 g; + + for (g=0; g<256; g = (g << 1) | 0x7f) + { + png_uint_32 b; + + /* This generates components with the values 0, 127 and + * 255 + */ + for (b=0; b<256; b = (b << 1) | 0x7f) + png_create_colormap_entry(display, cmap_entries++, + r, g, b, 128, P_sRGB); + } + } + + expand_tRNS = 1; + output_processing = PNG_CMAP_RGB_ALPHA; + } + + else + { + /* Alpha/transparency must be removed. The background must + * exist in the color map (achieved by setting adding it after + * the 666 color-map). If the standard processing code will + * pick up this entry automatically that's all that is + * required; libpng can be called to do the background + * processing. + */ + unsigned int sample_size = + PNG_IMAGE_SAMPLE_SIZE(output_format); + png_uint_32 r, g, b; /* sRGB background */ + + if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries) + png_error(png_ptr, "rgb-alpha color-map: too few entries"); + + cmap_entries = (unsigned int)make_rgb_colormap(display); + + png_create_colormap_entry(display, cmap_entries, back_r, + back_g, back_b, 0/*unused*/, output_encoding); + + if (output_encoding == P_LINEAR) + { + r = PNG_sRGB_FROM_LINEAR(back_r * 255); + g = PNG_sRGB_FROM_LINEAR(back_g * 255); + b = PNG_sRGB_FROM_LINEAR(back_b * 255); + } + + else + { + r = back_r; + g = back_g; + b = back_g; + } + + /* Compare the newly-created color-map entry with the one the + * PNG_CMAP_RGB algorithm will use. If the two entries don't + * match, add the new one and set this as the background + * index. + */ + if (memcmp((png_const_bytep)display->colormap + + sample_size * cmap_entries, + (png_const_bytep)display->colormap + + sample_size * PNG_RGB_INDEX(r,g,b), + sample_size) != 0) + { + /* The background color must be added. */ + background_index = cmap_entries++; + + /* Add 27 r,g,b entries each with created by composing with + * the background at alpha 0.5. + */ + for (r=0; r<256; r = (r << 1) | 0x7f) + { + for (g=0; g<256; g = (g << 1) | 0x7f) + { + /* This generates components with the values 0, 127 + * and 255 + */ + for (b=0; b<256; b = (b << 1) | 0x7f) + png_create_colormap_entry(display, cmap_entries++, + png_colormap_compose(display, r, P_sRGB, 128, + back_r, output_encoding), + png_colormap_compose(display, g, P_sRGB, 128, + back_g, output_encoding), + png_colormap_compose(display, b, P_sRGB, 128, + back_b, output_encoding), + 0/*unused*/, output_encoding); + } + } + + expand_tRNS = 1; + output_processing = PNG_CMAP_RGB_ALPHA; + } + + else /* background color is in the standard color-map */ + { + png_color_16 c; + + c.index = 0; /*unused*/ + c.red = (png_uint_16)back_r; + c.gray = c.green = (png_uint_16)back_g; + c.blue = (png_uint_16)back_b; + + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + + output_processing = PNG_CMAP_RGB; + } + } + } + + else /* no alpha or transparency in the input */ + { + /* Alpha in the output is irrelevant, simply map the opaque input + * pixels to the 6x6x6 color-map. + */ + if (PNG_RGB_COLORMAP_ENTRIES > image->colormap_entries) + png_error(png_ptr, "rgb color-map: too few entries"); + + cmap_entries = (unsigned int)make_rgb_colormap(display); + output_processing = PNG_CMAP_RGB; + } + } + break; + + case PNG_COLOR_TYPE_PALETTE: + /* It's already got a color-map. It may be necessary to eliminate the + * tRNS entries though. + */ + { + unsigned int num_trans = png_ptr->num_trans; + png_const_bytep trans = num_trans > 0 ? png_ptr->trans_alpha : NULL; + png_const_colorp colormap = png_ptr->palette; + int do_background = trans != NULL && + (output_format & PNG_FORMAT_FLAG_ALPHA) == 0; + unsigned int i; + + /* Just in case: */ + if (trans == NULL) + num_trans = 0; + + output_processing = PNG_CMAP_NONE; + data_encoding = P_FILE; /* Don't change from color-map indices */ + cmap_entries = (unsigned int)png_ptr->num_palette; + if (cmap_entries > 256) + cmap_entries = 256; + + if (cmap_entries > (unsigned int)image->colormap_entries) + png_error(png_ptr, "palette color-map: too few entries"); + + for (i=0; i < cmap_entries; ++i) + { + if (do_background != 0 && i < num_trans && trans[i] < 255) + { + if (trans[i] == 0) + png_create_colormap_entry(display, i, back_r, back_g, + back_b, 0, output_encoding); + + else + { + /* Must compose the PNG file color in the color-map entry + * on the sRGB color in 'back'. + */ + png_create_colormap_entry(display, i, + png_colormap_compose(display, colormap[i].red, + P_FILE, trans[i], back_r, output_encoding), + png_colormap_compose(display, colormap[i].green, + P_FILE, trans[i], back_g, output_encoding), + png_colormap_compose(display, colormap[i].blue, + P_FILE, trans[i], back_b, output_encoding), + output_encoding == P_LINEAR ? trans[i] * 257U : + trans[i], + output_encoding); + } + } + + else + png_create_colormap_entry(display, i, colormap[i].red, + colormap[i].green, colormap[i].blue, + i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/); + } + + /* The PNG data may have indices packed in fewer than 8 bits, it + * must be expanded if so. + */ + if (png_ptr->bit_depth < 8) + png_set_packing(png_ptr); + } + break; + + default: + png_error(png_ptr, "invalid PNG color type"); + /*NOT REACHED*/ + } + + /* Now deal with the output processing */ + if (expand_tRNS != 0 && png_ptr->num_trans > 0 && + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) == 0) + png_set_tRNS_to_alpha(png_ptr); + + switch (data_encoding) + { + case P_sRGB: + /* Change to 8-bit sRGB */ + png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB); + /* FALLTHROUGH */ + + case P_FILE: + if (png_ptr->bit_depth > 8) + png_set_scale_16(png_ptr); + break; + +#ifdef __GNUC__ + default: + png_error(png_ptr, "bad data option (internal error)"); +#endif + } + + if (cmap_entries > 256 || cmap_entries > image->colormap_entries) + png_error(png_ptr, "color map overflow (BAD internal error)"); + + image->colormap_entries = cmap_entries; + + /* Double check using the recorded background index */ + switch (output_processing) + { + case PNG_CMAP_NONE: + if (background_index != PNG_CMAP_NONE_BACKGROUND) + goto bad_background; + break; + + case PNG_CMAP_GA: + if (background_index != PNG_CMAP_GA_BACKGROUND) + goto bad_background; + break; + + case PNG_CMAP_TRANS: + if (background_index >= cmap_entries || + background_index != PNG_CMAP_TRANS_BACKGROUND) + goto bad_background; + break; + + case PNG_CMAP_RGB: + if (background_index != PNG_CMAP_RGB_BACKGROUND) + goto bad_background; + break; + + case PNG_CMAP_RGB_ALPHA: + if (background_index != PNG_CMAP_RGB_ALPHA_BACKGROUND) + goto bad_background; + break; + + default: + png_error(png_ptr, "bad processing option (internal error)"); + + bad_background: + png_error(png_ptr, "bad background index (internal error)"); + } + + display->colormap_processing = (int)output_processing; + + return 1/*ok*/; +} + +/* The final part of the color-map read called from png_image_finish_read. */ +static int +png_image_read_and_map(png_voidp argument) +{ + png_image_read_control *display = png_voidcast(png_image_read_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + int passes; + + /* Called when the libpng data must be transformed into the color-mapped + * form. There is a local row buffer in display->local and this routine must + * do the interlace handling. + */ + switch (png_ptr->interlaced) + { + case PNG_INTERLACE_NONE: + passes = 1; + break; + + case PNG_INTERLACE_ADAM7: + passes = PNG_INTERLACE_ADAM7_PASSES; + break; + + default: + png_error(png_ptr, "unknown interlace type"); + } + + { + png_uint_32 height = image->height; + png_uint_32 width = image->width; + int proc = display->colormap_processing; + png_bytep first_row = png_voidcast(png_bytep, display->first_row); + ptrdiff_t step_row = display->row_bytes; + int pass; + + for (pass = 0; pass < passes; ++pass) + { + unsigned int startx, stepx, stepy; + png_uint_32 y; + + if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) + { + /* The row may be empty for a short image: */ + if (PNG_PASS_COLS(width, pass) == 0) + continue; + + startx = PNG_PASS_START_COL(pass); + stepx = PNG_PASS_COL_OFFSET(pass); + y = PNG_PASS_START_ROW(pass); + stepy = PNG_PASS_ROW_OFFSET(pass); + } + + else + { + y = 0; + startx = 0; + stepx = stepy = 1; + } + + for (; ylocal_row); + png_bytep outrow = first_row + y * step_row; + png_const_bytep end_row = outrow + width; + + /* Read read the libpng data into the temporary buffer. */ + png_read_row(png_ptr, inrow, NULL); + + /* Now process the row according to the processing option, note + * that the caller verifies that the format of the libpng output + * data is as required. + */ + outrow += startx; + switch (proc) + { + case PNG_CMAP_GA: + for (; outrow < end_row; outrow += stepx) + { + /* The data is always in the PNG order */ + unsigned int gray = *inrow++; + unsigned int alpha = *inrow++; + unsigned int entry; + + /* NOTE: this code is copied as a comment in + * make_ga_colormap above. Please update the + * comment if you change this code! + */ + if (alpha > 229) /* opaque */ + { + entry = (231 * gray + 128) >> 8; + } + else if (alpha < 26) /* transparent */ + { + entry = 231; + } + else /* partially opaque */ + { + entry = 226 + 6 * PNG_DIV51(alpha) + PNG_DIV51(gray); + } + + *outrow = (png_byte)entry; + } + break; + + case PNG_CMAP_TRANS: + for (; outrow < end_row; outrow += stepx) + { + png_byte gray = *inrow++; + png_byte alpha = *inrow++; + + if (alpha == 0) + *outrow = PNG_CMAP_TRANS_BACKGROUND; + + else if (gray != PNG_CMAP_TRANS_BACKGROUND) + *outrow = gray; + + else + *outrow = (png_byte)(PNG_CMAP_TRANS_BACKGROUND+1); + } + break; + + case PNG_CMAP_RGB: + for (; outrow < end_row; outrow += stepx) + { + *outrow = PNG_RGB_INDEX(inrow[0], inrow[1], inrow[2]); + inrow += 3; + } + break; + + case PNG_CMAP_RGB_ALPHA: + for (; outrow < end_row; outrow += stepx) + { + unsigned int alpha = inrow[3]; + + /* Because the alpha entries only hold alpha==0.5 values + * split the processing at alpha==0.25 (64) and 0.75 + * (196). + */ + + if (alpha >= 196) + *outrow = PNG_RGB_INDEX(inrow[0], inrow[1], + inrow[2]); + + else if (alpha < 64) + *outrow = PNG_CMAP_RGB_ALPHA_BACKGROUND; + + else + { + /* Likewise there are three entries for each of r, g + * and b. We could select the entry by popcount on + * the top two bits on those architectures that + * support it, this is what the code below does, + * crudely. + */ + unsigned int back_i = PNG_CMAP_RGB_ALPHA_BACKGROUND+1; + + /* Here are how the values map: + * + * 0x00 .. 0x3f -> 0 + * 0x40 .. 0xbf -> 1 + * 0xc0 .. 0xff -> 2 + * + * So, as above with the explicit alpha checks, the + * breakpoints are at 64 and 196. + */ + if (inrow[0] & 0x80) back_i += 9; /* red */ + if (inrow[0] & 0x40) back_i += 9; + if (inrow[0] & 0x80) back_i += 3; /* green */ + if (inrow[0] & 0x40) back_i += 3; + if (inrow[0] & 0x80) back_i += 1; /* blue */ + if (inrow[0] & 0x40) back_i += 1; + + *outrow = (png_byte)back_i; + } + + inrow += 4; + } + break; + + default: + break; + } + } + } + } + + return 1; +} + +static int +png_image_read_colormapped(png_voidp argument) +{ + png_image_read_control *display = png_voidcast(png_image_read_control*, + argument); + png_imagep image = display->image; + png_controlp control = image->opaque; + png_structrp png_ptr = control->png_ptr; + png_inforp info_ptr = control->info_ptr; + + int passes = 0; /* As a flag */ + + PNG_SKIP_CHUNKS(png_ptr); + + /* Update the 'info' structure and make sure the result is as required; first + * make sure to turn on the interlace handling if it will be required + * (because it can't be turned on *after* the call to png_read_update_info!) + */ + if (display->colormap_processing == PNG_CMAP_NONE) + passes = png_set_interlace_handling(png_ptr); + + png_read_update_info(png_ptr, info_ptr); + + /* The expected output can be deduced from the colormap_processing option. */ + switch (display->colormap_processing) + { + case PNG_CMAP_NONE: + /* Output must be one channel and one byte per pixel, the output + * encoding can be anything. + */ + if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE || + info_ptr->color_type == PNG_COLOR_TYPE_GRAY) && + info_ptr->bit_depth == 8) + break; + + goto bad_output; + + case PNG_CMAP_TRANS: + case PNG_CMAP_GA: + /* Output must be two channels and the 'G' one must be sRGB, the latter + * can be checked with an exact number because it should have been set + * to this number above! + */ + if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + info_ptr->bit_depth == 8 && + png_ptr->screen_gamma == PNG_GAMMA_sRGB && + image->colormap_entries == 256) + break; + + goto bad_output; + + case PNG_CMAP_RGB: + /* Output must be 8-bit sRGB encoded RGB */ + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB && + info_ptr->bit_depth == 8 && + png_ptr->screen_gamma == PNG_GAMMA_sRGB && + image->colormap_entries == 216) + break; + + goto bad_output; + + case PNG_CMAP_RGB_ALPHA: + /* Output must be 8-bit sRGB encoded RGBA */ + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA && + info_ptr->bit_depth == 8 && + png_ptr->screen_gamma == PNG_GAMMA_sRGB && + image->colormap_entries == 244 /* 216 + 1 + 27 */) + break; + + goto bad_output; + + default: + bad_output: + png_error(png_ptr, "bad color-map processing (internal error)"); + } + + /* Now read the rows. Do this here if it is possible to read directly into + * the output buffer, otherwise allocate a local row buffer of the maximum + * size libpng requires and call the relevant processing routine safely. + */ + { + png_voidp first_row = display->buffer; + ptrdiff_t row_bytes = display->row_stride; + + /* The following expression is designed to work correctly whether it gives + * a signed or an unsigned result. + */ + if (row_bytes < 0) + { + char *ptr = png_voidcast(char*, first_row); + ptr += (image->height-1) * (-row_bytes); + first_row = png_voidcast(png_voidp, ptr); + } + + display->first_row = first_row; + display->row_bytes = row_bytes; + } + + if (passes == 0) + { + int result; + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); + + display->local_row = row; + result = png_safe_execute(image, png_image_read_and_map, display); + display->local_row = NULL; + png_free(png_ptr, row); + + return result; + } + + else + { + png_alloc_size_t row_bytes = (png_alloc_size_t)display->row_bytes; + + while (--passes >= 0) + { + png_uint_32 y = image->height; + png_bytep row = png_voidcast(png_bytep, display->first_row); + + for (; y > 0; --y) + { + png_read_row(png_ptr, row, NULL); + row += row_bytes; + } + } + + return 1; + } +} + +/* Just the row reading part of png_image_read. */ +static int +png_image_read_composite(png_voidp argument) +{ + png_image_read_control *display = png_voidcast(png_image_read_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + int passes; + + switch (png_ptr->interlaced) + { + case PNG_INTERLACE_NONE: + passes = 1; + break; + + case PNG_INTERLACE_ADAM7: + passes = PNG_INTERLACE_ADAM7_PASSES; + break; + + default: + png_error(png_ptr, "unknown interlace type"); + } + + { + png_uint_32 height = image->height; + png_uint_32 width = image->width; + ptrdiff_t step_row = display->row_bytes; + unsigned int channels = + (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1; + int pass; + + for (pass = 0; pass < passes; ++pass) + { + unsigned int startx, stepx, stepy; + png_uint_32 y; + + if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) + { + /* The row may be empty for a short image: */ + if (PNG_PASS_COLS(width, pass) == 0) + continue; + + startx = PNG_PASS_START_COL(pass) * channels; + stepx = PNG_PASS_COL_OFFSET(pass) * channels; + y = PNG_PASS_START_ROW(pass); + stepy = PNG_PASS_ROW_OFFSET(pass); + } + + else + { + y = 0; + startx = 0; + stepx = channels; + stepy = 1; + } + + for (; ylocal_row); + png_bytep outrow; + png_const_bytep end_row; + + /* Read the row, which is packed: */ + png_read_row(png_ptr, inrow, NULL); + + outrow = png_voidcast(png_bytep, display->first_row); + outrow += y * step_row; + end_row = outrow + width * channels; + + /* Now do the composition on each pixel in this row. */ + outrow += startx; + for (; outrow < end_row; outrow += stepx) + { + png_byte alpha = inrow[channels]; + + if (alpha > 0) /* else no change to the output */ + { + unsigned int c; + + for (c=0; cimage; + png_structrp png_ptr = image->opaque->png_ptr; + png_inforp info_ptr = image->opaque->info_ptr; + png_uint_32 height = image->height; + png_uint_32 width = image->width; + int pass, passes; + + /* Double check the convoluted logic below. We expect to get here with + * libpng doing rgb to gray and gamma correction but background processing + * left to the png_image_read_background function. The rows libpng produce + * might be 8 or 16-bit but should always have two channels; gray plus alpha. + */ + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == 0) + png_error(png_ptr, "lost rgb to gray"); + + if ((png_ptr->transformations & PNG_COMPOSE) != 0) + png_error(png_ptr, "unexpected compose"); + + if (png_get_channels(png_ptr, info_ptr) != 2) + png_error(png_ptr, "lost/gained channels"); + + /* Expect the 8-bit case to always remove the alpha channel */ + if ((image->format & PNG_FORMAT_FLAG_LINEAR) == 0 && + (image->format & PNG_FORMAT_FLAG_ALPHA) != 0) + png_error(png_ptr, "unexpected 8-bit transformation"); + + switch (png_ptr->interlaced) + { + case PNG_INTERLACE_NONE: + passes = 1; + break; + + case PNG_INTERLACE_ADAM7: + passes = PNG_INTERLACE_ADAM7_PASSES; + break; + + default: + png_error(png_ptr, "unknown interlace type"); + } + + /* Use direct access to info_ptr here because otherwise the simplified API + * would require PNG_EASY_ACCESS_SUPPORTED (just for this.) Note this is + * checking the value after libpng expansions, not the original value in the + * PNG. + */ + switch (info_ptr->bit_depth) + { + case 8: + /* 8-bit sRGB gray values with an alpha channel; the alpha channel is + * to be removed by composing on a background: either the row if + * display->background is NULL or display->background->green if not. + * Unlike the code above ALPHA_OPTIMIZED has *not* been done. + */ + { + png_bytep first_row = png_voidcast(png_bytep, display->first_row); + ptrdiff_t step_row = display->row_bytes; + + for (pass = 0; pass < passes; ++pass) + { + png_bytep row = png_voidcast(png_bytep, display->first_row); + unsigned int startx, stepx, stepy; + png_uint_32 y; + + if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) + { + /* The row may be empty for a short image: */ + if (PNG_PASS_COLS(width, pass) == 0) + continue; + + startx = PNG_PASS_START_COL(pass); + stepx = PNG_PASS_COL_OFFSET(pass); + y = PNG_PASS_START_ROW(pass); + stepy = PNG_PASS_ROW_OFFSET(pass); + } + + else + { + y = 0; + startx = 0; + stepx = stepy = 1; + } + + if (display->background == NULL) + { + for (; ylocal_row); + png_bytep outrow = first_row + y * step_row; + png_const_bytep end_row = outrow + width; + + /* Read the row, which is packed: */ + png_read_row(png_ptr, inrow, NULL); + + /* Now do the composition on each pixel in this row. */ + outrow += startx; + for (; outrow < end_row; outrow += stepx) + { + png_byte alpha = inrow[1]; + + if (alpha > 0) /* else no change to the output */ + { + png_uint_32 component = inrow[0]; + + if (alpha < 255) /* else just use component */ + { + /* Since PNG_OPTIMIZED_ALPHA was not set it is + * necessary to invert the sRGB transfer + * function and multiply the alpha out. + */ + component = png_sRGB_table[component] * alpha; + component += png_sRGB_table[outrow[0]] * + (255-alpha); + component = PNG_sRGB_FROM_LINEAR(component); + } + + outrow[0] = (png_byte)component; + } + + inrow += 2; /* gray and alpha channel */ + } + } + } + + else /* constant background value */ + { + png_byte background8 = display->background->green; + png_uint_16 background = png_sRGB_table[background8]; + + for (; ylocal_row); + png_bytep outrow = first_row + y * step_row; + png_const_bytep end_row = outrow + width; + + /* Read the row, which is packed: */ + png_read_row(png_ptr, inrow, NULL); + + /* Now do the composition on each pixel in this row. */ + outrow += startx; + for (; outrow < end_row; outrow += stepx) + { + png_byte alpha = inrow[1]; + + if (alpha > 0) /* else use background */ + { + png_uint_32 component = inrow[0]; + + if (alpha < 255) /* else just use component */ + { + component = png_sRGB_table[component] * alpha; + component += background * (255-alpha); + component = PNG_sRGB_FROM_LINEAR(component); + } + + outrow[0] = (png_byte)component; + } + + else + outrow[0] = background8; + + inrow += 2; /* gray and alpha channel */ + } + + row += display->row_bytes; + } + } + } + } + break; + + case 16: + /* 16-bit linear with pre-multiplied alpha; the pre-multiplication must + * still be done and, maybe, the alpha channel removed. This code also + * handles the alpha-first option. + */ + { + png_uint_16p first_row = png_voidcast(png_uint_16p, + display->first_row); + /* The division by two is safe because the caller passed in a + * stride which was multiplied by 2 (below) to get row_bytes. + */ + ptrdiff_t step_row = display->row_bytes / 2; + unsigned int preserve_alpha = (image->format & + PNG_FORMAT_FLAG_ALPHA) != 0; + unsigned int outchannels = 1U+preserve_alpha; + int swap_alpha = 0; + +# ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED + if (preserve_alpha != 0 && + (image->format & PNG_FORMAT_FLAG_AFIRST) != 0) + swap_alpha = 1; +# endif + + for (pass = 0; pass < passes; ++pass) + { + unsigned int startx, stepx, stepy; + png_uint_32 y; + + /* The 'x' start and step are adjusted to output components here. + */ + if (png_ptr->interlaced == PNG_INTERLACE_ADAM7) + { + /* The row may be empty for a short image: */ + if (PNG_PASS_COLS(width, pass) == 0) + continue; + + startx = PNG_PASS_START_COL(pass) * outchannels; + stepx = PNG_PASS_COL_OFFSET(pass) * outchannels; + y = PNG_PASS_START_ROW(pass); + stepy = PNG_PASS_ROW_OFFSET(pass); + } + + else + { + y = 0; + startx = 0; + stepx = outchannels; + stepy = 1; + } + + for (; ylocal_row), NULL); + inrow = png_voidcast(png_const_uint_16p, display->local_row); + + /* Now do the pre-multiplication on each pixel in this row. + */ + outrow += startx; + for (; outrow < end_row; outrow += stepx) + { + png_uint_32 component = inrow[0]; + png_uint_16 alpha = inrow[1]; + + if (alpha > 0) /* else 0 */ + { + if (alpha < 65535) /* else just use component */ + { + component *= alpha; + component += 32767; + component /= 65535; + } + } + + else + component = 0; + + outrow[swap_alpha] = (png_uint_16)component; + if (preserve_alpha != 0) + outrow[1 ^ swap_alpha] = alpha; + + inrow += 2; /* components and alpha channel */ + } + } + } + } + break; + +#ifdef __GNUC__ + default: + png_error(png_ptr, "unexpected bit depth"); +#endif + } + + return 1; +} + +/* The guts of png_image_finish_read as a png_safe_execute callback. */ +static int +png_image_read_direct(png_voidp argument) +{ + png_image_read_control *display = png_voidcast(png_image_read_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + png_inforp info_ptr = image->opaque->info_ptr; + + png_uint_32 format = image->format; + int linear = (format & PNG_FORMAT_FLAG_LINEAR) != 0; + int do_local_compose = 0; + int do_local_background = 0; /* to avoid double gamma correction bug */ + int passes = 0; + + /* Add transforms to ensure the correct output format is produced then check + * that the required implementation support is there. Always expand; always + * need 8 bits minimum, no palette and expanded tRNS. + */ + png_set_expand(png_ptr); + + /* Now check the format to see if it was modified. */ + { + png_uint_32 base_format = png_image_format(png_ptr) & + ~PNG_FORMAT_FLAG_COLORMAP /* removed by png_set_expand */; + png_uint_32 change = format ^ base_format; + png_fixed_point output_gamma; + int mode; /* alpha mode */ + + /* Do this first so that we have a record if rgb to gray is happening. */ + if ((change & PNG_FORMAT_FLAG_COLOR) != 0) + { + /* gray<->color transformation required. */ + if ((format & PNG_FORMAT_FLAG_COLOR) != 0) + png_set_gray_to_rgb(png_ptr); + + else + { + /* libpng can't do both rgb to gray and + * background/pre-multiplication if there is also significant gamma + * correction, because both operations require linear colors and + * the code only supports one transform doing the gamma correction. + * Handle this by doing the pre-multiplication or background + * operation in this code, if necessary. + * + * TODO: fix this by rewriting pngrtran.c (!) + * + * For the moment (given that fixing this in pngrtran.c is an + * enormous change) 'do_local_background' is used to indicate that + * the problem exists. + */ + if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0) + do_local_background = 1/*maybe*/; + + png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, + PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT); + } + + change &= ~PNG_FORMAT_FLAG_COLOR; + } + + /* Set the gamma appropriately, linear for 16-bit input, sRGB otherwise. + */ + { + png_fixed_point input_gamma_default; + + if ((base_format & PNG_FORMAT_FLAG_LINEAR) != 0 && + (image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0) + input_gamma_default = PNG_GAMMA_LINEAR; + else + input_gamma_default = PNG_DEFAULT_sRGB; + + /* Call png_set_alpha_mode to set the default for the input gamma; the + * output gamma is set by a second call below. + */ + png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, input_gamma_default); + } + + if (linear != 0) + { + /* If there *is* an alpha channel in the input it must be multiplied + * out; use PNG_ALPHA_STANDARD, otherwise just use PNG_ALPHA_PNG. + */ + if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0) + mode = PNG_ALPHA_STANDARD; /* associated alpha */ + + else + mode = PNG_ALPHA_PNG; + + output_gamma = PNG_GAMMA_LINEAR; + } + + else + { + mode = PNG_ALPHA_PNG; + output_gamma = PNG_DEFAULT_sRGB; + } + + if ((change & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0) + { + mode = PNG_ALPHA_OPTIMIZED; + change &= ~PNG_FORMAT_FLAG_ASSOCIATED_ALPHA; + } + + /* If 'do_local_background' is set check for the presence of gamma + * correction; this is part of the work-round for the libpng bug + * described above. + * + * TODO: fix libpng and remove this. + */ + if (do_local_background != 0) + { + png_fixed_point gtest; + + /* This is 'png_gamma_threshold' from pngrtran.c; the test used for + * gamma correction, the screen gamma hasn't been set on png_struct + * yet; it's set below. png_struct::gamma, however, is set to the + * final value. + */ + if (png_muldiv(>est, output_gamma, png_ptr->colorspace.gamma, + PNG_FP_1) != 0 && png_gamma_significant(gtest) == 0) + do_local_background = 0; + + else if (mode == PNG_ALPHA_STANDARD) + { + do_local_background = 2/*required*/; + mode = PNG_ALPHA_PNG; /* prevent libpng doing it */ + } + + /* else leave as 1 for the checks below */ + } + + /* If the bit-depth changes then handle that here. */ + if ((change & PNG_FORMAT_FLAG_LINEAR) != 0) + { + if (linear != 0 /*16-bit output*/) + png_set_expand_16(png_ptr); + + else /* 8-bit output */ + png_set_scale_16(png_ptr); + + change &= ~PNG_FORMAT_FLAG_LINEAR; + } + + /* Now the background/alpha channel changes. */ + if ((change & PNG_FORMAT_FLAG_ALPHA) != 0) + { + /* Removing an alpha channel requires composition for the 8-bit + * formats; for the 16-bit it is already done, above, by the + * pre-multiplication and the channel just needs to be stripped. + */ + if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + /* If RGB->gray is happening the alpha channel must be left and the + * operation completed locally. + * + * TODO: fix libpng and remove this. + */ + if (do_local_background != 0) + do_local_background = 2/*required*/; + + /* 16-bit output: just remove the channel */ + else if (linear != 0) /* compose on black (well, pre-multiply) */ + png_set_strip_alpha(png_ptr); + + /* 8-bit output: do an appropriate compose */ + else if (display->background != NULL) + { + png_color_16 c; + + c.index = 0; /*unused*/ + c.red = display->background->red; + c.green = display->background->green; + c.blue = display->background->blue; + c.gray = display->background->green; + + /* This is always an 8-bit sRGB value, using the 'green' channel + * for gray is much better than calculating the luminance here; + * we can get off-by-one errors in that calculation relative to + * the app expectations and that will show up in transparent + * pixels. + */ + png_set_background_fixed(png_ptr, &c, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, + 0/*gamma: not used*/); + } + + else /* compose on row: implemented below. */ + { + do_local_compose = 1; + /* This leaves the alpha channel in the output, so it has to be + * removed by the code below. Set the encoding to the 'OPTIMIZE' + * one so the code only has to hack on the pixels that require + * composition. + */ + mode = PNG_ALPHA_OPTIMIZED; + } + } + + else /* output needs an alpha channel */ + { + /* This is tricky because it happens before the swap operation has + * been accomplished; however, the swap does *not* swap the added + * alpha channel (weird API), so it must be added in the correct + * place. + */ + png_uint_32 filler; /* opaque filler */ + int where; + + if (linear != 0) + filler = 65535; + + else + filler = 255; + +#ifdef PNG_FORMAT_AFIRST_SUPPORTED + if ((format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + where = PNG_FILLER_BEFORE; + change &= ~PNG_FORMAT_FLAG_AFIRST; + } + + else +#endif + where = PNG_FILLER_AFTER; + + png_set_add_alpha(png_ptr, filler, where); + } + + /* This stops the (irrelevant) call to swap_alpha below. */ + change &= ~PNG_FORMAT_FLAG_ALPHA; + } + + /* Now set the alpha mode correctly; this is always done, even if there is + * no alpha channel in either the input or the output because it correctly + * sets the output gamma. + */ + png_set_alpha_mode_fixed(png_ptr, mode, output_gamma); + +# ifdef PNG_FORMAT_BGR_SUPPORTED + if ((change & PNG_FORMAT_FLAG_BGR) != 0) + { + /* Check only the output format; PNG is never BGR; don't do this if + * the output is gray, but fix up the 'format' value in that case. + */ + if ((format & PNG_FORMAT_FLAG_COLOR) != 0) + png_set_bgr(png_ptr); + + else + format &= ~PNG_FORMAT_FLAG_BGR; + + change &= ~PNG_FORMAT_FLAG_BGR; + } +# endif + +# ifdef PNG_FORMAT_AFIRST_SUPPORTED + if ((change & PNG_FORMAT_FLAG_AFIRST) != 0) + { + /* Only relevant if there is an alpha channel - it's particularly + * important to handle this correctly because do_local_compose may + * be set above and then libpng will keep the alpha channel for this + * code to remove. + */ + if ((format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + /* Disable this if doing a local background, + * TODO: remove this when local background is no longer required. + */ + if (do_local_background != 2) + png_set_swap_alpha(png_ptr); + } + + else + format &= ~PNG_FORMAT_FLAG_AFIRST; + + change &= ~PNG_FORMAT_FLAG_AFIRST; + } +# endif + + /* If the *output* is 16-bit then we need to check for a byte-swap on this + * architecture. + */ + if (linear != 0) + { + png_uint_16 le = 0x0001; + + if ((*(png_const_bytep) & le) != 0) + png_set_swap(png_ptr); + } + + /* If change is not now 0 some transformation is missing - error out. */ + if (change != 0) + png_error(png_ptr, "png_read_image: unsupported transformation"); + } + + PNG_SKIP_CHUNKS(png_ptr); + + /* Update the 'info' structure and make sure the result is as required; first + * make sure to turn on the interlace handling if it will be required + * (because it can't be turned on *after* the call to png_read_update_info!) + * + * TODO: remove the do_local_background fixup below. + */ + if (do_local_compose == 0 && do_local_background != 2) + passes = png_set_interlace_handling(png_ptr); + + png_read_update_info(png_ptr, info_ptr); + + { + png_uint_32 info_format = 0; + + if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + info_format |= PNG_FORMAT_FLAG_COLOR; + + if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) + { + /* do_local_compose removes this channel below. */ + if (do_local_compose == 0) + { + /* do_local_background does the same if required. */ + if (do_local_background != 2 || + (format & PNG_FORMAT_FLAG_ALPHA) != 0) + info_format |= PNG_FORMAT_FLAG_ALPHA; + } + } + + else if (do_local_compose != 0) /* internal error */ + png_error(png_ptr, "png_image_read: alpha channel lost"); + + if ((format & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0) { + info_format |= PNG_FORMAT_FLAG_ASSOCIATED_ALPHA; + } + + if (info_ptr->bit_depth == 16) + info_format |= PNG_FORMAT_FLAG_LINEAR; + +#ifdef PNG_FORMAT_BGR_SUPPORTED + if ((png_ptr->transformations & PNG_BGR) != 0) + info_format |= PNG_FORMAT_FLAG_BGR; +#endif + +#ifdef PNG_FORMAT_AFIRST_SUPPORTED + if (do_local_background == 2) + { + if ((format & PNG_FORMAT_FLAG_AFIRST) != 0) + info_format |= PNG_FORMAT_FLAG_AFIRST; + } + + if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0 || + ((png_ptr->transformations & PNG_ADD_ALPHA) != 0 && + (png_ptr->flags & PNG_FLAG_FILLER_AFTER) == 0)) + { + if (do_local_background == 2) + png_error(png_ptr, "unexpected alpha swap transformation"); + + info_format |= PNG_FORMAT_FLAG_AFIRST; + } +# endif + + /* This is actually an internal error. */ + if (info_format != format) + png_error(png_ptr, "png_read_image: invalid transformations"); + } + + /* Now read the rows. If do_local_compose is set then it is necessary to use + * a local row buffer. The output will be GA, RGBA or BGRA and must be + * converted to G, RGB or BGR as appropriate. The 'local_row' member of the + * display acts as a flag. + */ + { + png_voidp first_row = display->buffer; + ptrdiff_t row_bytes = display->row_stride; + + if (linear != 0) + row_bytes *= 2; + + /* The following expression is designed to work correctly whether it gives + * a signed or an unsigned result. + */ + if (row_bytes < 0) + { + char *ptr = png_voidcast(char*, first_row); + ptr += (image->height-1) * (-row_bytes); + first_row = png_voidcast(png_voidp, ptr); + } + + display->first_row = first_row; + display->row_bytes = row_bytes; + } + + if (do_local_compose != 0) + { + int result; + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); + + display->local_row = row; + result = png_safe_execute(image, png_image_read_composite, display); + display->local_row = NULL; + png_free(png_ptr, row); + + return result; + } + + else if (do_local_background == 2) + { + int result; + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); + + display->local_row = row; + result = png_safe_execute(image, png_image_read_background, display); + display->local_row = NULL; + png_free(png_ptr, row); + + return result; + } + + else + { + png_alloc_size_t row_bytes = (png_alloc_size_t)display->row_bytes; + + while (--passes >= 0) + { + png_uint_32 y = image->height; + png_bytep row = png_voidcast(png_bytep, display->first_row); + + for (; y > 0; --y) + { + png_read_row(png_ptr, row, NULL); + row += row_bytes; + } + } + + return 1; + } +} + +int PNGAPI +png_image_finish_read(png_imagep image, png_const_colorp background, + void *buffer, png_int_32 row_stride, void *colormap) +{ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + /* Check for row_stride overflow. This check is not performed on the + * original PNG format because it may not occur in the output PNG format + * and libpng deals with the issues of reading the original. + */ + unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format); + + /* The following checks just the 'row_stride' calculation to ensure it + * fits in a signed 32-bit value. Because channels/components can be + * either 1 or 2 bytes in size the length of a row can still overflow 32 + * bits; this is just to verify that the 'row_stride' argument can be + * represented. + */ + if (image->width <= 0x7fffffffU/channels) /* no overflow */ + { + png_uint_32 check; + png_uint_32 png_row_stride = image->width * channels; + + if (row_stride == 0) + row_stride = (png_int_32)/*SAFE*/png_row_stride; + + if (row_stride < 0) + check = (png_uint_32)(-row_stride); + + else + check = (png_uint_32)row_stride; + + /* This verifies 'check', the absolute value of the actual stride + * passed in and detects overflow in the application calculation (i.e. + * if the app did actually pass in a non-zero 'row_stride'. + */ + if (image->opaque != NULL && buffer != NULL && check >= png_row_stride) + { + /* Now check for overflow of the image buffer calculation; this + * limits the whole image size to 32 bits for API compatibility with + * the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro. + * + * The PNG_IMAGE_BUFFER_SIZE macro is: + * + * (PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)*height*(row_stride)) + * + * And the component size is always 1 or 2, so make sure that the + * number of *bytes* that the application is saying are available + * does actually fit into a 32-bit number. + * + * NOTE: this will be changed in 1.7 because PNG_IMAGE_BUFFER_SIZE + * will be changed to use png_alloc_size_t; bigger images can be + * accommodated on 64-bit systems. + */ + if (image->height <= + 0xffffffffU/PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format)/check) + { + if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 || + (image->colormap_entries > 0 && colormap != NULL)) + { + int result; + png_image_read_control display; + + memset(&display, 0, (sizeof display)); + display.image = image; + display.buffer = buffer; + display.row_stride = row_stride; + display.colormap = colormap; + display.background = background; + display.local_row = NULL; + + /* Choose the correct 'end' routine; for the color-map case + * all the setup has already been done. + */ + if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0) + result = + png_safe_execute(image, + png_image_read_colormap, &display) && + png_safe_execute(image, + png_image_read_colormapped, &display); + + else + result = + png_safe_execute(image, + png_image_read_direct, &display); + + png_image_free(image); + return result; + } + + else + return png_image_error(image, + "png_image_finish_read[color-map]: no color-map"); + } + + else + return png_image_error(image, + "png_image_finish_read: image too large"); + } + + else + return png_image_error(image, + "png_image_finish_read: invalid argument"); + } + + else + return png_image_error(image, + "png_image_finish_read: row_stride too large"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_finish_read: damaged PNG_IMAGE_VERSION"); + + return 0; +} + +#endif /* SIMPLIFIED_READ */ +#endif /* READ */ diff --git a/extern/libpng/pngrio.c b/extern/libpng/pngrio.c new file mode 100644 index 000000000..794635810 --- /dev/null +++ b/extern/libpng/pngrio.c @@ -0,0 +1,120 @@ + +/* pngrio.c - functions for data input + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all input. Users who need + * special handling are expected to write a function that has the same + * arguments as this and performs a similar function, but that possibly + * has a different input method. Note that you shouldn't change this + * function, but rather write a replacement function and then make + * libpng use it at run time with png_set_read_fn(...). + */ + +#include "pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +/* Read the data from whatever input you are using. The default routine + * reads from a file pointer. Note that this routine sometimes gets called + * with very small lengths, so you should implement some kind of simple + * buffering if you are using unbuffered reads. This should never be asked + * to read more than 64K on a 16-bit machine. + */ +void /* PRIVATE */ +png_read_data(png_structrp png_ptr, png_bytep data, size_t length) +{ + png_debug1(4, "reading %d bytes", (int)length); + + if (png_ptr->read_data_fn != NULL) + (*(png_ptr->read_data_fn))(png_ptr, data, length); + + else + png_error(png_ptr, "Call to NULL read function"); +} + +#ifdef PNG_STDIO_SUPPORTED +/* This is the function that does the actual reading of data. If you are + * not reading from a standard C stream, you should create a replacement + * read_data function and use it at run time with png_set_read_fn(), rather + * than changing the library. + */ +void PNGCBAPI +png_default_read_data(png_structp png_ptr, png_bytep data, size_t length) +{ + size_t check; + + if (png_ptr == NULL) + return; + + /* fread() returns 0 on error, so it is OK to store this in a size_t + * instead of an int, which is what fread() actually returns. + */ + check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr)); + + if (check != length) + png_error(png_ptr, "Read Error"); +} +#endif + +/* This function allows the application to supply a new input function + * for libpng if standard C streams aren't being used. + * + * This function takes as its arguments: + * + * png_ptr - pointer to a png input data structure + * + * io_ptr - pointer to user supplied structure containing info about + * the input functions. May be NULL. + * + * read_data_fn - pointer to a new input function that takes as its + * arguments a pointer to a png_struct, a pointer to + * a location where input data can be stored, and a 32-bit + * unsigned int that is the number of bytes to be read. + * To exit and output any fatal error messages the new write + * function should call png_error(png_ptr, "Error msg"). + * May be NULL, in which case libpng's default function will + * be used. + */ +void PNGAPI +png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr, + png_rw_ptr read_data_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->io_ptr = io_ptr; + +#ifdef PNG_STDIO_SUPPORTED + if (read_data_fn != NULL) + png_ptr->read_data_fn = read_data_fn; + + else + png_ptr->read_data_fn = png_default_read_data; +#else + png_ptr->read_data_fn = read_data_fn; +#endif + +#ifdef PNG_WRITE_SUPPORTED + /* It is an error to write to a read device */ + if (png_ptr->write_data_fn != NULL) + { + png_ptr->write_data_fn = NULL; + png_warning(png_ptr, + "Can't set both read_data_fn and write_data_fn in the" + " same structure"); + } +#endif + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_ptr->output_flush_fn = NULL; +#endif +} +#endif /* READ */ diff --git a/extern/libpng/pngrtran.c b/extern/libpng/pngrtran.c new file mode 100644 index 000000000..40c736a24 --- /dev/null +++ b/extern/libpng/pngrtran.c @@ -0,0 +1,5167 @@ + +/* pngrtran.c - transforms the data in a row for PNG readers + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains functions optionally called by an application + * in order to tell libpng how to handle data when reading a PNG. + * Transformations that are used in both reading and writing are + * in pngtrans.c. + */ + +#include "pngpriv.h" + +#ifdef PNG_ARM_NEON_IMPLEMENTATION +# if PNG_ARM_NEON_IMPLEMENTATION == 1 +# define PNG_ARM_NEON_INTRINSICS_AVAILABLE +# if defined(_MSC_VER) && defined(_M_ARM64) +# include +# else +# include +# endif +# endif +#endif + +#ifdef PNG_READ_SUPPORTED + +/* Set the action on getting a CRC error for an ancillary or critical chunk. */ +void PNGAPI +png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action) +{ + png_debug(1, "in png_set_crc_action"); + + if (png_ptr == NULL) + return; + + /* Tell libpng how we react to CRC errors in critical chunks */ + switch (crit_action) + { + case PNG_CRC_NO_CHANGE: /* Leave setting as is */ + break; + + case PNG_CRC_WARN_USE: /* Warn/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE; + break; + + case PNG_CRC_QUIET_USE: /* Quiet/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE | + PNG_FLAG_CRC_CRITICAL_IGNORE; + break; + + case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */ + png_warning(png_ptr, + "Can't discard critical data on CRC error"); + /* FALLTHROUGH */ + case PNG_CRC_ERROR_QUIT: /* Error/quit */ + + case PNG_CRC_DEFAULT: + default: + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + break; + } + + /* Tell libpng how we react to CRC errors in ancillary chunks */ + switch (ancil_action) + { + case PNG_CRC_NO_CHANGE: /* Leave setting as is */ + break; + + case PNG_CRC_WARN_USE: /* Warn/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE; + break; + + case PNG_CRC_QUIET_USE: /* Quiet/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE | + PNG_FLAG_CRC_ANCILLARY_NOWARN; + break; + + case PNG_CRC_ERROR_QUIT: /* Error/quit */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN; + break; + + case PNG_CRC_WARN_DISCARD: /* Warn/discard data */ + + case PNG_CRC_DEFAULT: + default: + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + break; + } +} + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +/* Is it OK to set a transformation now? Only if png_start_read_image or + * png_read_update_info have not been called. It is not necessary for the IHDR + * to have been read in all cases; the need_IHDR parameter allows for this + * check too. + */ +static int +png_rtran_ok(png_structrp png_ptr, int need_IHDR) +{ + if (png_ptr != NULL) + { + if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0) + png_app_error(png_ptr, + "invalid after png_start_read_image or png_read_update_info"); + + else if (need_IHDR && (png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_app_error(png_ptr, "invalid before the PNG header has been read"); + + else + { + /* Turn on failure to initialize correctly for all transforms. */ + png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED; + + return 1; /* Ok */ + } + } + + return 0; /* no png_error possible! */ +} +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +/* Handle alpha and tRNS via a background color */ +void PNGFAPI +png_set_background_fixed(png_structrp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, png_fixed_point background_gamma) +{ + png_debug(1, "in png_set_background_fixed"); + + if (png_rtran_ok(png_ptr, 0) == 0 || background_color == NULL) + return; + + if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) + { + png_warning(png_ptr, "Application must supply a known background gamma"); + return; + } + + png_ptr->transformations |= PNG_COMPOSE | PNG_STRIP_ALPHA; + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + + png_ptr->background = *background_color; + png_ptr->background_gamma = background_gamma; + png_ptr->background_gamma_type = (png_byte)(background_gamma_code); + if (need_expand != 0) + png_ptr->transformations |= PNG_BACKGROUND_EXPAND; + else + png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_background(png_structrp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma) +{ + png_set_background_fixed(png_ptr, background_color, background_gamma_code, + need_expand, png_fixed(png_ptr, background_gamma, "png_set_background")); +} +# endif /* FLOATING_POINT */ +#endif /* READ_BACKGROUND */ + +/* Scale 16-bit depth files to 8-bit depth. If both of these are set then the + * one that pngrtran does first (scale) happens. This is necessary to allow the + * TRANSFORM and API behavior to be somewhat consistent, and it's simpler. + */ +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED +void PNGAPI +png_set_scale_16(png_structrp png_ptr) +{ + png_debug(1, "in png_set_scale_16"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= PNG_SCALE_16_TO_8; +} +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED +/* Chop 16-bit depth files to 8-bit depth */ +void PNGAPI +png_set_strip_16(png_structrp png_ptr) +{ + png_debug(1, "in png_set_strip_16"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= PNG_16_TO_8; +} +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED +void PNGAPI +png_set_strip_alpha(png_structrp png_ptr) +{ + png_debug(1, "in png_set_strip_alpha"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= PNG_STRIP_ALPHA; +} +#endif + +#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED) +static png_fixed_point +translate_gamma_flags(png_structrp png_ptr, png_fixed_point output_gamma, + int is_screen) +{ + /* Check for flag values. The main reason for having the old Mac value as a + * flag is that it is pretty near impossible to work out what the correct + * value is from Apple documentation - a working Mac system is needed to + * discover the value! + */ + if (output_gamma == PNG_DEFAULT_sRGB || + output_gamma == PNG_FP_1 / PNG_DEFAULT_sRGB) + { + /* If there is no sRGB support this just sets the gamma to the standard + * sRGB value. (This is a side effect of using this function!) + */ +# ifdef PNG_READ_sRGB_SUPPORTED + png_ptr->flags |= PNG_FLAG_ASSUME_sRGB; +# else + PNG_UNUSED(png_ptr) +# endif + if (is_screen != 0) + output_gamma = PNG_GAMMA_sRGB; + else + output_gamma = PNG_GAMMA_sRGB_INVERSE; + } + + else if (output_gamma == PNG_GAMMA_MAC_18 || + output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18) + { + if (is_screen != 0) + output_gamma = PNG_GAMMA_MAC_OLD; + else + output_gamma = PNG_GAMMA_MAC_INVERSE; + } + + return output_gamma; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +static png_fixed_point +convert_gamma_value(png_structrp png_ptr, double output_gamma) +{ + /* The following silently ignores cases where fixed point (times 100,000) + * gamma values are passed to the floating point API. This is safe and it + * means the fixed point constants work just fine with the floating point + * API. The alternative would just lead to undetected errors and spurious + * bug reports. Negative values fail inside the _fixed API unless they + * correspond to the flag values. + */ + if (output_gamma > 0 && output_gamma < 128) + output_gamma *= PNG_FP_1; + + /* This preserves -1 and -2 exactly: */ + output_gamma = floor(output_gamma + .5); + + if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN) + png_fixed_error(png_ptr, "gamma value"); + + return (png_fixed_point)output_gamma; +} +# endif +#endif /* READ_ALPHA_MODE || READ_GAMMA */ + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED +void PNGFAPI +png_set_alpha_mode_fixed(png_structrp png_ptr, int mode, + png_fixed_point output_gamma) +{ + int compose = 0; + png_fixed_point file_gamma; + + png_debug(1, "in png_set_alpha_mode"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/); + + /* Validate the value to ensure it is in a reasonable range. The value + * is expected to be 1 or greater, but this range test allows for some + * viewing correction values. The intent is to weed out users of this API + * who use the inverse of the gamma value accidentally! Since some of these + * values are reasonable this may have to be changed: + * + * 1.6.x: changed from 0.07..3 to 0.01..100 (to accommodate the optimal 16-bit + * gamma of 36, and its reciprocal.) + */ + if (output_gamma < 1000 || output_gamma > 10000000) + png_error(png_ptr, "output gamma out of expected range"); + + /* The default file gamma is the inverse of the output gamma; the output + * gamma may be changed below so get the file value first: + */ + file_gamma = png_reciprocal(output_gamma); + + /* There are really 8 possibilities here, composed of any combination + * of: + * + * premultiply the color channels + * do not encode non-opaque pixels + * encode the alpha as well as the color channels + * + * The differences disappear if the input/output ('screen') gamma is 1.0, + * because then the encoding is a no-op and there is only the choice of + * premultiplying the color channels or not. + * + * png_set_alpha_mode and png_set_background interact because both use + * png_compose to do the work. Calling both is only useful when + * png_set_alpha_mode is used to set the default mode - PNG_ALPHA_PNG - along + * with a default gamma value. Otherwise PNG_COMPOSE must not be set. + */ + switch (mode) + { + case PNG_ALPHA_PNG: /* default: png standard */ + /* No compose, but it may be set by png_set_background! */ + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + break; + + case PNG_ALPHA_ASSOCIATED: /* color channels premultiplied */ + compose = 1; + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + /* The output is linear: */ + output_gamma = PNG_FP_1; + break; + + case PNG_ALPHA_OPTIMIZED: /* associated, non-opaque pixels linear */ + compose = 1; + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA; + /* output_gamma records the encoding of opaque pixels! */ + break; + + case PNG_ALPHA_BROKEN: /* associated, non-linear, alpha encoded */ + compose = 1; + png_ptr->transformations |= PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + break; + + default: + png_error(png_ptr, "invalid alpha mode"); + } + + /* Only set the default gamma if the file gamma has not been set (this has + * the side effect that the gamma in a second call to png_set_alpha_mode will + * be ignored.) + */ + if (png_ptr->colorspace.gamma == 0) + { + png_ptr->colorspace.gamma = file_gamma; + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; + } + + /* But always set the output gamma: */ + png_ptr->screen_gamma = output_gamma; + + /* Finally, if pre-multiplying, set the background fields to achieve the + * desired result. + */ + if (compose != 0) + { + /* And obtain alpha pre-multiplication by composing on black: */ + memset(&png_ptr->background, 0, (sizeof png_ptr->background)); + png_ptr->background_gamma = png_ptr->colorspace.gamma; /* just in case */ + png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE; + png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND; + + if ((png_ptr->transformations & PNG_COMPOSE) != 0) + png_error(png_ptr, + "conflicting calls to set alpha mode and background"); + + png_ptr->transformations |= PNG_COMPOSE; + } +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_alpha_mode(png_structrp png_ptr, int mode, double output_gamma) +{ + png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr, + output_gamma)); +} +# endif +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +/* Dither file to 8-bit. Supply a palette, the current number + * of elements in the palette, the maximum number of elements + * allowed, and a histogram if possible. If the current number + * of colors is greater than the maximum number, the palette will be + * modified to fit in the maximum number. "full_quantize" indicates + * whether we need a quantizing cube set up for RGB images, or if we + * simply are reducing the number of colors in a paletted image. + */ + +typedef struct png_dsort_struct +{ + struct png_dsort_struct * next; + png_byte left; + png_byte right; +} png_dsort; +typedef png_dsort * png_dsortp; +typedef png_dsort * * png_dsortpp; + +void PNGAPI +png_set_quantize(png_structrp png_ptr, png_colorp palette, + int num_palette, int maximum_colors, png_const_uint_16p histogram, + int full_quantize) +{ + png_debug(1, "in png_set_quantize"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= PNG_QUANTIZE; + + if (full_quantize == 0) + { + int i; + + png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr, + (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte)))); + for (i = 0; i < num_palette; i++) + png_ptr->quantize_index[i] = (png_byte)i; + } + + if (num_palette > maximum_colors) + { + if (histogram != NULL) + { + /* This is easy enough, just throw out the least used colors. + * Perhaps not the best solution, but good enough. + */ + + int i; + + /* Initialize an array to sort colors */ + png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr, + (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte)))); + + /* Initialize the quantize_sort array */ + for (i = 0; i < num_palette; i++) + png_ptr->quantize_sort[i] = (png_byte)i; + + /* Find the least used palette entries by starting a + * bubble sort, and running it until we have sorted + * out enough colors. Note that we don't care about + * sorting all the colors, just finding which are + * least used. + */ + + for (i = num_palette - 1; i >= maximum_colors; i--) + { + int done; /* To stop early if the list is pre-sorted */ + int j; + + done = 1; + for (j = 0; j < i; j++) + { + if (histogram[png_ptr->quantize_sort[j]] + < histogram[png_ptr->quantize_sort[j + 1]]) + { + png_byte t; + + t = png_ptr->quantize_sort[j]; + png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1]; + png_ptr->quantize_sort[j + 1] = t; + done = 0; + } + } + + if (done != 0) + break; + } + + /* Swap the palette around, and set up a table, if necessary */ + if (full_quantize != 0) + { + int j = num_palette; + + /* Put all the useful colors within the max, but don't + * move the others. + */ + for (i = 0; i < maximum_colors; i++) + { + if ((int)png_ptr->quantize_sort[i] >= maximum_colors) + { + do + j--; + while ((int)png_ptr->quantize_sort[j] >= maximum_colors); + + palette[i] = palette[j]; + } + } + } + else + { + int j = num_palette; + + /* Move all the used colors inside the max limit, and + * develop a translation table. + */ + for (i = 0; i < maximum_colors; i++) + { + /* Only move the colors we need to */ + if ((int)png_ptr->quantize_sort[i] >= maximum_colors) + { + png_color tmp_color; + + do + j--; + while ((int)png_ptr->quantize_sort[j] >= maximum_colors); + + tmp_color = palette[j]; + palette[j] = palette[i]; + palette[i] = tmp_color; + /* Indicate where the color went */ + png_ptr->quantize_index[j] = (png_byte)i; + png_ptr->quantize_index[i] = (png_byte)j; + } + } + + /* Find closest color for those colors we are not using */ + for (i = 0; i < num_palette; i++) + { + if ((int)png_ptr->quantize_index[i] >= maximum_colors) + { + int min_d, k, min_k, d_index; + + /* Find the closest color to one we threw out */ + d_index = png_ptr->quantize_index[i]; + min_d = PNG_COLOR_DIST(palette[d_index], palette[0]); + for (k = 1, min_k = 0; k < maximum_colors; k++) + { + int d; + + d = PNG_COLOR_DIST(palette[d_index], palette[k]); + + if (d < min_d) + { + min_d = d; + min_k = k; + } + } + /* Point to closest color */ + png_ptr->quantize_index[i] = (png_byte)min_k; + } + } + } + png_free(png_ptr, png_ptr->quantize_sort); + png_ptr->quantize_sort = NULL; + } + else + { + /* This is much harder to do simply (and quickly). Perhaps + * we need to go through a median cut routine, but those + * don't always behave themselves with only a few colors + * as input. So we will just find the closest two colors, + * and throw out one of them (chosen somewhat randomly). + * [We don't understand this at all, so if someone wants to + * work on improving it, be our guest - AED, GRP] + */ + int i; + int max_d; + int num_new_palette; + png_dsortp t; + png_dsortpp hash; + + t = NULL; + + /* Initialize palette index arrays */ + png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, + (png_alloc_size_t)((png_uint_32)num_palette * + (sizeof (png_byte)))); + png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, + (png_alloc_size_t)((png_uint_32)num_palette * + (sizeof (png_byte)))); + + /* Initialize the sort array */ + for (i = 0; i < num_palette; i++) + { + png_ptr->index_to_palette[i] = (png_byte)i; + png_ptr->palette_to_index[i] = (png_byte)i; + } + + hash = (png_dsortpp)png_calloc(png_ptr, (png_alloc_size_t)(769 * + (sizeof (png_dsortp)))); + + num_new_palette = num_palette; + + /* Initial wild guess at how far apart the farthest pixel + * pair we will be eliminating will be. Larger + * numbers mean more areas will be allocated, Smaller + * numbers run the risk of not saving enough data, and + * having to do this all over again. + * + * I have not done extensive checking on this number. + */ + max_d = 96; + + while (num_new_palette > maximum_colors) + { + for (i = 0; i < num_new_palette - 1; i++) + { + int j; + + for (j = i + 1; j < num_new_palette; j++) + { + int d; + + d = PNG_COLOR_DIST(palette[i], palette[j]); + + if (d <= max_d) + { + + t = (png_dsortp)png_malloc_warn(png_ptr, + (png_alloc_size_t)(sizeof (png_dsort))); + + if (t == NULL) + break; + + t->next = hash[d]; + t->left = (png_byte)i; + t->right = (png_byte)j; + hash[d] = t; + } + } + if (t == NULL) + break; + } + + if (t != NULL) + for (i = 0; i <= max_d; i++) + { + if (hash[i] != NULL) + { + png_dsortp p; + + for (p = hash[i]; p; p = p->next) + { + if ((int)png_ptr->index_to_palette[p->left] + < num_new_palette && + (int)png_ptr->index_to_palette[p->right] + < num_new_palette) + { + int j, next_j; + + if (num_new_palette & 0x01) + { + j = p->left; + next_j = p->right; + } + else + { + j = p->right; + next_j = p->left; + } + + num_new_palette--; + palette[png_ptr->index_to_palette[j]] + = palette[num_new_palette]; + if (full_quantize == 0) + { + int k; + + for (k = 0; k < num_palette; k++) + { + if (png_ptr->quantize_index[k] == + png_ptr->index_to_palette[j]) + png_ptr->quantize_index[k] = + png_ptr->index_to_palette[next_j]; + + if ((int)png_ptr->quantize_index[k] == + num_new_palette) + png_ptr->quantize_index[k] = + png_ptr->index_to_palette[j]; + } + } + + png_ptr->index_to_palette[png_ptr->palette_to_index + [num_new_palette]] = png_ptr->index_to_palette[j]; + + png_ptr->palette_to_index[png_ptr->index_to_palette[j]] + = png_ptr->palette_to_index[num_new_palette]; + + png_ptr->index_to_palette[j] = + (png_byte)num_new_palette; + + png_ptr->palette_to_index[num_new_palette] = + (png_byte)j; + } + if (num_new_palette <= maximum_colors) + break; + } + if (num_new_palette <= maximum_colors) + break; + } + } + + for (i = 0; i < 769; i++) + { + if (hash[i] != NULL) + { + png_dsortp p = hash[i]; + while (p) + { + t = p->next; + png_free(png_ptr, p); + p = t; + } + } + hash[i] = 0; + } + max_d += 96; + } + png_free(png_ptr, hash); + png_free(png_ptr, png_ptr->palette_to_index); + png_free(png_ptr, png_ptr->index_to_palette); + png_ptr->palette_to_index = NULL; + png_ptr->index_to_palette = NULL; + } + num_palette = maximum_colors; + } + if (png_ptr->palette == NULL) + { + png_ptr->palette = palette; + } + png_ptr->num_palette = (png_uint_16)num_palette; + + if (full_quantize != 0) + { + int i; + png_bytep distance; + int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS + + PNG_QUANTIZE_BLUE_BITS; + int num_red = (1 << PNG_QUANTIZE_RED_BITS); + int num_green = (1 << PNG_QUANTIZE_GREEN_BITS); + int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS); + size_t num_entries = ((size_t)1 << total_bits); + + png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr, + (png_alloc_size_t)(num_entries * (sizeof (png_byte)))); + + distance = (png_bytep)png_malloc(png_ptr, (png_alloc_size_t)(num_entries * + (sizeof (png_byte)))); + + memset(distance, 0xff, num_entries * (sizeof (png_byte))); + + for (i = 0; i < num_palette; i++) + { + int ir, ig, ib; + int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS)); + int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS)); + int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS)); + + for (ir = 0; ir < num_red; ir++) + { + /* int dr = abs(ir - r); */ + int dr = ((ir > r) ? ir - r : r - ir); + int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS + + PNG_QUANTIZE_GREEN_BITS)); + + for (ig = 0; ig < num_green; ig++) + { + /* int dg = abs(ig - g); */ + int dg = ((ig > g) ? ig - g : g - ig); + int dt = dr + dg; + int dm = ((dr > dg) ? dr : dg); + int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS); + + for (ib = 0; ib < num_blue; ib++) + { + int d_index = index_g | ib; + /* int db = abs(ib - b); */ + int db = ((ib > b) ? ib - b : b - ib); + int dmax = ((dm > db) ? dm : db); + int d = dmax + dt + db; + + if (d < (int)distance[d_index]) + { + distance[d_index] = (png_byte)d; + png_ptr->palette_lookup[d_index] = (png_byte)i; + } + } + } + } + } + + png_free(png_ptr, distance); + } +} +#endif /* READ_QUANTIZE */ + +#ifdef PNG_READ_GAMMA_SUPPORTED +void PNGFAPI +png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma, + png_fixed_point file_gamma) +{ + png_debug(1, "in png_set_gamma_fixed"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + /* New in libpng-1.5.4 - reserve particular negative values as flags. */ + scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/); + file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/); + + /* Checking the gamma values for being >0 was added in 1.5.4 along with the + * premultiplied alpha support; this actually hides an undocumented feature + * of the previous implementation which allowed gamma processing to be + * disabled in background handling. There is no evidence (so far) that this + * was being used; however, png_set_background itself accepted and must still + * accept '0' for the gamma value it takes, because it isn't always used. + * + * Since this is an API change (albeit a very minor one that removes an + * undocumented API feature) the following checks were only enabled in + * libpng-1.6.0. + */ + if (file_gamma <= 0) + png_error(png_ptr, "invalid file gamma in png_set_gamma"); + + if (scrn_gamma <= 0) + png_error(png_ptr, "invalid screen gamma in png_set_gamma"); + + /* Set the gamma values unconditionally - this overrides the value in the PNG + * file if a gAMA chunk was present. png_set_alpha_mode provides a + * different, easier, way to default the file gamma. + */ + png_ptr->colorspace.gamma = file_gamma; + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; + png_ptr->screen_gamma = scrn_gamma; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma) +{ + png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma), + convert_gamma_value(png_ptr, file_gamma)); +} +# endif /* FLOATING_POINT */ +#endif /* READ_GAMMA */ + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expand paletted images to RGB, expand grayscale images of + * less than 8-bit depth to 8-bit depth, and expand tRNS chunks + * to alpha channels. + */ +void PNGAPI +png_set_expand(png_structrp png_ptr) +{ + png_debug(1, "in png_set_expand"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} + +/* GRR 19990627: the following three functions currently are identical + * to png_set_expand(). However, it is entirely reasonable that someone + * might wish to expand an indexed image to RGB but *not* expand a single, + * fully transparent palette entry to a full alpha channel--perhaps instead + * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace + * the transparent color with a particular RGB value, or drop tRNS entirely. + * IOW, a future version of the library may make the transformations flag + * a bit more fine-grained, with separate bits for each of these three + * functions. + * + * More to the point, these functions make it obvious what libpng will be + * doing, whereas "expand" can (and does) mean any number of things. + * + * GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified + * to expand only the sample depth but not to expand the tRNS to alpha + * and its name was changed to png_set_expand_gray_1_2_4_to_8(). + */ + +/* Expand paletted images to RGB. */ +void PNGAPI +png_set_palette_to_rgb(png_structrp png_ptr) +{ + png_debug(1, "in png_set_palette_to_rgb"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} + +/* Expand grayscale images of less than 8-bit depth to 8 bits. */ +void PNGAPI +png_set_expand_gray_1_2_4_to_8(png_structrp png_ptr) +{ + png_debug(1, "in png_set_expand_gray_1_2_4_to_8"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= PNG_EXPAND; +} + +/* Expand tRNS chunks to alpha channels. */ +void PNGAPI +png_set_tRNS_to_alpha(png_structrp png_ptr) +{ + png_debug(1, "in png_set_tRNS_to_alpha"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} +#endif /* READ_EXPAND */ + +#ifdef PNG_READ_EXPAND_16_SUPPORTED +/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise + * it may not work correctly.) + */ +void PNGAPI +png_set_expand_16(png_structrp png_ptr) +{ + png_debug(1, "in png_set_expand_16"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS); +} +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +void PNGAPI +png_set_gray_to_rgb(png_structrp png_ptr) +{ + png_debug(1, "in png_set_gray_to_rgb"); + + if (png_rtran_ok(png_ptr, 0) == 0) + return; + + /* Because rgb must be 8 bits or more: */ + png_set_expand_gray_1_2_4_to_8(png_ptr); + png_ptr->transformations |= PNG_GRAY_TO_RGB; +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +void PNGFAPI +png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action, + png_fixed_point red, png_fixed_point green) +{ + png_debug(1, "in png_set_rgb_to_gray"); + + /* Need the IHDR here because of the check on color_type below. */ + /* TODO: fix this */ + if (png_rtran_ok(png_ptr, 1) == 0) + return; + + switch (error_action) + { + case PNG_ERROR_ACTION_NONE: + png_ptr->transformations |= PNG_RGB_TO_GRAY; + break; + + case PNG_ERROR_ACTION_WARN: + png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; + break; + + case PNG_ERROR_ACTION_ERROR: + png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; + break; + + default: + png_error(png_ptr, "invalid error action to rgb_to_gray"); + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#ifdef PNG_READ_EXPAND_SUPPORTED + png_ptr->transformations |= PNG_EXPAND; +#else + { + /* Make this an error in 1.6 because otherwise the application may assume + * that it just worked and get a memory overwrite. + */ + png_error(png_ptr, + "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED"); + + /* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */ + } +#endif + { + if (red >= 0 && green >= 0 && red + green <= PNG_FP_1) + { + png_uint_16 red_int, green_int; + + /* NOTE: this calculation does not round, but this behavior is retained + * for consistency; the inaccuracy is very small. The code here always + * overwrites the coefficients, regardless of whether they have been + * defaulted or set already. + */ + red_int = (png_uint_16)(((png_uint_32)red*32768)/100000); + green_int = (png_uint_16)(((png_uint_32)green*32768)/100000); + + png_ptr->rgb_to_gray_red_coeff = red_int; + png_ptr->rgb_to_gray_green_coeff = green_int; + png_ptr->rgb_to_gray_coefficients_set = 1; + } + + else + { + if (red >= 0 && green >= 0) + png_app_warning(png_ptr, + "ignoring out of range rgb_to_gray coefficients"); + + /* Use the defaults, from the cHRM chunk if set, else the historical + * values which are close to the sRGB/HDTV/ITU-Rec 709 values. See + * png_do_rgb_to_gray for more discussion of the values. In this case + * the coefficients are not marked as 'set' and are not overwritten if + * something has already provided a default. + */ + if (png_ptr->rgb_to_gray_red_coeff == 0 && + png_ptr->rgb_to_gray_green_coeff == 0) + { + png_ptr->rgb_to_gray_red_coeff = 6968; + png_ptr->rgb_to_gray_green_coeff = 23434; + /* png_ptr->rgb_to_gray_blue_coeff = 2366; */ + } + } + } +} + +#ifdef PNG_FLOATING_POINT_SUPPORTED +/* Convert a RGB image to a grayscale of the same width. This allows us, + * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. + */ + +void PNGAPI +png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red, + double green) +{ + png_set_rgb_to_gray_fixed(png_ptr, error_action, + png_fixed(png_ptr, red, "rgb to gray red coefficient"), + png_fixed(png_ptr, green, "rgb to gray green coefficient")); +} +#endif /* FLOATING POINT */ + +#endif /* RGB_TO_GRAY */ + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +void PNGAPI +png_set_read_user_transform_fn(png_structrp png_ptr, png_user_transform_ptr + read_user_transform_fn) +{ + png_debug(1, "in png_set_read_user_transform_fn"); + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + png_ptr->transformations |= PNG_USER_TRANSFORM; + png_ptr->read_user_transform_fn = read_user_transform_fn; +#endif +} +#endif + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +#ifdef PNG_READ_GAMMA_SUPPORTED +/* In the case of gamma transformations only do transformations on images where + * the [file] gamma and screen_gamma are not close reciprocals, otherwise it + * slows things down slightly, and also needlessly introduces small errors. + */ +static int /* PRIVATE */ +png_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma) +{ + /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma + * correction as a difference of the overall transform from 1.0 + * + * We want to compare the threshold with s*f - 1, if we get + * overflow here it is because of wacky gamma values so we + * turn on processing anyway. + */ + png_fixed_point gtest; + return !png_muldiv(>est, screen_gamma, file_gamma, PNG_FP_1) || + png_gamma_significant(gtest); +} +#endif + +/* Initialize everything needed for the read. This includes modifying + * the palette. + */ + +/* For the moment 'png_init_palette_transformations' and + * 'png_init_rgb_transformations' only do some flag canceling optimizations. + * The intent is that these two routines should have palette or rgb operations + * extracted from 'png_init_read_transformations'. + */ +static void /* PRIVATE */ +png_init_palette_transformations(png_structrp png_ptr) +{ + /* Called to handle the (input) palette case. In png_do_read_transformations + * the first step is to expand the palette if requested, so this code must + * take care to only make changes that are invariant with respect to the + * palette expansion, or only do them if there is no expansion. + * + * STRIP_ALPHA has already been handled in the caller (by setting num_trans + * to 0.) + */ + int input_has_alpha = 0; + int input_has_transparency = 0; + + if (png_ptr->num_trans > 0) + { + int i; + + /* Ignore if all the entries are opaque (unlikely!) */ + for (i=0; inum_trans; ++i) + { + if (png_ptr->trans_alpha[i] == 255) + continue; + else if (png_ptr->trans_alpha[i] == 0) + input_has_transparency = 1; + else + { + input_has_transparency = 1; + input_has_alpha = 1; + break; + } + } + } + + /* If no alpha we can optimize. */ + if (input_has_alpha == 0) + { + /* Any alpha means background and associative alpha processing is + * required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA + * and ENCODE_ALPHA are irrelevant. + */ + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + + if (input_has_transparency == 0) + png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND); + } + +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) + /* png_set_background handling - deals with the complexity of whether the + * background color is in the file format or the screen format in the case + * where an 'expand' will happen. + */ + + /* The following code cannot be entered in the alpha pre-multiplication case + * because PNG_BACKGROUND_EXPAND is cancelled below. + */ + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 && + (png_ptr->transformations & PNG_EXPAND) != 0) + { + { + png_ptr->background.red = + png_ptr->palette[png_ptr->background.index].red; + png_ptr->background.green = + png_ptr->palette[png_ptr->background.index].green; + png_ptr->background.blue = + png_ptr->palette[png_ptr->background.index].blue; + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0) + { + if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0) + { + /* Invert the alpha channel (in tRNS) unless the pixels are + * going to be expanded, in which case leave it for later + */ + int i, istop = png_ptr->num_trans; + + for (i = 0; i < istop; i++) + png_ptr->trans_alpha[i] = + (png_byte)(255 - png_ptr->trans_alpha[i]); + } + } +#endif /* READ_INVERT_ALPHA */ + } + } /* background expand and (therefore) no alpha association. */ +#endif /* READ_EXPAND && READ_BACKGROUND */ +} + +static void /* PRIVATE */ +png_init_rgb_transformations(png_structrp png_ptr) +{ + /* Added to libpng-1.5.4: check the color type to determine whether there + * is any alpha or transparency in the image and simply cancel the + * background and alpha mode stuff if there isn't. + */ + int input_has_alpha = (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0; + int input_has_transparency = png_ptr->num_trans > 0; + + /* If no alpha we can optimize. */ + if (input_has_alpha == 0) + { + /* Any alpha means background and associative alpha processing is + * required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA + * and ENCODE_ALPHA are irrelevant. + */ +# ifdef PNG_READ_ALPHA_MODE_SUPPORTED + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; +# endif + + if (input_has_transparency == 0) + png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND); + } + +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) + /* png_set_background handling - deals with the complexity of whether the + * background color is in the file format or the screen format in the case + * where an 'expand' will happen. + */ + + /* The following code cannot be entered in the alpha pre-multiplication case + * because PNG_BACKGROUND_EXPAND is cancelled below. + */ + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 && + (png_ptr->transformations & PNG_EXPAND) != 0 && + (png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) + /* i.e., GRAY or GRAY_ALPHA */ + { + { + /* Expand background and tRNS chunks */ + int gray = png_ptr->background.gray; + int trans_gray = png_ptr->trans_color.gray; + + switch (png_ptr->bit_depth) + { + case 1: + gray *= 0xff; + trans_gray *= 0xff; + break; + + case 2: + gray *= 0x55; + trans_gray *= 0x55; + break; + + case 4: + gray *= 0x11; + trans_gray *= 0x11; + break; + + default: + + case 8: + /* FALLTHROUGH */ /* (Already 8 bits) */ + + case 16: + /* Already a full 16 bits */ + break; + } + + png_ptr->background.red = png_ptr->background.green = + png_ptr->background.blue = (png_uint_16)gray; + + if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0) + { + png_ptr->trans_color.red = png_ptr->trans_color.green = + png_ptr->trans_color.blue = (png_uint_16)trans_gray; + } + } + } /* background expand and (therefore) no alpha association. */ +#endif /* READ_EXPAND && READ_BACKGROUND */ +} + +void /* PRIVATE */ +png_init_read_transformations(png_structrp png_ptr) +{ + png_debug(1, "in png_init_read_transformations"); + + /* This internal function is called from png_read_start_row in pngrutil.c + * and it is called before the 'rowbytes' calculation is done, so the code + * in here can change or update the transformations flags. + * + * First do updates that do not depend on the details of the PNG image data + * being processed. + */ + +#ifdef PNG_READ_GAMMA_SUPPORTED + /* Prior to 1.5.4 these tests were performed from png_set_gamma, 1.5.4 adds + * png_set_alpha_mode and this is another source for a default file gamma so + * the test needs to be performed later - here. In addition prior to 1.5.4 + * the tests were repeated for the PALETTE color type here - this is no + * longer necessary (and doesn't seem to have been necessary before.) + */ + { + /* The following temporary indicates if overall gamma correction is + * required. + */ + int gamma_correction = 0; + + if (png_ptr->colorspace.gamma != 0) /* has been set */ + { + if (png_ptr->screen_gamma != 0) /* screen set too */ + gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma, + png_ptr->screen_gamma); + + else + /* Assume the output matches the input; a long time default behavior + * of libpng, although the standard has nothing to say about this. + */ + png_ptr->screen_gamma = png_reciprocal(png_ptr->colorspace.gamma); + } + + else if (png_ptr->screen_gamma != 0) + /* The converse - assume the file matches the screen, note that this + * perhaps undesirable default can (from 1.5.4) be changed by calling + * png_set_alpha_mode (even if the alpha handling mode isn't required + * or isn't changed from the default.) + */ + png_ptr->colorspace.gamma = png_reciprocal(png_ptr->screen_gamma); + + else /* neither are set */ + /* Just in case the following prevents any processing - file and screen + * are both assumed to be linear and there is no way to introduce a + * third gamma value other than png_set_background with 'UNIQUE', and, + * prior to 1.5.4 + */ + png_ptr->screen_gamma = png_ptr->colorspace.gamma = PNG_FP_1; + + /* We have a gamma value now. */ + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; + + /* Now turn the gamma transformation on or off as appropriate. Notice + * that PNG_GAMMA just refers to the file->screen correction. Alpha + * composition may independently cause gamma correction because it needs + * linear data (e.g. if the file has a gAMA chunk but the screen gamma + * hasn't been specified.) In any case this flag may get turned off in + * the code immediately below if the transform can be handled outside the + * row loop. + */ + if (gamma_correction != 0) + png_ptr->transformations |= PNG_GAMMA; + + else + png_ptr->transformations &= ~PNG_GAMMA; + } +#endif + + /* Certain transformations have the effect of preventing other + * transformations that happen afterward in png_do_read_transformations; + * resolve the interdependencies here. From the code of + * png_do_read_transformations the order is: + * + * 1) PNG_EXPAND (including PNG_EXPAND_tRNS) + * 2) PNG_STRIP_ALPHA (if no compose) + * 3) PNG_RGB_TO_GRAY + * 4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY + * 5) PNG_COMPOSE + * 6) PNG_GAMMA + * 7) PNG_STRIP_ALPHA (if compose) + * 8) PNG_ENCODE_ALPHA + * 9) PNG_SCALE_16_TO_8 + * 10) PNG_16_TO_8 + * 11) PNG_QUANTIZE (converts to palette) + * 12) PNG_EXPAND_16 + * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY + * 14) PNG_INVERT_MONO + * 15) PNG_INVERT_ALPHA + * 16) PNG_SHIFT + * 17) PNG_PACK + * 18) PNG_BGR + * 19) PNG_PACKSWAP + * 20) PNG_FILLER (includes PNG_ADD_ALPHA) + * 21) PNG_SWAP_ALPHA + * 22) PNG_SWAP_BYTES + * 23) PNG_USER_TRANSFORM [must be last] + */ +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 && + (png_ptr->transformations & PNG_COMPOSE) == 0) + { + /* Stripping the alpha channel happens immediately after the 'expand' + * transformations, before all other transformation, so it cancels out + * the alpha handling. It has the side effect negating the effect of + * PNG_EXPAND_tRNS too: + */ + png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA | + PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + + /* Kill the tRNS chunk itself too. Prior to 1.5.4 this did not happen + * so transparency information would remain just so long as it wasn't + * expanded. This produces unexpected API changes if the set of things + * that do PNG_EXPAND_tRNS changes (perfectly possible given the + * documentation - which says ask for what you want, accept what you + * get.) This makes the behavior consistent from 1.5.4: + */ + png_ptr->num_trans = 0; + } +#endif /* STRIP_ALPHA supported, no COMPOSE */ + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED + /* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA + * settings will have no effect. + */ + if (png_gamma_significant(png_ptr->screen_gamma) == 0) + { + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + } +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* Make sure the coefficients for the rgb to gray conversion are set + * appropriately. + */ + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) + png_colorspace_set_rgb_coefficients(png_ptr); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) + /* Detect gray background and attempt to enable optimization for + * gray --> RGB case. + * + * Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or + * RGB_ALPHA (in which case need_expand is superfluous anyway), the + * background color might actually be gray yet not be flagged as such. + * This is not a problem for the current code, which uses + * PNG_BACKGROUND_IS_GRAY only to decide when to do the + * png_do_gray_to_rgb() transformation. + * + * TODO: this code needs to be revised to avoid the complexity and + * interdependencies. The color type of the background should be recorded in + * png_set_background, along with the bit depth, then the code has a record + * of exactly what color space the background is currently in. + */ + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0) + { + /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if + * the file was grayscale the background value is gray. + */ + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; + } + + else if ((png_ptr->transformations & PNG_COMPOSE) != 0) + { + /* PNG_COMPOSE: png_set_background was called with need_expand false, + * so the color is in the color space of the output or png_set_alpha_mode + * was called and the color is black. Ignore RGB_TO_GRAY because that + * happens before GRAY_TO_RGB. + */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0) + { + if (png_ptr->background.red == png_ptr->background.green && + png_ptr->background.red == png_ptr->background.blue) + { + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; + png_ptr->background.gray = png_ptr->background.red; + } + } + } +#endif /* READ_EXPAND && READ_BACKGROUND */ +#endif /* READ_GRAY_TO_RGB */ + + /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations + * can be performed directly on the palette, and some (such as rgb to gray) + * can be optimized inside the palette. This is particularly true of the + * composite (background and alpha) stuff, which can be pretty much all done + * in the palette even if the result is expanded to RGB or gray afterward. + * + * NOTE: this is Not Yet Implemented, the code behaves as in 1.5.1 and + * earlier and the palette stuff is actually handled on the first row. This + * leads to the reported bug that the palette returned by png_get_PLTE is not + * updated. + */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_init_palette_transformations(png_ptr); + + else + png_init_rgb_transformations(png_ptr); + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + defined(PNG_READ_EXPAND_16_SUPPORTED) + if ((png_ptr->transformations & PNG_EXPAND_16) != 0 && + (png_ptr->transformations & PNG_COMPOSE) != 0 && + (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 && + png_ptr->bit_depth != 16) + { + /* TODO: fix this. Because the expand_16 operation is after the compose + * handling the background color must be 8, not 16, bits deep, but the + * application will supply a 16-bit value so reduce it here. + * + * The PNG_BACKGROUND_EXPAND code above does not expand to 16 bits at + * present, so that case is ok (until do_expand_16 is moved.) + * + * NOTE: this discards the low 16 bits of the user supplied background + * color, but until expand_16 works properly there is no choice! + */ +# define CHOP(x) (x)=((png_uint_16)PNG_DIV257(x)) + CHOP(png_ptr->background.red); + CHOP(png_ptr->background.green); + CHOP(png_ptr->background.blue); + CHOP(png_ptr->background.gray); +# undef CHOP + } +#endif /* READ_BACKGROUND && READ_EXPAND_16 */ + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \ + defined(PNG_READ_STRIP_16_TO_8_SUPPORTED)) + if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) != 0 && + (png_ptr->transformations & PNG_COMPOSE) != 0 && + (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 && + png_ptr->bit_depth == 16) + { + /* On the other hand, if a 16-bit file is to be reduced to 8-bits per + * component this will also happen after PNG_COMPOSE and so the background + * color must be pre-expanded here. + * + * TODO: fix this too. + */ + png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257); + png_ptr->background.green = + (png_uint_16)(png_ptr->background.green * 257); + png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257); + png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257); + } +#endif + + /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the + * background support (see the comments in scripts/pnglibconf.dfa), this + * allows pre-multiplication of the alpha channel to be implemented as + * compositing on black. This is probably sub-optimal and has been done in + * 1.5.4 betas simply to enable external critique and testing (i.e. to + * implement the new API quickly, without lots of internal changes.) + */ + +#ifdef PNG_READ_GAMMA_SUPPORTED +# ifdef PNG_READ_BACKGROUND_SUPPORTED + /* Includes ALPHA_MODE */ + png_ptr->background_1 = png_ptr->background; +# endif + + /* This needs to change - in the palette image case a whole set of tables are + * built when it would be quicker to just calculate the correct value for + * each palette entry directly. Also, the test is too tricky - why check + * PNG_RGB_TO_GRAY if PNG_GAMMA is not set? The answer seems to be that + * PNG_GAMMA is cancelled even if the gamma is known? The test excludes the + * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction + * the gamma tables will not be built even if composition is required on a + * gamma encoded value. + * + * In 1.5.4 this is addressed below by an additional check on the individual + * file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the + * tables. + */ + if ((png_ptr->transformations & PNG_GAMMA) != 0 || + ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0 && + (png_gamma_significant(png_ptr->colorspace.gamma) != 0 || + png_gamma_significant(png_ptr->screen_gamma) != 0)) || + ((png_ptr->transformations & PNG_COMPOSE) != 0 && + (png_gamma_significant(png_ptr->colorspace.gamma) != 0 || + png_gamma_significant(png_ptr->screen_gamma) != 0 +# ifdef PNG_READ_BACKGROUND_SUPPORTED + || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE && + png_gamma_significant(png_ptr->background_gamma) != 0) +# endif + )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 && + png_gamma_significant(png_ptr->screen_gamma) != 0)) + { + png_build_gamma_table(png_ptr, png_ptr->bit_depth); + +#ifdef PNG_READ_BACKGROUND_SUPPORTED + if ((png_ptr->transformations & PNG_COMPOSE) != 0) + { + /* Issue a warning about this combination: because RGB_TO_GRAY is + * optimized to do the gamma transform if present yet do_background has + * to do the same thing if both options are set a + * double-gamma-correction happens. This is true in all versions of + * libpng to date. + */ + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) + png_warning(png_ptr, + "libpng does not support gamma+background+rgb_to_gray"); + + if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0) + { + /* We don't get to here unless there is a tRNS chunk with non-opaque + * entries - see the checking code at the start of this function. + */ + png_color back, back_1; + png_colorp palette = png_ptr->palette; + int num_palette = png_ptr->num_palette; + int i; + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) + { + + back.red = png_ptr->gamma_table[png_ptr->background.red]; + back.green = png_ptr->gamma_table[png_ptr->background.green]; + back.blue = png_ptr->gamma_table[png_ptr->background.blue]; + + back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; + back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; + back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; + } + else + { + png_fixed_point g, gs; + + switch (png_ptr->background_gamma_type) + { + case PNG_BACKGROUND_GAMMA_SCREEN: + g = (png_ptr->screen_gamma); + gs = PNG_FP_1; + break; + + case PNG_BACKGROUND_GAMMA_FILE: + g = png_reciprocal(png_ptr->colorspace.gamma); + gs = png_reciprocal2(png_ptr->colorspace.gamma, + png_ptr->screen_gamma); + break; + + case PNG_BACKGROUND_GAMMA_UNIQUE: + g = png_reciprocal(png_ptr->background_gamma); + gs = png_reciprocal2(png_ptr->background_gamma, + png_ptr->screen_gamma); + break; + default: + g = PNG_FP_1; /* back_1 */ + gs = PNG_FP_1; /* back */ + break; + } + + if (png_gamma_significant(gs) != 0) + { + back.red = png_gamma_8bit_correct(png_ptr->background.red, + gs); + back.green = png_gamma_8bit_correct(png_ptr->background.green, + gs); + back.blue = png_gamma_8bit_correct(png_ptr->background.blue, + gs); + } + + else + { + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + } + + if (png_gamma_significant(g) != 0) + { + back_1.red = png_gamma_8bit_correct(png_ptr->background.red, + g); + back_1.green = png_gamma_8bit_correct( + png_ptr->background.green, g); + back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue, + g); + } + + else + { + back_1.red = (png_byte)png_ptr->background.red; + back_1.green = (png_byte)png_ptr->background.green; + back_1.blue = (png_byte)png_ptr->background.blue; + } + } + + for (i = 0; i < num_palette; i++) + { + if (i < (int)png_ptr->num_trans && + png_ptr->trans_alpha[i] != 0xff) + { + if (png_ptr->trans_alpha[i] == 0) + { + palette[i] = back; + } + else /* if (png_ptr->trans_alpha[i] != 0xff) */ + { + png_byte v, w; + + v = png_ptr->gamma_to_1[palette[i].red]; + png_composite(w, v, png_ptr->trans_alpha[i], back_1.red); + palette[i].red = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[palette[i].green]; + png_composite(w, v, png_ptr->trans_alpha[i], back_1.green); + palette[i].green = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[palette[i].blue]; + png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue); + palette[i].blue = png_ptr->gamma_from_1[w]; + } + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + + /* Prevent the transformations being done again. + * + * NOTE: this is highly dubious; it removes the transformations in + * place. This seems inconsistent with the general treatment of the + * transformations elsewhere. + */ + png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA); + } /* color_type == PNG_COLOR_TYPE_PALETTE */ + + /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ + else /* color_type != PNG_COLOR_TYPE_PALETTE */ + { + int gs_sig, g_sig; + png_fixed_point g = PNG_FP_1; /* Correction to linear */ + png_fixed_point gs = PNG_FP_1; /* Correction to screen */ + + switch (png_ptr->background_gamma_type) + { + case PNG_BACKGROUND_GAMMA_SCREEN: + g = png_ptr->screen_gamma; + /* gs = PNG_FP_1; */ + break; + + case PNG_BACKGROUND_GAMMA_FILE: + g = png_reciprocal(png_ptr->colorspace.gamma); + gs = png_reciprocal2(png_ptr->colorspace.gamma, + png_ptr->screen_gamma); + break; + + case PNG_BACKGROUND_GAMMA_UNIQUE: + g = png_reciprocal(png_ptr->background_gamma); + gs = png_reciprocal2(png_ptr->background_gamma, + png_ptr->screen_gamma); + break; + + default: + png_error(png_ptr, "invalid background gamma type"); + } + + g_sig = png_gamma_significant(g); + gs_sig = png_gamma_significant(gs); + + if (g_sig != 0) + png_ptr->background_1.gray = png_gamma_correct(png_ptr, + png_ptr->background.gray, g); + + if (gs_sig != 0) + png_ptr->background.gray = png_gamma_correct(png_ptr, + png_ptr->background.gray, gs); + + if ((png_ptr->background.red != png_ptr->background.green) || + (png_ptr->background.red != png_ptr->background.blue) || + (png_ptr->background.red != png_ptr->background.gray)) + { + /* RGB or RGBA with color background */ + if (g_sig != 0) + { + png_ptr->background_1.red = png_gamma_correct(png_ptr, + png_ptr->background.red, g); + + png_ptr->background_1.green = png_gamma_correct(png_ptr, + png_ptr->background.green, g); + + png_ptr->background_1.blue = png_gamma_correct(png_ptr, + png_ptr->background.blue, g); + } + + if (gs_sig != 0) + { + png_ptr->background.red = png_gamma_correct(png_ptr, + png_ptr->background.red, gs); + + png_ptr->background.green = png_gamma_correct(png_ptr, + png_ptr->background.green, gs); + + png_ptr->background.blue = png_gamma_correct(png_ptr, + png_ptr->background.blue, gs); + } + } + + else + { + /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */ + png_ptr->background_1.red = png_ptr->background_1.green + = png_ptr->background_1.blue = png_ptr->background_1.gray; + + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + } + + /* The background is now in screen gamma: */ + png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN; + } /* color_type != PNG_COLOR_TYPE_PALETTE */ + }/* png_ptr->transformations & PNG_BACKGROUND */ + + else + /* Transformation does not include PNG_BACKGROUND */ +#endif /* READ_BACKGROUND */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* RGB_TO_GRAY needs to have non-gamma-corrected values! */ + && ((png_ptr->transformations & PNG_EXPAND) == 0 || + (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0) +#endif + ) + { + png_colorp palette = png_ptr->palette; + int num_palette = png_ptr->num_palette; + int i; + + /* NOTE: there are other transformations that should probably be in + * here too. + */ + for (i = 0; i < num_palette; i++) + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + + /* Done the gamma correction. */ + png_ptr->transformations &= ~PNG_GAMMA; + } /* color_type == PALETTE && !PNG_BACKGROUND transformation */ + } +#ifdef PNG_READ_BACKGROUND_SUPPORTED + else +#endif +#endif /* READ_GAMMA */ + +#ifdef PNG_READ_BACKGROUND_SUPPORTED + /* No GAMMA transformation (see the hanging else 4 lines above) */ + if ((png_ptr->transformations & PNG_COMPOSE) != 0 && + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) + { + int i; + int istop = (int)png_ptr->num_trans; + png_color back; + png_colorp palette = png_ptr->palette; + + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + + for (i = 0; i < istop; i++) + { + if (png_ptr->trans_alpha[i] == 0) + { + palette[i] = back; + } + + else if (png_ptr->trans_alpha[i] != 0xff) + { + /* The png_composite() macro is defined in png.h */ + png_composite(palette[i].red, palette[i].red, + png_ptr->trans_alpha[i], back.red); + + png_composite(palette[i].green, palette[i].green, + png_ptr->trans_alpha[i], back.green); + + png_composite(palette[i].blue, palette[i].blue, + png_ptr->trans_alpha[i], back.blue); + } + } + + png_ptr->transformations &= ~PNG_COMPOSE; + } +#endif /* READ_BACKGROUND */ + +#ifdef PNG_READ_SHIFT_SUPPORTED + if ((png_ptr->transformations & PNG_SHIFT) != 0 && + (png_ptr->transformations & PNG_EXPAND) == 0 && + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) + { + int i; + int istop = png_ptr->num_palette; + int shift = 8 - png_ptr->sig_bit.red; + + png_ptr->transformations &= ~PNG_SHIFT; + + /* significant bits can be in the range 1 to 7 for a meaningful result, if + * the number of significant bits is 0 then no shift is done (this is an + * error condition which is silently ignored.) + */ + if (shift > 0 && shift < 8) + for (i=0; ipalette[i].red; + + component >>= shift; + png_ptr->palette[i].red = (png_byte)component; + } + + shift = 8 - png_ptr->sig_bit.green; + if (shift > 0 && shift < 8) + for (i=0; ipalette[i].green; + + component >>= shift; + png_ptr->palette[i].green = (png_byte)component; + } + + shift = 8 - png_ptr->sig_bit.blue; + if (shift > 0 && shift < 8) + for (i=0; ipalette[i].blue; + + component >>= shift; + png_ptr->palette[i].blue = (png_byte)component; + } + } +#endif /* READ_SHIFT */ +} + +/* Modify the info structure to reflect the transformations. The + * info should be updated so a PNG file could be written with it, + * assuming the transformations result in valid PNG data. + */ +void /* PRIVATE */ +png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr) +{ + png_debug(1, "in png_read_transform_info"); + +#ifdef PNG_READ_EXPAND_SUPPORTED + if ((png_ptr->transformations & PNG_EXPAND) != 0) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + /* This check must match what actually happens in + * png_do_expand_palette; if it ever checks the tRNS chunk to see if + * it is all opaque we must do the same (at present it does not.) + */ + if (png_ptr->num_trans > 0) + info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + + else + info_ptr->color_type = PNG_COLOR_TYPE_RGB; + + info_ptr->bit_depth = 8; + info_ptr->num_trans = 0; + + if (png_ptr->palette == NULL) + png_error (png_ptr, "Palette is NULL in indexed image"); + } + else + { + if (png_ptr->num_trans != 0) + { + if ((png_ptr->transformations & PNG_EXPAND_tRNS) != 0) + info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; + } + if (info_ptr->bit_depth < 8) + info_ptr->bit_depth = 8; + + info_ptr->num_trans = 0; + } + } +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) + /* The following is almost certainly wrong unless the background value is in + * the screen space! + */ + if ((png_ptr->transformations & PNG_COMPOSE) != 0) + info_ptr->background = png_ptr->background; +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + /* The following used to be conditional on PNG_GAMMA (prior to 1.5.4), + * however it seems that the code in png_init_read_transformations, which has + * been called before this from png_read_update_info->png_read_start_row + * sometimes does the gamma transform and cancels the flag. + * + * TODO: this looks wrong; the info_ptr should end up with a gamma equal to + * the screen_gamma value. The following probably results in weirdness if + * the info_ptr is used by the app after the rows have been read. + */ + info_ptr->colorspace.gamma = png_ptr->colorspace.gamma; +#endif + + if (info_ptr->bit_depth == 16) + { +# ifdef PNG_READ_16BIT_SUPPORTED +# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0) + info_ptr->bit_depth = 8; +# endif + +# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + if ((png_ptr->transformations & PNG_16_TO_8) != 0) + info_ptr->bit_depth = 8; +# endif + +# else + /* No 16-bit support: force chopping 16-bit input down to 8, in this case + * the app program can chose if both APIs are available by setting the + * correct scaling to use. + */ +# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + /* For compatibility with previous versions use the strip method by + * default. This code works because if PNG_SCALE_16_TO_8 is already + * set the code below will do that in preference to the chop. + */ + png_ptr->transformations |= PNG_16_TO_8; + info_ptr->bit_depth = 8; +# else + +# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + png_ptr->transformations |= PNG_SCALE_16_TO_8; + info_ptr->bit_depth = 8; +# else + + CONFIGURATION ERROR: you must enable at least one 16 to 8 method +# endif +# endif +#endif /* !READ_16BIT */ + } + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0) + info_ptr->color_type = (png_byte)(info_ptr->color_type | + PNG_COLOR_MASK_COLOR); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) + info_ptr->color_type = (png_byte)(info_ptr->color_type & + ~PNG_COLOR_MASK_COLOR); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + if ((png_ptr->transformations & PNG_QUANTIZE) != 0) + { + if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || + (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && + png_ptr->palette_lookup != 0 && info_ptr->bit_depth == 8) + { + info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; + } + } +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED + if ((png_ptr->transformations & PNG_EXPAND_16) != 0 && + info_ptr->bit_depth == 8 && + info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + info_ptr->bit_depth = 16; + } +#endif + +#ifdef PNG_READ_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) != 0 && + (info_ptr->bit_depth < 8)) + info_ptr->bit_depth = 8; +#endif + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + info_ptr->channels = 1; + + else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + info_ptr->channels = 3; + + else + info_ptr->channels = 1; + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0) + { + info_ptr->color_type = (png_byte)(info_ptr->color_type & + ~PNG_COLOR_MASK_ALPHA); + info_ptr->num_trans = 0; + } +#endif + + if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) + info_ptr->channels++; + +#ifdef PNG_READ_FILLER_SUPPORTED + /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ + if ((png_ptr->transformations & PNG_FILLER) != 0 && + (info_ptr->color_type == PNG_COLOR_TYPE_RGB || + info_ptr->color_type == PNG_COLOR_TYPE_GRAY)) + { + info_ptr->channels++; + /* If adding a true alpha channel not just filler */ + if ((png_ptr->transformations & PNG_ADD_ALPHA) != 0) + info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; + } +#endif + +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ +defined(PNG_READ_USER_TRANSFORM_SUPPORTED) + if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) + { + if (png_ptr->user_transform_depth != 0) + info_ptr->bit_depth = png_ptr->user_transform_depth; + + if (png_ptr->user_transform_channels != 0) + info_ptr->channels = png_ptr->user_transform_channels; + } +#endif + + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * + info_ptr->bit_depth); + + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width); + + /* Adding in 1.5.4: cache the above value in png_struct so that we can later + * check in png_rowbytes that the user buffer won't get overwritten. Note + * that the field is not always set - if png_read_update_info isn't called + * the application has to either not do any transforms or get the calculation + * right itself. + */ + png_ptr->info_rowbytes = info_ptr->rowbytes; + +#ifndef PNG_READ_EXPAND_SUPPORTED + if (png_ptr != NULL) + return; +#endif +} + +#ifdef PNG_READ_PACK_SUPPORTED +/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, + * without changing the actual values. Thus, if you had a row with + * a bit depth of 1, you would end up with bytes that only contained + * the numbers 0 or 1. If you would rather they contain 0 and 255, use + * png_do_shift() after this. + */ +static void +png_do_unpack(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_unpack"); + + if (row_info->bit_depth < 8) + { + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + switch (row_info->bit_depth) + { + case 1: + { + png_bytep sp = row + (size_t)((row_width - 1) >> 3); + png_bytep dp = row + (size_t)row_width - 1; + png_uint_32 shift = 7U - ((row_width + 7U) & 0x07); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x01); + + if (shift == 7) + { + shift = 0; + sp--; + } + + else + shift++; + + dp--; + } + break; + } + + case 2: + { + + png_bytep sp = row + (size_t)((row_width - 1) >> 2); + png_bytep dp = row + (size_t)row_width - 1; + png_uint_32 shift = ((3U - ((row_width + 3U) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x03); + + if (shift == 6) + { + shift = 0; + sp--; + } + + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + png_bytep sp = row + (size_t)((row_width - 1) >> 1); + png_bytep dp = row + (size_t)row_width - 1; + png_uint_32 shift = ((1U - ((row_width + 1U) & 0x01)) << 2); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x0f); + + if (shift == 4) + { + shift = 0; + sp--; + } + + else + shift = 4; + + dp--; + } + break; + } + + default: + break; + } + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_width * row_info->channels; + } +} +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED +/* Reverse the effects of png_do_shift. This routine merely shifts the + * pixels back to their significant bits values. Thus, if you have + * a row of bit depth 8, but only 5 are significant, this will shift + * the values back to 0 through 31. + */ +static void +png_do_unshift(png_row_infop row_info, png_bytep row, + png_const_color_8p sig_bits) +{ + int color_type; + + png_debug(1, "in png_do_unshift"); + + /* The palette case has already been handled in the _init routine. */ + color_type = row_info->color_type; + + if (color_type != PNG_COLOR_TYPE_PALETTE) + { + int shift[4]; + int channels = 0; + int bit_depth = row_info->bit_depth; + + if ((color_type & PNG_COLOR_MASK_COLOR) != 0) + { + shift[channels++] = bit_depth - sig_bits->red; + shift[channels++] = bit_depth - sig_bits->green; + shift[channels++] = bit_depth - sig_bits->blue; + } + + else + { + shift[channels++] = bit_depth - sig_bits->gray; + } + + if ((color_type & PNG_COLOR_MASK_ALPHA) != 0) + { + shift[channels++] = bit_depth - sig_bits->alpha; + } + + { + int c, have_shift; + + for (c = have_shift = 0; c < channels; ++c) + { + /* A shift of more than the bit depth is an error condition but it + * gets ignored here. + */ + if (shift[c] <= 0 || shift[c] >= bit_depth) + shift[c] = 0; + + else + have_shift = 1; + } + + if (have_shift == 0) + return; + } + + switch (bit_depth) + { + default: + /* Must be 1bpp gray: should not be here! */ + /* NOTREACHED */ + break; + + case 2: + /* Must be 2bpp gray */ + /* assert(channels == 1 && shift[0] == 1) */ + { + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; + + while (bp < bp_end) + { + int b = (*bp >> 1) & 0x55; + *bp++ = (png_byte)b; + } + break; + } + + case 4: + /* Must be 4bpp gray */ + /* assert(channels == 1) */ + { + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; + int gray_shift = shift[0]; + int mask = 0xf >> gray_shift; + + mask |= mask << 4; + + while (bp < bp_end) + { + int b = (*bp >> gray_shift) & mask; + *bp++ = (png_byte)b; + } + break; + } + + case 8: + /* Single byte components, G, GA, RGB, RGBA */ + { + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; + int channel = 0; + + while (bp < bp_end) + { + int b = *bp >> shift[channel]; + if (++channel >= channels) + channel = 0; + *bp++ = (png_byte)b; + } + break; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + case 16: + /* Double byte components, G, GA, RGB, RGBA */ + { + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; + int channel = 0; + + while (bp < bp_end) + { + int value = (bp[0] << 8) + bp[1]; + + value >>= shift[channel]; + if (++channel >= channels) + channel = 0; + *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)value; + } + break; + } + } +#endif + } +} +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED +/* Scale rows of bit depth 16 down to 8 accurately */ +static void +png_do_scale_16_to_8(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_scale_16_to_8"); + + if (row_info->bit_depth == 16) + { + png_bytep sp = row; /* source */ + png_bytep dp = row; /* destination */ + png_bytep ep = sp + row_info->rowbytes; /* end+1 */ + + while (sp < ep) + { + /* The input is an array of 16-bit components, these must be scaled to + * 8 bits each. For a 16-bit value V the required value (from the PNG + * specification) is: + * + * (V * 255) / 65535 + * + * This reduces to round(V / 257), or floor((V + 128.5)/257) + * + * Represent V as the two byte value vhi.vlo. Make a guess that the + * result is the top byte of V, vhi, then the correction to this value + * is: + * + * error = floor(((V-vhi.vhi) + 128.5) / 257) + * = floor(((vlo-vhi) + 128.5) / 257) + * + * This can be approximated using integer arithmetic (and a signed + * shift): + * + * error = (vlo-vhi+128) >> 8; + * + * The approximate differs from the exact answer only when (vlo-vhi) is + * 128; it then gives a correction of +1 when the exact correction is + * 0. This gives 128 errors. The exact answer (correct for all 16-bit + * input values) is: + * + * error = (vlo-vhi+128)*65535 >> 24; + * + * An alternative arithmetic calculation which also gives no errors is: + * + * (V * 255 + 32895) >> 16 + */ + + png_int_32 tmp = *sp++; /* must be signed! */ + tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24; + *dp++ = (png_byte)tmp; + } + + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_info->width * row_info->channels; + } +} +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED +static void +/* Simply discard the low byte. This was the default behavior prior + * to libpng-1.5.4. + */ +png_do_chop(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_chop"); + + if (row_info->bit_depth == 16) + { + png_bytep sp = row; /* source */ + png_bytep dp = row; /* destination */ + png_bytep ep = sp + row_info->rowbytes; /* end+1 */ + + while (sp < ep) + { + *dp++ = *sp; + sp += 2; /* skip low byte */ + } + + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_info->width * row_info->channels; + } +} +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED +static void +png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) +{ + png_uint_32 row_width = row_info->width; + + png_debug(1, "in png_do_read_swap_alpha"); + + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This converts from RGBA to ARGB */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + /* This converts from RRGGBBAA to AARRGGBB */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save[2]; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save[0] = *(--sp); + save[1] = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save[0]; + *(--dp) = save[1]; + } + } +#endif + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This converts from GA to AG */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save; + } + } +#endif + } + +#ifdef PNG_READ_16BIT_SUPPORTED + /* This converts from GGAA to AAGG */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save[2]; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save[0] = *(--sp); + save[1] = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save[0]; + *(--dp) = save[1]; + } + } +#endif + } +} +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED +static void +png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) +{ + png_uint_32 row_width; + png_debug(1, "in png_do_read_invert_alpha"); + + row_width = row_info->width; + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This inverts the alpha channel in RGBA */ + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + +/* This does nothing: + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + We can replace it with: +*/ + sp-=3; + dp=sp; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + /* This inverts the alpha channel in RRGGBBAA */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = (png_byte)(255 - *(--sp)); + +/* This does nothing: + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + We can replace it with: +*/ + sp-=6; + dp=sp; + } + } +#endif + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This inverts the alpha channel in GA */ + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = *(--sp); + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + else + { + /* This inverts the alpha channel in GGAA */ + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = (png_byte)(255 - *(--sp)); +/* + *(--dp) = *(--sp); + *(--dp) = *(--sp); +*/ + sp-=2; + dp=sp; + } + } +#endif + } +} +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED +/* Add filler channel if we have RGB color */ +static void +png_do_read_filler(png_row_infop row_info, png_bytep row, + png_uint_32 filler, png_uint_32 flags) +{ + png_uint_32 i; + png_uint_32 row_width = row_info->width; + +#ifdef PNG_READ_16BIT_SUPPORTED + png_byte hi_filler = (png_byte)(filler>>8); +#endif + png_byte lo_filler = (png_byte)filler; + + png_debug(1, "in png_do_read_filler"); + + if ( + row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + if (row_info->bit_depth == 8) + { + if ((flags & PNG_FLAG_FILLER_AFTER) != 0) + { + /* This changes the data from G to GX */ + png_bytep sp = row + (size_t)row_width; + png_bytep dp = sp + (size_t)row_width; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + row_info->channels = 2; + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + + else + { + /* This changes the data from G to XG */ + png_bytep sp = row + (size_t)row_width; + png_bytep dp = sp + (size_t)row_width; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = lo_filler; + } + row_info->channels = 2; + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + if ((flags & PNG_FLAG_FILLER_AFTER) != 0) + { + /* This changes the data from GG to GGXX */ + png_bytep sp = row + (size_t)row_width * 2; + png_bytep dp = sp + (size_t)row_width * 2; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = hi_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + *(--dp) = hi_filler; + row_info->channels = 2; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + + else + { + /* This changes the data from GG to XXGG */ + png_bytep sp = row + (size_t)row_width * 2; + png_bytep dp = sp + (size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = lo_filler; + *(--dp) = hi_filler; + } + row_info->channels = 2; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + } +#endif + } /* COLOR_TYPE == GRAY */ + else if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + if (row_info->bit_depth == 8) + { + if ((flags & PNG_FLAG_FILLER_AFTER) != 0) + { + /* This changes the data from RGB to RGBX */ + png_bytep sp = row + (size_t)row_width * 3; + png_bytep dp = sp + (size_t)row_width; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + row_info->channels = 4; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + + else + { + /* This changes the data from RGB to XRGB */ + png_bytep sp = row + (size_t)row_width * 3; + png_bytep dp = sp + (size_t)row_width; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = lo_filler; + } + row_info->channels = 4; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + if ((flags & PNG_FLAG_FILLER_AFTER) != 0) + { + /* This changes the data from RRGGBB to RRGGBBXX */ + png_bytep sp = row + (size_t)row_width * 6; + png_bytep dp = sp + (size_t)row_width * 2; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = hi_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + *(--dp) = hi_filler; + row_info->channels = 4; + row_info->pixel_depth = 64; + row_info->rowbytes = row_width * 8; + } + + else + { + /* This changes the data from RRGGBB to XXRRGGBB */ + png_bytep sp = row + (size_t)row_width * 6; + png_bytep dp = sp + (size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = lo_filler; + *(--dp) = hi_filler; + } + + row_info->channels = 4; + row_info->pixel_depth = 64; + row_info->rowbytes = row_width * 8; + } + } +#endif + } /* COLOR_TYPE == RGB */ +} +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +/* Expand grayscale files to RGB, with or without alpha */ +static void +png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) +{ + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + png_debug(1, "in png_do_gray_to_rgb"); + + if (row_info->bit_depth >= 8 && + (row_info->color_type & PNG_COLOR_MASK_COLOR) == 0) + { + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + if (row_info->bit_depth == 8) + { + /* This changes G to RGB */ + png_bytep sp = row + (size_t)row_width - 1; + png_bytep dp = sp + (size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(dp--) = *sp; + *(dp--) = *sp; + *(dp--) = *(sp--); + } + } + + else + { + /* This changes GG to RRGGBB */ + png_bytep sp = row + (size_t)row_width * 2 - 1; + png_bytep dp = sp + (size_t)row_width * 4; + for (i = 0; i < row_width; i++) + { + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *(sp--); + *(dp--) = *(sp--); + } + } + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This converts from GA to AG */ + if (row_info->bit_depth == 8) + { + if (row_info->bit_depth == 8) + { + /* This changes GA to RGBA */ + png_bytep sp = row + (size_t)row_width * 2 - 1; + png_bytep dp = sp + (size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(dp--) = *(sp--); + *(dp--) = *sp; + *(dp--) = *sp; + *(dp--) = *(sp--); + } + } + + else + { + /* This changes GGAA to RRGGBBAA */ + png_bytep sp = row + (size_t)row_width * 4 - 1; + png_bytep dp = sp + (size_t)row_width * 4; + for (i = 0; i < row_width; i++) + { + *(dp--) = *(sp--); + *(dp--) = *(sp--); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *(sp--); + *(dp--) = *(sp--); + } + } + } + row_info->channels = (png_byte)(row_info->channels + 2); + row_info->color_type |= PNG_COLOR_MASK_COLOR; + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +/* Reduce RGB files to grayscale, with or without alpha + * using the equation given in Poynton's ColorFAQ of 1998-01-04 at + * (THIS LINK IS DEAD June 2008 but + * versions dated 1998 through November 2002 have been archived at + * https://web.archive.org/web/20000816232553/www.inforamp.net/ + * ~poynton/notes/colour_and_gamma/ColorFAQ.txt ) + * Charles Poynton poynton at poynton.com + * + * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B + * + * which can be expressed with integers as + * + * Y = (6969 * R + 23434 * G + 2365 * B)/32768 + * + * Poynton's current link (as of January 2003 through July 2011): + * + * has changed the numbers slightly: + * + * Y = 0.2126*R + 0.7152*G + 0.0722*B + * + * which can be expressed with integers as + * + * Y = (6966 * R + 23436 * G + 2366 * B)/32768 + * + * Historically, however, libpng uses numbers derived from the ITU-R Rec 709 + * end point chromaticities and the D65 white point. Depending on the + * precision used for the D65 white point this produces a variety of different + * numbers, however if the four decimal place value used in ITU-R Rec 709 is + * used (0.3127,0.3290) the Y calculation would be: + * + * Y = (6968 * R + 23435 * G + 2366 * B)/32768 + * + * While this is correct the rounding results in an overflow for white, because + * the sum of the rounded coefficients is 32769, not 32768. Consequently + * libpng uses, instead, the closest non-overflowing approximation: + * + * Y = (6968 * R + 23434 * G + 2366 * B)/32768 + * + * Starting with libpng-1.5.5, if the image being converted has a cHRM chunk + * (including an sRGB chunk) then the chromaticities are used to calculate the + * coefficients. See the chunk handling in pngrutil.c for more information. + * + * In all cases the calculation is to be done in a linear colorspace. If no + * gamma information is available to correct the encoding of the original RGB + * values this results in an implicit assumption that the original PNG RGB + * values were linear. + * + * Other integer coefficients can be used via png_set_rgb_to_gray(). Because + * the API takes just red and green coefficients the blue coefficient is + * calculated to make the sum 32768. This will result in different rounding + * to that used above. + */ +static int +png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row) +{ + int rgb_error = 0; + + png_debug(1, "in png_do_rgb_to_gray"); + + if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 && + (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; + png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; + png_uint_32 bc = 32768 - rc - gc; + png_uint_32 row_width = row_info->width; + int have_alpha = (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0; + + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + /* Notice that gamma to/from 1 are not necessarily inverses (if + * there is an overall gamma correction). Prior to 1.5.5 this code + * checked the linearized values for equality; this doesn't match + * the documentation, the original values must be checked. + */ + if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + + if (red != green || red != blue) + { + red = png_ptr->gamma_to_1[red]; + green = png_ptr->gamma_to_1[green]; + blue = png_ptr->gamma_to_1[blue]; + + rgb_error |= 1; + *(dp++) = png_ptr->gamma_from_1[ + (rc*red + gc*green + bc*blue + 16384)>>15]; + } + + else + { + /* If there is no overall correction the table will not be + * set. + */ + if (png_ptr->gamma_table != NULL) + red = png_ptr->gamma_table[red]; + + *(dp++) = red; + } + + if (have_alpha != 0) + *(dp++) = *(sp++); + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + + if (red != green || red != blue) + { + rgb_error |= 1; + /* NOTE: this is the historical approach which simply + * truncates the results. + */ + *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); + } + + else + *(dp++) = red; + + if (have_alpha != 0) + *(dp++) = *(sp++); + } + } + } + + else /* RGB bit_depth == 16 */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (png_ptr->gamma_16_to_1 != NULL && png_ptr->gamma_16_from_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, w; + png_byte hi,lo; + + hi=*(sp)++; lo=*(sp)++; red = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; blue = (png_uint_16)((hi << 8) | (lo)); + + if (red == green && red == blue) + { + if (png_ptr->gamma_16_table != NULL) + w = png_ptr->gamma_16_table[(red & 0xff) + >> png_ptr->gamma_shift][red >> 8]; + + else + w = red; + } + + else + { + png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red & 0xff) + >> png_ptr->gamma_shift][red>>8]; + png_uint_16 green_1 = + png_ptr->gamma_16_to_1[(green & 0xff) >> + png_ptr->gamma_shift][green>>8]; + png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue & 0xff) + >> png_ptr->gamma_shift][blue>>8]; + png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 + + bc*blue_1 + 16384)>>15); + w = png_ptr->gamma_16_from_1[(gray16 & 0xff) >> + png_ptr->gamma_shift][gray16 >> 8]; + rgb_error |= 1; + } + + *(dp++) = (png_byte)((w>>8) & 0xff); + *(dp++) = (png_byte)(w & 0xff); + + if (have_alpha != 0) + { + *(dp++) = *(sp++); + *(dp++) = *(sp++); + } + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, gray16; + png_byte hi,lo; + + hi=*(sp)++; lo=*(sp)++; red = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo)); + hi=*(sp)++; lo=*(sp)++; blue = (png_uint_16)((hi << 8) | (lo)); + + if (red != green || red != blue) + rgb_error |= 1; + + /* From 1.5.5 in the 16-bit case do the accurate conversion even + * in the 'fast' case - this is because this is where the code + * ends up when handling linear 16-bit data. + */ + gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >> + 15); + *(dp++) = (png_byte)((gray16 >> 8) & 0xff); + *(dp++) = (png_byte)(gray16 & 0xff); + + if (have_alpha != 0) + { + *(dp++) = *(sp++); + *(dp++) = *(sp++); + } + } + } + } + + row_info->channels = (png_byte)(row_info->channels - 2); + row_info->color_type = (png_byte)(row_info->color_type & + ~PNG_COLOR_MASK_COLOR); + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + return rgb_error; +} +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) +/* Replace any alpha or transparency with the supplied background color. + * "background" is already in the screen gamma, while "background_1" is + * at a gamma of 1.0. Paletted files have already been taken care of. + */ +static void +png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr) +{ +#ifdef PNG_READ_GAMMA_SUPPORTED + png_const_bytep gamma_table = png_ptr->gamma_table; + png_const_bytep gamma_from_1 = png_ptr->gamma_from_1; + png_const_bytep gamma_to_1 = png_ptr->gamma_to_1; + png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table; + png_const_uint_16pp gamma_16_from_1 = png_ptr->gamma_16_from_1; + png_const_uint_16pp gamma_16_to_1 = png_ptr->gamma_16_to_1; + int gamma_shift = png_ptr->gamma_shift; + int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0; +#endif + + png_bytep sp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + int shift; + + png_debug(1, "in png_do_compose"); + + switch (row_info->color_type) + { + case PNG_COLOR_TYPE_GRAY: + { + switch (row_info->bit_depth) + { + case 1: + { + sp = row; + shift = 7; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x01) + == png_ptr->trans_color.gray) + { + unsigned int tmp = *sp & (0x7f7f >> (7 - shift)); + tmp |= + (unsigned int)(png_ptr->background.gray << shift); + *sp = (png_byte)(tmp & 0xff); + } + + if (shift == 0) + { + shift = 7; + sp++; + } + + else + shift--; + } + break; + } + + case 2: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x03) + == png_ptr->trans_color.gray) + { + unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); + tmp |= + (unsigned int)png_ptr->background.gray << shift; + *sp = (png_byte)(tmp & 0xff); + } + + else + { + unsigned int p = (*sp >> shift) & 0x03; + unsigned int g = (gamma_table [p | (p << 2) | + (p << 4) | (p << 6)] >> 6) & 0x03; + unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); + tmp |= (unsigned int)(g << shift); + *sp = (png_byte)(tmp & 0xff); + } + + if (shift == 0) + { + shift = 6; + sp++; + } + + else + shift -= 2; + } + } + break; + } + + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x03) + == png_ptr->trans_color.gray) + { + unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); + tmp |= + (unsigned int)png_ptr->background.gray << shift; + *sp = (png_byte)(tmp & 0xff); + } + + if (shift == 0) + { + shift = 6; + sp++; + } + + else + shift -= 2; + } + } + break; + } + + case 4: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x0f) + == png_ptr->trans_color.gray) + { + unsigned int tmp = *sp & (0x0f0f >> (4 - shift)); + tmp |= + (unsigned int)(png_ptr->background.gray << shift); + *sp = (png_byte)(tmp & 0xff); + } + + else + { + unsigned int p = (*sp >> shift) & 0x0f; + unsigned int g = (gamma_table[p | (p << 4)] >> 4) & + 0x0f; + unsigned int tmp = *sp & (0x0f0f >> (4 - shift)); + tmp |= (unsigned int)(g << shift); + *sp = (png_byte)(tmp & 0xff); + } + + if (shift == 0) + { + shift = 4; + sp++; + } + + else + shift -= 4; + } + } + break; + } + + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x0f) + == png_ptr->trans_color.gray) + { + unsigned int tmp = *sp & (0x0f0f >> (4 - shift)); + tmp |= + (unsigned int)(png_ptr->background.gray << shift); + *sp = (png_byte)(tmp & 0xff); + } + + if (shift == 0) + { + shift = 4; + sp++; + } + + else + shift -= 4; + } + } + break; + } + + case 8: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + if (*sp == png_ptr->trans_color.gray) + *sp = (png_byte)png_ptr->background.gray; + + else + *sp = gamma_table[*sp]; + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + if (*sp == png_ptr->trans_color.gray) + *sp = (png_byte)png_ptr->background.gray; + } + } + break; + } + + case 16: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 v; + + v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + + if (v == png_ptr->trans_color.gray) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray + & 0xff); + } + + g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(v, g, a, png_ptr->background_1.gray); + if (optimize != 0) + w = v; + else + { + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + } + + else + shift -= 2; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 v; + + v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + + if (v == png_ptr->trans_color.gray) + { + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray + & 0xff); + } + + else + shift -= 4; + } + } + break; + } + + default: + break; + } + break; + } + + case PNG_COLOR_TYPE_RGB: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + if (*sp == png_ptr->trans_color.red && + *(sp + 1) == png_ptr->trans_color.green && + *(sp + 2) == png_ptr->trans_color.blue) + { + *sp = (png_byte)png_ptr->background.red; + *(sp + 1) = (png_byte)png_ptr->background.green; + *(sp + 2) = (png_byte)png_ptr->background.blue; + } + } + + else + { + *sp = gamma_table[*sp]; + *(sp + 1) = gamma_table[*(sp + 1)]; + *(sp + 2) = gamma_table[*(sp + 2)]; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + if (*sp == png_ptr->trans_color.red && + *(sp + 1) == png_ptr->trans_color.green && + *(sp + 2) == png_ptr->trans_color.blue) + { + *sp = (png_byte)png_ptr->background.red; + *(sp + 1) = (png_byte)png_ptr->background.green; + *(sp + 2) = (png_byte)png_ptr->background.blue; + } + } + } + } + else /* if (row_info->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + + png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + + png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) + + *(sp + 5)); + + if (r == png_ptr->trans_color.red && + g == png_ptr->trans_color.green && + b == png_ptr->trans_color.blue) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); + *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); + } + + else + { + png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + + v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; + *(sp + 2) = (png_byte)((v >> 8) & 0xff); + *(sp + 3) = (png_byte)(v & 0xff); + + v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; + *(sp + 4) = (png_byte)((v >> 8) & 0xff); + *(sp + 5) = (png_byte)(v & 0xff); + } + } + } + + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + + png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + + png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) + + *(sp + 5)); + + if (r == png_ptr->trans_color.red && + g == png_ptr->trans_color.green && + b == png_ptr->trans_color.blue) + { + *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); + *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); + } + } + } + } + break; + } + + case PNG_COLOR_TYPE_GRAY_ALPHA: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_to_1 != NULL && gamma_from_1 != NULL && + gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 a = *(sp + 1); + + if (a == 0xff) + *sp = gamma_table[*sp]; + + else if (a == 0) + { + /* Background is already in screen gamma */ + *sp = (png_byte)png_ptr->background.gray; + } + + else + { + png_byte v, w; + + v = gamma_to_1[*sp]; + png_composite(w, v, a, png_ptr->background_1.gray); + if (optimize == 0) + w = gamma_from_1[w]; + *sp = w; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_byte a = *(sp + 1); + + if (a == 0) + *sp = (png_byte)png_ptr->background.gray; + + else if (a < 0xff) + png_composite(*sp, *sp, a, png_ptr->background.gray); + } + } + } + else /* if (png_ptr->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL && gamma_16_from_1 != NULL && + gamma_16_to_1 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + + if (a == (png_uint_16)0xffff) + { + png_uint_16 v; + + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + } + + else if (a == 0) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); + } + + else + { + png_uint_16 g, v, w; + + g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(v, g, a, png_ptr->background_1.gray); + if (optimize != 0) + w = v; + else + w = gamma_16_from_1[(v & 0xff) >> + gamma_shift][v >> 8]; + *sp = (png_byte)((w >> 8) & 0xff); + *(sp + 1) = (png_byte)(w & 0xff); + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + + if (a == 0) + { + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); + } + + else if (a < 0xffff) + { + png_uint_16 g, v; + + g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_composite_16(v, g, a, png_ptr->background.gray); + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + } + } + } + } + break; + } + + case PNG_COLOR_TYPE_RGB_ALPHA: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_to_1 != NULL && gamma_from_1 != NULL && + gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + png_byte a = *(sp + 3); + + if (a == 0xff) + { + *sp = gamma_table[*sp]; + *(sp + 1) = gamma_table[*(sp + 1)]; + *(sp + 2) = gamma_table[*(sp + 2)]; + } + + else if (a == 0) + { + /* Background is already in screen gamma */ + *sp = (png_byte)png_ptr->background.red; + *(sp + 1) = (png_byte)png_ptr->background.green; + *(sp + 2) = (png_byte)png_ptr->background.blue; + } + + else + { + png_byte v, w; + + v = gamma_to_1[*sp]; + png_composite(w, v, a, png_ptr->background_1.red); + if (optimize == 0) w = gamma_from_1[w]; + *sp = w; + + v = gamma_to_1[*(sp + 1)]; + png_composite(w, v, a, png_ptr->background_1.green); + if (optimize == 0) w = gamma_from_1[w]; + *(sp + 1) = w; + + v = gamma_to_1[*(sp + 2)]; + png_composite(w, v, a, png_ptr->background_1.blue); + if (optimize == 0) w = gamma_from_1[w]; + *(sp + 2) = w; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + png_byte a = *(sp + 3); + + if (a == 0) + { + *sp = (png_byte)png_ptr->background.red; + *(sp + 1) = (png_byte)png_ptr->background.green; + *(sp + 2) = (png_byte)png_ptr->background.blue; + } + + else if (a < 0xff) + { + png_composite(*sp, *sp, a, png_ptr->background.red); + + png_composite(*(sp + 1), *(sp + 1), a, + png_ptr->background.green); + + png_composite(*(sp + 2), *(sp + 2), a, + png_ptr->background.blue); + } + } + } + } + else /* if (row_info->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL && gamma_16_from_1 != NULL && + gamma_16_to_1 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 8) + { + png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) + << 8) + (png_uint_16)(*(sp + 7))); + + if (a == (png_uint_16)0xffff) + { + png_uint_16 v; + + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + + v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; + *(sp + 2) = (png_byte)((v >> 8) & 0xff); + *(sp + 3) = (png_byte)(v & 0xff); + + v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; + *(sp + 4) = (png_byte)((v >> 8) & 0xff); + *(sp + 5) = (png_byte)(v & 0xff); + } + + else if (a == 0) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); + *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); + } + + else + { + png_uint_16 v, w; + + v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(w, v, a, png_ptr->background_1.red); + if (optimize == 0) + w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >> + 8]; + *sp = (png_byte)((w >> 8) & 0xff); + *(sp + 1) = (png_byte)(w & 0xff); + + v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)]; + png_composite_16(w, v, a, png_ptr->background_1.green); + if (optimize == 0) + w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >> + 8]; + + *(sp + 2) = (png_byte)((w >> 8) & 0xff); + *(sp + 3) = (png_byte)(w & 0xff); + + v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)]; + png_composite_16(w, v, a, png_ptr->background_1.blue); + if (optimize == 0) + w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >> + 8]; + + *(sp + 4) = (png_byte)((w >> 8) & 0xff); + *(sp + 5) = (png_byte)(w & 0xff); + } + } + } + + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 8) + { + png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) + << 8) + (png_uint_16)(*(sp + 7))); + + if (a == 0) + { + *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); + *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); + } + + else if (a < 0xffff) + { + png_uint_16 v; + + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) + + *(sp + 5)); + + png_composite_16(v, r, a, png_ptr->background.red); + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + + png_composite_16(v, g, a, png_ptr->background.green); + *(sp + 2) = (png_byte)((v >> 8) & 0xff); + *(sp + 3) = (png_byte)(v & 0xff); + + png_composite_16(v, b, a, png_ptr->background.blue); + *(sp + 4) = (png_byte)((v >> 8) & 0xff); + *(sp + 5) = (png_byte)(v & 0xff); + } + } + } + } + break; + } + + default: + break; + } +} +#endif /* READ_BACKGROUND || READ_ALPHA_MODE */ + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* Gamma correct the image, avoiding the alpha channel. Make sure + * you do this after you deal with the transparency issue on grayscale + * or RGB images. If your bit depth is 8, use gamma_table, if it + * is 16, use gamma_16_table and gamma_shift. Build these with + * build_gamma_table(). + */ +static void +png_do_gamma(png_row_infop row_info, png_bytep row, png_structrp png_ptr) +{ + png_const_bytep gamma_table = png_ptr->gamma_table; + png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table; + int gamma_shift = png_ptr->gamma_shift; + + png_bytep sp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_gamma"); + + if (((row_info->bit_depth <= 8 && gamma_table != NULL) || + (row_info->bit_depth == 16 && gamma_16_table != NULL))) + { + case PNG_COLOR_TYPE_GRAY: + { + case PNG_COLOR_TYPE_RGB: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + } + } + + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + } + } + + default: + break; + } + break; + } + + case PNG_COLOR_TYPE_RGB_ALPHA: + { + if (row_info->bit_depth == 8) + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + + *sp = gamma_table[*sp]; + sp++; + + *sp = gamma_table[*sp]; + sp++; + + sp++; + } + } + + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 4; + } + } + break; + } + break; + } + + case PNG_COLOR_TYPE_GRAY_ALPHA: + { + if (row_info->bit_depth == 8) + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp += 2; + } + } + + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 4; + } + } + break; + } + break; + } + + case PNG_COLOR_TYPE_GRAY: + { + if (row_info->bit_depth == 2) + { + sp = row; + for (i = 0; i < row_width; i += 4) + { + int a = *sp & 0xc0; + int b = *sp & 0x30; + int c = *sp & 0x0c; + int d = *sp & 0x03; + + *sp = (png_byte)( + ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)| + ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)| + ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)| + ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) )); + sp++; + } + } + + if (row_info->bit_depth == 4) + { + sp = row; + for (i = 0; i < row_width; i += 2) + { + int msb = *sp & 0xf0; + int lsb = *sp & 0x0f; + + *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0) + | (((int)gamma_table[(lsb << 4) | lsb]) >> 4)); + sp++; + } + break; + } + + else if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + } + break; + } + + case 4: + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + } + } + break; + } + break; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB && + trans_color != NULL) + { + if (row_info->bit_depth == 8) + { + png_byte red = (png_byte)(trans_color->red & 0xff); + png_byte green = (png_byte)(trans_color->green & 0xff); + png_byte blue = (png_byte)(trans_color->blue & 0xff); + sp = row + (size_t)row_info->rowbytes - 1; + dp = row + ((size_t)row_width << 2) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue) + *dp-- = 0; + + else + *dp-- = 0xff; + + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + else if (row_info->bit_depth == 16) + { + png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff); + png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff); + png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff); + png_byte red_low = (png_byte)(trans_color->red & 0xff); + png_byte green_low = (png_byte)(trans_color->green & 0xff); + png_byte blue_low = (png_byte)(trans_color->blue & 0xff); + sp = row + row_info->rowbytes - 1; + dp = row + ((size_t)row_width << 3) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 5) == red_high && + *(sp - 4) == red_low && + *(sp - 3) == green_high && + *(sp - 2) == green_low && + *(sp - 1) == blue_high && + *(sp ) == blue_low) + { + *dp-- = 0; + *dp-- = 0; + } + + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + row_info->channels = 4; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } +} +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED +/* Encode the alpha channel to the output gamma (the input channel is always + * linear.) Called only with color types that have an alpha channel. Needs the + * from_1 tables. + */ +static void +png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr) +{ + png_uint_32 row_width = row_info->width; + + png_debug(1, "in png_do_encode_alpha"); + + if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0) + { + if (row_info->bit_depth == 8) + { + png_bytep table = png_ptr->gamma_from_1; + + if (table != NULL) + { + int step = (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2; + + /* The alpha channel is the last component: */ + row += step - 1; + + for (; row_width > 0; --row_width, row += step) + *row = table[*row]; + + return; + } + } + + else if (row_info->bit_depth == 16) + { + png_uint_16pp table = png_ptr->gamma_16_from_1; + int gamma_shift = png_ptr->gamma_shift; + + if (table != NULL) + { + int step = (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4; + + /* The alpha channel is the last component: */ + row += step - 2; + + for (; row_width > 0; --row_width, row += step) + { + png_uint_16 v; + + v = table[*(row + 1) >> gamma_shift][*row]; + *row = (png_byte)((v >> 8) & 0xff); + *(row + 1) = (png_byte)(v & 0xff); + } + + return; + } + } + } + + /* Only get to here if called with a weird row_info; no harm has been done, + * so just issue a warning. + */ + png_warning(png_ptr, "png_do_encode_alpha: unexpected call"); +} +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expands a palette row to an RGB or RGBA row depending + * upon whether you supply trans and num_trans. + */ +static void +png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info, + png_bytep row, png_const_colorp palette, png_const_bytep trans_alpha, + int num_trans) +{ + int shift, value; + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_expand_palette"); + + if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (row_info->bit_depth < 8) + { + switch (row_info->bit_depth) + { + case 1: + { + sp = row + (size_t)((row_width - 1) >> 3); + dp = row + (size_t)row_width - 1; + shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + if ((*sp >> shift) & 0x01) + *dp = 1; + + else + *dp = 0; + + if (shift == 7) + { + shift = 0; + sp--; + } + + else + shift++; + + dp--; + } + break; + } + + case 2: + { + sp = row + (size_t)((row_width - 1) >> 2); + dp = row + (size_t)row_width - 1; + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x03; + *dp = (png_byte)value; + if (shift == 6) + { + shift = 0; + sp--; + } + + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + sp = row + (size_t)((row_width - 1) >> 1); + dp = row + (size_t)row_width - 1; + shift = (int)((row_width & 0x01) << 2); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x0f; + *dp = (png_byte)value; + if (shift == 4) + { + shift = 0; + sp--; + } + + else + shift += 4; + + dp--; + } + break; + } + + default: + break; + } + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + + if (row_info->bit_depth == 8) + { + { + if (num_trans > 0) + { + sp = row + (size_t)row_width - 1; + dp = row + ((size_t)row_width << 2) - 1; + + i = 0; +#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE + if (png_ptr->riffled_palette != NULL) + { + /* The RGBA optimization works with png_ptr->bit_depth == 8 + * but sometimes row_info->bit_depth has been changed to 8. + * In these cases, the palette hasn't been riffled. + */ + i = png_do_expand_palette_rgba8_neon(png_ptr, row_info, row, + &sp, &dp); + } +#else + PNG_UNUSED(png_ptr) +#endif + + for (; i < row_width; i++) + { + if ((int)(*sp) >= num_trans) + *dp-- = 0xff; + else + *dp-- = trans_alpha[*sp]; + *dp-- = palette[*sp].blue; + *dp-- = palette[*sp].green; + *dp-- = palette[*sp].red; + sp--; + } + row_info->bit_depth = 8; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + row_info->color_type = 6; + row_info->channels = 4; + } + + else + { + sp = row + (size_t)row_width - 1; + dp = row + (size_t)(row_width * 3) - 1; + i = 0; +#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE + i = png_do_expand_palette_rgb8_neon(png_ptr, row_info, row, + &sp, &dp); +#else + PNG_UNUSED(png_ptr) +#endif + + for (; i < row_width; i++) + { + *dp-- = palette[*sp].blue; + *dp-- = palette[*sp].green; + *dp-- = palette[*sp].red; + sp--; + } + break; + } + + row_info->bit_depth = 8; + row_info->pixel_depth = 24; + row_info->rowbytes = row_width * 3; + row_info->color_type = 2; + row_info->channels = 3; + } + } + } + } +} + +/* If the bit depth < 8, it is expanded to 8. Also, if the already + * expanded transparency value is supplied, an alpha channel is built. + */ +static void +png_do_expand(png_row_infop row_info, png_bytep row, + png_const_color_16p trans_color) +{ + int shift, value; + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_expand"); + + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + unsigned int gray = trans_color != NULL ? trans_color->gray : 0; + + if (row_info->bit_depth < 8) + { + switch (row_info->bit_depth) + { + case 1: + { + gray = (gray & 0x01) * 0xff; + sp = row + (size_t)((row_width - 1) >> 3); + dp = row + (size_t)row_width - 1; + shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + if ((*sp >> shift) & 0x01) + *dp = 0xff; + + else + *dp = 0; + + if (shift == 7) + { + shift = 0; + sp--; + } + + else + shift++; + + dp--; + } + break; + } + + case 2: + { + gray = (gray & 0x03) * 0x55; + sp = row + (size_t)((row_width - 1) >> 2); + dp = row + (size_t)row_width - 1; + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x03; + *dp = (png_byte)(value | (value << 2) | (value << 4) | + (value << 6)); + if (shift == 6) + { + shift = 0; + sp--; + } + + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + gray = (gray & 0x0f) * 0x11; + sp = row + (size_t)((row_width - 1) >> 1); + dp = row + (size_t)row_width - 1; + shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x0f; + *dp = (png_byte)(value | (value << 4)); + if (shift == 4) + { + shift = 0; + sp--; + } + + else + shift = 4; + + dp--; + } + break; + } + + default: + break; + } + + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + + if (trans_color != NULL) + { + if (row_info->bit_depth == 8) + { + gray = gray & 0xff; + sp = row + (size_t)row_width - 1; + dp = row + ((size_t)row_width << 1) - 1; + + for (i = 0; i < row_width; i++) + { + if ((*sp & 0xffU) == gray) + *dp-- = 0; + + else + *dp-- = 0xff; + + *dp-- = *sp--; + } + } + + else if (row_info->bit_depth == 16) + { + unsigned int gray_high = (gray >> 8) & 0xff; + unsigned int gray_low = gray & 0xff; + sp = row + row_info->rowbytes - 1; + dp = row + (row_info->rowbytes << 1) - 1; + for (i = 0; i < row_width; i++) + { + if ((*(sp - 1) & 0xffU) == gray_high && + (*(sp) & 0xffU) == gray_low) + { + *dp-- = 0; + *dp-- = 0; + } + + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + + *dp-- = *sp--; + *dp-- = *sp--; + } + } + + row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + row_info->channels = 2; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_width); + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB && + trans_color != NULL) + { + if (row_info->bit_depth == 8) + { + png_byte red = (png_byte)(trans_color->red & 0xff); + png_byte green = (png_byte)(trans_color->green & 0xff); + png_byte blue = (png_byte)(trans_color->blue & 0xff); + sp = row + (size_t)row_info->rowbytes - 1; + dp = row + ((size_t)row_width << 2) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue) + *dp-- = 0; + + else + *dp-- = 0xff; + + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + else if (row_info->bit_depth == 16) + { + png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff); + png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff); + png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff); + png_byte red_low = (png_byte)(trans_color->red & 0xff); + png_byte green_low = (png_byte)(trans_color->green & 0xff); + png_byte blue_low = (png_byte)(trans_color->blue & 0xff); + sp = row + row_info->rowbytes - 1; + dp = row + ((size_t)row_width << 3) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 5) == red_high && + *(sp - 4) == red_low && + *(sp - 3) == green_high && + *(sp - 2) == green_low && + *(sp - 1) == blue_high && + *(sp ) == blue_low) + { + *dp-- = 0; + *dp-- = 0; + } + + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + row_info->channels = 4; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } +} +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED +/* If the bit depth is 8 and the color type is not a palette type expand the + * whole row to 16 bits. Has no effect otherwise. + */ +static void +png_do_expand_16(png_row_infop row_info, png_bytep row) +{ + if (row_info->bit_depth == 8 && + row_info->color_type != PNG_COLOR_TYPE_PALETTE) + { + /* The row have a sequence of bytes containing [0..255] and we need + * to turn it into another row containing [0..65535], to do this we + * calculate: + * + * (input / 255) * 65535 + * + * Which happens to be exactly input * 257 and this can be achieved + * simply by byte replication in place (copying backwards). + */ + png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */ + png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */ + while (dp > sp) + { + dp[-2] = dp[-1] = *--sp; dp -= 2; + } + + row_info->rowbytes *= 2; + row_info->bit_depth = 16; + row_info->pixel_depth = (png_byte)(row_info->channels * 16); + } +} +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +static void +png_do_quantize(png_row_infop row_info, png_bytep row, + png_const_bytep palette_lookup, png_const_bytep quantize_lookup) +{ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_quantize"); + + if (row_info->bit_depth == 8) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup) + { + int r, g, b, p; + sp = row; + dp = row; + for (i = 0; i < row_width; i++) + { + r = *sp++; + g = *sp++; + b = *sp++; + + /* This looks real messy, but the compiler will reduce + * it down to a reasonable formula. For example, with + * 5 bits per color, we get: + * p = (((r >> 3) & 0x1f) << 10) | + * (((g >> 3) & 0x1f) << 5) | + * ((b >> 3) & 0x1f); + */ + p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) & + ((1 << PNG_QUANTIZE_RED_BITS) - 1)) << + (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) | + (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) & + ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) << + (PNG_QUANTIZE_BLUE_BITS)) | + ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) & + ((1 << PNG_QUANTIZE_BLUE_BITS) - 1)); + + *dp++ = palette_lookup[p]; + } + + row_info->color_type = PNG_COLOR_TYPE_PALETTE; + row_info->channels = 1; + row_info->pixel_depth = row_info->bit_depth; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && + palette_lookup != NULL) + { + int r, g, b, p; + sp = row; + dp = row; + for (i = 0; i < row_width; i++) + { + r = *sp++; + g = *sp++; + b = *sp++; + sp++; + + p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) & + ((1 << PNG_QUANTIZE_RED_BITS) - 1)) << + (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) | + (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) & + ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) << + (PNG_QUANTIZE_BLUE_BITS)) | + ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) & + ((1 << PNG_QUANTIZE_BLUE_BITS) - 1)); + + *dp++ = palette_lookup[p]; + } + + row_info->color_type = PNG_COLOR_TYPE_PALETTE; + row_info->channels = 1; + row_info->pixel_depth = row_info->bit_depth; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + + else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && + quantize_lookup) + { + sp = row; + + for (i = 0; i < row_width; i++, sp++) + { + *sp = quantize_lookup[*sp]; + } + } + } +} +#endif /* READ_QUANTIZE */ + +/* Transform the row. The order of transformations is significant, + * and is very touchy. If you add a transformation, take care to + * decide how it fits in with the other transformations here. + */ +void /* PRIVATE */ +png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info) +{ + png_debug(1, "in png_do_read_transformations"); + + if (png_ptr->row_buf == NULL) + { + /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this + * error is incredibly rare and incredibly easy to debug without this + * information. + */ + png_error(png_ptr, "NULL row buffer"); + } + + /* The following is debugging; prior to 1.5.4 the code was never compiled in; + * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro + * PNG_WARN_UNINITIALIZED_ROW removed. In 1.6 the new flag is set only for + * all transformations, however in practice the ROW_INIT always gets done on + * demand, if necessary. + */ + if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 && + (png_ptr->flags & PNG_FLAG_ROW_INIT) == 0) + { + /* Application has failed to call either png_read_start_image() or + * png_read_update_info() after setting transforms that expand pixels. + * This check added to libpng-1.2.19 (but not enabled until 1.5.4). + */ + png_error(png_ptr, "Uninitialized row"); + } + +#ifdef PNG_READ_EXPAND_SUPPORTED + if ((png_ptr->transformations & PNG_EXPAND) != 0) + { + if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) + { +#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE + if ((png_ptr->num_trans > 0) && (png_ptr->bit_depth == 8)) + { + if (png_ptr->riffled_palette == NULL) + { + /* Initialize the accelerated palette expansion. */ + png_ptr->riffled_palette = + (png_bytep)png_malloc(png_ptr, 256 * 4); + png_riffle_palette_neon(png_ptr); + } + } +#endif + png_do_expand_palette(png_ptr, row_info, png_ptr->row_buf + 1, + png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans); + } + + else + { + if (png_ptr->num_trans != 0 && + (png_ptr->transformations & PNG_EXPAND_tRNS) != 0) + png_do_expand(row_info, png_ptr->row_buf + 1, + &(png_ptr->trans_color)); + + else + png_do_expand(row_info, png_ptr->row_buf + 1, NULL); + } + } +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 && + (png_ptr->transformations & PNG_COMPOSE) == 0 && + (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + 0 /* at_start == false, because SWAP_ALPHA happens later */); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0) + { + int rgb_error = + png_do_rgb_to_gray(png_ptr, row_info, + png_ptr->row_buf + 1); + + if (rgb_error != 0) + { + png_ptr->rgb_to_gray_status=1; + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == + PNG_RGB_TO_GRAY_WARN) + png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == + PNG_RGB_TO_GRAY_ERR) + png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + } + } +#endif + +/* From Andreas Dilger e-mail to png-implement, 26 March 1998: + * + * In most cases, the "simple transparency" should be done prior to doing + * gray-to-RGB, or you will have to test 3x as many bytes to check if a + * pixel is transparent. You would also need to make sure that the + * transparency information is upgraded to RGB. + * + * To summarize, the current flow is: + * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite + * with background "in place" if transparent, + * convert to RGB if necessary + * - Gray + alpha -> composite with gray background and remove alpha bytes, + * convert to RGB if necessary + * + * To support RGB backgrounds for gray images we need: + * - Gray + simple transparency -> convert to RGB + simple transparency, + * compare 3 or 6 bytes and composite with + * background "in place" if transparent + * (3x compare/pixel compared to doing + * composite with gray bkgrnd) + * - Gray + alpha -> convert to RGB + alpha, composite with background and + * remove alpha bytes (3x float + * operations/pixel compared with composite + * on gray background) + * + * Greg's change will do this. The reason it wasn't done before is for + * performance, as this increases the per-pixel operations. If we would check + * in advance if the background was gray or RGB, and position the gray-to-RGB + * transform appropriately, then it would save a lot of work/time. + */ + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* If gray -> RGB, do so now only if background is non-gray; else do later + * for performance reasons + */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 && + (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) == 0) + png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) + if ((png_ptr->transformations & PNG_COMPOSE) != 0) + png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + if ((png_ptr->transformations & PNG_GAMMA) != 0 && +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* Because RGB_TO_GRAY does the gamma transform. */ + (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0 && +#endif +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) + /* Because PNG_COMPOSE does the gamma transform if there is something to + * do (if there is an alpha channel or transparency.) + */ + !((png_ptr->transformations & PNG_COMPOSE) != 0 && + ((png_ptr->num_trans != 0) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)) && +#endif + /* Because png_init_read_transformations transforms the palette, unless + * RGB_TO_GRAY will do the transform. + */ + (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) + png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 && + (png_ptr->transformations & PNG_COMPOSE) != 0 && + (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + 0 /* at_start == false, because SWAP_ALPHA happens later */); +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED + if ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 && + (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0) + png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0) + png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + /* There is no harm in doing both of these because only one has any effect, + * by putting the 'scale' option first if the app asks for scale (either by + * calling the API or in a TRANSFORM flag) this is what happens. + */ + if ((png_ptr->transformations & PNG_16_TO_8) != 0) + png_do_chop(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + if ((png_ptr->transformations & PNG_QUANTIZE) != 0) + { + png_do_quantize(row_info, png_ptr->row_buf + 1, + png_ptr->palette_lookup, png_ptr->quantize_index); + + if (row_info->rowbytes == 0) + png_error(png_ptr, "png_do_quantize returned rowbytes=0"); + } +#endif /* READ_QUANTIZE */ + +#ifdef PNG_READ_EXPAND_16_SUPPORTED + /* Do the expansion now, after all the arithmetic has been done. Notice + * that previous transformations can handle the PNG_EXPAND_16 flag if this + * is efficient (particularly true in the case of gamma correction, where + * better accuracy results faster!) + */ + if ((png_ptr->transformations & PNG_EXPAND_16) != 0) + png_do_expand_16(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* NOTE: moved here in 1.5.4 (from much later in this list.) */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 && + (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) != 0) + png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_INVERT_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_MONO) != 0) + png_do_invert(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0) + png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED + if ((png_ptr->transformations & PNG_SHIFT) != 0) + png_do_unshift(row_info, png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif + +#ifdef PNG_READ_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) != 0) + png_do_unpack(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Added at libpng-1.5.10 */ + if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max >= 0) + png_do_check_palette_indexes(png_ptr, row_info); +#endif + +#ifdef PNG_READ_BGR_SUPPORTED + if ((png_ptr->transformations & PNG_BGR) != 0) + png_do_bgr(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + png_do_packswap(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED + if ((png_ptr->transformations & PNG_FILLER) != 0) + png_do_read_filler(row_info, png_ptr->row_buf + 1, + (png_uint_32)png_ptr->filler, png_ptr->flags); +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0) + png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_16BIT_SUPPORTED +#ifdef PNG_READ_SWAP_SUPPORTED + if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0) + png_do_swap(row_info, png_ptr->row_buf + 1); +#endif +#endif + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) + { + if (png_ptr->read_user_transform_fn != NULL) + (*(png_ptr->read_user_transform_fn)) /* User read transform function */ + (png_ptr, /* png_ptr */ + row_info, /* row_info: */ + /* png_uint_32 width; width of row */ + /* size_t rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED + if (png_ptr->user_transform_depth != 0) + row_info->bit_depth = png_ptr->user_transform_depth; + + if (png_ptr->user_transform_channels != 0) + row_info->channels = png_ptr->user_transform_channels; +#endif + row_info->pixel_depth = (png_byte)(row_info->bit_depth * + row_info->channels); + + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width); + } +#endif +} + +#endif /* READ_TRANSFORMS */ +#endif /* READ */ diff --git a/extern/libpng/pngrutil.c b/extern/libpng/pngrutil.c new file mode 100644 index 000000000..b3264c4ae --- /dev/null +++ b/extern/libpng/pngrutil.c @@ -0,0 +1,4744 @@ + +/* pngrutil.c - utilities to read a PNG file + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains routines that are only called from within + * libpng itself during the course of reading an image. + */ + +#include "pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +png_uint_32 PNGAPI +png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf) +{ + png_uint_32 uval = png_get_uint_32(buf); + + if (uval > PNG_UINT_31_MAX) + png_error(png_ptr, "PNG unsigned integer out of range"); + + return (uval); +} + +#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED) +/* The following is a variation on the above for use with the fixed + * point values used for gAMA and cHRM. Instead of png_error it + * issues a warning and returns (-1) - an invalid value because both + * gAMA and cHRM use *unsigned* integers for fixed point values. + */ +#define PNG_FIXED_ERROR (-1) + +static png_fixed_point /* PRIVATE */ +png_get_fixed_point(png_structrp png_ptr, png_const_bytep buf) +{ + png_uint_32 uval = png_get_uint_32(buf); + + if (uval <= PNG_UINT_31_MAX) + return (png_fixed_point)uval; /* known to be in range */ + + /* The caller can turn off the warning by passing NULL. */ + if (png_ptr != NULL) + png_warning(png_ptr, "PNG fixed point integer out of range"); + + return PNG_FIXED_ERROR; +} +#endif + +#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED +/* NOTE: the read macros will obscure these definitions, so that if + * PNG_USE_READ_MACROS is set the library will not use them internally, + * but the APIs will still be available externally. + * + * The parentheses around "PNGAPI function_name" in the following three + * functions are necessary because they allow the macros to co-exist with + * these (unused but exported) functions. + */ + +/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ +png_uint_32 (PNGAPI +png_get_uint_32)(png_const_bytep buf) +{ + png_uint_32 uval = + ((png_uint_32)(*(buf )) << 24) + + ((png_uint_32)(*(buf + 1)) << 16) + + ((png_uint_32)(*(buf + 2)) << 8) + + ((png_uint_32)(*(buf + 3)) ) ; + + return uval; +} + +/* Grab a signed 32-bit integer from a buffer in big-endian format. The + * data is stored in the PNG file in two's complement format and there + * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore + * the following code does a two's complement to native conversion. + */ +png_int_32 (PNGAPI +png_get_int_32)(png_const_bytep buf) +{ + png_uint_32 uval = png_get_uint_32(buf); + if ((uval & 0x80000000) == 0) /* non-negative */ + return (png_int_32)uval; + + uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */ + if ((uval & 0x80000000) == 0) /* no overflow */ + return -(png_int_32)uval; + /* The following has to be safe; this function only gets called on PNG data + * and if we get here that data is invalid. 0 is the most safe value and + * if not then an attacker would surely just generate a PNG with 0 instead. + */ + return 0; +} + +/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */ +png_uint_16 (PNGAPI +png_get_uint_16)(png_const_bytep buf) +{ + /* ANSI-C requires an int value to accommodate at least 16 bits so this + * works and allows the compiler not to worry about possible narrowing + * on 32-bit systems. (Pre-ANSI systems did not make integers smaller + * than 16 bits either.) + */ + unsigned int val = + ((unsigned int)(*buf) << 8) + + ((unsigned int)(*(buf + 1))); + + return (png_uint_16)val; +} + +#endif /* READ_INT_FUNCTIONS */ + +/* Read and check the PNG file signature */ +void /* PRIVATE */ +png_read_sig(png_structrp png_ptr, png_inforp info_ptr) +{ + size_t num_checked, num_to_check; + + /* Exit if the user application does not expect a signature. */ + if (png_ptr->sig_bytes >= 8) + return; + + num_checked = png_ptr->sig_bytes; + num_to_check = 8 - num_checked; + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE; +#endif + + /* The signature must be serialized in a single I/O call. */ + png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); + png_ptr->sig_bytes = 8; + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + if (num_checked < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; +} + +/* Read the chunk header (length + type name). + * Put the type name into png_ptr->chunk_name, and return the length. + */ +png_uint_32 /* PRIVATE */ +png_read_chunk_header(png_structrp png_ptr) +{ + png_byte buf[8]; + png_uint_32 length; + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR; +#endif + + /* Read the length and the chunk name. + * This must be performed in a single I/O call. + */ + png_read_data(png_ptr, buf, 8); + length = png_get_uint_31(png_ptr, buf); + + /* Put the chunk name into png_ptr->chunk_name. */ + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(buf+4); + + png_debug2(0, "Reading %lx chunk, length = %lu", + (unsigned long)png_ptr->chunk_name, (unsigned long)length); + + /* Reset the crc and run it over the chunk name. */ + png_reset_crc(png_ptr); + png_calculate_crc(png_ptr, buf + 4, 4); + + /* Check to see if chunk name is valid. */ + png_check_chunk_name(png_ptr, png_ptr->chunk_name); + + /* Check for too-large chunk length */ + png_check_chunk_length(png_ptr, length); + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA; +#endif + + return length; +} + +/* Read data, and (optionally) run it through the CRC. */ +void /* PRIVATE */ +png_crc_read(png_structrp png_ptr, png_bytep buf, png_uint_32 length) +{ + if (png_ptr == NULL) + return; + + png_read_data(png_ptr, buf, length); + png_calculate_crc(png_ptr, buf, length); +} + +/* Optionally skip data and then check the CRC. Depending on whether we + * are reading an ancillary or critical chunk, and how the program has set + * things up, we may calculate the CRC on the data and print a message. + * Returns '1' if there was a CRC error, '0' otherwise. + */ +int /* PRIVATE */ +png_crc_finish(png_structrp png_ptr, png_uint_32 skip) +{ + /* The size of the local buffer for inflate is a good guess as to a + * reasonable size to use for buffering reads from the application. + */ + while (skip > 0) + { + png_uint_32 len; + png_byte tmpbuf[PNG_INFLATE_BUF_SIZE]; + + len = (sizeof tmpbuf); + if (len > skip) + len = skip; + skip -= len; + + png_crc_read(png_ptr, tmpbuf, len); + } + + if (png_crc_error(png_ptr) != 0) + { + if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0 ? + (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0 : + (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE) != 0) + { + png_chunk_warning(png_ptr, "CRC error"); + } + + else + png_chunk_error(png_ptr, "CRC error"); + + return (1); + } + + return (0); +} + +/* Compare the CRC stored in the PNG file with that calculated by libpng from + * the data it has read thus far. + */ +int /* PRIVATE */ +png_crc_error(png_structrp png_ptr) +{ + png_byte crc_bytes[4]; + png_uint_32 crc; + int need_crc = 1; + + if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0) + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == + (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) + need_crc = 0; + } + + else /* critical */ + { + if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0) + need_crc = 0; + } + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC; +#endif + + /* The chunk CRC must be serialized in a single I/O call. */ + png_read_data(png_ptr, crc_bytes, 4); + + if (need_crc != 0) + { + crc = png_get_uint_32(crc_bytes); + return ((int)(crc != png_ptr->crc)); + } + + else + return (0); +} + +#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\ + defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_sCAL_SUPPORTED) ||\ + defined(PNG_READ_sPLT_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) ||\ + defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_SEQUENTIAL_READ_SUPPORTED) +/* Manage the read buffer; this simply reallocates the buffer if it is not small + * enough (or if it is not allocated). The routine returns a pointer to the + * buffer; if an error occurs and 'warn' is set the routine returns NULL, else + * it will call png_error (via png_malloc) on failure. (warn == 2 means + * 'silent'). + */ +static png_bytep +png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn) +{ + png_bytep buffer = png_ptr->read_buffer; + + if (buffer != NULL && new_size > png_ptr->read_buffer_size) + { + png_ptr->read_buffer = NULL; + png_ptr->read_buffer = NULL; + png_ptr->read_buffer_size = 0; + png_free(png_ptr, buffer); + buffer = NULL; + } + + if (buffer == NULL) + { + buffer = png_voidcast(png_bytep, png_malloc_base(png_ptr, new_size)); + + if (buffer != NULL) + { + memset(buffer, 0, new_size); /* just in case */ + png_ptr->read_buffer = buffer; + png_ptr->read_buffer_size = new_size; + } + + else if (warn < 2) /* else silent */ + { + if (warn != 0) + png_chunk_warning(png_ptr, "insufficient memory to read chunk"); + + else + png_chunk_error(png_ptr, "insufficient memory to read chunk"); + } + } + + return buffer; +} +#endif /* READ_iCCP|iTXt|pCAL|sCAL|sPLT|tEXt|zTXt|SEQUENTIAL_READ */ + +/* png_inflate_claim: claim the zstream for some nefarious purpose that involves + * decompression. Returns Z_OK on success, else a zlib error code. It checks + * the owner but, in final release builds, just issues a warning if some other + * chunk apparently owns the stream. Prior to release it does a png_error. + */ +static int +png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) +{ + if (png_ptr->zowner != 0) + { + char msg[64]; + + PNG_STRING_FROM_CHUNK(msg, png_ptr->zowner); + /* So the message that results is " using zstream"; this is an + * internal error, but is very useful for debugging. i18n requirements + * are minimal. + */ + (void)png_safecat(msg, (sizeof msg), 4, " using zstream"); +#if PNG_RELEASE_BUILD + png_chunk_warning(png_ptr, msg); + png_ptr->zowner = 0; +#else + png_chunk_error(png_ptr, msg); +#endif + } + + /* Implementation note: unlike 'png_deflate_claim' this internal function + * does not take the size of the data as an argument. Some efficiency could + * be gained by using this when it is known *if* the zlib stream itself does + * not record the number; however, this is an illusion: the original writer + * of the PNG may have selected a lower window size, and we really must + * follow that because, for systems with with limited capabilities, we + * would otherwise reject the application's attempts to use a smaller window + * size (zlib doesn't have an interface to say "this or lower"!). + * + * inflateReset2 was added to zlib 1.2.4; before this the window could not be + * reset, therefore it is necessary to always allocate the maximum window + * size with earlier zlibs just in case later compressed chunks need it. + */ + { + int ret; /* zlib return code */ +#if ZLIB_VERNUM >= 0x1240 + int window_bits = 0; + +# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW) + if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) == + PNG_OPTION_ON) + { + window_bits = 15; + png_ptr->zstream_start = 0; /* fixed window size */ + } + + else + { + png_ptr->zstream_start = 1; + } +# endif + +#endif /* ZLIB_VERNUM >= 0x1240 */ + + /* Set this for safety, just in case the previous owner left pointers to + * memory allocations. + */ + png_ptr->zstream.next_in = NULL; + png_ptr->zstream.avail_in = 0; + png_ptr->zstream.next_out = NULL; + png_ptr->zstream.avail_out = 0; + + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0) + { +#if ZLIB_VERNUM >= 0x1240 + ret = inflateReset2(&png_ptr->zstream, window_bits); +#else + ret = inflateReset(&png_ptr->zstream); +#endif + } + + else + { +#if ZLIB_VERNUM >= 0x1240 + ret = inflateInit2(&png_ptr->zstream, window_bits); +#else + ret = inflateInit(&png_ptr->zstream); +#endif + + if (ret == Z_OK) + png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED; + } + +#if ZLIB_VERNUM >= 0x1290 && \ + defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32) + if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON) + /* Turn off validation of the ADLER32 checksum in IDAT chunks */ + ret = inflateValidate(&png_ptr->zstream, 0); +#endif + + if (ret == Z_OK) + png_ptr->zowner = owner; + + else + png_zstream_error(png_ptr, ret); + + return ret; + } + +#ifdef window_bits +# undef window_bits +#endif +} + +#if ZLIB_VERNUM >= 0x1240 +/* Handle the start of the inflate stream if we called inflateInit2(strm,0); + * in this case some zlib versions skip validation of the CINFO field and, in + * certain circumstances, libpng may end up displaying an invalid image, in + * contrast to implementations that call zlib in the normal way (e.g. libpng + * 1.5). + */ +int /* PRIVATE */ +png_zlib_inflate(png_structrp png_ptr, int flush) +{ + if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0) + { + if ((*png_ptr->zstream.next_in >> 4) > 7) + { + png_ptr->zstream.msg = "invalid window size (libpng)"; + return Z_DATA_ERROR; + } + + png_ptr->zstream_start = 0; + } + + return inflate(&png_ptr->zstream, flush); +} +#endif /* Zlib >= 1.2.4 */ + +#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED +#if defined(PNG_READ_zTXt_SUPPORTED) || defined (PNG_READ_iTXt_SUPPORTED) +/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to + * allow the caller to do multiple calls if required. If the 'finish' flag is + * set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must + * be returned or there has been a problem, otherwise Z_SYNC_FLUSH is used and + * Z_OK or Z_STREAM_END will be returned on success. + * + * The input and output sizes are updated to the actual amounts of data consumed + * or written, not the amount available (as in a z_stream). The data pointers + * are not changed, so the next input is (data+input_size) and the next + * available output is (output+output_size). + */ +static int +png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish, + /* INPUT: */ png_const_bytep input, png_uint_32p input_size_ptr, + /* OUTPUT: */ png_bytep output, png_alloc_size_t *output_size_ptr) +{ + if (png_ptr->zowner == owner) /* Else not claimed */ + { + int ret; + png_alloc_size_t avail_out = *output_size_ptr; + png_uint_32 avail_in = *input_size_ptr; + + /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it + * can't even necessarily handle 65536 bytes) because the type uInt is + * "16 bits or more". Consequently it is necessary to chunk the input to + * zlib. This code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the + * maximum value that can be stored in a uInt.) It is possible to set + * ZLIB_IO_MAX to a lower value in pngpriv.h and this may sometimes have + * a performance advantage, because it reduces the amount of data accessed + * at each step and that may give the OS more time to page it in. + */ + png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input); + /* avail_in and avail_out are set below from 'size' */ + png_ptr->zstream.avail_in = 0; + png_ptr->zstream.avail_out = 0; + + /* Read directly into the output if it is available (this is set to + * a local buffer below if output is NULL). + */ + if (output != NULL) + png_ptr->zstream.next_out = output; + + do + { + uInt avail; + Byte local_buffer[PNG_INFLATE_BUF_SIZE]; + + /* zlib INPUT BUFFER */ + /* The setting of 'avail_in' used to be outside the loop; by setting it + * inside it is possible to chunk the input to zlib and simply rely on + * zlib to advance the 'next_in' pointer. This allows arbitrary + * amounts of data to be passed through zlib at the unavoidable cost of + * requiring a window save (memcpy of up to 32768 output bytes) + * every ZLIB_IO_MAX input bytes. + */ + avail_in += png_ptr->zstream.avail_in; /* not consumed last time */ + + avail = ZLIB_IO_MAX; + + if (avail_in < avail) + avail = (uInt)avail_in; /* safe: < than ZLIB_IO_MAX */ + + avail_in -= avail; + png_ptr->zstream.avail_in = avail; + + /* zlib OUTPUT BUFFER */ + avail_out += png_ptr->zstream.avail_out; /* not written last time */ + + avail = ZLIB_IO_MAX; /* maximum zlib can process */ + + if (output == NULL) + { + /* Reset the output buffer each time round if output is NULL and + * make available the full buffer, up to 'remaining_space' + */ + png_ptr->zstream.next_out = local_buffer; + if ((sizeof local_buffer) < avail) + avail = (sizeof local_buffer); + } + + if (avail_out < avail) + avail = (uInt)avail_out; /* safe: < ZLIB_IO_MAX */ + + png_ptr->zstream.avail_out = avail; + avail_out -= avail; + + /* zlib inflate call */ + /* In fact 'avail_out' may be 0 at this point, that happens at the end + * of the read when the final LZ end code was not passed at the end of + * the previous chunk of input data. Tell zlib if we have reached the + * end of the output buffer. + */ + ret = PNG_INFLATE(png_ptr, avail_out > 0 ? Z_NO_FLUSH : + (finish ? Z_FINISH : Z_SYNC_FLUSH)); + } while (ret == Z_OK); + + /* For safety kill the local buffer pointer now */ + if (output == NULL) + png_ptr->zstream.next_out = NULL; + + /* Claw back the 'size' and 'remaining_space' byte counts. */ + avail_in += png_ptr->zstream.avail_in; + avail_out += png_ptr->zstream.avail_out; + + /* Update the input and output sizes; the updated values are the amount + * consumed or written, effectively the inverse of what zlib uses. + */ + if (avail_out > 0) + *output_size_ptr -= avail_out; + + if (avail_in > 0) + *input_size_ptr -= avail_in; + + /* Ensure png_ptr->zstream.msg is set (even in the success case!) */ + png_zstream_error(png_ptr, ret); + return ret; + } + + else + { + /* This is a bad internal error. The recovery assigns to the zstream msg + * pointer, which is not owned by the caller, but this is safe; it's only + * used on errors! + */ + png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed"); + return Z_STREAM_ERROR; + } +} + +/* + * Decompress trailing data in a chunk. The assumption is that read_buffer + * points at an allocated area holding the contents of a chunk with a + * trailing compressed part. What we get back is an allocated area + * holding the original prefix part and an uncompressed version of the + * trailing part (the malloc area passed in is freed). + */ +static int +png_decompress_chunk(png_structrp png_ptr, + png_uint_32 chunklength, png_uint_32 prefix_size, + png_alloc_size_t *newlength /* must be initialized to the maximum! */, + int terminate /*add a '\0' to the end of the uncompressed data*/) +{ + /* TODO: implement different limits for different types of chunk. + * + * The caller supplies *newlength set to the maximum length of the + * uncompressed data, but this routine allocates space for the prefix and + * maybe a '\0' terminator too. We have to assume that 'prefix_size' is + * limited only by the maximum chunk size. + */ + png_alloc_size_t limit = PNG_SIZE_MAX; + +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_malloc_max > 0 && + png_ptr->user_chunk_malloc_max < limit) + limit = png_ptr->user_chunk_malloc_max; +# elif PNG_USER_CHUNK_MALLOC_MAX > 0 + if (PNG_USER_CHUNK_MALLOC_MAX < limit) + limit = PNG_USER_CHUNK_MALLOC_MAX; +# endif + + if (limit >= prefix_size + (terminate != 0)) + { + int ret; + + limit -= prefix_size + (terminate != 0); + + if (limit < *newlength) + *newlength = limit; + + /* Now try to claim the stream. */ + ret = png_inflate_claim(png_ptr, png_ptr->chunk_name); + + if (ret == Z_OK) + { + png_uint_32 lzsize = chunklength - prefix_size; + + ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/, + /* input: */ png_ptr->read_buffer + prefix_size, &lzsize, + /* output: */ NULL, newlength); + + if (ret == Z_STREAM_END) + { + /* Use 'inflateReset' here, not 'inflateReset2' because this + * preserves the previously decided window size (otherwise it would + * be necessary to store the previous window size.) In practice + * this doesn't matter anyway, because png_inflate will call inflate + * with Z_FINISH in almost all cases, so the window will not be + * maintained. + */ + if (inflateReset(&png_ptr->zstream) == Z_OK) + { + /* Because of the limit checks above we know that the new, + * expanded, size will fit in a size_t (let alone an + * png_alloc_size_t). Use png_malloc_base here to avoid an + * extra OOM message. + */ + png_alloc_size_t new_size = *newlength; + png_alloc_size_t buffer_size = prefix_size + new_size + + (terminate != 0); + png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr, + buffer_size)); + + if (text != NULL) + { + memset(text, 0, buffer_size); + + ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/, + png_ptr->read_buffer + prefix_size, &lzsize, + text + prefix_size, newlength); + + if (ret == Z_STREAM_END) + { + if (new_size == *newlength) + { + if (terminate != 0) + text[prefix_size + *newlength] = 0; + + if (prefix_size > 0) + memcpy(text, png_ptr->read_buffer, prefix_size); + + { + png_bytep old_ptr = png_ptr->read_buffer; + + png_ptr->read_buffer = text; + png_ptr->read_buffer_size = buffer_size; + text = old_ptr; /* freed below */ + } + } + + else + { + /* The size changed on the second read, there can be no + * guarantee that anything is correct at this point. + * The 'msg' pointer has been set to "unexpected end of + * LZ stream", which is fine, but return an error code + * that the caller won't accept. + */ + ret = PNG_UNEXPECTED_ZLIB_RETURN; + } + } + + else if (ret == Z_OK) + ret = PNG_UNEXPECTED_ZLIB_RETURN; /* for safety */ + + /* Free the text pointer (this is the old read_buffer on + * success) + */ + png_free(png_ptr, text); + + /* This really is very benign, but it's still an error because + * the extra space may otherwise be used as a Trojan Horse. + */ + if (ret == Z_STREAM_END && + chunklength - prefix_size != lzsize) + png_chunk_benign_error(png_ptr, "extra compressed data"); + } + + else + { + /* Out of memory allocating the buffer */ + ret = Z_MEM_ERROR; + png_zstream_error(png_ptr, Z_MEM_ERROR); + } + } + + else + { + /* inflateReset failed, store the error message */ + png_zstream_error(png_ptr, ret); + ret = PNG_UNEXPECTED_ZLIB_RETURN; + } + } + + else if (ret == Z_OK) + ret = PNG_UNEXPECTED_ZLIB_RETURN; + + /* Release the claimed stream */ + png_ptr->zowner = 0; + } + + else /* the claim failed */ if (ret == Z_STREAM_END) /* impossible! */ + ret = PNG_UNEXPECTED_ZLIB_RETURN; + + return ret; + } + + else + { + /* Application/configuration limits exceeded */ + png_zstream_error(png_ptr, Z_MEM_ERROR); + return Z_MEM_ERROR; + } +} +#endif /* READ_zTXt || READ_iTXt */ +#endif /* READ_COMPRESSED_TEXT */ + +#ifdef PNG_READ_iCCP_SUPPORTED +/* Perform a partial read and decompress, producing 'avail_out' bytes and + * reading from the current chunk as required. + */ +static int +png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size, + png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size, + int finish) +{ + if (png_ptr->zowner == png_ptr->chunk_name) + { + int ret; + + /* next_in and avail_in must have been initialized by the caller. */ + png_ptr->zstream.next_out = next_out; + png_ptr->zstream.avail_out = 0; /* set in the loop */ + + do + { + if (png_ptr->zstream.avail_in == 0) + { + if (read_size > *chunk_bytes) + read_size = (uInt)*chunk_bytes; + *chunk_bytes -= read_size; + + if (read_size > 0) + png_crc_read(png_ptr, read_buffer, read_size); + + png_ptr->zstream.next_in = read_buffer; + png_ptr->zstream.avail_in = read_size; + } + + if (png_ptr->zstream.avail_out == 0) + { + uInt avail = ZLIB_IO_MAX; + if (avail > *out_size) + avail = (uInt)*out_size; + *out_size -= avail; + + png_ptr->zstream.avail_out = avail; + } + + /* Use Z_SYNC_FLUSH when there is no more chunk data to ensure that all + * the available output is produced; this allows reading of truncated + * streams. + */ + ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ? + Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH)); + } + while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0)); + + *out_size += png_ptr->zstream.avail_out; + png_ptr->zstream.avail_out = 0; /* Should not be required, but is safe */ + + /* Ensure the error message pointer is always set: */ + png_zstream_error(png_ptr, ret); + return ret; + } + + else + { + png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed"); + return Z_STREAM_ERROR; + } +} +#endif /* READ_iCCP */ + +/* Read and check the IDHR chunk */ + +void /* PRIVATE */ +png_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_byte buf[13]; + png_uint_32 width, height; + int bit_depth, color_type, compression_type, filter_type; + int interlace_type; + + png_debug(1, "in png_handle_IHDR"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) != 0) + png_chunk_error(png_ptr, "out of place"); + + /* Check the length */ + if (length != 13) + png_chunk_error(png_ptr, "invalid"); + + png_ptr->mode |= PNG_HAVE_IHDR; + + png_crc_read(png_ptr, buf, 13); + png_crc_finish(png_ptr, 0); + + width = png_get_uint_31(png_ptr, buf); + height = png_get_uint_31(png_ptr, buf + 4); + bit_depth = buf[8]; + color_type = buf[9]; + compression_type = buf[10]; + filter_type = buf[11]; + interlace_type = buf[12]; + + /* Set internal variables */ + png_ptr->width = width; + png_ptr->height = height; + png_ptr->bit_depth = (png_byte)bit_depth; + png_ptr->interlaced = (png_byte)interlace_type; + png_ptr->color_type = (png_byte)color_type; +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_ptr->filter_type = (png_byte)filter_type; +#endif + png_ptr->compression_type = (png_byte)compression_type; + + /* Find number of channels */ + switch (png_ptr->color_type) + { + default: /* invalid, png_set_IHDR calls png_error */ + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_PALETTE: + png_ptr->channels = 1; + break; + + case PNG_COLOR_TYPE_RGB: + png_ptr->channels = 3; + break; + + case PNG_COLOR_TYPE_GRAY_ALPHA: + png_ptr->channels = 2; + break; + + case PNG_COLOR_TYPE_RGB_ALPHA: + png_ptr->channels = 4; + break; + } + + /* Set up other useful info */ + png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * png_ptr->channels); + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width); + png_debug1(3, "bit_depth = %d", png_ptr->bit_depth); + png_debug1(3, "channels = %d", png_ptr->channels); + png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes); + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, + color_type, interlace_type, compression_type, filter_type); +} + +/* Read and check the palette */ +void /* PRIVATE */ +png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_color palette[PNG_MAX_PALETTE_LENGTH]; + int max_palette_length, num, i; +#ifdef PNG_POINTER_INDEXING_SUPPORTED + png_colorp pal_ptr; +#endif + + png_debug(1, "in png_handle_PLTE"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + /* Moved to before the 'after IDAT' check below because otherwise duplicate + * PLTE chunks are potentially ignored (the spec says there shall not be more + * than one PLTE, the error is not treated as benign, so this check trumps + * the requirement that PLTE appears before IDAT.) + */ + else if ((png_ptr->mode & PNG_HAVE_PLTE) != 0) + png_chunk_error(png_ptr, "duplicate"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + /* This is benign because the non-benign error happened before, when an + * IDAT was encountered in a color-mapped image with no PLTE. + */ + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + png_ptr->mode |= PNG_HAVE_PLTE; + + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "ignored in grayscale PNG"); + return; + } + +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + png_crc_finish(png_ptr, length); + return; + } +#endif + + if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) + { + png_crc_finish(png_ptr, length); + + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + png_chunk_benign_error(png_ptr, "invalid"); + + else + png_chunk_error(png_ptr, "invalid"); + + return; + } + + /* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */ + num = (int)length / 3; + + /* If the palette has 256 or fewer entries but is too large for the bit + * depth, we don't issue an error, to preserve the behavior of previous + * libpng versions. We silently truncate the unused extra palette entries + * here. + */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + max_palette_length = (1 << png_ptr->bit_depth); + else + max_palette_length = PNG_MAX_PALETTE_LENGTH; + + if (num > max_palette_length) + num = max_palette_length; + +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) + { + png_byte buf[3]; + + png_crc_read(png_ptr, buf, 3); + pal_ptr->red = buf[0]; + pal_ptr->green = buf[1]; + pal_ptr->blue = buf[2]; + } +#else + for (i = 0; i < num; i++) + { + png_byte buf[3]; + + png_crc_read(png_ptr, buf, 3); + /* Don't depend upon png_color being any order */ + palette[i].red = buf[0]; + palette[i].green = buf[1]; + palette[i].blue = buf[2]; + } +#endif + + /* If we actually need the PLTE chunk (ie for a paletted image), we do + * whatever the normal CRC configuration tells us. However, if we + * have an RGB image, the PLTE can be considered ancillary, so + * we will act as though it is. + */ +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#endif + { + png_crc_finish(png_ptr, (png_uint_32) (length - (unsigned int)num * 3)); + } + +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + else if (png_crc_error(png_ptr) != 0) /* Only if we have a CRC error */ + { + /* If we don't want to use the data from an ancillary chunk, + * we have two options: an error abort, or a warning and we + * ignore the data in this chunk (which should be OK, since + * it's considered ancillary for a RGB or RGBA image). + * + * IMPLEMENTATION NOTE: this is only here because png_crc_finish uses the + * chunk type to determine whether to check the ancillary or the critical + * flags. + */ + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE) == 0) + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) != 0) + return; + + else + png_chunk_error(png_ptr, "CRC error"); + } + + /* Otherwise, we (optionally) emit a warning and use the chunk. */ + else if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0) + png_chunk_warning(png_ptr, "CRC error"); + } +#endif + + /* TODO: png_set_PLTE has the side effect of setting png_ptr->palette to its + * own copy of the palette. This has the side effect that when png_start_row + * is called (this happens after any call to png_read_update_info) the + * info_ptr palette gets changed. This is extremely unexpected and + * confusing. + * + * Fix this by not sharing the palette in this way. + */ + png_set_PLTE(png_ptr, info_ptr, palette, num); + + /* The three chunks, bKGD, hIST and tRNS *must* appear after PLTE and before + * IDAT. Prior to 1.6.0 this was not checked; instead the code merely + * checked the apparent validity of a tRNS chunk inserted before PLTE on a + * palette PNG. 1.6.0 attempts to rigorously follow the standard and + * therefore does a benign error if the erroneous condition is detected *and* + * cancels the tRNS if the benign error returns. The alternative is to + * amend the standard since it would be rather hypocritical of the standards + * maintainers to ignore it. + */ +#ifdef PNG_READ_tRNS_SUPPORTED + if (png_ptr->num_trans > 0 || + (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0)) + { + /* Cancel this because otherwise it would be used if the transforms + * require it. Don't cancel the 'valid' flag because this would prevent + * detection of duplicate chunks. + */ + png_ptr->num_trans = 0; + + if (info_ptr != NULL) + info_ptr->num_trans = 0; + + png_chunk_benign_error(png_ptr, "tRNS must be after"); + } +#endif + +#ifdef PNG_READ_hIST_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0) + png_chunk_benign_error(png_ptr, "hIST must be after"); +#endif + +#ifdef PNG_READ_bKGD_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0) + png_chunk_benign_error(png_ptr, "bKGD must be after"); +#endif +} + +void /* PRIVATE */ +png_handle_IEND(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_debug(1, "in png_handle_IEND"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0 || + (png_ptr->mode & PNG_HAVE_IDAT) == 0) + png_chunk_error(png_ptr, "out of place"); + + png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); + + png_crc_finish(png_ptr, length); + + if (length != 0) + png_chunk_benign_error(png_ptr, "invalid"); + + PNG_UNUSED(info_ptr) +} + +#ifdef PNG_READ_gAMA_SUPPORTED +void /* PRIVATE */ +png_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_fixed_point igamma; + png_byte buf[4]; + + png_debug(1, "in png_handle_gAMA"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + if (length != 4) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, buf, 4); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + igamma = png_get_fixed_point(NULL, buf); + + png_colorspace_set_gamma(png_ptr, &png_ptr->colorspace, igamma); + png_colorspace_sync(png_ptr, info_ptr); +} +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED +void /* PRIVATE */ +png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + unsigned int truelen, i; + png_byte sample_depth; + png_byte buf[4]; + + png_debug(1, "in png_handle_sBIT"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + truelen = 3; + sample_depth = 8; + } + + else + { + truelen = png_ptr->channels; + sample_depth = png_ptr->bit_depth; + } + + if (length != truelen || length > 4) + { + png_chunk_benign_error(png_ptr, "invalid"); + png_crc_finish(png_ptr, length); + return; + } + + buf[0] = buf[1] = buf[2] = buf[3] = sample_depth; + png_crc_read(png_ptr, buf, truelen); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + for (i=0; i sample_depth) + { + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + } + + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + png_ptr->sig_bit.red = buf[0]; + png_ptr->sig_bit.green = buf[1]; + png_ptr->sig_bit.blue = buf[2]; + png_ptr->sig_bit.alpha = buf[3]; + } + + else + { + png_ptr->sig_bit.gray = buf[0]; + png_ptr->sig_bit.red = buf[0]; + png_ptr->sig_bit.green = buf[0]; + png_ptr->sig_bit.blue = buf[0]; + png_ptr->sig_bit.alpha = buf[1]; + } + + png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit)); +} +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED +void /* PRIVATE */ +png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_byte buf[32]; + png_xy xy; + + png_debug(1, "in png_handle_cHRM"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + if (length != 32) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, buf, 32); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + xy.whitex = png_get_fixed_point(NULL, buf); + xy.whitey = png_get_fixed_point(NULL, buf + 4); + xy.redx = png_get_fixed_point(NULL, buf + 8); + xy.redy = png_get_fixed_point(NULL, buf + 12); + xy.greenx = png_get_fixed_point(NULL, buf + 16); + xy.greeny = png_get_fixed_point(NULL, buf + 20); + xy.bluex = png_get_fixed_point(NULL, buf + 24); + xy.bluey = png_get_fixed_point(NULL, buf + 28); + + if (xy.whitex == PNG_FIXED_ERROR || + xy.whitey == PNG_FIXED_ERROR || + xy.redx == PNG_FIXED_ERROR || + xy.redy == PNG_FIXED_ERROR || + xy.greenx == PNG_FIXED_ERROR || + xy.greeny == PNG_FIXED_ERROR || + xy.bluex == PNG_FIXED_ERROR || + xy.bluey == PNG_FIXED_ERROR) + { + png_chunk_benign_error(png_ptr, "invalid values"); + return; + } + + /* If a colorspace error has already been output skip this chunk */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0) + return; + + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0) + { + png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID; + png_colorspace_sync(png_ptr, info_ptr); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + png_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; + (void)png_colorspace_set_chromaticities(png_ptr, &png_ptr->colorspace, &xy, + 1/*prefer cHRM values*/); + png_colorspace_sync(png_ptr, info_ptr); +} +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED +void /* PRIVATE */ +png_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_byte intent; + + png_debug(1, "in png_handle_sRGB"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + if (length != 1) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, &intent, 1); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + /* If a colorspace error has already been output skip this chunk */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0) + return; + + /* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect + * this. + */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) != 0) + { + png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID; + png_colorspace_sync(png_ptr, info_ptr); + png_chunk_benign_error(png_ptr, "too many profiles"); + return; + } + + (void)png_colorspace_set_sRGB(png_ptr, &png_ptr->colorspace, intent); + png_colorspace_sync(png_ptr, info_ptr); +} +#endif /* READ_sRGB */ + +#ifdef PNG_READ_iCCP_SUPPORTED +void /* PRIVATE */ +png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +/* Note: this does not properly handle profiles that are > 64K under DOS */ +{ + png_const_charp errmsg = NULL; /* error message output, or no error */ + int finished = 0; /* crc checked */ + + png_debug(1, "in png_handle_iCCP"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + /* Consistent with all the above colorspace handling an obviously *invalid* + * chunk is just ignored, so does not invalidate the color space. An + * alternative is to set the 'invalid' flags at the start of this routine + * and only clear them in they were not set before and all the tests pass. + */ + + /* The keyword must be at least one character and there is a + * terminator (0) byte and the compression method byte, and the + * 'zlib' datastream is at least 11 bytes. + */ + if (length < 14) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too short"); + return; + } + + /* If a colorspace error has already been output skip this chunk */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0) + { + png_crc_finish(png_ptr, length); + return; + } + + /* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect + * this. + */ + if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) == 0) + { + uInt read_length, keyword_length; + char keyword[81]; + + /* Find the keyword; the keyword plus separator and compression method + * bytes can be at most 81 characters long. + */ + read_length = 81; /* maximum */ + if (read_length > length) + read_length = (uInt)length; + + png_crc_read(png_ptr, (png_bytep)keyword, read_length); + length -= read_length; + + /* The minimum 'zlib' stream is assumed to be just the 2 byte header, + * 5 bytes minimum 'deflate' stream, and the 4 byte checksum. + */ + if (length < 11) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too short"); + return; + } + + keyword_length = 0; + while (keyword_length < 80 && keyword_length < read_length && + keyword[keyword_length] != 0) + ++keyword_length; + + /* TODO: make the keyword checking common */ + if (keyword_length >= 1 && keyword_length <= 79) + { + /* We only understand '0' compression - deflate - so if we get a + * different value we can't safely decode the chunk. + */ + if (keyword_length+1 < read_length && + keyword[keyword_length+1] == PNG_COMPRESSION_TYPE_BASE) + { + read_length -= keyword_length+2; + + if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK) + { + Byte profile_header[132]={0}; + Byte local_buffer[PNG_INFLATE_BUF_SIZE]; + png_alloc_size_t size = (sizeof profile_header); + + png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2); + png_ptr->zstream.avail_in = read_length; + (void)png_inflate_read(png_ptr, local_buffer, + (sizeof local_buffer), &length, profile_header, &size, + 0/*finish: don't, because the output is too small*/); + + if (size == 0) + { + /* We have the ICC profile header; do the basic header checks. + */ + png_uint_32 profile_length = png_get_uint_32(profile_header); + + if (png_icc_check_length(png_ptr, &png_ptr->colorspace, + keyword, profile_length) != 0) + { + /* The length is apparently ok, so we can check the 132 + * byte header. + */ + if (png_icc_check_header(png_ptr, &png_ptr->colorspace, + keyword, profile_length, profile_header, + png_ptr->color_type) != 0) + { + /* Now read the tag table; a variable size buffer is + * needed at this point, allocate one for the whole + * profile. The header check has already validated + * that none of this stuff will overflow. + */ + png_uint_32 tag_count = + png_get_uint_32(profile_header + 128); + png_bytep profile = png_read_buffer(png_ptr, + profile_length, 2/*silent*/); + + if (profile != NULL) + { + memcpy(profile, profile_header, + (sizeof profile_header)); + + size = 12 * tag_count; + + (void)png_inflate_read(png_ptr, local_buffer, + (sizeof local_buffer), &length, + profile + (sizeof profile_header), &size, 0); + + /* Still expect a buffer error because we expect + * there to be some tag data! + */ + if (size == 0) + { + if (png_icc_check_tag_table(png_ptr, + &png_ptr->colorspace, keyword, profile_length, + profile) != 0) + { + /* The profile has been validated for basic + * security issues, so read the whole thing in. + */ + size = profile_length - (sizeof profile_header) + - 12 * tag_count; + + (void)png_inflate_read(png_ptr, local_buffer, + (sizeof local_buffer), &length, + profile + (sizeof profile_header) + + 12 * tag_count, &size, 1/*finish*/); + + if (length > 0 && !(png_ptr->flags & + PNG_FLAG_BENIGN_ERRORS_WARN)) + errmsg = "extra compressed data"; + + /* But otherwise allow extra data: */ + else if (size == 0) + { + if (length > 0) + { + /* This can be handled completely, so + * keep going. + */ + png_chunk_warning(png_ptr, + "extra compressed data"); + } + + png_crc_finish(png_ptr, length); + finished = 1; + +# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0 + /* Check for a match against sRGB */ + png_icc_set_sRGB(png_ptr, + &png_ptr->colorspace, profile, + png_ptr->zstream.adler); +# endif + + /* Steal the profile for info_ptr. */ + if (info_ptr != NULL) + { + png_free_data(png_ptr, info_ptr, + PNG_FREE_ICCP, 0); + + info_ptr->iccp_name = png_voidcast(char*, + png_malloc_base(png_ptr, + keyword_length+1)); + if (info_ptr->iccp_name != NULL) + { + memcpy(info_ptr->iccp_name, keyword, + keyword_length+1); + info_ptr->iccp_proflen = + profile_length; + info_ptr->iccp_profile = profile; + png_ptr->read_buffer = NULL; /*steal*/ + info_ptr->free_me |= PNG_FREE_ICCP; + info_ptr->valid |= PNG_INFO_iCCP; + } + + else + { + png_ptr->colorspace.flags |= + PNG_COLORSPACE_INVALID; + errmsg = "out of memory"; + } + } + + /* else the profile remains in the read + * buffer which gets reused for subsequent + * chunks. + */ + + if (info_ptr != NULL) + png_colorspace_sync(png_ptr, info_ptr); + + if (errmsg == NULL) + { + png_ptr->zowner = 0; + return; + } + } + if (errmsg == NULL) + errmsg = png_ptr->zstream.msg; + } + /* else png_icc_check_tag_table output an error */ + } + else /* profile truncated */ + errmsg = png_ptr->zstream.msg; + } + + else + errmsg = "out of memory"; + } + + /* else png_icc_check_header output an error */ + } + + /* else png_icc_check_length output an error */ + } + + else /* profile truncated */ + errmsg = png_ptr->zstream.msg; + + /* Release the stream */ + png_ptr->zowner = 0; + } + + else /* png_inflate_claim failed */ + errmsg = png_ptr->zstream.msg; + } + + else + errmsg = "bad compression method"; /* or missing */ + } + + else + errmsg = "bad keyword"; + } + + else + errmsg = "too many profiles"; + + /* Failure: the reason is in 'errmsg' */ + if (finished == 0) + png_crc_finish(png_ptr, length); + + png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID; + png_colorspace_sync(png_ptr, info_ptr); + if (errmsg != NULL) /* else already output */ + png_chunk_benign_error(png_ptr, errmsg); +} +#endif /* READ_iCCP */ + +#ifdef PNG_READ_sPLT_SUPPORTED +void /* PRIVATE */ +png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +/* Note: this does not properly handle chunks that are > 64K under DOS */ +{ + png_bytep entry_start, buffer; + png_sPLT_t new_palette; + png_sPLT_entryp pp; + png_uint_32 data_length; + int entry_size, i; + png_uint_32 skip = 0; + png_uint_32 dl; + size_t max_dl; + + png_debug(1, "in png_handle_sPLT"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for sPLT"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + +#ifdef PNG_MAX_MALLOC_64K + if (length > 65535U) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too large to fit in memory"); + return; + } +#endif + + buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/); + if (buffer == NULL) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + + + /* WARNING: this may break if size_t is less than 32 bits; it is assumed + * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a + * potential breakage point if the types in pngconf.h aren't exactly right. + */ + png_crc_read(png_ptr, buffer, length); + + if (png_crc_finish(png_ptr, skip) != 0) + return; + + buffer[length] = 0; + + for (entry_start = buffer; *entry_start; entry_start++) + /* Empty loop to find end of name */ ; + + ++entry_start; + + /* A sample depth should follow the separator, and we should be on it */ + if (length < 2U || entry_start > buffer + (length - 2U)) + { + png_warning(png_ptr, "malformed sPLT chunk"); + return; + } + + new_palette.depth = *entry_start++; + entry_size = (new_palette.depth == 8 ? 6 : 10); + /* This must fit in a png_uint_32 because it is derived from the original + * chunk data length. + */ + data_length = length - (png_uint_32)(entry_start - buffer); + + /* Integrity-check the data length */ + if ((data_length % (unsigned int)entry_size) != 0) + { + png_warning(png_ptr, "sPLT chunk has bad length"); + return; + } + + dl = (png_uint_32)(data_length / (unsigned int)entry_size); + max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry)); + + if (dl > max_dl) + { + png_warning(png_ptr, "sPLT chunk too long"); + return; + } + + new_palette.nentries = (png_int_32)(data_length / (unsigned int)entry_size); + + new_palette.entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, + (png_alloc_size_t) new_palette.nentries * (sizeof (png_sPLT_entry))); + + if (new_palette.entries == NULL) + { + png_warning(png_ptr, "sPLT chunk requires too much memory"); + return; + } + +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0; i < new_palette.nentries; i++) + { + pp = new_palette.entries + i; + + if (new_palette.depth == 8) + { + pp->red = *entry_start++; + pp->green = *entry_start++; + pp->blue = *entry_start++; + pp->alpha = *entry_start++; + } + + else + { + pp->red = png_get_uint_16(entry_start); entry_start += 2; + pp->green = png_get_uint_16(entry_start); entry_start += 2; + pp->blue = png_get_uint_16(entry_start); entry_start += 2; + pp->alpha = png_get_uint_16(entry_start); entry_start += 2; + } + + pp->frequency = png_get_uint_16(entry_start); entry_start += 2; + } +#else + pp = new_palette.entries; + + for (i = 0; i < new_palette.nentries; i++) + { + + if (new_palette.depth == 8) + { + pp[i].red = *entry_start++; + pp[i].green = *entry_start++; + pp[i].blue = *entry_start++; + pp[i].alpha = *entry_start++; + } + + else + { + pp[i].red = png_get_uint_16(entry_start); entry_start += 2; + pp[i].green = png_get_uint_16(entry_start); entry_start += 2; + pp[i].blue = png_get_uint_16(entry_start); entry_start += 2; + pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2; + } + + pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2; + } +#endif + + /* Discard all chunk data except the name and stash that */ + new_palette.name = (png_charp)buffer; + + png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); + + png_free(png_ptr, new_palette.entries); +} +#endif /* READ_sPLT */ + +#ifdef PNG_READ_tRNS_SUPPORTED +void /* PRIVATE */ +png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; + + png_debug(1, "in png_handle_tRNS"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + png_byte buf[2]; + + if (length != 2) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, buf, 2); + png_ptr->num_trans = 1; + png_ptr->trans_color.gray = png_get_uint_16(buf); + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + png_byte buf[6]; + + if (length != 6) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, buf, length); + png_ptr->num_trans = 1; + png_ptr->trans_color.red = png_get_uint_16(buf); + png_ptr->trans_color.green = png_get_uint_16(buf + 2); + png_ptr->trans_color.blue = png_get_uint_16(buf + 4); + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if ((png_ptr->mode & PNG_HAVE_PLTE) == 0) + { + /* TODO: is this actually an error in the ISO spec? */ + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + if (length > (unsigned int) png_ptr->num_palette || + length > (unsigned int) PNG_MAX_PALETTE_LENGTH || + length == 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, readbuf, length); + png_ptr->num_trans = (png_uint_16)length; + } + + else + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid with alpha channel"); + return; + } + + if (png_crc_finish(png_ptr, 0) != 0) + { + png_ptr->num_trans = 0; + return; + } + + /* TODO: this is a horrible side effect in the palette case because the + * png_struct ends up with a pointer to the tRNS buffer owned by the + * png_info. Fix this. + */ + png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, + &(png_ptr->trans_color)); +} +#endif + +#ifdef PNG_READ_bKGD_SUPPORTED +void /* PRIVATE */ +png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + unsigned int truelen; + png_byte buf[6]; + png_color_16 background; + + png_debug(1, "in png_handle_bKGD"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 || + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + (png_ptr->mode & PNG_HAVE_PLTE) == 0)) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + truelen = 1; + + else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + truelen = 6; + + else + truelen = 2; + + if (length != truelen) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, buf, truelen); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + /* We convert the index value into RGB components so that we can allow + * arbitrary RGB values for background when we have transparency, and + * so it is easy to determine the RGB values of the background color + * from the info_ptr struct. + */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + background.index = buf[0]; + + if (info_ptr != NULL && info_ptr->num_palette != 0) + { + if (buf[0] >= info_ptr->num_palette) + { + png_chunk_benign_error(png_ptr, "invalid index"); + return; + } + + background.red = (png_uint_16)png_ptr->palette[buf[0]].red; + background.green = (png_uint_16)png_ptr->palette[buf[0]].green; + background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue; + } + + else + background.red = background.green = background.blue = 0; + + background.gray = 0; + } + + else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */ + { + if (png_ptr->bit_depth <= 8) + { + if (buf[0] != 0 || buf[1] >= (unsigned int)(1 << png_ptr->bit_depth)) + { + png_chunk_benign_error(png_ptr, "invalid gray level"); + return; + } + } + + background.index = 0; + background.red = + background.green = + background.blue = + background.gray = png_get_uint_16(buf); + } + + else + { + if (png_ptr->bit_depth <= 8) + { + if (buf[0] != 0 || buf[2] != 0 || buf[4] != 0) + { + png_chunk_benign_error(png_ptr, "invalid color"); + return; + } + } + + background.index = 0; + background.red = png_get_uint_16(buf); + background.green = png_get_uint_16(buf + 2); + background.blue = png_get_uint_16(buf + 4); + background.gray = 0; + } + + png_set_bKGD(png_ptr, info_ptr, &background); +} +#endif + +#ifdef PNG_READ_eXIf_SUPPORTED +void /* PRIVATE */ +png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + unsigned int i; + + png_debug(1, "in png_handle_eXIf"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + if (length < 2) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too short"); + return; + } + + else if (info_ptr == NULL || (info_ptr->valid & PNG_INFO_eXIf) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + info_ptr->free_me |= PNG_FREE_EXIF; + + info_ptr->eXIf_buf = png_voidcast(png_bytep, + png_malloc_warn(png_ptr, length)); + + if (info_ptr->eXIf_buf == NULL) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + + for (i = 0; i < length; i++) + { + png_byte buf[1]; + png_crc_read(png_ptr, buf, 1); + info_ptr->eXIf_buf[i] = buf[0]; + if (i == 1 && buf[0] != 'M' && buf[0] != 'I' + && info_ptr->eXIf_buf[0] != buf[0]) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "incorrect byte-order specifier"); + png_free(png_ptr, info_ptr->eXIf_buf); + info_ptr->eXIf_buf = NULL; + return; + } + } + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf); + + png_free(png_ptr, info_ptr->eXIf_buf); + info_ptr->eXIf_buf = NULL; +} +#endif + +#ifdef PNG_READ_eXIf_SUPPORTED +void /* PRIVATE */ +png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + unsigned int i; + + png_debug(1, "in png_handle_eXIf"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + if (length < 2) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too short"); + return; + } + + else if (info_ptr == NULL || (info_ptr->valid & PNG_INFO_eXIf) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + info_ptr->free_me |= PNG_FREE_EXIF; + + info_ptr->eXIf_buf = png_voidcast(png_bytep, + png_malloc_warn(png_ptr, length)); + + if (info_ptr->eXIf_buf == NULL) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + + for (i = 0; i < length; i++) + { + png_byte buf[1]; + png_crc_read(png_ptr, buf, 1); + info_ptr->eXIf_buf[i] = buf[0]; + if (i == 1 && buf[0] != 'M' && buf[0] != 'I' + && info_ptr->eXIf_buf[0] != buf[0]) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "incorrect byte-order specifier"); + png_free(png_ptr, info_ptr->eXIf_buf); + info_ptr->eXIf_buf = NULL; + return; + } + } + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf); + + png_free(png_ptr, info_ptr->eXIf_buf); + info_ptr->eXIf_buf = NULL; +} +#endif + +#ifdef PNG_READ_hIST_SUPPORTED +void /* PRIVATE */ +png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + unsigned int num, i; + png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; + + png_debug(1, "in png_handle_hIST"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 || + (png_ptr->mode & PNG_HAVE_PLTE) == 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + num = length / 2 ; + + if (num != (unsigned int) png_ptr->num_palette || + num > (unsigned int) PNG_MAX_PALETTE_LENGTH) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + for (i = 0; i < num; i++) + { + png_byte buf[2]; + + png_crc_read(png_ptr, buf, 2); + readbuf[i] = png_get_uint_16(buf); + } + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + png_set_hIST(png_ptr, info_ptr, readbuf); +} +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED +void /* PRIVATE */ +png_handle_pHYs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_byte buf[9]; + png_uint_32 res_x, res_y; + int unit_type; + + png_debug(1, "in png_handle_pHYs"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + if (length != 9) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, buf, 9); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + res_x = png_get_uint_32(buf); + res_y = png_get_uint_32(buf + 4); + unit_type = buf[8]; + png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type); +} +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED +void /* PRIVATE */ +png_handle_oFFs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_byte buf[9]; + png_int_32 offset_x, offset_y; + int unit_type; + + png_debug(1, "in png_handle_oFFs"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + if (length != 9) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, buf, 9); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + offset_x = png_get_int_32(buf); + offset_y = png_get_int_32(buf + 4); + unit_type = buf[8]; + png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type); +} +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED +/* Read the pCAL chunk (described in the PNG Extensions document) */ +void /* PRIVATE */ +png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_int_32 X0, X1; + png_byte type, nparams; + png_bytep buffer, buf, units, endptr; + png_charpp params; + int i; + + png_debug(1, "in png_handle_pCAL"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)", + length + 1); + + buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/); + + if (buffer == NULL) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + + png_crc_read(png_ptr, buffer, length); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + buffer[length] = 0; /* Null terminate the last string */ + + png_debug(3, "Finding end of pCAL purpose string"); + for (buf = buffer; *buf; buf++) + /* Empty loop */ ; + + endptr = buffer + length; + + /* We need to have at least 12 bytes after the purpose string + * in order to get the parameter information. + */ + if (endptr - buf <= 12) + { + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_debug(3, "Reading pCAL X0, X1, type, nparams, and units"); + X0 = png_get_int_32((png_bytep)buf+1); + X1 = png_get_int_32((png_bytep)buf+5); + type = buf[9]; + nparams = buf[10]; + units = buf + 11; + + png_debug(3, "Checking pCAL equation type and number of parameters"); + /* Check that we have the right number of parameters for known + * equation types. + */ + if ((type == PNG_EQUATION_LINEAR && nparams != 2) || + (type == PNG_EQUATION_BASE_E && nparams != 3) || + (type == PNG_EQUATION_ARBITRARY && nparams != 3) || + (type == PNG_EQUATION_HYPERBOLIC && nparams != 4)) + { + png_chunk_benign_error(png_ptr, "invalid parameter count"); + return; + } + + else if (type >= PNG_EQUATION_LAST) + { + png_chunk_benign_error(png_ptr, "unrecognized equation type"); + } + + for (buf = units; *buf; buf++) + /* Empty loop to move past the units string. */ ; + + png_debug(3, "Allocating pCAL parameters array"); + + params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, + nparams * (sizeof (png_charp)))); + + if (params == NULL) + { + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + + /* Get pointers to the start of each parameter string. */ + for (i = 0; i < nparams; i++) + { + buf++; /* Skip the null string terminator from previous parameter. */ + + png_debug1(3, "Reading pCAL parameter %d", i); + + for (params[i] = (png_charp)buf; buf <= endptr && *buf != 0; buf++) + /* Empty loop to move past each parameter string */ ; + + /* Make sure we haven't run out of data yet */ + if (buf > endptr) + { + png_free(png_ptr, params); + png_chunk_benign_error(png_ptr, "invalid data"); + return; + } + } + + png_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams, + (png_charp)units, params); + + png_free(png_ptr, params); +} +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED +/* Read the sCAL chunk */ +void /* PRIVATE */ +png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_bytep buffer; + size_t i; + int state; + + png_debug(1, "in png_handle_sCAL"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of place"); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + /* Need unit type, width, \0, height: minimum 4 bytes */ + else if (length < 4) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)", + length + 1); + + buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/); + + if (buffer == NULL) + { + png_chunk_benign_error(png_ptr, "out of memory"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buffer, length); + buffer[length] = 0; /* Null terminate the last string */ + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + /* Validate the unit. */ + if (buffer[0] != 1 && buffer[0] != 2) + { + png_chunk_benign_error(png_ptr, "invalid unit"); + return; + } + + /* Validate the ASCII numbers, need two ASCII numbers separated by + * a '\0' and they need to fit exactly in the chunk data. + */ + i = 1; + state = 0; + + if (png_check_fp_number((png_const_charp)buffer, length, &state, &i) == 0 || + i >= length || buffer[i++] != 0) + png_chunk_benign_error(png_ptr, "bad width format"); + + else if (PNG_FP_IS_POSITIVE(state) == 0) + png_chunk_benign_error(png_ptr, "non-positive width"); + + else + { + size_t heighti = i; + + state = 0; + if (png_check_fp_number((png_const_charp)buffer, length, + &state, &i) == 0 || i != length) + png_chunk_benign_error(png_ptr, "bad height format"); + + else if (PNG_FP_IS_POSITIVE(state) == 0) + png_chunk_benign_error(png_ptr, "non-positive height"); + + else + /* This is the (only) success case. */ + png_set_sCAL_s(png_ptr, info_ptr, buffer[0], + (png_charp)buffer+1, (png_charp)buffer+heighti); + } +} +#endif + +#ifdef PNG_READ_tIME_SUPPORTED +void /* PRIVATE */ +png_handle_tIME(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_byte buf[7]; + png_time mod_time; + + png_debug(1, "in png_handle_tIME"); + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) != 0) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "duplicate"); + return; + } + + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + png_ptr->mode |= PNG_AFTER_IDAT; + + if (length != 7) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "invalid"); + return; + } + + png_crc_read(png_ptr, buf, 7); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + mod_time.second = buf[6]; + mod_time.minute = buf[5]; + mod_time.hour = buf[4]; + mod_time.day = buf[3]; + mod_time.month = buf[2]; + mod_time.year = png_get_uint_16(buf); + + png_set_tIME(png_ptr, info_ptr, &mod_time); +} +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED +/* Note: this does not properly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_text text_info; + png_bytep buffer; + png_charp key; + png_charp text; + png_uint_32 skip = 0; + + png_debug(1, "in png_handle_tEXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "no space in chunk cache"); + return; + } + } +#endif + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + if (length > 65535U) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "too large to fit in memory"); + return; + } +#endif + + buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/); + + if (buffer == NULL) + { + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + + png_crc_read(png_ptr, buffer, length); + + if (png_crc_finish(png_ptr, skip) != 0) + return; + + key = (png_charp)buffer; + key[length] = 0; + + for (text = key; *text; text++) + /* Empty loop to find end of key */ ; + + if (text != key + length) + text++; + + text_info.compression = PNG_TEXT_COMPRESSION_NONE; + text_info.key = key; + text_info.lang = NULL; + text_info.lang_key = NULL; + text_info.itxt_length = 0; + text_info.text = text; + text_info.text_length = strlen(text); + + if (png_set_text_2(png_ptr, info_ptr, &text_info, 1) != 0) + png_warning(png_ptr, "Insufficient memory to process text chunk"); +} +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED +/* Note: this does not correctly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_const_charp errmsg = NULL; + png_bytep buffer; + png_uint_32 keyword_length; + + png_debug(1, "in png_handle_zTXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "no space in chunk cache"); + return; + } + } +#endif + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + png_ptr->mode |= PNG_AFTER_IDAT; + + /* Note, "length" is sufficient here; we won't be adding + * a null terminator later. + */ + buffer = png_read_buffer(png_ptr, length, 2/*silent*/); + + if (buffer == NULL) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + + png_crc_read(png_ptr, buffer, length); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + /* TODO: also check that the keyword contents match the spec! */ + for (keyword_length = 0; + keyword_length < length && buffer[keyword_length] != 0; + ++keyword_length) + /* Empty loop to find end of name */ ; + + if (keyword_length > 79 || keyword_length < 1) + errmsg = "bad keyword"; + + /* zTXt must have some LZ data after the keyword, although it may expand to + * zero bytes; we need a '\0' at the end of the keyword, the compression type + * then the LZ data: + */ + else if (keyword_length + 3 > length) + errmsg = "truncated"; + + else if (buffer[keyword_length+1] != PNG_COMPRESSION_TYPE_BASE) + errmsg = "unknown compression type"; + + else + { + png_alloc_size_t uncompressed_length = PNG_SIZE_MAX; + + /* TODO: at present png_decompress_chunk imposes a single application + * level memory limit, this should be split to different values for iCCP + * and text chunks. + */ + if (png_decompress_chunk(png_ptr, length, keyword_length+2, + &uncompressed_length, 1/*terminate*/) == Z_STREAM_END) + { + png_text text; + + if (png_ptr->read_buffer == NULL) + errmsg="Read failure in png_handle_zTXt"; + else + { + /* It worked; png_ptr->read_buffer now looks like a tEXt chunk + * except for the extra compression type byte and the fact that + * it isn't necessarily '\0' terminated. + */ + buffer = png_ptr->read_buffer; + buffer[uncompressed_length+(keyword_length+2)] = 0; + + text.compression = PNG_TEXT_COMPRESSION_zTXt; + text.key = (png_charp)buffer; + text.text = (png_charp)(buffer + keyword_length+2); + text.text_length = uncompressed_length; + text.itxt_length = 0; + text.lang = NULL; + text.lang_key = NULL; + + if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0) + errmsg = "insufficient memory"; + } + } + + else + errmsg = png_ptr->zstream.msg; + } + + if (errmsg != NULL) + png_chunk_benign_error(png_ptr, errmsg); +} +#endif + +#ifdef PNG_READ_iTXt_SUPPORTED +/* Note: this does not correctly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) +{ + png_const_charp errmsg = NULL; + png_bytep buffer; + png_uint_32 prefix_length; + + png_debug(1, "in png_handle_iTXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "no space in chunk cache"); + return; + } + } +#endif + + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) + png_chunk_error(png_ptr, "missing IHDR"); + + if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) + png_ptr->mode |= PNG_AFTER_IDAT; + + buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/); + + if (buffer == NULL) + { + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "out of memory"); + return; + } + + png_crc_read(png_ptr, buffer, length); + + if (png_crc_finish(png_ptr, 0) != 0) + return; + + /* First the keyword. */ + for (prefix_length=0; + prefix_length < length && buffer[prefix_length] != 0; + ++prefix_length) + /* Empty loop */ ; + + /* Perform a basic check on the keyword length here. */ + if (prefix_length > 79 || prefix_length < 1) + errmsg = "bad keyword"; + + /* Expect keyword, compression flag, compression type, language, translated + * keyword (both may be empty but are 0 terminated) then the text, which may + * be empty. + */ + else if (prefix_length + 5 > length) + errmsg = "truncated"; + + else if (buffer[prefix_length+1] == 0 || + (buffer[prefix_length+1] == 1 && + buffer[prefix_length+2] == PNG_COMPRESSION_TYPE_BASE)) + { + int compressed = buffer[prefix_length+1] != 0; + png_uint_32 language_offset, translated_keyword_offset; + png_alloc_size_t uncompressed_length = 0; + + /* Now the language tag */ + prefix_length += 3; + language_offset = prefix_length; + + for (; prefix_length < length && buffer[prefix_length] != 0; + ++prefix_length) + /* Empty loop */ ; + + /* WARNING: the length may be invalid here, this is checked below. */ + translated_keyword_offset = ++prefix_length; + + for (; prefix_length < length && buffer[prefix_length] != 0; + ++prefix_length) + /* Empty loop */ ; + + /* prefix_length should now be at the trailing '\0' of the translated + * keyword, but it may already be over the end. None of this arithmetic + * can overflow because chunks are at most 2^31 bytes long, but on 16-bit + * systems the available allocation may overflow. + */ + ++prefix_length; + + if (compressed == 0 && prefix_length <= length) + uncompressed_length = length - prefix_length; + + else if (compressed != 0 && prefix_length < length) + { + uncompressed_length = PNG_SIZE_MAX; + + /* TODO: at present png_decompress_chunk imposes a single application + * level memory limit, this should be split to different values for + * iCCP and text chunks. + */ + if (png_decompress_chunk(png_ptr, length, prefix_length, + &uncompressed_length, 1/*terminate*/) == Z_STREAM_END) + buffer = png_ptr->read_buffer; + + else + errmsg = png_ptr->zstream.msg; + } + + else + errmsg = "truncated"; + + if (errmsg == NULL) + { + png_text text; + + buffer[uncompressed_length+prefix_length] = 0; + + if (compressed == 0) + text.compression = PNG_ITXT_COMPRESSION_NONE; + + else + text.compression = PNG_ITXT_COMPRESSION_zTXt; + + text.key = (png_charp)buffer; + text.lang = (png_charp)buffer + language_offset; + text.lang_key = (png_charp)buffer + translated_keyword_offset; + text.text = (png_charp)buffer + prefix_length; + text.text_length = 0; + text.itxt_length = uncompressed_length; + + if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0) + errmsg = "insufficient memory"; + } + } + + else + errmsg = "bad compression info"; + + if (errmsg != NULL) + png_chunk_benign_error(png_ptr, errmsg); +} +#endif + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */ +static int +png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length) +{ + png_alloc_size_t limit = PNG_SIZE_MAX; + + if (png_ptr->unknown_chunk.data != NULL) + { + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + } + +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_malloc_max > 0 && + png_ptr->user_chunk_malloc_max < limit) + limit = png_ptr->user_chunk_malloc_max; + +# elif PNG_USER_CHUNK_MALLOC_MAX > 0 + if (PNG_USER_CHUNK_MALLOC_MAX < limit) + limit = PNG_USER_CHUNK_MALLOC_MAX; +# endif + + if (length <= limit) + { + PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name); + /* The following is safe because of the PNG_SIZE_MAX init above */ + png_ptr->unknown_chunk.size = (size_t)length/*SAFE*/; + /* 'mode' is a flag array, only the bottom four bits matter here */ + png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/; + + if (length == 0) + png_ptr->unknown_chunk.data = NULL; + + else + { + /* Do a 'warn' here - it is handled below. */ + png_ptr->unknown_chunk.data = png_voidcast(png_bytep, + png_malloc_warn(png_ptr, length)); + } + } + + if (png_ptr->unknown_chunk.data == NULL && length > 0) + { + /* This is benign because we clean up correctly */ + png_crc_finish(png_ptr, length); + png_chunk_benign_error(png_ptr, "unknown chunk exceeds memory limits"); + return 0; + } + + else + { + if (length > 0) + png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length); + png_crc_finish(png_ptr, 0); + return 1; + } +} +#endif /* READ_UNKNOWN_CHUNKS */ + +/* Handle an unknown, or known but disabled, chunk */ +void /* PRIVATE */ +png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr, + png_uint_32 length, int keep) +{ + int handled = 0; /* the chunk was handled */ + + png_debug(1, "in png_handle_unknown"); + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + /* NOTE: this code is based on the code in libpng-1.4.12 except for fixing + * the bug which meant that setting a non-default behavior for a specific + * chunk would be ignored (the default was always used unless a user + * callback was installed). + * + * 'keep' is the value from the png_chunk_unknown_handling, the setting for + * this specific chunk_name, if PNG_HANDLE_AS_UNKNOWN_SUPPORTED, if not it + * will always be PNG_HANDLE_CHUNK_AS_DEFAULT and it needs to be set here. + * This is just an optimization to avoid multiple calls to the lookup + * function. + */ +# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name); +# endif +# endif + + /* One of the following methods will read the chunk or skip it (at least one + * of these is always defined because this is the only way to switch on + * PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + */ +# ifdef PNG_READ_USER_CHUNKS_SUPPORTED + /* The user callback takes precedence over the chunk keep value, but the + * keep value is still required to validate a save of a critical chunk. + */ + if (png_ptr->read_user_chunk_fn != NULL) + { + if (png_cache_unknown_chunk(png_ptr, length) != 0) + { + /* Callback to user unknown chunk handler */ + int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr, + &png_ptr->unknown_chunk); + + /* ret is: + * negative: An error occurred; png_chunk_error will be called. + * zero: The chunk was not handled, the chunk will be discarded + * unless png_set_keep_unknown_chunks has been used to set + * a 'keep' behavior for this particular chunk, in which + * case that will be used. A critical chunk will cause an + * error at this point unless it is to be saved. + * positive: The chunk was handled, libpng will ignore/discard it. + */ + if (ret < 0) + png_chunk_error(png_ptr, "error in user chunk"); + + else if (ret == 0) + { + /* If the keep value is 'default' or 'never' override it, but + * still error out on critical chunks unless the keep value is + * 'always' While this is weird it is the behavior in 1.4.12. + * A possible improvement would be to obey the value set for the + * chunk, but this would be an API change that would probably + * damage some applications. + * + * The png_app_warning below catches the case that matters, where + * the application has not set specific save or ignore for this + * chunk or global save or ignore. + */ + if (keep < PNG_HANDLE_CHUNK_IF_SAFE) + { +# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE) + { + png_chunk_warning(png_ptr, "Saving unknown chunk:"); + png_app_warning(png_ptr, + "forcing save of an unhandled chunk;" + " please call png_set_keep_unknown_chunks"); + /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */ + } +# endif + keep = PNG_HANDLE_CHUNK_IF_SAFE; + } + } + + else /* chunk was handled */ + { + handled = 1; + /* Critical chunks can be safely discarded at this point. */ + keep = PNG_HANDLE_CHUNK_NEVER; + } + } + + else + keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */ + } + + else + /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */ +# endif /* READ_USER_CHUNKS */ + +# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED + { + /* keep is currently just the per-chunk setting, if there was no + * setting change it to the global default now (not that this may + * still be AS_DEFAULT) then obtain the cache of the chunk if required, + * if not simply skip the chunk. + */ + if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT) + keep = png_ptr->unknown_default; + + if (keep == PNG_HANDLE_CHUNK_ALWAYS || + (keep == PNG_HANDLE_CHUNK_IF_SAFE && + PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))) + { + if (png_cache_unknown_chunk(png_ptr, length) == 0) + keep = PNG_HANDLE_CHUNK_NEVER; + } + + else + png_crc_finish(png_ptr, length); + } +# else +# ifndef PNG_READ_USER_CHUNKS_SUPPORTED +# error no method to support READ_UNKNOWN_CHUNKS +# endif + + { + /* If here there is no read callback pointer set and no support is + * compiled in to just save the unknown chunks, so simply skip this + * chunk. If 'keep' is something other than AS_DEFAULT or NEVER then + * the app has erroneously asked for unknown chunk saving when there + * is no support. + */ + if (keep > PNG_HANDLE_CHUNK_NEVER) + png_app_error(png_ptr, "no unknown chunk support available"); + + png_crc_finish(png_ptr, length); + } +# endif + +# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED + /* Now store the chunk in the chunk list if appropriate, and if the limits + * permit it. + */ + if (keep == PNG_HANDLE_CHUNK_ALWAYS || + (keep == PNG_HANDLE_CHUNK_IF_SAFE && + PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))) + { +# ifdef PNG_USER_LIMITS_SUPPORTED + switch (png_ptr->user_chunk_cache_max) + { + case 2: + png_ptr->user_chunk_cache_max = 1; + png_chunk_benign_error(png_ptr, "no space in chunk cache"); + /* FALLTHROUGH */ + case 1: + /* NOTE: prior to 1.6.0 this case resulted in an unknown critical + * chunk being skipped, now there will be a hard error below. + */ + break; + + default: /* not at limit */ + --(png_ptr->user_chunk_cache_max); + /* FALLTHROUGH */ + case 0: /* no limit */ +# endif /* USER_LIMITS */ + /* Here when the limit isn't reached or when limits are compiled + * out; store the chunk. + */ + png_set_unknown_chunks(png_ptr, info_ptr, + &png_ptr->unknown_chunk, 1); + handled = 1; +# ifdef PNG_USER_LIMITS_SUPPORTED + break; + } +# endif + } +# else /* no store support: the chunk must be handled by the user callback */ + PNG_UNUSED(info_ptr) +# endif + + /* Regardless of the error handling below the cached data (if any) can be + * freed now. Notice that the data is not freed if there is a png_error, but + * it will be freed by destroy_read_struct. + */ + if (png_ptr->unknown_chunk.data != NULL) + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + +#else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */ + /* There is no support to read an unknown chunk, so just skip it. */ + png_crc_finish(png_ptr, length); + PNG_UNUSED(info_ptr) + PNG_UNUSED(keep) +#endif /* !READ_UNKNOWN_CHUNKS */ + + /* Check for unhandled critical chunks */ + if (handled == 0 && PNG_CHUNK_CRITICAL(png_ptr->chunk_name)) + png_chunk_error(png_ptr, "unhandled critical chunk"); +} + +/* This function is called to verify that a chunk name is valid. + * This function can't have the "critical chunk check" incorporated + * into it, since in the future we will need to be able to call user + * functions to handle unknown critical chunks after we check that + * the chunk name itself is valid. + */ + +/* Bit hacking: the test for an invalid byte in the 4 byte chunk name is: + * + * ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) + */ + +void /* PRIVATE */ +png_check_chunk_name(png_const_structrp png_ptr, png_uint_32 chunk_name) +{ + int i; + png_uint_32 cn=chunk_name; + + png_debug(1, "in png_check_chunk_name"); + + for (i=1; i<=4; ++i) + { + int c = cn & 0xff; + + if (c < 65 || c > 122 || (c > 90 && c < 97)) + png_chunk_error(png_ptr, "invalid chunk type"); + + cn >>= 8; + } +} + +void /* PRIVATE */ +png_check_chunk_length(png_const_structrp png_ptr, png_uint_32 length) +{ + png_alloc_size_t limit = PNG_UINT_31_MAX; + +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_malloc_max > 0 && + png_ptr->user_chunk_malloc_max < limit) + limit = png_ptr->user_chunk_malloc_max; +# elif PNG_USER_CHUNK_MALLOC_MAX > 0 + if (PNG_USER_CHUNK_MALLOC_MAX < limit) + limit = PNG_USER_CHUNK_MALLOC_MAX; +# endif + if (png_ptr->chunk_name == png_IDAT) + { + png_alloc_size_t idat_limit = PNG_UINT_31_MAX; + size_t row_factor = + (size_t)png_ptr->width + * (size_t)png_ptr->channels + * (png_ptr->bit_depth > 8? 2: 1) + + 1 + + (png_ptr->interlaced? 6: 0); + if (png_ptr->height > PNG_UINT_32_MAX/row_factor) + idat_limit = PNG_UINT_31_MAX; + else + idat_limit = png_ptr->height * row_factor; + row_factor = row_factor > 32566? 32566 : row_factor; + idat_limit += 6 + 5*(idat_limit/row_factor+1); /* zlib+deflate overhead */ + idat_limit=idat_limit < PNG_UINT_31_MAX? idat_limit : PNG_UINT_31_MAX; + limit = limit < idat_limit? idat_limit : limit; + } + + if (length > limit) + { + png_debug2(0," length = %lu, limit = %lu", + (unsigned long)length,(unsigned long)limit); + png_chunk_error(png_ptr, "chunk data is too large"); + } +} + +/* Combines the row recently read in with the existing pixels in the row. This + * routine takes care of alpha and transparency if requested. This routine also + * handles the two methods of progressive display of interlaced images, + * depending on the 'display' value; if 'display' is true then the whole row + * (dp) is filled from the start by replicating the available pixels. If + * 'display' is false only those pixels present in the pass are filled in. + */ +void /* PRIVATE */ +png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display) +{ + unsigned int pixel_depth = png_ptr->transformed_pixel_depth; + png_const_bytep sp = png_ptr->row_buf + 1; + png_alloc_size_t row_width = png_ptr->width; + unsigned int pass = png_ptr->pass; + png_bytep end_ptr = 0; + png_byte end_byte = 0; + unsigned int end_mask; + + png_debug(1, "in png_combine_row"); + + /* Added in 1.5.6: it should not be possible to enter this routine until at + * least one row has been read from the PNG data and transformed. + */ + if (pixel_depth == 0) + png_error(png_ptr, "internal row logic error"); + + /* Added in 1.5.4: the pixel depth should match the information returned by + * any call to png_read_update_info at this point. Do not continue if we got + * this wrong. + */ + if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes != + PNG_ROWBYTES(pixel_depth, row_width)) + png_error(png_ptr, "internal row size calculation error"); + + /* Don't expect this to ever happen: */ + if (row_width == 0) + png_error(png_ptr, "internal row width error"); + + /* Preserve the last byte in cases where only part of it will be overwritten, + * the multiply below may overflow, we don't care because ANSI-C guarantees + * we get the low bits. + */ + end_mask = (pixel_depth * row_width) & 7; + if (end_mask != 0) + { + /* end_ptr == NULL is a flag to say do nothing */ + end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1; + end_byte = *end_ptr; +# ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + /* little-endian byte */ + end_mask = (unsigned int)(0xff << end_mask); + + else /* big-endian byte */ +# endif + end_mask = 0xff >> end_mask; + /* end_mask is now the bits to *keep* from the destination row */ + } + + /* For non-interlaced images this reduces to a memcpy(). A memcpy() + * will also happen if interlacing isn't supported or if the application + * does not call png_set_interlace_handling(). In the latter cases the + * caller just gets a sequence of the unexpanded rows from each interlace + * pass. + */ +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0 && + pass < 6 && (display == 0 || + /* The following copies everything for 'display' on passes 0, 2 and 4. */ + (display == 1 && (pass & 1) != 0))) + { + /* Narrow images may have no bits in a pass; the caller should handle + * this, but this test is cheap: + */ + if (row_width <= PNG_PASS_START_COL(pass)) + return; + + if (pixel_depth < 8) + { + /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit + * into 32 bits, then a single loop over the bytes using the four byte + * values in the 32-bit mask can be used. For the 'display' option the + * expanded mask may also not require any masking within a byte. To + * make this work the PACKSWAP option must be taken into account - it + * simply requires the pixels to be reversed in each byte. + * + * The 'regular' case requires a mask for each of the first 6 passes, + * the 'display' case does a copy for the even passes in the range + * 0..6. This has already been handled in the test above. + * + * The masks are arranged as four bytes with the first byte to use in + * the lowest bits (little-endian) regardless of the order (PACKSWAP or + * not) of the pixels in each byte. + * + * NOTE: the whole of this logic depends on the caller of this function + * only calling it on rows appropriate to the pass. This function only + * understands the 'x' logic; the 'y' logic is handled by the caller. + * + * The following defines allow generation of compile time constant bit + * masks for each pixel depth and each possibility of swapped or not + * swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index, + * is in the range 0..7; and the result is 1 if the pixel is to be + * copied in the pass, 0 if not. 'S' is for the sparkle method, 'B' + * for the block method. + * + * With some compilers a compile time expression of the general form: + * + * (shift >= 32) ? (a >> (shift-32)) : (b >> shift) + * + * Produces warnings with values of 'shift' in the range 33 to 63 + * because the right hand side of the ?: expression is evaluated by + * the compiler even though it isn't used. Microsoft Visual C (various + * versions) and the Intel C compiler are known to do this. To avoid + * this the following macros are used in 1.5.6. This is a temporary + * solution to avoid destabilizing the code during the release process. + */ +# if PNG_USE_COMPILE_TIME_MASKS +# define PNG_LSR(x,s) ((x)>>((s) & 0x1f)) +# define PNG_LSL(x,s) ((x)<<((s) & 0x1f)) +# else +# define PNG_LSR(x,s) ((x)>>(s)) +# define PNG_LSL(x,s) ((x)<<(s)) +# endif +# define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\ + PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1) +# define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\ + PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1) + + /* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is + * little endian - the first pixel is at bit 0 - however the extra + * parameter 's' can be set to cause the mask position to be swapped + * within each byte, to match the PNG format. This is done by XOR of + * the shift with 7, 6 or 4 for bit depths 1, 2 and 4. + */ +# define PIXEL_MASK(p,x,d,s) \ + (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0)))) + + /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask. + */ +# define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0) +# define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0) + + /* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp + * cases the result needs replicating, for the 4-bpp case the above + * generates a full 32 bits. + */ +# define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1))) + +# define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\ + S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\ + S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d) + +# define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\ + B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\ + B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d) + +#if PNG_USE_COMPILE_TIME_MASKS + /* Utility macros to construct all the masks for a depth/swap + * combination. The 's' parameter says whether the format is PNG + * (big endian bytes) or not. Only the three odd-numbered passes are + * required for the display/block algorithm. + */ +# define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\ + S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) } + +# define B_MASKS(d,s) { B_MASK(1,d,s), B_MASK(3,d,s), B_MASK(5,d,s) } + +# define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2)) + + /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and + * then pass: + */ + static const png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] = + { + /* Little-endian byte masks for PACKSWAP */ + { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) }, + /* Normal (big-endian byte) masks - PNG format */ + { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) } + }; + + /* display_mask has only three entries for the odd passes, so index by + * pass>>1. + */ + static const png_uint_32 display_mask[2][3][3] = + { + /* Little-endian byte masks for PACKSWAP */ + { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) }, + /* Normal (big-endian byte) masks - PNG format */ + { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) } + }; + +# define MASK(pass,depth,display,png)\ + ((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\ + row_mask[png][DEPTH_INDEX(depth)][pass]) + +#else /* !PNG_USE_COMPILE_TIME_MASKS */ + /* This is the runtime alternative: it seems unlikely that this will + * ever be either smaller or faster than the compile time approach. + */ +# define MASK(pass,depth,display,png)\ + ((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png)) +#endif /* !USE_COMPILE_TIME_MASKS */ + + /* Use the appropriate mask to copy the required bits. In some cases + * the byte mask will be 0 or 0xff; optimize these cases. row_width is + * the number of pixels, but the code copies bytes, so it is necessary + * to special case the end. + */ + png_uint_32 pixels_per_byte = 8 / pixel_depth; + png_uint_32 mask; + +# ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + mask = MASK(pass, pixel_depth, display, 0); + + else +# endif + mask = MASK(pass, pixel_depth, display, 1); + + for (;;) + { + png_uint_32 m; + + /* It doesn't matter in the following if png_uint_32 has more than + * 32 bits because the high bits always match those in m<<24; it is, + * however, essential to use OR here, not +, because of this. + */ + m = mask; + mask = (m >> 8) | (m << 24); /* rotate right to good compilers */ + m &= 0xff; + + if (m != 0) /* something to copy */ + { + if (m != 0xff) + *dp = (png_byte)((*dp & ~m) | (*sp & m)); + else + *dp = *sp; + } + + /* NOTE: this may overwrite the last byte with garbage if the image + * is not an exact number of bytes wide; libpng has always done + * this. + */ + if (row_width <= pixels_per_byte) + break; /* May need to restore part of the last byte */ + + row_width -= pixels_per_byte; + ++dp; + ++sp; + } + } + + else /* pixel_depth >= 8 */ + { + unsigned int bytes_to_copy, bytes_to_jump; + + /* Validate the depth - it must be a multiple of 8 */ + if (pixel_depth & 7) + png_error(png_ptr, "invalid user transform pixel depth"); + + pixel_depth >>= 3; /* now in bytes */ + row_width *= pixel_depth; + + /* Regardless of pass number the Adam 7 interlace always results in a + * fixed number of pixels to copy then to skip. There may be a + * different number of pixels to skip at the start though. + */ + { + unsigned int offset = PNG_PASS_START_COL(pass) * pixel_depth; + + row_width -= offset; + dp += offset; + sp += offset; + } + + /* Work out the bytes to copy. */ + if (display != 0) + { + /* When doing the 'block' algorithm the pixel in the pass gets + * replicated to adjacent pixels. This is why the even (0,2,4,6) + * passes are skipped above - the entire expanded row is copied. + */ + bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth; + + /* But don't allow this number to exceed the actual row width. */ + if (bytes_to_copy > row_width) + bytes_to_copy = (unsigned int)/*SAFE*/row_width; + } + + else /* normal row; Adam7 only ever gives us one pixel to copy. */ + bytes_to_copy = pixel_depth; + + /* In Adam7 there is a constant offset between where the pixels go. */ + bytes_to_jump = PNG_PASS_COL_OFFSET(pass) * pixel_depth; + + /* And simply copy these bytes. Some optimization is possible here, + * depending on the value of 'bytes_to_copy'. Special case the low + * byte counts, which we know to be frequent. + * + * Notice that these cases all 'return' rather than 'break' - this + * avoids an unnecessary test on whether to restore the last byte + * below. + */ + switch (bytes_to_copy) + { + case 1: + for (;;) + { + *dp = *sp; + + if (row_width <= bytes_to_jump) + return; + + dp += bytes_to_jump; + sp += bytes_to_jump; + row_width -= bytes_to_jump; + } + + case 2: + /* There is a possibility of a partial copy at the end here; this + * slows the code down somewhat. + */ + do + { + dp[0] = sp[0]; dp[1] = sp[1]; + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + } + while (row_width > 1); + + /* And there can only be one byte left at this point: */ + *dp = *sp; + return; + + case 3: + /* This can only be the RGB case, so each copy is exactly one + * pixel and it is not necessary to check for a partial copy. + */ + for (;;) + { + dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2]; + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + } + + default: +#if PNG_ALIGN_TYPE != PNG_ALIGN_NONE + /* Check for double byte alignment and, if possible, use a + * 16-bit copy. Don't attempt this for narrow images - ones that + * are less than an interlace panel wide. Don't attempt it for + * wide bytes_to_copy either - use the memcpy there. + */ + if (bytes_to_copy < 16 /*else use memcpy*/ && + png_isaligned(dp, png_uint_16) && + png_isaligned(sp, png_uint_16) && + bytes_to_copy % (sizeof (png_uint_16)) == 0 && + bytes_to_jump % (sizeof (png_uint_16)) == 0) + { + /* Everything is aligned for png_uint_16 copies, but try for + * png_uint_32 first. + */ + if (png_isaligned(dp, png_uint_32) && + png_isaligned(sp, png_uint_32) && + bytes_to_copy % (sizeof (png_uint_32)) == 0 && + bytes_to_jump % (sizeof (png_uint_32)) == 0) + { + png_uint_32p dp32 = png_aligncast(png_uint_32p,dp); + png_const_uint_32p sp32 = png_aligncastconst( + png_const_uint_32p, sp); + size_t skip = (bytes_to_jump-bytes_to_copy) / + (sizeof (png_uint_32)); + + do + { + size_t c = bytes_to_copy; + do + { + *dp32++ = *sp32++; + c -= (sizeof (png_uint_32)); + } + while (c > 0); + + if (row_width <= bytes_to_jump) + return; + + dp32 += skip; + sp32 += skip; + row_width -= bytes_to_jump; + } + while (bytes_to_copy <= row_width); + + /* Get to here when the row_width truncates the final copy. + * There will be 1-3 bytes left to copy, so don't try the + * 16-bit loop below. + */ + dp = (png_bytep)dp32; + sp = (png_const_bytep)sp32; + do + *dp++ = *sp++; + while (--row_width > 0); + return; + } + + /* Else do it in 16-bit quantities, but only if the size is + * not too large. + */ + else + { + png_uint_16p dp16 = png_aligncast(png_uint_16p, dp); + png_const_uint_16p sp16 = png_aligncastconst( + png_const_uint_16p, sp); + size_t skip = (bytes_to_jump-bytes_to_copy) / + (sizeof (png_uint_16)); + + do + { + size_t c = bytes_to_copy; + do + { + *dp16++ = *sp16++; + c -= (sizeof (png_uint_16)); + } + while (c > 0); + + if (row_width <= bytes_to_jump) + return; + + dp16 += skip; + sp16 += skip; + row_width -= bytes_to_jump; + } + while (bytes_to_copy <= row_width); + + /* End of row - 1 byte left, bytes_to_copy > row_width: */ + dp = (png_bytep)dp16; + sp = (png_const_bytep)sp16; + do + *dp++ = *sp++; + while (--row_width > 0); + return; + } + } +#endif /* ALIGN_TYPE code */ + + /* The true default - use a memcpy: */ + for (;;) + { + memcpy(dp, sp, bytes_to_copy); + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + if (bytes_to_copy > row_width) + bytes_to_copy = (unsigned int)/*SAFE*/row_width; + } + } + + /* NOT REACHED*/ + } /* pixel_depth >= 8 */ + + /* Here if pixel_depth < 8 to check 'end_ptr' below. */ + } + else +#endif /* READ_INTERLACING */ + + /* If here then the switch above wasn't used so just memcpy the whole row + * from the temporary row buffer (notice that this overwrites the end of the + * destination row if it is a partial byte.) + */ + memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width)); + + /* Restore the overwritten bits from the last byte if necessary. */ + if (end_ptr != NULL) + *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask)); +} + +#ifdef PNG_READ_INTERLACING_SUPPORTED +void /* PRIVATE */ +png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, + png_uint_32 transformations /* Because these may affect the byte layout */) +{ + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + /* Offset to next interlace block */ + static const unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + png_debug(1, "in png_do_read_interlace"); + if (row != NULL && row_info != NULL) + { + png_uint_32 final_width; + + final_width = row_info->width * png_pass_inc[pass]; + + switch (row_info->pixel_depth) + { + case 1: + { + png_bytep sp = row + (size_t)((row_info->width - 1) >> 3); + png_bytep dp = row + (size_t)((final_width - 1) >> 3); + unsigned int sshift, dshift; + unsigned int s_start, s_end; + int s_inc; + int jstop = (int)png_pass_inc[pass]; + png_byte v; + png_uint_32 i; + int j; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((transformations & PNG_PACKSWAP) != 0) + { + sshift = ((row_info->width + 7) & 0x07); + dshift = ((final_width + 7) & 0x07); + s_start = 7; + s_end = 0; + s_inc = -1; + } + + else +#endif + { + sshift = 7 - ((row_info->width + 7) & 0x07); + dshift = 7 - ((final_width + 7) & 0x07); + s_start = 0; + s_end = 7; + s_inc = 1; + } + + for (i = 0; i < row_info->width; i++) + { + v = (png_byte)((*sp >> sshift) & 0x01); + for (j = 0; j < jstop; j++) + { + unsigned int tmp = *dp & (0x7f7f >> (7 - dshift)); + tmp |= (unsigned int)(v << dshift); + *dp = (png_byte)(tmp & 0xff); + + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + + else + dshift = (unsigned int)((int)dshift + s_inc); + } + + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + + else + sshift = (unsigned int)((int)sshift + s_inc); + } + break; + } + + case 2: + { + png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2); + png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2); + unsigned int sshift, dshift; + unsigned int s_start, s_end; + int s_inc; + int jstop = (int)png_pass_inc[pass]; + png_uint_32 i; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((transformations & PNG_PACKSWAP) != 0) + { + sshift = (((row_info->width + 3) & 0x03) << 1); + dshift = (((final_width + 3) & 0x03) << 1); + s_start = 6; + s_end = 0; + s_inc = -2; + } + + else +#endif + { + sshift = ((3 - ((row_info->width + 3) & 0x03)) << 1); + dshift = ((3 - ((final_width + 3) & 0x03)) << 1); + s_start = 0; + s_end = 6; + s_inc = 2; + } + + for (i = 0; i < row_info->width; i++) + { + png_byte v; + int j; + + v = (png_byte)((*sp >> sshift) & 0x03); + for (j = 0; j < jstop; j++) + { + unsigned int tmp = *dp & (0x3f3f >> (6 - dshift)); + tmp |= (unsigned int)(v << dshift); + *dp = (png_byte)(tmp & 0xff); + + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + + else + dshift = (unsigned int)((int)dshift + s_inc); + } + + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + + else + sshift = (unsigned int)((int)sshift + s_inc); + } + break; + } + + case 4: + { + png_bytep sp = row + (size_t)((row_info->width - 1) >> 1); + png_bytep dp = row + (size_t)((final_width - 1) >> 1); + unsigned int sshift, dshift; + unsigned int s_start, s_end; + int s_inc; + png_uint_32 i; + int jstop = (int)png_pass_inc[pass]; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if ((transformations & PNG_PACKSWAP) != 0) + { + sshift = (((row_info->width + 1) & 0x01) << 2); + dshift = (((final_width + 1) & 0x01) << 2); + s_start = 4; + s_end = 0; + s_inc = -4; + } + + else +#endif + { + sshift = ((1 - ((row_info->width + 1) & 0x01)) << 2); + dshift = ((1 - ((final_width + 1) & 0x01)) << 2); + s_start = 0; + s_end = 4; + s_inc = 4; + } + + for (i = 0; i < row_info->width; i++) + { + png_byte v = (png_byte)((*sp >> sshift) & 0x0f); + int j; + + for (j = 0; j < jstop; j++) + { + unsigned int tmp = *dp & (0xf0f >> (4 - dshift)); + tmp |= (unsigned int)(v << dshift); + *dp = (png_byte)(tmp & 0xff); + + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + + else + dshift = (unsigned int)((int)dshift + s_inc); + } + + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + + else + sshift = (unsigned int)((int)sshift + s_inc); + } + break; + } + + default: + { + size_t pixel_bytes = (row_info->pixel_depth >> 3); + + png_bytep sp = row + (size_t)(row_info->width - 1) + * pixel_bytes; + + png_bytep dp = row + (size_t)(final_width - 1) * pixel_bytes; + + int jstop = (int)png_pass_inc[pass]; + png_uint_32 i; + + for (i = 0; i < row_info->width; i++) + { + png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */ + int j; + + memcpy(v, sp, pixel_bytes); + + for (j = 0; j < jstop; j++) + { + memcpy(dp, v, pixel_bytes); + dp -= pixel_bytes; + } + + sp -= pixel_bytes; + } + break; + } + } + + row_info->width = final_width; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); + } +#ifndef PNG_READ_PACKSWAP_SUPPORTED + PNG_UNUSED(transformations) /* Silence compiler warning */ +#endif +} +#endif /* READ_INTERLACING */ + +static void +png_read_filter_row_sub(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + size_t i; + size_t istop = row_info->rowbytes; + unsigned int bpp = (row_info->pixel_depth + 7) >> 3; + png_bytep rp = row + bpp; + + PNG_UNUSED(prev_row) + + for (i = bpp; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff); + rp++; + } +} + +static void +png_read_filter_row_up(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + size_t i; + size_t istop = row_info->rowbytes; + png_bytep rp = row; + png_const_bytep pp = prev_row; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; + } +} + +static void +png_read_filter_row_avg(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + size_t i; + png_bytep rp = row; + png_const_bytep pp = prev_row; + unsigned int bpp = (row_info->pixel_depth + 7) >> 3; + size_t istop = row_info->rowbytes - bpp; + + for (i = 0; i < bpp; i++) + { + *rp = (png_byte)(((int)(*rp) + + ((int)(*pp++) / 2 )) & 0xff); + + rp++; + } + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + + (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff); + + rp++; + } +} + +static void +png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp_end = row + row_info->rowbytes; + int a, c; + + /* First pixel/byte */ + c = *prev_row++; + a = *row + c; + *row++ = (png_byte)a; + + /* Remainder */ + while (row < rp_end) + { + int b, pa, pb, pc, p; + + a &= 0xff; /* From previous iteration or start */ + b = *prev_row++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + /* Find the best predictor, the least of pa, pb, pc favoring the earlier + * ones in the case of a tie. + */ + if (pb < pa) + { + pa = pb; a = b; + } + if (pc < pa) a = c; + + /* Calculate the current pixel in a, and move the previous row pixel to c + * for the next time round the loop + */ + c = b; + a += *row; + *row++ = (png_byte)a; + } +} + +static void +png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + unsigned int bpp = (row_info->pixel_depth + 7) >> 3; + png_bytep rp_end = row + bpp; + + /* Process the first pixel in the row completely (this is the same as 'up' + * because there is only one candidate predictor for the first row). + */ + while (row < rp_end) + { + int a = *row + *prev_row++; + *row++ = (png_byte)a; + } + + /* Remainder */ + rp_end = rp_end + (row_info->rowbytes - bpp); + + while (row < rp_end) + { + int a, b, c, pa, pb, pc, p; + + c = *(prev_row - bpp); + a = *(row - bpp); + b = *prev_row++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + if (pb < pa) + { + pa = pb; a = b; + } + if (pc < pa) a = c; + + a += *row; + *row++ = (png_byte)a; + } +} + +static void +png_init_filter_functions(png_structrp pp) + /* This function is called once for every PNG image (except for PNG images + * that only use PNG_FILTER_VALUE_NONE for all rows) to set the + * implementations required to reverse the filtering of PNG rows. Reversing + * the filter is the first transformation performed on the row data. It is + * performed in place, therefore an implementation can be selected based on + * the image pixel format. If the implementation depends on image width then + * take care to ensure that it works correctly if the image is interlaced - + * interlacing causes the actual row width to vary. + */ +{ + unsigned int bpp = (pp->pixel_depth + 7) >> 3; + + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub; + pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg; + if (bpp == 1) + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth_1byte_pixel; + else + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth_multibyte_pixel; + +#ifdef PNG_FILTER_OPTIMIZATIONS + /* To use this define PNG_FILTER_OPTIMIZATIONS as the name of a function to + * call to install hardware optimizations for the above functions; simply + * replace whatever elements of the pp->read_filter[] array with a hardware + * specific (or, for that matter, generic) optimization. + * + * To see an example of this examine what configure.ac does when + * --enable-arm-neon is specified on the command line. + */ + PNG_FILTER_OPTIMIZATIONS(pp, bpp); +#endif +} + +void /* PRIVATE */ +png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row, + png_const_bytep prev_row, int filter) +{ + /* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define + * PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic + * implementations. See png_init_filter_functions above. + */ + if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST) + { + if (pp->read_filter[0] == NULL) + png_init_filter_functions(pp); + + pp->read_filter[filter-1](row_info, row, prev_row); + } +} + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +void /* PRIVATE */ +png_read_IDAT_data(png_structrp png_ptr, png_bytep output, + png_alloc_size_t avail_out) +{ + /* Loop reading IDATs and decompressing the result into output[avail_out] */ + png_ptr->zstream.next_out = output; + png_ptr->zstream.avail_out = 0; /* safety: set below */ + + if (output == NULL) + avail_out = 0; + + do + { + int ret; + png_byte tmpbuf[PNG_INFLATE_BUF_SIZE]; + + if (png_ptr->zstream.avail_in == 0) + { + uInt avail_in; + png_bytep buffer; + + while (png_ptr->idat_size == 0) + { + png_crc_finish(png_ptr, 0); + + png_ptr->idat_size = png_read_chunk_header(png_ptr); + /* This is an error even in the 'check' case because the code just + * consumed a non-IDAT header. + */ + if (png_ptr->chunk_name != png_IDAT) + png_error(png_ptr, "Not enough image data"); + } + + avail_in = png_ptr->IDAT_read_size; + + if (avail_in > png_ptr->idat_size) + avail_in = (uInt)png_ptr->idat_size; + + /* A PNG with a gradually increasing IDAT size will defeat this attempt + * to minimize memory usage by causing lots of re-allocs, but + * realistically doing IDAT_read_size re-allocs is not likely to be a + * big problem. + */ + buffer = png_read_buffer(png_ptr, avail_in, 0/*error*/); + + png_crc_read(png_ptr, buffer, avail_in); + png_ptr->idat_size -= avail_in; + + png_ptr->zstream.next_in = buffer; + png_ptr->zstream.avail_in = avail_in; + } + + /* And set up the output side. */ + if (output != NULL) /* standard read */ + { + uInt out = ZLIB_IO_MAX; + + if (out > avail_out) + out = (uInt)avail_out; + + avail_out -= out; + png_ptr->zstream.avail_out = out; + } + + else /* after last row, checking for end */ + { + png_ptr->zstream.next_out = tmpbuf; + png_ptr->zstream.avail_out = (sizeof tmpbuf); + } + + /* Use NO_FLUSH; this gives zlib the maximum opportunity to optimize the + * process. If the LZ stream is truncated the sequential reader will + * terminally damage the stream, above, by reading the chunk header of the + * following chunk (it then exits with png_error). + * + * TODO: deal more elegantly with truncated IDAT lists. + */ + ret = PNG_INFLATE(png_ptr, Z_NO_FLUSH); + + /* Take the unconsumed output back. */ + if (output != NULL) + avail_out += png_ptr->zstream.avail_out; + + else /* avail_out counts the extra bytes */ + avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out; + + png_ptr->zstream.avail_out = 0; + + if (ret == Z_STREAM_END) + { + /* Do this for safety; we won't read any more into this row. */ + png_ptr->zstream.next_out = NULL; + + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + + if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0) + png_chunk_benign_error(png_ptr, "Extra compressed data"); + break; + } + + if (ret != Z_OK) + { + png_zstream_error(png_ptr, ret); + + if (output != NULL) + png_chunk_error(png_ptr, png_ptr->zstream.msg); + + else /* checking */ + { + png_chunk_benign_error(png_ptr, png_ptr->zstream.msg); + return; + } + } + } while (avail_out > 0); + + if (avail_out > 0) + { + /* The stream ended before the image; this is the same as too few IDATs so + * should be handled the same way. + */ + if (output != NULL) + png_error(png_ptr, "Not enough image data"); + + else /* the deflate stream contained extra data */ + png_chunk_benign_error(png_ptr, "Too much image data"); + } +} + +void /* PRIVATE */ +png_read_finish_IDAT(png_structrp png_ptr) +{ + /* We don't need any more data and the stream should have ended, however the + * LZ end code may actually not have been processed. In this case we must + * read it otherwise stray unread IDAT data or, more likely, an IDAT chunk + * may still remain to be consumed. + */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) + { + /* The NULL causes png_read_IDAT_data to swallow any remaining bytes in + * the compressed stream, but the stream may be damaged too, so even after + * this call we may need to terminate the zstream ownership. + */ + png_read_IDAT_data(png_ptr, NULL, 0); + png_ptr->zstream.next_out = NULL; /* safety */ + + /* Now clear everything out for safety; the following may not have been + * done. + */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) + { + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; + } + } + + /* If the zstream has not been released do it now *and* terminate the reading + * of the final IDAT chunk. + */ + if (png_ptr->zowner == png_IDAT) + { + /* Always do this; the pointers otherwise point into the read buffer. */ + png_ptr->zstream.next_in = NULL; + png_ptr->zstream.avail_in = 0; + + /* Now we no longer own the zstream. */ + png_ptr->zowner = 0; + + /* The slightly weird semantics of the sequential IDAT reading is that we + * are always in or at the end of an IDAT chunk, so we always need to do a + * crc_finish here. If idat_size is non-zero we also need to read the + * spurious bytes at the end of the chunk now. + */ + (void)png_crc_finish(png_ptr, png_ptr->idat_size); + } +} + +void /* PRIVATE */ +png_read_finish_row(png_structrp png_ptr) +{ + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; + + png_debug(1, "in png_read_finish_row"); + png_ptr->row_number++; + if (png_ptr->row_number < png_ptr->num_rows) + return; + + if (png_ptr->interlaced != 0) + { + png_ptr->row_number = 0; + + /* TO DO: don't do this if prev_row isn't needed (requires + * read-ahead of the next row's filter byte. + */ + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + + do + { + png_ptr->pass++; + + if (png_ptr->pass >= 7) + break; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + if ((png_ptr->transformations & PNG_INTERLACE) == 0) + { + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + } + + else /* if (png_ptr->transformations & PNG_INTERLACE) */ + break; /* libpng deinterlacing sees every row */ + + } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0); + + if (png_ptr->pass < 7) + return; + } + + /* Here after at the end of the last row of the last pass. */ + png_read_finish_IDAT(png_ptr); +} +#endif /* SEQUENTIAL_READ */ + +void /* PRIVATE */ +png_read_start_row(png_structrp png_ptr) +{ + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; + + unsigned int max_pixel_depth; + size_t row_bytes; + + png_debug(1, "in png_read_start_row"); + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED + png_init_read_transformations(png_ptr); +#endif + if (png_ptr->interlaced != 0) + { + if ((png_ptr->transformations & PNG_INTERLACE) == 0) + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + + else + png_ptr->num_rows = png_ptr->height; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + } + + else + { + png_ptr->num_rows = png_ptr->height; + png_ptr->iwidth = png_ptr->width; + } + + max_pixel_depth = (unsigned int)png_ptr->pixel_depth; + + /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of + * calculations to calculate the final pixel depth, then + * png_do_read_transforms actually does the transforms. This means that the + * code which effectively calculates this value is actually repeated in three + * separate places. They must all match. Innocent changes to the order of + * transformations can and will break libpng in a way that causes memory + * overwrites. + * + * TODO: fix this. + */ +#ifdef PNG_READ_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) != 0 && png_ptr->bit_depth < 8) + max_pixel_depth = 8; +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED + if ((png_ptr->transformations & PNG_EXPAND) != 0) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (png_ptr->num_trans != 0) + max_pixel_depth = 32; + + else + max_pixel_depth = 24; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + if (max_pixel_depth < 8) + max_pixel_depth = 8; + + if (png_ptr->num_trans != 0) + max_pixel_depth *= 2; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + if (png_ptr->num_trans != 0) + { + max_pixel_depth *= 4; + max_pixel_depth /= 3; + } + } + } +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED + if ((png_ptr->transformations & PNG_EXPAND_16) != 0) + { +# ifdef PNG_READ_EXPAND_SUPPORTED + /* In fact it is an error if it isn't supported, but checking is + * the safe way. + */ + if ((png_ptr->transformations & PNG_EXPAND) != 0) + { + if (png_ptr->bit_depth < 16) + max_pixel_depth *= 2; + } + else +# endif + png_ptr->transformations &= ~PNG_EXPAND_16; + } +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED + if ((png_ptr->transformations & (PNG_FILLER)) != 0) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + if (max_pixel_depth <= 8) + max_pixel_depth = 16; + + else + max_pixel_depth = 32; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB || + png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (max_pixel_depth <= 32) + max_pixel_depth = 32; + + else + max_pixel_depth = 64; + } + } +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0) + { + if ( +#ifdef PNG_READ_EXPAND_SUPPORTED + (png_ptr->num_trans != 0 && + (png_ptr->transformations & PNG_EXPAND) != 0) || +#endif +#ifdef PNG_READ_FILLER_SUPPORTED + (png_ptr->transformations & (PNG_FILLER)) != 0 || +#endif + png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (max_pixel_depth <= 16) + max_pixel_depth = 32; + + else + max_pixel_depth = 64; + } + + else + { + if (max_pixel_depth <= 8) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + max_pixel_depth = 32; + + else + max_pixel_depth = 24; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + max_pixel_depth = 64; + + else + max_pixel_depth = 48; + } + } +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \ +defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) + if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) + { + unsigned int user_pixel_depth = png_ptr->user_transform_depth * + png_ptr->user_transform_channels; + + if (user_pixel_depth > max_pixel_depth) + max_pixel_depth = user_pixel_depth; + } +#endif + + /* This value is stored in png_struct and double checked in the row read + * code. + */ + png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth; + png_ptr->transformed_pixel_depth = 0; /* calculated on demand */ + + /* Align the width on the next larger 8 pixels. Mainly used + * for interlacing + */ + row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7)); + /* Calculate the maximum bytes needed, adding a byte and a pixel + * for safety's sake + */ + row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) + + 1 + ((max_pixel_depth + 7) >> 3U); + +#ifdef PNG_MAX_MALLOC_64K + if (row_bytes > (png_uint_32)65536L) + png_error(png_ptr, "This image requires a row greater than 64KB"); +#endif + + if (row_bytes + 48 > png_ptr->old_big_row_buf_size) + { + png_free(png_ptr, png_ptr->big_row_buf); + png_free(png_ptr, png_ptr->big_prev_row); + + if (png_ptr->interlaced != 0) + png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, + row_bytes + 48); + + else + png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48); + + png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48); + +#ifdef PNG_ALIGNED_MEMORY_SUPPORTED + /* Use 16-byte aligned memory for row_buf with at least 16 bytes + * of padding before and after row_buf; treat prev_row similarly. + * NOTE: the alignment is to the start of the pixels, one beyond the start + * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this + * was incorrect; the filter byte was aligned, which had the exact + * opposite effect of that intended. + */ + { + png_bytep temp = png_ptr->big_row_buf + 32; + int extra = (int)((temp - (png_bytep)0) & 0x0f); + png_ptr->row_buf = temp - extra - 1/*filter byte*/; + + temp = png_ptr->big_prev_row + 32; + extra = (int)((temp - (png_bytep)0) & 0x0f); + png_ptr->prev_row = temp - extra - 1/*filter byte*/; + } + +#else + /* Use 31 bytes of padding before and 17 bytes after row_buf. */ + png_ptr->row_buf = png_ptr->big_row_buf + 31; + png_ptr->prev_row = png_ptr->big_prev_row + 31; +#endif + png_ptr->old_big_row_buf_size = row_bytes + 48; + } + +#ifdef PNG_MAX_MALLOC_64K + if (png_ptr->rowbytes > 65535) + png_error(png_ptr, "This image requires a row greater than 64KB"); + +#endif + if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1)) + png_error(png_ptr, "Row has too many bytes to allocate in memory"); + + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + + png_debug1(3, "width = %u,", png_ptr->width); + png_debug1(3, "height = %u,", png_ptr->height); + png_debug1(3, "iwidth = %u,", png_ptr->iwidth); + png_debug1(3, "num_rows = %u,", png_ptr->num_rows); + png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes); + png_debug1(3, "irowbytes = %lu", + (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); + + /* The sequential reader needs a buffer for IDAT, but the progressive reader + * does not, so free the read buffer now regardless; the sequential reader + * reallocates it on demand. + */ + if (png_ptr->read_buffer != NULL) + { + png_bytep buffer = png_ptr->read_buffer; + + png_ptr->read_buffer_size = 0; + png_ptr->read_buffer = NULL; + png_free(png_ptr, buffer); + } + + /* Finally claim the zstream for the inflate of the IDAT data, use the bits + * value from the stream (note that this will result in a fatal error if the + * IDAT stream has a bogus deflate header window_bits value, but this should + * not be happening any longer!) + */ + if (png_inflate_claim(png_ptr, png_IDAT) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); + + png_ptr->flags |= PNG_FLAG_ROW_INIT; +} +#endif /* READ */ diff --git a/extern/libpng/pngset.c b/extern/libpng/pngset.c new file mode 100644 index 000000000..ec75dbe36 --- /dev/null +++ b/extern/libpng/pngset.c @@ -0,0 +1,1802 @@ + +/* pngset.c - storage of image information into info struct + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * The functions here are used during reads to store data from the file + * into the info struct, and during writes to store application data + * into the info struct for writing into the file. This abstracts the + * info struct and allows us to change the structure in the future. + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +#ifdef PNG_bKGD_SUPPORTED +void PNGAPI +png_set_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_color_16p background) +{ + png_debug1(1, "in %s storage function", "bKGD"); + + if (png_ptr == NULL || info_ptr == NULL || background == NULL) + return; + + info_ptr->background = *background; + info_ptr->valid |= PNG_INFO_bKGD; +} +#endif + +#ifdef PNG_cHRM_SUPPORTED +void PNGFAPI +png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr, + png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, + png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, + png_fixed_point blue_x, png_fixed_point blue_y) +{ + png_xy xy; + + png_debug1(1, "in %s storage function", "cHRM fixed"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + xy.redx = red_x; + xy.redy = red_y; + xy.greenx = green_x; + xy.greeny = green_y; + xy.bluex = blue_x; + xy.bluey = blue_y; + xy.whitex = white_x; + xy.whitey = white_y; + + if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy, + 2/* override with app values*/) != 0) + info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; + + png_colorspace_sync_info(png_ptr, info_ptr); +} + +void PNGFAPI +png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr, + png_fixed_point int_red_X, png_fixed_point int_red_Y, + png_fixed_point int_red_Z, png_fixed_point int_green_X, + png_fixed_point int_green_Y, png_fixed_point int_green_Z, + png_fixed_point int_blue_X, png_fixed_point int_blue_Y, + png_fixed_point int_blue_Z) +{ + png_XYZ XYZ; + + png_debug1(1, "in %s storage function", "cHRM XYZ fixed"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + XYZ.red_X = int_red_X; + XYZ.red_Y = int_red_Y; + XYZ.red_Z = int_red_Z; + XYZ.green_X = int_green_X; + XYZ.green_Y = int_green_Y; + XYZ.green_Z = int_green_Z; + XYZ.blue_X = int_blue_X; + XYZ.blue_Y = int_blue_Y; + XYZ.blue_Z = int_blue_Z; + + if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, + &XYZ, 2) != 0) + info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; + + png_colorspace_sync_info(png_ptr, info_ptr); +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, + double white_x, double white_y, double red_x, double red_y, + double green_x, double green_y, double blue_x, double blue_y) +{ + png_set_cHRM_fixed(png_ptr, info_ptr, + png_fixed(png_ptr, white_x, "cHRM White X"), + png_fixed(png_ptr, white_y, "cHRM White Y"), + png_fixed(png_ptr, red_x, "cHRM Red X"), + png_fixed(png_ptr, red_y, "cHRM Red Y"), + png_fixed(png_ptr, green_x, "cHRM Green X"), + png_fixed(png_ptr, green_y, "cHRM Green Y"), + png_fixed(png_ptr, blue_x, "cHRM Blue X"), + png_fixed(png_ptr, blue_y, "cHRM Blue Y")); +} + +void PNGAPI +png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X, + double red_Y, double red_Z, double green_X, double green_Y, double green_Z, + double blue_X, double blue_Y, double blue_Z) +{ + png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, + png_fixed(png_ptr, red_X, "cHRM Red X"), + png_fixed(png_ptr, red_Y, "cHRM Red Y"), + png_fixed(png_ptr, red_Z, "cHRM Red Z"), + png_fixed(png_ptr, green_X, "cHRM Green X"), + png_fixed(png_ptr, green_Y, "cHRM Green Y"), + png_fixed(png_ptr, green_Z, "cHRM Green Z"), + png_fixed(png_ptr, blue_X, "cHRM Blue X"), + png_fixed(png_ptr, blue_Y, "cHRM Blue Y"), + png_fixed(png_ptr, blue_Z, "cHRM Blue Z")); +} +# endif /* FLOATING_POINT */ + +#endif /* cHRM */ + +#ifdef PNG_eXIf_SUPPORTED +void PNGAPI +png_set_eXIf(png_const_structrp png_ptr, png_inforp info_ptr, + png_bytep eXIf_buf) +{ + png_warning(png_ptr, "png_set_eXIf does not work; use png_set_eXIf_1"); + PNG_UNUSED(info_ptr) + PNG_UNUSED(eXIf_buf) +} + +void PNGAPI +png_set_eXIf_1(png_const_structrp png_ptr, png_inforp info_ptr, + png_uint_32 num_exif, png_bytep eXIf_buf) +{ + int i; + + png_debug1(1, "in %s storage function", "eXIf"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (info_ptr->exif) + { + png_free(png_ptr, info_ptr->exif); + info_ptr->exif = NULL; + } + + info_ptr->num_exif = num_exif; + + info_ptr->exif = png_voidcast(png_bytep, png_malloc_warn(png_ptr, + info_ptr->num_exif)); + + if (info_ptr->exif == NULL) + { + png_warning(png_ptr, "Insufficient memory for eXIf chunk data"); + return; + } + + info_ptr->free_me |= PNG_FREE_EXIF; + + for (i = 0; i < (int) info_ptr->num_exif; i++) + info_ptr->exif[i] = eXIf_buf[i]; + + info_ptr->valid |= PNG_INFO_eXIf; +} +#endif /* eXIf */ + +#ifdef PNG_gAMA_SUPPORTED +void PNGFAPI +png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr, + png_fixed_point file_gamma) +{ + png_debug1(1, "in %s storage function", "gAMA"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_colorspace_set_gamma(png_ptr, &info_ptr->colorspace, file_gamma); + png_colorspace_sync_info(png_ptr, info_ptr); +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_gAMA(png_const_structrp png_ptr, png_inforp info_ptr, double file_gamma) +{ + png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma, + "png_set_gAMA")); +} +# endif +#endif + +#ifdef PNG_hIST_SUPPORTED +void PNGAPI +png_set_hIST(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_uint_16p hist) +{ + int i; + + png_debug1(1, "in %s storage function", "hIST"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (info_ptr->num_palette == 0 || info_ptr->num_palette + > PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, + "Invalid palette size, hIST allocation skipped"); + + return; + } + + png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); + + /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in + * version 1.2.1 + */ + info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr, + PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16)))); + + if (info_ptr->hist == NULL) + { + png_warning(png_ptr, "Insufficient memory for hIST chunk data"); + + return; + } + + info_ptr->free_me |= PNG_FREE_HIST; + + for (i = 0; i < info_ptr->num_palette; i++) + info_ptr->hist[i] = hist[i]; + + info_ptr->valid |= PNG_INFO_hIST; +} +#endif + +void PNGAPI +png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type) +{ + png_debug1(1, "in %s storage function", "IHDR"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->width = width; + info_ptr->height = height; + info_ptr->bit_depth = (png_byte)bit_depth; + info_ptr->color_type = (png_byte)color_type; + info_ptr->compression_type = (png_byte)compression_type; + info_ptr->filter_type = (png_byte)filter_type; + info_ptr->interlace_type = (png_byte)interlace_type; + + png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, + info_ptr->compression_type, info_ptr->filter_type); + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + info_ptr->channels = 1; + + else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) + info_ptr->channels = 3; + + else + info_ptr->channels = 1; + + if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) + info_ptr->channels++; + + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); + + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); +} + +#ifdef PNG_oFFs_SUPPORTED +void PNGAPI +png_set_oFFs(png_const_structrp png_ptr, png_inforp info_ptr, + png_int_32 offset_x, png_int_32 offset_y, int unit_type) +{ + png_debug1(1, "in %s storage function", "oFFs"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_offset = offset_x; + info_ptr->y_offset = offset_y; + info_ptr->offset_unit_type = (png_byte)unit_type; + info_ptr->valid |= PNG_INFO_oFFs; +} +#endif + +#ifdef PNG_pCAL_SUPPORTED +void PNGAPI +png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, + int nparams, png_const_charp units, png_charpp params) +{ + size_t length; + int i; + + png_debug1(1, "in %s storage function", "pCAL"); + + if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL + || (nparams > 0 && params == NULL)) + return; + + length = strlen(purpose) + 1; + png_debug1(3, "allocating purpose for info (%lu bytes)", + (unsigned long)length); + + /* TODO: validate format of calibration name and unit name */ + + /* Check that the type matches the specification. */ + if (type < 0 || type > 3) + { + png_chunk_report(png_ptr, "Invalid pCAL equation type", + PNG_CHUNK_WRITE_ERROR); + return; + } + + if (nparams < 0 || nparams > 255) + { + png_chunk_report(png_ptr, "Invalid pCAL parameter count", + PNG_CHUNK_WRITE_ERROR); + return; + } + + /* Validate params[nparams] */ + for (i=0; ipcal_purpose = png_voidcast(png_charp, + png_malloc_warn(png_ptr, length)); + + if (info_ptr->pcal_purpose == NULL) + { + png_chunk_report(png_ptr, "Insufficient memory for pCAL purpose", + PNG_CHUNK_WRITE_ERROR); + return; + } + + memcpy(info_ptr->pcal_purpose, purpose, length); + + png_debug(3, "storing X0, X1, type, and nparams in info"); + info_ptr->pcal_X0 = X0; + info_ptr->pcal_X1 = X1; + info_ptr->pcal_type = (png_byte)type; + info_ptr->pcal_nparams = (png_byte)nparams; + + length = strlen(units) + 1; + png_debug1(3, "allocating units for info (%lu bytes)", + (unsigned long)length); + + info_ptr->pcal_units = png_voidcast(png_charp, + png_malloc_warn(png_ptr, length)); + + if (info_ptr->pcal_units == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL units"); + + return; + } + + memcpy(info_ptr->pcal_units, units, length); + + info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, + (size_t)(((unsigned int)nparams + 1) * (sizeof (png_charp))))); + + if (info_ptr->pcal_params == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL params"); + + return; + } + + memset(info_ptr->pcal_params, 0, ((unsigned int)nparams + 1) * + (sizeof (png_charp))); + + for (i = 0; i < nparams; i++) + { + length = strlen(params[i]) + 1; + png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, + (unsigned long)length); + + info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); + + if (info_ptr->pcal_params[i] == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL parameter"); + + return; + } + + memcpy(info_ptr->pcal_params[i], params[i], length); + } + + info_ptr->valid |= PNG_INFO_pCAL; + info_ptr->free_me |= PNG_FREE_PCAL; +} +#endif + +#ifdef PNG_sCAL_SUPPORTED +void PNGAPI +png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr, + int unit, png_const_charp swidth, png_const_charp sheight) +{ + size_t lengthw = 0, lengthh = 0; + + png_debug1(1, "in %s storage function", "sCAL"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Double check the unit (should never get here with an invalid + * unit unless this is an API call.) + */ + if (unit != 1 && unit != 2) + png_error(png_ptr, "Invalid sCAL unit"); + + if (swidth == NULL || (lengthw = strlen(swidth)) == 0 || + swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw)) + png_error(png_ptr, "Invalid sCAL width"); + + if (sheight == NULL || (lengthh = strlen(sheight)) == 0 || + sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh)) + png_error(png_ptr, "Invalid sCAL height"); + + info_ptr->scal_unit = (png_byte)unit; + + ++lengthw; + + png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw); + + info_ptr->scal_s_width = png_voidcast(png_charp, + png_malloc_warn(png_ptr, lengthw)); + + if (info_ptr->scal_s_width == NULL) + { + png_warning(png_ptr, "Memory allocation failed while processing sCAL"); + + return; + } + + memcpy(info_ptr->scal_s_width, swidth, lengthw); + + ++lengthh; + + png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh); + + info_ptr->scal_s_height = png_voidcast(png_charp, + png_malloc_warn(png_ptr, lengthh)); + + if (info_ptr->scal_s_height == NULL) + { + png_free (png_ptr, info_ptr->scal_s_width); + info_ptr->scal_s_width = NULL; + + png_warning(png_ptr, "Memory allocation failed while processing sCAL"); + + return; + } + + memcpy(info_ptr->scal_s_height, sheight, lengthh); + + info_ptr->valid |= PNG_INFO_sCAL; + info_ptr->free_me |= PNG_FREE_SCAL; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit, + double width, double height) +{ + png_debug1(1, "in %s storage function", "sCAL"); + + /* Check the arguments. */ + if (width <= 0) + png_warning(png_ptr, "Invalid sCAL width ignored"); + + else if (height <= 0) + png_warning(png_ptr, "Invalid sCAL height ignored"); + + else + { + /* Convert 'width' and 'height' to ASCII. */ + char swidth[PNG_sCAL_MAX_DIGITS+1]; + char sheight[PNG_sCAL_MAX_DIGITS+1]; + + png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width, + PNG_sCAL_PRECISION); + png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height, + PNG_sCAL_PRECISION); + + png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); + } +} +# endif + +# ifdef PNG_FIXED_POINT_SUPPORTED +void PNGAPI +png_set_sCAL_fixed(png_const_structrp png_ptr, png_inforp info_ptr, int unit, + png_fixed_point width, png_fixed_point height) +{ + png_debug1(1, "in %s storage function", "sCAL"); + + /* Check the arguments. */ + if (width <= 0) + png_warning(png_ptr, "Invalid sCAL width ignored"); + + else if (height <= 0) + png_warning(png_ptr, "Invalid sCAL height ignored"); + + else + { + /* Convert 'width' and 'height' to ASCII. */ + char swidth[PNG_sCAL_MAX_DIGITS+1]; + char sheight[PNG_sCAL_MAX_DIGITS+1]; + + png_ascii_from_fixed(png_ptr, swidth, (sizeof swidth), width); + png_ascii_from_fixed(png_ptr, sheight, (sizeof sheight), height); + + png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); + } +} +# endif +#endif + +#ifdef PNG_pHYs_SUPPORTED +void PNGAPI +png_set_pHYs(png_const_structrp png_ptr, png_inforp info_ptr, + png_uint_32 res_x, png_uint_32 res_y, int unit_type) +{ + png_debug1(1, "in %s storage function", "pHYs"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_pixels_per_unit = res_x; + info_ptr->y_pixels_per_unit = res_y; + info_ptr->phys_unit_type = (png_byte)unit_type; + info_ptr->valid |= PNG_INFO_pHYs; +} +#endif + +void PNGAPI +png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, + png_const_colorp palette, int num_palette) +{ + + png_uint_32 max_palette_length; + + png_debug1(1, "in %s storage function", "PLTE"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + max_palette_length = (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? + (1 << info_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; + + if (num_palette < 0 || num_palette > (int) max_palette_length) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Invalid palette length"); + + else + { + png_warning(png_ptr, "Invalid palette length"); + + return; + } + } + + if ((num_palette > 0 && palette == NULL) || + (num_palette == 0 +# ifdef PNG_MNG_FEATURES_SUPPORTED + && (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 +# endif + )) + { + png_error(png_ptr, "Invalid palette"); + } + + /* It may not actually be necessary to set png_ptr->palette here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + * + * 1.6.0: the above statement appears to be incorrect; something has to set + * the palette inside png_struct on read. + */ + png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); + + /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead + * of num_palette entries, in case of an invalid PNG file or incorrect + * call to png_set_PLTE() with too-large sample values. + */ + png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr, + PNG_MAX_PALETTE_LENGTH * (sizeof (png_color)))); + + if (num_palette > 0) + memcpy(png_ptr->palette, palette, (unsigned int)num_palette * + (sizeof (png_color))); + info_ptr->palette = png_ptr->palette; + info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; + + info_ptr->free_me |= PNG_FREE_PLTE; + + info_ptr->valid |= PNG_INFO_PLTE; +} + +#ifdef PNG_sBIT_SUPPORTED +void PNGAPI +png_set_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_color_8p sig_bit) +{ + png_debug1(1, "in %s storage function", "sBIT"); + + if (png_ptr == NULL || info_ptr == NULL || sig_bit == NULL) + return; + + info_ptr->sig_bit = *sig_bit; + info_ptr->valid |= PNG_INFO_sBIT; +} +#endif + +#ifdef PNG_sRGB_SUPPORTED +void PNGAPI +png_set_sRGB(png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent) +{ + png_debug1(1, "in %s storage function", "sRGB"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + (void)png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent); + png_colorspace_sync_info(png_ptr, info_ptr); +} + +void PNGAPI +png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, + int srgb_intent) +{ + png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, + srgb_intent) != 0) + { + /* This causes the gAMA and cHRM to be written too */ + info_ptr->colorspace.flags |= + PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; + } + + png_colorspace_sync_info(png_ptr, info_ptr); +} +#endif /* sRGB */ + + +#ifdef PNG_iCCP_SUPPORTED +void PNGAPI +png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_charp name, int compression_type, + png_const_bytep profile, png_uint_32 proflen) +{ + png_charp new_iccp_name; + png_bytep new_iccp_profile; + size_t length; + + png_debug1(1, "in %s storage function", "iCCP"); + + if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) + return; + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + png_app_error(png_ptr, "Invalid iCCP compression method"); + + /* Set the colorspace first because this validates the profile; do not + * override previously set app cHRM or gAMA here (because likely as not the + * application knows better than libpng what the correct values are.) Pass + * the info_ptr color_type field to png_colorspace_set_ICC because in the + * write case it has not yet been stored in png_ptr. + */ + { + int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name, + proflen, profile, info_ptr->color_type); + + png_colorspace_sync_info(png_ptr, info_ptr); + + /* Don't do any of the copying if the profile was bad, or inconsistent. */ + if (result == 0) + return; + + /* But do write the gAMA and cHRM chunks from the profile. */ + info_ptr->colorspace.flags |= + PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; + } + + length = strlen(name)+1; + new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length)); + + if (new_iccp_name == NULL) + { + png_benign_error(png_ptr, "Insufficient memory to process iCCP chunk"); + + return; + } + + memcpy(new_iccp_name, name, length); + new_iccp_profile = png_voidcast(png_bytep, + png_malloc_warn(png_ptr, proflen)); + + if (new_iccp_profile == NULL) + { + png_free(png_ptr, new_iccp_name); + png_benign_error(png_ptr, + "Insufficient memory to process iCCP profile"); + + return; + } + + memcpy(new_iccp_profile, profile, proflen); + + png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); + + info_ptr->iccp_proflen = proflen; + info_ptr->iccp_name = new_iccp_name; + info_ptr->iccp_profile = new_iccp_profile; + info_ptr->free_me |= PNG_FREE_ICCP; + info_ptr->valid |= PNG_INFO_iCCP; +} +#endif + +#ifdef PNG_TEXT_SUPPORTED +void PNGAPI +png_set_text(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_textp text_ptr, int num_text) +{ + int ret; + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); + + if (ret != 0) + png_error(png_ptr, "Insufficient memory to store text"); +} + +int /* PRIVATE */ +png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_textp text_ptr, int num_text) +{ + int i; + + png_debug1(1, "in %lx storage function", png_ptr == NULL ? 0xabadca11U : + (unsigned long)png_ptr->chunk_name); + + if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL) + return(0); + + /* Make sure we have enough space in the "text" array in info_struct + * to hold all of the incoming text_ptr objects. This compare can't overflow + * because max_text >= num_text (anyway, subtract of two positive integers + * can't overflow in any case.) + */ + if (num_text > info_ptr->max_text - info_ptr->num_text) + { + int old_num_text = info_ptr->num_text; + int max_text; + png_textp new_text = NULL; + + /* Calculate an appropriate max_text, checking for overflow. */ + max_text = old_num_text; + if (num_text <= INT_MAX - max_text) + { + max_text += num_text; + + /* Round up to a multiple of 8 */ + if (max_text < INT_MAX-8) + max_text = (max_text + 8) & ~0x7; + + else + max_text = INT_MAX; + + /* Now allocate a new array and copy the old members in; this does all + * the overflow checks. + */ + new_text = png_voidcast(png_textp,png_realloc_array(png_ptr, + info_ptr->text, old_num_text, max_text-old_num_text, + sizeof *new_text)); + } + + if (new_text == NULL) + { + png_chunk_report(png_ptr, "too many text chunks", + PNG_CHUNK_WRITE_ERROR); + + return 1; + } + + png_free(png_ptr, info_ptr->text); + + info_ptr->text = new_text; + info_ptr->free_me |= PNG_FREE_TEXT; + info_ptr->max_text = max_text; + /* num_text is adjusted below as the entries are copied in */ + + png_debug1(3, "allocated %d entries for info_ptr->text", max_text); + } + + for (i = 0; i < num_text; i++) + { + size_t text_length, key_len; + size_t lang_len, lang_key_len; + png_textp textp = &(info_ptr->text[info_ptr->num_text]); + + if (text_ptr[i].key == NULL) + continue; + + if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE || + text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST) + { + png_chunk_report(png_ptr, "text compression mode is out of range", + PNG_CHUNK_WRITE_ERROR); + continue; + } + + key_len = strlen(text_ptr[i].key); + + if (text_ptr[i].compression <= 0) + { + lang_len = 0; + lang_key_len = 0; + } + + else +# ifdef PNG_iTXt_SUPPORTED + { + /* Set iTXt data */ + + if (text_ptr[i].lang != NULL) + lang_len = strlen(text_ptr[i].lang); + + else + lang_len = 0; + + if (text_ptr[i].lang_key != NULL) + lang_key_len = strlen(text_ptr[i].lang_key); + + else + lang_key_len = 0; + } +# else /* iTXt */ + { + png_chunk_report(png_ptr, "iTXt chunk not supported", + PNG_CHUNK_WRITE_ERROR); + continue; + } +# endif + + if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') + { + text_length = 0; +# ifdef PNG_iTXt_SUPPORTED + if (text_ptr[i].compression > 0) + textp->compression = PNG_ITXT_COMPRESSION_NONE; + + else +# endif + textp->compression = PNG_TEXT_COMPRESSION_NONE; + } + + else + { + text_length = strlen(text_ptr[i].text); + textp->compression = text_ptr[i].compression; + } + + textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr, + key_len + text_length + lang_len + lang_key_len + 4)); + + if (textp->key == NULL) + { + png_chunk_report(png_ptr, "text chunk: out of memory", + PNG_CHUNK_WRITE_ERROR); + + return 1; + } + + png_debug2(2, "Allocated %lu bytes at %p in png_set_text", + (unsigned long)(png_uint_32) + (key_len + lang_len + lang_key_len + text_length + 4), + textp->key); + + memcpy(textp->key, text_ptr[i].key, key_len); + *(textp->key + key_len) = '\0'; + + if (text_ptr[i].compression > 0) + { + textp->lang = textp->key + key_len + 1; + memcpy(textp->lang, text_ptr[i].lang, lang_len); + *(textp->lang + lang_len) = '\0'; + textp->lang_key = textp->lang + lang_len + 1; + memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); + *(textp->lang_key + lang_key_len) = '\0'; + textp->text = textp->lang_key + lang_key_len + 1; + } + + else + { + textp->lang=NULL; + textp->lang_key=NULL; + textp->text = textp->key + key_len + 1; + } + + if (text_length != 0) + memcpy(textp->text, text_ptr[i].text, text_length); + + *(textp->text + text_length) = '\0'; + +# ifdef PNG_iTXt_SUPPORTED + if (textp->compression > 0) + { + textp->text_length = 0; + textp->itxt_length = text_length; + } + + else +# endif + { + textp->text_length = text_length; + textp->itxt_length = 0; + } + + info_ptr->num_text++; + png_debug1(3, "transferred text chunk %d", info_ptr->num_text); + } + + return(0); +} +#endif + +#ifdef PNG_tIME_SUPPORTED +void PNGAPI +png_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr, + png_const_timep mod_time) +{ + png_debug1(1, "in %s storage function", "tIME"); + + if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL || + (png_ptr->mode & PNG_WROTE_tIME) != 0) + return; + + if (mod_time->month == 0 || mod_time->month > 12 || + mod_time->day == 0 || mod_time->day > 31 || + mod_time->hour > 23 || mod_time->minute > 59 || + mod_time->second > 60) + { + png_warning(png_ptr, "Ignoring invalid time value"); + + return; + } + + info_ptr->mod_time = *mod_time; + info_ptr->valid |= PNG_INFO_tIME; +} +#endif + +#ifdef PNG_tRNS_SUPPORTED +void PNGAPI +png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr, + png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color) +{ + png_debug1(1, "in %s storage function", "tRNS"); + + if (png_ptr == NULL || info_ptr == NULL) + + return; + + if (trans_alpha != NULL) + { + /* It may not actually be necessary to set png_ptr->trans_alpha here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + * + * 1.6.0: The above statement is incorrect; png_handle_tRNS effectively + * relies on png_set_tRNS storing the information in png_struct + * (otherwise it won't be there for the code in pngrtran.c). + */ + + png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); + + if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) + { + /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ + info_ptr->trans_alpha = png_voidcast(png_bytep, + png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH)); + memcpy(info_ptr->trans_alpha, trans_alpha, (size_t)num_trans); + } + png_ptr->trans_alpha = info_ptr->trans_alpha; + } + + if (trans_color != NULL) + { +#ifdef PNG_WARNINGS_SUPPORTED + if (info_ptr->bit_depth < 16) + { + int sample_max = (1 << info_ptr->bit_depth) - 1; + + if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && + trans_color->gray > sample_max) || + (info_ptr->color_type == PNG_COLOR_TYPE_RGB && + (trans_color->red > sample_max || + trans_color->green > sample_max || + trans_color->blue > sample_max))) + png_warning(png_ptr, + "tRNS chunk has out-of-range samples for bit_depth"); + } +#endif + + info_ptr->trans_color = *trans_color; + + if (num_trans == 0) + num_trans = 1; + } + + info_ptr->num_trans = (png_uint_16)num_trans; + + if (num_trans != 0) + { + info_ptr->valid |= PNG_INFO_tRNS; + info_ptr->free_me |= PNG_FREE_TRNS; + } +} +#endif + +#ifdef PNG_sPLT_SUPPORTED +void PNGAPI +png_set_sPLT(png_const_structrp png_ptr, + png_inforp info_ptr, png_const_sPLT_tp entries, int nentries) +/* + * entries - array of png_sPLT_t structures + * to be added to the list of palettes + * in the info structure. + * + * nentries - number of palette structures to be + * added. + */ +{ + png_sPLT_tp np; + + if (png_ptr == NULL || info_ptr == NULL || nentries <= 0 || entries == NULL) + return; + + /* Use the internal realloc function, which checks for all the possible + * overflows. Notice that the parameters are (int) and (size_t) + */ + np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr, + info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries, + sizeof *np)); + + if (np == NULL) + { + /* Out of memory or too many chunks */ + png_chunk_report(png_ptr, "too many sPLT chunks", PNG_CHUNK_WRITE_ERROR); + + return; + } + + png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes = np; + info_ptr->free_me |= PNG_FREE_SPLT; + + np += info_ptr->splt_palettes_num; + + do + { + size_t length; + + /* Skip invalid input entries */ + if (entries->name == NULL || entries->entries == NULL) + { + /* png_handle_sPLT doesn't do this, so this is an app error */ + png_app_error(png_ptr, "png_set_sPLT: invalid sPLT"); + /* Just skip the invalid entry */ + continue; + } + + np->depth = entries->depth; + + /* In the event of out-of-memory just return - there's no point keeping + * on trying to add sPLT chunks. + */ + length = strlen(entries->name) + 1; + np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length)); + + if (np->name == NULL) + break; + + memcpy(np->name, entries->name, length); + + /* IMPORTANT: we have memory now that won't get freed if something else + * goes wrong; this code must free it. png_malloc_array produces no + * warnings; use a png_chunk_report (below) if there is an error. + */ + np->entries = png_voidcast(png_sPLT_entryp, png_malloc_array(png_ptr, + entries->nentries, sizeof (png_sPLT_entry))); + + if (np->entries == NULL) + { + png_free(png_ptr, np->name); + np->name = NULL; + break; + } + + np->nentries = entries->nentries; + /* This multiply can't overflow because png_malloc_array has already + * checked it when doing the allocation. + */ + memcpy(np->entries, entries->entries, + (unsigned int)entries->nentries * sizeof (png_sPLT_entry)); + + /* Note that 'continue' skips the advance of the out pointer and out + * count, so an invalid entry is not added. + */ + info_ptr->valid |= PNG_INFO_sPLT; + ++(info_ptr->splt_palettes_num); + ++np; + ++entries; + } + while (--nentries); + + if (nentries > 0) + png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR); +} +#endif /* sPLT */ + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +static png_byte +check_location(png_const_structrp png_ptr, int location) +{ + location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT); + + /* New in 1.6.0; copy the location and check it. This is an API + * change; previously the app had to use the + * png_set_unknown_chunk_location API below for each chunk. + */ + if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0) + { + /* Write struct, so unknown chunks come from the app */ + png_app_warning(png_ptr, + "png_set_unknown_chunks now expects a valid location"); + /* Use the old behavior */ + location = (png_byte)(png_ptr->mode & + (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)); + } + + /* This need not be an internal error - if the app calls + * png_set_unknown_chunks on a read pointer it must get the location right. + */ + if (location == 0) + png_error(png_ptr, "invalid location in png_set_unknown_chunks"); + + /* Now reduce the location to the top-most set bit by removing each least + * significant bit in turn. + */ + while (location != (location & -location)) + location &= ~(location & -location); + + /* The cast is safe because 'location' is a bit mask and only the low four + * bits are significant. + */ + return (png_byte)location; +} + +void PNGAPI +png_set_unknown_chunks(png_const_structrp png_ptr, + png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns) +{ + png_unknown_chunkp np; + + if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 || + unknowns == NULL) + return; + + /* Check for the failure cases where support has been disabled at compile + * time. This code is hardly ever compiled - it's here because + * STORE_UNKNOWN_CHUNKS is set by both read and write code (compiling in this + * code) but may be meaningless if the read or write handling of unknown + * chunks is not compiled in. + */ +# if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \ + defined(PNG_READ_SUPPORTED) + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) + { + png_app_error(png_ptr, "no unknown chunk support on read"); + + return; + } +# endif +# if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \ + defined(PNG_WRITE_SUPPORTED) + if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) + { + png_app_error(png_ptr, "no unknown chunk support on write"); + + return; + } +# endif + + /* Prior to 1.6.0 this code used png_malloc_warn; however, this meant that + * unknown critical chunks could be lost with just a warning resulting in + * undefined behavior. Now png_chunk_report is used to provide behavior + * appropriate to read or write. + */ + np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr, + info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns, + sizeof *np)); + + if (np == NULL) + { + png_chunk_report(png_ptr, "too many unknown chunks", + PNG_CHUNK_WRITE_ERROR); + + return; + } + + png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks = np; /* safe because it is initialized */ + info_ptr->free_me |= PNG_FREE_UNKN; + + np += info_ptr->unknown_chunks_num; + + /* Increment unknown_chunks_num each time round the loop to protect the + * just-allocated chunk data. + */ + for (; num_unknowns > 0; --num_unknowns, ++unknowns) + { + memcpy(np->name, unknowns->name, (sizeof np->name)); + np->name[(sizeof np->name)-1] = '\0'; + np->location = check_location(png_ptr, unknowns->location); + + if (unknowns->size == 0) + { + np->data = NULL; + np->size = 0; + } + + else + { + np->data = png_voidcast(png_bytep, + png_malloc_base(png_ptr, unknowns->size)); + + if (np->data == NULL) + { + png_chunk_report(png_ptr, "unknown chunk: out of memory", + PNG_CHUNK_WRITE_ERROR); + /* But just skip storing the unknown chunk */ + continue; + } + + memcpy(np->data, unknowns->data, unknowns->size); + np->size = unknowns->size; + } + + /* These increments are skipped on out-of-memory for the data - the + * unknown chunk entry gets overwritten if the png_chunk_report returns. + * This is correct in the read case (the chunk is just dropped.) + */ + ++np; + ++(info_ptr->unknown_chunks_num); + } +} + +void PNGAPI +png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr, + int chunk, int location) +{ + /* This API is pretty pointless in 1.6.0 because the location can be set + * before the call to png_set_unknown_chunks. + * + * TODO: add a png_app_warning in 1.7 + */ + if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && + chunk < info_ptr->unknown_chunks_num) + { + if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0) + { + png_app_error(png_ptr, "invalid unknown chunk location"); + /* Fake out the pre 1.6.0 behavior: */ + if (((unsigned int)location & PNG_HAVE_IDAT) != 0) /* undocumented! */ + location = PNG_AFTER_IDAT; + + else + location = PNG_HAVE_IHDR; /* also undocumented */ + } + + info_ptr->unknown_chunks[chunk].location = + check_location(png_ptr, location); + } +} +#endif /* STORE_UNKNOWN_CHUNKS */ + +#ifdef PNG_MNG_FEATURES_SUPPORTED +png_uint_32 PNGAPI +png_permit_mng_features (png_structrp png_ptr, png_uint_32 mng_features) +{ + png_debug(1, "in png_permit_mng_features"); + + if (png_ptr == NULL) + return 0; + + png_ptr->mng_features_permitted = mng_features & PNG_ALL_MNG_FEATURES; + + return png_ptr->mng_features_permitted; +} +#endif + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +static unsigned int +add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep) +{ + unsigned int i; + + /* Utility function: update the 'keep' state of a chunk if it is already in + * the list, otherwise add it to the list. + */ + for (i=0; i= PNG_HANDLE_CHUNK_LAST) + { + png_app_error(png_ptr, "png_set_keep_unknown_chunks: invalid keep"); + + return; + } + + if (num_chunks_in <= 0) + { + png_ptr->unknown_default = keep; + + /* '0' means just set the flags, so stop here */ + if (num_chunks_in == 0) + return; + } + + if (num_chunks_in < 0) + { + /* Ignore all unknown chunks and all chunks recognized by + * libpng except for IHDR, PLTE, tRNS, IDAT, and IEND + */ + static const png_byte chunks_to_ignore[] = { + 98, 75, 71, 68, '\0', /* bKGD */ + 99, 72, 82, 77, '\0', /* cHRM */ + 101, 88, 73, 102, '\0', /* eXIf */ + 103, 65, 77, 65, '\0', /* gAMA */ + 104, 73, 83, 84, '\0', /* hIST */ + 105, 67, 67, 80, '\0', /* iCCP */ + 105, 84, 88, 116, '\0', /* iTXt */ + 111, 70, 70, 115, '\0', /* oFFs */ + 112, 67, 65, 76, '\0', /* pCAL */ + 112, 72, 89, 115, '\0', /* pHYs */ + 115, 66, 73, 84, '\0', /* sBIT */ + 115, 67, 65, 76, '\0', /* sCAL */ + 115, 80, 76, 84, '\0', /* sPLT */ + 115, 84, 69, 82, '\0', /* sTER */ + 115, 82, 71, 66, '\0', /* sRGB */ + 116, 69, 88, 116, '\0', /* tEXt */ + 116, 73, 77, 69, '\0', /* tIME */ + 122, 84, 88, 116, '\0' /* zTXt */ + }; + + chunk_list = chunks_to_ignore; + num_chunks = (unsigned int)/*SAFE*/(sizeof chunks_to_ignore)/5U; + } + + else /* num_chunks_in > 0 */ + { + if (chunk_list == NULL) + { + /* Prior to 1.6.0 this was silently ignored, now it is an app_error + * which can be switched off. + */ + png_app_error(png_ptr, "png_set_keep_unknown_chunks: no chunk list"); + + return; + } + + num_chunks = (unsigned int)num_chunks_in; + } + + old_num_chunks = png_ptr->num_chunk_list; + if (png_ptr->chunk_list == NULL) + old_num_chunks = 0; + + /* Since num_chunks is always restricted to UINT_MAX/5 this can't overflow. + */ + if (num_chunks + old_num_chunks > UINT_MAX/5) + { + png_app_error(png_ptr, "png_set_keep_unknown_chunks: too many chunks"); + + return; + } + + /* If these chunks are being reset to the default then no more memory is + * required because add_one_chunk above doesn't extend the list if the 'keep' + * parameter is the default. + */ + if (keep != 0) + { + new_list = png_voidcast(png_bytep, png_malloc(png_ptr, + 5 * (num_chunks + old_num_chunks))); + + if (old_num_chunks > 0) + memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); + } + + else if (old_num_chunks > 0) + new_list = png_ptr->chunk_list; + + else + new_list = NULL; + + /* Add the new chunks together with each one's handling code. If the chunk + * already exists the code is updated, otherwise the chunk is added to the + * end. (In libpng 1.6.0 order no longer matters because this code enforces + * the earlier convention that the last setting is the one that is used.) + */ + if (new_list != NULL) + { + png_const_bytep inlist; + png_bytep outlist; + unsigned int i; + + for (i=0; ichunk_list != new_list) + png_free(png_ptr, new_list); + + new_list = NULL; + } + } + + else + num_chunks = 0; + + png_ptr->num_chunk_list = num_chunks; + + if (png_ptr->chunk_list != new_list) + { + if (png_ptr->chunk_list != NULL) + png_free(png_ptr, png_ptr->chunk_list); + + png_ptr->chunk_list = new_list; + } +} +#endif + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED +void PNGAPI +png_set_read_user_chunk_fn(png_structrp png_ptr, png_voidp user_chunk_ptr, + png_user_chunk_ptr read_user_chunk_fn) +{ + png_debug(1, "in png_set_read_user_chunk_fn"); + + if (png_ptr == NULL) + return; + + png_ptr->read_user_chunk_fn = read_user_chunk_fn; + png_ptr->user_chunk_ptr = user_chunk_ptr; +} +#endif + +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr, + png_bytepp row_pointers) +{ + png_debug1(1, "in %s storage function", "rows"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (info_ptr->row_pointers != NULL && + (info_ptr->row_pointers != row_pointers)) + png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); + + info_ptr->row_pointers = row_pointers; + + if (row_pointers != NULL) + info_ptr->valid |= PNG_INFO_IDAT; +} +#endif + +void PNGAPI +png_set_compression_buffer_size(png_structrp png_ptr, size_t size) +{ + if (png_ptr == NULL) + return; + + if (size == 0 || size > PNG_UINT_31_MAX) + png_error(png_ptr, "invalid compression buffer size"); + +# ifdef PNG_SEQUENTIAL_READ_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) + { + png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */ + return; + } +# endif + +# ifdef PNG_WRITE_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) + { + if (png_ptr->zowner != 0) + { + png_warning(png_ptr, + "Compression buffer size cannot be changed because it is in use"); + + return; + } + +#ifndef __COVERITY__ + /* Some compilers complain that this is always false. However, it + * can be true when integer overflow happens. + */ + if (size > ZLIB_IO_MAX) + { + png_warning(png_ptr, + "Compression buffer size limited to system maximum"); + size = ZLIB_IO_MAX; /* must fit */ + } +#endif + + if (size < 6) + { + /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH + * if this is permitted. + */ + png_warning(png_ptr, + "Compression buffer size cannot be reduced below 6"); + + return; + } + + if (png_ptr->zbuffer_size != size) + { + png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list); + png_ptr->zbuffer_size = (uInt)size; + } + } +# endif +} + +void PNGAPI +png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask) +{ + if (png_ptr != NULL && info_ptr != NULL) + info_ptr->valid &= (unsigned int)(~mask); +} + + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +/* This function was added to libpng 1.2.6 */ +void PNGAPI +png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max, + png_uint_32 user_height_max) +{ + /* Images with dimensions larger than these limits will be + * rejected by png_set_IHDR(). To accept any PNG datastream + * regardless of dimensions, set both limits to 0x7fffffff. + */ + if (png_ptr == NULL) + return; + + png_ptr->user_width_max = user_width_max; + png_ptr->user_height_max = user_height_max; +} + +/* This function was added to libpng 1.4.0 */ +void PNGAPI +png_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max) +{ + if (png_ptr != NULL) + png_ptr->user_chunk_cache_max = user_chunk_cache_max; +} + +/* This function was added to libpng 1.4.1 */ +void PNGAPI +png_set_chunk_malloc_max (png_structrp png_ptr, + png_alloc_size_t user_chunk_malloc_max) +{ + if (png_ptr != NULL) + png_ptr->user_chunk_malloc_max = user_chunk_malloc_max; +} +#endif /* ?SET_USER_LIMITS */ + + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_set_benign_errors(png_structrp png_ptr, int allowed) +{ + png_debug(1, "in png_set_benign_errors"); + + /* If allowed is 1, png_benign_error() is treated as a warning. + * + * If allowed is 0, png_benign_error() is treated as an error (which + * is the default behavior if png_set_benign_errors() is not called). + */ + + if (allowed != 0) + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN | + PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN; + + else + png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN | + PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN); +} +#endif /* BENIGN_ERRORS */ + +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Whether to report invalid palette index; added at libng-1.5.10. + * It is possible for an indexed (color-type==3) PNG file to contain + * pixels with invalid (out-of-range) indexes if the PLTE chunk has + * fewer entries than the image's bit-depth would allow. We recover + * from this gracefully by filling any incomplete palette with zeros + * (opaque black). By default, when this occurs libpng will issue + * a benign error. This API can be used to override that behavior. + */ +void PNGAPI +png_set_check_for_invalid_index(png_structrp png_ptr, int allowed) +{ + png_debug(1, "in png_set_check_for_invalid_index"); + + if (allowed > 0) + png_ptr->num_palette_max = 0; + + else + png_ptr->num_palette_max = -1; +} +#endif + +#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) || \ + defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) +/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, + * and if invalid, correct the keyword rather than discarding the entire + * chunk. The PNG 1.0 specification requires keywords 1-79 characters in + * length, forbids leading or trailing whitespace, multiple internal spaces, + * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. + * + * The 'new_key' buffer must be 80 characters in size (for the keyword plus a + * trailing '\0'). If this routine returns 0 then there was no keyword, or a + * valid one could not be generated, and the caller must png_error. + */ +png_uint_32 /* PRIVATE */ +png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key) +{ +#ifdef PNG_WARNINGS_SUPPORTED + png_const_charp orig_key = key; +#endif + png_uint_32 key_len = 0; + int bad_character = 0; + int space = 1; + + png_debug(1, "in png_check_keyword"); + + if (key == NULL) + { + *new_key = 0; + return 0; + } + + while (*key && key_len < 79) + { + png_byte ch = (png_byte)*key++; + + if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/)) + { + *new_key++ = ch; ++key_len; space = 0; + } + + else if (space == 0) + { + /* A space or an invalid character when one wasn't seen immediately + * before; output just a space. + */ + *new_key++ = 32; ++key_len; space = 1; + + /* If the character was not a space then it is invalid. */ + if (ch != 32) + bad_character = ch; + } + + else if (bad_character == 0) + bad_character = ch; /* just skip it, record the first error */ + } + + if (key_len > 0 && space != 0) /* trailing space */ + { + --key_len; --new_key; + if (bad_character == 0) + bad_character = 32; + } + + /* Terminate the keyword */ + *new_key = 0; + + if (key_len == 0) + return 0; + +#ifdef PNG_WARNINGS_SUPPORTED + /* Try to only output one warning per keyword: */ + if (*key != 0) /* keyword too long */ + png_warning(png_ptr, "keyword truncated"); + + else if (bad_character != 0) + { + PNG_WARNING_PARAMETERS(p) + + png_warning_parameter(p, 1, orig_key); + png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character); + + png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'"); + } +#else /* !WARNINGS */ + PNG_UNUSED(png_ptr) +#endif /* !WARNINGS */ + + return key_len; +} +#endif /* TEXT || pCAL || iCCP || sPLT */ +#endif /* READ || WRITE */ diff --git a/extern/libpng/pngstruct.h b/extern/libpng/pngstruct.h new file mode 100644 index 000000000..8bdc7ce46 --- /dev/null +++ b/extern/libpng/pngstruct.h @@ -0,0 +1,489 @@ + +/* pngstruct.h - header file for PNG reference library + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* The structure that holds the information to read and write PNG files. + * The only people who need to care about what is inside of this are the + * people who will be modifying the library for their own special needs. + * It should NOT be accessed directly by an application. + */ + +#ifndef PNGSTRUCT_H +#define PNGSTRUCT_H +/* zlib.h defines the structure z_stream, an instance of which is included + * in this structure and is required for decompressing the LZ compressed + * data in PNG files. + */ +#ifndef ZLIB_CONST + /* We must ensure that zlib uses 'const' in declarations. */ +# define ZLIB_CONST +#endif +#include "zlib.h" +#ifdef const + /* zlib.h sometimes #defines const to nothing, undo this. */ +# undef const +#endif + +/* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility + * with older builds. + */ +#if ZLIB_VERNUM < 0x1260 +# define PNGZ_MSG_CAST(s) png_constcast(char*,s) +# define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b) +#else +# define PNGZ_MSG_CAST(s) (s) +# define PNGZ_INPUT_CAST(b) (b) +#endif + +/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib + * can handle at once. This type need be no larger than 16 bits (so maximum of + * 65535), this define allows us to discover how big it is, but limited by the + * maximum for size_t. The value can be overridden in a library build + * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably + * lower value (e.g. 255 works). A lower value may help memory usage (slightly) + * and may even improve performance on some systems (and degrade it on others.) + */ +#ifndef ZLIB_IO_MAX +# define ZLIB_IO_MAX ((uInt)-1) +#endif + +#ifdef PNG_WRITE_SUPPORTED +/* The type of a compression buffer list used by the write code. */ +typedef struct png_compression_buffer +{ + struct png_compression_buffer *next; + png_byte output[1]; /* actually zbuf_size */ +} png_compression_buffer, *png_compression_bufferp; + +#define PNG_COMPRESSION_BUFFER_SIZE(pp)\ + (offsetof(png_compression_buffer, output) + (pp)->zbuffer_size) +#endif + +/* Colorspace support; structures used in png_struct, png_info and in internal + * functions to hold and communicate information about the color space. + * + * PNG_COLORSPACE_SUPPORTED is only required if the application will perform + * colorspace corrections, otherwise all the colorspace information can be + * skipped and the size of libpng can be reduced (significantly) by compiling + * out the colorspace support. + */ +#ifdef PNG_COLORSPACE_SUPPORTED +/* The chromaticities of the red, green and blue colorants and the chromaticity + * of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)). + */ +typedef struct png_xy +{ + png_fixed_point redx, redy; + png_fixed_point greenx, greeny; + png_fixed_point bluex, bluey; + png_fixed_point whitex, whitey; +} png_xy; + +/* The same data as above but encoded as CIE XYZ values. When this data comes + * from chromaticities the sum of the Y values is assumed to be 1.0 + */ +typedef struct png_XYZ +{ + png_fixed_point red_X, red_Y, red_Z; + png_fixed_point green_X, green_Y, green_Z; + png_fixed_point blue_X, blue_Y, blue_Z; +} png_XYZ; +#endif /* COLORSPACE */ + +#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) +/* A colorspace is all the above plus, potentially, profile information; + * however at present libpng does not use the profile internally so it is only + * stored in the png_info struct (if iCCP is supported.) The rendering intent + * is retained here and is checked. + * + * The file gamma encoding information is also stored here and gamma correction + * is done by libpng, whereas color correction must currently be done by the + * application. + */ +typedef struct png_colorspace +{ +#ifdef PNG_GAMMA_SUPPORTED + png_fixed_point gamma; /* File gamma */ +#endif + +#ifdef PNG_COLORSPACE_SUPPORTED + png_xy end_points_xy; /* End points as chromaticities */ + png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */ + png_uint_16 rendering_intent; /* Rendering intent of a profile */ +#endif + + /* Flags are always defined to simplify the code. */ + png_uint_16 flags; /* As defined below */ +} png_colorspace, * PNG_RESTRICT png_colorspacerp; + +typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp; + +/* General flags for the 'flags' field */ +#define PNG_COLORSPACE_HAVE_GAMMA 0x0001 +#define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002 +#define PNG_COLORSPACE_HAVE_INTENT 0x0004 +#define PNG_COLORSPACE_FROM_gAMA 0x0008 +#define PNG_COLORSPACE_FROM_cHRM 0x0010 +#define PNG_COLORSPACE_FROM_sRGB 0x0020 +#define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040 +#define PNG_COLORSPACE_MATCHES_sRGB 0x0080 /* exact match on profile */ +#define PNG_COLORSPACE_INVALID 0x8000 +#define PNG_COLORSPACE_CANCEL(flags) (0xffff ^ (flags)) +#endif /* COLORSPACE || GAMMA */ + +struct png_struct_def +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf jmp_buf_local; /* New name in 1.6.0 for jmp_buf in png_struct */ + png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */ + jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */ + size_t jmp_buf_size; /* size of the above, if allocated */ +#endif + png_error_ptr error_fn; /* function for printing errors and aborting */ +#ifdef PNG_WARNINGS_SUPPORTED + png_error_ptr warning_fn; /* function for printing warnings */ +#endif + png_voidp error_ptr; /* user supplied struct for error functions */ + png_rw_ptr write_data_fn; /* function for writing output data */ + png_rw_ptr read_data_fn; /* function for reading input data */ + png_voidp io_ptr; /* ptr to application struct for I/O functions */ + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + png_user_transform_ptr read_user_transform_fn; /* user read transform */ +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + png_user_transform_ptr write_user_transform_fn; /* user write transform */ +#endif + +/* These were added in libpng-1.0.2 */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) + png_voidp user_transform_ptr; /* user supplied struct for user transform */ + png_byte user_transform_depth; /* bit depth of user transformed pixels */ + png_byte user_transform_channels; /* channels in user transformed pixels */ +#endif +#endif + + png_uint_32 mode; /* tells us where we are in the PNG file */ + png_uint_32 flags; /* flags indicating various things to libpng */ + png_uint_32 transformations; /* which transformations to perform */ + + png_uint_32 zowner; /* ID (chunk type) of zstream owner, 0 if none */ + z_stream zstream; /* decompression structure */ + +#ifdef PNG_WRITE_SUPPORTED + png_compression_bufferp zbuffer_list; /* Created on demand during write */ + uInt zbuffer_size; /* size of the actual buffer */ + + int zlib_level; /* holds zlib compression level */ + int zlib_method; /* holds zlib compression method */ + int zlib_window_bits; /* holds zlib compression window bits */ + int zlib_mem_level; /* holds zlib compression memory level */ + int zlib_strategy; /* holds zlib compression strategy */ +#endif +/* Added at libpng 1.5.4 */ +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED + int zlib_text_level; /* holds zlib compression level */ + int zlib_text_method; /* holds zlib compression method */ + int zlib_text_window_bits; /* holds zlib compression window bits */ + int zlib_text_mem_level; /* holds zlib compression memory level */ + int zlib_text_strategy; /* holds zlib compression strategy */ +#endif +/* End of material added at libpng 1.5.4 */ +/* Added at libpng 1.6.0 */ +#ifdef PNG_WRITE_SUPPORTED + int zlib_set_level; /* Actual values set into the zstream on write */ + int zlib_set_method; + int zlib_set_window_bits; + int zlib_set_mem_level; + int zlib_set_strategy; +#endif + + png_uint_32 width; /* width of image in pixels */ + png_uint_32 height; /* height of image in pixels */ + png_uint_32 num_rows; /* number of rows in current pass */ + png_uint_32 usr_width; /* width of row at start of write */ + size_t rowbytes; /* size of row in bytes */ + png_uint_32 iwidth; /* width of current interlaced row in pixels */ + png_uint_32 row_number; /* current row in interlace pass */ + png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */ + png_bytep prev_row; /* buffer to save previous (unfiltered) row. + * While reading this is a pointer into + * big_prev_row; while writing it is separately + * allocated if needed. + */ + png_bytep row_buf; /* buffer to save current (unfiltered) row. + * While reading, this is a pointer into + * big_row_buf; while writing it is separately + * allocated. + */ +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_bytep try_row; /* buffer to save trial row when filtering */ + png_bytep tst_row; /* buffer to save best trial row when filtering */ +#endif + size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */ + + png_uint_32 idat_size; /* current IDAT size for read */ + png_uint_32 crc; /* current chunk CRC value */ + png_colorp palette; /* palette from the input file */ + png_uint_16 num_palette; /* number of color entries in palette */ + +/* Added at libpng-1.5.10 */ +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED + int num_palette_max; /* maximum palette index found in IDAT */ +#endif + + png_uint_16 num_trans; /* number of transparency values */ + png_byte compression; /* file compression type (always 0) */ + png_byte filter; /* file filter type (always 0) */ + png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ + png_byte pass; /* current interlace pass (0 - 6) */ + png_byte do_filter; /* row filter flags (see PNG_FILTER_ in png.h ) */ + png_byte color_type; /* color type of file */ + png_byte bit_depth; /* bit depth of file */ + png_byte usr_bit_depth; /* bit depth of users row: write only */ + png_byte pixel_depth; /* number of bits per pixel */ + png_byte channels; /* number of channels in file */ +#ifdef PNG_WRITE_SUPPORTED + png_byte usr_channels; /* channels at start of write: write only */ +#endif + png_byte sig_bytes; /* magic bytes read/written from start of file */ + png_byte maximum_pixel_depth; + /* pixel depth used for the row buffers */ + png_byte transformed_pixel_depth; + /* pixel depth after read/write transforms */ +#if ZLIB_VERNUM >= 0x1240 + png_byte zstream_start; /* at start of an input zlib stream */ +#endif /* Zlib >= 1.2.4 */ +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) + png_uint_16 filler; /* filler bytes for pixel expansion */ +#endif + +#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) + png_byte background_gamma_type; + png_fixed_point background_gamma; + png_color_16 background; /* background color in screen gamma space */ +#ifdef PNG_READ_GAMMA_SUPPORTED + png_color_16 background_1; /* background normalized to gamma 1.0 */ +#endif +#endif /* bKGD */ + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_flush_ptr output_flush_fn; /* Function for flushing output */ + png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */ + png_uint_32 flush_rows; /* number of rows written since last flush */ +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */ + png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */ + + png_bytep gamma_table; /* gamma table for 8-bit depth files */ + png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + png_bytep gamma_from_1; /* converts from 1.0 to screen */ + png_bytep gamma_to_1; /* converts from file to 1.0 */ + png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */ + png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) + png_color_8 sig_bit; /* significant bits in each available channel */ +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) + png_color_8 shift; /* shift for significant bit transformation */ +#endif + +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ + || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + png_bytep trans_alpha; /* alpha values for paletted files */ + png_color_16 trans_color; /* transparent color for non-paletted files */ +#endif + + png_read_status_ptr read_row_fn; /* called after each row is decoded */ + png_write_status_ptr write_row_fn; /* called after each row is encoded */ +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_progressive_info_ptr info_fn; /* called after header data fully read */ + png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */ + png_progressive_end_ptr end_fn; /* called after image is complete */ + png_bytep save_buffer_ptr; /* current location in save_buffer */ + png_bytep save_buffer; /* buffer for previously read data */ + png_bytep current_buffer_ptr; /* current location in current_buffer */ + png_bytep current_buffer; /* buffer for recently used data */ + png_uint_32 push_length; /* size of current input chunk */ + png_uint_32 skip_length; /* bytes to skip in input data */ + size_t save_buffer_size; /* amount of data now in save_buffer */ + size_t save_buffer_max; /* total size of save_buffer */ + size_t buffer_size; /* total amount of available input data */ + size_t current_buffer_size; /* amount of data now in current_buffer */ + int process_mode; /* what push library is currently doing */ + int cur_palette; /* current push library palette index */ + +#endif /* PROGRESSIVE_READ */ + +#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) +/* For the Borland special 64K segment handler */ + png_bytepp offset_table_ptr; + png_bytep offset_table; + png_uint_16 offset_table_number; + png_uint_16 offset_table_count; + png_uint_16 offset_table_count_free; +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + png_bytep palette_lookup; /* lookup table for quantizing */ + png_bytep quantize_index; /* index translation for palette files */ +#endif + +/* Options */ +#ifdef PNG_SET_OPTION_SUPPORTED + png_uint_32 options; /* On/off state (up to 16 options) */ +#endif + +#if PNG_LIBPNG_VER < 10700 +/* To do: remove this from libpng-1.7 */ +#ifdef PNG_TIME_RFC1123_SUPPORTED + char time_buffer[29]; /* String to hold RFC 1123 time text */ +#endif +#endif + +/* New members added in libpng-1.0.6 */ + + png_uint_32 free_me; /* flags items libpng is responsible for freeing */ + +#ifdef PNG_USER_CHUNKS_SUPPORTED + png_voidp user_chunk_ptr; +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ +#endif +#endif + +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + int unknown_default; /* As PNG_HANDLE_* */ + unsigned int num_chunk_list; /* Number of entries in the list */ + png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name + * followed by a PNG_HANDLE_* byte */ +#endif + +/* New members added in libpng-1.0.3 */ +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + png_byte rgb_to_gray_status; + /* Added in libpng 1.5.5 to record setting of coefficients: */ + png_byte rgb_to_gray_coefficients_set; + /* These were changed from png_byte in libpng-1.0.6 */ + png_uint_16 rgb_to_gray_red_coeff; + png_uint_16 rgb_to_gray_green_coeff; + /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */ +#endif + +/* New member added in libpng-1.6.36 */ +#if defined(PNG_READ_EXPAND_SUPPORTED) && \ + defined(PNG_ARM_NEON_IMPLEMENTATION) + png_bytep riffled_palette; /* buffer for accelerated palette expansion */ +#endif + +/* New member added in libpng-1.0.4 (renamed in 1.0.9) */ +#if defined(PNG_MNG_FEATURES_SUPPORTED) +/* Changed from png_byte to png_uint_32 at version 1.2.0 */ + png_uint_32 mng_features_permitted; +#endif + +/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_byte filter_type; +#endif + +/* New members added in libpng-1.2.0 */ + +/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ +#ifdef PNG_USER_MEM_SUPPORTED + png_voidp mem_ptr; /* user supplied struct for mem functions */ + png_malloc_ptr malloc_fn; /* function for allocating memory */ + png_free_ptr free_fn; /* function for freeing memory */ +#endif + +/* New member added in libpng-1.0.13 and 1.2.0 */ + png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +/* The following three members were added at version 1.0.14 and 1.2.4 */ + png_bytep quantize_sort; /* working sort array */ + png_bytep index_to_palette; /* where the original index currently is + in the palette */ + png_bytep palette_to_index; /* which original index points to this + palette color */ +#endif + +/* New members added in libpng-1.0.16 and 1.2.6 */ + png_byte compression_type; + +#ifdef PNG_USER_LIMITS_SUPPORTED + png_uint_32 user_width_max; + png_uint_32 user_height_max; + + /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown + * chunks that can be stored (0 means unlimited). + */ + png_uint_32 user_chunk_cache_max; + + /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk + * can occupy when decompressed. 0 means unlimited. + */ + png_alloc_size_t user_chunk_malloc_max; +#endif + +/* New member added in libpng-1.0.25 and 1.2.17 */ +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + /* Temporary storage for unknown chunk that the library doesn't recognize, + * used while reading the chunk. + */ + png_unknown_chunk unknown_chunk; +#endif + +/* New member added in libpng-1.2.26 */ + size_t old_big_row_buf_size; + +#ifdef PNG_READ_SUPPORTED +/* New member added in libpng-1.2.30 */ + png_bytep read_buffer; /* buffer for reading chunk data */ + png_alloc_size_t read_buffer_size; /* current size of the buffer */ +#endif +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED + uInt IDAT_read_size; /* limit on read buffer size for IDAT */ +#endif + +#ifdef PNG_IO_STATE_SUPPORTED +/* New member added in libpng-1.4.0 */ + png_uint_32 io_state; +#endif + +/* New member added in libpng-1.5.6 */ + png_bytep big_prev_row; + +/* New member added in libpng-1.5.7 */ + void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info, + png_bytep row, png_const_bytep prev_row); + +#ifdef PNG_READ_SUPPORTED +#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) + png_colorspace colorspace; +#endif +#endif +}; +#endif /* PNGSTRUCT_H */ diff --git a/extern/libpng/pngtest.c b/extern/libpng/pngtest.c new file mode 100644 index 000000000..2f0a4ac83 --- /dev/null +++ b/extern/libpng/pngtest.c @@ -0,0 +1,2175 @@ + +/* pngtest.c - a simple test program to test libpng + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This program reads in a PNG image, writes it out again, and then + * compares the two files. If the files are identical, this shows that + * the basic chunk handling, filtering, and (de)compression code is working + * properly. It does not currently test all of the transforms, although + * it probably should. + * + * The program will report "FAIL" in certain legitimate cases: + * 1) when the compression level or filter selection method is changed. + * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192. + * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks + * exist in the input file. + * 4) others not listed here... + * In these cases, it is best to check with another tool such as "pngcheck" + * to see what the differences between the two files are. + * + * If a filename is given on the command-line, then this file is used + * for the input, rather than the default "pngtest.png". This allows + * testing a wide variety of files easily. You can also test a number + * of files at once by typing "pngtest -m file1.png file2.png ..." + */ + +#define _POSIX_SOURCE 1 + +#include +#include +#include + +/* Defined so I can write to a file on gui/windowing platforms */ +/* #define STDERR stderr */ +#define STDERR stdout /* For DOS */ + +#include "png.h" + +/* Known chunks that exist in pngtest.png must be supported or pngtest will fail + * simply as a result of re-ordering them. This may be fixed in 1.7 + * + * pngtest allocates a single row buffer for each row and overwrites it, + * therefore if the write side doesn't support the writing of interlaced images + * nothing can be done for an interlaced image (and the code below will fail + * horribly trying to write extra data after writing garbage). + */ +#if defined PNG_READ_SUPPORTED && /* else nothing can be done */\ + defined PNG_READ_bKGD_SUPPORTED &&\ + defined PNG_READ_cHRM_SUPPORTED &&\ + defined PNG_READ_gAMA_SUPPORTED &&\ + defined PNG_READ_oFFs_SUPPORTED &&\ + defined PNG_READ_pCAL_SUPPORTED &&\ + defined PNG_READ_pHYs_SUPPORTED &&\ + defined PNG_READ_sBIT_SUPPORTED &&\ + defined PNG_READ_sCAL_SUPPORTED &&\ + defined PNG_READ_sRGB_SUPPORTED &&\ + defined PNG_READ_sPLT_SUPPORTED &&\ + defined PNG_READ_tEXt_SUPPORTED &&\ + defined PNG_READ_tIME_SUPPORTED &&\ + defined PNG_READ_zTXt_SUPPORTED &&\ + (defined PNG_WRITE_INTERLACING_SUPPORTED || PNG_LIBPNG_VER >= 10700) + +#ifdef PNG_ZLIB_HEADER +# include PNG_ZLIB_HEADER /* defined by pnglibconf.h from 1.7 */ +#else +# include "zlib.h" +#endif + +/* Copied from pngpriv.h but only used in error messages below. */ +#ifndef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 8192 +#endif +#define FCLOSE(file) fclose(file) + +#ifndef PNG_STDIO_SUPPORTED +typedef FILE * png_FILE_p; +#endif + +/* Makes pngtest verbose so we can find problems. */ +#ifndef PNG_DEBUG +# define PNG_DEBUG 0 +#endif + +#if PNG_DEBUG > 1 +# define pngtest_debug(m) ((void)fprintf(stderr, m "\n")) +# define pngtest_debug1(m,p1) ((void)fprintf(stderr, m "\n", p1)) +# define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2)) +#else +# define pngtest_debug(m) ((void)0) +# define pngtest_debug1(m,p1) ((void)0) +# define pngtest_debug2(m,p1,p2) ((void)0) +#endif + +#if !PNG_DEBUG +# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */ +#endif + +#ifndef PNG_UNUSED +# define PNG_UNUSED(param) (void)param; +#endif + +/* Turn on CPU timing +#define PNGTEST_TIMING +*/ + +#ifndef PNG_FLOATING_POINT_SUPPORTED +#undef PNGTEST_TIMING +#endif + +#ifdef PNGTEST_TIMING +static float t_start, t_stop, t_decode, t_encode, t_misc; +#include +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED +#define PNG_tIME_STRING_LENGTH 29 +static int tIME_chunk_present = 0; +static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present"; + +#if PNG_LIBPNG_VER < 10619 +#define png_convert_to_rfc1123_buffer(ts, t) tIME_to_str(read_ptr, ts, t) + +static int +tIME_to_str(png_structp png_ptr, png_charp ts, png_const_timep t) +{ + png_const_charp str = png_convert_to_rfc1123(png_ptr, t); + + if (str == NULL) + return 0; + + strcpy(ts, str); + return 1; +} +#endif /* older libpng */ +#endif + +static int verbose = 0; +static int strict = 0; +static int relaxed = 0; +static int xfail = 0; +static int unsupported_chunks = 0; /* chunk unsupported by libpng in input */ +static int error_count = 0; /* count calls to png_error */ +static int warning_count = 0; /* count calls to png_warning */ + +/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) png_ptr->jmpbuf +#endif + +/* Defines for unknown chunk handling if required. */ +#ifndef PNG_HANDLE_CHUNK_ALWAYS +# define PNG_HANDLE_CHUNK_ALWAYS 3 +#endif +#ifndef PNG_HANDLE_CHUNK_IF_SAFE +# define PNG_HANDLE_CHUNK_IF_SAFE 2 +#endif + +/* Utility to save typing/errors, the argument must be a name */ +#define MEMZERO(var) ((void)memset(&var, 0, sizeof var)) + +/* Example of using row callbacks to make a simple progress meter */ +static int status_pass = 1; +static int status_dots_requested = 0; +static int status_dots = 1; + +static void PNGCBAPI +read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) +{ + if (png_ptr == NULL || row_number > PNG_UINT_31_MAX) + return; + + if (status_pass != pass) + { + fprintf(stdout, "\n Pass %d: ", pass); + status_pass = pass; + status_dots = 31; + } + + status_dots--; + + if (status_dots == 0) + { + fprintf(stdout, "\n "); + status_dots=30; + } + + fprintf(stdout, "r"); +} + +#ifdef PNG_WRITE_SUPPORTED +static void PNGCBAPI +write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) +{ + if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) + return; + + fprintf(stdout, "w"); +} +#endif + + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED +/* Example of using a user transform callback (doesn't do anything at present). + */ +static void PNGCBAPI +read_user_callback(png_structp png_ptr, png_row_infop row_info, png_bytep data) +{ + PNG_UNUSED(png_ptr) + PNG_UNUSED(row_info) + PNG_UNUSED(data) +} +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +/* Example of using user transform callback (we don't transform anything, + * but merely count the zero samples) + */ + +static png_uint_32 zero_samples; + +static void PNGCBAPI +count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) +{ + png_bytep dp = data; + if (png_ptr == NULL) + return; + + /* Contents of row_info: + * png_uint_32 width width of row + * png_uint_32 rowbytes number of bytes in row + * png_byte color_type color type of pixels + * png_byte bit_depth bit depth of samples + * png_byte channels number of channels (1-4) + * png_byte pixel_depth bits per pixel (depth*channels) + */ + + /* Counts the number of zero samples (or zero pixels if color_type is 3 */ + + if (row_info->color_type == 0 || row_info->color_type == 3) + { + int pos = 0; + png_uint_32 n, nstop; + + for (n = 0, nstop=row_info->width; nbit_depth == 1) + { + if (((*dp << pos++ ) & 0x80) == 0) + zero_samples++; + + if (pos == 8) + { + pos = 0; + dp++; + } + } + + if (row_info->bit_depth == 2) + { + if (((*dp << (pos+=2)) & 0xc0) == 0) + zero_samples++; + + if (pos == 8) + { + pos = 0; + dp++; + } + } + + if (row_info->bit_depth == 4) + { + if (((*dp << (pos+=4)) & 0xf0) == 0) + zero_samples++; + + if (pos == 8) + { + pos = 0; + dp++; + } + } + + if (row_info->bit_depth == 8) + if (*dp++ == 0) + zero_samples++; + + if (row_info->bit_depth == 16) + { + if ((*dp | *(dp+1)) == 0) + zero_samples++; + dp+=2; + } + } + } + else /* Other color types */ + { + png_uint_32 n, nstop; + int channel; + int color_channels = row_info->channels; + if (row_info->color_type > 3) + color_channels--; + + for (n = 0, nstop=row_info->width; nbit_depth == 8) + if (*dp++ == 0) + zero_samples++; + + if (row_info->bit_depth == 16) + { + if ((*dp | *(dp+1)) == 0) + zero_samples++; + + dp+=2; + } + } + if (row_info->color_type > 3) + { + dp++; + if (row_info->bit_depth == 16) + dp++; + } + } + } +} +#endif /* WRITE_USER_TRANSFORM */ + +#ifndef PNG_STDIO_SUPPORTED +/* START of code to validate stdio-free compilation */ +/* These copies of the default read/write functions come from pngrio.c and + * pngwio.c. They allow "don't include stdio" testing of the library. + * This is the function that does the actual reading of data. If you are + * not reading from a standard C stream, you should create a replacement + * read_data function and use it at run time with png_set_read_fn(), rather + * than changing the library. + */ + +#ifdef PNG_IO_STATE_SUPPORTED +void +pngtest_check_io_state(png_structp png_ptr, size_t data_length, + png_uint_32 io_op); +void +pngtest_check_io_state(png_structp png_ptr, size_t data_length, + png_uint_32 io_op) +{ + png_uint_32 io_state = png_get_io_state(png_ptr); + int err = 0; + + /* Check if the current operation (reading / writing) is as expected. */ + if ((io_state & PNG_IO_MASK_OP) != io_op) + png_error(png_ptr, "Incorrect operation in I/O state"); + + /* Check if the buffer size specific to the current location + * (file signature / header / data / crc) is as expected. + */ + switch (io_state & PNG_IO_MASK_LOC) + { + case PNG_IO_SIGNATURE: + if (data_length > 8) + err = 1; + break; + case PNG_IO_CHUNK_HDR: + if (data_length != 8) + err = 1; + break; + case PNG_IO_CHUNK_DATA: + break; /* no restrictions here */ + case PNG_IO_CHUNK_CRC: + if (data_length != 4) + err = 1; + break; + default: + err = 1; /* uninitialized */ + } + if (err != 0) + png_error(png_ptr, "Bad I/O state or buffer size"); +} +#endif + +static void PNGCBAPI +pngtest_read_data(png_structp png_ptr, png_bytep data, size_t length) +{ + size_t check = 0; + png_voidp io_ptr; + + /* fread() returns 0 on error, so it is OK to store this in a size_t + * instead of an int, which is what fread() actually returns. + */ + io_ptr = png_get_io_ptr(png_ptr); + if (io_ptr != NULL) + { + check = fread(data, 1, length, (png_FILE_p)io_ptr); + } + + if (check != length) + { + png_error(png_ptr, "Read Error"); + } + +#ifdef PNG_IO_STATE_SUPPORTED + pngtest_check_io_state(png_ptr, length, PNG_IO_READING); +#endif +} + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +static void PNGCBAPI +pngtest_flush(png_structp png_ptr) +{ + /* Do nothing; fflush() is said to be just a waste of energy. */ + PNG_UNUSED(png_ptr) /* Stifle compiler warning */ +} +#endif + +/* This is the function that does the actual writing of data. If you are + * not writing to a standard C stream, you should create a replacement + * write_data function and use it at run time with png_set_write_fn(), rather + * than changing the library. + */ +static void PNGCBAPI +pngtest_write_data(png_structp png_ptr, png_bytep data, size_t length) +{ + size_t check; + + check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr)); + + if (check != length) + { + png_error(png_ptr, "Write Error"); + } + +#ifdef PNG_IO_STATE_SUPPORTED + pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING); +#endif +} +#endif /* !STDIO */ + +/* This function is called when there is a warning, but the library thinks + * it can continue anyway. Replacement functions don't have to do anything + * here if you don't want to. In the default configuration, png_ptr is + * not used, but it is passed in case it may be useful. + */ +typedef struct +{ + const char *file_name; +} pngtest_error_parameters; + +static void PNGCBAPI +pngtest_warning(png_structp png_ptr, png_const_charp message) +{ + const char *name = "UNKNOWN (ERROR!)"; + pngtest_error_parameters *test = + (pngtest_error_parameters*)png_get_error_ptr(png_ptr); + + ++warning_count; + + if (test != NULL && test->file_name != NULL) + name = test->file_name; + + fprintf(STDERR, "\n%s: libpng warning: %s\n", name, message); +} + +/* This is the default error handling function. Note that replacements for + * this function MUST NOT RETURN, or the program will likely crash. This + * function is used by default, or if the program supplies NULL for the + * error function pointer in png_set_error_fn(). + */ +static void PNGCBAPI +pngtest_error(png_structp png_ptr, png_const_charp message) +{ + ++error_count; + + pngtest_warning(png_ptr, message); + /* We can return because png_error calls the default handler, which is + * actually OK in this case. + */ +} + +/* END of code to validate stdio-free compilation */ + +/* START of code to validate memory allocation and deallocation */ +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more than 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + * + * This piece of code can be compiled to validate max 64K allocations + * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. + */ +typedef struct memory_information +{ + png_alloc_size_t size; + png_voidp pointer; + struct memory_information *next; +} memory_information; +typedef memory_information *memory_infop; + +static memory_infop pinformation = NULL; +static int current_allocation = 0; +static int maximum_allocation = 0; +static int total_allocation = 0; +static int num_allocations = 0; + +png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr, + png_alloc_size_t size)); +void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr)); + +png_voidp +PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size) +{ + + /* png_malloc has already tested for NULL; png_create_struct calls + * png_debug_malloc directly, with png_ptr == NULL which is OK + */ + + if (size == 0) + return (NULL); + + /* This calls the library allocator twice, once to get the requested + buffer and once to get a new free list entry. */ + { + /* Disable malloc_fn and free_fn */ + memory_infop pinfo; + png_set_mem_fn(png_ptr, NULL, NULL, NULL); + pinfo = (memory_infop)png_malloc(png_ptr, + (sizeof *pinfo)); + pinfo->size = size; + current_allocation += size; + total_allocation += size; + num_allocations ++; + + if (current_allocation > maximum_allocation) + maximum_allocation = current_allocation; + + pinfo->pointer = png_malloc(png_ptr, size); + /* Restore malloc_fn and free_fn */ + + png_set_mem_fn(png_ptr, + NULL, png_debug_malloc, png_debug_free); + + if (size != 0 && pinfo->pointer == NULL) + { + current_allocation -= size; + total_allocation -= size; + png_error(png_ptr, + "out of memory in pngtest->png_debug_malloc"); + } + + pinfo->next = pinformation; + pinformation = pinfo; + /* Make sure the caller isn't assuming zeroed memory. */ + memset(pinfo->pointer, 0xdd, pinfo->size); + + if (verbose != 0) + printf("png_malloc %lu bytes at %p\n", (unsigned long)size, + pinfo->pointer); + + return (png_voidp)(pinfo->pointer); + } +} + +/* Free a pointer. It is removed from the list at the same time. */ +void PNGCBAPI +png_debug_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL) + fprintf(STDERR, "NULL pointer to png_debug_free.\n"); + + if (ptr == 0) + { +#if 0 /* This happens all the time. */ + fprintf(STDERR, "WARNING: freeing NULL pointer\n"); +#endif + return; + } + + /* Unlink the element from the list. */ + if (pinformation != NULL) + { + memory_infop *ppinfo = &pinformation; + + for (;;) + { + memory_infop pinfo = *ppinfo; + + if (pinfo->pointer == ptr) + { + *ppinfo = pinfo->next; + current_allocation -= pinfo->size; + if (current_allocation < 0) + fprintf(STDERR, "Duplicate free of memory\n"); + /* We must free the list element too, but first kill + the memory that is to be freed. */ + memset(ptr, 0x55, pinfo->size); + free(pinfo); + pinfo = NULL; + break; + } + + if (pinfo->next == NULL) + { + fprintf(STDERR, "Pointer %p not found\n", ptr); + break; + } + + ppinfo = &pinfo->next; + } + } + + /* Finally free the data. */ + if (verbose != 0) + printf("Freeing %p\n", ptr); + + if (ptr != NULL) + free(ptr); + ptr = NULL; +} +#endif /* USER_MEM && DEBUG */ +/* END of code to test memory allocation/deallocation */ + + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED +/* Demonstration of user chunk support of the sTER and vpAg chunks */ + +/* (sTER is a public chunk not yet known by libpng. vpAg is a private +chunk used in ImageMagick to store "virtual page" size). */ + +static struct user_chunk_data +{ + png_const_infop info_ptr; + png_uint_32 vpAg_width, vpAg_height; + png_byte vpAg_units; + png_byte sTER_mode; + int location[2]; +} +user_chunk_data; + +/* Used for location and order; zero means nothing. */ +#define have_sTER 0x01 +#define have_vpAg 0x02 +#define before_PLTE 0x10 +#define before_IDAT 0x20 +#define after_IDAT 0x40 + +static void +init_callback_info(png_const_infop info_ptr) +{ + MEMZERO(user_chunk_data); + user_chunk_data.info_ptr = info_ptr; +} + +static int +set_location(png_structp png_ptr, struct user_chunk_data *data, int what) +{ + int location; + + if ((data->location[0] & what) != 0 || (data->location[1] & what) != 0) + return 0; /* already have one of these */ + + /* Find where we are (the code below zeroes info_ptr to indicate that the + * chunks before the first IDAT have been read.) + */ + if (data->info_ptr == NULL) /* after IDAT */ + location = what | after_IDAT; + + else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE) != 0) + location = what | before_IDAT; + + else + location = what | before_PLTE; + + if (data->location[0] == 0) + data->location[0] = location; + + else + data->location[1] = location; + + return 1; /* handled */ +} + +static int PNGCBAPI +read_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk) +{ + struct user_chunk_data *my_user_chunk_data = + (struct user_chunk_data*)png_get_user_chunk_ptr(png_ptr); + + if (my_user_chunk_data == NULL) + png_error(png_ptr, "lost user chunk pointer"); + + /* Return one of the following: + * return (-n); chunk had an error + * return (0); did not recognize + * return (n); success + * + * The unknown chunk structure contains the chunk data: + * png_byte name[5]; + * png_byte *data; + * size_t size; + * + * Note that libpng has already taken care of the CRC handling. + */ + + if (chunk->name[0] == 115 && chunk->name[1] == 84 && /* s T */ + chunk->name[2] == 69 && chunk->name[3] == 82) /* E R */ + { + /* Found sTER chunk */ + if (chunk->size != 1) + return (-1); /* Error return */ + + if (chunk->data[0] != 0 && chunk->data[0] != 1) + return (-1); /* Invalid mode */ + + if (set_location(png_ptr, my_user_chunk_data, have_sTER) != 0) + { + my_user_chunk_data->sTER_mode=chunk->data[0]; + return (1); + } + + else + return (0); /* duplicate sTER - give it to libpng */ + } + + if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */ + chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */ + return (0); /* Did not recognize */ + + /* Found ImageMagick vpAg chunk */ + + if (chunk->size != 9) + return (-1); /* Error return */ + + if (set_location(png_ptr, my_user_chunk_data, have_vpAg) == 0) + return (0); /* duplicate vpAg */ + + my_user_chunk_data->vpAg_width = png_get_uint_31(png_ptr, chunk->data); + my_user_chunk_data->vpAg_height = png_get_uint_31(png_ptr, chunk->data + 4); + my_user_chunk_data->vpAg_units = chunk->data[8]; + + return (1); +} + +#ifdef PNG_WRITE_SUPPORTED +static void +write_sTER_chunk(png_structp write_ptr) +{ + png_byte sTER[5] = {115, 84, 69, 82, '\0'}; + + if (verbose != 0) + fprintf(STDERR, "\n stereo mode = %d\n", user_chunk_data.sTER_mode); + + png_write_chunk(write_ptr, sTER, &user_chunk_data.sTER_mode, 1); +} + +static void +write_vpAg_chunk(png_structp write_ptr) +{ + png_byte vpAg[5] = {118, 112, 65, 103, '\0'}; + + png_byte vpag_chunk_data[9]; + + if (verbose != 0) + fprintf(STDERR, " vpAg = %lu x %lu, units = %d\n", + (unsigned long)user_chunk_data.vpAg_width, + (unsigned long)user_chunk_data.vpAg_height, + user_chunk_data.vpAg_units); + + png_save_uint_32(vpag_chunk_data, user_chunk_data.vpAg_width); + png_save_uint_32(vpag_chunk_data + 4, user_chunk_data.vpAg_height); + vpag_chunk_data[8] = user_chunk_data.vpAg_units; + png_write_chunk(write_ptr, vpAg, vpag_chunk_data, 9); +} + +static void +write_chunks(png_structp write_ptr, int location) +{ + int i; + + /* Notice that this preserves the original chunk order, however chunks + * intercepted by the callback will be written *after* chunks passed to + * libpng. This will actually reverse a pair of sTER chunks or a pair of + * vpAg chunks, resulting in an error later. This is not worth worrying + * about - the chunks should not be duplicated! + */ + for (i=0; i<2; ++i) + { + if (user_chunk_data.location[i] == (location | have_sTER)) + write_sTER_chunk(write_ptr); + + else if (user_chunk_data.location[i] == (location | have_vpAg)) + write_vpAg_chunk(write_ptr); + } +} +#endif /* WRITE */ +#else /* !READ_USER_CHUNKS */ +# define write_chunks(pp,loc) ((void)0) +#endif +/* END of code to demonstrate user chunk support */ + +/* START of code to check that libpng has the required text support; this only + * checks for the write support because if read support is missing the chunk + * will simply not be reported back to pngtest. + */ +#ifdef PNG_TEXT_SUPPORTED +static void +pngtest_check_text_support(png_structp png_ptr, png_textp text_ptr, + int num_text) +{ + while (num_text > 0) + { + switch (text_ptr[--num_text].compression) + { + case PNG_TEXT_COMPRESSION_NONE: + break; + + case PNG_TEXT_COMPRESSION_zTXt: +# ifndef PNG_WRITE_zTXt_SUPPORTED + ++unsupported_chunks; + /* In libpng 1.7 this now does an app-error, so stop it: */ + text_ptr[num_text].compression = PNG_TEXT_COMPRESSION_NONE; +# endif + break; + + case PNG_ITXT_COMPRESSION_NONE: + case PNG_ITXT_COMPRESSION_zTXt: +# ifndef PNG_WRITE_iTXt_SUPPORTED + ++unsupported_chunks; + text_ptr[num_text].compression = PNG_TEXT_COMPRESSION_NONE; +# endif + break; + + default: + /* This is an error */ + png_error(png_ptr, "invalid text chunk compression field"); + break; + } + } +} +#endif +/* END of code to check that libpng has the required text support */ + +/* Test one file */ +static int +test_one_file(const char *inname, const char *outname) +{ + static png_FILE_p fpin; + static png_FILE_p fpout; /* "static" prevents setjmp corruption */ + pngtest_error_parameters error_parameters; + png_structp read_ptr; + png_infop read_info_ptr, end_info_ptr; +#ifdef PNG_WRITE_SUPPORTED + png_structp write_ptr; + png_infop write_info_ptr; + png_infop write_end_info_ptr; +#ifdef PNG_WRITE_FILTER_SUPPORTED + int interlace_preserved = 1; +#endif /* WRITE_FILTER */ +#else /* !WRITE */ + png_structp write_ptr = NULL; + png_infop write_info_ptr = NULL; + png_infop write_end_info_ptr = NULL; +#endif /* !WRITE */ + png_bytep row_buf; + png_uint_32 y; + png_uint_32 width, height; + volatile int num_passes; + int pass; + int bit_depth, color_type; + + row_buf = NULL; + error_parameters.file_name = inname; + + if ((fpin = fopen(inname, "rb")) == NULL) + { + fprintf(STDERR, "Could not find input file %s\n", inname); + return (1); + } + + if ((fpout = fopen(outname, "wb")) == NULL) + { + fprintf(STDERR, "Could not open output file %s\n", outname); + FCLOSE(fpin); + return (1); + } + + pngtest_debug("Allocating read and write structures"); +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + read_ptr = + png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL, NULL, png_debug_malloc, png_debug_free); +#else + read_ptr = + png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); +#endif + png_set_error_fn(read_ptr, &error_parameters, pngtest_error, + pngtest_warning); + +#ifdef PNG_WRITE_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + write_ptr = + png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL, NULL, png_debug_malloc, png_debug_free); +#else + write_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); +#endif + png_set_error_fn(write_ptr, &error_parameters, pngtest_error, + pngtest_warning); +#endif + pngtest_debug("Allocating read_info, write_info and end_info structures"); + read_info_ptr = png_create_info_struct(read_ptr); + end_info_ptr = png_create_info_struct(read_ptr); +#ifdef PNG_WRITE_SUPPORTED + write_info_ptr = png_create_info_struct(write_ptr); + write_end_info_ptr = png_create_info_struct(write_ptr); +#endif + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + init_callback_info(read_info_ptr); + png_set_read_user_chunk_fn(read_ptr, &user_chunk_data, + read_user_chunk_callback); +#endif + +#ifdef PNG_SETJMP_SUPPORTED + pngtest_debug("Setting jmpbuf for read struct"); + if (setjmp(png_jmpbuf(read_ptr))) + { + fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); + png_free(read_ptr, row_buf); + row_buf = NULL; + if (verbose != 0) + fprintf(STDERR, " destroy read structs\n"); + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); +#ifdef PNG_WRITE_SUPPORTED + if (verbose != 0) + fprintf(STDERR, " destroy write structs\n"); + png_destroy_info_struct(write_ptr, &write_end_info_ptr); + png_destroy_write_struct(&write_ptr, &write_info_ptr); + FCLOSE(fpin); + FCLOSE(fpout); + return (1); + } + +#ifdef PNG_WRITE_SUPPORTED + pngtest_debug("Setting jmpbuf for write struct"); + + if (setjmp(png_jmpbuf(write_ptr))) + { + fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); + png_free(read_ptr, row_buf); + row_buf = NULL; + if (verbose != 0) + fprintf(STDERR, " destroying read structs\n"); + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); + if (verbose != 0) + fprintf(STDERR, " destroying write structs\n"); + png_destroy_info_struct(write_ptr, &write_end_info_ptr); + png_destroy_write_struct(&write_ptr, &write_info_ptr); + FCLOSE(fpin); + FCLOSE(fpout); + return (1); + } +#endif +#endif + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED + if (strict != 0) + { + /* Treat png_benign_error() as errors on read */ + png_set_benign_errors(read_ptr, 0); + +# ifdef PNG_WRITE_SUPPORTED + /* Treat them as errors on write */ + png_set_benign_errors(write_ptr, 0); +# endif + + /* if strict is not set, then app warnings and errors are treated as + * warnings in release builds, but not in unstable builds; this can be + * changed with '--relaxed'. + */ + } + + else if (relaxed != 0) + { + /* Allow application (pngtest) errors and warnings to pass */ + png_set_benign_errors(read_ptr, 1); + + /* Turn off CRC checking while reading */ + png_set_crc_action(read_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE); + +#ifdef PNG_IGNORE_ADLER32 + /* Turn off ADLER32 checking while reading */ + png_set_option(read_ptr, PNG_IGNORE_ADLER32, PNG_OPTION_ON); +#endif + +# ifdef PNG_WRITE_SUPPORTED + png_set_benign_errors(write_ptr, 1); +# endif + + } +#endif /* BENIGN_ERRORS */ + + pngtest_debug("Initializing input and output streams"); +#ifdef PNG_STDIO_SUPPORTED + png_init_io(read_ptr, fpin); +# ifdef PNG_WRITE_SUPPORTED + png_init_io(write_ptr, fpout); +# endif +#else + png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data); +# ifdef PNG_WRITE_SUPPORTED + png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data, +# ifdef PNG_WRITE_FLUSH_SUPPORTED + pngtest_flush); +# else + NULL); +# endif +# endif +#endif + + if (status_dots_requested == 1) + { +#ifdef PNG_WRITE_SUPPORTED + png_set_write_status_fn(write_ptr, write_row_callback); +#endif + png_set_read_status_fn(read_ptr, read_row_callback); + } + + else + { +#ifdef PNG_WRITE_SUPPORTED + png_set_write_status_fn(write_ptr, NULL); +#endif + png_set_read_status_fn(read_ptr, NULL); + } + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + png_set_read_user_transform_fn(read_ptr, read_user_callback); +#endif +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + zero_samples = 0; + png_set_write_user_transform_fn(write_ptr, count_zero_samples); +#endif + +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + /* Preserve all the unknown chunks, if possible. If this is disabled then, + * even if the png_{get,set}_unknown_chunks stuff is enabled, we can't use + * libpng to *save* the unknown chunks on read (because we can't switch the + * save option on!) + * + * Notice that if SET_UNKNOWN_CHUNKS is *not* supported read will discard all + * unknown chunks and write will write them all. + */ +#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED + png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, + NULL, 0); +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS, + NULL, 0); +#endif +#endif + + pngtest_debug("Reading info struct"); + png_read_info(read_ptr, read_info_ptr); + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + /* This is a bit of a hack; there is no obvious way in the callback function + * to determine that the chunks before the first IDAT have been read, so + * remove the info_ptr (which is only used to determine position relative to + * PLTE) here to indicate that we are after the IDAT. + */ + user_chunk_data.info_ptr = NULL; +#endif + + pngtest_debug("Transferring info struct"); + { + int interlace_type, compression_type, filter_type; + + if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, + &color_type, &interlace_type, &compression_type, &filter_type) != 0) + { + png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, + color_type, interlace_type, compression_type, filter_type); + /* num_passes may not be available below if interlace support is not + * provided by libpng for both read and write. + */ + switch (interlace_type) + { + case PNG_INTERLACE_NONE: + num_passes = 1; + break; + + case PNG_INTERLACE_ADAM7: + num_passes = 7; + break; + + default: + png_error(read_ptr, "invalid interlace type"); + /*NOT REACHED*/ + } + } + + else + png_error(read_ptr, "png_get_IHDR failed"); + } +#ifdef PNG_FIXED_POINT_SUPPORTED +#ifdef PNG_cHRM_SUPPORTED + { + png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x, + blue_y; + + if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, + &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0) + { + png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x, + red_y, green_x, green_y, blue_x, blue_y); + } + } +#endif +#ifdef PNG_gAMA_SUPPORTED + { + png_fixed_point gamma; + + if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma) != 0) + png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma); + } +#endif +#else /* Use floating point versions */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +#ifdef PNG_cHRM_SUPPORTED + { + double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, + blue_y; + + if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, + &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0) + { + png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, + red_y, green_x, green_y, blue_x, blue_y); + } + } +#endif +#ifdef PNG_gAMA_SUPPORTED + { + double gamma; + + if (png_get_gAMA(read_ptr, read_info_ptr, &gamma) != 0) + png_set_gAMA(write_ptr, write_info_ptr, gamma); + } +#endif +#endif /* Floating point */ +#endif /* Fixed point */ +#ifdef PNG_iCCP_SUPPORTED + { + png_charp name; + png_bytep profile; + png_uint_32 proflen; + int compression_type; + + if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, + &profile, &proflen) != 0) + { + png_set_iCCP(write_ptr, write_info_ptr, name, compression_type, + profile, proflen); + } + } +#endif +#ifdef PNG_sRGB_SUPPORTED + { + int intent; + + if (png_get_sRGB(read_ptr, read_info_ptr, &intent) != 0) + png_set_sRGB(write_ptr, write_info_ptr, intent); + } +#endif + { + png_colorp palette; + int num_palette; + + if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette) != 0) + png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); + } +#ifdef PNG_bKGD_SUPPORTED + { + png_color_16p background; + + if (png_get_bKGD(read_ptr, read_info_ptr, &background) != 0) + { + png_set_bKGD(write_ptr, write_info_ptr, background); + } + } +#endif +#ifdef PNG_READ_eXIf_SUPPORTED + { + png_bytep exif=NULL; + png_uint_32 exif_length; + + if (png_get_eXIf_1(read_ptr, read_info_ptr, &exif_length, &exif) != 0) + { + if (exif_length > 1) + fprintf(STDERR," eXIf type %c%c, %lu bytes\n",exif[0],exif[1], + (unsigned long)exif_length); +# ifdef PNG_WRITE_eXIf_SUPPORTED + png_set_eXIf_1(write_ptr, write_info_ptr, exif_length, exif); +# endif + } + } +#endif +#ifdef PNG_hIST_SUPPORTED + { + png_uint_16p hist; + + if (png_get_hIST(read_ptr, read_info_ptr, &hist) != 0) + png_set_hIST(write_ptr, write_info_ptr, hist); + } +#endif +#ifdef PNG_oFFs_SUPPORTED + { + png_int_32 offset_x, offset_y; + int unit_type; + + if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y, + &unit_type) != 0) + { + png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type); + } + } +#endif +#ifdef PNG_pCAL_SUPPORTED + { + png_charp purpose, units; + png_charpp params; + png_int_32 X0, X1; + int type, nparams; + + if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, + &nparams, &units, ¶ms) != 0) + { + png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, + nparams, units, params); + } + } +#endif +#ifdef PNG_pHYs_SUPPORTED + { + png_uint_32 res_x, res_y; + int unit_type; + + if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, + &unit_type) != 0) + png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); + } +#endif +#ifdef PNG_sBIT_SUPPORTED + { + png_color_8p sig_bit; + + if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit) != 0) + png_set_sBIT(write_ptr, write_info_ptr, sig_bit); + } +#endif +#ifdef PNG_sCAL_SUPPORTED +#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ + defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) + { + int unit; + double scal_width, scal_height; + + if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, + &scal_height) != 0) + { + png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); + } + } +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + { + int unit; + png_charp scal_width, scal_height; + + if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, + &scal_height) != 0) + { + png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, + scal_height); + } + } +#endif +#endif +#endif + +#ifdef PNG_sPLT_SUPPORTED + { + png_sPLT_tp entries; + + int num_entries = (int) png_get_sPLT(read_ptr, read_info_ptr, &entries); + if (num_entries) + { + png_set_sPLT(write_ptr, write_info_ptr, entries, num_entries); + } + } +#endif + +#ifdef PNG_TEXT_SUPPORTED + { + png_textp text_ptr; + int num_text; + + if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0) + { + pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); + + pngtest_check_text_support(read_ptr, text_ptr, num_text); + + if (verbose != 0) + { + int i; + + fprintf(STDERR,"\n"); + for (i=0; igray > sample_max) || + (color_type == PNG_COLOR_TYPE_RGB && + ((int)trans_color->red > sample_max || + (int)trans_color->green > sample_max || + (int)trans_color->blue > sample_max)))) + png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans, + trans_color); + } + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + { + png_unknown_chunkp unknowns; + int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr, + &unknowns); + + if (num_unknowns != 0) + { + png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns, + num_unknowns); +#if PNG_LIBPNG_VER < 10600 + /* Copy the locations from the read_info_ptr. The automatically + * generated locations in write_end_info_ptr are wrong prior to 1.6.0 + * because they are reset from the write pointer (removed in 1.6.0). + */ + { + int i; + for (i = 0; i < num_unknowns; i++) + png_set_unknown_chunk_location(write_ptr, write_info_ptr, i, + unknowns[i].location); + } + } + } +#endif +#ifdef PNG_READ_eXIf_SUPPORTED + { + png_bytep exif=NULL; + png_uint_32 exif_length; + +#ifdef PNG_WRITE_SUPPORTED + pngtest_debug("Writing info struct"); + + /* Write the info in two steps so that if we write the 'unknown' chunks here + * they go to the correct place. + */ + png_write_info_before_PLTE(write_ptr, write_info_ptr); + + write_chunks(write_ptr, before_PLTE); /* before PLTE */ + + png_write_info(write_ptr, write_info_ptr); + + write_chunks(write_ptr, before_IDAT); /* after PLTE */ + + png_write_info(write_ptr, write_end_info_ptr); + + write_chunks(write_ptr, after_IDAT); /* after IDAT */ + +#ifdef PNG_COMPRESSION_COMPAT + /* Test the 'compatibility' setting here, if it is available. */ + png_set_compression(write_ptr, PNG_COMPRESSION_COMPAT); +#endif +#endif + +#ifdef SINGLE_ROWBUF_ALLOC + pngtest_debug("Allocating row buffer..."); + row_buf = (png_bytep)png_malloc(read_ptr, + png_get_rowbytes(read_ptr, read_info_ptr)); + + pngtest_debug1("\t%p", row_buf); +#endif /* SINGLE_ROWBUF_ALLOC */ + pngtest_debug("Writing row data"); + +#if defined(PNG_READ_INTERLACING_SUPPORTED) &&\ + defined(PNG_WRITE_INTERLACING_SUPPORTED) + /* Both must be defined for libpng to be able to handle the interlace, + * otherwise it gets handled below by simply reading and writing the passes + * directly. + */ + if (png_set_interlace_handling(read_ptr) != num_passes) + png_error(write_ptr, + "png_set_interlace_handling(read): wrong pass count "); + if (png_set_interlace_handling(write_ptr) != num_passes) + png_error(write_ptr, + "png_set_interlace_handling(write): wrong pass count "); +#else /* png_set_interlace_handling not called on either read or write */ +# define calc_pass_height +#endif /* not using libpng interlace handling */ + +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_misc += (t_stop - t_start); + t_start = t_stop; +#endif + for (pass = 0; pass < num_passes; pass++) + { +# ifdef calc_pass_height + png_uint_32 pass_height; + + if (num_passes == 7) /* interlaced */ + { + if (PNG_PASS_COLS(width, pass) > 0) + pass_height = PNG_PASS_ROWS(height, pass); + + else + pass_height = 0; + } + + else /* not interlaced */ + pass_height = height; +# else +# define pass_height height +# endif + + pngtest_debug1("Writing row data for pass %d", pass); + for (y = 0; y < pass_height; y++) + { +#ifndef SINGLE_ROWBUF_ALLOC + pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y); + + row_buf = (png_bytep)png_malloc(read_ptr, + png_get_rowbytes(read_ptr, read_info_ptr)); + + pngtest_debug2("\t%p (%lu bytes)", row_buf, + (unsigned long)png_get_rowbytes(read_ptr, read_info_ptr)); + +#endif /* !SINGLE_ROWBUF_ALLOC */ + png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1); + +#ifdef PNG_WRITE_SUPPORTED +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_decode += (t_stop - t_start); + t_start = t_stop; +#endif + png_write_rows(write_ptr, (png_bytepp)&row_buf, 1); +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_encode += (t_stop - t_start); + t_start = t_stop; +#endif +#endif /* WRITE */ + +#ifndef SINGLE_ROWBUF_ALLOC + pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y); + png_free(read_ptr, row_buf); + row_buf = NULL; +#endif /* !SINGLE_ROWBUF_ALLOC */ + } + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +# ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); +# endif +# ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); +# endif +#endif + + pngtest_debug("Reading and writing end_info data"); + + png_read_end(read_ptr, end_info_ptr); +#ifdef PNG_TEXT_SUPPORTED + { + png_textp text_ptr; + int num_text; + + if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0) + { + pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); + + pngtest_check_text_support(read_ptr, text_ptr, num_text); + + if (verbose != 0) + { + int i; + + fprintf(STDERR,"\n"); + for (i=0; i 1) + fprintf(STDERR," eXIf type %c%c, %lu bytes\n",exif[0],exif[1], + (unsigned long)exif_length); +# ifdef PNG_WRITE_eXIf_SUPPORTED + png_set_eXIf_1(write_ptr, write_end_info_ptr, exif_length, exif); +# endif + } + } +#endif +#ifdef PNG_READ_eXIf_SUPPORTED + { + png_bytep exif=NULL; + png_uint_32 exif_length; + + if (png_get_eXIf_1(read_ptr, end_info_ptr, &exif_length, &exif) != 0) + { + if (exif_length > 1) + fprintf(STDERR," eXIf type %c%c, %lu bytes\n",exif[0],exif[1], + (unsigned long)exif_length); +# ifdef PNG_WRITE_eXIf_SUPPORTED + png_set_eXIf_1(write_ptr, write_end_info_ptr, exif_length, exif); +# endif + } + } +#endif +#ifdef PNG_tIME_SUPPORTED + { + png_timep mod_time; + + if (png_get_tIME(read_ptr, end_info_ptr, &mod_time) != 0) + { + png_set_tIME(write_ptr, write_end_info_ptr, mod_time); +#ifdef PNG_TIME_RFC1123_SUPPORTED + if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0) + tIME_string[(sizeof tIME_string) - 1] = '\0'; + + else + { + strncpy(tIME_string, "*** invalid time ***", sizeof tIME_string); + tIME_string[(sizeof tIME_string)-1] = '\0'; + } + + tIME_chunk_present++; +#endif /* TIME_RFC1123 */ + } + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + { + png_unknown_chunkp unknowns; + int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr, + &unknowns); + + if (num_unknowns != 0) + { + png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns, + num_unknowns); +#if PNG_LIBPNG_VER < 10600 + /* Copy the locations from the read_info_ptr. The automatically + * generated locations in write_end_info_ptr are wrong prior to 1.6.0 + * because they are reset from the write pointer (removed in 1.6.0). + */ + { + int i; + for (i = 0; i < num_unknowns; i++) + png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i, + unknowns[i].location); + } +#endif + } + } +#endif + +#ifdef PNG_WRITE_SUPPORTED +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED + /* Normally one would use Z_DEFAULT_STRATEGY for text compression. + * This is here just to make pngtest replicate the results from libpng + * versions prior to 1.5.4, and to test this new API. + */ + png_set_text_compression_strategy(write_ptr, Z_FILTERED); +#endif + + /* When the unknown vpAg/sTER chunks are written by pngtest the only way to + * do it is to write them *before* calling png_write_end. When unknown + * chunks are written by libpng, however, they are written just before IEND. + * There seems to be no way round this, however vpAg/sTER are not expected + * after IDAT. + */ + write_chunks(write_ptr, after_IDAT); + + png_write_end(write_ptr, write_end_info_ptr); +#endif + +#ifdef PNG_EASY_ACCESS_SUPPORTED + if (verbose != 0) + { + png_uint_32 iwidth, iheight; + iwidth = png_get_image_width(write_ptr, write_info_ptr); + iheight = png_get_image_height(write_ptr, write_info_ptr); + fprintf(STDERR, "\n Image width = %lu, height = %lu\n", + (unsigned long)iwidth, (unsigned long)iheight); + } +#endif + + pngtest_debug("Destroying data structs"); +#ifdef SINGLE_ROWBUF_ALLOC + pngtest_debug("destroying row_buf for read_ptr"); + png_free(read_ptr, row_buf); + row_buf = NULL; +#endif /* SINGLE_ROWBUF_ALLOC */ + pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr"); + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); +#ifdef PNG_WRITE_SUPPORTED + pngtest_debug("destroying write_end_info_ptr"); + png_destroy_info_struct(write_ptr, &write_end_info_ptr); + pngtest_debug("destroying write_ptr, write_info_ptr"); + png_destroy_write_struct(&write_ptr, &write_info_ptr); +#endif + pngtest_debug("Destruction complete."); + + FCLOSE(fpin); + FCLOSE(fpout); + + /* Summarize any warnings or errors and in 'strict' mode fail the test. + * Unsupported chunks can result in warnings, in that case ignore the strict + * setting, otherwise fail the test on warnings as well as errors. + */ + if (error_count > 0) + { + /* We don't really expect to get here because of the setjmp handling + * above, but this is safe. + */ + fprintf(STDERR, "\n %s: %d libpng errors found (%d warnings)", + inname, error_count, warning_count); + + if (strict != 0) + return (1); + } + +# ifdef PNG_WRITE_SUPPORTED + /* If there is no write support nothing was written! */ + else if (unsupported_chunks > 0) + { + fprintf(STDERR, "\n %s: unsupported chunks (%d)%s", + inname, unsupported_chunks, strict ? ": IGNORED --strict!" : ""); + } +# endif + + else if (warning_count > 0) + { + fprintf(STDERR, "\n %s: %d libpng warnings found", + inname, warning_count); + + if (strict != 0) + return (1); + } + + pngtest_debug("Opening files for comparison"); + if ((fpin = fopen(inname, "rb")) == NULL) + { + fprintf(STDERR, "Could not find file %s\n", inname); + return (1); + } + + if ((fpout = fopen(outname, "rb")) == NULL) + { + fprintf(STDERR, "Could not find file %s\n", outname); + FCLOSE(fpin); + return (1); + } + +#if defined (PNG_WRITE_SUPPORTED) /* else nothing was written */ &&\ + defined (PNG_WRITE_FILTER_SUPPORTED) + if (interlace_preserved != 0) /* else the files will be changed */ + { + for (;;) + { + static int wrote_question = 0; + size_t num_in, num_out; + char inbuf[256], outbuf[256]; + + num_in = fread(inbuf, 1, sizeof inbuf, fpin); + num_out = fread(outbuf, 1, sizeof outbuf, fpout); + + if (num_in != num_out) + { + fprintf(STDERR, "\nFiles %s and %s are of a different size\n", + inname, outname); + + if (wrote_question == 0 && unsupported_chunks == 0) + { + fprintf(STDERR, + " Was %s written with the same maximum IDAT" + " chunk size (%d bytes),", + inname, PNG_ZBUF_SIZE); + fprintf(STDERR, + "\n filtering heuristic (libpng default), compression"); + fprintf(STDERR, + " level (zlib default),\n and zlib version (%s)?\n\n", + ZLIB_VERSION); + wrote_question = 1; + } + + FCLOSE(fpin); + FCLOSE(fpout); + + if (strict != 0 && unsupported_chunks == 0) + return (1); + + else + return (0); + } + + if (num_in == 0) + break; + + if (memcmp(inbuf, outbuf, num_in)) + { + fprintf(STDERR, "\nFiles %s and %s are different\n", inname, + outname); + + if (wrote_question == 0 && unsupported_chunks == 0) + { + fprintf(STDERR, + " Was %s written with the same maximum" + " IDAT chunk size (%d bytes),", + inname, PNG_ZBUF_SIZE); + fprintf(STDERR, + "\n filtering heuristic (libpng default), compression"); + fprintf(STDERR, + " level (zlib default),\n and zlib version (%s)?\n\n", + ZLIB_VERSION); + wrote_question = 1; + } + + FCLOSE(fpin); + FCLOSE(fpout); + + /* NOTE: the unsupported_chunks escape is permitted here because + * unsupported text chunk compression will result in the compression + * mode being changed (to NONE) yet, in the test case, the result + * can be exactly the same size! + */ + if (strict != 0 && unsupported_chunks == 0) + return (1); + + else + return (0); + } + } + } +#endif /* WRITE && WRITE_FILTER */ + + FCLOSE(fpin); + FCLOSE(fpout); + + return (0); +} + +/* Input and output filenames */ +#ifdef RISCOS +static const char *inname = "pngtest/png"; +static const char *outname = "pngout/png"; +#else +static const char *inname = "pngtest.png"; +static const char *outname = "pngout.png"; +#endif + +int +main(int argc, char *argv[]) +{ + int multiple = 0; + int ierror = 0; + + png_structp dummy_ptr; + + fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING); + fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); + fprintf(STDERR, "%s", png_get_copyright(NULL)); + /* Show the version of libpng used in building the library */ + fprintf(STDERR, " library (%lu):%s", + (unsigned long)png_access_version_number(), + png_get_header_version(NULL)); + + /* Show the version of libpng used in building the application */ + fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, + PNG_HEADER_VERSION_STRING); + + /* Do some consistency checking on the memory allocation settings, I'm + * not sure this matters, but it is nice to know, the first of these + * tests should be impossible because of the way the macros are set + * in pngconf.h + */ +#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) + fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n"); +#endif + /* I think the following can happen. */ +#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K) + fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n"); +#endif + + if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING)) + { + fprintf(STDERR, + "Warning: versions are different between png.h and png.c\n"); + fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING); + fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver); + ++ierror; + } + + if (argc > 1) + { + if (strcmp(argv[1], "-m") == 0) + { + multiple = 1; + status_dots_requested = 0; + } + + else if (strcmp(argv[1], "-mv") == 0 || + strcmp(argv[1], "-vm") == 0 ) + { + multiple = 1; + verbose = 1; + status_dots_requested = 1; + } + + else if (strcmp(argv[1], "-v") == 0) + { + verbose = 1; + status_dots_requested = 1; + inname = argv[2]; + } + + else if (strcmp(argv[1], "--strict") == 0) + { + status_dots_requested = 0; + verbose = 1; + inname = argv[2]; + strict++; + relaxed = 0; + multiple=1; + } + + else if (strcmp(argv[1], "--relaxed") == 0) + { + status_dots_requested = 0; + verbose = 1; + inname = argv[2]; + strict = 0; + relaxed++; + multiple=1; + } + else if (strcmp(argv[1], "--xfail") == 0) + { + status_dots_requested = 0; + verbose = 1; + inname = argv[2]; + strict = 0; + xfail++; + relaxed++; + multiple=1; + } + + else + { + inname = argv[1]; + status_dots_requested = 0; + } + } + + if (multiple == 0 && argc == 3 + verbose) + outname = argv[2 + verbose]; + + if ((multiple == 0 && argc > 3 + verbose) || + (multiple != 0 && argc < 2)) + { + fprintf(STDERR, + "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", + argv[0], argv[0]); + fprintf(STDERR, + " reads/writes one PNG file (without -m) or multiple files (-m)\n"); + fprintf(STDERR, + " with -m %s is used as a temporary file\n", outname); + exit(1); + } + + if (multiple != 0) + { + int i; +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + int allocation_now = current_allocation; +#endif + for (i=2; i 0 + fprintf(STDERR, "\n"); +#endif + kerror = test_one_file(argv[i], outname); + if (kerror == 0) + { +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + fprintf(STDERR, "\n PASS (%lu zero samples)\n", + (unsigned long)zero_samples); +#else + fprintf(STDERR, " PASS\n"); +#endif +#ifdef PNG_TIME_RFC1123_SUPPORTED + if (tIME_chunk_present != 0) + fprintf(STDERR, " tIME = %s\n", tIME_string); + + tIME_chunk_present = 0; +#endif /* TIME_RFC1123 */ + } + + else + { + if (xfail) + fprintf(STDERR, " XFAIL\n"); + else + { + fprintf(STDERR, " FAIL\n"); + ierror += kerror; + } + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + if (allocation_now != current_allocation) + fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", + current_allocation - allocation_now); + + if (current_allocation != 0) + { + memory_infop pinfo = pinformation; + + fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", + current_allocation); + + while (pinfo != NULL) + { + fprintf(STDERR, " %lu bytes at %p\n", + (unsigned long)pinfo->size, + pinfo->pointer); + pinfo = pinfo->next; + } + } +#endif + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + fprintf(STDERR, " Current memory allocation: %10d bytes\n", + current_allocation); + fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", + maximum_allocation); + fprintf(STDERR, " Total memory allocation: %10d bytes\n", + total_allocation); + fprintf(STDERR, " Number of allocations: %10d\n", + num_allocations); +#endif + } + + else + { + int i; + for (i = 0; i<3; ++i) + { + int kerror; +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + int allocation_now = current_allocation; +#endif + if (i == 1) + status_dots_requested = 1; + + else if (verbose == 0) + status_dots_requested = 0; + + if (i == 0 || verbose == 1 || ierror != 0) + { + fprintf(STDERR, "\n Testing %s:", inname); +#if PNG_DEBUG > 0 + fprintf(STDERR, "\n"); +#endif + } + + kerror = test_one_file(inname, outname); + + if (kerror == 0) + { + if (verbose == 1 || i == 2) + { +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + fprintf(STDERR, "\n PASS (%lu zero samples)\n", + (unsigned long)zero_samples); +#else + fprintf(STDERR, " PASS\n"); +#endif +#ifdef PNG_TIME_RFC1123_SUPPORTED + if (tIME_chunk_present != 0) + fprintf(STDERR, " tIME = %s\n", tIME_string); +#endif /* TIME_RFC1123 */ + } + } + + else + { + if (verbose == 0 && i != 2) + { + fprintf(STDERR, "\n Testing %s:", inname); +#if PNG_DEBUG > 0 + fprintf(STDERR, "\n"); +#endif + } + + if (xfail) + fprintf(STDERR, " XFAIL\n"); + else + { + fprintf(STDERR, " FAIL\n"); + ierror += kerror; + } + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + if (allocation_now != current_allocation) + fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", + current_allocation - allocation_now); + + if (current_allocation != 0) + { + memory_infop pinfo = pinformation; + + fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", + current_allocation); + + while (pinfo != NULL) + { + fprintf(STDERR, " %lu bytes at %p\n", + (unsigned long)pinfo->size, pinfo->pointer); + pinfo = pinfo->next; + } + } +#endif + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + fprintf(STDERR, " Current memory allocation: %10d bytes\n", + current_allocation); + fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", + maximum_allocation); + fprintf(STDERR, " Total memory allocation: %10d bytes\n", + total_allocation); + fprintf(STDERR, " Number of allocations: %10d\n", + num_allocations); +#endif + } + +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_misc += (t_stop - t_start); + t_start = t_stop; + fprintf(STDERR, " CPU time used = %.3f seconds", + (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " (decoding %.3f,\n", + t_decode/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " encoding %.3f ,", + t_encode/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " other %.3f seconds)\n\n", + t_misc/(float)CLOCKS_PER_SEC); +#endif + + if (ierror == 0) + fprintf(STDERR, " libpng passes test\n"); + + else + fprintf(STDERR, " libpng FAILS test\n"); + + dummy_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + fprintf(STDERR, " Default limits:\n"); + fprintf(STDERR, " width_max = %lu\n", + (unsigned long) png_get_user_width_max(dummy_ptr)); + fprintf(STDERR, " height_max = %lu\n", + (unsigned long) png_get_user_height_max(dummy_ptr)); + if (png_get_chunk_cache_max(dummy_ptr) == 0) + fprintf(STDERR, " cache_max = unlimited\n"); + else + fprintf(STDERR, " cache_max = %lu\n", + (unsigned long) png_get_chunk_cache_max(dummy_ptr)); + if (png_get_chunk_malloc_max(dummy_ptr) == 0) + fprintf(STDERR, " malloc_max = unlimited\n"); + else + fprintf(STDERR, " malloc_max = %lu\n", + (unsigned long) png_get_chunk_malloc_max(dummy_ptr)); + png_destroy_read_struct(&dummy_ptr, NULL, NULL); + + return (int)(ierror != 0); +} +#else +int +main(void) +{ + fprintf(STDERR, + " test ignored because libpng was not built with read support\n"); + /* And skip this test */ + return PNG_LIBPNG_VER < 10600 ? 0 : 77; +} +#endif + +/* Generate a compiler error if there is an old png.h in the search path. */ +typedef png_libpng_version_1_6_37 Your_png_h_is_not_version_1_6_37; diff --git a/extern/libpng/pngtrans.c b/extern/libpng/pngtrans.c new file mode 100644 index 000000000..1100f46eb --- /dev/null +++ b/extern/libpng/pngtrans.c @@ -0,0 +1,864 @@ + +/* pngtrans.c - transforms the data in a row (used by both readers and writers) + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Turn on BGR-to-RGB mapping */ +void PNGAPI +png_set_bgr(png_structrp png_ptr) +{ + png_debug(1, "in png_set_bgr"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_BGR; +} +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Turn on 16-bit byte swapping */ +void PNGAPI +png_set_swap(png_structrp png_ptr) +{ + png_debug(1, "in png_set_swap"); + + if (png_ptr == NULL) + return; + + if (png_ptr->bit_depth == 16) + png_ptr->transformations |= PNG_SWAP_BYTES; +} +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* Turn on pixel packing */ +void PNGAPI +png_set_packing(png_structrp png_ptr) +{ + png_debug(1, "in png_set_packing"); + + if (png_ptr == NULL) + return; + + if (png_ptr->bit_depth < 8) + { + png_ptr->transformations |= PNG_PACK; +# ifdef PNG_WRITE_SUPPORTED + png_ptr->usr_bit_depth = 8; +# endif + } +} +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* Turn on packed pixel swapping */ +void PNGAPI +png_set_packswap(png_structrp png_ptr) +{ + png_debug(1, "in png_set_packswap"); + + if (png_ptr == NULL) + return; + + if (png_ptr->bit_depth < 8) + png_ptr->transformations |= PNG_PACKSWAP; +} +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +void PNGAPI +png_set_shift(png_structrp png_ptr, png_const_color_8p true_bits) +{ + png_debug(1, "in png_set_shift"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_SHIFT; + png_ptr->shift = *true_bits; +} +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +int PNGAPI +png_set_interlace_handling(png_structrp png_ptr) +{ + png_debug(1, "in png_set_interlace handling"); + + if (png_ptr != 0 && png_ptr->interlaced != 0) + { + png_ptr->transformations |= PNG_INTERLACE; + return (7); + } + + return (1); +} +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte on read, or remove a filler or alpha byte on write. + * The filler type has changed in v0.95 to allow future 2-byte fillers + * for 48-bit input data, as well as to avoid problems with some compilers + * that don't like bytes as parameters. + */ +void PNGAPI +png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc) +{ + png_debug(1, "in png_set_filler"); + + if (png_ptr == NULL) + return; + + /* In libpng 1.6 it is possible to determine whether this is a read or write + * operation and therefore to do more checking here for a valid call. + */ + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) + { +# ifdef PNG_READ_FILLER_SUPPORTED + /* On read png_set_filler is always valid, regardless of the base PNG + * format, because other transformations can give a format where the + * filler code can execute (basically an 8 or 16-bit component RGB or G + * format.) + * + * NOTE: usr_channels is not used by the read code! (This has led to + * confusion in the past.) The filler is only used in the read code. + */ + png_ptr->filler = (png_uint_16)filler; +# else + png_app_error(png_ptr, "png_set_filler not supported on read"); + PNG_UNUSED(filler) /* not used in the write case */ + return; +# endif + } + + else /* write */ + { +# ifdef PNG_WRITE_FILLER_SUPPORTED + /* On write the usr_channels parameter must be set correctly at the + * start to record the number of channels in the app-supplied data. + */ + switch (png_ptr->color_type) + { + case PNG_COLOR_TYPE_RGB: + png_ptr->usr_channels = 4; + break; + + case PNG_COLOR_TYPE_GRAY: + if (png_ptr->bit_depth >= 8) + { + png_ptr->usr_channels = 2; + break; + } + + else + { + /* There simply isn't any code in libpng to strip out bits + * from bytes when the components are less than a byte in + * size! + */ + png_app_error(png_ptr, + "png_set_filler is invalid for" + " low bit depth gray output"); + return; + } + + default: + png_app_error(png_ptr, + "png_set_filler: inappropriate color type"); + return; + } +# else + png_app_error(png_ptr, "png_set_filler not supported on write"); + return; +# endif + } + + /* Here on success - libpng supports the operation, set the transformation + * and the flag to say where the filler channel is. + */ + png_ptr->transformations |= PNG_FILLER; + + if (filler_loc == PNG_FILLER_AFTER) + png_ptr->flags |= PNG_FLAG_FILLER_AFTER; + + else + png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; +} + +/* Added to libpng-1.2.7 */ +void PNGAPI +png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc) +{ + png_debug(1, "in png_set_add_alpha"); + + if (png_ptr == NULL) + return; + + png_set_filler(png_ptr, filler, filler_loc); + /* The above may fail to do anything. */ + if ((png_ptr->transformations & PNG_FILLER) != 0) + png_ptr->transformations |= PNG_ADD_ALPHA; +} + +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +void PNGAPI +png_set_swap_alpha(png_structrp png_ptr) +{ + png_debug(1, "in png_set_swap_alpha"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_SWAP_ALPHA; +} +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +void PNGAPI +png_set_invert_alpha(png_structrp png_ptr) +{ + png_debug(1, "in png_set_invert_alpha"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_INVERT_ALPHA; +} +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +void PNGAPI +png_set_invert_mono(png_structrp png_ptr) +{ + png_debug(1, "in png_set_invert_mono"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_INVERT_MONO; +} + +/* Invert monochrome grayscale data */ +void /* PRIVATE */ +png_do_invert(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_invert"); + + /* This test removed from libpng version 1.0.13 and 1.2.0: + * if (row_info->bit_depth == 1 && + */ + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + png_bytep rp = row; + size_t i; + size_t istop = row_info->rowbytes; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(~(*rp)); + rp++; + } + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + row_info->bit_depth == 8) + { + png_bytep rp = row; + size_t i; + size_t istop = row_info->rowbytes; + + for (i = 0; i < istop; i += 2) + { + *rp = (png_byte)(~(*rp)); + rp += 2; + } + } + +#ifdef PNG_16BIT_SUPPORTED + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + row_info->bit_depth == 16) + { + png_bytep rp = row; + size_t i; + size_t istop = row_info->rowbytes; + + for (i = 0; i < istop; i += 4) + { + *rp = (png_byte)(~(*rp)); + *(rp + 1) = (png_byte)(~(*(rp + 1))); + rp += 4; + } + } +#endif +} +#endif + +#ifdef PNG_16BIT_SUPPORTED +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Swaps byte order on 16-bit depth images */ +void /* PRIVATE */ +png_do_swap(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_swap"); + + if (row_info->bit_depth == 16) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop= row_info->width * row_info->channels; + + for (i = 0; i < istop; i++, rp += 2) + { +#ifdef PNG_BUILTIN_BSWAP16_SUPPORTED + /* Feature added to libpng-1.6.11 for testing purposes, not + * enabled by default. + */ + *(png_uint_16*)rp = __builtin_bswap16(*(png_uint_16*)rp); +#else + png_byte t = *rp; + *rp = *(rp + 1); + *(rp + 1) = t; +#endif + } + } +} +#endif +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) +static const png_byte onebppswaptable[256] = { + 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, + 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, + 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, + 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, + 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, + 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, + 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, + 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, + 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, + 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, + 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, + 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, + 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, + 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, + 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, + 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, + 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, + 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, + 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, + 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, + 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, + 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, + 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, + 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, + 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, + 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, + 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, + 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, + 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, + 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, + 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, + 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF +}; + +static const png_byte twobppswaptable[256] = { + 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0, + 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0, + 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4, + 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4, + 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8, + 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8, + 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC, + 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC, + 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1, + 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1, + 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5, + 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5, + 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9, + 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9, + 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD, + 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD, + 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2, + 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2, + 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6, + 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6, + 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA, + 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA, + 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE, + 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE, + 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3, + 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3, + 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7, + 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7, + 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB, + 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB, + 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF, + 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF +}; + +static const png_byte fourbppswaptable[256] = { + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, + 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0, + 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, + 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1, + 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72, + 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2, + 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, + 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3, + 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74, + 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4, + 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75, + 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5, + 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76, + 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6, + 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77, + 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7, + 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78, + 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8, + 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79, + 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9, + 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A, + 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA, + 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, + 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB, + 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C, + 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC, + 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D, + 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD, + 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E, + 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE, + 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, + 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF +}; + +/* Swaps pixel packing order within bytes */ +void /* PRIVATE */ +png_do_packswap(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_packswap"); + + if (row_info->bit_depth < 8) + { + png_bytep rp; + png_const_bytep end, table; + + end = row + row_info->rowbytes; + + if (row_info->bit_depth == 1) + table = onebppswaptable; + + else if (row_info->bit_depth == 2) + table = twobppswaptable; + + else if (row_info->bit_depth == 4) + table = fourbppswaptable; + + else + return; + + for (rp = row; rp < end; rp++) + *rp = table[*rp]; + } +} +#endif /* PACKSWAP || WRITE_PACKSWAP */ + +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +/* Remove a channel - this used to be 'png_do_strip_filler' but it used a + * somewhat weird combination of flags to determine what to do. All the calls + * to png_do_strip_filler are changed in 1.5.2 to call this instead with the + * correct arguments. + * + * The routine isn't general - the channel must be the channel at the start or + * end (not in the middle) of each pixel. + */ +void /* PRIVATE */ +png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) +{ + png_bytep sp = row; /* source pointer */ + png_bytep dp = row; /* destination pointer */ + png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */ + + /* At the start sp will point to the first byte to copy and dp to where + * it is copied to. ep always points just beyond the end of the row, so + * the loop simply copies (channels-1) channels until sp reaches ep. + * + * at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc. + * nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc. + */ + + /* GA, GX, XG cases */ + if (row_info->channels == 2) + { + if (row_info->bit_depth == 8) + { + if (at_start != 0) /* Skip initial filler */ + ++sp; + else /* Skip initial channel and, for sp, the filler */ + { + sp += 2; ++dp; + } + + /* For a 1 pixel wide image there is nothing to do */ + while (sp < ep) + { + *dp++ = *sp; sp += 2; + } + + row_info->pixel_depth = 8; + } + + else if (row_info->bit_depth == 16) + { + if (at_start != 0) /* Skip initial filler */ + sp += 2; + else /* Skip initial channel and, for sp, the filler */ + { + sp += 4; dp += 2; + } + + while (sp < ep) + { + *dp++ = *sp++; *dp++ = *sp; sp += 3; + } + + row_info->pixel_depth = 16; + } + + else + return; /* bad bit depth */ + + row_info->channels = 1; + + /* Finally fix the color type if it records an alpha channel */ + if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + row_info->color_type = PNG_COLOR_TYPE_GRAY; + } + + /* RGBA, RGBX, XRGB cases */ + else if (row_info->channels == 4) + { + if (row_info->bit_depth == 8) + { + if (at_start != 0) /* Skip initial filler */ + ++sp; + else /* Skip initial channels and, for sp, the filler */ + { + sp += 4; dp += 3; + } + + /* Note that the loop adds 3 to dp and 4 to sp each time. */ + while (sp < ep) + { + *dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp; sp += 2; + } + + row_info->pixel_depth = 24; + } + + else if (row_info->bit_depth == 16) + { + if (at_start != 0) /* Skip initial filler */ + sp += 2; + else /* Skip initial channels and, for sp, the filler */ + { + sp += 8; dp += 6; + } + + while (sp < ep) + { + /* Copy 6 bytes, skip 2 */ + *dp++ = *sp++; *dp++ = *sp++; + *dp++ = *sp++; *dp++ = *sp++; + *dp++ = *sp++; *dp++ = *sp; sp += 3; + } + + row_info->pixel_depth = 48; + } + + else + return; /* bad bit depth */ + + row_info->channels = 3; + + /* Finally fix the color type if it records an alpha channel */ + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + row_info->color_type = PNG_COLOR_TYPE_RGB; + } + + else + return; /* The filler channel has gone already */ + + /* Fix the rowbytes value. */ + row_info->rowbytes = (size_t)(dp-row); +} +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Swaps red and blue bytes within a pixel */ +void /* PRIVATE */ +png_do_bgr(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_bgr"); + + if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 3) + { + png_byte save = *rp; + *rp = *(rp + 2); + *(rp + 2) = save; + } + } + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 4) + { + png_byte save = *rp; + *rp = *(rp + 2); + *(rp + 2) = save; + } + } + } + +#ifdef PNG_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 6) + { + png_byte save = *rp; + *rp = *(rp + 4); + *(rp + 4) = save; + save = *(rp + 1); + *(rp + 1) = *(rp + 5); + *(rp + 5) = save; + } + } + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 8) + { + png_byte save = *rp; + *rp = *(rp + 4); + *(rp + 4) = save; + save = *(rp + 1); + *(rp + 1) = *(rp + 5); + *(rp + 5) = save; + } + } + } +#endif + } +} +#endif /* READ_BGR || WRITE_BGR */ + +#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ + defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) +/* Added at libpng-1.5.10 */ +void /* PRIVATE */ +png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info) +{ + if (png_ptr->num_palette < (1 << row_info->bit_depth) && + png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */ + { + /* Calculations moved outside switch in an attempt to stop different + * compiler warnings. 'padding' is in *bits* within the last byte, it is + * an 'int' because pixel_depth becomes an 'int' in the expression below, + * and this calculation is used because it avoids warnings that other + * forms produced on either GCC or MSVC. + */ + int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width); + png_bytep rp = png_ptr->row_buf + row_info->rowbytes - 1; + + switch (row_info->bit_depth) + { + case 1: + { + /* in this case, all bytes must be 0 so we don't need + * to unpack the pixels except for the rightmost one. + */ + for (; rp > png_ptr->row_buf; rp--) + { + if ((*rp >> padding) != 0) + png_ptr->num_palette_max = 1; + padding = 0; + } + + break; + } + + case 2: + { + for (; rp > png_ptr->row_buf; rp--) + { + int i = ((*rp >> padding) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 2) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 4) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 6) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + padding = 0; + } + + break; + } + + case 4: + { + for (; rp > png_ptr->row_buf; rp--) + { + int i = ((*rp >> padding) & 0x0f); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 4) & 0x0f); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + padding = 0; + } + + break; + } + + case 8: + { + for (; rp > png_ptr->row_buf; rp--) + { + if (*rp > png_ptr->num_palette_max) + png_ptr->num_palette_max = (int) *rp; + } + + break; + } + + default: + break; + } + } +} +#endif /* CHECK_FOR_INVALID_INDEX */ + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +void PNGAPI +png_set_user_transform_info(png_structrp png_ptr, png_voidp + user_transform_ptr, int user_transform_depth, int user_transform_channels) +{ + png_debug(1, "in png_set_user_transform_info"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + (png_ptr->flags & PNG_FLAG_ROW_INIT) != 0) + { + png_app_error(png_ptr, + "info change after png_start_read_image or png_read_update_info"); + return; + } +#endif + + png_ptr->user_transform_ptr = user_transform_ptr; + png_ptr->user_transform_depth = (png_byte)user_transform_depth; + png_ptr->user_transform_channels = (png_byte)user_transform_channels; +} +#endif + +/* This function returns a pointer to the user_transform_ptr associated with + * the user transform functions. The application should free any memory + * associated with this pointer before png_write_destroy and png_read_destroy + * are called. + */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +png_voidp PNGAPI +png_get_user_transform_ptr(png_const_structrp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + + return png_ptr->user_transform_ptr; +} +#endif + +#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED +png_uint_32 PNGAPI +png_get_current_row_number(png_const_structrp png_ptr) +{ + /* See the comments in png.h - this is the sub-image row when reading an + * interlaced image. + */ + if (png_ptr != NULL) + return png_ptr->row_number; + + return PNG_UINT_32_MAX; /* help the app not to fail silently */ +} + +png_byte PNGAPI +png_get_current_pass_number(png_const_structrp png_ptr) +{ + if (png_ptr != NULL) + return png_ptr->pass; + return 8; /* invalid */ +} +#endif /* USER_TRANSFORM_INFO */ +#endif /* READ_USER_TRANSFORM || WRITE_USER_TRANSFORM */ +#endif /* READ || WRITE */ diff --git a/extern/libpng/pngwio.c b/extern/libpng/pngwio.c new file mode 100644 index 000000000..10e919dd0 --- /dev/null +++ b/extern/libpng/pngwio.c @@ -0,0 +1,168 @@ + +/* pngwio.c - functions for data output + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2014,2016,2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all output. Users who need + * special handling are expected to write functions that have the same + * arguments as these and perform similar functions, but that possibly + * use different output methods. Note that you shouldn't change these + * functions, but rather write replacement functions and then change + * them at run time with png_set_write_fn(...). + */ + +#include "pngpriv.h" + +#ifdef PNG_WRITE_SUPPORTED + +/* Write the data to whatever output you are using. The default routine + * writes to a file pointer. Note that this routine sometimes gets called + * with very small lengths, so you should implement some kind of simple + * buffering if you are using unbuffered writes. This should never be asked + * to write more than 64K on a 16-bit machine. + */ + +void /* PRIVATE */ +png_write_data(png_structrp png_ptr, png_const_bytep data, size_t length) +{ + /* NOTE: write_data_fn must not change the buffer! */ + if (png_ptr->write_data_fn != NULL ) + (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data), + length); + + else + png_error(png_ptr, "Call to NULL write function"); +} + +#ifdef PNG_STDIO_SUPPORTED +/* This is the function that does the actual writing of data. If you are + * not writing to a standard C stream, you should create a replacement + * write_data function and use it at run time with png_set_write_fn(), rather + * than changing the library. + */ +void PNGCBAPI +png_default_write_data(png_structp png_ptr, png_bytep data, size_t length) +{ + size_t check; + + if (png_ptr == NULL) + return; + + check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); + + if (check != length) + png_error(png_ptr, "Write Error"); +} +#endif + +/* This function is called to output any data pending writing (normally + * to disk). After png_flush is called, there should be no data pending + * writing in any buffers. + */ +#ifdef PNG_WRITE_FLUSH_SUPPORTED +void /* PRIVATE */ +png_flush(png_structrp png_ptr) +{ + if (png_ptr->output_flush_fn != NULL) + (*(png_ptr->output_flush_fn))(png_ptr); +} + +# ifdef PNG_STDIO_SUPPORTED +void PNGCBAPI +png_default_flush(png_structp png_ptr) +{ + png_FILE_p io_ptr; + + if (png_ptr == NULL) + return; + + io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr)); + fflush(io_ptr); +} +# endif +#endif + +/* This function allows the application to supply new output functions for + * libpng if standard C streams aren't being used. + * + * This function takes as its arguments: + * png_ptr - pointer to a png output data structure + * io_ptr - pointer to user supplied structure containing info about + * the output functions. May be NULL. + * write_data_fn - pointer to a new output function that takes as its + * arguments a pointer to a png_struct, a pointer to + * data to be written, and a 32-bit unsigned int that is + * the number of bytes to be written. The new write + * function should call png_error(png_ptr, "Error msg") + * to exit and output any fatal error messages. May be + * NULL, in which case libpng's default function will + * be used. + * flush_data_fn - pointer to a new flush function that takes as its + * arguments a pointer to a png_struct. After a call to + * the flush function, there should be no data in any buffers + * or pending transmission. If the output method doesn't do + * any buffering of output, a function prototype must still be + * supplied although it doesn't have to do anything. If + * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile + * time, output_flush_fn will be ignored, although it must be + * supplied for compatibility. May be NULL, in which case + * libpng's default function will be used, if + * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not + * a good idea if io_ptr does not point to a standard + * *FILE structure. + */ +void PNGAPI +png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr, + png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->io_ptr = io_ptr; + +#ifdef PNG_STDIO_SUPPORTED + if (write_data_fn != NULL) + png_ptr->write_data_fn = write_data_fn; + + else + png_ptr->write_data_fn = png_default_write_data; +#else + png_ptr->write_data_fn = write_data_fn; +#endif + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +# ifdef PNG_STDIO_SUPPORTED + + if (output_flush_fn != NULL) + png_ptr->output_flush_fn = output_flush_fn; + + else + png_ptr->output_flush_fn = png_default_flush; + +# else + png_ptr->output_flush_fn = output_flush_fn; +# endif +#else + PNG_UNUSED(output_flush_fn) +#endif /* WRITE_FLUSH */ + +#ifdef PNG_READ_SUPPORTED + /* It is an error to read while writing a png file */ + if (png_ptr->read_data_fn != NULL) + { + png_ptr->read_data_fn = NULL; + + png_warning(png_ptr, + "Can't set both read_data_fn and write_data_fn in the" + " same structure"); + } +#endif +} +#endif /* WRITE */ diff --git a/extern/libpng/pngwrite.c b/extern/libpng/pngwrite.c new file mode 100644 index 000000000..59377a4dd --- /dev/null +++ b/extern/libpng/pngwrite.c @@ -0,0 +1,2395 @@ + +/* pngwrite.c - general routines to write a PNG file + * + * Copyright (c) 2018-2019 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" +#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED +# include +#endif /* SIMPLIFIED_WRITE_STDIO */ + +#ifdef PNG_WRITE_SUPPORTED + +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +/* Write out all the unknown chunks for the current given location */ +static void +write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr, + unsigned int where) +{ + if (info_ptr->unknown_chunks_num != 0) + { + png_const_unknown_chunkp up; + + png_debug(5, "writing extra chunks"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + ++up) + if ((up->location & where) != 0) + { + /* If per-chunk unknown chunk handling is enabled use it, otherwise + * just write the chunks the application has set. + */ +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + int keep = png_handle_as_unknown(png_ptr, up->name); + + /* NOTE: this code is radically different from the read side in the + * matter of handling an ancillary unknown chunk. In the read side + * the default behavior is to discard it, in the code below the default + * behavior is to write it. Critical chunks are, however, only + * written if explicitly listed or if the default is set to write all + * unknown chunks. + * + * The default handling is also slightly weird - it is not possible to + * stop the writing of all unsafe-to-copy chunks! + * + * TODO: REVIEW: this would seem to be a bug. + */ + if (keep != PNG_HANDLE_CHUNK_NEVER && + ((up->name[3] & 0x20) /* safe-to-copy overrides everything */ || + keep == PNG_HANDLE_CHUNK_ALWAYS || + (keep == PNG_HANDLE_CHUNK_AS_DEFAULT && + png_ptr->unknown_default == PNG_HANDLE_CHUNK_ALWAYS))) +#endif + { + /* TODO: review, what is wrong with a zero length unknown chunk? */ + if (up->size == 0) + png_warning(png_ptr, "Writing zero-length unknown chunk"); + + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +} +#endif /* WRITE_UNKNOWN_CHUNKS */ + +/* Writes all the PNG information. This is the suggested way to use the + * library. If you have a new chunk to add, make a function to write it, + * and put it in the correct location here. If you want the chunk written + * after the image data, put it in png_write_end(). I strongly encourage + * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing + * the chunk, as that will keep the code from breaking if you want to just + * write a plain PNG file. If you have long comments, I suggest writing + * them in png_write_end(), and compressing them. + */ +void PNGAPI +png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr) +{ + png_debug(1, "in png_write_info_before_PLTE"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0) + { + /* Write PNG signature */ + png_write_sig(png_ptr); + +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \ + png_ptr->mng_features_permitted != 0) + { + png_warning(png_ptr, + "MNG features are not allowed in a PNG datastream"); + png_ptr->mng_features_permitted = 0; + } +#endif + + /* Write IHDR information. */ + png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, + info_ptr->filter_type, +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + info_ptr->interlace_type +#else + 0 +#endif + ); + + /* The rest of these check to see if the valid field has the appropriate + * flag set, and if it does, writes the chunk. + * + * 1.6.0: COLORSPACE support controls the writing of these chunks too, and + * the chunks will be written if the WRITE routine is there and + * information * is available in the COLORSPACE. (See + * png_colorspace_sync_info in png.c for where the valid flags get set.) + * + * Under certain circumstances the colorspace can be invalidated without + * syncing the info_struct 'valid' flags; this happens if libpng detects + * an error and calls png_error while the color space is being set, yet + * the application continues writing the PNG. So check the 'invalid' + * flag here too. + */ +#ifdef PNG_GAMMA_SUPPORTED +# ifdef PNG_WRITE_gAMA_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_gAMA) != 0 && + (info_ptr->valid & PNG_INFO_gAMA) != 0) + png_write_gAMA_fixed(png_ptr, info_ptr->colorspace.gamma); +# endif +#endif + +#ifdef PNG_COLORSPACE_SUPPORTED + /* Write only one of sRGB or an ICC profile. If a profile was supplied + * and it matches one of the known sRGB ones issue a warning. + */ +# ifdef PNG_WRITE_iCCP_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->valid & PNG_INFO_iCCP) != 0) + { +# ifdef PNG_WRITE_sRGB_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sRGB) != 0) + png_app_warning(png_ptr, + "profile matches sRGB but writing iCCP instead"); +# endif + + png_write_iCCP(png_ptr, info_ptr->iccp_name, + info_ptr->iccp_profile); + } +# ifdef PNG_WRITE_sRGB_SUPPORTED + else +# endif +# endif + +# ifdef PNG_WRITE_sRGB_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->valid & PNG_INFO_sRGB) != 0) + png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent); +# endif /* WRITE_sRGB */ +#endif /* COLORSPACE */ + +#ifdef PNG_WRITE_sBIT_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sBIT) != 0) + png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); +#endif + +#ifdef PNG_COLORSPACE_SUPPORTED +# ifdef PNG_WRITE_cHRM_SUPPORTED + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 && + (info_ptr->valid & PNG_INFO_cHRM) != 0) + png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy); +# endif +#endif + +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR); +#endif + + png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; + } +} + +void PNGAPI +png_write_info(png_structrp png_ptr, png_const_inforp info_ptr) +{ +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) + int i; +#endif + + png_debug(1, "in png_write_info"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_write_info_before_PLTE(png_ptr, info_ptr); + + if ((info_ptr->valid & PNG_INFO_PLTE) != 0) + png_write_PLTE(png_ptr, info_ptr->palette, + (png_uint_32)info_ptr->num_palette); + + else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Valid palette required for paletted images"); + +#ifdef PNG_WRITE_tRNS_SUPPORTED + if ((info_ptr->valid & PNG_INFO_tRNS) !=0) + { +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel (in tRNS) */ + if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0 && + info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + int j, jend; + + jend = info_ptr->num_trans; + if (jend > PNG_MAX_PALETTE_LENGTH) + jend = PNG_MAX_PALETTE_LENGTH; + + for (j = 0; jtrans_alpha[j] = + (png_byte)(255 - info_ptr->trans_alpha[j]); + } +#endif + png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color), + info_ptr->num_trans, info_ptr->color_type); + } +#endif +#ifdef PNG_WRITE_bKGD_SUPPORTED + if ((info_ptr->valid & PNG_INFO_bKGD) != 0) + png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); +#endif + +#ifdef PNG_WRITE_eXIf_SUPPORTED + if ((info_ptr->valid & PNG_INFO_eXIf) != 0) + png_write_eXIf(png_ptr, info_ptr->exif, info_ptr->num_exif); +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED + if ((info_ptr->valid & PNG_INFO_hIST) != 0) + png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED + if ((info_ptr->valid & PNG_INFO_oFFs) != 0) + png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, + info_ptr->offset_unit_type); +#endif + +#ifdef PNG_WRITE_pCAL_SUPPORTED + if ((info_ptr->valid & PNG_INFO_pCAL) != 0) + png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, + info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, + info_ptr->pcal_units, info_ptr->pcal_params); +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sCAL) != 0) + png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, + info_ptr->scal_s_width, info_ptr->scal_s_height); +#endif /* sCAL */ + +#ifdef PNG_WRITE_pHYs_SUPPORTED + if ((info_ptr->valid & PNG_INFO_pHYs) != 0) + png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, + info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); +#endif /* pHYs */ + +#ifdef PNG_WRITE_tIME_SUPPORTED + if ((info_ptr->valid & PNG_INFO_tIME) != 0) + { + png_write_tIME(png_ptr, &(info_ptr->mod_time)); + png_ptr->mode |= PNG_WROTE_tIME; + } +#endif /* tIME */ + +#ifdef PNG_WRITE_sPLT_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sPLT) != 0) + for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) + png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); +#endif /* sPLT */ + +#ifdef PNG_WRITE_TEXT_SUPPORTED + /* Check to see if we need to write text chunks */ + for (i = 0; i < info_ptr->num_text; i++) + { + png_debug2(2, "Writing header text chunk %d, type %d", i, + info_ptr->text[i].compression); + /* An internationalized chunk? */ + if (info_ptr->text[i].compression > 0) + { +#ifdef PNG_WRITE_iTXt_SUPPORTED + /* Write international chunk */ + png_write_iTXt(png_ptr, + info_ptr->text[i].compression, + info_ptr->text[i].key, + info_ptr->text[i].lang, + info_ptr->text[i].lang_key, + info_ptr->text[i].text); + /* Mark this chunk as written */ + if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + else + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; +#else + png_warning(png_ptr, "Unable to write international text"); +#endif + } + + /* If we want a compressed text chunk */ + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) + { +#ifdef PNG_WRITE_zTXt_SUPPORTED + /* Write compressed chunk */ + png_write_zTXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, info_ptr->text[i].compression); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; +#else + png_warning(png_ptr, "Unable to write compressed text"); +#endif + } + + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + { +#ifdef PNG_WRITE_tEXt_SUPPORTED + /* Write uncompressed chunk */ + png_write_tEXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, + 0); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; +#else + /* Can't get here */ + png_warning(png_ptr, "Unable to write uncompressed text"); +#endif + } + } +#endif /* tEXt */ + +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_PLTE); +#endif +} + +/* Writes the end of the PNG file. If you don't want to write comments or + * time information, you can pass NULL for info. If you already wrote these + * in png_write_info(), do not write them again here. If you have long + * comments, I suggest writing them here, and compressing them. + */ +void PNGAPI +png_write_end(png_structrp png_ptr, png_inforp info_ptr) +{ + png_debug(1, "in png_write_end"); + + if (png_ptr == NULL) + return; + + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0) + png_error(png_ptr, "No IDATs written into file"); + +#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED + if (png_ptr->num_palette_max > png_ptr->num_palette) + png_benign_error(png_ptr, "Wrote palette index exceeding num_palette"); +#endif + + /* See if user wants us to write information chunks */ + if (info_ptr != NULL) + { +#ifdef PNG_WRITE_TEXT_SUPPORTED + int i; /* local index variable */ +#endif +#ifdef PNG_WRITE_tIME_SUPPORTED + /* Check to see if user has supplied a time chunk */ + if ((info_ptr->valid & PNG_INFO_tIME) != 0 && + (png_ptr->mode & PNG_WROTE_tIME) == 0) + png_write_tIME(png_ptr, &(info_ptr->mod_time)); + +#endif +#ifdef PNG_WRITE_TEXT_SUPPORTED + /* Loop through comment chunks */ + for (i = 0; i < info_ptr->num_text; i++) + { + png_debug2(2, "Writing trailer text chunk %d, type %d", i, + info_ptr->text[i].compression); + /* An internationalized chunk? */ + if (info_ptr->text[i].compression > 0) + { +#ifdef PNG_WRITE_iTXt_SUPPORTED + /* Write international chunk */ + png_write_iTXt(png_ptr, + info_ptr->text[i].compression, + info_ptr->text[i].key, + info_ptr->text[i].lang, + info_ptr->text[i].lang_key, + info_ptr->text[i].text); + /* Mark this chunk as written */ + if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + else + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; +#else + png_warning(png_ptr, "Unable to write international text"); +#endif + } + + else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) + { +#ifdef PNG_WRITE_zTXt_SUPPORTED + /* Write compressed chunk */ + png_write_zTXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, info_ptr->text[i].compression); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; +#else + png_warning(png_ptr, "Unable to write compressed text"); +#endif + } + + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + { +#ifdef PNG_WRITE_tEXt_SUPPORTED + /* Write uncompressed chunk */ + png_write_tEXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; +#else + png_warning(png_ptr, "Unable to write uncompressed text"); +#endif + } + } +#endif + +#ifdef PNG_WRITE_eXIf_SUPPORTED + if ((info_ptr->valid & PNG_INFO_eXIf) != 0) + png_write_eXIf(png_ptr, info_ptr->exif, info_ptr->num_exif); +#endif + +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + write_unknown_chunks(png_ptr, info_ptr, PNG_AFTER_IDAT); +#endif + } + + png_ptr->mode |= PNG_AFTER_IDAT; + + /* Write end of PNG file */ + png_write_IEND(png_ptr); + + /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03, + * and restored again in libpng-1.2.30, may cause some applications that + * do not set png_ptr->output_flush_fn to crash. If your application + * experiences a problem, please try building libpng with + * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to + * png-mng-implement at lists.sf.net . + */ +#ifdef PNG_WRITE_FLUSH_SUPPORTED +# ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED + png_flush(png_ptr); +# endif +#endif +} + +#ifdef PNG_CONVERT_tIME_SUPPORTED +void PNGAPI +png_convert_from_struct_tm(png_timep ptime, const struct tm * ttime) +{ + png_debug(1, "in png_convert_from_struct_tm"); + + ptime->year = (png_uint_16)(1900 + ttime->tm_year); + ptime->month = (png_byte)(ttime->tm_mon + 1); + ptime->day = (png_byte)ttime->tm_mday; + ptime->hour = (png_byte)ttime->tm_hour; + ptime->minute = (png_byte)ttime->tm_min; + ptime->second = (png_byte)ttime->tm_sec; +} + +void PNGAPI +png_convert_from_time_t(png_timep ptime, time_t ttime) +{ + struct tm *tbuf; + + png_debug(1, "in png_convert_from_time_t"); + + tbuf = gmtime(&ttime); + png_convert_from_struct_tm(ptime, tbuf); +} +#endif + +/* Initialize png_ptr structure, and allocate any memory needed */ +PNG_FUNCTION(png_structp,PNGAPI +png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) +{ +#ifndef PNG_USER_MEM_SUPPORTED + png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr, + error_fn, warn_fn, NULL, NULL, NULL); +#else + return png_create_write_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, NULL, NULL, NULL); +} + +/* Alternate initialize png_ptr structure, and allocate any memory needed */ +PNG_FUNCTION(png_structp,PNGAPI +png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) +{ + png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr, + error_fn, warn_fn, mem_ptr, malloc_fn, free_fn); +#endif /* USER_MEM */ + if (png_ptr != NULL) + { + /* Set the zlib control values to defaults; they can be overridden by the + * application after the struct has been created. + */ + png_ptr->zbuffer_size = PNG_ZBUF_SIZE; + + /* The 'zlib_strategy' setting is irrelevant because png_default_claim in + * pngwutil.c defaults it according to whether or not filters will be + * used, and ignores this setting. + */ + png_ptr->zlib_strategy = PNG_Z_DEFAULT_STRATEGY; + png_ptr->zlib_level = PNG_Z_DEFAULT_COMPRESSION; + png_ptr->zlib_mem_level = 8; + png_ptr->zlib_window_bits = 15; + png_ptr->zlib_method = 8; + +#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED + png_ptr->zlib_text_strategy = PNG_TEXT_Z_DEFAULT_STRATEGY; + png_ptr->zlib_text_level = PNG_TEXT_Z_DEFAULT_COMPRESSION; + png_ptr->zlib_text_mem_level = 8; + png_ptr->zlib_text_window_bits = 15; + png_ptr->zlib_text_method = 8; +#endif /* WRITE_COMPRESSED_TEXT */ + + /* This is a highly dubious configuration option; by default it is off, + * but it may be appropriate for private builds that are testing + * extensions not conformant to the current specification, or of + * applications that must not fail to write at all costs! + */ +#ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED + /* In stable builds only warn if an application error can be completely + * handled. + */ + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; +#endif + + /* App warnings are warnings in release (or release candidate) builds but + * are errors during development. + */ +#if PNG_RELEASE_BUILD + png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN; +#endif + + /* TODO: delay this, it can be done in png_init_io() (if the app doesn't + * do it itself) avoiding setting the default function if it is not + * required. + */ + png_set_write_fn(png_ptr, NULL, NULL, NULL); + } + + return png_ptr; +} + + +/* Write a few rows of image data. If the image is interlaced, + * either you will have to write the 7 sub images, or, if you + * have called png_set_interlace_handling(), you will have to + * "write" the image seven times. + */ +void PNGAPI +png_write_rows(png_structrp png_ptr, png_bytepp row, + png_uint_32 num_rows) +{ + png_uint_32 i; /* row counter */ + png_bytepp rp; /* row pointer */ + + png_debug(1, "in png_write_rows"); + + if (png_ptr == NULL) + return; + + /* Loop through the rows */ + for (i = 0, rp = row; i < num_rows; i++, rp++) + { + png_write_row(png_ptr, *rp); + } +} + +/* Write the image. You only need to call this function once, even + * if you are writing an interlaced image. + */ +void PNGAPI +png_write_image(png_structrp png_ptr, png_bytepp image) +{ + png_uint_32 i; /* row index */ + int pass, num_pass; /* pass variables */ + png_bytepp rp; /* points to current row */ + + if (png_ptr == NULL) + return; + + png_debug(1, "in png_write_image"); + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Initialize interlace handling. If image is not interlaced, + * this will set pass to 1 + */ + num_pass = png_set_interlace_handling(png_ptr); +#else + num_pass = 1; +#endif + /* Loop through passes */ + for (pass = 0; pass < num_pass; pass++) + { + /* Loop through image */ + for (i = 0, rp = image; i < png_ptr->height; i++, rp++) + { + png_write_row(png_ptr, *rp); + } + } +} + +#ifdef PNG_MNG_FEATURES_SUPPORTED +/* Performs intrapixel differencing */ +static void +png_do_write_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_intrapixel"); + + if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)(*rp - *(rp + 1)); + *(rp + 2) = (png_byte)(*(rp + 2) - *(rp + 1)); + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (png_uint_32)(*(rp ) << 8) | *(rp + 1); + png_uint_32 s1 = (png_uint_32)(*(rp + 2) << 8) | *(rp + 3); + png_uint_32 s2 = (png_uint_32)(*(rp + 4) << 8) | *(rp + 5); + png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL); + png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); + *(rp ) = (png_byte)(red >> 8); + *(rp + 1) = (png_byte)red; + *(rp + 4) = (png_byte)(blue >> 8); + *(rp + 5) = (png_byte)blue; + } + } +#endif /* WRITE_16BIT */ + } +} +#endif /* MNG_FEATURES */ + +/* Called by user to write a row of image data */ +void PNGAPI +png_write_row(png_structrp png_ptr, png_const_bytep row) +{ + /* 1.5.6: moved from png_struct to be a local structure: */ + png_row_info row_info; + + if (png_ptr == NULL) + return; + + png_debug2(1, "in png_write_row (row %u, pass %d)", + png_ptr->row_number, png_ptr->pass); + + /* Initialize transformations and other stuff if first time */ + if (png_ptr->row_number == 0 && png_ptr->pass == 0) + { + /* Make sure we wrote the header info */ + if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0) + png_error(png_ptr, + "png_write_info was never called before png_write_row"); + + /* Check for transforms that have been set but were defined out */ +#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) + if ((png_ptr->transformations & PNG_INVERT_MONO) != 0) + png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) + if ((png_ptr->transformations & PNG_FILLER) != 0) + png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined"); +#endif +#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ + defined(PNG_READ_PACKSWAP_SUPPORTED) + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + png_warning(png_ptr, + "PNG_WRITE_PACKSWAP_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) + if ((png_ptr->transformations & PNG_PACK) != 0) + png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) + if ((png_ptr->transformations & PNG_SHIFT) != 0) + png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) + if ((png_ptr->transformations & PNG_BGR) != 0) + png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) + if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0) + png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined"); +#endif + + png_write_start_row(png_ptr); + } + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced and not interested in row, return */ + if (png_ptr->interlaced != 0 && + (png_ptr->transformations & PNG_INTERLACE) != 0) + { + switch (png_ptr->pass) + { + case 0: + if ((png_ptr->row_number & 0x07) != 0) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 1: + if ((png_ptr->row_number & 0x07) != 0 || png_ptr->width < 5) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 2: + if ((png_ptr->row_number & 0x07) != 4) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 3: + if ((png_ptr->row_number & 0x03) != 0 || png_ptr->width < 3) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 4: + if ((png_ptr->row_number & 0x03) != 2) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 5: + if ((png_ptr->row_number & 0x01) != 0 || png_ptr->width < 2) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 6: + if ((png_ptr->row_number & 0x01) == 0) + { + png_write_finish_row(png_ptr); + return; + } + break; + + default: /* error: ignore it */ + break; + } + } +#endif + + /* Set up row info for transformations */ + row_info.color_type = png_ptr->color_type; + row_info.width = png_ptr->usr_width; + row_info.channels = png_ptr->usr_channels; + row_info.bit_depth = png_ptr->usr_bit_depth; + row_info.pixel_depth = (png_byte)(row_info.bit_depth * row_info.channels); + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); + + png_debug1(3, "row_info->color_type = %d", row_info.color_type); + png_debug1(3, "row_info->width = %u", row_info.width); + png_debug1(3, "row_info->channels = %d", row_info.channels); + png_debug1(3, "row_info->bit_depth = %d", row_info.bit_depth); + png_debug1(3, "row_info->pixel_depth = %d", row_info.pixel_depth); + png_debug1(3, "row_info->rowbytes = %lu", (unsigned long)row_info.rowbytes); + + /* Copy user's row into buffer, leaving room for filter byte. */ + memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes); + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Handle interlacing */ + if (png_ptr->interlaced && png_ptr->pass < 6 && + (png_ptr->transformations & PNG_INTERLACE) != 0) + { + png_do_write_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass); + /* This should always get caught above, but still ... */ + if (row_info.width == 0) + { + png_write_finish_row(png_ptr); + return; + } + } +#endif + +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED + /* Handle other transformations */ + if (png_ptr->transformations != 0) + png_do_write_transformations(png_ptr, &row_info); +#endif + + /* At this point the row_info pixel depth must match the 'transformed' depth, + * which is also the output depth. + */ + if (row_info.pixel_depth != png_ptr->pixel_depth || + row_info.pixel_depth != png_ptr->transformed_pixel_depth) + png_error(png_ptr, "internal write transform logic error"); + +#ifdef PNG_MNG_FEATURES_SUPPORTED + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && + (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) + { + /* Intrapixel differencing */ + png_do_write_intrapixel(&row_info, png_ptr->row_buf + 1); + } +#endif + +/* Added at libpng-1.5.10 */ +#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Check for out-of-range palette index */ + if (row_info.color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max >= 0) + png_do_check_palette_indexes(png_ptr, &row_info); +#endif + + /* Find a filter if necessary, filter the row and write it out. */ + png_write_find_filter(png_ptr, &row_info); + + if (png_ptr->write_row_fn != NULL) + (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); +} + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +/* Set the automatic flush interval or 0 to turn flushing off */ +void PNGAPI +png_set_flush(png_structrp png_ptr, int nrows) +{ + png_debug(1, "in png_set_flush"); + + if (png_ptr == NULL) + return; + + png_ptr->flush_dist = (nrows < 0 ? 0 : (png_uint_32)nrows); +} + +/* Flush the current output buffers now */ +void PNGAPI +png_write_flush(png_structrp png_ptr) +{ + png_debug(1, "in png_write_flush"); + + if (png_ptr == NULL) + return; + + /* We have already written out all of the data */ + if (png_ptr->row_number >= png_ptr->num_rows) + return; + + png_compress_IDAT(png_ptr, NULL, 0, Z_SYNC_FLUSH); + png_ptr->flush_rows = 0; + png_flush(png_ptr); +} +#endif /* WRITE_FLUSH */ + +/* Free any memory used in png_ptr struct without freeing the struct itself. */ +static void +png_write_destroy(png_structrp png_ptr) +{ + png_debug(1, "in png_write_destroy"); + + /* Free any memory zlib uses */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0) + deflateEnd(&png_ptr->zstream); + + /* Free our memory. png_free checks NULL for us. */ + png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list); + png_free(png_ptr, png_ptr->row_buf); + png_ptr->row_buf = NULL; +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_free(png_ptr, png_ptr->prev_row); + png_free(png_ptr, png_ptr->try_row); + png_free(png_ptr, png_ptr->tst_row); + png_ptr->prev_row = NULL; + png_ptr->try_row = NULL; + png_ptr->tst_row = NULL; +#endif + +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list = NULL; +#endif + + /* The error handling and memory handling information is left intact at this + * point: the jmp_buf may still have to be freed. See png_destroy_png_struct + * for how this happens. + */ +} + +/* Free all memory used by the write. + * In libpng 1.6.0 this API changed quietly to no longer accept a NULL value for + * *png_ptr_ptr. Prior to 1.6.0 it would accept such a value and it would free + * the passed in info_structs but it would quietly fail to free any of the data + * inside them. In 1.6.0 it quietly does nothing (it has to be quiet because it + * has no png_ptr.) + */ +void PNGAPI +png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) +{ + png_debug(1, "in png_destroy_write_struct"); + + if (png_ptr_ptr != NULL) + { + png_structrp png_ptr = *png_ptr_ptr; + + if (png_ptr != NULL) /* added in libpng 1.6.0 */ + { + png_destroy_info_struct(png_ptr, info_ptr_ptr); + + *png_ptr_ptr = NULL; + png_write_destroy(png_ptr); + png_destroy_png_struct(png_ptr); + } + } +} + +/* Allow the application to select one or more row filters to use. */ +void PNGAPI +png_set_filter(png_structrp png_ptr, int method, int filters) +{ + png_debug(1, "in png_set_filter"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && + (method == PNG_INTRAPIXEL_DIFFERENCING)) + method = PNG_FILTER_TYPE_BASE; + +#endif + if (method == PNG_FILTER_TYPE_BASE) + { + switch (filters & (PNG_ALL_FILTERS | 0x07)) + { +#ifdef PNG_WRITE_FILTER_SUPPORTED + case 5: + case 6: + case 7: png_app_error(png_ptr, "Unknown row filter for method 0"); +#endif /* WRITE_FILTER */ + /* FALLTHROUGH */ + case PNG_FILTER_VALUE_NONE: + png_ptr->do_filter = PNG_FILTER_NONE; break; + +#ifdef PNG_WRITE_FILTER_SUPPORTED + case PNG_FILTER_VALUE_SUB: + png_ptr->do_filter = PNG_FILTER_SUB; break; + + case PNG_FILTER_VALUE_UP: + png_ptr->do_filter = PNG_FILTER_UP; break; + + case PNG_FILTER_VALUE_AVG: + png_ptr->do_filter = PNG_FILTER_AVG; break; + + case PNG_FILTER_VALUE_PAETH: + png_ptr->do_filter = PNG_FILTER_PAETH; break; + + default: + png_ptr->do_filter = (png_byte)filters; break; +#else + default: + png_app_error(png_ptr, "Unknown row filter for method 0"); +#endif /* WRITE_FILTER */ + } + +#ifdef PNG_WRITE_FILTER_SUPPORTED + /* If we have allocated the row_buf, this means we have already started + * with the image and we should have allocated all of the filter buffers + * that have been selected. If prev_row isn't already allocated, then + * it is too late to start using the filters that need it, since we + * will be missing the data in the previous row. If an application + * wants to start and stop using particular filters during compression, + * it should start out with all of the filters, and then remove them + * or add them back after the start of compression. + * + * NOTE: this is a nasty constraint on the code, because it means that the + * prev_row buffer must be maintained even if there are currently no + * 'prev_row' requiring filters active. + */ + if (png_ptr->row_buf != NULL) + { + int num_filters; + png_alloc_size_t buf_size; + + /* Repeat the checks in png_write_start_row; 1 pixel high or wide + * images cannot benefit from certain filters. If this isn't done here + * the check below will fire on 1 pixel high images. + */ + if (png_ptr->height == 1) + filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH); + + if (png_ptr->width == 1) + filters &= ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH); + + if ((filters & (PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH)) != 0 + && png_ptr->prev_row == NULL) + { + /* This is the error case, however it is benign - the previous row + * is not available so the filter can't be used. Just warn here. + */ + png_app_warning(png_ptr, + "png_set_filter: UP/AVG/PAETH cannot be added after start"); + filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH); + } + + num_filters = 0; + + if (filters & PNG_FILTER_SUB) + num_filters++; + + if (filters & PNG_FILTER_UP) + num_filters++; + + if (filters & PNG_FILTER_AVG) + num_filters++; + + if (filters & PNG_FILTER_PAETH) + num_filters++; + + /* Allocate needed row buffers if they have not already been + * allocated. + */ + buf_size = PNG_ROWBYTES(png_ptr->usr_channels * png_ptr->usr_bit_depth, + png_ptr->width) + 1; + + if (png_ptr->try_row == NULL) + png_ptr->try_row = png_voidcast(png_bytep, + png_malloc(png_ptr, buf_size)); + + if (num_filters > 1) + { + if (png_ptr->tst_row == NULL) + png_ptr->tst_row = png_voidcast(png_bytep, + png_malloc(png_ptr, buf_size)); + } + } + png_ptr->do_filter = (png_byte)filters; +#endif + } + else + png_error(png_ptr, "Unknown custom filter method"); +} + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */ +/* Provide floating and fixed point APIs */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_filter_heuristics(png_structrp png_ptr, int heuristic_method, + int num_weights, png_const_doublep filter_weights, + png_const_doublep filter_costs) +{ + PNG_UNUSED(png_ptr) + PNG_UNUSED(heuristic_method) + PNG_UNUSED(num_weights) + PNG_UNUSED(filter_weights) + PNG_UNUSED(filter_costs) +} +#endif /* FLOATING_POINT */ + +#ifdef PNG_FIXED_POINT_SUPPORTED +void PNGAPI +png_set_filter_heuristics_fixed(png_structrp png_ptr, int heuristic_method, + int num_weights, png_const_fixed_point_p filter_weights, + png_const_fixed_point_p filter_costs) +{ + PNG_UNUSED(png_ptr) + PNG_UNUSED(heuristic_method) + PNG_UNUSED(num_weights) + PNG_UNUSED(filter_weights) + PNG_UNUSED(filter_costs) +} +#endif /* FIXED_POINT */ +#endif /* WRITE_WEIGHTED_FILTER */ + +#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED +void PNGAPI +png_set_compression_level(png_structrp png_ptr, int level) +{ + png_debug(1, "in png_set_compression_level"); + + if (png_ptr == NULL) + return; + + png_ptr->zlib_level = level; +} + +void PNGAPI +png_set_compression_mem_level(png_structrp png_ptr, int mem_level) +{ + png_debug(1, "in png_set_compression_mem_level"); + + if (png_ptr == NULL) + return; + + png_ptr->zlib_mem_level = mem_level; +} + +void PNGAPI +png_set_compression_strategy(png_structrp png_ptr, int strategy) +{ + png_debug(1, "in png_set_compression_strategy"); + + if (png_ptr == NULL) + return; + + /* The flag setting here prevents the libpng dynamic selection of strategy. + */ + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; + png_ptr->zlib_strategy = strategy; +} + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +void PNGAPI +png_set_compression_window_bits(png_structrp png_ptr, int window_bits) +{ + if (png_ptr == NULL) + return; + + /* Prior to 1.6.0 this would warn but then set the window_bits value. This + * meant that negative window bits values could be selected that would cause + * libpng to write a non-standard PNG file with raw deflate or gzip + * compressed IDAT or ancillary chunks. Such files can be read and there is + * no warning on read, so this seems like a very bad idea. + */ + if (window_bits > 15) + { + png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + window_bits = 15; + } + + else if (window_bits < 8) + { + png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); + window_bits = 8; + } + + png_ptr->zlib_window_bits = window_bits; +} + +void PNGAPI +png_set_compression_method(png_structrp png_ptr, int method) +{ + png_debug(1, "in png_set_compression_method"); + + if (png_ptr == NULL) + return; + + /* This would produce an invalid PNG file if it worked, but it doesn't and + * deflate will fault it, so it is harmless to just warn here. + */ + if (method != 8) + png_warning(png_ptr, "Only compression method 8 is supported by PNG"); + + png_ptr->zlib_method = method; +} +#endif /* WRITE_CUSTOMIZE_COMPRESSION */ + +/* The following were added to libpng-1.5.4 */ +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +void PNGAPI +png_set_text_compression_level(png_structrp png_ptr, int level) +{ + png_debug(1, "in png_set_text_compression_level"); + + if (png_ptr == NULL) + return; + + png_ptr->zlib_text_level = level; +} + +void PNGAPI +png_set_text_compression_mem_level(png_structrp png_ptr, int mem_level) +{ + png_debug(1, "in png_set_text_compression_mem_level"); + + if (png_ptr == NULL) + return; + + png_ptr->zlib_text_mem_level = mem_level; +} + +void PNGAPI +png_set_text_compression_strategy(png_structrp png_ptr, int strategy) +{ + png_debug(1, "in png_set_text_compression_strategy"); + + if (png_ptr == NULL) + return; + + png_ptr->zlib_text_strategy = strategy; +} + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +void PNGAPI +png_set_text_compression_window_bits(png_structrp png_ptr, int window_bits) +{ + if (png_ptr == NULL) + return; + + if (window_bits > 15) + { + png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + window_bits = 15; + } + + else if (window_bits < 8) + { + png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); + window_bits = 8; + } + + png_ptr->zlib_text_window_bits = window_bits; +} + +void PNGAPI +png_set_text_compression_method(png_structrp png_ptr, int method) +{ + png_debug(1, "in png_set_text_compression_method"); + + if (png_ptr == NULL) + return; + + if (method != 8) + png_warning(png_ptr, "Only compression method 8 is supported by PNG"); + + png_ptr->zlib_text_method = method; +} +#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */ +/* end of API added to libpng-1.5.4 */ + +void PNGAPI +png_set_write_status_fn(png_structrp png_ptr, png_write_status_ptr write_row_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->write_row_fn = write_row_fn; +} + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +void PNGAPI +png_set_write_user_transform_fn(png_structrp png_ptr, png_user_transform_ptr + write_user_transform_fn) +{ + png_debug(1, "in png_set_write_user_transform_fn"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_USER_TRANSFORM; + png_ptr->write_user_transform_fn = write_user_transform_fn; +} +#endif + + +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_write_png(png_structrp png_ptr, png_inforp info_ptr, + int transforms, voidp params) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; + + if ((info_ptr->valid & PNG_INFO_IDAT) == 0) + { + png_app_error(png_ptr, "no rows for png_write_image to write"); + return; + } + + /* Write the file header information. */ + png_write_info(png_ptr, info_ptr); + + /* ------ these transformations don't touch the info structure ------- */ + + /* Invert monochrome pixels */ + if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0) +#ifdef PNG_WRITE_INVERT_SUPPORTED + png_set_invert_mono(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported"); +#endif + + /* Shift the pixels up to a legal bit depth and fill in + * as appropriate to correctly scale the image. + */ + if ((transforms & PNG_TRANSFORM_SHIFT) != 0) +#ifdef PNG_WRITE_SHIFT_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sBIT) != 0) + png_set_shift(png_ptr, &info_ptr->sig_bit); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported"); +#endif + + /* Pack pixels into bytes */ + if ((transforms & PNG_TRANSFORM_PACKING) != 0) +#ifdef PNG_WRITE_PACK_SUPPORTED + png_set_packing(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported"); +#endif + + /* Swap location of alpha bytes from ARGB to RGBA */ + if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0) +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED + png_set_swap_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported"); +#endif + + /* Remove a filler (X) from XRGB/RGBX/AG/GA into to convert it into + * RGB, note that the code expects the input color type to be G or RGB; no + * alpha channel. + */ + if ((transforms & (PNG_TRANSFORM_STRIP_FILLER_AFTER| + PNG_TRANSFORM_STRIP_FILLER_BEFORE)) != 0) + { +#ifdef PNG_WRITE_FILLER_SUPPORTED + if ((transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) != 0) + { + if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0) + png_app_error(png_ptr, + "PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported"); + + /* Continue if ignored - this is the pre-1.6.10 behavior */ + png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); + } + + else if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0) + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_FILLER not supported"); +#endif + } + + /* Flip BGR pixels to RGB */ + if ((transforms & PNG_TRANSFORM_BGR) != 0) +#ifdef PNG_WRITE_BGR_SUPPORTED + png_set_bgr(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported"); +#endif + + /* Swap bytes of 16-bit files to most significant byte first */ + if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0) +#ifdef PNG_WRITE_SWAP_SUPPORTED + png_set_swap(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported"); +#endif + + /* Swap bits of 1-bit, 2-bit, 4-bit packed pixel formats */ + if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0) +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED + png_set_packswap(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported"); +#endif + + /* Invert the alpha channel from opacity to transparency */ + if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0) +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + png_set_invert_alpha(png_ptr); +#else + png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported"); +#endif + + /* ----------------------- end of transformations ------------------- */ + + /* Write the bits */ + png_write_image(png_ptr, info_ptr->row_pointers); + + /* It is REQUIRED to call this to finish writing the rest of the file */ + png_write_end(png_ptr, info_ptr); + + PNG_UNUSED(params) +} +#endif + + +#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED +/* Initialize the write structure - general purpose utility. */ +static int +png_image_write_init(png_imagep image) +{ + png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, image, + png_safe_error, png_safe_warning); + + if (png_ptr != NULL) + { + png_infop info_ptr = png_create_info_struct(png_ptr); + + if (info_ptr != NULL) + { + png_controlp control = png_voidcast(png_controlp, + png_malloc_warn(png_ptr, (sizeof *control))); + + if (control != NULL) + { + memset(control, 0, (sizeof *control)); + + control->png_ptr = png_ptr; + control->info_ptr = info_ptr; + control->for_write = 1; + + image->opaque = control; + return 1; + } + + /* Error clean up */ + png_destroy_info_struct(png_ptr, &info_ptr); + } + + png_destroy_write_struct(&png_ptr, NULL); + } + + return png_image_error(image, "png_image_write_: out of memory"); +} + +/* Arguments to png_image_write_main: */ +typedef struct +{ + /* Arguments: */ + png_imagep image; + png_const_voidp buffer; + png_int_32 row_stride; + png_const_voidp colormap; + int convert_to_8bit; + /* Local variables: */ + png_const_voidp first_row; + ptrdiff_t row_bytes; + png_voidp local_row; + /* Byte count for memory writing */ + png_bytep memory; + png_alloc_size_t memory_bytes; /* not used for STDIO */ + png_alloc_size_t output_bytes; /* running total */ +} png_image_write_control; + +/* Write png_uint_16 input to a 16-bit PNG; the png_ptr has already been set to + * do any necessary byte swapping. The component order is defined by the + * png_image format value. + */ +static int +png_write_image_16bit(png_voidp argument) +{ + png_image_write_control *display = png_voidcast(png_image_write_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + + png_const_uint_16p input_row = png_voidcast(png_const_uint_16p, + display->first_row); + png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row); + png_uint_16p row_end; + unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? + 3 : 1; + int aindex = 0; + png_uint_32 y = image->height; + + if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0) + { +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED + if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + aindex = -1; + ++input_row; /* To point to the first component */ + ++output_row; + } + else + aindex = (int)channels; +# else + aindex = (int)channels; +# endif + } + + else + png_error(png_ptr, "png_write_image: internal call error"); + + /* Work out the output row end and count over this, note that the increment + * above to 'row' means that row_end can actually be beyond the end of the + * row; this is correct. + */ + row_end = output_row + image->width * (channels+1); + + for (; y > 0; --y) + { + png_const_uint_16p in_ptr = input_row; + png_uint_16p out_ptr = output_row; + + while (out_ptr < row_end) + { + png_uint_16 alpha = in_ptr[aindex]; + png_uint_32 reciprocal = 0; + int c; + + out_ptr[aindex] = alpha; + + /* Calculate a reciprocal. The correct calculation is simply + * component/alpha*65535 << 15. (I.e. 15 bits of precision); this + * allows correct rounding by adding .5 before the shift. 'reciprocal' + * is only initialized when required. + */ + if (alpha > 0 && alpha < 65535) + reciprocal = ((0xffff<<15)+(alpha>>1))/alpha; + + c = (int)channels; + do /* always at least one channel */ + { + png_uint_16 component = *in_ptr++; + + /* The following gives 65535 for an alpha of 0, which is fine, + * otherwise if 0/0 is represented as some other value there is more + * likely to be a discontinuity which will probably damage + * compression when moving from a fully transparent area to a + * nearly transparent one. (The assumption here is that opaque + * areas tend not to be 0 intensity.) + */ + if (component >= alpha) + component = 65535; + + /* component 0 && alpha < 65535) + { + png_uint_32 calc = component * reciprocal; + calc += 16384; /* round to nearest */ + component = (png_uint_16)(calc >> 15); + } + + *out_ptr++ = component; + } + while (--c > 0); + + /* Skip to next component (skip the intervening alpha channel) */ + ++in_ptr; + ++out_ptr; + } + + png_write_row(png_ptr, png_voidcast(png_const_bytep, display->local_row)); + input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16)); + } + + return 1; +} + +/* Given 16-bit input (1 to 4 channels) write 8-bit output. If an alpha channel + * is present it must be removed from the components, the components are then + * written in sRGB encoding. No components are added or removed. + * + * Calculate an alpha reciprocal to reverse pre-multiplication. As above the + * calculation can be done to 15 bits of accuracy; however, the output needs to + * be scaled in the range 0..255*65535, so include that scaling here. + */ +# define UNP_RECIPROCAL(alpha) ((((0xffff*0xff)<<7)+((alpha)>>1))/(alpha)) + +static png_byte +png_unpremultiply(png_uint_32 component, png_uint_32 alpha, + png_uint_32 reciprocal/*from the above macro*/) +{ + /* The following gives 1.0 for an alpha of 0, which is fine, otherwise if 0/0 + * is represented as some other value there is more likely to be a + * discontinuity which will probably damage compression when moving from a + * fully transparent area to a nearly transparent one. (The assumption here + * is that opaque areas tend not to be 0 intensity.) + * + * There is a rounding problem here; if alpha is less than 128 it will end up + * as 0 when scaled to 8 bits. To avoid introducing spurious colors into the + * output change for this too. + */ + if (component >= alpha || alpha < 128) + return 255; + + /* component 0) + { + /* The test is that alpha/257 (rounded) is less than 255, the first value + * that becomes 255 is 65407. + * NOTE: this must agree with the PNG_DIV257 macro (which must, therefore, + * be exact!) [Could also test reciprocal != 0] + */ + if (alpha < 65407) + { + component *= reciprocal; + component += 64; /* round to nearest */ + component >>= 7; + } + + else + component *= 255; + + /* Convert the component to sRGB. */ + return (png_byte)PNG_sRGB_FROM_LINEAR(component); + } + + else + return 0; +} + +static int +png_write_image_8bit(png_voidp argument) +{ + png_image_write_control *display = png_voidcast(png_image_write_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + + png_const_uint_16p input_row = png_voidcast(png_const_uint_16p, + display->first_row); + png_bytep output_row = png_voidcast(png_bytep, display->local_row); + png_uint_32 y = image->height; + unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? + 3 : 1; + + if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0) + { + png_bytep row_end; + int aindex; + +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED + if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + aindex = -1; + ++input_row; /* To point to the first component */ + ++output_row; + } + + else +# endif + aindex = (int)channels; + + /* Use row_end in place of a loop counter: */ + row_end = output_row + image->width * (channels+1); + + for (; y > 0; --y) + { + png_const_uint_16p in_ptr = input_row; + png_bytep out_ptr = output_row; + + while (out_ptr < row_end) + { + png_uint_16 alpha = in_ptr[aindex]; + png_byte alphabyte = (png_byte)PNG_DIV257(alpha); + png_uint_32 reciprocal = 0; + int c; + + /* Scale and write the alpha channel. */ + out_ptr[aindex] = alphabyte; + + if (alphabyte > 0 && alphabyte < 255) + reciprocal = UNP_RECIPROCAL(alpha); + + c = (int)channels; + do /* always at least one channel */ + *out_ptr++ = png_unpremultiply(*in_ptr++, alpha, reciprocal); + while (--c > 0); + + /* Skip to next component (skip the intervening alpha channel) */ + ++in_ptr; + ++out_ptr; + } /* while out_ptr < row_end */ + + png_write_row(png_ptr, png_voidcast(png_const_bytep, + display->local_row)); + input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16)); + } /* while y */ + } + + else + { + /* No alpha channel, so the row_end really is the end of the row and it + * is sufficient to loop over the components one by one. + */ + png_bytep row_end = output_row + image->width * channels; + + for (; y > 0; --y) + { + png_const_uint_16p in_ptr = input_row; + png_bytep out_ptr = output_row; + + while (out_ptr < row_end) + { + png_uint_32 component = *in_ptr++; + + component *= 255; + *out_ptr++ = (png_byte)PNG_sRGB_FROM_LINEAR(component); + } + + png_write_row(png_ptr, output_row); + input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16)); + } + } + + return 1; +} + +static void +png_image_set_PLTE(png_image_write_control *display) +{ + png_imagep image = display->image; + const void *cmap = display->colormap; + int entries = image->colormap_entries > 256 ? 256 : + (int)image->colormap_entries; + + /* NOTE: the caller must check for cmap != NULL and entries != 0 */ + png_uint_32 format = image->format; + unsigned int channels = PNG_IMAGE_SAMPLE_CHANNELS(format); + +# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\ + defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED) + int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 && + (format & PNG_FORMAT_FLAG_ALPHA) != 0; +# else +# define afirst 0 +# endif + +# ifdef PNG_FORMAT_BGR_SUPPORTED + int bgr = (format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0; +# else +# define bgr 0 +# endif + + int i, num_trans; + png_color palette[256]; + png_byte tRNS[256]; + + memset(tRNS, 255, (sizeof tRNS)); + memset(palette, 0, (sizeof palette)); + + for (i=num_trans=0; i= 3) /* RGB */ + { + palette[i].blue = (png_byte)PNG_sRGB_FROM_LINEAR(255 * + entry[(2 ^ bgr)]); + palette[i].green = (png_byte)PNG_sRGB_FROM_LINEAR(255 * + entry[1]); + palette[i].red = (png_byte)PNG_sRGB_FROM_LINEAR(255 * + entry[bgr]); + } + + else /* Gray */ + palette[i].blue = palette[i].red = palette[i].green = + (png_byte)PNG_sRGB_FROM_LINEAR(255 * *entry); + } + + else /* alpha */ + { + png_uint_16 alpha = entry[afirst ? 0 : channels-1]; + png_byte alphabyte = (png_byte)PNG_DIV257(alpha); + png_uint_32 reciprocal = 0; + + /* Calculate a reciprocal, as in the png_write_image_8bit code above + * this is designed to produce a value scaled to 255*65535 when + * divided by 128 (i.e. asr 7). + */ + if (alphabyte > 0 && alphabyte < 255) + reciprocal = (((0xffff*0xff)<<7)+(alpha>>1))/alpha; + + tRNS[i] = alphabyte; + if (alphabyte < 255) + num_trans = i+1; + + if (channels >= 3) /* RGB */ + { + palette[i].blue = png_unpremultiply(entry[afirst + (2 ^ bgr)], + alpha, reciprocal); + palette[i].green = png_unpremultiply(entry[afirst + 1], alpha, + reciprocal); + palette[i].red = png_unpremultiply(entry[afirst + bgr], alpha, + reciprocal); + } + + else /* gray */ + palette[i].blue = palette[i].red = palette[i].green = + png_unpremultiply(entry[afirst], alpha, reciprocal); + } + } + + else /* Color-map has sRGB values */ + { + png_const_bytep entry = png_voidcast(png_const_bytep, cmap); + + entry += (unsigned int)i * channels; + + switch (channels) + { + case 4: + tRNS[i] = entry[afirst ? 0 : 3]; + if (tRNS[i] < 255) + num_trans = i+1; + /* FALLTHROUGH */ + case 3: + palette[i].blue = entry[afirst + (2 ^ bgr)]; + palette[i].green = entry[afirst + 1]; + palette[i].red = entry[afirst + bgr]; + break; + + case 2: + tRNS[i] = entry[1 ^ afirst]; + if (tRNS[i] < 255) + num_trans = i+1; + /* FALLTHROUGH */ + case 1: + palette[i].blue = palette[i].red = palette[i].green = + entry[afirst]; + break; + + default: + break; + } + } + } + +# ifdef afirst +# undef afirst +# endif +# ifdef bgr +# undef bgr +# endif + + png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette, + entries); + + if (num_trans > 0) + png_set_tRNS(image->opaque->png_ptr, image->opaque->info_ptr, tRNS, + num_trans, NULL); + + image->colormap_entries = (png_uint_32)entries; +} + +static int +png_image_write_main(png_voidp argument) +{ + png_image_write_control *display = png_voidcast(png_image_write_control*, + argument); + png_imagep image = display->image; + png_structrp png_ptr = image->opaque->png_ptr; + png_inforp info_ptr = image->opaque->info_ptr; + png_uint_32 format = image->format; + + /* The following four ints are actually booleans */ + int colormap = (format & PNG_FORMAT_FLAG_COLORMAP); + int linear = !colormap && (format & PNG_FORMAT_FLAG_LINEAR); /* input */ + int alpha = !colormap && (format & PNG_FORMAT_FLAG_ALPHA); + int write_16bit = linear && (display->convert_to_8bit == 0); + +# ifdef PNG_BENIGN_ERRORS_SUPPORTED + /* Make sure we error out on any bad situation */ + png_set_benign_errors(png_ptr, 0/*error*/); +# endif + + /* Default the 'row_stride' parameter if required, also check the row stride + * and total image size to ensure that they are within the system limits. + */ + { + unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format); + + if (image->width <= 0x7fffffffU/channels) /* no overflow */ + { + png_uint_32 check; + png_uint_32 png_row_stride = image->width * channels; + + if (display->row_stride == 0) + display->row_stride = (png_int_32)/*SAFE*/png_row_stride; + + if (display->row_stride < 0) + check = (png_uint_32)(-display->row_stride); + + else + check = (png_uint_32)display->row_stride; + + if (check >= png_row_stride) + { + /* Now check for overflow of the image buffer calculation; this + * limits the whole image size to 32 bits for API compatibility with + * the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro. + */ + if (image->height > 0xffffffffU/png_row_stride) + png_error(image->opaque->png_ptr, "memory image too large"); + } + + else + png_error(image->opaque->png_ptr, "supplied row stride too small"); + } + + else + png_error(image->opaque->png_ptr, "image row stride too large"); + } + + /* Set the required transforms then write the rows in the correct order. */ + if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0) + { + if (display->colormap != NULL && image->colormap_entries > 0) + { + png_uint_32 entries = image->colormap_entries; + + png_set_IHDR(png_ptr, info_ptr, image->width, image->height, + entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)), + PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_image_set_PLTE(display); + } + + else + png_error(image->opaque->png_ptr, + "no color-map for color-mapped image"); + } + + else + png_set_IHDR(png_ptr, info_ptr, image->width, image->height, + write_16bit ? 16 : 8, + ((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) + + ((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0), + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + /* Counter-intuitively the data transformations must be called *after* + * png_write_info, not before as in the read code, but the 'set' functions + * must still be called before. Just set the color space information, never + * write an interlaced image. + */ + + if (write_16bit != 0) + { + /* The gamma here is 1.0 (linear) and the cHRM chunk matches sRGB. */ + png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_LINEAR); + + if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0) + png_set_cHRM_fixed(png_ptr, info_ptr, + /* color x y */ + /* white */ 31270, 32900, + /* red */ 64000, 33000, + /* green */ 30000, 60000, + /* blue */ 15000, 6000 + ); + } + + else if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0) + png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_PERCEPTUAL); + + /* Else writing an 8-bit file and the *colors* aren't sRGB, but the 8-bit + * space must still be gamma encoded. + */ + else + png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE); + + /* Write the file header. */ + png_write_info(png_ptr, info_ptr); + + /* Now set up the data transformations (*after* the header is written), + * remove the handled transformations from the 'format' flags for checking. + * + * First check for a little endian system if writing 16-bit files. + */ + if (write_16bit != 0) + { + png_uint_16 le = 0x0001; + + if ((*(png_const_bytep) & le) != 0) + png_set_swap(png_ptr); + } + +# ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED + if ((format & PNG_FORMAT_FLAG_BGR) != 0) + { + if (colormap == 0 && (format & PNG_FORMAT_FLAG_COLOR) != 0) + png_set_bgr(png_ptr); + format &= ~PNG_FORMAT_FLAG_BGR; + } +# endif + +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED + if ((format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + if (colormap == 0 && (format & PNG_FORMAT_FLAG_ALPHA) != 0) + png_set_swap_alpha(png_ptr); + format &= ~PNG_FORMAT_FLAG_AFIRST; + } +# endif + + /* If there are 16 or fewer color-map entries we wrote a lower bit depth + * above, but the application data is still byte packed. + */ + if (colormap != 0 && image->colormap_entries <= 16) + png_set_packing(png_ptr); + + /* That should have handled all (both) the transforms. */ + if ((format & ~(png_uint_32)(PNG_FORMAT_FLAG_COLOR | PNG_FORMAT_FLAG_LINEAR | + PNG_FORMAT_FLAG_ALPHA | PNG_FORMAT_FLAG_COLORMAP)) != 0) + png_error(png_ptr, "png_write_image: unsupported transformation"); + + { + png_const_bytep row = png_voidcast(png_const_bytep, display->buffer); + ptrdiff_t row_bytes = display->row_stride; + + if (linear != 0) + row_bytes *= (sizeof (png_uint_16)); + + if (row_bytes < 0) + row += (image->height-1) * (-row_bytes); + + display->first_row = row; + display->row_bytes = row_bytes; + } + + /* Apply 'fast' options if the flag is set. */ + if ((image->flags & PNG_IMAGE_FLAG_FAST) != 0) + { + png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_NO_FILTERS); + /* NOTE: determined by experiment using pngstest, this reflects some + * balance between the time to write the image once and the time to read + * it about 50 times. The speed-up in pngstest was about 10-20% of the + * total (user) time on a heavily loaded system. + */ +# ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED + png_set_compression_level(png_ptr, 3); +# endif + } + + /* Check for the cases that currently require a pre-transform on the row + * before it is written. This only applies when the input is 16-bit and + * either there is an alpha channel or it is converted to 8-bit. + */ + if ((linear != 0 && alpha != 0 ) || + (colormap == 0 && display->convert_to_8bit != 0)) + { + png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr, + png_get_rowbytes(png_ptr, info_ptr))); + int result; + + display->local_row = row; + if (write_16bit != 0) + result = png_safe_execute(image, png_write_image_16bit, display); + else + result = png_safe_execute(image, png_write_image_8bit, display); + display->local_row = NULL; + + png_free(png_ptr, row); + + /* Skip the 'write_end' on error: */ + if (result == 0) + return 0; + } + + /* Otherwise this is the case where the input is in a format currently + * supported by the rest of the libpng write code; call it directly. + */ + else + { + png_const_bytep row = png_voidcast(png_const_bytep, display->first_row); + ptrdiff_t row_bytes = display->row_bytes; + png_uint_32 y = image->height; + + for (; y > 0; --y) + { + png_write_row(png_ptr, row); + row += row_bytes; + } + } + + png_write_end(png_ptr, info_ptr); + return 1; +} + + +static void (PNGCBAPI +image_memory_write)(png_structp png_ptr, png_bytep/*const*/ data, size_t size) +{ + png_image_write_control *display = png_voidcast(png_image_write_control*, + png_ptr->io_ptr/*backdoor: png_get_io_ptr(png_ptr)*/); + png_alloc_size_t ob = display->output_bytes; + + /* Check for overflow; this should never happen: */ + if (size <= ((png_alloc_size_t)-1) - ob) + { + /* I don't think libpng ever does this, but just in case: */ + if (size > 0) + { + if (display->memory_bytes >= ob+size) /* writing */ + memcpy(display->memory+ob, data, size); + + /* Always update the size: */ + display->output_bytes = ob+size; + } + } + + else + png_error(png_ptr, "png_image_write_to_memory: PNG too big"); +} + +static void (PNGCBAPI +image_memory_flush)(png_structp png_ptr) +{ + PNG_UNUSED(png_ptr) +} + +static int +png_image_write_memory(png_voidp argument) +{ + png_image_write_control *display = png_voidcast(png_image_write_control*, + argument); + + /* The rest of the memory-specific init and write_main in an error protected + * environment. This case needs to use callbacks for the write operations + * since libpng has no built in support for writing to memory. + */ + png_set_write_fn(display->image->opaque->png_ptr, display/*io_ptr*/, + image_memory_write, image_memory_flush); + + return png_image_write_main(display); +} + +int PNGAPI +png_image_write_to_memory(png_imagep image, void *memory, + png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8bit, + const void *buffer, png_int_32 row_stride, const void *colormap) +{ + /* Write the image to the given buffer, or count the bytes if it is NULL */ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (memory_bytes != NULL && buffer != NULL) + { + /* This is to give the caller an easier error detection in the NULL + * case and guard against uninitialized variable problems: + */ + if (memory == NULL) + *memory_bytes = 0; + + if (png_image_write_init(image) != 0) + { + png_image_write_control display; + int result; + + memset(&display, 0, (sizeof display)); + display.image = image; + display.buffer = buffer; + display.row_stride = row_stride; + display.colormap = colormap; + display.convert_to_8bit = convert_to_8bit; + display.memory = png_voidcast(png_bytep, memory); + display.memory_bytes = *memory_bytes; + display.output_bytes = 0; + + result = png_safe_execute(image, png_image_write_memory, &display); + png_image_free(image); + + /* write_memory returns true even if we ran out of buffer. */ + if (result) + { + /* On out-of-buffer this function returns '0' but still updates + * memory_bytes: + */ + if (memory != NULL && display.output_bytes > *memory_bytes) + result = 0; + + *memory_bytes = display.output_bytes; + } + + return result; + } + + else + return 0; + } + + else + return png_image_error(image, + "png_image_write_to_memory: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_write_to_memory: incorrect PNG_IMAGE_VERSION"); + + else + return 0; +} + +#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED +int PNGAPI +png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit, + const void *buffer, png_int_32 row_stride, const void *colormap) +{ + /* Write the image to the given (FILE*). */ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (file != NULL && buffer != NULL) + { + if (png_image_write_init(image) != 0) + { + png_image_write_control display; + int result; + + /* This is slightly evil, but png_init_io doesn't do anything other + * than this and we haven't changed the standard IO functions so + * this saves a 'safe' function. + */ + image->opaque->png_ptr->io_ptr = file; + + memset(&display, 0, (sizeof display)); + display.image = image; + display.buffer = buffer; + display.row_stride = row_stride; + display.colormap = colormap; + display.convert_to_8bit = convert_to_8bit; + + result = png_safe_execute(image, png_image_write_main, &display); + png_image_free(image); + return result; + } + + else + return 0; + } + + else + return png_image_error(image, + "png_image_write_to_stdio: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION"); + + else + return 0; +} + +int PNGAPI +png_image_write_to_file(png_imagep image, const char *file_name, + int convert_to_8bit, const void *buffer, png_int_32 row_stride, + const void *colormap) +{ + /* Write the image to the named file. */ + if (image != NULL && image->version == PNG_IMAGE_VERSION) + { + if (file_name != NULL && buffer != NULL) + { + FILE *fp = fopen(file_name, "wb"); + + if (fp != NULL) + { + if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer, + row_stride, colormap) != 0) + { + int error; /* from fflush/fclose */ + + /* Make sure the file is flushed correctly. */ + if (fflush(fp) == 0 && ferror(fp) == 0) + { + if (fclose(fp) == 0) + return 1; + + error = errno; /* from fclose */ + } + + else + { + error = errno; /* from fflush or ferror */ + (void)fclose(fp); + } + + (void)remove(file_name); + /* The image has already been cleaned up; this is just used to + * set the error (because the original write succeeded). + */ + return png_image_error(image, strerror(error)); + } + + else + { + /* Clean up: just the opened file. */ + (void)fclose(fp); + (void)remove(file_name); + return 0; + } + } + + else + return png_image_error(image, strerror(errno)); + } + + else + return png_image_error(image, + "png_image_write_to_file: invalid argument"); + } + + else if (image != NULL) + return png_image_error(image, + "png_image_write_to_file: incorrect PNG_IMAGE_VERSION"); + + else + return 0; +} +#endif /* SIMPLIFIED_WRITE_STDIO */ +#endif /* SIMPLIFIED_WRITE */ +#endif /* WRITE */ diff --git a/extern/libpng/pngwtran.c b/extern/libpng/pngwtran.c new file mode 100644 index 000000000..49a13c1e9 --- /dev/null +++ b/extern/libpng/pngwtran.c @@ -0,0 +1,575 @@ + +/* pngwtran.c - transforms the data in a row for PNG writers + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#ifdef PNG_WRITE_SUPPORTED +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED + +#ifdef PNG_WRITE_PACK_SUPPORTED +/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The + * row_info bit depth should be 8 (one pixel per byte). The channels + * should be 1 (this only happens on grayscale and paletted images). + */ +static void +png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) +{ + png_debug(1, "in png_do_pack"); + + if (row_info->bit_depth == 8 && + row_info->channels == 1) + { + switch ((int)bit_depth) + { + case 1: + { + png_bytep sp, dp; + int mask, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + mask = 0x80; + v = 0; + + for (i = 0; i < row_width; i++) + { + if (*sp != 0) + v |= mask; + + sp++; + + if (mask > 1) + mask >>= 1; + + else + { + mask = 0x80; + *dp = (png_byte)v; + dp++; + v = 0; + } + } + + if (mask != 0x80) + *dp = (png_byte)v; + + break; + } + + case 2: + { + png_bytep sp, dp; + unsigned int shift; + int v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + shift = 6; + v = 0; + + for (i = 0; i < row_width; i++) + { + png_byte value; + + value = (png_byte)(*sp & 0x03); + v |= (value << shift); + + if (shift == 0) + { + shift = 6; + *dp = (png_byte)v; + dp++; + v = 0; + } + + else + shift -= 2; + + sp++; + } + + if (shift != 6) + *dp = (png_byte)v; + + break; + } + + case 4: + { + png_bytep sp, dp; + unsigned int shift; + int v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + shift = 4; + v = 0; + + for (i = 0; i < row_width; i++) + { + png_byte value; + + value = (png_byte)(*sp & 0x0f); + v |= (value << shift); + + if (shift == 0) + { + shift = 4; + *dp = (png_byte)v; + dp++; + v = 0; + } + + else + shift -= 4; + + sp++; + } + + if (shift != 4) + *dp = (png_byte)v; + + break; + } + + default: + break; + } + + row_info->bit_depth = (png_byte)bit_depth; + row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_info->width); + } +} +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED +/* Shift pixel values to take advantage of whole range. Pass the + * true number of bits in bit_depth. The row should be packed + * according to row_info->bit_depth. Thus, if you had a row of + * bit depth 4, but the pixels only had values from 0 to 7, you + * would pass 3 as bit_depth, and this routine would translate the + * data to 0 to 15. + */ +static void +png_do_shift(png_row_infop row_info, png_bytep row, + png_const_color_8p bit_depth) +{ + png_debug(1, "in png_do_shift"); + + if (row_info->color_type != PNG_COLOR_TYPE_PALETTE) + { + int shift_start[4], shift_dec[4]; + unsigned int channels = 0; + + if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) + { + shift_start[channels] = row_info->bit_depth - bit_depth->red; + shift_dec[channels] = bit_depth->red; + channels++; + + shift_start[channels] = row_info->bit_depth - bit_depth->green; + shift_dec[channels] = bit_depth->green; + channels++; + + shift_start[channels] = row_info->bit_depth - bit_depth->blue; + shift_dec[channels] = bit_depth->blue; + channels++; + } + + else + { + shift_start[channels] = row_info->bit_depth - bit_depth->gray; + shift_dec[channels] = bit_depth->gray; + channels++; + } + + if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0) + { + shift_start[channels] = row_info->bit_depth - bit_depth->alpha; + shift_dec[channels] = bit_depth->alpha; + channels++; + } + + /* With low row depths, could only be grayscale, so one channel */ + if (row_info->bit_depth < 8) + { + png_bytep bp = row; + size_t i; + unsigned int mask; + size_t row_bytes = row_info->rowbytes; + + if (bit_depth->gray == 1 && row_info->bit_depth == 2) + mask = 0x55; + + else if (row_info->bit_depth == 4 && bit_depth->gray == 3) + mask = 0x11; + + else + mask = 0xff; + + for (i = 0; i < row_bytes; i++, bp++) + { + int j; + unsigned int v, out; + + v = *bp; + out = 0; + + for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0]) + { + if (j > 0) + out |= v << j; + + else + out |= (v >> (-j)) & mask; + } + + *bp = (png_byte)(out & 0xff); + } + } + + else if (row_info->bit_depth == 8) + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = channels * row_info->width; + + for (i = 0; i < istop; i++, bp++) + { + unsigned int c = i%channels; + int j; + unsigned int v, out; + + v = *bp; + out = 0; + + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + out |= v << j; + + else + out |= v >> (-j); + } + + *bp = (png_byte)(out & 0xff); + } + } + + else + { + png_bytep bp; + png_uint_32 i; + png_uint_32 istop = channels * row_info->width; + + for (bp = row, i = 0; i < istop; i++) + { + unsigned int c = i%channels; + int j; + unsigned int value, v; + + v = png_get_uint_16(bp); + value = 0; + + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + value |= v << j; + + else + value |= v >> (-j); + } + *bp++ = (png_byte)((value >> 8) & 0xff); + *bp++ = (png_byte)(value & 0xff); + } + } + } +} +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED +static void +png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_swap_alpha"); + + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This converts from ARGB to RGBA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save; + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else + { + /* This converts from AARRGGBB to RRGGBBAA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save[2]; + save[0] = *(sp++); + save[1] = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save[0]; + *(dp++) = save[1]; + } + } +#endif /* WRITE_16BIT */ + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This converts from AG to GA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save; + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else + { + /* This converts from AAGG to GGAA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save[2]; + save[0] = *(sp++); + save[1] = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save[0]; + *(dp++) = save[1]; + } + } +#endif /* WRITE_16BIT */ + } + } +} +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED +static void +png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_invert_alpha"); + + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This inverts the alpha channel in RGBA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=3; dp = sp; + *dp = (png_byte)(255 - *(sp++)); + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else + { + /* This inverts the alpha channel in RRGGBBAA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=6; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + *dp = (png_byte)(255 - *(sp++)); + } + } +#endif /* WRITE_16BIT */ + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This inverts the alpha channel in GA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + *(dp++) = *(sp++); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else + { + /* This inverts the alpha channel in GGAA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=2; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + *dp = (png_byte)(255 - *(sp++)); + } + } +#endif /* WRITE_16BIT */ + } + } +} +#endif + +/* Transform the data according to the user's wishes. The order of + * transformations is significant. + */ +void /* PRIVATE */ +png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info) +{ + png_debug(1, "in png_do_write_transformations"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) + if (png_ptr->write_user_transform_fn != NULL) + (*(png_ptr->write_user_transform_fn)) /* User write transform + function */ + (png_ptr, /* png_ptr */ + row_info, /* row_info: */ + /* png_uint_32 width; width of row */ + /* size_t rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#endif + +#ifdef PNG_WRITE_FILLER_SUPPORTED + if ((png_ptr->transformations & PNG_FILLER) != 0) + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + !(png_ptr->flags & PNG_FLAG_FILLER_AFTER)); +#endif + +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + png_do_packswap(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) != 0) + png_do_pack(row_info, png_ptr->row_buf + 1, + (png_uint_32)png_ptr->bit_depth); +#endif + +#ifdef PNG_WRITE_SWAP_SUPPORTED +# ifdef PNG_16BIT_SUPPORTED + if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0) + png_do_swap(row_info, png_ptr->row_buf + 1); +# endif +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED + if ((png_ptr->transformations & PNG_SHIFT) != 0) + png_do_shift(row_info, png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0) + png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0) + png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_BGR_SUPPORTED + if ((png_ptr->transformations & PNG_BGR) != 0) + png_do_bgr(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_INVERT_SUPPORTED + if ((png_ptr->transformations & PNG_INVERT_MONO) != 0) + png_do_invert(row_info, png_ptr->row_buf + 1); +#endif +} +#endif /* WRITE_TRANSFORMS */ +#endif /* WRITE */ diff --git a/extern/libpng/pngwutil.c b/extern/libpng/pngwutil.c new file mode 100644 index 000000000..c41baa139 --- /dev/null +++ b/extern/libpng/pngwutil.c @@ -0,0 +1,2798 @@ + +/* pngwutil.c - utilities to write a PNG file + * + * Copyright (c) 2018 Cosmin Truta + * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson + * Copyright (c) 1996-1997 Andreas Dilger + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#ifdef PNG_WRITE_SUPPORTED + +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED +/* Place a 32-bit number into a buffer in PNG byte order. We work + * with unsigned numbers for convenience, although one supported + * ancillary chunk uses signed (two's complement) numbers. + */ +void PNGAPI +png_save_uint_32(png_bytep buf, png_uint_32 i) +{ + buf[0] = (png_byte)((i >> 24) & 0xffU); + buf[1] = (png_byte)((i >> 16) & 0xffU); + buf[2] = (png_byte)((i >> 8) & 0xffU); + buf[3] = (png_byte)( i & 0xffU); +} + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +void PNGAPI +png_save_uint_16(png_bytep buf, unsigned int i) +{ + buf[0] = (png_byte)((i >> 8) & 0xffU); + buf[1] = (png_byte)( i & 0xffU); +} +#endif + +/* Simple function to write the signature. If we have already written + * the magic bytes of the signature, or more likely, the PNG stream is + * being embedded into another stream and doesn't need its own signature, + * we should call png_set_sig_bytes() to tell libpng how many of the + * bytes have already been written. + */ +void PNGAPI +png_write_sig(png_structrp png_ptr) +{ + png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + +#ifdef PNG_IO_STATE_SUPPORTED + /* Inform the I/O callback that the signature is being written */ + png_ptr->io_state = PNG_IO_WRITING | PNG_IO_SIGNATURE; +#endif + + /* Write the rest of the 8 byte signature */ + png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], + (size_t)(8 - png_ptr->sig_bytes)); + + if (png_ptr->sig_bytes < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; +} + +/* Write the start of a PNG chunk. The type is the chunk type. + * The total_length is the sum of the lengths of all the data you will be + * passing in png_write_chunk_data(). + */ +static void +png_write_chunk_header(png_structrp png_ptr, png_uint_32 chunk_name, + png_uint_32 length) +{ + png_byte buf[8]; + +#if defined(PNG_DEBUG) && (PNG_DEBUG > 0) + PNG_CSTRING_FROM_CHUNK(buf, chunk_name); + png_debug2(0, "Writing %s chunk, length = %lu", buf, (unsigned long)length); +#endif + + if (png_ptr == NULL) + return; + +#ifdef PNG_IO_STATE_SUPPORTED + /* Inform the I/O callback that the chunk header is being written. + * PNG_IO_CHUNK_HDR requires a single I/O call. + */ + png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR; +#endif + + /* Write the length and the chunk name */ + png_save_uint_32(buf, length); + png_save_uint_32(buf + 4, chunk_name); + png_write_data(png_ptr, buf, 8); + + /* Put the chunk name into png_ptr->chunk_name */ + png_ptr->chunk_name = chunk_name; + + /* Reset the crc and run it over the chunk name */ + png_reset_crc(png_ptr); + + png_calculate_crc(png_ptr, buf + 4, 4); + +#ifdef PNG_IO_STATE_SUPPORTED + /* Inform the I/O callback that chunk data will (possibly) be written. + * PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls. + */ + png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_DATA; +#endif +} + +void PNGAPI +png_write_chunk_start(png_structrp png_ptr, png_const_bytep chunk_string, + png_uint_32 length) +{ + png_write_chunk_header(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), length); +} + +/* Write the data of a PNG chunk started with png_write_chunk_header(). + * Note that multiple calls to this function are allowed, and that the + * sum of the lengths from these calls *must* add up to the total_length + * given to png_write_chunk_header(). + */ +void PNGAPI +png_write_chunk_data(png_structrp png_ptr, png_const_bytep data, size_t length) +{ + /* Write the data, and run the CRC over it */ + if (png_ptr == NULL) + return; + + if (data != NULL && length > 0) + { + png_write_data(png_ptr, data, length); + + /* Update the CRC after writing the data, + * in case the user I/O routine alters it. + */ + png_calculate_crc(png_ptr, data, length); + } +} + +/* Finish a chunk started with png_write_chunk_header(). */ +void PNGAPI +png_write_chunk_end(png_structrp png_ptr) +{ + png_byte buf[4]; + + if (png_ptr == NULL) return; + +#ifdef PNG_IO_STATE_SUPPORTED + /* Inform the I/O callback that the chunk CRC is being written. + * PNG_IO_CHUNK_CRC requires a single I/O function call. + */ + png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_CRC; +#endif + + /* Write the crc in a single operation */ + png_save_uint_32(buf, png_ptr->crc); + + png_write_data(png_ptr, buf, 4); +} + +/* Write a PNG chunk all at once. The type is an array of ASCII characters + * representing the chunk name. The array must be at least 4 bytes in + * length, and does not need to be null terminated. To be safe, pass the + * pre-defined chunk names here, and if you need a new one, define it + * where the others are defined. The length is the length of the data. + * All the data must be present. If that is not possible, use the + * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() + * functions instead. + */ +static void +png_write_complete_chunk(png_structrp png_ptr, png_uint_32 chunk_name, + png_const_bytep data, size_t length) +{ + if (png_ptr == NULL) + return; + + /* On 64-bit architectures 'length' may not fit in a png_uint_32. */ + if (length > PNG_UINT_31_MAX) + png_error(png_ptr, "length exceeds PNG maximum"); + + png_write_chunk_header(png_ptr, chunk_name, (png_uint_32)length); + png_write_chunk_data(png_ptr, data, length); + png_write_chunk_end(png_ptr); +} + +/* This is the API that calls the internal function above. */ +void PNGAPI +png_write_chunk(png_structrp png_ptr, png_const_bytep chunk_string, + png_const_bytep data, size_t length) +{ + png_write_complete_chunk(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), data, + length); +} + +/* This is used below to find the size of an image to pass to png_deflate_claim, + * so it only needs to be accurate if the size is less than 16384 bytes (the + * point at which a lower LZ window size can be used.) + */ +static png_alloc_size_t +png_image_size(png_structrp png_ptr) +{ + /* Only return sizes up to the maximum of a png_uint_32; do this by limiting + * the width and height used to 15 bits. + */ + png_uint_32 h = png_ptr->height; + + if (png_ptr->rowbytes < 32768 && h < 32768) + { + if (png_ptr->interlaced != 0) + { + /* Interlacing makes the image larger because of the replication of + * both the filter byte and the padding to a byte boundary. + */ + png_uint_32 w = png_ptr->width; + unsigned int pd = png_ptr->pixel_depth; + png_alloc_size_t cb_base; + int pass; + + for (cb_base=0, pass=0; pass<=6; ++pass) + { + png_uint_32 pw = PNG_PASS_COLS(w, pass); + + if (pw > 0) + cb_base += (PNG_ROWBYTES(pd, pw)+1) * PNG_PASS_ROWS(h, pass); + } + + return cb_base; + } + + else + return (png_ptr->rowbytes+1) * h; + } + + else + return 0xffffffffU; +} + +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + /* This is the code to hack the first two bytes of the deflate stream (the + * deflate header) to correct the windowBits value to match the actual data + * size. Note that the second argument is the *uncompressed* size but the + * first argument is the *compressed* data (and it must be deflate + * compressed.) + */ +static void +optimize_cmf(png_bytep data, png_alloc_size_t data_size) +{ + /* Optimize the CMF field in the zlib stream. The resultant zlib stream is + * still compliant to the stream specification. + */ + if (data_size <= 16384) /* else windowBits must be 15 */ + { + unsigned int z_cmf = data[0]; /* zlib compression method and flags */ + + if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) + { + unsigned int z_cinfo; + unsigned int half_z_window_size; + + z_cinfo = z_cmf >> 4; + half_z_window_size = 1U << (z_cinfo + 7); + + if (data_size <= half_z_window_size) /* else no change */ + { + unsigned int tmp; + + do + { + half_z_window_size >>= 1; + --z_cinfo; + } + while (z_cinfo > 0 && data_size <= half_z_window_size); + + z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); + + data[0] = (png_byte)z_cmf; + tmp = data[1] & 0xe0; + tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; + data[1] = (png_byte)tmp; + } + } + } +} +#endif /* WRITE_OPTIMIZE_CMF */ + +/* Initialize the compressor for the appropriate type of compression. */ +static int +png_deflate_claim(png_structrp png_ptr, png_uint_32 owner, + png_alloc_size_t data_size) +{ + if (png_ptr->zowner != 0) + { +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED) + char msg[64]; + + PNG_STRING_FROM_CHUNK(msg, owner); + msg[4] = ':'; + msg[5] = ' '; + PNG_STRING_FROM_CHUNK(msg+6, png_ptr->zowner); + /* So the message that results is " using zstream"; this is an + * internal error, but is very useful for debugging. i18n requirements + * are minimal. + */ + (void)png_safecat(msg, (sizeof msg), 10, " using zstream"); +#endif +#if PNG_RELEASE_BUILD + png_warning(png_ptr, msg); + + /* Attempt sane error recovery */ + if (png_ptr->zowner == png_IDAT) /* don't steal from IDAT */ + { + png_ptr->zstream.msg = PNGZ_MSG_CAST("in use by IDAT"); + return Z_STREAM_ERROR; + } + + png_ptr->zowner = 0; +#else + png_error(png_ptr, msg); +#endif + } + + { + int level = png_ptr->zlib_level; + int method = png_ptr->zlib_method; + int windowBits = png_ptr->zlib_window_bits; + int memLevel = png_ptr->zlib_mem_level; + int strategy; /* set below */ + int ret; /* zlib return code */ + + if (owner == png_IDAT) + { + if ((png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY) != 0) + strategy = png_ptr->zlib_strategy; + + else if (png_ptr->do_filter != PNG_FILTER_NONE) + strategy = PNG_Z_DEFAULT_STRATEGY; + + else + strategy = PNG_Z_DEFAULT_NOFILTER_STRATEGY; + } + + else + { +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED + level = png_ptr->zlib_text_level; + method = png_ptr->zlib_text_method; + windowBits = png_ptr->zlib_text_window_bits; + memLevel = png_ptr->zlib_text_mem_level; + strategy = png_ptr->zlib_text_strategy; +#else + /* If customization is not supported the values all come from the + * IDAT values except for the strategy, which is fixed to the + * default. (This is the pre-1.6.0 behavior too, although it was + * implemented in a very different way.) + */ + strategy = Z_DEFAULT_STRATEGY; +#endif + } + + /* Adjust 'windowBits' down if larger than 'data_size'; to stop this + * happening just pass 32768 as the data_size parameter. Notice that zlib + * requires an extra 262 bytes in the window in addition to the data to be + * able to see the whole of the data, so if data_size+262 takes us to the + * next windowBits size we need to fix up the value later. (Because even + * though deflate needs the extra window, inflate does not!) + */ + if (data_size <= 16384) + { + /* IMPLEMENTATION NOTE: this 'half_window_size' stuff is only here to + * work round a Microsoft Visual C misbehavior which, contrary to C-90, + * widens the result of the following shift to 64-bits if (and, + * apparently, only if) it is used in a test. + */ + unsigned int half_window_size = 1U << (windowBits-1); + + while (data_size + 262 <= half_window_size) + { + half_window_size >>= 1; + --windowBits; + } + } + + /* Check against the previous initialized values, if any. */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0 && + (png_ptr->zlib_set_level != level || + png_ptr->zlib_set_method != method || + png_ptr->zlib_set_window_bits != windowBits || + png_ptr->zlib_set_mem_level != memLevel || + png_ptr->zlib_set_strategy != strategy)) + { + if (deflateEnd(&png_ptr->zstream) != Z_OK) + png_warning(png_ptr, "deflateEnd failed (ignored)"); + + png_ptr->flags &= ~PNG_FLAG_ZSTREAM_INITIALIZED; + } + + /* For safety clear out the input and output pointers (currently zlib + * doesn't use them on Init, but it might in the future). + */ + png_ptr->zstream.next_in = NULL; + png_ptr->zstream.avail_in = 0; + png_ptr->zstream.next_out = NULL; + png_ptr->zstream.avail_out = 0; + + /* Now initialize if required, setting the new parameters, otherwise just + * do a simple reset to the previous parameters. + */ + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0) + ret = deflateReset(&png_ptr->zstream); + + else + { + ret = deflateInit2(&png_ptr->zstream, level, method, windowBits, + memLevel, strategy); + + if (ret == Z_OK) + png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED; + } + + /* The return code is from either deflateReset or deflateInit2; they have + * pretty much the same set of error codes. + */ + if (ret == Z_OK) + png_ptr->zowner = owner; + + else + png_zstream_error(png_ptr, ret); + + return ret; + } +} + +/* Clean up (or trim) a linked list of compression buffers. */ +void /* PRIVATE */ +png_free_buffer_list(png_structrp png_ptr, png_compression_bufferp *listp) +{ + png_compression_bufferp list = *listp; + + if (list != NULL) + { + *listp = NULL; + + do + { + png_compression_bufferp next = list->next; + + png_free(png_ptr, list); + list = next; + } + while (list != NULL); + } +} + +#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED +/* This pair of functions encapsulates the operation of (a) compressing a + * text string, and (b) issuing it later as a series of chunk data writes. + * The compression_state structure is shared context for these functions + * set up by the caller to allow access to the relevant local variables. + * + * compression_buffer (new in 1.6.0) is just a linked list of zbuffer_size + * temporary buffers. From 1.6.0 it is retained in png_struct so that it will + * be correctly freed in the event of a write error (previous implementations + * just leaked memory.) + */ +typedef struct +{ + png_const_bytep input; /* The uncompressed input data */ + png_alloc_size_t input_len; /* Its length */ + png_uint_32 output_len; /* Final compressed length */ + png_byte output[1024]; /* First block of output */ +} compression_state; + +static void +png_text_compress_init(compression_state *comp, png_const_bytep input, + png_alloc_size_t input_len) +{ + comp->input = input; + comp->input_len = input_len; + comp->output_len = 0; +} + +/* Compress the data in the compression state input */ +static int +png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name, + compression_state *comp, png_uint_32 prefix_len) +{ + int ret; + + /* To find the length of the output it is necessary to first compress the + * input. The result is buffered rather than using the two-pass algorithm + * that is used on the inflate side; deflate is assumed to be slower and a + * PNG writer is assumed to have more memory available than a PNG reader. + * + * IMPLEMENTATION NOTE: the zlib API deflateBound() can be used to find an + * upper limit on the output size, but it is always bigger than the input + * size so it is likely to be more efficient to use this linked-list + * approach. + */ + ret = png_deflate_claim(png_ptr, chunk_name, comp->input_len); + + if (ret != Z_OK) + return ret; + + /* Set up the compression buffers, we need a loop here to avoid overflowing a + * uInt. Use ZLIB_IO_MAX to limit the input. The output is always limited + * by the output buffer size, so there is no need to check that. Since this + * is ANSI-C we know that an 'int', hence a uInt, is always at least 16 bits + * in size. + */ + { + png_compression_bufferp *end = &png_ptr->zbuffer_list; + png_alloc_size_t input_len = comp->input_len; /* may be zero! */ + png_uint_32 output_len; + + /* zlib updates these for us: */ + png_ptr->zstream.next_in = PNGZ_INPUT_CAST(comp->input); + png_ptr->zstream.avail_in = 0; /* Set below */ + png_ptr->zstream.next_out = comp->output; + png_ptr->zstream.avail_out = (sizeof comp->output); + + output_len = png_ptr->zstream.avail_out; + + do + { + uInt avail_in = ZLIB_IO_MAX; + + if (avail_in > input_len) + avail_in = (uInt)input_len; + + input_len -= avail_in; + + png_ptr->zstream.avail_in = avail_in; + + if (png_ptr->zstream.avail_out == 0) + { + png_compression_buffer *next; + + /* Chunk data is limited to 2^31 bytes in length, so the prefix + * length must be counted here. + */ + if (output_len + prefix_len > PNG_UINT_31_MAX) + { + ret = Z_MEM_ERROR; + break; + } + + /* Need a new (malloc'ed) buffer, but there may be one present + * already. + */ + next = *end; + if (next == NULL) + { + next = png_voidcast(png_compression_bufferp, png_malloc_base + (png_ptr, PNG_COMPRESSION_BUFFER_SIZE(png_ptr))); + + if (next == NULL) + { + ret = Z_MEM_ERROR; + break; + } + + /* Link in this buffer (so that it will be freed later) */ + next->next = NULL; + *end = next; + } + + png_ptr->zstream.next_out = next->output; + png_ptr->zstream.avail_out = png_ptr->zbuffer_size; + output_len += png_ptr->zstream.avail_out; + + /* Move 'end' to the next buffer pointer. */ + end = &next->next; + } + + /* Compress the data */ + ret = deflate(&png_ptr->zstream, + input_len > 0 ? Z_NO_FLUSH : Z_FINISH); + + /* Claw back input data that was not consumed (because avail_in is + * reset above every time round the loop). + */ + input_len += png_ptr->zstream.avail_in; + png_ptr->zstream.avail_in = 0; /* safety */ + } + while (ret == Z_OK); + + /* There may be some space left in the last output buffer. This needs to + * be subtracted from output_len. + */ + output_len -= png_ptr->zstream.avail_out; + png_ptr->zstream.avail_out = 0; /* safety */ + comp->output_len = output_len; + + /* Now double check the output length, put in a custom message if it is + * too long. Otherwise ensure the z_stream::msg pointer is set to + * something. + */ + if (output_len + prefix_len >= PNG_UINT_31_MAX) + { + png_ptr->zstream.msg = PNGZ_MSG_CAST("compressed data too long"); + ret = Z_MEM_ERROR; + } + + else + png_zstream_error(png_ptr, ret); + + /* Reset zlib for another zTXt/iTXt or image data */ + png_ptr->zowner = 0; + + /* The only success case is Z_STREAM_END, input_len must be 0; if not this + * is an internal error. + */ + if (ret == Z_STREAM_END && input_len == 0) + { +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + /* Fix up the deflate header, if required */ + optimize_cmf(comp->output, comp->input_len); +#endif + /* But Z_OK is returned, not Z_STREAM_END; this allows the claim + * function above to return Z_STREAM_END on an error (though it never + * does in the current versions of zlib.) + */ + return Z_OK; + } + + else + return ret; + } +} + +/* Ship the compressed text out via chunk writes */ +static void +png_write_compressed_data_out(png_structrp png_ptr, compression_state *comp) +{ + png_uint_32 output_len = comp->output_len; + png_const_bytep output = comp->output; + png_uint_32 avail = (sizeof comp->output); + png_compression_buffer *next = png_ptr->zbuffer_list; + + for (;;) + { + if (avail > output_len) + avail = output_len; + + png_write_chunk_data(png_ptr, output, avail); + + output_len -= avail; + + if (output_len == 0 || next == NULL) + break; + + avail = png_ptr->zbuffer_size; + output = next->output; + next = next->next; + } + + /* This is an internal error; 'next' must have been NULL! */ + if (output_len > 0) + png_error(png_ptr, "error writing ancillary chunked compressed data"); +} +#endif /* WRITE_COMPRESSED_TEXT */ + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. Note that the rest of this code depends upon this + * information being correct. + */ +void /* PRIVATE */ +png_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height, + int bit_depth, int color_type, int compression_type, int filter_type, + int interlace_type) +{ + png_byte buf[13]; /* Buffer to store the IHDR info */ + int is_invalid_depth; + + png_debug(1, "in png_write_IHDR"); + + /* Check that we have valid input data from the application info */ + switch (color_type) + { + case PNG_COLOR_TYPE_GRAY: + switch (bit_depth) + { + case 1: + case 2: + case 4: + case 8: +#ifdef PNG_WRITE_16BIT_SUPPORTED + case 16: +#endif + png_ptr->channels = 1; break; + + default: + png_error(png_ptr, + "Invalid bit depth for grayscale image"); + } + break; + + case PNG_COLOR_TYPE_RGB: + is_invalid_depth = (bit_depth != 8); +#ifdef PNG_WRITE_16BIT_SUPPORTED + is_invalid_depth = (is_invalid_depth && bit_depth != 16); +#endif + if (is_invalid_depth) + png_error(png_ptr, "Invalid bit depth for RGB image"); + + png_ptr->channels = 3; + break; + + case PNG_COLOR_TYPE_PALETTE: + switch (bit_depth) + { + case 1: + case 2: + case 4: + case 8: + png_ptr->channels = 1; + break; + + default: + png_error(png_ptr, "Invalid bit depth for paletted image"); + } + break; + + case PNG_COLOR_TYPE_GRAY_ALPHA: + is_invalid_depth = (bit_depth != 8); +#ifdef PNG_WRITE_16BIT_SUPPORTED + is_invalid_depth = (is_invalid_depth && bit_depth != 16); +#endif + if (is_invalid_depth) + png_error(png_ptr, "Invalid bit depth for grayscale+alpha image"); + + png_ptr->channels = 2; + break; + + case PNG_COLOR_TYPE_RGB_ALPHA: + is_invalid_depth = (bit_depth != 8); +#ifdef PNG_WRITE_16BIT_SUPPORTED + is_invalid_depth = (is_invalid_depth && bit_depth != 16); +#endif + if (is_invalid_depth) + png_error(png_ptr, "Invalid bit depth for RGBA image"); + + png_ptr->channels = 4; + break; + + default: + png_error(png_ptr, "Invalid image color type specified"); + } + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + { + png_warning(png_ptr, "Invalid compression type specified"); + compression_type = PNG_COMPRESSION_TYPE_BASE; + } + + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ( +#ifdef PNG_MNG_FEATURES_SUPPORTED + !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 && + ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && +#endif + filter_type != PNG_FILTER_TYPE_BASE) + { + png_warning(png_ptr, "Invalid filter type specified"); + filter_type = PNG_FILTER_TYPE_BASE; + } + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + if (interlace_type != PNG_INTERLACE_NONE && + interlace_type != PNG_INTERLACE_ADAM7) + { + png_warning(png_ptr, "Invalid interlace type specified"); + interlace_type = PNG_INTERLACE_ADAM7; + } +#else + interlace_type=PNG_INTERLACE_NONE; +#endif + + /* Save the relevant information */ + png_ptr->bit_depth = (png_byte)bit_depth; + png_ptr->color_type = (png_byte)color_type; + png_ptr->interlaced = (png_byte)interlace_type; +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_ptr->filter_type = (png_byte)filter_type; +#endif + png_ptr->compression_type = (png_byte)compression_type; + png_ptr->width = width; + png_ptr->height = height; + + png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels); + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); + /* Set the usr info, so any transformations can modify it */ + png_ptr->usr_width = png_ptr->width; + png_ptr->usr_bit_depth = png_ptr->bit_depth; + png_ptr->usr_channels = png_ptr->channels; + + /* Pack the header information into the buffer */ + png_save_uint_32(buf, width); + png_save_uint_32(buf + 4, height); + buf[8] = (png_byte)bit_depth; + buf[9] = (png_byte)color_type; + buf[10] = (png_byte)compression_type; + buf[11] = (png_byte)filter_type; + buf[12] = (png_byte)interlace_type; + + /* Write the chunk */ + png_write_complete_chunk(png_ptr, png_IHDR, buf, 13); + + if ((png_ptr->do_filter) == PNG_NO_FILTERS) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || + png_ptr->bit_depth < 8) + png_ptr->do_filter = PNG_FILTER_NONE; + + else + png_ptr->do_filter = PNG_ALL_FILTERS; + } + + png_ptr->mode = PNG_HAVE_IHDR; /* not READY_FOR_ZTXT */ +} + +/* Write the palette. We are careful not to trust png_color to be in the + * correct order for PNG, so people can redefine it to any convenient + * structure. + */ +void /* PRIVATE */ +png_write_PLTE(png_structrp png_ptr, png_const_colorp palette, + png_uint_32 num_pal) +{ + png_uint_32 max_palette_length, i; + png_const_colorp pal_ptr; + png_byte buf[3]; + + png_debug(1, "in png_write_PLTE"); + + max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? + (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; + + if (( +#ifdef PNG_MNG_FEATURES_SUPPORTED + (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 && +#endif + num_pal == 0) || num_pal > max_palette_length) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_error(png_ptr, "Invalid number of colors in palette"); + } + + else + { + png_warning(png_ptr, "Invalid number of colors in palette"); + return; + } + } + + if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) + { + png_warning(png_ptr, + "Ignoring request to write a PLTE chunk in grayscale PNG"); + + return; + } + + png_ptr->num_palette = (png_uint_16)num_pal; + png_debug1(3, "num_palette = %d", png_ptr->num_palette); + + png_write_chunk_header(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3)); +#ifdef PNG_POINTER_INDEXING_SUPPORTED + + for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) + { + buf[0] = pal_ptr->red; + buf[1] = pal_ptr->green; + buf[2] = pal_ptr->blue; + png_write_chunk_data(png_ptr, buf, 3); + } + +#else + /* This is a little slower but some buggy compilers need to do this + * instead + */ + pal_ptr=palette; + + for (i = 0; i < num_pal; i++) + { + buf[0] = pal_ptr[i].red; + buf[1] = pal_ptr[i].green; + buf[2] = pal_ptr[i].blue; + png_write_chunk_data(png_ptr, buf, 3); + } + +#endif + png_write_chunk_end(png_ptr); + png_ptr->mode |= PNG_HAVE_PLTE; +} + +/* This is similar to png_text_compress, above, except that it does not require + * all of the data at once and, instead of buffering the compressed result, + * writes it as IDAT chunks. Unlike png_text_compress it *can* png_error out + * because it calls the write interface. As a result it does its own error + * reporting and does not return an error code. In the event of error it will + * just call png_error. The input data length may exceed 32-bits. The 'flush' + * parameter is exactly the same as that to deflate, with the following + * meanings: + * + * Z_NO_FLUSH: normal incremental output of compressed data + * Z_SYNC_FLUSH: do a SYNC_FLUSH, used by png_write_flush + * Z_FINISH: this is the end of the input, do a Z_FINISH and clean up + * + * The routine manages the acquire and release of the png_ptr->zstream by + * checking and (at the end) clearing png_ptr->zowner; it does some sanity + * checks on the 'mode' flags while doing this. + */ +void /* PRIVATE */ +png_compress_IDAT(png_structrp png_ptr, png_const_bytep input, + png_alloc_size_t input_len, int flush) +{ + if (png_ptr->zowner != png_IDAT) + { + /* First time. Ensure we have a temporary buffer for compression and + * trim the buffer list if it has more than one entry to free memory. + * If 'WRITE_COMPRESSED_TEXT' is not set the list will never have been + * created at this point, but the check here is quick and safe. + */ + if (png_ptr->zbuffer_list == NULL) + { + png_ptr->zbuffer_list = png_voidcast(png_compression_bufferp, + png_malloc(png_ptr, PNG_COMPRESSION_BUFFER_SIZE(png_ptr))); + png_ptr->zbuffer_list->next = NULL; + } + + else + png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list->next); + + /* It is a terminal error if we can't claim the zstream. */ + if (png_deflate_claim(png_ptr, png_IDAT, png_image_size(png_ptr)) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); + + /* The output state is maintained in png_ptr->zstream, so it must be + * initialized here after the claim. + */ + png_ptr->zstream.next_out = png_ptr->zbuffer_list->output; + png_ptr->zstream.avail_out = png_ptr->zbuffer_size; + } + + /* Now loop reading and writing until all the input is consumed or an error + * terminates the operation. The _out values are maintained across calls to + * this function, but the input must be reset each time. + */ + png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input); + png_ptr->zstream.avail_in = 0; /* set below */ + for (;;) + { + int ret; + + /* INPUT: from the row data */ + uInt avail = ZLIB_IO_MAX; + + if (avail > input_len) + avail = (uInt)input_len; /* safe because of the check */ + + png_ptr->zstream.avail_in = avail; + input_len -= avail; + + ret = deflate(&png_ptr->zstream, input_len > 0 ? Z_NO_FLUSH : flush); + + /* Include as-yet unconsumed input */ + input_len += png_ptr->zstream.avail_in; + png_ptr->zstream.avail_in = 0; + + /* OUTPUT: write complete IDAT chunks when avail_out drops to zero. Note + * that these two zstream fields are preserved across the calls, therefore + * there is no need to set these up on entry to the loop. + */ + if (png_ptr->zstream.avail_out == 0) + { + png_bytep data = png_ptr->zbuffer_list->output; + uInt size = png_ptr->zbuffer_size; + + /* Write an IDAT containing the data then reset the buffer. The + * first IDAT may need deflate header optimization. + */ +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0 && + png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) + optimize_cmf(data, png_image_size(png_ptr)); +#endif + + if (size > 0) + png_write_complete_chunk(png_ptr, png_IDAT, data, size); + png_ptr->mode |= PNG_HAVE_IDAT; + + png_ptr->zstream.next_out = data; + png_ptr->zstream.avail_out = size; + + /* For SYNC_FLUSH or FINISH it is essential to keep calling zlib with + * the same flush parameter until it has finished output, for NO_FLUSH + * it doesn't matter. + */ + if (ret == Z_OK && flush != Z_NO_FLUSH) + continue; + } + + /* The order of these checks doesn't matter much; it just affects which + * possible error might be detected if multiple things go wrong at once. + */ + if (ret == Z_OK) /* most likely return code! */ + { + /* If all the input has been consumed then just return. If Z_FINISH + * was used as the flush parameter something has gone wrong if we get + * here. + */ + if (input_len == 0) + { + if (flush == Z_FINISH) + png_error(png_ptr, "Z_OK on Z_FINISH with output space"); + + return; + } + } + + else if (ret == Z_STREAM_END && flush == Z_FINISH) + { + /* This is the end of the IDAT data; any pending output must be + * flushed. For small PNG files we may still be at the beginning. + */ + png_bytep data = png_ptr->zbuffer_list->output; + uInt size = png_ptr->zbuffer_size - png_ptr->zstream.avail_out; + +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + if ((png_ptr->mode & PNG_HAVE_IDAT) == 0 && + png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) + optimize_cmf(data, png_image_size(png_ptr)); +#endif + + if (size > 0) + png_write_complete_chunk(png_ptr, png_IDAT, data, size); + png_ptr->zstream.avail_out = 0; + png_ptr->zstream.next_out = NULL; + png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT; + + png_ptr->zowner = 0; /* Release the stream */ + return; + } + + else + { + /* This is an error condition. */ + png_zstream_error(png_ptr, ret); + png_error(png_ptr, png_ptr->zstream.msg); + } + } +} + +/* Write an IEND chunk */ +void /* PRIVATE */ +png_write_IEND(png_structrp png_ptr) +{ + png_debug(1, "in png_write_IEND"); + + png_write_complete_chunk(png_ptr, png_IEND, NULL, 0); + png_ptr->mode |= PNG_HAVE_IEND; +} + +#ifdef PNG_WRITE_gAMA_SUPPORTED +/* Write a gAMA chunk */ +void /* PRIVATE */ +png_write_gAMA_fixed(png_structrp png_ptr, png_fixed_point file_gamma) +{ + png_byte buf[4]; + + png_debug(1, "in png_write_gAMA"); + + /* file_gamma is saved in 1/100,000ths */ + png_save_uint_32(buf, (png_uint_32)file_gamma); + png_write_complete_chunk(png_ptr, png_gAMA, buf, 4); +} +#endif + +#ifdef PNG_WRITE_sRGB_SUPPORTED +/* Write a sRGB chunk */ +void /* PRIVATE */ +png_write_sRGB(png_structrp png_ptr, int srgb_intent) +{ + png_byte buf[1]; + + png_debug(1, "in png_write_sRGB"); + + if (srgb_intent >= PNG_sRGB_INTENT_LAST) + png_warning(png_ptr, + "Invalid sRGB rendering intent specified"); + + buf[0]=(png_byte)srgb_intent; + png_write_complete_chunk(png_ptr, png_sRGB, buf, 1); +} +#endif + +#ifdef PNG_WRITE_iCCP_SUPPORTED +/* Write an iCCP chunk */ +void /* PRIVATE */ +png_write_iCCP(png_structrp png_ptr, png_const_charp name, + png_const_bytep profile) +{ + png_uint_32 name_len; + png_uint_32 profile_len; + png_byte new_name[81]; /* 1 byte for the compression byte */ + compression_state comp; + png_uint_32 temp; + + png_debug(1, "in png_write_iCCP"); + + /* These are all internal problems: the profile should have been checked + * before when it was stored. + */ + if (profile == NULL) + png_error(png_ptr, "No profile for iCCP chunk"); /* internal error */ + + profile_len = png_get_uint_32(profile); + + if (profile_len < 132) + png_error(png_ptr, "ICC profile too short"); + + temp = (png_uint_32) (*(profile+8)); + if (temp > 3 && (profile_len & 0x03)) + png_error(png_ptr, "ICC profile length invalid (not a multiple of 4)"); + + { + png_uint_32 embedded_profile_len = png_get_uint_32(profile); + + if (profile_len != embedded_profile_len) + png_error(png_ptr, "Profile length does not match profile"); + } + + name_len = png_check_keyword(png_ptr, name, new_name); + + if (name_len == 0) + png_error(png_ptr, "iCCP: invalid keyword"); + + new_name[++name_len] = PNG_COMPRESSION_TYPE_BASE; + + /* Make sure we include the NULL after the name and the compression type */ + ++name_len; + + png_text_compress_init(&comp, profile, profile_len); + + /* Allow for keyword terminator and compression byte */ + if (png_text_compress(png_ptr, png_iCCP, &comp, name_len) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); + + png_write_chunk_header(png_ptr, png_iCCP, name_len + comp.output_len); + + png_write_chunk_data(png_ptr, new_name, name_len); + + png_write_compressed_data_out(png_ptr, &comp); + + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_sPLT_SUPPORTED +/* Write a sPLT chunk */ +void /* PRIVATE */ +png_write_sPLT(png_structrp png_ptr, png_const_sPLT_tp spalette) +{ + png_uint_32 name_len; + png_byte new_name[80]; + png_byte entrybuf[10]; + size_t entry_size = (spalette->depth == 8 ? 6 : 10); + size_t palette_size = entry_size * (size_t)spalette->nentries; + png_sPLT_entryp ep; +#ifndef PNG_POINTER_INDEXING_SUPPORTED + int i; +#endif + + png_debug(1, "in png_write_sPLT"); + + name_len = png_check_keyword(png_ptr, spalette->name, new_name); + + if (name_len == 0) + png_error(png_ptr, "sPLT: invalid keyword"); + + /* Make sure we include the NULL after the name */ + png_write_chunk_header(png_ptr, png_sPLT, + (png_uint_32)(name_len + 2 + palette_size)); + + png_write_chunk_data(png_ptr, (png_bytep)new_name, (size_t)(name_len + 1)); + + png_write_chunk_data(png_ptr, &spalette->depth, 1); + + /* Loop through each palette entry, writing appropriately */ +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (ep = spalette->entries; epentries + spalette->nentries; ep++) + { + if (spalette->depth == 8) + { + entrybuf[0] = (png_byte)ep->red; + entrybuf[1] = (png_byte)ep->green; + entrybuf[2] = (png_byte)ep->blue; + entrybuf[3] = (png_byte)ep->alpha; + png_save_uint_16(entrybuf + 4, ep->frequency); + } + + else + { + png_save_uint_16(entrybuf + 0, ep->red); + png_save_uint_16(entrybuf + 2, ep->green); + png_save_uint_16(entrybuf + 4, ep->blue); + png_save_uint_16(entrybuf + 6, ep->alpha); + png_save_uint_16(entrybuf + 8, ep->frequency); + } + + png_write_chunk_data(png_ptr, entrybuf, entry_size); + } +#else + ep=spalette->entries; + for (i = 0; i>spalette->nentries; i++) + { + if (spalette->depth == 8) + { + entrybuf[0] = (png_byte)ep[i].red; + entrybuf[1] = (png_byte)ep[i].green; + entrybuf[2] = (png_byte)ep[i].blue; + entrybuf[3] = (png_byte)ep[i].alpha; + png_save_uint_16(entrybuf + 4, ep[i].frequency); + } + + else + { + png_save_uint_16(entrybuf + 0, ep[i].red); + png_save_uint_16(entrybuf + 2, ep[i].green); + png_save_uint_16(entrybuf + 4, ep[i].blue); + png_save_uint_16(entrybuf + 6, ep[i].alpha); + png_save_uint_16(entrybuf + 8, ep[i].frequency); + } + + png_write_chunk_data(png_ptr, entrybuf, entry_size); + } +#endif + + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_sBIT_SUPPORTED +/* Write the sBIT chunk */ +void /* PRIVATE */ +png_write_sBIT(png_structrp png_ptr, png_const_color_8p sbit, int color_type) +{ + png_byte buf[4]; + size_t size; + + png_debug(1, "in png_write_sBIT"); + + /* Make sure we don't depend upon the order of PNG_COLOR_8 */ + if ((color_type & PNG_COLOR_MASK_COLOR) != 0) + { + png_byte maxbits; + + maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 : + png_ptr->usr_bit_depth); + + if (sbit->red == 0 || sbit->red > maxbits || + sbit->green == 0 || sbit->green > maxbits || + sbit->blue == 0 || sbit->blue > maxbits) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + + buf[0] = sbit->red; + buf[1] = sbit->green; + buf[2] = sbit->blue; + size = 3; + } + + else + { + if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + + buf[0] = sbit->gray; + size = 1; + } + + if ((color_type & PNG_COLOR_MASK_ALPHA) != 0) + { + if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + + buf[size++] = sbit->alpha; + } + + png_write_complete_chunk(png_ptr, png_sBIT, buf, size); +} +#endif + +#ifdef PNG_WRITE_cHRM_SUPPORTED +/* Write the cHRM chunk */ +void /* PRIVATE */ +png_write_cHRM_fixed(png_structrp png_ptr, const png_xy *xy) +{ + png_byte buf[32]; + + png_debug(1, "in png_write_cHRM"); + + /* Each value is saved in 1/100,000ths */ + png_save_int_32(buf, xy->whitex); + png_save_int_32(buf + 4, xy->whitey); + + png_save_int_32(buf + 8, xy->redx); + png_save_int_32(buf + 12, xy->redy); + + png_save_int_32(buf + 16, xy->greenx); + png_save_int_32(buf + 20, xy->greeny); + + png_save_int_32(buf + 24, xy->bluex); + png_save_int_32(buf + 28, xy->bluey); + + png_write_complete_chunk(png_ptr, png_cHRM, buf, 32); +} +#endif + +#ifdef PNG_WRITE_tRNS_SUPPORTED +/* Write the tRNS chunk */ +void /* PRIVATE */ +png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, + png_const_color_16p tran, int num_trans, int color_type) +{ + png_byte buf[6]; + + png_debug(1, "in png_write_tRNS"); + + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) + { + png_app_warning(png_ptr, + "Invalid number of transparent colors specified"); + return; + } + + /* Write the chunk out as it is */ + png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha, + (size_t)num_trans); + } + + else if (color_type == PNG_COLOR_TYPE_GRAY) + { + /* One 16-bit value */ + if (tran->gray >= (1 << png_ptr->bit_depth)) + { + png_app_warning(png_ptr, + "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); + + return; + } + + png_save_uint_16(buf, tran->gray); + png_write_complete_chunk(png_ptr, png_tRNS, buf, 2); + } + + else if (color_type == PNG_COLOR_TYPE_RGB) + { + /* Three 16-bit values */ + png_save_uint_16(buf, tran->red); + png_save_uint_16(buf + 2, tran->green); + png_save_uint_16(buf + 4, tran->blue); +#ifdef PNG_WRITE_16BIT_SUPPORTED + if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]) != 0) +#else + if ((buf[0] | buf[2] | buf[4]) != 0) +#endif + { + png_app_warning(png_ptr, + "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); + return; + } + + png_write_complete_chunk(png_ptr, png_tRNS, buf, 6); + } + + else + { + png_app_warning(png_ptr, "Can't write tRNS with an alpha channel"); + } +} +#endif + +#ifdef PNG_WRITE_bKGD_SUPPORTED +/* Write the background chunk */ +void /* PRIVATE */ +png_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type) +{ + png_byte buf[6]; + + png_debug(1, "in png_write_bKGD"); + + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + if ( +#ifdef PNG_MNG_FEATURES_SUPPORTED + (png_ptr->num_palette != 0 || + (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0) && +#endif + back->index >= png_ptr->num_palette) + { + png_warning(png_ptr, "Invalid background palette index"); + return; + } + + buf[0] = back->index; + png_write_complete_chunk(png_ptr, png_bKGD, buf, 1); + } + + else if ((color_type & PNG_COLOR_MASK_COLOR) != 0) + { + png_save_uint_16(buf, back->red); + png_save_uint_16(buf + 2, back->green); + png_save_uint_16(buf + 4, back->blue); +#ifdef PNG_WRITE_16BIT_SUPPORTED + if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]) != 0) +#else + if ((buf[0] | buf[2] | buf[4]) != 0) +#endif + { + png_warning(png_ptr, + "Ignoring attempt to write 16-bit bKGD chunk " + "when bit_depth is 8"); + + return; + } + + png_write_complete_chunk(png_ptr, png_bKGD, buf, 6); + } + + else + { + if (back->gray >= (1 << png_ptr->bit_depth)) + { + png_warning(png_ptr, + "Ignoring attempt to write bKGD chunk out-of-range for bit_depth"); + + return; + } + + png_save_uint_16(buf, back->gray); + png_write_complete_chunk(png_ptr, png_bKGD, buf, 2); + } +} +#endif + +#ifdef PNG_WRITE_eXIf_SUPPORTED +/* Write the Exif data */ +void /* PRIVATE */ +png_write_eXIf(png_structrp png_ptr, png_bytep exif, int num_exif) +{ + int i; + png_byte buf[1]; + + png_debug(1, "in png_write_eXIf"); + + png_write_chunk_header(png_ptr, png_eXIf, (png_uint_32)(num_exif)); + + for (i = 0; i < num_exif; i++) + { + buf[0] = exif[i]; + png_write_chunk_data(png_ptr, buf, 1); + } + + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED +/* Write the histogram */ +void /* PRIVATE */ +png_write_hIST(png_structrp png_ptr, png_const_uint_16p hist, int num_hist) +{ + int i; + png_byte buf[3]; + + png_debug(1, "in png_write_hIST"); + + if (num_hist > (int)png_ptr->num_palette) + { + png_debug2(3, "num_hist = %d, num_palette = %d", num_hist, + png_ptr->num_palette); + + png_warning(png_ptr, "Invalid number of histogram entries specified"); + return; + } + + png_write_chunk_header(png_ptr, png_hIST, (png_uint_32)(num_hist * 2)); + + for (i = 0; i < num_hist; i++) + { + png_save_uint_16(buf, hist[i]); + png_write_chunk_data(png_ptr, buf, 2); + } + + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_tEXt_SUPPORTED +/* Write a tEXt chunk */ +void /* PRIVATE */ +png_write_tEXt(png_structrp png_ptr, png_const_charp key, png_const_charp text, + size_t text_len) +{ + png_uint_32 key_len; + png_byte new_key[80]; + + png_debug(1, "in png_write_tEXt"); + + key_len = png_check_keyword(png_ptr, key, new_key); + + if (key_len == 0) + png_error(png_ptr, "tEXt: invalid keyword"); + + if (text == NULL || *text == '\0') + text_len = 0; + + else + text_len = strlen(text); + + if (text_len > PNG_UINT_31_MAX - (key_len+1)) + png_error(png_ptr, "tEXt: text too long"); + + /* Make sure we include the 0 after the key */ + png_write_chunk_header(png_ptr, png_tEXt, + (png_uint_32)/*checked above*/(key_len + text_len + 1)); + /* + * We leave it to the application to meet PNG-1.0 requirements on the + * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of + * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. + * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + */ + png_write_chunk_data(png_ptr, new_key, key_len + 1); + + if (text_len != 0) + png_write_chunk_data(png_ptr, (png_const_bytep)text, text_len); + + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_zTXt_SUPPORTED +/* Write a compressed text chunk */ +void /* PRIVATE */ +png_write_zTXt(png_structrp png_ptr, png_const_charp key, png_const_charp text, + int compression) +{ + png_uint_32 key_len; + png_byte new_key[81]; + compression_state comp; + + png_debug(1, "in png_write_zTXt"); + + if (compression == PNG_TEXT_COMPRESSION_NONE) + { + png_write_tEXt(png_ptr, key, text, 0); + return; + } + + if (compression != PNG_TEXT_COMPRESSION_zTXt) + png_error(png_ptr, "zTXt: invalid compression type"); + + key_len = png_check_keyword(png_ptr, key, new_key); + + if (key_len == 0) + png_error(png_ptr, "zTXt: invalid keyword"); + + /* Add the compression method and 1 for the keyword separator. */ + new_key[++key_len] = PNG_COMPRESSION_TYPE_BASE; + ++key_len; + + /* Compute the compressed data; do it now for the length */ + png_text_compress_init(&comp, (png_const_bytep)text, + text == NULL ? 0 : strlen(text)); + + if (png_text_compress(png_ptr, png_zTXt, &comp, key_len) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); + + /* Write start of chunk */ + png_write_chunk_header(png_ptr, png_zTXt, key_len + comp.output_len); + + /* Write key */ + png_write_chunk_data(png_ptr, new_key, key_len); + + /* Write the compressed data */ + png_write_compressed_data_out(png_ptr, &comp); + + /* Close the chunk */ + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_iTXt_SUPPORTED +/* Write an iTXt chunk */ +void /* PRIVATE */ +png_write_iTXt(png_structrp png_ptr, int compression, png_const_charp key, + png_const_charp lang, png_const_charp lang_key, png_const_charp text) +{ + png_uint_32 key_len, prefix_len; + size_t lang_len, lang_key_len; + png_byte new_key[82]; + compression_state comp; + + png_debug(1, "in png_write_iTXt"); + + key_len = png_check_keyword(png_ptr, key, new_key); + + if (key_len == 0) + png_error(png_ptr, "iTXt: invalid keyword"); + + /* Set the compression flag */ + switch (compression) + { + case PNG_ITXT_COMPRESSION_NONE: + case PNG_TEXT_COMPRESSION_NONE: + compression = new_key[++key_len] = 0; /* no compression */ + break; + + case PNG_TEXT_COMPRESSION_zTXt: + case PNG_ITXT_COMPRESSION_zTXt: + compression = new_key[++key_len] = 1; /* compressed */ + break; + + default: + png_error(png_ptr, "iTXt: invalid compression"); + } + + new_key[++key_len] = PNG_COMPRESSION_TYPE_BASE; + ++key_len; /* for the keywod separator */ + + /* We leave it to the application to meet PNG-1.0 requirements on the + * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of + * any non-Latin-1 characters except for NEWLINE. ISO PNG, however, + * specifies that the text is UTF-8 and this really doesn't require any + * checking. + * + * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + * + * TODO: validate the language tag correctly (see the spec.) + */ + if (lang == NULL) lang = ""; /* empty language is valid */ + lang_len = strlen(lang)+1; + if (lang_key == NULL) lang_key = ""; /* may be empty */ + lang_key_len = strlen(lang_key)+1; + if (text == NULL) text = ""; /* may be empty */ + + prefix_len = key_len; + if (lang_len > PNG_UINT_31_MAX-prefix_len) + prefix_len = PNG_UINT_31_MAX; + else + prefix_len = (png_uint_32)(prefix_len + lang_len); + + if (lang_key_len > PNG_UINT_31_MAX-prefix_len) + prefix_len = PNG_UINT_31_MAX; + else + prefix_len = (png_uint_32)(prefix_len + lang_key_len); + + png_text_compress_init(&comp, (png_const_bytep)text, strlen(text)); + + if (compression != 0) + { + if (png_text_compress(png_ptr, png_iTXt, &comp, prefix_len) != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg); + } + + else + { + if (comp.input_len > PNG_UINT_31_MAX-prefix_len) + png_error(png_ptr, "iTXt: uncompressed text too long"); + + /* So the string will fit in a chunk: */ + comp.output_len = (png_uint_32)/*SAFE*/comp.input_len; + } + + png_write_chunk_header(png_ptr, png_iTXt, comp.output_len + prefix_len); + + png_write_chunk_data(png_ptr, new_key, key_len); + + png_write_chunk_data(png_ptr, (png_const_bytep)lang, lang_len); + + png_write_chunk_data(png_ptr, (png_const_bytep)lang_key, lang_key_len); + + if (compression != 0) + png_write_compressed_data_out(png_ptr, &comp); + + else + png_write_chunk_data(png_ptr, (png_const_bytep)text, comp.output_len); + + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED +/* Write the oFFs chunk */ +void /* PRIVATE */ +png_write_oFFs(png_structrp png_ptr, png_int_32 x_offset, png_int_32 y_offset, + int unit_type) +{ + png_byte buf[9]; + + png_debug(1, "in png_write_oFFs"); + + if (unit_type >= PNG_OFFSET_LAST) + png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); + + png_save_int_32(buf, x_offset); + png_save_int_32(buf + 4, y_offset); + buf[8] = (png_byte)unit_type; + + png_write_complete_chunk(png_ptr, png_oFFs, buf, 9); +} +#endif +#ifdef PNG_WRITE_pCAL_SUPPORTED +/* Write the pCAL chunk (described in the PNG extensions document) */ +void /* PRIVATE */ +png_write_pCAL(png_structrp png_ptr, png_charp purpose, png_int_32 X0, + png_int_32 X1, int type, int nparams, png_const_charp units, + png_charpp params) +{ + png_uint_32 purpose_len; + size_t units_len, total_len; + png_size_tp params_len; + png_byte buf[10]; + png_byte new_purpose[80]; + int i; + + png_debug1(1, "in png_write_pCAL (%d parameters)", nparams); + + if (type >= PNG_EQUATION_LAST) + png_error(png_ptr, "Unrecognized equation type for pCAL chunk"); + + purpose_len = png_check_keyword(png_ptr, purpose, new_purpose); + + if (purpose_len == 0) + png_error(png_ptr, "pCAL: invalid keyword"); + + ++purpose_len; /* terminator */ + + png_debug1(3, "pCAL purpose length = %d", (int)purpose_len); + units_len = strlen(units) + (nparams == 0 ? 0 : 1); + png_debug1(3, "pCAL units length = %d", (int)units_len); + total_len = purpose_len + units_len + 10; + + params_len = (png_size_tp)png_malloc(png_ptr, + (png_alloc_size_t)((png_alloc_size_t)nparams * (sizeof (size_t)))); + + /* Find the length of each parameter, making sure we don't count the + * null terminator for the last parameter. + */ + for (i = 0; i < nparams; i++) + { + params_len[i] = strlen(params[i]) + (i == nparams - 1 ? 0 : 1); + png_debug2(3, "pCAL parameter %d length = %lu", i, + (unsigned long)params_len[i]); + total_len += params_len[i]; + } + + png_debug1(3, "pCAL total length = %d", (int)total_len); + png_write_chunk_header(png_ptr, png_pCAL, (png_uint_32)total_len); + png_write_chunk_data(png_ptr, new_purpose, purpose_len); + png_save_int_32(buf, X0); + png_save_int_32(buf + 4, X1); + buf[8] = (png_byte)type; + buf[9] = (png_byte)nparams; + png_write_chunk_data(png_ptr, buf, 10); + png_write_chunk_data(png_ptr, (png_const_bytep)units, (size_t)units_len); + + for (i = 0; i < nparams; i++) + { + png_write_chunk_data(png_ptr, (png_const_bytep)params[i], params_len[i]); + } + + png_free(png_ptr, params_len); + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED +/* Write the sCAL chunk */ +void /* PRIVATE */ +png_write_sCAL_s(png_structrp png_ptr, int unit, png_const_charp width, + png_const_charp height) +{ + png_byte buf[64]; + size_t wlen, hlen, total_len; + + png_debug(1, "in png_write_sCAL_s"); + + wlen = strlen(width); + hlen = strlen(height); + total_len = wlen + hlen + 2; + + if (total_len > 64) + { + png_warning(png_ptr, "Can't write sCAL (buffer too small)"); + return; + } + + buf[0] = (png_byte)unit; + memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */ + memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */ + + png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); + png_write_complete_chunk(png_ptr, png_sCAL, buf, total_len); +} +#endif + +#ifdef PNG_WRITE_pHYs_SUPPORTED +/* Write the pHYs chunk */ +void /* PRIVATE */ +png_write_pHYs(png_structrp png_ptr, png_uint_32 x_pixels_per_unit, + png_uint_32 y_pixels_per_unit, + int unit_type) +{ + png_byte buf[9]; + + png_debug(1, "in png_write_pHYs"); + + if (unit_type >= PNG_RESOLUTION_LAST) + png_warning(png_ptr, "Unrecognized unit type for pHYs chunk"); + + png_save_uint_32(buf, x_pixels_per_unit); + png_save_uint_32(buf + 4, y_pixels_per_unit); + buf[8] = (png_byte)unit_type; + + png_write_complete_chunk(png_ptr, png_pHYs, buf, 9); +} +#endif + +#ifdef PNG_WRITE_tIME_SUPPORTED +/* Write the tIME chunk. Use either png_convert_from_struct_tm() + * or png_convert_from_time_t(), or fill in the structure yourself. + */ +void /* PRIVATE */ +png_write_tIME(png_structrp png_ptr, png_const_timep mod_time) +{ + png_byte buf[7]; + + png_debug(1, "in png_write_tIME"); + + if (mod_time->month > 12 || mod_time->month < 1 || + mod_time->day > 31 || mod_time->day < 1 || + mod_time->hour > 23 || mod_time->second > 60) + { + png_warning(png_ptr, "Invalid time specified for tIME chunk"); + return; + } + + png_save_uint_16(buf, mod_time->year); + buf[2] = mod_time->month; + buf[3] = mod_time->day; + buf[4] = mod_time->hour; + buf[5] = mod_time->minute; + buf[6] = mod_time->second; + + png_write_complete_chunk(png_ptr, png_tIME, buf, 7); +} +#endif + +/* Initializes the row writing capability of libpng */ +void /* PRIVATE */ +png_write_start_row(png_structrp png_ptr) +{ +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + png_alloc_size_t buf_size; + int usr_pixel_depth; + +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_byte filters; +#endif + + png_debug(1, "in png_write_start_row"); + + usr_pixel_depth = png_ptr->usr_channels * png_ptr->usr_bit_depth; + buf_size = PNG_ROWBYTES(usr_pixel_depth, png_ptr->width) + 1; + + /* 1.5.6: added to allow checking in the row write code. */ + png_ptr->transformed_pixel_depth = png_ptr->pixel_depth; + png_ptr->maximum_pixel_depth = (png_byte)usr_pixel_depth; + + /* Set up row buffer */ + png_ptr->row_buf = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size)); + + png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; + +#ifdef PNG_WRITE_FILTER_SUPPORTED + filters = png_ptr->do_filter; + + if (png_ptr->height == 1) + filters &= 0xff & ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH); + + if (png_ptr->width == 1) + filters &= 0xff & ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH); + + if (filters == 0) + filters = PNG_FILTER_NONE; + + png_ptr->do_filter = filters; + + if (((filters & (PNG_FILTER_SUB | PNG_FILTER_UP | PNG_FILTER_AVG | + PNG_FILTER_PAETH)) != 0) && png_ptr->try_row == NULL) + { + int num_filters = 0; + + png_ptr->try_row = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size)); + + if (filters & PNG_FILTER_SUB) + num_filters++; + + if (filters & PNG_FILTER_UP) + num_filters++; + + if (filters & PNG_FILTER_AVG) + num_filters++; + + if (filters & PNG_FILTER_PAETH) + num_filters++; + + if (num_filters > 1) + png_ptr->tst_row = png_voidcast(png_bytep, png_malloc(png_ptr, + buf_size)); + } + + /* We only need to keep the previous row if we are using one of the following + * filters. + */ + if ((filters & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0) + png_ptr->prev_row = png_voidcast(png_bytep, + png_calloc(png_ptr, buf_size)); +#endif /* WRITE_FILTER */ + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced, we need to set up width and height of pass */ + if (png_ptr->interlaced != 0) + { + if ((png_ptr->transformations & PNG_INTERLACE) == 0) + { + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + + png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - + png_pass_start[0]) / png_pass_inc[0]; + } + + else + { + png_ptr->num_rows = png_ptr->height; + png_ptr->usr_width = png_ptr->width; + } + } + + else +#endif + { + png_ptr->num_rows = png_ptr->height; + png_ptr->usr_width = png_ptr->width; + } +} + +/* Internal use only. Called when finished processing a row of data. */ +void /* PRIVATE */ +png_write_finish_row(png_structrp png_ptr) +{ +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + png_debug(1, "in png_write_finish_row"); + + /* Next row */ + png_ptr->row_number++; + + /* See if we are done */ + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced, go to next pass */ + if (png_ptr->interlaced != 0) + { + png_ptr->row_number = 0; + if ((png_ptr->transformations & PNG_INTERLACE) != 0) + { + png_ptr->pass++; + } + + else + { + /* Loop until we find a non-zero width or height pass */ + do + { + png_ptr->pass++; + + if (png_ptr->pass >= 7) + break; + + png_ptr->usr_width = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + + if ((png_ptr->transformations & PNG_INTERLACE) != 0) + break; + + } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); + + } + + /* Reset the row above the image for the next pass */ + if (png_ptr->pass < 7) + { + if (png_ptr->prev_row != NULL) + memset(png_ptr->prev_row, 0, + PNG_ROWBYTES(png_ptr->usr_channels * + png_ptr->usr_bit_depth, png_ptr->width) + 1); + + return; + } + } +#endif + + /* If we get here, we've just written the last row, so we need + to flush the compressor */ + png_compress_IDAT(png_ptr, NULL, 0, Z_FINISH); +} + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED +/* Pick out the correct pixels for the interlace pass. + * The basic idea here is to go through the row with a source + * pointer and a destination pointer (sp and dp), and copy the + * correct pixels for the pass. As the row gets compacted, + * sp will always be >= dp, so we should never overwrite anything. + * See the default: case for the easiest code to understand. + */ +void /* PRIVATE */ +png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) +{ + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + png_debug(1, "in png_do_write_interlace"); + + /* We don't have to do anything on the last pass (6) */ + if (pass < 6) + { + /* Each pixel depth is handled separately */ + switch (row_info->pixel_depth) + { + case 1: + { + png_bytep sp; + png_bytep dp; + unsigned int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + d = 0; + shift = 7; + + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (size_t)(i >> 3); + value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01; + d |= (value << shift); + + if (shift == 0) + { + shift = 7; + *dp++ = (png_byte)d; + d = 0; + } + + else + shift--; + + } + if (shift != 7) + *dp = (png_byte)d; + + break; + } + + case 2: + { + png_bytep sp; + png_bytep dp; + unsigned int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + shift = 6; + d = 0; + + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (size_t)(i >> 2); + value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03; + d |= (value << shift); + + if (shift == 0) + { + shift = 6; + *dp++ = (png_byte)d; + d = 0; + } + + else + shift -= 2; + } + if (shift != 6) + *dp = (png_byte)d; + + break; + } + + case 4: + { + png_bytep sp; + png_bytep dp; + unsigned int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + shift = 4; + d = 0; + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (size_t)(i >> 1); + value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f; + d |= (value << shift); + + if (shift == 0) + { + shift = 4; + *dp++ = (png_byte)d; + d = 0; + } + + else + shift -= 4; + } + if (shift != 4) + *dp = (png_byte)d; + + break; + } + + default: + { + png_bytep sp; + png_bytep dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + size_t pixel_bytes; + + /* Start at the beginning */ + dp = row; + + /* Find out how many bytes each pixel takes up */ + pixel_bytes = (row_info->pixel_depth >> 3); + + /* Loop through the row, only looking at the pixels that matter */ + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + /* Find out where the original pixel is */ + sp = row + (size_t)i * pixel_bytes; + + /* Move the pixel */ + if (dp != sp) + memcpy(dp, sp, pixel_bytes); + + /* Next pixel */ + dp += pixel_bytes; + } + break; + } + } + /* Set new row width */ + row_info->width = (row_info->width + + png_pass_inc[pass] - 1 - + png_pass_start[pass]) / + png_pass_inc[pass]; + + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_info->width); + } + + png_write_chunk_end(png_ptr); +} +#endif + + +/* This filters the row, chooses which filter to use, if it has not already + * been specified by the application, and then writes the row out with the + * chosen filter. + */ +static void /* PRIVATE */ +png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row, + size_t row_bytes); + +#ifdef PNG_WRITE_FILTER_SUPPORTED +static size_t /* PRIVATE */ +png_setup_sub_row(png_structrp png_ptr, png_uint_32 bpp, + size_t row_bytes, size_t lmins) +{ + png_bytep rp, dp, lp; + size_t i; + size_t sum = 0; + unsigned int v; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1; i < bpp; + i++, rp++, dp++) + { + v = *dp = *rp; +#ifdef PNG_USE_ABS + sum += 128 - abs((int)v - 128); +#else + sum += (v < 128) ? v : 256 - v; +#endif + } + + for (lp = png_ptr->row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); +#ifdef PNG_USE_ABS + sum += 128 - abs((int)v - 128); +#else + sum += (v < 128) ? v : 256 - v; +#endif + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + + return (sum); +} +static void /* PRIVATE */ +png_setup_up_row_only(png_structrp png_ptr, size_t row_bytes) +{ + png_bytep rp, dp, pp; + size_t i; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_UP; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < row_bytes; + i++, rp++, pp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); + } +} + +static void /* PRIVATE */ +png_setup_sub_row_only(png_structrp png_ptr, png_uint_32 bpp, + size_t row_bytes) +{ + png_bytep rp, dp, lp; + size_t i; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1; i < bpp; + i++, rp++, dp++) + { + *dp = *rp; + } + + for (lp = png_ptr->row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); + } +} + +static size_t /* PRIVATE */ +png_setup_up_row(png_structrp png_ptr, size_t row_bytes, size_t lmins) +{ + png_bytep rp, dp, pp; + size_t i; + size_t sum = 0; + unsigned int v; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_UP; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < row_bytes; + i++, rp++, pp++, dp++) + { + v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); +#ifdef PNG_USE_ABS + sum += 128 - abs((int)v - 128); +#else + sum += (v < 128) ? v : 256 - v; +#endif + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + + return (sum); +} +static void /* PRIVATE */ +png_setup_up_row_only(png_structrp png_ptr, size_t row_bytes) +{ + png_bytep rp, dp, pp; + size_t i; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_UP; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < row_bytes; + i++, rp++, pp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); + } +} + +static size_t /* PRIVATE */ +png_setup_avg_row(png_structrp png_ptr, png_uint_32 bpp, + size_t row_bytes, size_t lmins) +{ + png_bytep rp, dp, pp, lp; + png_uint_32 i; + size_t sum = 0; + unsigned int v; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + +#ifdef PNG_USE_ABS + sum += 128 - abs((int)v - 128); +#else + sum += (v < 128) ? v : 256 - v; +#endif + } + + for (lp = png_ptr->row_buf + 1; i < row_bytes; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) + & 0xff); + +#ifdef PNG_USE_ABS + sum += 128 - abs((int)v - 128); +#else + sum += (v < 128) ? v : 256 - v; +#endif + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + + return (sum); +} +static void /* PRIVATE */ +png_setup_avg_row_only(png_structrp png_ptr, png_uint_32 bpp, + size_t row_bytes) +{ + png_bytep rp, dp, pp, lp; + png_uint_32 i; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < bpp; i++) + { + *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + } + + for (lp = png_ptr->row_buf + 1; i < row_bytes; i++) + { + *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) + & 0xff); + } +} + +static size_t /* PRIVATE */ +png_setup_paeth_row(png_structrp png_ptr, png_uint_32 bpp, + size_t row_bytes, size_t lmins) +{ + png_bytep rp, dp, pp, cp, lp; + size_t i; + size_t sum = 0; + unsigned int v; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + +#ifdef PNG_USE_ABS + sum += 128 - abs((int)v - 128); +#else + sum += (v < 128) ? v : 256 - v; +#endif + } + + for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes; + i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; + + v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + +#ifdef PNG_USE_ABS + sum += 128 - abs((int)v - 128); +#else + sum += (v < 128) ? v : 256 - v; +#endif + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + + return (sum); +} +static void /* PRIVATE */ +png_setup_paeth_row_only(png_structrp png_ptr, png_uint_32 bpp, + size_t row_bytes) +{ + png_bytep rp, dp, pp, cp, lp; + size_t i; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < bpp; i++) + { + *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + } + + for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes; + i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; + + *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + } +} +#endif /* WRITE_FILTER */ + +void /* PRIVATE */ +png_write_find_filter(png_structrp png_ptr, png_row_infop row_info) +{ +#ifndef PNG_WRITE_FILTER_SUPPORTED + png_write_filtered_row(png_ptr, png_ptr->row_buf, row_info->rowbytes+1); +#else + unsigned int filter_to_do = png_ptr->do_filter; + png_bytep row_buf; + png_bytep best_row; + png_uint_32 bpp; + size_t mins; + size_t row_bytes = row_info->rowbytes; + + png_debug(1, "in png_write_find_filter"); + + /* Find out how many bytes offset each pixel is */ + bpp = (row_info->pixel_depth + 7) >> 3; + + row_buf = png_ptr->row_buf; + mins = PNG_SIZE_MAX - 256/* so we can detect potential overflow of the + running sum */; + + /* The prediction method we use is to find which method provides the + * smallest value when summing the absolute values of the distances + * from zero, using anything >= 128 as negative numbers. This is known + * as the "minimum sum of absolute differences" heuristic. Other + * heuristics are the "weighted minimum sum of absolute differences" + * (experimental and can in theory improve compression), and the "zlib + * predictive" method (not implemented yet), which does test compressions + * of lines using different filter methods, and then chooses the + * (series of) filter(s) that give minimum compressed data size (VERY + * computationally expensive). + * + * GRR 980525: consider also + * + * (1) minimum sum of absolute differences from running average (i.e., + * keep running sum of non-absolute differences & count of bytes) + * [track dispersion, too? restart average if dispersion too large?] + * + * (1b) minimum sum of absolute differences from sliding average, probably + * with window size <= deflate window (usually 32K) + * + * (2) minimum sum of squared differences from zero or running average + * (i.e., ~ root-mean-square approach) + */ + + + /* We don't need to test the 'no filter' case if this is the only filter + * that has been chosen, as it doesn't actually do anything to the data. + */ + best_row = png_ptr->row_buf; + + if (PNG_SIZE_MAX/128 <= row_bytes) + { + /* Overflow can occur in the calculation, just select the lowest set + * filter. + */ + filter_to_do &= 0U-filter_to_do; + } + else if ((filter_to_do & PNG_FILTER_NONE) != 0 && + filter_to_do != PNG_FILTER_NONE) + { + /* Overflow not possible and multiple filters in the list, including the + * 'none' filter. + */ + png_bytep rp; + size_t sum = 0; + size_t i; + unsigned int v; + + { + for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) + { + v = *rp; +#ifdef PNG_USE_ABS + sum += 128 - abs((int)v - 128); +#else + sum += (v < 128) ? v : 256 - v; +#endif + } + } + + mins = sum; + } + + /* Sub filter */ + if (filter_to_do == PNG_FILTER_SUB) + /* It's the only filter so no testing is needed */ + { + png_setup_sub_row_only(png_ptr, bpp, row_bytes); + best_row = png_ptr->try_row; + } + + else if ((filter_to_do & PNG_FILTER_SUB) != 0) + { + size_t sum; + size_t lmins = mins; + + sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins); + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->try_row; + if (png_ptr->tst_row != NULL) + { + png_ptr->try_row = png_ptr->tst_row; + png_ptr->tst_row = best_row; + } + } + } + + /* Up filter */ + if (filter_to_do == PNG_FILTER_UP) + { + png_setup_up_row_only(png_ptr, row_bytes); + best_row = png_ptr->try_row; + } + + else if ((filter_to_do & PNG_FILTER_UP) != 0) + { + size_t sum; + size_t lmins = mins; + + sum = png_setup_up_row(png_ptr, row_bytes, lmins); + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->try_row; + if (png_ptr->tst_row != NULL) + { + png_ptr->try_row = png_ptr->tst_row; + png_ptr->tst_row = best_row; + } + } + } + + /* Avg filter */ + if (filter_to_do == PNG_FILTER_AVG) + { + png_setup_avg_row_only(png_ptr, bpp, row_bytes); + best_row = png_ptr->try_row; + } + + else if ((filter_to_do & PNG_FILTER_AVG) != 0) + { + size_t sum; + size_t lmins = mins; + + sum= png_setup_avg_row(png_ptr, bpp, row_bytes, lmins); + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->try_row; + if (png_ptr->tst_row != NULL) + { + png_ptr->try_row = png_ptr->tst_row; + png_ptr->tst_row = best_row; + } + } + } + + /* Paeth filter */ + if (filter_to_do == PNG_FILTER_PAETH) + { + png_setup_paeth_row_only(png_ptr, bpp, row_bytes); + best_row = png_ptr->try_row; + } + + else if ((filter_to_do & PNG_FILTER_PAETH) != 0) + { + size_t sum; + size_t lmins = mins; + + sum = png_setup_paeth_row(png_ptr, bpp, row_bytes, lmins); + + if (sum < mins) + { + best_row = png_ptr->try_row; + if (png_ptr->tst_row != NULL) + { + png_ptr->try_row = png_ptr->tst_row; + png_ptr->tst_row = best_row; + } + } + } + + /* Do the actual writing of the filtered row data from the chosen filter. */ + png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1); + +#endif /* WRITE_FILTER */ +} + + +/* Do the actual writing of a previously filtered row. */ +static void +png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row, + size_t full_row_length/*includes filter byte*/) +{ + png_debug(1, "in png_write_filtered_row"); + + png_debug1(2, "filter = %d", filtered_row[0]); + + png_compress_IDAT(png_ptr, filtered_row, full_row_length, Z_NO_FLUSH); + +#ifdef PNG_WRITE_FILTER_SUPPORTED + /* Swap the current and previous rows */ + if (png_ptr->prev_row != NULL) + { + png_bytep tptr; + + tptr = png_ptr->prev_row; + png_ptr->prev_row = png_ptr->row_buf; + png_ptr->row_buf = tptr; + } +#endif /* WRITE_FILTER */ + + /* Finish row - updates counters and flushes zlib if last row */ + png_write_finish_row(png_ptr); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_ptr->flush_rows++; + + if (png_ptr->flush_dist > 0 && + png_ptr->flush_rows >= png_ptr->flush_dist) + { + png_write_flush(png_ptr); + } +#endif /* WRITE_FLUSH */ +} +#endif /* WRITE */ diff --git a/extern/nod b/extern/nod new file mode 160000 index 000000000..d14b798b5 --- /dev/null +++ b/extern/nod @@ -0,0 +1 @@ +Subproject commit d14b798b5f79c566ba6e6ca0434ce155f2b81d1b diff --git a/extern/rapidjson b/extern/rapidjson new file mode 160000 index 000000000..49aa0fc15 --- /dev/null +++ b/extern/rapidjson @@ -0,0 +1 @@ +Subproject commit 49aa0fc15d63a2132ecf3ba0eda1ecf6fef215a1 diff --git a/extern/sanitizers-cmake b/extern/sanitizers-cmake new file mode 160000 index 000000000..99e159ec9 --- /dev/null +++ b/extern/sanitizers-cmake @@ -0,0 +1 @@ +Subproject commit 99e159ec9bc8dd362b08d18436bd40ff0648417b diff --git a/extern/tinyxml2 b/extern/tinyxml2 new file mode 160000 index 000000000..2ab76dab6 --- /dev/null +++ b/extern/tinyxml2 @@ -0,0 +1 @@ +Subproject commit 2ab76dab6d3d744b4992a7795d3648dc86a1a890 diff --git a/extern/xxhash/CMakeLists.txt b/extern/xxhash/CMakeLists.txt new file mode 100644 index 000000000..4ce1f8266 --- /dev/null +++ b/extern/xxhash/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(xxhash hecl-xxhash.c hecl-xxhash.h) +target_include_directories(xxhash PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/extern/xxhash/LICENSE b/extern/xxhash/LICENSE new file mode 100644 index 000000000..7de801ed1 --- /dev/null +++ b/extern/xxhash/LICENSE @@ -0,0 +1,24 @@ +xxHash Library +Copyright (c) 2012-2014, Yann Collet +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/extern/xxhash/hecl-xxhash.c b/extern/xxhash/hecl-xxhash.c new file mode 100644 index 000000000..305edd616 --- /dev/null +++ b/extern/xxhash/hecl-xxhash.c @@ -0,0 +1,962 @@ +/* +xxHash - Fast Hash algorithm +Copyright (C) 2012-2015, Yann Collet + +BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +You can contact the author at : +- xxHash source repository : https://github.com/Cyan4973/xxHash +*/ + + +/************************************** +* Tuning parameters +**************************************/ +/* XXH_FORCE_MEMORY_ACCESS + * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. + * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. + * The below switch allow to select different access method for improved performance. + * Method 0 (default) : use `memcpy()`. Safe and portable. + * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable). + * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`. + * Method 2 : direct access. This method is portable but violate C standard. + * It can generate buggy code on targets which generate assembly depending on alignment. + * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6) + * See http://stackoverflow.com/a/32095106/646947 for details. + * Prefer these methods in priority order (0 > 1 > 2) + */ +#ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */ +# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) +# define XXH_FORCE_MEMORY_ACCESS 2 +# elif defined(__INTEL_COMPILER) || \ + (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) )) +# define XXH_FORCE_MEMORY_ACCESS 1 +# endif +#endif + +/* XXH_ACCEPT_NULL_INPUT_POINTER : + * If the input pointer is a null pointer, xxHash default behavior is to trigger a memory access error, since it is a bad pointer. + * When this option is enabled, xxHash output for null input pointers will be the same as a null-length input. + * By default, this option is disabled. To enable it, uncomment below define : + */ +/* #define XXH_ACCEPT_NULL_INPUT_POINTER 1 */ + +/* XXH_FORCE_NATIVE_FORMAT : + * By default, xxHash library provides endian-independant Hash values, based on little-endian convention. + * Results are therefore identical for little-endian and big-endian CPU. + * This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format. + * Should endian-independance be of no importance for your application, you may set the #define below to 1, + * to improve speed for Big-endian CPU. + * This option has no impact on Little_Endian CPU. + */ +#define XXH_FORCE_NATIVE_FORMAT 0 + +/* XXH_USELESS_ALIGN_BRANCH : + * This is a minor performance trick, only useful with lots of very small keys. + * It means : don't make a test between aligned/unaligned, because performance will be the same. + * It saves one initial branch per hash. + */ +#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) +# define XXH_USELESS_ALIGN_BRANCH 1 +#endif + + +/************************************** +* Compiler Specific Options +***************************************/ +#ifdef _MSC_VER /* Visual Studio */ +# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ +# define FORCE_INLINE static __forceinline +#else +# if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ +# ifdef __GNUC__ +# define FORCE_INLINE static inline __attribute__((always_inline)) +# else +# define FORCE_INLINE static inline +# endif +# else +# define FORCE_INLINE static +# endif /* __STDC_VERSION__ */ +#endif + + +/************************************** +* Includes & Memory related functions +***************************************/ +#include "hecl-xxhash.h" +/* Modify the local functions below should you wish to use some other memory routines */ +/* for malloc(), free() */ +#include +static void* XXH_malloc(size_t s) { return malloc(s); } +static void XXH_free (void* p) { free(p); } +/* for memcpy() */ +#include +static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); } + + +/************************************** +* Basic Types +***************************************/ +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ +# include + typedef uint8_t BYTE; + typedef uint16_t U16; + typedef uint32_t U32; + typedef int32_t S32; + typedef uint64_t U64; +#else + typedef unsigned char BYTE; + typedef unsigned short U16; + typedef unsigned int U32; + typedef signed int S32; + typedef unsigned long long U64; +#endif + + +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2)) + +/* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */ +static U32 XXH_read32(const void* memPtr) { return *(const U32*) memPtr; } +static U64 XXH_read64(const void* memPtr) { return *(const U64*) memPtr; } + +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1)) + +/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ +/* currently only defined for gcc and icc */ +typedef union { U32 u32; U64 u64; } __attribute__((packed)) unalign; + +static U32 XXH_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } +static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; } + +#else + +/* portable and safe solution. Generally efficient. + * see : http://stackoverflow.com/a/32095106/646947 + */ + +static U32 XXH_read32(const void* memPtr) +{ + U32 val; + memcpy(&val, memPtr, sizeof(val)); + return val; +} + +static U64 XXH_read64(const void* memPtr) +{ + U64 val; + memcpy(&val, memPtr, sizeof(val)); + return val; +} + +#endif // XXH_FORCE_DIRECT_MEMORY_ACCESS + + +/****************************************** +* Compiler-specific Functions and Macros +******************************************/ +#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) + +/* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */ +#if defined(_MSC_VER) +# define XXH_rotl32(x,r) _rotl(x,r) +# define XXH_rotl64(x,r) _rotl64(x,r) +#else +# define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r))) +# define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r))) +#endif + +#if defined(_MSC_VER) /* Visual Studio */ +# define XXH_swap32 _byteswap_ulong +# define XXH_swap64 _byteswap_uint64 +#elif GCC_VERSION >= 403 || __clang__ +# define XXH_swap32 __builtin_bswap32 +# define XXH_swap64 __builtin_bswap64 +#else +static U32 XXH_swap32 (U32 x) +{ + return ((x << 24) & 0xff000000 ) | + ((x << 8) & 0x00ff0000 ) | + ((x >> 8) & 0x0000ff00 ) | + ((x >> 24) & 0x000000ff ); +} +static U64 XXH_swap64 (U64 x) +{ + return ((x << 56) & 0xff00000000000000ULL) | + ((x << 40) & 0x00ff000000000000ULL) | + ((x << 24) & 0x0000ff0000000000ULL) | + ((x << 8) & 0x000000ff00000000ULL) | + ((x >> 8) & 0x00000000ff000000ULL) | + ((x >> 24) & 0x0000000000ff0000ULL) | + ((x >> 40) & 0x000000000000ff00ULL) | + ((x >> 56) & 0x00000000000000ffULL); +} +#endif + + +/*************************************** +* Architecture Macros +***************************************/ +typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess; + +/* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example one the compiler command line */ +#ifndef XXH_CPU_LITTLE_ENDIAN + static const int one = 1; +# define XXH_CPU_LITTLE_ENDIAN (*(const char*)(&one)) +#endif + + +/***************************** +* Memory reads +*****************************/ +typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment; + +FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align) +{ + if (align==XXH_unaligned) + return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr)); + else + return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr); +} + +FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian) +{ + return XXH_readLE32_align(ptr, endian, XXH_unaligned); +} + +FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align) +{ + if (align==XXH_unaligned) + return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr)); + else + return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr); +} + +FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian) +{ + return XXH_readLE64_align(ptr, endian, XXH_unaligned); +} + + +/*************************************** +* Macros +***************************************/ +#define XXH_STATIC_ASSERT(c) { enum { XXH_static_assert = 1/(!!(c)) }; } /* use only *after* variable declarations */ + + +/*************************************** +* Constants +***************************************/ +#define PRIME32_1 2654435761U +#define PRIME32_2 2246822519U +#define PRIME32_3 3266489917U +#define PRIME32_4 668265263U +#define PRIME32_5 374761393U + +#define PRIME64_1 11400714785074694791ULL +#define PRIME64_2 14029467366897019727ULL +#define PRIME64_3 1609587929392839161ULL +#define PRIME64_4 9650029242287828579ULL +#define PRIME64_5 2870177450012600261ULL + + +/***************************** +* Simple Hash Functions +*****************************/ +FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align) +{ + const BYTE* p = (const BYTE*)input; + const BYTE* bEnd = p + len; + U32 h32; +#define XXH_get32bits(p) XXH_readLE32_align(p, endian, align) + +#ifdef XXH_ACCEPT_NULL_INPUT_POINTER + if (p==NULL) + { + len=0; + bEnd=p=(const BYTE*)(size_t)16; + } +#endif + + if (len>=16) + { + const BYTE* const limit = bEnd - 16; + U32 v1 = seed + PRIME32_1 + PRIME32_2; + U32 v2 = seed + PRIME32_2; + U32 v3 = seed + 0; + U32 v4 = seed - PRIME32_1; + + do + { + v1 += XXH_get32bits(p) * PRIME32_2; + v1 = XXH_rotl32(v1, 13); + v1 *= PRIME32_1; + p+=4; + v2 += XXH_get32bits(p) * PRIME32_2; + v2 = XXH_rotl32(v2, 13); + v2 *= PRIME32_1; + p+=4; + v3 += XXH_get32bits(p) * PRIME32_2; + v3 = XXH_rotl32(v3, 13); + v3 *= PRIME32_1; + p+=4; + v4 += XXH_get32bits(p) * PRIME32_2; + v4 = XXH_rotl32(v4, 13); + v4 *= PRIME32_1; + p+=4; + } + while (p<=limit); + + h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18); + } + else + { + h32 = seed + PRIME32_5; + } + + h32 += (U32) len; + + while (p+4<=bEnd) + { + h32 += XXH_get32bits(p) * PRIME32_3; + h32 = XXH_rotl32(h32, 17) * PRIME32_4 ; + p+=4; + } + + while (p> 15; + h32 *= PRIME32_2; + h32 ^= h32 >> 13; + h32 *= PRIME32_3; + h32 ^= h32 >> 16; + + return h32; +} + + +unsigned int XXH32 (const void* input, size_t len, unsigned int seed) +{ +#if 0 + /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ + XXH32_state_t state; + XXH32_reset(&state, seed); + XXH32_update(&state, input, len); + return XXH32_digest(&state); +#else + XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; + +# if !defined(XXH_USELESS_ALIGN_BRANCH) + if ((((size_t)input) & 3) == 0) /* Input is 4-bytes aligned, leverage the speed benefit */ + { + if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) + return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned); + else + return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned); + } +# endif + + if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) + return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned); + else + return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned); +#endif +} + +FORCE_INLINE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align) +{ + const BYTE* p = (const BYTE*)input; + const BYTE* bEnd = p + len; + U64 h64; +#define XXH_get64bits(p) XXH_readLE64_align(p, endian, align) + +#ifdef XXH_ACCEPT_NULL_INPUT_POINTER + if (p==NULL) + { + len=0; + bEnd=p=(const BYTE*)(size_t)32; + } +#endif + + if (len>=32) + { + const BYTE* const limit = bEnd - 32; + U64 v1 = seed + PRIME64_1 + PRIME64_2; + U64 v2 = seed + PRIME64_2; + U64 v3 = seed + 0; + U64 v4 = seed - PRIME64_1; + + do + { + v1 += XXH_get64bits(p) * PRIME64_2; + p+=8; + v1 = XXH_rotl64(v1, 31); + v1 *= PRIME64_1; + v2 += XXH_get64bits(p) * PRIME64_2; + p+=8; + v2 = XXH_rotl64(v2, 31); + v2 *= PRIME64_1; + v3 += XXH_get64bits(p) * PRIME64_2; + p+=8; + v3 = XXH_rotl64(v3, 31); + v3 *= PRIME64_1; + v4 += XXH_get64bits(p) * PRIME64_2; + p+=8; + v4 = XXH_rotl64(v4, 31); + v4 *= PRIME64_1; + } + while (p<=limit); + + h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18); + + v1 *= PRIME64_2; + v1 = XXH_rotl64(v1, 31); + v1 *= PRIME64_1; + h64 ^= v1; + h64 = h64 * PRIME64_1 + PRIME64_4; + + v2 *= PRIME64_2; + v2 = XXH_rotl64(v2, 31); + v2 *= PRIME64_1; + h64 ^= v2; + h64 = h64 * PRIME64_1 + PRIME64_4; + + v3 *= PRIME64_2; + v3 = XXH_rotl64(v3, 31); + v3 *= PRIME64_1; + h64 ^= v3; + h64 = h64 * PRIME64_1 + PRIME64_4; + + v4 *= PRIME64_2; + v4 = XXH_rotl64(v4, 31); + v4 *= PRIME64_1; + h64 ^= v4; + h64 = h64 * PRIME64_1 + PRIME64_4; + } + else + { + h64 = seed + PRIME64_5; + } + + h64 += (U64) len; + + while (p+8<=bEnd) + { + U64 k1 = XXH_get64bits(p); + k1 *= PRIME64_2; + k1 = XXH_rotl64(k1,31); + k1 *= PRIME64_1; + h64 ^= k1; + h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; + p+=8; + } + + if (p+4<=bEnd) + { + h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1; + h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3; + p+=4; + } + + while (p> 33; + h64 *= PRIME64_2; + h64 ^= h64 >> 29; + h64 *= PRIME64_3; + h64 ^= h64 >> 32; + + return h64; +} + + +unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed) +{ +#if 0 + /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ + XXH64_state_t state; + XXH64_reset(&state, seed); + XXH64_update(&state, input, len); + return XXH64_digest(&state); +#else + XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; + +# if !defined(XXH_USELESS_ALIGN_BRANCH) + if ((((size_t)input) & 7)==0) /* Input is aligned, let's leverage the speed advantage */ + { + if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) + return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned); + else + return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned); + } +# endif + + if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) + return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned); + else + return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned); +#endif +} + +/**************************************************** +* Advanced Hash Functions +****************************************************/ + +/*** Allocation ***/ +typedef struct +{ + U64 total_len; + U32 seed; + U32 v1; + U32 v2; + U32 v3; + U32 v4; + U32 mem32[4]; /* defined as U32 for alignment */ + U32 memsize; +} XXH_istate32_t; + +typedef struct +{ + U64 total_len; + U64 seed; + U64 v1; + U64 v2; + U64 v3; + U64 v4; + U64 mem64[4]; /* defined as U64 for alignment */ + U32 memsize; +} XXH_istate64_t; + + +XXH32_state_t* XXH32_createState(void) +{ + XXH_STATIC_ASSERT(sizeof(XXH32_state_t) >= sizeof(XXH_istate32_t)); /* A compilation error here means XXH32_state_t is not large enough */ + return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t)); +} +XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr) +{ + XXH_free(statePtr); + return XXH_OK; +} + +XXH64_state_t* XXH64_createState(void) +{ + XXH_STATIC_ASSERT(sizeof(XXH64_state_t) >= sizeof(XXH_istate64_t)); /* A compilation error here means XXH64_state_t is not large enough */ + return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t)); +} +XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr) +{ + XXH_free(statePtr); + return XXH_OK; +} + + +/*** Hash feed ***/ + +XXH_errorcode XXH32_reset(XXH32_state_t* state_in, unsigned int seed) +{ + XXH_istate32_t* state = (XXH_istate32_t*) state_in; + state->seed = seed; + state->v1 = seed + PRIME32_1 + PRIME32_2; + state->v2 = seed + PRIME32_2; + state->v3 = seed + 0; + state->v4 = seed - PRIME32_1; + state->total_len = 0; + state->memsize = 0; + return XXH_OK; +} + +XXH_errorcode XXH64_reset(XXH64_state_t* state_in, unsigned long long seed) +{ + XXH_istate64_t* state = (XXH_istate64_t*) state_in; + state->seed = seed; + state->v1 = seed + PRIME64_1 + PRIME64_2; + state->v2 = seed + PRIME64_2; + state->v3 = seed + 0; + state->v4 = seed - PRIME64_1; + state->total_len = 0; + state->memsize = 0; + return XXH_OK; +} + + +FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state_in, const void* input, size_t len, XXH_endianess endian) +{ + XXH_istate32_t* state = (XXH_istate32_t *) state_in; + const BYTE* p = (const BYTE*)input; + const BYTE* const bEnd = p + len; + +#ifdef XXH_ACCEPT_NULL_INPUT_POINTER + if (input==NULL) return XXH_ERROR; +#endif + + state->total_len += len; + + if (state->memsize + len < 16) /* fill in tmp buffer */ + { + XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len); + state->memsize += (U32)len; + return XXH_OK; + } + + if (state->memsize) /* some data left from previous update */ + { + XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize); + { + const U32* p32 = state->mem32; + state->v1 += XXH_readLE32(p32, endian) * PRIME32_2; + state->v1 = XXH_rotl32(state->v1, 13); + state->v1 *= PRIME32_1; + p32++; + state->v2 += XXH_readLE32(p32, endian) * PRIME32_2; + state->v2 = XXH_rotl32(state->v2, 13); + state->v2 *= PRIME32_1; + p32++; + state->v3 += XXH_readLE32(p32, endian) * PRIME32_2; + state->v3 = XXH_rotl32(state->v3, 13); + state->v3 *= PRIME32_1; + p32++; + state->v4 += XXH_readLE32(p32, endian) * PRIME32_2; + state->v4 = XXH_rotl32(state->v4, 13); + state->v4 *= PRIME32_1; + p32++; + } + p += 16-state->memsize; + state->memsize = 0; + } + + if (p <= bEnd-16) + { + const BYTE* const limit = bEnd - 16; + U32 v1 = state->v1; + U32 v2 = state->v2; + U32 v3 = state->v3; + U32 v4 = state->v4; + + do + { + v1 += XXH_readLE32(p, endian) * PRIME32_2; + v1 = XXH_rotl32(v1, 13); + v1 *= PRIME32_1; + p+=4; + v2 += XXH_readLE32(p, endian) * PRIME32_2; + v2 = XXH_rotl32(v2, 13); + v2 *= PRIME32_1; + p+=4; + v3 += XXH_readLE32(p, endian) * PRIME32_2; + v3 = XXH_rotl32(v3, 13); + v3 *= PRIME32_1; + p+=4; + v4 += XXH_readLE32(p, endian) * PRIME32_2; + v4 = XXH_rotl32(v4, 13); + v4 *= PRIME32_1; + p+=4; + } + while (p<=limit); + + state->v1 = v1; + state->v2 = v2; + state->v3 = v3; + state->v4 = v4; + } + + if (p < bEnd) + { + XXH_memcpy(state->mem32, p, bEnd-p); + state->memsize = (int)(bEnd-p); + } + + return XXH_OK; +} + +XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t len) +{ + XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; + + if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) + return XXH32_update_endian(state_in, input, len, XXH_littleEndian); + else + return XXH32_update_endian(state_in, input, len, XXH_bigEndian); +} + + + +FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state_in, XXH_endianess endian) +{ + const XXH_istate32_t* state = (const XXH_istate32_t*) state_in; + const BYTE * p = (const BYTE*)state->mem32; + const BYTE* bEnd = (const BYTE*)(state->mem32) + state->memsize; + U32 h32; + + if (state->total_len >= 16) + { + h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18); + } + else + { + h32 = state->seed + PRIME32_5; + } + + h32 += (U32) state->total_len; + + while (p+4<=bEnd) + { + h32 += XXH_readLE32(p, endian) * PRIME32_3; + h32 = XXH_rotl32(h32, 17) * PRIME32_4; + p+=4; + } + + while (p> 15; + h32 *= PRIME32_2; + h32 ^= h32 >> 13; + h32 *= PRIME32_3; + h32 ^= h32 >> 16; + + return h32; +} + + +unsigned int XXH32_digest (const XXH32_state_t* state_in) +{ + XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; + + if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) + return XXH32_digest_endian(state_in, XXH_littleEndian); + else + return XXH32_digest_endian(state_in, XXH_bigEndian); +} + + +FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state_in, const void* input, size_t len, XXH_endianess endian) +{ + XXH_istate64_t * state = (XXH_istate64_t *) state_in; + const BYTE* p = (const BYTE*)input; + const BYTE* const bEnd = p + len; + +#ifdef XXH_ACCEPT_NULL_INPUT_POINTER + if (input==NULL) return XXH_ERROR; +#endif + + state->total_len += len; + + if (state->memsize + len < 32) /* fill in tmp buffer */ + { + XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len); + state->memsize += (U32)len; + return XXH_OK; + } + + if (state->memsize) /* some data left from previous update */ + { + XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize); + { + const U64* p64 = state->mem64; + state->v1 += XXH_readLE64(p64, endian) * PRIME64_2; + state->v1 = XXH_rotl64(state->v1, 31); + state->v1 *= PRIME64_1; + p64++; + state->v2 += XXH_readLE64(p64, endian) * PRIME64_2; + state->v2 = XXH_rotl64(state->v2, 31); + state->v2 *= PRIME64_1; + p64++; + state->v3 += XXH_readLE64(p64, endian) * PRIME64_2; + state->v3 = XXH_rotl64(state->v3, 31); + state->v3 *= PRIME64_1; + p64++; + state->v4 += XXH_readLE64(p64, endian) * PRIME64_2; + state->v4 = XXH_rotl64(state->v4, 31); + state->v4 *= PRIME64_1; + p64++; + } + p += 32-state->memsize; + state->memsize = 0; + } + + if (p+32 <= bEnd) + { + const BYTE* const limit = bEnd - 32; + U64 v1 = state->v1; + U64 v2 = state->v2; + U64 v3 = state->v3; + U64 v4 = state->v4; + + do + { + v1 += XXH_readLE64(p, endian) * PRIME64_2; + v1 = XXH_rotl64(v1, 31); + v1 *= PRIME64_1; + p+=8; + v2 += XXH_readLE64(p, endian) * PRIME64_2; + v2 = XXH_rotl64(v2, 31); + v2 *= PRIME64_1; + p+=8; + v3 += XXH_readLE64(p, endian) * PRIME64_2; + v3 = XXH_rotl64(v3, 31); + v3 *= PRIME64_1; + p+=8; + v4 += XXH_readLE64(p, endian) * PRIME64_2; + v4 = XXH_rotl64(v4, 31); + v4 *= PRIME64_1; + p+=8; + } + while (p<=limit); + + state->v1 = v1; + state->v2 = v2; + state->v3 = v3; + state->v4 = v4; + } + + if (p < bEnd) + { + XXH_memcpy(state->mem64, p, bEnd-p); + state->memsize = (int)(bEnd-p); + } + + return XXH_OK; +} + +XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* input, size_t len) +{ + XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; + + if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) + return XXH64_update_endian(state_in, input, len, XXH_littleEndian); + else + return XXH64_update_endian(state_in, input, len, XXH_bigEndian); +} + + + +FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state_in, XXH_endianess endian) +{ + const XXH_istate64_t * state = (const XXH_istate64_t *) state_in; + const BYTE * p = (const BYTE*)state->mem64; + const BYTE* bEnd = (const BYTE*)state->mem64 + state->memsize; + U64 h64; + + if (state->total_len >= 32) + { + U64 v1 = state->v1; + U64 v2 = state->v2; + U64 v3 = state->v3; + U64 v4 = state->v4; + + h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18); + + v1 *= PRIME64_2; + v1 = XXH_rotl64(v1, 31); + v1 *= PRIME64_1; + h64 ^= v1; + h64 = h64*PRIME64_1 + PRIME64_4; + + v2 *= PRIME64_2; + v2 = XXH_rotl64(v2, 31); + v2 *= PRIME64_1; + h64 ^= v2; + h64 = h64*PRIME64_1 + PRIME64_4; + + v3 *= PRIME64_2; + v3 = XXH_rotl64(v3, 31); + v3 *= PRIME64_1; + h64 ^= v3; + h64 = h64*PRIME64_1 + PRIME64_4; + + v4 *= PRIME64_2; + v4 = XXH_rotl64(v4, 31); + v4 *= PRIME64_1; + h64 ^= v4; + h64 = h64*PRIME64_1 + PRIME64_4; + } + else + { + h64 = state->seed + PRIME64_5; + } + + h64 += (U64) state->total_len; + + while (p+8<=bEnd) + { + U64 k1 = XXH_readLE64(p, endian); + k1 *= PRIME64_2; + k1 = XXH_rotl64(k1,31); + k1 *= PRIME64_1; + h64 ^= k1; + h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; + p+=8; + } + + if (p+4<=bEnd) + { + h64 ^= (U64)(XXH_readLE32(p, endian)) * PRIME64_1; + h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3; + p+=4; + } + + while (p> 33; + h64 *= PRIME64_2; + h64 ^= h64 >> 29; + h64 *= PRIME64_3; + h64 ^= h64 >> 32; + + return h64; +} + + +unsigned long long XXH64_digest (const XXH64_state_t* state_in) +{ + XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; + + if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) + return XXH64_digest_endian(state_in, XXH_littleEndian); + else + return XXH64_digest_endian(state_in, XXH_bigEndian); +} + + diff --git a/extern/xxhash/hecl-xxhash.h b/extern/xxhash/hecl-xxhash.h new file mode 100644 index 000000000..c60aa6157 --- /dev/null +++ b/extern/xxhash/hecl-xxhash.h @@ -0,0 +1,192 @@ +/* + xxHash - Extremely Fast Hash algorithm + Header File + Copyright (C) 2012-2015, Yann Collet. + + BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + You can contact the author at : + - xxHash source repository : https://github.com/Cyan4973/xxHash +*/ + +/* Notice extracted from xxHash homepage : + +xxHash is an extremely fast Hash algorithm, running at RAM speed limits. +It also successfully passes all tests from the SMHasher suite. + +Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz) + +Name Speed Q.Score Author +xxHash 5.4 GB/s 10 +CrapWow 3.2 GB/s 2 Andrew +MumurHash 3a 2.7 GB/s 10 Austin Appleby +SpookyHash 2.0 GB/s 10 Bob Jenkins +SBox 1.4 GB/s 9 Bret Mulvey +Lookup3 1.2 GB/s 9 Bob Jenkins +SuperFastHash 1.2 GB/s 1 Paul Hsieh +CityHash64 1.05 GB/s 10 Pike & Alakuijala +FNV 0.55 GB/s 5 Fowler, Noll, Vo +CRC32 0.43 GB/s 9 +MD5-32 0.33 GB/s 10 Ronald L. Rivest +SHA1-32 0.28 GB/s 10 + +Q.Score is a measure of quality of the hash function. +It depends on successfully passing SMHasher test set. +10 is a perfect score. + +A 64-bits version, named XXH64, is available since r35. +It offers much better speed, but for 64-bits applications only. +Name Speed on 64 bits Speed on 32 bits +XXH64 13.8 GB/s 1.9 GB/s +XXH32 6.8 GB/s 6.0 GB/s +*/ + +#pragma once + +#if defined (__cplusplus) +extern "C" { +#endif + + +/***************************** +* Definitions +*****************************/ +#include /* size_t */ +typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; + + +/***************************** +* Namespace Emulation +*****************************/ +/* Motivations : + +If you need to include xxHash into your library, +but wish to avoid xxHash symbols to be present on your library interface +in an effort to avoid potential name collision if another library also includes xxHash, + +you can use XXH_NAMESPACE, which will automatically prefix any symbol from xxHash +with the value of XXH_NAMESPACE (so avoid to keep it NULL, and avoid numeric values). + +Note that no change is required within the calling program : +it can still call xxHash functions using their regular name. +They will be automatically translated by this header. +*/ +#ifdef XXH_NAMESPACE +# define XXH_CAT(A,B) A##B +# define XXH_NAME2(A,B) XXH_CAT(A,B) +# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32) +# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64) +# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState) +# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState) +# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState) +# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState) +# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset) +# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset) +# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update) +# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update) +# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest) +# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest) +#endif + + +/***************************** +* Simple Hash Functions +*****************************/ + +unsigned int XXH32 (const void* input, size_t length, unsigned seed); +unsigned long long XXH64 (const void* input, size_t length, unsigned long long seed); + +/* +XXH32() : + Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input". + The memory between input & input+length must be valid (allocated and read-accessible). + "seed" can be used to alter the result predictably. + This function successfully passes all SMHasher tests. + Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s +XXH64() : + Calculate the 64-bits hash of sequence of length "len" stored at memory address "input". + Faster on 64-bits systems. Slower on 32-bits systems. +*/ + + + +/***************************** +* Advanced Hash Functions +*****************************/ +typedef struct { long long ll[ 6]; } XXH32_state_t; +typedef struct { long long ll[11]; } XXH64_state_t; + +/* +These structures allow static allocation of XXH states. +States must then be initialized using XXHnn_reset() before first use. + +If you prefer dynamic allocation, please refer to functions below. +*/ + +XXH32_state_t* XXH32_createState(void); +XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr); + +XXH64_state_t* XXH64_createState(void); +XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr); + +/* +These functions create and release memory for XXH state. +States must then be initialized using XXHnn_reset() before first use. +*/ + + +XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned seed); +XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length); +unsigned int XXH32_digest (const XXH32_state_t* statePtr); + +XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed); +XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length); +unsigned long long XXH64_digest (const XXH64_state_t* statePtr); + +/* +These functions calculate the xxHash of an input provided in multiple smaller packets, +as opposed to an input provided as a single block. + +XXH state space must first be allocated, using either static or dynamic method provided above. + +Start a new hash by initializing state with a seed, using XXHnn_reset(). + +Then, feed the hash state by calling XXHnn_update() as many times as necessary. +Obviously, input must be valid, meaning allocated and read accessible. +The function returns an error code, with 0 meaning OK, and any other value meaning there is an error. + +Finally, you can produce a hash anytime, by using XXHnn_digest(). +This function returns the final nn-bits hash. +You can nonetheless continue feeding the hash state with more input, +and therefore get some new hashes, by calling again XXHnn_digest(). + +When you are done, don't forget to free XXH state space, using typically XXHnn_freeState(). +*/ + + +#if defined (__cplusplus) +} +#endif diff --git a/extern/zeus b/extern/zeus new file mode 160000 index 000000000..b3806c03a --- /dev/null +++ b/extern/zeus @@ -0,0 +1 @@ +Subproject commit b3806c03a5e7d5cde5d10f04b18e8fb25a751b59 diff --git a/GMM-LICENSE b/gmm/LICENSE similarity index 100% rename from GMM-LICENSE rename to gmm/LICENSE diff --git a/hecl b/hecl deleted file mode 160000 index 8e67a9928..000000000 --- a/hecl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8e67a9928f54a32dc2c541c77b3b5f9c5773be93 diff --git a/hecl-gui b/hecl-gui deleted file mode 160000 index 6d0a738e1..000000000 --- a/hecl-gui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6d0a738e1bf93b47c38e8042086b836142ca48e8 diff --git a/hecl/.gitignore b/hecl/.gitignore new file mode 100644 index 000000000..f7e5c090f --- /dev/null +++ b/hecl/.gitignore @@ -0,0 +1,2 @@ +DataSpecRegistry.hpp +.DS_Store diff --git a/hecl/CMakeLists.txt b/hecl/CMakeLists.txt new file mode 100644 index 000000000..14bb9d6f9 --- /dev/null +++ b/hecl/CMakeLists.txt @@ -0,0 +1,45 @@ +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) +cmake_minimum_required(VERSION 3.10 FATAL_ERROR) # because of c++17 +project(hecl) + +if(MSVC) + add_compile_options( + # Disable exceptions + $<$:/EHsc> + /wd4267 /wd4244 + ) + add_compile_definitions(UNICODE=1 _UNICODE=1 _CRT_SECURE_NO_WARNINGS=1) +else() + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + add_compile_options( + # Disable exceptions + $<$:-fno-exceptions> + -Wno-multichar + ) +endif() +endif() + +include(ExternalProject) +ExternalProject_Add(bintoc + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bintoc" + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH= + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install) +include(bintoc/bintocHelpers.cmake) + +if(NOT TARGET atdna) + # Import native atdna if cross-compiling + find_package(atdna REQUIRED) + if(NOT TARGET atdna) + message(FATAL_ERROR "atdna required for building hecl; please verify LLVM installation") + endif() +endif() + +add_subdirectory(lib) +add_subdirectory(blender) +add_subdirectory(driver) + +configure_file(DataSpecRegistry.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/DataSpecRegistry.hpp @ONLY) +target_include_directories(hecl PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + +install(DIRECTORY include/hecl DESTINATION include/hecl) diff --git a/hecl/DataSpecRegistry.hpp.in b/hecl/DataSpecRegistry.hpp.in new file mode 100644 index 000000000..9d485954c --- /dev/null +++ b/hecl/DataSpecRegistry.hpp.in @@ -0,0 +1,21 @@ +/* Include this file once in the main translation unit of any executable file + * using HECL's database functionality (see driver/main.cpp) + */ +#ifdef DATA_SPEC_REGISTRY_HPP +#error DataSpecRegistry.hpp may only be included once +#endif +#define DATA_SPEC_REGISTRY_HPP + +#include "hecl/Database.hpp" + +namespace hecl::Database { +/* Centralized registry for DataSpec lookup */ +std::vector DATA_SPEC_REGISTRY; +} + +@HECL_DATASPEC_DECLS@ + +/* Please Call Me! */ +void HECLRegisterDataSpecs() { +@HECL_DATASPEC_PUSHES@ +} diff --git a/Doxyfile b/hecl/Doxyfile similarity index 95% rename from Doxyfile rename to hecl/Doxyfile index da33f39c1..edf7d6418 100644 --- a/Doxyfile +++ b/hecl/Doxyfile @@ -1,4 +1,4 @@ -# Doxyfile 1.8.11 +# Doxyfile 1.8.9.1 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. @@ -32,33 +32,33 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = URDE +PROJECT_NAME = "hecl" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = +PROJECT_NUMBER = # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = +PROJECT_BRIEF = "High-Level Extensible Combiner Language and Resource Database" # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # the logo to the output directory. -PROJECT_LOGO = ./Editor/platforms/freedesktop/128x128/apps/urde.png +PROJECT_LOGO = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = docs +OUTPUT_DIRECTORY = "doc" # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and @@ -118,7 +118,7 @@ REPEAT_BRIEF = YES # the entity):The $name class, The $name widget, The $name file, is, provides, # specifies, contains, represents, a, an and the. -ABBREVIATE_BRIEF = +ABBREVIATE_BRIEF = # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # doxygen will generate a detailed section even if there is only a brief @@ -152,7 +152,7 @@ FULL_PATH_NAMES = YES # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. -STRIP_FROM_PATH = +STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which @@ -161,7 +161,7 @@ STRIP_FROM_PATH = # specify the list of include paths that are normally passed to the compiler # using the -I flag. -STRIP_FROM_INC_PATH = +STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but # less readable) file names. This can be useful is your file systems doesn't @@ -228,13 +228,13 @@ TAB_SIZE = 4 # "Side Effects:". You can put \n's in the value part of an alias to insert # newlines. -ALIASES = +ALIASES = # This tag can be used to specify a number of word-keyword mappings (TCL only). # A mapping has the form "name=value". For example adding "class=itcl::class" # will allow you to use the command class in the itcl::class meaning. -TCL_SUBST = +TCL_SUBST = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For @@ -281,7 +281,7 @@ OPTIMIZE_OUTPUT_VHDL = NO # Note that for custom extensions you also need to set FILE_PATTERNS otherwise # the files are not read by doxygen. -EXTENSION_MAPPING = +EXTENSION_MAPPING = # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable @@ -309,7 +309,7 @@ AUTOLINK_SUPPORT = YES # diagrams that involve STL classes more complete and accurate. # The default value is: NO. -BUILTIN_STL_SUPPORT = NO +BUILTIN_STL_SUPPORT = YES # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. @@ -343,13 +343,6 @@ IDL_PROPERTY_SUPPORT = YES DISTRIBUTE_GROUP_DOC = NO -# If one adds a struct or class to a group and this option is enabled, then also -# any nested class or struct is added to the same group. By default this option -# is disabled and one has to add nested compounds explicitly via \ingroup. -# The default value is: NO. - -GROUP_NESTED_COMPOUNDS = NO - # Set the SUBGROUPING tag to YES to allow class member groups of the same type # (for instance a group of public functions) to be put as a subgroup of that # type (e.g. under the Public Functions section). Set it to NO to prevent @@ -629,7 +622,7 @@ GENERATE_DEPRECATEDLIST= YES # sections, marked by \if ... \endif and \cond # ... \endcond blocks. -ENABLED_SECTIONS = +ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the # initial value of a variable or macro / define can have for it to appear in the @@ -671,7 +664,7 @@ SHOW_NAMESPACES = YES # by doxygen. Whatever the program writes to standard output is used as the file # version. For an example see the documentation. -FILE_VERSION_FILTER = +FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated @@ -684,7 +677,7 @@ FILE_VERSION_FILTER = # DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE # tag is left empty. -LAYOUT_FILE = +LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files containing # the reference definitions. This must be a list of .bib files. The .bib @@ -694,7 +687,7 @@ LAYOUT_FILE = # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the # search path. See also \cite for info how to create references. -CITE_BIB_FILES = +CITE_BIB_FILES = #--------------------------------------------------------------------------- # Configuration options related to warning and progress messages @@ -739,12 +732,6 @@ WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO -# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when -# a warning is encountered. -# The default value is: NO. - -WARN_AS_ERROR = NO - # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which # will be replaced by the file and line number from which the warning originated @@ -759,7 +746,7 @@ WARN_FORMAT = "$file:$line: $text" # messages should be written. If left blank the output is written to standard # error (stderr). -WARN_LOGFILE = +WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files @@ -768,12 +755,10 @@ WARN_LOGFILE = # The INPUT tag is used to specify the files and/or directories that contain # documented source files. You may enter file names like myfile.cpp or # directories like /usr/src/myproject. Separate the files or directories with -# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# spaces. # Note: If this tag is empty the current directory is searched. -INPUT = Runtime \ - Editor \ - DataSpec +INPUT = include # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -786,19 +771,14 @@ INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. -# -# Note that for custom extensions or not directly supported extensions you also -# need to set EXTENSION_MAPPING for the extension otherwise the files are not -# read by doxygen. -# -# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, -# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, -# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, -# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f, *.for, *.tcl, -# *.vhd, *.vhdl, *.ucf, *.qsf, *.as and *.js. +# *.h) to filter out the source-files in the directories. If left blank the +# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, +# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, +# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, +# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, +# *.qsf, *.as and *.js. -FILE_PATTERNS = *.hpp +FILE_PATTERNS = # The RECURSIVE tag can be used to specify whether or not subdirectories should # be searched for input files as well. @@ -813,7 +793,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = +EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -829,7 +809,7 @@ EXCLUDE_SYMLINKS = NO # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the @@ -840,20 +820,20 @@ EXCLUDE_PATTERNS = # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories use the pattern */test/* -EXCLUDE_SYMBOLS = +EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or directories # that contain example code fragments that are included (see the \include # command). -EXAMPLE_PATH = +EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and # *.h) to filter out the source-files in the directories. If left blank all # files are included. -EXAMPLE_PATTERNS = +EXAMPLE_PATTERNS = # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude commands @@ -866,7 +846,7 @@ EXAMPLE_RECURSIVE = NO # that contain images that are to be included in the documentation (see the # \image command). -IMAGE_PATH = +IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program @@ -882,12 +862,8 @@ IMAGE_PATH = # Note that the filter must not add or remove lines; it is applied before the # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. -# -# Note that for custom extensions or not directly supported extensions you also -# need to set EXTENSION_MAPPING for the extension otherwise the files are not -# properly processed by doxygen. -INPUT_FILTER = +INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the @@ -895,12 +871,8 @@ INPUT_FILTER = # (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how # filters are used. If the FILTER_PATTERNS tag is empty or if none of the # patterns match the file name, INPUT_FILTER is applied. -# -# Note that for custom extensions or not directly supported extensions you also -# need to set EXTENSION_MAPPING for the extension otherwise the files are not -# properly processed by doxygen. -FILTER_PATTERNS = +FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will also be used to filter the input files that are used for @@ -915,14 +887,14 @@ FILTER_SOURCE_FILES = NO # *.ext= (so without naming a filter). # This tag requires that the tag FILTER_SOURCE_FILES is set to YES. -FILTER_SOURCE_PATTERNS = +FILTER_SOURCE_PATTERNS = # If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that # is part of the input, its contents will be placed on the main page # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = #--------------------------------------------------------------------------- # Configuration options related to source browsing @@ -1034,7 +1006,7 @@ COLS_IN_ALPHA_INDEX = 5 # while generating the index headers. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. -IGNORE_PREFIX = +IGNORE_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the HTML output @@ -1078,7 +1050,7 @@ HTML_FILE_EXTENSION = .html # of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_HEADER = +HTML_HEADER = # The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each # generated HTML page. If the tag is left blank doxygen will generate a standard @@ -1088,7 +1060,7 @@ HTML_HEADER = # that doxygen normally uses. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_FOOTER = +HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading style # sheet that is used by each HTML page. It can be used to fine-tune the look of @@ -1100,7 +1072,7 @@ HTML_FOOTER = # obsolete. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_STYLESHEET = +HTML_STYLESHEET = # The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined # cascading style sheets that are included after the standard style sheets @@ -1113,7 +1085,7 @@ HTML_STYLESHEET = # list). For an example see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_STYLESHEET = +HTML_EXTRA_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note @@ -1123,7 +1095,7 @@ HTML_EXTRA_STYLESHEET = # files will be copied as-is; there are no commands or markers available. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_FILES = +HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen # will adjust the colors in the style sheet and background images according to @@ -1157,12 +1129,11 @@ HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting this -# to YES can help to show when doxygen was last run and thus if the -# documentation is up to date. -# The default value is: NO. +# to NO can help when comparing the output of multiple runs. +# The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_TIMESTAMP = NO +HTML_TIMESTAMP = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the @@ -1252,7 +1223,7 @@ GENERATE_HTMLHELP = NO # written to the html output directory. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. -CHM_FILE = +CHM_FILE = # The HHC_LOCATION tag can be used to specify the location (absolute path # including file name) of the HTML help compiler (hhc.exe). If non-empty, @@ -1260,7 +1231,7 @@ CHM_FILE = # The file has to be specified with full path. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. -HHC_LOCATION = +HHC_LOCATION = # The GENERATE_CHI flag controls if a separate .chi index file is generated # (YES) or that it should be included in the master .chm file (NO). @@ -1273,7 +1244,7 @@ GENERATE_CHI = NO # and project file content. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. -CHM_INDEX_ENCODING = +CHM_INDEX_ENCODING = # The BINARY_TOC flag controls whether a binary table of contents is generated # (YES) or a normal table of contents (NO) in the .chm file. Furthermore it @@ -1304,7 +1275,7 @@ GENERATE_QHP = NO # the HTML output folder. # This tag requires that the tag GENERATE_QHP is set to YES. -QCH_FILE = +QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace @@ -1329,7 +1300,7 @@ QHP_VIRTUAL_FOLDER = doc # filters). # This tag requires that the tag GENERATE_QHP is set to YES. -QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom @@ -1337,21 +1308,21 @@ QHP_CUST_FILTER_NAME = # filters). # This tag requires that the tag GENERATE_QHP is set to YES. -QHP_CUST_FILTER_ATTRS = +QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's filter section matches. Qt Help Project / Filter Attributes (see: # http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). # This tag requires that the tag GENERATE_QHP is set to YES. -QHP_SECT_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = # The QHG_LOCATION tag can be used to specify the location of Qt's # qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the # generated .qhp file. # This tag requires that the tag GENERATE_QHP is set to YES. -QHG_LOCATION = +QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be # generated, together with the HTML files, they form an Eclipse help plugin. To @@ -1399,7 +1370,7 @@ DISABLE_INDEX = NO # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -GENERATE_TREEVIEW = YES +GENERATE_TREEVIEW = NO # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. @@ -1484,7 +1455,7 @@ MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest # MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols # This tag requires that the tag USE_MATHJAX is set to YES. -MATHJAX_EXTENSIONS = +MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site @@ -1492,7 +1463,7 @@ MATHJAX_EXTENSIONS = # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. -MATHJAX_CODEFILE = +MATHJAX_CODEFILE = # When the SEARCHENGINE tag is enabled doxygen will generate a search box for # the HTML output. The underlying search engine uses javascript and DHTML and @@ -1552,7 +1523,7 @@ EXTERNAL_SEARCH = NO # Searching" for details. # This tag requires that the tag SEARCHENGINE is set to YES. -SEARCHENGINE_URL = +SEARCHENGINE_URL = # When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed # search data is written to a file for indexing by an external tool. With the @@ -1568,7 +1539,7 @@ SEARCHDATA_FILE = searchdata.xml # projects and redirect the results back to the right project. # This tag requires that the tag SEARCHENGINE is set to YES. -EXTERNAL_SEARCH_ID = +EXTERNAL_SEARCH_ID = # The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen # projects other than the one defined by this configuration file, but that are @@ -1578,7 +1549,7 @@ EXTERNAL_SEARCH_ID = # EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ... # This tag requires that the tag SEARCHENGINE is set to YES. -EXTRA_SEARCH_MAPPINGS = +EXTRA_SEARCH_MAPPINGS = #--------------------------------------------------------------------------- # Configuration options related to the LaTeX output @@ -1633,16 +1604,13 @@ COMPACT_LATEX = NO PAPER_TYPE = a4 # The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names -# that should be included in the LaTeX output. The package can be specified just -# by its name or with the correct syntax as to be used with the LaTeX -# \usepackage command. To get the times font for instance you can specify : -# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times} -# To use the option intlimits with the amsmath package you can specify: -# EXTRA_PACKAGES=[intlimits]{amsmath} +# that should be included in the LaTeX output. To get the times font for +# instance you can specify +# EXTRA_PACKAGES=times # If left blank no extra packages will be included. # This tag requires that the tag GENERATE_LATEX is set to YES. -EXTRA_PACKAGES = +EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a personal LaTeX header for the # generated LaTeX document. The header should contain everything until the first @@ -1658,7 +1626,7 @@ EXTRA_PACKAGES = # to HTML_HEADER. # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_HEADER = +LATEX_HEADER = # The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the # generated LaTeX document. The footer should contain everything after the last @@ -1669,7 +1637,7 @@ LATEX_HEADER = # Note: Only use a user-defined footer if you know what you are doing! # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_FOOTER = +LATEX_FOOTER = # The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined # LaTeX style sheets that are included after the standard style sheets created @@ -1680,7 +1648,7 @@ LATEX_FOOTER = # list). # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_EXTRA_STYLESHEET = +LATEX_EXTRA_STYLESHEET = # The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the LATEX_OUTPUT output @@ -1688,7 +1656,7 @@ LATEX_EXTRA_STYLESHEET = # markers available. # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_EXTRA_FILES = +LATEX_EXTRA_FILES = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is # prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will @@ -1741,14 +1709,6 @@ LATEX_SOURCE_CODE = NO LATEX_BIB_STYLE = plain -# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated -# page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: NO. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_TIMESTAMP = NO - #--------------------------------------------------------------------------- # Configuration options related to the RTF output #--------------------------------------------------------------------------- @@ -1796,14 +1756,14 @@ RTF_HYPERLINKS = NO # default style sheet that doxygen normally uses. # This tag requires that the tag GENERATE_RTF is set to YES. -RTF_STYLESHEET_FILE = +RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an RTF document. Syntax is # similar to doxygen's config file. A template extensions file can be generated # using doxygen -e rtf extensionFile. # This tag requires that the tag GENERATE_RTF is set to YES. -RTF_EXTENSIONS_FILE = +RTF_EXTENSIONS_FILE = # If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code # with syntax highlighting in the RTF output. @@ -1848,7 +1808,7 @@ MAN_EXTENSION = .3 # MAN_EXTENSION with the initial . removed. # This tag requires that the tag GENERATE_MAN is set to YES. -MAN_SUBDIR = +MAN_SUBDIR = # If the MAN_LINKS tag is set to YES and doxygen generates man output, then it # will generate one additional man file for each entity documented in the real @@ -1961,7 +1921,7 @@ PERLMOD_PRETTY = YES # overwrite each other's variables. # This tag requires that the tag GENERATE_PERLMOD is set to YES. -PERLMOD_MAKEVAR_PREFIX = +PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor @@ -2002,7 +1962,7 @@ SEARCH_INCLUDES = YES # preprocessor. # This tag requires that the tag SEARCH_INCLUDES is set to YES. -INCLUDE_PATH = +INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the @@ -2010,7 +1970,7 @@ INCLUDE_PATH = # used. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -INCLUDE_FILE_PATTERNS = +INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that are # defined before the preprocessor is started (similar to the -D option of e.g. @@ -2020,7 +1980,7 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = +PREDEFINED = # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The @@ -2029,7 +1989,7 @@ PREDEFINED = # definition found in the source code. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -EXPAND_AS_DEFINED = +EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will # remove all references to function-like macros that are alone on a line, have @@ -2058,13 +2018,13 @@ SKIP_FUNCTION_MACROS = YES # the path). If a tag file is not located in the directory in which doxygen is # run, you must also specify the path to the tagfile here. -TAGFILES = +TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create a # tag file that is based on the input files it reads. See section "Linking to # external documentation" for more information about the usage of tag files. -GENERATE_TAGFILE = +GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES, all external class will be listed in # the class index. If set to NO, only the inherited external classes will be @@ -2113,14 +2073,14 @@ CLASS_DIAGRAMS = YES # the mscgen tool resides. If left empty the tool is assumed to be found in the # default search path. -MSCGEN_PATH = +MSCGEN_PATH = # You can include diagrams made with dia in doxygen documentation. Doxygen will # then run dia to produce the diagram and insert it in the documentation. The # DIA_PATH tag allows you to specify the directory where the dia binary resides. # If left empty dia is assumed to be found in the default search path. -DIA_PATH = +DIA_PATH = # If set to YES the inheritance and collaboration graphs will hide inheritance # and usage relations if the target is undocumented or is not a class. @@ -2169,7 +2129,7 @@ DOT_FONTSIZE = 10 # the path where dot can find it using this tag. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_FONTPATH = +DOT_FONTPATH = # If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for # each documented class showing the direct and indirect inheritance relations. @@ -2201,7 +2161,7 @@ GROUP_GRAPHS = YES # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -UML_LOOK = NO +UML_LOOK = YES # If the UML_LOOK tag is enabled, the fields and methods are shown inside the # class node. If there are many fields or methods and many nodes the graph may @@ -2247,24 +2207,22 @@ INCLUDED_BY_GRAPH = YES # # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable call graphs for selected -# functions only using the \callgraph command. Disabling a call graph can be -# accomplished by means of the command \hidecallgraph. +# functions only using the \callgraph command. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -CALL_GRAPH = YES +CALL_GRAPH = NO # If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller # dependency graph for every global function or class method. # # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable caller graphs for selected -# functions only using the \callergraph command. Disabling a caller graph can be -# accomplished by means of the command \hidecallergraph. +# functions only using the \callergraph command. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -CALLER_GRAPH = YES +CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical # hierarchy of all classes instead of a textual one. @@ -2283,19 +2241,15 @@ GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. For an explanation of the image formats see the section -# output formats in the documentation of the dot tool (Graphviz (see: -# http://www.graphviz.org/)). +# generated by dot. # Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order # to make the SVG files visible in IE 9+ (other browsers do not have this # requirement). -# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo, -# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and -# png:gdiplus:gdiplus. +# Possible values are: png, jpg, gif and svg. # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_IMAGE_FORMAT = svg +DOT_IMAGE_FORMAT = png # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to # enable generation of interactive SVG images that allow zooming and panning. @@ -2307,32 +2261,32 @@ DOT_IMAGE_FORMAT = svg # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -INTERACTIVE_SVG = YES +INTERACTIVE_SVG = NO # The DOT_PATH tag can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_PATH = +DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the \dotfile # command). # This tag requires that the tag HAVE_DOT is set to YES. -DOTFILE_DIRS = +DOTFILE_DIRS = # The MSCFILE_DIRS tag can be used to specify one or more directories that # contain msc files that are included in the documentation (see the \mscfile # command). -MSCFILE_DIRS = +MSCFILE_DIRS = # The DIAFILE_DIRS tag can be used to specify one or more directories that # contain dia files that are included in the documentation (see the \diafile # command). -DIAFILE_DIRS = +DIAFILE_DIRS = # When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the # path where java can find the plantuml.jar file. If left blank, it is assumed @@ -2340,12 +2294,12 @@ DIAFILE_DIRS = # generate a warning when it encounters a \startuml command in this case and # will not generate output for the diagram. -PLANTUML_JAR_PATH = +PLANTUML_JAR_PATH = # When using plantuml, the specified paths are searched for files specified by # the !include statement in a plantuml block. -PLANTUML_INCLUDE_PATH = +PLANTUML_INCLUDE_PATH = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes # that will be shown in the graph. If the number of nodes in a graph becomes @@ -2381,7 +2335,7 @@ MAX_DOT_GRAPH_DEPTH = 0 # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_TRANSPARENT = YES +DOT_TRANSPARENT = NO # Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This @@ -2390,7 +2344,7 @@ DOT_TRANSPARENT = YES # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_MULTI_TARGETS = YES +DOT_MULTI_TARGETS = NO # If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page # explaining the meaning of the various boxes and arrows in the dot generated diff --git a/hecl/LICENSE b/hecl/LICENSE new file mode 100644 index 000000000..b9b66e63f --- /dev/null +++ b/hecl/LICENSE @@ -0,0 +1,22 @@ +The MIT License + +Copyright (c) 2015-2018 HECL Contributors +Original Authors: Jack Andersen and Phillip "Antidote" Stephens + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/hecl/README.md b/hecl/README.md new file mode 100644 index 000000000..ec5ab6668 --- /dev/null +++ b/hecl/README.md @@ -0,0 +1,29 @@ +### HECL (high-level, extensible combiner language) + +**HECL** is a toolkit for building custom asset pipelines, assisting the development of conversion tools and runtime loaders. + +The most significant feature is the intermediate HECL language, using an expressive command syntax to represent cross-platform shaders. This includes a common source representation and intermediate binary representation. Complete vertex and fragment shader programs are generated for supported platforms and may be built on-demand as part of a 3D application runtime. + +```py +# Combiner 1: Opaque *Diffuse* and *Emissive* +HECLOpaque(Texture(0, UV(0)) * Lighting() + Texture(1, UV(0))) + +# Combiner 2: Alpha-blended single-texture +# (both texture-accesses folded to a single sample operation) +HECLAlpha(Texture(0, UV(0)), Texture(0, UV(0)).a) + +# Combiner 3: Additive-blended single-texture +# (modern graphics APIs require blending configuration along with all shader configs) +HECLAdditive(Texture(0, UV(0)), Texture(0, UV(0)).a) +``` + +Beyond shaders, HECL also defines a rigged mesh format called HMDL. Meshes using this encoding interact with HECL, with pose transforms applied via the vertex shader. + +For asset pipelines, HECL provides a project system with dependency-resolution much like an IDE or `make`. Assets in their editable representation are *cooked* in-bulk and whenever the source file is updated. Currently, blender is the only-supported input format for rigged meshes with node-materials. + +#### Supported Backends + +* GLSL 330 *(with optional SPIR-V conversion)* +* HLSL (Shader Model 4) +* Metal 1.1 +* GX *(complete TexCoordGen and TEV configs in intermediate structures)* diff --git a/hecl/bintoc/CMakeLists.txt b/hecl/bintoc/CMakeLists.txt new file mode 100644 index 000000000..7fc94c258 --- /dev/null +++ b/hecl/bintoc/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) +cmake_policy(VERSION 3.15...3.20) +project(bintoc LANGUAGES C) + +add_executable(bintoc bintoc.c) +find_package(ZLIB REQUIRED) +target_link_libraries(bintoc PRIVATE ZLIB::ZLIB) + +install(TARGETS bintoc DESTINATION bin) \ No newline at end of file diff --git a/hecl/bintoc/bintoc.c b/hecl/bintoc/bintoc.c new file mode 100644 index 000000000..fc81b906e --- /dev/null +++ b/hecl/bintoc/bintoc.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include + +#define CHUNK 16384 +#define LINE_BREAK 32 +static uint8_t buf[CHUNK]; +static uint8_t zbuf[CHUNK]; + +void print_usage() { fprintf(stderr, "Usage: bintoc [--compress] \n"); } + +int main(int argc, char** argv) { + if (argc < 4) { + print_usage(); + return 1; + } + char* input = argv[1]; + char* output = argv[2]; + char* symbol = argv[3]; + bool compress = false; + if (strcmp(input, "--compress") == 0) { + if (argc < 5) { + print_usage(); + return 1; + } + input = argv[2]; + output = argv[3]; + symbol = argv[4]; + compress = true; + } + FILE* fin = fopen(input, "rb"); + if (!fin) { + fprintf(stderr, "Unable to open %s for reading\n", input); + return 1; + } + FILE* fout = fopen(output, "wb"); + if (!fout) { + fprintf(stderr, "Unable to open %s for writing\n", output); + return 1; + } + fprintf(fout, "#include \n#include \n"); + fprintf(fout, "extern \"C\" const uint8_t %s[] =\n{\n ", symbol); + size_t totalSz = 0; + size_t readSz; + if (compress) { + size_t compressedSz = 0; + z_stream strm = {.zalloc = Z_NULL, .zfree = Z_NULL, .opaque = Z_NULL}; + int ret = deflateInit2(&strm, Z_BEST_COMPRESSION, Z_DEFLATED, MAX_WBITS | 16, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); + if (ret != Z_OK) { + fprintf(stderr, "zlib initialization failed %d\n", ret); + return 1; + } + while ((strm.avail_in = fread(buf, 1, sizeof(buf), fin))) { + totalSz += strm.avail_in; + strm.next_in = buf; + int eof = feof(fin); + do { + strm.next_out = zbuf; + strm.avail_out = sizeof(zbuf); + ret = deflate(&strm, eof ? Z_FINISH : Z_NO_FLUSH); + if (ret == Z_STREAM_ERROR) { + fprintf(stderr, "zlib compression failed %d\n", ret); + return 1; + } + size_t sz = sizeof(zbuf) - strm.avail_out; + if (sz > 0) { + for (int b = 0; b < sz; ++b) { + fprintf(fout, "0x%02X, ", zbuf[b]); + if ((compressedSz + b + 1) % LINE_BREAK == 0) + fprintf(fout, "\n "); + } + compressedSz += sz; + } + } while (strm.avail_out == 0 || (eof && (ret == Z_OK || ret == Z_BUF_ERROR))); + } + deflateEnd(&strm); + fprintf(fout, "0x00};\nextern \"C\" const size_t %s_SZ = %zu;\n", symbol, compressedSz); + fprintf(fout, "extern \"C\" const size_t %s_DECOMPRESSED_SZ = %zu;\n", symbol, totalSz); + } else { + while ((readSz = fread(buf, 1, sizeof(buf), fin))) { + for (int b = 0; b < readSz; ++b) { + fprintf(fout, "0x%02X, ", buf[b]); + if ((totalSz + b + 1) % LINE_BREAK == 0) + fprintf(fout, "\n "); + } + totalSz += readSz; + } + fprintf(fout, "0x0};\nextern \"C\" const size_t %s_SZ = %zu;\n", symbol, totalSz); + } + fclose(fin); + fclose(fout); + return 0; +} diff --git a/hecl/bintoc/bintocHelpers.cmake b/hecl/bintoc/bintocHelpers.cmake new file mode 100644 index 000000000..cb32651d7 --- /dev/null +++ b/hecl/bintoc/bintocHelpers.cmake @@ -0,0 +1,37 @@ +function(bintoc out in sym) + if(IS_ABSOLUTE ${out}) + set(theOut ${out}) + else() + set(theOut ${CMAKE_CURRENT_BINARY_DIR}/${out}) + endif() + if(IS_ABSOLUTE ${in}) + set(theIn ${in}) + else() + set(theIn ${CMAKE_CURRENT_SOURCE_DIR}/${in}) + endif() + get_filename_component(outDir ${theOut} DIRECTORY) + file(MAKE_DIRECTORY ${outDir}) + ExternalProject_Get_Property(bintoc INSTALL_DIR) + add_custom_command(OUTPUT ${theOut} + COMMAND "${INSTALL_DIR}/bin/bintoc" ARGS ${theIn} ${theOut} ${sym} + DEPENDS ${theIn} bintoc) +endfunction() + +function(bintoc_compress out in sym) + if(IS_ABSOLUTE ${out}) + set(theOut ${out}) + else() + set(theOut ${CMAKE_CURRENT_BINARY_DIR}/${out}) + endif() + if(IS_ABSOLUTE ${in}) + set(theIn ${in}) + else() + set(theIn ${CMAKE_CURRENT_SOURCE_DIR}/${in}) + endif() + get_filename_component(outDir ${theOut} DIRECTORY) + file(MAKE_DIRECTORY ${outDir}) + ExternalProject_Get_Property(bintoc INSTALL_DIR) + add_custom_command(OUTPUT ${theOut} + COMMAND "${INSTALL_DIR}/bin/bintoc" ARGS --compress ${theIn} ${theOut} ${sym} + DEPENDS ${theIn} bintoc) +endfunction() diff --git a/hecl/blender/CMakeLists.txt b/hecl/blender/CMakeLists.txt new file mode 100644 index 000000000..87520afcc --- /dev/null +++ b/hecl/blender/CMakeLists.txt @@ -0,0 +1,35 @@ +list(APPEND PY_SOURCES + hecl/__init__.py + hecl/Nodegrid.py + hecl/Patching.py + hecl/hmdl/__init__.py + hecl/hmdl/HMDLMesh.py + hecl/hmdl/HMDLShader.py + hecl/sact/__init__.py + hecl/sact/SACTAction.py + hecl/sact/SACTSubtype.py + hecl/srea/__init__.py + hecl/swld/__init__.py + hecl/armature.py + hecl/mapa.py + hecl/mapu.py + hecl/frme.py + hecl/path.py) + +bintoc(hecl_blendershell.cpp hecl_blendershell.py HECL_BLENDERSHELL) + +find_package(Python COMPONENTS Interpreter REQUIRED) + +add_custom_command(OUTPUT hecl.zip DEPENDS ${PY_SOURCES} + COMMAND ${Python_EXECUTABLE} ARGS zip_package.py ${CMAKE_CURRENT_BINARY_DIR}/hecl.zip + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Generating addon package") +bintoc(hecl_addon.cpp "${CMAKE_CURRENT_BINARY_DIR}/hecl.zip" HECL_ADDON) + +add_library(hecl-blender-addon + hecl_blendershell.py + hecl_blendershell.cpp + zip_package.py + hecl.zip + hecl_addon.cpp + ${PY_SOURCES}) diff --git a/hecl/blender/hecl/Nodegrid.py b/hecl/blender/hecl/Nodegrid.py new file mode 100644 index 000000000..d43395adb --- /dev/null +++ b/hecl/blender/hecl/Nodegrid.py @@ -0,0 +1,59 @@ +# Node Grid Arranger Class +NODE_PADDING = 80 +FRAME_NAMES = ['Textures','Output','Blend'] +FRAME_WIDTHS = [400, 180, 180] +TOTAL_WIDTH = 0.0 +for width in FRAME_WIDTHS: + TOTAL_WIDTH += width + NODE_PADDING +FRAME_COLORS = [(0.6,0.48,0.44),(0.53,0.6,0.47),(0.56,0.46,0.90)] +class Nodegrid: + + def __init__(self, nodetree, cycles=False): + self.ncol = len(FRAME_NAMES) + self.heights = [] + self.frames = [] + self.col_roffs = [[0.0,0.0]] * self.ncol + for i in range(self.ncol): + if cycles and i<1: + self.heights.append(-1600.0) + self.frames.append(None) + continue + elif cycles: + self.heights.append(-1600.0) + else: + self.heights.append(0.0) + frame_node = nodetree.nodes.new('NodeFrame') + frame_node.label = FRAME_NAMES[i] + frame_node.use_custom_color = True + frame_node.color = FRAME_COLORS[i] + self.frames.append(frame_node) + + def place_node(self, node, col, update_height = True): + if col < 0 or col >= self.ncol: + return False + + x_pos = NODE_PADDING + for i in range(col): + x_pos += FRAME_WIDTHS[i] + NODE_PADDING*2 + node.location[0] = x_pos - TOTAL_WIDTH/2 + node.location[1] = self.heights[col] + if update_height: + self.heights[col] -= node.height + NODE_PADDING + self.frames[col].height += node.height + NODE_PADDING + node.parent = self.frames[col] + + return True + + def place_node_right(self, node, col, srow): + heights_backup = self.heights[col] + if self.place_node(node, col): + node.location[0] += self.col_roffs[col][srow] + if srow == 1: + node.location[1] -= 175 + self.col_roffs[col][srow] += 200 + self.heights[col] = heights_backup + + def row_break(self, col): + self.heights[col] -= 350 + self.col_roffs[col][0] = 0.0 + self.col_roffs[col][1] = 0.0 diff --git a/hecl/blender/hecl/Patching.py b/hecl/blender/hecl/Patching.py new file mode 100644 index 000000000..054b0296c --- /dev/null +++ b/hecl/blender/hecl/Patching.py @@ -0,0 +1,144 @@ +import bpy +import os +import os.path +from pathlib import Path + +def _mkdir(path): + try: + os.mkdir(path) + except: + pass + +def path_components(path): + retval = [] + base, end = os.path.split(path) + while end != '': + retval.insert(0, end) + base, end = os.path.split(base) + return retval + +def find_project_root(): + if bpy.data.filepath == '': + return None + path = os.path.split(bpy.data.filepath) + test_path = os.path.join(path[0], '.hecl') + while not os.path.exists(test_path): + path = os.path.split(path[0]) + test_path = os.path.join(path[0], '.hecl') + if os.path.exists(test_path): + return path[0] + return None + +def get_patching_dirs(make_dirs=False): + proj_root = find_project_root() + if not proj_root: + return None, None + rel_to_blend = os.path.relpath(bpy.data.filepath, start=proj_root) + rel_to_blend_comps = path_components(rel_to_blend) + trace_dir = os.path.join(proj_root, '.hecl', 'patches') + global_out = trace_dir + if not make_dirs and not os.path.exists(trace_dir): + return None, global_out + _mkdir(trace_dir) + for comp in rel_to_blend_comps: + ext_pair = os.path.splitext(comp) + if ext_pair[1] == '.blend': + trace_dir = os.path.join(trace_dir, ext_pair[0]) + if not make_dirs and not os.path.exists(trace_dir): + return None, global_out + _mkdir(trace_dir) + return trace_dir, global_out + trace_dir = os.path.join(trace_dir, comp) + if not make_dirs and not os.path.exists(trace_dir): + return None, global_out + _mkdir(trace_dir) + +class FILE_OT_hecl_patching_save(bpy.types.Operator): + '''Save text datablocks to hecl patching directory''' + bl_idname = "file.hecl_patching_save" + bl_label = "Save HECL Patches" + bl_options = {'REGISTER'} + + def execute(self, context): + patching_dir, global_dir = get_patching_dirs(make_dirs=True) + if not patching_dir: + self.report({'WARNING'}, 'Unable to save patches for ' + bpy.data.filepath) + return {'CANCELLED'} + count = 0 + for text in bpy.data.texts: + if not text.name.endswith('.py') or text.name.startswith('g_'): + continue + text_abspath = os.path.join(patching_dir, text.name) + text_file = open(text_abspath, 'w') + text_file.write(text.as_string()) + text_file.close() + count += 1 + if count == 1: + self.report({'INFO'}, 'saved 1 patch') + else: + self.report({'INFO'}, 'saved %d patches' % count) + return {'FINISHED'} + +class FILE_OT_hecl_patching_load(bpy.types.Operator): + '''Load text datablocks from hecl patching directory''' + bl_idname = "file.hecl_patching_load" + bl_label = "Load HECL Patches" + bl_options = {'REGISTER'} + + def execute(self, context): + patching_dir, global_dir = get_patching_dirs() + count = 0 + + # Locals + if patching_dir: + p = Path(patching_dir) + for path in p.glob('*.py'): + path = path.name + text_abspath = os.path.join(patching_dir, path) + text_file = open(text_abspath, 'r') + if path in bpy.data.texts: + text = bpy.data.texts[path] + else: + text = bpy.data.texts.new(path) + text.from_string(text_file.read()) + text_file.close() + count += 1 + + # Globals + if global_dir: + p = Path(global_dir) + for path in p.glob('g_*.py'): + path = path.name + text_abspath = os.path.join(global_dir, path) + text_file = open(text_abspath, 'r') + if path in bpy.data.texts: + text = bpy.data.texts[path] + else: + text = bpy.data.texts.new(path) + text.from_string(text_file.read()) + text_file.close() + count += 1 + + if count == 1: + self.report({'INFO'}, 'loaded 1 patch') + else: + self.report({'INFO'}, 'loaded %d patches' % count) + return {'FINISHED'} + +def save_func(self, context): + self.layout.operator("file.hecl_patching_save", text="Save HECL Patches") + +def load_func(self, context): + self.layout.operator("file.hecl_patching_load", text="Load HECL Patches") + +def register(): + bpy.utils.register_class(FILE_OT_hecl_patching_save) + bpy.utils.register_class(FILE_OT_hecl_patching_load) + bpy.types.TOPBAR_MT_file_external_data.append(load_func) + bpy.types.TOPBAR_MT_file_external_data.append(save_func) + +def unregister(): + bpy.utils.unregister_class(FILE_OT_hecl_patching_save) + bpy.utils.unregister_class(FILE_OT_hecl_patching_load) + bpy.types.TOPBAR_MT_file_external_data.remove(load_func) + bpy.types.TOPBAR_MT_file_external_data.remove(save_func) diff --git a/hecl/blender/hecl/__init__.py b/hecl/blender/hecl/__init__.py new file mode 100644 index 000000000..8b9c5a808 --- /dev/null +++ b/hecl/blender/hecl/__init__.py @@ -0,0 +1,267 @@ +bl_info = { + "name": "HECL", + "author": "Jack Andersen ", + "version": (1, 0), + "blender": (2, 80, 0), + "tracker_url": "https://github.com/AxioDL/hecl/issues/new", + "location": "Properties > Scene > HECL", + "description": "Enables blender to gather meshes, materials, and textures for hecl", + "category": "System"} + +# Package import +from . import hmdl, sact, srea, swld, armature, mapa, mapu, frme, path, Nodegrid, Patching +Nodegrid = Nodegrid.Nodegrid +parent_armature = sact.SACTSubtype.parent_armature +import bpy, os, sys, struct, math +from mathutils import Vector + +# Appendable list allowing external addons to register additional resource types +hecl_typeS = [ +('NONE', "None", "Active scene not using HECL", None), +('MESH', "Mesh", "Active scene represents an HMDL Mesh", hmdl.draw), +('CMESH', "Collision Mesh", "Active scene represents a Collision Mesh", None), +('ARMATURE', "Armature", "Active scene represents an Armature", armature.draw), +('ACTOR', "Actor", "Active scene represents a HECL Actor", sact.draw), +('AREA', "Area", "Active scene represents a HECL Area", srea.draw), +('WORLD', "World", "Active scene represents a HECL World", swld.draw), +('MAPAREA', "Map Area", "Active scene represents a HECL Map Area", mapa.draw), +('MAPUNIVERSE', "Map Universe", "Active scene represents a HECL Map Universe", mapu.draw), +('FRAME', "Gui Frame", "Active scene represents a HECL Gui Frame", frme.draw), +('PATH', "Path Mesh", "Active scene represents a HECL Path Mesh", path.draw)] + +# Main Scene Panel +class hecl_scene_panel(bpy.types.Panel): + bl_idname = "SCENE_PT_hecl" + bl_label = "HECL" + bl_space_type = 'PROPERTIES' + bl_region_type = 'WINDOW' + bl_context = "scene" + + @classmethod + def poll(cls, context): + return (context.scene is not None) + + def draw(self, context): + layout = self.layout + type_row = layout.row(align=True) + type_row.prop_menu_enum(context.scene, 'hecl_type', text='Export Type') + + if context.scene.hecl_type == 'MESH' or context.scene.hecl_type == 'AREA' or context.scene.hecl_type == 'ACTOR': + sm_row = layout.row(align=True) + sm_row.prop_enum(context.scene, 'hecl_shader_model', 'ORIGINAL') + sm_row.prop_enum(context.scene, 'hecl_shader_model', 'PBR') + layout.prop(context.scene, 'hecl_mp3_bloom', text='View MP3 Bloom') + + for exp_type in hecl_typeS: + if exp_type[0] == context.scene.hecl_type and callable(exp_type[3]): + exp_type[3](self.layout, context) + break + +# Light Panel +class hecl_light_panel(bpy.types.Panel): + bl_idname = "DATA_PT_hecl_light" + bl_label = "HECL" + bl_space_type = 'PROPERTIES' + bl_region_type = 'WINDOW' + bl_context = "data" + + @classmethod + def poll(cls, context): + return context.light + + def draw(self, context): + layout = self.layout + layout.prop(context.light, 'hecl_falloff_constant') + layout.prop(context.light, 'hecl_falloff_linear') + layout.prop(context.light, 'hecl_falloff_quadratic') + +# Blender export-type registration +def register_export_type_enum(): + bpy.types.Scene.hecl_type = bpy.props.EnumProperty(items= + [tp[:3] for tp in hecl_typeS], + name="HECL Export Type", + description="Selects how active scene is exported by HECL") + +# Function for external addons to register export types with HECL +def add_export_type(type_tuple): + type_tup = tuple(type_tuple) + for tp in hecl_typeS: + if tp[0] == type_tup[0]: + raise RuntimeError("Type already registered with HECL") + hecl_types.append(type_tup) + register_export_type_enum() + +# Shell command receiver (from HECL driver) +def command(cmdline, writepipeline, writepipebuf): + pass + +def mesh_aabb(writepipebuf): + scene = bpy.context.scene + total_min = Vector((99999.0, 99999.0, 99999.0)) + total_max = Vector((-99999.0, -99999.0, -99999.0)) + + if bpy.context.scene.hecl_type == 'ACTOR': + sact_data = bpy.context.scene.hecl_sact_data + for subtype in sact_data.subtypes: + if subtype.linked_mesh in bpy.data.objects: + mesh = bpy.data.objects[subtype.linked_mesh] + minPt = mesh.bound_box[0] + maxPt = mesh.bound_box[6] + for comp in range(3): + if minPt[comp] < total_min[comp]: + total_min[comp] = minPt[comp] + for comp in range(3): + if maxPt[comp] > total_max[comp]: + total_max[comp] = maxPt[comp] + + elif bpy.context.scene.hecl_type == 'MESH': + meshName = bpy.context.scene.hecl_mesh_obj + if meshName in bpy.data.objects: + mesh = bpy.data.objects[meshName] + minPt = mesh.bound_box[0] + maxPt = mesh.bound_box[6] + for comp in range(3): + if minPt[comp] < total_min[comp]: + total_min[comp] = minPt[comp] + for comp in range(3): + if maxPt[comp] > total_max[comp]: + total_max[comp] = maxPt[comp] + + writepipebuf(struct.pack('fff', total_min[0], total_min[1], total_min[2])) + writepipebuf(struct.pack('fff', total_max[0], total_max[1], total_max[2])) + +def shader_model_update(self, context): + value = 0.0 + if self.hecl_shader_model == 'PBR': + value = 1.0 + bloom_value = 0.0 + if self.hecl_mp3_bloom: + bloom_value = 1.0 + for shad in ('RetroShader', 'RetroDynamicShader', 'RetroDynamicAlphaShader', 'RetroDynamicCharacterShader'): + if shad in bpy.data.node_groups and 'NewShaderModel' in bpy.data.node_groups[shad].nodes: + bpy.data.node_groups[shad].nodes['NewShaderModel'].outputs[0].default_value = value + for shad in ('RetroShaderMP3',): + if shad in bpy.data.node_groups and 'Mix Shader' in bpy.data.node_groups[shad].nodes: + bpy.data.node_groups[shad].nodes['Mix Shader'].inputs[0].default_value = bloom_value + +# Load scene callback +from bpy.app.handlers import persistent +@persistent +def scene_loaded(dummy): + # Hide everything from an external library + if bpy.context.scene.hecl_type != 'FRAME': + for o in bpy.context.scene.objects: + if o.library or (o.data and o.data.library): + o.hide_set(True) + + # Show PATH library objects as wireframes + if bpy.context.scene.hecl_type == 'PATH': + if bpy.context.scene.background_set: + for o in bpy.context.scene.background_set.objects: + o.display_type = 'WIRE' + if bpy.context.scene.hecl_path_obj in bpy.context.scene.objects: + path_obj = bpy.context.scene.objects[bpy.context.scene.hecl_path_obj] + path_obj.show_wire = True + + # Linked-Child Detection + for scene in bpy.data.scenes: + if scene.hecl_type == 'ACTOR': + actor_data = scene.hecl_sact_data + for subtype in actor_data.subtypes: + if subtype.linked_mesh in bpy.data.objects: + mesh_obj = bpy.data.objects[subtype.linked_mesh] + if subtype.linked_armature in bpy.data.objects: + arm_obj = bpy.data.objects[subtype.linked_armature] + parent_armature(mesh_obj, arm_obj) + for overlay in subtype.overlays: + if overlay.linked_mesh in bpy.data.objects: + mesh_obj = bpy.data.objects[overlay.linked_mesh] + parent_armature(mesh_obj, arm_obj) + + # Show only the active mesh and action + if sact.SACTSubtype.SACTSubtype_load.poll(bpy.context): + bpy.ops.scene.sactsubtype_load() + if sact.SACTAction.SACTAction_load.poll(bpy.context): + bpy.ops.scene.sactaction_load() + + shader_model_update(bpy.context.scene, bpy.context) + +def power_of_distance(context, light, dist): + color = light.color + return dist * dist * context.scene.eevee.light_threshold / max(color[0], max(color[1], color[2])) + +def power_of_coefficients(context, light): + epsilon = 1.19e-07 + if light.hecl_falloff_linear < epsilon and light.hecl_falloff_quadratic < epsilon: + return 0.0 + color = light.color + intens = max(color[0], max(color[1], color[2])) + if light.hecl_falloff_quadratic > epsilon: + if intens <= epsilon: + return 0.0 + return power_of_distance(context, light, math.sqrt(intens / (0.0588235 * light.hecl_falloff_quadratic))) + if light.hecl_falloff_linear > epsilon: + return power_of_distance(context, light, intens / (0.0588235 * light.hecl_falloff_linear)) + return 0.0 + +def set_light_falloff(self, context): + self.energy = power_of_coefficients(context, self) + +# Registration +def register(): + register_export_type_enum() + hmdl.register() + sact.register() + srea.register() + frme.register() + mapa.register() + mapu.register() + path.register() + armature.register() + bpy.utils.register_class(hecl_scene_panel) + bpy.utils.register_class(hecl_light_panel) + bpy.types.Scene.hecl_auto_select = bpy.props.BoolProperty(name='HECL Auto Select', default=True) + bpy.types.Light.hecl_falloff_constant = bpy.props.FloatProperty( + name="HECL Falloff Constant", + description="Constant falloff coefficient", + update=set_light_falloff, + default=1.0, + min=0.0) + bpy.types.Light.hecl_falloff_linear = bpy.props.FloatProperty( + name="HECL Falloff Linear", + description="Linear falloff coefficient", + update=set_light_falloff, + default=0.0, + min=0.0) + bpy.types.Light.hecl_falloff_quadratic = bpy.props.FloatProperty( + name="HECL Falloff Quadratic", + description="Quadratic falloff coefficient", + update=set_light_falloff, + default=0.0, + min=0.0) + bpy.types.Scene.hecl_shader_model = bpy.props.EnumProperty(name="HECL Shader Model", + description="Which shader model to use for rendering", + items=[ + ('ORIGINAL', "Original", "Close approximation of GameCube materials"), + ('PBR', "PBR", "Hybrid PBR materials replacing original reflection")], + update=shader_model_update, + default='ORIGINAL') + bpy.types.Scene.hecl_mp3_bloom = bpy.props.BoolProperty(name="HECL View MP3 Bloom", + description="Preview MP3 bloom factors of model", + update=shader_model_update, + default=False) + bpy.app.handlers.load_post.append(scene_loaded) + Patching.register() + +def unregister(): + bpy.app.handlers.load_post.remove(scene_loaded) + hmdl.unregister() + sact.unregister() + srea.unregister() + path.unregister() + bpy.utils.unregister_class(hecl_scene_panel) + bpy.utils.unregister_class(hecl_light_panel) + Patching.unregister() + +if __name__ == "__main__": + register() diff --git a/hecl/blender/hecl/armature.py b/hecl/blender/hecl/armature.py new file mode 100644 index 000000000..91477a9ce --- /dev/null +++ b/hecl/blender/hecl/armature.py @@ -0,0 +1,35 @@ +import struct + +def cook(writebuf, arm): + writebuf(struct.pack('I', len(arm.bones))) + for bone in arm.bones: + writebuf(struct.pack('I', len(bone.name))) + writebuf(bone.name.encode()) + + writebuf(struct.pack('fff', bone.head_local[0], bone.head_local[1], bone.head_local[2])) + + if bone.parent: + writebuf(struct.pack('i', arm.bones.find(bone.parent.name))) + else: + writebuf(struct.pack('i', -1)) + + writebuf(struct.pack('I', len(bone.children))) + for child in bone.children: + writebuf(struct.pack('i', arm.bones.find(child.name))) + +def draw(layout, context): + layout.prop_search(context.scene, 'hecl_arm_obj', context.scene, 'objects') + if not len(context.scene.hecl_arm_obj): + layout.label(text="Armature not specified", icon='ERROR') + elif context.scene.hecl_arm_obj not in context.scene.objects: + layout.label(text="'"+context.scene.hecl_arm_obj+"' not in scene", icon='ERROR') + else: + obj = context.scene.objects[context.scene.hecl_arm_obj] + if obj.type != 'ARMATURE': + layout.label(text="'"+context.scene.hecl_arm_obj+"' not an 'ARMATURE'", icon='ERROR') + +import bpy +def register(): + bpy.types.Scene.hecl_arm_obj = bpy.props.StringProperty( + name='HECL Armature Object', + description='Blender Armature Object to export during HECL\'s cook process') diff --git a/hecl/blender/hecl/frme.py b/hecl/blender/hecl/frme.py new file mode 100644 index 000000000..76c25ba5d --- /dev/null +++ b/hecl/blender/hecl/frme.py @@ -0,0 +1,391 @@ +import bpy, struct, math +from mathutils import Quaternion + +def draw(layout, context): + if bpy.context.active_object: + obj = bpy.context.active_object + layout.label(text="Widget Settings:", icon='OBJECT_DATA') + layout.prop_menu_enum(obj, 'retro_widget_type', text='Widget Type') + #layout.prop_search(obj, 'retro_widget_parent', context.scene, 'objects', text='Widget Parent') + row = layout.row(align=True) + row.prop(obj, 'retro_widget_default_visible', text='Visible') + row.prop(obj, 'retro_widget_default_active', text='Active') + row.prop(obj, 'retro_widget_cull_faces', text='Cull Faces') + layout.prop(obj, 'retro_widget_color', text='Color') + layout.prop_menu_enum(obj, 'retro_widget_model_draw_flags', text='Draw Flags') + row = layout.row(align=True) + row.prop(obj, 'retro_widget_is_worker', text='Is Worker') + if obj.retro_widget_is_worker: + row.prop(obj, 'retro_widget_worker_id', text='Worker Id') + + if obj.retro_widget_type == 'RETRO_MODL': + layout.prop(obj, 'retro_model_light_mask', text='Light Mask') + elif obj.retro_widget_type == 'RETRO_PANE': + layout.prop(obj, 'retro_pane_dimensions', text='Dimensions') + layout.prop(obj, 'retro_pane_scale_center', text='Center') + elif obj.retro_widget_type == 'RETRO_TXPN': + layout.prop(obj, 'retro_pane_dimensions', text='Dimensions') + layout.prop(obj, 'retro_pane_scale_center', text='Center') + layout.prop(obj, 'retro_textpane_font_path', text='Font Path') + row = layout.row(align=True) + row.prop(obj, 'retro_textpane_word_wrap', text='Word Wrap') + row.prop(obj, 'retro_textpane_horizontal', text='Horizontal') + layout.prop(obj, 'retro_textpane_fill_color', text='Fill Color') + layout.prop(obj, 'retro_textpane_outline_color', text='Outline Color') + layout.prop(obj, 'retro_textpane_block_extent', text='Point Dimensions') + layout.prop(obj, 'retro_textpane_jp_font_path', text='JP Font Path') + layout.prop(obj, 'retro_textpane_jp_font_scale', text='JP Point Dimensions') + layout.prop_menu_enum(obj, 'retro_textpane_hjustification', text='Horizontal Justification') + layout.prop_menu_enum(obj, 'retro_textpane_vjustification', text='Vertical Justification') + elif obj.retro_widget_type == 'RETRO_TBGP': + layout.prop(obj, 'retro_tablegroup_elem_count', text='Element Count') + layout.prop(obj, 'retro_tablegroup_elem_default', text='Default Element') + layout.prop(obj, 'retro_tablegroup_wraparound', text='Wraparound') + elif obj.retro_widget_type == 'RETRO_GRUP': + layout.prop(obj, 'retro_group_default_worker', text='Default Worker') + elif obj.retro_widget_type == 'RETRO_SLGP': + row = layout.row(align=True) + row.prop(obj, 'retro_slider_min', text='Min') + row.prop(obj, 'retro_slider_max', text='Max') + layout.prop(obj, 'retro_slider_default', text='Default') + layout.prop(obj, 'retro_slider_increment', text='Increment') + elif obj.retro_widget_type == 'RETRO_ENRG': + layout.prop(obj, 'retro_energybar_texture_path', text='Energy Bar Texture Path') + elif obj.retro_widget_type == 'RETRO_METR': + layout.prop(obj, 'retro_meter_no_round_up', text='No Round Up') + layout.prop(obj, 'retro_meter_max_capacity', text='Max Capacity') + layout.prop(obj, 'retro_meter_worker_count', text='Worker Count') + elif obj.retro_widget_type == 'RETRO_LITE': + if obj.data and obj.type == 'LIGHT': + layout.prop(obj.data, 'retro_light_index', text='Index') + layout.label(text="Angular Falloff:", icon='LIGHT') + row = layout.row(align=True) + row.prop(obj.data, 'retro_light_angle_constant', text='Constant') + row.prop(obj.data, 'retro_light_angle_linear', text='Linear') + row.prop(obj.data, 'retro_light_angle_quadratic', text='Quadratic') + +hjustifications = None +vjustifications = None +model_draw_flags_e = None + +def recursive_cook(buffer, obj, version, path_hasher, parent_name): + buffer += struct.pack('>4s', obj.retro_widget_type[6:].encode()) + buffer += obj.name.encode() + b'\0' + buffer += parent_name.encode() + b'\0' + buffer += struct.pack('>bbbbffffI', + False, + obj.retro_widget_default_visible, + obj.retro_widget_default_active, + obj.retro_widget_cull_faces, + obj.retro_widget_color[0], + obj.retro_widget_color[1], + obj.retro_widget_color[2], + obj.retro_widget_color[3], + model_draw_flags_e[obj.retro_widget_model_draw_flags]) + + angle = Quaternion((1.0, 0.0, 0.0), 0) + + if obj.retro_widget_type == 'RETRO_CAMR': + angle = Quaternion((1.0, 0.0, 0.0), math.radians(-90.0)) + aspect = bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y + + if obj.data.type == 'PERSP': + if aspect > 1.0: + fov = math.degrees(math.atan(math.tan(obj.data.angle / 2.0) / aspect)) * 2.0 + else: + fov = math.degrees(obj.data.angle) + buffer += struct.pack('>Iffff', 0, fov, aspect, obj.data.clip_start, obj.data.clip_end) + + elif obj.data.type == 'ORTHO': + ortho_half = obj.data.ortho_scale / 2.0 + buffer += struct.pack('>Iffffff', 1, -ortho_half, ortho_half, ortho_half / aspect, + -ortho_half / aspect, obj.data.clip_start, obj.data.clip_end) + + elif obj.retro_widget_type == 'RETRO_MODL': + if len(obj.children) == 0: + raise RuntimeException('Model Widget must have a child model object') + model_obj = obj.children[0] + if model_obj.type != 'MESH': + raise RuntimeException('Model Widget must have a child MESH') + if not model_obj.data.library: + raise RuntimeException('Model Widget must have a linked library MESH') + path = bpy.path.abspath(model_obj.data.library.filepath) + path_hash = path_hasher.hashpath32(path) + buffer += struct.pack('>III', path_hash, 0, obj.retro_model_light_mask) + + elif obj.retro_widget_type == 'RETRO_PANE': + buffer += struct.pack('>fffff', + obj.retro_pane_dimensions[0], + obj.retro_pane_dimensions[1], + obj.retro_pane_scale_center[0], + obj.retro_pane_scale_center[1], + obj.retro_pane_scale_center[2]) + + elif obj.retro_widget_type == 'RETRO_TXPN': + path_hash = path_hasher.hashpath32(obj.retro_textpane_font_path) + buffer += struct.pack('>fffffIbbIIffffffffff', + obj.retro_pane_dimensions[0], + obj.retro_pane_dimensions[1], + obj.retro_pane_scale_center[0], + obj.retro_pane_scale_center[1], + obj.retro_pane_scale_center[2], + path_hash, + obj.retro_textpane_word_wrap, + obj.retro_textpane_horizontal, + hjustifications[obj.retro_textpane_hjustification], + vjustifications[obj.retro_textpane_vjustification], + obj.retro_textpane_fill_color[0], + obj.retro_textpane_fill_color[1], + obj.retro_textpane_fill_color[2], + obj.retro_textpane_fill_color[3], + obj.retro_textpane_outline_color[0], + obj.retro_textpane_outline_color[1], + obj.retro_textpane_outline_color[2], + obj.retro_textpane_outline_color[3], + obj.retro_textpane_block_extent[0], + obj.retro_textpane_block_extent[1]) + if version >= 1: + path_hash = path_hasher.hashpath32(obj.retro_textpane_jp_font_path) + buffer += struct.pack('>III', + path_hash, + obj.retro_textpane_jp_font_scale[0], + obj.retro_textpane_jp_font_scale[1]) + + elif obj.retro_widget_type == 'RETRO_TBGP': + buffer += struct.pack('>HHIHHbbffbfHHHH', + obj.retro_tablegroup_elem_count, + 0, + 0, + obj.retro_tablegroup_elem_default, + 0, + obj.retro_tablegroup_wraparound, + False, + 0.0, + 0.0, + False, + 0.0, + 0, + 0, + 0, + 0) + + elif obj.retro_widget_type == 'RETRO_GRUP': + buffer += struct.pack('>Hb', + obj.retro_group_default_worker, + False) + + elif obj.retro_widget_type == 'RETRO_SLGP': + buffer += struct.pack('>ffff', + obj.retro_slider_min, + obj.retro_slider_max, + obj.retro_slider_default, + obj.retro_slider_increment) + + elif obj.retro_widget_type == 'RETRO_ENRG': + path_hash = path_hasher.hashpath32(obj.retro_energybar_texture_path) + buffer += struct.pack('>I', path_hash) + + elif obj.retro_widget_type == 'RETRO_METR': + buffer += struct.pack('>bbII', + False, + obj.retro_meter_no_round_up, + obj.retro_meter_max_capacity, + obj.retro_meter_worker_count) + + elif obj.retro_widget_type == 'RETRO_LITE': + angle = Quaternion((1.0, 0.0, 0.0), math.radians(-90.0)) + type_enum = 0 + constant = 1.0 + linear = 0.0 + quadratic = 0.0 + cutoff = 0.0 + if obj.data.type == 'POINT': + type_enum = 4 + elif obj.data.type == 'SUN': + type_enum = 2 + elif obj.data.type == 'SPOT': + type_enum = 0 + cutoff = obj.data.spot_size + + if obj.data.type == 'POINT' or obj.data.type == 'SPOT': + constant = obj.data.constant_coefficient + linear = obj.data.linear_coefficient + quadratic = obj.data.quadratic_coefficient + + buffer += struct.pack('>IffffffI', + type_enum, constant, linear, quadratic, + obj.data.retro_light_angle_constant, + obj.data.retro_light_angle_linear, + obj.data.retro_light_angle_quadratic, + obj.data.retro_light_index) + if obj.data.type == 'SPOT': + buffer += struct.pack('>f', cutoff) + + elif obj.retro_widget_type == 'RETRO_IMGP': + if obj.type != 'MESH': + raise RuntimeException('Imagepane Widget must be a MESH') + if len(obj.data.loops) < 4: + raise RuntimeException('Imagepane Widget must be a MESH with 4 verts') + if len(obj.data.uv_layers) < 1: + raise RuntimeException('Imagepane Widget must ba a MESH with a UV layer') + path_hash = 0xffffffff + if len(obj.data.materials): + material = obj.data.materials[0] + if 'Image Texture' in material.node_tree.nodes: + image_node = material.node_tree.nodes['Image Texture'] + if image_node.image: + image = image_node.image + path = bpy.path.abspath(image.filepath) + path_hash = path_hasher.hashpath32(path) + + buffer += struct.pack('>IIII', path_hash, 0, 0, 4) + for i in range(4): + vi = obj.data.loops[i].vertex_index + co = obj.data.vertices[vi].co + buffer += struct.pack('>fff', co[0], co[1], co[2]) + + buffer += struct.pack('>I', 4) + for i in range(4): + co = obj.data.uv_layers[0].data[i].uv + buffer += struct.pack('>ff', co[0], co[1]) + + if obj.retro_widget_is_worker: + buffer += struct.pack('>bH', True, obj.retro_widget_worker_id) + else: + buffer += struct.pack('>b', False) + + angMtx = angle.to_matrix() @ obj.matrix_local.to_3x3() + buffer += struct.pack('>fffffffffffffffIH', + obj.matrix_local[0][3], + obj.matrix_local[1][3], + obj.matrix_local[2][3], + angMtx[0][0], angMtx[0][1], angMtx[0][2], + angMtx[1][0], angMtx[1][1], angMtx[1][2], + angMtx[2][0], angMtx[2][1], angMtx[2][2], + 0.0, 0.0, 0.0, 0, 0) + + ch_list = [] + for ch in obj.children: + ch_list.append((ch.pass_index, ch.name)) + for s_pair in sorted(ch_list): + ch = bpy.data.objects[s_pair[1]] + if ch.retro_widget_type != 'RETRO_NONE': + recursive_cook(buffer, ch, version, path_hasher, obj.name) + + +def cook(writepipebuf, version, path_hasher): + global hjustifications, vjustifications, model_draw_flags_e + hjustifications = dict((i[0], i[3]) for i in bpy.types.Object.retro_textpane_hjustification[1]['items']) + vjustifications = dict((i[0], i[3]) for i in bpy.types.Object.retro_textpane_vjustification[1]['items']) + model_draw_flags_e = dict((i[0], i[3]) for i in bpy.types.Object.retro_widget_model_draw_flags[1]['items']) + + buffer = bytearray() + buffer += struct.pack('>IIII', 0, 0, 0, 0) + + widget_count = 0 + for obj in bpy.data.objects: + if obj.retro_widget_type != 'RETRO_NONE': + widget_count += 1 + buffer += struct.pack('>I', widget_count) + + for obj in bpy.data.objects: + if obj.retro_widget_type != 'RETRO_NONE' and not obj.parent: + recursive_cook(buffer, obj, version, path_hasher, 'kGSYS_DummyWidgetID') + + return buffer + + +# Registration +def register(): + frame_widget_types = [ + ('RETRO_NONE', 'Not a Widget', '', 0), + ('RETRO_BWIG', 'Base Widget', '', 1), + ('RETRO_CAMR', 'Camera', '', 2), + ('RETRO_ENRG', 'Energy Bar', '', 3), + ('RETRO_GRUP', 'Group', '', 4), + ('RETRO_HWIG', 'Head Widget', '', 5), + ('RETRO_IMGP', 'Image Pane', '', 6), + ('RETRO_LITE', 'Light', '', 7), + ('RETRO_MODL', 'Model', '', 8), + ('RETRO_METR', 'Meter', '', 9), + ('RETRO_PANE', 'Pane', '', 10), + ('RETRO_SLGP', 'Slider Group', '', 11), + ('RETRO_TBGP', 'Table Group', '', 12), + ('RETRO_TXPN', 'Text Pane', '', 13)] + bpy.types.Object.retro_widget_type = bpy.props.EnumProperty(items=frame_widget_types, name='Retro: FRME Widget Type', default='RETRO_NONE') + model_draw_flags = [ + ('RETRO_SHADELESS', 'Shadeless', '', 0), + ('RETRO_OPAQUE', 'Opaque', '', 1), + ('RETRO_ALPHA', 'Alpha', '', 2), + ('RETRO_ADDITIVE', 'Additive', '', 3), + ('RETRO_ALPHA_ADDITIVE_OVERDRAW', 'Alpha Additive Overdraw', '', 4)] + bpy.types.Object.retro_widget_parent = bpy.props.StringProperty(name='Retro: FRME Widget Parent', description='Refers to internal frame widgets') + bpy.types.Object.retro_widget_use_anim_controller = bpy.props.BoolProperty(name='Retro: Use Animiation Conroller') + bpy.types.Object.retro_widget_default_visible = bpy.props.BoolProperty(name='Retro: Default Visible', description='Sets widget is visible by default') + bpy.types.Object.retro_widget_default_active = bpy.props.BoolProperty(name='Retro: Default Active', description='Sets widget is cases by default') + bpy.types.Object.retro_widget_cull_faces = bpy.props.BoolProperty(name='Retro: Cull Faces', description='Enables face culling') + bpy.types.Object.retro_widget_color = bpy.props.FloatVectorProperty(name='Retro: Color', description='Sets widget color', subtype='COLOR', size=4, min=0.0, max=1.0) + bpy.types.Object.retro_widget_model_draw_flags = bpy.props.EnumProperty(items=model_draw_flags, name='Retro: Model Draw Flags', default='RETRO_ALPHA') + bpy.types.Object.retro_widget_is_worker = bpy.props.BoolProperty(name='Retro: Is Worker Widget', default=False) + bpy.types.Object.retro_widget_worker_id = bpy.props.IntProperty(name='Retro: Worker Widget ID', min=0, default=0) + + bpy.types.Object.retro_model_light_mask = bpy.props.IntProperty(name='Retro: Model Light Mask', min=0, default=0) + + bpy.types.Object.retro_pane_dimensions = bpy.props.FloatVectorProperty(name='Retro: Pane Dimensions', min=0.0, size=2) + bpy.types.Object.retro_pane_scale_center = bpy.props.FloatVectorProperty(name='Retro: Scale Center', size=3) + + bpy.types.Object.retro_textpane_font_path = bpy.props.StringProperty(name='Retro: Font Path') + bpy.types.Object.retro_textpane_word_wrap = bpy.props.BoolProperty(name='Retro: Word Wrap') + bpy.types.Object.retro_textpane_horizontal = bpy.props.BoolProperty(name='Retro: Horizontal', default=True) + bpy.types.Object.retro_textpane_fill_color = bpy.props.FloatVectorProperty(name='Retro: Fill Color', min=0.0, max=1.0, size=4, subtype='COLOR') + bpy.types.Object.retro_textpane_outline_color = bpy.props.FloatVectorProperty(name='Retro: Outline Color', min=0.0, max=1.0, size=4, subtype='COLOR') + bpy.types.Object.retro_textpane_block_extent = bpy.props.FloatVectorProperty(name='Retro: Block Extent', min=0.0, size=2) + bpy.types.Object.retro_textpane_jp_font_path = bpy.props.StringProperty(name='Retro: Japanese Font Path') + bpy.types.Object.retro_textpane_jp_font_scale = bpy.props.IntVectorProperty(name='Retro: Japanese Font Scale', min=0, size=2) + frame_textpane_hjustifications = [ + ('LEFT', 'Left', '', 0), + ('CENTER', 'Center', '', 1), + ('RIGHT', 'Right', '', 2), + ('FULL', 'Full', '', 3), + ('NLEFT', 'Left Normalized', '', 4), + ('NCENTER', 'Center Normalized', '', 5), + ('NRIGHT', 'Right Normalized', '', 6), + ('LEFTMONO', 'Left Monospaced', '', 7), + ('CENTERMONO', 'Center Monospaced', '', 8), + ('RIGHTMONO', 'Right Monospaced', '', 9)] + bpy.types.Object.retro_textpane_hjustification = bpy.props.EnumProperty(items=frame_textpane_hjustifications, name='Retro: Horizontal Justification', default='LEFT') + frame_textpane_vjustifications = [ + ('TOP', 'Top', '', 0), + ('CENTER', 'Center', '', 1), + ('BOTTOM', 'Bottom', '', 2), + ('FULL', 'Full', '', 3), + ('NTOP', 'Top Normalized', '', 4), + ('NCENTER', 'Center Normalized', '', 5), + ('NBOTTOM', 'Bottom Normalized', '', 6), + ('TOPMONO', 'Top Monospaced', '', 7), + ('CENTERMONO', 'Center Monospaced', '', 8), + ('BOTTOMMONO', 'Bottom Monospaced', '', 9)] + bpy.types.Object.retro_textpane_vjustification = bpy.props.EnumProperty(items=frame_textpane_vjustifications, name='Retro: Vertical Justification', default='TOP') + + bpy.types.Object.retro_tablegroup_elem_count = bpy.props.IntProperty(name='Retro: Table Group Element Count', min=0, default=0) + bpy.types.Object.retro_tablegroup_elem_default = bpy.props.IntProperty(name='Retro: Table Group Default Element', min=0, default=0) + bpy.types.Object.retro_tablegroup_wraparound = bpy.props.BoolProperty(name='Retro: Table Group Wraparound', default=False) + + bpy.types.Object.retro_group_default_worker = bpy.props.IntProperty(name='Retro: Group Default Worker', min=0, default=0) + + bpy.types.Object.retro_slider_min = bpy.props.FloatProperty(name='Retro: Slider Min', default=0.0) + bpy.types.Object.retro_slider_max = bpy.props.FloatProperty(name='Retro: Slider Max', default=1.0) + bpy.types.Object.retro_slider_default = bpy.props.FloatProperty(name='Retro: Slider Default', default=0.0) + bpy.types.Object.retro_slider_increment = bpy.props.FloatProperty(name='Retro: Slider Increment', min=0.0, default=1.0) + + bpy.types.Object.retro_energybar_texture_path = bpy.props.StringProperty(name='Retro: Energy Bar Texture Path') + + bpy.types.Object.retro_meter_no_round_up = bpy.props.BoolProperty(name='Retro: No Round Up', default=True) + bpy.types.Object.retro_meter_max_capacity = bpy.props.IntProperty(name='Retro: Max Capacity', min=0, default=100) + bpy.types.Object.retro_meter_worker_count = bpy.props.IntProperty(name='Retro: Worker Count', min=0, default=1) + + bpy.types.Light.retro_light_index = bpy.props.IntProperty(name='Retro: Light Index', min=0, default=0) + bpy.types.Light.retro_light_angle_constant = bpy.props.FloatProperty(name='Retro: Light Angle Constant', min=0.0, default=0.0) + bpy.types.Light.retro_light_angle_linear = bpy.props.FloatProperty(name='Retro: Light Angle Linear', min=0.0, default=0.0) + bpy.types.Light.retro_light_angle_quadratic = bpy.props.FloatProperty(name='Retro: Light Angle Quadratic', min=0.0, default=0.0) + diff --git a/hecl/blender/hecl/hmdl/HMDLMesh.py b/hecl/blender/hecl/hmdl/HMDLMesh.py new file mode 100644 index 000000000..612f43798 --- /dev/null +++ b/hecl/blender/hecl/hmdl/HMDLMesh.py @@ -0,0 +1,100 @@ +import bpy, bmesh, operator, struct + +# Function to quantize normals to 15-bit precision +def quant_norm(n): + nf = n.copy() + for i in range(3): + nf[i] = int(nf[i] * 16384) / 16384.0 + return nf.freeze() + +# Function to quantize lightmap UVs to 15-bit precision +def quant_luv(n): + uf = n.copy() + for i in range(2): + uf[i] = int(uf[i] * 32768) / 32768.0 + return uf.freeze() + +# Function to output all mesh attribute values +def write_mesh_attrs(writebuf, bm, rna_loops, use_luv, material_slots): + dlay = None + if len(bm.verts.layers.deform): + dlay = bm.verts.layers.deform[0] + + clays = [] + for cl in range(len(bm.loops.layers.color)): + clays.append(bm.loops.layers.color[cl]) + writebuf(struct.pack('I', len(clays))) + + luvlay = None + if use_luv: + luvlay = bm.loops.layers.uv[0] + ulays = [] + for ul in range(len(bm.loops.layers.uv)): + ulays.append(bm.loops.layers.uv[ul]) + writebuf(struct.pack('I', len(ulays))) + + # Verts + writebuf(struct.pack('I', len(bm.verts))) + for v in bm.verts: + writebuf(struct.pack('fff', v.co[0], v.co[1], v.co[2])) + if dlay: + sf = tuple(sorted(v[dlay].items())) + writebuf(struct.pack('I', len(sf))) + total_len = 0.0 + for ent in sf: + total_len += ent[1] + for ent in sf: + writebuf(struct.pack('If', ent[0], ent[1] / total_len)) + else: + writebuf(struct.pack('I', 0)) + + # Loops + loop_count = 0 + for f in bm.faces: + for l in f.loops: + loop_count += 1 + writebuf(struct.pack('I', loop_count)) + for f in bm.faces: + for l in f.loops: + if rna_loops: + nf = quant_norm(rna_loops[l.index].normal) + else: + nf = quant_norm(l.vert.normal) + writebuf(struct.pack('fff', nf[0], nf[1], nf[2])) + for cl in range(len(clays)): + col = l[clays[cl]] + writebuf(struct.pack('fff', col[0], col[1], col[2])) + for cl in range(len(ulays)): + if luvlay and cl == 0 and material_slots[l.face.material_index].material['retro_lightmapped']: + uv = quant_luv(l[luvlay].uv) + else: + uv = l[ulays[cl]].uv + writebuf(struct.pack('ff', uv[0], uv[1])) + writebuf(struct.pack('IIIII', l.vert.index, l.edge.index, l.face.index, + l.link_loop_next.index, l.link_loop_prev.index)) + if l.edge.is_contiguous: + writebuf(struct.pack('II', l.link_loop_radial_next.index, l.link_loop_radial_prev.index)) + else: + writebuf(struct.pack('II', 0xffffffff, 0xffffffff)) + + # Edges + writebuf(struct.pack('I', len(bm.edges))) + for e in bm.edges: + for v in e.verts: + writebuf(struct.pack('I', v.index)) + writebuf(struct.pack('I', len(e.link_faces))) + for f in e.link_faces: + writebuf(struct.pack('I', f.index)) + writebuf(struct.pack('b', e.is_contiguous)) + + # Faces + writebuf(struct.pack('I', len(bm.faces))) + for f in bm.faces: + norm = f.normal + writebuf(struct.pack('fff', norm[0], norm[1], norm[2])) + centroid = f.calc_center_bounds() + writebuf(struct.pack('fff', centroid[0], centroid[1], centroid[2])) + writebuf(struct.pack('I', f.material_index)) + for l in f.loops: + writebuf(struct.pack('I', l.index)) + diff --git a/hecl/blender/hecl/hmdl/HMDLShader.py b/hecl/blender/hecl/hmdl/HMDLShader.py new file mode 100644 index 000000000..d21ec085a --- /dev/null +++ b/hecl/blender/hecl/hmdl/HMDLShader.py @@ -0,0 +1,164 @@ +import bpy, bpy.path, os.path, struct + +def get_texture_path(image): + return os.path.normpath(bpy.path.abspath(image.filepath)) + +SHADER_TYPES = { + 'RetroShader': b'RSHD', + 'RetroDynamicShader': b'RDYN', + 'RetroDynamicAlphaShader': b'RDAL', + 'RetroDynamicCharacterShader': b'RCHR', +} + +PASS_TYPE = { + 'Lightmap': b'LMAP', + 'Diffuse': b'DIFF', + 'DiffuseMod': b'DIFM', + 'Emissive': b'EMIS', + 'Specular': b'SPEC', + 'ExtendedSpecular': b'ESPC', + 'Reflection': b'REFL', + 'IndirectTex': b'INDR', + 'Alpha': b'ALPH', + 'AlphaMod': b'ALPM' +} + +def write_chunks(writebuf, mat_obj, mesh_obj): + + if not mat_obj.use_nodes: + raise RuntimeError("HMDL *requires* that shader nodes are used; '{0}' does not".format(mat_obj.name)) + + if 'Output' not in mat_obj.node_tree.nodes or mat_obj.node_tree.nodes['Output'].type != 'GROUP': + raise RuntimeError("HMDL *requires* that an group shader node named 'Output' is present") + + # Root (output) node + output_node = mat_obj.node_tree.nodes['Output'] + if output_node.node_tree.name not in SHADER_TYPES: + raise RuntimeError("HMDL *requires* one of the RetroShader group nodes for the 'Output' node") + writebuf(SHADER_TYPES[output_node.node_tree.name]) + + # Count sockets + chunk_count = 0 + for inp, def_inp in zip(output_node.inputs, output_node.node_tree.inputs): + if inp.name in PASS_TYPE: + if inp.is_linked: + chunk_count += 1 + else: + # Color pass + color_set = False + if inp.type == 'VALUE': + color_set = inp.default_value != def_inp.default_value + else: + for comp, def_comp in zip(inp.default_value, def_inp.default_value): + color_set |= comp != def_comp + if color_set: + chunk_count += 1 + + writebuf(struct.pack('I', chunk_count)) + + # Enumerate sockets + for inp, def_inp in zip(output_node.inputs, output_node.node_tree.inputs): + if inp.name in PASS_TYPE: + pass_fourcc = PASS_TYPE[inp.name] + if inp.is_linked: + socket = inp.links[0].from_socket + node = socket.node + if node.type != 'TEX_IMAGE': + raise RuntimeError("HMDL requires all group node inputs connect to Image Texture nodes") + + if not node.image: + raise RuntimeError("HMDL texture nodes must specify an image object") + + if not node.inputs['Vector'].is_linked: + raise RuntimeError("HMDL texture nodes must have a 'Texture Coordinate', 'UV Map' or 'Group' UV modifier node linked") + + # Determine matrix generator type + tex_coord_source = 0xff + uv_anim_type = 0xff + uv_anim_args = [] + soc_from = node.inputs['Vector'].links[0].from_socket + + if soc_from.node.type == 'GROUP': + if soc_from.node.node_tree.name.startswith('RetroUVMode'): + uv_anim_type = int(soc_from.node.node_tree.name[11:12]) + if len(soc_from.node.inputs)-1: + for s in range(len(soc_from.node.inputs)-1): + soc = soc_from.node.inputs[s+1] + if len(soc.links): + raise RuntimeError("UV Modifier nodes may not have parameter links (default values only)") + if soc.type == 'VALUE': + uv_anim_args.append(soc.default_value) + else: + uv_anim_args.append(soc.default_value[0]) + uv_anim_args.append(soc.default_value[1]) + soc_from = soc_from.node.inputs[0].links[0].from_socket + + elif soc_from.node.type == 'UVMAP' or soc_from.node.type == 'TEX_COORD': + pass + + else: + raise RuntimeError("HMDL texture nodes must have a 'Texture Coordinate', 'UV Map' or 'Group' UV modifier node linked") + + if soc_from.node.type != 'UVMAP' and soc_from.node.type != 'TEX_COORD': + raise RuntimeError("Matrix animator nodes must connect to 'Texture Coordinate' or 'UV Map' node") + + + # Resolve map and matrix index + node_label = soc_from.node.label + matrix_idx = None + if node_label.startswith('MTX_'): + matrix_idx = int(node_label[4:]) + + if soc_from.name == 'UV': + if hasattr(soc_from.node, 'uv_map'): + uv_name = soc_from.node.uv_map + uv_idx = mesh_obj.data.uv_layers.find(uv_name) + if uv_idx == -1: + raise RuntimeError('UV Layer "%s" doesn\'t exist' % uv_name) + tex_coord_source = uv_idx + 2 + else: + tex_coord_source = 2 + + elif soc_from.name == 'Normal': + tex_coord_source = 1 + + elif soc_from.name == 'Window': + tex_coord_source = 0 + + else: + raise RuntimeError("Only the 'UV', 'Normal' and 'Window' sockets may be used from 'Texture Coordinate' nodes") + + alpha = False + if socket.name == 'Alpha': + alpha = True + + writebuf(b'PASS') + writebuf(pass_fourcc) + path = get_texture_path(node.image) + writebuf(struct.pack('I', len(path))) + writebuf(path.encode()) + writebuf(struct.pack('B', tex_coord_source)) + writebuf(struct.pack('B', uv_anim_type)) + writebuf(struct.pack('I', len(uv_anim_args))) + for arg in uv_anim_args: + writebuf(struct.pack('f', arg)) + writebuf(struct.pack('B', alpha)) + + else: + # Color pass + color_set = False + if inp.type == 'VALUE': + color_set = inp.default_value != def_inp.default_value + else: + for comp, def_comp in zip(inp.default_value, def_inp.default_value): + color_set |= comp != def_comp + + if color_set: + writebuf(b'CLR ') + writebuf(pass_fourcc) + if inp.type == 'VALUE': + writebuf(struct.pack('ffff', inp.default_value, inp.default_value, + inp.default_value, inp.default_value)) + else: + writebuf(struct.pack('ffff', inp.default_value[0], inp.default_value[1], + inp.default_value[2], inp.default_value[3])) diff --git a/hecl/blender/hecl/hmdl/__init__.py b/hecl/blender/hecl/hmdl/__init__.py new file mode 100644 index 000000000..ae765b416 --- /dev/null +++ b/hecl/blender/hecl/hmdl/__init__.py @@ -0,0 +1,312 @@ +import struct, bpy, bmesh +from . import HMDLShader, HMDLMesh + +BLEND_TYPES = { + 'HECLAdditiveOutput': 2, + 'HECLBlendOutput': 1, + 'HECLOpaqueOutput': 0, +} + +def write_out_material(writebuf, mat, mesh_obj): + writebuf(struct.pack('I', len(mat.name))) + writebuf(mat.name.encode()) + + writebuf(struct.pack('I', mat.pass_index)) + + HMDLShader.write_chunks(writebuf, mat, mesh_obj) + + prop_count = 0 + for prop in mat.items(): + if isinstance(prop[1], int): + prop_count += 1 + writebuf(struct.pack('I', prop_count)) + for prop in mat.items(): + if isinstance(prop[1], int): + writebuf(struct.pack('I', len(prop[0]))) + writebuf(prop[0].encode()) + writebuf(struct.pack('i', prop[1])) + + blend_node = mat.node_tree.nodes['Blend'] + if blend_node.node_tree.name not in BLEND_TYPES: + raise RuntimeError("HMDL *requires* one of the HMDL*Output group nodes for the 'Blend' node") + writebuf(struct.pack('I', BLEND_TYPES[blend_node.node_tree.name])) + +# Takes a Blender 'Mesh' object (not the datablock) +# and performs a one-shot conversion process to HMDL +def cook(writebuf, mesh_obj, use_luv=False): + if mesh_obj.type != 'MESH': + raise RuntimeError("%s is not a mesh" % mesh_obj.name) + + # Copy mesh (and apply mesh modifiers with triangulation) + copy_name = mesh_obj.name + "_hmdltri" + copy_mesh = bpy.data.meshes.new_from_object(mesh_obj, preserve_all_data_layers=True, + depsgraph=bpy.context.evaluated_depsgraph_get()) + copy_obj = bpy.data.objects.new(copy_name, copy_mesh) + copy_obj.scale = mesh_obj.scale + bpy.context.scene.collection.objects.link(copy_obj) + bpy.ops.object.select_all(action='DESELECT') + bpy.context.view_layer.objects.active = copy_obj + copy_obj.select_set(True) + bpy.ops.object.mode_set(mode='EDIT') + bpy.ops.mesh.select_all(action='SELECT') + bpy.ops.mesh.quads_convert_to_tris() + bpy.ops.mesh.select_all(action='DESELECT') + bpy.context.scene.update_tag() + bpy.ops.object.mode_set(mode='OBJECT') + copy_mesh.calc_normals_split() + rna_loops = copy_mesh.loops + + # Send scene matrix + wmtx = mesh_obj.matrix_world + writebuf(struct.pack('ffffffffffffffff', + wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3], + wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3], + wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3], + wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3])) + + # Filter out useless AABB points and send data + pt = copy_obj.bound_box[0] + writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) + pt = copy_obj.bound_box[6] + writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) + + # Create master BMesh + bm_master = bmesh.new() + bm_master.from_mesh(copy_mesh) + + # Generate shaders + if mesh_obj.data.hecl_material_count > 0: + writebuf(struct.pack('I', mesh_obj.data.hecl_material_count)) + for grp_idx in range(mesh_obj.data.hecl_material_count): + writebuf(struct.pack('I', len(mesh_obj.data.materials))) + for ref_mat in mesh_obj.data.materials: + ref_mat_split = ref_mat.name.split('_') + if len(ref_mat_split) != 3: + raise RuntimeError('material names must follow MAT_%u_%u format') + ref_mat_idx = int(ref_mat_split[2]) + found = False + for mat in bpy.data.materials: + if mat.name.endswith('_%u_%u' % (grp_idx, ref_mat_idx)): + write_out_material(writebuf, mat, mesh_obj) + found = True + break + if not found: + raise RuntimeError('uneven material set %d in %s' % (grp_idx, mesh_obj.name)) + else: + writebuf(struct.pack('II', 1, len(mesh_obj.data.materials))) + for mat in mesh_obj.data.materials: + write_out_material(writebuf, mat, mesh_obj) + + # Output attribute lists + HMDLMesh.write_mesh_attrs(writebuf, bm_master, rna_loops, use_luv, mesh_obj.material_slots) + + # Vertex groups + writebuf(struct.pack('I', len(mesh_obj.vertex_groups))) + for vgrp in mesh_obj.vertex_groups: + writebuf(struct.pack('I', len(vgrp.name))) + writebuf(vgrp.name.encode()) + + # Enumerate custom props + writebuf(struct.pack('I', len(mesh_obj.keys()))) + for k in mesh_obj.keys(): + writebuf(struct.pack('I', len(k))) + writebuf(k.encode()) + val_str = str(mesh_obj[k]) + writebuf(struct.pack('I', len(val_str))) + writebuf(val_str.encode()) + + # Delete copied mesh from scene + bm_master.free() + #bpy.context.scene.objects.unlink(copy_obj) + bpy.data.objects.remove(copy_obj) + bpy.data.meshes.remove(copy_mesh) + +def prop_val_from_colmat(name, m): + if name in m: + return m[name] + + return False + +# Takes a Blender 'Mesh' object (not the datablock) +# and performs a one-shot conversion process to collision geometry +def cookcol(writebuf, mesh_obj): + if mesh_obj.type != 'MESH': + raise RuntimeError("%s is not a mesh" % mesh_obj.name) + + # Copy mesh (and apply mesh modifiers with triangulation) + copy_name = mesh_obj.name + "_hmdltri" + copy_mesh = bpy.data.meshes.new_from_object(mesh_obj, preserve_all_data_layers=True, + depsgraph=bpy.context.evaluated_depsgraph_get()) + copy_obj = bpy.data.objects.new(copy_name, copy_mesh) + copy_obj.scale = mesh_obj.scale + bpy.context.scene.collection.objects.link(copy_obj) + bpy.ops.object.select_all(action='DESELECT') + bpy.context.view_layer.objects.active = copy_obj + copy_obj.select_set(True) + bpy.ops.object.mode_set(mode='EDIT') + bpy.ops.mesh.select_all(action='SELECT') + bpy.ops.mesh.quads_convert_to_tris() + bpy.ops.mesh.select_all(action='DESELECT') + bpy.context.scene.update_tag() + bpy.ops.object.mode_set(mode='OBJECT') + copy_mesh.calc_normals_split() + rna_loops = copy_mesh.loops + + # Send scene matrix + wmtx = mesh_obj.matrix_world + #writebuf(struct.pack('ffffffffffffffff', + #wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3], + #wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3], + #wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3], + #wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3])) + + # Filter out useless AABB points and send data + #pt = wmtx * Vector(copy_obj.bound_box[0]) + #writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) + #pt = wmtx * Vector(copy_obj.bound_box[6]) + #writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) + + # Send materials + writebuf(struct.pack('I', len(copy_mesh.materials))) + for m in copy_mesh.materials: + writebuf(struct.pack('I', len(m.name))) + writebuf(m.name.encode()) + unknown = prop_val_from_colmat('retro_unknown', m) + surfaceStone = prop_val_from_colmat('retro_surface_stone', m) + surfaceMetal = prop_val_from_colmat('retro_surface_metal', m) + surfaceGrass = prop_val_from_colmat('retro_surface_grass', m) + surfaceIce = prop_val_from_colmat('retro_surface_ice', m) + pillar = prop_val_from_colmat('retro_pillar', m) + surfaceMetalGrating = prop_val_from_colmat('retro_surface_metal_grating', m) + surfacePhazon = prop_val_from_colmat('retro_surface_phazon', m) + surfaceDirt = prop_val_from_colmat('retro_surface_dirt', m) + surfaceLava = prop_val_from_colmat('retro_surface_lava', m) + surfaceSPMetal = prop_val_from_colmat('retro_surface_sp_metal', m) + surfaceStoneRock = prop_val_from_colmat('retro_surface_lava_stone', m) + surfaceSnow = prop_val_from_colmat('retro_surface_snow', m) + surfaceMudSlow = prop_val_from_colmat('retro_surface_mud_slow', m) + surfaceFabric = prop_val_from_colmat('retro_surface_fabric', m) + halfPipe = prop_val_from_colmat('retro_half_pipe', m) + surfaceMud = prop_val_from_colmat('retro_surface_mud', m) + surfaceGlass = prop_val_from_colmat('retro_surface_glass', m) + unused3 = prop_val_from_colmat('retro_unused3', m) + unused4 = prop_val_from_colmat('retro_unused4', m) + surfaceShield = prop_val_from_colmat('retro_surface_shield', m) + surfaceSand = prop_val_from_colmat('retro_surface_sand', m) + surfaceMothOrSeedOrganics = prop_val_from_colmat('retro_surface_moth_or_seed_organics', m) + surfaceWeb = prop_val_from_colmat('retro_surface_web', m) + projPassthrough = prop_val_from_colmat('retro_projectile_passthrough', m) + solid = prop_val_from_colmat('retro_solid', m) + noPlatformCollision = prop_val_from_colmat('retro_no_platform_collision', m) + camPassthrough = prop_val_from_colmat('retro_camera_passthrough', m) + surfaceWood = prop_val_from_colmat('retro_surface_wood', m) + surfaceOrganic = prop_val_from_colmat('retro_surface_organic', m) + noEdgeCollision = prop_val_from_colmat('retro_no_edge_collision', m) + surfaceRubber = prop_val_from_colmat('retro_surface_rubber', m) + seeThrough = prop_val_from_colmat('retro_see_through', m) + scanPassthrough = prop_val_from_colmat('retro_scan_passthrough', m) + aiPassthrough = prop_val_from_colmat('retro_ai_passthrough', m) + ceiling = prop_val_from_colmat('retro_ceiling', m) + wall = prop_val_from_colmat('retro_wall', m) + floor = prop_val_from_colmat('retro_floor', m) + aiBlock = prop_val_from_colmat('retro_ai_block', m) + jumpNotAllowed = prop_val_from_colmat('retro_jump_not_allowed', m) + spiderBall = prop_val_from_colmat('retro_spider_ball', m) + screwAttackWallJump = prop_val_from_colmat('retro_screw_attack_wall_jump', m) + + writebuf(struct.pack('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', unknown, surfaceStone, surfaceMetal, surfaceGrass, + surfaceIce, pillar, surfaceMetalGrating, surfacePhazon, surfaceDirt, surfaceLava, surfaceSPMetal, + surfaceStoneRock, surfaceSnow, surfaceMudSlow, surfaceFabric, halfPipe, surfaceMud, surfaceGlass, + unused3, unused4, surfaceShield, surfaceSand, surfaceMothOrSeedOrganics, surfaceWeb, projPassthrough, + solid, noPlatformCollision, camPassthrough, surfaceWood, surfaceOrganic, noEdgeCollision, surfaceRubber, + seeThrough, scanPassthrough, aiPassthrough, ceiling, wall, floor, aiBlock, jumpNotAllowed, spiderBall, + screwAttackWallJump)) + + # Send verts + writebuf(struct.pack('I', len(copy_mesh.vertices))) + for v in copy_mesh.vertices: + xfVert = wmtx @ v.co + writebuf(struct.pack('fff', xfVert[0], xfVert[1], xfVert[2])) + + # Send edges + writebuf(struct.pack('I', len(copy_mesh.edges))) + for e in copy_mesh.edges: + writebuf(struct.pack('IIb', e.vertices[0], e.vertices[1], e.use_seam)) + + # Send trianges + writebuf(struct.pack('I', len(copy_mesh.polygons))) + for p in copy_mesh.polygons: + edge_idxs = [] + for loopi in p.loop_indices: + edge_idxs.append(copy_mesh.loops[loopi].edge_index) + l0 = copy_mesh.loops[p.loop_indices[0]] + e0 = copy_mesh.edges[l0.edge_index] + flip = l0.vertex_index != e0.vertices[0] + writebuf(struct.pack('IIIIb', edge_idxs[0], edge_idxs[1], edge_idxs[2], p.material_index, flip)) + + # Delete copied mesh from scene + #bpy.context.scene.objects.unlink(copy_obj) + bpy.data.objects.remove(copy_obj) + bpy.data.meshes.remove(copy_mesh) + + +def draw(layout, context): + layout.prop_search(context.scene, 'hecl_mesh_obj', context.scene, 'objects') + if not len(context.scene.hecl_mesh_obj): + layout.label(text="Mesh not specified", icon='ERROR') + elif context.scene.hecl_mesh_obj not in context.scene.objects: + layout.label(text="'"+context.scene.hecl_mesh_obj+"' not in scene", icon='ERROR') + else: + obj = context.scene.objects[context.scene.hecl_mesh_obj] + if obj.type != 'MESH': + layout.label(text="'"+context.scene.hecl_mesh_obj+"' not a 'MESH'", icon='ERROR') + layout.prop(obj.data, 'cskr_id') + layout.prop(obj.data, 'hecl_active_material') + layout.prop(obj.data, 'hecl_material_count') + +# Material update +def material_update(self, context): + target_idx = self.hecl_active_material + if target_idx >= self.hecl_material_count or target_idx < 0: + return + slot_count = len(self.materials) + for mat_idx in range(slot_count): + for mat in bpy.data.materials: + if mat.name.endswith('_%u_%u' % (target_idx, mat_idx)): + self.materials[mat_idx] = mat + + +def fake_writebuf(by): + pass + +# DEBUG operator +import bpy +class hecl_mesh_operator(bpy.types.Operator): + bl_idname = "scene.hecl_mesh" + bl_label = "DEBUG HECL mesh maker" + bl_description = "Test mesh generation utility" + + @classmethod + def poll(cls, context): + return context.object and context.object.type == 'MESH' + + def execute(self, context): + cook(fake_writebuf, context.object, -1) + return {'FINISHED'} + +import bpy +def register(): + bpy.types.Scene.hecl_mesh_obj = bpy.props.StringProperty( + name='HECL Mesh Object', + description='Blender Mesh Object to export during HECL\'s cook process') + bpy.types.Scene.hecl_actor_obj = bpy.props.StringProperty( + name='HECL Actor Object', + description='Blender Empty Object to export during HECL\'s cook process') + bpy.types.Mesh.cskr_id = bpy.props.StringProperty(name='Original CSKR ID') + bpy.types.Mesh.hecl_material_count = bpy.props.IntProperty(name='HECL Material Count', default=0, min=0) + bpy.types.Mesh.hecl_active_material = bpy.props.IntProperty(name='HECL Active Material', default=0, min=0, update=material_update) + bpy.utils.register_class(hecl_mesh_operator) + pass +def unregister(): + bpy.utils.unregister_class(hecl_mesh_operator) + pass diff --git a/hecl/blender/hecl/mapa.py b/hecl/blender/hecl/mapa.py new file mode 100644 index 000000000..1817b5042 --- /dev/null +++ b/hecl/blender/hecl/mapa.py @@ -0,0 +1,460 @@ +import bpy, struct, bmesh, operator +from mathutils import Vector + +# Function to quantize normals to 15-bit precision +def quant_norm(n): + nf = n.copy() + for i in range(3): + nf[i] = int(nf[i] * 16384) / 16384.0 + return nf.freeze() + +# Function to quantize lightmap UVs to 15-bit precision +def quant_luv(n): + uf = n.copy() + for i in range(2): + uf[i] = int(uf[i] * 32768) / 32768.0 + return uf.freeze() + +# Class for building unique sets of vertex attributes for VBO generation +class VertPool: + + # Initialize hash-unique index for each available attribute + def __init__(self, bm, rna_loops, use_luv, material_slots): + self.bm = bm + self.rna_loops = rna_loops + self.material_slots = material_slots + self.pos = {} + self.norm = {} + self.skin = {} + self.color = {} + self.uv = {} + self.luv = {} + self.dlay = None + self.clays = [] + self.ulays = [] + self.luvlay = None + + dlay = None + if len(bm.verts.layers.deform): + dlay = bm.verts.layers.deform[0] + self.dlay = dlay + + clays = [] + for cl in range(len(bm.loops.layers.color)): + clays.append(bm.loops.layers.color[cl]) + self.clays = clays + + luvlay = None + if use_luv: + luvlay = bm.loops.layers.uv[0] + self.luvlay = luvlay + ulays = [] + for ul in range(len(bm.loops.layers.uv)): + ulays.append(bm.loops.layers.uv[ul]) + self.ulays = ulays + + # Per-vert pool attributes + for v in bm.verts: + pf = v.co.copy().freeze() + if pf not in self.pos: + self.pos[pf] = len(self.pos) + if not rna_loops: + nf = quant_norm(v.normal) + if nf not in self.norm: + self.norm[nf] = len(self.norm) + if dlay: + sf = tuple(sorted(v[dlay].items())) + if sf not in self.skin: + self.skin[sf] = len(self.skin) + + # Per-loop pool attributes + for f in bm.faces: + lightmapped = f.material_index < len(material_slots) and \ + material_slots[f.material_index].material['retro_lightmapped'] + for l in f.loops: + if rna_loops: + nf = quant_norm(rna_loops[l.index].normal) + if nf not in self.norm: + self.norm[nf] = len(self.norm) + for cl in range(len(clays)): + cf = l[clays[cl]].copy().freeze() + if cf not in self.color: + self.color[cf] = len(self.color) + start_uvlay = 0 + if use_luv and lightmapped: + start_uvlay = 1 + uf = quant_luv(l[luvlay].uv) + if uf not in self.luv: + self.luv[uf] = len(self.luv) + for ul in range(start_uvlay, len(ulays)): + uf = l[ulays[ul]].uv.copy().freeze() + if uf not in self.uv: + self.uv[uf] = len(self.uv) + + def write_out(self, writebuf, vert_groups): + writebuf(struct.pack('I', len(self.pos))) + for p in sorted(self.pos.items(), key=operator.itemgetter(1)): + writebuf(struct.pack('fff', p[0][0], p[0][1], p[0][2])) + + writebuf(struct.pack('I', len(self.norm))) + for n in sorted(self.norm.items(), key=operator.itemgetter(1)): + writebuf(struct.pack('fff', n[0][0], n[0][1], n[0][2])) + + writebuf(struct.pack('II', len(self.clays), len(self.color))) + for c in sorted(self.color.items(), key=operator.itemgetter(1)): + writebuf(struct.pack('fff', c[0][0], c[0][1], c[0][2])) + + writebuf(struct.pack('II', len(self.ulays), len(self.uv))) + for u in sorted(self.uv.items(), key=operator.itemgetter(1)): + writebuf(struct.pack('ff', u[0][0], u[0][1])) + + luv_count = 0 + if self.luvlay is not None: + luv_count = 1 + writebuf(struct.pack('II', luv_count, len(self.luv))) + for u in sorted(self.luv.items(), key=operator.itemgetter(1)): + writebuf(struct.pack('ff', u[0][0], u[0][1])) + + writebuf(struct.pack('I', len(vert_groups))) + for vgrp in vert_groups: + writebuf(struct.pack('I', len(vgrp.name))) + writebuf(vgrp.name.encode()) + + writebuf(struct.pack('I', len(self.skin))) + for s in sorted(self.skin.items(), key=operator.itemgetter(1)): + entries = s[0] + writebuf(struct.pack('I', len(entries))) + if len(entries): + total_len = 0.0 + for ent in entries: + total_len += ent[1] + for ent in entries: + writebuf(struct.pack('If', ent[0], ent[1] / total_len)) + + def write_out_map(self, writebuf): + writebuf(struct.pack('I', len(self.pos))) + for p in sorted(self.pos.items(), key=operator.itemgetter(1)): + writebuf(struct.pack('fff', p[0][0], p[0][1], p[0][2])) + + def get_pos_idx(self, vert): + pf = vert.co.copy().freeze() + return self.pos[pf] + + def get_norm_idx(self, loop): + if self.rna_loops: + nf = quant_norm(self.rna_loops[loop.index].normal) + else: + nf = quant_norm(loop.vert.normal) + return self.norm[nf] + + def get_skin_idx(self, vert): + if not self.dlay: + return 0 + sf = tuple(sorted(vert[self.dlay].items())) + return self.skin[sf] + + def get_color_idx(self, loop, cidx): + cf = loop[self.clays[cidx]].copy().freeze() + return self.color[cf] + + def get_uv_idx(self, loop, uidx): + if self.luvlay is not None and uidx == 0: + if self.material_slots[loop.face.material_index].material['retro_lightmapped']: + uf = quant_luv(loop[self.luvlay].uv) + return self.luv[uf] + uf = loop[self.ulays[uidx]].uv.copy().freeze() + return self.uv[uf] + + def loops_contiguous(self, la, lb): + if la.vert != lb.vert: + return False + if self.get_norm_idx(la) != self.get_norm_idx(lb): + return False + for cl in range(len(self.clays)): + if self.get_color_idx(la, cl) != self.get_color_idx(lb, cl): + return False + for ul in range(len(self.ulays)): + if self.get_uv_idx(la, ul) != self.get_uv_idx(lb, ul): + return False + return True + + def splitable_edge(self, edge): + if len(edge.link_faces) < 2: + return False + for v in edge.verts: + found = None + for f in edge.link_faces: + for l in f.loops: + if l.vert == v: + if not found: + found = l + break + else: + if not self.loops_contiguous(found, l): + return True + break + return False + + def loop_out(self, writebuf, loop): + writebuf(struct.pack('B', 1)) + writebuf(struct.pack('II', self.get_pos_idx(loop.vert), self.get_norm_idx(loop))) + for cl in range(len(self.clays)): + writebuf(struct.pack('I', self.get_color_idx(loop, cl))) + for ul in range(len(self.ulays)): + writebuf(struct.pack('I', self.get_uv_idx(loop, ul))) + sp = struct.pack('I', self.get_skin_idx(loop.vert)) + writebuf(sp) + + def null_loop_out(self, writebuf): + writebuf(struct.pack('B', 1)) + writebuf(struct.pack('I', 0xffffffff)) + + def loop_out_map(self, writebuf, loop): + writebuf(struct.pack('B', 1)) + writebuf(struct.pack('I', self.get_pos_idx(loop.vert))) + + def vert_out_map(self, writebuf, vert): + writebuf(struct.pack('B', 1)) + writebuf(struct.pack('I', self.get_pos_idx(vert))) + + +def strip_next_loop(prev_loop, out_count): + if out_count & 1: + radial_loop = prev_loop.link_loop_radial_next + loop = radial_loop.link_loop_prev + return loop, loop + else: + radial_loop = prev_loop.link_loop_radial_prev + loop = radial_loop.link_loop_next + return loop.link_loop_next, loop + + +def recursive_faces_islands(list_out, rem_list, face): + if face not in rem_list: + return [] + + list_out.append(face) + rem_list.remove(face) + next_faces = [] + for e in face.edges: + if not e.is_contiguous or e.seam: + continue + for f in e.link_faces: + if f == face: + continue + next_faces.append(f) + return next_faces + +def cook(writebuf, mesh_obj): + if mesh_obj.type != 'MESH': + raise RuntimeError("%s is not a mesh" % mesh_obj.name) + + obj_vismodes = dict((i[0], i[3]) for i in bpy.types.Object.retro_mapobj_vis_mode[1]['items']) + + # Write out visibility type + vis_types = dict((i[0], i[3]) for i in bpy.types.Scene.retro_map_vis_mode[1]['items']) + writebuf(struct.pack('I', vis_types[bpy.context.scene.retro_map_vis_mode])) + + # Copy mesh (and apply mesh modifiers with triangulation) + copy_name = mesh_obj.name + "_hmdltri" + copy_mesh = bpy.data.meshes.new_from_object(mesh_obj, preserve_all_data_layers=True, + depsgraph=bpy.context.evaluated_depsgraph_get()) + copy_obj = bpy.data.objects.new(copy_name, copy_mesh) + copy_obj.scale = mesh_obj.scale + bpy.context.scene.collection.objects.link(copy_obj) + bpy.ops.object.select_all(action='DESELECT') + bpy.context.view_layer.objects.active = copy_obj + copy_obj.select_set(True) + bpy.ops.object.mode_set(mode='EDIT') + bpy.ops.mesh.select_all(action='SELECT') + bpy.ops.mesh.quads_convert_to_tris() + bpy.ops.mesh.select_all(action='DESELECT') + bpy.context.scene.update_tag() + bpy.ops.object.mode_set(mode='OBJECT') + copy_mesh.calc_normals_split() + rna_loops = copy_mesh.loops + + # Create master BMesh and VertPool + bm_master = bmesh.new() + bm_master.from_mesh(copy_obj.data) + vert_pool = VertPool(bm_master, rna_loops, False, mesh_obj.material_slots) + + # Output vert pool + vert_pool.write_out_map(writebuf) + + # Create map surfaces and borders + faces_rem = list(bm_master.faces) + loop_iter = 0 + loop_ranges = [] + while len(faces_rem): + island_faces = [] + faces = [faces_rem[0]] + while len(faces): + next_faces = [] + ret_faces = None + for f in faces: + ret_faces = recursive_faces_islands(island_faces, faces_rem, f) + if ret_faces == False: + break + next_faces.extend(ret_faces) + if ret_faces == False: + break + faces = next_faces + + # island_faces now holds one island (map edge delimited) + prev_loop_emit = None + loop_set = set() + edge_set = set() + out_count = 0 + loop_count = 0 + while len(island_faces): + sel_lists_local = [] + restore_out_count = out_count + for start_face in island_faces: + for l in start_face.loops: + out_count = restore_out_count + island_local = list(island_faces) + if out_count & 1: + prev_loop = l.link_loop_prev + loop = prev_loop.link_loop_prev + sel_list = [l, prev_loop, loop] + prev_loop = loop + else: + prev_loop = l.link_loop_next + loop = prev_loop.link_loop_next + sel_list = [l, prev_loop, loop] + out_count += 3 + island_local.remove(start_face) + while True: + if not prev_loop.edge.is_contiguous or prev_loop.edge.seam: + break + loop, prev_loop = strip_next_loop(prev_loop, out_count) + face = loop.face + if face not in island_local: + break + sel_list.append(loop) + island_local.remove(face) + out_count += 1 + sel_lists_local.append((sel_list, island_local, out_count)) + max_count = 0 + max_sl = None + max_island_faces = None + for sl in sel_lists_local: + if len(sl[0]) > max_count: + max_count = len(sl[0]) + max_sl = sl[0] + max_island_faces = sl[1] + out_count = sl[2] + island_faces = max_island_faces + + if prev_loop_emit: + vert_pool.loop_out_map(writebuf, prev_loop_emit) + vert_pool.loop_out_map(writebuf, max_sl[0]) + loop_count += 2 + loop_set.add(prev_loop_emit) + loop_set.add(max_sl[0]) + loop_count += len(max_sl) + for loop in max_sl: + vert_pool.loop_out_map(writebuf, loop) + prev_loop_emit = loop + loop_set.add(loop) + for edge in loop.face.edges: + if edge.seam: + edge_set.add(edge) + + # Create island surface with edges + if len(edge_set): + trace_edge = edge_set.pop() + else: + trace_edge = None + edge_ranges = [] + edge_iter = loop_iter + loop_count + while trace_edge: + edge_count = 0 + vert_pool.vert_out_map(writebuf, trace_edge.verts[0]) + vert_pool.vert_out_map(writebuf, trace_edge.verts[1]) + edge_count += 2 + next_vert = trace_edge.verts[1] + found_edge = True + while found_edge: + found_edge = False + for edge in next_vert.link_edges: + if edge in edge_set: + edge_set.remove(edge) + next_vert = edge.other_vert(next_vert) + vert_pool.vert_out_map(writebuf, next_vert) + edge_count += 1 + found_edge = True + break + if len(edge_set): + trace_edge = edge_set.pop() + else: + trace_edge = None + edge_ranges.append((edge_iter, edge_count)) + edge_iter += edge_count + + pos_avg = Vector() + norm_avg = Vector() + if len(loop_set): + for loop in loop_set: + pos_avg += loop.vert.co + norm_avg += loop.vert.normal + pos_avg /= len(loop_set) + norm_avg /= len(loop_set) + norm_avg.normalize() + + loop_ranges.append((loop_iter, loop_count, edge_ranges, pos_avg, norm_avg)) + loop_iter = edge_iter + + # No more surfaces + writebuf(struct.pack('B', 0)) + + # Write out loop ranges and averages + writebuf(struct.pack('I', len(loop_ranges))) + for loop_range in loop_ranges: + writebuf(struct.pack('fff', loop_range[3][0], loop_range[3][1], loop_range[3][2])) + writebuf(struct.pack('fff', loop_range[4][0], loop_range[4][1], loop_range[4][2])) + writebuf(struct.pack('II', loop_range[0], loop_range[1])) + writebuf(struct.pack('I', len(loop_range[2]))) + for edge_range in loop_range[2]: + writebuf(struct.pack('II', edge_range[0], edge_range[1])) + + # Write out mappable objects + poi_count = 0 + for obj in bpy.context.scene.objects: + if obj.retro_mappable_type != -1: + poi_count += 1 + + writebuf(struct.pack('I', poi_count)) + for obj in bpy.context.scene.objects: + if obj.retro_mappable_type != -1: + writebuf(struct.pack('III', + obj.retro_mappable_type, obj_vismodes[obj.retro_mapobj_vis_mode], int(obj.retro_mappable_sclyid, 0))) + writebuf(struct.pack('ffffffffffffffff', + obj.matrix_world[0][0], obj.matrix_world[0][1], obj.matrix_world[0][2], obj.matrix_world[0][3], + obj.matrix_world[1][0], obj.matrix_world[1][1], obj.matrix_world[1][2], obj.matrix_world[1][3], + obj.matrix_world[2][0], obj.matrix_world[2][1], obj.matrix_world[2][2], obj.matrix_world[2][3], + obj.matrix_world[3][0], obj.matrix_world[3][1], obj.matrix_world[3][2], obj.matrix_world[3][3])) + +def draw(layout, context): + obj = context.active_object + layout.prop(context.scene, 'retro_map_vis_mode', text='Visibility Mode') + if obj and obj.retro_mappable_type != -1: + layout.prop(obj, 'retro_mappable_type', text='Object Type') + layout.prop(obj, 'retro_mapobj_vis_mode', text='Object Visibility Mode') + layout.prop(obj, 'retro_mappable_sclyid', text='Object ID') + +def register(): + bpy.types.Object.retro_mappable_type = bpy.props.IntProperty(name='Retro: MAPA object type', default=-1) + bpy.types.Object.retro_mappable_sclyid = bpy.props.StringProperty(name='Retro: MAPA object SCLY ID') + bpy.types.Scene.retro_map_vis_mode = bpy.props.EnumProperty(items=[('ALWAYS', 'Always', 'Always Visible', 0), + ('MAPSTATIONORVISIT', 'Map Station or Visit', 'Visible after Map Station or Visit', 1), + ('VISIT', 'Visit', 'Visible after Visit', 2), + ('NEVER', 'Never', 'Never Visible', 3)], + name='Retro: Map Visibility Mode') + bpy.types.Object.retro_mapobj_vis_mode = bpy.props.EnumProperty(items=[('ALWAYS', 'Always', 'Always Visible', 0), + ('MAPSTATIONORVISIT', 'Map Station or Visit', 'Visible after Map Station or Visit', 1), + ('VISIT', 'Visit', 'Visible after Door Visit', 2), + ('NEVER', 'Never', 'Never Visible', 3), + ('MAPSTATIONORVISIT2', 'Map Station or Visit 2', 'Visible after Map Station or Visit', 4)], + name='Retro: Map Object Visibility Mode') diff --git a/hecl/blender/hecl/mapu.py b/hecl/blender/hecl/mapu.py new file mode 100644 index 000000000..f6e7ff721 --- /dev/null +++ b/hecl/blender/hecl/mapu.py @@ -0,0 +1,55 @@ +import bpy, os, struct + +def cook(writebuf): + found_lib = False + for obj in bpy.context.scene.objects: + if obj.data and obj.data.library: + path = os.path.normpath(bpy.path.abspath(obj.data.library.filepath)) + writebuf(struct.pack('I', len(path))) + writebuf(path.encode()) + found_lib = True + break + if not found_lib: + raise RuntimeError('No hexagon segments present') + + world_count = 0 + for obj in bpy.context.scene.objects: + if not obj.parent and obj.type == 'EMPTY': + world_count += 1 + writebuf(struct.pack('I', world_count)) + + for obj in bpy.context.scene.objects: + if not obj.parent and obj.type == 'EMPTY': + writebuf(struct.pack('I', len(obj.name))) + writebuf(obj.name.encode()) + writebuf(struct.pack('ffffffffffffffff', + obj.matrix_local[0][0], obj.matrix_local[0][1], obj.matrix_local[0][2], obj.matrix_local[0][3], + obj.matrix_local[1][0], obj.matrix_local[1][1], obj.matrix_local[1][2], obj.matrix_local[1][3], + obj.matrix_local[2][0], obj.matrix_local[2][1], obj.matrix_local[2][2], obj.matrix_local[2][3], + obj.matrix_local[3][0], obj.matrix_local[3][1], obj.matrix_local[3][2], obj.matrix_local[3][3])) + writebuf(struct.pack('I', len(obj.children))) + for child in obj.children: + writebuf(struct.pack('ffffffffffffffff', + child.matrix_local[0][0], child.matrix_local[0][1], child.matrix_local[0][2], child.matrix_local[0][3], + child.matrix_local[1][0], child.matrix_local[1][1], child.matrix_local[1][2], child.matrix_local[1][3], + child.matrix_local[2][0], child.matrix_local[2][1], child.matrix_local[2][2], child.matrix_local[2][3], + child.matrix_local[3][0], child.matrix_local[3][1], child.matrix_local[3][2], child.matrix_local[3][3])) + writebuf(struct.pack('ffff', obj.retro_mapworld_color[0], obj.retro_mapworld_color[1], + obj.retro_mapworld_color[2], obj.retro_mapworld_color[3])) + writebuf(struct.pack('I', len(obj.retro_mapworld_path))) + writebuf(obj.retro_mapworld_path.encode()) + +def draw(layout, context): + obj = context.active_object + if not obj: + return + while obj.parent: + obj = obj.parent + layout.prop(obj, 'retro_mapworld_color', text='Color') + layout.prop(obj, 'retro_mapworld_path', text='Path') + +# Registration +def register(): + bpy.types.Object.retro_mapworld_color = bpy.props.FloatVectorProperty(name='Retro: MapWorld Color',\ + description='Sets map world color', subtype='COLOR', size=4, min=0.0, max=1.0) + bpy.types.Object.retro_mapworld_path = bpy.props.StringProperty(name='Retro: MapWorld Path', description='Sets path to World root') diff --git a/hecl/blender/hecl/path.py b/hecl/blender/hecl/path.py new file mode 100644 index 000000000..d6a350bed --- /dev/null +++ b/hecl/blender/hecl/path.py @@ -0,0 +1,388 @@ +import bpy, gpu, sys, bmesh, struct +from mathutils import Vector +from gpu_extras.batch import batch_for_shader + +# Convenience class that automatically brings active edit mesh's face into scope for get/set +class HeightRef: + def __init__(self): + self.bm = None + context = bpy.context + obj = context.scene.objects[context.scene.hecl_path_obj] + if obj.type != 'MESH': + return + if context.edit_object != obj: + return + bm = bmesh.from_edit_mesh(obj.data) + if 'Height' not in bm.faces.layers.float: + return + self.height_lay = bm.faces.layers.float['Height'] + self.bm = bm + + @property + def ready(self): + return self.bm is not None and self.bm.faces.active is not None + + @property + def value(self): + if self.ready: + return self.bm.faces.active[self.height_lay] + + @value.setter + def value(self, value): + if self.ready: + for f in self.bm.faces: + if f.select: + f[self.height_lay] = value + +# Active edit face height get +def get_height(self): + return HeightRef().value + +# Selected edit face(s) height set +def set_height(self, val): + HeightRef().value = val + for ar in bpy.context.screen.areas: + if ar.type == 'VIEW_3D': + ar.tag_redraw() + +# Simple AABB class +class AABB: + def __init__(self): + self.min = Vector((999999.0, 999999.0, 999999.0)) + self.max = Vector((-999999.0, -999999.0, -999999.0)) + def accumulate(self, vec): + for i in range(3): + if vec[i] < self.min[i]: + self.min[i] = vec[i] + if vec[i] > self.max[i]: + self.max[i] = vec[i] + def isValid(self): + for i in range(3): + if self.min[i] > self.max[i]: + return False + return True + +# Simple adjacency calculator +class AdjacencySet: + def __init__(self, bm, mesh_obj, type_mask): + self.faces = {} + for f in bm.faces: + material = mesh_obj.material_slots[f.material_index].material + if (material.retro_path_type_mask & type_mask) == 0: + continue + face_set = set() + face_set.add(f) + + # Breadth-first loop to avoid crashing python with large recursion + next_level = [f] + while len(next_level): + next_next_level = [] + for of in next_level: + for e in of.edges: + for of2 in e.link_faces: + if of2 == of: + continue + if of2 not in face_set: + material = mesh_obj.material_slots[of2.material_index].material + if material.retro_path_type_mask & type_mask: + face_set.add(of2) + next_next_level.append(of2) + next_level = next_next_level + self.faces[f] = face_set + + def has_adjacency(self, face_a, face_b): + if face_a not in self.faces: + return False + return face_b in self.faces[face_a] + +# Cooking entry point +def cook(writebuf, mesh_obj): + ba = bytearray() + # Version 4 + ba += struct.pack('>I', 4) + + bm = bmesh.new() + bm.from_mesh(mesh_obj.data) + bm.faces.ensure_lookup_table() + height_lay = None + if 'Height' in bm.faces.layers.float: + height_lay = bm.faces.layers.float['Height'] + + # Gather immediate adjacencies + node_list = [] + link_list = [] + region_list = [] + up_vec = Vector((0.0, 0.0, 1.0)) + for f in bm.faces: + start_loop = f.loops[0] + cur_loop = start_loop + node_idx = 0 + start_node = len(node_list) + start_link = len(link_list) + while True: + node_list.append([cur_loop, up_vec]) + nv1 = cur_loop.vert.co + cur_loop = cur_loop.link_loop_prev + nv0 = cur_loop.vert.co + node_list[-1][1] = (nv0 - nv1).cross(up_vec).normalized() + for other_face in cur_loop.edge.link_faces: + if other_face == f: + continue + link_list.append((node_idx, other_face.index, cur_loop.edge.calc_length())) + node_idx += 1 + if cur_loop == start_loop: + break + region_list.append((f, range(start_node, len(node_list)), range(start_link, len(link_list)))) + + # Emit nodes + ba += struct.pack('>I', len(node_list)) + for n in node_list: + v = n[0].vert + normal = n[1] + ba += struct.pack('>ffffff', v.co[0], v.co[1], v.co[2], normal[0], normal[1], normal[2]) + + # Emit links + ba += struct.pack('>I', len(link_list)) + for l in link_list: + ba += struct.pack('>IIff', l[0], l[1], l[2], 1.0 / l[2]) + + # Emit regions + ba += struct.pack('>I', len(region_list)) + for r in region_list: + material = mesh_obj.material_slots[r[0].material_index].material + height = 1.0 + if height_lay is not None: + height = r[0][height_lay] + center = r[0].calc_center_median_weighted() + aabb = AABB() + for v in r[0].verts: + aabb.accumulate(v.co) + aabb.accumulate(v.co + Vector((0.0, 0.0, height))) + ba += struct.pack('>IIIIHHffffIfffffffffI', len(r[1]), r[1].start, len(r[2]), r[2].start, + material.retro_path_idx_mask, material.retro_path_type_mask, + height, r[0].normal[0], r[0].normal[1], r[0].normal[2], + r[0].index, center[0], center[1], center[2], + aabb.min[0], aabb.min[1], aabb.min[2], + aabb.max[0], aabb.max[1], aabb.max[2], + r[0].index) + + num_regions = len(region_list) + total_adjacencies = num_regions * (num_regions - 1) // 2 + num_words = (total_adjacencies + 31) // 32 + + # Find ground adjacencies + words = [0] * num_words + ground_adjacencies = AdjacencySet(bm, mesh_obj, 0x1) + for i in range(num_regions): + for j in range(num_regions): + if i == j: + continue + i1 = i + i2 = j + if i1 > i2: + continue + if ground_adjacencies.has_adjacency(bm.faces[i], bm.faces[j]): + rem_regions = num_regions - i1 + rem_connections = rem_regions * (rem_regions - 1) // 2 + bit = total_adjacencies - rem_connections + i2 - (i1 + 1) + words[bit // 32] |= 1 << (bit % 32) + for w in words: + ba += struct.pack('>I', w) + + # Find flyer adjacencies + words = [0] * num_words + flyer_adjacencies = AdjacencySet(bm, mesh_obj, 0x3) + for i in range(num_regions): + for j in range(num_regions): + if i == j: + continue + i1 = i + i2 = j + if i1 > i2: + continue + if flyer_adjacencies.has_adjacency(bm.faces[i], bm.faces[j]): + rem_regions = num_regions - i1 + rem_connections = rem_regions * (rem_regions - 1) // 2 + bit = total_adjacencies - rem_connections + i2 - (i1 + 1) + words[bit // 32] |= 1 << (bit % 32) + for w in words: + ba += struct.pack('>I', w) + + # Unused zero bits + for i in range((((num_regions * num_regions) + 31) // 32 - num_words) * 2): + ba += struct.pack('>I', 0) + + # Empty octree (to be generated by hecl) + ba += struct.pack('>II', 0, 0) + + # Write out + writebuf(struct.pack('I', len(ba))) + writebuf(ba) + +try: + line_shader = gpu.shader.from_builtin('3D_FLAT_COLOR') +except: + pass + +# Line draw helper +def draw_line_3d(pos_vbo, color_vbo, color, start, end): + pos_vbo.append(start) + pos_vbo.append(end) + color_vbo.append(color) + color_vbo.append(color) + +# Draw RNA polygon +def draw_poly(pos_vbo, color_vbo, p, obj, obj_mtx, height, top_color, side_color): + for ek in p.edge_keys: + co0 = obj_mtx @ obj.data.vertices[ek[0]].co + co1 = obj_mtx @ obj.data.vertices[ek[1]].co + draw_line_3d(pos_vbo, color_vbo, top_color, co0 + Vector((0.0, 0.0, height)), + co1 + Vector((0.0, 0.0, height))) + for vk in p.vertices: + co = obj_mtx @ obj.data.vertices[vk].co + draw_line_3d(pos_vbo, color_vbo, side_color, co, co + Vector((0.0, 0.0, height))) + +# Draw bmesh face +def draw_face(pos_vbo, color_vbo, f, obj_mtx, height, top_color, side_color): + for e in f.edges: + co0 = obj_mtx @ e.verts[0].co + co1 = obj_mtx @ e.verts[1].co + draw_line_3d(pos_vbo, color_vbo, top_color, co0 + Vector((0.0, 0.0, height)), + co1 + Vector((0.0, 0.0, height))) + for v in f.verts: + co = obj_mtx @ v.co + draw_line_3d(pos_vbo, color_vbo, side_color, co, co + Vector((0.0, 0.0, height))) + +# Viewport hook callback +def draw_callback_3d(self, context): + # object locations + if context.scene.hecl_path_obj not in context.scene.objects: + return + obj = context.scene.objects[context.scene.hecl_path_obj] + if obj.type != 'MESH': + return + obj_mtx = obj.matrix_world + + bm = None + height_lay = None + if obj == context.edit_object: + bm = bmesh.from_edit_mesh(obj.data) + if 'Height' in bm.faces.layers.float: + height_lay = bm.faces.layers.float['Height'] + else: + if 'Height' in obj.data.polygon_layers_float: + height_lay = obj.data.polygon_layers_float['Height'] + + pos_vbo = [] + color_vbo = [] + + # Deselected colors + top_color = (0.0, 0.0, 1.0, 0.7) + side_color = (1.0, 0.0, 0.0, 0.7) + if bm is not None: + for f in bm.faces: + height = 1.0 + if height_lay is not None: + selected = f.select + if selected: + continue + height = f[height_lay] + draw_face(pos_vbo, color_vbo, f, obj_mtx, height, top_color, side_color) + else: + for p in obj.data.polygons: + height = 1.0 + if height_lay is not None: + height = height_lay.data[p.index].value + draw_poly(pos_vbo, color_vbo, p, obj, obj_mtx, height, top_color, side_color) + + # Selected colors + if bm is not None: + top_color = (1.0, 0.0, 1.0, 0.7) + side_color = (0.0, 1.0, 0.0, 0.7) + # Avoid z-fighting on selected lines + #bgl.glDepthRange(-0.001, 0.999) + for f in bm.faces: + if height_lay is not None: + selected = f.select + if not selected: + continue + height = f[height_lay] + draw_face(pos_vbo, color_vbo, f, obj_mtx, height, top_color, side_color) + #bgl.glEnd() + #bgl.glDepthRange(0.0, 1.0) + + line_shader.bind() + batch = batch_for_shader(line_shader, 'LINES', {"pos": pos_vbo, "color": color_vbo}) + batch.draw(line_shader) + + +# Toggle height viz button +class PathHeightDrawOperator(bpy.types.Operator): + bl_idname = "view3d.toggle_path_height_visualization" + bl_label = "Toggle PATH height visualization" + _handle_3d = None + + def execute(self, context): + # the arguments we pass the the callback + args = (self, context) + # Add the region OpenGL drawing callback + # draw in view space with 'POST_VIEW' and 'PRE_VIEW' + if self._handle_3d is None: + PathHeightDrawOperator._handle_3d = \ + bpy.types.SpaceView3D.draw_handler_add(draw_callback_3d, args, 'WINDOW', 'POST_VIEW') + else: + bpy.types.SpaceView3D.draw_handler_remove(PathHeightDrawOperator._handle_3d, 'WINDOW') + PathHeightDrawOperator._handle_3d = None + + for ar in bpy.context.screen.areas: + if ar.type == 'VIEW_3D': + ar.tag_redraw() + return {'FINISHED'} + +# Toggle background wire button +class PathBackgroundWireframeOperator(bpy.types.Operator): + bl_idname = "view3d.toggle_path_background_wireframe" + bl_label = "Toggle PATH background wireframe" + + def execute(self, context): + if context.scene.background_set: + to_wire = False + for o in context.scene.background_set.objects: + if o.display_type != 'WIRE': + to_wire = True + break + if to_wire: + for o in context.scene.background_set.objects: + o.display_type = 'WIRE' + else: + for o in context.scene.background_set.objects: + o.display_type = 'TEXTURED' + return {'FINISHED'} + +# Edit panel +def draw(layout, context): + layout.prop_search(context.scene, 'hecl_path_obj', context.scene, 'objects') + layout.operator('view3d.toggle_path_background_wireframe', text='Toggle Background Wire', icon='SHADING_WIRE') + if PathHeightDrawOperator._handle_3d: + icon = 'HIDE_OFF' + else: + icon = 'HIDE_ON' + layout.operator('view3d.toggle_path_height_visualization', text='Toggle Height Viz', icon=icon) + if HeightRef().ready: + layout.prop(context.window_manager, 'hecl_height_prop', text='Height') + +# Registration +def register(): + bpy.types.Material.retro_path_idx_mask = bpy.props.IntProperty(name='Retro: Path Index Mask') + bpy.types.Material.retro_path_type_mask = bpy.props.IntProperty(name='Retro: Path Type Mask') + bpy.types.WindowManager.hecl_height_prop = bpy.props.FloatProperty( + get=get_height, set=set_height, options={'HIDDEN'}) + bpy.types.Scene.hecl_path_obj = bpy.props.StringProperty( + name='HECL Path Object', + description='Blender Mesh Object to export during PATH\'s cook process') + bpy.utils.register_class(PathHeightDrawOperator) + bpy.utils.register_class(PathBackgroundWireframeOperator) + +def unregister(): + bpy.utils.unregister_class(PathHeightDrawOperator) + bpy.utils.unregister_class(PathBackgroundWireframeOperator) diff --git a/hecl/blender/hecl/sact/ANIM.py b/hecl/blender/hecl/sact/ANIM.py new file mode 100644 index 000000000..90d3a1cfc --- /dev/null +++ b/hecl/blender/hecl/sact/ANIM.py @@ -0,0 +1,208 @@ +''' +This file provides a means to encode animation key-channels +in an interleaved, sparse array for use by the runtime +''' + +import re +import struct +import mathutils + +# Regex RNA path matchers +scale_matcher = re.compile(r'pose.bones\["(\S+)"\].scale') +rotation_matcher = re.compile(r'pose.bones\["(\S+)"\].rotation') +location_matcher = re.compile(r'pose.bones\["(\S+)"\].location') + +# Effect transform modes +EFFECT_XF_MODES = {'STATIONARY':0, 'WORLD':1, 'LOCAL':2} + +# Generate animation info +def generate_animation_info(action, res_db, rani_db_id, arg_package, endian_char='<'): + + # Set of frame indices + frame_set = set() + + # Set of unique bone names + bone_set = set() + + # Scan through all fcurves to build animated bone set + for fcurve in action.fcurves: + data_path = fcurve.data_path + scale_match = scale_matcher.match(data_path) + rotation_match = rotation_matcher.match(data_path) + location_match = location_matcher.match(data_path) + + if scale_match: + bone_set.add(scale_match.group(1)) + elif rotation_match: + bone_set.add(rotation_match.group(1)) + elif location_match: + bone_set.add(location_match.group(1)) + else: + continue + + # Count unified keyframes for interleaving channel data + for key in fcurve.keyframe_points: + frame_set.add(int(key.co[0])) + + # Relate fcurves per-frame / per-bone and assemble data + key_stream = bytearray() + key_stream += struct.pack(endian_char + 'II', len(frame_set), len(bone_set)) + duration = action.frame_range[1] / action.hecl_fps + interval = 1.0 / action.hecl_fps + key_stream += struct.pack(endian_char + 'ff', duration, interval) + + # Generate keyframe bitmap + fr = int(round(action.frame_range[1])) + key_stream += struct.pack(endian_char + 'I', fr) + bitmap_words = [0] * (fr // 32) + if fr % 32: + bitmap_words.append(0) + for i in range(fr): + if i in frame_set: + bitmap_words[i//32] |= 1 << i%32 + for word in bitmap_words: + key_stream += struct.pack(endian_char + 'I', word) + + + # Build bone table + bone_list = [] + for bone in bone_set: + fc_dict = dict() + rotation_mode = None + property_bits = 0 + for fcurve in action.fcurves: + if fcurve.data_path == 'pose.bones["'+bone+'"].scale': + if 'scale' not in fc_dict: + fc_dict['scale'] = [None, None, None] + property_bits |= 1 + fc_dict['scale'][fcurve.array_index] = fcurve + elif fcurve.data_path == 'pose.bones["'+bone+'"].rotation_euler': + if 'rotation_euler' not in fc_dict: + fc_dict['rotation_euler'] = [None, None, None] + rotation_mode = 'rotation_euler' + property_bits |= 2 + fc_dict['rotation_euler'][fcurve.array_index] = fcurve + elif fcurve.data_path == 'pose.bones["'+bone+'"].rotation_quaternion': + if 'rotation_quaternion' not in fc_dict: + fc_dict['rotation_quaternion'] = [None, None, None, None] + rotation_mode = 'rotation_quaternion' + property_bits |= 2 + fc_dict['rotation_quaternion'][fcurve.array_index] = fcurve + elif fcurve.data_path == 'pose.bones["'+bone+'"].rotation_axis_angle': + if 'rotation_axis_angle' not in fc_dict: + fc_dict['rotation_axis_angle'] = [None, None, None, None] + rotation_mode = 'rotation_axis_angle' + property_bits |= 2 + fc_dict['rotation_axis_angle'][fcurve.array_index] = fcurve + elif fcurve.data_path == 'pose.bones["'+bone+'"].location': + if 'location' not in fc_dict: + fc_dict['location'] = [None, None, None] + property_bits |= 4 + fc_dict['location'][fcurve.array_index] = fcurve + bone_list.append((bone, rotation_mode, fc_dict)) + bone_head = hashbone(bone) + bone_head |= (property_bits << 28) + key_stream += struct.pack(endian_char + 'I', bone_head) + + # Interleave / interpolate keyframe data + for frame in sorted(frame_set): + for bone in bone_list: + + bone_name = bone[0] + rotation_mode = bone[1] + fc_dict = bone[2] + + # Scale curves + if 'scale' in fc_dict: + for comp in range(3): + if fc_dict['scale'][comp]: + key_stream += struct.pack(endian_char + 'f', fc_dict['scale'][comp].evaluate(frame)) + else: + key_stream += struct.pack(endian_char + 'f', 0.0) + + # Rotation curves + if rotation_mode == 'rotation_quaternion': + for comp in range(4): + if fc_dict['rotation_quaternion'][comp]: + key_stream += struct.pack(endian_char + 'f', fc_dict['rotation_quaternion'][comp].evaluate(frame)) + else: + key_stream += struct.pack(endian_char + 'f', 0.0) + + elif rotation_mode == 'rotation_euler': + euler = [0.0, 0.0, 0.0] + for comp in range(3): + if fc_dict['rotation_euler'][comp]: + euler[comp] = fc_dict['rotation_euler'][comp].evaluate(frame) + euler_o = mathutils.Euler(euler, 'XYZ') + quat = euler_o.to_quaternion() + key_stream += struct.pack(endian_char + 'ffff', quat[0], quat[1], quat[2], quat[3]) + + elif rotation_mode == 'rotation_axis_angle': + axis_angle = [0.0, 0.0, 0.0, 0.0] + for comp in range(4): + if fc_dict['rotation_axis_angle'][comp]: + axis_angle[comp] = fc_dict['rotation_axis_angle'][comp].evaluate(frame) + quat = mathutils.Quaternion(axis_angle[1:4], axis_angle[0]) + key_stream += struct.pack(endian_char + 'ffff', quat[0], quat[1], quat[2], quat[3]) + + # Location curves + if 'location' in fc_dict: + for comp in range(3): + if fc_dict['location'][comp]: + key_stream += struct.pack(endian_char + 'f', fc_dict['location'][comp].evaluate(frame)) + else: + key_stream += struct.pack(endian_char + 'f', 0.0) + + + # Generate event buffer + event_buf = bytearray() + if hasattr(action, 'hecl_events'): + c1 = 0 + c2 = 0 + c3 = 0 + c4 = 0 + for event in action.hecl_events: + if event.type == 'LOOP': + c1 += 1 + elif event.type == 'UEVT': + c2 += 1 + elif event.type == 'EFFECT': + c3 += 1 + elif event.type == 'SOUND': + c4 += 1 + event_buf += struct.pack(endian_char + 'IIII', c1, c2, c3, c4) + + for event in action.hecl_events: + if event.type == 'LOOP': + event_buf += struct.pack(endian_char + 'fi', event.time, event.loop_data.bool) + + for event in action.hecl_events: + if event.type == 'UEVT': + event_buf += struct.pack(endian_char + 'fii', event.time, event.uevt_data.type, + hashbone(event.uevt_data.bone_name)) + + for event in action.hecl_events: + if event.type == 'EFFECT': + effect_db_id, effect_hash = res_db.search_for_resource(event.effect_data.uid, arg_package) + if effect_hash: + res_db.register_dependency(rani_db_id, effect_db_id) + else: + raise RuntimeError("Error - unable to find effect '{0}'".format(event.effect_data.uid)) + event_buf += struct.pack(endian_char + 'fiifi', event.time, event.effect_data.frame_count, + hashbone(event.effect_data.bone_name), event.effect_data.scale, + EFFECT_XF_MODES[event.effect_data.transform_mode]) + event_buf += effect_hash + + for event in action.hecl_events: + if event.type == 'SOUND': + sid = int.from_bytes(event.sound_data.sound_id.encode()[:4], byteorder='big', signed=False) + event_buf += struct.pack(endian_char + 'fIff', event.time, sid, + event.sound_data.ref_amp, event.sound_data.ref_dist) + + else: + event_buf += struct.pack('IIII',0,0,0,0) + + + + return key_stream + event_buf + diff --git a/hecl/blender/hecl/sact/SACTAction.py b/hecl/blender/hecl/sact/SACTAction.py new file mode 100644 index 000000000..1a25ce9a9 --- /dev/null +++ b/hecl/blender/hecl/sact/SACTAction.py @@ -0,0 +1,220 @@ +import bpy + +# Action update (if anything important changes) +def active_action_update(self, context): + if not bpy.app.background: + if context.scene.hecl_type == 'ACTOR' and context.scene.hecl_auto_select: + if SACTAction_load.poll(context): + bpy.ops.scene.sactaction_load() + +# Action type update +def action_type_update(self, context): + if not bpy.app.background: + actor_data = context.scene.hecl_sact_data + active_action_update(self, context) + +# Actor action class +class SACTAction(bpy.types.PropertyGroup): + name: bpy.props.StringProperty(name="Action Name") + +# Panel draw +def draw(layout, context): + actor_data = context.scene.hecl_sact_data + + row = layout.row(align=True) + row.alignment = 'LEFT' + row.prop(actor_data, 'show_actions', text="Actions", icon='ACTION', emboss=False) + if actor_data.show_actions: + + row = layout.row() + row.template_list("UI_UL_list", "SCENE_UL_SACTActions", + actor_data, 'actions', actor_data, 'active_action') + col = row.column(align=True) + col.operator("scene.sactaction_add", icon="ADD", text="") + col.operator("scene.sactaction_remove", icon="REMOVE", text="") + + if len(actor_data.actions) and actor_data.active_action >= 0: + action = actor_data.actions[actor_data.active_action] + + # Load action operator + if not bpy.context.scene.hecl_auto_select: + layout.operator("scene.sactaction_load", icon='FILE_TICK', text="Load Action") + + # Name edit field + layout.prop_search(action, 'name', bpy.data, 'actions', text="Name") + linked_action = None + if bpy.data.actions.find(action.name) != -1: + linked_action = bpy.data.actions[action.name] + + # Validate + if linked_action is None: + layout.label(text="Source action not set", icon='ERROR') + else: + #layout.prop(linked_action, 'hecl_index', text="Index") + #layout.prop(linked_action, 'hecl_anim_props', text="Props") + layout.prop(linked_action, 'anim_id', text="ANIM ID") + layout.prop(linked_action, 'hecl_fps', text="Frame Rate") + row = layout.row() + row.prop(context.scene, 'hecl_auto_remap', text="60-fps Remap") + row.prop(linked_action, 'hecl_additive', text="Additive") + #row.prop(linked_action, 'hecl_looping', text="Looping") + + + +# Action 'add' operator +class SACTAction_add(bpy.types.Operator): + bl_idname = "scene.sactaction_add" + bl_label = "New HECL Actor Action" + bl_description = "Add New HECL Actor Action to active scene" + + @classmethod + def poll(cls, context): + return (context.scene is not None and + not context.scene.library and + context.scene.hecl_type == 'ACTOR') + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + action_name = 'ActorAction' + if action_name in actor_data.actions: + action_name = 'ActorAction.001' + action_idx = 1 + while action_name in actor_data.actions: + action_idx += 1 + action_name = 'ActorAction.{:0>3}'.format(action_idx) + action = actor_data.actions.add() + action.name = action_name + actor_data.active_action = len(actor_data.actions)-1 + + return {'FINISHED'} + +# Action 'remove' operator +class SACTAction_remove(bpy.types.Operator): + bl_idname = "scene.sactaction_remove" + bl_label = "Remove HECL Actor Action" + bl_description = "Remove HECL Actor Action from active scene" + + @classmethod + def poll(cls, context): + actor_data = context.scene.hecl_sact_data + return (context.scene is not None and + not context.scene.library and + context.scene.hecl_type == 'ACTOR' and + actor_data.active_action >= 0 and + len(actor_data.actions)) + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + actor_data.actions.remove(actor_data.active_action) + actor_data.active_action -= 1 + if actor_data.active_action == -1: + actor_data.active_action = 0 + return {'FINISHED'} + + +# Action 'load' operator +class SACTAction_load(bpy.types.Operator): + bl_idname = "scene.sactaction_load" + bl_label = "Load HECL Actor Action" + bl_description = "Loads Action for playback in active scene" + + @classmethod + def poll(cls, context): + return (context.scene is not None and + context.scene.hecl_type == 'ACTOR' and + len(context.scene.hecl_sact_data.actions) and + context.scene.hecl_sact_data.active_action >= 0) + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + + if actor_data.active_action not in range(len(actor_data.actions)): + return {'CANCELLED'} + if actor_data.active_subtype not in range(len(actor_data.subtypes)): + return {'CANCELLED'} + + action_data = actor_data.actions[actor_data.active_action] + subtype = actor_data.subtypes[actor_data.active_subtype] + + # Refresh event markers + #SACTEvent.clear_event_markers(actor_data, context) + #SACTEvent.update_action_events(None) + #SACTEvent.active_event_update(None, context) + + # Clear animation data for all subtypes + for s in range(len(actor_data.subtypes)): + st = actor_data.subtypes[s] + if st.linked_armature in bpy.data.objects: + am = bpy.data.objects[st.linked_armature] + am.animation_data_clear() + + # Set single action into armature + if subtype.linked_armature in bpy.data.objects: + armature_objs = [bpy.data.objects[subtype.linked_armature]] + + for attachment in actor_data.attachments: + if attachment.linked_armature in bpy.data.objects: + attachment_armature = bpy.data.objects[attachment.linked_armature] + armature_objs.append(attachment_armature) + + for armature_obj in armature_objs: + for bone in armature_obj.pose.bones: + bone.location = (0,0,0) + bone.rotation_quaternion = (1,0,0,0) + bone.scale = (1,1,1) + + if action_data.name in bpy.data.actions: + action_obj =\ + bpy.data.actions[action_data.name] + armature_obj.animation_data_clear() + armature_obj.animation_data_create() + armature_obj.animation_data.action = action_obj + + # Time remapping + if context.scene.hecl_auto_remap: + bpy.context.scene.render.fps = 60 + bpy.context.scene.render.frame_map_old = action_obj.hecl_fps + bpy.context.scene.render.frame_map_new = 60 + bpy.context.scene.frame_start = 0 + bpy.context.scene.frame_end = action_obj.frame_range[1] * (60 / action_obj.hecl_fps) + else: + bpy.context.scene.render.fps = action_obj.hecl_fps + bpy.context.scene.render.frame_map_old = action_obj.hecl_fps + bpy.context.scene.render.frame_map_new = action_obj.hecl_fps + bpy.context.scene.frame_start = 0 + bpy.context.scene.frame_end = action_obj.frame_range[1] + + # Events + #SACTEvent.clear_action_events(self, context, actor_data) + #SACTEvent.load_action_events(self, context, action_obj, 0) + + else: + armature_obj.animation_data_clear() + self.report({'WARNING'}, "Unable to load action; check HECL panel") + return {'FINISHED'} + + return {'FINISHED'} + + else: + self.report({'WARNING'}, "Unable to load armature; check HECL panel") + return {'FINISHED'} + + + + +# Registration +def register(): + bpy.types.Action.hecl_fps = bpy.props.IntProperty(name="HECL Actor Sub-action Frame-rate", + description="Frame-rate at which action is authored; to be interpolated at 60-fps by runtime", + min=1, max=60, default=30, update=active_action_update) + bpy.utils.register_class(SACTAction) + bpy.utils.register_class(SACTAction_add) + bpy.utils.register_class(SACTAction_load) + bpy.utils.register_class(SACTAction_remove) + + +def unregister(): + bpy.utils.unregister_class(SACTAction) + bpy.utils.unregister_class(SACTAction_add) + bpy.utils.unregister_class(SACTAction_load) + bpy.utils.unregister_class(SACTAction_remove) diff --git a/hecl/blender/hecl/sact/SACTSubtype.py b/hecl/blender/hecl/sact/SACTSubtype.py new file mode 100644 index 000000000..6a8500c62 --- /dev/null +++ b/hecl/blender/hecl/sact/SACTSubtype.py @@ -0,0 +1,408 @@ +import bpy + +# Subtype update (if anything important changes) +def active_subtype_update(self, context): + if context.scene.hecl_type == 'ACTOR' and context.scene.hecl_auto_select: + if SACTSubtype_load.poll(context): + bpy.ops.scene.sactsubtype_load() + + +# Actor subtype overlay class +class SACTSubtypeOverlay(bpy.types.PropertyGroup): + name: bpy.props.StringProperty(name="Overlay Name") + linked_mesh: bpy.props.StringProperty(name="Linked Mesh Object Source", update=active_subtype_update) + show_overlay: bpy.props.BoolProperty(name="Show Overlay Mesh", update=active_subtype_update) + +# Actor attachment class +class SACTAttachment(bpy.types.PropertyGroup): + name: bpy.props.StringProperty(name="Attachment Name") + linked_armature: bpy.props.StringProperty(name="Linked Armature Object Source", update=active_subtype_update) + linked_mesh: bpy.props.StringProperty(name="Linked Mesh Object Source", update=active_subtype_update) + show_attachment: bpy.props.BoolProperty(name="Show Attachment Mesh", update=active_subtype_update) + +# Actor subtype class +class SACTSubtype(bpy.types.PropertyGroup): + name: bpy.props.StringProperty(name="Actor Mesh Name") + linked_armature: bpy.props.StringProperty(name="Linked Armature Object Source", update=active_subtype_update) + linked_mesh: bpy.props.StringProperty(name="Linked Mesh Object Source", update=active_subtype_update) + show_mesh: bpy.props.BoolProperty(name="Show Mesh", default=True, update=active_subtype_update) + + overlays: bpy.props.CollectionProperty(type=SACTSubtypeOverlay, name="Subtype Overlay List") + active_overlay: bpy.props.IntProperty(name="Active Subtype Overlay", default=0, update=active_subtype_update) + +# Panel draw +def draw(layout, context): + actor_data = context.scene.hecl_sact_data + + row = layout.row(align=True) + row.alignment = 'LEFT' + row.prop(actor_data, 'show_subtypes', text="Subtypes", icon='MESH_DATA', emboss=False) + if actor_data.show_subtypes: + + row = layout.row() + row.template_list("UI_UL_list", "SCENE_UL_SACTSubtypes", + actor_data, 'subtypes', actor_data, 'active_subtype') + col = row.column(align=True) + col.operator("scene.sactsubtype_add", icon="ADD", text="") + col.operator("scene.sactsubtype_remove", icon="REMOVE", text="") + + if len(actor_data.subtypes) and actor_data.active_subtype >= 0: + subtype = actor_data.subtypes[actor_data.active_subtype] + + # Load subtype operator + if not bpy.context.scene.hecl_auto_select: + layout.operator("scene.sactsubtype_load", icon='FILE_TICK', text="Load Subtype") + + # Name edit field + layout.prop(subtype, 'name', text="Name") + + + # Link external armature search + layout.prop_search(subtype, 'linked_armature', bpy.data, 'objects', text="Armature") + linked_armature = None + if subtype.linked_armature in bpy.data.objects: + linked_armature = bpy.data.objects[subtype.linked_armature] + + # Validate + if linked_armature is None: + layout.label(text="Source armature not set", icon='ERROR') + elif linked_armature is not None and linked_armature.type != 'ARMATURE': + layout.label(text="Source armature is not an 'ARMATURE'", icon='ERROR') + + + # Link external mesh search + layout.prop_search(subtype, 'linked_mesh', bpy.data, 'objects', text="Mesh") + linked_mesh = None + if subtype.linked_mesh in bpy.data.objects: + linked_mesh = bpy.data.objects[subtype.linked_mesh] + layout.prop(subtype, 'show_mesh', text="Show Mesh") + + # Mesh overlays + layout.label(text="Overlay Meshes:") + row = layout.row() + row.template_list("UI_UL_list", "SCENE_UL_SACTSubtypeOverlays", + subtype, 'overlays', subtype, 'active_overlay') + col = row.column(align=True) + col.operator("scene.sactsubtypeoverlay_add", icon="ADD", text="") + col.operator("scene.sactsubtypeoverlay_remove", icon="REMOVE", text="") + + overlay_mesh = None + if len(subtype.overlays) and subtype.active_overlay >= 0: + overlay = subtype.overlays[subtype.active_overlay] + layout.prop(overlay, 'name', text="Name") + layout.prop_search(overlay, 'linked_mesh', bpy.data, 'objects', text="Mesh") + if overlay.linked_mesh in bpy.data.objects: + overlay_mesh = bpy.data.objects[overlay.linked_mesh] + layout.prop(overlay, 'show_overlay', text="Show Overlay") + + # Mesh attachments + layout.label(text="Attachment Meshes:") + row = layout.row() + row.template_list("UI_UL_list", "SCENE_UL_SACTAttachments", + actor_data, 'attachments', actor_data, 'active_attachment') + col = row.column(align=True) + col.operator("scene.sactattachment_add", icon="ADD", text="") + col.operator("scene.sactattachment_remove", icon="REMOVE", text="") + + attachment_armature = linked_armature + attachment_mesh = None + if len(actor_data.attachments) and actor_data.active_attachment >= 0: + attachment = actor_data.attachments[actor_data.active_attachment] + layout.prop(attachment, 'name', text="Name") + layout.prop_search(attachment, 'linked_armature', bpy.data, 'objects', text="Armature") + if attachment.linked_armature in bpy.data.objects: + attachment_armature = bpy.data.objects[attachment.linked_armature] + layout.prop_search(attachment, 'linked_mesh', bpy.data, 'objects', text="Mesh") + if attachment.linked_mesh in bpy.data.objects: + attachment_mesh = bpy.data.objects[attachment.linked_mesh] + layout.prop(attachment, 'show_attachment', text="Show Attachment") + + # Validate + if linked_mesh is None: + layout.label(text="Source mesh not set", icon='ERROR') + elif linked_mesh.type != 'MESH': + layout.label(text="Source mesh not 'MESH'", icon='ERROR') + elif linked_armature is not None and linked_mesh not in linked_armature.children: + layout.label(linked_mesh.name+" not a child of "+linked_armature.name, icon='ERROR') + elif linked_mesh.parent_type != 'ARMATURE': + layout.label(text="Source mesh not 'ARMATURE' parent type", icon='ERROR') + + if overlay_mesh: + if overlay_mesh.type != 'MESH': + layout.label(text="Overlay mesh not 'MESH'", icon='ERROR') + elif overlay_mesh.parent_type != 'ARMATURE': + layout.label(text="Overlay mesh not 'ARMATURE' parent type", icon='ERROR') + + if attachment_mesh: + if attachment_mesh.type != 'MESH': + layout.label(text="Attachment mesh not 'MESH'", icon='ERROR') + elif attachment_armature is not None and attachment_mesh not in attachment_armature.children: + layout.label(attachment_mesh.name+" not a child of "+attachment_armature.name, icon='ERROR') + elif attachment_mesh.parent_type != 'ARMATURE': + layout.label(text="Attachment mesh not 'ARMATURE' parent type", icon='ERROR') + + +# Subtype 'add' operator +class SACTSubtype_add(bpy.types.Operator): + bl_idname = "scene.sactsubtype_add" + bl_label = "New HECL Actor Subtype" + bl_description = "Add New HECL Actor Subtype to active scene" + + @classmethod + def poll(cls, context): + return (context.scene is not None and + not context.scene.library and + context.scene.hecl_type == 'ACTOR') + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + mesh_name = 'ActorMesh' + if mesh_name in actor_data.subtypes: + mesh_name = 'ActorMesh.001' + mesh_idx = 1 + while mesh_name in actor_data.subtypes: + mesh_idx += 1 + mesh_name = 'ActorMesh.{:0>3}'.format(mesh_idx) + mesh = actor_data.subtypes.add() + mesh.name = mesh_name + actor_data.active_subtype = len(actor_data.subtypes)-1 + + return {'FINISHED'} + +# Subtype 'remove' operator +class SACTSubtype_remove(bpy.types.Operator): + bl_idname = "scene.sactsubtype_remove" + bl_label = "Remove HECL Actor Subtype" + bl_description = "Remove HECL Actor Subtype from active scene" + + @classmethod + def poll(cls, context): + actor_data = context.scene.hecl_sact_data + return (context.scene is not None and + not context.scene.library and + context.scene.hecl_type == 'ACTOR' and + actor_data.active_subtype >= 0 and + len(actor_data.subtypes)) + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + actor_data.subtypes.remove(actor_data.active_subtype) + actor_data.active_subtype -= 1 + if actor_data.active_subtype == -1: + actor_data.active_subtype = 0 + return {'FINISHED'} + + +def parent_armature(mesh_obj, arm_obj): + mesh_obj.parent = None + for mod in mesh_obj.modifiers: + if mod.type == 'ARMATURE': + mod.object = arm_obj + return + mod = mesh_obj.modifiers.new('Parent', 'ARMATURE') + mod.object = arm_obj + #mesh_obj.parent = arm_obj + #mesh_obj.parent_type = 'ARMATURE' + +# Subtype 'load' operator +class SACTSubtype_load(bpy.types.Operator): + bl_idname = "scene.sactsubtype_load" + bl_label = "Load HECL Actor Subtype" + bl_description = "Loads Subtype for viewing in active scene" + + @classmethod + def poll(cls, context): + return (context.scene is not None and + context.scene.hecl_type == 'ACTOR' and + len(context.scene.hecl_sact_data.subtypes) and + context.scene.hecl_sact_data.active_subtype >= 0) + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + subtype = actor_data.subtypes[actor_data.active_subtype] + + # Armature + linked_armature = None + if subtype.linked_armature in bpy.data.objects: + linked_armature = bpy.data.objects[subtype.linked_armature] + else: + return {'FINISHED'} + + # Hide armature children + for object in linked_armature.children: + if object.name in context.scene.objects: + object.hide_set(True) + + # Hide all meshes (incl overlays) + for subtype_data in actor_data.subtypes: + if subtype_data.linked_mesh in bpy.data.objects: + mesh = bpy.data.objects[subtype_data.linked_mesh] + if mesh.name in context.scene.objects: + mesh.hide_set(True) + for overlay in subtype_data.overlays: + if overlay.linked_mesh in bpy.data.objects: + mesh = bpy.data.objects[overlay.linked_mesh] + if mesh.name in context.scene.objects: + mesh.hide_set(True) + + # Hide/Show selected attachment meshes + for attachment in actor_data.attachments: + if attachment.linked_mesh in bpy.data.objects: + mesh_obj = bpy.data.objects[attachment.linked_mesh] + if mesh_obj.name in context.scene.objects: + mesh_obj.hide_set(not attachment.show_attachment) + attachment_armature = linked_armature + if attachment.linked_armature in bpy.data.objects: + attachment_armature = bpy.data.objects[attachment.linked_armature] + if mesh_obj != attachment_armature: + parent_armature(mesh_obj, attachment_armature) + + # Show only the chosen subtype (and selected overlays) + if subtype.linked_mesh in bpy.data.objects: + mesh_obj = bpy.data.objects[subtype.linked_mesh] + if subtype.show_mesh: + mesh_obj.hide_set(False) + if mesh_obj != linked_armature: + parent_armature(mesh_obj, linked_armature) + for overlay in subtype.overlays: + if overlay.linked_mesh in bpy.data.objects: + mesh_obj = bpy.data.objects[overlay.linked_mesh] + if overlay.show_overlay: + mesh_obj.hide_set(False) + if mesh_obj != linked_armature: + parent_armature(mesh_obj, linked_armature) + + return {'FINISHED'} + + +# Subtype overlay 'add' operator +class SACTSubtypeOverlay_add(bpy.types.Operator): + bl_idname = "scene.sactsubtypeoverlay_add" + bl_label = "New HECL Actor Subtype Overlay" + bl_description = "Add New HECL Actor Subtype Overlay" + + @classmethod + def poll(cls, context): + actor_data = context.scene.hecl_sact_data + return (context.scene is not None and + not context.scene.library and + context.scene.hecl_type == 'ACTOR' and + len(actor_data.subtypes) and actor_data.active_subtype >= 0) + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + subtype = actor_data.subtypes[actor_data.active_subtype] + overlay_name = 'ActorOverlay' + if overlay_name in subtype.overlays: + overlay_name = 'ActorOverlay.001' + overlay_idx = 1 + while overlay_name in subtype.overlays: + overlay_idx += 1 + overlay_name = 'ActorOverlay.{:0>3}'.format(overlay_idx) + overlay = subtype.overlays.add() + overlay.name = overlay_name + subtype.active_overlay = len(subtype.overlays)-1 + + return {'FINISHED'} + +# Subtype overlay 'remove' operator +class SACTSubtypeOverlay_remove(bpy.types.Operator): + bl_idname = "scene.sactsubtypeoverlay_remove" + bl_label = "Remove HECL Actor Subtype Overlay" + bl_description = "Remove HECL Actor Subtype Overlay" + + @classmethod + def poll(cls, context): + actor_data = context.scene.hecl_sact_data + return (context.scene is not None and + not context.scene.library and + context.scene.hecl_type == 'ACTOR' and + actor_data.active_subtype >= 0 and + len(actor_data.subtypes) and + actor_data.subtypes[actor_data.active_subtype].active_overlay >= 0 and + len(actor_data.subtypes[actor_data.active_subtype].overlays)) + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + subtype = actor_data.subtypes[actor_data.active_subtype] + subtype.overlays.remove(subtype.active_overlay) + subtype.active_overlay -= 1 + if subtype.active_overlay == -1: + subtype.active_overlay = 0 + return {'FINISHED'} + +# Subtype overlay 'add' operator +class SACTAttachment_add(bpy.types.Operator): + bl_idname = "scene.sactattachment_add" + bl_label = "New HECL Actor Attachment" + bl_description = "Add New HECL Actor Attachment" + + @classmethod + def poll(cls, context): + actor_data = context.scene.hecl_sact_data + return (context.scene is not None and + not context.scene.library and + context.scene.hecl_type == 'ACTOR') + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + attachment_name = 'ActorAttachment' + if attachment_name in actor_data.attachments: + attachment_name = 'ActorAttachment.001' + attachment_idx = 1 + while attachment_name in actor_data.attachments: + attachment_idx += 1 + attachment_name = 'ActorAttachment.{:0>3}'.format(attachment_idx) + attachment = actor_data.attachments.add() + attachment.name = attachment_name + actor_data.active_attachment = len(actor_data.attachments)-1 + + return {'FINISHED'} + +# Subtype overlay 'remove' operator +class SACTAttachment_remove(bpy.types.Operator): + bl_idname = "scene.sactattachment_remove" + bl_label = "Remove HECL Actor Attachment" + bl_description = "Remove HECL Actor Attachment" + + @classmethod + def poll(cls, context): + actor_data = context.scene.hecl_sact_data + return (context.scene is not None and + not context.scene.library and + context.scene.hecl_type == 'ACTOR' and + actor_data.active_attachment >= 0 and + len(actor_data.attachments)) + + def execute(self, context): + actor_data = context.scene.hecl_sact_data + actor_data.attachments.remove(actor_data.active_attachment) + actor_data.active_attachment -= 1 + if actor_data.active_attachment == -1: + actor_data.active_attachment = 0 + return {'FINISHED'} + +# Registration +def register(): + bpy.utils.register_class(SACTSubtypeOverlay) + bpy.utils.register_class(SACTSubtypeOverlay_add) + bpy.utils.register_class(SACTSubtypeOverlay_remove) + bpy.utils.register_class(SACTAttachment) + bpy.utils.register_class(SACTAttachment_add) + bpy.utils.register_class(SACTAttachment_remove) + bpy.utils.register_class(SACTSubtype) + bpy.utils.register_class(SACTSubtype_add) + bpy.utils.register_class(SACTSubtype_remove) + bpy.utils.register_class(SACTSubtype_load) + +def unregister(): + bpy.utils.unregister_class(SACTSubtype) + bpy.utils.unregister_class(SACTSubtype_add) + bpy.utils.unregister_class(SACTSubtype_remove) + bpy.utils.unregister_class(SACTSubtype_load) + bpy.utils.unregister_class(SACTAttachment) + bpy.utils.unregister_class(SACTAttachment_add) + bpy.utils.unregister_class(SACTAttachment_remove) + bpy.utils.unregister_class(SACTSubtypeOverlay) + bpy.utils.unregister_class(SACTSubtypeOverlay_add) + bpy.utils.unregister_class(SACTSubtypeOverlay_remove) diff --git a/hecl/blender/hecl/sact/__init__.py b/hecl/blender/hecl/sact/__init__.py new file mode 100644 index 000000000..636156242 --- /dev/null +++ b/hecl/blender/hecl/sact/__init__.py @@ -0,0 +1,488 @@ +from . import SACTSubtype, SACTAction, ANIM +from .. import armature + +import bpy +import bpy.path +import re +import struct +from mathutils import Vector, Quaternion, Euler + +# Actor data class +class SACTData(bpy.types.PropertyGroup): + + subtypes: bpy.props.CollectionProperty(type=SACTSubtype.SACTSubtype, name="Actor Subtype List") + active_subtype: bpy.props.IntProperty(name="Active Actor Subtype", default=0, update=SACTSubtype.active_subtype_update) + show_subtypes: bpy.props.BoolProperty() + + attachments: bpy.props.CollectionProperty(type=SACTSubtype.SACTAttachment, name="Attachment List") + active_attachment: bpy.props.IntProperty(name="Active Attachment", default=0, update=SACTSubtype.active_subtype_update) + + actions: bpy.props.CollectionProperty(type=SACTAction.SACTAction, name="Actor Action List") + active_action: bpy.props.IntProperty(name="Active Actor Action", default=0, update=SACTAction.active_action_update) + show_actions: bpy.props.BoolProperty() + +# Regex RNA path matchers +scale_matcher = re.compile(r'pose.bones\["(\S+)"\].scale') +rotation_matcher = re.compile(r'pose.bones\["(\S+)"\].rotation') +location_matcher = re.compile(r'pose.bones\["(\S+)"\].location') + +def write_action_channels(writebuf, action): + # Set of frame indices + frame_set = set() + + # Set of unique bone names + bone_set = [] + + # Scan through all fcurves to build animated bone set + for fcurve in action.fcurves: + data_path = fcurve.data_path + scale_match = scale_matcher.match(data_path) + rotation_match = rotation_matcher.match(data_path) + location_match = location_matcher.match(data_path) + + if scale_match: + if scale_match.group(1) not in bone_set: + bone_set.append(scale_match.group(1)) + elif rotation_match: + if rotation_match.group(1) not in bone_set: + bone_set.append(rotation_match.group(1)) + elif location_match: + if location_match.group(1) not in bone_set: + bone_set.append(location_match.group(1)) + else: + continue + + # Count unified keyframes for interleaving channel data + for key in fcurve.keyframe_points: + frame_set.add(int(key.co[0])) + + # Build bone table + bone_list = [] + for bone in bone_set: + fc_dict = dict() + rotation_mode = None + property_bits = 0 + for fcurve in action.fcurves: + if fcurve.data_path == 'pose.bones["'+bone+'"].scale': + if 'scale' not in fc_dict: + fc_dict['scale'] = [None, None, None] + property_bits |= 4 + fc_dict['scale'][fcurve.array_index] = fcurve + elif fcurve.data_path == 'pose.bones["'+bone+'"].rotation_euler': + if 'rotation_euler' not in fc_dict: + fc_dict['rotation_euler'] = [None, None, None] + rotation_mode = 'rotation_euler' + property_bits |= 1 + fc_dict['rotation_euler'][fcurve.array_index] = fcurve + elif fcurve.data_path == 'pose.bones["'+bone+'"].rotation_quaternion': + if 'rotation_quaternion' not in fc_dict: + fc_dict['rotation_quaternion'] = [None, None, None, None] + rotation_mode = 'rotation_quaternion' + property_bits |= 1 + fc_dict['rotation_quaternion'][fcurve.array_index] = fcurve + elif fcurve.data_path == 'pose.bones["'+bone+'"].rotation_axis_angle': + if 'rotation_axis_angle' not in fc_dict: + fc_dict['rotation_axis_angle'] = [None, None, None, None] + rotation_mode = 'rotation_axis_angle' + property_bits |= 1 + fc_dict['rotation_axis_angle'][fcurve.array_index] = fcurve + elif fcurve.data_path == 'pose.bones["'+bone+'"].location': + if 'location' not in fc_dict: + fc_dict['location'] = [None, None, None] + property_bits |= 2 + fc_dict['location'][fcurve.array_index] = fcurve + bone_list.append((bone, rotation_mode, fc_dict, property_bits)) + + # Write out frame indices + sorted_frames = sorted(frame_set) + writebuf(struct.pack('I', len(sorted_frames))) + for frame in sorted_frames: + writebuf(struct.pack('i', frame)) + + # Interleave / interpolate keyframe data + writebuf(struct.pack('I', len(bone_list))) + for bone in bone_list: + + bone_name = bone[0] + rotation_mode = bone[1] + fc_dict = bone[2] + property_bits = bone[3] + + writebuf(struct.pack('I', len(bone_name))) + writebuf(bone_name.encode()) + + writebuf(struct.pack('I', property_bits)) + + writebuf(struct.pack('I', len(sorted_frames))) + for frame in sorted_frames: + + # Rotation curves + if rotation_mode == 'rotation_quaternion': + quat = [0.0]*4 + for comp in range(4): + if fc_dict['rotation_quaternion'][comp]: + quat[comp] = fc_dict['rotation_quaternion'][comp].evaluate(frame) + quat = Quaternion(quat).normalized() + writebuf(struct.pack('ffff', quat[0], quat[1], quat[2], quat[3])) + + elif rotation_mode == 'rotation_euler': + euler = [0.0]*3 + for comp in range(3): + if fc_dict['rotation_euler'][comp]: + euler[comp] = fc_dict['rotation_euler'][comp].evaluate(frame) + euler_o = Euler(euler, 'XYZ') + quat = euler_o.to_quaternion() + writebuf(struct.pack('ffff', quat[0], quat[1], quat[2], quat[3])) + + elif rotation_mode == 'rotation_axis_angle': + axis_angle = [0.0]*4 + for comp in range(4): + if fc_dict['rotation_axis_angle'][comp]: + axis_angle[comp] = fc_dict['rotation_axis_angle'][comp].evaluate(frame) + quat = Quaternion(axis_angle[1:4], axis_angle[0]) + writebuf(struct.pack('ffff', quat[0], quat[1], quat[2], quat[3])) + + # Location curves + if 'location' in fc_dict: + writevec = [0.0]*3 + for comp in range(3): + if fc_dict['location'][comp]: + writevec[comp] = fc_dict['location'][comp].evaluate(frame) + writebuf(struct.pack('fff', writevec[0], writevec[1], writevec[2])) + + # Scale curves + if 'scale' in fc_dict: + writevec = [1.0]*3 + for comp in range(3): + if fc_dict['scale'][comp]: + writevec[comp] = fc_dict['scale'][comp].evaluate(frame) + writebuf(struct.pack('fff', writevec[0], writevec[1], writevec[2])) + + +def write_action_aabb(writebuf, arm_obj, mesh_obj, action): + scene = bpy.context.scene + + # Mute root channels + for fcurve in action.fcurves: + fcurve.mute = fcurve.data_path == 'pose.bones["root"].location' + + # Transform against root + root_bone = arm_obj.pose.bones['root'] + root_bone.location = (0.0,0.0,0.0) + if root_bone.rotation_mode == 'QUATERNION': + root_bone.rotation_quaternion = (1.0,0.0,0.0,0.0) + else: + root_bone.rotation_euler = (0.0,0.0,0.0) + + # Frame 1 + scene.frame_set(1) + + root_aabb_min = Vector(mesh_obj.bound_box[0]) + root_aabb_max = Vector(mesh_obj.bound_box[6]) + + # Accumulate AABB for each frame + for frame_idx in range(2, scene.frame_end + 1): + scene.frame_set(frame_idx) + + test_aabb_min = Vector(mesh_obj.bound_box[0]) + test_aabb_max = Vector(mesh_obj.bound_box[6]) + + for comp in range(3): + if test_aabb_min[comp] < root_aabb_min[comp]: + root_aabb_min[comp] = test_aabb_min[comp] + for comp in range(3): + if test_aabb_max[comp] > root_aabb_max[comp]: + root_aabb_max[comp] = test_aabb_max[comp] + + # Unmute root channels + for fcurve in action.fcurves: + fcurve.mute = False + + writebuf(struct.pack('ffffff', + root_aabb_min[0], root_aabb_min[1], root_aabb_min[2], + root_aabb_max[0], root_aabb_max[1], root_aabb_max[2])) + +def _out_armatures(sact_data, writebuf): + writebuf(struct.pack('I', len(bpy.data.armatures))) + for arm in bpy.data.armatures: + writebuf(struct.pack('I', len(arm.name))) + writebuf(arm.name.encode()) + + if arm.library: + arm_path = bpy.path.abspath(arm.library.filepath) + writebuf(struct.pack('I', len(arm_path))) + writebuf(arm_path.encode()) + else: + writebuf(struct.pack('I', 0)) + + armature.cook(writebuf, arm) + +def _out_subtypes(sact_data, writebuf): + writebuf(struct.pack('I', len(sact_data.subtypes))) + for subtype in sact_data.subtypes: + writebuf(struct.pack('I', len(subtype.name))) + writebuf(subtype.name.encode()) + + mesh = None + if subtype.linked_mesh in bpy.data.objects: + mesh = bpy.data.objects[subtype.linked_mesh] + cskr_id = mesh.data.cskr_id + writebuf(struct.pack('I', len(cskr_id))) + writebuf(cskr_id.encode()) + else: + writebuf(struct.pack('I', 0)) + + if mesh and mesh.data.library: + mesh_path = bpy.path.abspath(mesh.data.library.filepath) + writebuf(struct.pack('I', len(mesh_path))) + writebuf(mesh_path.encode()) + else: + writebuf(struct.pack('I', 0)) + + arm = None + if subtype.linked_armature in bpy.data.objects: + arm = bpy.data.objects[subtype.linked_armature] + + arm_idx = -1 + if arm: + arm_idx = bpy.data.armatures.find(arm.name) + writebuf(struct.pack('i', arm_idx)) + + writebuf(struct.pack('I', len(subtype.overlays))) + for overlay in subtype.overlays: + writebuf(struct.pack('I', len(overlay.name))) + writebuf(overlay.name.encode()) + + mesh = None + if overlay.linked_mesh in bpy.data.objects: + mesh = bpy.data.objects[overlay.linked_mesh] + cskr_id = mesh.data.cskr_id + writebuf(struct.pack('I', len(cskr_id))) + writebuf(cskr_id.encode()) + else: + writebuf(struct.pack('I', 0)) + + if mesh and mesh.data.library: + mesh_path = bpy.path.abspath(mesh.data.library.filepath) + writebuf(struct.pack('I', len(mesh_path))) + writebuf(mesh_path.encode()) + else: + writebuf(struct.pack('I', 0)) + +def _out_attachments(sact_data, writebuf): + writebuf(struct.pack('I', len(sact_data.attachments))) + for attachment in sact_data.attachments: + writebuf(struct.pack('I', len(attachment.name))) + writebuf(attachment.name.encode()) + + mesh = None + if attachment.linked_mesh in bpy.data.objects: + mesh = bpy.data.objects[attachment.linked_mesh] + cskr_id = mesh.data.cskr_id + writebuf(struct.pack('I', len(cskr_id))) + writebuf(cskr_id.encode()) + else: + writebuf(struct.pack('I', 0)) + + if mesh and mesh.data.library: + mesh_path = bpy.path.abspath(mesh.data.library.filepath) + writebuf(struct.pack('I', len(mesh_path))) + writebuf(mesh_path.encode()) + else: + writebuf(struct.pack('I', 0)) + + arm = None + if attachment.linked_armature in bpy.data.objects: + arm = bpy.data.objects[attachment.linked_armature] + + arm_idx = -1 + if arm: + arm_idx = bpy.data.armatures.find(arm.name) + writebuf(struct.pack('i', arm_idx)) + +def _out_actions(sact_data, writebuf): + writebuf(struct.pack('I', len(sact_data.actions))) + for action_idx in range(len(sact_data.actions)): + sact_data.active_action = action_idx + action = sact_data.actions[action_idx] + writebuf(struct.pack('I', len(action.name))) + writebuf(action.name.encode()) + + bact = None + if action.name in bpy.data.actions: + bact = bpy.data.actions[action.name] + anim_id = bact.anim_id + writebuf(struct.pack('I', len(anim_id))) + writebuf(anim_id.encode()) + if not bact: + raise RuntimeError('action %s not found' % action.name) + + writebuf(struct.pack('f', 1.0 / bact.hecl_fps)) + writebuf(struct.pack('b', int(bact.hecl_additive))) + writebuf(struct.pack('b', int(bact.hecl_looping))) + + write_action_channels(writebuf, bact) + writebuf(struct.pack('I', len(sact_data.subtypes))) + for subtype_idx in range(len(sact_data.subtypes)): + subtype = sact_data.subtypes[subtype_idx] + sact_data.active_subtype = subtype_idx + bpy.ops.scene.sactaction_load() + if subtype.linked_armature not in bpy.data.objects: + raise RuntimeError('armature %s not found' % subtype.linked_armature) + arm = bpy.data.objects[subtype.linked_armature] + if subtype.linked_mesh not in bpy.data.objects: + raise RuntimeError('mesh %s not found' % subtype.linked_mesh) + mesh = bpy.data.objects[subtype.linked_mesh] + write_action_aabb(writebuf, arm, mesh, bact) + +def _out_action_no_subtypes(sact_data, writebuf, action_name): + for action_idx in range(len(sact_data.actions)): + action = sact_data.actions[action_idx] + if action.name == action_name: + sact_data.active_action = action_idx + writebuf(struct.pack('I', len(action.name))) + writebuf(action.name.encode()) + + bact = None + if action.name in bpy.data.actions: + bact = bpy.data.actions[action.name] + anim_id = bact.anim_id + writebuf(struct.pack('I', len(anim_id))) + writebuf(anim_id.encode()) + if not bact: + raise RuntimeError('action %s not found' % action.name) + + writebuf(struct.pack('f', 1.0 / bact.hecl_fps)) + writebuf(struct.pack('b', int(bact.hecl_additive))) + writebuf(struct.pack('b', int(bact.hecl_looping))) + + write_action_channels(writebuf, bact) + writebuf(struct.pack('I', 0)) + return + + raise RuntimeError("Unable to find action '%s'" % action_name) + +# Cook +def cook(writebuf): + bpy.context.scene.hecl_auto_remap = False + sact_data = bpy.context.scene.hecl_sact_data + + # Output armatures + _out_armatures(sact_data, writebuf) + + # Output subtypes + _out_subtypes(sact_data, writebuf) + + # Output attachments + _out_attachments(sact_data, writebuf) + + # Output actions + _out_actions(sact_data, writebuf) + +# Cook Character Data only +def cook_character_only(writebuf): + sact_data = bpy.context.scene.hecl_sact_data + + # Output armatures + _out_armatures(sact_data, writebuf) + + # Output subtypes + _out_subtypes(sact_data, writebuf) + + # Output attachments + _out_attachments(sact_data, writebuf) + + # Output no actions + writebuf(struct.pack('I', 0)) + +def cook_action_channels_only(writebuf, action_name): + sact_data = bpy.context.scene.hecl_sact_data + + # Output action without AABBs + _out_action_no_subtypes(sact_data, writebuf, action_name) + +# Access actor's contained subtype names +def get_subtype_names(writebuf): + sact_data = bpy.context.scene.hecl_sact_data + writebuf(struct.pack('I', len(sact_data.subtypes))) + for sub_idx in range(len(sact_data.subtypes)): + subtype = sact_data.subtypes[sub_idx] + writebuf(struct.pack('I', len(subtype.name))) + writebuf(subtype.name.encode()) + obj = bpy.data.objects[subtype.linked_mesh] + cskr_id = obj.data.cskr_id + writebuf(struct.pack('I', len(cskr_id))) + writebuf(cskr_id.encode()) + +# Access subtype's contained overlay names +def get_subtype_overlay_names(writebuf, subtypeName): + sact_data = bpy.context.scene.hecl_sact_data + for sub_idx in range(len(sact_data.subtypes)): + subtype = sact_data.subtypes[sub_idx] + if subtype.name == subtypeName: + writebuf(struct.pack('I', len(subtype.overlays))) + for overlay in subtype.overlays: + writebuf(struct.pack('I', len(overlay.name))) + writebuf(overlay.name.encode()) + obj = bpy.data.objects[overlay.linked_mesh] + cskr_id = obj.data.cskr_id + writebuf(struct.pack('I', len(cskr_id))) + writebuf(cskr_id.encode()) + return + writebuf(struct.pack('I', 0)) + +# Access contained attachment names +def get_attachment_names(writebuf): + sact_data = bpy.context.scene.hecl_sact_data + writebuf(struct.pack('I', len(sact_data.attachments))) + for att_idx in range(len(sact_data.attachments)): + attachment = sact_data.attachments[att_idx] + writebuf(struct.pack('I', len(attachment.name))) + writebuf(attachment.name.encode()) + obj = bpy.data.objects[attachment.linked_mesh] + cskr_id = obj.data.cskr_id + writebuf(struct.pack('I', len(cskr_id))) + writebuf(cskr_id.encode()) + +# Access actor's contained action names +def get_action_names(writebuf): + sact_data = bpy.context.scene.hecl_sact_data + writebuf(struct.pack('I', len(sact_data.actions))) + for action_idx in range(len(sact_data.actions)): + action = sact_data.actions[action_idx] + writebuf(struct.pack('I', len(action.name))) + writebuf(action.name.encode()) + anim_id = bpy.data.actions[action.name].anim_id + writebuf(struct.pack('I', len(anim_id))) + writebuf(anim_id.encode()) + +# Panel draw +def draw(layout, context): + SACTSubtype.draw(layout.box(), context) + SACTAction.draw(layout.box(), context) + + +# Time-remap option update +def time_remap_update(self, context): + if context.scene.hecl_type == 'ACTOR': + SACTAction.active_action_update(self, context) + + +# Registration +def register(): + SACTSubtype.register() + SACTAction.register() + bpy.utils.register_class(SACTData) + bpy.types.Scene.hecl_sact_data = bpy.props.PointerProperty(type=SACTData) + bpy.types.Action.anim_id = bpy.props.StringProperty(name='Original ANIM ID') + bpy.types.Action.hecl_fps = bpy.props.IntProperty(name='HECL Action FPS', default=30) + bpy.types.Action.hecl_additive = bpy.props.BoolProperty(name='HECL Additive Action', default=False) + bpy.types.Action.hecl_looping = bpy.props.BoolProperty(name='HECL Looping Action', default=False) + bpy.types.Scene.hecl_auto_remap = bpy.props.BoolProperty(name="Auto Remap", + description="Enables automatic 60-fps time-remapping for playback-validation purposes", + default=True, update=time_remap_update) + +def unregister(): + bpy.utils.unregister_class(SACTData) + SACTSubtype.unregister() + SACTAction.unregister() diff --git a/hecl/blender/hecl/srea/__init__.py b/hecl/blender/hecl/srea/__init__.py new file mode 100644 index 000000000..043d1d5ae --- /dev/null +++ b/hecl/blender/hecl/srea/__init__.py @@ -0,0 +1,490 @@ +import bpy +from bpy.app.handlers import persistent +from mathutils import Quaternion, Color +import math +import os.path +from .. import swld + +# Preview update func (for lighting preview) +def preview_update(self, context): + if context.scene.hecl_type == 'AREA': + area_data = context.scene.hecl_srea_data + + # Original Lightmaps + if area_data.lightmap_mode == 'ORIGINAL': + for material in bpy.data.materials: + if material.hecl_lightmap and 'Lightmap' in material.node_tree.nodes: + lm_node = material.node_tree.nodes['Lightmap'] + # Reference original game lightmaps + if material.hecl_lightmap in bpy.data.images: + lm_node.image = bpy.data.images[material.hecl_lightmap] + else: + lm_node.image = None + + # Cycles Lightmaps + elif area_data.lightmap_mode == 'CYCLES': + for material in bpy.data.materials: + if material.hecl_lightmap and 'Lightmap' in material.node_tree.nodes: + lm_node = material.node_tree.nodes['Lightmap'] + # Reference newly-generated lightmaps + img_name = material.hecl_lightmap + '_CYCLES' + if img_name in bpy.data.images: + lm_node.image = bpy.data.images[img_name] + else: + lm_node.image = None + + # White Lightmaps + elif area_data.lightmap_mode == 'NONE': + img_name = 'NONE' + img = None + if img_name in bpy.data.images: + img = bpy.data.images[img_name] + else: + img = bpy.data.images.new(img_name, width=1, height=1) + pixels = [1.0] * (4 * 1 * 1) + img.pixels = pixels + img.use_fake_user = True + img.file_format = 'PNG' + + for material in bpy.data.materials: + if material.hecl_lightmap and 'Lightmap' in material.node_tree.nodes: + lm_node = material.node_tree.nodes['Lightmap'] + # Reference NONE + lm_node.image = img + + +# Update lightmap output-resolution +def set_lightmap_resolution(self, context): + area_data = context.scene.hecl_srea_data + pixel_size = int(area_data.lightmap_resolution) + for mat in bpy.data.materials: + if not mat.hecl_lightmap: + continue + + # Determine proportional aspect + old_image = bpy.data.images[mat.hecl_lightmap] + width_fac = 1 + height_fac = 1 + if old_image.size[0] > old_image.size[1]: + height_fac = old_image.size[0] // old_image.size[1] + else: + width_fac = old_image.size[1] // old_image.size[0] + width = pixel_size // width_fac + height = pixel_size // height_fac + + # Find target texture and scale connected image + if 'CYCLES_OUT' in mat.node_tree.nodes: + out_node = mat.node_tree.nodes['CYCLES_OUT'] + if out_node.type == 'TEX_IMAGE': + image = out_node.image + if image: + image.scale(width, height) + +def make_or_load_cycles_image(mat, area_data): + if not mat.hecl_lightmap: + return + pixel_size = int(area_data.lightmap_resolution) + tex_name = mat.hecl_lightmap + '_CYCLES' + if area_data.adjacent_area < 0: + path_name = '//' + mat.hecl_lightmap + '_CYCLES.png' + else: + path_name = '//' + mat.hecl_lightmap + '_CYCLES_%d.png' % area_data.adjacent_area + + # Determine proportional aspect + old_image = bpy.data.images[mat.hecl_lightmap] + width_fac = 1 + height_fac = 1 + if old_image.size[0] > old_image.size[1]: + height_fac = old_image.size[0] // old_image.size[1] + else: + width_fac = old_image.size[1] // old_image.size[0] + width = pixel_size // width_fac + height = pixel_size // height_fac + + # Check for consistency with on-disk image + if tex_name in bpy.data.images: + image = bpy.data.images[tex_name] + image.use_fake_user = True + image.file_format = 'PNG' + image.filepath = path_name + good = True + if image.size[0] != width or image.size[1] != height: + try: + image.scale(width, height) + except: + good = False + if good: + return image + # Remove and recreate if we get here + bpy.data.images.remove(bpy.data.images[tex_name]) + + # New image (or load from disk if available) + try: + new_image = bpy.data.images.load(path_name) + new_image.name = tex_name + new_image.use_fake_user = True + if new_image.size[0] != width or new_image.size[1] != height: + new_image.scale(width, height) + except: + new_image = bpy.data.images.new(tex_name, width, height) + new_image.use_fake_user = True + new_image.file_format = 'PNG' + new_image.filepath = path_name + + return new_image + +# Set adjacent area lightmaps +def set_adjacent_area(self, context): + bg_scene = context.scene.background_set + dock_idx = context.scene.hecl_srea_data.adjacent_area + if bg_scene is None: + self.report({'ERROR_INVALID_CONTEXT'}, 'No background world scene is set') + return + + if bg_scene.hecl_type != 'WORLD': + self.report({'ERROR_INVALID_CONTEXT'}, 'Scene "%s" is not a hecl WORLD' % bg_scene.name) + return + + adjacent = dock_idx >= 0 + if len(context.scene.render.layers): + context.scene.view_layers[0].use_sky = not adjacent + + # Remove linked lamps and show/hide locals + for obj in bpy.data.objects: + if obj.library is not None and (obj.type == 'LIGHT' or obj.type == 'MESH'): + try: + context.scene.collection.children.unlink(obj) + except: + pass + continue + if obj.type == 'LIGHT': + obj.hide_render = adjacent + + # Remove linked scenes + to_remove = [] + for scene in bpy.data.scenes: + if scene.hecl_type == 'AREA' and scene.library is not None: + to_remove.append(scene) + for scene in to_remove: + bpy.data.scenes.remove(scene) + + # Link scene, meshes, and lamps + if dock_idx >= 0: + other_area_name = get_other_area_name(self, bg_scene, dock_idx) + if other_area_name is None: + return + other_area_scene_name = None + this_dir = os.path.split(bpy.data.filepath)[0] + try: + with bpy.data.libraries.load('%s/../%s/!area.blend' % (this_dir, other_area_name), + link=True, relative=True) as (data_from, data_to): + for scene in data_from.scenes: + other_area_scene_name = scene + data_to.scenes = [other_area_scene_name] + break + except Exception as e: + self.report({'ERROR_INVALID_CONTEXT'}, 'Unable to open "%s" blend file: %s' % (other_area_name, str(e))) + return + if other_area_scene_name is None: + self.report({'ERROR_INVALID_CONTEXT'}, '"%s" does not have an area scene' % other_area_name) + return + other_scene = bpy.data.scenes[other_area_scene_name] + if other_scene.hecl_type != 'AREA': + self.report({'ERROR_INVALID_CONTEXT'}, '"%s" does not have an area scene' % other_area_name) + bpy.data.scenes.remove(other_scene) + return + for obj in other_scene.objects: + if (obj.type == 'LIGHT' or obj.type == 'MESH') and obj.layers[0]: + context.scene.collection.objects.link(obj) + obj.hide_render = False + + # Ensure filepaths target the current dock index + for mat in bpy.data.materials: + if not mat.library and mat.use_nodes and 'CYCLES_OUT' in mat.node_tree.nodes: + texture_node = mat.node_tree.nodes['CYCLES_OUT'] + texture_node.image = make_or_load_cycles_image(mat, context.scene.hecl_srea_data) + +# Area data class +class SREAData(bpy.types.PropertyGroup): + lightmap_resolution: bpy.props.EnumProperty(name="HECL Area Lightmap Resolution", + description="Set square resolution to use when rendering new lightmaps", + items=[ + ('256', "256", "256x256 (original quality)"), + ('512', "512", "512x512"), + ('1024', "1024", "1024x1024"), + ('2048', "2048", "2048x2048"), + ('4096', "4096", "4096x4096")], + update=set_lightmap_resolution, + default='1024') + + lightmap_mode: bpy.props.EnumProperty(name="HECL Area Lightmap Mode", + description="Simple way to manipulate all lightmap-using materials", + items=[ + ('NONE', "None", "Pure white lightmaps"), + ('ORIGINAL', "Original", "Original extracted lightmaps"), + ('CYCLES', "Cycles", "Blender-rendered lightmaps")], + update=preview_update, + default='ORIGINAL') + + adjacent_area: bpy.props.IntProperty(name="HECL Adjacent Area Lightmap", + description="Dock index of adjacent area to render, or -1 for local lights", + update=set_adjacent_area, + default=-1, + min=-1, + max=8) + + def report(self, code, string): + pass + +# Trace color output searching for material node and making list from it +def recursive_build_material_chain(node): + if node.type == 'OUTPUT': + if node.inputs[0].is_linked: + ret = recursive_build_material_chain(node.inputs[0].links[0].from_node) + if ret: + ret.append(node) + return ret + elif node.type == 'MIX_RGB': + if node.inputs[1].is_linked: + ret = recursive_build_material_chain(node.inputs[1].links[0].from_node) + if ret: + ret.append(node) + return ret + if node.inputs[2].is_linked: + ret = recursive_build_material_chain(node.inputs[2].links[0].from_node) + if ret: + ret.append(node) + return ret + elif node.type == 'MATERIAL': + return [node] + return None + +# Get Diffuse and Emissive output sockets from chain +def get_de_sockets(chain): + found_add = None + found_mul = None + n = None + for nn in reversed(chain): + if not n: + n = nn + continue + if n.type == 'MIX_RGB': + if not found_add and n.blend_type == 'ADD' and nn.type != 'MATERIAL': + use_idx = 1 + if n.inputs[1].is_linked: + tn = n.inputs[1].links[0].from_node + if tn == nn: + use_idx = 2 + if n.inputs[use_idx].is_linked: + found_add = n.inputs[use_idx].links[0].from_socket + found_mul = None + elif n.blend_type == 'MULTIPLY': + use_idx = 1 + if n.inputs[1].is_linked: + tn = n.inputs[1].links[0].from_node + if tn == nn: + use_idx = 2 + if n.inputs[use_idx].is_linked: + found_mul = n.inputs[use_idx].links[0].from_socket + n = nn + + return found_mul, found_add + +# Lookup the directory name of other area via dock link +def get_other_area_name(op, bg_scene, dock_idx): + dock_conns = swld.build_dock_connections(bg_scene) + this_dir = os.path.split(bpy.data.filepath)[0] + this_area_name = os.path.basename(this_dir) + wld_area = next((area for area in dock_conns[0] if area[0].name == this_area_name), None) + if wld_area is None: + op.report({'ERROR_INVALID_CONTEXT'}, 'Unable to resolve area in world') + return None + if dock_idx not in range(len(wld_area[1])): + op.report({'ERROR_INVALID_CONTEXT'}, 'Dock %d is out of this area\'s range [0,%d]' % + (dock_idx, len(wld_area[1]))) + return None + dock_obj = wld_area[1][dock_idx] + if dock_obj.name not in dock_conns[1]: + op.report({'ERROR_INVALID_CONTEXT'}, 'Unable to find sister dock for %s' % dock_obj.name) + return None + other_wld_area = dock_conns[1][dock_obj.name][2].parent + if other_wld_area is None: + op.report({'ERROR_INVALID_CONTEXT'}, '%s does not have a parent area' % dock_obj.name) + return None + return other_wld_area.name + +# Shared lightmap render procedure +def render_lightmaps(context): + if context.scene is not None: + area_data = context.scene.hecl_srea_data + + # Resolution + pixel_size = int(area_data.lightmap_resolution) + + # Mmm Cycles + context.scene.render.engine = 'CYCLES' + context.scene.render.bake.margin = pixel_size // 256 + + # Iterate materials and setup cycles + for mat in bpy.data.materials: + if mat.use_nodes: + # Set bake target node active + if 'CYCLES_OUT' in mat.node_tree.nodes: + mat.node_tree.nodes.active = mat.node_tree.nodes['CYCLES_OUT'] + elif mat.hecl_lightmap and not mat.library: + image_out_node = mat.node_tree.nodes.new('ShaderNodeTexImage') + mat.node_tree.nodes.active = image_out_node + image_out_node.name = 'CYCLES_OUT' + image_out_node.image = make_or_load_cycles_image(mat, area_data) + else: + image_out_node = mat.node_tree.nodes.new('ShaderNodeTexImage') + mat.node_tree.nodes.active = image_out_node + image_out_node.name = 'CYCLES_OUT' + if 'FAKE' in bpy.data.images: + image_out_node.image = bpy.data.images['FAKE'] + else: + fake_img = bpy.data.images.new('FAKE', 1, 1) + image_out_node.image = fake_img + + # Iterate mesh objects and set UV 0 as the active UV layer + for obj in context.scene.objects: + if obj.type == 'MESH': + + if not len(obj.data.uv_layers): + continue + + # Make correct UV layer active + obj.data.uv_layers.active_index = 0 + + # Make lightmaps + bpy.ops.object.bake('INVOKE_DEFAULT', type='DIFFUSE', pass_filter={'AO', 'DIRECT', 'INDIRECT'}) + +# Lightmap render operator +class SREARenderLightmaps(bpy.types.Operator): + bl_idname = "scene.hecl_area_render_lightmaps" + bl_label = "HECL Render New Lightmaps" + bl_description = "Bake new lightmaps for HECL runtime" + + @classmethod + def poll(cls, context): + return context.scene is not None + + def execute(self, context): + if not context.selected_objects: + for obj in context.scene.objects: + if obj.type == 'MESH' and not obj.library: + obj.select_set(True) + context.view_layer.objects.active = obj + + render_lightmaps(context) + + return {'FINISHED'} + +def shadeless_material(idx): + name = 'SHADELESS_MAT_%d' % idx + if name in bpy.data.materials: + return bpy.data.materials[name] + mat = bpy.data.materials.new(name) + r = idx % 256 + g = (idx % 65536) // 256 + b = idx // 65536 + mat.diffuse_color = Color((r / 255.0, g / 255.0, b / 255.0)) + return mat + +look_forward = Quaternion((1.0, 0.0, 0.0), math.radians(90.0)) +look_backward = Quaternion((0.0, 0.0, 1.0), math.radians(180.0)) @ Quaternion((1.0, 0.0, 0.0), math.radians(90.0)) +look_up = Quaternion((1.0, 0.0, 0.0), math.radians(180.0)) +look_down = Quaternion((1.0, 0.0, 0.0), math.radians(0.0)) +look_left = Quaternion((0.0, 0.0, 1.0), math.radians(90.0)) @ Quaternion((1.0, 0.0, 0.0), math.radians(90.0)) +look_right = Quaternion((0.0, 0.0, 1.0), math.radians(-90.0)) @ Quaternion((1.0, 0.0, 0.0), math.radians(90.0)) +look_list = (look_forward, look_backward, look_up, look_down, look_left, look_right) + +# Render PVS for location +def render_pvs(pathOut, location): + bpy.context.scene.render.resolution_x = 256 + bpy.context.scene.render.resolution_y = 256 + bpy.context.scene.render.resolution_percentage = 100 + bpy.context.scene.render.use_antialiasing = False + bpy.context.scene.render.use_textures = False + bpy.context.scene.render.use_shadows = False + bpy.context.scene.render.use_sss = False + bpy.context.scene.render.use_envmaps = False + bpy.context.scene.render.use_raytrace = False + bpy.context.scene.display_settings.display_device = 'None' + bpy.context.scene.render.image_settings.file_format = 'PNG' + bpy.context.scene.world.horizon_color = Color((1.0, 1.0, 1.0)) + bpy.context.scene.world.zenith_color = Color((1.0, 1.0, 1.0)) + + cam = bpy.data.cameras.new('CUBIC_CAM') + cam_obj = bpy.data.objects.new('CUBIC_CAM', cam) + bpy.context.scene.collection.objects.link(cam_obj) + bpy.context.scene.camera = cam_obj + cam.lens_unit = 'FOV' + cam.angle = math.radians(90.0) + + mat_idx = 0 + for obj in bpy.context.scene.objects: + if obj.type == 'MESH': + if obj.name == 'CMESH': + continue + mat = shadeless_material(mat_idx) + for slot in obj.material_slots: + slot.material = mat + mat_idx += 1 + + cam_obj.location = location + cam_obj.rotation_mode = 'QUATERNION' + + for i in range(6): + cam_obj.rotation_quaternion = look_list[i] + bpy.context.scene.render.filepath = '%s%d' % (pathOut, i) + bpy.ops.render.render(write_still=True) + + bpy.context.scene.camera = None + #bpy.context.scene.objects.unlink(cam_obj) + bpy.data.objects.remove(cam_obj) + bpy.data.cameras.remove(cam) + +# Render PVS for light +def render_pvs_light(pathOut, lightName): + if lightName not in bpy.context.scene.objects: + raise RuntimeError('Unable to find light %s' % lightName) + render_pvs(pathOut, bpy.context.scene.objects[lightName].location) + +# Cook +def cook(writebuffunc, platform, endianchar): + print('COOKING SREA') + +# Panel draw +def draw(layout, context): + area_data = context.scene.hecl_srea_data + layout.label(text="Lighting:", icon='LIGHT') + light_row = layout.row(align=True) + light_row.prop_enum(area_data, 'lightmap_mode', 'NONE') + light_row.prop_enum(area_data, 'lightmap_mode', 'ORIGINAL') + light_row.prop_enum(area_data, 'lightmap_mode', 'CYCLES') + layout.prop(area_data, 'lightmap_resolution', text="Resolution") + layout.popover("CYCLES_PT_sampling_presets", text=bpy.types.CYCLES_PT_sampling_presets.bl_label) + layout.prop(context.scene.render.bake, "use_clear", text="Clear Before Baking") + layout.prop(area_data, 'adjacent_area', text='Adjacent Dock Index', icon='MOD_OPACITY') + layout.operator("scene.hecl_area_render_lightmaps", text="Bake Cycles Lightmaps", icon='RENDER_STILL') + layout.operator("image.save_dirty", text="Save Lightmaps", icon='FILE_TICK') + + +# Load scene callback +@persistent +def scene_loaded(dummy): + preview_update(None, bpy.context) + +# Registration +def register(): + bpy.utils.register_class(SREAData) + bpy.utils.register_class(SREARenderLightmaps) + bpy.types.Scene.hecl_srea_data = bpy.props.PointerProperty(type=SREAData) + bpy.types.Material.hecl_lightmap = bpy.props.StringProperty(name='HECL: Lightmap Base Name') + bpy.app.handlers.load_post.append(scene_loaded) + +def unregister(): + bpy.utils.unregister_class(SREAData) + bpy.utils.unregister_class(SREARenderLightmaps) + diff --git a/hecl/blender/hecl/swld/__init__.py b/hecl/blender/hecl/swld/__init__.py new file mode 100644 index 000000000..d656e2b8a --- /dev/null +++ b/hecl/blender/hecl/swld/__init__.py @@ -0,0 +1,79 @@ +import bpy, struct +from mathutils import Vector + +def build_dock_connections(scene): + areas = [] + docks = [] + + for obj in sorted(scene.objects, key=lambda x: x.name): + if obj.type == 'MESH' and obj.parent is None: + dock_list = [] + for ch in obj.children: + if ch.type == 'MESH': + docks.append((len(areas), len(dock_list), ch)) + dock_list.append(ch) + areas.append((obj, dock_list)) + + dock_dict = dict() + + for dockA in docks: + mtxA = dockA[2].matrix_world + locA = Vector((mtxA[0][3], mtxA[1][3], mtxA[2][3])) + match = False + for dockB in docks: + if dockA == dockB: + continue + mtxB = dockB[2].matrix_world + locB = Vector((mtxB[0][3], mtxB[1][3], mtxB[2][3])) + if (locA - locB).magnitude < 0.1: + dock_dict[dockA[2].name] = dockB + match = True + break + #if not match: + # raise RuntimeError('No dock match for %s' % dockA[2].name) + + return (areas, dock_dict) + +# Cook +def cook(writebuf): + areas, dock_conns = build_dock_connections(bpy.context.scene) + writebuf(struct.pack('I', len(areas))) + for area in areas: + obj = area[0] + dock_list = area[1] + writebuf(struct.pack('I', len(obj.name))) + writebuf(obj.name.encode()) + + pt = Vector(obj.bound_box[0]) + writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) + pt = Vector(obj.bound_box[6]) + writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) + + wmtx = obj.matrix_world + writebuf(struct.pack('ffffffffffffffff', + wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3], + wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3], + wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3], + wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3])) + + wmtx_inv = wmtx.inverted() + + writebuf(struct.pack('I', len(dock_list))) + for ch in dock_list: + if len(ch.data.vertices) < 4: + raise RuntimeError('Not enough vertices in dock %s' % ch.name) + wmtx = wmtx_inv @ ch.matrix_world + for vi in range(4): + v = wmtx @ ch.data.vertices[vi].co + writebuf(struct.pack('fff', v[0], v[1], v[2])) + if ch.name in dock_conns: + conn_dock = dock_conns[ch.name] + writebuf(struct.pack('I', conn_dock[0])) + writebuf(struct.pack('I', conn_dock[1])) + else: + writebuf(struct.pack('I', 0xffffffff)) + writebuf(struct.pack('I', 0xffffffff)) + +# Panel draw +def draw(layout, context): + pass diff --git a/hecl/blender/hecl_blendershell.py b/hecl/blender/hecl_blendershell.py new file mode 100644 index 000000000..7af8a934f --- /dev/null +++ b/hecl/blender/hecl_blendershell.py @@ -0,0 +1,590 @@ +import bpy, sys, os, re, struct, traceback + +ARGS_PATTERN = re.compile(r'''(?:"([^"]+)"|'([^']+)'|(\S+))''') + +# Background mode seems to require quit() in some 2.80 builds +def _quitblender(): + bpy.ops.wm.quit_blender() + quit() + +MIN_BLENDER_MAJOR = 2 +MIN_BLENDER_MINOR = 83 +# Extract pipe file descriptors from arguments +print('HECL Blender Launch', sys.argv) +if '--' not in sys.argv: + _quitblender() +args = sys.argv[sys.argv.index('--')+1:] +readfd = int(args[0]) +writefd = int(args[1]) +verbosity_level = int(args[2]) +err_path = "" +if sys.platform == "win32": + import msvcrt + readfd = msvcrt.open_osfhandle(readfd, os.O_RDONLY | os.O_BINARY) + writefd = msvcrt.open_osfhandle(writefd, os.O_WRONLY | os.O_BINARY) + err_path = "/Temp" + if 'TEMP' in os.environ: + err_path = os.environ['TEMP'] +else: + err_path = "/tmp" + if 'TMPDIR' in os.environ: + err_path = os.environ['TMPDIR'] + +err_path += "/hecl_%016X.derp" % os.getpid() + +def readpipestr(): + read_bytes = os.read(readfd, 4) + if len(read_bytes) != 4: + print('HECL connection lost or desynchronized') + _quitblender() + read_len = struct.unpack('I', read_bytes)[0] + return os.read(readfd, read_len) + +def writepipestr(linebytes): + #print('LINE', linebytes) + os.write(writefd, struct.pack('I', len(linebytes))) + os.write(writefd, linebytes) + +def writepipebuf(linebytes): + #print('BUF', linebytes) + os.write(writefd, linebytes) + +def quitblender(): + writepipestr(b'QUITTING') + _quitblender() + +class PathHasher: + def hashpath32(self, path): + writepipestr(path.encode()) + read_str = readpipestr() + return int(read_str[0:8], 16) + +# Ensure Blender 2.83+ is being used +if bpy.app.version < (MIN_BLENDER_MAJOR, MIN_BLENDER_MINOR, 0): + writepipestr(b'INVALIDBLENDERVER') + _quitblender() + +# If there's a third argument, use it as the .zip path containing the addon +did_install = False +if len(args) >= 4 and args[3] != 'SKIPINSTALL': + bpy.ops.preferences.addon_install(overwrite=True, target='DEFAULT', filepath=args[3]) + bpy.ops.preferences.addon_refresh() + did_install = True + +# Make addon available to commands +if bpy.context.preferences.addons.find('hecl') == -1: + try: + bpy.ops.preferences.addon_enable(module='hecl') + bpy.ops.wm.save_userpref() + except: + pass +try: + import hecl +except: + writepipestr(b'NOADDON') + _quitblender() + +# Quit if just installed +if did_install: + writepipestr(b'ADDONINSTALLED') + _quitblender() + +# Intro handshake +writepipestr(b'READY') +ackbytes = readpipestr() +if ackbytes != b'ACK': + quitblender() + +# Count brackets +def count_brackets(linestr): + bracket_count = 0 + for ch in linestr: + if ch in {'[','{','('}: + bracket_count += 1 + elif ch in {']','}',')'}: + bracket_count -= 1 + return bracket_count + +# Read line of space-separated/quoted arguments +def read_cmdargs(): + cmdline = readpipestr() + if cmdline == b'': + print('HECL connection lost') + _quitblender() + cmdargs = [] + for match in ARGS_PATTERN.finditer(cmdline.decode()): + cmdargs.append(match.group(match.lastindex)) + return cmdargs + +# Complete sequences of statements compiled/executed here +def exec_compbuf(compbuf, globals): + if verbosity_level >= 3: + print(compbuf) + try: + co = compile(compbuf, '', 'exec') + exec(co, globals) + except Exception as e: + trace_prefix = 'Error processing:\n' + trace_prefix += compbuf + raise RuntimeError(trace_prefix) from e + +# Command loop for writing animation key data to blender +def animin_loop(globals): + writepipestr(b'ANIMREADY') + while True: + crv_type = struct.unpack('b', os.read(readfd, 1)) + if crv_type[0] < 0: + writepipestr(b'ANIMDONE') + return + elif crv_type[0] == 0: + crvs = globals['rotCurves'] + elif crv_type[0] == 1: + crvs = globals['transCurves'] + elif crv_type[0] == 2: + crvs = globals['scaleCurves'] + + key_info = struct.unpack('ii', os.read(readfd, 8)) + crv = crvs[key_info[0]] + crv.keyframe_points.add(count=key_info[1]) + + if crv_type[0] == 1: + for k in range(key_info[1]): + key_data = struct.unpack('if', os.read(readfd, 8)) + pt = crv.keyframe_points[k] + pt.interpolation = 'LINEAR' + pt.co = (key_data[0], key_data[1]) + else: + for k in range(key_info[1]): + key_data = struct.unpack('if', os.read(readfd, 8)) + pt = crv.keyframe_points[k] + pt.interpolation = 'LINEAR' + pt.co = (key_data[0], key_data[1]) + +def writelight(obj): + wmtx = obj.matrix_world + writepipebuf(struct.pack('ffffffffffffffff', + wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3], + wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3], + wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3], + wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3])) + writepipebuf(struct.pack('fff', obj.data.color[0], obj.data.color[1], obj.data.color[2])) + + type = 2 + spotCutoff = 0.0 + hasFalloff = False + castShadow = False + if obj.data.type == 'POINT': + type = 2 + hasFalloff = True + castShadow = obj.data.use_shadow + elif obj.data.type == 'SPOT': + type = 3 + hasFalloff = True + spotCutoff = obj.data.spot_size + castShadow = obj.data.use_shadow + elif obj.data.type == 'SUN': + type = 1 + castShadow = obj.data.use_shadow + + constant = 1.0 + linear = 0.0 + quadratic = 0.0 + if hasFalloff: + if obj.data.falloff_type == 'INVERSE_COEFFICIENTS': + constant = obj.data.constant_coefficient + linear = obj.data.linear_coefficient + quadratic = obj.data.quadratic_coefficient + + layer = 0 + if 'retro_layer' in obj.data.keys(): + layer = obj.data['retro_layer'] + + writepipebuf(struct.pack('IIfffffb', layer, type, obj.data.energy, spotCutoff, constant, linear, quadratic, + castShadow)) + + writepipestr(obj.name.encode()) + +# Command loop for reading data from blender +def dataout_loop(): + writepipestr(b'READY') + while True: + cmdargs = read_cmdargs() + print(cmdargs) + + if cmdargs[0] == 'DATAEND': + writepipestr(b'DONE') + return + + elif cmdargs[0] == 'MESHLIST': + meshCount = 0 + for meshobj in bpy.data.objects: + if meshobj.type == 'MESH' and not meshobj.data.library: + meshCount += 1 + writepipebuf(struct.pack('I', meshCount)) + for meshobj in bpy.data.objects: + if meshobj.type == 'MESH' and not meshobj.data.library: + writepipestr(meshobj.name.encode()) + + elif cmdargs[0] == 'LIGHTLIST': + lightCount = 0 + for obj in bpy.context.scene.objects: + if obj.type == 'LIGHT' and not obj.data.library: + lightCount += 1 + writepipebuf(struct.pack('I', lightCount)) + for obj in bpy.context.scene.objects: + if obj.type == 'LIGHT' and not obj.data.library: + writepipestr(obj.name.encode()) + + elif cmdargs[0] == 'MESHAABB': + writepipestr(b'OK') + hecl.mesh_aabb(writepipebuf) + + elif cmdargs[0] == 'MESHCOMPILE': + meshName = bpy.context.scene.hecl_mesh_obj + if meshName not in bpy.data.objects: + writepipestr(('mesh %s not found' % meshName).encode()) + continue + + writepipestr(b'OK') + hecl.hmdl.cook(writepipebuf, bpy.data.objects[meshName]) + + elif cmdargs[0] == 'ARMATURECOMPILE': + armName = bpy.context.scene.hecl_arm_obj + if armName not in bpy.data.objects: + writepipestr(('armature %s not found' % armName).encode()) + continue + + writepipestr(b'OK') + hecl.armature.cook(writepipebuf, bpy.data.objects[armName].data) + + elif cmdargs[0] == 'MESHCOMPILENAME': + meshName = cmdargs[1] + useLuv = int(cmdargs[2]) + + if meshName not in bpy.data.objects: + writepipestr(('mesh %s not found' % meshName).encode()) + continue + + writepipestr(b'OK') + hecl.hmdl.cook(writepipebuf, bpy.data.objects[meshName], useLuv) + + elif cmdargs[0] == 'MESHCOMPILENAMECOLLISION': + meshName = cmdargs[1] + + if meshName not in bpy.data.objects: + writepipestr(('mesh %s not found' % meshName).encode()) + continue + + writepipestr(b'OK') + hecl.hmdl.cookcol(writepipebuf, bpy.data.objects[meshName]) + + elif cmdargs[0] == 'MESHCOMPILECOLLISIONALL': + writepipestr(b'OK') + colCount = 0 + for obj in bpy.context.scene.objects: + if obj.type == 'MESH' and not obj.data.library: + colCount += 1 + + writepipebuf(struct.pack('I', colCount)) + + for obj in bpy.context.scene.objects: + if obj.type == 'MESH' and not obj.data.library: + hecl.hmdl.cookcol(writepipebuf, obj) + + elif cmdargs[0] == 'MESHCOMPILEPATH': + meshName = bpy.context.scene.hecl_path_obj + if meshName not in bpy.data.objects: + writepipestr(('mesh %s not found' % meshName).encode()) + continue + + writepipestr(b'OK') + hecl.path.cook(writepipebuf, bpy.data.objects[meshName]) + + elif cmdargs[0] == 'WORLDCOMPILE': + writepipestr(b'OK') + hecl.swld.cook(writepipebuf) + + elif cmdargs[0] == 'FRAMECOMPILE': + version = int(cmdargs[1]) + if version != 0 and version != 1: + writepipestr(b'bad version') + continue + + writepipestr(b'OK') + buffer = hecl.frme.cook(writepipebuf, version, PathHasher()) + writepipestr(b'FRAMEDONE') + writepipebuf(struct.pack('I', len(buffer))) + writepipebuf(buffer) + + elif cmdargs[0] == 'LIGHTCOMPILEALL': + writepipestr(b'OK') + lampCount = 0 + firstSpot = None + for obj in bpy.context.scene.objects: + if obj.type == 'LIGHT': + lampCount += 1 + if firstSpot is None and obj.data.type == 'SPOT': + firstSpot = obj + + # Ambient + world = bpy.context.scene.world + ambient_energy = 0.0 + ambient_color = None + if world.use_nodes and 'Background' in world.node_tree.nodes: + bg_node = world.node_tree.nodes['Background'] + ambient_energy = bg_node.inputs[1].default_value + ambient_color = bg_node.inputs[0].default_value + if ambient_energy: + lampCount += 1 + + writepipebuf(struct.pack('I', lampCount)) + + if firstSpot is not None: + writelight(firstSpot) + + if ambient_energy: + writepipebuf(struct.pack('ffffffffffffffff', + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0)) + writepipebuf(struct.pack('fff', ambient_color[0], ambient_color[1], ambient_color[2])) + writepipebuf(struct.pack('IIfffffb', 0, 0, ambient_energy, 0.0, 1.0, 0.0, 0.0, False)) + writepipestr(b'AMBIENT') + + # Lamp objects + for obj in bpy.context.scene.objects: + if obj != firstSpot and obj.type == 'LIGHT': + writelight(obj) + + elif cmdargs[0] == 'GETTEXTURES': + writepipestr(b'OK') + + img_count = 0 + for img in bpy.data.images: + if img.type == 'IMAGE': + img_count += 1 + writepipebuf(struct.pack('I', img_count)) + + for img in bpy.data.images: + if img.type == 'IMAGE': + path = os.path.normpath(bpy.path.abspath(img.filepath)) + writepipebuf(struct.pack('I', len(path))) + writepipebuf(path.encode()) + + elif cmdargs[0] == 'ACTORCOMPILE': + writepipestr(b'OK') + hecl.sact.cook(writepipebuf) + + elif cmdargs[0] == 'ACTORCOMPILECHARACTERONLY': + writepipestr(b'OK') + hecl.sact.cook_character_only(writepipebuf) + + elif cmdargs[0] == 'ACTIONCOMPILECHANNELSONLY': + actionName = cmdargs[1] + writepipestr(b'OK') + hecl.sact.cook_action_channels_only(writepipebuf, actionName) + + elif cmdargs[0] == 'GETSUBTYPENAMES': + writepipestr(b'OK') + hecl.sact.get_subtype_names(writepipebuf) + + elif cmdargs[0] == 'GETSUBTYPEOVERLAYNAMES': + subtypeName = cmdargs[1] + writepipestr(b'OK') + hecl.sact.get_subtype_overlay_names(writepipebuf, subtypeName) + + elif cmdargs[0] == 'GETATTACHMENTNAMES': + writepipestr(b'OK') + hecl.sact.get_attachment_names(writepipebuf) + + elif cmdargs[0] == 'GETACTIONNAMES': + writepipestr(b'OK') + hecl.sact.get_action_names(writepipebuf) + + elif cmdargs[0] == 'GETBONEMATRICES': + armName = cmdargs[1] + + if armName not in bpy.data.objects: + writepipestr(('armature %s not found' % armName).encode()) + continue + + armObj = bpy.data.objects[armName] + if armObj.type != 'ARMATURE': + writepipestr(('object %s not an ARMATURE' % armName).encode()) + continue + + writepipestr(b'OK') + writepipebuf(struct.pack('I', len(armObj.data.bones))) + for bone in armObj.data.bones: + writepipebuf(struct.pack('I', len(bone.name))) + writepipebuf(bone.name.encode()) + for r in bone.matrix_local.to_3x3(): + for c in r: + writepipebuf(struct.pack('f', c)) + + elif cmdargs[0] == 'RENDERPVS': + pathOut = cmdargs[1] + locX = float(cmdargs[2]) + locY = float(cmdargs[3]) + locZ = float(cmdargs[4]) + hecl.srea.render_pvs(pathOut, (locX, locY, locZ)) + writepipestr(b'OK') + + elif cmdargs[0] == 'RENDERPVSLIGHT': + pathOut = cmdargs[1] + lightName = cmdargs[2] + hecl.srea.render_pvs_light(pathOut, lightName) + writepipestr(b'OK') + + elif cmdargs[0] == 'MAPAREACOMPILE': + if 'MAP' not in bpy.data.objects: + writepipestr(('"MAP" object not in .blend').encode()) + continue + map_obj = bpy.data.objects['MAP'] + if map_obj.type != 'MESH': + writepipestr(('object "MAP" not a MESH').encode()) + continue + writepipestr(b'OK') + hecl.mapa.cook(writepipebuf, map_obj) + + elif cmdargs[0] == 'MAPUNIVERSECOMPILE': + writepipestr(b'OK') + hecl.mapu.cook(writepipebuf) + +loaded_blend = None + +# Main exception handling +try: + # Command loop + while True: + cmdargs = read_cmdargs() + print(cmdargs) + + if cmdargs[0] == 'QUIT': + quitblender() + + elif cmdargs[0] == 'OPEN': + if 'FINISHED' in bpy.ops.wm.open_mainfile(filepath=cmdargs[1]): + if bpy.ops.object.mode_set.poll(): + bpy.ops.object.mode_set(mode = 'OBJECT') + loaded_blend = cmdargs[1] + writepipestr(b'FINISHED') + else: + writepipestr(b'CANCELLED') + + elif cmdargs[0] == 'CREATE': + if len(cmdargs) >= 4: + bpy.ops.wm.open_mainfile(filepath=cmdargs[3]) + else: + bpy.ops.wm.read_homefile(use_empty=True) + bpy.context.scene.world = bpy.data.worlds.new('World') + loaded_blend = cmdargs[1] + bpy.context.preferences.filepaths.save_version = 0 + if 'FINISHED' in bpy.ops.wm.save_as_mainfile(filepath=cmdargs[1]): + bpy.ops.file.hecl_patching_load() + bpy.context.scene.hecl_type = cmdargs[2] + writepipestr(b'FINISHED') + else: + writepipestr(b'CANCELLED') + + elif cmdargs[0] == 'GETTYPE': + writepipestr(bpy.context.scene.hecl_type.encode()) + + elif cmdargs[0] == 'GETMESHRIGGED': + meshName = bpy.context.scene.hecl_mesh_obj + if meshName not in bpy.data.objects: + writepipestr(b'FALSE') + else: + if len(bpy.data.objects[meshName].vertex_groups): + writepipestr(b'TRUE') + else: + writepipestr(b'FALSE') + + elif cmdargs[0] == 'SAVE': + bpy.context.preferences.filepaths.save_version = 0 + print('SAVING %s' % loaded_blend) + if loaded_blend: + if 'FINISHED' in bpy.ops.wm.save_as_mainfile(filepath=loaded_blend, check_existing=False, compress=True): + writepipestr(b'FINISHED') + else: + writepipestr(b'CANCELLED') + + elif cmdargs[0] == 'PYBEGIN': + writepipestr(b'READY') + globals = {'hecl':hecl} + compbuf = str() + bracket_count = 0 + while True: + try: + line = readpipestr() + + # ANIM check + if line == b'PYANIM': + # Ensure remaining block gets executed + if len(compbuf): + exec_compbuf(compbuf, globals) + compbuf = str() + animin_loop(globals) + continue + + # End check + elif line == b'PYEND': + # Ensure remaining block gets executed + if len(compbuf): + exec_compbuf(compbuf, globals) + compbuf = str() + writepipestr(b'DONE') + break + + # Syntax filter + linestr = line.decode().rstrip() + if not len(linestr) or linestr.lstrip()[0] == '#': + writepipestr(b'OK') + continue + leading_spaces = len(linestr) - len(linestr.lstrip()) + + # Block lines always get appended right away + if linestr.endswith(':') or leading_spaces or bracket_count: + if len(compbuf): + compbuf += '\n' + compbuf += linestr + bracket_count += count_brackets(linestr) + writepipestr(b'OK') + continue + + # Complete non-block statement in compbuf + if len(compbuf): + exec_compbuf(compbuf, globals) + + # Establish new compbuf + compbuf = linestr + bracket_count += count_brackets(linestr) + + except Exception as e: + writepipestr(b'EXCEPTION') + raise + break + writepipestr(b'OK') + + elif cmdargs[0] == 'PYEND': + writepipestr(b'ERROR') + + elif cmdargs[0] == 'DATABEGIN': + try: + dataout_loop() + except Exception as e: + writepipestr(b'EXCEPTION') + raise + + elif cmdargs[0] == 'DATAEND': + writepipestr(b'ERROR') + + else: + hecl.command(cmdargs, writepipestr, writepipebuf) + +except Exception: + fout = open(err_path, 'w') + traceback.print_exc(file=fout) + fout.close() + raise diff --git a/hecl/blender/zip_package.py b/hecl/blender/zip_package.py new file mode 100644 index 000000000..dc4b897e6 --- /dev/null +++ b/hecl/blender/zip_package.py @@ -0,0 +1,18 @@ +import sys, os +import zipfile + +def zipdir(path, ziph): + # ziph is zipfile handle + for root, dirs, files in os.walk(path): + for file in files: + ziph.write(os.path.join(root, file)) + +package_path = 'hecl' +target_zip = sys.argv[1] + +zf = zipfile.ZipFile(target_zip, mode='w', compression=zipfile.ZIP_DEFLATED) +#print('GENERATING', target_zip) +if os.path.isdir(package_path): + zipdir(package_path, zf) + +zf.close() diff --git a/hecl/bootstrap.sh b/hecl/bootstrap.sh new file mode 100755 index 000000000..f2a3f6193 --- /dev/null +++ b/hecl/bootstrap.sh @@ -0,0 +1,3 @@ +#!/bin/bash +git submodule update --init --recursive + diff --git a/hecl/driver/CMakeLists.txt b/hecl/driver/CMakeLists.txt new file mode 100644 index 000000000..c40ff5cb5 --- /dev/null +++ b/hecl/driver/CMakeLists.txt @@ -0,0 +1,32 @@ +if(NOT WINDOWS_STORE) + +add_executable(hecl main.cpp + ToolBase.hpp + ToolPackage.hpp + ToolExtract.hpp + ToolInit.hpp + ToolHelp.hpp + ToolCook.hpp + ToolImage.hpp + ToolSpec.hpp) +if(COMMAND add_sanitizers) + add_sanitizers(hecl) +endif() + +if(NOT WIN32) + list(APPEND PLAT_LIBS pthread) +endif() + +if(APPLE) + find_library(CF_LIBRARY CoreFoundation) + list(APPEND PLAT_LIBS ${CF_LIBRARY}) +endif() + +target_link_libraries(hecl PUBLIC ${DATA_SPEC_LIBS} hecl-full) + +if(TARGET nod) + target_link_libraries(hecl PUBLIC nod) + target_compile_definitions(hecl PUBLIC HECL_HAS_NOD=1) +endif() + +endif() diff --git a/hecl/driver/ToolBase.hpp b/hecl/driver/ToolBase.hpp new file mode 100644 index 000000000..dc028ee0a --- /dev/null +++ b/hecl/driver/ToolBase.hpp @@ -0,0 +1,235 @@ +#pragma once + +#include +#include +#include +#include +#include + +#ifndef _WIN32 +#include +#include +#else +#include +#endif + +#include "hecl/Database.hpp" +#include "logvisor/logvisor.hpp" + +extern logvisor::Module LogModule; + +struct ToolPassInfo { + hecl::SystemString pname; + hecl::SystemString cwd; + std::vector args; + std::vector flags; + hecl::SystemString output; + hecl::Database::Project* project = nullptr; + unsigned verbosityLevel = 0; + bool force = false; + bool yes = false; + bool gui = false; +}; + +#define RED "\033[0;31m" +#define GREEN "\033[0;32m" +#define YELLOW "\033[0;33m" +#define BLUE "\033[0;34m" +#define MAGENTA "\033[0;35m" +#define CYAN "\033[0;36m" +#define BOLD "\033[1m" +#define NORMAL "\033[0m" + +#define HIDE_CURSOR "\033[?25l" +#define SHOW_CURSOR "\033[?25h" + +#define WRAP_INDENT 4 + +extern bool XTERM_COLOR; + +class ToolBase { +protected: + const ToolPassInfo& m_info; + bool m_good = false; + + bool continuePrompt() { + if (!m_info.yes) { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("\n" BLUE BOLD "Continue?" NORMAL " (Y/n) "))); + else + fmt::print(FMT_STRING(_SYS_STR("\nContinue? (Y/n) "))); + fflush(stdout); + + int ch; +#ifndef _WIN32 + struct termios tioOld, tioNew; + tcgetattr(0, &tioOld); + tioNew = tioOld; + tioNew.c_lflag &= ~ICANON; + tcsetattr(0, TCSANOW, &tioNew); + while ((ch = getchar())) +#else + while ((ch = getch())) +#endif + { + if (ch == 'n' || ch == 'N') { + fmt::print(FMT_STRING(_SYS_STR("\n"))); + return false; + } + if (ch == 'y' || ch == 'Y' || ch == '\r' || ch == '\n') + break; + } +#ifndef _WIN32 + tcsetattr(0, TCSANOW, &tioOld); +#endif + } + fmt::print(FMT_STRING(_SYS_STR("\n"))); + return true; + } + +public: + explicit ToolBase(const ToolPassInfo& info) : m_info(info) { + hecl::VerbosityLevel = info.verbosityLevel; + hecl::GuiMode = info.gui; + } + virtual ~ToolBase() = default; + virtual hecl::SystemStringView toolName() const = 0; + virtual int run() = 0; + virtual void cancel() {} + explicit operator bool() const { return m_good; } +}; + +class HelpOutput { +public: + using HelpFunc = void (*)(HelpOutput&); + +private: + FILE* m_sout = nullptr; + HelpFunc m_helpFunc; + int m_lineWidth; + hecl::SystemString m_wrapBuffer; + + void _wrapBuf(hecl::SystemString& string) { + int counter; + hecl::SystemString::iterator it = string.begin(); + + while (it != string.end()) { + std::ptrdiff_t v = it - string.begin(); + + /* copy string until the end of the line is reached */ + for (counter = WRAP_INDENT; counter < m_lineWidth; ++counter) { + if (it >= string.end()) + return; + if (*it == _SYS_STR('\n')) { + counter = WRAP_INDENT; + ++it; + } + if (counter == WRAP_INDENT) { + for (int i = 0; i < WRAP_INDENT; ++i) + it = string.insert(it, _SYS_STR(' ')) + 1; + } + if (it >= string.end()) + return; + if (*it != _SYS_STR('\n')) + ++it; + } + /* check for whitespace */ + if (isspace(*it)) { + *it = _SYS_STR('\n'); + counter = WRAP_INDENT; + ++it; + } else { + /* check for nearest whitespace back in string */ + for (hecl::SystemString::iterator k = it; k != string.begin(); --k) { + if (isspace(*k)) { + counter = WRAP_INDENT; + if (k - string.begin() < v) + k = string.insert(it, _SYS_STR('\n')); + else + *k = _SYS_STR('\n'); + it = k + 1; + break; + } + } + } + } + } + +public: + explicit HelpOutput(HelpFunc helpFunc) + : m_helpFunc(helpFunc), m_lineWidth(hecl::GuiMode ? 120 : hecl::ConsoleWidth()) {} + + void go() { +#if _WIN32 + m_sout = stdout; + m_helpFunc(*this); +#else + m_sout = popen("less -R", "w"); + if (m_sout) { + m_helpFunc(*this); + pclose(m_sout); + } else { + m_sout = stdout; + m_helpFunc(*this); + } +#endif + } + + void print(const hecl::SystemChar* str) { fmt::print(m_sout, FMT_STRING(_SYS_STR("{}")), str); } + + void printBold(const hecl::SystemChar* str) { + if (XTERM_COLOR) + fmt::print(m_sout, FMT_STRING(_SYS_STR("" BOLD "{}" NORMAL "")), str); + else + fmt::print(m_sout, FMT_STRING(_SYS_STR("{}")), str); + } + + void secHead(const hecl::SystemChar* headName) { + if (XTERM_COLOR) + fmt::print(m_sout, FMT_STRING(_SYS_STR("" BOLD "{}" NORMAL "\n")), headName); + else + fmt::print(m_sout, FMT_STRING(_SYS_STR("{}\n")), headName); + } + + void optionHead(const hecl::SystemChar* flag, const hecl::SystemChar* synopsis) { + if (XTERM_COLOR) + fmt::print(m_sout, FMT_STRING(_SYS_STR("" BOLD "{}" NORMAL " ({})\n")), flag, synopsis); + else + fmt::print(m_sout, FMT_STRING(_SYS_STR("{} ({})\n")), flag, synopsis); + } + + void beginWrap() { m_wrapBuffer.clear(); } + + void wrap(const hecl::SystemChar* str) { m_wrapBuffer += str; } + + void wrapBold(const hecl::SystemChar* str) { + if (XTERM_COLOR) + m_wrapBuffer += _SYS_STR("" BOLD ""); + m_wrapBuffer += str; + if (XTERM_COLOR) + m_wrapBuffer += _SYS_STR("" NORMAL ""); + } + + void endWrap() { + _wrapBuf(m_wrapBuffer); + m_wrapBuffer += _SYS_STR('\n'); + fmt::print(m_sout, FMT_STRING(_SYS_STR("{}")), m_wrapBuffer); + m_wrapBuffer.clear(); + } +}; + +static hecl::SystemString MakePathArgAbsolute(const hecl::SystemString& arg, const hecl::SystemString& cwd) { +#if _WIN32 + if (arg.size() >= 2 && iswalpha(arg[0]) && arg[1] == _SYS_STR(':')) + return arg; + if (arg[0] == _SYS_STR('\\') || arg[0] == _SYS_STR('/')) + return arg; + return cwd + _SYS_STR('\\') + arg; +#else + if (arg[0] == _SYS_STR('/') || arg[0] == _SYS_STR('\\')) + return arg; + if (cwd.back() == _SYS_STR('/') || cwd.back() == _SYS_STR('\\')) + return cwd + arg; + return cwd + _SYS_STR('/') + arg; +#endif +} diff --git a/hecl/driver/ToolCook.hpp b/hecl/driver/ToolCook.hpp new file mode 100644 index 000000000..3bedd07e8 --- /dev/null +++ b/hecl/driver/ToolCook.hpp @@ -0,0 +1,160 @@ +#pragma once + +#include "ToolBase.hpp" +#include +#include "hecl/ClientProcess.hpp" + +class ToolCook final : public ToolBase { + std::vector m_selectedItems; + std::unique_ptr m_fallbackProj; + hecl::Database::Project* m_useProj; + const hecl::Database::DataSpecEntry* m_spec = nullptr; + bool m_recursive = false; + bool m_fast = false; + +public: + explicit ToolCook(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { + /* Check for recursive flag */ + for (hecl::SystemChar arg : info.flags) + if (arg == _SYS_STR('r')) + m_recursive = true; + + /* Scan args */ + if (info.args.size()) { + /* See if project path is supplied via args and use that over the getcwd one */ + m_selectedItems.reserve(info.args.size()); + for (const hecl::SystemString& arg : info.args) { + if (arg.empty()) + continue; + else if (arg == _SYS_STR("--fast")) { + m_fast = true; + continue; + } else if (arg.size() >= 8 && !arg.compare(0, 7, _SYS_STR("--spec="))) { + hecl::SystemString specName(arg.begin() + 7, arg.end()); + for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) { + if (!hecl::StrCaseCmp(spec->m_name.data(), specName.c_str())) { + m_spec = spec; + break; + } + } + if (!m_spec) + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to find data spec '{}'")), specName); + continue; + } else if (arg.size() >= 2 && arg[0] == _SYS_STR('-') && arg[1] == _SYS_STR('-')) + continue; + + hecl::SystemString subPath; + hecl::ProjectRootPath root = hecl::SearchForProject(MakePathArgAbsolute(arg, info.cwd), subPath); + if (root) { + if (!m_fallbackProj) { + m_fallbackProj.reset(new hecl::Database::Project(root)); + m_useProj = m_fallbackProj.get(); + } else if (m_fallbackProj->getProjectRootPath() != root) + LogModule.report(logvisor::Fatal, + FMT_STRING(_SYS_STR("hecl cook can only process multiple items in the same project; ") + _SYS_STR("'{}' and '{}' are different projects")), + m_fallbackProj->getProjectRootPath().getAbsolutePath(), + root.getAbsolutePath()); + m_selectedItems.emplace_back(*m_useProj, subPath); + } + } + } + if (!m_useProj) + LogModule.report(logvisor::Fatal, + FMT_STRING("hecl cook must be ran within a project directory or " + "provided a path within a project")); + + /* Default case: recursive at root */ + if (m_selectedItems.empty()) { + m_selectedItems.reserve(1); + m_selectedItems.push_back({hecl::ProjectPath(*m_useProj, _SYS_STR(""))}); + m_recursive = true; + } + } + + static void Help(HelpOutput& help) { + help.secHead(_SYS_STR("NAME")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl-cook - Cook objects within the project database\n")); + help.endWrap(); + + help.secHead(_SYS_STR("SYNOPSIS")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl cook [-rf] [--fast] [--spec=] [...]\n")); + help.endWrap(); + + help.secHead(_SYS_STR("DESCRIPTION")); + help.beginWrap(); + help.wrap(_SYS_STR("This command initiates a cooking pass on the project database. Cooking ") + _SYS_STR("is analogous to compiling in software development. The resulting object buffers ") + _SYS_STR("are cached within the project database. HECL performs the following ") + _SYS_STR("tasks for each object during the cook process:\n\n")); + help.wrapBold(_SYS_STR("- Object Gather: ")); + help.wrap(_SYS_STR("Files added with ")); + help.wrapBold(_SYS_STR("hecl add")); + help.wrap(_SYS_STR(" are queried for their dependent files (e.g. ")); + help.wrapBold(_SYS_STR(".blend")); + help.wrap(_SYS_STR(" files return any linked ")); + help.wrapBold(_SYS_STR(".png")); + help.wrap(_SYS_STR(" images). If the dependent files are unable to be found, the cook process aborts.\n\n")); + help.wrapBold(_SYS_STR("- Modtime Comparison: ")); + help.wrap(_SYS_STR("Files that have previously finished a cook pass are inspected for their time of ") + _SYS_STR("last modification. If the file hasn't changed since its previous cook-pass, the ") _SYS_STR( + "process is skipped. If the file has been moved or deleted, the object is automatically ") + _SYS_STR("removed from the project database.\n\n")); + help.wrapBold(_SYS_STR("- Cook: ")); + help.wrap(_SYS_STR("A type-specific procedure compiles the file's contents into an efficient format ") + _SYS_STR("for use by the runtime. A data-buffer is provided to HECL.\n\n")); + help.wrapBold(_SYS_STR("- Hash and Compress: ")); + help.wrap(_SYS_STR("The data-buffer is hashed and compressed before being cached in the object database.\n\n")); + help.endWrap(); + + help.secHead(_SYS_STR("OPTIONS")); + help.optionHead(_SYS_STR("..."), _SYS_STR("input file(s)")); + help.beginWrap(); + help.wrap(_SYS_STR("Specifies working file(s) containing production data to be cooked by HECL. ") + _SYS_STR("Glob-strings may be specified (e.g. ")); + help.wrapBold(_SYS_STR("*.blend")); + help.wrap(_SYS_STR(") to automatically cook all matching current-directory files in the project database. ") + _SYS_STR("If no path specified, all files in the project database are cooked.\n")); + help.endWrap(); + + help.optionHead(_SYS_STR("-r"), _SYS_STR("recursion")); + help.beginWrap(); + help.wrap(_SYS_STR("Enables recursive file-matching for cooking entire directories of working files.\n")); + help.endWrap(); + help.optionHead(_SYS_STR("-f"), _SYS_STR("force")); + help.beginWrap(); + help.wrap(_SYS_STR("Forces cooking of all matched files, ignoring timestamp differences.\n")); + help.endWrap(); + help.optionHead(_SYS_STR("--fast"), _SYS_STR("fast cook")); + help.beginWrap(); + help.wrap(_SYS_STR("Performs draft-optimization cooking for supported data types.\n")); + help.endWrap(); + + help.optionHead(_SYS_STR("--spec="), _SYS_STR("data specification")); + help.beginWrap(); + help.wrap(_SYS_STR("Specifies a DataSpec to use when cooking. ") + _SYS_STR("This build of hecl supports the following values of :\n")); + for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) { + if (!spec->m_factory) + continue; + help.wrap(_SYS_STR(" ")); + help.wrapBold(spec->m_name.data()); + help.wrap(_SYS_STR("\n")); + } + } + + hecl::SystemStringView toolName() const override { return _SYS_STR("cook"sv); } + + int run() override { + hecl::MultiProgressPrinter printer(true); + hecl::ClientProcess cp(&printer); + for (const hecl::ProjectPath& path : m_selectedItems) + m_useProj->cookPath(path, printer, m_recursive, m_info.force, m_fast, m_spec, &cp); + cp.waitUntilComplete(); + return 0; + } + + void cancel() override { m_useProj->interruptCook(); } +}; diff --git a/hecl/driver/ToolExtract.hpp b/hecl/driver/ToolExtract.hpp new file mode 100644 index 000000000..4b62ff3e5 --- /dev/null +++ b/hecl/driver/ToolExtract.hpp @@ -0,0 +1,166 @@ +#pragma once + +#include "ToolBase.hpp" +#include + +#if _WIN32 +#include +#else +#include +#endif + +#include "hecl/MultiProgressPrinter.hpp" + +class ToolExtract final : public ToolBase { + hecl::Database::IDataSpec::ExtractPassInfo m_einfo; + struct SpecExtractPass { + const hecl::Database::DataSpecEntry* m_entry; + std::unique_ptr m_instance; + SpecExtractPass(const hecl::Database::DataSpecEntry* entry, std::unique_ptr&& instance) + : m_entry(entry), m_instance(std::move(instance)) {} + SpecExtractPass(const SpecExtractPass& other) = delete; + SpecExtractPass(SpecExtractPass&& other) = default; + }; + std::vector m_specPasses; + std::vector m_reps; + std::unique_ptr m_fallbackProj; + hecl::Database::Project* m_useProj = nullptr; + +public: + explicit ToolExtract(const ToolPassInfo& info) : ToolBase(info) { + if (!m_info.args.size()) + LogModule.report(logvisor::Fatal, FMT_STRING("hecl extract needs a source path as its first argument")); + + if (!info.project) { + hecl::SystemString rootDir; + + if (info.output.empty()) { + /* Get name from input file and init project there */ + hecl::SystemString baseFile = info.args.front(); + size_t slashPos = baseFile.rfind(_SYS_STR('/')); + if (slashPos == hecl::SystemString::npos) + slashPos = baseFile.rfind(_SYS_STR('\\')); + if (slashPos != hecl::SystemString::npos) + baseFile.assign(baseFile.begin() + slashPos + 1, baseFile.end()); + size_t dotPos = baseFile.rfind(_SYS_STR('.')); + if (dotPos != hecl::SystemString::npos) + baseFile.assign(baseFile.begin(), baseFile.begin() + dotPos); + + if (baseFile.empty()) + LogModule.report(logvisor::Fatal, FMT_STRING("hecl extract must be ran within a project directory")); + + rootDir = info.cwd + baseFile; + } else { + if (hecl::PathRelative(info.output.c_str())) + rootDir = info.cwd + info.output; + else + rootDir = info.output; + } + + size_t ErrorRef = logvisor::ErrorCount; + hecl::ProjectRootPath newProjRoot(rootDir); + newProjRoot.makeDir(); + m_fallbackProj.reset(new hecl::Database::Project(newProjRoot)); + if (logvisor::ErrorCount > ErrorRef) + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to init project at '{}'")), rootDir); + LogModule.report(logvisor::Info, FMT_STRING(_SYS_STR("initialized project at '{}/.hecl'")), rootDir); + m_useProj = m_fallbackProj.get(); + } else + m_useProj = info.project; + + m_einfo.srcpath = m_info.args.front(); + m_einfo.force = info.force; + m_einfo.extractArgs.reserve(info.args.size()); + auto it = info.args.cbegin(); + ++it; + for (; it != info.args.cend(); ++it) + m_einfo.extractArgs.push_back(*it); + + m_specPasses.reserve(hecl::Database::DATA_SPEC_REGISTRY.size()); + for (const hecl::Database::DataSpecEntry* entry : hecl::Database::DATA_SPEC_REGISTRY) { + if (entry->m_factory) { + auto ds = entry->m_factory(*m_useProj, hecl::Database::DataSpecTool::Extract); + if (ds && ds->canExtract(m_einfo, m_reps)) + m_specPasses.emplace_back(entry, std::move(ds)); + } + } + } + + static void Help(HelpOutput& help) { + help.secHead(_SYS_STR("NAME")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl-extract - Extract objects from supported package/image formats\n")); + help.endWrap(); + + help.secHead(_SYS_STR("SYNOPSIS")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl extract [...]\n")); + help.endWrap(); + + help.secHead(_SYS_STR("DESCRIPTION")); + help.beginWrap(); + help.wrap(_SYS_STR("This command recursively extracts all or part of a dataspec-supported ") + _SYS_STR("package format. Each object is decoded to a working format and added to the project.\n\n")); + help.endWrap(); + + help.secHead(_SYS_STR("OPTIONS")); + help.optionHead(_SYS_STR("[/...]"), _SYS_STR("input file")); + help.beginWrap(); + help.wrap(_SYS_STR("Specifies the package file or disc image to source data from. ") + _SYS_STR("An optional subnode specifies a named hierarchical-node specific ") + _SYS_STR("to the game architecture (levels/areas).")); + help.endWrap(); + } + + hecl::SystemStringView toolName() const override { return _SYS_STR("extract"sv); } + + static void _recursivePrint(int level, hecl::Database::IDataSpec::ExtractReport& rep) { + for (int l = 0; l < level; ++l) + fmt::print(FMT_STRING(_SYS_STR(" "))); + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" BOLD "{}" NORMAL "")), rep.name); + else + fmt::print(FMT_STRING(_SYS_STR("{}")), rep.name); + + if (rep.desc.size()) + fmt::print(FMT_STRING(_SYS_STR(" [{}]")), rep.desc); + fmt::print(FMT_STRING(_SYS_STR("\n"))); + for (hecl::Database::IDataSpec::ExtractReport& child : rep.childOpts) + _recursivePrint(level + 1, child); + } + + int run() override { + if (m_specPasses.empty()) { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" RED BOLD "NOTHING TO EXTRACT" NORMAL "\n"))); + else + fmt::print(FMT_STRING(_SYS_STR("NOTHING TO EXTRACT\n"))); + return 1; + } + + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" GREEN BOLD "ABOUT TO EXTRACT:" NORMAL "\n"))); + else + fmt::print(FMT_STRING(_SYS_STR("ABOUT TO EXTRACT:\n"))); + + for (hecl::Database::IDataSpec::ExtractReport& rep : m_reps) { + _recursivePrint(0, rep); + fmt::print(FMT_STRING(_SYS_STR("\n"))); + } + fflush(stdout); + + if (continuePrompt()) { + for (SpecExtractPass& ds : m_specPasses) { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" MAGENTA BOLD "Using DataSpec {}:" NORMAL "\n")), ds.m_entry->m_name); + else + fmt::print(FMT_STRING(_SYS_STR("Using DataSpec {}:\n")), ds.m_entry->m_name); + + ds.m_instance->doExtract(m_einfo, {true}); + fmt::print(FMT_STRING(_SYS_STR("\n\n"))); + } + } + + return 0; + } +}; diff --git a/hecl/driver/ToolHelp.hpp b/hecl/driver/ToolHelp.hpp new file mode 100644 index 000000000..04a558a27 --- /dev/null +++ b/hecl/driver/ToolHelp.hpp @@ -0,0 +1,80 @@ +#pragma once + +#include "ToolBase.hpp" +#include +#include + +class ToolHelp final : public ToolBase { + +public: + explicit ToolHelp(const ToolPassInfo& info) : ToolBase(info) { + if (m_info.args.empty()) { + LogModule.report(logvisor::Error, FMT_STRING("help requires a tool name argument")); + return; + } + m_good = true; + } + + ~ToolHelp() override = default; + + static void Help(HelpOutput& help) { + /* clang-format off */ + help.printBold( + _SYS_STR(" ___________ \n") + _SYS_STR(" ,.-'\"...........``~., \n") + _SYS_STR(" ,.-\".......................\"-., \n") + _SYS_STR(" ,/..................................\":, \n") + _SYS_STR(" .,?........................................, \n") + _SYS_STR(" /...........................................,}\n") + _SYS_STR(" ./........................................,:`^`..}\n") + _SYS_STR(" ./.......................................,:\"...../\n") + _SYS_STR(" ?.....__..................................:`...../\n") + _SYS_STR(" /__.(...\"~-,_...........................,:`....../\n") + _SYS_STR(" /(_....\"~,_....\"~,_.....................,:`...._/ \n") + _SYS_STR(" {.._$;_....\"=,_.....\"-,_......,.-~-,},.~\";/....} \n") + _SYS_STR(" ((...*~_......\"=-._...\";,,./`........../\"..../ \n") + _SYS_STR(" ,,,___.`~,......\"~.,....................`......}....../ \n") + _SYS_STR("............(....`=-,,...`.........................(...;_,,-\" \n") + _SYS_STR("............/.`~,......`-.................................../ \n") + _SYS_STR(".............`~.*-,.....................................|,./...,__ \n") + _SYS_STR(",,_..........}.>-._...................................|.......`=~-, \n") + _SYS_STR(".....`=~-,__......`,................................. \n") + _SYS_STR("...................`=~-,,.,........................... \n") + _SYS_STR(".........................`:,,..........................`\n") + _SYS_STR("...........................`=-,...............,%%`>--==`` \n") + _SYS_STR(".................................._.........._,-%%...` \n") + _SYS_STR("...................................,\n")); + /* clang-format on */ + } + + static void ShowHelp(const hecl::SystemString& toolName) { + /* Select tool's help-text streamer */ + HelpOutput::HelpFunc helpFunc = nullptr; + if (toolName == _SYS_STR("init")) + helpFunc = ToolInit::Help; + else if (toolName == _SYS_STR("spec")) + helpFunc = ToolSpec::Help; + else if (toolName == _SYS_STR("extract")) + helpFunc = ToolExtract::Help; + else if (toolName == _SYS_STR("cook")) + helpFunc = ToolCook::Help; + else if (toolName == _SYS_STR("package") || toolName == _SYS_STR("pack")) + helpFunc = ToolPackage::Help; + else if (toolName == _SYS_STR("help")) + helpFunc = ToolHelp::Help; + else { + LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("unrecognized tool '{}' - can't help")), toolName); + return; + } + + HelpOutput ho(helpFunc); + ho.go(); + } + + hecl::SystemStringView toolName() const override { return _SYS_STR("help"sv); } + + int run() override { + ShowHelp(m_info.args.front()); + return 0; + } +}; diff --git a/hecl/driver/ToolImage.hpp b/hecl/driver/ToolImage.hpp new file mode 100644 index 000000000..7e1b9cac5 --- /dev/null +++ b/hecl/driver/ToolImage.hpp @@ -0,0 +1,137 @@ +#pragma once + +#if HECL_HAS_NOD + +#include +#include +#include "ToolBase.hpp" +#include +#include "nod/DiscGCN.hpp" +#include "nod/DiscWii.hpp" +#include "athena/FileReader.hpp" + +class ToolImage final : public ToolBase { + std::unique_ptr m_fallbackProj; + hecl::Database::Project* m_useProj; + +public: + explicit ToolImage(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { + if (!info.project) + LogModule.report(logvisor::Fatal, FMT_STRING("hecl image must be ran within a project directory")); + + /* Scan args */ + if (info.args.size()) { + /* See if project path is supplied via args and use that over the getcwd one */ + for (const hecl::SystemString& arg : info.args) { + if (arg.empty()) + continue; + + hecl::SystemString subPath; + hecl::ProjectRootPath root = hecl::SearchForProject(MakePathArgAbsolute(arg, info.cwd), subPath); + + if (root) { + if (!m_fallbackProj) { + m_fallbackProj.reset(new hecl::Database::Project(root)); + m_useProj = m_fallbackProj.get(); + break; + } + } + } + } + if (!m_useProj) + LogModule.report(logvisor::Fatal, + FMT_STRING("hecl image must be ran within a project directory or " + "provided a path within a project")); + } + + ~ToolImage() override = default; + + static void Help(HelpOutput& help) { + help.secHead(_SYS_STR("NAME")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl-image - Generate GameCube/Wii disc image from packaged files\n")); + help.endWrap(); + + help.secHead(_SYS_STR("SYNOPSIS")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl image []\n")); + help.endWrap(); + + help.secHead(_SYS_STR("DESCRIPTION")); + help.beginWrap(); + help.wrap(_SYS_STR("This command uses the current contents of `out` to generate a GameCube or ") + _SYS_STR("Wii disc image. `hecl package` must have been run previously to be effective.\n")); + help.endWrap(); + + help.secHead(_SYS_STR("OPTIONS")); + help.optionHead(_SYS_STR(""), _SYS_STR("input directory")); + help.beginWrap(); + help.wrap(_SYS_STR("Specifies a project subdirectory to root the resulting image from. ") + _SYS_STR("Project must contain an out/sys and out/files directory to succeed.\n")); + help.endWrap(); + } + + hecl::SystemStringView toolName() const override { return _SYS_STR("image"sv); } + + int run() override { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" GREEN BOLD "ABOUT TO IMAGE:" NORMAL "\n"))); + else + fmt::print(FMT_STRING(_SYS_STR("ABOUT TO IMAGE:\n"))); + + fmt::print(FMT_STRING(_SYS_STR(" {}\n")), m_useProj->getProjectRootPath().getAbsolutePath()); + fflush(stdout); + + if (continuePrompt()) { + hecl::ProjectPath outPath(m_useProj->getProjectWorkingPath(), _SYS_STR("out")); + if (!outPath.isDirectory()) { + LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("{} is not a directory")), outPath.getAbsolutePath()); + return 1; + } + + hecl::ProjectPath bootBinPath(outPath, _SYS_STR("sys/boot.bin")); + if (!bootBinPath.isFile()) { + LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("{} is not a file")), bootBinPath.getAbsolutePath()); + return 1; + } + + athena::io::FileReader r(bootBinPath.getAbsolutePath()); + if (r.hasError()) { + LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("unable to open {}")), bootBinPath.getAbsolutePath()); + return 1; + } + std::string id = r.readString(6); + r.close(); + + hecl::SystemStringConv idView(id); + hecl::SystemString fileOut = hecl::SystemString(outPath.getAbsolutePath()) + _SYS_STR('/') + idView.c_str(); + hecl::MultiProgressPrinter printer(true); + auto progFunc = [&printer](float totalProg, nod::SystemStringView fileName, size_t fileBytesXfered) { + printer.print(fileName.data(), nullptr, totalProg); + }; + if (id[0] == 'G') { + fileOut += _SYS_STR(".gcm"); + if (nod::DiscBuilderGCN::CalculateTotalSizeRequired(outPath.getAbsolutePath()) == UINT64_MAX) + return 1; + LogModule.report(logvisor::Info, FMT_STRING(_SYS_STR("Generating {} as GameCube image")), fileOut); + nod::DiscBuilderGCN db(fileOut, progFunc); + if (db.buildFromDirectory(outPath.getAbsolutePath()) != nod::EBuildResult::Success) + return 1; + } else { + fileOut += _SYS_STR(".iso"); + bool dualLayer; + if (nod::DiscBuilderWii::CalculateTotalSizeRequired(outPath.getAbsolutePath(), dualLayer) == UINT64_MAX) + return 1; + LogModule.report(logvisor::Info, FMT_STRING(_SYS_STR("Generating {} as {}-layer Wii image")), fileOut, + dualLayer ? _SYS_STR("dual") : _SYS_STR("single")); + nod::DiscBuilderWii db(fileOut, dualLayer, progFunc); + if (db.buildFromDirectory(outPath.getAbsolutePath()) != nod::EBuildResult::Success) + return 1; + } + } + + return 0; + } +}; + +#endif diff --git a/hecl/driver/ToolInit.hpp b/hecl/driver/ToolInit.hpp new file mode 100644 index 000000000..ed2758f26 --- /dev/null +++ b/hecl/driver/ToolInit.hpp @@ -0,0 +1,77 @@ +#pragma once + +#include "ToolBase.hpp" +#include + +class ToolInit final : public ToolBase { + const hecl::SystemString* m_dir = nullptr; + +public: + explicit ToolInit(const ToolPassInfo& info) : ToolBase(info) { + hecl::Sstat theStat; + const hecl::SystemString* dir; + if (info.args.size()) + dir = &info.args.front(); + else + dir = &info.cwd; + + if (hecl::Stat(dir->c_str(), &theStat)) { + hecl::MakeDir(dir->c_str()); + if (hecl::Stat(dir->c_str(), &theStat)) { + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to stat '{}'")), *dir); + return; + } + } + if (!S_ISDIR(theStat.st_mode)) { + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("'{}' is not a directory")), *dir); + return; + } + + hecl::SystemString testPath = *dir + _SYS_STR("/.hecl/beacon"); + if (!hecl::Stat(testPath.c_str(), &theStat)) { + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("project already exists at '{}'")), *dir); + return; + } + + m_dir = dir; + } + + int run() override { + if (!m_dir) + return 1; + size_t ErrorRef = logvisor::ErrorCount; + hecl::Database::Project proj((hecl::ProjectRootPath(*m_dir))); + if (logvisor::ErrorCount > ErrorRef) + return 1; + LogModule.report(logvisor::Info, FMT_STRING(_SYS_STR("initialized project at '{}/.hecl'")), *m_dir); + return 0; + } + + static void Help(HelpOutput& help) { + help.secHead(_SYS_STR("NAME")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl-init - Initialize a brand-new project database\n")); + help.endWrap(); + + help.secHead(_SYS_STR("SYNOPSIS")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl init []\n")); + help.endWrap(); + + help.secHead(_SYS_STR("DESCRIPTION")); + help.beginWrap(); + help.wrap(_SYS_STR("Creates a ")); + help.wrapBold(_SYS_STR(".hecl")); + help.wrap(_SYS_STR(" directory within the selected directory with an initialized database index. ") + _SYS_STR("This constitutes an empty HECL project, ready for making stuff!!\n")); + help.endWrap(); + + help.secHead(_SYS_STR("OPTIONS")); + help.optionHead(_SYS_STR(""), _SYS_STR("group directory path")); + help.beginWrap(); + help.wrap(_SYS_STR("Directory to create new project database in. If not specified, current directory is used.\n")); + help.endWrap(); + } + + hecl::SystemStringView toolName() const override { return _SYS_STR("init"sv); } +}; diff --git a/hecl/driver/ToolInstallAddon.hpp b/hecl/driver/ToolInstallAddon.hpp new file mode 100644 index 000000000..3b5721db1 --- /dev/null +++ b/hecl/driver/ToolInstallAddon.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "ToolBase.hpp" +#include + +class ToolInstallAddon final : public ToolBase { +public: + explicit ToolInstallAddon(const ToolPassInfo& info) : ToolBase(info) {} + + int run() override { + hecl::blender::SharedBlenderToken.getBlenderConnection(); + return 0; + } + + static void Help(HelpOutput& help) { + help.secHead(_SYS_STR("NAME")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl-installaddon - Installs embedded Blender addon into local Blender\n")); + help.endWrap(); + + help.secHead(_SYS_STR("SYNOPSIS")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl installaddon\n")); + help.endWrap(); + + help.secHead(_SYS_STR("DESCRIPTION")); + help.beginWrap(); + help.wrap(_SYS_STR("Installs the hecl Blender addon into Blender. The path to the blender executable ") + _SYS_STR("can be overridden by setting the BLENDER_BIN environment variable.")); + help.endWrap(); + } + + hecl::SystemStringView toolName() const override { return _SYS_STR("installaddon"sv); } +}; diff --git a/hecl/driver/ToolPackage.hpp b/hecl/driver/ToolPackage.hpp new file mode 100644 index 000000000..6f68936d4 --- /dev/null +++ b/hecl/driver/ToolPackage.hpp @@ -0,0 +1,180 @@ +#pragma once + +#include +#include +#include "ToolBase.hpp" +#include + +class ToolPackage final : public ToolBase { + std::vector m_selectedItems; + std::unique_ptr m_fallbackProj; + hecl::Database::Project* m_useProj; + const hecl::Database::DataSpecEntry* m_spec = nullptr; + bool m_fast = false; + + void AddSelectedItem(const hecl::ProjectPath& path) { + for (const hecl::ProjectPath& item : m_selectedItems) + if (item == path) + return; + m_selectedItems.push_back(path); + } + + void CheckFile(const hecl::ProjectPath& path) { + auto lastComp = path.getLastComponent(); + if (hecl::StringUtils::BeginsWith(lastComp, _SYS_STR("!world_")) && + hecl::StringUtils::EndsWith(lastComp, _SYS_STR(".blend"))) + AddSelectedItem(path); + } + + void FindSelectedItems(const hecl::ProjectPath& path, bool checkGeneral) { + if (path.isFile()) { + CheckFile(path); + return; + } + + size_t origSize = m_selectedItems.size(); + hecl::DirectoryEnumerator dEnum(path.getAbsolutePath(), hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted, false, + false, true); + for (const auto& ent : dEnum) { + hecl::ProjectPath childPath(path, ent.m_name); + if (ent.m_isDir) + FindSelectedItems(childPath, checkGeneral && childPath.getPathComponents().size() <= 2); + else + CheckFile(childPath); + } + + /* Directory with 2 components not "Shared" or macOS app bundle + * and no nested !world.blend files == General PAK */ + if (checkGeneral && origSize == m_selectedItems.size()) { + auto pathComps = path.getPathComponents(); + if (pathComps.size() == 2 && pathComps[0] != _SYS_STR("out") && pathComps[1] != _SYS_STR("Shared") && + pathComps[0].find(_SYS_STR(".app")) == hecl::SystemString::npos) + AddSelectedItem(path); + } + } + +public: + explicit ToolPackage(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { + if (!info.project) + LogModule.report(logvisor::Fatal, FMT_STRING("hecl package must be ran within a project directory")); + + /* Scan args */ + if (info.args.size()) { + /* See if project path is supplied via args and use that over the getcwd one */ + m_selectedItems.reserve(info.args.size()); + for (const hecl::SystemString& arg : info.args) { + if (arg.empty()) + continue; + else if (arg == _SYS_STR("--fast")) { + m_fast = true; + continue; + } else if (arg.size() >= 8 && !arg.compare(0, 7, _SYS_STR("--spec="))) { + hecl::SystemString specName(arg.begin() + 7, arg.end()); + for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) { + if (!hecl::StrCaseCmp(spec->m_name.data(), specName.c_str())) { + m_spec = spec; + break; + } + } + if (!m_spec) + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to find data spec '{}'")), specName); + continue; + } else if (arg.size() >= 2 && arg[0] == _SYS_STR('-') && arg[1] == _SYS_STR('-')) + continue; + + hecl::SystemString subPath; + hecl::ProjectRootPath root = hecl::SearchForProject(MakePathArgAbsolute(arg, info.cwd), subPath); + + if (root) { + if (!m_fallbackProj) { + m_fallbackProj.reset(new hecl::Database::Project(root)); + m_useProj = m_fallbackProj.get(); + } else if (m_fallbackProj->getProjectRootPath() != root) + LogModule.report(logvisor::Fatal, + FMT_STRING(_SYS_STR("hecl package can only process multiple items in the same project; ") + _SYS_STR("'{}' and '{}' are different projects")), + m_fallbackProj->getProjectRootPath().getAbsolutePath(), + root.getAbsolutePath()); + + FindSelectedItems({*m_useProj, subPath}, true); + } + } + } + if (!m_useProj) + LogModule.report(logvisor::Fatal, + FMT_STRING("hecl package must be ran within a project directory or " + "provided a path within a project")); + + /* Default case: recursive at root */ + if (m_selectedItems.empty()) + FindSelectedItems({*m_useProj, _SYS_STR("")}, true); + } + + static void Help(HelpOutput& help) { + help.secHead(_SYS_STR("NAME")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl-pack\n") _SYS_STR("hecl-package - Package objects within the project database\n")); + help.endWrap(); + + help.secHead(_SYS_STR("SYNOPSIS")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl package [--spec=] []\n")); + help.endWrap(); + + help.secHead(_SYS_STR("DESCRIPTION")); + help.beginWrap(); + help.wrap(_SYS_STR("This command initiates a packaging pass on the project database. Packaging ") + _SYS_STR("is analogous to linking in software development. All objects necessary to ") _SYS_STR( + "generate a complete package are gathered, grouped, and indexed within a .upak file.\n")); + help.endWrap(); + + help.secHead(_SYS_STR("OPTIONS")); + help.optionHead(_SYS_STR("--spec="), _SYS_STR("data specification")); + help.beginWrap(); + help.wrap(_SYS_STR("Specifies a DataSpec to use when cooking and generating the package. ") + _SYS_STR("This build of hecl supports the following values of :\n")); + for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) { + if (!spec->m_factory) + continue; + help.wrap(_SYS_STR(" ")); + help.wrapBold(spec->m_name.data()); + help.wrap(_SYS_STR("\n")); + } + help.endWrap(); + + help.secHead(_SYS_STR("OPTIONS")); + help.optionHead(_SYS_STR(""), _SYS_STR("input directory")); + help.beginWrap(); + help.wrap(_SYS_STR("Specifies a project subdirectory to root the resulting package from. ") + _SYS_STR("If any dependent files fall outside this subdirectory, they will be implicitly ") + _SYS_STR("gathered and packaged.\n")); + help.endWrap(); + } + + hecl::SystemStringView toolName() const override { return _SYS_STR("package"sv); } + + int run() override { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" GREEN BOLD "ABOUT TO PACKAGE:" NORMAL "\n"))); + else + fmt::print(FMT_STRING(_SYS_STR("ABOUT TO PACKAGE:\n"))); + + for (auto& item : m_selectedItems) + fmt::print(FMT_STRING(_SYS_STR(" {}\n")), item.getRelativePath()); + fflush(stdout); + + if (continuePrompt()) { + hecl::MultiProgressPrinter printer(true); + hecl::ClientProcess cp(&printer); + for (const hecl::ProjectPath& path : m_selectedItems) { + if (!m_useProj->packagePath(path, printer, m_fast, m_spec, &cp)) + LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("Unable to package {}")), path.getAbsolutePath()); + } + cp.waitUntilComplete(); + } + + return 0; + } + + void cancel() override { m_useProj->interruptCook(); } +}; diff --git a/hecl/driver/ToolSpec.hpp b/hecl/driver/ToolSpec.hpp new file mode 100644 index 000000000..35b1b63d5 --- /dev/null +++ b/hecl/driver/ToolSpec.hpp @@ -0,0 +1,131 @@ +#pragma once + +#include "ToolBase.hpp" +#include +#include + +class ToolSpec final : public ToolBase { + enum Mode { MLIST = 0, MENABLE, MDISABLE } mode = MLIST; + +public: + explicit ToolSpec(const ToolPassInfo& info) : ToolBase(info) { + if (info.args.empty()) + return; + + if (!info.project) + LogModule.report(logvisor::Fatal, FMT_STRING("hecl spec must be ran within a project directory")); + + const auto& specs = info.project->getDataSpecs(); + hecl::SystemString firstArg = info.args.front(); + hecl::ToLower(firstArg); + + if (firstArg == _SYS_STR("enable")) + mode = MENABLE; + else if (firstArg == _SYS_STR("disable")) + mode = MDISABLE; + else + return; + + if (info.args.size() < 2) + LogModule.report(logvisor::Fatal, FMT_STRING("Speclist argument required")); + + auto it = info.args.begin(); + ++it; + for (; it != info.args.end(); ++it) { + + bool found = false; + for (auto& spec : specs) { + if (!it->compare(spec.spec.m_name)) { + found = true; + break; + } + } + if (!found) + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("'{}' is not found in the dataspec registry")), *it); + } + } + + static void Help(HelpOutput& help) { + help.secHead(_SYS_STR("NAME")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl-spec - Configure target data options\n")); + help.endWrap(); + + help.secHead(_SYS_STR("SYNOPSIS")); + help.beginWrap(); + help.wrap(_SYS_STR("hecl spec [enable|disable] [...]\n")); + help.endWrap(); + + help.secHead(_SYS_STR("DESCRIPTION")); + help.beginWrap(); + help.wrap( + _SYS_STR("This command configures the HECL project with the user's preferred target DataSpecs.\n\n") + _SYS_STR("Providing enable/disable argument will bulk-set the enable status of the provided spec(s)") + _SYS_STR("list. If enable/disable is not provided, a list of supported DataSpecs is printed.\n\n")); + help.endWrap(); + + help.secHead(_SYS_STR("OPTIONS")); + help.optionHead(_SYS_STR("..."), _SYS_STR("DataSpec name(s)")); + help.beginWrap(); + help.wrap(_SYS_STR("Specifies platform-names to enable/disable")); + help.endWrap(); + } + + hecl::SystemStringView toolName() const override { return _SYS_STR("spec"sv); } + + int run() override { + if (!m_info.project) { + for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" BOLD CYAN "{}" NORMAL "\n")), spec->m_name); + else + fmt::print(FMT_STRING(_SYS_STR("{}\n")), spec->m_name); + fmt::print(FMT_STRING(_SYS_STR(" {}\n")), spec->m_desc); + } + return 0; + } + + const auto& specs = m_info.project->getDataSpecs(); + if (mode == MLIST) { + for (auto& spec : specs) { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" BOLD CYAN "{}" NORMAL "")), spec.spec.m_name); + else + fmt::print(FMT_STRING(_SYS_STR("{}")), spec.spec.m_name); + if (spec.active) { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR(" " BOLD GREEN "[ENABLED]" NORMAL ""))); + else + fmt::print(FMT_STRING(_SYS_STR(" [ENABLED]"))); + } + fmt::print(FMT_STRING(_SYS_STR("\n {}\n")), spec.spec.m_desc); + } + return 0; + } + + std::vector opSpecs; + auto it = m_info.args.begin(); + ++it; + for (; it != m_info.args.end(); ++it) { + hecl::SystemString itName = *it; + hecl::ToLower(itName); + for (auto& spec : specs) { + hecl::SystemString compName(spec.spec.m_name); + hecl::ToLower(compName); + if (itName == compName) { + opSpecs.emplace_back(spec.spec.m_name); + break; + } + } + } + + if (opSpecs.size()) { + if (mode == MENABLE) + m_info.project->enableDataSpecs(opSpecs); + else if (mode == MDISABLE) + m_info.project->disableDataSpecs(opSpecs); + } + + return 0; + } +}; diff --git a/hecl/driver/main.cpp b/hecl/driver/main.cpp new file mode 100644 index 000000000..54b5763c3 --- /dev/null +++ b/hecl/driver/main.cpp @@ -0,0 +1,378 @@ +#if _WIN32 +#ifndef NOMINMAX +#define NOMINMAX +#endif +#define WIN_PAUSE 0 +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include "hecl/Database.hpp" +#include "hecl/Blender/Connection.hpp" +#include "hecl/Runtime.hpp" +#include "logvisor/logvisor.hpp" +#include "../version.h" + +logvisor::Module LogModule("hecl::Driver"); + +#include "ToolBase.hpp" +#include "ToolInit.hpp" +#include "ToolSpec.hpp" +#include "ToolExtract.hpp" +#include "ToolCook.hpp" +#include "ToolPackage.hpp" +#include "ToolImage.hpp" +#include "ToolInstallAddon.hpp" +#include "ToolHelp.hpp" + +/* Static reference to dataspec additions + * (used by MSVC to definitively link DataSpecs) */ +#include "DataSpecRegistry.hpp" + +bool XTERM_COLOR = false; + +/* +#define HECL_GIT 1234567 +#define HECL_GIT_S "1234567" +#define HECL_BRANCH master +#define HECL_BRANCH_S "master" +*/ + +/* Main usage message */ +static void printHelp(const hecl::SystemChar* pname) { + if (XTERM_COLOR) + fmt::print(FMT_STRING(_SYS_STR("" BOLD "HECL" NORMAL ""))); + else + fmt::print(FMT_STRING(_SYS_STR("HECL"))); +#if HECL_HAS_NOD +#define TOOL_LIST "extract|init|cook|package|image|installaddon|help" +#else +#define TOOL_LIST "extract|init|cook|package|installaddon|help" +#endif +#if HECL_GIT + fmt::print(FMT_STRING(_SYS_STR(" Commit " HECL_GIT_S " " HECL_BRANCH_S "\nUsage: {} " TOOL_LIST "\n")), pname); +#elif HECL_VER + fmt::print(FMT_STRING(_SYS_STR(" Version " HECL_VER_S "\nUsage: {} " TOOL_LIST "\n")), pname); +#else + fmt::print(FMT_STRING(_SYS_STR("\nUsage: {} " TOOL_LIST "\n")), pname); +#endif +} + +/* Regex patterns */ +static const hecl::SystemRegex regOPEN(_SYS_STR("-o([^\"]*|\\S*)"), std::regex::ECMAScript | std::regex::optimize); + +static ToolBase* ToolPtr = nullptr; + +/* SIGINT will gracefully close blender connections and delete blends in progress */ +static void SIGINTHandler(int sig) { + if (ToolPtr) + ToolPtr->cancel(); + hecl::blender::Connection::Shutdown(); + logvisor::KillProcessTree(); + exit(1); +} + +static logvisor::Module AthenaLog("Athena"); +static void AthenaExc(athena::error::Level level, const char* file, const char*, int line, fmt::string_view fmt, + fmt::format_args args) { + AthenaLog.vreport(logvisor::Level(level), fmt, args); +} + +hecl::SystemString ExeDir; + +#if _WIN32 +static ToolPassInfo CreateInfo(int argc, const wchar_t** argv) { +#else +static ToolPassInfo CreateInfo(int argc, const char** argv) { +#endif + hecl::SystemChar cwdbuf[1024]; + + ToolPassInfo info; + info.pname = argv[0]; + + if (hecl::Getcwd(cwdbuf, static_cast(std::size(cwdbuf)))) { + info.cwd = cwdbuf; + if (info.cwd.size() && info.cwd.back() != _SYS_STR('/') && info.cwd.back() != _SYS_STR('\\')) { +#if _WIN32 + info.cwd += _SYS_STR('\\'); +#else + info.cwd += _SYS_STR('/'); +#endif + } + + if (hecl::PathRelative(argv[0])) { + ExeDir = hecl::SystemString(cwdbuf) + _SYS_STR('/'); + } + hecl::SystemString Argv0(argv[0]); + hecl::SystemString::size_type lastIdx = Argv0.find_last_of(_SYS_STR("/\\")); + if (lastIdx != hecl::SystemString::npos) { + ExeDir.insert(ExeDir.end(), Argv0.begin(), Argv0.begin() + lastIdx); + } + } + + /* Concatenate args */ + std::vector args; + args.reserve(argc - 2); + for (int i = 2; i < argc; ++i) { + args.emplace_back(argv[i]); + } + + if (!args.empty()) { + /* Extract output argument */ + for (auto it = args.cbegin(); it != args.cend();) { + const hecl::SystemString& arg = *it; + hecl::SystemRegexMatch oMatch; + + if (std::regex_search(arg, oMatch, regOPEN)) { + const hecl::SystemString& token = oMatch[1].str(); + + if (token.size()) { + if (info.output.empty()) { + info.output = oMatch[1].str(); + } + + it = args.erase(it); + } else { + it = args.erase(it); + + if (it == args.end()) { + break; + } + + if (info.output.empty()) { + info.output = *it; + } + + it = args.erase(it); + } + + continue; + } + + ++it; + } + + /* Iterate flags */ + bool threadArg = false; + for (auto it = args.cbegin(); it != args.cend();) { + const hecl::SystemString& arg = *it; + if (threadArg) { + threadArg = false; + hecl::CpuCountOverride = int(hecl::StrToUl(arg.c_str(), nullptr, 0)); + it = args.erase(it); + continue; + } + if (arg.size() < 2 || arg[0] != _SYS_STR('-') || arg[1] == _SYS_STR('-')) { + ++it; + continue; + } + + for (auto chit = arg.cbegin() + 1; chit != arg.cend(); ++chit) { + if (*chit == _SYS_STR('v')) + ++info.verbosityLevel; + else if (*chit == _SYS_STR('f')) + info.force = true; + else if (*chit == _SYS_STR('y')) + info.yes = true; + else if (*chit == _SYS_STR('g')) + info.gui = true; + else if (*chit == _SYS_STR('j')) { + ++chit; + if (*chit) + hecl::CpuCountOverride = int(hecl::StrToUl(&*chit, nullptr, 0)); + else + threadArg = true; + break; + } else + info.flags.push_back(*chit); + } + + it = args.erase(it); + } + + /* Gather remaining args */ + info.args.reserve(args.size()); + for (const hecl::SystemString& arg : args) + info.args.push_back(arg); + } + + return info; +} + +static std::unique_ptr FindProject(hecl::SystemStringView cwd) { + const hecl::ProjectRootPath rootPath = hecl::SearchForProject(cwd); + if (!rootPath) { + return nullptr; + } + + const size_t ErrorRef = logvisor::ErrorCount; + auto newProj = std::make_unique(rootPath); + if (logvisor::ErrorCount > ErrorRef) { +#if WIN_PAUSE + system("PAUSE"); +#endif + return nullptr; + } + + return newProj; +} + +static std::unique_ptr MakeSelectedTool(hecl::SystemString toolName, ToolPassInfo& info) { + hecl::SystemString toolNameLower = toolName; + hecl::ToLower(toolNameLower); + + if (toolNameLower == _SYS_STR("init")) { + return std::make_unique(info); + } + + if (toolNameLower == _SYS_STR("spec")) { + return std::make_unique(info); + } + + if (toolNameLower == _SYS_STR("extract")) { + return std::make_unique(info); + } + + if (toolNameLower == _SYS_STR("cook")) { + return std::make_unique(info); + } + + if (toolNameLower == _SYS_STR("package") || toolNameLower == _SYS_STR("pack")) { + return std::make_unique(info); + } + +#if HECL_HAS_NOD + if (toolNameLower == _SYS_STR("image")) { + return std::make_unique(info); + } +#endif + + if (toolNameLower == _SYS_STR("installaddon")) { + return std::make_unique(info); + } + + if (toolNameLower == _SYS_STR("help")) { + return std::make_unique(info); + } + + auto fp = hecl::FopenUnique(toolName.c_str(), _SYS_STR("rb")); + if (fp == nullptr) { + LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("unrecognized tool '{}'")), toolNameLower); + return nullptr; + } + fp.reset(); + + /* Shortcut-case: implicit extract */ + info.args.insert(info.args.begin(), std::move(toolName)); + return std::make_unique(info); +} + +#if _WIN32 +int wmain(int argc, const wchar_t** argv) +#else +/* SIGWINCH should do nothing */ +static void SIGWINCHHandler(int sig) {} +int main(int argc, const char** argv) +#endif +{ + if (argc > 1 && !hecl::StrCmp(argv[1], _SYS_STR("--dlpackage"))) { + fmt::print(FMT_STRING("{}\n"), METAFORCE_DLPACKAGE); + return 100; + } + +#if _WIN32 + CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE); +#else + std::setlocale(LC_ALL, "en-US.UTF-8"); +#endif + + /* Xterm check */ +#if _WIN32 + const char* conemuANSI = getenv("ConEmuANSI"); + if (conemuANSI && !strcmp(conemuANSI, "ON")) + XTERM_COLOR = true; +#else + const char* term = getenv("TERM"); + if (term && !strncmp(term, "xterm", 5)) + XTERM_COLOR = true; + signal(SIGWINCH, SIGWINCHHandler); +#endif + signal(SIGINT, SIGINTHandler); + + logvisor::RegisterStandardExceptions(); + logvisor::RegisterConsoleLogger(); + atSetExceptionHandler(AthenaExc); + +#if SENTRY_ENABLED + hecl::Runtime::FileStoreManager fileMgr{_SYS_STR("sentry-native-hecl")}; + hecl::SystemUTF8Conv cacheDir{fileMgr.getStoreRoot()}; + logvisor::RegisterSentry("hecl", METAFORCE_WC_DESCRIBE, cacheDir.c_str()); +#endif + + /* Basic usage check */ + if (argc == 1) { + printHelp(argv[0]); +#if WIN_PAUSE + system("PAUSE"); +#endif + return 0; + } else if (argc == 0) { + printHelp(_SYS_STR("hecl")); +#if WIN_PAUSE + system("PAUSE"); +#endif + return 0; + } + + /* Prepare DataSpecs */ + HECLRegisterDataSpecs(); + + /* Assemble common tool pass info */ + ToolPassInfo info = CreateInfo(argc, argv); + + /* Attempt to find hecl project */ + auto project = FindProject(info.cwd); + if (project != nullptr) { + info.project = project.get(); + } + + /* Construct selected tool */ + const size_t MakeToolErrorRef = logvisor::ErrorCount; + auto tool = MakeSelectedTool(argv[1], info); + if (logvisor::ErrorCount > MakeToolErrorRef) { +#if WIN_PAUSE + system("PAUSE"); +#endif + return 1; + } + if (info.verbosityLevel) { + LogModule.report(logvisor::Info, FMT_STRING(_SYS_STR("Constructed tool '{}' {}\n")), tool->toolName(), + info.verbosityLevel); + } + + /* Run tool */ + const size_t RunToolErrorRef = logvisor::ErrorCount; + ToolPtr = tool.get(); + const int retval = tool->run(); + ToolPtr = nullptr; + if (logvisor::ErrorCount > RunToolErrorRef) { + hecl::blender::Connection::Shutdown(); +#if WIN_PAUSE + system("PAUSE"); +#endif + return 1; + } + + hecl::blender::Connection::Shutdown(); +#if WIN_PAUSE + system("PAUSE"); +#endif + return retval; +} diff --git a/hecl/extra/hecl_autocomplete.sh b/hecl/extra/hecl_autocomplete.sh new file mode 100755 index 000000000..eafa89c99 --- /dev/null +++ b/hecl/extra/hecl_autocomplete.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +_hecl () +{ + local word=${COMP_WORDS[COMP_CWORD]} + local filecmds=(init spec extract add remove group cook clean package) + + if [ $COMP_CWORD == 1 ] + then + COMPREPLY=($(compgen -W "${filecmds[*]} help" "${word}")) + return 0 + elif [ $COMP_CWORD == 2 ] + then + case ${COMP_WORDS[1]} in + init|extract|add|remove|group|cook|clean|package) + COMPREPLY=($(compgen -f -- "${word}")) + ;; + spec) + COMPREPLY=($(compgen -W "enable disable" "${word}")) + ;; + help) + COMPREPLY=($(compgen -W "${filecmds[*]}" "${word}")) + ;; + esac + fi +} + +complete -F _hecl hecl + diff --git a/hecl/include/hecl/Backend.hpp b/hecl/include/hecl/Backend.hpp new file mode 100644 index 000000000..d6c667aa0 --- /dev/null +++ b/hecl/include/hecl/Backend.hpp @@ -0,0 +1,231 @@ +#pragma once + +#include +#include +#include +#include + +#include "hecl.hpp" +#include "hecl-xxhash.h" + +namespace hsh { +enum Topology : uint8_t; +} // namespace hsh + +namespace hecl::Backend { +struct ExtensionSlot; +using namespace std::literals; + +enum class TexCoordSource : uint8_t { + Invalid = 0xff, + Position = 0, + Normal = 1, + Tex0 = 2, + Tex1 = 3, + Tex2 = 4, + Tex3 = 5, + Tex4 = 6, + Tex5 = 7, + Tex6 = 8, + Tex7 = 9, +}; + +enum class BlendFactor : uint8_t { + Zero, + One, + SrcColor, + InvSrcColor, + DstColor, + InvDstColor, + SrcAlpha, + InvSrcAlpha, + DstAlpha, + InvDstAlpha, + SrcColor1, + InvSrcColor1, + Original = 0xff +}; + +constexpr std::string_view BlendFactorToDefine(BlendFactor factor, BlendFactor defaultFactor) { + switch (factor) { + case BlendFactor::Zero: + return "ZERO"sv; + case BlendFactor::One: + return "ONE"sv; + case BlendFactor::SrcColor: + return "SRCCOLOR"sv; + case BlendFactor::InvSrcColor: + return "INVSRCCOLOR"sv; + case BlendFactor::DstColor: + return "DSTCOLOR"sv; + case BlendFactor::InvDstColor: + return "INVDSTCOLOR"sv; + case BlendFactor::SrcAlpha: + return "SRCALPHA"sv; + case BlendFactor::InvSrcAlpha: + return "INVSRCALPHA"sv; + case BlendFactor::DstAlpha: + return "DSTALPHA"sv; + case BlendFactor::InvDstAlpha: + return "INVDSTALPHA"sv; + case BlendFactor::SrcColor1: + return "SRCCOLOR1"sv; + case BlendFactor::InvSrcColor1: + return "INVSRCCOLOR1"sv; + default: + return BlendFactorToDefine(defaultFactor, BlendFactor::Zero); + } +} + +enum class ZTest : uint8_t { None, LEqual, Greater, Equal, GEqual, Original = 0xff }; + +enum class CullMode : uint8_t { None, Backface, Frontface, Original = 0xff }; + +struct TextureInfo { + TexCoordSource src; + uint8_t mtxIdx; + bool normalize; +}; + +enum class ReflectionType { None, Simple, Indirect }; + +/** + * @brief Hash subclass for identifying shaders and their metadata + */ +class ShaderTag : public Hash { + union { + uint64_t m_meta = 0; + struct { + uint8_t m_colorCount; + uint8_t m_uvCount; + uint8_t m_weightCount; + uint8_t m_skinSlotCount; + uint8_t m_primitiveType; + uint8_t m_reflectionType; + bool m_depthTest : 1; + bool m_depthWrite : 1; + bool m_backfaceCulling : 1; + bool m_alphaTest : 1; + }; + }; + +public: + ShaderTag() = default; + ShaderTag(std::string_view source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, hsh::Topology pt, + Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling, + bool alphaTest) + : Hash(source) { + m_colorCount = c; + m_uvCount = u; + m_weightCount = w; + m_skinSlotCount = s; + m_primitiveType = uint8_t(pt); + m_reflectionType = uint8_t(reflectionType); + m_depthTest = depthTest; + m_depthWrite = depthWrite; + m_backfaceCulling = backfaceCulling; + m_alphaTest = alphaTest; + hash ^= m_meta; + } + ShaderTag(uint64_t hashin, uint8_t c, uint8_t u, uint8_t w, uint8_t s, hsh::Topology pt, + Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling, + bool alphaTest) + : Hash(hashin) { + m_colorCount = c; + m_uvCount = u; + m_weightCount = w; + m_skinSlotCount = s; + m_primitiveType = uint8_t(pt); + m_reflectionType = uint8_t(reflectionType); + m_depthTest = depthTest; + m_depthWrite = depthWrite; + m_backfaceCulling = backfaceCulling; + m_alphaTest = alphaTest; + hash ^= m_meta; + } + ShaderTag(uint64_t comphashin, uint64_t meta) : Hash(comphashin), m_meta(meta) {} + ShaderTag(const ShaderTag& other) : Hash(other), m_meta(other.m_meta) {} + uint8_t getColorCount() const { return m_colorCount; } + uint8_t getUvCount() const { return m_uvCount; } + uint8_t getWeightCount() const { return m_weightCount; } + uint8_t getSkinSlotCount() const { return m_skinSlotCount; } + hsh::Topology getPrimType() const { return hsh::Topology(m_primitiveType); } + Backend::ReflectionType getReflectionType() const { return Backend::ReflectionType(m_reflectionType); } + bool getDepthTest() const { return m_depthTest; } + bool getDepthWrite() const { return m_depthWrite; } + bool getBackfaceCulling() const { return m_backfaceCulling; } + bool getAlphaTest() const { return m_alphaTest; } + uint64_t getMetaData() const { return m_meta; } +}; + +struct Function { + std::string_view m_source; + std::string_view m_entry; + Function() = default; + Function(std::string_view source, std::string_view entry) : m_source(source), m_entry(entry) {} +}; + +struct ExtensionSlot { + const char* shaderMacro = nullptr; + size_t texCount = 0; + const Backend::TextureInfo* texs = nullptr; + Backend::BlendFactor srcFactor = Backend::BlendFactor::Original; + Backend::BlendFactor dstFactor = Backend::BlendFactor::Original; + Backend::ZTest depthTest = Backend::ZTest::Original; + Backend::CullMode cullMode = Backend::CullMode::Backface; + bool noDepthWrite = false; + bool noColorWrite = false; + bool noAlphaWrite = false; + bool noAlphaOverwrite = false; + bool noReflection = false; + bool forceAlphaTest = false; + bool diffuseOnly = false; + + constexpr ExtensionSlot(size_t texCount = 0, const Backend::TextureInfo* texs = nullptr, + Backend::BlendFactor srcFactor = Backend::BlendFactor::Original, + Backend::BlendFactor dstFactor = Backend::BlendFactor::Original, + Backend::ZTest depthTest = Backend::ZTest::Original, + Backend::CullMode cullMode = Backend::CullMode::Backface, bool noDepthWrite = false, + bool noColorWrite = false, bool noAlphaWrite = false, bool noAlphaOverwrite = false, + bool noReflection = false, bool forceAlphaTest = false, bool diffuseOnly = false) noexcept + : texCount(texCount) + , texs(texs) + , srcFactor(srcFactor) + , dstFactor(dstFactor) + , depthTest(depthTest) + , cullMode(cullMode) + , noDepthWrite(noDepthWrite) + , noColorWrite(noColorWrite) + , noAlphaWrite(noAlphaWrite) + , noAlphaOverwrite(noAlphaOverwrite) + , noReflection(noReflection) + , forceAlphaTest(forceAlphaTest) + , diffuseOnly(diffuseOnly) {} + + mutable uint64_t m_hash = 0; + void calculateHash() const { + XXH64_state_t st; + XXH64_reset(&st, 0); + XXH64_update(&st, shaderMacro, strlen(shaderMacro)); + for (size_t i = 0; i < texCount; ++i) { + const Backend::TextureInfo& tinfo = texs[i]; + XXH64_update(&st, &tinfo, sizeof(tinfo)); + } + XXH64_update(&st, &srcFactor, offsetof(ExtensionSlot, m_hash) - offsetof(ExtensionSlot, srcFactor)); + m_hash = XXH64_digest(&st); + } + uint64_t hash() const { + if (m_hash == 0) + calculateHash(); + return m_hash; + } +}; + +} // namespace hecl::Backend + +namespace std { +template <> +struct hash { + size_t operator()(const hecl::Backend::ShaderTag& val) const noexcept { return val.valSizeT(); } +}; +} // namespace std diff --git a/hecl/include/hecl/BitVector.hpp b/hecl/include/hecl/BitVector.hpp new file mode 100644 index 000000000..3944b6512 --- /dev/null +++ b/hecl/include/hecl/BitVector.hpp @@ -0,0 +1,588 @@ +//===- llvm/ADT/BitVector.h - Bit vectors -----------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the BitVector class. +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "MathExtras.hpp" +#include +#include +#include +#include +#include +#include + +namespace hecl { +namespace llvm { + +class BitVector { + typedef unsigned long BitWord; + + enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT }; + + static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32, "Unsupported word size"); + + BitWord* Bits; // Actual bits. + unsigned Size; // Size of bitvector in bits. + unsigned Capacity; // Number of BitWords allocated in the Bits array. + +public: + typedef unsigned size_type; + // Encapsulation of a single bit. + class reference { + friend class BitVector; + + BitWord* WordRef; + unsigned BitPos; + + reference(); // Undefined + + public: + reference(BitVector& b, unsigned Idx) { + WordRef = &b.Bits[Idx / BITWORD_SIZE]; + BitPos = Idx % BITWORD_SIZE; + } + + reference(const reference&) = default; + + reference& operator=(reference t) { + *this = bool(t); + return *this; + } + + reference& operator=(bool t) { + if (t) + *WordRef |= BitWord(1) << BitPos; + else + *WordRef &= ~(BitWord(1) << BitPos); + return *this; + } + + explicit operator bool() const { return ((*WordRef) & (BitWord(1) << BitPos)) != 0; } + }; + + /// BitVector default ctor - Creates an empty bitvector. + BitVector() : Size(0), Capacity(0) { Bits = nullptr; } + + /// BitVector ctor - Creates a bitvector of specified number of bits. All + /// bits are initialized to the specified value. + explicit BitVector(unsigned s, bool t = false) : Size(s) { + Capacity = NumBitWords(s); + Bits = (BitWord*)std::malloc(Capacity * sizeof(BitWord)); + init_words(Bits, Capacity, t); + if (t) + clear_unused_bits(); + } + + /// BitVector copy ctor. + BitVector(const BitVector& RHS) : Size(RHS.size()) { + if (Size == 0) { + Bits = nullptr; + Capacity = 0; + return; + } + + Capacity = NumBitWords(RHS.size()); + Bits = (BitWord*)std::malloc(Capacity * sizeof(BitWord)); + std::memcpy(Bits, RHS.Bits, Capacity * sizeof(BitWord)); + } + + BitVector(BitVector&& RHS) : Bits(RHS.Bits), Size(RHS.Size), Capacity(RHS.Capacity) { + RHS.Bits = nullptr; + RHS.Size = RHS.Capacity = 0; + } + + ~BitVector() { std::free(Bits); } + + /// empty - Tests whether there are no bits in this bitvector. + bool empty() const { return Size == 0; } + + /// size - Returns the number of bits in this bitvector. + size_type size() const { return Size; } + + /// count - Returns the number of bits which are set. + size_type count() const { + unsigned NumBits = 0; + for (unsigned i = 0; i < NumBitWords(size()); ++i) + NumBits += countPopulation(Bits[i]); + return NumBits; + } + + /// any - Returns true if any bit is set. + bool any() const { + for (unsigned i = 0; i < NumBitWords(size()); ++i) + if (Bits[i] != 0) + return true; + return false; + } + + /// all - Returns true if all bits are set. + bool all() const { + for (unsigned i = 0; i < Size / BITWORD_SIZE; ++i) + if (Bits[i] != ~0UL) + return false; + + // If bits remain check that they are ones. The unused bits are always zero. + if (unsigned Remainder = Size % BITWORD_SIZE) + return Bits[Size / BITWORD_SIZE] == (1UL << Remainder) - 1; + + return true; + } + + /// none - Returns true if none of the bits are set. + bool none() const { return !any(); } + + /// find_first - Returns the index of the first set bit, -1 if none + /// of the bits are set. + int find_first() const { + for (unsigned i = 0; i < NumBitWords(size()); ++i) + if (Bits[i] != 0) + return i * BITWORD_SIZE + countTrailingZeros(Bits[i]); + return -1; + } + + /// find_next - Returns the index of the next set bit following the + /// "Prev" bit. Returns -1 if the next set bit is not found. + int find_next(unsigned Prev) const { + ++Prev; + if (Prev >= Size) + return -1; + + unsigned WordPos = Prev / BITWORD_SIZE; + unsigned BitPos = Prev % BITWORD_SIZE; + BitWord Copy = Bits[WordPos]; + // Mask off previous bits. + Copy &= ~0UL << BitPos; + + if (Copy != 0) + return WordPos * BITWORD_SIZE + countTrailingZeros(Copy); + + // Check subsequent words. + for (unsigned i = WordPos + 1; i < NumBitWords(size()); ++i) + if (Bits[i] != 0) + return i * BITWORD_SIZE + countTrailingZeros(Bits[i]); + return -1; + } + + /// find_first_contiguous - Returns the index of the first contiguous + /// set of bits of "Length", -1 if no contiguous bits found. + int find_first_contiguous(unsigned Length, unsigned BucketSz) const { + for (int idx = find_first(); idx != -1; idx = find_next(idx)) { + if (idx + Length > size()) + return -1; + bool good = true; + for (unsigned i = 0; i < Length; ++i) { + int ThisIdx = idx + i; + if (!test(ThisIdx)) { + good = false; + idx = ThisIdx; + break; + } + } + if (good) { + unsigned space = BucketSz - (idx % BucketSz); + if (space >= Length) + return idx; + } + } + return -1; + } + + /// clear - Clear all bits. + void clear() { Size = 0; } + + /// resize - Grow or shrink the bitvector. + void resize(unsigned N, bool t = false) { + if (N > Capacity * BITWORD_SIZE) { + unsigned OldCapacity = Capacity; + grow(N); + init_words(&Bits[OldCapacity], (Capacity - OldCapacity), t); + } + + // Set any old unused bits that are now included in the BitVector. This + // may set bits that are not included in the new vector, but we will clear + // them back out below. + if (N > Size) + set_unused_bits(t); + + // Update the size, and clear out any bits that are now unused + unsigned OldSize = Size; + Size = N; + if (t || N < OldSize) + clear_unused_bits(); + } + + void reserve(unsigned N) { + if (N > Capacity * BITWORD_SIZE) + grow(N); + } + + // Set, reset, flip + BitVector& set() { + init_words(Bits, Capacity, true); + clear_unused_bits(); + return *this; + } + + BitVector& set(unsigned Idx) { + assert(Bits && "Bits never allocated"); + Bits[Idx / BITWORD_SIZE] |= BitWord(1) << (Idx % BITWORD_SIZE); + return *this; + } + + /// set - Efficiently set a range of bits in [I, E) + BitVector& set(unsigned I, unsigned E) { + assert(I <= E && "Attempted to set backwards range!"); + assert(E <= size() && "Attempted to set out-of-bounds range!"); + + if (I == E) + return *this; + + if (I / BITWORD_SIZE == E / BITWORD_SIZE) { + BitWord EMask = 1UL << (E % BITWORD_SIZE); + BitWord IMask = 1UL << (I % BITWORD_SIZE); + BitWord Mask = EMask - IMask; + Bits[I / BITWORD_SIZE] |= Mask; + return *this; + } + + BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE); + Bits[I / BITWORD_SIZE] |= PrefixMask; + I = alignTo(I, BITWORD_SIZE); + + for (; I + BITWORD_SIZE <= E; I += BITWORD_SIZE) + Bits[I / BITWORD_SIZE] = ~0UL; + + BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1; + if (I < E) + Bits[I / BITWORD_SIZE] |= PostfixMask; + + return *this; + } + + BitVector& reset() { + init_words(Bits, Capacity, false); + return *this; + } + + BitVector& reset(unsigned Idx) { + Bits[Idx / BITWORD_SIZE] &= ~(BitWord(1) << (Idx % BITWORD_SIZE)); + return *this; + } + + /// reset - Efficiently reset a range of bits in [I, E) + BitVector& reset(unsigned I, unsigned E) { + assert(I <= E && "Attempted to reset backwards range!"); + assert(E <= size() && "Attempted to reset out-of-bounds range!"); + + if (I == E) + return *this; + + if (I / BITWORD_SIZE == E / BITWORD_SIZE) { + BitWord EMask = 1UL << (E % BITWORD_SIZE); + BitWord IMask = 1UL << (I % BITWORD_SIZE); + BitWord Mask = EMask - IMask; + Bits[I / BITWORD_SIZE] &= ~Mask; + return *this; + } + + BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE); + Bits[I / BITWORD_SIZE] &= ~PrefixMask; + I = alignTo(I, BITWORD_SIZE); + + for (; I + BITWORD_SIZE <= E; I += BITWORD_SIZE) + Bits[I / BITWORD_SIZE] = 0UL; + + BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1; + if (I < E) + Bits[I / BITWORD_SIZE] &= ~PostfixMask; + + return *this; + } + + BitVector& flip() { + for (unsigned i = 0; i < NumBitWords(size()); ++i) + Bits[i] = ~Bits[i]; + clear_unused_bits(); + return *this; + } + + BitVector& flip(unsigned Idx) { + Bits[Idx / BITWORD_SIZE] ^= BitWord(1) << (Idx % BITWORD_SIZE); + return *this; + } + + // Indexing. + reference operator[](unsigned Idx) { + assert(Idx < Size && "Out-of-bounds Bit access."); + return reference(*this, Idx); + } + + bool operator[](unsigned Idx) const { + assert(Idx < Size && "Out-of-bounds Bit access."); + BitWord Mask = BitWord(1) << (Idx % BITWORD_SIZE); + return (Bits[Idx / BITWORD_SIZE] & Mask) != 0; + } + + bool test(unsigned Idx) const { return (*this)[Idx]; } + + /// Test if any common bits are set. + bool anyCommon(const BitVector& RHS) const { + unsigned ThisWords = NumBitWords(size()); + unsigned RHSWords = NumBitWords(RHS.size()); + for (unsigned i = 0, e = std::min(ThisWords, RHSWords); i != e; ++i) + if (Bits[i] & RHS.Bits[i]) + return true; + return false; + } + + // Comparison operators. + bool operator==(const BitVector& RHS) const { + unsigned ThisWords = NumBitWords(size()); + unsigned RHSWords = NumBitWords(RHS.size()); + unsigned i; + for (i = 0; i != std::min(ThisWords, RHSWords); ++i) + if (Bits[i] != RHS.Bits[i]) + return false; + + // Verify that any extra words are all zeros. + if (i != ThisWords) { + for (; i != ThisWords; ++i) + if (Bits[i]) + return false; + } else if (i != RHSWords) { + for (; i != RHSWords; ++i) + if (RHS.Bits[i]) + return false; + } + return true; + } + + bool operator!=(const BitVector& RHS) const { return !(*this == RHS); } + + /// Intersection, union, disjoint union. + BitVector& operator&=(const BitVector& RHS) { + unsigned ThisWords = NumBitWords(size()); + unsigned RHSWords = NumBitWords(RHS.size()); + unsigned i; + for (i = 0; i != std::min(ThisWords, RHSWords); ++i) + Bits[i] &= RHS.Bits[i]; + + // Any bits that are just in this bitvector become zero, because they aren't + // in the RHS bit vector. Any words only in RHS are ignored because they + // are already zero in the LHS. + for (; i != ThisWords; ++i) + Bits[i] = 0; + + return *this; + } + + /// reset - Reset bits that are set in RHS. Same as *this &= ~RHS. + BitVector& reset(const BitVector& RHS) { + unsigned ThisWords = NumBitWords(size()); + unsigned RHSWords = NumBitWords(RHS.size()); + unsigned i; + for (i = 0; i != std::min(ThisWords, RHSWords); ++i) + Bits[i] &= ~RHS.Bits[i]; + return *this; + } + + /// test - Check if (This - RHS) is zero. + /// This is the same as reset(RHS) and any(). + bool test(const BitVector& RHS) const { + unsigned ThisWords = NumBitWords(size()); + unsigned RHSWords = NumBitWords(RHS.size()); + unsigned i; + for (i = 0; i != std::min(ThisWords, RHSWords); ++i) + if ((Bits[i] & ~RHS.Bits[i]) != 0) + return true; + + for (; i != ThisWords; ++i) + if (Bits[i] != 0) + return true; + + return false; + } + + BitVector& operator|=(const BitVector& RHS) { + if (size() < RHS.size()) + resize(RHS.size()); + for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i) + Bits[i] |= RHS.Bits[i]; + return *this; + } + + BitVector& operator^=(const BitVector& RHS) { + if (size() < RHS.size()) + resize(RHS.size()); + for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i) + Bits[i] ^= RHS.Bits[i]; + return *this; + } + + // Assignment operator. + const BitVector& operator=(const BitVector& RHS) { + if (this == &RHS) + return *this; + + Size = RHS.size(); + unsigned RHSWords = NumBitWords(Size); + if (Size <= Capacity * BITWORD_SIZE) { + if (Size) + std::memcpy(Bits, RHS.Bits, RHSWords * sizeof(BitWord)); + clear_unused_bits(); + return *this; + } + + // Grow the bitvector to have enough elements. + Capacity = RHSWords; + assert(Capacity > 0 && "negative capacity?"); + BitWord* NewBits = (BitWord*)std::malloc(Capacity * sizeof(BitWord)); + std::memcpy(NewBits, RHS.Bits, Capacity * sizeof(BitWord)); + + // Destroy the old bits. + std::free(Bits); + Bits = NewBits; + + return *this; + } + + const BitVector& operator=(BitVector&& RHS) { + if (this == &RHS) + return *this; + + std::free(Bits); + Bits = RHS.Bits; + Size = RHS.Size; + Capacity = RHS.Capacity; + + RHS.Bits = nullptr; + RHS.Size = RHS.Capacity = 0; + + return *this; + } + + void swap(BitVector& RHS) { + std::swap(Bits, RHS.Bits); + std::swap(Size, RHS.Size); + std::swap(Capacity, RHS.Capacity); + } + + //===--------------------------------------------------------------------===// + // Portable bit mask operations. + //===--------------------------------------------------------------------===// + // + // These methods all operate on arrays of uint32_t, each holding 32 bits. The + // fixed word size makes it easier to work with literal bit vector constants + // in portable code. + // + // The LSB in each word is the lowest numbered bit. The size of a portable + // bit mask is always a whole multiple of 32 bits. If no bit mask size is + // given, the bit mask is assumed to cover the entire BitVector. + + /// setBitsInMask - Add '1' bits from Mask to this vector. Don't resize. + /// This computes "*this |= Mask". + void setBitsInMask(const uint32_t* Mask, unsigned MaskWords = ~0u) { applyMask(Mask, MaskWords); } + + /// clearBitsInMask - Clear any bits in this vector that are set in Mask. + /// Don't resize. This computes "*this &= ~Mask". + void clearBitsInMask(const uint32_t* Mask, unsigned MaskWords = ~0u) { applyMask(Mask, MaskWords); } + + /// setBitsNotInMask - Add a bit to this vector for every '0' bit in Mask. + /// Don't resize. This computes "*this |= ~Mask". + void setBitsNotInMask(const uint32_t* Mask, unsigned MaskWords = ~0u) { applyMask(Mask, MaskWords); } + + /// clearBitsNotInMask - Clear a bit in this vector for every '0' bit in Mask. + /// Don't resize. This computes "*this &= Mask". + void clearBitsNotInMask(const uint32_t* Mask, unsigned MaskWords = ~0u) { applyMask(Mask, MaskWords); } + +private: + unsigned NumBitWords(unsigned S) const { return (S + BITWORD_SIZE - 1) / BITWORD_SIZE; } + + // Set the unused bits in the high words. + void set_unused_bits(bool t = true) { + // Set high words first. + unsigned UsedWords = NumBitWords(Size); + if (Capacity > UsedWords) + init_words(&Bits[UsedWords], (Capacity - UsedWords), t); + + // Then set any stray high bits of the last used word. + unsigned ExtraBits = Size % BITWORD_SIZE; + if (ExtraBits) { + BitWord ExtraBitMask = ~0UL << ExtraBits; + if (t) + Bits[UsedWords - 1] |= ExtraBitMask; + else + Bits[UsedWords - 1] &= ~ExtraBitMask; + } + } + + // Clear the unused bits in the high words. + void clear_unused_bits() { set_unused_bits(false); } + + void grow(unsigned NewSize) { + Capacity = std::max(NumBitWords(NewSize), Capacity * 2); + assert(Capacity > 0 && "realloc-ing zero space"); + Bits = (BitWord*)std::realloc(Bits, Capacity * sizeof(BitWord)); + + clear_unused_bits(); + } + + void init_words(BitWord* B, unsigned NumWords, bool t) { memset(B, 0 - (int)t, NumWords * sizeof(BitWord)); } + + template + void applyMask(const uint32_t* Mask, unsigned MaskWords) { + static_assert(BITWORD_SIZE % 32 == 0, "Unsupported BitWord size."); + MaskWords = std::min(MaskWords, (size() + 31) / 32); + const unsigned Scale = BITWORD_SIZE / 32; + unsigned i; + for (i = 0; MaskWords >= Scale; ++i, MaskWords -= Scale) { + BitWord BW = Bits[i]; + // This inner loop should unroll completely when BITWORD_SIZE > 32. + for (unsigned b = 0; b != BITWORD_SIZE; b += 32) { + uint32_t M = *Mask++; + if (InvertMask) + M = ~M; + if (AddBits) + BW |= BitWord(M) << b; + else + BW &= ~(BitWord(M) << b); + } + Bits[i] = BW; + } + for (unsigned b = 0; MaskWords; b += 32, --MaskWords) { + uint32_t M = *Mask++; + if (InvertMask) + M = ~M; + if (AddBits) + Bits[i] |= BitWord(M) << b; + else + Bits[i] &= ~(BitWord(M) << b); + } + if (AddBits) + clear_unused_bits(); + } + +public: + /// Return the size (in bytes) of the bit vector. + size_t getMemorySize() const { return Capacity * sizeof(BitWord); } +}; + +static inline size_t capacity_in_bytes(const BitVector& X) { return X.getMemorySize(); } + +} // end namespace llvm +} // end namespace hecl + +namespace std { +/// Implement std::swap in terms of BitVector swap. +inline void swap(hecl::llvm::BitVector& LHS, hecl::llvm::BitVector& RHS) { LHS.swap(RHS); } +} // end namespace std diff --git a/hecl/include/hecl/Blender/Connection.hpp b/hecl/include/hecl/Blender/Connection.hpp new file mode 100644 index 000000000..f207816f4 --- /dev/null +++ b/hecl/include/hecl/Blender/Connection.hpp @@ -0,0 +1,938 @@ +#pragma once + +#if _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hecl/hecl.hpp" +#include "hecl/Backend.hpp" +#include "hecl/HMDLMeta.hpp" +#include "hecl/TypedVariant.hpp" + +#include +#include +#include + +namespace hecl::blender { +using namespace std::literals; + +class Connection; +class HMDLBuffers; + +extern logvisor::Module BlenderLog; + +struct PoolSkinIndex { + std::size_t m_poolSz = 0; + std::unique_ptr m_poolToSkinIndex; + + void allocate(std::size_t poolSz) { + m_poolSz = poolSz; + if (poolSz) + m_poolToSkinIndex.reset(new uint32_t[poolSz]); + } +}; + +enum class ANIMCurveType { Rotate, Translate, Scale }; + +class ANIMOutStream { + Connection* m_parent; + unsigned m_curCount = 0; + unsigned m_totalCount = 0; + bool m_inCurve = false; + +public: + using CurveType = ANIMCurveType; + ANIMOutStream(Connection* parent); + ~ANIMOutStream(); + void changeCurve(CurveType type, unsigned crvIdx, unsigned keyCount); + void write(unsigned frame, float val); +}; + +class PyOutStream : public std::ostream { + friend class Connection; + Connection* m_parent; + struct StreamBuf : std::streambuf { + PyOutStream& m_parent; + std::string m_lineBuf; + bool m_deleteOnError; + StreamBuf(PyOutStream& parent, bool deleteOnError) : m_parent(parent), m_deleteOnError(deleteOnError) {} + StreamBuf(const StreamBuf& other) = delete; + StreamBuf(StreamBuf&& other) = default; + bool sendLine(std::string_view line); + int_type overflow(int_type ch) override; + std::streamsize xsputn(const char_type* __s, std::streamsize __n) override; + } m_sbuf; + PyOutStream(Connection* parent, bool deleteOnError); + +public: + PyOutStream(const PyOutStream& other) = delete; + PyOutStream(PyOutStream&& other) : std::ostream(&m_sbuf), m_parent(other.m_parent), m_sbuf(std::move(other.m_sbuf)) { + other.m_parent = nullptr; + } + ~PyOutStream() override { close(); } + void close(); + template > + void format(const S& format, Args&&... args); + void linkBlend(std::string_view target, std::string_view objName, bool link = true); + void linkArmature(std::string_view target, std::string_view armName); + void linkMesh(std::string_view target, std::string_view meshName); + void linkBackground(std::string_view target, std::string_view sceneName = {}); + void AABBToBMesh(const atVec3f& min, const atVec3f& max); + void centerView(); + + ANIMOutStream beginANIMCurve() { return ANIMOutStream(m_parent); } + Connection& getConnection() { return *m_parent; } +}; + +/* Vector types with integrated stream reading constructor */ +struct Vector2f { + atVec2f val; + Vector2f() = default; + void read(Connection& conn); + Vector2f(Connection& conn) { read(conn); } + operator const atVec2f&() const { return val; } + bool operator==(const Vector2f& other) const { + return val.simd[0] == other.val.simd[0] && + val.simd[1] == other.val.simd[1]; + } +}; +struct Vector3f { + atVec3f val; + Vector3f() = default; + void read(Connection& conn); + Vector3f(Connection& conn) { read(conn); } + operator const atVec3f&() const { return val; } + bool operator==(const Vector3f& other) const { + return val.simd[0] == other.val.simd[0] && + val.simd[1] == other.val.simd[1] && + val.simd[2] == other.val.simd[2]; + } +}; +struct Vector4f { + atVec4f val; + Vector4f() = default; + void read(Connection& conn); + Vector4f(Connection& conn) { read(conn); } + operator const atVec4f&() const { return val; } + bool operator==(const Vector4f& other) const { + return val.simd[0] == other.val.simd[0] && + val.simd[1] == other.val.simd[1] && + val.simd[2] == other.val.simd[2] && + val.simd[3] == other.val.simd[3]; + } +}; +struct Matrix3f { + std::array m; + atVec3f& operator[](std::size_t idx) { return m[idx]; } + const atVec3f& operator[](std::size_t idx) const { return m[idx]; } +}; +struct Matrix4f { + std::array val; + Matrix4f() = default; + Matrix4f(Connection& conn) { read(conn); } + void read(Connection& conn); + const atVec4f& operator[](std::size_t idx) const { return val[idx]; } +}; +struct Index { + uint32_t val; + Index() = default; + void read(Connection& conn); + Index(Connection& conn) { read(conn); } + operator const uint32_t&() const { return val; } +}; +struct Float { + float val; + Float() = default; + void read(Connection& conn); + Float(Connection& conn) { read(conn); } + operator const float&() const { return val; } +}; +struct Boolean { + bool val; + Boolean() = default; + void read(Connection& conn); + Boolean(Connection& conn) { read(conn); } + operator const bool&() const { return val; } +}; + +atVec3f MtxVecMul4RM(const Matrix4f& mtx, const Vector3f& vec); +atVec3f MtxVecMul3RM(const Matrix4f& mtx, const Vector3f& vec); + +/** Intermediate material representation */ +struct Material { + enum class ShaderType : uint32_t { + Invalid = 0, + RetroShader = 'RSHD', + RetroDynamicShader = 'RDYN', + RetroDynamicAlphaShader = 'RDAL', + RetroDynamicCharacterShader = 'RCHR', + }; + enum class ChunkType : uint32_t { + Invalid = 0, + TexturePass = 'PASS', + ColorPass = 'CLR ', + }; + enum class PassType : uint32_t { + Invalid = 0, + Lightmap = 'LMAP', + Diffuse = 'DIFF', + Emissive = 'EMIS', + Specular = 'SPEC', + ExtendedSpecular = 'ESPC', + Reflection = 'REFL', + IndirectTex = 'INDR', + Alpha = 'ALPH', + }; + static constexpr std::string_view PassTypeToString(PassType tp) { + switch (tp) { + case PassType::Lightmap: return "lightmap"sv; + case PassType::Diffuse: return "diffuse"sv; + case PassType::Emissive: return "emissive"sv; + case PassType::Specular: return "specular"sv; + case PassType::ExtendedSpecular: return "extendedSpecular"sv; + case PassType::Reflection: return "reflection"sv; + case PassType::Alpha: return "alpha"sv; + default: + assert(false && "Unknown pass type"); + return ""sv; + } + } + enum class UVAnimType : uint8_t { + MvInvNoTranslation, + MvInv, + Scroll, + Rotation, + HStrip, + VStrip, + Model, + CylinderEnvironment, + Eight, + Invalid = UINT8_MAX + }; + using TexCoordSource = hecl::Backend::TexCoordSource; + struct PASS : hecl::TypedRecord { + PassType type; + ProjectPath tex; + TexCoordSource source; + UVAnimType uvAnimType; + std::array uvAnimParms = {}; + bool alpha; + explicit PASS(Connection& conn); + bool operator==(const PASS& other) const { + return type == other.type && + tex == other.tex && + source == other.source && + uvAnimType == other.uvAnimType && + uvAnimParms == other.uvAnimParms && + alpha == other.alpha; + } + void hash(XXH64_state_t* st) const { + XXH64_update(st, &type, sizeof(type)); + XXH64_update(st, &source, sizeof(source)); + XXH64_update(st, &uvAnimType, sizeof(uvAnimType)); + XXH64_update(st, &alpha, sizeof(alpha)); + } + }; + struct CLR : hecl::TypedRecord { + PassType type; + Vector4f color; + explicit CLR(Connection& conn); + bool operator==(const CLR& other) const { + return type == other.type && color == other.color; + } + void hash(XXH64_state_t* st) const { + XXH64_update(st, &type, sizeof(type)); + } + }; + using Chunk = hecl::TypedVariant; + + enum class BlendMode : uint32_t { + Opaque = 0, + Alpha = 1, + Additive = 2 + }; + + std::string name; + uint32_t passIndex; + ShaderType shaderType; + std::vector chunks; + std::unordered_map iprops; + BlendMode blendMode = BlendMode::Opaque; + + explicit Material(Connection& conn); + bool operator==(const Material& other) const { + return chunks == other.chunks && iprops == other.iprops && blendMode == other.blendMode; + } +}; + +/** Intermediate mesh representation prepared by blender from a single mesh object */ +struct Mesh { + static constexpr std::size_t MaxColorLayers = 4; + static constexpr std::size_t MaxUVLayers = 8; + static constexpr std::size_t MaxSkinEntries = 16; + + HMDLTopology topology; + + /* Object transform in scene */ + Matrix4f sceneXf; + + /* Cumulative AABB */ + Vector3f aabbMin; + Vector3f aabbMax; + + std::vector> materialSets; + + /* Vertex buffer data */ + std::vector pos; + std::vector norm; + uint32_t colorLayerCount = 0; + std::vector color; + uint32_t uvLayerCount = 0; + std::vector uv; + uint32_t luvLayerCount = 0; + std::vector luv; + + /* Skinning data */ + std::vector boneNames; + struct SkinBind { + uint32_t vg_idx = UINT32_MAX; + float weight = 0.f; + SkinBind() = default; + explicit SkinBind(Connection& conn); + bool valid() const { return vg_idx != UINT32_MAX; } + bool operator==(const SkinBind& other) const { return vg_idx == other.vg_idx && weight == other.weight; } + }; + std::vector> skins; + std::vector contiguousSkinVertCounts; + + static std::size_t countSkinBinds(const std::array& arr) { + std::size_t ret = 0; + for (const auto& b : arr) + if (b.valid()) + ++ret; + else + break; + return ret; + } + void normalizeSkinBinds(); + + /** Islands of the same material/skinBank are represented here */ + struct Surface { + Vector3f centroid; + uint32_t materialIdx; + Vector3f aabbMin; + Vector3f aabbMax; + Vector3f reflectionNormal; + uint32_t skinBankIdx; + + /** Vertex indexing data (all primitives joined as degenerate tri-strip) */ + struct Vert { + uint32_t iPos = 0xffffffff; + uint32_t iNorm = 0xffffffff; + std::array iColor = {0xffffffff}; + std::array iUv = {0xffffffff}; + uint32_t iSkin = 0xffffffff; + uint32_t iBankSkin = 0xffffffff; + + bool operator==(const Vert& other) const; + }; + std::vector verts; + }; + std::vector surfaces; + + std::unordered_map customProps; + + struct SkinBanks { + struct Bank { + std::vector m_skinIdxs; + std::vector m_boneIdxs; + + void addSkins(const Mesh& parent, const std::vector& skinIdxs); + }; + std::vector banks; + std::vector::iterator addSkinBank(int skinSlotCount); + uint32_t addSurface(const Mesh& mesh, const Surface& surf, int skinSlotCount); + } skinBanks; + + Mesh(Connection& conn, HMDLTopology topology, int skinSlotCount, bool useLuvs = false); + + Mesh getContiguousSkinningVersion() const; + + /** Prepares mesh representation for indexed access on modern APIs. + * Mesh must remain resident for accessing reference members + */ + HMDLBuffers getHMDLBuffers(bool absoluteCoords, PoolSkinIndex& poolSkinIndex) const; +}; + +/** Intermediate collision mesh representation prepared by blender from a single mesh object */ +struct ColMesh { + /** HECL source and metadata of each material */ + struct Material { + std::string name; + bool unknown; + bool surfaceStone; + bool surfaceMetal; + bool surfaceGrass; + bool surfaceIce; + bool pillar; + bool surfaceMetalGrating; + bool surfacePhazon; + bool surfaceDirt; + bool surfaceLava; + bool surfaceSPMetal; + bool surfaceLavaStone; + bool surfaceSnow; + bool surfaceMudSlow; + bool surfaceFabric; + bool halfPipe; + bool surfaceMud; + bool surfaceGlass; + bool unused3; + bool unused4; + bool surfaceShield; + bool surfaceSand; + bool surfaceMothOrSeedOrganics; + bool surfaceWeb; + bool projPassthrough; + bool solid; + bool noPlatformCollision; + bool camPassthrough; + bool surfaceWood; + bool surfaceOrganic; + bool noEdgeCollision; + bool surfaceRubber; + bool seeThrough; + bool scanPassthrough; + bool aiPassthrough; + bool ceiling; + bool wall; + bool floor; + bool aiBlock; + bool jumpNotAllowed; + bool spiderBall; + bool screwAttackWallJump; + + Material(Connection& conn); + }; + std::vector materials; + + std::vector verts; + + struct Edge { + std::array verts; + bool seam; + Edge(Connection& conn); + }; + std::vector edges; + + struct Triangle { + std::array edges; + uint32_t matIdx; + bool flip; + Triangle(Connection& conn); + }; + std::vector trianges; + + ColMesh(Connection& conn); +}; + +/** Intermediate world representation */ +struct World { + struct Area { + ProjectPath path; + std::array aabb; + Matrix4f transform; + struct Dock { + std::array verts; + Index targetArea; + Index targetDock; + Dock(Connection& conn); + }; + std::vector docks; + Area(Connection& conn); + }; + std::vector areas; + World(Connection& conn); +}; + +/** Intermediate lamp representation */ +struct Light { + /* Object transform in scene */ + Matrix4f sceneXf; + Vector3f color; + + uint32_t layer; + + enum class Type : uint32_t { Ambient, Directional, Custom, Spot } type; + + float energy; + float spotCutoff; + float constant; + float linear; + float quadratic; + bool shadow; + + std::string name; + + Light(Connection& conn); +}; + +/** Intermediate MapArea representation */ +struct MapArea { + uint32_t visType; + std::vector verts; + std::vector indices; + struct Surface { + Vector3f normal; + Vector3f centerOfMass; + uint32_t start; + uint32_t count; + std::vector> borders; + Surface(Connection& conn); + }; + std::vector surfaces; + struct POI { + uint32_t type; + uint32_t visMode; + uint32_t objid; + Matrix4f xf; + POI(Connection& conn); + }; + std::vector pois; + MapArea(Connection& conn); +}; + +/** Intermediate MapUniverse representation */ +struct MapUniverse { + hecl::ProjectPath hexagonPath; + struct World { + std::string name; + Matrix4f xf; + std::vector hexagons; + Vector4f color; + hecl::ProjectPath worldPath; + World(Connection& conn); + }; + std::vector worlds; + MapUniverse(Connection& conn); +}; + +/** Intermediate bone representation used in Armature */ +struct Bone { + std::string name; + Vector3f origin; + int32_t parent = -1; + std::vector children; + Bone(Connection& conn); +}; + +/** Intermediate armature representation used in Actor */ +struct Armature { + std::vector bones; + const Bone* lookupBone(const char* name) const; + const Bone* getParent(const Bone* bone) const; + const Bone* getChild(const Bone* bone, std::size_t child) const; + const Bone* getRoot() const; + Armature(Connection& conn); +}; + +/** Intermediate action representation used in Actor */ +struct Action { + std::string name; + std::string animId; + float interval; + bool additive; + bool looping; + std::vector frames; + struct Channel { + std::string boneName; + uint32_t attrMask; + struct Key { + Vector4f rotation; + Vector3f position; + Vector3f scale; + Key(Connection& conn, uint32_t attrMask); + }; + std::vector keys; + Channel(Connection& conn); + }; + std::vector channels; + std::vector> subtypeAABBs; + Action(Connection& conn); +}; + +/** Intermediate actor representation prepared by blender from a single HECL actor blend */ +struct Actor { + struct ActorArmature { + std::string name; + ProjectPath path; + std::optional armature; + ActorArmature(Connection& conn); + }; + std::vector armatures; + + struct Subtype { + std::string name; + std::string cskrId; + ProjectPath mesh; + int32_t armature = -1; + struct OverlayMesh { + std::string name; + std::string cskrId; + ProjectPath mesh; + OverlayMesh(Connection& conn); + }; + std::vector overlayMeshes; + Subtype(Connection& conn); + }; + std::vector subtypes; + struct Attachment { + std::string name; + std::string cskrId; + ProjectPath mesh; + int32_t armature = -1; + Attachment(Connection& conn); + }; + std::vector attachments; + std::vector actions; + + Actor(Connection& conn); +}; + +/** Intermediate pathfinding representation prepared by blender */ +struct PathMesh { + std::vector data; + PathMesh(Connection& conn); +}; + +class DataStream { + friend class Connection; + Connection* m_parent; + DataStream(Connection* parent); + +public: + DataStream(const DataStream& other) = delete; + DataStream(DataStream&& other) : m_parent(other.m_parent) { other.m_parent = nullptr; } + ~DataStream() { close(); } + void close(); + std::vector getMeshList(); + std::vector getLightList(); + std::pair getMeshAABB(); + static const char* MeshOutputModeString(HMDLTopology topology); + + /** Compile mesh by context (MESH blends only) */ + Mesh compileMesh(HMDLTopology topology, int skinSlotCount = 10); + + /** Compile mesh by name (AREA blends only) */ + Mesh compileMesh(std::string_view name, HMDLTopology topology, int skinSlotCount = 10, bool useLuv = false); + + /** Compile collision mesh by name (AREA blends only) */ + ColMesh compileColMesh(std::string_view name); + + /** Compile all meshes as collision meshes (CMESH blends only) */ + std::vector compileColMeshes(); + + /** Compile world intermediate (WORLD blends only) */ + World compileWorld(); + + /** Gather all lights in scene (AREA blends only) */ + std::vector compileLights(); + + /** Get PathMesh from scene (PATH blends only) */ + PathMesh compilePathMesh(); + + /** Compile GUI into FRME data (FRAME blends only) */ + std::vector compileGuiFrame(int version); + + /** Gather all texture paths in scene */ + std::vector getTextures(); + + Actor compileActor(); + Actor compileActorCharacterOnly(); + Armature compileArmature(); + Action compileActionChannelsOnly(std::string_view name); + std::vector> getSubtypeNames(); + std::vector> getActionNames(); + std::vector> getSubtypeOverlayNames(std::string_view name); + std::vector> getAttachmentNames(); + + std::unordered_map getBoneMatrices(std::string_view name); + + bool renderPvs(std::string_view path, const atVec3f& location); + bool renderPvsLight(std::string_view path, std::string_view lightName); + + MapArea compileMapArea(); + MapUniverse compileMapUniverse(); +}; + +class Connection { + friend class ANIMOutStream; + friend class DataStream; + friend class PyOutStream; + friend struct Action; + friend struct Actor; + friend struct Armature; + friend struct Bone; + friend struct Boolean; + friend struct ColMesh; + friend struct Float; + friend struct Index; + friend struct Light; + friend struct MapArea; + friend struct MapUniverse; + friend struct Material; + friend struct Matrix3f; + friend struct Matrix4f; + friend struct Mesh; + friend struct PathMesh; + friend struct PyOutStream::StreamBuf; + friend struct Vector2f; + friend struct Vector3f; + friend struct Vector4f; + friend struct World; + friend class MeshOptimizer; + + std::atomic_bool m_lock = {false}; + bool m_pyStreamActive = false; + bool m_dataStreamActive = false; + bool m_blenderQuit = false; +#if _WIN32 + PROCESS_INFORMATION m_pinfo = {}; + std::thread m_consoleThread; + bool m_consoleThreadRunning = true; +#else + pid_t m_blenderProc = 0; +#endif + std::array m_readpipe{}; + std::array m_writepipe{}; + BlendType m_loadedType = BlendType::None; + bool m_loadedRigged = false; + ProjectPath m_loadedBlend; + hecl::SystemString m_errPath; + uint32_t _readStr(char* buf, uint32_t bufSz); + uint32_t _writeStr(const char* str, uint32_t len, int wpipe); + uint32_t _writeStr(const char* str, uint32_t len) { return _writeStr(str, len, m_writepipe[1]); } + uint32_t _writeStr(std::string_view view) { return _writeStr(view.data(), view.size()); } + std::size_t _readBuf(void* buf, std::size_t len); + std::size_t _writeBuf(const void* buf, std::size_t len); + std::string _readStdString() { + uint32_t bufSz; + _readBuf(&bufSz, 4); + std::string ret(bufSz, ' '); + _readBuf(&ret[0], bufSz); + return ret; + } + template, std::is_enum>, int> = 0> + void _readValue(T& v) { _readBuf(&v, sizeof(T)); } + template + void _readItems(T enumerator) { + uint32_t nItems; + _readBuf(&nItems, 4); + for (uint32_t i = 0; i < nItems; ++i) + enumerator(*this); + } + template, std::is_enum, std::is_same>, int> = 0> + void _readVector(std::vector& container, Args&&... args) { + uint32_t nItems; + _readBuf(&nItems, 4); + container.clear(); + container.reserve(nItems); + for (uint32_t i = 0; i < nItems; ++i) + container.emplace_back(*this, std::forward(args)...); + } + template, std::is_enum>, int> = 0> + void _readVector(std::vector& container) { + uint32_t nItems; + _readBuf(&nItems, 4); + container.clear(); + container.resize(nItems); + _readBuf(&container[0], sizeof(T) * nItems); + } + void _readVector(std::vector& container) { + uint32_t nItems; + _readBuf(&nItems, 4); + container.clear(); + container.reserve(nItems); + for (uint32_t i = 0; i < nItems; ++i) { + uint32_t strSize; + _readBuf(&strSize, 4); + _readBuf(&container.emplace_back(strSize, ' ')[0], strSize); + } + } + template + void _readVectorFunc(std::vector& container, F func) { + uint32_t nItems; + _readBuf(&nItems, 4); + container.clear(); + container.reserve(nItems); + for (uint32_t i = 0; i < nItems; ++i) + func(); + } + ProjectPath _readPath(); + bool _isStatus(const char* status) { + char readBuf[16]; + _readStr(readBuf, 16); + return std::strcmp(readBuf, status) == 0; + } + bool _isOk() { return _isStatus("OK"); } + bool _isFinished() { return _isStatus("FINISHED"); } + bool _isTrue() { return _isStatus("TRUE"); } + void _checkStatus(std::string_view action, std::string_view status) { + char readBuf[16]; + _readStr(readBuf, 16); + if (status != readBuf) + BlenderLog.report(logvisor::Fatal, FMT_STRING("{}: {}: {}"), m_loadedBlend.getRelativePathUTF8(), action, readBuf); + } + void _checkReady(std::string_view action) { _checkStatus(action, "READY"sv); } + void _checkDone(std::string_view action) { _checkStatus(action, "DONE"sv); } + void _checkOk(std::string_view action) { _checkStatus(action, "OK"sv); } + void _checkAnimReady(std::string_view action) { _checkStatus(action, "ANIMREADY"sv); } + void _checkAnimDone(std::string_view action) { _checkStatus(action, "ANIMDONE"sv); } + void _closePipe(); + void _blenderDied(); + +public: + Connection(int verbosityLevel = 1); + ~Connection(); + + Connection(const Connection&) = delete; + Connection& operator=(const Connection&) = delete; + Connection(Connection&&) = delete; + Connection& operator=(Connection&&) = delete; + + bool createBlend(const ProjectPath& path, BlendType type); + BlendType getBlendType() const { return m_loadedType; } + const ProjectPath& getBlendPath() const { return m_loadedBlend; } + bool getRigged() const { return m_loadedRigged; } + bool openBlend(const ProjectPath& path, bool force = false); + bool saveBlend(); + void deleteBlend(); + + PyOutStream beginPythonOut(bool deleteOnError = false) { + bool expect = false; + if (!m_lock.compare_exchange_strong(expect, true)) + BlenderLog.report(logvisor::Fatal, FMT_STRING("lock already held for blender::Connection::beginPythonOut()")); + return PyOutStream(this, deleteOnError); + } + + DataStream beginData() { + bool expect = false; + if (!m_lock.compare_exchange_strong(expect, true)) + BlenderLog.report(logvisor::Fatal, FMT_STRING("lock already held for blender::Connection::beginDataIn()")); + return DataStream(this); + } + + void quitBlender(); + + void closeStream() { + if (m_lock) + deleteBlend(); + } + + static Connection& SharedConnection(); + static void Shutdown(); +}; + +template +void PyOutStream::format(const S& format, Args&&... args) { + if (!m_parent || !m_parent->m_lock) + BlenderLog.report(logvisor::Fatal, FMT_STRING("lock not held for PyOutStream::format()")); + fmt::print(*this, format, std::forward(args)...); +} + +class HMDLBuffers { +public: + struct Surface; + +private: + friend struct Mesh; + HMDLBuffers(HMDLMeta&& meta, std::size_t vboSz, const std::vector& iboData, std::vector&& surfaces, + const Mesh::SkinBanks& skinBanks); + +public: + HMDLMeta m_meta; + std::size_t m_vboSz; + std::unique_ptr m_vboData; + std::size_t m_iboSz; + std::unique_ptr m_iboData; + + struct Surface { + Surface(const Mesh::Surface& origSurf, atUint32 start, atUint32 count) + : m_origSurf(origSurf), m_start(start), m_count(count) {} + const Mesh::Surface& m_origSurf; + atUint32 m_start; + atUint32 m_count; + }; + std::vector m_surfaces; + + const Mesh::SkinBanks& m_skinBanks; +}; + +} // namespace hecl::blender + +namespace std { +template <> +struct hash { + std::size_t operator()(const hecl::blender::Vector2f& val) const noexcept { + std::size_t h = std::hash()(val.val.simd[0]); + hecl::hash_combine_impl(h, std::hash()(val.val.simd[1])); + return h; + } +}; +template <> +struct hash { + std::size_t operator()(const hecl::blender::Vector3f& val) const noexcept { + std::size_t h = std::hash()(val.val.simd[0]); + hecl::hash_combine_impl(h, std::hash()(val.val.simd[1])); + hecl::hash_combine_impl(h, std::hash()(val.val.simd[2])); + return h; + } +}; +template <> +struct hash { + std::size_t operator()(const hecl::blender::Vector4f& val) const noexcept { + std::size_t h = std::hash()(val.val.simd[0]); + hecl::hash_combine_impl(h, std::hash()(val.val.simd[1])); + hecl::hash_combine_impl(h, std::hash()(val.val.simd[2])); + hecl::hash_combine_impl(h, std::hash()(val.val.simd[3])); + return h; + } +}; +template <> +struct hash> { + std::size_t operator()(const array& val) const noexcept { + std::size_t h = 0; + for (const auto& bind : val) { + if (!bind.valid()) + break; + hecl::hash_combine_impl(h, std::hash()(bind.vg_idx)); + hecl::hash_combine_impl(h, std::hash()(bind.weight)); + } + return h; + } +}; +} diff --git a/hecl/include/hecl/Blender/SDNARead.hpp b/hecl/include/hecl/Blender/SDNARead.hpp new file mode 100644 index 000000000..c853dc9a5 --- /dev/null +++ b/hecl/include/hecl/Blender/SDNARead.hpp @@ -0,0 +1,76 @@ +#pragma once + +#include +#include + +#include "hecl/FourCC.hpp" +#include "hecl/SystemChar.hpp" + +#include + +namespace athena::io { +class MemoryReader; +} + +namespace hecl::blender { +enum class BlendType; + +struct SDNABlock : public athena::io::DNA { + AT_DECL_DNA + DNAFourCC magic; + DNAFourCC nameMagic; + Value numNames; + Vector, AT_DNA_COUNT(numNames)> names; + Align<4> align1; + DNAFourCC typeMagic; + Value numTypes; + Vector, AT_DNA_COUNT(numTypes)> types; + Align<4> align2; + DNAFourCC tlenMagic; + Vector, AT_DNA_COUNT(numTypes)> tlens; + Align<4> align3; + DNAFourCC strcMagic; + Value numStrcs; + struct SDNAStruct : public athena::io::DNA { + AT_DECL_DNA + Value type; + Value numFields; + struct SDNAField : public athena::io::DNA { + AT_DECL_DNA + Value type; + Value name; + atUint32 offset; + }; + Vector fields; + + void computeOffsets(const SDNABlock& block); + const SDNAField* lookupField(const SDNABlock& block, const char* n) const; + }; + Vector strcs; + + const SDNAStruct* lookupStruct(const char* n, atUint32& idx) const; +}; + +struct FileBlock : public athena::io::DNA { + AT_DECL_DNA + DNAFourCC type; + Value size; + Value ptr; + Value sdnaIdx; + Value count; +}; + +class SDNARead { + std::vector m_data; + SDNABlock m_sdnaBlock; + +public: + explicit SDNARead(SystemStringView path); + explicit operator bool() const { return !m_data.empty(); } + const SDNABlock& sdnaBlock() const { return m_sdnaBlock; } + void enumerate(const std::function& func) const; +}; + +BlendType GetBlendType(SystemStringView path); + +} // namespace hecl::blender diff --git a/hecl/include/hecl/Blender/Token.hpp b/hecl/include/hecl/Blender/Token.hpp new file mode 100644 index 000000000..59859b7e9 --- /dev/null +++ b/hecl/include/hecl/Blender/Token.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace hecl::blender { +class Connection; + +class Token { + std::unique_ptr m_conn; + +public: + Connection& getBlenderConnection(); + void shutdown(); + + Token() = default; + ~Token(); + Token(const Token&) = delete; + Token& operator=(const Token&) = delete; + Token(Token&&) = default; + Token& operator=(Token&&) = default; +}; + +} // namespace hecl::blender diff --git a/hecl/include/hecl/CVar.hpp b/hecl/include/hecl/CVar.hpp new file mode 100644 index 000000000..989c7ea6b --- /dev/null +++ b/hecl/include/hecl/CVar.hpp @@ -0,0 +1,320 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + +namespace hecl { +namespace DNACVAR { +enum class EType : atUint8 { Boolean, Signed, Unsigned, Real, Literal, Vec2f, Vec2d, Vec3f, Vec3d, Vec4f, Vec4d }; + +enum class EFlags { + None = 0, + System = (1 << 0), + Game = (1 << 1), + Editor = (1 << 2), + Gui = (1 << 3), + Cheat = (1 << 4), + Hidden = (1 << 5), + ReadOnly = (1 << 6), + Archive = (1 << 7), + InternalArchivable = (1 << 8), + Modified = (1 << 9), + ModifyRestart = (1 << 10), //!< If this bit is set, any modification will inform the user that a restart is required + Color = (1 << 11), //!< If this bit is set, Vec3f and Vec4f will be displayed in the console with a colored square + NoDeveloper = (1 << 12), //!< Not even developer mode can modify this + Any = -1 +}; +ENABLE_BITWISE_ENUM(EFlags) + +class CVar : public athena::io::DNA { +public: + AT_DECL_DNA + String<-1> m_name; + String<-1> m_value; +}; + +struct CVarContainer : public athena::io::DNA { + AT_DECL_DNA + Value magic = 'CVAR'; + Value cvarCount; + Vector cvars; +}; + +} // namespace DNACVAR + +class CVarManager; +class CVar : protected DNACVAR::CVar { + friend class CVarManager; + Delete _d; + +public: + typedef std::function ListenerFunc; + + using EType = DNACVAR::EType; + using EFlags = DNACVAR::EFlags; + + CVar(std::string_view name, std::string_view value, std::string_view help, EFlags flags); + CVar(std::string_view name, const atVec2f& value, std::string_view help, EFlags flags); + CVar(std::string_view name, const atVec2d& value, std::string_view help, EFlags flags); + CVar(std::string_view name, const atVec3f& value, std::string_view help, EFlags flags); + CVar(std::string_view name, const atVec3d& value, std::string_view help, EFlags flags); + CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags); + CVar(std::string_view name, const atVec4d& value, std::string_view help, EFlags flags); + CVar(std::string_view name, double value, std::string_view help, EFlags flags); + CVar(std::string_view name, bool value, std::string_view help, EFlags flags); + CVar(std::string_view name, int32_t value, std::string_view help, EFlags flags); + CVar(std::string_view name, uint32_t value, std::string_view help, EFlags flags); + + std::string_view name() const { return m_name; } + std::string_view rawHelp() const { return m_help; } + std::string help() const; + std::string value() const { return m_value; } + + template + inline bool toValue(T& value) const; + atVec2f toVec2f(bool* isValid = nullptr) const; + atVec2d toVec2d(bool* isValid = nullptr) const; + atVec3f toVec3f(bool* isValid = nullptr) const; + atVec3d toVec3d(bool* isValid = nullptr) const; + atVec4f toVec4f(bool* isValid = nullptr) const; + atVec4d toVec4d(bool* isValid = nullptr) const; + double toReal(bool* isValid = nullptr) const; + bool toBoolean(bool* isValid = nullptr) const; + int32_t toSigned(bool* isValid = nullptr) const; + uint32_t toUnsigned(bool* isValid = nullptr) const; + std::wstring toWideLiteral(bool* isValid = nullptr) const; + std::string toLiteral(bool* isValid = nullptr) const; + + template + inline bool fromValue(T value) { + return false; + } + bool fromVec2f(const atVec2f& val); + bool fromVec2d(const atVec2d& val); + bool fromVec3f(const atVec3f& val); + bool fromVec3d(const atVec3d& val); + bool fromVec4f(const atVec4f& val); + bool fromVec4d(const atVec4d& val); + bool fromReal(double val); + bool fromBoolean(bool val); + bool fromInteger(int32_t val); + bool fromInteger(uint32_t val); + bool fromLiteral(std::string_view val); + bool fromLiteral(std::wstring_view val); + bool fromLiteralToType(std::string_view val); + bool fromLiteralToType(std::wstring_view val); + + bool isVec2f() const { return m_type == EType::Vec2f; } + bool isVec2d() const { return m_type == EType::Vec2d; } + bool isVec3f() const { return m_type == EType::Vec3f; } + bool isVec3d() const { return m_type == EType::Vec3d; } + bool isVec4f() const { return m_type == EType::Vec4f; } + bool isVec4d() const { return m_type == EType::Vec4d; } + bool isFloat() const { return m_type == EType::Real; } + bool isBoolean() const { return m_type == EType::Boolean; } + bool isInteger() const { return m_type == EType::Signed || m_type == EType::Unsigned; } + bool isLiteral() const { return m_type == EType::Literal; } + bool isModified() const; + bool modificationRequiresRestart() const; + bool isReadOnly() const; + bool isCheat() const; + bool isHidden() const; + bool isArchive() const; + bool isInternalArchivable() const; + bool isNoDeveloper() const; + bool isColor() const; + bool wasDeserialized() const; + bool hasDefaultValue() const; + + EType type() const { return m_type; } + EFlags flags() const { return (m_unlocked ? m_oldFlags : m_flags); } + + /*! + * \brief Unlocks the CVar for writing if it is ReadOnly. + * Handle with care!!! if you use unlock(), make sure + * you lock the cvar using lock() + * \see lock + */ + void unlock(); + + /*! + * \brief Locks the CVar to prevent writing if it is ReadOnly. + * Unlike its partner function unlock, lock is harmless + * \see unlock + */ + void lock(); + + void addListener(ListenerFunc func) { m_listeners.push_back(std::move(func)); } + + bool isValidInput(std::string_view input) const; + bool isValidInput(std::wstring_view input) const; + +private: + CVar(std::string_view name, std::string_view help, EType type) : m_help(help), m_type(type) { m_name = name; } + void dispatch(); + void clearModified(); + void setModified(); + std::string m_help; + EType m_type; + std::string m_defaultValue; + EFlags m_flags = EFlags::None; + EFlags m_oldFlags = EFlags::None; + bool m_unlocked = false; + bool m_wasDeserialized = false; + std::vector m_listeners; + bool safeToModify(EType type) const; + void init(EFlags flags, bool removeColor = true); +}; + +template <> +inline bool CVar::toValue(atVec2f& value) const { + bool isValid = false; + value = toVec2f(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(atVec2d& value) const { + bool isValid = false; + value = toVec2d(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(atVec3f& value) const { + bool isValid = false; + value = toVec3f(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(atVec3d& value) const { + bool isValid = false; + value = toVec3d(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(atVec4f& value) const { + bool isValid = false; + value = toVec4f(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(atVec4d& value) const { + bool isValid = false; + value = toVec4d(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(double& value) const { + bool isValid = false; + value = toReal(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(float& value) const { + bool isValid = false; + value = static_cast(toReal(&isValid)); + return isValid; +} +template <> +inline bool CVar::toValue(bool& value) const { + bool isValid = false; + value = toBoolean(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(int32_t& value) const { + bool isValid = false; + value = toSigned(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(uint32_t& value) const { + bool isValid = false; + value = toUnsigned(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(std::wstring& value) const { + bool isValid = false; + value = toWideLiteral(&isValid); + return isValid; +} +template <> +inline bool CVar::toValue(std::string& value) const { + bool isValid = false; + value = toLiteral(&isValid); + return isValid; +} + +template <> +inline bool CVar::fromValue(const atVec2f& val) { + return fromVec2f(val); +} +template <> +inline bool CVar::fromValue(const atVec2d& val) { + return fromVec2d(val); +} +template <> +inline bool CVar::fromValue(const atVec3f& val) { + return fromVec3f(val); +} +template <> +inline bool CVar::fromValue(const atVec3d& val) { + return fromVec3d(val); +} +template <> +inline bool CVar::fromValue(const atVec4f& val) { + return fromVec4f(val); +} +template <> +inline bool CVar::fromValue(const atVec4d& val) { + return fromVec4d(val); +} +template <> +inline bool CVar::fromValue(float val) { + return fromReal(val); +} +template <> +inline bool CVar::fromValue(double val) { + return fromReal(val); +} +template <> +inline bool CVar::fromValue(bool val) { + return fromBoolean(val); +} +template <> +inline bool CVar::fromValue(int32_t val) { + return fromInteger(val); +} +template <> +inline bool CVar::fromValue(uint32_t val) { + return fromInteger(val); +} +template <> +inline bool CVar::fromValue(std::string_view val) { + return fromLiteral(val); +} +template <> +inline bool CVar::fromValue(std::wstring_view val) { + return fromLiteral(val); +} + +class CVarUnlocker { + CVar* m_cvar; + +public: + CVarUnlocker(CVar* cvar) : m_cvar(cvar) { + if (m_cvar) + m_cvar->unlock(); + } + ~CVarUnlocker() { + if (m_cvar) + m_cvar->lock(); + } +}; + +} // namespace hecl diff --git a/hecl/include/hecl/CVarCommons.hpp b/hecl/include/hecl/CVarCommons.hpp new file mode 100644 index 000000000..5229543e9 --- /dev/null +++ b/hecl/include/hecl/CVarCommons.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include +#include +#include + +#include "hecl/CVarManager.hpp" + +#undef min +#undef max + +namespace hecl { + +using namespace std::literals; + +#if defined(__APPLE__) +#define DEFAULT_GRAPHICS_API "Metal"sv +#else +#define DEFAULT_GRAPHICS_API "Vulkan"sv +#endif + +struct CVarCommons { + CVarManager& m_mgr; + CVar* m_fullscreen = nullptr; + CVar* m_graphicsApi = nullptr; + CVar* m_drawSamples = nullptr; + CVar* m_texAnisotropy = nullptr; + CVar* m_deepColor = nullptr; + CVar* m_variableDt = nullptr; + + CVar* m_debugOverlayPlayerInfo = nullptr; + CVar* m_debugOverlayWorldInfo = nullptr; + CVar* m_debugOverlayAreaInfo = nullptr; + CVar* m_debugOverlayShowFrameCounter = nullptr; + CVar* m_debugOverlayShowFramerate = nullptr; + CVar* m_debugOverlayShowInGameTime = nullptr; + CVar* m_debugOverlayShowResourceStats = nullptr; + CVar* m_debugOverlayShowRandomStats = nullptr; + CVar* m_debugOverlayShowRoomTimer = nullptr; + CVar* m_debugToolDrawAiPath = nullptr; + CVar* m_debugToolDrawLighting = nullptr; + CVar* m_debugToolDrawCollisionActors = nullptr; + CVar* m_debugToolDrawMazePath = nullptr; + CVar* m_debugToolDrawPlatformCollision = nullptr; + CVar* m_logFile = nullptr; + + CVarCommons(CVarManager& manager); + + bool getFullscreen() const { return m_fullscreen->toBoolean(); } + + void setFullscreen(bool b) { m_fullscreen->fromBoolean(b); } + + std::string getGraphicsApi() const { return m_graphicsApi->toLiteral(); } + + void setGraphicsApi(std::string_view api) { m_graphicsApi->fromLiteral(api); } + + uint32_t getSamples() const { return std::max(1u, m_drawSamples->toUnsigned()); } + + void setSamples(uint32_t v) { m_drawSamples->fromInteger(std::max(uint32_t(1), v)); } + + uint32_t getAnisotropy() const { return std::max(1u, uint32_t(m_texAnisotropy->toUnsigned())); } + + void setAnisotropy(uint32_t v) { m_texAnisotropy->fromInteger(std::max(1u, v)); } + + bool getDeepColor() const { return m_deepColor->toBoolean(); } + + void setDeepColor(bool b) { m_deepColor->fromBoolean(b); } + + bool getVariableFrameTime() const { return m_variableDt->toBoolean(); } + + void setVariableFrameTime(bool b) { m_variableDt->fromBoolean(b); } + + std::string getLogFile() const { return m_logFile->toLiteral(); }; + + void setLogFile(std::string_view log) { m_logFile->fromLiteral(log); } + + void serialize() { m_mgr.serialize(); } + + static CVarCommons* instance(); +}; + +} // namespace hecl diff --git a/hecl/include/hecl/CVarManager.hpp b/hecl/include/hecl/CVarManager.hpp new file mode 100644 index 000000000..6f8ffea2f --- /dev/null +++ b/hecl/include/hecl/CVarManager.hpp @@ -0,0 +1,116 @@ +#pragma once + +#include +#include +#include +#include + +#include "hecl/CVar.hpp" +#include "hecl/SystemChar.hpp" + +namespace hecl { +namespace Runtime { +class FileStoreManager; +} +extern CVar* com_developer; +extern CVar* com_configfile; +extern CVar* com_enableCheats; +extern CVar* com_cubemaps; +class CVarManager final { + using CVarContainer = DNACVAR::CVarContainer; + template + CVar* _newCVar(std::string_view name, std::string_view help, const T& value, CVar::EFlags flags) { + if (CVar* ret = registerCVar(std::make_unique(name, value, help, flags))) { + deserialize(ret); + return ret; + } + return nullptr; + } + + hecl::Runtime::FileStoreManager& m_store; + bool m_useBinary; + static CVarManager* m_instance; + +public: + CVarManager() = delete; + CVarManager(const CVarManager&) = delete; + CVarManager& operator=(const CVarManager&) = delete; + CVarManager& operator=(const CVarManager&&) = delete; + CVarManager(hecl::Runtime::FileStoreManager& store, bool useBinary = false); + ~CVarManager(); + + CVar* newCVar(std::string_view name, std::string_view help, const atVec2f& value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + CVar* newCVar(std::string_view name, std::string_view help, const atVec2d& value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + CVar* newCVar(std::string_view name, std::string_view help, const atVec3f& value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + CVar* newCVar(std::string_view name, std::string_view help, const atVec3d& value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + CVar* newCVar(std::string_view name, std::string_view help, const atVec4f& value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + CVar* newCVar(std::string_view name, std::string_view help, const atVec4d& value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + CVar* newCVar(std::string_view name, std::string_view help, std::string_view value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + CVar* newCVar(std::string_view name, std::string_view help, bool value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + // Float and double are internally identical, all floating point values are stored as `double` + CVar* newCVar(std::string_view name, std::string_view help, float value, CVar::EFlags flags) { + return _newCVar(name, help, static_cast(value), flags); + } + CVar* newCVar(std::string_view name, std::string_view help, double value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + // Integer CVars can be seamlessly converted between either type, the distinction is to make usage absolutely clear + CVar* newCVar(std::string_view name, std::string_view help, int32_t value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + + CVar* newCVar(std::string_view name, std::string_view help, uint32_t value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + + CVar* registerCVar(std::unique_ptr&& cvar); + + CVar* findCVar(std::string_view name); + template + CVar* findOrMakeCVar(std::string_view name, _Args&&... args) { + if (CVar* cv = findCVar(name)) + return cv; + return newCVar(name, std::forward<_Args>(args)...); + } + + std::vector archivedCVars() const; + std::vector cvars(CVar::EFlags filter = CVar::EFlags::Any) const; + + void deserialize(CVar* cvar); + void serialize(); + + static CVarManager* instance(); + + void proc(); + + void setDeveloperMode(bool v, bool setDeserialized = false); + void setCheatsEnabled(bool v, bool setDeserialized = false); + bool restartRequired() const; + + void parseCommandLine(const std::vector& args); + +private: + bool suppressDeveloper(); + void restoreDeveloper(bool oldDeveloper); + + std::unordered_map> m_cvars; + std::unordered_map m_deferedCVars; +}; + +} // namespace hecl diff --git a/hecl/include/hecl/ClientProcess.hpp b/hecl/include/hecl/ClientProcess.hpp new file mode 100644 index 000000000..e99b32c54 --- /dev/null +++ b/hecl/include/hecl/ClientProcess.hpp @@ -0,0 +1,108 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "hecl/Blender/Token.hpp" +#include "hecl/hecl.hpp" +#include "hecl/SystemChar.hpp" + +namespace hecl::Database { +class IDataSpec; +} + +namespace hecl { +class MultiProgressPrinter; + +extern int CpuCountOverride; +void SetCpuCountOverride(int argc, const SystemChar** argv); + +class ClientProcess { + std::mutex m_mutex; + std::condition_variable m_cv; + std::condition_variable m_initCv; + std::condition_variable m_waitCv; + const MultiProgressPrinter* m_progPrinter; + int m_completedCooks = 0; + int m_addedCooks = 0; + +public: + struct Transaction { + ClientProcess& m_parent; + enum class Type { Buffer, Cook, Lambda } m_type; + bool m_complete = false; + virtual void run(blender::Token& btok) = 0; + Transaction(ClientProcess& parent, Type tp) : m_parent(parent), m_type(tp) {} + }; + struct BufferTransaction final : Transaction { + ProjectPath m_path; + void* m_targetBuf; + size_t m_maxLen; + size_t m_offset; + void run(blender::Token& btok) override; + BufferTransaction(ClientProcess& parent, const ProjectPath& path, void* target, size_t maxLen, size_t offset) + : Transaction(parent, Type::Buffer), m_path(path), m_targetBuf(target), m_maxLen(maxLen), m_offset(offset) {} + }; + struct CookTransaction final : Transaction { + ProjectPath m_path; + Database::IDataSpec* m_dataSpec; + bool m_returnResult = false; + bool m_force; + bool m_fast; + void run(blender::Token& btok) override; + CookTransaction(ClientProcess& parent, const ProjectPath& path, bool force, bool fast, Database::IDataSpec* spec) + : Transaction(parent, Type::Cook), m_path(path), m_dataSpec(spec), m_force(force), m_fast(fast) {} + }; + struct LambdaTransaction final : Transaction { + std::function m_func; + void run(blender::Token& btok) override; + LambdaTransaction(ClientProcess& parent, std::function&& func) + : Transaction(parent, Type::Lambda), m_func(std::move(func)) {} + }; + +private: + std::list> m_pendingQueue; + std::list> m_completedQueue; + int m_inProgress = 0; + bool m_running = true; + + struct Worker { + ClientProcess& m_proc; + int m_idx; + std::thread m_thr; + blender::Token m_blendTok; + bool m_didInit = false; + Worker(ClientProcess& proc, int idx); + void proc(); + }; + std::vector m_workers; + static thread_local ClientProcess::Worker* ThreadWorker; + +public: + ClientProcess(const MultiProgressPrinter* progPrinter = nullptr); + ~ClientProcess() { shutdown(); } + std::shared_ptr addBufferTransaction(const hecl::ProjectPath& path, void* target, + size_t maxLen, size_t offset); + std::shared_ptr addCookTransaction(const hecl::ProjectPath& path, bool force, bool fast, + Database::IDataSpec* spec); + std::shared_ptr addLambdaTransaction(std::function&& func); + bool syncCook(const hecl::ProjectPath& path, Database::IDataSpec* spec, blender::Token& btok, bool force, bool fast); + void swapCompletedQueue(std::list>& queue); + void waitUntilComplete(); + void shutdown(); + bool isBusy() const { return m_pendingQueue.size() || m_inProgress; } + + static int GetThreadWorkerIdx() { + Worker* w = ThreadWorker; + if (w) + return w->m_idx; + return -1; + } +}; + +} // namespace hecl diff --git a/hecl/include/hecl/Database.hpp b/hecl/include/hecl/Database.hpp new file mode 100644 index 000000000..1b6c426fe --- /dev/null +++ b/hecl/include/hecl/Database.hpp @@ -0,0 +1,442 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hecl/hecl.hpp" + +#include + +namespace hecl { +class ClientProcess; + +namespace Database { +class Project; + +extern logvisor::Module LogModule; + +/** + * @brief Nodegraph class for gathering dependency-resolved objects for packaging + */ +class PackageDepsgraph { +public: + struct Node { + enum class Type { Data, Group } type; + ProjectPath path; + ProjectPath cookedPath; + class ObjectBase* projectObj; + Node* sub; + Node* next; + }; + +private: + friend class Project; + std::vector m_nodes; + +public: + const Node* getRootNode() const { return &m_nodes[0]; } +}; + +/** + * @brief Subclassed by dataspec entries to manage per-game aspects of the data pipeline + * + * The DataSpec class manages interfaces for unpackaging, cooking, and packaging + * of data for interacting with a specific system/game-engine. + */ +class IDataSpec { + const DataSpecEntry* m_specEntry; + +public: + IDataSpec(const DataSpecEntry* specEntry) : m_specEntry(specEntry) {} + virtual ~IDataSpec() = default; + using FCookProgress = std::function; + + /** + * @brief Extract Pass Info + * + * An extract pass iterates through a source package or image and + * reverses the cooking process by emitting editable resources + */ + struct ExtractPassInfo { + SystemString srcpath; + std::vector extractArgs; + bool force; + }; + + /** + * @brief Extract Report Representation + * + * Constructed by canExtract() to advise the user of the content about + * to be extracted + */ + struct ExtractReport { + SystemString name; + SystemString desc; + std::vector childOpts; + }; + + virtual void setThreadProject() {} + + virtual bool canExtract([[maybe_unused]] const ExtractPassInfo& info, + [[maybe_unused]] std::vector& reps) { + LogModule.report(logvisor::Error, FMT_STRING("not implemented")); + return false; + } + virtual void doExtract([[maybe_unused]] const ExtractPassInfo& info, + [[maybe_unused]] const MultiProgressPrinter& progress) {} + + virtual bool canCook([[maybe_unused]] const ProjectPath& path, [[maybe_unused]] blender::Token& btok) { + LogModule.report(logvisor::Error, FMT_STRING("not implemented")); + return false; + } + virtual const DataSpecEntry* overrideDataSpec([[maybe_unused]] const ProjectPath& path, + const DataSpecEntry* oldEntry) const { + return oldEntry; + } + virtual void doCook([[maybe_unused]] const ProjectPath& path, [[maybe_unused]] const ProjectPath& cookedPath, + [[maybe_unused]] bool fast, [[maybe_unused]] blender::Token& btok, + [[maybe_unused]] FCookProgress progress) {} + + virtual bool canPackage([[maybe_unused]] const ProjectPath& path) { + return false; + } + virtual void doPackage([[maybe_unused]] const ProjectPath& path, [[maybe_unused]] const DataSpecEntry* entry, + [[maybe_unused]] bool fast, [[maybe_unused]] blender::Token& btok, + [[maybe_unused]] const MultiProgressPrinter& progress, + [[maybe_unused]] ClientProcess* cp = nullptr) {} + + virtual void interruptCook() {} + + const DataSpecEntry* getDataSpecEntry() const { return m_specEntry; } +}; + +/** + * @brief Pre-emptive indication of what the constructed DataSpec is used for + */ +enum class DataSpecTool { Extract, Cook, Package }; + +extern std::vector DATA_SPEC_REGISTRY; + +/** + * @brief IDataSpec registry entry + * + * Auto-registers with data spec registry + */ +struct DataSpecEntry { + SystemStringView m_name; + SystemStringView m_desc; + SystemStringView m_pakExt; + std::function(Project&, DataSpecTool)> m_factory; + + DataSpecEntry(SystemStringView name, SystemStringView desc, SystemStringView pakExt, + std::function(Project& project, DataSpecTool)>&& factory) + : m_name(name), m_desc(desc), m_pakExt(pakExt), m_factory(std::move(factory)) {} +}; + +/** + * @brief Base object to subclass for integrating with key project operations + * + * All project objects are provided with IDataObject pointers to their database + * entries. Subclasses register themselves with a type registry so instances + * are automatically constructed when performing operations like cooking and packaging. + * + * DO NOT CONSTRUCT THIS OR SUBCLASSES DIRECTLY!! + */ +class ObjectBase { + friend class Project; + SystemString m_path; + +protected: + /** + * @brief Byte-order of target system + */ + enum class DataEndianness { + None, + Big, /**< Big-endian (PowerPC) */ + Little /**< Little-endian (Intel) */ + }; + + /** + * @brief Data-formats of target system + */ + enum class DataPlatform { + None, + Generic, /**< Scanline textures and 3-way shader bundle (GLSL, HLSL, SPIR-V) */ + Revolution, /**< Tiled textures and GX register buffers */ + Cafe /**< Swizzled textures and R700 shader objects */ + }; + + using FDataAppender = std::function; + + /** + * @brief Optional private method implemented by subclasses to cook objects + * @param dataAppender subclass calls this function zero or more times to provide cooked-data linearly + * @param endianness byte-order to target + * @param platform data-formats to target + * @return true if cook succeeded + * + * This method is called during IProject::cookPath(). + * Part of the cooking process may include embedding database-refs to dependencies. + * This method should store the 64-bit value provided by IDataObject::id() when doing this. + */ + virtual bool cookObject([[maybe_unused]] FDataAppender dataAppender, [[maybe_unused]] DataEndianness endianness, + [[maybe_unused]] DataPlatform platform) { + return true; + } + + using FDepAdder = std::function; + + /** + * @brief Optional private method implemented by CProjectObject subclasses to resolve dependencies + * @param depAdder subclass calls this function zero or more times to register each dependency + * + * This method is called during IProject::packagePath(). + * Dependencies registered via this method will eventually have this method called on themselves + * as well. This is a non-recursive operation, no need for subclasses to implement recursion-control. + */ + virtual void gatherDeps([[maybe_unused]] FDepAdder depAdder) {} + + /** + * @brief Get a packagable FourCC representation of the object's type + * @return FourCC of the type + */ + virtual FourCC getType() const { return FourCC("NULL"); } + +public: + ObjectBase(SystemStringView path) : m_path(path) {} + + SystemStringView getPath() const { return m_path; } +}; + +/** + * @brief Main project interface + * + * Projects are intermediate working directories used for staging + * resources in their ideal editor-formats. This interface exposes all + * primary operations to perform on a given project. + */ +class Project { +public: + struct ProjectDataSpec { + const DataSpecEntry& spec; + ProjectPath cookedPath; + bool active; + }; + +private: + ProjectRootPath m_rootPath; + ProjectPath m_workRoot; + ProjectPath m_dotPath; + ProjectPath m_cookedRoot; + std::vector m_compiledSpecs; + std::unordered_map m_bridgePathCache; + std::vector> m_cookSpecs; + std::unique_ptr m_lastPackageSpec; + bool m_valid = false; + +public: + Project(const ProjectRootPath& rootPath); + explicit operator bool() const { return m_valid; } + + /** + * @brief Configuration file handle + * + * Holds a path to a line-delimited textual configuration file; + * opening a locked handle for read/write transactions + */ + class ConfigFile { + SystemString m_filepath; + std::vector m_lines; + UniqueFilePtr m_lockedFile; + + public: + ConfigFile(const Project& project, SystemStringView name, SystemStringView subdir = _SYS_STR("/.hecl/")); + std::vector& lockAndRead(); + void addLine(std::string_view line); + void removeLine(std::string_view refLine); + bool checkForLine(std::string_view refLine) const; + void unlockAndDiscard(); + bool unlockAndCommit(); + }; + ConfigFile m_specs; + ConfigFile m_paths; + ConfigFile m_groups; + + /** + * @brief A rough description of how 'expensive' a given cook operation is + * + * This is used to provide pretty colors during the cook operation + */ + enum class Cost { None, Light, Medium, Heavy }; + + /** + * @brief Get the path of the project's root-directory + * @return project root path + * + * Self explanatory + */ + const ProjectRootPath& getProjectRootPath() const { return m_rootPath; } + + /** + * @brief Get the path of project's working directory + * @return project working path + */ + const ProjectPath& getProjectWorkingPath() const { return m_workRoot; } + + /** + * @brief Get the path of project's cooked directory for a specific DataSpec + * @param spec DataSpec to retrieve path for + * @return project cooked path + * + * The cooked path matches the directory layout of the working directory + */ + const ProjectPath& getProjectCookedPath(const DataSpecEntry& spec) const; + + /** + * @brief Add given file(s) to the database + * @param paths files or patterns within project + * @return true on success + * + * This method blocks while object hashing takes place + */ + bool addPaths(const std::vector& paths); + + /** + * @brief Remove a given file or file-pattern from the database + * @param paths file(s) or pattern(s) within project + * @param recursive traverse into matched subdirectories + * @return true on success + * + * This method will not delete actual working files from the project + * directory. It will delete associated cooked objects though. + */ + bool removePaths(const std::vector& paths, bool recursive = false); + + /** + * @brief Register a working sub-directory as a Dependency Group + * @param path directory to register as Dependency Group + * @return true on success + * + * Dependency Groups are used at runtime to stage burst load-transactions. + * They may only be added to directories and will automatically claim + * subdirectories as well. + * + * Cooked objects in dependency groups will be packaged contiguously + * and automatically duplicated if shared with other dependency groups. + * This contiguous storage makes for optimal loading from slow block-devices + * like optical drives. + */ + bool addGroup(const ProjectPath& path); + + /** + * @brief Unregister a working sub-directory as a dependency group + * @param path directory to unregister as Dependency Group + * @return true on success + */ + bool removeGroup(const ProjectPath& path); + + /** + * @brief Re-reads the data store holding user's spec preferences + * + * Call periodically in a long-term use of the hecl::Database::Project class. + * Install filesystem event-hooks if possible. + */ + void rescanDataSpecs(); + + /** + * @brief Return map populated with dataspecs targetable by this project interface + * @return Platform map with name-string keys and enable-status values + */ + const std::vector& getDataSpecs() const { return m_compiledSpecs; } + + /** + * @brief Enable persistent user preference for particular spec string(s) + * @param specs String(s) representing unique spec(s) from getDataSpecs + * @return true on success + */ + bool enableDataSpecs(const std::vector& specs); + + /** + * @brief Disable persistent user preference for particular spec string(s) + * @param specs String(s) representing unique spec(s) from getDataSpecs + * @return true on success + */ + bool disableDataSpecs(const std::vector& specs); + + /** + * @brief Begin cook process for specified directory + * @param path directory of intermediates to cook + * @param feedbackCb a callback to run reporting cook-progress + * @param recursive traverse subdirectories to cook as well + * @param fast enables faster (draft) extraction for supported data types + * @param spec if non-null, cook using a manually-selected dataspec + * @param cp if non-null, cook asynchronously via the ClientProcess + * @return true on success + * + * Object cooking is generally an expensive process for large projects. + * This method blocks execution during the procedure, with periodic + * feedback delivered via feedbackCb. + */ + bool cookPath(const ProjectPath& path, const MultiProgressPrinter& feedbackCb, bool recursive = false, + bool force = false, bool fast = false, const DataSpecEntry* spec = nullptr, + ClientProcess* cp = nullptr); + + /** + * @brief Begin package process for specified !world.blend or directory + * @param path Path to !world.blend or directory + * @param feedbackCb a callback to run reporting cook-progress + * @param fast enables faster (draft) extraction for supported data types + * @param spec if non-null, cook using a manually-selected dataspec + * @param cp if non-null, cook asynchronously via the ClientProcess + */ + bool packagePath(const ProjectPath& path, const MultiProgressPrinter& feedbackCb, bool fast = false, + const DataSpecEntry* spec = nullptr, ClientProcess* cp = nullptr); + + /** + * @brief Interrupts a cook in progress (call from SIGINT handler) + * + * Database corruption is bad! HECL spreads its data objects through + * the filesystem; this ensures that open objects are cleanly + * finalized or discarded before stopping. + * + * Note that this method returns immediately; the resumed cookPath() + * call will return as quickly as possible. + */ + void interruptCook(); + + /** + * @brief Delete cooked objects for directory + * @param path directory of intermediates to clean + * @param recursive traverse subdirectories to clean as well + * @return true on success + * + * Developers understand how useful 'clean' is. While ideally not required, + * it's useful for verifying that a rebuild from ground-up is doable. + */ + bool cleanPath(const ProjectPath& path, bool recursive = false); + + /** + * @brief Constructs a full depsgraph of the project-subpath provided + * @param path Subpath of project to root depsgraph at + * @return Populated depsgraph ready to traverse + */ + PackageDepsgraph buildPackageDepsgraph(const ProjectPath& path); + + /** Add ProjectPath to bridge cache */ + void addBridgePathToCache(uint64_t id, const ProjectPath& path); + + /** Clear all ProjectPaths in bridge cache */ + void clearBridgePathCache(); + + /** Lookup ProjectPath from bridge cache */ + const ProjectPath* lookupBridgePath(uint64_t id) const; +}; + +} // namespace Database +} // namespace hecl diff --git a/hecl/include/hecl/FourCC.hpp b/hecl/include/hecl/FourCC.hpp new file mode 100644 index 000000000..5056a8e87 --- /dev/null +++ b/hecl/include/hecl/FourCC.hpp @@ -0,0 +1,103 @@ +#pragma once + +#include +#include +#include + +#include +#include + +namespace hecl { + +/** + * @brief FourCC representation used within HECL's database + * + * FourCCs are efficient, mnemonic four-char-sequences used to represent types + * while fitting comfortably in a 32-bit word. HECL uses a four-char array + * to remain endian-independent. + */ +class FourCC { +protected: + union { + char fcc[4]; + uint32_t num = 0; + }; + +public: + // Sentinel FourCC + constexpr FourCC() noexcept = default; + constexpr FourCC(const FourCC& other) noexcept = default; + constexpr FourCC(FourCC&& other) noexcept = default; + constexpr FourCC(const char* name) noexcept : fcc{name[0], name[1], name[2], name[3]} {} + constexpr FourCC(uint32_t n) noexcept : num(n) {} + + constexpr FourCC& operator=(const FourCC&) noexcept = default; + constexpr FourCC& operator=(FourCC&&) noexcept = default; + + constexpr bool operator==(const FourCC& other) const noexcept { return num == other.num; } + constexpr bool operator!=(const FourCC& other) const noexcept { return !operator==(other); } + constexpr bool operator==(const char* other) const noexcept { + return other[0] == fcc[0] && other[1] == fcc[1] && other[2] == fcc[2] && other[3] == fcc[3]; + } + constexpr bool operator!=(const char* other) const noexcept { return !operator==(other); } + constexpr bool operator==(int32_t other) const noexcept { return num == uint32_t(other); } + constexpr bool operator!=(int32_t other) const noexcept { return !operator==(other); } + constexpr bool operator==(uint32_t other) const noexcept { return num == other; } + constexpr bool operator!=(uint32_t other) const noexcept { return !operator==(other); } + + std::string toString() const { return std::string(std::begin(fcc), std::end(fcc)); } + constexpr std::string_view toStringView() const { return std::string_view(fcc, std::size(fcc)); } + constexpr uint32_t toUint32() const noexcept { return num; } + constexpr const char* getChars() const noexcept { return fcc; } + constexpr char* getChars() noexcept { return fcc; } + constexpr bool IsValid() const noexcept { return num != 0; } +}; +#define FOURCC(chars) FourCC(SBIG(chars)) + +using BigDNA = athena::io::DNA; + +/** FourCC with DNA read/write */ +class DNAFourCC final : public BigDNA, public FourCC { +public: + constexpr DNAFourCC() noexcept : FourCC() {} + constexpr DNAFourCC(const FourCC& other) noexcept : FourCC(other) {} + constexpr DNAFourCC(const char* name) noexcept : FourCC(name) {} + constexpr DNAFourCC(uint32_t n) noexcept : FourCC(n) {} + DNAFourCC(athena::io::IStreamReader& r) { read(r); } + AT_DECL_EXPLICIT_DNA_YAML +}; +template <> +inline void DNAFourCC::Enumerate(Read::StreamT& r) { + r.readUBytesToBuf(fcc, std::size(fcc)); +} +template <> +inline void DNAFourCC::Enumerate(Write::StreamT& w) { + w.writeBytes(fcc, std::size(fcc)); +} +template <> +inline void DNAFourCC::Enumerate(ReadYaml::StreamT& r) { + const std::string rs = r.readString(); + rs.copy(fcc, std::size(fcc)); +} +template <> +inline void DNAFourCC::Enumerate(WriteYaml::StreamT& w) { + w.writeString(std::string_view{fcc, std::size(fcc)}); +} +template <> +inline void DNAFourCC::Enumerate(BinarySize::StreamT& s) { + s += std::size(fcc); +} + +} // namespace hecl + +namespace std { +template <> +struct hash { + size_t operator()(const hecl::FourCC& val) const noexcept { return val.toUint32(); } +}; +} // namespace std + +FMT_CUSTOM_FORMATTER(hecl::FourCC, "{:c}{:c}{:c}{:c}", obj.getChars()[0], obj.getChars()[1], obj.getChars()[2], + obj.getChars()[3]) +FMT_CUSTOM_FORMATTER(hecl::DNAFourCC, "{:c}{:c}{:c}{:c}", obj.getChars()[0], obj.getChars()[1], obj.getChars()[2], + obj.getChars()[3]) diff --git a/hecl/include/hecl/HMDLMeta.hpp b/hecl/include/hecl/HMDLMeta.hpp new file mode 100644 index 000000000..7575f2c15 --- /dev/null +++ b/hecl/include/hecl/HMDLMeta.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include + +namespace hecl { + +enum class HMDLTopology : atUint32 { + Triangles, + TriStrips, +}; + +#define HECL_HMDL_META_SZ 32 + +struct HMDLMeta : athena::io::DNA { + AT_DECL_DNA + Value magic = 'TACO'; + Value topology; + Value vertStride; + Value vertCount; + Value indexCount; + Value colorCount; + Value uvCount; + Value weightCount; + Value bankCount; +}; + +} // namespace hecl diff --git a/hecl/include/hecl/MathExtras.hpp b/hecl/include/hecl/MathExtras.hpp new file mode 100644 index 000000000..14192a7cb --- /dev/null +++ b/hecl/include/hecl/MathExtras.hpp @@ -0,0 +1,821 @@ +//===-- llvm/Support/MathExtras.h - Useful math functions -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains some functions that are useful for math stuff. +// +//===----------------------------------------------------------------------===// + +#pragma once + +/// \macro LLVM_GNUC_PREREQ +/// \brief Extend the default __GNUC_PREREQ even if glibc's features.h isn't +/// available. +#ifndef LLVM_GNUC_PREREQ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +#define LLVM_GNUC_PREREQ(maj, min, patch) \ + ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= ((maj) << 20) + ((min) << 10) + (patch)) +#elif defined(__GNUC__) && defined(__GNUC_MINOR__) +#define LLVM_GNUC_PREREQ(maj, min, patch) ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) +#else +#define LLVM_GNUC_PREREQ(maj, min, patch) 0 +#endif +#endif + +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + +#include "hecl.hpp" +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#include +#endif + +#ifdef __ANDROID_NDK__ +#include +#endif + +namespace hecl { +namespace llvm { +/// \brief The behavior an operation has on an input of 0. +enum ZeroBehavior { + /// \brief The returned value is undefined. + ZB_Undefined, + /// \brief The returned value is numeric_limits::max() + ZB_Max, + /// \brief The returned value is numeric_limits::digits + ZB_Width +}; + +namespace detail { +template +struct TrailingZerosCounter { + static std::size_t count(T Val, ZeroBehavior) { + if (!Val) + return std::numeric_limits::digits; + if (Val & 0x1) + return 0; + + // Bisection method. + std::size_t ZeroBits = 0; + T Shift = std::numeric_limits::digits >> 1; + T Mask = std::numeric_limits::max() >> Shift; + while (Shift) { + if ((Val & Mask) == 0) { + Val >>= Shift; + ZeroBits |= Shift; + } + Shift >>= 1; + Mask >>= Shift; + } + return ZeroBits; + } +}; + +#if __GNUC__ >= 4 || defined(_MSC_VER) +template +struct TrailingZerosCounter { + static std::size_t count(T Val, ZeroBehavior ZB) { + if (ZB != ZB_Undefined && Val == 0) + return 32; + +#if __has_builtin(__builtin_ctz) || LLVM_GNUC_PREREQ(4, 0, 0) + return __builtin_ctz(Val); +#elif defined(_MSC_VER) + unsigned long Index; + _BitScanForward(&Index, Val); + return Index; +#endif + } +}; + +#if !defined(_MSC_VER) || defined(_M_X64) +template +struct TrailingZerosCounter { + static std::size_t count(T Val, ZeroBehavior ZB) { + if (ZB != ZB_Undefined && Val == 0) + return 64; + +#if __has_builtin(__builtin_ctzll) || LLVM_GNUC_PREREQ(4, 0, 0) + return __builtin_ctzll(Val); +#elif defined(_MSC_VER) + unsigned long Index; + _BitScanForward64(&Index, Val); + return Index; +#endif + } +}; +#endif +#endif +} // namespace detail + +/// \brief Count number of 0's from the least significant bit to the most +/// stopping at the first 1. +/// +/// Only unsigned integral types are allowed. +/// +/// \param ZB the behavior on an input of 0. Only ZB_Width and ZB_Undefined are +/// valid arguments. +template +std::size_t countTrailingZeros(T Val, ZeroBehavior ZB = ZB_Width) { + static_assert(std::numeric_limits::is_integer && !std::numeric_limits::is_signed, + "Only unsigned integral types are allowed."); + return detail::TrailingZerosCounter::count(Val, ZB); +} + +namespace detail { +template +struct LeadingZerosCounter { + static std::size_t count(T Val, ZeroBehavior) { + if (!Val) + return std::numeric_limits::digits; + + // Bisection method. + std::size_t ZeroBits = 0; + for (T Shift = std::numeric_limits::digits >> 1; Shift; Shift >>= 1) { + T Tmp = Val >> Shift; + if (Tmp) + Val = Tmp; + else + ZeroBits |= Shift; + } + return ZeroBits; + } +}; + +#if __GNUC__ >= 4 || defined(_MSC_VER) +template +struct LeadingZerosCounter { + static std::size_t count(T Val, ZeroBehavior ZB) { + if (ZB != ZB_Undefined && Val == 0) + return 32; + +#if __has_builtin(__builtin_clz) || LLVM_GNUC_PREREQ(4, 0, 0) + return __builtin_clz(Val); +#elif defined(_MSC_VER) + unsigned long Index; + _BitScanReverse(&Index, Val); + return Index ^ 31; +#endif + } +}; + +#if !defined(_MSC_VER) || defined(_M_X64) +template +struct LeadingZerosCounter { + static std::size_t count(T Val, ZeroBehavior ZB) { + if (ZB != ZB_Undefined && Val == 0) + return 64; + +#if __has_builtin(__builtin_clzll) || LLVM_GNUC_PREREQ(4, 0, 0) + return __builtin_clzll(Val); +#elif defined(_MSC_VER) + unsigned long Index; + _BitScanReverse64(&Index, Val); + return Index ^ 63; +#endif + } +}; +#endif +#endif +} // namespace detail + +/// \brief Count number of 0's from the most significant bit to the least +/// stopping at the first 1. +/// +/// Only unsigned integral types are allowed. +/// +/// \param ZB the behavior on an input of 0. Only ZB_Width and ZB_Undefined are +/// valid arguments. +template +std::size_t countLeadingZeros(T Val, ZeroBehavior ZB = ZB_Width) { + static_assert(std::numeric_limits::is_integer && !std::numeric_limits::is_signed, + "Only unsigned integral types are allowed."); + return detail::LeadingZerosCounter::count(Val, ZB); +} + +/// \brief Get the index of the first set bit starting from the least +/// significant bit. +/// +/// Only unsigned integral types are allowed. +/// +/// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are +/// valid arguments. +template +T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) { + if (ZB == ZB_Max && Val == 0) + return std::numeric_limits::max(); + + return countTrailingZeros(Val, ZB_Undefined); +} + +/// \brief Get the index of the last set bit starting from the least +/// significant bit. +/// +/// Only unsigned integral types are allowed. +/// +/// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are +/// valid arguments. +template +T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) { + if (ZB == ZB_Max && Val == 0) + return std::numeric_limits::max(); + + // Use ^ instead of - because both gcc and llvm can remove the associated ^ + // in the __builtin_clz intrinsic on x86. + return countLeadingZeros(Val, ZB_Undefined) ^ (std::numeric_limits::digits - 1); +} + +/// \brief Macro compressed bit reversal table for 256 bits. +/// +/// http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable +static const unsigned char BitReverseTable256[256] = { +#define R2(n) n, n + 2 * 64, n + 1 * 64, n + 3 * 64 +#define R4(n) R2(n), R2(n + 2 * 16), R2(n + 1 * 16), R2(n + 3 * 16) +#define R6(n) R4(n), R4(n + 2 * 4), R4(n + 1 * 4), R4(n + 3 * 4) + R6(0), R6(2), R6(1), R6(3) +#undef R2 +#undef R4 +#undef R6 +}; + +/// \brief Reverse the bits in \p Val. +template +T reverseBits(T Val) { + unsigned char in[sizeof(Val)]; + unsigned char out[sizeof(Val)]; + std::memcpy(in, &Val, sizeof(Val)); + for (unsigned i = 0; i < sizeof(Val); ++i) + out[(sizeof(Val) - i) - 1] = BitReverseTable256[in[i]]; + std::memcpy(&Val, out, sizeof(Val)); + return Val; +} + +// NOTE: The following support functions use the _32/_64 extensions instead of +// type overloading so that signed and unsigned integers can be used without +// ambiguity. + +/// Hi_32 - This function returns the high 32 bits of a 64 bit value. +constexpr inline uint32_t Hi_32(uint64_t Value) { return static_cast(Value >> 32); } + +/// Lo_32 - This function returns the low 32 bits of a 64 bit value. +constexpr inline uint32_t Lo_32(uint64_t Value) { return static_cast(Value); } + +/// Make_64 - This functions makes a 64-bit integer from a high / low pair of +/// 32-bit integers. +constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) { return ((uint64_t)High << 32) | (uint64_t)Low; } + +/// isInt - Checks if an integer fits into the given bit width. +template +constexpr inline bool isInt(int64_t x) { + return N >= 64 || (-(INT64_C(1) << (N - 1)) <= x && x < (INT64_C(1) << (N - 1))); +} +// Template specializations to get better code for common cases. +template <> +constexpr inline bool isInt<8>(int64_t x) { + return static_cast(x) == x; +} +template <> +constexpr inline bool isInt<16>(int64_t x) { + return static_cast(x) == x; +} +template <> +constexpr inline bool isInt<32>(int64_t x) { + return static_cast(x) == x; +} + +/// isShiftedInt - Checks if a signed integer is an N bit number shifted +/// left by S. +template +constexpr inline bool isShiftedInt(int64_t x) { + static_assert(N > 0, "isShiftedInt<0> doesn't make sense (refers to a 0-bit number."); + static_assert(N + S <= 64, "isShiftedInt with N + S > 64 is too wide."); + return isInt(x) && (x % (UINT64_C(1) << S) == 0); +} + +/// isUInt - Checks if an unsigned integer fits into the given bit width. +/// +/// This is written as two functions rather than as simply +/// +/// return N >= 64 || X < (UINT64_C(1) << N); +/// +/// to keep MSVC from (incorrectly) warning on isUInt<64> that we're shifting +/// left too many places. +template +constexpr inline typename std::enable_if<(N < 64), bool>::type isUInt(uint64_t X) { + static_assert(N > 0, "isUInt<0> doesn't make sense"); + return X < (UINT64_C(1) << (N)); +} +template +constexpr inline typename std::enable_if= 64, bool>::type isUInt(uint64_t X) { + return true; +} + +// Template specializations to get better code for common cases. +template <> +constexpr inline bool isUInt<8>(uint64_t x) { + return static_cast(x) == x; +} +template <> +constexpr inline bool isUInt<16>(uint64_t x) { + return static_cast(x) == x; +} +template <> +constexpr inline bool isUInt<32>(uint64_t x) { + return static_cast(x) == x; +} + +/// Checks if a unsigned integer is an N bit number shifted left by S. +template +constexpr inline bool isShiftedUInt(uint64_t x) { + static_assert(N > 0, "isShiftedUInt<0> doesn't make sense (refers to a 0-bit number)"); + static_assert(N + S <= 64, "isShiftedUInt with N + S > 64 is too wide."); + // Per the two static_asserts above, S must be strictly less than 64. So + // 1 << S is not undefined behavior. + return isUInt(x) && (x % (UINT64_C(1) << S) == 0); +} + +/// Gets the maximum value for a N-bit unsigned integer. +inline uint64_t maxUIntN(uint64_t N) { + assert(N > 0 && N <= 64 && "integer width out of range"); + + // uint64_t(1) << 64 is undefined behavior, so we can't do + // (uint64_t(1) << N) - 1 + // without checking first that N != 64. But this works and doesn't have a + // branch. + return UINT64_MAX >> (64 - N); +} + +/// Gets the minimum value for a N-bit signed integer. +inline int64_t minIntN(int64_t N) { + assert(N > 0 && N <= 64 && "integer width out of range"); + + return -(UINT64_C(1) << (N - 1)); +} + +/// Gets the maximum value for a N-bit signed integer. +inline int64_t maxIntN(int64_t N) { + assert(N > 0 && N <= 64 && "integer width out of range"); + + // This relies on two's complement wraparound when N == 64, so we convert to + // int64_t only at the very end to avoid UB. + return (UINT64_C(1) << (N - 1)) - 1; +} + +/// isUIntN - Checks if an unsigned integer fits into the given (dynamic) +/// bit width. +inline bool isUIntN(unsigned N, uint64_t x) { return N >= 64 || x <= maxUIntN(N); } + +/// isIntN - Checks if an signed integer fits into the given (dynamic) +/// bit width. +inline bool isIntN(unsigned N, int64_t x) { return N >= 64 || (minIntN(N) <= x && x <= maxIntN(N)); } + +/// isMask_32 - This function returns true if the argument is a non-empty +/// sequence of ones starting at the least significant bit with the remainder +/// zero (32 bit version). Ex. isMask_32(0x0000FFFFU) == true. +constexpr inline bool isMask_32(uint32_t Value) { return Value && ((Value + 1) & Value) == 0; } + +/// isMask_64 - This function returns true if the argument is a non-empty +/// sequence of ones starting at the least significant bit with the remainder +/// zero (64 bit version). +constexpr inline bool isMask_64(uint64_t Value) { return Value && ((Value + 1) & Value) == 0; } + +/// isShiftedMask_32 - This function returns true if the argument contains a +/// non-empty sequence of ones with the remainder zero (32 bit version.) +/// Ex. isShiftedMask_32(0x0000FF00U) == true. +constexpr inline bool isShiftedMask_32(uint32_t Value) { return Value && isMask_32((Value - 1) | Value); } + +/// isShiftedMask_64 - This function returns true if the argument contains a +/// non-empty sequence of ones with the remainder zero (64 bit version.) +constexpr inline bool isShiftedMask_64(uint64_t Value) { return Value && isMask_64((Value - 1) | Value); } + +/// isPowerOf2_32 - This function returns true if the argument is a power of +/// two > 0. Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.) +constexpr inline bool isPowerOf2_32(uint32_t Value) { return Value && !(Value & (Value - 1)); } + +/// isPowerOf2_64 - This function returns true if the argument is a power of two +/// > 0 (64 bit edition.) +constexpr inline bool isPowerOf2_64(uint64_t Value) { return Value && !(Value & (Value - int64_t(1L))); } + +/// ByteSwap_16 - This function returns a byte-swapped representation of the +/// 16-bit argument, Value. +inline uint16_t ByteSwap_16(uint16_t Value) { return hecl::bswap16(Value); } + +/// ByteSwap_32 - This function returns a byte-swapped representation of the +/// 32-bit argument, Value. +inline uint32_t ByteSwap_32(uint32_t Value) { return hecl::bswap32(Value); } + +/// ByteSwap_64 - This function returns a byte-swapped representation of the +/// 64-bit argument, Value. +inline uint64_t ByteSwap_64(uint64_t Value) { return hecl::bswap64(Value); } + +/// \brief Count the number of ones from the most significant bit to the first +/// zero bit. +/// +/// Ex. CountLeadingOnes(0xFF0FFF00) == 8. +/// Only unsigned integral types are allowed. +/// +/// \param ZB the behavior on an input of all ones. Only ZB_Width and +/// ZB_Undefined are valid arguments. +template +std::size_t countLeadingOnes(T Value, ZeroBehavior ZB = ZB_Width) { + static_assert(std::numeric_limits::is_integer && !std::numeric_limits::is_signed, + "Only unsigned integral types are allowed."); + return countLeadingZeros(~Value, ZB); +} + +/// \brief Count the number of ones from the least significant bit to the first +/// zero bit. +/// +/// Ex. countTrailingOnes(0x00FF00FF) == 8. +/// Only unsigned integral types are allowed. +/// +/// \param ZB the behavior on an input of all ones. Only ZB_Width and +/// ZB_Undefined are valid arguments. +template +std::size_t countTrailingOnes(T Value, ZeroBehavior ZB = ZB_Width) { + static_assert(std::numeric_limits::is_integer && !std::numeric_limits::is_signed, + "Only unsigned integral types are allowed."); + return countTrailingZeros(~Value, ZB); +} + +namespace detail { +template +struct PopulationCounter { + static unsigned count(T Value) { + // Generic version, forward to 32 bits. + static_assert(SizeOfT <= 4, "Not implemented!"); +#if __GNUC__ >= 4 + return __builtin_popcount(Value); +#else + uint32_t v = Value; + v = v - ((v >> 1) & 0x55555555); + v = (v & 0x33333333) + ((v >> 2) & 0x33333333); + return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; +#endif + } +}; + +template +struct PopulationCounter { + static unsigned count(T Value) { +#if __GNUC__ >= 4 + return __builtin_popcountll(Value); +#else + uint64_t v = Value; + v = v - ((v >> 1) & 0x5555555555555555ULL); + v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL); + v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL; + return unsigned((uint64_t)(v * 0x0101010101010101ULL) >> 56); +#endif + } +}; +} // namespace detail + +/// \brief Count the number of set bits in a value. +/// Ex. countPopulation(0xF000F000) = 8 +/// Returns 0 if the word is zero. +template +inline unsigned countPopulation(T Value) { + static_assert(std::numeric_limits::is_integer && !std::numeric_limits::is_signed, + "Only unsigned integral types are allowed."); + return detail::PopulationCounter::count(Value); +} + +/// Log2 - This function returns the log base 2 of the specified value +inline double Log2(double Value) { +#if defined(__ANDROID_API__) && __ANDROID_API__ < 18 + return __builtin_log(Value) / __builtin_log(2.0); +#else + return log2(Value); +#endif +} + +/// Log2_32 - This function returns the floor log base 2 of the specified value, +/// -1 if the value is zero. (32 bit edition.) +/// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2 +inline unsigned Log2_32(uint32_t Value) { return 31 - countLeadingZeros(Value); } + +/// Log2_64 - This function returns the floor log base 2 of the specified value, +/// -1 if the value is zero. (64 bit edition.) +inline unsigned Log2_64(uint64_t Value) { return 63 - countLeadingZeros(Value); } + +/// Log2_32_Ceil - This function returns the ceil log base 2 of the specified +/// value, 32 if the value is zero. (32 bit edition). +/// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3 +inline unsigned Log2_32_Ceil(uint32_t Value) { return 32 - countLeadingZeros(Value - 1); } + +/// Log2_64_Ceil - This function returns the ceil log base 2 of the specified +/// value, 64 if the value is zero. (64 bit edition.) +inline unsigned Log2_64_Ceil(uint64_t Value) { return 64 - countLeadingZeros(Value - 1); } + +/// GreatestCommonDivisor64 - Return the greatest common divisor of the two +/// values using Euclid's algorithm. +inline uint64_t GreatestCommonDivisor64(uint64_t A, uint64_t B) { + while (B) { + uint64_t T = B; + B = A % B; + A = T; + } + return A; +} + +/// BitsToDouble - This function takes a 64-bit integer and returns the bit +/// equivalent double. +inline double BitsToDouble(uint64_t Bits) { + union { + uint64_t L; + double D; + } T; + T.L = Bits; + return T.D; +} + +/// BitsToFloat - This function takes a 32-bit integer and returns the bit +/// equivalent float. +inline float BitsToFloat(uint32_t Bits) { + union { + uint32_t I; + float F; + } T; + T.I = Bits; + return T.F; +} + +/// DoubleToBits - This function takes a double and returns the bit +/// equivalent 64-bit integer. Note that copying doubles around +/// changes the bits of NaNs on some hosts, notably x86, so this +/// routine cannot be used if these bits are needed. +inline uint64_t DoubleToBits(double Double) { + union { + uint64_t L; + double D; + } T; + T.D = Double; + return T.L; +} + +/// FloatToBits - This function takes a float and returns the bit +/// equivalent 32-bit integer. Note that copying floats around +/// changes the bits of NaNs on some hosts, notably x86, so this +/// routine cannot be used if these bits are needed. +inline uint32_t FloatToBits(float Float) { + union { + uint32_t I; + float F; + } T; + T.F = Float; + return T.I; +} + +/// MinAlign - A and B are either alignments or offsets. Return the minimum +/// alignment that may be assumed after adding the two together. +constexpr inline uint64_t MinAlign(uint64_t A, uint64_t B) { + // The largest power of 2 that divides both A and B. + // + // Replace "-Value" by "1+~Value" in the following commented code to avoid + // MSVC warning C4146 + // return (A | B) & -(A | B); + return (A | B) & (1 + ~(A | B)); +} + +/// \brief Aligns \c Addr to \c Alignment bytes, rounding up. +/// +/// Alignment should be a power of two. This method rounds up, so +/// alignAddr(7, 4) == 8 and alignAddr(8, 4) == 8. +inline uintptr_t alignAddr(const void* Addr, size_t Alignment) { + assert(Alignment && isPowerOf2_64((uint64_t)Alignment) && "Alignment is not a power of two!"); + + assert((uintptr_t)Addr + Alignment - 1 >= (uintptr_t)Addr); + + return (((uintptr_t)Addr + Alignment - 1) & ~(uintptr_t)(Alignment - 1)); +} + +/// \brief Returns the necessary adjustment for aligning \c Ptr to \c Alignment +/// bytes, rounding up. +inline size_t alignmentAdjustment(const void* Ptr, size_t Alignment) { + return alignAddr(Ptr, Alignment) - (uintptr_t)Ptr; +} + +/// NextPowerOf2 - Returns the next power of two (in 64-bits) +/// that is strictly greater than A. Returns zero on overflow. +inline uint64_t NextPowerOf2(uint64_t A) { + A |= (A >> 1); + A |= (A >> 2); + A |= (A >> 4); + A |= (A >> 8); + A |= (A >> 16); + A |= (A >> 32); + return A + 1; +} + +/// Returns the power of two which is less than or equal to the given value. +/// Essentially, it is a floor operation across the domain of powers of two. +inline uint64_t PowerOf2Floor(uint64_t A) { + if (!A) + return 0; + return 1ull << (63 - countLeadingZeros(A, ZB_Undefined)); +} + +/// Returns the power of two which is greater than or equal to the given value. +/// Essentially, it is a ceil operation across the domain of powers of two. +inline uint64_t PowerOf2Ceil(uint64_t A) { + if (!A) + return 0; + return NextPowerOf2(A - 1); +} + +/// Returns the next integer (mod 2**64) that is greater than or equal to +/// \p Value and is a multiple of \p Align. \p Align must be non-zero. +/// +/// If non-zero \p Skew is specified, the return value will be a minimal +/// integer that is greater than or equal to \p Value and equal to +/// \p Align * N + \p Skew for some integer N. If \p Skew is larger than +/// \p Align, its value is adjusted to '\p Skew mod \p Align'. +/// +/// Examples: +/// \code +/// alignTo(5, 8) = 8 +/// alignTo(17, 8) = 24 +/// alignTo(~0LL, 8) = 0 +/// alignTo(321, 255) = 510 +/// +/// alignTo(5, 8, 7) = 7 +/// alignTo(17, 8, 1) = 17 +/// alignTo(~0LL, 8, 3) = 3 +/// alignTo(321, 255, 42) = 552 +/// \endcode +inline uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew = 0) { + assert(Align != 0u && "Align can't be 0."); + Skew %= Align; + return (Value + Align - 1 - Skew) / Align * Align + Skew; +} + +/// Returns the next integer (mod 2**64) that is greater than or equal to +/// \p Value and is a multiple of \c Align. \c Align must be non-zero. +template +constexpr inline uint64_t alignTo(uint64_t Value) { + static_assert(Align != 0u, "Align must be non-zero"); + return (Value + Align - 1) / Align * Align; +} + +/// \c alignTo for contexts where a constant expression is required. +/// \sa alignTo +/// +/// \todo FIXME: remove when \c constexpr becomes really \c constexpr +template +struct AlignTo { + static_assert(Align != 0u, "Align must be non-zero"); + template + struct from_value { + static const uint64_t value = (Value + Align - 1) / Align * Align; + }; +}; + +/// Returns the largest uint64_t less than or equal to \p Value and is +/// \p Skew mod \p Align. \p Align must be non-zero +inline uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew = 0) { + assert(Align != 0u && "Align can't be 0."); + Skew %= Align; + return (Value - Skew) / Align * Align + Skew; +} + +/// Returns the offset to the next integer (mod 2**64) that is greater than +/// or equal to \p Value and is a multiple of \p Align. \p Align must be +/// non-zero. +inline uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align) { return alignTo(Value, Align) - Value; } + +/// Sign-extend the number in the bottom B bits of X to a 32-bit integer. +/// Requires 0 < B <= 32. +template +constexpr inline int32_t SignExtend32(uint32_t X) { + static_assert(B > 0, "Bit width can't be 0."); + static_assert(B <= 32, "Bit width out of range."); + return int32_t(X << (32 - B)) >> (32 - B); +} + +/// Sign-extend the number in the bottom B bits of X to a 32-bit integer. +/// Requires 0 < B < 32. +inline int32_t SignExtend32(uint32_t X, unsigned B) { + assert(B > 0 && "Bit width can't be 0."); + assert(B <= 32 && "Bit width out of range."); + return int32_t(X << (32 - B)) >> (32 - B); +} + +/// Sign-extend the number in the bottom B bits of X to a 64-bit integer. +/// Requires 0 < B < 64. +template +constexpr inline int64_t SignExtend64(uint64_t x) { + static_assert(B > 0, "Bit width can't be 0."); + static_assert(B <= 64, "Bit width out of range."); + return int64_t(x << (64 - B)) >> (64 - B); +} + +/// Sign-extend the number in the bottom B bits of X to a 64-bit integer. +/// Requires 0 < B < 64. +inline int64_t SignExtend64(uint64_t X, unsigned B) { + assert(B > 0 && "Bit width can't be 0."); + assert(B <= 64 && "Bit width out of range."); + return int64_t(X << (64 - B)) >> (64 - B); +} + +/// Subtract two unsigned integers, X and Y, of type T and return the absolute +/// value of the result. +template +typename std::enable_if::value, T>::type AbsoluteDifference(T X, T Y) { + return std::max(X, Y) - std::min(X, Y); +} + +/// Add two unsigned integers, X and Y, of type T. Clamp the result to the +/// maximum representable value of T on overflow. ResultOverflowed indicates if +/// the result is larger than the maximum representable value of type T. +template +typename std::enable_if::value, T>::type SaturatingAdd(T X, T Y, bool* ResultOverflowed = nullptr) { + bool Dummy; + bool& Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy; + // Hacker's Delight, p. 29 + T Z = X + Y; + Overflowed = (Z < X || Z < Y); + if (Overflowed) + return std::numeric_limits::max(); + else + return Z; +} + +/// Multiply two unsigned integers, X and Y, of type T. Clamp the result to the +/// maximum representable value of T on overflow. ResultOverflowed indicates if +/// the result is larger than the maximum representable value of type T. +template +typename std::enable_if::value, T>::type SaturatingMultiply(T X, T Y, + bool* ResultOverflowed = nullptr) { + bool Dummy; + bool& Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy; + + // Hacker's Delight, p. 30 has a different algorithm, but we don't use that + // because it fails for uint16_t (where multiplication can have undefined + // behavior due to promotion to int), and requires a division in addition + // to the multiplication. + + Overflowed = false; + + // Log2(Z) would be either Log2Z or Log2Z + 1. + // Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z + // will necessarily be less than Log2Max as desired. + int Log2Z = Log2_64(X) + Log2_64(Y); + const T Max = std::numeric_limits::max(); + int Log2Max = Log2_64(Max); + if (Log2Z < Log2Max) { + return X * Y; + } + if (Log2Z > Log2Max) { + Overflowed = true; + return Max; + } + + // We're going to use the top bit, and maybe overflow one + // bit past it. Multiply all but the bottom bit then add + // that on at the end. + T Z = (X >> 1) * Y; + if (Z & ~(Max >> 1)) { + Overflowed = true; + return Max; + } + Z <<= 1; + if (X & 1) + return SaturatingAdd(Z, Y, ResultOverflowed); + + return Z; +} + +/// Multiply two unsigned integers, X and Y, and add the unsigned integer, A to +/// the product. Clamp the result to the maximum representable value of T on +/// overflow. ResultOverflowed indicates if the result is larger than the +/// maximum representable value of type T. +template +typename std::enable_if::value, T>::type SaturatingMultiplyAdd(T X, T Y, T A, + bool* ResultOverflowed = nullptr) { + bool Dummy; + bool& Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy; + + T Product = SaturatingMultiply(X, Y, &Overflowed); + if (Overflowed) + return Product; + + return SaturatingAdd(A, Product, &Overflowed); +} + +/// Use this rather than HUGE_VALF; the latter causes warnings on MSVC. +extern const float huge_valf; +} // namespace llvm +} // namespace hecl diff --git a/hecl/include/hecl/MultiProgressPrinter.hpp b/hecl/include/hecl/MultiProgressPrinter.hpp new file mode 100644 index 000000000..0eb9b508a --- /dev/null +++ b/hecl/include/hecl/MultiProgressPrinter.hpp @@ -0,0 +1,66 @@ +#pragma once + +#include +#include +#include +#include + +#include "hecl/SystemChar.hpp" + +#if _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#endif + +namespace hecl { + +class MultiProgressPrinter { + std::thread m_logThread; + mutable std::mutex m_logLock; + bool m_newLineAfter; + + struct TermInfo { +#if _WIN32 + HANDLE console; +#endif + int width; + bool xtermColor = false; + bool truncate = false; + } m_termInfo; + + struct ThreadStat { + hecl::SystemString m_message, m_submessage; + float m_factor = 0.f; + bool m_active = false; + void print(const TermInfo& tinfo) const; + }; + mutable std::vector m_threadStats; + + mutable float m_mainFactor = -1.f; + mutable int m_indeterminateCounter = 0; + mutable int m_curThreadLines = 0; + mutable int m_curProgLines = 0; + mutable int m_latestThread = -1; + mutable bool m_running = false; + mutable bool m_dirty = false; + mutable bool m_mainIndeterminate = false; + uint64_t m_lastLogCounter = 0; + void LogProc(); + void DoPrint(); + void DrawIndeterminateBar(); + void MoveCursorUp(int n); + +public: + MultiProgressPrinter(bool activate = false); + ~MultiProgressPrinter(); + void print(const hecl::SystemChar* message, const hecl::SystemChar* submessage, float factor = -1.f, + int threadIdx = 0) const; + void setMainFactor(float factor) const; + void setMainIndeterminate(bool indeterminate) const; + void startNewLine() const; + void flush() const; +}; + +} // namespace hecl diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp new file mode 100644 index 000000000..250722d4b --- /dev/null +++ b/hecl/include/hecl/Runtime.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +#include "hecl/SystemChar.hpp" + +namespace hecl { +struct HMDLMeta; + +namespace Runtime { + +/** + * @brief Per-platform file store resolution + */ +class FileStoreManager { + SystemString m_domain; + SystemString m_storeRoot; + +public: + FileStoreManager(SystemStringView domain); + SystemStringView getDomain() const { return m_domain; } + /** + * @brief Returns the full path to the file store, including domain + * @return Full path to store e.g /home/foo/.hecl/bar + */ + SystemStringView getStoreRoot() const { return m_storeRoot; } +}; + +} // namespace Runtime +} // namespace hecl diff --git a/hecl/include/hecl/SteamFinder.hpp b/hecl/include/hecl/SteamFinder.hpp new file mode 100644 index 000000000..501ec3781 --- /dev/null +++ b/hecl/include/hecl/SteamFinder.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "hecl/SystemChar.hpp" + +namespace hecl { + +hecl::SystemString FindCommonSteamApp(const hecl::SystemChar* name); + +} diff --git a/hecl/include/hecl/SystemChar.hpp b/hecl/include/hecl/SystemChar.hpp new file mode 100644 index 000000000..124c28332 --- /dev/null +++ b/hecl/include/hecl/SystemChar.hpp @@ -0,0 +1,57 @@ +#pragma once + +#ifndef _WIN32 +#include +#include +#include +#else +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#endif +#include +#include +#include +#include + +namespace hecl { + +#if _WIN32 && UNICODE +#define HECL_UCS2 1 +#endif + +#if HECL_UCS2 +typedef wchar_t SystemChar; +typedef std::wstring SystemString; +typedef std::wstring_view SystemStringView; +static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); } +static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); } +#ifndef _SYS_STR +#define _SYS_STR(val) L##val +#endif +typedef struct _stat Sstat; +#else +typedef char SystemChar; +typedef std::string SystemString; +typedef std::string_view SystemStringView; +static inline void ToLower(SystemString& str) { + std::transform(str.begin(), str.end(), str.begin(), + [](SystemChar c) { return std::tolower(static_cast(c)); }); +} +static inline void ToUpper(SystemString& str) { + std::transform(str.begin(), str.end(), str.begin(), + [](SystemChar c) { return std::toupper(static_cast(c)); }); +} +#ifndef _SYS_STR +#define _SYS_STR(val) val +#endif +typedef struct stat Sstat; +#endif + +constexpr size_t StrLen(const SystemChar* str) { return std::char_traits::length(str); } + +} // namespace hecl diff --git a/hecl/include/hecl/TypedVariant.hpp b/hecl/include/hecl/TypedVariant.hpp new file mode 100644 index 000000000..d548fe319 --- /dev/null +++ b/hecl/include/hecl/TypedVariant.hpp @@ -0,0 +1,268 @@ +#pragma once + +#include +#include +#include + +#include + +/* + * The TypedVariant system is a type-safe union implementation capable of selecting + * a participating field type based on an enumeration constant. As an extension of + * std::variant, the usage pattern is similar to that of std::visit. A key difference + * with TypedVariant is the monostate is implicitly supplied as the first argument. + * The monostate will cause the visit implementation to function as a no-op, returning + * a specified default value. + */ + +/* Example user code: + +enum class ChunkType { + Invalid = 0, + TYP1 = SBIG('TYP1'), + TYP2 = SBIG('TYP2'), + TYP3 = SBIG('TYP3'), +}; + +struct TYP1 : TypedRecord { + static void PrintMe() { std::cout << "TYP1" << std::endl; } +}; +struct TYP2 : TypedRecord { + static void PrintMe() { std::cout << "TYP2" << std::endl; } +}; +struct TYP3 : TypedRecord { + static void PrintMe() { std::cout << "TYP3" << std::endl; } +}; + +using ChunkVariant = TypedVariant; + +int main(int argc, char** argv) { + volatile ChunkType tp = ChunkType::TYP2; + auto var = ChunkVariant::Build(tp); + var.visit([](auto& arg) { arg.PrintMe(); }); + return 0; +} + + */ + +namespace hecl { + +template +struct TypedRecord { + using TypedType = std::integral_constant; + static constexpr auto variant_type() { return _Type; } + static constexpr bool is_monostate() { return false; } +}; + +template +struct TypedMonostate : TypedRecord<_Enum(0)> { + static constexpr bool is_monostate() { return true; } + bool operator==(const TypedMonostate& other) const { return true; } + bool operator!=(const TypedMonostate& other) const { return false; } +}; + +template +class _TypedVariant : public std::variant<_Types...> { +public: + using base = std::variant<_Types...>; + using EnumType = typename std::variant_alternative_t<0, std::variant<_Types...>>::TypedType::value_type; + +private: + template + struct _Match; + + template + struct _Match<_Type, std::variant<_First, _Rest...>> + : _Match<_Type, std::variant<_Rest...>> {}; + + template + struct _Match> + { using type = _First; }; + +public: + template + using Match = typename _Match, std::variant<_Types...>>::type; + +private: + template + struct _Builder { + template + static constexpr _TypedVariant _Build(EnumType tp, _Args&&... args) { + //static_assert(std::is_constructible_v<_First, _Args...>, + // "All variant types must be constructible with the same parameters."); + if (_First::TypedType::value == tp) { + if constexpr (std::is_constructible_v<_First, _Args...>) { + return {_First(std::forward<_Args>(args)...)}; + } else { + assert(false && "Variant not constructible with supplied args."); + return {}; + } + } + else if constexpr (sizeof...(_Rest) > 0) + return _Builder<_Rest...>::template _Build<_Args...>(tp, std::forward<_Args>(args)...); + return {}; + } + template + static constexpr _TypedVariant _BuildSkip(EnumType tp, _Args&&... args) { + /* This prevents selecting the monostate explicitly (so constructor arguments aren't passed) */ + if constexpr (sizeof...(_Rest) > 0) + return _Builder<_Rest...>::template _Build<_Args...>(tp, std::forward<_Args>(args)...); + return {}; + } + }; + +public: + template + static constexpr _TypedVariant Build(EnumType tp, _Args&&... args) { + return _Builder<_Types...>::template _BuildSkip<_Args...>(tp, std::forward<_Args>(args)...); + } + + template + constexpr auto visit(_Visitor&& visitor, _Return&& def) { + return std::visit([&](T0& arg) { + using T = std::decay_t; + if constexpr (!T::is_monostate()) + return visitor(arg); + return def; + }, static_cast(*this)); + } + + template + constexpr void visit(_Visitor&& visitor) { + std::visit([&](T0& arg) { + using T = std::decay_t; + if constexpr (!T::is_monostate()) + visitor(arg); + }, static_cast(*this)); + } + + template + constexpr auto visit(_Visitor&& visitor, _Return&& def) const { + return std::visit([&](const T0& arg) { + using T = std::decay_t; + if constexpr (!T::is_monostate()) + return visitor(arg); + return def; + }, static_cast(*this)); + } + + template + constexpr void visit(_Visitor&& visitor) const { + std::visit([&](const T0& arg) { + using T = std::decay_t; + if constexpr (!T::is_monostate()) + visitor(arg); + }, static_cast(*this)); + } + + template + constexpr T& get() { return std::get(*this); } + + template + constexpr const T& get() const { return std::get(*this); } + + template + constexpr std::add_pointer_t get_if() noexcept { return std::get_if(this); } + + template + constexpr std::add_pointer_t get_if() const noexcept { return std::get_if(this); } + + template + constexpr bool holds_alternative() const noexcept { return std::holds_alternative(*this); } + + constexpr EnumType variant_type() const { + return std::visit([](const auto& arg) { + return arg.variant_type(); + }, static_cast(*this)); + } + + constexpr explicit operator bool() const noexcept { + return !std::holds_alternative>>(*this); + } +}; + +template +using TypedVariant = _TypedVariant>::TypedType::value_type>, _Types...>; + +/* DNA support below here */ + +template +struct TypedRecordBigDNA : BigDNA, TypedRecord<_Type> {}; + +template +struct TypedVariantBigDNA : BigDNA, TypedVariant<_Types...> { + AT_DECL_EXPLICIT_DNA_YAML + template + static constexpr TypedVariantBigDNA Build(typename TypedVariant<_Types...>::EnumType tp, _Args&&... args) { + return TypedVariantBigDNA(TypedVariant<_Types...>::Build(tp, std::forward<_Args>(args)...)); + } + TypedVariantBigDNA() = default; +private: + TypedVariantBigDNA(TypedVariant<_Types...> var) : TypedVariant<_Types...>(std::move(var)) {} +}; + +#define AT_SPECIALIZE_TYPED_VARIANT_BIGDNA(...) \ + template <> \ + template <> \ + inline void hecl::TypedVariantBigDNA<__VA_ARGS__>::Enumerate::Read>( \ + typename Read::StreamT & r) { \ + hecl::TypedVariant<__VA_ARGS__>::EnumType variant_type = {}; \ + Do::Read>(athena::io::PropId("variant_type"sv), variant_type, r); \ + static_cast&>(*this) = Build(variant_type); \ + visit([&](auto& var) { var.read(r); }); \ + } \ + \ + template <> \ + template <> \ + inline void hecl::TypedVariantBigDNA<__VA_ARGS__>::Enumerate::Write>( \ + typename Write::StreamT & w) { \ + visit([&](auto& var) { \ + using T = std::decay_t; \ + hecl::TypedVariant<__VA_ARGS__>::EnumType variant_type = T::variant_type(); \ + Do::Write>(athena::io::PropId("variant_type"sv), variant_type, w); \ + var.write(w); \ + }); \ + } \ + \ + template <> \ + template <> \ + inline void hecl::TypedVariantBigDNA<__VA_ARGS__>::Enumerate::BinarySize>( \ + typename BinarySize::StreamT & sz) { \ + visit([&](auto& var) { \ + using T = std::decay_t; \ + hecl::TypedVariant<__VA_ARGS__>::EnumType variant_type = T::variant_type(); \ + Do::BinarySize>(athena::io::PropId("variant_type"sv), variant_type, sz); \ + var.binarySize(sz); \ + }); \ + } \ + template <> \ + inline std::string_view hecl::TypedVariantBigDNA<__VA_ARGS__>::DNAType() { \ + return "hecl::TypedVariantBigDNA<" #__VA_ARGS__ ">"sv; \ + } + +#define AT_SPECIALIZE_TYPED_VARIANT_BIGDNA_YAML(...) \ + AT_SPECIALIZE_TYPED_VARIANT_BIGDNA(__VA_ARGS__) \ + template <> \ + template <> \ + inline void hecl::TypedVariantBigDNA<__VA_ARGS__>::Enumerate::ReadYaml>( \ + typename ReadYaml::StreamT & r) { \ + hecl::TypedVariant<__VA_ARGS__>::EnumType variant_type = {}; \ + Do::ReadYaml>(athena::io::PropId("variant_type"sv), variant_type, r); \ + static_cast&>(*this) = Build(variant_type); \ + visit([&](auto& var) { var.read(r); }); \ + } \ + \ + template <> \ + template <> \ + inline void hecl::TypedVariantBigDNA<__VA_ARGS__>::Enumerate::WriteYaml>( \ + typename WriteYaml::StreamT & w) { \ + visit([&](auto& var) { \ + using T = std::decay_t; \ + hecl::TypedVariant<__VA_ARGS__>::EnumType variant_type = T::variant_type(); \ + Do::WriteYaml>(athena::io::PropId("variant_type"sv), variant_type, w); \ + var.write(w); \ + }); \ + } + +} diff --git a/hecl/include/hecl/hecl.hpp b/hecl/include/hecl/hecl.hpp new file mode 100644 index 000000000..6b54fc8a2 --- /dev/null +++ b/hecl/include/hecl/hecl.hpp @@ -0,0 +1,1396 @@ +#pragma once + +#ifndef _WIN32 +#include +#include +#include +#include +#include +#include +#include +#include +#if __linux__ || __APPLE__ +extern "C" int rep_closefrom(int lower); +#define closefrom rep_closefrom +#endif +#else +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#include +#include +#include +#include "winsupport.hpp" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "logvisor/logvisor.hpp" +#include "athena/Global.hpp" +#include "hecl-xxhash.h" +#include "SystemChar.hpp" +#include "FourCC.hpp" + +#if defined(__has_feature) +#if __has_feature(thread_sanitizer) +#define HECL_NO_SANITIZE_THREAD __attribute__((no_sanitize("thread"))) +#endif +#endif +#ifndef HECL_NO_SANITIZE_THREAD +#define HECL_NO_SANITIZE_THREAD +#endif + +namespace hecl { +namespace Database { +class Project; +struct DataSpecEntry; +} // namespace Database + +namespace blender { +enum class BlendType { None, Mesh, ColMesh, Armature, Actor, Area, + World, MapArea, MapUniverse, Frame, PathMesh }; + +class ANIMOutStream; +class Connection; +class DataStream; +class PyOutStream; +class Token; + +struct Action; +struct Actor; +struct Armature; +struct Bone; +struct ColMesh; +struct Light; +struct MapArea; +struct MapUniverse; +struct Material; +struct Matrix3f; +struct Matrix4f; +struct Mesh; +struct PathMesh; +struct PoolSkinIndex; +struct World; + +extern class Token SharedBlenderToken; +} // namespace blender + +extern unsigned VerbosityLevel; +extern bool GuiMode; +extern logvisor::Module LogModule; + +std::string WideToUTF8(std::wstring_view src); +std::string Char16ToUTF8(std::u16string_view src); +std::wstring Char16ToWide(std::u16string_view src); +std::wstring UTF8ToWide(std::string_view src); +std::u16string UTF8ToChar16(std::string_view src); + +/* humanize_number port from FreeBSD's libutil */ +enum class HNFlags { None = 0, Decimal = 0x01, NoSpace = 0x02, B = 0x04, Divisor1000 = 0x08, IECPrefixes = 0x10 }; +ENABLE_BITWISE_ENUM(HNFlags) + +enum class HNScale { None = 0, AutoScale = 0x20 }; +ENABLE_BITWISE_ENUM(HNScale) + +std::string HumanizeNumber(int64_t quotient, size_t len, const char* suffix, int scale, HNFlags flags); + +#if HECL_UCS2 +class SystemUTF8Conv { + std::string m_utf8; + +public: + explicit SystemUTF8Conv(SystemStringView str) : m_utf8(WideToUTF8(str)) {} + + std::string_view str() const { return m_utf8; } + const char* c_str() const { return m_utf8.c_str(); } + + friend std::string operator+(const SystemUTF8Conv& lhs, std::string_view rhs) { return lhs.m_utf8 + rhs.data(); } + friend std::string operator+(std::string_view lhs, const SystemUTF8Conv& rhs) { + return std::string(lhs).append(rhs.m_utf8); + } +}; + +class SystemStringConv { + std::wstring m_sys; + +public: + explicit SystemStringConv(std::string_view str) : m_sys(UTF8ToWide(str)) {} + + SystemStringView sys_str() const { return m_sys; } + const SystemChar* c_str() const { return m_sys.c_str(); } + + friend std::wstring operator+(const SystemStringConv& lhs, const std::wstring_view rhs) { + return lhs.m_sys + rhs.data(); + } + friend std::wstring operator+(std::wstring_view lhs, const SystemStringConv& rhs) { + return std::wstring(lhs).append(rhs.m_sys); + } +}; + +inline hecl::SystemString UTF8StringToSysString(std::string_view src) { return UTF8ToWide(src); } +#else +class SystemUTF8Conv { + std::string_view m_utf8; + +public: + explicit SystemUTF8Conv(SystemStringView str) : m_utf8(str) {} + + std::string_view str() const { return m_utf8; } + const char* c_str() const { return m_utf8.data(); } + + friend std::string operator+(const SystemUTF8Conv& lhs, std::string_view rhs) { + return std::string(lhs.m_utf8).append(rhs); + } + friend std::string operator+(std::string_view lhs, const SystemUTF8Conv& rhs) { + return std::string(lhs).append(rhs.m_utf8); + } +}; + +class SystemStringConv { + std::string_view m_sys; + +public: + explicit SystemStringConv(std::string_view str) : m_sys(str) {} + + SystemStringView sys_str() const { return m_sys; } + const SystemChar* c_str() const { return m_sys.data(); } + + friend std::string operator+(const SystemStringConv& lhs, std::string_view rhs) { + return std::string(lhs.m_sys).append(rhs); + } + friend std::string operator+(std::string_view lhs, const SystemStringConv& rhs) { + return std::string(lhs).append(rhs.m_sys); + } +}; + +inline hecl::SystemString UTF8StringToSysString(std::string src) { return src; } +#endif + +void SanitizePath(std::string& path); +void SanitizePath(std::wstring& path); + +inline void Unlink(const SystemChar* file) { +#if _WIN32 + _wunlink(file); +#else + unlink(file); +#endif +} + +inline void MakeDir(const char* dir) { +#if _WIN32 + HRESULT err; + if (!CreateDirectoryA(dir, NULL)) + if ((err = GetLastError()) != ERROR_ALREADY_EXISTS) + LogModule.report(logvisor::Fatal, FMT_STRING("MakeDir({})"), dir); +#else + if (mkdir(dir, 0755)) + if (errno != EEXIST) + LogModule.report(logvisor::Fatal, FMT_STRING("MakeDir({}): {}"), dir, strerror(errno)); +#endif +} + +#if _WIN32 +inline void MakeDir(const wchar_t* dir) { + HRESULT err; + if (!CreateDirectoryW(dir, NULL)) + if ((err = GetLastError()) != ERROR_ALREADY_EXISTS) + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("MakeDir({})")), dir); +} +#endif + +int RecursiveMakeDir(const SystemChar* dir); + +inline const SystemChar* GetEnv(const SystemChar* name) { +#if WINDOWS_STORE + return nullptr; +#else +#if HECL_UCS2 + return _wgetenv(name); +#else + return getenv(name); +#endif +#endif +} + +inline SystemChar* Getcwd(SystemChar* buf, int maxlen) { +#if HECL_UCS2 + return _wgetcwd(buf, maxlen); +#else + return getcwd(buf, maxlen); +#endif +} + +SystemString GetcwdStr(); + +inline bool IsAbsolute(SystemStringView path) { +#if _WIN32 + if (path.size() && (path[0] == _SYS_STR('\\') || path[0] == _SYS_STR('/'))) + return true; + if (path.size() >= 2 && iswalpha(path[0]) && path[1] == _SYS_STR(':')) + return true; +#else + if (path.size() && path[0] == _SYS_STR('/')) + return true; +#endif + return false; +} + +const SystemChar* GetTmpDir(); + +#if !WINDOWS_STORE +int RunProcess(const SystemChar* path, const SystemChar* const args[]); +#endif + +enum class FileLockType { None = 0, Read, Write }; +inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLockType lock = FileLockType::None) { +#if HECL_UCS2 + FILE* fp = _wfopen(path, mode); + if (!fp) + return nullptr; +#else + FILE* fp = fopen(path, mode); + if (!fp) + return nullptr; +#endif + + if (lock != FileLockType::None) { +#if _WIN32 + OVERLAPPED ov = {}; + LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == FileLockType::Write) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, + &ov); +#elif !defined(__SWITCH__) + if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB)) + LogModule.report(logvisor::Error, FMT_STRING("flock {}: {}"), path, strerror(errno)); +#endif + } + + return fp; +} + +struct UniqueFileDeleter { + void operator()(FILE* file) const noexcept { std::fclose(file); } +}; +using UniqueFilePtr = std::unique_ptr; + +inline UniqueFilePtr FopenUnique(const SystemChar* path, const SystemChar* mode, + FileLockType lock = FileLockType::None) { + return UniqueFilePtr{Fopen(path, mode, lock)}; +} + +inline int FSeek(FILE* fp, int64_t offset, int whence) { +#if _WIN32 + return _fseeki64(fp, offset, whence); +#elif __APPLE__ || __FreeBSD__ + return fseeko(fp, offset, whence); +#else + return fseeko64(fp, offset, whence); +#endif +} + +inline int64_t FTell(FILE* fp) { +#if _WIN32 + return _ftelli64(fp); +#elif __APPLE__ || __FreeBSD__ + return ftello(fp); +#else + return ftello64(fp); +#endif +} + +inline int Rename(const SystemChar* oldpath, const SystemChar* newpath) { +#if HECL_UCS2 + // return _wrename(oldpath, newpath); + return MoveFileExW(oldpath, newpath, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) == 0; +#else + return rename(oldpath, newpath); +#endif +} + +inline int Stat(const SystemChar* path, Sstat* statOut) { +#if HECL_UCS2 + size_t pos; + for (pos = 0; pos < 3 && path[pos] != L'\0'; ++pos) {} + if (pos == 2 && path[1] == L':') { + SystemChar fixPath[4] = {path[0], L':', L'/', L'\0'}; + return _wstat(fixPath, statOut); + } + return _wstat(path, statOut); +#else + return stat(path, statOut); +#endif +} + +inline int StrCmp(const SystemChar* str1, const SystemChar* str2) { + if (!str1 || !str2) + return str1 != str2; +#if HECL_UCS2 + return wcscmp(str1, str2); +#else + return strcmp(str1, str2); +#endif +} + +inline int StrNCmp(const SystemChar* str1, const SystemChar* str2, size_t count) { + if (!str1 || !str2) + return str1 != str2; + + return std::char_traits::compare(str1, str2, count); +} + +inline int StrCaseCmp(const SystemChar* str1, const SystemChar* str2) { + if (!str1 || !str2) + return str1 != str2; +#if HECL_UCS2 + return _wcsicmp(str1, str2); +#else + return strcasecmp(str1, str2); +#endif +} + +inline unsigned long StrToUl(const SystemChar* str, SystemChar** endPtr, int base) { +#if HECL_UCS2 + return wcstoul(str, endPtr, base); +#else + return strtoul(str, endPtr, base); +#endif +} + +inline bool CheckFreeSpace(const SystemChar* path, size_t reqSz) { +#if _WIN32 + ULARGE_INTEGER freeBytes; + wchar_t buf[1024]; + wchar_t* end; + DWORD ret = GetFullPathNameW(path, 1024, buf, &end); + if (!ret || ret > 1024) + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("GetFullPathNameW {}")), path); + if (end) + end[0] = L'\0'; + if (!GetDiskFreeSpaceExW(buf, &freeBytes, nullptr, nullptr)) + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("GetDiskFreeSpaceExW {}: {}")), path, GetLastError()); + return reqSz < freeBytes.QuadPart; +#else + struct statvfs svfs; + if (statvfs(path, &svfs)) + LogModule.report(logvisor::Fatal, FMT_STRING("statvfs {}: {}"), path, strerror(errno)); + return reqSz < svfs.f_frsize * svfs.f_bavail; +#endif +} + +inline bool PathRelative(const SystemChar* path) { + if (!path || !path[0]) + return false; +#if _WIN32 && !WINDOWS_STORE + return PathIsRelative(path); +#else + return path[0] != '/'; +#endif +} + +inline int ConsoleWidth(bool* ok = nullptr) { + int retval = 80; +#if _WIN32 +#if !WINDOWS_STORE + CONSOLE_SCREEN_BUFFER_INFO info; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); + retval = info.dwSize.X; + if (ok) + *ok = true; +#endif +#elif !defined(__SWITCH__) + if (ok) + *ok = false; + struct winsize w; + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) { + retval = w.ws_col; + if (ok) + *ok = true; + } +#endif + if (retval < 10) + return 10; + return retval; +} + +class MultiProgressPrinter; +class ProjectRootPath; + +using SystemRegex = std::basic_regex; +using SystemRegexIterator = std::regex_iterator; +using SystemRegexMatch = std::match_results; +using SystemViewRegexMatch = std::match_results; +using SystemRegexTokenIterator = std::regex_token_iterator; + +/** + * @brief Hash representation used for all storable and comparable objects + * + * Hashes are used within HECL to avoid redundant storage of objects; + * providing a rapid mechanism to compare for equality. + */ +class Hash { +protected: + uint64_t hash = 0; + +public: + constexpr Hash() noexcept = default; + constexpr Hash(const Hash&) noexcept = default; + constexpr Hash(Hash&&) noexcept = default; + constexpr Hash(uint64_t hashin) noexcept : hash(hashin) {} + explicit Hash(const void* buf, size_t len) noexcept : hash(XXH64(buf, len, 0)) {} + explicit Hash(std::string_view str) noexcept : hash(XXH64(str.data(), str.size(), 0)) {} + explicit Hash(std::wstring_view str) noexcept : hash(XXH64(str.data(), str.size() * 2, 0)) {} + + constexpr uint32_t val32() const noexcept { return uint32_t(hash) ^ uint32_t(hash >> 32); } + constexpr uint64_t val64() const noexcept { return uint64_t(hash); } + constexpr size_t valSizeT() const noexcept { return size_t(hash); } + template + constexpr T valT() const noexcept; + + constexpr Hash& operator=(const Hash& other) noexcept = default; + constexpr Hash& operator=(Hash&& other) noexcept = default; + constexpr bool operator==(const Hash& other) const noexcept { return hash == other.hash; } + constexpr bool operator!=(const Hash& other) const noexcept { return !operator==(other); } + constexpr bool operator<(const Hash& other) const noexcept { return hash < other.hash; } + constexpr bool operator>(const Hash& other) const noexcept { return hash > other.hash; } + constexpr bool operator<=(const Hash& other) const noexcept { return hash <= other.hash; } + constexpr bool operator>=(const Hash& other) const noexcept { return hash >= other.hash; } + constexpr explicit operator bool() const noexcept { return hash != 0; } +}; +template <> +constexpr uint32_t Hash::valT() const noexcept { + return val32(); +} +template <> +constexpr uint64_t Hash::valT() const noexcept { + return val64(); +} + +/** + * @brief Timestamp representation used for comparing modtimes of cooked resources + */ +class Time final { + time_t ts; + +public: + Time() : ts(std::time(nullptr)) {} + constexpr Time(time_t ti) noexcept : ts{ti} {} + constexpr Time(const Time& other) noexcept : ts{other.ts} {} + [[nodiscard]] constexpr time_t getTs() const { return ts; } + constexpr Time& operator=(const Time& other) noexcept { + ts = other.ts; + return *this; + } + [[nodiscard]] constexpr bool operator==(const Time& other) const noexcept { return ts == other.ts; } + [[nodiscard]] constexpr bool operator!=(const Time& other) const noexcept { return ts != other.ts; } + [[nodiscard]] constexpr bool operator<(const Time& other) const noexcept { return ts < other.ts; } + [[nodiscard]] constexpr bool operator>(const Time& other) const noexcept { return ts > other.ts; } + [[nodiscard]] constexpr bool operator<=(const Time& other) const noexcept { return ts <= other.ts; } + [[nodiscard]] constexpr bool operator>=(const Time& other) const noexcept { return ts >= other.ts; } +}; + +/** + * @brief Case-insensitive comparator for std::map sorting + */ +struct CaseInsensitiveCompare { + // Allow heterogenous lookup with maps that use this comparator. + using is_transparent = void; + + bool operator()(std::string_view lhs, std::string_view rhs) const { + return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), [](char lhs, char rhs) { + return std::tolower(static_cast(lhs)) < std::tolower(static_cast(rhs)); + }); + } + + bool operator()(std::wstring_view lhs, std::wstring_view rhs) const { + return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), [](wchar_t lhs, wchar_t rhs) { + return std::towlower(lhs) < std::towlower(rhs); + }); + } +}; + +/** + * @brief Directory traversal tool for accessing sorted directory entries + */ +class DirectoryEnumerator { +public: + enum class Mode { Native, DirsSorted, FilesSorted, DirsThenFilesSorted }; + struct Entry { + hecl::SystemString m_path; + hecl::SystemString m_name; + size_t m_fileSz; + bool m_isDir; + + Entry(hecl::SystemString path, const hecl::SystemChar* name, size_t sz, bool isDir) + : m_path(std::move(path)), m_name(name), m_fileSz(sz), m_isDir(isDir) {} + }; + +private: + std::vector m_entries; + +public: + DirectoryEnumerator(SystemStringView path, Mode mode = Mode::DirsThenFilesSorted, bool sizeSort = false, + bool reverse = false, bool noHidden = false); + + explicit operator bool() const { return m_entries.size() != 0; } + size_t size() const { return m_entries.size(); } + std::vector::const_iterator begin() const { return m_entries.cbegin(); } + std::vector::const_iterator end() const { return m_entries.cend(); } +}; + +/** + * @brief Build list of common OS-specific directories + */ +std::vector> GetSystemLocations(); + +/** + * @brief Special ProjectRootPath class for opening Database::Project instances + * + * Constructing a ProjectPath requires supplying a ProjectRootPath to consistently + * resolve canonicalized relative paths. + */ +class ProjectRootPath { + SystemString m_projRoot; + Hash m_hash = 0; + +public: + /** + * @brief Empty constructor + * + * Used to preallocate ProjectPath for later population using assign() + */ + ProjectRootPath() = default; + + /** + * @brief Tests for non-empty project root path + */ + explicit operator bool() const { return m_projRoot.size() != 0; } + + /** + * @brief Construct a representation of a project root path + * @param path valid filesystem-path (relative or absolute) to project root + */ + ProjectRootPath(SystemStringView path) : m_projRoot(path) { + SanitizePath(m_projRoot); + m_hash = Hash(m_projRoot); + } + + /** + * @brief Access fully-canonicalized absolute path + * @return Absolute path reference + */ + SystemStringView getAbsolutePath() const { return m_projRoot; } + + /** + * @brief Make absolute path project relative + * @param absPath Absolute path + * @return SystemString of path relative to project root + */ + SystemString getProjectRelativeFromAbsolute(SystemStringView absPath) const { + if (absPath.size() > m_projRoot.size()) { + SystemString absPathForward(absPath); + for (SystemChar& ch : absPathForward) + if (ch == _SYS_STR('\\')) + ch = _SYS_STR('/'); + if (!absPathForward.compare(0, m_projRoot.size(), m_projRoot)) { + auto beginIt = absPathForward.cbegin() + m_projRoot.size(); + while (*beginIt == _SYS_STR('/')) + ++beginIt; + return SystemString(beginIt, absPathForward.cend()); + } + } + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to resolve '{}' as project relative '{}'")), absPath, + m_projRoot); + return SystemString(); + } + + /** + * @brief Create directory at path + * + * Fatal log report is issued if directory is not able to be created or doesn't already exist. + * If directory already exists, no action taken. + */ + void makeDir() const { MakeDir(m_projRoot.c_str()); } + + /** + * @brief HECL-specific xxhash + * @return unique hash value + */ + Hash hash() const noexcept { return m_hash; } + bool operator==(const ProjectRootPath& other) const noexcept { return m_hash == other.m_hash; } + bool operator!=(const ProjectRootPath& other) const noexcept { return !operator==(other); } + + /** + * @brief Obtain c-string of final path component + * @return Final component c-string (may be empty) + */ + SystemStringView getLastComponent() const { + size_t pos = m_projRoot.rfind(_SYS_STR('/')); + if (pos == SystemString::npos) + return {}; + return {m_projRoot.c_str() + pos + 1, size_t(m_projRoot.size() - pos - 1)}; + } +}; + +/** + * @brief Canonicalized project path representation using POSIX conventions + * + * HECL uses POSIX-style paths (with '/' separator) and directory tokens + * ('.','..') to resolve files within a project. The database internally + * uses this representation to track working files. + * + * This class provides a convenient way to resolve paths relative to the + * project root. Part of this representation involves resolving symbolic + * links to regular file/directory paths and determining its type. + * + * NOTE THAT PROJECT PATHS ARE TREATED AS CASE SENSITIVE!! + */ +class ProjectPath { + Database::Project* m_proj = nullptr; + SystemString m_absPath; + SystemString m_relPath; + SystemString m_auxInfo; + Hash m_hash = 0; +#if HECL_UCS2 + std::string m_utf8AbsPath; + std::string m_utf8RelPath; + std::string m_utf8AuxInfo; +#endif + void ComputeHash() { +#if HECL_UCS2 + m_utf8AbsPath = WideToUTF8(m_absPath); + m_utf8RelPath = WideToUTF8(m_relPath); + m_utf8AuxInfo = WideToUTF8(m_auxInfo); + if (m_utf8AuxInfo.size()) + m_hash = Hash(m_utf8RelPath + '|' + m_utf8AuxInfo); + else + m_hash = Hash(m_utf8RelPath); +#else + if (m_auxInfo.size()) + m_hash = Hash(m_relPath + '|' + m_auxInfo); + else + m_hash = Hash(m_relPath); +#endif + } + +public: + /** + * @brief Empty constructor + * + * Used to preallocate ProjectPath for later population using assign() + */ + ProjectPath() = default; + + /** + * @brief Tests for non-empty project path + */ + explicit operator bool() const { return m_absPath.size() != 0; } + + /** + * @brief Clears path + */ + void clear() { + m_proj = nullptr; + m_absPath.clear(); + m_relPath.clear(); + m_hash = 0; +#if HECL_UCS2 + m_utf8AbsPath.clear(); + m_utf8RelPath.clear(); +#endif + } + + /** + * @brief Construct a project subpath representation within a project's root path + * @param project previously constructed Project to use root path of + * @param path valid filesystem-path (relative or absolute) to subpath + */ + ProjectPath(Database::Project& project, SystemStringView path) { assign(project, path); } + void assign(Database::Project& project, SystemStringView path); + +#if HECL_UCS2 + ProjectPath(Database::Project& project, std::string_view path) { assign(project, path); } + void assign(Database::Project& project, std::string_view path); +#endif + + /** + * @brief Construct a project subpath representation within another subpath + * @param parentPath previously constructed ProjectPath which ultimately connects to a ProjectRootPath + * @param path valid filesystem-path (relative or absolute) to subpath + */ + ProjectPath(const ProjectPath& parentPath, SystemStringView path) { assign(parentPath, path); } + void assign(const ProjectPath& parentPath, SystemStringView path); + +#if HECL_UCS2 + ProjectPath(const ProjectPath& parentPath, std::string_view path) { assign(parentPath, path); } + void assign(const ProjectPath& parentPath, std::string_view path); +#endif + + /** + * @brief Determine if ProjectPath represents project root directory + * @return true if project root directory + */ + bool isRoot() const { return m_relPath.empty(); } + + /** + * @brief Return new ProjectPath with extension added + * @param ext file extension to add (nullptr may be passed to remove the extension) + * @param replace remove existing extension (if any) before appending new extension + * @return new path with extension + */ + ProjectPath getWithExtension(const SystemChar* ext, bool replace = false) const; + + /** + * @brief Access fully-canonicalized absolute path + * @return Absolute path reference + */ + SystemStringView getAbsolutePath() const { return m_absPath; } + + /** + * @brief Access fully-canonicalized project-relative path + * @return Relative pointer to within absolute-path or "." for project root-directory (use isRoot to detect) + */ + SystemStringView getRelativePath() const { + if (m_relPath.size()) + return m_relPath; + static const SystemString dot = _SYS_STR("."); + return dot; + } + + /** + * @brief Obtain cooked equivalent of this ProjectPath + * @param spec DataSpec to get path against + * @return Cooked representation path + */ + ProjectPath getCookedPath(const Database::DataSpecEntry& spec) const; + + /** + * @brief Obtain path of parent entity (a directory for file paths) + * @return Parent Path + * + * This will not resolve outside the project root (error in that case) + */ + ProjectPath getParentPath() const { + if (m_relPath == _SYS_STR(".")) + LogModule.report(logvisor::Fatal, FMT_STRING("attempted to resolve parent of root project path")); + size_t pos = m_relPath.rfind(_SYS_STR('/')); + if (pos == SystemString::npos) + return ProjectPath(*m_proj, _SYS_STR("")); + return ProjectPath(*m_proj, SystemString(m_relPath.begin(), m_relPath.begin() + pos)); + } + + /** + * @brief Obtain c-string of final path component (stored within relative path) + * @return Final component c-string (may be empty) + */ + SystemStringView getLastComponent() const { + size_t pos = m_relPath.rfind(_SYS_STR('/')); + if (pos == SystemString::npos) + return m_relPath; + return {m_relPath.c_str() + pos + 1, m_relPath.size() - pos - 1}; + } + std::string_view getLastComponentUTF8() const { + size_t pos = m_relPath.rfind(_SYS_STR('/')); +#if HECL_UCS2 + if (pos == SystemString::npos) + return m_utf8RelPath; + return {m_utf8RelPath.c_str() + pos + 1, size_t(m_utf8RelPath.size() - pos - 1)}; +#else + if (pos == SystemString::npos) + return m_relPath; + return {m_relPath.c_str() + pos + 1, size_t(m_relPath.size() - pos - 1)}; +#endif + } + + /** + * @brief Obtain c-string of extension of final path component (stored within relative path) + * @return Final component extension c-string (may be empty) + */ + SystemStringView getLastComponentExt() const { + SystemStringView lastCompOrig = getLastComponent().data(); + const SystemChar* end = lastCompOrig.data() + lastCompOrig.size(); + const SystemChar* lastComp = end; + while (lastComp != lastCompOrig.data()) { + if (*lastComp == _SYS_STR('.')) + return {lastComp + 1, size_t(end - lastComp - 1)}; + --lastComp; + } + return {}; + } + + /** + * @brief Build vector of project-relative directory/file components + * @return Vector of path components + */ + std::vector getPathComponents() const { + std::vector ret; + if (m_relPath.empty()) + return ret; + auto it = m_relPath.cbegin(); + if (*it == _SYS_STR('/')) { + ret.push_back(_SYS_STR("/")); + ++it; + } + hecl::SystemString comp; + for (; it != m_relPath.cend(); ++it) { + if (*it == _SYS_STR('/')) { + if (comp.empty()) + continue; + ret.push_back(std::move(comp)); + comp.clear(); + continue; + } + comp += *it; + } + if (comp.size()) + ret.push_back(std::move(comp)); + return ret; + } + + /** + * @brief Build vector of project-relative directory/file components + * @return Vector of path components encoded as UTF8 + */ + std::vector getPathComponentsUTF8() const { +#if HECL_UCS2 + const std::string& relPath = m_utf8RelPath; +#else + const std::string& relPath = m_relPath; +#endif + std::vector ret; + if (relPath.empty()) + return ret; + auto it = relPath.cbegin(); + if (*it == '/') { + ret.push_back("/"); + ++it; + } + std::string comp; + for (; it != relPath.cend(); ++it) { + if (*it == '/') { + if (comp.empty()) + continue; + ret.push_back(std::move(comp)); + comp.clear(); + continue; + } + comp += *it; + } + if (comp.size()) + ret.push_back(std::move(comp)); + return ret; + } + + /** + * @brief Access fully-canonicalized absolute path in UTF-8 + * @return Absolute path reference + */ + std::string_view getAbsolutePathUTF8() const { +#if HECL_UCS2 + return m_utf8AbsPath; +#else + return m_absPath; +#endif + } + + std::string_view getRelativePathUTF8() const { +#if HECL_UCS2 + return m_utf8RelPath; +#else + return m_relPath; +#endif + } + + SystemStringView getAuxInfo() const { return m_auxInfo; } + + std::string_view getAuxInfoUTF8() const { +#if HECL_UCS2 + return m_utf8AuxInfo; +#else + return m_auxInfo; +#endif + } + + /** + * @brief Construct a path with the aux info overwritten with specified string + * @param auxStr string to replace existing auxInfo with + */ + ProjectPath ensureAuxInfo(SystemStringView auxStr) const { + if (auxStr.empty()) + return ProjectPath(getProject(), getRelativePath()); + else + return ProjectPath(getProject(), SystemString(getRelativePath()) + _SYS_STR('|') + auxStr.data()); + } + +#if HECL_UCS2 + ProjectPath ensureAuxInfo(std::string_view auxStr) const { + return ProjectPath(getProject(), SystemString(getRelativePath()) + _SYS_STR('|') + UTF8ToWide(auxStr)); + } +#endif + + template + class EncodableString { + friend class ProjectPath; + using EncStringView = std::basic_string_view; + StringT m_ownedString; + EncStringView m_stringView; + EncodableString(StringT s) : m_ownedString(std::move(s)), m_stringView(m_ownedString) {} + EncodableString(EncStringView sv) : m_stringView(sv) {} + EncodableString(const EncodableString&) = delete; + EncodableString& operator=(const EncodableString&) = delete; + EncodableString(EncodableString&&) = delete; + EncodableString& operator=(EncodableString&&) = delete; + public: + operator EncStringView() const { return m_stringView; } + }; + + EncodableString getEncodableString() const { + if (!getAuxInfo().empty()) + return {SystemString(getRelativePath()) + _SYS_STR('|') + getAuxInfo().data()}; + else + return {getRelativePath()}; + } + + EncodableString getEncodableStringUTF8() const { + if (!getAuxInfo().empty()) + return {std::string(getRelativePathUTF8()) + '|' + getAuxInfoUTF8().data()}; + else + return {getRelativePathUTF8()}; + } + + /** + * @brief Type of path + */ + enum class Type { + None, /**< If path doesn't reference a valid filesystem entity, this is returned */ + File, /**< Singular file path (confirmed with filesystem) */ + Directory, /**< Singular directory path (confirmed with filesystem) */ + Glob, /**< Glob-path (whenever one or more '*' occurs in syntax) */ + }; + + /** + * @brief Get type of path based on syntax and filesystem queries + * @return Type of path + */ + Type getPathType() const; + + /** + * @brief Test if nothing exists at path + * @return True if nothing exists at path + */ + bool isNone() const { return getPathType() == Type::None; } + + /** + * @brief Test if regular file exists at path + * @return True if regular file exists at path + */ + bool isFile() const { return getPathType() == Type::File; } + + /** + * @brief Test if directory exists at path + * @return True if directory exists at path + */ + bool isDirectory() const { return getPathType() == Type::Directory; } + + /** + * @brief Certain singular resource targets are cooked based on this test + * @return True if file or glob + */ + bool isFileOrGlob() const { + Type type = getPathType(); + return (type == Type::File || type == Type::Glob); + } + + /** + * @brief Get time of last modification with special behaviors for directories and glob-paths + * @return Time object representing entity's time of last modification + * + * Regular files simply return their modtime as queried from the OS + * Directories return the latest modtime of all first-level regular files + * Glob-paths return the latest modtime of all matched regular files + */ + Time getModtime() const; + + /** + * @brief Insert directory children into list + * @param outPaths list to append children to + */ + void getDirChildren(std::map& outPaths) const; + + /** + * @brief Construct DirectoryEnumerator set to project path + */ + hecl::DirectoryEnumerator enumerateDir() const; + + /** + * @brief Insert glob matches into existing vector + * @param outPaths Vector to add matches to (will not erase existing contents) + */ + void getGlobResults(std::vector& outPaths) const; + + /** + * @brief Count how many directory levels deep in project path is + * @return Level Count + */ + size_t levelCount() const { + size_t count = 0; + for (SystemChar ch : m_relPath) + if (ch == _SYS_STR('/') || ch == _SYS_STR('\\')) + ++count; + return count; + } + + /** + * @brief Create directory at path + * + * Fatal log report is issued if directory is not able to be created or doesn't already exist. + * If directory already exists, no action taken. + */ + void makeDir() const { MakeDir(m_absPath.c_str()); } + + /** + * @brief Create directory chain leading up to path + * @param includeLastComp if set, the ProjectPath is assumed to be a + * directory, creating the final component + */ + void makeDirChain(bool includeLastComp) const { + std::vector comps = getPathComponents(); + auto end = comps.cend(); + if (end != comps.cbegin() && !includeLastComp) + --end; + ProjectPath compPath(*m_proj, _SYS_STR(".")); + for (auto it = comps.cbegin(); it != end; ++it) { + compPath = ProjectPath(compPath, *it); + compPath.makeDir(); + } + } + + /** + * @brief Fetch project that contains path + * @return Project + */ + Database::Project& getProject() const { + if (!m_proj) + LogModule.report(logvisor::Fatal, FMT_STRING("ProjectPath::getProject() called on unqualified path")); + return *m_proj; + } + + /** + * @brief HECL-specific xxhash + * @return unique hash value + */ + Hash hash() const noexcept { return m_hash; } + bool operator==(const ProjectPath& other) const noexcept { return m_hash == other.m_hash; } + bool operator!=(const ProjectPath& other) const noexcept { return !operator==(other); } + + uint32_t parsedHash32() const; +}; + +/** + * @brief Handy functions not directly provided via STL strings + */ +class StringUtils { +public: + static bool BeginsWith(SystemStringView str, SystemStringView test) { + if (test.size() > str.size()) + return false; + return str.compare(0, test.size(), test) == 0; + } + + static bool EndsWith(SystemStringView str, SystemStringView test) { + if (test.size() > str.size()) + return false; + return str.compare(str.size() - test.size(), SystemStringView::npos, test) == 0; + } + + static std::string TrimWhitespace(std::string_view str) { + auto bit = str.begin(); + while (bit != str.cend() && std::isspace(static_cast(*bit))) + ++bit; + auto eit = str.end(); + while (eit != str.cbegin() && std::isspace(static_cast(*(eit - 1)))) + --eit; + return {bit, eit}; + } + +#if HECL_UCS2 + static bool BeginsWith(std::string_view str, std::string_view test) { + if (test.size() > str.size()) + return false; + return str.compare(0, test.size(), test) == 0; + } + + static bool EndsWith(std::string_view str, std::string_view test) { + if (test.size() > str.size()) + return false; + return str.compare(str.size() - test.size(), std::string_view::npos, test) == 0; + } + + static SystemString TrimWhitespace(SystemStringView str) { + auto bit = str.begin(); + while (bit != str.cend() && std::iswspace(*bit)) + ++bit; + auto eit = str.end(); + while (eit != str.cbegin() && std::iswspace(*(eit - 1))) + --eit; + return {bit, eit}; + } +#endif +}; + +/** + * @brief Mutex-style centralized resource-path tracking + * + * Provides a means to safely parallelize resource processing; detecting when another + * thread is working on the same resource. + */ +class ResourceLock { + static bool SetThreadRes(const ProjectPath& path); + static void ClearThreadRes(); + bool good; + +public: + explicit operator bool() const { return good; } + static bool InProgress(const ProjectPath& path); + explicit ResourceLock(const ProjectPath& path) : good{SetThreadRes(path)} {} + ~ResourceLock() { + if (good) + ClearThreadRes(); + } + ResourceLock(const ResourceLock&) = delete; + ResourceLock& operator=(const ResourceLock&) = delete; + ResourceLock(ResourceLock&&) = delete; + ResourceLock& operator=(ResourceLock&&) = delete; +}; + +/** + * @brief Search from within provided directory for the project root + * @param path absolute or relative file path to search from + * @return Newly-constructed root path (bool-evaluating to false if not found) + */ +ProjectRootPath SearchForProject(SystemStringView path); + +/** + * @brief Search from within provided directory for the project root + * @param path absolute or relative file path to search from + * @param subpathOut remainder of provided path assigned to this ProjectPath + * @return Newly-constructed root path (bool-evaluating to false if not found) + */ +ProjectRootPath SearchForProject(SystemStringView path, SystemString& subpathOut); + +/** + * @brief Test if given path is a PNG (based on file header) + * @param path Path to test + * @return true if PNG + */ +bool IsPathPNG(const hecl::ProjectPath& path); + +/** + * @brief Test if given path is a blend (based on file header) + * @param path Path to test + * @return true if blend + */ +bool IsPathBlend(const hecl::ProjectPath& path); + +/** + * @brief Test if given path is a yaml (based on file extension) + * @param path Path to test + * @return true if yaml + */ +bool IsPathYAML(const hecl::ProjectPath& path); + +#undef bswap16 +#undef bswap32 +#undef bswap64 + +/* Type-sensitive byte swappers */ +template +constexpr T bswap16(T val) noexcept { +#if __GNUC__ + return __builtin_bswap16(val); +#elif _WIN32 + return _byteswap_ushort(val); +#else + return (val = (val << 8) | ((val >> 8) & 0xFF)); +#endif +} + +template +constexpr T bswap32(T val) noexcept { +#if __GNUC__ + return __builtin_bswap32(val); +#elif _WIN32 + return _byteswap_ulong(val); +#else + val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16; + val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8; + return val; +#endif +} + +template +constexpr T bswap64(T val) noexcept { +#if __GNUC__ + return __builtin_bswap64(val); +#elif _WIN32 + return _byteswap_uint64(val); +#else + return ((val & 0xFF00000000000000ULL) >> 56) | ((val & 0x00FF000000000000ULL) >> 40) | + ((val & 0x0000FF0000000000ULL) >> 24) | ((val & 0x000000FF00000000ULL) >> 8) | + ((val & 0x00000000FF000000ULL) << 8) | ((val & 0x0000000000FF0000ULL) << 24) | + ((val & 0x000000000000FF00ULL) << 40) | ((val & 0x00000000000000FFULL) << 56); +#endif +} + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +constexpr int16_t SBig(int16_t val) noexcept { return bswap16(val); } +constexpr uint16_t SBig(uint16_t val) noexcept { return bswap16(val); } +constexpr int32_t SBig(int32_t val) noexcept { return bswap32(val); } +constexpr uint32_t SBig(uint32_t val) noexcept { return bswap32(val); } +constexpr int64_t SBig(int64_t val) noexcept { return bswap64(val); } +constexpr uint64_t SBig(uint64_t val) noexcept { return bswap64(val); } +constexpr float SBig(float val) noexcept { + union { + float f; + atInt32 i; + } uval1 = {val}; + union { + atInt32 i; + float f; + } uval2 = {bswap32(uval1.i)}; + return uval2.f; +} +constexpr double SBig(double val) noexcept { + union { + double f; + atInt64 i; + } uval1 = {val}; + union { + atInt64 i; + double f; + } uval2 = {bswap64(uval1.i)}; + return uval2.f; +} +#ifndef SBIG +#define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24) +#endif + +constexpr int16_t SLittle(int16_t val) noexcept { return val; } +constexpr uint16_t SLittle(uint16_t val) noexcept { return val; } +constexpr int32_t SLittle(int32_t val) noexcept { return val; } +constexpr uint32_t SLittle(uint32_t val) noexcept { return val; } +constexpr int64_t SLittle(int64_t val) noexcept { return val; } +constexpr uint64_t SLittle(uint64_t val) noexcept { return val; } +constexpr float SLittle(float val) noexcept { return val; } +constexpr double SLittle(double val) noexcept { return val; } +#ifndef SLITTLE +#define SLITTLE(q) (q) +#endif +#else +constexpr int16_t SLittle(int16_t val) noexcept { return bswap16(val); } +constexpr uint16_t SLittle(uint16_t val) noexcept { return bswap16(val); } +constexpr int32_t SLittle(int32_t val) noexcept { return bswap32(val); } +constexpr uint32_t SLittle(uint32_t val) noexcept { return bswap32(val); } +constexpr int64_t SLittle(int64_t val) noexcept { return bswap64(val); } +constexpr uint64_t SLittle(uint64_t val) noexcept { return bswap64(val); } +constexpr float SLittle(float val) noexcept { + int32_t ival = bswap32(*((int32_t*)(&val))); + return *((float*)(&ival)); +} +constexpr double SLittle(double val) noexcept { + int64_t ival = bswap64(*((int64_t*)(&val))); + return *((double*)(&ival)); +} +#ifndef SLITTLE +#define SLITTLE(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24) +#endif + +constexpr int16_t SBig(int16_t val) noexcept { return val; } +constexpr uint16_t SBig(uint16_t val) noexcept { return val; } +constexpr int32_t SBig(int32_t val) noexcept { return val; } +constexpr uint32_t SBig(uint32_t val) noexcept { return val; } +constexpr int64_t SBig(int64_t val) noexcept { return val; } +constexpr uint64_t SBig(uint64_t val) noexcept { return val; } +constexpr float SBig(float val) noexcept { return val; } +constexpr double SBig(double val) noexcept { return val; } +#ifndef SBIG +#define SBIG(q) (q) +#endif +#endif + +template +constexpr void hash_combine_impl(SizeT& seed, SizeT value) noexcept { + seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2); +} + +} // namespace hecl + +#define CHAINED_SIGNAL_HANDLER(name, signal) \ +class ChainedSignalHandler_##name { \ + typedef void(*sighandler_t)(int); \ + typedef void(*sigaction_t)(int, siginfo_t*, void*); \ + static std::atomic_bool m_isSetup; \ + static sighandler_t m_nextsh; \ + static sigaction_t m_nextsa; \ + static void my_sig_action(int sig, siginfo_t* si, void* ctx); \ + static void sig_action(int sig, siginfo_t* si, void* ctx) { \ + my_sig_action(sig, si, ctx); \ + if (m_nextsa) \ + m_nextsa(sig, si, ctx); \ + else if (m_nextsh) \ + m_nextsh(sig); \ + } \ +public: \ + static void setup() { \ + if (ChainedSignalHandler_##name::m_isSetup.exchange(true) == true) \ + return; \ + { \ + struct sigaction sold; \ + if (sigaction(signal, nullptr, &sold) == 0) { \ + if (sold.sa_flags & SA_SIGINFO) \ + m_nextsa = sold.sa_sigaction; \ + else \ + m_nextsh = sold.sa_handler; \ + } \ + } \ + { \ + struct sigaction snew = {}; \ + snew.sa_sigaction = sig_action; \ + snew.sa_flags = SA_RESTART | SA_NOCLDSTOP | SA_SIGINFO; \ + sigaction(signal, &snew, nullptr); \ + } \ + } \ +}; \ +std::atomic_bool ChainedSignalHandler_##name::m_isSetup = {false}; \ +ChainedSignalHandler_##name::sighandler_t ChainedSignalHandler_##name::m_nextsh = {}; \ +ChainedSignalHandler_##name::sigaction_t ChainedSignalHandler_##name::m_nextsa = {}; \ +inline void ChainedSignalHandler_##name::my_sig_action + +#define SETUP_CHAINED_SIGNAL_HANDLER(name) \ +ChainedSignalHandler_##name::setup() + +namespace std { +template <> +struct hash { + size_t operator()(const hecl::ProjectPath& val) const noexcept { return val.hash().valSizeT(); } +}; +template <> +struct hash { + size_t operator()(const hecl::Hash& val) const noexcept { return val.valSizeT(); } +}; +} // namespace std + +FMT_CUSTOM_FORMATTER(hecl::SystemUTF8Conv, "{}", obj.str()) +FMT_CUSTOM_FORMATTER(hecl::SystemStringConv, "{}", obj.sys_str()) diff --git a/hecl/include/hecl/winsupport.hpp b/hecl/include/hecl/winsupport.hpp new file mode 100644 index 000000000..851d727ed --- /dev/null +++ b/hecl/include/hecl/winsupport.hpp @@ -0,0 +1,36 @@ +#pragma once + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#ifndef NOMINMAX +#define NOMINMAX 1 +#endif +#include "windows.h" +#include +#include +#include + +#ifndef DEF_INLINE_MEMMEM +#define DEF_INLINE_MEMMEM +inline void* memmem(const void* haystack, size_t hlen, const void* needle, size_t nlen) { + int needle_first; + const uint8_t* p = static_cast(haystack); + size_t plen = hlen; + + if (!nlen) + return NULL; + + needle_first = *(unsigned char*)needle; + + while (plen >= nlen && (p = static_cast(memchr(p, needle_first, plen - nlen + 1)))) { + if (!memcmp(p, needle, nlen)) + return (void*)p; + + p++; + plen = hlen - (p - static_cast(haystack)); + } + + return NULL; +} +#endif diff --git a/hecl/lib/Blender/CMakeLists.txt b/hecl/lib/Blender/CMakeLists.txt new file mode 100644 index 000000000..f757890ba --- /dev/null +++ b/hecl/lib/Blender/CMakeLists.txt @@ -0,0 +1,8 @@ +set(BLENDER_SOURCES + Connection.cpp + MeshOptimizer.hpp + MeshOptimizer.cpp + SDNARead.cpp + HMDL.cpp) + +hecl_add_list(Blender BLENDER_SOURCES) diff --git a/hecl/lib/Blender/Connection.cpp b/hecl/lib/Blender/Connection.cpp new file mode 100644 index 000000000..b4277804f --- /dev/null +++ b/hecl/lib/Blender/Connection.cpp @@ -0,0 +1,1752 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hecl/Blender/Connection.hpp" +#include "hecl/Blender/Token.hpp" +#include "hecl/Database.hpp" +#include "hecl/hecl.hpp" +#include "hecl/SteamFinder.hpp" +#include "MeshOptimizer.hpp" + +#include +#include + +#if _WIN32 +#include +#include +#else +#include +#endif + +#undef min +#undef max + +namespace std { +template <> +struct hash> { + std::size_t operator()(const std::pair& val) const noexcept { + /* this will potentially truncate the second value if 32-bit size_t, + * however, its application here is intended to operate in 16-bit indices */ + return val.first | (val.second << 16); + } +}; +} // namespace std + +using namespace std::literals; + +namespace hecl::blender { + +static const uint32_t MinBlenderMajorSearch = 2; +static const uint32_t MaxBlenderMajorSearch = 2; +static const uint32_t MinBlenderMinorSearch = 83; +static const uint32_t MaxBlenderMinorSearch = 92; + +logvisor::Module BlenderLog("hecl::blender::Connection"); +Token SharedBlenderToken; + +#ifdef __APPLE__ +#define DEFAULT_BLENDER_BIN "/Applications/Blender.app/Contents/MacOS/blender" +#else +#define DEFAULT_BLENDER_BIN "blender" +#endif + +extern "C" uint8_t HECL_BLENDERSHELL[]; +extern "C" size_t HECL_BLENDERSHELL_SZ; + +extern "C" uint8_t HECL_ADDON[]; +extern "C" size_t HECL_ADDON_SZ; + +extern "C" uint8_t HECL_STARTUP[]; +extern "C" size_t HECL_STARTUP_SZ; + +static void InstallBlendershell(const SystemChar* path) { + auto fp = hecl::FopenUnique(path, _SYS_STR("w")); + + if (fp == nullptr) { + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to open {} for writing")), path); + } + + std::fwrite(HECL_BLENDERSHELL, 1, HECL_BLENDERSHELL_SZ, fp.get()); +} + +static void InstallAddon(const SystemChar* path) { + auto fp = hecl::FopenUnique(path, _SYS_STR("wb")); + + if (fp == nullptr) { + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Unable to install blender addon at '{}'")), path); + } + + std::fwrite(HECL_ADDON, 1, HECL_ADDON_SZ, fp.get()); +} + +static int Read(int fd, void* buf, std::size_t size) { + int intrCount = 0; + do { + auto ret = read(fd, buf, size); + if (ret < 0) { + if (errno == EINTR) + ++intrCount; + else + return -1; + } else + return ret; + } while (intrCount < 1000); + return -1; +} + +static int Write(int fd, const void* buf, std::size_t size) { + int intrCount = 0; + do { + auto ret = write(fd, buf, size); + if (ret < 0) { + if (errno == EINTR) + ++intrCount; + else + return -1; + } else + return ret; + } while (intrCount < 1000); + return -1; +} + +static std::size_t BoundedStrLen(const char* buf, std::size_t maxLen) { + std::size_t ret; + for (ret = 0; ret < maxLen; ++ret) + if (buf[ret] == '\0') + break; + return ret; +} + +uint32_t Connection::_readStr(char* buf, uint32_t bufSz) { + uint32_t readLen; + int ret = Read(m_readpipe[0], &readLen, sizeof(readLen)); + if (ret < 4) { + BlenderLog.report(logvisor::Error, FMT_STRING("Pipe error {} {}"), ret, strerror(errno)); + _blenderDied(); + return 0; + } + + if (readLen >= bufSz) { + BlenderLog.report(logvisor::Fatal, FMT_STRING("Pipe buffer overrun [{}/{}]"), readLen, bufSz); + *buf = '\0'; + return 0; + } + + ret = Read(m_readpipe[0], buf, readLen); + if (ret < 0) { + BlenderLog.report(logvisor::Fatal, FMT_STRING("{}"), strerror(errno)); + return 0; + } + + constexpr std::string_view exception_str{"EXCEPTION"}; + const std::size_t readStrLen = BoundedStrLen(buf, readLen); + if (readStrLen >= exception_str.size()) { + if (exception_str.compare(0, exception_str.size(), std::string_view(buf, readStrLen)) == 0) { + _blenderDied(); + return 0; + } + } + + *(buf + readLen) = '\0'; + return readLen; +} + +uint32_t Connection::_writeStr(const char* buf, uint32_t len, int wpipe) { + const auto error = [this] { + _blenderDied(); + return 0U; + }; + + const int nlerr = Write(wpipe, &len, 4); + if (nlerr < 4) { + return error(); + } + + const int ret = Write(wpipe, buf, len); + if (ret < 0) { + return error(); + } + + return static_cast(ret); +} + +std::size_t Connection::_readBuf(void* buf, std::size_t len) { + const auto error = [this] { + _blenderDied(); + return 0U; + }; + + auto* cBuf = static_cast(buf); + std::size_t readLen = 0; + + do { + const int ret = Read(m_readpipe[0], cBuf, len); + if (ret < 0) { + return error(); + } + + constexpr std::string_view exception_str{"EXCEPTION"}; + const std::size_t readStrLen = BoundedStrLen(static_cast(buf), len); + if (readStrLen >= exception_str.size()) { + if (exception_str.compare(0, exception_str.size(), std::string_view(static_cast(buf), readStrLen)) == 0) { + _blenderDied(); + } + } + + readLen += ret; + cBuf += ret; + len -= ret; + } while (len != 0); + + return readLen; +} + +std::size_t Connection::_writeBuf(const void* buf, std::size_t len) { + const auto error = [this] { + _blenderDied(); + return 0U; + }; + + const auto* cBuf = static_cast(buf); + std::size_t writeLen = 0; + + do { + const int ret = Write(m_writepipe[1], cBuf, len); + if (ret < 0) { + return error(); + } + + writeLen += ret; + cBuf += ret; + len -= ret; + } while (len != 0); + + return writeLen; +} + +ProjectPath Connection::_readPath() { + std::string path = _readStdString(); + if (!path.empty()) { + SystemStringConv pathAbs(path); + SystemString meshPathRel = + getBlendPath().getProject().getProjectRootPath().getProjectRelativeFromAbsolute(pathAbs.sys_str()); + return ProjectPath(getBlendPath().getProject().getProjectWorkingPath(), meshPathRel); + } + return {}; +} + +void Connection::_closePipe() { + close(m_readpipe[0]); + close(m_writepipe[1]); +#ifdef _WIN32 + CloseHandle(m_pinfo.hProcess); + CloseHandle(m_pinfo.hThread); + m_consoleThreadRunning = false; + if (m_consoleThread.joinable()) + m_consoleThread.join(); +#endif +} + +void Connection::_blenderDied() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + auto errFp = hecl::FopenUnique(m_errPath.c_str(), _SYS_STR("r")); + + if (errFp != nullptr) { + std::fseek(errFp.get(), 0, SEEK_END); + const int64_t len = hecl::FTell(errFp.get()); + + if (len != 0) { + std::fseek(errFp.get(), 0, SEEK_SET); + const auto buf = std::make_unique(len + 1); + std::fread(buf.get(), 1, len, errFp.get()); + BlenderLog.report(logvisor::Fatal, FMT_STRING("\n{:.{}s}"), buf.get(), len); + } + } + + BlenderLog.report(logvisor::Fatal, FMT_STRING("Blender Exception")); +} + +static std::atomic_bool BlenderFirstInit(false); + +#if _WIN32 +static bool RegFileExists(const hecl::SystemChar* path) { + if (!path) + return false; + hecl::Sstat theStat; + return !hecl::Stat(path, &theStat) && S_ISREG(theStat.st_mode); +} +#endif + +Connection::Connection(int verbosityLevel) { +#if !WINDOWS_STORE && !defined(__SWITCH__) + if (hecl::VerbosityLevel >= 1) + BlenderLog.report(logvisor::Info, FMT_STRING("Establishing BlenderConnection...")); + + /* Put hecl_blendershell.py in temp dir */ + const SystemChar* TMPDIR = GetTmpDir(); +#ifndef _WIN32 + signal(SIGPIPE, SIG_IGN); +#endif + + hecl::SystemString blenderShellPath(TMPDIR); + blenderShellPath += _SYS_STR("/hecl_blendershell.py"); + + hecl::SystemString blenderAddonPath(TMPDIR); + blenderAddonPath += _SYS_STR("/hecl_blenderaddon.zip"); + + bool FalseCmp = false; + if (BlenderFirstInit.compare_exchange_strong(FalseCmp, true)) { + InstallBlendershell(blenderShellPath.c_str()); + InstallAddon(blenderAddonPath.c_str()); + } + + int installAttempt = 0; + while (true) { + /* Construct communication pipes */ +#if _WIN32 + _pipe(m_readpipe.data(), 2048, _O_BINARY); + _pipe(m_writepipe.data(), 2048, _O_BINARY); + HANDLE writehandle = HANDLE(_get_osfhandle(m_writepipe[0])); + SetHandleInformation(writehandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); + HANDLE readhandle = HANDLE(_get_osfhandle(m_readpipe[1])); + SetHandleInformation(readhandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); + + SECURITY_ATTRIBUTES sattrs = {sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE}; + HANDLE consoleOutReadTmp, consoleOutWrite, consoleErrWrite, consoleOutRead; + if (!CreatePipe(&consoleOutReadTmp, &consoleOutWrite, &sattrs, 1024)) + BlenderLog.report(logvisor::Fatal, FMT_STRING("Error with CreatePipe")); + + if (!DuplicateHandle(GetCurrentProcess(), consoleOutWrite, GetCurrentProcess(), &consoleErrWrite, 0, TRUE, + DUPLICATE_SAME_ACCESS)) + BlenderLog.report(logvisor::Fatal, FMT_STRING("Error with DuplicateHandle")); + + if (!DuplicateHandle(GetCurrentProcess(), consoleOutReadTmp, GetCurrentProcess(), + &consoleOutRead, // Address of new handle. + 0, FALSE, // Make it uninheritable. + DUPLICATE_SAME_ACCESS)) + BlenderLog.report(logvisor::Fatal, FMT_STRING("Error with DupliateHandle")); + + if (!CloseHandle(consoleOutReadTmp)) + BlenderLog.report(logvisor::Fatal, FMT_STRING("Error with CloseHandle")); +#else + pipe(m_readpipe.data()); + pipe(m_writepipe.data()); +#endif + + /* User-specified blender path */ +#if _WIN32 + wchar_t BLENDER_BIN_BUF[2048]; + std::wstring blenderBinBuf; + const wchar_t* blenderBin = _wgetenv(L"BLENDER_BIN"); +#else + const char* blenderBin = getenv("BLENDER_BIN"); +#endif + + /* Steam blender */ + hecl::SystemString steamBlender; + + /* Child process of blender */ +#if _WIN32 + if (!blenderBin || !RegFileExists(blenderBin)) { + /* Environment not set; try steam */ + steamBlender = hecl::FindCommonSteamApp(_SYS_STR("Blender")); + if (steamBlender.size()) { + steamBlender += _SYS_STR("\\blender.exe"); + blenderBin = steamBlender.c_str(); + } + + if (!RegFileExists(blenderBin)) { + /* No steam; try default */ + wchar_t progFiles[256]; + if (GetEnvironmentVariableW(L"ProgramFiles", progFiles, 256)) { + for (size_t major = MaxBlenderMajorSearch; major >= MinBlenderMajorSearch; --major) { + bool found = false; + for (size_t minor = MaxBlenderMinorSearch; minor >= MinBlenderMinorSearch; --minor) { + _snwprintf(BLENDER_BIN_BUF, 2048, L"%s\\Blender Foundation\\Blender %i.%i\\blender.exe", progFiles, major, + minor); + if (RegFileExists(BLENDER_BIN_BUF)) { + blenderBin = BLENDER_BIN_BUF; + found = true; + break; + } + } + + if (found) { + break; + } + } + } + } + } + + std::wstring cmdLine = fmt::format(FMT_STRING(L" --background -P \"{}\" -- {} {} {} \"{}\""), blenderShellPath, + uintptr_t(writehandle), uintptr_t(readhandle), verbosityLevel, blenderAddonPath); + + STARTUPINFO sinfo = {sizeof(STARTUPINFO)}; + HANDLE nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sattrs, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, nullptr); + sinfo.dwFlags = STARTF_USESTDHANDLES; + sinfo.hStdInput = nulHandle; + if (verbosityLevel == 0) { + sinfo.hStdError = nulHandle; + sinfo.hStdOutput = nulHandle; + } else { + sinfo.hStdError = consoleErrWrite; + sinfo.hStdOutput = consoleOutWrite; + } + + if (!CreateProcessW(blenderBin, cmdLine.data(), nullptr, nullptr, TRUE, NORMAL_PRIORITY_CLASS, nullptr, nullptr, + &sinfo, &m_pinfo)) { + LPWSTR messageBuffer = nullptr; + FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, + nullptr); + BlenderLog.report(logvisor::Fatal, FMT_STRING(L"unable to launch blender from {}: {}"), blenderBin, + messageBuffer); + } + + close(m_writepipe[0]); + close(m_readpipe[1]); + + CloseHandle(nulHandle); + CloseHandle(consoleErrWrite); + CloseHandle(consoleOutWrite); + + m_consoleThreadRunning = true; + m_consoleThread = std::thread([=]() { + CHAR lpBuffer[1024]; + DWORD nBytesRead; + DWORD nCharsWritten; + + while (m_consoleThreadRunning) { + if (!ReadFile(consoleOutRead, lpBuffer, sizeof(lpBuffer), &nBytesRead, nullptr) || !nBytesRead) { + DWORD err = GetLastError(); + if (err == ERROR_BROKEN_PIPE) + break; // pipe done - normal exit path. + else + BlenderLog.report(logvisor::Error, FMT_STRING("Error with ReadFile: {:08X}"), + err); // Something bad happened. + } + + // Display the character read on the screen. + auto lk = logvisor::LockLog(); + if (!WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), lpBuffer, nBytesRead, &nCharsWritten, nullptr)) { + // BlenderLog.report(logvisor::Error, FMT_STRING("Error with WriteConsole: %08X"), GetLastError()); + } + } + + CloseHandle(consoleOutRead); + }); + +#else + pid_t pid = fork(); + if (!pid) { + /* Close all file descriptors besides those this blender instance uses */ + int upper_fd = std::max(m_writepipe[0], m_readpipe[1]); + for (int i = 3; i < upper_fd; ++i) { + if (i != m_writepipe[0] && i != m_readpipe[1]) + close(i); + } + closefrom(upper_fd + 1); + + if (verbosityLevel == 0) { + int devNull = open("/dev/null", O_WRONLY); + dup2(devNull, STDOUT_FILENO); + dup2(devNull, STDERR_FILENO); + close(devNull); + } + + std::string errbuf; + std::string readfds = fmt::format(FMT_STRING("{}"), m_writepipe[0]); + std::string writefds = fmt::format(FMT_STRING("{}"), m_readpipe[1]); + std::string vLevel = fmt::format(FMT_STRING("{}"), verbosityLevel); + + /* Try user-specified blender first */ + if (blenderBin) { + execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--", readfds.c_str(), + writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr); + if (errno != ENOENT) { + errbuf = fmt::format(FMT_STRING("NOLAUNCH {}"), strerror(errno)); + _writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]); + exit(1); + } + } + + /* Try steam */ + steamBlender = hecl::FindCommonSteamApp(_SYS_STR("Blender")); + if (steamBlender.size()) { +#ifdef __APPLE__ + steamBlender += "/blender.app/Contents/MacOS/blender"; +#else + steamBlender += "/blender"; +#endif + blenderBin = steamBlender.c_str(); + execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--", readfds.c_str(), + writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr); + if (errno != ENOENT) { + errbuf = fmt::format(FMT_STRING("NOLAUNCH {}"), strerror(errno)); + _writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]); + exit(1); + } + } + + /* Otherwise default blender */ + execlp(DEFAULT_BLENDER_BIN, DEFAULT_BLENDER_BIN, "--background", "-P", blenderShellPath.c_str(), "--", + readfds.c_str(), writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr); + if (errno != ENOENT) { + errbuf = fmt::format(FMT_STRING("NOLAUNCH {}"), strerror(errno)); + _writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]); + exit(1); + } + + /* Unable to find blender */ + _writeStr("NOBLENDER", 9, m_readpipe[1]); + exit(1); + } + close(m_writepipe[0]); + close(m_readpipe[1]); + m_blenderProc = pid; +#endif + + /* Stash error path and unlink existing file */ +#if _WIN32 + m_errPath = hecl::SystemString(TMPDIR) + + fmt::format(FMT_STRING(_SYS_STR("/hecl_{:016X}.derp")), (unsigned long long)m_pinfo.dwProcessId); +#else + m_errPath = hecl::SystemString(TMPDIR) + + fmt::format(FMT_STRING(_SYS_STR("/hecl_{:016X}.derp")), (unsigned long long)m_blenderProc); +#endif + hecl::Unlink(m_errPath.c_str()); + + /* Handle first response */ + std::string lineStr = _readStdString(); + + if (!lineStr.compare(0, 8, "NOLAUNCH")) { + _closePipe(); + BlenderLog.report(logvisor::Fatal, FMT_STRING("Unable to launch blender: {}"), lineStr.c_str() + 9); + } else if (!lineStr.compare(0, 9, "NOBLENDER")) { + _closePipe(); +#if _WIN32 + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Unable to find blender at '{}'")), blenderBin); +#else + if (blenderBin) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Unable to find blender at '{}' or '{}'")), blenderBin, + DEFAULT_BLENDER_BIN); + else + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Unable to find blender at '{}'")), DEFAULT_BLENDER_BIN); +#endif + } else if (lineStr == "INVALIDBLENDERVER") { + _closePipe(); + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Installed blender version must be >= {}.{}")), + MinBlenderMajorSearch, MinBlenderMinorSearch); + } else if (lineStr == "NOADDON") { + _closePipe(); + if (blenderAddonPath != _SYS_STR("SKIPINSTALL")) + InstallAddon(blenderAddonPath.c_str()); + ++installAttempt; + if (installAttempt >= 2) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to install blender addon using '{}'")), + blenderAddonPath.c_str()); +#ifndef _WIN32 + waitpid(pid, nullptr, 0); +#endif + continue; + } else if (lineStr == "ADDONINSTALLED") { + _closePipe(); + blenderAddonPath = _SYS_STR("SKIPINSTALL"); +#ifndef _WIN32 + waitpid(pid, nullptr, 0); +#endif + continue; + } else if (lineStr != "READY") { + _closePipe(); + BlenderLog.report(logvisor::Fatal, FMT_STRING("read '{}' from blender; expected 'READY'"), lineStr); + } + _writeStr("ACK"); + + break; + } +#else + BlenderLog.report(logvisor::Fatal, FMT_STRING("BlenderConnection not available on UWP")); +#endif +} + +Connection::~Connection() { _closePipe(); } + +void Vector2f::read(Connection& conn) { conn._readBuf(&val, 8); } +void Vector3f::read(Connection& conn) { conn._readBuf(&val, 12); } +void Vector4f::read(Connection& conn) { conn._readBuf(&val, 16); } +void Matrix4f::read(Connection& conn) { conn._readBuf(&val, 64); } +void Index::read(Connection& conn) { conn._readBuf(&val, 4); } +void Float::read(Connection& conn) { conn._readBuf(&val, 4); } +void Boolean::read(Connection& conn) { conn._readBuf(&val, 1); } + +bool PyOutStream::StreamBuf::sendLine(std::string_view line) { + m_parent.m_parent->_writeStr(line); + if (!m_parent.m_parent->_isOk()) { + if (m_deleteOnError) + m_parent.m_parent->deleteBlend(); + m_parent.m_parent->_blenderDied(); + return false; + } + return true; +} + +PyOutStream::StreamBuf::int_type PyOutStream::StreamBuf::overflow(int_type ch) { + if (!m_parent.m_parent || !m_parent.m_parent->m_lock) + BlenderLog.report(logvisor::Fatal, FMT_STRING("lock not held for PyOutStream writing")); + if (ch != traits_type::eof() && ch != '\n' && ch != '\0') { + m_lineBuf += char_type(ch); + return ch; + } + sendLine(m_lineBuf); + m_lineBuf.clear(); + return ch; +} + +std::streamsize PyOutStream::StreamBuf::xsputn(const char_type* __first, std::streamsize __n) { + if (!m_parent.m_parent || !m_parent.m_parent->m_lock) + BlenderLog.report(logvisor::Fatal, FMT_STRING("lock not held for PyOutStream writing")); + const char_type* __last = __first + __n; + const char_type* __s = __first; + for (const char_type* __e = __first; __e != __last; ++__e) { + if (*__e == '\n' || traits_type::to_int_type(*__e) == traits_type::eof()) { + std::string_view line(__s, __e - __s); + bool result; + if (!m_lineBuf.empty()) { + /* Complete line with incomplete line from previous call */ + m_lineBuf += line; + result = sendLine(m_lineBuf); + m_lineBuf.clear(); + } else { + /* Complete line (optimal case) */ + result = sendLine(line); + } + if (!result || traits_type::to_int_type(*__e) == traits_type::eof()) + return __e - __first; /* Error or eof, end now */ + __s += line.size() + 1; + } + } + if (__s != __last) /* String ended with incomplete line (ideally this shouldn't happen for zero buffer overhead) */ + m_lineBuf += std::string_view(__s, __last - __s); + return __n; +} + +constexpr std::array BlendTypeStrs{"NONE"sv, "MESH"sv, "CMESH"sv, "ARMATURE"sv, + "ACTOR"sv, "AREA"sv, "WORLD"sv, "MAPAREA"sv, + "MAPUNIVERSE"sv, "FRAME"sv, "PATH"sv}; + +bool Connection::createBlend(const ProjectPath& path, BlendType type) { + if (m_lock) { + BlenderLog.report(logvisor::Fatal, + FMT_STRING("BlenderConnection::createBlend() musn't be called with stream active")); + return false; + } + _writeStr(fmt::format(FMT_STRING("CREATE \"{}\" {}"), path.getAbsolutePathUTF8(), BlendTypeStrs[int(type)])); + if (_isFinished()) { + /* Delete immediately in case save doesn't occur */ + hecl::Unlink(path.getAbsolutePath().data()); + m_loadedBlend = path; + m_loadedType = type; + return true; + } + return false; +} + +bool Connection::openBlend(const ProjectPath& path, bool force) { + if (m_lock) { + BlenderLog.report(logvisor::Fatal, + FMT_STRING("BlenderConnection::openBlend() musn't be called with stream active")); + return false; + } + if (!force && path == m_loadedBlend) + return true; + _writeStr(fmt::format(FMT_STRING("OPEN \"{}\""), path.getAbsolutePathUTF8())); + if (_isFinished()) { + m_loadedBlend = path; + _writeStr("GETTYPE"); + std::string typeStr = _readStdString(); + m_loadedType = BlendType::None; + unsigned idx = 0; + for (const auto& type : BlendTypeStrs) { + if (type == typeStr) { + m_loadedType = BlendType(idx); + break; + } + ++idx; + } + m_loadedRigged = false; + if (m_loadedType == BlendType::Mesh) { + _writeStr("GETMESHRIGGED"); + if (_isTrue()) + m_loadedRigged = true; + } + return true; + } + return false; +} + +bool Connection::saveBlend() { + if (m_lock) { + BlenderLog.report(logvisor::Fatal, + FMT_STRING("BlenderConnection::saveBlend() musn't be called with stream active")); + return false; + } + _writeStr("SAVE"); + return _isFinished(); +} + +void Connection::deleteBlend() { + if (m_loadedBlend) { + hecl::Unlink(m_loadedBlend.getAbsolutePath().data()); + BlenderLog.report(logvisor::Info, FMT_STRING(_SYS_STR("Deleted '{}'")), m_loadedBlend.getAbsolutePath()); + m_loadedBlend = ProjectPath(); + } +} + +PyOutStream::PyOutStream(Connection* parent, bool deleteOnError) +: std::ostream(&m_sbuf), m_parent(parent), m_sbuf(*this, deleteOnError) { + m_parent->m_pyStreamActive = true; + m_parent->_writeStr("PYBEGIN"); + m_parent->_checkReady("unable to open PyOutStream with blender"sv); +} + +void PyOutStream::close() { + if (m_parent && m_parent->m_lock) { + m_parent->_writeStr("PYEND"); + m_parent->_checkDone("unable to close PyOutStream with blender"sv); + m_parent->m_pyStreamActive = false; + m_parent->m_lock = false; + } +} + +void PyOutStream::linkBlend(std::string_view target, std::string_view objName, bool link) { + format( + FMT_STRING("if '{}' not in bpy.data.scenes:\n" + " with bpy.data.libraries.load('''{}''', link={}, relative=True) as (data_from, data_to):\n" + " data_to.scenes = data_from.scenes\n" + " obj_scene = None\n" + " for scene in data_to.scenes:\n" + " if scene.name == '{}':\n" + " obj_scene = scene\n" + " break\n" + " if not obj_scene:\n" + " raise RuntimeError('''unable to find {} in {}. try deleting it and restart the extract.''')\n" + " obj = None\n" + " for object in obj_scene.objects:\n" + " if object.name == obj_scene.name:\n" + " obj = object\n" + "else:\n" + " obj = bpy.data.objects['{}']\n" + "\n"), + objName, target, link ? "True" : "False", objName, objName, target, objName); +} + +void PyOutStream::linkArmature(std::string_view target, std::string_view armName) { + format(FMT_STRING( + "target_arm_name = '{}'\n" + "if target_arm_name not in bpy.data.armatures:\n" + " with bpy.data.libraries.load('''{}''', link=True, relative=True) as (data_from, data_to):\n" + " if target_arm_name not in data_from.armatures:\n" + " raise RuntimeError('''unable to find {} in {}. try deleting it and restart the extract.''')\n" + " data_to.armatures.append(target_arm_name)\n" + " obj = bpy.data.objects.new(target_arm_name, bpy.data.armatures[target_arm_name])\n" + "else:\n" + " obj = bpy.data.objects[target_arm_name]\n" + "\n"), + armName, target, armName, target); +} + +void PyOutStream::linkMesh(std::string_view target, std::string_view meshName) { + format(FMT_STRING( + "target_mesh_name = '{}'\n" + "if target_mesh_name not in bpy.data.objects:\n" + " with bpy.data.libraries.load('''{}''', link=True, relative=True) as (data_from, data_to):\n" + " if target_mesh_name not in data_from.objects:\n" + " raise RuntimeError('''unable to find {} in {}. try deleting it and restart the extract.''')\n" + " data_to.objects.append(target_mesh_name)\n" + "obj = bpy.data.objects[target_mesh_name]\n" + "\n"), + meshName, target, meshName, target); +} + +void PyOutStream::linkBackground(std::string_view target, std::string_view sceneName) { + if (sceneName.empty()) { + format(FMT_STRING("with bpy.data.libraries.load('''{}''', link=True, relative=True) as (data_from, data_to):\n" + " data_to.scenes = data_from.scenes\n" + "obj_scene = None\n" + "for scene in data_to.scenes:\n" + " obj_scene = scene\n" + " break\n" + "if not obj_scene:\n" + " raise RuntimeError('''unable to find {}. try deleting it and restart the extract.''')\n" + "\n" + "bpy.context.scene.background_set = obj_scene\n"), + target, target); + } else { + format(FMT_STRING( + "if '{}' not in bpy.data.scenes:\n" + " with bpy.data.libraries.load('''{}''', link=True, relative=True) as (data_from, data_to):\n" + " data_to.scenes = data_from.scenes\n" + " obj_scene = None\n" + " for scene in data_to.scenes:\n" + " if scene.name == '{}':\n" + " obj_scene = scene\n" + " break\n" + " if not obj_scene:\n" + " raise RuntimeError('''unable to find {} in {}. try deleting it and restart the extract.''')\n" + "\n" + "bpy.context.scene.background_set = bpy.data.scenes['{}']\n"), + sceneName, target, sceneName, sceneName, target, sceneName); + } +} + +void PyOutStream::AABBToBMesh(const atVec3f& min, const atVec3f& max) { + athena::simd_floats minf(min.simd); + athena::simd_floats maxf(max.simd); + format(FMT_STRING("bm = bmesh.new()\n" + "bm.verts.new(({},{},{}))\n" + "bm.verts.new(({},{},{}))\n" + "bm.verts.new(({},{},{}))\n" + "bm.verts.new(({},{},{}))\n" + "bm.verts.new(({},{},{}))\n" + "bm.verts.new(({},{},{}))\n" + "bm.verts.new(({},{},{}))\n" + "bm.verts.new(({},{},{}))\n" + "bm.verts.ensure_lookup_table()\n" + "bm.edges.new((bm.verts[0], bm.verts[1]))\n" + "bm.edges.new((bm.verts[0], bm.verts[2]))\n" + "bm.edges.new((bm.verts[0], bm.verts[4]))\n" + "bm.edges.new((bm.verts[3], bm.verts[1]))\n" + "bm.edges.new((bm.verts[3], bm.verts[2]))\n" + "bm.edges.new((bm.verts[3], bm.verts[7]))\n" + "bm.edges.new((bm.verts[5], bm.verts[1]))\n" + "bm.edges.new((bm.verts[5], bm.verts[4]))\n" + "bm.edges.new((bm.verts[5], bm.verts[7]))\n" + "bm.edges.new((bm.verts[6], bm.verts[2]))\n" + "bm.edges.new((bm.verts[6], bm.verts[4]))\n" + "bm.edges.new((bm.verts[6], bm.verts[7]))\n"), + minf[0], minf[1], minf[2], maxf[0], minf[1], minf[2], minf[0], maxf[1], minf[2], maxf[0], maxf[1], minf[2], + minf[0], minf[1], maxf[2], maxf[0], minf[1], maxf[2], minf[0], maxf[1], maxf[2], maxf[0], maxf[1], maxf[2]); +} + +void PyOutStream::centerView() { + *this << "for obj in bpy.context.scene.objects:\n" + " if obj.type == 'CAMERA' or obj.type == 'LIGHT':\n" + " obj.hide_set(True)\n" + "\n" + "old_smooth_view = bpy.context.preferences.view.smooth_view\n" + "bpy.context.preferences.view.smooth_view = 0\n" + "for window in bpy.context.window_manager.windows:\n" + " screen = window.screen\n" + " for area in screen.areas:\n" + " if area.type == 'VIEW_3D':\n" + " for region in area.regions:\n" + " if region.type == 'WINDOW':\n" + " override = {'scene': bpy.context.scene, 'window': window, 'screen': screen, 'area': " + "area, 'region': region}\n" + " bpy.ops.view3d.view_all(override)\n" + " break\n" + "bpy.context.preferences.view.smooth_view = old_smooth_view\n" + "\n" + "for obj in bpy.context.scene.objects:\n" + " if obj.type == 'CAMERA' or obj.type == 'LIGHT':\n" + " obj.hide_set(True)\n"; +} + +ANIMOutStream::ANIMOutStream(Connection* parent) : m_parent(parent) { + m_parent->_writeStr("PYANIM"); + m_parent->_checkAnimReady("unable to open ANIMOutStream"sv); +} + +ANIMOutStream::~ANIMOutStream() { + char tp = -1; + m_parent->_writeBuf(&tp, 1); + m_parent->_checkAnimDone("unable to close ANIMOutStream"sv); +} + +void ANIMOutStream::changeCurve(CurveType type, unsigned crvIdx, unsigned keyCount) { + if (m_curCount != m_totalCount) + BlenderLog.report(logvisor::Fatal, FMT_STRING("incomplete ANIMOutStream for change")); + m_curCount = 0; + m_totalCount = keyCount; + char tp = char(type); + m_parent->_writeBuf(&tp, 1); + struct { + uint32_t ci; + uint32_t kc; + } info = {uint32_t(crvIdx), uint32_t(keyCount)}; + m_parent->_writeBuf(reinterpret_cast(&info), 8); + m_inCurve = true; +} + +void ANIMOutStream::write(unsigned frame, float val) { + if (!m_inCurve) + BlenderLog.report(logvisor::Fatal, FMT_STRING("changeCurve not called before write")); + if (m_curCount < m_totalCount) { + struct { + uint32_t frm; + float val; + } key = {uint32_t(frame), val}; + m_parent->_writeBuf(reinterpret_cast(&key), 8); + ++m_curCount; + } else + BlenderLog.report(logvisor::Fatal, FMT_STRING("ANIMOutStream keyCount overflow")); +} + +Mesh::SkinBind::SkinBind(Connection& conn) { + conn._readValue(vg_idx); + conn._readValue(weight); +} + +void Mesh::normalizeSkinBinds() { + for (auto& skin : skins) { + float accum = 0.f; + for (const SkinBind& bind : skin) + if (bind.valid()) + accum += bind.weight; + if (accum > FLT_EPSILON) { + for (SkinBind& bind : skin) + if (bind.valid()) + bind.weight /= accum; + } + } +} + +Mesh::Mesh(Connection& conn, HMDLTopology topologyIn, int skinSlotCount, bool useLuvs) +: topology(topologyIn), sceneXf(conn), aabbMin(conn), aabbMax(conn) { + conn._readVectorFunc(materialSets, [&]() { conn._readVector(materialSets.emplace_back()); }); + + MeshOptimizer opt(conn, materialSets[0], useLuvs); + opt.optimize(*this, skinSlotCount); + + conn._readVector(boneNames); + if (boneNames.size()) + for (Surface& s : surfaces) + s.skinBankIdx = skinBanks.addSurface(*this, s, skinSlotCount); + + /* Custom properties */ + uint32_t propCount; + conn._readValue(propCount); + std::string keyBuf; + std::string valBuf; + for (uint32_t i = 0; i < propCount; ++i) { + keyBuf = conn._readStdString(); + valBuf = conn._readStdString(); + customProps[keyBuf] = valBuf; + } + + /* Connect skinned verts to bank slots */ + if (boneNames.size()) { + for (Surface& surf : surfaces) { + SkinBanks::Bank& bank = skinBanks.banks[surf.skinBankIdx]; + for (Surface::Vert& vert : surf.verts) { + if (vert.iPos == 0xffffffff) + continue; + for (uint32_t i = 0; i < bank.m_skinIdxs.size(); ++i) { + if (bank.m_skinIdxs[i] == vert.iSkin) { + vert.iBankSkin = i; + break; + } + } + } + } + } +} + +Mesh Mesh::getContiguousSkinningVersion() const { + Mesh newMesh = *this; + newMesh.pos.clear(); + newMesh.norm.clear(); + newMesh.contiguousSkinVertCounts.clear(); + newMesh.contiguousSkinVertCounts.reserve(skins.size()); + for (std::size_t i = 0; i < skins.size(); ++i) { + std::unordered_map, uint32_t> contigMap; + std::size_t vertCount = 0; + for (Surface& surf : newMesh.surfaces) { + for (Surface::Vert& vert : surf.verts) { + if (vert.iPos == 0xffffffff) + continue; + if (vert.iSkin == i) { + auto key = std::make_pair(vert.iPos, vert.iNorm); + auto search = contigMap.find(key); + if (search != contigMap.end()) { + vert.iPos = search->second; + vert.iNorm = search->second; + } else { + uint32_t newIdx = newMesh.pos.size(); + contigMap[key] = newIdx; + newMesh.pos.push_back(pos.at(vert.iPos)); + newMesh.norm.push_back(norm.at(vert.iNorm)); + vert.iPos = newIdx; + vert.iNorm = newIdx; + ++vertCount; + } + } + } + } + newMesh.contiguousSkinVertCounts.push_back(vertCount); + } + return newMesh; +} + +template +static T SwapFourCC(T fcc) { + return T(hecl::SBig(std::underlying_type_t(fcc))); +} + +Material::PASS::PASS(Connection& conn) { + conn._readValue(type); + type = SwapFourCC(type); + tex = conn._readPath(); + + conn._readValue(source); + conn._readValue(uvAnimType); + uint32_t argCount; + conn._readValue(argCount); + for (uint32_t i = 0; i < argCount; ++i) + conn._readValue(uvAnimParms[i]); + conn._readValue(alpha); +} + +Material::CLR::CLR(Connection& conn) { + conn._readValue(type); + type = SwapFourCC(type); + color.read(conn); +} + +Material::Material(Connection& conn) { + name = conn._readStdString(); + + conn._readValue(passIndex); + conn._readValue(shaderType); + shaderType = SwapFourCC(shaderType); + + conn._readVectorFunc(chunks, [&]() { + ChunkType type; + conn._readValue(type); + type = SwapFourCC(type); + chunks.push_back(Chunk::Build(type, conn)); + }); + + uint32_t iPropCount; + conn._readValue(iPropCount); + iprops.reserve(iPropCount); + for (uint32_t i = 0; i < iPropCount; ++i) { + std::string readStr = conn._readStdString(); + conn._readValue(iprops[readStr]); + } + + conn._readValue(blendMode); +} + +bool Mesh::Surface::Vert::operator==(const Vert& other) const { + return std::tie(iPos, iNorm, iColor, iUv, iSkin) == + std::tie(other.iPos, other.iNorm, other.iColor, other.iUv, other.iSkin); +} + +static bool VertInBank(const std::vector& bank, uint32_t sIdx) { + return std::any_of(bank.cbegin(), bank.cend(), [sIdx](auto index) { return index == sIdx; }); +} + +void Mesh::SkinBanks::Bank::addSkins(const Mesh& parent, const std::vector& skinIdxs) { + for (uint32_t sidx : skinIdxs) { + m_skinIdxs.push_back(sidx); + for (const SkinBind& bind : parent.skins[sidx]) { + if (!bind.valid()) + break; + bool found = false; + for (uint32_t bidx : m_boneIdxs) { + if (bidx == bind.vg_idx) { + found = true; + break; + } + } + if (!found) + m_boneIdxs.push_back(bind.vg_idx); + } + } +} + +std::vector::iterator Mesh::SkinBanks::addSkinBank(int skinSlotCount) { + banks.emplace_back(); + if (skinSlotCount > 0) + banks.back().m_skinIdxs.reserve(skinSlotCount); + return banks.end() - 1; +} + +uint32_t Mesh::SkinBanks::addSurface(const Mesh& mesh, const Surface& surf, int skinSlotCount) { + if (banks.empty()) + addSkinBank(skinSlotCount); + std::vector toAdd; + if (skinSlotCount > 0) + toAdd.reserve(skinSlotCount); + std::vector::iterator bankIt = banks.begin(); + for (;;) { + bool done = true; + for (; bankIt != banks.end(); ++bankIt) { + Bank& bank = *bankIt; + done = true; + for (const Surface::Vert& v : surf.verts) { + if (v.iPos == 0xffffffff) + continue; + if (!VertInBank(bank.m_skinIdxs, v.iSkin) && !VertInBank(toAdd, v.iSkin)) { + toAdd.push_back(v.iSkin); + if (skinSlotCount > 0 && bank.m_skinIdxs.size() + toAdd.size() > std::size_t(skinSlotCount)) { + toAdd.clear(); + done = false; + break; + } + } + } + if (toAdd.size()) { + bank.addSkins(mesh, toAdd); + toAdd.clear(); + } + if (done) + return uint32_t(bankIt - banks.begin()); + } + if (!done) { + bankIt = addSkinBank(skinSlotCount); + continue; + } + break; + } + return uint32_t(-1); +} + +ColMesh::ColMesh(Connection& conn) { + conn._readVector(materials); + conn._readVector(verts); + conn._readVector(edges); + conn._readVector(trianges); +} + +ColMesh::Material::Material(Connection& conn) { + name = conn._readStdString(); + conn._readBuf(&unknown, 42); +} + +ColMesh::Edge::Edge(Connection& conn) { conn._readBuf(this, 9); } + +ColMesh::Triangle::Triangle(Connection& conn) { conn._readBuf(this, 17); } + +World::Area::Dock::Dock(Connection& conn) { + verts[0].read(conn); + verts[1].read(conn); + verts[2].read(conn); + verts[3].read(conn); + targetArea.read(conn); + targetDock.read(conn); +} + +World::Area::Area(Connection& conn) { + std::string name = conn._readStdString(); + + path.assign(conn.getBlendPath().getParentPath(), name); + aabb[0].read(conn); + aabb[1].read(conn); + transform.read(conn); + conn._readVector(docks); +} + +World::World(Connection& conn) { conn._readVector(areas); } + +Light::Light(Connection& conn) : sceneXf(conn), color(conn) { + conn._readBuf(&layer, 29); + name = conn._readStdString(); +} + +MapArea::Surface::Surface(Connection& conn) { + centerOfMass.read(conn); + normal.read(conn); + conn._readBuf(&start, 8); + conn._readVectorFunc(borders, [&]() { conn._readBuf(&borders.emplace_back(), 8); }); +} + +MapArea::POI::POI(Connection& conn) { + conn._readBuf(&type, 12); + xf.read(conn); +} + +MapArea::MapArea(Connection& conn) { + conn._readValue(visType); + conn._readVector(verts); + + uint8_t isIdx; + conn._readValue(isIdx); + while (isIdx) { + conn._readValue(indices.emplace_back()); + conn._readValue(isIdx); + } + + conn._readVector(surfaces); + conn._readVector(pois); +} + +MapUniverse::World::World(Connection& conn) { + name = conn._readStdString(); + xf.read(conn); + conn._readVector(hexagons); + color.read(conn); + std::string path = conn._readStdString(); + if (!path.empty()) { + hecl::SystemStringConv sysPath(path); + worldPath.assign(conn.getBlendPath().getProject().getProjectWorkingPath(), sysPath.sys_str()); + } +} + +MapUniverse::MapUniverse(Connection& conn) { + hexagonPath = conn._readPath(); + conn._readVector(worlds); +} + +Actor::Actor(Connection& conn) { + conn._readVector(armatures); + conn._readVector(subtypes); + conn._readVector(attachments); + conn._readVector(actions); +} + +PathMesh::PathMesh(Connection& conn) { conn._readVector(data); } + +const Bone* Armature::lookupBone(const char* name) const { + for (const Bone& b : bones) + if (b.name == name) + return &b; + return nullptr; +} + +const Bone* Armature::getParent(const Bone* bone) const { + if (bone->parent < 0) + return nullptr; + return &bones[bone->parent]; +} + +const Bone* Armature::getChild(const Bone* bone, std::size_t child) const { + if (child >= bone->children.size()) + return nullptr; + int32_t cIdx = bone->children[child]; + if (cIdx < 0) + return nullptr; + return &bones[cIdx]; +} + +const Bone* Armature::getRoot() const { + for (const Bone& b : bones) + if (b.parent < 0) + return &b; + return nullptr; +} + +Armature::Armature(Connection& conn) { conn._readVector(bones); } + +Bone::Bone(Connection& conn) { + name = conn._readStdString(); + origin.read(conn); + conn._readValue(parent); + conn._readVector(children); +} + +Actor::ActorArmature::ActorArmature(Connection& conn) { + name = conn._readStdString(); + path = conn._readPath(); + armature.emplace(conn); +} + +Actor::Subtype::OverlayMesh::OverlayMesh(Connection& conn) { + name = conn._readStdString(); + cskrId = conn._readStdString(); + mesh = conn._readPath(); +} + +Actor::Subtype::Subtype(Connection& conn) { + name = conn._readStdString(); + cskrId = conn._readStdString(); + mesh = conn._readPath(); + conn._readValue(armature); + conn._readVector(overlayMeshes); +} + +Actor::Attachment::Attachment(Connection& conn) { + name = conn._readStdString(); + cskrId = conn._readStdString(); + mesh = conn._readPath(); + conn._readValue(armature); +} + +Action::Action(Connection& conn) { + name = conn._readStdString(); + animId = conn._readStdString(); + conn._readValue(interval); + conn._readValue(additive); + conn._readValue(looping); + conn._readVector(frames); + conn._readVector(channels); + conn._readVectorFunc(subtypeAABBs, [&]() { + auto& p = subtypeAABBs.emplace_back(); + p.first.read(conn); + p.second.read(conn); + }); +} + +Action::Channel::Channel(Connection& conn) { + boneName = conn._readStdString(); + conn._readValue(attrMask); + conn._readVector(keys, attrMask); +} + +Action::Channel::Key::Key(Connection& conn, uint32_t attrMask) { + if (attrMask & 1) + rotation.read(conn); + + if (attrMask & 2) + position.read(conn); + + if (attrMask & 4) + scale.read(conn); +} + +DataStream::DataStream(Connection* parent) : m_parent(parent) { + m_parent->m_dataStreamActive = true; + m_parent->_writeStr("DATABEGIN"); + m_parent->_checkReady("unable to open DataStream with blender"sv); +} + +void DataStream::close() { + if (m_parent && m_parent->m_lock) { + m_parent->_writeStr("DATAEND"); + m_parent->_checkDone("unable to close DataStream with blender"sv); + m_parent->m_dataStreamActive = false; + m_parent->m_lock = false; + } +} + +std::vector DataStream::getMeshList() { + m_parent->_writeStr("MESHLIST"); + std::vector retval; + m_parent->_readVector(retval); + return retval; +} + +std::vector DataStream::getLightList() { + m_parent->_writeStr("LIGHTLIST"); + std::vector retval; + m_parent->_readVector(retval); + return retval; +} + +std::pair DataStream::getMeshAABB() { + if (m_parent->m_loadedType != BlendType::Mesh && m_parent->m_loadedType != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not a MESH or ACTOR blend")), + m_parent->m_loadedBlend.getAbsolutePath()); + + m_parent->_writeStr("MESHAABB"); + m_parent->_checkOk("unable get AABB"sv); + + Vector3f minPt(*m_parent); + Vector3f maxPt(*m_parent); + return std::make_pair(minPt.val, maxPt.val); +} + +const char* DataStream::MeshOutputModeString(HMDLTopology topology) { + static constexpr std::array STRS{"TRIANGLES", "TRISTRIPS"}; + return STRS[int(topology)]; +} + +Mesh DataStream::compileMesh(HMDLTopology topology, int skinSlotCount) { + if (m_parent->getBlendType() != BlendType::Mesh) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not a MESH blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("MESHCOMPILE"); + m_parent->_checkOk("unable to cook mesh"sv); + + return Mesh(*m_parent, topology, skinSlotCount); +} + +Mesh DataStream::compileMesh(std::string_view name, HMDLTopology topology, int skinSlotCount, bool useLuv) { + if (m_parent->getBlendType() != BlendType::Area) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an AREA blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr(fmt::format(FMT_STRING("MESHCOMPILENAME {} {}"), name, int(useLuv))); + m_parent->_checkOk("unable to cook mesh"sv); + + return Mesh(*m_parent, topology, skinSlotCount, useLuv); +} + +ColMesh DataStream::compileColMesh(std::string_view name) { + if (m_parent->getBlendType() != BlendType::Area) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an AREA blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr(fmt::format(FMT_STRING("MESHCOMPILENAMECOLLISION {}"), name)); + m_parent->_checkOk("unable to cook collision mesh"sv); + + return ColMesh(*m_parent); +} + +std::vector DataStream::compileColMeshes() { + if (m_parent->getBlendType() != BlendType::ColMesh) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not a CMESH blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("MESHCOMPILECOLLISIONALL"); + m_parent->_checkOk("unable to cook collision meshes"sv); + + std::vector ret; + m_parent->_readVector(ret); + return ret; +} + +std::vector DataStream::compileLights() { + if (m_parent->getBlendType() != BlendType::Area) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an AREA blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("LIGHTCOMPILEALL"); + m_parent->_checkOk("unable to gather all lights"sv); + + std::vector ret; + m_parent->_readVector(ret); + return ret; +} + +PathMesh DataStream::compilePathMesh() { + if (m_parent->getBlendType() != BlendType::PathMesh) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not a PATH blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("MESHCOMPILEPATH"); + m_parent->_checkOk("unable to compile path mesh"sv); + + return PathMesh(*m_parent); +} + +std::vector DataStream::compileGuiFrame(int version) { + if (m_parent->getBlendType() != BlendType::Frame) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not a FRAME blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr(fmt::format(FMT_STRING("FRAMECOMPILE {}"), version)); + m_parent->_checkOk("unable to compile frame"sv); + + while (true) { + std::string readStr = m_parent->_readStdString(); + if (readStr == "FRAMEDONE") + break; + + SystemStringConv absolute(readStr); + auto& proj = m_parent->getBlendPath().getProject(); + SystemString relative; + if (PathRelative(absolute.c_str())) + relative = absolute.sys_str(); + else + relative = proj.getProjectRootPath().getProjectRelativeFromAbsolute(absolute.sys_str()); + hecl::ProjectPath path(proj.getProjectWorkingPath(), relative); + + m_parent->_writeStr(fmt::format(FMT_STRING("{:08X}"), path.parsedHash32())); + } + + std::vector ret; + m_parent->_readVector(ret); + return ret; +} + +std::vector DataStream::getTextures() { + m_parent->_writeStr("GETTEXTURES"); + m_parent->_checkOk("unable to get textures"sv); + + std::vector texs; + m_parent->_readVectorFunc(texs, [&]() { texs.push_back(m_parent->_readPath()); }); + + return texs; +} + +Actor DataStream::compileActor() { + if (m_parent->getBlendType() != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ACTOR blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("ACTORCOMPILE"); + m_parent->_checkOk("unable to compile actor"sv); + + return Actor(*m_parent); +} + +Actor DataStream::compileActorCharacterOnly() { + if (m_parent->getBlendType() != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ACTOR blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("ACTORCOMPILECHARACTERONLY"); + m_parent->_checkOk("unable to compile actor"sv); + + return Actor(*m_parent); +} + +Armature DataStream::compileArmature() { + if (m_parent->getBlendType() != BlendType::Armature) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ARMATURE blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("ARMATURECOMPILE"); + m_parent->_checkOk("unable to compile armature"sv); + + return Armature(*m_parent); +} + +Action DataStream::compileActionChannelsOnly(std::string_view name) { + if (m_parent->getBlendType() != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ACTOR blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr(fmt::format(FMT_STRING("ACTIONCOMPILECHANNELSONLY {}"), name)); + m_parent->_checkOk("unable to compile action"sv); + + return Action(*m_parent); +} + +World DataStream::compileWorld() { + if (m_parent->getBlendType() != BlendType::World) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an WORLD blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("WORLDCOMPILE"); + m_parent->_checkOk("unable to compile world"sv); + + return World(*m_parent); +} + +std::vector> DataStream::getSubtypeNames() { + if (m_parent->getBlendType() != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ACTOR blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("GETSUBTYPENAMES"); + m_parent->_checkOk("unable to get subtypes of actor"sv); + + std::vector> ret; + m_parent->_readVectorFunc(ret, [&]() { + auto& [name, cskrId] = ret.emplace_back(); + name = m_parent->_readStdString(); + cskrId = m_parent->_readStdString(); + }); + + return ret; +} + +std::vector> DataStream::getActionNames() { + if (m_parent->getBlendType() != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ACTOR blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("GETACTIONNAMES"); + m_parent->_checkOk("unable to get actions of actor"sv); + + std::vector> ret; + m_parent->_readVectorFunc(ret, [&]() { + auto& [name, animId] = ret.emplace_back(); + name = m_parent->_readStdString(); + animId = m_parent->_readStdString(); + }); + + return ret; +} + +std::vector> DataStream::getSubtypeOverlayNames(std::string_view name) { + if (m_parent->getBlendType() != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ACTOR blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr(fmt::format(FMT_STRING("GETSUBTYPEOVERLAYNAMES {}"), name)); + m_parent->_checkOk("unable to get subtype overlays of actor"sv); + + std::vector> ret; + m_parent->_readVectorFunc(ret, [&]() { + auto& [subtypeName, cskrId] = ret.emplace_back(); + subtypeName = m_parent->_readStdString(); + cskrId = m_parent->_readStdString(); + }); + + return ret; +} + +std::vector> DataStream::getAttachmentNames() { + if (m_parent->getBlendType() != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ACTOR blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("GETATTACHMENTNAMES"); + m_parent->_checkOk("unable to get attachments of actor"sv); + + std::vector> ret; + m_parent->_readVectorFunc(ret, [&]() { + auto& [name, cskrId] = ret.emplace_back(); + name = m_parent->_readStdString(); + cskrId = m_parent->_readStdString(); + }); + + return ret; +} + +std::unordered_map DataStream::getBoneMatrices(std::string_view name) { + if (name.empty()) + return {}; + + if (m_parent->getBlendType() != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an ACTOR blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr(fmt::format(FMT_STRING("GETBONEMATRICES {}"), name)); + m_parent->_checkOk("unable to get matrices of armature"sv); + + std::unordered_map ret; + + uint32_t boneCount; + m_parent->_readValue(boneCount); + ret.reserve(boneCount); + for (uint32_t i = 0; i < boneCount; ++i) { + std::string mat_name = m_parent->_readStdString(); + + Matrix3f matOut; + for (int mat_i = 0; mat_i < 3; ++mat_i) { + for (int mat_j = 0; mat_j < 3; ++mat_j) { + float val; + m_parent->_readValue(val); + matOut[mat_i].simd[mat_j] = val; + } + matOut[mat_i].simd[3] = 0.f; + } + + ret.emplace(std::move(mat_name), std::move(matOut)); + } + + return ret; +} + +bool DataStream::renderPvs(std::string_view path, const atVec3f& location) { + if (path.empty()) + return false; + + if (m_parent->getBlendType() != BlendType::Area) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an AREA blend")), + m_parent->getBlendPath().getAbsolutePath()); + + athena::simd_floats f(location.simd); + m_parent->_writeStr(fmt::format(FMT_STRING("RENDERPVS {} {} {} {}"), path, f[0], f[1], f[2])); + m_parent->_checkOk("unable to render PVS"sv); + + return true; +} + +bool DataStream::renderPvsLight(std::string_view path, std::string_view lightName) { + if (path.empty()) + return false; + + if (m_parent->getBlendType() != BlendType::Area) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not an AREA blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr(fmt::format(FMT_STRING("RENDERPVSLIGHT {} {}"), path, lightName)); + m_parent->_checkOk("unable to render PVS light"sv); + + return true; +} + +MapArea DataStream::compileMapArea() { + if (m_parent->getBlendType() != BlendType::MapArea) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not a MAPAREA blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("MAPAREACOMPILE"); + m_parent->_checkOk("unable to compile map area"sv); + + return {*m_parent}; +} + +MapUniverse DataStream::compileMapUniverse() { + if (m_parent->getBlendType() != BlendType::MapUniverse) + BlenderLog.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{} is not a MAPUNIVERSE blend")), + m_parent->getBlendPath().getAbsolutePath()); + + m_parent->_writeStr("MAPUNIVERSECOMPILE"); + m_parent->_checkOk("unable to compile map universe"sv); + + return {*m_parent}; +} + +void Connection::quitBlender() { + if (m_blenderQuit) + return; + m_blenderQuit = true; + char lineBuf[256]; + if (m_lock) { + if (m_pyStreamActive) { + _writeStr("PYEND"); + _readStr(lineBuf, sizeof(lineBuf)); + m_pyStreamActive = false; + } else if (m_dataStreamActive) { + _writeStr("DATAEND"); + _readStr(lineBuf, sizeof(lineBuf)); + m_dataStreamActive = false; + } + m_lock = false; + } + _writeStr("QUIT"); + _readStr(lineBuf, sizeof(lineBuf)); +#if !defined(_WIN32) && !defined(__SWITCH__) + waitpid(m_blenderProc, nullptr, 0); +#endif +} + +Connection& Connection::SharedConnection() { return SharedBlenderToken.getBlenderConnection(); } + +void Connection::Shutdown() { SharedBlenderToken.shutdown(); } + +Connection& Token::getBlenderConnection() { + if (!m_conn) + m_conn = std::make_unique(hecl::VerbosityLevel); + return *m_conn; +} + +void Token::shutdown() { + if (m_conn) { + m_conn->quitBlender(); + m_conn.reset(); + if (hecl::VerbosityLevel >= 1) + BlenderLog.report(logvisor::Info, FMT_STRING("Blender Shutdown Successful")); + } +} + +Token::~Token() { shutdown(); } + +HMDLBuffers::HMDLBuffers(HMDLMeta&& meta, std::size_t vboSz, const std::vector& iboData, + std::vector&& surfaces, const Mesh::SkinBanks& skinBanks) +: m_meta(std::move(meta)) +, m_vboSz(vboSz) +, m_vboData(new uint8_t[vboSz]) +, m_iboSz(iboData.size() * 4) +, m_iboData(new uint8_t[iboData.size() * 4]) +, m_surfaces(std::move(surfaces)) +, m_skinBanks(skinBanks) { + if (m_iboSz) { + athena::io::MemoryWriter w(m_iboData.get(), m_iboSz); + w.enumerateLittle(iboData); + } +} + +} // namespace hecl::blender diff --git a/hecl/lib/Blender/HMDL.cpp b/hecl/lib/Blender/HMDL.cpp new file mode 100644 index 000000000..b44f55e6b --- /dev/null +++ b/hecl/lib/Blender/HMDL.cpp @@ -0,0 +1,176 @@ +#include "hecl/Blender/Connection.hpp" + +#include +#include +#include +#include + +#include + +#undef min +#undef max + +namespace hecl::blender { + +atVec3f MtxVecMul4RM(const Matrix4f& mtx, const Vector3f& vec) { + atVec3f res; + athena::simd_floats resf; + athena::simd_floats mtxf[3]; + for (int i = 0; i < 3; ++i) + mtx[i].simd.copy_to(mtxf[i]); + athena::simd_floats vecf(vec.val.simd); + resf[0] = mtxf[0][0] * vecf[0] + mtxf[0][1] * vecf[1] + mtxf[0][2] * vecf[2] + mtxf[0][3]; + resf[1] = mtxf[1][0] * vecf[0] + mtxf[1][1] * vecf[1] + mtxf[1][2] * vecf[2] + mtxf[1][3]; + resf[2] = mtxf[2][0] * vecf[0] + mtxf[2][1] * vecf[1] + mtxf[2][2] * vecf[2] + mtxf[2][3]; + res.simd.copy_from(resf); + return res; +} + +atVec3f MtxVecMul3RM(const Matrix4f& mtx, const Vector3f& vec) { + atVec3f res; + athena::simd_floats resf; + athena::simd_floats mtxf[3]; + for (int i = 0; i < 3; ++i) + mtx[i].simd.copy_to(mtxf[i]); + athena::simd_floats vecf(vec.val.simd); + resf[0] = mtxf[0][0] * vecf[0] + mtxf[0][1] * vecf[1] + mtxf[0][2] * vecf[2]; + resf[1] = mtxf[1][0] * vecf[0] + mtxf[1][1] * vecf[1] + mtxf[1][2] * vecf[2]; + resf[2] = mtxf[2][0] * vecf[0] + mtxf[2][1] * vecf[1] + mtxf[2][2] * vecf[2]; + res.simd.copy_from(resf); + return res; +} + +HMDLBuffers Mesh::getHMDLBuffers(bool absoluteCoords, PoolSkinIndex& poolSkinIndex) const { + /* If skinned, compute max weight vec count */ + size_t weightCount = 0; + for (const SkinBanks::Bank& bank : skinBanks.banks) + weightCount = std::max(weightCount, bank.m_boneIdxs.size()); + size_t weightVecCount = weightCount / 4; + if (weightCount % 4) + ++weightVecCount; + + /* Prepare HMDL meta */ + HMDLMeta metaOut; + metaOut.topology = topology; + metaOut.vertStride = (3 + 3 + colorLayerCount + uvLayerCount * 2 + weightVecCount * 4) * 4; + metaOut.colorCount = colorLayerCount; + metaOut.uvCount = uvLayerCount; + metaOut.weightCount = weightVecCount; + metaOut.bankCount = skinBanks.banks.size(); + + /* Total all verts from all surfaces (for ibo length) */ + size_t boundVerts = 0; + for (const Surface& surf : surfaces) + boundVerts += surf.verts.size(); + + /* Maintain unique vert pool for VBO */ + std::vector> vertPool; + vertPool.reserve(boundVerts); + + /* Target surfaces representation */ + std::vector outSurfaces; + outSurfaces.reserve(surfaces.size()); + + /* Index buffer */ + std::vector iboData; + iboData.reserve(boundVerts); + + for (const Surface& surf : surfaces) { + size_t iboStart = iboData.size(); + for (const Surface::Vert& v : surf.verts) { + if (v.iPos == 0xffffffff) { + iboData.push_back(0xffffffff); + continue; + } + + size_t ti = 0; + bool found = false; + for (const std::pair& tv : vertPool) { + if (v == *tv.second && surf.skinBankIdx == tv.first->skinBankIdx) { + iboData.push_back(ti); + found = true; + break; + } + ++ti; + } + if (!found) { + iboData.push_back(vertPool.size()); + vertPool.emplace_back(&surf, &v); + } + } + outSurfaces.emplace_back(surf, iboStart, iboData.size() - iboStart); + } + + metaOut.vertCount = vertPool.size(); + metaOut.indexCount = iboData.size(); + + size_t vboSz = metaOut.vertCount * metaOut.vertStride; + poolSkinIndex.allocate(vertPool.size()); + HMDLBuffers ret(std::move(metaOut), vboSz, iboData, std::move(outSurfaces), skinBanks); + athena::io::MemoryWriter vboW(ret.m_vboData.get(), vboSz); + uint32_t curPoolIdx = 0; + for (const std::pair& sv : vertPool) { + const Surface& s = *sv.first; + const Surface::Vert& v = *sv.second; + + if (absoluteCoords) { + atVec3f preXfPos = MtxVecMul4RM(sceneXf, pos[v.iPos]); + vboW.writeVec3fLittle(preXfPos); + + atVec3f preXfNorm = MtxVecMul3RM(sceneXf, norm[v.iNorm]); + athena::simd_floats f(preXfNorm.simd * preXfNorm.simd); + float mag = f[0] + f[1] + f[2]; + if (mag > FLT_EPSILON) + mag = 1.f / std::sqrt(mag); + preXfNorm.simd *= mag; + vboW.writeVec3fLittle(preXfNorm); + } else { + vboW.writeVec3fLittle(pos[v.iPos]); + vboW.writeVec3fLittle(norm[v.iNorm]); + } + + for (size_t i = 0; i < colorLayerCount; ++i) { + const Vector3f& c = color[v.iColor[i]]; + athena::simd_floats f(c.val.simd); + vboW.writeUByte(std::max(0, std::min(255, int(f[0] * 255)))); + vboW.writeUByte(std::max(0, std::min(255, int(f[1] * 255)))); + vboW.writeUByte(std::max(0, std::min(255, int(f[2] * 255)))); + vboW.writeUByte(255); + } + + for (size_t i = 0; i < uvLayerCount; ++i) + vboW.writeVec2fLittle(uv[v.iUv[i]]); + + if (weightVecCount) { + const SkinBanks::Bank& bank = skinBanks.banks[s.skinBankIdx]; + const auto& binds = skins[v.iSkin]; + + auto it = bank.m_boneIdxs.cbegin(); + for (size_t i = 0; i < weightVecCount; ++i) { + atVec4f vec = {}; + for (size_t j = 0; j < 4; ++j) { + if (it == bank.m_boneIdxs.cend()) + break; + for (const SkinBind& bind : binds) { + if (!bind.valid()) + break; + if (bind.vg_idx == *it) { + vec.simd[j] = bind.weight; + break; + } + } + ++it; + } + vboW.writeVec4fLittle(vec); + } + } + + /* mapping pool verts to skin indices */ + poolSkinIndex.m_poolToSkinIndex[curPoolIdx] = sv.second->iSkin; + ++curPoolIdx; + } + + return ret; +} + +} // namespace hecl::blender diff --git a/hecl/lib/Blender/MeshOptimizer.cpp b/hecl/lib/Blender/MeshOptimizer.cpp new file mode 100644 index 000000000..60c5e519f --- /dev/null +++ b/hecl/lib/Blender/MeshOptimizer.cpp @@ -0,0 +1,439 @@ +#include "MeshOptimizer.hpp" + +#include +#include +#include +#include +#include +#include + +namespace hecl::blender { + +logvisor::Module Log("MeshOptimizer"); + +template +static void insert_unique_attr(std::unordered_map& set, const T& attr) { + if (set.find(attr) == set.cend()) { + size_t sz = set.size(); + set.insert(std::make_pair(attr, sz)); + } +} + +template +static std::vector sort_unordered_map(const std::unordered_map& map) { + struct SortableIterator { + typename std::unordered_map::const_iterator it; + bool operator<(const SortableIterator& other) const { return it->second < other.it->second; } + explicit SortableIterator(typename std::unordered_map::const_iterator i) : it(i) {} + }; + std::vector to_sort; + to_sort.reserve(map.size()); + for (auto I = map.cbegin(), E = map.cend(); I != E; ++I) + to_sort.emplace_back(I); + std::sort(to_sort.begin(), to_sort.end()); + std::vector ret; + ret.reserve(to_sort.size()); + for (const auto& sit : to_sort) + ret.push_back(sit.it->first); + return ret; +} + +static bool material_is_lightmapped(const Material& mat) { + auto search = mat.iprops.find("retro_lightmapped"); + if (search != mat.iprops.cend()) + return search->second; + return false; +} + +MeshOptimizer::Vertex::Vertex(Connection& conn) { + co.read(conn); + uint32_t skin_count; + conn._readValue(skin_count); + if (skin_count > MaxSkinEntries) + Log.report(logvisor::Fatal, FMT_STRING("Skin entry overflow {}/{}"), skin_count, MaxSkinEntries); + for (uint32_t i = 0; i < skin_count; ++i) + skin_ents[i] = Mesh::SkinBind(conn); +} + +MeshOptimizer::Loop::Loop(Connection& conn, uint32_t color_count, uint32_t uv_count) { + normal.read(conn); + for (uint32_t i = 0; i < color_count; ++i) + colors[i].read(conn); + for (uint32_t i = 0; i < uv_count; ++i) + uvs[i].read(conn); + conn._readValue(vert); + conn._readValue(edge); + conn._readValue(face); + conn._readValue(link_loop_next); + conn._readValue(link_loop_prev); + conn._readValue(link_loop_radial_next); + conn._readValue(link_loop_radial_prev); +} + +MeshOptimizer::Edge::Edge(Connection& conn) { + for (uint32_t i = 0; i < 2; ++i) + conn._readValue(verts[i]); + uint32_t face_count; + conn._readValue(face_count); + if (face_count > MaxLinkFaces) + Log.report(logvisor::Fatal, FMT_STRING("Face overflow {}/{}"), face_count, MaxLinkFaces); + for (uint32_t i = 0; i < face_count; ++i) + conn._readValue(link_faces[i]); + conn._readValue(is_contiguous); +} + +MeshOptimizer::Face::Face(Connection& conn) { + normal.read(conn); + centroid.read(conn); + conn._readValue(material_index); + for (uint32_t i = 0; i < 3; ++i) + conn._readValue(loops[i]); +} + +uint32_t MeshOptimizer::get_pos_idx(const Vertex& v) const { + auto search = b_pos.find(v.co); + if (search != b_pos.cend()) + return search->second; + return UINT32_MAX; +} + +uint32_t MeshOptimizer::get_norm_idx(const Loop& l) const { + auto search = b_norm.find(l.normal); + if (search != b_norm.cend()) + return search->second; + return UINT32_MAX; +} + +uint32_t MeshOptimizer::get_skin_idx(const Vertex& v) const { + auto search = b_skin.find(v.skin_ents); + if (search != b_skin.cend()) + return search->second; + return UINT32_MAX; +} + +uint32_t MeshOptimizer::get_color_idx(const Loop& l, uint32_t cidx) const { + auto search = b_color.find(l.colors[cidx]); + if (search != b_color.cend()) + return search->second; + return UINT32_MAX; +} + +uint32_t MeshOptimizer::get_uv_idx(const Loop& l, uint32_t uidx) const { + if (use_luvs && uidx == 0 && material_is_lightmapped(materials[faces[l.face].material_index])) { + auto search = b_luv.find(l.uvs[0]); + if (search != b_luv.cend()) + return search->second; + return UINT32_MAX; + } + auto search = b_uv.find(l.uvs[uidx]); + if (search != b_uv.cend()) + return search->second; + return UINT32_MAX; +} + +bool MeshOptimizer::loops_contiguous(const Loop& la, const Loop& lb) const { + if (la.vert != lb.vert) + return false; + if (get_norm_idx(la) != get_norm_idx(lb)) + return false; + for (uint32_t i = 0; i < color_count; ++i) + if (get_color_idx(la, i) != get_color_idx(lb, i)) + return false; + for (uint32_t i = 0; i < uv_count; ++i) + if (get_uv_idx(la, i) != get_uv_idx(lb, i)) + return false; + return true; +} + +bool MeshOptimizer::splitable_edge(const Edge& e) const { + if (!e.is_contiguous) + return false; + for (uint32_t vidx : e.verts) { + const Loop* found = nullptr; + for (uint32_t fidx : e.link_faces) { + for (uint32_t lidx : faces[fidx].loops) { + if (loops[lidx].vert == vidx) { + if (!found) { + found = &loops[lidx]; + break; + } else { + if (!loops_contiguous(*found, loops[lidx])) + return true; + break; + } + } + } + } + } + return false; +} + +void MeshOptimizer::sort_faces_by_skin_group(std::vector& sfaces) const { + std::vector faces_out; + faces_out.reserve(sfaces.size()); + std::unordered_set done_sg; + uint32_t ref_sg = UINT32_MAX; + while (faces_out.size() < sfaces.size()) { + for (uint32_t f : sfaces) { + bool found = false; + for (uint32_t l : faces[f].loops) { + uint32_t skin_idx = get_skin_idx(verts[loops[l].vert]); + if (done_sg.find(skin_idx) == done_sg.end()) { + ref_sg = skin_idx; + done_sg.insert(skin_idx); + found = true; + break; + } + } + if (found) + break; + } + for (uint32_t f : sfaces) { + if (std::find(faces_out.begin(), faces_out.end(), f) != faces_out.end()) + continue; + for (uint32_t l : faces[f].loops) { + uint32_t skin_idx = get_skin_idx(verts[loops[l].vert]); + if (skin_idx == ref_sg) { + faces_out.push_back(f); + break; + } + } + } + } + sfaces = std::move(faces_out); +} + +std::pair MeshOptimizer::strip_next_loop(uint32_t prev_loop, uint32_t out_count) const { + if (out_count & 0x1) { + uint32_t radial_loop = loops[prev_loop].link_loop_radial_next; + uint32_t loop = loops[radial_loop].link_loop_prev; + return {loop, loop}; + } else { + uint32_t radial_loop = loops[prev_loop].link_loop_radial_prev; + uint32_t loop = loops[radial_loop].link_loop_next; + return {loops[loop].link_loop_next, loop}; + } +} + +static float Magnitude(const Vector3f& v) { return std::sqrt(v.val.simd.dot3(v.val.simd)); } +static void Normalize(Vector3f& v) { + float mag = 1.f / Magnitude(v); + v.val.simd *= athena::simd(mag); +} + +Mesh::Surface MeshOptimizer::generate_surface(std::vector& island_faces, uint32_t mat_idx) const { + Mesh::Surface ret = {}; + ret.materialIdx = mat_idx; + + /* Centroid of surface */ + for (const auto& f : island_faces) + ret.centroid.val.simd += faces[f].centroid.val.simd; + ret.centroid.val.simd /= athena::simd(island_faces.size()); + + /* AABB of surface */ + ret.aabbMin.val.simd = athena::simd(FLT_MAX); + ret.aabbMax.val.simd = athena::simd(-FLT_MAX); + for (const auto& f : island_faces) { + for (const auto l : faces[f].loops) { + const Vertex& v = verts[loops[l].vert]; + for (int c = 0; c < 3; ++c) { + if (v.co.val.simd[c] < ret.aabbMin.val.simd[c]) + ret.aabbMin.val.simd[c] = v.co.val.simd[c]; + if (v.co.val.simd[c] > ret.aabbMax.val.simd[c]) + ret.aabbMax.val.simd[c] = v.co.val.simd[c]; + } + } + } + + /* Average normal of surface */ + for (const auto& f : island_faces) + ret.reflectionNormal.val.simd += faces[f].normal.val.simd; + Normalize(ret.reflectionNormal); + + /* Verts themselves */ + uint32_t prev_loop_emit = UINT32_MAX; + std::vector, std::vector>> sel_lists_local; + sel_lists_local.reserve(loops.size()); + while (island_faces.size()) { + sel_lists_local.clear(); + for (uint32_t start_face : island_faces) { + for (uint32_t l : faces[start_face].loops) { + std::vector island_local(island_faces); + uint32_t prev_loop = loops[l].link_loop_next; + uint32_t loop = loops[prev_loop].link_loop_next; + std::vector sel_list; + sel_list.reserve(64); + sel_list.push_back(l); + sel_list.push_back(prev_loop); + sel_list.push_back(loop); + island_local.erase(std::find(island_local.begin(), island_local.end(), start_face)); + while (true) { + const Edge& prev_edge = edges[loops[prev_loop].edge]; + if (!prev_edge.is_contiguous || prev_edge.tag) + break; + std::tie(loop, prev_loop) = strip_next_loop(prev_loop, sel_list.size()); + uint32_t face = loops[loop].face; + auto search = std::find(island_local.begin(), island_local.end(), face); + if (search == island_local.end()) + break; + sel_list.push_back(loop); + island_local.erase(search); + } + sel_lists_local.emplace_back(std::move(sel_list), std::move(island_local)); + } + } + uint32_t max_count = 0; + const std::vector* max_sl = nullptr; + const std::vector* max_island_faces = nullptr; + for (const auto& sl : sel_lists_local) { + if (sl.first.size() > max_count) { + max_count = sl.first.size(); + max_sl = &sl.first; + max_island_faces = &sl.second; + } + } + assert(max_island_faces && "Should not be null"); + assert(max_island_faces->size() < island_faces.size() && "Infinite loop condition"); + island_faces = std::move(*max_island_faces); + if (prev_loop_emit != UINT32_MAX) + ret.verts.emplace_back(); + for (uint32_t loop : *max_sl) { + ret.verts.emplace_back(); + const auto& l = loops[loop]; + auto& vert = ret.verts.back(); + vert.iPos = get_pos_idx(verts[l.vert]); + vert.iNorm = get_norm_idx(l); + for (uint32_t i = 0; i < color_count; ++i) + vert.iColor[i] = get_color_idx(l, i); + for (uint32_t i = 0; i < uv_count; ++i) + vert.iUv[i] = get_uv_idx(l, i); + vert.iSkin = get_skin_idx(verts[l.vert]); + prev_loop_emit = loop; + } + } + + return ret; +} + +void MeshOptimizer::optimize(Mesh& mesh, int max_skin_banks) const { + mesh.topology = HMDLTopology::TriStrips; + + mesh.pos = sort_unordered_map(b_pos); + mesh.norm = sort_unordered_map(b_norm); + mesh.colorLayerCount = color_count; + mesh.color = sort_unordered_map(b_color); + mesh.uvLayerCount = uv_count; + mesh.uv = sort_unordered_map(b_uv); + mesh.luv = sort_unordered_map(b_luv); + mesh.skins = sort_unordered_map(b_skin); + + /* Sort materials by pass index */ + std::vector sorted_material_idxs(materials.size()); + std::iota(sorted_material_idxs.begin(), sorted_material_idxs.end(), 0); + std::sort(sorted_material_idxs.begin(), sorted_material_idxs.end(), + [this](uint32_t a, uint32_t b) { return materials[a].passIndex < materials[b].passIndex; }); + + /* Generate island surfaces */ + std::vector mat_faces_rem, the_list; + mat_faces_rem.reserve(faces.size()); + the_list.reserve(faces.size()); + std::unordered_set skin_slot_set; + skin_slot_set.reserve(b_skin.size()); + for (uint32_t mat_idx : sorted_material_idxs) { + const auto& mat = materials[mat_idx]; + mat_faces_rem.clear(); + for (auto B = faces.begin(), I = B, E = faces.end(); I != E; ++I) { + if (I->material_index == mat_idx) + mat_faces_rem.push_back(I - B); + } + if (b_skin.size()) + sort_faces_by_skin_group(mat_faces_rem); + size_t rem_count = mat_faces_rem.size(); + while (rem_count) { + the_list.clear(); + skin_slot_set.clear(); + for (uint32_t& f : mat_faces_rem) { + if (f == UINT32_MAX) + continue; + if (b_skin.size()) { + bool brk = false; + for (const auto l : faces[f].loops) { + const Vertex& v = verts[loops[l].vert]; + uint32_t skin_idx = get_skin_idx(v); + if (skin_slot_set.find(skin_idx) == skin_slot_set.end()) { + if (max_skin_banks > 0 && skin_slot_set.size() == size_t(max_skin_banks)) { + brk = true; + break; + } + skin_slot_set.insert(skin_idx); + } + } + if (brk) + break; + } + the_list.push_back(f); + f = UINT32_MAX; + --rem_count; + } + mesh.surfaces.push_back(generate_surface(the_list, mat_idx)); + } + } +} + +MeshOptimizer::MeshOptimizer(Connection& conn, const std::vector& materials, bool use_luvs) +: materials(materials), use_luvs(use_luvs) { + conn._readValue(color_count); + if (color_count > MaxColorLayers) + Log.report(logvisor::Fatal, FMT_STRING("Color layer overflow {}/{}"), color_count, MaxColorLayers); + conn._readValue(uv_count); + if (uv_count > MaxUVLayers) + Log.report(logvisor::Fatal, FMT_STRING("UV layer overflow {}/{}"), uv_count, MaxUVLayers); + + /* Simultaneously load topology objects and build unique mapping indices */ + + uint32_t vert_count; + conn._readValue(vert_count); + verts.reserve(vert_count); + b_pos.reserve(vert_count); + b_skin.reserve(vert_count * 4); + for (uint32_t i = 0; i < vert_count; ++i) { + verts.emplace_back(conn); + insert_unique_attr(b_pos, verts.back().co); + if (verts.back().skin_ents[0].valid()) + insert_unique_attr(b_skin, verts.back().skin_ents); + } + + uint32_t loop_count; + conn._readValue(loop_count); + loops.reserve(loop_count); + b_norm.reserve(loop_count); + if (use_luvs) { + b_uv.reserve(std::max(int(loop_count) - 1, 0) * uv_count); + b_luv.reserve(loop_count); + } else { + b_uv.reserve(loop_count * uv_count); + } + for (uint32_t i = 0; i < loop_count; ++i) { + loops.emplace_back(conn, color_count, uv_count); + insert_unique_attr(b_norm, loops.back().normal); + for (const auto& c : loops.back().colors) + insert_unique_attr(b_color, c); + if (use_luvs && material_is_lightmapped(materials[faces[loops.back().face].material_index])) { + insert_unique_attr(b_luv, loops.back().uvs[0]); + for (auto I = std::begin(loops.back().uvs) + 1, E = std::end(loops.back().uvs); I != E; ++I) + insert_unique_attr(b_uv, *I); + } else { + for (const auto& c : loops.back().uvs) + insert_unique_attr(b_uv, c); + } + } + + conn._readVector(edges); + conn._readVector(faces); + + /* Cache edges that should block tristrip traversal */ + for (auto& e : edges) + e.tag = splitable_edge(e); +} + +} diff --git a/hecl/lib/Blender/MeshOptimizer.hpp b/hecl/lib/Blender/MeshOptimizer.hpp new file mode 100644 index 000000000..af8e4bb3a --- /dev/null +++ b/hecl/lib/Blender/MeshOptimizer.hpp @@ -0,0 +1,117 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "hecl/Blender/Connection.hpp" + +namespace hecl::blender { + +template +class IndexArray { + std::array arr; +public: + IndexArray() { std::fill(arr.begin(), arr.end(), UINT32_MAX); } + class const_iterator { + typename std::array::const_iterator it; + public: + explicit const_iterator(typename std::array::const_iterator i) : it(i) {} + bool operator==(const_iterator other) const { return it == other.it; } + bool operator!=(const_iterator other) const { return it != other.it; } + const_iterator& operator++() { ++it; return *this; } + uint32_t operator*() const { return *it; } + }; + const_iterator begin() const { return const_iterator(arr.cbegin()); } + const_iterator end() const { + typename std::array::const_iterator I, E; + for (I = arr.cbegin(), E = arr.cend(); I != E && *I != UINT32_MAX; ++I) {} + return const_iterator(I); + } + uint32_t& operator[](size_t idx) { return arr[idx]; } + const uint32_t& operator[](size_t idx) const { return arr[idx]; } + static constexpr size_t capacity() { return S; } + size_t size() const { return end() - begin(); } +}; + +class MeshOptimizer { + static constexpr size_t MaxColorLayers = Mesh::MaxColorLayers; + static constexpr size_t MaxUVLayers = Mesh::MaxUVLayers; + static constexpr size_t MaxSkinEntries = Mesh::MaxSkinEntries; + + const std::vector& materials; + bool use_luvs; + + uint32_t color_count; + uint32_t uv_count; + + struct Vertex { + Vector3f co = {}; + std::array skin_ents = {}; + explicit Vertex(Connection& conn); + }; + std::vector verts; + + struct Loop { + Vector3f normal = {}; + std::array colors = {}; + std::array uvs = {}; + uint32_t vert = UINT32_MAX; + uint32_t edge = UINT32_MAX; + uint32_t face = UINT32_MAX; + uint32_t link_loop_next = UINT32_MAX; + uint32_t link_loop_prev = UINT32_MAX; + uint32_t link_loop_radial_next = UINT32_MAX; + uint32_t link_loop_radial_prev = UINT32_MAX; + explicit Loop(Connection& conn, uint32_t color_count, uint32_t uv_count); + }; + std::vector loops; + + struct Edge { + static constexpr size_t MaxLinkFaces = 8; + IndexArray<2> verts; + IndexArray link_faces; + bool is_contiguous = false; + bool tag = false; + explicit Edge(Connection& conn); + }; + std::vector edges; + + struct Face { + Vector3f normal = {}; + Vector3f centroid = {}; + uint32_t material_index = UINT32_MAX; + IndexArray<3> loops; + explicit Face(Connection& conn); + }; + std::vector faces; + + std::unordered_map b_pos; + std::unordered_map b_norm; + std::unordered_map, uint32_t> b_skin; + std::unordered_map b_color; + std::unordered_map b_uv; + std::unordered_map b_luv; + + uint32_t get_pos_idx(const Vertex& v) const; + uint32_t get_norm_idx(const Loop& l) const; + uint32_t get_skin_idx(const Vertex& v) const; + uint32_t get_color_idx(const Loop& l, uint32_t cidx) const; + uint32_t get_uv_idx(const Loop& l, uint32_t uidx) const; + void sort_faces_by_skin_group(std::vector& faces) const; + std::pair strip_next_loop(uint32_t prev_loop, uint32_t out_count) const; + + bool loops_contiguous(const Loop& la, const Loop& lb) const; + bool splitable_edge(const Edge& e) const; + Mesh::Surface generate_surface(std::vector& island_faces, uint32_t mat_idx) const; + +public: + explicit MeshOptimizer(Connection& conn, const std::vector& materials, bool use_luvs); + void optimize(Mesh& mesh, int max_skin_banks) const; +}; + +} \ No newline at end of file diff --git a/hecl/lib/Blender/SDNARead.cpp b/hecl/lib/Blender/SDNARead.cpp new file mode 100644 index 000000000..da769eeab --- /dev/null +++ b/hecl/lib/Blender/SDNARead.cpp @@ -0,0 +1,190 @@ +#include "hecl/Blender/SDNARead.hpp" + +#include +#include + +#include "hecl/hecl.hpp" + +#include +#include + +#include + +namespace hecl::blender { + +void SDNABlock::SDNAStruct::computeOffsets(const SDNABlock& block) { + atUint32 offset = 0; + for (SDNAField& f : fields) { + const auto& name = block.names[f.name]; + f.offset = offset; + if (name.front() == '*') { + offset += 8; + } else { + atUint32 length = block.tlens[f.type]; + auto bracket = name.find('['); + if (bracket != std::string::npos) + length *= strtoul(name.data() + bracket + 1, nullptr, 10); + offset += length; + } + } +} + +const SDNABlock::SDNAStruct::SDNAField* SDNABlock::SDNAStruct::lookupField(const SDNABlock& block, + const char* n) const { + for (const SDNAField& field : fields) { + const auto& name = block.names[field.name]; + auto bracket = name.find('['); + if (bracket != std::string::npos) { + if (!name.compare(0, bracket, n)) + return &field; + } else if (name == n) + return &field; + } + return nullptr; +} + +const SDNABlock::SDNAStruct* SDNABlock::lookupStruct(const char* n, atUint32& idx) const { + idx = 0; + for (const SDNAStruct& strc : strcs) { + const auto& name = types[strc.type]; + if (name == n) + return &strc; + ++idx; + } + return nullptr; +} + +void SDNARead::enumerate(const std::function& func) const { + athena::io::MemoryReader r(m_data.data(), m_data.size()); + r.seek(12); + while (r.position() < r.length()) { + FileBlock block; + block.read(r); + if (block.type == FOURCC('ENDB')) + break; + athena::io::MemoryReader r2(m_data.data() + r.position(), block.size); + if (!func(block, r2)) + break; + r.seek(block.size); + } +} + +SDNARead::SDNARead(SystemStringView path) { + athena::io::FileReader r(path); + if (r.hasError()) + return; + + atUint64 length = r.length(); + char magicBuf[7]; + r.readUBytesToBuf(magicBuf, 7); + r.seek(0, athena::SeekOrigin::Begin); + if (strncmp(magicBuf, "BLENDER", 7)) { + /* Try gzip decompression */ + std::unique_ptr compBuf(new uint8_t[4096]); + m_data.resize((length * 2 + 4095) & ~4095); + z_stream zstrm = {}; + inflateInit2(&zstrm, 16 + MAX_WBITS); + zstrm.next_out = (Bytef*)m_data.data(); + zstrm.avail_out = m_data.size(); + zstrm.total_out = 0; + + atUint64 rs; + while ((rs = r.readUBytesToBuf(compBuf.get(), 4096))) { + int inflateRet; + zstrm.next_in = compBuf.get(); + zstrm.avail_in = rs; + while (zstrm.avail_in) { + if (!zstrm.avail_out) { + zstrm.avail_out = m_data.size(); + m_data.resize(zstrm.avail_out * 2); + zstrm.next_out = (Bytef*)m_data.data() + zstrm.avail_out; + } + inflateRet = inflate(&zstrm, Z_NO_FLUSH); + if (inflateRet == Z_STREAM_END) + break; + if (inflateRet != Z_OK) { + inflateEnd(&zstrm); + m_data = std::vector(); + return; + } + } + if (inflateRet == Z_STREAM_END) + break; + } + + inflateEnd(&zstrm); + + if (strncmp((char*)m_data.data(), "BLENDER", 7)) { + m_data = std::vector(); + return; + } + } else { + m_data.resize(length); + r.readUBytesToBuf(m_data.data(), length); + } + + enumerate([this](const FileBlock& block, athena::io::MemoryReader& r) { + if (block.type == FOURCC('DNA1')) { + m_sdnaBlock.read(r); + for (SDNABlock::SDNAStruct& s : m_sdnaBlock.strcs) + s.computeOffsets(m_sdnaBlock); + return false; + } + return true; + }); +} + +BlendType GetBlendType(SystemStringView path) { + SDNARead r(path); + if (!r) + return BlendType::None; + + atUint32 idPropIdx; + const auto* idPropStruct = r.sdnaBlock().lookupStruct("IDProperty", idPropIdx); + if (!idPropStruct) + return BlendType::None; + const auto* typeField = idPropStruct->lookupField(r.sdnaBlock(), "type"); + if (!typeField) + return BlendType::None; + atUint32 typeOffset = typeField->offset; + const auto* nameField = idPropStruct->lookupField(r.sdnaBlock(), "name"); + if (!nameField) + return BlendType::None; + atUint32 nameOffset = nameField->offset; + const auto* dataField = idPropStruct->lookupField(r.sdnaBlock(), "data"); + if (!dataField) + return BlendType::None; + atUint32 dataOffset = dataField->offset; + + atUint32 idPropDataIdx; + const auto* idPropDataStruct = r.sdnaBlock().lookupStruct("IDPropertyData", idPropDataIdx); + if (!idPropDataStruct) + return BlendType::None; + const auto* valField = idPropDataStruct->lookupField(r.sdnaBlock(), "val"); + if (!valField) + return BlendType::None; + atUint32 valOffset = dataOffset + valField->offset; + + BlendType ret = BlendType::None; + r.enumerate( + [idPropIdx, typeOffset, nameOffset, valOffset, &ret](const FileBlock& block, athena::io::MemoryReader& r) { + if (block.type == FOURCC('DATA') && block.sdnaIdx == idPropIdx) { + r.seek(typeOffset, athena::SeekOrigin::Begin); + if (r.readUByte() != 1) + return true; + + r.seek(nameOffset, athena::SeekOrigin::Begin); + if (r.readString() != "hecl_type") + return true; + + r.seek(valOffset, athena::SeekOrigin::Begin); + ret = BlendType(r.readUint32Little()); + return false; + } + return true; + }); + + return ret; +} + +} // namespace hecl::blender diff --git a/hecl/lib/CMakeLists.txt b/hecl/lib/CMakeLists.txt new file mode 100644 index 000000000..b6a2d4419 --- /dev/null +++ b/hecl/lib/CMakeLists.txt @@ -0,0 +1,84 @@ +macro(hecl_add_list rel_path a_list) + unset(tmp_list) + foreach(path IN LISTS ${a_list}) + list(APPEND tmp_list "${rel_path}/${path}") + endforeach(path) + set(${a_list} "${tmp_list}" PARENT_SCOPE) +endmacro(hecl_add_list) + +add_subdirectory(Blender) +add_subdirectory(Runtime) + +if(WIN32) +list(APPEND PLAT_SRCS ../include/hecl/winsupport.hpp) +endif() + +if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + add_definitions(-DHECL_MULTIPROCESSOR) +endif() + +set(HECL_HEADERS + ../include/hecl/CVar.hpp + ../include/hecl/CVarManager.hpp + ../include/hecl/CVarCommons.hpp + ../include/hecl/hecl.hpp + ../include/hecl/MultiProgressPrinter.hpp + ../include/hecl/FourCC.hpp + ../include/hecl/TypedVariant.hpp + ../include/hecl/Backend.hpp + ../include/hecl/Blender/Connection.hpp + ../include/hecl/Blender/SDNARead.hpp + ../include/hecl/Blender/Token.hpp + ../include/hecl/SteamFinder.hpp + ../include/hecl/Database.hpp + ../include/hecl/Runtime.hpp + ../include/hecl/ClientProcess.hpp + ../include/hecl/SystemChar.hpp + ../include/hecl/BitVector.hpp + ../include/hecl/MathExtras.hpp) +set(COMMON_SOURCES + hecl.cpp + MultiProgressPrinter.cpp + Project.cpp + ProjectPath.cpp + HumanizeNumber.cpp + CVar.cpp + CVarCommons.cpp + CVarManager.cpp + ClientProcess.cpp + SteamFinder.cpp + WideStringConvert.cpp) + +if(UNIX) + list(APPEND PLAT_SRCS closefrom.c) +endif() + +add_library(hecl-full + ${FRONTEND_SOURCES} + ${RUNTIME_SOURCES} + ${BLENDER_SOURCES} + ${COMMON_SOURCES} + ${HECL_HEADERS} + ${PLAT_SRCS} + Pipeline.cpp) +target_include_directories(hecl-full PUBLIC ../include) +target_link_libraries(hecl-full PUBLIC + hecl-blender-addon xxhash hsh athena-core logvisor) +target_atdna(hecl-full atdna_HMDLMeta_full.cpp ../include/hecl/HMDLMeta.hpp) +target_atdna(hecl-full atdna_CVar_full.cpp ../include/hecl/CVar.hpp) +target_atdna(hecl-full atdna_SDNARead_full.cpp ../include/hecl/Blender/SDNARead.hpp) + +add_library(hecl-light + ${RUNTIME_SOURCES} + ${COMMON_SOURCES} + ${HECL_HEADERS} + ${PLAT_SRCS}) +target_include_directories(hecl-light PUBLIC ../include) +target_link_libraries(hecl-light PUBLIC xxhash hsh athena-core logvisor) +target_atdna(hecl-light atdna_HMDLMeta_light.cpp ../include/hecl/HMDLMeta.hpp) +target_atdna(hecl-light atdna_CVar_light.cpp ../include/hecl/CVar.hpp) + +if(COMMAND add_sanitizers) + add_sanitizers(hecl-full) + add_sanitizers(hecl-light) +endif() diff --git a/hecl/lib/CVar.cpp b/hecl/lib/CVar.cpp new file mode 100644 index 000000000..e323b4a32 --- /dev/null +++ b/hecl/lib/CVar.cpp @@ -0,0 +1,556 @@ +#include "hecl/CVar.hpp" + +#include + +#include "hecl/CVarManager.hpp" +#include "hecl/hecl.hpp" + +#include + +namespace hecl { +extern CVar* com_developer; +extern CVar* com_enableCheats; + +using namespace std::literals; + +CVar::CVar(std::string_view name, std::string_view value, std::string_view help, CVar::EFlags flags) +: CVar(name, help, EType::Literal) { + fromLiteral(value); + init(flags); +} + +CVar::CVar(std::string_view name, const atVec2f& value, std::string_view help, EFlags flags) +: CVar(name, help, EType::Vec2f) { + fromVec2f(value); + init(flags); +} + +CVar::CVar(std::string_view name, const atVec2d& value, std::string_view help, EFlags flags) +: CVar(name, help, EType::Vec2d) { + fromVec2d(value); + + init(flags); +} + +CVar::CVar(std::string_view name, const atVec3f& value, std::string_view help, EFlags flags) +: CVar(name, help, EType::Vec3f) { + fromVec3f(value); + init(flags, false); +} + +CVar::CVar(std::string_view name, const atVec3d& value, std::string_view help, EFlags flags) +: CVar(name, help, EType::Vec3d) { + fromVec3d(value); + init(flags, false); +} + +CVar::CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags) +: CVar(name, help, EType::Vec4f) { + fromVec4f(value); + init(flags, false); +} + +CVar::CVar(std::string_view name, const atVec4d& value, std::string_view help, EFlags flags) +: CVar(name, help, EType::Vec4d) { + fromVec4d(value); + init(flags, false); +} + +CVar::CVar(std::string_view name, double value, std::string_view help, EFlags flags) : CVar(name, help, EType::Real) { + fromReal(value); + init(flags); +} + +CVar::CVar(std::string_view name, bool value, std::string_view help, CVar::EFlags flags) +: CVar(name, help, EType::Boolean) { + fromBoolean(value); + init(flags); +} + +CVar::CVar(std::string_view name, int32_t value, std::string_view help, CVar::EFlags flags) +: CVar(name, help, EType::Signed) { + fromInteger(value); + init(flags); +} + +CVar::CVar(std::string_view name, uint32_t value, std::string_view help, CVar::EFlags flags) +: CVar(name, help, EType::Unsigned) { + fromInteger(value); + init(flags); +} + +std::string CVar::help() const { + return m_help + (m_defaultValue.empty() ? "" : "\ndefault: " + m_defaultValue) + (isReadOnly() ? " [ReadOnly]" : ""); +} + +atVec2f CVar::toVec2f(bool* isValid) const { + if (m_type != EType::Vec2f) { + if (isValid != nullptr) + *isValid = false; + + return atVec2f{}; + } + + if (isValid != nullptr) + *isValid = true; + + atVec2f vec{}; + athena::simd_floats f; + std::sscanf(m_value.c_str(), "%g %g", &f[0], &f[1]); + vec.simd.copy_from(f); + + return vec; +} + +atVec2d CVar::toVec2d(bool* isValid) const { + if (m_type != EType::Vec2d) { + if (isValid != nullptr) + *isValid = false; + + return atVec2d{}; + } + + if (isValid != nullptr) + *isValid = true; + + atVec2d vec{}; + athena::simd_doubles f; + std::sscanf(m_value.c_str(), "%lg %lg", &f[0], &f[1]); + vec.simd.copy_from(f); + + return vec; +} + +atVec3f CVar::toVec3f(bool* isValid) const { + if (m_type != EType::Vec3f) { + if (isValid != nullptr) + *isValid = false; + + return atVec3f{}; + } + + if (isValid != nullptr) + *isValid = true; + + atVec3f vec{}; + athena::simd_floats f; + std::sscanf(m_value.c_str(), "%g %g %g", &f[0], &f[1], &f[2]); + vec.simd.copy_from(f); + + return vec; +} + +atVec3d CVar::toVec3d(bool* isValid) const { + if (m_type != EType::Vec3d) { + if (isValid != nullptr) + *isValid = false; + + return atVec3d{}; + } + + if (isValid != nullptr) + *isValid = true; + + atVec3d vec{}; + athena::simd_doubles f; + std::sscanf(m_value.c_str(), "%lg %lg %lg", &f[0], &f[1], &f[2]); + vec.simd.copy_from(f); + + return vec; +} + +atVec4f CVar::toVec4f(bool* isValid) const { + if (m_type != EType::Vec4f) { + if (isValid != nullptr) + *isValid = false; + + return atVec4f{}; + } + + if (isValid != nullptr) + *isValid = true; + + atVec4f vec{}; + athena::simd_floats f; + std::sscanf(m_value.c_str(), "%g %g %g %g", &f[0], &f[1], &f[2], &f[3]); + vec.simd.copy_from(f); + + return vec; +} + +atVec4d CVar::toVec4d(bool* isValid) const { + if (m_type != EType::Vec4d) { + if (isValid != nullptr) + *isValid = false; + + return atVec4d{}; + } + + if (isValid != nullptr) + *isValid = true; + + atVec4d vec{}; + athena::simd_doubles f; + std::sscanf(m_value.c_str(), "%lg %lg %lg %lg", &f[0], &f[1], &f[2], &f[3]); + vec.simd.copy_from(f); + + return vec; +} + +double CVar::toReal(bool* isValid) const { + if (m_type != EType::Real) { + if (isValid) + *isValid = false; + return 0.0f; + } + + if (isValid != nullptr) + *isValid = true; + + return strtod(m_value.c_str(), nullptr); +} + +bool CVar::toBoolean(bool* isValid) const { + if (m_type != EType::Boolean) { + if (isValid) + *isValid = false; + + return false; + } + + if (isValid != nullptr) + *isValid = true; + + return athena::utility::parseBool(m_value); +} + +int32_t CVar::toSigned(bool* isValid) const { + if (m_type != EType::Signed && m_type != EType::Unsigned) { + if (isValid) + *isValid = false; + return 0; + } + + if (isValid != nullptr) + *isValid = true; + + return strtol(m_value.c_str(), nullptr, 0); +} + +uint32_t CVar::toUnsigned(bool* isValid) const { + if (m_type != EType::Signed && m_type != EType::Unsigned) { + if (isValid) + *isValid = false; + return 0; + } + + if (isValid != nullptr) + *isValid = true; + + return strtoul(m_value.c_str(), nullptr, 0); +} + +std::string CVar::toLiteral(bool* isValid) const { + if (m_type != EType::Literal && (com_developer && com_developer->toBoolean())) { + if (isValid != nullptr) + *isValid = false; + } else if (isValid != nullptr) { + *isValid = true; + } + + // Even if it's not a literal, it's still safe to return + return m_value; +} + +std::wstring CVar::toWideLiteral(bool* isValid) const { + if (m_type != EType::Literal && (com_developer && com_developer->toBoolean())) { + if (isValid != nullptr) + *isValid = false; + } else if (isValid != nullptr) { + *isValid = true; + } + + // Even if it's not a literal, it's still safe to return + return hecl::UTF8ToWide(m_value); +} + +bool CVar::fromVec2f(const atVec2f& val) { + if (!safeToModify(EType::Vec2f)) + return false; + + athena::simd_floats f(val.simd); + m_value.assign(fmt::format(FMT_STRING("{} {}"), f[0], f[1])); + m_flags |= EFlags::Modified; + return true; +} + +bool CVar::fromVec2d(const atVec2d& val) { + if (!safeToModify(EType::Vec2d)) + return false; + + athena::simd_doubles f(val.simd); + m_value.assign(fmt::format(FMT_STRING("{} {}"), f[0], f[1])); + m_flags |= EFlags::Modified; + return true; +} + +bool CVar::fromVec3f(const atVec3f& val) { + if (!safeToModify(EType::Vec3f)) + return false; + + athena::simd_floats f(val.simd); + m_value.assign(fmt::format(FMT_STRING("{} {} {}"), f[0], f[1], f[2])); + m_flags |= EFlags::Modified; + return true; +} + +bool CVar::fromVec3d(const atVec3d& val) { + if (!safeToModify(EType::Vec3d)) + return false; + + athena::simd_doubles f(val.simd); + m_value.assign(fmt::format(FMT_STRING("{} {} {}"), f[0], f[1], f[2])); + m_flags |= EFlags::Modified; + return true; +} + +bool CVar::fromVec4f(const atVec4f& val) { + if (!safeToModify(EType::Vec4f)) + return false; + + athena::simd_floats f(val.simd); + m_value.assign(fmt::format(FMT_STRING("{} {} {} {}"), f[0], f[1], f[2], f[3])); + m_flags |= EFlags::Modified; + return true; +} + +bool CVar::fromVec4d(const atVec4d& val) { + if (!safeToModify(EType::Vec4d)) + return false; + + athena::simd_doubles f(val.simd); + m_value.assign(fmt::format(FMT_STRING("{} {} {} {}"), f[0], f[1], f[2], f[3])); + m_flags |= EFlags::Modified; + return true; +} + +bool CVar::fromReal(double val) { + if (!safeToModify(EType::Real)) + return false; + + m_value.assign(fmt::format(FMT_STRING("{}"), val)); + setModified(); + return true; +} + +bool CVar::fromBoolean(bool val) { + if (!safeToModify(EType::Boolean)) + return false; + + if (val) + m_value = "true"sv; + else + m_value = "false"sv; + + setModified(); + return true; +} + +bool CVar::fromInteger(int32_t val) { + if ((com_developer && com_enableCheats) && (!com_developer->toBoolean() || !com_enableCheats->toBoolean()) && + isCheat()) + return false; + + // We'll accept both signed an unsigned input + if (m_type != EType::Signed && m_type != EType::Unsigned) + return false; + + if (isReadOnly() && (com_developer && !com_developer->toBoolean())) + return false; + + // Properly format based on signedness + m_value = fmt::format(FMT_STRING("{}"), (m_type == EType::Signed ? val : static_cast(val))); + setModified(); + return true; +} + +bool CVar::fromInteger(uint32_t val) { + if ((com_developer && com_enableCheats) && (!com_developer->toBoolean() || !com_enableCheats->toBoolean()) && + isCheat()) + return false; + + // We'll accept both signed an unsigned input + if (m_type != EType::Signed && m_type != EType::Unsigned) + return false; + + if (isReadOnly() && (com_developer && !com_developer->toBoolean())) + return false; + + // Properly format based on signedness + m_value = fmt::format(FMT_STRING("{}"), (m_type == EType::Unsigned ? val : static_cast(val))); + setModified(); + return true; +} + +bool CVar::fromLiteral(std::string_view val) { + if (!safeToModify(EType::Literal)) + return false; + + m_value.assign(val); + setModified(); + return true; +} + +bool CVar::fromLiteral(std::wstring_view val) { + if (!safeToModify(EType::Literal)) + return false; + + m_value.assign(hecl::WideToUTF8(val)); + setModified(); + return true; +} + +bool CVar::fromLiteralToType(std::string_view val) { + if (!safeToModify(m_type) || !isValidInput(val)) + return false; + m_value = val; + setModified(); + return true; +} + +bool CVar::fromLiteralToType(std::wstring_view val) { + return fromLiteralToType(hecl::WideToUTF8(val)); +} + +bool CVar::isModified() const { return True(m_flags & EFlags::Modified); } +bool CVar::modificationRequiresRestart() const { return True(m_flags & EFlags::ModifyRestart); } + +bool CVar::isReadOnly() const { return True(m_flags & EFlags::ReadOnly); } + +bool CVar::isCheat() const { return True(m_flags & EFlags::Cheat); } + +bool CVar::isHidden() const { return True(m_flags & EFlags::Hidden); } + +bool CVar::isArchive() const { return True(m_flags & EFlags::Archive); } + +bool CVar::isInternalArchivable() const { return True(m_flags & EFlags::InternalArchivable); } + +bool CVar::isColor() const { + return True(m_flags & EFlags::Color) && + (m_type == EType::Vec3f || m_type == EType::Vec3d || m_type == EType::Vec3f || m_type == EType::Vec4d); +} + +bool CVar::isNoDeveloper() const { return True(m_flags & EFlags::NoDeveloper); } + +bool CVar::wasDeserialized() const { return m_wasDeserialized; } + +bool CVar::hasDefaultValue() const { return m_defaultValue == m_value; } + +void CVar::clearModified() { + if (!modificationRequiresRestart()) + m_flags &= ~EFlags::Modified; +} + +void CVar::setModified() { m_flags |= EFlags::Modified; } + +void CVar::unlock() { + if (isReadOnly() && !m_unlocked) { + m_oldFlags = m_flags; + m_flags &= ~EFlags::ReadOnly; + m_unlocked = true; + } +} + +void CVar::lock() { + if (!isReadOnly() && m_unlocked) { + m_flags = m_oldFlags; + m_unlocked = false; + } +} + +void CVar::dispatch() { + for (const ListenerFunc& listen : m_listeners) + listen(this); +} + + +bool isReal(std::string_view v) { + char* p; + std::strtod(v.data(), &p); + return *p == 0; +} +bool isReal(const std::vector& v) { + for (auto& s : v) { + if (!isReal(s)) + return false; + } + return true; +} + +bool CVar::isValidInput(std::string_view input) const { + std::vector parts = athena::utility::split(input, ' '); + char* p; + switch(m_type) { + case EType::Boolean: { + bool valid = false; + athena::utility::parseBool(input, &valid); + return valid; + } + case EType::Signed: + std::strtol(input.data(), &p, 0); + return p == nullptr; + case EType::Unsigned: + std::strtoul(input.data(), &p, 0); + return p == nullptr; + case EType::Real: { + bool size = parts.size() == 1; + bool ret = isReal(input); + return ret && size; + } + case EType::Literal: + return true; + case EType::Vec2f: + case EType::Vec2d: + return parts.size() == 2 && isReal(parts); + case EType::Vec3f: + case EType::Vec3d: + return parts.size() == 3 && isReal(parts); + case EType::Vec4f: + case EType::Vec4d: + return parts.size() == 4 && isReal(parts); + } + + return false; +} + +bool CVar::isValidInput(std::wstring_view input) const { + return isValidInput(hecl::WideToUTF8(input)); +} + +bool CVar::safeToModify(EType type) const { + // Are we NoDevelper? + if (isNoDeveloper()) + return false; + + // Are we a cheat? + if (isCheat() && (com_developer && com_enableCheats) && + (!com_developer->toBoolean() || !com_enableCheats->toBoolean())) + return false; + + // Are we read only? + if (isReadOnly() && (com_developer && !com_developer->toBoolean())) + return false; + + return m_type == type; +} + +void CVar::init(EFlags flags, bool removeColor) { + m_defaultValue = m_value; + m_flags = flags; + if (removeColor) { + // If the user specifies color, we don't want it + m_flags &= ~EFlags::Color; + } +} + +} // namespace hecl diff --git a/hecl/lib/CVarCommons.cpp b/hecl/lib/CVarCommons.cpp new file mode 100644 index 000000000..941cba87d --- /dev/null +++ b/hecl/lib/CVarCommons.cpp @@ -0,0 +1,78 @@ +#include "hecl/CVarCommons.hpp" + +namespace hecl { + +namespace { +CVarCommons* m_instance = nullptr; +} + +CVarCommons::CVarCommons(CVarManager& manager) : m_mgr(manager) { + m_fullscreen = m_mgr.findOrMakeCVar("fullscreen"sv, "Start in fullscreen"sv, false, + hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive); + m_graphicsApi = m_mgr.findOrMakeCVar("graphicsApi"sv, "API to use for rendering graphics"sv, DEFAULT_GRAPHICS_API, + hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | + hecl::CVar::EFlags::ModifyRestart); + m_drawSamples = m_mgr.findOrMakeCVar("drawSamples"sv, "Number of MSAA samples to use for render targets"sv, 1, + hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | + hecl::CVar::EFlags::ModifyRestart); + m_texAnisotropy = m_mgr.findOrMakeCVar( + "texAnisotropy"sv, "Number of anisotropic samples to use for sampling textures"sv, 1, + hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart); + m_deepColor = m_mgr.findOrMakeCVar("deepColor"sv, "Allow framebuffer with color depth greater-then 24-bits"sv, false, + hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | + hecl::CVar::EFlags::ModifyRestart); + m_variableDt = m_mgr.findOrMakeCVar( + "variableDt", "Enable variable delta time (experimental)", false, + (hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart)); + + m_debugOverlayPlayerInfo = m_mgr.findOrMakeCVar( + "debugOverlay.playerInfo"sv, "Displays information about the player, such as location and orientation"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugOverlayWorldInfo = m_mgr.findOrMakeCVar( + "debugOverlay.worldInfo"sv, "Displays information about the current world, such as world asset ID, and areaId"sv, + false, hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugOverlayAreaInfo = m_mgr.findOrMakeCVar( + "debugOverlay.areaInfo"sv, + "Displays information about the current area, such as asset ID, object/layer counts, and active layer bits"sv, + false, hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugOverlayShowFrameCounter = + m_mgr.findOrMakeCVar("debugOverlay.showFrameCounter"sv, "Displays the current frame index"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugOverlayShowFramerate = + m_mgr.findOrMakeCVar("debugOverlay.showFramerate"sv, "Displays the current framerate"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugOverlayShowInGameTime = + m_mgr.findOrMakeCVar("debugOverlay.showInGameTime"sv, "Displays the current in game time"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugOverlayShowRoomTimer = m_mgr.findOrMakeCVar( + "debugOverlay.showRoomTimer", "Displays the current/last room timers in seconds and frames"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugOverlayShowResourceStats = m_mgr.findOrMakeCVar( + "debugOverlay.showResourceStats"sv, "Displays the current live resource object and token counts"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugOverlayShowRandomStats = m_mgr.findOrMakeCVar( + "debugOverlay.showRandomStats", "Displays the current number of random calls per frame"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugToolDrawAiPath = + m_mgr.findOrMakeCVar("debugTool.drawAiPath", "Draws the selected paths of any AI in the room"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugToolDrawLighting = m_mgr.findOrMakeCVar("debugTool.drawLighting", "Draws the lighting setup in a room"sv, + false, hecl::CVar::EFlags::Game | hecl::CVar::EFlags::ReadOnly); + m_debugToolDrawCollisionActors = + m_mgr.findOrMakeCVar("debugTool.drawCollisionActors", "Draws the collision actors for enemies and objects"sv, + false, hecl::CVar::EFlags::Game | hecl::CVar::EFlags::ReadOnly); + m_debugToolDrawMazePath = + m_mgr.findOrMakeCVar("debugTool.drawMazePath", "Draws the maze path in Dynamo"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_debugToolDrawPlatformCollision = + m_mgr.findOrMakeCVar("debugTool.drawPlatformCollision", "Draws the bounding boxes of platforms"sv, false, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ReadOnly); + m_logFile = m_mgr.findOrMakeCVar("logFile"sv, "Any log prints will be stored to this file upon exit"sv, "app.log"sv, + hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | + hecl::CVar::EFlags::ModifyRestart); + + m_instance = this; +} + +CVarCommons* CVarCommons::instance() { return m_instance; } +} // namespace hecl \ No newline at end of file diff --git a/hecl/lib/CVarManager.cpp b/hecl/lib/CVarManager.cpp new file mode 100644 index 000000000..712a51270 --- /dev/null +++ b/hecl/lib/CVarManager.cpp @@ -0,0 +1,309 @@ +#include "hecl/CVarManager.hpp" + +#include +#include +#include + +#include "hecl/hecl.hpp" +#include "hecl/Runtime.hpp" + +#include +#include + +namespace hecl { + +CVar* com_developer = nullptr; +CVar* com_configfile = nullptr; +CVar* com_enableCheats = nullptr; +CVar* com_cubemaps = nullptr; + +static const std::regex cmdLineRegex("\\+([\\w\\.]+)=([\\w\\.\\-]+)"); +static const std::regex cmdLineRegexNoValue("\\+([\\w\\.]+)"); +CVarManager* CVarManager::m_instance = nullptr; + +static logvisor::Module CVarLog("CVarManager"); +CVarManager::CVarManager(hecl::Runtime::FileStoreManager& store, bool useBinary) +: m_store(store), m_useBinary(useBinary) { + m_instance = this; + com_configfile = + newCVar("config", "File to store configuration", std::string("config"), + CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::NoDeveloper | CVar::EFlags::Hidden); + com_developer = newCVar("developer", "Enables developer mode", false, + (CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::InternalArchivable)); + com_enableCheats = newCVar( + "cheats", "Enable cheats", false, + (CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::Hidden | CVar::EFlags::InternalArchivable)); + com_cubemaps = newCVar("cubemaps", "Enable cubemaps", false, + (CVar::EFlags::Game | CVar::EFlags::ReadOnly | CVar::EFlags::InternalArchivable)); +} + +CVarManager::~CVarManager() {} + +CVar* CVarManager::registerCVar(std::unique_ptr&& cvar) { + std::string tmp(cvar->name()); + athena::utility::tolower(tmp); + + if (m_cvars.find(tmp) != m_cvars.end()) { + return nullptr; + } + + CVar* ret = cvar.get(); + m_cvars.insert_or_assign(std::move(tmp), std::move(cvar)); + return ret; +} + +CVar* CVarManager::findCVar(std::string_view name) { + std::string lower(name); + athena::utility::tolower(lower); + auto search = m_cvars.find(lower); + if (search == m_cvars.end()) + return nullptr; + + return search->second.get(); +} + +std::vector CVarManager::archivedCVars() const { + std::vector ret; + for (const auto& pair : m_cvars) + if (pair.second->isArchive()) + ret.push_back(pair.second.get()); + + return ret; +} + +std::vector CVarManager::cvars(CVar::EFlags filter) const { + std::vector ret; + for (const auto& pair : m_cvars) + if (filter == CVar::EFlags::Any || True(pair.second->flags() & filter)) + ret.push_back(pair.second.get()); + + return ret; +} + +void CVarManager::deserialize(CVar* cvar) { + /* Make sure we're not trying to deserialize a CVar that is invalid or not exposed, unless it's been specified on the + * command line (i.e deferred) */ + if (!cvar) { + return; + } + + /* First let's check for a deferred value */ + std::string lowName = cvar->name().data(); + athena::utility::tolower(lowName); + if (const auto iter = m_deferedCVars.find(lowName); iter != m_deferedCVars.end()) { + std::string val = std::move(iter->second); + m_deferedCVars.erase(lowName); + if (cvar->isBoolean() && val.empty()) { + // We were deferred without a value, assume true + cvar->fromBoolean(true); + } else if (!val.empty() && cvar->fromLiteralToType(val)) { + return; + } + } + + /* Enforce isArchive and isInternalArchivable now that we've checked if it's been deferred */ + if (!cvar->isArchive() && !cvar->isInternalArchivable()) { + return; + } + + /* We were either unable to find a deferred value or got an invalid value */ +#if _WIN32 + hecl::SystemString filename = + hecl::SystemString(m_store.getStoreRoot()) + _SYS_STR('/') + com_configfile->toWideLiteral(); +#else + hecl::SystemString filename = + hecl::SystemString(m_store.getStoreRoot()) + _SYS_STR('/') + com_configfile->toLiteral(); +#endif + hecl::Sstat st; + + if (m_useBinary) { + CVarContainer container; + filename += _SYS_STR(".bin"); + if (hecl::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode)) + return; + athena::io::FileReader reader(filename); + if (reader.isOpen()) + container.read(reader); + + if (container.cvars.size() > 0) { + auto serialized = std::find_if(container.cvars.begin(), container.cvars.end(), + [&cvar](const DNACVAR::CVar& c) { return c.m_name == cvar->name(); }); + + if (serialized != container.cvars.end()) { + DNACVAR::CVar& tmp = *serialized; + + if (cvar->m_value != tmp.m_value) { + CVarUnlocker lc(cvar); + cvar->fromLiteralToType(tmp.m_value); + cvar->m_wasDeserialized = true; + } + } + } + } else { + filename += _SYS_STR(".yaml"); + if (hecl::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode)) + return; + athena::io::FileReader reader(filename); + if (reader.isOpen()) { + athena::io::YAMLDocReader docReader; + if (docReader.parse(&reader)) { + std::unique_ptr root = docReader.releaseRootNode(); + auto serialized = std::find_if(root->m_mapChildren.begin(), root->m_mapChildren.end(), + [&cvar](const auto& c) { return c.first == cvar->name(); }); + + if (serialized != root->m_mapChildren.end()) { + const std::unique_ptr& tmp = serialized->second; + + if (cvar->m_value != tmp->m_scalarString) { + CVarUnlocker lc(cvar); + cvar->fromLiteralToType(tmp->m_scalarString); + cvar->m_wasDeserialized = true; + } + } + } + } + } +} + +void CVarManager::serialize() { +#if _WIN32 + hecl::SystemString filename = + hecl::SystemString(m_store.getStoreRoot()) + _SYS_STR('/') + com_configfile->toWideLiteral(); +#else + hecl::SystemString filename = + hecl::SystemString(m_store.getStoreRoot()) + _SYS_STR('/') + com_configfile->toLiteral(); +#endif + + if (m_useBinary) { + CVarContainer container; + for (const auto& pair : m_cvars) { + const auto& cvar = pair.second; + + if (cvar->isArchive() || (cvar->isInternalArchivable() && cvar->wasDeserialized() && !cvar->hasDefaultValue())) { + container.cvars.push_back(*cvar); + } + } + container.cvarCount = atUint32(container.cvars.size()); + + filename += _SYS_STR(".bin"); + athena::io::FileWriter writer(filename); + if (writer.isOpen()) + container.write(writer); + } else { + filename += _SYS_STR(".yaml"); + + athena::io::FileReader r(filename); + athena::io::YAMLDocWriter docWriter(r.isOpen() ? &r : nullptr); + r.close(); + + docWriter.setStyle(athena::io::YAMLNodeStyle::Block); + for (const auto& pair : m_cvars) { + const auto& cvar = pair.second; + + if (cvar->isArchive() || (cvar->isInternalArchivable() && cvar->wasDeserialized() && !cvar->hasDefaultValue())) { + docWriter.writeString(cvar->name().data(), cvar->toLiteral()); + } + } + + athena::io::FileWriter w(filename); + if (w.isOpen()) + docWriter.finish(&w); + } +} + +CVarManager* CVarManager::instance() { return m_instance; } + +void CVarManager::setDeveloperMode(bool v, bool setDeserialized) { + com_developer->unlock(); + com_developer->fromBoolean(v); + if (setDeserialized) + com_developer->m_wasDeserialized = true; + com_developer->lock(); + com_developer->setModified(); +} + +void CVarManager::setCheatsEnabled(bool v, bool setDeserialized) { + com_enableCheats->unlock(); + com_enableCheats->fromBoolean(v); + if (setDeserialized) + com_enableCheats->m_wasDeserialized = true; + com_enableCheats->lock(); + com_enableCheats->setModified(); +} + +bool CVarManager::restartRequired() const { + return std::any_of(m_cvars.cbegin(), m_cvars.cend(), [](const auto& entry) { + return entry.second->isModified() && entry.second->modificationRequiresRestart(); + }); +} + +void CVarManager::parseCommandLine(const std::vector& args) { + bool oldDeveloper = suppressDeveloper(); + std::string developerName(com_developer->name()); + athena::utility::tolower(developerName); + for (const SystemString& arg : args) { + if (arg[0] != _SYS_STR('+')) { + continue; + } + + const std::string tmp(SystemUTF8Conv(arg).str()); + std::smatch matches; + std::string cvarName; + std::string cvarValue; + + if (!std::regex_match(tmp, matches, cmdLineRegex)) { + if (std::regex_match(tmp, matches, cmdLineRegexNoValue)) { + // No Value was supplied, assume the player wanted to set value to 1 + cvarName = matches[1].str(); + } else { + continue; + } + } else { + cvarName = matches[1].str(); + cvarValue = matches[2].str(); + } + + if (CVar* cv = findCVar(cvarName)) { + if (cvarValue.empty() && cv->isBoolean()) { + // We were set from the command line with an empty value, assume true + cv->fromBoolean(true); + } else if (!cvarValue.empty()) { + cv->fromLiteralToType(cvarValue); + } + athena::utility::tolower(cvarName); + if (developerName == cvarName) + /* Make sure we're not overriding developer mode when we restore */ + oldDeveloper = com_developer->toBoolean(); + } else { + /* Unable to find an existing CVar, let's defer for the time being 8 */ + athena::utility::tolower(cvarName); + m_deferedCVars.insert_or_assign(std::move(cvarName), std::move(cvarValue)); + } + } + + restoreDeveloper(oldDeveloper); +} + +bool CVarManager::suppressDeveloper() { + bool oldDeveloper = com_developer->toBoolean(); + CVarUnlocker unlock(com_developer); + com_developer->fromBoolean(true); + + return oldDeveloper; +} + +void CVarManager::restoreDeveloper(bool oldDeveloper) { + CVarUnlocker unlock(com_developer); + com_developer->fromBoolean(oldDeveloper); +} +void CVarManager::proc() { + for (const auto& [name, cvar] : m_cvars) { + if (cvar->isModified() && !cvar->modificationRequiresRestart()) { + cvar->dispatch(); + // Clear the modified flag now that we've informed everyone we've changed + cvar->clearModified(); + } + } +} + +} // namespace hecl diff --git a/hecl/lib/ClientProcess.cpp b/hecl/lib/ClientProcess.cpp new file mode 100644 index 000000000..3ff546bb9 --- /dev/null +++ b/hecl/lib/ClientProcess.cpp @@ -0,0 +1,237 @@ +#include "hecl/ClientProcess.hpp" + +#include + +#include "hecl/Blender/Connection.hpp" +#include "hecl/Database.hpp" +#include "hecl/MultiProgressPrinter.hpp" + +#include +#include + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#endif + +#define HECL_MULTIPROCESSOR 1 + +namespace hecl { +static logvisor::Module CP_Log("hecl::ClientProcess"); + +thread_local ClientProcess::Worker* ClientProcess::ThreadWorker; + +int CpuCountOverride = 0; + +void SetCpuCountOverride(int argc, const SystemChar** argv) { + bool threadArg = false; + for (int i = 1; i < argc; ++i) { + if (threadArg) { + if (int count = int(hecl::StrToUl(argv[i], nullptr, 0))) { + CpuCountOverride = count; + return; + } + } + if (!hecl::StrNCmp(argv[i], _SYS_STR("-j"), 2)) { + if (int count = int(hecl::StrToUl(argv[i] + 2, nullptr, 0))) { + CpuCountOverride = count; + return; + } + threadArg = true; + } + } +} + +static int GetCPUCount() { + if (CpuCountOverride > 0) { + return CpuCountOverride; + } + + int ret; +#if _WIN32 + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + ret = sysinfo.dwNumberOfProcessors; +#elif defined(__SWITCH__) + ret = 4; +#else + ret = sysconf(_SC_NPROCESSORS_ONLN); +#endif + + return ret; +} + +void ClientProcess::BufferTransaction::run(blender::Token& btok) { + athena::io::FileReader r(m_path.getAbsolutePath(), 32 * 1024, false); + if (r.hasError()) { + CP_Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to background-buffer '{}'")), m_path.getAbsolutePath()); + return; + } + if (m_offset) + r.seek(m_offset, athena::SeekOrigin::Begin); + r.readBytesToBuf(m_targetBuf, m_maxLen); + m_complete = true; +} + +void ClientProcess::CookTransaction::run(blender::Token& btok) { + m_dataSpec->setThreadProject(); + m_returnResult = m_parent.syncCook(m_path, m_dataSpec, btok, m_force, m_fast); + std::unique_lock lk{m_parent.m_mutex}; + ++m_parent.m_completedCooks; + m_parent.m_progPrinter->setMainFactor(m_parent.m_completedCooks / float(m_parent.m_addedCooks)); + m_complete = true; +} + +void ClientProcess::LambdaTransaction::run(blender::Token& btok) { + m_func(btok); + m_complete = true; +} + +ClientProcess::Worker::Worker(ClientProcess& proc, int idx) : m_proc(proc), m_idx(idx) { + m_thr = std::thread(std::bind(&Worker::proc, this)); +} + +void ClientProcess::Worker::proc() { + ClientProcess::ThreadWorker = this; + + std::string thrName = fmt::format(FMT_STRING("HECL Worker {}"), m_idx); + logvisor::RegisterThreadName(thrName.c_str()); + + std::unique_lock lk{m_proc.m_mutex}; + while (m_proc.m_running) { + if (!m_didInit) { + m_proc.m_initCv.notify_one(); + m_didInit = true; + } + while (m_proc.m_running && m_proc.m_pendingQueue.size()) { + std::shared_ptr trans = std::move(m_proc.m_pendingQueue.front()); + ++m_proc.m_inProgress; + m_proc.m_pendingQueue.pop_front(); + lk.unlock(); + trans->run(m_blendTok); + lk.lock(); + m_proc.m_completedQueue.push_back(std::move(trans)); + --m_proc.m_inProgress; + } + m_proc.m_waitCv.notify_one(); + if (!m_proc.m_running) + break; + m_proc.m_cv.wait(lk); + } + lk.unlock(); + m_blendTok.shutdown(); +} + +ClientProcess::ClientProcess(const MultiProgressPrinter* progPrinter) : m_progPrinter(progPrinter) { +#if HECL_MULTIPROCESSOR + const int cpuCount = GetCPUCount(); +#else + constexpr int cpuCount = 1; +#endif + m_workers.reserve(cpuCount); + for (int i = 0; i < cpuCount; ++i) { + std::unique_lock lk{m_mutex}; + m_workers.emplace_back(*this, m_workers.size()); + m_initCv.wait(lk); + } +} + +std::shared_ptr ClientProcess::addBufferTransaction(const ProjectPath& path, + void* target, size_t maxLen, + size_t offset) { + std::unique_lock lk{m_mutex}; + auto ret = std::make_shared(*this, path, target, maxLen, offset); + m_pendingQueue.emplace_back(ret); + m_cv.notify_one(); + return ret; +} + +std::shared_ptr ClientProcess::addCookTransaction(const hecl::ProjectPath& path, + bool force, bool fast, + Database::IDataSpec* spec) { + std::unique_lock lk{m_mutex}; + auto ret = std::make_shared(*this, path, force, fast, spec); + m_pendingQueue.emplace_back(ret); + m_cv.notify_one(); + ++m_addedCooks; + m_progPrinter->setMainFactor(m_completedCooks / float(m_addedCooks)); + return ret; +} + +std::shared_ptr +ClientProcess::addLambdaTransaction(std::function&& func) { + std::unique_lock lk{m_mutex}; + auto ret = std::make_shared(*this, std::move(func)); + m_pendingQueue.emplace_back(ret); + m_cv.notify_one(); + return ret; +} + +bool ClientProcess::syncCook(const hecl::ProjectPath& path, Database::IDataSpec* spec, blender::Token& btok, bool force, + bool fast) { + if (spec->canCook(path, btok)) { + const Database::DataSpecEntry* specEnt = spec->overrideDataSpec(path, spec->getDataSpecEntry()); + if (specEnt) { + hecl::ProjectPath cooked = path.getCookedPath(*specEnt); + if (fast) + cooked = cooked.getWithExtension(_SYS_STR(".fast")); + cooked.makeDirChain(false); + if (force || cooked.getPathType() == ProjectPath::Type::None || path.getModtime() > cooked.getModtime()) { + if (m_progPrinter) { + hecl::SystemString str; + if (path.getAuxInfo().empty()) + str = fmt::format(FMT_STRING(_SYS_STR("Cooking {}")), path.getRelativePath()); + else + str = fmt::format(FMT_STRING(_SYS_STR("Cooking {}|{}")), path.getRelativePath(), path.getAuxInfo()); + m_progPrinter->print(str.c_str(), nullptr, -1.f, hecl::ClientProcess::GetThreadWorkerIdx()); + m_progPrinter->flush(); + } else { + if (path.getAuxInfo().empty()) + LogModule.report(logvisor::Info, FMT_STRING(_SYS_STR("Cooking {}")), path.getRelativePath()); + else + LogModule.report(logvisor::Info, FMT_STRING(_SYS_STR("Cooking {}|{}")), path.getRelativePath(), path.getAuxInfo()); + } + spec->doCook(path, cooked, false, btok, [](const SystemChar*) {}); + if (m_progPrinter) { + hecl::SystemString str; + if (path.getAuxInfo().empty()) + str = fmt::format(FMT_STRING(_SYS_STR("Cooked {}")), path.getRelativePath()); + else + str = fmt::format(FMT_STRING(_SYS_STR("Cooked {}|{}")), path.getRelativePath(), path.getAuxInfo()); + m_progPrinter->print(str.c_str(), nullptr, -1.f, hecl::ClientProcess::GetThreadWorkerIdx()); + m_progPrinter->flush(); + } + } + return true; + } + } + return false; +} + +void ClientProcess::swapCompletedQueue(std::list>& queue) { + std::unique_lock lk{m_mutex}; + queue.swap(m_completedQueue); +} + +void ClientProcess::waitUntilComplete() { + std::unique_lock lk{m_mutex}; + while (isBusy()) + m_waitCv.wait(lk); +} + +void ClientProcess::shutdown() { + if (!m_running) + return; + std::unique_lock lk{m_mutex}; + m_pendingQueue.clear(); + m_running = false; + m_cv.notify_all(); + lk.unlock(); + for (Worker& worker : m_workers) + if (worker.m_thr.joinable()) + worker.m_thr.join(); +} + +} // namespace hecl diff --git a/hecl/lib/HumanizeNumber.cpp b/hecl/lib/HumanizeNumber.cpp new file mode 100644 index 000000000..3764cedcc --- /dev/null +++ b/hecl/lib/HumanizeNumber.cpp @@ -0,0 +1,151 @@ +#include "hecl/hecl.hpp" +#include "logvisor/logvisor.hpp" + +/* + * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. + * Copyright 2013 John-Mark Gurney + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center, by Luke Mewburn and by Tomas Svensson. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +namespace hecl { +static logvisor::Module Log("hecl::HumanizeNumber"); + +static const int maxscale = 7; + +std::string HumanizeNumber(int64_t quotient, size_t len, const char* suffix, int scale, HNFlags flags) { + const char *prefixes, *sep; + int i, remainder, s1, s2, sign; + int divisordeccut; + int64_t divisor, max; + size_t baselen; + + /* validate args */ + if (suffix == nullptr) + suffix = ""; + if ((flags & HNFlags::Divisor1000) != HNFlags::None && (flags & HNFlags::IECPrefixes) != HNFlags::None) + Log.report(logvisor::Fatal, FMT_STRING("invalid flags combo")); + + /* setup parameters */ + remainder = 0; + + if ((flags & HNFlags::IECPrefixes) != HNFlags::None) { + baselen = 2; + /* + * Use the prefixes for power of two recommended by + * the International Electrotechnical Commission + * (IEC) in IEC 80000-3 (i.e. Ki, Mi, Gi...). + * + * HN_IEC_PREFIXES implies a divisor of 1024 here + * (use of HN_DIVISOR_1000 would have triggered + * an assertion earlier). + */ + divisor = 1024; + divisordeccut = 973; /* ceil(.95 * 1024) */ + if ((flags & HNFlags::B) != HNFlags::None) + prefixes = "B\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei"; + else + prefixes = "\0\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei"; + } else { + baselen = 1; + if ((flags & HNFlags::Divisor1000) != HNFlags::None) { + divisor = 1000; + divisordeccut = 950; + if ((flags & HNFlags::B) != HNFlags::None) + prefixes = "B\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; + else + prefixes = "\0\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; + } else { + divisor = 1024; + divisordeccut = 973; /* ceil(.95 * 1024) */ + if ((flags & HNFlags::B) != HNFlags::None) + prefixes = "B\0\0K\0\0M\0\0G\0\0T\0\0P\0\0E"; + else + prefixes = "\0\0\0K\0\0M\0\0G\0\0T\0\0P\0\0E"; + } + } + +#define SCALE2PREFIX(scale) (&prefixes[(scale)*3]) + + if (quotient < 0) { + sign = -1; + quotient = -quotient; + baselen += 2; /* sign, digit */ + } else { + sign = 1; + baselen += 1; /* digit */ + } + if ((flags & HNFlags::NoSpace) != HNFlags::None) + sep = ""; + else { + sep = " "; + baselen++; + } + baselen += strlen(suffix); + + /* Check if enough room for `x y' + suffix */ + if (len < baselen) + Log.report(logvisor::Fatal, FMT_STRING("buffer size {} insufficient for minimum size {}"), len, baselen); + len += 1; + + if ((scale & int(HNScale::AutoScale)) != 0) { + /* See if there is additional columns can be used. */ + for (max = 1, i = len - baselen; i-- > 0;) + max *= 10; + + /* + * Divide the number until it fits the given column. + * If there will be an overflow by the rounding below, + * divide once more. + */ + for (i = 0; (quotient >= max || (quotient == max - 1 && remainder >= divisordeccut)) && i < maxscale; i++) { + remainder = quotient % divisor; + quotient /= divisor; + } + } else { + for (i = 0; i < scale && i < maxscale; i++) { + remainder = quotient % divisor; + quotient /= divisor; + } + } + + /* If a value <= 9.9 after rounding and ... */ + /* + * XXX - should we make sure there is enough space for the decimal + * place and if not, don't do HN_DECIMAL? + */ + if (((quotient == 9 && remainder < divisordeccut) || quotient < 9) && i > 0 && + (flags & HNFlags::Decimal) != HNFlags::None) { + s1 = (int)quotient + ((remainder * 10 + divisor / 2) / divisor / 10); + s2 = ((remainder * 10 + divisor / 2) / divisor) % 10; + return fmt::format(FMT_STRING("{}{}{}{}{}{}"), sign * s1, localeconv()->decimal_point, s2, sep, SCALE2PREFIX(i), suffix); + } else + return fmt::format(FMT_STRING("{}{}{}{}"), sign * (quotient + (remainder + divisor / 2) / divisor), sep, + SCALE2PREFIX(i), suffix); +} + +} // namespace hecl diff --git a/hecl/lib/MultiProgressPrinter.cpp b/hecl/lib/MultiProgressPrinter.cpp new file mode 100644 index 000000000..211e37de1 --- /dev/null +++ b/hecl/lib/MultiProgressPrinter.cpp @@ -0,0 +1,365 @@ +#include "hecl/MultiProgressPrinter.hpp" + +#include +#include + +#include "hecl/hecl.hpp" + +#define BOLD "\033[1m" +#define NORMAL "\033[0m" +#define PREV_LINE "\r\033[{:d}A" +#define HIDE_CURSOR "\033[?25l" +#define SHOW_CURSOR "\033[?25h" + +#if _WIN32 +#define FOREGROUND_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE +#endif + +namespace hecl { + +void MultiProgressPrinter::ThreadStat::print(const TermInfo& tinfo) const { + bool blocks = m_factor >= 0.f; + float factor = std::max(0.f, std::min(1.f, m_factor)); + int iFactor = factor * 100.f; + + int messageLen = m_message.size(); + int submessageLen = m_submessage.size(); + + int half; + if (blocks) + half = (tinfo.width + 1) / 2 - 2; + else if (tinfo.truncate) + half = tinfo.width - 4; + else + half = messageLen; + + if (half - messageLen < submessageLen - 2) + submessageLen = 0; + + if (submessageLen) { + if (messageLen > half - submessageLen - 1) + fmt::print(FMT_STRING(_SYS_STR(" {:.{}}... {} ")), m_message, half - submessageLen - 4, m_submessage); + else { + fmt::print(FMT_STRING(_SYS_STR(" {}")), m_message); + for (int i = half - messageLen - submessageLen - 1; i >= 0; --i) + fmt::print(FMT_STRING(_SYS_STR(" "))); + fmt::print(FMT_STRING(_SYS_STR("{} ")), m_submessage); + } + } else { + if (messageLen > half) + fmt::print(FMT_STRING(_SYS_STR(" {:.{}}... ")), m_message, half - 3); + else { + fmt::print(FMT_STRING(_SYS_STR(" {}")), m_message); + for (int i = half - messageLen; i >= 0; --i) + fmt::print(FMT_STRING(_SYS_STR(" "))); + } + } + + if (blocks) { + int rightHalf = tinfo.width - half - 4; + int nblocks = rightHalf - 7; + int filled = nblocks * factor; + int rem = nblocks - filled; + + if (tinfo.xtermColor) { + fmt::print(FMT_STRING(_SYS_STR("" BOLD "{:3d}% [")), iFactor); + for (int b = 0; b < filled; ++b) + fmt::print(FMT_STRING(_SYS_STR("#"))); + for (int b = 0; b < rem; ++b) + fmt::print(FMT_STRING(_SYS_STR("-"))); + fmt::print(FMT_STRING(_SYS_STR("]" NORMAL ""))); + } else { +#if _WIN32 + SetConsoleTextAttribute(tinfo.console, FOREGROUND_INTENSITY | FOREGROUND_WHITE); +#endif + fmt::print(FMT_STRING(_SYS_STR("{:3d}% [")), iFactor); + for (int b = 0; b < filled; ++b) + fmt::print(FMT_STRING(_SYS_STR("#"))); + for (int b = 0; b < rem; ++b) + fmt::print(FMT_STRING(_SYS_STR("-"))); + fmt::print(FMT_STRING(_SYS_STR("]"))); +#if _WIN32 + SetConsoleTextAttribute(tinfo.console, FOREGROUND_WHITE); +#endif + } + } +} + +void MultiProgressPrinter::DrawIndeterminateBar() { + int half = m_termInfo.width - 2; + int blocks = half - 2; + + ++m_indeterminateCounter; + if (m_indeterminateCounter <= -blocks) + m_indeterminateCounter = -blocks + 1; + else if (m_indeterminateCounter >= blocks) + m_indeterminateCounter = -blocks + 2; + int absCounter = std::abs(m_indeterminateCounter); + + int pre = absCounter; + int rem = blocks - pre - 1; + + if (m_termInfo.xtermColor) { + fmt::print(FMT_STRING(_SYS_STR("" BOLD " ["))); + for (int b = 0; b < pre; ++b) + fmt::print(FMT_STRING(_SYS_STR("-"))); + fmt::print(FMT_STRING(_SYS_STR("#"))); + for (int b = 0; b < rem; ++b) + fmt::print(FMT_STRING(_SYS_STR("-"))); + fmt::print(FMT_STRING(_SYS_STR("]" NORMAL ""))); + } else { +#if _WIN32 + SetConsoleTextAttribute(m_termInfo.console, FOREGROUND_INTENSITY | FOREGROUND_WHITE); +#endif + fmt::print(FMT_STRING(_SYS_STR(" ["))); + for (int b = 0; b < pre; ++b) + fmt::print(FMT_STRING(_SYS_STR("-"))); + fmt::print(FMT_STRING(_SYS_STR("#"))); + for (int b = 0; b < rem; ++b) + fmt::print(FMT_STRING(_SYS_STR("-"))); + fmt::print(FMT_STRING(_SYS_STR("]"))); +#if _WIN32 + SetConsoleTextAttribute(m_termInfo.console, FOREGROUND_WHITE); +#endif + } +} + +void MultiProgressPrinter::MoveCursorUp(int n) { + if (n) { + if (m_termInfo.xtermColor) { + fmt::print(FMT_STRING(_SYS_STR("" PREV_LINE "")), n); + } +#if _WIN32 + else { + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + GetConsoleScreenBufferInfo(m_termInfo.console, &consoleInfo); + consoleInfo.dwCursorPosition.X = 0; + consoleInfo.dwCursorPosition.Y -= n; + SetConsoleCursorPosition(m_termInfo.console, consoleInfo.dwCursorPosition); + } +#endif + } else { + fmt::print(FMT_STRING(_SYS_STR("\r"))); + } +} + +void MultiProgressPrinter::DoPrint() { + auto logLk = logvisor::LockLog(); + uint64_t logCounter = logvisor::GetLogCounter(); + if (logCounter != m_lastLogCounter) { + m_curThreadLines = 0; + m_lastLogCounter = logCounter; + } +#if _WIN32 + CONSOLE_CURSOR_INFO cursorInfo; + GetConsoleCursorInfo(m_termInfo.console, &cursorInfo); + cursorInfo.bVisible = FALSE; + SetConsoleCursorInfo(m_termInfo.console, &cursorInfo); +#endif + if (m_termInfo.xtermColor) + fmt::print(FMT_STRING(_SYS_STR("" HIDE_CURSOR ""))); + + if (m_dirty) { + m_termInfo.width = (hecl::GuiMode ? 120 : std::max(80, hecl::ConsoleWidth(&m_termInfo.truncate))); + MoveCursorUp(m_curThreadLines + m_curProgLines); + m_curThreadLines = m_curProgLines = 0; + + if (m_newLineAfter) { + for (const ThreadStat& stat : m_threadStats) { + if (stat.m_active) { + stat.print(m_termInfo); + fmt::print(FMT_STRING(_SYS_STR("\n"))); + ++m_curThreadLines; + } + } + + if (m_mainIndeterminate +#ifndef _WIN32 + && m_termInfo.xtermColor +#endif + ) { + DrawIndeterminateBar(); + fmt::print(FMT_STRING(_SYS_STR("\n"))); + ++m_curProgLines; + } else if (m_mainFactor >= 0.f) { + float factor = std::max(0.0f, std::min(1.0f, m_mainFactor)); + int iFactor = factor * 100.0; + int half = m_termInfo.width - 2; + + int blocks = half - 8; + int filled = blocks * factor; + int rem = blocks - filled; + + if (m_termInfo.xtermColor) { + fmt::print(FMT_STRING(_SYS_STR("" BOLD " {:3d}% [")), iFactor); + for (int b = 0; b < filled; ++b) + fmt::print(FMT_STRING(_SYS_STR("#"))); + for (int b = 0; b < rem; ++b) + fmt::print(FMT_STRING(_SYS_STR("-"))); + fmt::print(FMT_STRING(_SYS_STR("]" NORMAL ""))); + } else { +#if _WIN32 + SetConsoleTextAttribute(m_termInfo.console, FOREGROUND_INTENSITY | FOREGROUND_WHITE); +#endif + fmt::print(FMT_STRING(_SYS_STR(" {:3d}% [")), iFactor); + for (int b = 0; b < filled; ++b) + fmt::print(FMT_STRING(_SYS_STR("#"))); + for (int b = 0; b < rem; ++b) + fmt::print(FMT_STRING(_SYS_STR("-"))); + fmt::print(FMT_STRING(_SYS_STR("]"))); +#if _WIN32 + SetConsoleTextAttribute(m_termInfo.console, FOREGROUND_WHITE); +#endif + } + + fmt::print(FMT_STRING(_SYS_STR("\n"))); + ++m_curProgLines; + } + } else if (m_latestThread != -1) { + const ThreadStat& stat = m_threadStats[m_latestThread]; + stat.print(m_termInfo); + fmt::print(FMT_STRING(_SYS_STR("\r"))); + } + m_dirty = false; + } else if (m_mainIndeterminate +#ifndef _WIN32 + && m_termInfo.xtermColor +#endif + ) { + m_termInfo.width = (hecl::GuiMode ? 120 : std::max(80, hecl::ConsoleWidth())); + MoveCursorUp(m_curProgLines); + m_curProgLines = 0; + DrawIndeterminateBar(); + fmt::print(FMT_STRING(_SYS_STR("\n"))); + ++m_curProgLines; + } + + if (m_termInfo.xtermColor) + fmt::print(FMT_STRING(_SYS_STR("" SHOW_CURSOR ""))); + fflush(stdout); + +#if _WIN32 + cursorInfo.bVisible = TRUE; + SetConsoleCursorInfo(m_termInfo.console, &cursorInfo); +#endif +} + +void MultiProgressPrinter::LogProc() { + while (m_running) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + if (!m_dirty && !m_mainIndeterminate) { + continue; + } + + std::lock_guard lk{m_logLock}; + DoPrint(); + } +} + +MultiProgressPrinter::MultiProgressPrinter(bool activate) { + if (activate) { + /* Xterm check */ +#if _WIN32 + m_newLineAfter = true; + m_termInfo.console = GetStdHandle(STD_OUTPUT_HANDLE); + const char* conemuANSI = getenv("ConEmuANSI"); + if (conemuANSI && !strcmp(conemuANSI, "ON")) + m_termInfo.xtermColor = true; +#else + m_newLineAfter = false; + const char* term = getenv("TERM"); + if (term && !strncmp(term, "xterm", 5)) { + m_termInfo.xtermColor = true; + m_newLineAfter = true; + } +#endif + + m_running = true; + m_logThread = std::thread(std::bind(&MultiProgressPrinter::LogProc, this)); + } +} + +MultiProgressPrinter::~MultiProgressPrinter() { + m_running = false; + if (m_logThread.joinable()) + m_logThread.join(); +} + +void MultiProgressPrinter::print(const hecl::SystemChar* message, const hecl::SystemChar* submessage, float factor, + int threadIdx) const { + if (!m_running) { + return; + } + + std::lock_guard lk{m_logLock}; + if (threadIdx < 0) { + threadIdx = 0; + } + if (threadIdx >= m_threadStats.size()) { + m_threadStats.resize(threadIdx + 1); + } + + ThreadStat& stat = m_threadStats[threadIdx]; + if (message) { + stat.m_message = message; + } else { + stat.m_message.clear(); + } + if (submessage) { + stat.m_submessage = submessage; + } else { + stat.m_submessage.clear(); + } + + stat.m_factor = factor; + stat.m_active = true; + m_latestThread = threadIdx; + m_dirty = true; +} + +void MultiProgressPrinter::setMainFactor(float factor) const { + if (!m_running) { + return; + } + + std::lock_guard lk{m_logLock}; + if (!m_mainIndeterminate) { + m_dirty = true; + } + m_mainFactor = factor; +} + +void MultiProgressPrinter::setMainIndeterminate(bool indeterminate) const { + if (!m_running) { + return; + } + + std::lock_guard lk{m_logLock}; + if (m_mainIndeterminate != indeterminate) { + m_mainIndeterminate = indeterminate; + m_dirty = true; + } +} + +void MultiProgressPrinter::startNewLine() const { + if (!m_running) { + return; + } + + std::lock_guard lk{m_logLock}; + const_cast(*this).DoPrint(); + m_threadStats.clear(); + m_latestThread = -1; + m_curThreadLines = 0; + m_mainFactor = -1.f; + auto logLk = logvisor::LockLog(); + fmt::print(FMT_STRING(_SYS_STR("\n"))); +} + +void MultiProgressPrinter::flush() const { + std::lock_guard lk{m_logLock}; + const_cast(*this).DoPrint(); +} + +} // namespace hecl diff --git a/hecl/lib/Project.cpp b/hecl/lib/Project.cpp new file mode 100644 index 000000000..99625fbf9 --- /dev/null +++ b/hecl/lib/Project.cpp @@ -0,0 +1,505 @@ +#include + +#include +#include +#include +#include +#include +#include + +#if _WIN32 +#else +#include +#endif + +#include "hecl/ClientProcess.hpp" +#include "hecl/Database.hpp" +#include "hecl/Blender/Connection.hpp" +#include "hecl/MultiProgressPrinter.hpp" + +#include + +namespace hecl::Database { + +logvisor::Module LogModule("hecl::Database"); +constexpr hecl::FourCC HECLfcc("HECL"); + +/********************************************** + * Project::ConfigFile + **********************************************/ + +static bool CheckNewLineAdvance(std::string::const_iterator& it) { + if (*it == '\n') { + it += 1; + return true; + } else if (*it == '\r') { + if (*(it + 1) == '\n') { + it += 2; + return true; + } + it += 1; + return true; + } + return false; +} + +Project::ConfigFile::ConfigFile(const Project& project, SystemStringView name, SystemStringView subdir) { + m_filepath = SystemString(project.m_rootPath.getAbsolutePath()) + subdir.data() + name.data(); +} + +std::vector& Project::ConfigFile::lockAndRead() { + if (m_lockedFile != nullptr) { + return m_lines; + } + + m_lockedFile = hecl::FopenUnique(m_filepath.c_str(), _SYS_STR("a+"), FileLockType::Write); + hecl::FSeek(m_lockedFile.get(), 0, SEEK_SET); + + std::string mainString; + char readBuf[1024]; + size_t readSz; + while ((readSz = std::fread(readBuf, 1, sizeof(readBuf), m_lockedFile.get()))) { + mainString += std::string(readBuf, readSz); + } + + auto begin = mainString.cbegin(); + auto end = mainString.cbegin(); + + m_lines.clear(); + while (end != mainString.end()) { + auto origEnd = end; + if (*end == '\0') { + break; + } + if (CheckNewLineAdvance(end)) { + if (begin != origEnd) { + m_lines.emplace_back(begin, origEnd); + } + begin = end; + continue; + } + ++end; + } + if (begin != end) { + m_lines.emplace_back(begin, end); + } + + return m_lines; +} + +void Project::ConfigFile::addLine(std::string_view line) { + if (!checkForLine(line)) + m_lines.emplace_back(line); +} + +void Project::ConfigFile::removeLine(std::string_view refLine) { + if (!m_lockedFile) { + LogModule.reportSource(logvisor::Fatal, __FILE__, __LINE__, FMT_STRING("Project::ConfigFile::lockAndRead not yet called")); + return; + } + + for (auto it = m_lines.begin(); it != m_lines.end();) { + if (*it == refLine) { + it = m_lines.erase(it); + continue; + } + ++it; + } +} + +bool Project::ConfigFile::checkForLine(std::string_view refLine) const { + if (!m_lockedFile) { + LogModule.reportSource(logvisor::Fatal, __FILE__, __LINE__, FMT_STRING("Project::ConfigFile::lockAndRead not yet called")); + return false; + } + + return std::any_of(m_lines.cbegin(), m_lines.cend(), [&refLine](const auto& line) { return line == refLine; }); +} + +void Project::ConfigFile::unlockAndDiscard() { + if (m_lockedFile == nullptr) { + LogModule.reportSource(logvisor::Fatal, __FILE__, __LINE__, FMT_STRING("Project::ConfigFile::lockAndRead not yet called")); + return; + } + + m_lines.clear(); + m_lockedFile.reset(); +} + +bool Project::ConfigFile::unlockAndCommit() { + if (!m_lockedFile) { + LogModule.reportSource(logvisor::Fatal, __FILE__, __LINE__, FMT_STRING("Project::ConfigFile::lockAndRead not yet called")); + return false; + } + + const SystemString newPath = m_filepath + _SYS_STR(".part"); + auto newFile = hecl::FopenUnique(newPath.c_str(), _SYS_STR("w"), FileLockType::Write); + bool fail = false; + for (const std::string& line : m_lines) { + if (std::fwrite(line.c_str(), 1, line.size(), newFile.get()) != line.size()) { + fail = true; + break; + } + if (std::fputc('\n', newFile.get()) == EOF) { + fail = true; + break; + } + } + m_lines.clear(); + newFile.reset(); + m_lockedFile.reset(); + if (fail) { +#if HECL_UCS2 + _wunlink(newPath.c_str()); +#else + unlink(newPath.c_str()); +#endif + return false; + } else { +#if HECL_UCS2 + //_wrename(newPath.c_str(), m_filepath.c_str()); + MoveFileExW(newPath.c_str(), m_filepath.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH); +#else + rename(newPath.c_str(), m_filepath.c_str()); +#endif + return true; + } +} + +/********************************************** + * Project + **********************************************/ + +Project::Project(const ProjectRootPath& rootPath) +: m_rootPath(rootPath) +, m_workRoot(*this, _SYS_STR("")) +, m_dotPath(m_workRoot, _SYS_STR(".hecl")) +, m_cookedRoot(m_dotPath, _SYS_STR("cooked")) +, m_specs(*this, _SYS_STR("specs")) +, m_paths(*this, _SYS_STR("paths")) +, m_groups(*this, _SYS_STR("groups")) { + /* Stat for existing project directory (must already exist) */ + Sstat myStat; + if (hecl::Stat(m_rootPath.getAbsolutePath().data(), &myStat)) { + LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("unable to stat {}")), m_rootPath.getAbsolutePath()); + return; + } + + if (!S_ISDIR(myStat.st_mode)) { + LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("provided path must be a directory; '{}' isn't")), + m_rootPath.getAbsolutePath()); + return; + } + + /* Create project directory structure */ + m_dotPath.makeDir(); + m_cookedRoot.makeDir(); + + /* Ensure beacon is valid or created */ + const ProjectPath beaconPath(m_dotPath, _SYS_STR("beacon")); + auto bf = hecl::FopenUnique(beaconPath.getAbsolutePath().data(), _SYS_STR("a+b")); + struct BeaconStruct { + hecl::FourCC magic; + uint32_t version; + } beacon; + constexpr uint32_t DATA_VERSION = 1; + if (std::fread(&beacon, 1, sizeof(beacon), bf.get()) != sizeof(beacon)) { + std::fseek(bf.get(), 0, SEEK_SET); + beacon.magic = HECLfcc; + beacon.version = SBig(DATA_VERSION); + std::fwrite(&beacon, 1, sizeof(beacon), bf.get()); + } + bf.reset(); + + if (beacon.magic != HECLfcc || SBig(beacon.version) != DATA_VERSION) { + LogModule.report(logvisor::Fatal, FMT_STRING("incompatible project version")); + return; + } + + /* Compile current dataspec */ + rescanDataSpecs(); + m_valid = true; +} + +const ProjectPath& Project::getProjectCookedPath(const DataSpecEntry& spec) const { + for (const ProjectDataSpec& sp : m_compiledSpecs) + if (&sp.spec == &spec) + return sp.cookedPath; + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Unable to find spec '{}'")), spec.m_name); + return m_cookedRoot; +} + +bool Project::addPaths(const std::vector& paths) { + m_paths.lockAndRead(); + for (const ProjectPath& path : paths) + m_paths.addLine(path.getRelativePathUTF8()); + return m_paths.unlockAndCommit(); +} + +bool Project::removePaths(const std::vector& paths, bool recursive) { + std::vector& existingPaths = m_paths.lockAndRead(); + if (recursive) { + for (const ProjectPath& path : paths) { + auto recursiveBase = path.getRelativePathUTF8(); + for (auto it = existingPaths.begin(); it != existingPaths.end();) { + if (!(*it).compare(0, recursiveBase.size(), recursiveBase)) { + it = existingPaths.erase(it); + continue; + } + ++it; + } + } + } else + for (const ProjectPath& path : paths) + m_paths.removeLine(path.getRelativePathUTF8()); + return m_paths.unlockAndCommit(); +} + +bool Project::addGroup(const hecl::ProjectPath& path) { + m_groups.lockAndRead(); + m_groups.addLine(path.getRelativePathUTF8()); + return m_groups.unlockAndCommit(); +} + +bool Project::removeGroup(const ProjectPath& path) { + m_groups.lockAndRead(); + m_groups.removeLine(path.getRelativePathUTF8()); + return m_groups.unlockAndCommit(); +} + +void Project::rescanDataSpecs() { + m_compiledSpecs.clear(); + m_specs.lockAndRead(); + for (const DataSpecEntry* spec : DATA_SPEC_REGISTRY) { + hecl::SystemString specStr(spec->m_name); + SystemUTF8Conv specUTF8(specStr); + m_compiledSpecs.push_back({*spec, ProjectPath(m_cookedRoot, hecl::SystemString(spec->m_name) + _SYS_STR(".spec")), + m_specs.checkForLine(specUTF8.str())}); + } + m_specs.unlockAndDiscard(); +} + +bool Project::enableDataSpecs(const std::vector& specs) { + m_specs.lockAndRead(); + for (const SystemString& spec : specs) { + SystemUTF8Conv specView(spec); + m_specs.addLine(specView.str()); + } + bool result = m_specs.unlockAndCommit(); + rescanDataSpecs(); + return result; +} + +bool Project::disableDataSpecs(const std::vector& specs) { + m_specs.lockAndRead(); + for (const SystemString& spec : specs) { + SystemUTF8Conv specView(spec); + m_specs.removeLine(specView.str()); + } + bool result = m_specs.unlockAndCommit(); + rescanDataSpecs(); + return result; +} + +class CookProgress { + const hecl::MultiProgressPrinter& m_progPrinter; + const SystemChar* m_dir = nullptr; + const SystemChar* m_file = nullptr; + float m_prog = 0.f; + +public: + CookProgress(const hecl::MultiProgressPrinter& progPrinter) : m_progPrinter(progPrinter) {} + void changeDir(const SystemChar* dir) { + m_dir = dir; + m_progPrinter.startNewLine(); + } + void changeFile(const SystemChar* file, float prog) { + m_file = file; + m_prog = prog; + } + void reportFile(const DataSpecEntry* specEnt) { + SystemString submsg(m_file); + submsg += _SYS_STR(" ("); + submsg += specEnt->m_name.data(); + submsg += _SYS_STR(')'); + m_progPrinter.print(m_dir, submsg.c_str(), m_prog); + } + void reportFile(const DataSpecEntry* specEnt, const SystemChar* extra) { + SystemString submsg(m_file); + submsg += _SYS_STR(" ("); + submsg += specEnt->m_name.data(); + submsg += _SYS_STR(", "); + submsg += extra; + submsg += _SYS_STR(')'); + m_progPrinter.print(m_dir, submsg.c_str(), m_prog); + } + void reportDirComplete() { m_progPrinter.print(m_dir, nullptr, 1.f); } +}; + +static void VisitFile(const ProjectPath& path, bool force, bool fast, + std::vector>& specInsts, CookProgress& progress, ClientProcess* cp) { + for (auto& spec : specInsts) { + if (spec->canCook(path, hecl::blender::SharedBlenderToken)) { + if (cp) { + cp->addCookTransaction(path, force, fast, spec.get()); + } else { + const DataSpecEntry* override = spec->overrideDataSpec(path, spec->getDataSpecEntry()); + if (!override) + continue; + ProjectPath cooked = path.getCookedPath(*override); + if (fast) + cooked = cooked.getWithExtension(_SYS_STR(".fast")); + if (force || cooked.getPathType() == ProjectPath::Type::None || path.getModtime() > cooked.getModtime()) { + progress.reportFile(override); + spec->doCook(path, cooked, fast, hecl::blender::SharedBlenderToken, + [&](const SystemChar* extra) { progress.reportFile(override, extra); }); + } + } + } + } +} + +static void VisitDirectory(const ProjectPath& dir, bool recursive, bool force, bool fast, + std::vector>& specInsts, CookProgress& progress, + ClientProcess* cp) { + if (dir.getLastComponent().size() > 1 && dir.getLastComponent()[0] == _SYS_STR('.')) + return; + + if (hecl::ProjectPath(dir, _SYS_STR("!project.yaml")).isFile() && + hecl::ProjectPath(dir, _SYS_STR("!pool.yaml")).isFile()) { + /* Handle AudioGroup case */ + VisitFile(dir, force, fast, specInsts, progress, cp); + return; + } + + std::map children; + dir.getDirChildren(children); + + /* Pass 1: child file count */ + int childFileCount = 0; + for (auto& child : children) + if (child.second.getPathType() == ProjectPath::Type::File) + ++childFileCount; + + /* Pass 2: child files */ + int progNum = 0; + float progDenom = childFileCount; + progress.changeDir(dir.getLastComponent().data()); + for (auto& child : children) { + if (child.second.getPathType() == ProjectPath::Type::File) { + progress.changeFile(child.first.c_str(), progNum++ / progDenom); + VisitFile(child.second, force, fast, specInsts, progress, cp); + } + } + progress.reportDirComplete(); + + /* Pass 3: child directories */ + if (recursive) { + for (auto& child : children) { + switch (child.second.getPathType()) { + case ProjectPath::Type::Directory: { + VisitDirectory(child.second, recursive, force, fast, specInsts, progress, cp); + break; + } + default: + break; + } + } + } +} + +bool Project::cookPath(const ProjectPath& path, const hecl::MultiProgressPrinter& progress, bool recursive, bool force, + bool fast, const DataSpecEntry* spec, ClientProcess* cp) { + /* Construct DataSpec instances for cooking */ + if (spec) { + if (m_cookSpecs.size() != 1 || m_cookSpecs[0]->getDataSpecEntry() != spec) { + m_cookSpecs.clear(); + if (spec->m_factory) + m_cookSpecs.push_back(spec->m_factory(*this, DataSpecTool::Cook)); + } + } else if (m_cookSpecs.empty()) { + m_cookSpecs.reserve(m_compiledSpecs.size()); + for (const ProjectDataSpec& projectSpec : m_compiledSpecs) { + if (projectSpec.active && projectSpec.spec.m_factory) { + m_cookSpecs.push_back(projectSpec.spec.m_factory(*this, DataSpecTool::Cook)); + } + } + } + + /* Iterate complete directory/file/glob list */ + CookProgress cookProg(progress); + switch (path.getPathType()) { + case ProjectPath::Type::File: + case ProjectPath::Type::Glob: { + cookProg.changeFile(path.getLastComponent().data(), 0.f); + VisitFile(path, force, fast, m_cookSpecs, cookProg, cp); + break; + } + case ProjectPath::Type::Directory: { + VisitDirectory(path, recursive, force, fast, m_cookSpecs, cookProg, cp); + break; + } + default: + break; + } + + return true; +} + +bool Project::packagePath(const ProjectPath& path, const hecl::MultiProgressPrinter& progress, bool fast, + const DataSpecEntry* spec, ClientProcess* cp) { + /* Construct DataSpec instance for packaging */ + const DataSpecEntry* specEntry = nullptr; + if (spec) { + if (spec->m_factory) { + specEntry = spec; + } + } else { + bool foundPC = false; + for (const ProjectDataSpec& projectSpec : m_compiledSpecs) { + if (projectSpec.active && projectSpec.spec.m_factory) { + if (hecl::StringUtils::EndsWith(projectSpec.spec.m_name, _SYS_STR("-PC"))) { + foundPC = true; + specEntry = &projectSpec.spec; + } else if (!foundPC) { + specEntry = &projectSpec.spec; + } + } + } + } + + if (!specEntry) + LogModule.report(logvisor::Fatal, FMT_STRING("No matching DataSpec")); + + if (!m_lastPackageSpec || m_lastPackageSpec->getDataSpecEntry() != specEntry) + m_lastPackageSpec = specEntry->m_factory(*this, DataSpecTool::Package); + + if (m_lastPackageSpec->canPackage(path)) { + m_lastPackageSpec->doPackage(path, specEntry, fast, hecl::blender::SharedBlenderToken, progress, cp); + return true; + } + + return false; +} + +void Project::interruptCook() { + if (m_lastPackageSpec) + m_lastPackageSpec->interruptCook(); +} + +bool Project::cleanPath(const ProjectPath& path, bool recursive) { return false; } + +PackageDepsgraph Project::buildPackageDepsgraph(const ProjectPath& path) { return PackageDepsgraph(); } + +void Project::addBridgePathToCache(uint64_t id, const ProjectPath& path) { m_bridgePathCache[id] = path; } + +void Project::clearBridgePathCache() { m_bridgePathCache.clear(); } + +const ProjectPath* Project::lookupBridgePath(uint64_t id) const { + auto search = m_bridgePathCache.find(id); + if (search == m_bridgePathCache.cend()) + return nullptr; + return &search->second; +} + +} // namespace hecl::Database diff --git a/hecl/lib/ProjectPath.cpp b/hecl/lib/ProjectPath.cpp new file mode 100644 index 000000000..08f3e656f --- /dev/null +++ b/hecl/lib/ProjectPath.cpp @@ -0,0 +1,377 @@ +#include "hecl/hecl.hpp" + +#include + +#include "hecl/Database.hpp" +#include "hecl/FourCC.hpp" + +namespace hecl { +static const SystemRegex regPATHCOMP(_SYS_STR("[/\\\\]*([^/\\\\]+)"), SystemRegex::ECMAScript | SystemRegex::optimize); + +static SystemString CanonRelPath(SystemStringView path) { + /* Tokenize Path */ + std::vector comps; + hecl::SystemRegexMatch matches; + SystemString in(path); + SanitizePath(in); + for (; std::regex_search(in, matches, regPATHCOMP); in = matches.suffix().str()) { + hecl::SystemRegexMatch::const_reference match = matches[1]; + if (match == _SYS_STR(".")) + continue; + else if (match == _SYS_STR("..")) { + if (comps.empty()) { + /* Unable to resolve outside project */ + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Unable to resolve outside project root in {}")), path); + return _SYS_STR("."); + } + comps.pop_back(); + continue; + } + comps.push_back(match.str()); + } + + /* Emit relative path */ + if (comps.size()) { + auto it = comps.begin(); + SystemString retval = *it; + for (++it; it != comps.end(); ++it) { + if ((*it).size()) { + retval += _SYS_STR('/'); + retval += *it; + } + } + return retval; + } + return _SYS_STR("."); +} + +static SystemString CanonRelPath(SystemStringView path, const ProjectRootPath& projectRoot) { + /* Absolute paths not allowed; attempt to make project-relative */ + if (IsAbsolute(path)) + return CanonRelPath(projectRoot.getProjectRelativeFromAbsolute(path)); + return CanonRelPath(path); +} + +void ProjectPath::assign(Database::Project& project, SystemStringView path) { + m_proj = &project; + + SystemString usePath; + size_t pipeFind = path.rfind(_SYS_STR('|')); + if (pipeFind != SystemString::npos) { + m_auxInfo.assign(path.cbegin() + pipeFind + 1, path.cend()); + usePath.assign(path.cbegin(), path.cbegin() + pipeFind); + } else + usePath = path; + + m_relPath = CanonRelPath(usePath, project.getProjectRootPath()); + m_absPath = SystemString(project.getProjectRootPath().getAbsolutePath()) + _SYS_STR('/') + m_relPath; + SanitizePath(m_relPath); + SanitizePath(m_absPath); + + ComputeHash(); +} + +#if HECL_UCS2 +void ProjectPath::assign(Database::Project& project, std::string_view path) { + std::wstring wpath = UTF8ToWide(path); + assign(project, wpath); +} +#endif + +void ProjectPath::assign(const ProjectPath& parentPath, SystemStringView path) { + m_proj = parentPath.m_proj; + + SystemString usePath; + size_t pipeFind = path.rfind(_SYS_STR('|')); + if (pipeFind != SystemString::npos) { + m_auxInfo.assign(path.cbegin() + pipeFind + 1, path.cend()); + usePath.assign(path.cbegin(), path.cbegin() + pipeFind); + } else + usePath = path; + + m_relPath = CanonRelPath(parentPath.m_relPath + _SYS_STR('/') + usePath); + m_absPath = SystemString(m_proj->getProjectRootPath().getAbsolutePath()) + _SYS_STR('/') + m_relPath; + SanitizePath(m_relPath); + SanitizePath(m_absPath); + + ComputeHash(); +} + +#if HECL_UCS2 +void ProjectPath::assign(const ProjectPath& parentPath, std::string_view path) { + std::wstring wpath = UTF8ToWide(path); + assign(parentPath, wpath); +} +#endif + +ProjectPath ProjectPath::getWithExtension(const SystemChar* ext, bool replace) const { + ProjectPath pp(*this); + if (replace) { + auto relIt = pp.m_relPath.end(); + if (relIt != pp.m_relPath.begin()) + --relIt; + auto absIt = pp.m_absPath.end(); + if (absIt != pp.m_absPath.begin()) + --absIt; + while (relIt != pp.m_relPath.begin() && *relIt != _SYS_STR('.') && *relIt != _SYS_STR('/')) { + --relIt; + --absIt; + } + if (*relIt == _SYS_STR('.') && relIt != pp.m_relPath.begin()) { + pp.m_relPath.resize(relIt - pp.m_relPath.begin()); + pp.m_absPath.resize(absIt - pp.m_absPath.begin()); + } + } + if (ext) { + pp.m_relPath += ext; + pp.m_absPath += ext; + } + + pp.ComputeHash(); + return pp; +} + +ProjectPath ProjectPath::getCookedPath(const Database::DataSpecEntry& spec) const { + ProjectPath woExt = getWithExtension(nullptr, true); + ProjectPath ret(m_proj->getProjectCookedPath(spec), woExt.getRelativePath()); + + if (getAuxInfo().size()) + return ret.getWithExtension((SystemString(_SYS_STR(".")) + getAuxInfo().data()).c_str()); + else + return ret; +} + +ProjectPath::Type ProjectPath::getPathType() const { + if (m_absPath.empty()) + return Type::None; + if (m_absPath.find(_SYS_STR('*')) != SystemString::npos) + return Type::Glob; + Sstat theStat; + if (hecl::Stat(m_absPath.c_str(), &theStat)) + return Type::None; + if (S_ISDIR(theStat.st_mode)) + return Type::Directory; + if (S_ISREG(theStat.st_mode)) + return Type::File; + return Type::None; +} + +Time ProjectPath::getModtime() const { + Sstat theStat; + time_t latestTime = 0; + if (m_absPath.find(_SYS_STR('*')) != SystemString::npos) { + std::vector globResults; + getGlobResults(globResults); + for (ProjectPath& path : globResults) { + if (!hecl::Stat(path.getAbsolutePath().data(), &theStat)) { + if (S_ISREG(theStat.st_mode) && theStat.st_mtime > latestTime) + latestTime = theStat.st_mtime; + } + } + return Time(latestTime); + } + if (!hecl::Stat(m_absPath.c_str(), &theStat)) { + if (S_ISREG(theStat.st_mode)) { + return Time(theStat.st_mtime); + } else if (S_ISDIR(theStat.st_mode)) { + hecl::DirectoryEnumerator de(m_absPath, hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true); + for (const hecl::DirectoryEnumerator::Entry& ent : de) { + if (!hecl::Stat(ent.m_path.c_str(), &theStat)) { + if (S_ISREG(theStat.st_mode) && theStat.st_mtime > latestTime) + latestTime = theStat.st_mtime; + } + } + return Time(latestTime); + } + } + LogModule.report(logvisor::Fatal, FMT_STRING(_SYS_STR("invalid path type for computing modtime in '{}'")), m_absPath); + return Time(); +} + +static void _recursiveGlob(Database::Project& proj, std::vector& outPaths, const SystemString& remPath, + const SystemString& itStr, bool needSlash) { + SystemRegexMatch matches; + if (!std::regex_search(remPath, matches, regPATHCOMP)) + return; + + const SystemString& comp = matches[1]; + if (comp.find(_SYS_STR('*')) == SystemString::npos) { + SystemString nextItStr = itStr; + if (needSlash) + nextItStr += _SYS_STR('/'); + nextItStr += comp; + + hecl::Sstat theStat; + if (Stat(nextItStr.c_str(), &theStat)) + return; + + if (S_ISDIR(theStat.st_mode)) + _recursiveGlob(proj, outPaths, matches.suffix().str(), nextItStr, true); + else + outPaths.emplace_back(proj, nextItStr); + return; + } + + /* Compile component into regex */ + SystemRegex regComp(comp, SystemRegex::ECMAScript); + + hecl::DirectoryEnumerator de(itStr, hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true); + for (const hecl::DirectoryEnumerator::Entry& ent : de) { + if (std::regex_match(ent.m_name, regComp)) { + SystemString nextItStr = itStr; + if (needSlash) + nextItStr += '/'; + nextItStr += ent.m_name; + + hecl::Sstat theStat; + if (Stat(nextItStr.c_str(), &theStat)) + continue; + + if (ent.m_isDir) + _recursiveGlob(proj, outPaths, matches.suffix().str(), nextItStr, true); + else + outPaths.emplace_back(proj, nextItStr); + } + } +} + +void ProjectPath::getDirChildren(std::map& outPaths) const { + hecl::DirectoryEnumerator de(m_absPath, hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true); + for (const hecl::DirectoryEnumerator::Entry& ent : de) + outPaths[ent.m_name] = ProjectPath(*this, ent.m_name); +} + +hecl::DirectoryEnumerator ProjectPath::enumerateDir() const { + return hecl::DirectoryEnumerator(m_absPath, hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true); +} + +void ProjectPath::getGlobResults(std::vector& outPaths) const { + auto rootPath = m_proj->getProjectRootPath().getAbsolutePath(); + _recursiveGlob(*m_proj, outPaths, m_relPath, rootPath.data(), rootPath.back() != _SYS_STR('/')); +} + +template +static bool RegexSearchLast(const T& str, std::match_results& m, + const std::basic_regex& reg) { + using Iterator = std::regex_iterator; + Iterator begin = Iterator(str.begin(), str.end(), reg); + Iterator end = Iterator(); + if (begin == end) + return false; + Iterator last_it; + for (auto it = begin; it != end; ++it) + last_it = it; + m = *last_it; + return true; +} + +static const hecl::SystemRegex regParsedHash32(_SYS_STR(R"(_([0-9a-fA-F]{8}))"), + std::regex::ECMAScript | std::regex::optimize); +uint32_t ProjectPath::parsedHash32() const { + if (!m_auxInfo.empty()) { + hecl::SystemRegexMatch match; + if (RegexSearchLast(m_auxInfo, match, regParsedHash32)) { + auto hexStr = match[1].str(); + if (auto val = hecl::StrToUl(hexStr.c_str(), nullptr, 16)) + return val; + } + } else { + hecl::SystemViewRegexMatch match; + if (RegexSearchLast(getLastComponent(), match, regParsedHash32)) { + auto hexStr = match[1].str(); + if (auto val = hecl::StrToUl(hexStr.c_str(), nullptr, 16)) + return val; + } + } + return hash().val32(); +} + +ProjectRootPath SearchForProject(SystemStringView path) { + ProjectRootPath testRoot(path); + auto begin = testRoot.getAbsolutePath().begin(); + auto end = testRoot.getAbsolutePath().end(); + while (begin != end) { + SystemString testPath(begin, end); + SystemString testIndexPath = testPath + _SYS_STR("/.hecl/beacon"); + Sstat theStat; + if (!hecl::Stat(testIndexPath.c_str(), &theStat)) { + if (S_ISREG(theStat.st_mode)) { + const auto fp = hecl::FopenUnique(testIndexPath.c_str(), _SYS_STR("rb")); + if (fp == nullptr) { + continue; + } + + char magic[4]; + const size_t readSize = std::fread(magic, 1, sizeof(magic), fp.get()); + if (readSize != sizeof(magic)) { + continue; + } + + static constexpr hecl::FourCC hecl("HECL"); + if (hecl::FourCC(magic) != hecl) { + continue; + } + + return ProjectRootPath(testPath); + } + } + + while (begin != end && *(end - 1) != _SYS_STR('/') && *(end - 1) != _SYS_STR('\\')) + --end; + if (begin != end) + --end; + } + return ProjectRootPath(); +} + +ProjectRootPath SearchForProject(SystemStringView path, SystemString& subpathOut) { + const ProjectRootPath testRoot(path); + auto begin = testRoot.getAbsolutePath().begin(); + auto end = testRoot.getAbsolutePath().end(); + + while (begin != end) { + SystemString testPath(begin, end); + SystemString testIndexPath = testPath + _SYS_STR("/.hecl/beacon"); + Sstat theStat; + + if (!hecl::Stat(testIndexPath.c_str(), &theStat)) { + if (S_ISREG(theStat.st_mode)) { + const auto fp = hecl::FopenUnique(testIndexPath.c_str(), _SYS_STR("rb")); + if (fp == nullptr) { + continue; + } + + char magic[4]; + const size_t readSize = std::fread(magic, 1, sizeof(magic), fp.get()); + if (readSize != sizeof(magic)) { + continue; + } + if (hecl::FourCC(magic) != FOURCC('HECL')) { + continue; + } + + const ProjectRootPath newRootPath = ProjectRootPath(testPath); + const auto origEnd = testRoot.getAbsolutePath().end(); + while (end != origEnd && *end != _SYS_STR('/') && *end != _SYS_STR('\\')) { + ++end; + } + if (end != origEnd && (*end == _SYS_STR('/') || *end == _SYS_STR('\\'))) { + ++end; + } + + subpathOut.assign(end, origEnd); + return newRootPath; + } + } + + while (begin != end && *(end - 1) != _SYS_STR('/') && *(end - 1) != _SYS_STR('\\')) { + --end; + } + if (begin != end) { + --end; + } + } + return ProjectRootPath(); +} + +} // namespace hecl diff --git a/hecl/lib/Runtime/CMakeLists.txt b/hecl/lib/Runtime/CMakeLists.txt new file mode 100644 index 000000000..409a62c83 --- /dev/null +++ b/hecl/lib/Runtime/CMakeLists.txt @@ -0,0 +1,4 @@ +set(RUNTIME_SOURCES + FileStoreManager.cpp) + +hecl_add_list(Runtime RUNTIME_SOURCES) diff --git a/hecl/lib/Runtime/FileStoreManager.cpp b/hecl/lib/Runtime/FileStoreManager.cpp new file mode 100644 index 000000000..505ad6f08 --- /dev/null +++ b/hecl/lib/Runtime/FileStoreManager.cpp @@ -0,0 +1,66 @@ +#include "hecl/Runtime.hpp" + +#include "hecl/hecl.hpp" + +#include + +#if _WIN32 +#include +#endif + +#if WINDOWS_STORE +using namespace Windows::Storage; +#endif + +namespace hecl::Runtime { +static logvisor::Module Log("FileStoreManager"); + +FileStoreManager::FileStoreManager(SystemStringView domain) : m_domain(domain) { +#if _WIN32 +#if !WINDOWS_STORE + WCHAR home[MAX_PATH]; + if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, home))) + Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("unable to locate profile for file store"))); + + SystemString path(home); +#else + StorageFolder ^ cacheFolder = ApplicationData::Current->LocalCacheFolder; + SystemString path(cacheFolder->Path->Data()); +#endif + path += _SYS_STR("/.heclrun"); + + hecl::MakeDir(path.c_str()); + path += _SYS_STR('/'); + path += domain.data(); + + hecl::MakeDir(path.c_str()); + m_storeRoot = path; +#elif defined(__SWITCH__) + std::string path = "/"; + path += domain.data(); + if (mkdir(path.c_str(), 0755) && errno != EEXIST) + Log.report(logvisor::Fatal, FMT_STRING("unable to mkdir at {}"), path); + m_storeRoot = path; +#else + const char* xdg_data_home = getenv("XDG_DATA_HOME"); + std::string path; + if (xdg_data_home) { + if (xdg_data_home[0] != '/') + Log.report(logvisor::Fatal, FMT_STRING("invalid $XDG_DATA_HOME for file store (must be absolute)")); + path = xdg_data_home; + } else { + const char* home = getenv("HOME"); + if (!home) + Log.report(logvisor::Fatal, FMT_STRING("unable to locate $HOME for file store")); + path = home; + path += "/.local/share"; + } + path += "/hecl/"; + path += domain.data(); + if (RecursiveMakeDir(path.c_str()) != 0) + Log.report(logvisor::Fatal, FMT_STRING("unable to mkdir at {}"), path); + m_storeRoot = path; +#endif +} + +} // namespace hecl::Runtime diff --git a/hecl/lib/SteamFinder.cpp b/hecl/lib/SteamFinder.cpp new file mode 100644 index 000000000..a930e5d5f --- /dev/null +++ b/hecl/lib/SteamFinder.cpp @@ -0,0 +1,105 @@ +#include "hecl/SteamFinder.hpp" +#include "hecl/hecl.hpp" +#ifdef WIN32 +#include +#define PATH_SEP L'\\' +#else +#define PATH_SEP '/' +#endif + +namespace hecl { + +/* Used to extract alternate steam install directories from libraryfolders.vdf */ +static const std::regex regSteamPath(R"(^\s+\"[0-9]+\"\s+\"(.*)\")", std::regex::ECMAScript | std::regex::optimize); + +hecl::SystemString FindCommonSteamApp(const hecl::SystemChar* name) { + hecl::SystemString steamInstallDir; + hecl::Sstat theStat; + +#ifdef WIN32 +#if !WINDOWS_STORE + HKEY hkey; + hecl::SystemChar _steamInstallDir[MAX_PATH] = {0}; + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _SYS_STR("Software\\Valve\\Steam"), 0, KEY_QUERY_VALUE, &hkey) != + ERROR_SUCCESS) { + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _SYS_STR("Software\\Valve\\Steam"), 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, + &hkey) != ERROR_SUCCESS) + return {}; + } + + DWORD size = MAX_PATH; + if (RegQueryValueEx(hkey, _SYS_STR("InstallPath"), nullptr, nullptr, (LPBYTE)_steamInstallDir, &size) == + ERROR_SUCCESS) + steamInstallDir = _steamInstallDir; + RegCloseKey(hkey); + + if (steamInstallDir.empty()) + return {}; +#else + return {}; +#endif + +#elif defined(__APPLE__) + steamInstallDir = getenv("HOME"); + steamInstallDir += "/Library/Application Support/Steam"; + if (hecl::Stat(steamInstallDir.c_str(), &theStat) || !S_ISDIR(theStat.st_mode)) + return {}; + +#else + steamInstallDir = getenv("HOME"); + steamInstallDir += "/.local/share/Steam"; + if (hecl::Stat(steamInstallDir.c_str(), &theStat) || !S_ISDIR(theStat.st_mode)) { + steamInstallDir = getenv("HOME"); + steamInstallDir += "/.steam/steam"; + if (hecl::Stat(steamInstallDir.c_str(), &theStat) || !S_ISDIR(theStat.st_mode)) + return {}; + } + +#endif + + const hecl::SystemString appPath = hecl::SystemString(_SYS_STR("common")) + PATH_SEP + name; + + /* Try main steam install directory first */ + const hecl::SystemString steamAppsMain = steamInstallDir + PATH_SEP + _SYS_STR("steamapps"); + const hecl::SystemString mainAppPath = steamAppsMain + PATH_SEP + appPath; + if (!hecl::Stat(mainAppPath.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) { + return mainAppPath; + } + + /* Iterate alternate steam install dirs */ + const hecl::SystemString libraryFoldersVdfPath = steamAppsMain + PATH_SEP + _SYS_STR("libraryfolders.vdf"); + auto fp = hecl::FopenUnique(libraryFoldersVdfPath.c_str(), _SYS_STR("r")); + if (fp == nullptr) { + return {}; + } + hecl::FSeek(fp.get(), 0, SEEK_END); + const int64_t fileLen = hecl::FTell(fp.get()); + if (fileLen <= 0) { + return {}; + } + hecl::FSeek(fp.get(), 0, SEEK_SET); + std::string fileBuf(fileLen, '\0'); + if (std::fread(fileBuf.data(), 1, fileLen, fp.get()) != fileLen) { + return {}; + } + + std::smatch dirMatch; + auto begin = fileBuf.cbegin(); + const auto end = fileBuf.cend(); + while (std::regex_search(begin, end, dirMatch, regSteamPath)) { + const std::string match = dirMatch[1].str(); + const hecl::SystemStringConv otherInstallDir(match); + const auto otherAppPath = + hecl::SystemString(otherInstallDir.sys_str()) + PATH_SEP + _SYS_STR("steamapps") + PATH_SEP + appPath; + + if (!hecl::Stat(otherAppPath.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) { + return otherAppPath; + } + + begin = dirMatch.suffix().first; + } + + return {}; +} + +} // namespace hecl diff --git a/hecl/lib/WideStringConvert.cpp b/hecl/lib/WideStringConvert.cpp new file mode 100644 index 000000000..036e3d385 --- /dev/null +++ b/hecl/lib/WideStringConvert.cpp @@ -0,0 +1,71 @@ +#include +#include + +namespace hecl { +static logvisor::Module Log("hecl-wsconv"); + +std::string WideToUTF8(std::wstring_view src) { + std::string retval; + retval.reserve(src.length()); + for (wchar_t ch : src) { + utf8proc_uint8_t mb[4]; + utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb); + if (c < 0) { + Log.report(logvisor::Warning, FMT_STRING("invalid UTF-8 character while encoding")); + return retval; + } + retval.append(reinterpret_cast(mb), c); + } + return retval; +} + +std::string Char16ToUTF8(std::u16string_view src) { + std::string retval; + retval.reserve(src.length()); + for (char16_t ch : src) { + utf8proc_uint8_t mb[4]; + utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb); + if (c < 0) { + Log.report(logvisor::Warning, FMT_STRING("invalid UTF-8 character while encoding")); + return retval; + } + retval.append(reinterpret_cast(mb), c); + } + return retval; +} + +std::wstring UTF8ToWide(std::string_view src) { + std::wstring retval; + retval.reserve(src.length()); + const utf8proc_uint8_t* buf = reinterpret_cast(src.data()); + while (*buf) { + utf8proc_int32_t wc; + utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc); + if (len < 0) { + Log.report(logvisor::Warning, FMT_STRING("invalid UTF-8 character while decoding")); + return retval; + } + buf += len; + retval += wchar_t(wc); + } + return retval; +} + +std::u16string UTF8ToChar16(std::string_view src) { + std::u16string retval; + retval.reserve(src.length()); + const utf8proc_uint8_t* buf = reinterpret_cast(src.data()); + while (*buf) { + utf8proc_int32_t wc; + utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc); + if (len < 0) { + Log.report(logvisor::Warning, FMT_STRING("invalid UTF-8 character while decoding")); + return retval; + } + buf += len; + retval += char16_t(wc); + } + return retval; +} + +} // namespace hecl diff --git a/hecl/lib/closefrom.c b/hecl/lib/closefrom.c new file mode 100644 index 000000000..d7e44bee9 --- /dev/null +++ b/hecl/lib/closefrom.c @@ -0,0 +1,139 @@ +/* + * Unix SMB/CIFS implementation. + * Samba utility functions + * Copyright (C) Volker Lendecke 2016 + * + * ** NOTE! The following LGPL license applies to the replace + * ** library. This does NOT imply that all of Samba is released + * ** under the LGPL + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include +#include +#include +#include + +static int closefrom_sysconf(int lower) +{ + long max_files, fd; + + max_files = sysconf(_SC_OPEN_MAX); + if (max_files == -1) { + max_files = 65536; + } + + for (fd=lower; fdd_name, &endptr, 10); + if ((fd == 0) && (errno == EINVAL)) { + continue; + } + if ((fd == ULLONG_MAX) && (errno == ERANGE)) { + continue; + } + if (*endptr != '\0') { + continue; + } + if (fd == dir_fd) { + continue; + } + if (fd > INT_MAX) { + continue; + } + if (fd < lower) { + continue; + } + + if (num_fds >= (fd_array_size / sizeof(int))) { + void *tmp; + + if (fd_array_size == 0) { + fd_array_size = 16 * sizeof(int); + } else { + if (fd_array_size + fd_array_size < + fd_array_size) { + /* overflow */ + goto fail; + } + fd_array_size = fd_array_size + fd_array_size; + } + + tmp = realloc(fds, fd_array_size); + if (tmp == NULL) { + goto fail; + } + fds = tmp; + } + + fds[num_fds++] = fd; + } + + for (i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +#include +#ifndef _WIN32_IE +#define _WIN32_IE 0x0400 +#endif +#include +#endif + +#ifdef __APPLE__ +#include +#endif + +#ifdef __linux__ +#include +#include +#endif + +#include + +using namespace std::literals; + +namespace hecl { +unsigned VerbosityLevel = 0; +bool GuiMode = false; +logvisor::Module LogModule("hecl"); +constexpr std::string_view Illegals = "<>?\""sv; + +void SanitizePath(std::string& path) { + if (path.empty()) + return; + path.erase(std::remove(path.begin(), path.end(), '\n'), path.end()); + path.erase(std::remove(path.begin(), path.end(), '\r'), path.end()); + std::string::iterator p1 = path.begin(); + bool ic = false; + std::transform(path.begin(), path.end(), path.begin(), [&](const char a) -> char { + ++p1; + if (Illegals.find_first_of(a) != std::string::npos) { + ic = false; + return '_'; + } + + if (ic) { + ic = false; + return a; + } + if (a == '\\' && (p1 == path.end() || *p1 != '\\')) { + ic = true; + return '/'; + } + return a; + }); + while (path.back() == '/') + path.pop_back(); +} + +constexpr std::wstring_view WIllegals = L"<>?\""sv; + +void SanitizePath(std::wstring& path) { + if (path.empty()) + return; + path.erase(std::remove(path.begin(), path.end(), L'\n'), path.end()); + path.erase(std::remove(path.begin(), path.end(), L'\r'), path.end()); + std::wstring::iterator p1 = path.begin(); + bool ic = false; + std::transform(path.begin(), path.end(), path.begin(), [&](const wchar_t a) -> wchar_t { + ++p1; + if (WIllegals.find_first_of(a) != std::wstring::npos) { + ic = false; + return L'_'; + } + + if (ic) { + ic = false; + return a; + } + if (a == L'\\' && (p1 == path.end() || *p1 != L'\\')) { + ic = true; + return L'/'; + } + return a; + }); + while (path.back() == L'/') + path.pop_back(); +} + +SystemString GetcwdStr() { + /* http://stackoverflow.com/a/2869667 */ + // const size_t ChunkSize=255; + // const int MaxChunks=10240; // 2550 KiBs of current path are more than enough + + SystemChar stackBuffer[255]; // Stack buffer for the "normal" case + if (Getcwd(stackBuffer, int(std::size(stackBuffer))) != nullptr) { + return SystemString(stackBuffer); + } + if (errno != ERANGE) { + // It's not ERANGE, so we don't know how to handle it + LogModule.report(logvisor::Fatal, FMT_STRING("Cannot determine the current path.")); + // Of course you may choose a different error reporting method + } + // Ok, the stack buffer isn't long enough; fallback to heap allocation + for (int chunks = 2; chunks < 10240; chunks++) { + // With boost use scoped_ptr; in C++0x, use unique_ptr + // If you want to be less C++ but more efficient you may want to use realloc + const int bufSize = 255 * chunks; + std::unique_ptr cwd(new SystemChar[bufSize]); + if (Getcwd(cwd.get(), bufSize) != nullptr) { + return SystemString(cwd.get()); + } + if (errno != ERANGE) { + // It's not ERANGE, so we don't know how to handle it + LogModule.report(logvisor::Fatal, FMT_STRING("Cannot determine the current path.")); + // Of course you may choose a different error reporting method + } + } + LogModule.report(logvisor::Fatal, FMT_STRING("Cannot determine the current path; the path is apparently unreasonably long")); + return SystemString(); +} + +static std::mutex PathsMutex; +static std::unordered_map PathsInProgress; + +bool ResourceLock::InProgress(const ProjectPath& path) { + std::unique_lock lk{PathsMutex}; + return std::any_of(PathsInProgress.cbegin(), PathsInProgress.cend(), + [&path](const auto& entry) { return entry.second == path; }); +} + +bool ResourceLock::SetThreadRes(const ProjectPath& path) { + std::unique_lock lk{PathsMutex}; + if (PathsInProgress.find(std::this_thread::get_id()) != PathsInProgress.cend()) { + LogModule.report(logvisor::Fatal, FMT_STRING("multiple resource locks on thread")); + } + + const bool isInProgress = std::any_of(PathsInProgress.cbegin(), PathsInProgress.cend(), + [&path](const auto& entry) { return entry.second == path; }); + if (isInProgress) { + return false; + } + + PathsInProgress.insert_or_assign(std::this_thread::get_id(), path); + return true; +} + +void ResourceLock::ClearThreadRes() { + std::unique_lock lk{PathsMutex}; + PathsInProgress.erase(std::this_thread::get_id()); +} + +bool IsPathPNG(const hecl::ProjectPath& path) { + const auto fp = hecl::FopenUnique(path.getAbsolutePath().data(), _SYS_STR("rb")); + if (fp == nullptr) { + return false; + } + + uint32_t buf = 0; + if (std::fread(&buf, 1, sizeof(buf), fp.get()) != sizeof(buf)) { + return false; + } + + buf = hecl::SBig(buf); + return buf == 0x89504e47; +} + +bool IsPathBlend(const hecl::ProjectPath& path) { + const auto lastCompExt = path.getLastComponentExt(); + if (lastCompExt.empty() || lastCompExt != _SYS_STR("blend")) + return false; + + const auto fp = hecl::FopenUnique(path.getAbsolutePath().data(), _SYS_STR("rb")); + if (fp == nullptr) { + return false; + } + + uint32_t buf = 0; + if (std::fread(&buf, 1, sizeof(buf), fp.get()) != sizeof(buf)) { + return false; + } + + buf = hecl::SLittle(buf); + return buf == 0x4e454c42 || buf == 0x88b1f; +} + +bool IsPathYAML(const hecl::ProjectPath& path) { + auto lastComp = path.getLastComponent(); + if (lastComp == _SYS_STR("!catalog.yaml") || + lastComp == _SYS_STR("!memoryid.yaml") || + lastComp == _SYS_STR("!memoryrelays.yaml")) + return false; /* !catalog.yaml, !memoryid.yaml, !memoryrelays.yaml are exempt from general use */ + auto lastCompExt = path.getLastComponentExt(); + if (lastCompExt.empty()) + return false; + return lastCompExt == _SYS_STR("yaml") || lastCompExt == _SYS_STR("yml"); +} + +hecl::DirectoryEnumerator::DirectoryEnumerator(SystemStringView path, Mode mode, bool sizeSort, bool reverse, + bool noHidden) { + hecl::Sstat theStat; + if (hecl::Stat(path.data(), &theStat) || !S_ISDIR(theStat.st_mode)) + return; + +#if _WIN32 + hecl::SystemString wc(path); + wc += _SYS_STR("/*"); + WIN32_FIND_DATAW d; + HANDLE dir = FindFirstFileW(wc.c_str(), &d); + if (dir == INVALID_HANDLE_VALUE) + return; + switch (mode) { + case Mode::Native: + do { + if (!wcscmp(d.cFileName, _SYS_STR(".")) || !wcscmp(d.cFileName, _SYS_STR(".."))) + continue; + if (noHidden && (d.cFileName[0] == L'.' || (d.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)) + continue; + hecl::SystemString fp(path); + fp += _SYS_STR('/'); + fp += d.cFileName; + hecl::Sstat st; + if (hecl::Stat(fp.c_str(), &st)) + continue; + + size_t sz = 0; + bool isDir = false; + if (S_ISDIR(st.st_mode)) + isDir = true; + else if (S_ISREG(st.st_mode)) + sz = st.st_size; + else + continue; + + m_entries.emplace_back(fp, d.cFileName, sz, isDir); + } while (FindNextFileW(dir, &d)); + break; + case Mode::DirsThenFilesSorted: + case Mode::DirsSorted: { + std::map sort; + do { + if (!wcscmp(d.cFileName, _SYS_STR(".")) || !wcscmp(d.cFileName, _SYS_STR(".."))) + continue; + if (noHidden && (d.cFileName[0] == L'.' || (d.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)) + continue; + hecl::SystemString fp(path); + fp += _SYS_STR('/'); + fp += d.cFileName; + hecl::Sstat st; + if (hecl::Stat(fp.c_str(), &st) || !S_ISDIR(st.st_mode)) + continue; + sort.emplace(std::make_pair(d.cFileName, Entry(std::move(fp), d.cFileName, 0, true))); + } while (FindNextFileW(dir, &d)); + + if (reverse) + for (auto it = sort.crbegin(); it != sort.crend(); ++it) + m_entries.push_back(std::move(it->second)); + else + for (auto& e : sort) + m_entries.push_back(std::move(e.second)); + + if (mode == Mode::DirsSorted) + break; + FindClose(dir); + dir = FindFirstFileW(wc.c_str(), &d); + } + case Mode::FilesSorted: { + if (mode == Mode::FilesSorted) + m_entries.clear(); + + if (sizeSort) { + std::multimap sort; + do { + if (!wcscmp(d.cFileName, _SYS_STR(".")) || !wcscmp(d.cFileName, _SYS_STR(".."))) + continue; + if (noHidden && (d.cFileName[0] == L'.' || (d.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)) + continue; + hecl::SystemString fp(path); + fp += _SYS_STR('/'); + fp += d.cFileName; + hecl::Sstat st; + if (hecl::Stat(fp.c_str(), &st) || !S_ISREG(st.st_mode)) + continue; + sort.emplace(std::make_pair(st.st_size, Entry(std::move(fp), d.cFileName, st.st_size, false))); + } while (FindNextFileW(dir, &d)); + + if (reverse) + for (auto it = sort.crbegin(); it != sort.crend(); ++it) + m_entries.push_back(std::move(it->second)); + else + for (auto& e : sort) + m_entries.push_back(std::move(e.second)); + } else { + std::map sort; + do { + if (!wcscmp(d.cFileName, _SYS_STR(".")) || !wcscmp(d.cFileName, _SYS_STR(".."))) + continue; + if (noHidden && (d.cFileName[0] == L'.' || (d.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)) + continue; + hecl::SystemString fp(path); + fp += _SYS_STR('/'); + fp += d.cFileName; + hecl::Sstat st; + if (hecl::Stat(fp.c_str(), &st) || !S_ISREG(st.st_mode)) + continue; + sort.emplace(std::make_pair(d.cFileName, Entry(std::move(fp), d.cFileName, st.st_size, false))); + } while (FindNextFileW(dir, &d)); + + if (reverse) + for (auto it = sort.crbegin(); it != sort.crend(); ++it) + m_entries.push_back(std::move(it->second)); + else + for (auto& e : sort) + m_entries.push_back(std::move(e.second)); + } + + break; + } + } + FindClose(dir); + +#else + + DIR* dir = opendir(path.data()); + if (!dir) + return; + const dirent* d; + switch (mode) { + case Mode::Native: + while ((d = readdir(dir))) { + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) + continue; + if (noHidden && d->d_name[0] == '.') + continue; + hecl::SystemString fp(path); + fp += '/'; + fp += d->d_name; + hecl::Sstat st; + if (hecl::Stat(fp.c_str(), &st)) + continue; + + size_t sz = 0; + bool isDir = false; + if (S_ISDIR(st.st_mode)) + isDir = true; + else if (S_ISREG(st.st_mode)) + sz = st.st_size; + else + continue; + + m_entries.push_back(Entry(std::move(fp), d->d_name, sz, isDir)); + } + break; + case Mode::DirsThenFilesSorted: + case Mode::DirsSorted: { + std::map sort; + while ((d = readdir(dir))) { + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) + continue; + if (noHidden && d->d_name[0] == '.') + continue; + hecl::SystemString fp(path); + fp += '/'; + fp += d->d_name; + hecl::Sstat st; + if (hecl::Stat(fp.c_str(), &st) || !S_ISDIR(st.st_mode)) + continue; + sort.emplace(std::make_pair(d->d_name, Entry(std::move(fp), d->d_name, 0, true))); + } + + if (reverse) + for (auto it = sort.crbegin(); it != sort.crend(); ++it) + m_entries.push_back(std::move(it->second)); + else + for (auto& e : sort) + m_entries.push_back(std::move(e.second)); + + if (mode == Mode::DirsSorted) + break; +#ifdef __SWITCH__ + // rewinddir is broken + closedir(dir); + dir = opendir(path.data()); +#else + rewinddir(dir); +#endif + [[fallthrough]]; + } + case Mode::FilesSorted: { + if (mode == Mode::FilesSorted) + m_entries.clear(); + + if (sizeSort) { + std::multimap sort; + while ((d = readdir(dir))) { + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) + continue; + if (noHidden && d->d_name[0] == '.') + continue; + hecl::SystemString fp(path); + fp += '/'; + fp += d->d_name; + hecl::Sstat st; + if (hecl::Stat(fp.c_str(), &st) || !S_ISREG(st.st_mode)) + continue; + sort.emplace(std::make_pair(st.st_size, Entry(std::move(fp), d->d_name, st.st_size, false))); + } + + if (reverse) + for (auto it = sort.crbegin(); it != sort.crend(); ++it) + m_entries.push_back(std::move(it->second)); + else + for (auto& e : sort) + m_entries.push_back(std::move(e.second)); + } else { + std::map sort; + while ((d = readdir(dir))) { + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) + continue; + if (noHidden && d->d_name[0] == '.') + continue; + hecl::SystemString fp(path); + fp += '/'; + fp += d->d_name; + hecl::Sstat st; + if (hecl::Stat(fp.c_str(), &st) || !S_ISREG(st.st_mode)) + continue; + sort.emplace(std::make_pair(d->d_name, Entry(std::move(fp), d->d_name, st.st_size, false))); + } + + if (reverse) + for (auto it = sort.crbegin(); it != sort.crend(); ++it) + m_entries.push_back(std::move(it->second)); + else + for (auto& e : sort) + m_entries.push_back(std::move(e.second)); + } + + break; + } + } + closedir(dir); + +#endif +} + +static std::pair NameFromPath(hecl::SystemStringView path) { + hecl::SystemUTF8Conv utf8(path); + if (utf8.str().size() == 1 && utf8.str()[0] == '/') + return {hecl::SystemString(path), "/"}; + size_t lastSlash = utf8.str().rfind('/'); + if (lastSlash != std::string::npos) + return {hecl::SystemString(path), std::string(utf8.str().cbegin() + lastSlash + 1, utf8.str().cend())}; + else + return {hecl::SystemString(path), std::string(utf8.str())}; +} + +std::vector> GetSystemLocations() { + std::vector> ret; +#ifdef WIN32 +#if !WINDOWS_STORE + /* Add the drive names to the listing (as queried by blender) */ + { + constexpr uint32_t FILE_MAXDIR = 768; + wchar_t wline[FILE_MAXDIR]; + const uint32_t tmp = GetLogicalDrives(); + + for (uint32_t i = 0; i < 26; i++) { + if ((tmp >> i) & 1) { + wline[0] = L'A' + i; + wline[1] = L':'; + wline[2] = L'/'; + wline[3] = L'\0'; + wchar_t* name = nullptr; + + /* Flee from horrible win querying hover floppy drives! */ + if (i > 1) { + /* Try to get volume label as well... */ + if (GetVolumeInformationW(wline, wline + 4, FILE_MAXDIR - 4, nullptr, nullptr, nullptr, nullptr, 0)) { + const size_t labelLen = std::wcslen(wline + 4); + _snwprintf(wline + 4 + labelLen, FILE_MAXDIR - 4 - labelLen, L" (%.2s)", wline); + name = wline + 4; + } + } + + wline[2] = L'\0'; + if (name == nullptr) { + ret.push_back(NameFromPath(wline)); + } else { + ret.emplace_back(wline, hecl::WideToUTF8(name)); + } + } + } + + /* Adding Desktop and My Documents */ + SystemString wpath; + SHGetSpecialFolderPathW(nullptr, wline, CSIDL_PERSONAL, 0); + wpath.assign(wline); + SanitizePath(wpath); + ret.push_back(NameFromPath(wpath)); + SHGetSpecialFolderPathW(nullptr, wline, CSIDL_DESKTOPDIRECTORY, 0); + wpath.assign(wline); + SanitizePath(wpath); + ret.push_back(NameFromPath(wpath)); + } +#endif +#else +#ifdef __APPLE__ + { + hecl::Sstat theStat; + const char* home = getenv("HOME"); + + if (home) { + ret.push_back(NameFromPath(home)); + std::string desktop(home); + desktop += "/Desktop"; + if (!hecl::Stat(desktop.c_str(), &theStat)) + ret.push_back(NameFromPath(desktop)); + } + + /* Get mounted volumes better method OSX 10.6 and higher, see: */ + /*https://developer.apple.com/library/mac/#documentation/CoreFOundation/Reference/CFURLRef/Reference/reference.html*/ + /* we get all volumes sorted including network and do not relay on user-defined finder visibility, less confusing */ + + CFURLRef cfURL = nullptr; + CFURLEnumeratorResult result = kCFURLEnumeratorSuccess; + CFURLEnumeratorRef volEnum = + CFURLEnumeratorCreateForMountedVolumes(nullptr, kCFURLEnumeratorSkipInvisibles, nullptr); + + while (result != kCFURLEnumeratorEnd) { + char defPath[1024]; + + result = CFURLEnumeratorGetNextURL(volEnum, &cfURL, nullptr); + if (result != kCFURLEnumeratorSuccess) { + continue; + } + + CFURLGetFileSystemRepresentation(cfURL, false, reinterpret_cast(defPath), std::size(defPath)); + ret.push_back(NameFromPath(defPath)); + } + + CFRelease(volEnum); + } +#else + /* unix */ + { + hecl::Sstat theStat; + const char* home = getenv("HOME"); + + if (home) { + ret.push_back(NameFromPath(home)); + std::string desktop(home); + desktop += "/Desktop"; + if (!hecl::Stat(desktop.c_str(), &theStat)) + ret.push_back(NameFromPath(desktop)); + } + + { + bool found = false; +#ifdef __linux__ + /* Loop over mount points */ + struct mntent* mnt; + + FILE* fp = setmntent(MOUNTED, "r"); + if (fp) { + while ((mnt = getmntent(fp))) { + if (strlen(mnt->mnt_fsname) < 4 || strncmp(mnt->mnt_fsname, "/dev", 4)) + continue; + + std::string mntStr(mnt->mnt_dir); + if (mntStr.size() > 1 && mntStr.back() == '/') + mntStr.pop_back(); + ret.push_back(NameFromPath(mntStr)); + + found = true; + } + endmntent(fp); + } +#endif + /* Fallback */ + if (!found) + ret.push_back(NameFromPath("/")); + } + } +#endif +#endif + return ret; +} + +std::wstring Char16ToWide(std::u16string_view src) { return std::wstring(src.begin(), src.end()); } + +/* recursive mkdir */ +#if _WIN32 +int RecursiveMakeDir(const SystemChar* dir) { + SystemChar tmp[1024]; + + /* copy path */ + std::wcsncpy(tmp, dir, std::size(tmp)); + const size_t len = std::wcslen(tmp); + if (len >= std::size(tmp)) { + return -1; + } + + /* remove trailing slash */ + if (tmp[len - 1] == '/' || tmp[len - 1] == '\\') { + tmp[len - 1] = 0; + } + + /* recursive mkdir */ + SystemChar* p = nullptr; + Sstat sb; + for (p = tmp + 1; *p; p++) { + if (*p == '/' || *p == '\\') { + *p = 0; + /* test path */ + if (Stat(tmp, &sb) != 0) { + /* path does not exist - create directory */ + if (!CreateDirectoryW(tmp, nullptr)) { + return -1; + } + } else if (!S_ISDIR(sb.st_mode)) { + /* not a directory */ + return -1; + } + *p = '/'; + } + } + /* test path */ + if (Stat(tmp, &sb) != 0) { + /* path does not exist - create directory */ + if (!CreateDirectoryW(tmp, nullptr)) { + return -1; + } + } else if (!S_ISDIR(sb.st_mode)) { + /* not a directory */ + return -1; + } + return 0; +} +#else +int RecursiveMakeDir(const SystemChar* dir) { + SystemChar tmp[1024]; + + /* copy path */ + std::memset(tmp, 0, std::size(tmp)); + std::strncpy(tmp, dir, std::size(tmp) - 1); + const size_t len = std::strlen(tmp); + if (len >= std::size(tmp) - 1) { + return -1; + } + + /* remove trailing slash */ + if (tmp[len - 1] == '/') { + tmp[len - 1] = 0; + } + + /* recursive mkdir */ + SystemChar* p = nullptr; + Sstat sb; + for (p = tmp + 1; *p; p++) { + if (*p == '/') { + *p = 0; + /* test path */ + if (Stat(tmp, &sb) != 0) { + /* path does not exist - create directory */ + if (mkdir(tmp, 0755) < 0) { + return -1; + } + } else if (!S_ISDIR(sb.st_mode)) { + /* not a directory */ + return -1; + } + *p = '/'; + } + } + /* test path */ + if (Stat(tmp, &sb) != 0) { + /* path does not exist - create directory */ + if (mkdir(tmp, 0755) < 0) { + return -1; + } + } else if (!S_ISDIR(sb.st_mode)) { + /* not a directory */ + return -1; + } + return 0; +} +#endif + +const SystemChar* GetTmpDir() { +#ifdef _WIN32 +#if WINDOWS_STORE + const wchar_t* TMPDIR = nullptr; +#else + const wchar_t* TMPDIR = _wgetenv(L"TEMP"); + if (!TMPDIR) + TMPDIR = L"\\Temp"; +#endif +#else + const char* TMPDIR = getenv("TMPDIR"); + if (!TMPDIR) + TMPDIR = "/tmp"; +#endif + return TMPDIR; +} + +#if !WINDOWS_STORE +int RunProcess(const SystemChar* path, const SystemChar* const args[]) { +#ifdef _WIN32 + SECURITY_ATTRIBUTES sattrs = {sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE}; + HANDLE consoleOutReadTmp = INVALID_HANDLE_VALUE; + HANDLE consoleOutWrite = INVALID_HANDLE_VALUE; + if (!CreatePipe(&consoleOutReadTmp, &consoleOutWrite, &sattrs, 0)) { + LogModule.report(logvisor::Fatal, FMT_STRING("Error with CreatePipe")); + return -1; + } + + HANDLE consoleErrWrite = INVALID_HANDLE_VALUE; + if (!DuplicateHandle(GetCurrentProcess(), consoleOutWrite, GetCurrentProcess(), &consoleErrWrite, 0, TRUE, + DUPLICATE_SAME_ACCESS)) { + LogModule.report(logvisor::Fatal, FMT_STRING("Error with DuplicateHandle")); + CloseHandle(consoleOutReadTmp); + CloseHandle(consoleOutWrite); + return -1; + } + + HANDLE consoleOutRead = INVALID_HANDLE_VALUE; + if (!DuplicateHandle(GetCurrentProcess(), consoleOutReadTmp, GetCurrentProcess(), + &consoleOutRead, // Address of new handle. + 0, FALSE, // Make it uninheritable. + DUPLICATE_SAME_ACCESS)) { + LogModule.report(logvisor::Fatal, FMT_STRING("Error with DuplicateHandle")); + CloseHandle(consoleOutReadTmp); + CloseHandle(consoleOutWrite); + CloseHandle(consoleErrWrite); + return -1; + } + + CloseHandle(consoleOutReadTmp); + + hecl::SystemString cmdLine; + const SystemChar* const* arg = &args[1]; + while (*arg) { + cmdLine += _SYS_STR(" \""); + cmdLine += *arg++; + cmdLine += _SYS_STR('"'); + } + + STARTUPINFO sinfo = {sizeof(STARTUPINFO)}; + HANDLE nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sattrs, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, nullptr); + sinfo.dwFlags = STARTF_USESTDHANDLES; + sinfo.hStdInput = nulHandle; + sinfo.hStdError = consoleErrWrite; + sinfo.hStdOutput = consoleOutWrite; + + PROCESS_INFORMATION pinfo = {}; + if (!CreateProcessW(path, cmdLine.data(), nullptr, nullptr, TRUE, NORMAL_PRIORITY_CLASS, nullptr, nullptr, &sinfo, + &pinfo)) { + LPWSTR messageBuffer = nullptr; + FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, + GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, nullptr); + LogModule.report(logvisor::Error, FMT_STRING(L"unable to launch process from {}: {}"), path, messageBuffer); + LocalFree(messageBuffer); + + CloseHandle(nulHandle); + CloseHandle(consoleErrWrite); + CloseHandle(consoleOutWrite); + CloseHandle(consoleOutRead); + return -1; + } + + CloseHandle(nulHandle); + CloseHandle(consoleErrWrite); + CloseHandle(consoleOutWrite); + + bool consoleThreadRunning = true; + auto consoleThread = std::thread([=, &consoleThreadRunning]() { + CHAR lpBuffer[256]; + DWORD nBytesRead; + DWORD nCharsWritten; + + while (consoleThreadRunning) { + if (!ReadFile(consoleOutRead, lpBuffer, sizeof(lpBuffer), &nBytesRead, nullptr) || !nBytesRead) { + DWORD err = GetLastError(); + if (err == ERROR_BROKEN_PIPE) + break; // pipe done - normal exit path. + else + LogModule.report(logvisor::Error, FMT_STRING("Error with ReadFile: {:08X}"), err); // Something bad happened. + } + + // Display the character read on the screen. + auto lk = logvisor::LockLog(); + if (!WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), lpBuffer, nBytesRead, &nCharsWritten, nullptr)) { + // LogModule.report(logvisor::Error, FMT_STRING("Error with WriteConsole: {:08X}"), GetLastError()); + } + } + + CloseHandle(consoleOutRead); + }); + + WaitForSingleObject(pinfo.hProcess, INFINITE); + DWORD ret; + if (!GetExitCodeProcess(pinfo.hProcess, &ret)) + ret = -1; + consoleThreadRunning = false; + if (consoleThread.joinable()) + consoleThread.join(); + + CloseHandle(pinfo.hProcess); + CloseHandle(pinfo.hThread); + + return ret; +#elif !defined(__SWITCH__) + pid_t pid = fork(); + if (!pid) { + closefrom(3); + execvp(path, (char* const*)args); + exit(1); + } + int ret; + if (waitpid(pid, &ret, 0) < 0) + return -1; + if (WIFEXITED(ret)) + return WEXITSTATUS(ret); + return -1; +#else + return -1; +#endif +} +#endif + +} // namespace hecl diff --git a/kabufuda b/kabufuda deleted file mode 160000 index b58530500..000000000 --- a/kabufuda +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b585305009dfad79060b2c020b1541aba9adc211 diff --git a/lldb-extras/.lldbinit b/lldb-extras/.lldbinit index 130bb0d8b..a1028cd63 100644 --- a/lldb-extras/.lldbinit +++ b/lldb-extras/.lldbinit @@ -1,6 +1,6 @@ -command script import ~/urde_lldb_tools.py -type synthetic add zeus::CMatrix3f --python-class urde_lldb_tools.CMatrix3f_Provider -type synthetic add zeus::CMatrix4f --python-class urde_lldb_tools.CMatrix4f_Provider +command script import ~/metaforce_lldb_tools.py +type synthetic add zeus::CMatrix3f --python-class metaforce_lldb_tools.CMatrix3f_Provider +type synthetic add zeus::CMatrix4f --python-class metaforce_lldb_tools.CMatrix4f_Provider type summary add --summary-string "(${var.__s_.__storage_[0]}, ${var.__s_.__storage_[1]}, ${var.__s_.__storage_[2]}, ${var.__s_.__storage_[3]})" zeus::simd type summary add --summary-string "(${var.__s_.__storage_[0]}, ${var.__s_.__storage_[1]}, ${var.__s_.__storage_[2]}, ${var.__s_.__storage_[3]})" zeus::simd @@ -21,147 +21,147 @@ type summary add --summary-string "start=${var.x0_start} dir=${var.xc_dir} end=$ type summary add --summary-string "pos=${var.position} size=${var.size}" zeus::CRectangle type summary add --summary-string "${var.origin}" zeus::CTransform -type summary add --summary-string "${var.id%x} area=${var.id[16-25]}, layer=${var.id[26-31]}, id=${var.id[0-15]}" urde::TEditorId -type summary add --summary-string "${var.id}" urde::TUniqueId +type summary add --summary-string "${var.id%x} area=${var.id[16-25]}, layer=${var.id[26-31]}, id=${var.id[0-15]}" metaforce::TEditorId +type summary add --summary-string "${var.id}" metaforce::TUniqueId -type summary add --summary-string "${var.x0_time}" urde::CCharAnimTime +type summary add --summary-string "${var.x0_time}" metaforce::CCharAnimTime -type summary add --summary-string "${var.id%x}" urde::CAssetId -type summary add --summary-string "${var.type.fcc} ${var.id.id%x}" urde::SObjectTag +type summary add --summary-string "${var.id%x}" metaforce::CAssetId +type summary add --summary-string "${var.type.fcc} ${var.id.id%x}" metaforce::SObjectTag # \s*(\S+) \((\S+)\) # type summary add --summary-string "\${var.x10_name} \${var.xc_editorId}" $2::$1\n -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}, active=${var.x30_24_active}" urde::CEntity -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CActor -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CEffect -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CExplosion -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CHUDBillboardEffect -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CIceImpact -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CFire -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CFishCloud -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CFishCloudModifier -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CGameCamera -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CBallCamera -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CCinematicCamera -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CFirstPersonCamera -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CInterpolationCamera -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CPathCamera -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptSpindleCamera -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CGameLight -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CPhysicsActor -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CAi -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CDestroyableRock -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CPatterned -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CAtomicAlpha -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CBabygoth -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CBeetle -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CBloodFlower -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CBurrower -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CChozoGhost -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CElitePirate -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CEyeball -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CFireFlea -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CFlickerBat -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CFlyingPirate -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CMagdolite -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CMetaree -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CMetroid -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CMetroidBeta -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CMetroidPrimeExo -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CNewIntroBoss -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CPuddleToadGamma -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CPuffer -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CRidley -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CSpacePirate -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CThardusRockProjectile -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CTryclops -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CWallWalker -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CParasite -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CSeedling -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CWarWasp -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CAmbientAI -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CCollisionActor -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CPlayer -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptActor -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CActorContraption -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptPlayerActor -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptDebris -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptDock -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptDoor -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptGunTurret -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptPickup -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptPlatform -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CRepulsor -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptAiJumpPoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptBeam -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCameraHint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCameraHintTrigger -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCameraPitchVolume -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCameraWaypoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCoverPoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptDamageableTrigger -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptDebugCameraWaypoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptEffect -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptEMPulse -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptGrapplePoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptMazeNode -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptPlayerHint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptPointOfInterest -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptShadowProjector -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptSound -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptSpecialFunction -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptSpiderBallAttractionSurface -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptSpiderBallWaypoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptTargetingPoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptTrigger -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptBallTrigger -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptSteam -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptWater -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptVisorFlare -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptVisorGoo -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptWaypoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CSnakeWeedSwarm -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CWallCrawlerSwarm -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CWeapon -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CBomb -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CGameProjectile -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CBeamProjectile -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CPlasmaProjectile -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CEnergyProjectile -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CFlaahgraProjectile -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CMetroidPrimeProjectile -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CTargetableProjectile -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CFlameThrower -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CNewFlameThrower -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CWaveBuster -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CPowerBomb -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CFireFlea::CDeathCameraEffect -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::MP1::CMetroidPrimeRelay -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptActorKeyframe -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptActorRotate -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptAreaAttributes -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCameraBlurKeyframe -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCameraFilterKeyframe -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCameraShaker -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptColorModulate -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptControllerAction -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptCounter -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptDistanceFog -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptDockAreaChange -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptGenerator -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptHUDMemo -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptMemoryRelay -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptMidi -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptPickupGenerator -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptPlayerStateChange -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptRandomRelay -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptRelay -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptRipple -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptRoomAcoustics -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptSpawnPoint -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptStreamedMusic -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptSwitch -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptTimer -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CScriptWorldTeleporter -type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" urde::CTeamAiMgr +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}, active=${var.x30_24_active}" metaforce::CEntity +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CActor +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CEffect +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CExplosion +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CHUDBillboardEffect +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CIceImpact +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CFire +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CFishCloud +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CFishCloudModifier +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CGameCamera +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CBallCamera +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CCinematicCamera +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CFirstPersonCamera +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CInterpolationCamera +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CPathCamera +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptSpindleCamera +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CGameLight +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CPhysicsActor +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CAi +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CDestroyableRock +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CPatterned +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CAtomicAlpha +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CBabygoth +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CBeetle +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CBloodFlower +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CBurrower +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CChozoGhost +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CElitePirate +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CEyeball +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CFireFlea +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CFlickerBat +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CFlyingPirate +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CMagdolite +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CMetaree +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CMetroid +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CMetroidBeta +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CMetroidPrimeExo +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CNewIntroBoss +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CPuddleToadGamma +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CPuffer +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CRidley +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CSpacePirate +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CThardusRockProjectile +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CTryclops +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CWallWalker +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CParasite +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CSeedling +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CWarWasp +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CAmbientAI +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CCollisionActor +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CPlayer +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptActor +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CActorContraption +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptPlayerActor +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptDebris +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptDock +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptDoor +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptGunTurret +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptPickup +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptPlatform +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CRepulsor +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptAiJumpPoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptBeam +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCameraHint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCameraHintTrigger +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCameraPitchVolume +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCameraWaypoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCoverPoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptDamageableTrigger +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptDebugCameraWaypoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptEffect +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptEMPulse +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptGrapplePoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptMazeNode +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptPlayerHint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptPointOfInterest +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptShadowProjector +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptSound +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptSpecialFunction +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptSpiderBallAttractionSurface +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptSpiderBallWaypoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptTargetingPoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptTrigger +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptBallTrigger +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptSteam +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptWater +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptVisorFlare +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptVisorGoo +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptWaypoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CSnakeWeedSwarm +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CWallCrawlerSwarm +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CWeapon +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CBomb +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CGameProjectile +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CBeamProjectile +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CPlasmaProjectile +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CEnergyProjectile +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CFlaahgraProjectile +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CMetroidPrimeProjectile +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CTargetableProjectile +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CFlameThrower +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CNewFlameThrower +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CWaveBuster +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CPowerBomb +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CFireFlea::CDeathCameraEffect +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::MP1::CMetroidPrimeRelay +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptActorKeyframe +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptActorRotate +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptAreaAttributes +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCameraBlurKeyframe +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCameraFilterKeyframe +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCameraShaker +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptColorModulate +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptControllerAction +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptCounter +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptDistanceFog +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptDockAreaChange +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptGenerator +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptHUDMemo +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptMemoryRelay +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptMidi +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptPickupGenerator +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptPlayerStateChange +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptRandomRelay +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptRelay +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptRipple +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptRoomAcoustics +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptSpawnPoint +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptStreamedMusic +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptSwitch +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptTimer +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CScriptWorldTeleporter +type summary add --summary-string "${var.x10_name} ${var.xc_editorId}" metaforce::CTeamAiMgr diff --git a/lldb-extras/README.txt b/lldb-extras/README.txt index 5499d6a9d..7b6cddce5 100644 --- a/lldb-extras/README.txt +++ b/lldb-extras/README.txt @@ -1,3 +1,3 @@ -Copy (or append) .lldbinit and urde_lldb_tools.py to your home directory to -enable various URDE type summaries in LLDB. +Copy (or append) .lldbinit and metaforce_lldb_tools.py to your home directory to +enable various Metaforce type summaries in LLDB. diff --git a/lldb-extras/urde_lldb_tools.py b/lldb-extras/metaforce_lldb_tools.py similarity index 100% rename from lldb-extras/urde_lldb_tools.py rename to lldb-extras/metaforce_lldb_tools.py diff --git a/lxd-build-appimage.sh b/lxd-build-appimage.sh new file mode 100755 index 000000000..c9e6a5da0 --- /dev/null +++ b/lxd-build-appimage.sh @@ -0,0 +1,74 @@ +#!/bin/bash -ex + +############################################################### +# Uses LXD to create an Ubuntu focal container and produce # +# a reasonably portable AppImage of Metaforce. # +############################################################### + +VERSION=${VERSION:-local} +CONTAINER_NAME=metaforce-ci + +# Set up container, deleting existing if necessary +if lxc info $CONTAINER_NAME >& /dev/null +then + lxc delete $CONTAINER_NAME --force +fi +lxc init ubuntu:20.04 $CONTAINER_NAME + +# Inject build script +lxc file push - $CONTAINER_NAME/root/dobuild.sh </dev/null; do echo 'Waiting for network...'; sleep 1; done" + +# Run build script +lxc exec $CONTAINER_NAME -t -- bash /root/dobuild.sh + +# Retrieve AppImage +lxc file pull $CONTAINER_NAME/URDE-$VERSION-$(uname -m).AppImage . + +# Cleanup +lxc delete $CONTAINER_NAME --force diff --git a/metaforce-gui/ArgumentEditor.cpp b/metaforce-gui/ArgumentEditor.cpp new file mode 100644 index 000000000..db1d9c038 --- /dev/null +++ b/metaforce-gui/ArgumentEditor.cpp @@ -0,0 +1,67 @@ +#include "ArgumentEditor.hpp" +#include "ui_ArgumentEditor.h" +//#include "CVarDialog.hpp" +#include +#include +#include + +ArgumentEditor::ArgumentEditor(QWidget* parent) : QDialog(parent), m_ui(std::make_unique()) { + m_ui->setupUi(this); + m_model.setStringList(QSettings().value(QStringLiteral("metaforce_arguments")).toStringList()); + m_ui->argumentEditor->setModel(&m_model); +} + +ArgumentEditor::~ArgumentEditor() = default; + +void ArgumentEditor::on_addButton_clicked() { + QInputDialog input(this); + int code = input.exec(); + if (code == DialogCode::Accepted) { + QStringList list = m_model.stringList(); + list << input.textValue(); + m_model.setStringList(list); + } +} + +void ArgumentEditor::on_addCvarButton_clicked() { + CVarDialog input(this); + int code = input.exec(); + if (code == DialogCode::Accepted) { + QStringList list = m_model.stringList(); + list << input.textValue(); + m_model.setStringList(list); + } +} + +void ArgumentEditor::on_editButton_clicked() { + QModelIndex index = m_ui->argumentEditor->currentIndex(); + if (!index.isValid()) { + return; + } + + QInputDialog input(this); + input.setTextValue(m_model.stringList().value(index.row())); + int code = input.exec(); + if (code == DialogCode::Accepted) { + QStringList list = m_model.stringList(); + list[index.row()] = input.textValue(); + m_model.setStringList(list); + } +} + +void ArgumentEditor::on_deleteButton_clicked() { + QModelIndex index = m_ui->argumentEditor->currentIndex(); + if (index.isValid()) { + m_model.removeRows(index.row(), 1); + } +} + +void ArgumentEditor::on_buttonBox_clicked(QAbstractButton* button) { + auto* buttonBox = qobject_cast(sender()); + if (button == buttonBox->button(QDialogButtonBox::Ok)) { + QSettings().setValue(QStringLiteral("metaforce_arguments"), m_model.stringList()); + accept(); + } else { + reject(); + } +} diff --git a/metaforce-gui/ArgumentEditor.hpp b/metaforce-gui/ArgumentEditor.hpp new file mode 100644 index 000000000..ce0e1e0fa --- /dev/null +++ b/metaforce-gui/ArgumentEditor.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include + +#include +#include + +class QAbstractButton; + +namespace Ui { +class ArgumentEditor; +} // namespace Ui + +class ArgumentEditor : public QDialog { + Q_OBJECT + + std::unique_ptr m_ui; + QStringListModel m_model; + +public: + explicit ArgumentEditor(QWidget* parent = nullptr); + ~ArgumentEditor() override; + +private slots: + void on_addButton_clicked(); + void on_addCvarButton_clicked(); + void on_editButton_clicked(); + void on_deleteButton_clicked(); + void on_buttonBox_clicked(QAbstractButton*); +}; diff --git a/metaforce-gui/ArgumentEditor.ui b/metaforce-gui/ArgumentEditor.ui new file mode 100644 index 000000000..5dff1500c --- /dev/null +++ b/metaforce-gui/ArgumentEditor.ui @@ -0,0 +1,75 @@ + + + ArgumentEditor + + + + 0 + 0 + 613 + 525 + + + + Argument Editor + + + + + + + + + &Add + + + + + + + Add &CVar + + + + + + + &Edit + + + + + + + &Delete + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + + diff --git a/metaforce-gui/CMakeLists.txt b/metaforce-gui/CMakeLists.txt new file mode 100644 index 000000000..5433bf099 --- /dev/null +++ b/metaforce-gui/CMakeLists.txt @@ -0,0 +1,173 @@ +cmake_minimum_required(VERSION 3.10) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) + +if (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) + set(QT_HOMEBREW_PATH /usr/local/opt/qt) +elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) + set(QT_HOMEBREW_PATH /opt/homebrew/opt/qt) +else () + set(QT_HOMEBREW_PATH "") +endif () + +find_package(Qt6Widgets QUIET PATHS ${QT_HOMEBREW_PATH}) +if (Qt6Widgets_FOUND) + find_package(Qt6 COMPONENTS Core5Compat Network Widgets Xml Gui REQUIRED PATHS ${QT_HOMEBREW_PATH}) + set(QUAZIP_QT_MAJOR_VERSION 6 CACHE STRING "") +else () + find_package(Qt5Widgets REQUIRED PATHS ${QT_HOMEBREW_PATH}) + find_package(Qt5 COMPONENTS Network Widgets Xml Gui REQUIRED PATHS ${QT_HOMEBREW_PATH}) + set(QUAZIP_QT_MAJOR_VERSION 5 CACHE STRING "") +endif () + +set(BUILD_SHARED_LIBS OFF CACHE BOOL "") +set(QUAZIP_INSTALL OFF CACHE BOOL "") +add_subdirectory(quazip) + +add_executable(metaforce-gui WIN32 MACOSX_BUNDLE + #ArgumentEditor.cpp + #ArgumentEditor.hpp + #ArgumentEditor.ui + Common.cpp + Common.hpp + #CVarDialog.cpp + #CVarDialog.hpp + #CVarDialog.ui + DownloadManager.cpp + DownloadManager.hpp + ErrorLabel.hpp + EscapeSequenceParser.cpp + EscapeSequenceParser.hpp + ExtractZip.cpp + ExtractZip.hpp + FileDirDialog.hpp + FindBlender.cpp + FindBlender.hpp + MainWindow.cpp + MainWindow.hpp + MainWindow.ui + LayerDialog.cpp + LayerDialog.hpp + LayerDialog.ui + SysReqTableView.cpp + SysReqTableView.hpp + + main.cpp + + ${QUAZIP_SRCS} + ) + +target_compile_definitions(metaforce-gui PRIVATE + # Disable implicit conversions from ASCII to QString. + -DQT_NO_CAST_FROM_ASCII + -DQT_NO_CAST_TO_ASCII + + # Disable implicit conversions of QByteArray to const char* or const void* + -DQT_NO_CAST_FROM_BYTEARRAY + + # Disable narrowing conversions in signal/slot connect() calls. + -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT + + # Disable unsafe overloads of QProcess' start() function. + -DQT_NO_PROCESS_COMBINED_ARGUMENT_START + + # Disable implicit QString->QUrl conversions to enforce use of proper resolving functions. + -DQT_NO_URL_CAST_FROM_STRING + + # Allows for more efficient string concatenation, resulting in less temporaries. + -DQT_USE_QSTRINGBUILDER + ) + +if (Qt6Widgets_FOUND) + set(Qt_LIBS + Qt6::Core + Qt6::Core5Compat + Qt6::Gui + Qt6::Network + Qt6::Widgets + Qt6::Xml) +else () + set(Qt_LIBS + Qt5::Core + Qt5::Gui + Qt5::Network + Qt5::Widgets + Qt5::Xml) + # Check for static linking + if (WIN32) + get_target_property(_MSVC_RUNTIME_LIBRARY metaforce-gui MSVC_RUNTIME_LIBRARY) + if (NOT "${_MSVC_RUNTIME_LIBRARY}" MATCHES "DLL$") + list(APPEND Qt_LIBS Qt5::QWindowsIntegrationPlugin) + endif () + endif () +endif () +target_link_libraries(metaforce-gui PRIVATE + ${Qt_LIBS} + hecl-light + zeus + QuaZip::QuaZip) + +target_include_directories(metaforce-gui PRIVATE quazip/quazip) +target_compile_definitions(metaforce-gui PRIVATE QUAZIP_STATIC=1) + +if (APPLE) + target_sources(metaforce-gui PRIVATE + MacOSSystemVersion.hpp + MacOSSystemVersion.mm + ) + set_source_files_properties(MacOSSystemVersion.mm + PROPERTIES COMPILE_FLAGS -fobjc-arc + ) + find_library(FOUNDATION_LIBRARY Foundation) + target_link_libraries(metaforce-gui PRIVATE ${FOUNDATION_LIBRARY}) +elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + target_link_libraries(metaforce-gui PRIVATE + dl + pthread + ) +endif () + +if (WIN32) + target_sources(metaforce-gui PRIVATE + platforms/win/metaforce-gui.manifest + platforms/win/metaforce-gui.rc + ) + target_link_libraries(metaforce-gui PRIVATE + Version) +elseif (APPLE) + set_target_properties(metaforce-gui PROPERTIES + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/platforms/mac/Info.plist" + ) + target_sources(metaforce-gui PRIVATE platforms/mac/mainicon.icns) + set_source_files_properties(platforms/mac/mainicon.icns PROPERTIES + MACOSX_PACKAGE_LOCATION Resources + ) + add_custom_command( + TARGET metaforce-gui POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E copy $ $ + DEPENDS metaforce hecl visigen + ) + if (NOT "${SENTRY_DSN}" STREQUAL "") + add_custom_command( + TARGET metaforce-gui POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + DEPENDS crashpad_handler + ) + endif() +endif () + +add_subdirectory(platforms/freedesktop) +declare_qticon_target() +target_sources(metaforce-gui PRIVATE mainicon_qt.cpp) + +if (COMMAND add_sanitizers) + add_sanitizers(metaforce-gui) +endif () + +if (NOT MSVC) + target_compile_options(metaforce-gui PRIVATE -Wno-misleading-indentation) +endif () diff --git a/metaforce-gui/CVarDialog.cpp b/metaforce-gui/CVarDialog.cpp new file mode 100644 index 000000000..f4bd493be --- /dev/null +++ b/metaforce-gui/CVarDialog.cpp @@ -0,0 +1,78 @@ +#include "CVarDialog.hpp" +#include "ui_CVarDialog.h" +#include + +enum class CVarType { + String, + Boolean, +}; + +struct CVarItem { + QString m_name; + CVarType m_type; + QVariant m_defaultValue; + + CVarItem(QString name, CVarType type, QVariant defaultValue) + : m_name(std::move(name)), m_type(type), m_defaultValue(std::move(defaultValue)) {} +}; + +static std::array cvarList{ + CVarItem{QStringLiteral("tweak.game.FieldOfView"), CVarType::String, 55}, + CVarItem{QStringLiteral("debugOverlay.playerInfo"), CVarType::Boolean, false}, + CVarItem{QStringLiteral("debugOverlay.areaInfo"), CVarType::Boolean, false}, + // TODO expand +}; + +CVarDialog::CVarDialog(QWidget* parent) : QDialog(parent), m_ui(std::make_unique()) { + m_ui->setupUi(this); + QStringList list; + for (const auto& item : cvarList) { + list << item.m_name; + } + m_model.setStringList(list); + m_ui->cvarList->setModel(&m_model); + connect(m_ui->cvarList->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, + SLOT(handleSelectionChanged(QItemSelection))); +} + +CVarDialog::~CVarDialog() = default; + +void CVarDialog::on_buttonBox_accepted() { + const QModelIndexList& list = m_ui->cvarList->selectionModel()->selectedIndexes(); + if (list.isEmpty()) { + reject(); + } else { + accept(); + } +} + +void CVarDialog::on_buttonBox_rejected() { reject(); } + +void CVarDialog::handleSelectionChanged(const QItemSelection& selection) { + const QModelIndexList& list = selection.indexes(); + if (list.isEmpty()) { + return; + } + const auto item = cvarList[(*list.begin()).row()]; + m_ui->valueStack->setCurrentIndex(static_cast(item.m_type)); + if (item.m_type == CVarType::String) { + m_ui->stringValueField->setText(item.m_defaultValue.toString()); + } else if (item.m_type == CVarType::Boolean) { + m_ui->booleanValueField->setChecked(item.m_defaultValue.toBool()); + } +} + +QString CVarDialog::textValue() { + const QModelIndexList& list = m_ui->cvarList->selectionModel()->selectedIndexes(); + if (list.isEmpty()) { + return QStringLiteral(""); + } + const auto item = cvarList[(*list.begin()).row()]; + QVariant value; + if (item.m_type == CVarType::String) { + value = m_ui->stringValueField->text(); + } else if (item.m_type == CVarType::Boolean) { + value = m_ui->booleanValueField->isChecked(); + } + return QStringLiteral("+") + item.m_name + QStringLiteral("=") + value.toString(); +} diff --git a/metaforce-gui/CVarDialog.hpp b/metaforce-gui/CVarDialog.hpp new file mode 100644 index 000000000..46ac1569a --- /dev/null +++ b/metaforce-gui/CVarDialog.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace Ui { +class CVarDialog; +} // namespace Ui + +class CVarDialog : public QDialog { + Q_OBJECT + +public: + explicit CVarDialog(QWidget* parent = nullptr); + ~CVarDialog() override; + + QString textValue(); + +private: + std::unique_ptr m_ui; + QStringListModel m_model; + +private slots: + void on_buttonBox_accepted(); + void on_buttonBox_rejected(); + void handleSelectionChanged(const QItemSelection& selection); +}; diff --git a/metaforce-gui/CVarDialog.ui b/metaforce-gui/CVarDialog.ui new file mode 100644 index 000000000..6d44604e9 --- /dev/null +++ b/metaforce-gui/CVarDialog.ui @@ -0,0 +1,139 @@ + + + CVarDialog + + + + 0 + 0 + 613 + 525 + + + + Add CVar + + + + + + + 0 + 0 + + + + Qt::Vertical + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + + + + + + 0 + 0 + + + + 0 + + + + + + + + 0 + 0 + + + + Value + + + Qt::PlainText + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + + + + + + + + true + + + + 0 + 0 + + + + Enabled + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/metaforce-gui/Common.cpp b/metaforce-gui/Common.cpp new file mode 100644 index 000000000..936332593 --- /dev/null +++ b/metaforce-gui/Common.cpp @@ -0,0 +1,192 @@ +#include "Common.hpp" +#include +#include + +#ifndef _WIN32 +#include +#endif + +#if __APPLE__ +const QString CurPlatformString = QStringLiteral("macos"); +#elif _WIN32 +const QString CurPlatformString = QStringLiteral("win32"); +#elif __linux__ +const QString CurPlatformString = QStringLiteral("linux"); +#else +#error HECL does not know which OS to fetch for +#endif + +QString PlatformToString(Platform plat) { + switch (plat) { + case Platform::MacOS: + return QStringLiteral("macos"); + case Platform::Win32: + return QStringLiteral("win32"); + case Platform::Linux: + return QStringLiteral("linux"); + default: + return QString(); + } +} + +Architecture CurArchitecture = Architecture::Invalid; +QString CurArchitectureString; + +Platform StringToPlatform(const QString& str) { + for (int i = 1; i < int(Platform::MAXPlatform); ++i) + if (!str.compare(PlatformToString(Platform(i)), Qt::CaseInsensitive)) + return Platform(i); + return Platform::Invalid; +} + +QString ArchitectureToString(Architecture arch) { + switch (arch) { + case Architecture::X86: + return QStringLiteral("x86"); + case Architecture::X86_64: + return QStringLiteral("x86_64"); + case Architecture::ARM: + return QStringLiteral("arm"); + case Architecture::ARM64: + return QStringLiteral("arm64"); + default: + return QString(); + } +} + +Architecture StringToArchitecture(const QString& str) { + for (int i = 1; i < int(Architecture::MAXArchitecture); ++i) + if (!str.compare(ArchitectureToString(Architecture(i)), Qt::CaseInsensitive)) + return Architecture(i); + return Architecture::Invalid; +} + +QString VectorISAToString(VectorISA visa) { + switch (visa) { + case VectorISA::X87: + return QStringLiteral("x87"); + case VectorISA::SSE: + return QStringLiteral("sse"); + case VectorISA::SSE2: + return QStringLiteral("sse2"); + case VectorISA::SSE3: + return QStringLiteral("sse3"); + case VectorISA::SSE41: + return QStringLiteral("sse41"); + case VectorISA::AVX: + return QStringLiteral("avx"); + case VectorISA::AVX2: + return QStringLiteral("avx2"); + case VectorISA::AVX512: + return QStringLiteral("avx512"); + default: + return QString(); + } +} + +VectorISA StringToVectorISA(const QString& str) { + for (int i = 1; i < int(VectorISA::MAXVectorISA); ++i) + if (!str.compare(VectorISAToString(VectorISA(i)), Qt::CaseInsensitive)) + return VectorISA(i); + return VectorISA::Invalid; +} + +MetaforceVersion::MetaforceVersion(const QString& filename) { + int idx; + QString useFilename = filename; + if ((idx = filename.lastIndexOf(QLatin1Char{'.'})) > filename.lastIndexOf(QLatin1Char{'-'})) { + m_extension = QString(filename).remove(0, idx); + useFilename.truncate(idx); + } + + const QStringList list = useFilename.split(QLatin1Char{'-'}); + enum { + version, + platform, + architecture, + vectorISA, + extra + } state = version; + for (size_t i = 1; i < list.size(); ++i) { + if (state == version) { + if (m_version.isEmpty()) { + m_version = list[i]; + continue; + } + bool ok; + int patch = list[i].toInt(&ok); + if (ok) { + m_version += QLatin1Char('-') + QString::number(patch); + continue; + } + state = platform; + } + if (state == platform) { + if (list[i] == QStringLiteral("dirty")) { + m_version += QLatin1Char{'-'} + list[i]; + continue; + } + state = architecture; + Platform platValue = StringToPlatform(list[i]); + if (platValue != Platform::Invalid) { + m_platform = platValue; + continue; + } + } + if (state == architecture) { + state = extra; + Architecture archValue = StringToArchitecture(list[i]); + if (archValue != Architecture::Invalid) { + m_architecture = archValue; + continue; + } + } +// if (state == vectorISA) { +// state = extra; +// VectorISA isa = StringToVectorISA(list[i]); +// if (isa != VectorISA::Invalid) { +// m_vectorISA = isa; +// continue; +// } +// } + m_extra += QLatin1Char('-') + list[i]; + } +} + +QString MetaforceVersion::fileString(bool withExtension) const { + if (m_version.isEmpty()) { + return {}; + } + + if (withExtension && !m_extension.isEmpty()) { + return QStringLiteral("metaforce-%1-%2-%3%4%5") + .arg(m_version, PlatformToString(m_platform), ArchitectureToString(m_architecture), m_extra, m_extension); + } else { + return QStringLiteral("metaforce-%1-%2-%3%4") + .arg(m_version, PlatformToString(m_platform), ArchitectureToString(m_architecture), m_extra); + } +} + +#ifndef _WIN32 +static void HUPHandler(int) {} +#endif + +void InitializePlatform() { +#ifndef _WIN32 + /* This can happen when terminating hecl - do nothing */ + signal(SIGHUP, HUPHandler); +#endif + +#if ZEUS_ARCH_X86_64 + const_cast(CurArchitecture) = Architecture::X86_64; +#elif ZEUS_ARCH_X86 +#if !defined(__APPLE__) && !defined(_WIN32) + const_cast(CurArchitecture) = (sysconf(_SC_WORD_BIT) == 64 ? Architecture::X86_64 : Architecture::X86); +#elif _WIN32 + bool isWOW = false; + IsWow64Process(GetCurrentProcess(), &isWOW); + const_cast(CurArchitecture) = (isWOW ? Architecture::X86_64 : Architecture::X86); +#endif +#endif + const_cast(CurArchitectureString) = ArchitectureToString(CurArchitecture); +} diff --git a/metaforce-gui/Common.hpp b/metaforce-gui/Common.hpp new file mode 100644 index 000000000..f71eac6f5 --- /dev/null +++ b/metaforce-gui/Common.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include "zeus/Math.hpp" + +enum class Platform { Invalid, MacOS, Win32, Linux, MAXPlatform }; +QString PlatformToString(Platform plat); +Platform StringToPlatform(const QString& str); + +#if __APPLE__ +constexpr Platform CurPlatform = Platform::MacOS; +#elif _WIN32 +constexpr Platform CurPlatform = Platform::Win32; +#elif __linux__ +constexpr Platform CurPlatform = Platform::Linux; +#endif + +extern const QString CurPlatformString; + +enum class Architecture { Invalid, X86, X86_64, ARM, ARM64, MAXArchitecture }; +QString ArchitectureToString(Architecture arch); +Architecture StringToArchitecture(const QString& str); + +extern Architecture CurArchitecture; +extern QString CurArchitectureString; + +enum class VectorISA { Invalid, X87, SSE, SSE2, SSE3, SSE41, AVX, AVX2, AVX512, MAXVectorISA }; +QString VectorISAToString(VectorISA visa); +VectorISA StringToVectorISA(const QString& str); + +class MetaforceVersion { + QString m_version{}; + Platform m_platform = CurPlatform; + Architecture m_architecture = CurArchitecture; + VectorISA m_vectorISA = VectorISA::Invalid; + QString m_extension{}; + QString m_extra{}; + +public: + MetaforceVersion() = default; + explicit MetaforceVersion(const QString& filename); + bool isValid() const { return !m_version.isEmpty(); } + QString fileString(bool withExtension) const; + QString getVersion() const { return m_version; } + Platform getPlatform() const { return m_platform; } + Architecture getArchitecture() const { return m_architecture; } + VectorISA getVectorISA() const { return m_vectorISA; } + QString getExtra() const { return m_extra; } +}; +Q_DECLARE_METATYPE(MetaforceVersion); + +void InitializePlatform(); diff --git a/metaforce-gui/DownloadManager.cpp b/metaforce-gui/DownloadManager.cpp new file mode 100644 index 000000000..dca11f9b8 --- /dev/null +++ b/metaforce-gui/DownloadManager.cpp @@ -0,0 +1,176 @@ +#include "DownloadManager.hpp" +#include "Common.hpp" +#include + +#include + +#define KEY_PINNING 0 + +#if KEY_PINNING +static const char AxioDLPublicKeyPEM[] = + "-----BEGIN PUBLIC KEY-----\n" + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvtshImzoP1a++9P5RK0k\n" + "btTOpwie7O7S/wWFZxwwbMezEPhjw2uu86TPqJe3P/1v+6xRKrEf9zFn/sKNygvD\n" + "bO64ZkJre4M46IYd0XxwIhiu7PBR+13CD+fqbrbYwPkoG090CP4MtZZN6mt5NAKB\n" + "QHoIj0wV5K/jJE9cBQxViwOqrxK05Cl/ivy0gRtpL7Ot6S+QHL3++rb6U2hWydIQ\n" + "kS+ucufKCIL77RcDwAc9vwNvzxf9EUU2pmq+EsEtLgRw3fR6BInoltOI8P9X5Wo6\n" + "/skeg92xZA++vv0neq5gjjDfa2A1zDgJRysz3Xps/AMlLOe55XCzXse9BpvChT+Z\n" + "pwIDAQAB\n" + "-----END PUBLIC KEY-----\n"; + +static const QSslKey AxioDLPublicKey = QSslKey({AxioDLPublicKeyPEM}, QSsl::Rsa, QSsl::Pem, QSsl::PublicKey); + +static const char AxioDLEdgePublicKeyPEM[] = + "-----BEGIN PUBLIC KEY-----\n" + "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4a8ZLg3LRU0FiK6m8g2pT3qVBTMA\n" + "K2Uu5VGl7iamdGpUjynQ4uYWMx+WXf2Qkh7UZZgYvA6UeWHEs3M6ME8T6g==\n" + "-----END PUBLIC KEY-----\n"; + +static const QSslKey AxioDLEdgePublicKey = QSslKey({AxioDLEdgePublicKeyPEM}, QSsl::Ec, QSsl::Pem, QSsl::PublicKey); +#endif + +void DownloadManager::_validateCert(QNetworkReply* reply) { +#if KEY_PINNING + QSslCertificate peerCert = reply->sslConfiguration().peerCertificate(); + QSslKey peerKey = peerCert.publicKey(); + if (peerKey != AxioDLPublicKey && peerKey != AxioDLEdgePublicKey) { + const auto cn = peerCert.subjectInfo(QSslCertificate::CommonName); + if (cn.empty()) { + setError(QNetworkReply::SslHandshakeFailedError, tr("Certificate pinning mismatch")); + } else { + setError(QNetworkReply::SslHandshakeFailedError, tr("Certificate pinning mismatch \"%1\"").arg(cn.first())); + } + reply->abort(); + } +#endif +} + +static const QString Domain = QStringLiteral("https://releases.axiodl.com/"); +static const QString Index = QStringLiteral("index.txt"); + +void DownloadManager::fetchIndex() { + if (m_indexInProgress != nullptr) { + return; + } + + resetError(); + + const QString track = QSettings().value(QStringLiteral("update_track")).toString(); + const auto url = QUrl(QStringLiteral("%1%2/%3/%4").arg(Domain, track, CurPlatformString, Index)); + + m_indexInProgress = m_netManager.get(QNetworkRequest(url)); + connect(m_indexInProgress, &QNetworkReply::finished, this, &DownloadManager::indexFinished); +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + connect(m_indexInProgress, &QNetworkReply::errorOccurred, this, &DownloadManager::indexError); +#else + connect(m_indexInProgress, qOverload(&QNetworkReply::error), this, + &DownloadManager::indexError); +#endif + connect(m_indexInProgress, &QNetworkReply::encrypted, this, &DownloadManager::indexValidateCert); +} + +void DownloadManager::fetchBinary(const QString& str, const QString& outPath) { + if (m_binaryInProgress != nullptr) { + return; + } + + resetError(); + m_outPath = outPath; + + const QString track = QSettings().value(QStringLiteral("update_track")).toString(); + const auto url = QUrl(QStringLiteral("%1%2/%3/%4").arg(Domain, track, CurPlatformString, str)); +#if PLATFORM_ZIP_DOWNLOAD + m_binaryInProgress = m_netManager.get(QNetworkRequest(url)); + connect(m_binaryInProgress, &QNetworkReply::finished, this, &DownloadManager::binaryFinished); +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + connect(m_binaryInProgress, &QNetworkReply::errorOccurred, this, &DownloadManager::binaryError); +#else + connect(m_binaryInProgress, qOverload(&QNetworkReply::error), this, + &DownloadManager::binaryError); +#endif + connect(m_binaryInProgress, &QNetworkReply::encrypted, this, &DownloadManager::binaryValidateCert); + connect(m_binaryInProgress, &QNetworkReply::downloadProgress, this, &DownloadManager::binaryDownloadProgress); + + if (m_progBar != nullptr) { + m_progBar->setEnabled(true); + m_progBar->setValue(0); + } +#else + QDesktopServices::openUrl(url); +#endif +} + +void DownloadManager::indexFinished() { + if (m_hasError) + return; + + QStringList files; + + while (!m_indexInProgress->atEnd()) { + QString line = QString::fromUtf8(m_indexInProgress->readLine()).trimmed(); + if (line.isEmpty()) + continue; + files.push_back(line); + } + + if (m_indexCompletionHandler) + m_indexCompletionHandler(files); + + m_indexInProgress->deleteLater(); + m_indexInProgress = nullptr; +} + +void DownloadManager::indexError(QNetworkReply::NetworkError error) { + setError(error, m_indexInProgress->errorString()); + m_indexInProgress->deleteLater(); + m_indexInProgress = nullptr; +} + +void DownloadManager::indexValidateCert() { _validateCert(m_indexInProgress); } + +void DownloadManager::binaryFinished() { + if (m_hasError) + return; + + if (m_progBar) + m_progBar->setValue(100); + + QByteArray all = m_binaryInProgress->readAll(); + QBuffer buff(&all); + QuaZip zip(&buff); + if (!zip.open(QuaZip::mdUnzip)) { + setError(QNetworkReply::UnknownContentError, tr("Unable to open zip archive.")); + m_binaryInProgress->deleteLater(); + m_binaryInProgress = nullptr; + return; + } + + if (m_completionHandler) + m_completionHandler(zip); + + m_binaryInProgress->deleteLater(); + m_binaryInProgress = nullptr; +} + +void DownloadManager::binaryError(QNetworkReply::NetworkError error) { + setError(error, m_binaryInProgress->errorString()); + m_binaryInProgress->deleteLater(); + m_binaryInProgress = nullptr; + + if (m_progBar) + m_progBar->setEnabled(false); + + if (m_failedHandler) + m_failedHandler(); +} + +void DownloadManager::binaryValidateCert() { _validateCert(m_binaryInProgress); } + +void DownloadManager::binaryDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { + if (m_progBar) { + if (bytesReceived == bytesTotal) + m_progBar->setValue(100); + else + m_progBar->setValue(int(bytesReceived * 100 / bytesTotal)); + } +} diff --git a/metaforce-gui/DownloadManager.hpp b/metaforce-gui/DownloadManager.hpp new file mode 100644 index 000000000..03186d498 --- /dev/null +++ b/metaforce-gui/DownloadManager.hpp @@ -0,0 +1,70 @@ +#pragma once + +#include +#include +#include +#include +#include + +//#if _WIN32 +//#define PLATFORM_ZIP_DOWNLOAD 1 +//#else +#define PLATFORM_ZIP_DOWNLOAD 0 +//#endif + +class QuaZip; + +class DownloadManager : public QObject { + Q_OBJECT + QNetworkAccessManager m_netManager; + QNetworkReply* m_indexInProgress = nullptr; + QNetworkReply* m_binaryInProgress = nullptr; + QString m_outPath; + bool m_hasError = false; + QProgressBar* m_progBar = nullptr; + QLabel* m_errorLabel = nullptr; + std::function m_indexCompletionHandler; + std::function m_completionHandler; + std::function m_failedHandler; + + void resetError() { + m_hasError = false; + if (m_errorLabel) + m_errorLabel->setText(QString()); + } + + void setError(QNetworkReply::NetworkError error, const QString& errStr) { + if (m_hasError && error == QNetworkReply::OperationCanceledError) + return; + m_hasError = true; + if (m_errorLabel) + m_errorLabel->setText(errStr); + } + + void _validateCert(QNetworkReply* reply); + +public: + explicit DownloadManager(QObject* parent = Q_NULLPTR) : QObject(parent), m_netManager(this) {} + void connectWidgets(QProgressBar* progBar, QLabel* errorLabel, + std::function&& indexCompletionHandler, + std::function&& completionHandler, std::function&& failedHandler) { + m_progBar = progBar; + m_errorLabel = errorLabel; + m_indexCompletionHandler = std::move(indexCompletionHandler); + m_completionHandler = std::move(completionHandler); + m_failedHandler = std::move(failedHandler); + } + void fetchIndex(); + void fetchBinary(const QString& str, const QString& outPath); + bool hasError() const { return m_hasError; } + +public slots: + void indexFinished(); + void indexError(QNetworkReply::NetworkError error); + void indexValidateCert(); + + void binaryFinished(); + void binaryError(QNetworkReply::NetworkError error); + void binaryValidateCert(); + void binaryDownloadProgress(qint64 bytesReceived, qint64 bytesTotal); +}; diff --git a/metaforce-gui/ErrorLabel.hpp b/metaforce-gui/ErrorLabel.hpp new file mode 100644 index 000000000..92cade714 --- /dev/null +++ b/metaforce-gui/ErrorLabel.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include + +class ErrorLabel : public QLabel { +public: + ErrorLabel(QWidget* parent = Q_NULLPTR) : QLabel(parent) {} + void setText(const QString& str, bool success = false) { + QPalette pal = QLabel::palette(); + if (success) + pal.setColor(QPalette::WindowText, QColor(0, 255, 0)); + else + pal.setColor(QPalette::WindowText, QColor(255, 47, 0)); + QLabel::setPalette(pal); + QLabel::setText(str); + } +}; diff --git a/metaforce-gui/EscapeSequenceParser.cpp b/metaforce-gui/EscapeSequenceParser.cpp new file mode 100644 index 000000000..b61c41707 --- /dev/null +++ b/metaforce-gui/EscapeSequenceParser.cpp @@ -0,0 +1,561 @@ +#include "EscapeSequenceParser.hpp" +#include + +/* TODO: more complete Vt102 emulation */ +// based on information: http://en.m.wikipedia.org/wiki/ANSI_escape_code +// http://misc.flogisoft.com/bash/tip_colors_and_formatting +// http://invisible-island.net/xterm/ctlseqs/ctlseqs.html +void ParseEscapeSequence(int attribute, QListIterator& i, QTextCharFormat& textCharFormat, + const QTextCharFormat& defaultTextCharFormat) { + switch (attribute) { + case 0: { // Normal/Default (reset all attributes) + textCharFormat = defaultTextCharFormat; + break; + } + case 1: { // Bold/Bright (bold or increased intensity) + textCharFormat.setFontWeight(QFont::Bold); + break; + } + case 2: { // Dim/Faint (decreased intensity) + textCharFormat.setFontWeight(QFont::Light); + break; + } + case 3: { // Italicized (italic on) + textCharFormat.setFontItalic(true); + break; + } + case 4: { // Underscore (single underlined) + textCharFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); + textCharFormat.setFontUnderline(true); + break; + } + case 5: { // Blink (slow, appears as Bold) + textCharFormat.setFontWeight(QFont::Bold); + break; + } + case 6: { // Blink (rapid, appears as very Bold) + textCharFormat.setFontWeight(QFont::Black); + break; + } + case 7: { // Reverse/Inverse (swap foreground and background) + QBrush foregroundBrush = textCharFormat.foreground(); + textCharFormat.setForeground(textCharFormat.background()); + textCharFormat.setBackground(foregroundBrush); + break; + } + case 8: { // Concealed/Hidden/Invisible (usefull for passwords) + textCharFormat.setForeground(textCharFormat.background()); + break; + } + case 9: { // Crossed-out characters + textCharFormat.setFontStrikeOut(true); + break; + } + case 10: { // Primary (default) font + textCharFormat.setFont(defaultTextCharFormat.font()); + break; + } + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QString fontFamily = textCharFormat.fontFamily(); + QStringList fontStyles = QFontDatabase::styles(fontFamily); + int fontStyleIndex = attribute - 11; + if (fontStyleIndex < fontStyles.length()) { + textCharFormat.setFont( + QFontDatabase::font(fontFamily, fontStyles.at(fontStyleIndex), textCharFormat.font().pointSize())); + } +#else + QFontDatabase fontDatabase; + QString fontFamily = textCharFormat.fontFamily(); + QStringList fontStyles = fontDatabase.styles(fontFamily); + int fontStyleIndex = attribute - 11; + if (fontStyleIndex < fontStyles.length()) { + textCharFormat.setFont( + fontDatabase.font(fontFamily, fontStyles.at(fontStyleIndex), textCharFormat.font().pointSize())); + } +#endif + break; + } + case 20: { // Fraktur (unsupported) + break; + } + case 21: { // Set Bold off + textCharFormat.setFontWeight(QFont::Normal); + break; + } + case 22: { // Set Dim off + textCharFormat.setFontWeight(QFont::Normal); + break; + } + case 23: { // Unset italic and unset fraktur + textCharFormat.setFontItalic(false); + break; + } + case 24: { // Unset underlining + textCharFormat.setUnderlineStyle(QTextCharFormat::NoUnderline); + textCharFormat.setFontUnderline(false); + break; + } + case 25: { // Unset Blink/Bold + textCharFormat.setFontWeight(QFont::Normal); + break; + } + case 26: { // Reserved + break; + } + case 27: { // Positive (non-inverted) + QBrush backgroundBrush = textCharFormat.background(); + textCharFormat.setBackground(textCharFormat.foreground()); + textCharFormat.setForeground(backgroundBrush); + break; + } + case 28: { + textCharFormat.setForeground(defaultTextCharFormat.foreground()); + textCharFormat.setBackground(defaultTextCharFormat.background()); + break; + } + case 29: { + textCharFormat.setUnderlineStyle(QTextCharFormat::NoUnderline); + textCharFormat.setFontUnderline(false); + break; + } + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: { + int colorIndex = attribute - 30; + QColor color; + if (QFont::Normal < textCharFormat.fontWeight()) { + switch (colorIndex) { + case 0: { + color = Qt::darkGray; + break; + } + case 1: { + color = Qt::red; + break; + } + case 2: { + color = Qt::green; + break; + } + case 3: { + color = Qt::yellow; + break; + } + case 4: { + color = Qt::blue; + break; + } + case 5: { + color = Qt::magenta; + break; + } + case 6: { + color = Qt::cyan; + break; + } + case 7: { + color = Qt::white; + break; + } + default: { Q_ASSERT(false); } + } + } else { + /* Normally dark colors, but forced to light colors for visibility */ + switch (colorIndex) { + case 0: { + color = Qt::darkGray; + break; + } + case 1: { + color = Qt::red; + break; + } + case 2: { + color = Qt::green; + break; + } + case 3: { + color = Qt::yellow; + break; + } + case 4: { + color = Qt::blue; + break; + } + case 5: { + color = Qt::magenta; + break; + } + case 6: { + color = Qt::cyan; + break; + } + case 7: { + color = Qt::white; + break; + } + default: { Q_ASSERT(false); } + } + } + textCharFormat.setForeground(color); + break; + } + case 38: { + if (i.hasNext()) { + bool ok = false; + int selector = i.next().toInt(&ok); + Q_ASSERT(ok); + QColor color; + switch (selector) { + case 2: { + if (!i.hasNext()) { + break; + } + int red = i.next().toInt(&ok); + Q_ASSERT(ok); + if (!i.hasNext()) { + break; + } + int green = i.next().toInt(&ok); + Q_ASSERT(ok); + if (!i.hasNext()) { + break; + } + int blue = i.next().toInt(&ok); + Q_ASSERT(ok); + color.setRgb(red, green, blue); + break; + } + case 5: { + if (!i.hasNext()) { + break; + } + int index = i.next().toInt(&ok); + Q_ASSERT(ok); + if (index >= 0 && index <= 0x07) { // 0x00-0x07: standard colors (as in ESC [ 30..37 m) + return ParseEscapeSequence(index - 0x00 + 30, i, textCharFormat, defaultTextCharFormat); + } else if (index >= 0x08 && index <= 0x0F) { // 0x08-0x0F: high intensity colors (as in ESC [ 90..97 m) + return ParseEscapeSequence(index - 0x08 + 90, i, textCharFormat, defaultTextCharFormat); + } else if (index >= 0x10 && index <= 0xE7) { // 0x10-0xE7: 6*6*6=216 colors: 16 + 36*r + 6*g + b (0≤r,g,b≤5) + index -= 0x10; + int red = index % 6; + index /= 6; + int green = index % 6; + index /= 6; + int blue = index % 6; + index /= 6; + Q_ASSERT(index == 0); + color.setRgb(red, green, blue); + break; + } else if (index >= 0xE8 && index <= 0xFF) { // 0xE8-0xFF: grayscale from black to white in 24 steps + qreal intensity = qreal(index - 0xE8) / (0xFF - 0xE8); + color.setRgbF(intensity, intensity, intensity); + break; + } + textCharFormat.setForeground(color); + break; + } + default: { break; } + } + } + break; + } + case 39: { + textCharFormat.setForeground(defaultTextCharFormat.foreground()); + break; + } + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: { + int colorIndex = attribute - 40; + QColor color; + switch (colorIndex) { + case 0: { + color = Qt::darkGray; + break; + } + case 1: { + color = Qt::red; + break; + } + case 2: { + color = Qt::green; + break; + } + case 3: { + color = Qt::yellow; + break; + } + case 4: { + color = Qt::blue; + break; + } + case 5: { + color = Qt::magenta; + break; + } + case 6: { + color = Qt::cyan; + break; + } + case 7: { + color = Qt::white; + break; + } + default: { Q_ASSERT(false); } + } + textCharFormat.setBackground(color); + break; + } + case 48: { + if (i.hasNext()) { + bool ok = false; + int selector = i.next().toInt(&ok); + Q_ASSERT(ok); + QColor color; + switch (selector) { + case 2: { + if (!i.hasNext()) { + break; + } + int red = i.next().toInt(&ok); + Q_ASSERT(ok); + if (!i.hasNext()) { + break; + } + int green = i.next().toInt(&ok); + Q_ASSERT(ok); + if (!i.hasNext()) { + break; + } + int blue = i.next().toInt(&ok); + Q_ASSERT(ok); + color.setRgb(red, green, blue); + break; + } + case 5: { + if (!i.hasNext()) { + break; + } + int index = i.next().toInt(&ok); + Q_ASSERT(ok); + if (index >= 0x00 && index <= 0x07) { // 0x00-0x07: standard colors (as in ESC [ 40..47 m) + return ParseEscapeSequence(index - 0x00 + 40, i, textCharFormat, defaultTextCharFormat); + } else if (index >= 0x08 && index <= 0x0F) { // 0x08-0x0F: high intensity colors (as in ESC [ 100..107 m) + return ParseEscapeSequence(index - 0x08 + 100, i, textCharFormat, defaultTextCharFormat); + } else if (index >= 0x10 && index <= 0xE7) { // 0x10-0xE7: 6*6*6=216 colors: 16 + 36*r + 6*g + b (0≤r,g,b≤5) + index -= 0x10; + int red = index % 6; + index /= 6; + int green = index % 6; + index /= 6; + int blue = index % 6; + index /= 6; + Q_ASSERT(index == 0); + color.setRgb(red, green, blue); + break; + } else if (index >= 0xE8 && index <= 0xFF) { // 0xE8-0xFF: grayscale from black to white in 24 steps + qreal intensity = qreal(index - 0xE8) / (0xFF - 0xE8); + color.setRgbF(intensity, intensity, intensity); + } + } + textCharFormat.setBackground(color); + break; + } + } + break; + } + case 49: { + textCharFormat.setBackground(defaultTextCharFormat.background()); + break; + } + case 90: + case 91: + case 92: + case 93: + case 94: + case 95: + case 96: + case 97: { + int colorIndex = attribute - 90; + QColor color; + switch (colorIndex) { + case 0: { + color = Qt::darkGray; + break; + } + case 1: { + color = Qt::red; + break; + } + case 2: { + color = Qt::green; + break; + } + case 3: { + color = Qt::yellow; + break; + } + case 4: { + color = Qt::blue; + break; + } + case 5: { + color = Qt::magenta; + break; + } + case 6: { + color = Qt::cyan; + break; + } + case 7: { + color = Qt::white; + break; + } + default: { Q_ASSERT(false); } + } + // color.setRedF(color.redF() * 0.8); + // color.setGreenF(color.greenF() * 0.8); + // color.setBlueF(color.blueF() * 0.8); + textCharFormat.setForeground(color); + break; + } + case 100: + case 101: + case 102: + case 103: + case 104: + case 105: + case 106: + case 107: { + int colorIndex = attribute - 100; + QColor color; + switch (colorIndex) { + case 0: { + color = Qt::darkGray; + break; + } + case 1: { + color = Qt::red; + break; + } + case 2: { + color = Qt::green; + break; + } + case 3: { + color = Qt::yellow; + break; + } + case 4: { + color = Qt::blue; + break; + } + case 5: { + color = Qt::magenta; + break; + } + case 6: { + color = Qt::cyan; + break; + } + case 7: { + color = Qt::white; + break; + } + default: { Q_ASSERT(false); } + } + // color.setRedF(color.redF() * 0.8); + // color.setGreenF(color.greenF() * 0.8); + // color.setBlueF(color.blueF() * 0.8); + textCharFormat.setBackground(color); + break; + } + default: { break; } + } +} + +void ReturnInsert(QTextCursor& cur, const QString& text) { + const auto DoLine = [&](const QString& line) { + const auto DoReturn = [&](const QString& ret) { + if (!ret.isEmpty()) { + cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, ret.size()); + cur.insertText(ret); + } + }; + const QStringList list = line.split(QLatin1Char{'\r'}); + DoReturn(list.front()); + if (list.size() > 1) { + for (auto it = list.begin() + 1; it != list.end(); ++it) { + cur.movePosition(QTextCursor::StartOfBlock); + DoReturn(*it); + } + } + }; + +#if _WIN32 + const QStringList lineSplit = text.split(QStringLiteral("\r\n")); +#else + const QStringList lineSplit = text.split(QLatin1Char{'\n'}); +#endif + DoLine(lineSplit.front()); + if (lineSplit.size() > 1) { + for (auto it = lineSplit.begin() + 1; it != lineSplit.end(); ++it) { + cur.movePosition(QTextCursor::EndOfLine); + cur.insertBlock(); + DoLine(*it); + } + } +} + +void ReturnInsert(QTextCursor& cur, const QString& text, const QTextCharFormat& format) { + const auto DoLine = [&](const QString& line) { + const auto DoReturn = [&](const QString& ret) { + if (!ret.isEmpty()) { + cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, ret.size()); + cur.insertText(ret, format); + } + }; + const QStringList list = line.split(QLatin1Char{'\r'}); + DoReturn(list.front()); + if (list.size() > 1) { + for (auto it = list.begin() + 1; it != list.end(); ++it) { + cur.movePosition(QTextCursor::StartOfBlock); + DoReturn(*it); + } + } + }; + +#if _WIN32 + const QStringList lineSplit = text.split(QStringLiteral("\r\n")); +#else + const QStringList lineSplit = text.split(QLatin1Char{'\n'}); +#endif + DoLine(lineSplit.front()); + if (lineSplit.size() > 1) { + for (auto it = lineSplit.begin() + 1; it != lineSplit.end(); ++it) { + cur.movePosition(QTextCursor::EndOfLine); + cur.insertBlock(); + DoLine(*it); + } + } +} diff --git a/metaforce-gui/EscapeSequenceParser.hpp b/metaforce-gui/EscapeSequenceParser.hpp new file mode 100644 index 000000000..2e1cb5631 --- /dev/null +++ b/metaforce-gui/EscapeSequenceParser.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include +#include +#include + +void ParseEscapeSequence(int attribute, QListIterator& i, QTextCharFormat& textCharFormat, + const QTextCharFormat& defaultTextCharFormat); + +void ReturnInsert(QTextCursor& cur, const QString& text); + +void ReturnInsert(QTextCursor& cur, const QString& text, const QTextCharFormat& format); diff --git a/metaforce-gui/ExtractZip.cpp b/metaforce-gui/ExtractZip.cpp new file mode 100644 index 000000000..c1a256288 --- /dev/null +++ b/metaforce-gui/ExtractZip.cpp @@ -0,0 +1,141 @@ +#include "ExtractZip.hpp" +#include +#include +#include + +/** + * Modified JICompress utilities to operate on in-memory zip. + * Only contains directory extraction functionality. + */ + +static bool copyData(QIODevice& inFile, QIODevice& outFile) { + while (!inFile.atEnd()) { + char buf[4096]; + qint64 readLen = inFile.read(buf, 4096); + if (readLen <= 0) + return false; + if (outFile.write(buf, readLen) != readLen) + return false; + } + return true; +} + +QStringList ExtractZip::getFileList(QuaZip& zip) { + // Estraggo i nomi dei file + QStringList lst; + QuaZipFileInfo64 info; + for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { + if (!zip.getCurrentFileInfo(&info)) + return {}; + lst << info.name; + // info.name.toLocal8Bit().constData() + } + + return lst; +} + +/**OK + * Estrae il file fileName, contenuto nell'oggetto zip, con il nome fileDest. + * Se la funzione fallisce restituisce false e cancella il file che si e tentato di estrarre. + * + * La funzione fallisce se: + * * zip==NULL; + * * l'oggetto zip e stato aperto in una modalita non compatibile con l'estrazione di file; + * * non e possibile aprire il file all'interno dell'oggetto zip; + * * non e possibile creare il file estratto; + * * si e rilevato un errore nella copia dei dati (1); + * * non e stato possibile chiudere il file all'interno dell'oggetto zip (1); + * + * (1): prima di uscire dalla funzione cancella il file estratto. + */ +bool ExtractZip::extractFile(QuaZip& zip, QString fileName, QString fileDest) { + // zip: oggetto dove aggiungere il file + // filename: nome del file reale + // fileincompress: nome del file all'interno del file compresso + + // Controllo l'apertura dello zip + if (zip.getMode() != QuaZip::mdUnzip) + return false; + + // Apro il file compresso + if (!fileName.isEmpty()) + zip.setCurrentFile(fileName); + QuaZipFile inFile(&zip); + if (!inFile.open(QIODevice::ReadOnly) || inFile.getZipError() != UNZ_OK) + return false; + + // Controllo esistenza cartella file risultato + QDir curDir; + if (fileDest.endsWith(QLatin1Char{'/'})) { + if (!curDir.mkpath(fileDest)) { + return false; + } + } else { + if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) { + return false; + } + } + + QuaZipFileInfo64 info; + if (!zip.getCurrentFileInfo(&info)) + return false; + + QFile::Permissions srcPerm = info.getPermissions(); + if (fileDest.endsWith(QLatin1Char{'/'}) && QFileInfo(fileDest).isDir()) { + if (srcPerm != 0) { + QFile(fileDest).setPermissions(srcPerm); + } + return true; + } + + // Apro il file risultato + QFile outFile; + outFile.setFileName(fileDest); + if (!outFile.open(QIODevice::WriteOnly)) + return false; + + // Copio i dati + if (!copyData(inFile, outFile) || inFile.getZipError() != UNZ_OK) { + outFile.close(); + return false; + } + outFile.close(); + + // Chiudo i file + inFile.close(); + if (inFile.getZipError() != UNZ_OK) { + return false; + } + + if (srcPerm != 0) { + outFile.setPermissions(srcPerm); + } + return true; +} + +/**OK + * Estrae il file fileCompressed nella cartella dir. + * Se dir = "" allora il file viene estratto nella cartella corrente. + * Se la funzione fallisce cancella i file che si e tentato di estrarre. + * Restituisce i nomi assoluti dei file estratti. + * + * La funzione fallisce se: + * * non si riesce ad aprire l'oggetto zip; + * * la compressione di un file fallisce; + * * non si riesce a chiudere l'oggetto zip; + */ +bool ExtractZip::extractDir(QuaZip& zip, QString dir) { + const QDir directory(dir); + if (!zip.goToFirstFile()) { + return false; + } + do { + const QString name = zip.getCurrentFileName(); + const QString absFilePath = directory.absoluteFilePath(name); + if (!extractFile(zip, {}, absFilePath)) { + return false; + } + } while (zip.goToNextFile()); + + return true; +} diff --git a/metaforce-gui/ExtractZip.hpp b/metaforce-gui/ExtractZip.hpp new file mode 100644 index 000000000..41fee234f --- /dev/null +++ b/metaforce-gui/ExtractZip.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include +class QuaZip; +class QString; + +class ExtractZip { +public: + static QStringList getFileList(QuaZip& zip); + static bool extractFile(QuaZip& zip, QString fileName, QString fileDest); + static bool extractDir(QuaZip& zip, QString dir); +}; diff --git a/metaforce-gui/FileDirDialog.hpp b/metaforce-gui/FileDirDialog.hpp new file mode 100644 index 000000000..ade623493 --- /dev/null +++ b/metaforce-gui/FileDirDialog.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +class FileDirDialog : public QFileDialog { + Q_OBJECT +public: + FileDirDialog(QWidget* parent = nullptr) : QFileDialog(parent) { setFileMode(QFileDialog::Directory); } +}; diff --git a/metaforce-gui/FindBlender.cpp b/metaforce-gui/FindBlender.cpp new file mode 100644 index 000000000..16d250587 --- /dev/null +++ b/metaforce-gui/FindBlender.cpp @@ -0,0 +1,140 @@ +#include "FindBlender.hpp" +#include "hecl/SteamFinder.hpp" +#include "hecl/hecl.hpp" + +namespace hecl::blender { + +#ifdef __APPLE__ +#define DEFAULT_BLENDER_BIN "/Applications/Blender.app/Contents/MacOS/blender" +#elif __linux__ +#define DEFAULT_BLENDER_BIN "/usr/bin/blender" +#else +#define DEFAULT_BLENDER_BIN "blender" +#endif + +static const std::regex regBlenderVersion(R"(Blender (\d+)\.(\d+)(?:\.(\d+))?)", + std::regex::ECMAScript | std::regex::optimize); + +static bool RegFileExists(const hecl::SystemChar* path) { + if (!path) + return false; + hecl::Sstat theStat; + return !hecl::Stat(path, &theStat) && S_ISREG(theStat.st_mode); +} + +hecl::SystemString FindBlender(int& major, int& minor) { + major = 0; + minor = 0; + + /* User-specified blender path */ +#if _WIN32 + wchar_t BLENDER_BIN_BUF[2048]; + const wchar_t* blenderBin = _wgetenv(L"BLENDER_BIN"); +#else + const char* blenderBin = getenv("BLENDER_BIN"); +#endif + + /* Steam blender */ + hecl::SystemString steamBlender; + + /* Child process of blender */ +#if _WIN32 + if (!blenderBin || !RegFileExists(blenderBin)) { + /* Environment not set; try steam */ + steamBlender = hecl::FindCommonSteamApp(_SYS_STR("Blender")); + if (steamBlender.size()) { + steamBlender += _SYS_STR("\\blender.exe"); + blenderBin = steamBlender.c_str(); + } + + if (!RegFileExists(blenderBin)) { + /* No steam; try default */ + wchar_t progFiles[256]; + if (GetEnvironmentVariableW(L"ProgramFiles", progFiles, 256)) { + for (size_t major = MaxBlenderMajorSearch; major >= MinBlenderMajorSearch; --major) { + bool found = false; + for (size_t minor = MaxBlenderMinorSearch; minor > MinBlenderMinorSearch; --minor) { + _snwprintf(BLENDER_BIN_BUF, 2048, L"%s\\Blender Foundation\\Blender %i.%i\\blender.exe", progFiles, major, + minor); + if (RegFileExists(BLENDER_BIN_BUF)) { + blenderBin = BLENDER_BIN_BUF; + found = true; + break; + } + } + if (found) { + break; + } + } + } + } + } + +#else + if (!RegFileExists(blenderBin)) { + /* Try steam */ + steamBlender = hecl::FindCommonSteamApp(_SYS_STR("Blender")); + if (steamBlender.size()) { +#ifdef __APPLE__ + steamBlender += "/blender.app/Contents/MacOS/blender"; +#else + steamBlender += "/blender"; +#endif + blenderBin = steamBlender.c_str(); + if (!RegFileExists(blenderBin)) { + blenderBin = DEFAULT_BLENDER_BIN; + if (!RegFileExists(blenderBin)) { + blenderBin = nullptr; + } + } + } else { + blenderBin = DEFAULT_BLENDER_BIN; + if (!RegFileExists(blenderBin)) { + blenderBin = nullptr; + } + } + } +#endif + + if (!blenderBin) + return {}; + +#if _WIN32 + DWORD handle = 0; + DWORD infoSize = GetFileVersionInfoSizeW(blenderBin, &handle); + + if (infoSize != NULL) { + auto* infoData = new char[infoSize]; + if (GetFileVersionInfoW(blenderBin, handle, infoSize, infoData)) { + UINT size = 0; + LPVOID lpBuffer = nullptr; + if (VerQueryValueW(infoData, L"\\", &lpBuffer, &size) && size != 0u) { + auto* verInfo = static_cast(lpBuffer); + if (verInfo->dwSignature == 0xfeef04bd) { + major = static_cast((verInfo->dwFileVersionMS >> 16) & 0xffff); + minor = static_cast((verInfo->dwFileVersionMS >> 0 & 0xffff) * 10 + + (verInfo->dwFileVersionLS >> 16 & 0xffff)); + } + } + } + delete[] infoData; + } +#else + hecl::SystemString command = hecl::SystemString(_SYS_STR("\"")) + blenderBin + _SYS_STR("\" --version"); + FILE* fp = popen(command.c_str(), "r"); + char versionBuf[256]; + size_t rdSize = fread(versionBuf, 1, 255, fp); + versionBuf[rdSize] = '\0'; + pclose(fp); + + std::cmatch match; + if (std::regex_search(versionBuf, match, regBlenderVersion)) { + major = atoi(match[1].str().c_str()); + minor = atoi(match[2].str().c_str()); + } +#endif + + return blenderBin; +} + +} // namespace hecl::blender diff --git a/metaforce-gui/FindBlender.hpp b/metaforce-gui/FindBlender.hpp new file mode 100644 index 000000000..7a09faeee --- /dev/null +++ b/metaforce-gui/FindBlender.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "hecl/hecl.hpp" + +namespace hecl::blender { +constexpr uint32_t MinBlenderMajorSearch = 2; +constexpr uint32_t MaxBlenderMajorSearch = 2; +constexpr uint32_t MinBlenderMinorSearch = 83; +constexpr uint32_t MaxBlenderMinorSearch = 92; + +hecl::SystemString FindBlender(int& major, int& minor); + +} diff --git a/metaforce-gui/LayerDialog.cpp b/metaforce-gui/LayerDialog.cpp new file mode 100644 index 000000000..0320d19e3 --- /dev/null +++ b/metaforce-gui/LayerDialog.cpp @@ -0,0 +1,35 @@ +#include "LayerDialog.hpp" +#include +#include "ui_LayerDialog.h" + +LayerDialog::LayerDialog(QWidget* parent) : QDialog(parent), m_ui(std::make_unique()) { + m_ui->setupUi(this); +} + +LayerDialog::~LayerDialog() = default; + +void LayerDialog::createLayerCheckboxes(QList layers) { + bool firstLayer = true; + for (const auto& layer : layers) { + QCheckBox* chkBox = new QCheckBox(layer.name); + chkBox->setChecked(layer.active); + if (firstLayer) { + chkBox->setEnabled(false); + firstLayer = false; + } + m_ui->checkboxLayout->addWidget(chkBox); + } +} +QString LayerDialog::getLayerBits() const { + QString layerBits; + bool firstLayer = true; + for (const auto& item : findChildren()) { + if (firstLayer) { + layerBits += QLatin1String("1"); + firstLayer = false; + } else { + layerBits += item->isChecked() ? QStringLiteral("1") : QStringLiteral("0"); + } + } + return layerBits; +} diff --git a/metaforce-gui/LayerDialog.hpp b/metaforce-gui/LayerDialog.hpp new file mode 100644 index 000000000..759fae418 --- /dev/null +++ b/metaforce-gui/LayerDialog.hpp @@ -0,0 +1,27 @@ +#ifndef LAYERDIALOG_HPP +#define LAYERDIALOG_HPP + +#include +#include + +namespace Ui { +class LayerDialog; +} // namespace Ui + +struct Layer { + QString name; + bool active; +}; +class LayerDialog : public QDialog { + Q_OBJECT + std::unique_ptr m_ui; + +public: + explicit LayerDialog(QWidget* parent = nullptr); + ~LayerDialog() override; + + void createLayerCheckboxes(QList layers); + QString getLayerBits() const; +}; + +#endif \ No newline at end of file diff --git a/metaforce-gui/LayerDialog.ui b/metaforce-gui/LayerDialog.ui new file mode 100644 index 000000000..2f2c0f1f1 --- /dev/null +++ b/metaforce-gui/LayerDialog.ui @@ -0,0 +1,80 @@ + + + LayerDialog + + + + 0 + 0 + 400 + 209 + + + + Select Active Layers + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + LayerDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + LayerDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/metaforce-gui/MacOSSystemVersion.hpp b/metaforce-gui/MacOSSystemVersion.hpp new file mode 100644 index 000000000..39957b2b2 --- /dev/null +++ b/metaforce-gui/MacOSSystemVersion.hpp @@ -0,0 +1,3 @@ +#pragma once + +void GetMacOSSystemVersion(int& major, int& minor, int& patch); diff --git a/metaforce-gui/MacOSSystemVersion.mm b/metaforce-gui/MacOSSystemVersion.mm new file mode 100644 index 000000000..b6074c0c4 --- /dev/null +++ b/metaforce-gui/MacOSSystemVersion.mm @@ -0,0 +1,172 @@ +#include "MacOSSystemVersion.hpp" +#include +#include + +#if !__has_feature(objc_arc) +#error ARC Required +#endif + +void GetMacOSSystemVersion(int& major, int& minor, int& patch) +{ + major = 0; + minor = 0; + patch = 0; + + id pInfo = [NSProcessInfo processInfo]; + if ([pInfo respondsToSelector:@selector(operatingSystemVersion)]) + { + NSOperatingSystemVersion version = [pInfo operatingSystemVersion]; + major = version.majorVersion; + minor = version.minorVersion; + patch = version.patchVersion; + } + else + { + major = 10; + if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_9_2) + { + minor = 9; + patch = 2; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_9_1) + { + minor = 9; + patch = 1; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_9) + { + minor = 9; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8_4) + { + minor = 8; + patch = 4; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8_3) + { + minor = 8; + patch = 3; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8_2) + { + minor = 8; + patch = 2; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8_1) + { + minor = 8; + patch = 1; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8) + { + minor = 8; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_5) + { + minor = 7; + patch = 5; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_4) + { + minor = 7; + patch = 4; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_3) + { + minor = 7; + patch = 3; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_2) + { + minor = 7; + patch = 2; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_1) + { + minor = 7; + patch = 1; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7) + { + minor = 7; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_8) + { + minor = 6; + patch = 8; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_7) + { + minor = 6; + patch = 7; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_6) + { + minor = 6; + patch = 6; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_5) + { + minor = 6; + patch = 5; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_4) + { + minor = 6; + patch = 4; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_3) + { + minor = 6; + patch = 3; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_2) + { + minor = 6; + patch = 2; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_1) + { + minor = 6; + patch = 1; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6) + { + minor = 6; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_5) + { + minor = 5; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_4) + { + minor = 4; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_3) + { + minor = 3; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_2) + { + minor = 2; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_1) + { + minor = 1; + patch = 0; + } + else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_0) + { + minor = 0; + patch = 0; + } + } +} diff --git a/metaforce-gui/MainWindow.cpp b/metaforce-gui/MainWindow.cpp new file mode 100644 index 000000000..36fa272fc --- /dev/null +++ b/metaforce-gui/MainWindow.cpp @@ -0,0 +1,786 @@ +#include "MainWindow.hpp" +#include "ui_MainWindow.h" +#include "LayerDialog.hpp" + +#include +#include +#include +#include +#include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif +#include "EscapeSequenceParser.hpp" +#include "FileDirDialog.hpp" +#include "ExtractZip.hpp" + +#if _WIN32 +#include +#include +#include + +static void KillProcessTree(QProcess& proc) { + quint64 pid = proc.processId(); + if (pid == 0) { + return; + } + + PROCESSENTRY32 pe = {}; + pe.dwSize = sizeof(PROCESSENTRY32); + + HANDLE hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + + if (::Process32First(hSnap, &pe) == TRUE) { + BOOL bContinue = TRUE; + + // kill child processes + while (bContinue != FALSE) { + // only kill child processes + if (pe.th32ParentProcessID == pid) { + HANDLE hChildProc = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); + + if (hChildProc) { + ::TerminateProcess(hChildProc, 1); + ::CloseHandle(hChildProc); + } + } + + bContinue = ::Process32Next(hSnap, &pe); + } + } + + proc.close(); + proc.terminate(); +} +#else +static void KillProcessTree(QProcess& proc) { + proc.close(); + proc.terminate(); +} +#endif + +const QStringList MainWindow::skUpdateTracks = {QStringLiteral("stable"), QStringLiteral("dev"), + QStringLiteral("continuous")}; + +MainWindow::MainWindow(QWidget* parent) +: QMainWindow(parent) +, m_ui(std::make_unique()) +, m_fileMgr(_SYS_STR("metaforce")) +, m_cvarManager(m_fileMgr) +, m_cvarCommons(m_cvarManager) +, m_heclProc(this) +, m_dlManager(this) { + if (m_settings.value(QStringLiteral("metaforce_arguments")).isNull()) { + m_settings.setValue(QStringLiteral("metaforce_arguments"), QStringList{QStringLiteral("--no-shader-warmup")}); + } + if (m_settings.value(QStringLiteral("update_track")).isNull()) { + m_settings.setValue(QStringLiteral("update_track"), QStringLiteral("dev")); + } + + m_ui->setupUi(this); + m_ui->heclTabs->setCurrentIndex(0); + + m_ui->aboutIcon->setPixmap(QApplication::windowIcon().pixmap(256, 256)); + + QFont mFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); + mFont.setPointSize(m_ui->currentBinaryLabel->font().pointSize()); + m_ui->currentBinaryLabel->setFont(mFont); + m_ui->recommendedBinaryLabel->setFont(mFont); + mFont.setPointSize(10); + m_ui->processOutput->setFont(mFont); + m_cursor = QTextCursor(m_ui->processOutput->document()); + connect(m_ui->saveLogButton, &QPushButton::pressed, this, [this] { + QString defaultFileName = QStringLiteral("metaforce-") + + QDateTime::currentDateTime().toString(Qt::DateFormat::ISODate) + QStringLiteral(".log"); + defaultFileName.replace(QLatin1Char(':'), QLatin1Char('-')); + const QString fileName = + QFileDialog::getSaveFileName(this, tr("Save Log"), defaultFileName, QStringLiteral("*.log")); + if (fileName.isEmpty()) { + return; + } + QFile file = QFile(fileName); + if (file.open(QFile::OpenModeFlag::WriteOnly | QFile::OpenModeFlag::Truncate | QFile::OpenModeFlag::Text)) { + QTextStream stream(&file); + stream << m_ui->processOutput->toPlainText(); + stream.flush(); + file.close(); + } else { + QMessageBox::critical(this, tr("Save Log"), tr("Failed to open log file")); + } + }); + + qDebug() << "Stored track " << m_settings.value(QStringLiteral("update_track")); + const int index = skUpdateTracks.indexOf(m_settings.value(QStringLiteral("update_track")).toString()); + m_ui->devTrackWarning->setVisible(index == 1); + m_ui->continuousTrackWarning->setVisible(index == 2); + m_ui->updateTrackComboBox->setCurrentIndex(index); + connect(m_ui->updateTrackComboBox, qOverload(&QComboBox::currentIndexChanged), this, + &MainWindow::onUpdateTrackChanged); + + m_dlManager.connectWidgets(m_ui->downloadProgressBar, m_ui->downloadErrorLabel, + std::bind(&MainWindow::onIndexDownloaded, this, std::placeholders::_1), + std::bind(&MainWindow::onBinaryDownloaded, this, std::placeholders::_1), + std::bind(&MainWindow::onBinaryFailed, this)); +#if !PLATFORM_ZIP_DOWNLOAD + m_ui->downloadProgressBar->hide(); +#endif + + initOptions(); + initSlots(); + + m_dlManager.fetchIndex(); + + setPath(m_settings.value(QStringLiteral("working_dir")).toString()); + resize(1024, 768); +} + +MainWindow::~MainWindow() { KillProcessTree(m_heclProc); } + +void MainWindow::onExtract() { + if (m_path.isEmpty()) { + return; + } + + const QString imgPath = + QFileDialog::getOpenFileName(this, tr("Extract Game"), m_path, tr("Images (*.iso *.wbfs *.gcm)")); + if (imgPath.isEmpty()) { + return; + } + + m_ui->processOutput->clear(); + KillProcessTree(m_heclProc); + m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels); + m_heclProc.setWorkingDirectory(m_path); + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color")); + env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON")); + m_heclProc.setProcessEnvironment(env); + disconnect(&m_heclProc, qOverload(&QProcess::finished), nullptr, nullptr); + connect(&m_heclProc, qOverload(&QProcess::finished), this, &MainWindow::onExtractFinished); + + const QStringList heclProcArguments{ + QStringLiteral("extract"), QStringLiteral("-y"), QStringLiteral("-g"), QStringLiteral("-o"), m_path, imgPath}; + m_heclProc.start(m_heclPath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered); + + m_ui->heclTabs->setCurrentIndex(0); + + disableOperations(); + m_ui->extractBtn->setText(tr("&Cancel")); + m_ui->extractBtn->setEnabled(true); + disconnect(m_ui->extractBtn, &QPushButton::clicked, nullptr, nullptr); + connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::doHECLTerminate); +} + +void MainWindow::onExtractFinished(int returnCode, QProcess::ExitStatus) { + m_cursor.movePosition(QTextCursor::End); + m_cursor.insertBlock(); + disconnect(m_ui->extractBtn, &QPushButton::clicked, nullptr, nullptr); + connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::onExtract); + checkDownloadedBinary(); +} + +void MainWindow::onPackage() { + if (m_path.isEmpty()) + return; + m_ui->processOutput->clear(); + KillProcessTree(m_heclProc); + m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels); + m_heclProc.setWorkingDirectory(m_path); + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color")); + env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON")); + m_heclProc.setProcessEnvironment(env); + disconnect(&m_heclProc, qOverload(&QProcess::finished), nullptr, nullptr); + connect(&m_heclProc, qOverload(&QProcess::finished), this, &MainWindow::onPackageFinished); + + const QStringList heclProcArguments{QStringLiteral("package"), QStringLiteral("MP1"), QStringLiteral("-y"), + QStringLiteral("-g")}; + m_heclProc.start(m_heclPath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered); + + m_ui->heclTabs->setCurrentIndex(0); + + disableOperations(); + m_ui->packageBtn->setText(tr("&Cancel")); + m_ui->packageBtn->setEnabled(true); + disconnect(m_ui->packageBtn, &QPushButton::clicked, nullptr, nullptr); + connect(m_ui->packageBtn, &QPushButton::clicked, this, &MainWindow::doHECLTerminate); + + QSize size = QWidget::size(); + if (size.width() < 1100) + size.setWidth(1100); + resize(size); +} + +void MainWindow::onPackageFinished(int returnCode, QProcess::ExitStatus) { + m_cursor.movePosition(QTextCursor::End); + m_cursor.insertBlock(); + disconnect(m_ui->packageBtn, &QPushButton::clicked, nullptr, nullptr); + connect(m_ui->packageBtn, &QPushButton::clicked, this, &MainWindow::onPackage); + checkDownloadedBinary(); +} + +void MainWindow::onLaunch() { + if (m_path.isEmpty()) + return; + m_ui->processOutput->clear(); + KillProcessTree(m_heclProc); + m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels); + m_heclProc.setWorkingDirectory(m_path); + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color")); + env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON")); + m_heclProc.setProcessEnvironment(env); + disconnect(&m_heclProc, qOverload(&QProcess::finished), nullptr, nullptr); + connect(&m_heclProc, qOverload(&QProcess::finished), this, &MainWindow::onLaunchFinished); + + const auto heclProcArguments = QStringList{m_path + QStringLiteral("/out/MP1")} + << m_warpSettings << QStringLiteral("-l") + << m_settings.value(QStringLiteral("metaforce_arguments")) + .toStringList() + .join(QLatin1Char{' '}) + .split(QLatin1Char{' '}); + m_heclProc.start(m_metaforcePath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered); + + m_ui->heclTabs->setCurrentIndex(0); + + disableOperations(); +} + +void MainWindow::onLaunchFinished(int returnCode, QProcess::ExitStatus) { + m_cursor.movePosition(QTextCursor::End); + m_cursor.insertBlock(); + checkDownloadedBinary(); +} + +void MainWindow::doHECLTerminate() { KillProcessTree(m_heclProc); } + +void MainWindow::onReturnPressed() { + if (sender() == m_ui->pathEdit) + setPath(m_ui->pathEdit->text()); +} + +void MainWindow::onIndexDownloaded(const QStringList& index) { + int bestVersion = 0; + m_ui->binaryComboBox->clear(); + for (const QString& str : index) { + MetaforceVersion version(str); + m_ui->binaryComboBox->addItem(version.fileString(false), QVariant::fromValue(version)); + } + m_ui->binaryComboBox->setCurrentIndex(bestVersion); + m_recommendedVersion = m_ui->binaryComboBox->itemData(bestVersion).value(); + m_ui->recommendedBinaryLabel->setText(m_recommendedVersion.fileString(false)); + m_ui->binaryComboBox->setEnabled(true); + + if (!m_path.isEmpty()) { + checkDownloadedBinary(); + m_ui->downloadButton->setEnabled(true); + } +} + +void MainWindow::onDownloadPressed() { + QString filename = m_ui->binaryComboBox->currentData().value().fileString(true); +#if PLATFORM_ZIP_DOWNLOAD + disableOperations(); + m_ui->downloadButton->setEnabled(false); +#endif + m_dlManager.fetchBinary(filename, m_path + QLatin1Char{'/'} + filename); +} + +void MainWindow::onBinaryDownloaded(QuaZip& file) { + const bool err = !ExtractZip::extractDir(file, m_path); + + if (err) { + m_ui->downloadErrorLabel->setText(tr("Error extracting zip")); + } else { + m_ui->downloadErrorLabel->setText(tr("Download successful"), true); + } + + m_ui->downloadButton->setEnabled(true); + checkDownloadedBinary(); + + if (!err && m_ui->extractBtn->isEnabled()) { + m_ui->downloadErrorLabel->setText(tr("Download successful - Press 'Extract' to continue."), true); + } + if (!err && !m_ui->sysReqTable->isBlenderVersionOk()) { + m_ui->downloadErrorLabel->setText( + tr("Blender 2.90 or greater must be installed. Please download via Steam or blender.org.")); + } +} + +void MainWindow::onBinaryFailed() { + m_ui->downloadButton->setEnabled(true); + checkDownloadedBinary(); +} + +void MainWindow::disableOperations() { + m_ui->extractBtn->setEnabled(false); + m_ui->packageBtn->setEnabled(false); + m_ui->launchBtn->setEnabled(false); + m_ui->pathEdit->setEnabled(false); + m_ui->browseBtn->setEnabled(false); + m_ui->downloadButton->setEnabled(false); + m_ui->warpBtn->setEnabled(false); +} + +void MainWindow::enableOperations() { + disableOperations(); + m_ui->pathEdit->setEnabled(true); + m_ui->browseBtn->setEnabled(true); + + if (hecl::com_enableCheats->toBoolean()) { + m_ui->warpBtn->show(); + } else { + m_ui->warpBtn->hide(); + } + + if (m_path.isEmpty()) + return; + + m_ui->downloadButton->setEnabled(true); + + if (m_heclPath.isEmpty()) + return; + + m_ui->extractBtn->setText(tr("&Extract")); + m_ui->packageBtn->setText(tr("&Package")); + m_ui->launchBtn->setText(tr("&Launch")); + + m_ui->extractBtn->setEnabled(true); + if (QFile::exists(m_path + QStringLiteral("/out/files/MP1/version.yaml"))) { + m_ui->packageBtn->setEnabled(true); + if (isPackageComplete()) { + m_ui->launchBtn->setEnabled(true); + if (hecl::com_enableCheats->toBoolean()) { + m_ui->warpBtn->setEnabled(true); + } + } + } + + if (!m_ui->sysReqTable->isBlenderVersionOk()) { + insertContinueNote(tr("Blender 2.90 or greater must be installed. Please download via Steam or blender.org.")); + } else if (m_ui->launchBtn->isEnabled()) { + insertContinueNote(tr("Package complete - Press 'Launch' to start Metaforce.")); + } else if (m_ui->packageBtn->isEnabled()) { + insertContinueNote(tr("Extract complete - Press 'Package' to continue.")); + } else if (m_ui->extractBtn->isEnabled()) { + insertContinueNote(tr("Press 'Extract' to begin.")); + } +} + +bool MainWindow::isPackageComplete() const { + return QFile::exists(m_path + QStringLiteral("/out/files/MP1/AudioGrp.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/GGuiSys.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid1.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid2.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid3.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid4.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/metroid5.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid6.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid7.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid8.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/MidiData.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/MiscData.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/NoARAM.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/SamGunFx.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/SamusGun.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/SlideShow.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/TestAnim.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/Tweaks.upak")) && + QFile::exists(m_path + QStringLiteral("/out/files/MP1/URDE.upak")); +} + +static bool GetDLPackage(const QString& path, QString& dlPackage) { + QProcess proc; + proc.start(path, {QStringLiteral("--dlpackage")}, QIODevice::ReadOnly); + if (proc.waitForStarted()) { + proc.waitForFinished(); + if (proc.exitCode() == 100) + dlPackage = QString::fromUtf8(proc.readLine()).trimmed(); + return true; + } + return false; +} + +bool MainWindow::checkDownloadedBinary() { + m_metaforcePath = QString(); + m_heclPath = QString(); + + if (m_path.isEmpty()) { + m_ui->heclTabs->setCurrentIndex(2); + m_ui->downloadErrorLabel->setText(tr("Set working directory to continue."), true); + enableOperations(); + return false; + } + + const QString dir = QApplication::instance()->applicationDirPath(); +#if _WIN32 + QString metaforcePath = dir + QStringLiteral("/metaforce.exe"); + QString heclPath = dir + QStringLiteral("/hecl.exe"); + QString visigenPath = dir + QStringLiteral("/visigen.exe"); + if (!QFileInfo::exists(metaforcePath) || !QFileInfo::exists(heclPath) || !QFileInfo::exists(visigenPath)) { + metaforcePath = m_path + QStringLiteral("/metaforce.exe"); + heclPath = m_path + QStringLiteral("/hecl.exe"); + visigenPath = m_path + QStringLiteral("/visigen.exe"); + } +#else + QString metaforcePath = dir + QStringLiteral("/metaforce"); + QString heclPath = dir + QStringLiteral("/hecl"); + QString visigenPath = dir + QStringLiteral("/visigen"); +#endif + metaforcePath = QFileInfo(metaforcePath).absoluteFilePath(); + heclPath = QFileInfo(heclPath).absoluteFilePath(); + visigenPath = QFileInfo(visigenPath).absoluteFilePath(); + + QString metaforceDlPackage, heclDlPackage, visigenDlPackage; + if (GetDLPackage(metaforcePath, metaforceDlPackage) && GetDLPackage(heclPath, heclDlPackage) && + GetDLPackage(visigenPath, visigenDlPackage)) { + if (!metaforceDlPackage.isEmpty() && metaforceDlPackage == heclDlPackage && + metaforceDlPackage == visigenDlPackage) { + MetaforceVersion v(metaforceDlPackage); + m_ui->currentBinaryLabel->setText(v.fileString(false)); + } else { + m_ui->currentBinaryLabel->setText(tr("unknown -- re-download recommended")); + } + + m_metaforcePath = metaforcePath; + m_heclPath = heclPath; + m_ui->downloadErrorLabel->setText({}, true); + enableOperations(); + return true; + } + + m_ui->currentBinaryLabel->setText(tr("none")); + m_ui->heclTabs->setCurrentIndex(2); + m_ui->downloadErrorLabel->setText(tr("Press 'Download' to fetch latest Metaforce binary."), true); + enableOperations(); + return false; +} + +void MainWindow::setPath(const QString& path) { + const QFileInfo finfo(path); + + QString usePath; + if (!path.isEmpty()) { + usePath = finfo.absoluteFilePath(); + } + + if (!usePath.isEmpty() && !finfo.exists()) { + if (QMessageBox::question(this, tr("Make Directory"), tr("%1 does not exist. Create it now?").arg(usePath)) == + QMessageBox::Yes) { + QDir().mkpath(usePath); + } else { + usePath = QString(); + } + } + + if (!usePath.isEmpty() && !finfo.isDir()) { + QMessageBox::warning(this, tr("Directory Error"), tr("%1 is not a directory").arg(usePath), QMessageBox::Ok, + QMessageBox::NoButton); + usePath = QString(); + } + + m_path = usePath; + m_settings.setValue(QStringLiteral("working_dir"), m_path); + + if (!m_path.isEmpty()) { + m_ui->pathEdit->setText(m_path); + m_ui->downloadButton->setToolTip(QString()); + m_ui->downloadButton->setEnabled(m_ui->binaryComboBox->isEnabled()); + } else { + m_ui->downloadButton->setToolTip(tr("Working directory must be set")); + m_ui->downloadButton->setEnabled(false); + m_ui->currentBinaryLabel->setText(tr("none")); + } + + m_ui->sysReqTable->updateFreeDiskSpace(m_path); + checkDownloadedBinary(); +} + +void MainWindow::initSlots() { + connect(&m_heclProc, &QProcess::readyRead, [this]() { + const QByteArray bytes = m_heclProc.readAll(); + setTextTermFormatting(QString::fromUtf8(bytes)); + }); + + connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::onExtract); + connect(m_ui->packageBtn, &QPushButton::clicked, this, &MainWindow::onPackage); + connect(m_ui->launchBtn, &QPushButton::clicked, this, &MainWindow::onLaunch); + + connect(m_ui->browseBtn, &QPushButton::clicked, [this]() { + FileDirDialog dialog(this); + dialog.setDirectory(m_path); + dialog.setWindowTitle(tr("Select Working Directory")); + int res = dialog.exec(); + if (res == QFileDialog::Rejected) + return; + + if (dialog.selectedFiles().size() <= 0) + return; + + setPath(dialog.selectedFiles().at(0)); + }); + connect(m_ui->pathEdit, &QLineEdit::editingFinished, [this]() { setPath(m_ui->pathEdit->text()); }); + + connect(m_ui->downloadButton, &QPushButton::clicked, this, &MainWindow::onDownloadPressed); +} + +void MainWindow::setTextTermFormatting(const QString& text) { + m_inContinueNote = false; + + m_cursor.beginEditBlock(); + // TODO: Migrate QRegExp to QRegularExpression + QRegExp const escapeSequenceExpression(QStringLiteral(R"(\x1B\[([\d;\?FA]+)([mlh]?))")); + QTextCharFormat defaultTextCharFormat = m_cursor.charFormat(); + int offset = escapeSequenceExpression.indexIn(text); + ReturnInsert(m_cursor, text.mid(0, offset)); + QTextCharFormat textCharFormat = defaultTextCharFormat; + while (offset >= 0) { + int previousOffset = offset + escapeSequenceExpression.matchedLength(); + QStringList captures = escapeSequenceExpression.capturedTexts(); + if (captures.size() >= 3 && captures[2] == QStringLiteral("m")) { + QStringList capturedTexts = captures[1].split(QLatin1Char{';'}); + QListIterator i(capturedTexts); + while (i.hasNext()) { + bool ok = false; + int attribute = i.next().toInt(&ok); + Q_ASSERT(ok); + ParseEscapeSequence(attribute, i, textCharFormat, defaultTextCharFormat); + } + } else if (captures.size() >= 2 && + (captures[1].endsWith(QLatin1Char{'F'}) || captures[1].endsWith(QLatin1Char{'A'}))) { + int lineCount = captures[1].chopped(1).toInt(); + if (!lineCount) + lineCount = 1; + for (int i = 0; i < lineCount; ++i) { + m_cursor.movePosition(QTextCursor::PreviousBlock); + m_cursor.select(QTextCursor::BlockUnderCursor); + m_cursor.removeSelectedText(); + m_cursor.insertBlock(); + } + } + offset = escapeSequenceExpression.indexIn(text, previousOffset); + if (offset < 0) { + ReturnInsert(m_cursor, text.mid(previousOffset), textCharFormat); + } else { + ReturnInsert(m_cursor, text.mid(previousOffset, offset - previousOffset), textCharFormat); + } + } + m_cursor.setCharFormat(defaultTextCharFormat); + m_cursor.endEditBlock(); + m_ui->processOutput->ensureCursorVisible(); +} + +void MainWindow::insertContinueNote(const QString& text) { + if (m_inContinueNote) + return; + m_inContinueNote = true; + + m_cursor.movePosition(QTextCursor::End); + QTextCharFormat textCharFormat = m_cursor.charFormat(); + textCharFormat.setForeground(QColor(0, 255, 0)); + m_cursor.insertText(text, textCharFormat); + m_cursor.insertBlock(); + m_ui->processOutput->ensureCursorVisible(); +} + +void MainWindow::onUpdateTrackChanged(int index) { + qDebug() << "Track changed from " << m_settings.value(QStringLiteral("update_track")) << " to " + << skUpdateTracks[index]; + m_settings.setValue(QStringLiteral("update_track"), skUpdateTracks[index]); + m_dlManager.fetchIndex(); + m_ui->devTrackWarning->setVisible(index == 1); + m_ui->continuousTrackWarning->setVisible(index == 2); +} + +void MainWindow::initOptions() { + initGraphicsApiOption(m_ui->metalOption, CurPlatform != Platform::MacOS, DEFAULT_GRAPHICS_API == "Metal"sv); + initGraphicsApiOption(m_ui->vulkanOption, CurPlatform == Platform::MacOS, DEFAULT_GRAPHICS_API == "Vulkan"sv); + initGraphicsApiOption(m_ui->d3d11Option, CurPlatform != Platform::Win32, DEFAULT_GRAPHICS_API == "D3D11"sv); + initNumberComboOption(m_ui->anistropicFilteringBox, m_cvarCommons.m_texAnisotropy); + initNumberComboOption(m_ui->antialiasingBox, m_cvarCommons.m_drawSamples); + initCheckboxOption(m_ui->fullscreen, m_cvarCommons.m_fullscreen); + initCheckboxOption(m_ui->deepColor, m_cvarCommons.m_deepColor); + + m_ui->developerModeBox->setToolTip(QString::fromUtf8(hecl::com_developer->rawHelp().data())); + m_ui->developerModeBox->setChecked(hecl::com_developer->toBoolean()); + m_ui->developerOptionsGroup->setVisible(hecl::com_developer->toBoolean()); + connect(m_ui->developerModeBox, &QCheckBox::stateChanged, this, [this](int state) { + bool isChecked = state == Qt::Checked; + if (hecl::com_enableCheats->toBoolean() && !isChecked) { + m_ui->enableCheatsBox->setChecked(false); + // m_ui->tweaksOptionsGroup->setVisible(false); + m_ui->warpBtn->setVisible(false); + } + m_ui->developerOptionsGroup->setVisible(isChecked); + hecl::CVarManager::instance()->setDeveloperMode(isChecked, true); + m_cvarManager.serialize(); + }); + + m_ui->enableCheatsBox->setToolTip(QString::fromUtf8(hecl::com_enableCheats->rawHelp().data())); + m_ui->enableCheatsBox->setChecked(hecl::com_enableCheats->toBoolean()); + m_ui->tweaksOptionsGroup->setVisible(false); // hecl::com_enableCheats->toBoolean() + m_ui->warpBtn->setVisible(hecl::com_enableCheats->toBoolean()); + connect(m_ui->enableCheatsBox, &QCheckBox::stateChanged, this, [this](int state) { + bool isChecked = state == Qt::Checked; + if (!hecl::com_developer->toBoolean() && isChecked) { + m_ui->developerModeBox->setChecked(true); + m_ui->developerOptionsGroup->setVisible(true); + } + // m_ui->tweaksOptionsGroup->setVisible(isChecked); + m_ui->warpBtn->setVisible(isChecked); + hecl::CVarManager::instance()->setCheatsEnabled(isChecked, true); + m_cvarManager.serialize(); + }); + + initCheckboxOption(m_ui->developerModeBox, hecl::com_developer); + initCheckboxOption(m_ui->enableCheatsBox, hecl::com_enableCheats); + initCheckboxOption(m_ui->variableDtBox, m_cvarCommons.m_variableDt); + initCheckboxOption(m_ui->areaInfoOverlayBox, m_cvarCommons.m_debugOverlayAreaInfo); + initCheckboxOption(m_ui->playerInfoOverlayBox, m_cvarCommons.m_debugOverlayPlayerInfo); + initCheckboxOption(m_ui->worldInfoOverlayBox, m_cvarCommons.m_debugOverlayWorldInfo); + initCheckboxOption(m_ui->frameCounterBox, m_cvarCommons.m_debugOverlayShowFrameCounter); + initCheckboxOption(m_ui->inGameTimeBox, m_cvarCommons.m_debugOverlayShowInGameTime); + initCheckboxOption(m_ui->resourceStatsOverlayBox, m_cvarCommons.m_debugOverlayShowResourceStats); + initCheckboxOption(m_ui->drawLighting, m_cvarCommons.m_debugToolDrawLighting); + initCheckboxOption(m_ui->drawAiPaths, m_cvarCommons.m_debugToolDrawAiPath); + initCheckboxOption(m_ui->drawCollisionActors, m_cvarCommons.m_debugToolDrawCollisionActors); + initCheckboxOption(m_ui->drawMazePath, m_cvarCommons.m_debugToolDrawMazePath); + initCheckboxOption(m_ui->drawPlatformCollision, m_cvarCommons.m_debugToolDrawPlatformCollision); + initCheckboxOption(m_ui->logScriptingBox, + // TODO centralize + hecl::CVarManager::instance()->findOrMakeCVar( + "stateManager.logScripting"sv, "Prints object communication to the console", false, + hecl::CVar::EFlags::ReadOnly | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Game)); + initCheckboxOption(m_ui->skipSplashScreensBox, + // TODO centralize + hecl::CVarManager::instance()->findOrMakeCVar( + "tweak.game.SplashScreensDisabled"sv, "Skip splash screens on game startup", false, + hecl::CVar::EFlags::ReadOnly | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Game)); + + m_launchOptionsModel.setStringList(QSettings().value(QStringLiteral("metaforce_arguments")).toStringList()); + m_ui->launchOptionsList->setModel(&m_launchOptionsModel); + + connect(m_ui->launchOptionAddButton, &QPushButton::clicked, this, [this] { + int row = m_launchOptionsModel.rowCount(); + if (m_launchOptionsModel.insertRow(row)) { + QModelIndex index = m_launchOptionsModel.index(row); + m_ui->launchOptionsList->selectionModel()->select(index, QItemSelectionModel::SelectionFlag::ClearAndSelect); + m_ui->launchOptionsList->edit(index); + } + }); + connect(m_ui->launchOptionDeleteButton, &QPushButton::clicked, this, [this] { + QItemSelectionModel* selection = m_ui->launchOptionsList->selectionModel(); + if (selection == nullptr) { + return; + } + QModelIndexList list = selection->selectedRows(); + for (QModelIndex index : list) { + m_launchOptionsModel.removeRow(index.row()); + } + }); + connect(&m_launchOptionsModel, &QStringListModel::dataChanged, this, + [this]() { QSettings().setValue(QStringLiteral("metaforce_arguments"), m_launchOptionsModel.stringList()); }); + connect(&m_launchOptionsModel, &QStringListModel::rowsRemoved, this, + [this]() { QSettings().setValue(QStringLiteral("metaforce_arguments"), m_launchOptionsModel.stringList()); }); + connect(m_ui->warpBtn, &QPushButton::clicked, this, [this] { + QFileInfo areaPath( + QFileDialog::getOpenFileName(this, tr("Select area to warp to..."), m_path, QStringLiteral("*.blend"))); + if (!areaPath.exists() || areaPath.suffix() != QStringLiteral("blend") || + !areaPath.fileName().contains(QStringLiteral("!area_"))) { + m_warpSettings.clear(); + return; + } + + auto ret = + QMessageBox::question(this, tr("Select enabled layers?"), tr("Do you want to only enable certain layers?")); + + QString layerBits; + if (ret == QMessageBox::StandardButton::Yes) { + QList layers; + QDirIterator iter(areaPath.absolutePath(), QDir::Filter::Dirs); + while (iter.hasNext()) { + QFileInfo f(iter.next()); + if (f.isDir()) { + QDir dir(f.absoluteFilePath()); + if (dir.exists(QStringLiteral("!objects.yaml"))) { + bool active = dir.exists(QStringLiteral("!defaultactive")); + layers.push_back({f.baseName(), active}); + } + } + } + std::sort(layers.begin(), layers.end(), [&](const auto& a, const auto& b) { return a.name < b.name; }); + + LayerDialog layer(this); + layer.createLayerCheckboxes(layers); + auto code = layer.exec(); + if (code == QDialog::DialogCode::Accepted) { + layerBits = layer.getLayerBits(); + } + } + QString directoryPath = areaPath.path(); +#if _WIN32 + directoryPath.replace(QLatin1Char('/'), QDir::separator()); +#else + directoryPath.replace(QLatin1Char('\\'), QDir::separator()); +#endif + auto list = directoryPath.split(QDir::separator()); + std::string areaDirectory = list.last().toLower().toStdString(); + list.pop_back(); + list.pop_back(); + std::string worldDir = list.last().toLower().toStdString(); + quint32 worldIndex; + std::sscanf(worldDir.c_str(), "metroid%i", &worldIndex); + quint32 areaIndex; + char areaName[2048]; + std::sscanf(areaDirectory.c_str(), "%2i%[^\n]", &areaIndex, areaName); + if (layerBits.isEmpty()) { + m_warpSettings = QStringLiteral("--warp %1 %2").arg(worldIndex).arg(areaIndex).split(QLatin1Char(' ')); + } else { + m_warpSettings = + QStringLiteral("--warp %1 %2 %3").arg(worldIndex).arg(areaIndex).arg(layerBits).split(QLatin1Char(' ')); + } + onLaunch(); + m_warpSettings.clear(); + }); +} + +void MainWindow::initNumberComboOption(QComboBox* action, hecl::CVar* cvar) { + QString itemString; + for (int i = 0; !(itemString = action->itemText(i)).isEmpty(); ++i) { + if (itemString.toInt() == cvar->toSigned()) { + action->setCurrentIndex(i); + break; + } + } + action->setToolTip(QString::fromUtf8(cvar->rawHelp().data())); + connect(action, static_cast(&QComboBox::currentIndexChanged), this, + [this, action, cvar](const int i) { + cvar->fromInteger(action->itemText(i).toInt()); + m_cvarManager.serialize(); + }); +} + +void MainWindow::initCheckboxOption(QCheckBox* action, hecl::CVar* cvar) { + action->setToolTip(QString::fromUtf8(cvar->rawHelp().data())); + action->setChecked(cvar->toBoolean()); + connect(action, &QCheckBox::stateChanged, this, [this, cvar](int state) { + cvar->fromBoolean(state == Qt::Checked); + m_cvarManager.serialize(); + }); +} + +void MainWindow::initGraphicsApiOption(QRadioButton* action, bool hidden, bool isDefault) { + if (hidden) { + action->hide(); + return; + } + const std::string& currApi = m_cvarCommons.getGraphicsApi(); + action->setChecked(action->text().compare(QString::fromUtf8(currApi.data()), Qt::CaseInsensitive) == 0 || + (isDefault && currApi.empty())); + connect(action, &QRadioButton::toggled, this, [this, action](bool checked) { + if (checked) { + m_cvarCommons.setGraphicsApi(action->text().toStdString()); + m_cvarCommons.serialize(); + } + }); +} diff --git a/metaforce-gui/MainWindow.hpp b/metaforce-gui/MainWindow.hpp new file mode 100644 index 000000000..2c4de4f32 --- /dev/null +++ b/metaforce-gui/MainWindow.hpp @@ -0,0 +1,80 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +#include "Common.hpp" +#include "DownloadManager.hpp" + +#include +#include + +class QPushButton; +class QTextCharFormat; +class QTextEdit; +class QuaZip; + +namespace Ui { +class MainWindow; +} // namespace Ui + +class MainWindow : public QMainWindow { + static const QStringList skUpdateTracks; + Q_OBJECT + std::unique_ptr m_ui; + hecl::Runtime::FileStoreManager m_fileMgr; + hecl::CVarManager m_cvarManager; + hecl::CVarCommons m_cvarCommons; + QTextCursor m_cursor; + QString m_path; + QString m_metaforcePath; + QString m_heclPath; + QProcess m_heclProc; + DownloadManager m_dlManager; + QStringList m_warpSettings; + QSettings m_settings; + MetaforceVersion m_recommendedVersion; + bool m_inContinueNote = false; + QStringListModel m_launchOptionsModel; + +public: + explicit MainWindow(QWidget* parent = nullptr); + ~MainWindow() override; + + void setTextTermFormatting(const QString& text); + void insertContinueNote(const QString& text); + +private slots: + void onExtract(); + void onExtractFinished(int exitCode, QProcess::ExitStatus); + void onPackage(); + void onPackageFinished(int exitCode, QProcess::ExitStatus); + void onLaunch(); + void onLaunchFinished(int exitCode, QProcess::ExitStatus); + void doHECLTerminate(); + void onReturnPressed(); + void onDownloadPressed(); +// void onUpdateURDEPressed(); + void onUpdateTrackChanged(int index); + +private: + bool checkDownloadedBinary(); + void setPath(const QString& path); + void initSlots(); + void onIndexDownloaded(const QStringList& index); + void onBinaryDownloaded(QuaZip& file); + void onBinaryFailed(); + void disableOperations(); + void enableOperations(); + bool isPackageComplete() const; + void initOptions(); + void initGraphicsApiOption(QRadioButton* action, bool hidden, bool isDefault); + void initNumberComboOption(QComboBox* action, hecl::CVar* cvar); + void initCheckboxOption(QCheckBox* action, hecl::CVar* cvar); +}; diff --git a/metaforce-gui/MainWindow.ui b/metaforce-gui/MainWindow.ui new file mode 100644 index 000000000..f8a7ca099 --- /dev/null +++ b/metaforce-gui/MainWindow.ui @@ -0,0 +1,1418 @@ + + + MainWindow + + + + 0 + 0 + 972 + 946 + + + + + 0 + 0 + + + + Metaforce + + + + + + + 2 + + + + &Data + + + + + + + + + + + 255 + 255 + 255 + + + + + + + 29 + 29 + 29 + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + 29 + 29 + 29 + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + + true + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 0 + 0 + + + + Save Log + + + + + + + + Options + + + + + + + 0 + 0 + + + + + 396 + 0 + + + + Launch Options + + + + + + Add + + + + + + + Delete + + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectRows + + + + + + + + + + + 396 + 0 + + + + Tweaks + + + + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 0 + + + + + 0 + 0 + 428 + 592 + + + + Graphics + + + + + + + + D3D11 + + + + + + + Metal + + + + + + + Vulkan + + + + + + + + + Anti-Aliasing + + + + + + + + 0 + 0 + + + + + 1 + + + + + 2 + + + + + 4 + + + + + 8 + + + + + 16 + + + + + + + + Anistropic Filtering + + + + + + + + 0 + 0 + + + + + 1 + + + + + 2 + + + + + 4 + + + + + 8 + + + + + 16 + + + + + + + + Start in fullscreen + + + + + + + Deep Color + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 0 + 0 + 161 + 89 + + + + Game + + + + + + Skip Splash Screens + + + + + + + Developer Mode + + + + + + + Enable Cheats + + + + + + + Qt::Vertical + + + + 20 + 603 + + + + + + + + + + 0 + 0 + 212 + 47 + + + + Experimental + + + + + + Variable Delta Time (broken) + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 0 + 0 + 210 + 366 + + + + Developer + + + + + + Log Scripting + + + + + + + Debug Overlays + + + + + + Area Info Overlay + + + + + + + Show Frame Counter + + + + + + + Show Resource Stats + + + + + + + Player Info Overlay + + + + + + + Show In-Game Time + + + + + + + World Info Overlay + + + + + + + + + + Debug Tools + + + + + + Draw AI Paths + + + + + + + <html><head/><body><p>Draws lighting radii using models obtained from https://axiodl.com/files/debug_models.zip</p></body></html> + + + Draw Lighting + + + + + + + Draw Collision Actors + + + + + + + Draw Maze Path + + + + + + + Draw Platform Collision + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + 0 + 0 + + + + &System Check + + + + + + + + false + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + false + + + + 0 + 0 + + + + + 150 + 0 + + + + + + + + + 53 + 53 + 72 + + + + + + + + + 53 + 53 + 72 + + + + + + + + + 53 + 53 + 72 + + + + + + + + Download + + + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + + + 68 + 68 + 68 + + + + + + + + QAbstractItemView::NoSelection + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + 12 + + + + + Downloaded Metaforce version: + + + + + + + none + + + + + + + Recommended Metaforce version: + + + + + + + fetching... + + + + + + + Update track: + + + + + + + + 0 + 0 + + + + + Stable + + + + + Development + + + + + Continuous + + + + + + + + + + + + + + + 255 + 47 + 0 + + + + + + + + + 255 + 47 + 0 + + + + + + + + + 164 + 166 + 168 + + + + + + + + + + + true + + + + + + + <html><head/><body><p align="center"><span style=" color:#ff0000;">Continuous track selected!<br/>Continuous builds are built after every commit <br/>and have </span><span style=" font-weight:600; color:#ff0000;">no</span><span style=" color:#ff0000;"> guarantee of working at all.</span></p></body></html> + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + false + + + 0 + + + + + + + <html><head/><body><p align="center"><span style=" color:#1a5fb4;">Development track selected!<br/>Development builds are considered unstable and may cause crashes.</span></p></body></html> + + + true + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + &About + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 128 + 128 + + + + + 128 + 128 + + + + Icon + + + true + + + 16 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + + 208 + 208 + 208 + + + + + + + 208 + 208 + 208 + + + + + + + 208 + 208 + 208 + + + + + + + 46 + 47 + 48 + + + + + + + 46 + 47 + 48 + + + + + + + 208 + 208 + 208 + + + + + + + + + 208 + 208 + 208 + + + + + + + 208 + 208 + 208 + + + + + + + 208 + 208 + 208 + + + + + + + 46 + 47 + 48 + + + + + + + 46 + 47 + 48 + + + + + + + 208 + 208 + 208 + + + + + + + + + 64 + 66 + 68 + + + + + + + 64 + 66 + 68 + + + + + + + 64 + 66 + 68 + + + + + + + 46 + 47 + 48 + + + + + + + 46 + 47 + 48 + + + + + + + 208 + 208 + 208 + + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;"> +<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Noto Sans'; font-size:10pt; font-weight:600;">About Metaforce</span></p> +<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Noto Sans'; font-size:10pt;"><br />The Metaforce frontend UI is designed and built by </span><a href="https://axiodl.com"><span style=" font-family:'Noto Sans'; font-size:10pt; text-decoration: underline; color:#007af4;">Axiomatic Data Laboratories</span></a><span style=" font-family:'Noto Sans'; font-size:10pt;"> Copyright 2020<br /><br /></span><span style=" font-family:'Noto Sans'; font-size:10pt; font-weight:600;">Authors:</span><span style=" font-family:'Noto Sans'; font-size:10pt;"><br />Phillip &quot;Antidote&quot; Stephens<br />Jack &quot;jackoalan&quot; Andersen<br />Luke &quot;encounter&quot; Street</span></p> +<p style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Courier New'; font-size:10pt;">The MIT License</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Courier New'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Courier New'; font-size:10pt;">Copyright (c) 2015-2021 Metaforce Contributors</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Courier New'; font-size:10pt;">Original Authors: Jack Andersen and Phillip &quot;Antidote&quot; Stephens</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Courier New'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Courier New'; font-size:10pt;">Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &quot;Software&quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Courier New'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Courier New'; font-size:10pt;">The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Courier New'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Courier New'; font-size:10pt;">THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</span></p></body></html> + + + true + + + + + + + + + + + + + + 0 + 0 + + + + Extract Directory: + + + pathEdit + + + + + + + + 0 + 0 + + + + + 1 + 0 + + + + + + + + + 0 + 0 + + + + + 32 + 16777215 + + + + ... + + + + + + + + + + + Qt::Horizontal + + + + 167 + 20 + + + + + + + + false + + + + 16777215 + 16777215 + + + + &Extract + + + + + + + false + + + + 16777215 + 16777215 + + + + &Package + + + + + + + false + + + + 16777215 + 16777215 + + + + &Launch + + + + + + + false + + + Launch && &Warp + + + + + + + Qt::Horizontal + + + + 166 + 20 + + + + + + + + + + <center><h1 style="color:red">ALPHA VERSION</h1></center> + + + + + + + + + SysReqTableView + QTableView +
SysReqTableView.hpp
+
+ + ErrorLabel + QLabel +
ErrorLabel.hpp
+
+
+ + + + pathEdit + returnPressed() + MainWindow + onReturnPressed() + + + 331 + 20 + + + 302 + 305 + + + + + + onReturnPressed() + +
diff --git a/metaforce-gui/SysReqTableView.cpp b/metaforce-gui/SysReqTableView.cpp new file mode 100644 index 000000000..0bb0ab625 --- /dev/null +++ b/metaforce-gui/SysReqTableView.cpp @@ -0,0 +1,250 @@ +#include "SysReqTableView.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FindBlender.hpp" +#include + +#if _WIN32 +#include +#include +#else +#include +#endif + +#if __APPLE__ +#include "MacOSSystemVersion.hpp" +#elif _WIN32 +static QString GetWindowsVersionString() { + if (IsWindows10OrGreater()) + return QObject::tr("Windows 10"); + else if (IsWindows8Point1OrGreater()) + return QObject::tr("Windows 8.1"); + else if (IsWindows8OrGreater()) + return QObject::tr("Windows 8"); + else if (IsWindows7SP1OrGreater()) + return QObject::tr("Windows 7 SP1"); + else if (IsWindows7OrGreater()) + return QObject::tr("Windows 7"); + else if (IsWindowsVistaOrGreater()) + return QObject::tr("Windows Vista"); + else if (IsWindowsXPOrGreater()) + return QObject::tr("Windows XP"); + else + return QObject::tr("Windows Old And Won't Work"); +} +#endif + +SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent) { +#if _WIN32 + ULONGLONG memSize; + GetPhysicallyInstalledSystemMemory(&memSize); + m_memorySize = memSize * 1024; +#else + m_memorySize = uint64_t(sysconf(_SC_PHYS_PAGES)) * sysconf(_SC_PAGESIZE); +#endif + m_memorySizeStr = tr("%1 GiB").arg(m_memorySize / 1024.f / 1024.f / 1024.f); +#ifdef __APPLE__ + GetMacOSSystemVersion(m_macosMajor, m_macosMinor, m_macosPatch); + if (m_macosPatch == 0) { + m_osVersion = tr("macOS %1.%2").arg(m_macosMajor, m_macosMinor); + } else { + m_osVersion = tr("macOS %1.%2.%3") + .arg(QString::number(m_macosMajor), QString::number(m_macosMinor), QString::number(m_macosPatch)); + } +#elif _WIN32 + m_win7SP1OrGreater = IsWindows7SP1OrGreater(); + m_osVersion = GetWindowsVersionString(); +#elif __linux__ + m_osVersion = tr("Linux"); +#endif + hecl::blender::FindBlender(m_blendMajor, m_blendMinor); + if (m_blendMajor != 0) { + m_blendVersionStr = tr("Blender %1.%2").arg(QString::number(m_blendMajor), QString::number(m_blendMinor)); + } else { + m_blendVersionStr = tr("Not Found"); + } +} + +void SysReqTableModel::updateFreeDiskSpace(const QString& path) { + if (path.isEmpty()) { + m_freeDiskSpace = 0; + m_freeDiskSpaceStr = tr(""); + } else { + m_freeDiskSpace = QStorageInfo(path).bytesFree(); + m_freeDiskSpaceStr = tr("%1 GB").arg(m_freeDiskSpace / 1000.f / 1000.f / 1000.f, 1, 'f', 1); + } + emit dataChanged(index(1, 0), index(1, 0)); +} + +int SysReqTableModel::rowCount(const QModelIndex& parent) const { return 4; } + +int SysReqTableModel::columnCount(const QModelIndex& parent) const { return 2; } + +QVariant SysReqTableModel::data(const QModelIndex& index, int role) const { + if (role != Qt::DisplayRole && role != Qt::UserRole) { + return {}; + } + + if (role == Qt::UserRole) { + switch (index.row()) { + case 0: + return m_memorySize >= 0xC0000000; + case 1: + return m_freeDiskSpace >= qint64(5) * 1000 * 1000 * 1000; + case 2: +#ifdef __APPLE__ + return m_macosMajor > 10 || m_macosMinor >= 11; +#elif defined(_WIN32) + return m_win7SP1OrGreater; +#else + return true; +#endif + case 3: + return isBlenderVersionOk(); + } + } else { + if (index.column() == 0) { + /* Recommended */ + switch (index.row()) { + case 0: + return tr("3 GiB"); + case 1: + return tr("5 GB (MP1)"); + case 2: +#ifdef __APPLE__ + return tr("macOS 10.11"); +#elif defined(_WIN32) + return tr("Windows 7 SP1"); +#elif defined(__linux__) + return tr("Linux"); +#else + return {}; +#endif + case 3: + return QStringLiteral("Blender %1.%2+") + .arg(hecl::blender::MinBlenderMajorSearch) + .arg(hecl::blender::MinBlenderMinorSearch); + } + } else if (index.column() == 1) { + /* Your System */ + switch (index.row()) { + case 0: + return m_memorySizeStr; + case 1: + return m_freeDiskSpaceStr; + case 2: + return m_osVersion; + case 3: + return m_blendVersionStr; + } + } + } + return {}; +} + +QVariant SysReqTableModel::headerData(int section, Qt::Orientation orientation, int role) const { + if (role != Qt::DisplayRole) { + return {}; + } + + if (orientation == Qt::Horizontal) { + switch (section) { + case 0: + default: + return tr("Recommended"); + case 1: + return tr("Your System"); + } + } else { + switch (section) { + default: + case 0: + return tr("Memory"); + case 1: + return tr("Disk Space"); + case 2: + return tr("OS"); + case 3: + return tr("Blender"); + } + } +} + +bool SysReqTableModel::isBlenderVersionOk() const { + return (m_blendMajor >= hecl::blender::MinBlenderMajorSearch && + m_blendMajor <= hecl::blender::MaxBlenderMajorSearch) && + (m_blendMinor >= hecl::blender::MinBlenderMinorSearch && m_blendMinor <= hecl::blender::MaxBlenderMinorSearch); +} + +void SysReqTableView::paintEvent(QPaintEvent* e) { + int tableWidth = columnWidth(0) + columnWidth(1); + int tableX = verticalHeader()->width() + columnViewportPosition(0); + int tableY = horizontalHeader()->height(); + for (int i = 0; i < 6; ++i) { + QWidget* w = std::get<0>(m_backgroundWidgets[i]); + + QPalette pal = palette(); + if (m_model.data(m_model.index(i, 0), Qt::UserRole).toBool()) + pal.setColor(QPalette::Window, QColor::fromRgbF(0.f, 1.f, 0.f, 0.2f)); + else + pal.setColor(QPalette::Window, QColor::fromRgbF(1.f, 0.f, 0.f, 0.2f)); + w->setPalette(pal); + + QSequentialAnimationGroup* animation = std::get<1>(m_backgroundWidgets[i]); + QPropertyAnimation* pAnimation = static_cast(animation->animationAt(1)); + bool& running = std::get<2>(m_backgroundWidgets[i]); + if (!running) { + w->setGeometry(QRect(tableX, tableY + rowViewportPosition(i), 0, rowHeight(i))); + pAnimation->setStartValue(QRect(tableX, tableY + rowViewportPosition(i), 0, rowHeight(i))); + pAnimation->setEndValue(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i))); + animation->start(); + running = true; + } + if (animation->state() == QAbstractAnimation::State::Running) + pAnimation->setEndValue(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i))); + else + w->setGeometry(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i))); + } + QTableView::paintEvent(e); +} + +SysReqTableView::SysReqTableView(QWidget* parent) : QTableView(parent) { + setModel(&m_model); + + horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); + setSelectionMode(QAbstractItemView::SelectionMode::NoSelection); + setFocusPolicy(Qt::NoFocus); + + for (int i = 0; i < 6; ++i) { + QWidget* w = new QWidget(this); + std::get<0>(m_backgroundWidgets[i]) = w; + + QPalette pal = palette(); + if (m_model.data(m_model.index(i, 0), Qt::UserRole).toBool()) + pal.setColor(QPalette::Window, QColor::fromRgbF(0.f, 1.f, 0.f, 0.2f)); + else + pal.setColor(QPalette::Window, QColor::fromRgbF(1.f, 0.f, 0.f, 0.2f)); + + w->setAutoFillBackground(true); + w->setPalette(pal); + w->lower(); + w->show(); + + QPropertyAnimation* animation = new QPropertyAnimation(w, "geometry", this); + animation->setDuration(2000); + animation->setEasingCurve(QEasingCurve::Type::InOutCubic); + + QSequentialAnimationGroup* seq = new QSequentialAnimationGroup(this); + std::get<1>(m_backgroundWidgets[i]) = seq; + seq->addPause(i * 100); + seq->addAnimation(animation); + } +} diff --git a/metaforce-gui/SysReqTableView.hpp b/metaforce-gui/SysReqTableView.hpp new file mode 100644 index 000000000..c9c4aface --- /dev/null +++ b/metaforce-gui/SysReqTableView.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include + +class QSequentialAnimationGroup; + +class SysReqTableModel : public QAbstractTableModel { + Q_OBJECT + uint64_t m_memorySize = 0; + QString m_memorySizeStr; + qint64 m_freeDiskSpace = 0; + QString m_freeDiskSpaceStr = tr(""); +#if __APPLE__ + int m_macosMajor = 0; + int m_macosMinor = 0; + int m_macosPatch = 0; +#elif _WIN32 + bool m_win7SP1OrGreater = false; +#endif + QString m_osVersion; + int m_blendMajor = 0; + int m_blendMinor = 0; + QString m_blendVersionStr; + +public: + SysReqTableModel(QObject* parent = Q_NULLPTR); + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + bool isBlenderVersionOk() const; + void updateFreeDiskSpace(const QString& path); +}; + +class SysReqTableView : public QTableView { + Q_OBJECT + SysReqTableModel m_model; + std::tuple m_backgroundWidgets[6] = {}; + +public: + SysReqTableView(QWidget* parent = Q_NULLPTR); + void paintEvent(QPaintEvent* e) override; + const SysReqTableModel& getModel() const { return m_model; } + bool isBlenderVersionOk() const { return m_model.isBlenderVersionOk(); } + void updateFreeDiskSpace(const QString& path) { m_model.updateFreeDiskSpace(path); } +}; diff --git a/metaforce-gui/main.cpp b/metaforce-gui/main.cpp new file mode 100644 index 000000000..5d7aec628 --- /dev/null +++ b/metaforce-gui/main.cpp @@ -0,0 +1,73 @@ +#include +#if defined(_WIN32) && !defined(_DLL) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +// Static linking on Windows +#include +Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin); +#endif +#endif + +#include +#include +#include "MainWindow.hpp" +#include "Common.hpp" + +extern "C" const uint8_t MAINICON_QT[]; + +static QIcon MakeAppIcon() { + QIcon ret; + + const uint8_t* ptr = MAINICON_QT; + for (int i = 0; i < 6; ++i) { + uint32_t size = *reinterpret_cast(ptr); + ptr += 4; + + QPixmap pm; + pm.loadFromData(ptr, size); + ret.addPixmap(pm); + ptr += size; + } + + return ret; +} + +int main(int argc, char* argv[]) { + InitializePlatform(); + + QApplication::setOrganizationName(QStringLiteral("AxioDL")); + QApplication::setApplicationName(QStringLiteral("HECL")); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); +#endif + QApplication::setStyle(QStyleFactory::create(QStringLiteral("Fusion"))); + QApplication a(argc, argv); + QApplication::setWindowIcon(MakeAppIcon()); + + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, QColor(42, 42, 42)); + darkPalette.setColor(QPalette::Disabled, QPalette::Base, QColor(25, 25, 25, 53)); + darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53)); + darkPalette.setColor(QPalette::ToolTipBase, QColor(42, 42, 42)); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(255, 255, 255, 120)); + darkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); + darkPalette.setColor(QPalette::Disabled, QPalette::Button, QColor(53, 53, 53, 53)); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(255, 255, 255, 120)); + darkPalette.setColor(QPalette::BrightText, Qt::red); + darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(42, 130, 218, 53)); + darkPalette.setColor(QPalette::HighlightedText, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(255, 255, 255, 120)); + QApplication::setPalette(darkPalette); + + MainWindow w; + w.show(); + return QApplication::exec(); +} diff --git a/metaforce-gui/platforms/freedesktop/1024x1024/apps/metaforce-gui.png b/metaforce-gui/platforms/freedesktop/1024x1024/apps/metaforce-gui.png new file mode 100644 index 000000000..a57f16e8e Binary files /dev/null and b/metaforce-gui/platforms/freedesktop/1024x1024/apps/metaforce-gui.png differ diff --git a/metaforce-gui/platforms/freedesktop/128x128/apps/metaforce-gui.png b/metaforce-gui/platforms/freedesktop/128x128/apps/metaforce-gui.png new file mode 100644 index 000000000..9de9aa99d Binary files /dev/null and b/metaforce-gui/platforms/freedesktop/128x128/apps/metaforce-gui.png differ diff --git a/metaforce-gui/platforms/freedesktop/16x16/apps/metaforce-gui.png b/metaforce-gui/platforms/freedesktop/16x16/apps/metaforce-gui.png new file mode 100644 index 000000000..2190e6a17 Binary files /dev/null and b/metaforce-gui/platforms/freedesktop/16x16/apps/metaforce-gui.png differ diff --git a/metaforce-gui/platforms/freedesktop/256x256/apps/metaforce-gui.png b/metaforce-gui/platforms/freedesktop/256x256/apps/metaforce-gui.png new file mode 100644 index 000000000..85bae4843 Binary files /dev/null and b/metaforce-gui/platforms/freedesktop/256x256/apps/metaforce-gui.png differ diff --git a/metaforce-gui/platforms/freedesktop/32x32/apps/metaforce-gui.png b/metaforce-gui/platforms/freedesktop/32x32/apps/metaforce-gui.png new file mode 100644 index 000000000..43b33b99c Binary files /dev/null and b/metaforce-gui/platforms/freedesktop/32x32/apps/metaforce-gui.png differ diff --git a/metaforce-gui/platforms/freedesktop/48x48/apps/metaforce-gui.png b/metaforce-gui/platforms/freedesktop/48x48/apps/metaforce-gui.png new file mode 100644 index 000000000..d55aaec9d Binary files /dev/null and b/metaforce-gui/platforms/freedesktop/48x48/apps/metaforce-gui.png differ diff --git a/metaforce-gui/platforms/freedesktop/512x512/apps/metaforce-gui.png b/metaforce-gui/platforms/freedesktop/512x512/apps/metaforce-gui.png new file mode 100644 index 000000000..5e31fabe7 Binary files /dev/null and b/metaforce-gui/platforms/freedesktop/512x512/apps/metaforce-gui.png differ diff --git a/metaforce-gui/platforms/freedesktop/64x64/apps/metaforce-gui.png b/metaforce-gui/platforms/freedesktop/64x64/apps/metaforce-gui.png new file mode 100644 index 000000000..7e8a5d937 Binary files /dev/null and b/metaforce-gui/platforms/freedesktop/64x64/apps/metaforce-gui.png differ diff --git a/metaforce-gui/platforms/freedesktop/CMakeLists.txt b/metaforce-gui/platforms/freedesktop/CMakeLists.txt new file mode 100644 index 000000000..49359e607 --- /dev/null +++ b/metaforce-gui/platforms/freedesktop/CMakeLists.txt @@ -0,0 +1,18 @@ +add_executable(mkqticon mkqticon.c) +target_link_libraries(mkqticon ${PNG_LIBRARIES} ${ZLIB_LIBRARIES}) +target_include_directories(mkqticon PRIVATE ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}) + +macro(declare_qticon_target) +add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/metaforce-gui/platforms/freedesktop/mainicon_qt.bin + COMMAND $ + ARGS ${CMAKE_BINARY_DIR}/metaforce-gui/platforms/freedesktop/mainicon_qt.bin + DEPENDS + ${CMAKE_SOURCE_DIR}/metaforce-gui/platforms/freedesktop/128x128/apps/metaforce-gui.png + ${CMAKE_SOURCE_DIR}/metaforce-gui/platforms/freedesktop/64x64/apps/metaforce-gui.png + ${CMAKE_SOURCE_DIR}/metaforce-gui/platforms/freedesktop/48x48/apps/metaforce-gui.png + ${CMAKE_SOURCE_DIR}/metaforce-gui/platforms/freedesktop/32x32/apps/metaforce-gui.png + ${CMAKE_SOURCE_DIR}/metaforce-gui/platforms/freedesktop/16x16/apps/metaforce-gui.png + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/metaforce-gui/platforms/freedesktop + COMMENT "Generating mainicon_qt.bin") +bintoc(mainicon_qt.cpp ${CMAKE_BINARY_DIR}/metaforce-gui/platforms/freedesktop/mainicon_qt.bin MAINICON_QT) +endmacro() diff --git a/metaforce-gui/platforms/freedesktop/metaforce.desktop b/metaforce-gui/platforms/freedesktop/metaforce.desktop new file mode 100644 index 000000000..bf89271aa --- /dev/null +++ b/metaforce-gui/platforms/freedesktop/metaforce.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=Metaforce +GenericName=Game Data Prep Tool +Comment=Prepare Game Data for Metaforce +Exec=metaforce-gui +Icon=metaforce-gui +Terminal=false +Type=Application +Categories=Graphics;3DGraphics; diff --git a/metaforce-gui/platforms/freedesktop/mkqticon.c b/metaforce-gui/platforms/freedesktop/mkqticon.c new file mode 100644 index 000000000..1eb80fa95 --- /dev/null +++ b/metaforce-gui/platforms/freedesktop/mkqticon.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +static const int DIMS[] = +{ + 16, + 32, + 48, + 64, + 128, + 256, + 0 +}; + +int main(int argc, char* argv[]) +{ + if (argc < 2) + { + fprintf(stderr, "Usage: makeqticon \n"); + return 1; + } + + FILE* ofp = fopen(argv[1], "wb"); + if (!ofp) + { + fprintf(stderr, "'%s' is not able to be opened for writing as a regular file\n", argv[1]); + return 1; + } + + char command[2048]; + + for (const int* d = DIMS ; *d != 0 ; ++d) + { + printf("Rendering main icon @%dx%d\n", *d, *d); + fflush(stdout); + + snprintf(command, 2048, "%dx%d/apps/metaforce-gui.png", *d, *d); + FILE* fp = fopen(command, "rb"); + if (!fp) + { + fprintf(stderr, "unable to open '%s' for reading\n", command); + fclose(ofp); + return 1; + } + + fseek(fp, 0, SEEK_END); + uint32_t size = (uint32_t)ftell(fp); + fseek(fp, 0, SEEK_SET); + + fwrite(&size, 1, 4, ofp); + + uint8_t buf[1024]; + while (size > 0) + { + long thisSize = size; + if (thisSize > 1024) + thisSize = 1024; + + fread(buf, 1, (size_t)thisSize, fp); + fwrite(buf, 1, (size_t)thisSize, ofp); + size -= thisSize; + } + + fclose(fp); + } + + fclose(ofp); + return 0; +} diff --git a/Editor/platforms/mac/Info.plist.in b/metaforce-gui/platforms/mac/Info.plist similarity index 76% rename from Editor/platforms/mac/Info.plist.in rename to metaforce-gui/platforms/mac/Info.plist index 9094d1432..5e38330af 100644 --- a/Editor/platforms/mac/Info.plist.in +++ b/metaforce-gui/platforms/mac/Info.plist @@ -3,13 +3,13 @@ CFBundleExecutable - urde + metaforce-gui CFBundleGetInfoString - @METADATA_VERSION_STRING@ + @METAFORCE_WC_DESCRIBE@ CFBundleShortVersionString - @METADATA_VERSION_STRING@ + @METAFORCE_WC_DESCRIBE@ NSHumanReadableCopyright - 2015-2018 Antidote / Jackoalan + 2015-@CURRENT_YEAR@ AxioDL Team CFBundleIconFile mainicon.icns CFBundleIdentifier @@ -17,9 +17,9 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - URDE + Metaforce CFBundleVersion - @METADATA_VERSION_STRING@ + @METAFORCE_WC_DESCRIBE@ CFBundlePackageType APPL CFBundleSignature diff --git a/Editor/platforms/mac/mainicon.icns b/metaforce-gui/platforms/mac/mainicon.icns similarity index 100% rename from Editor/platforms/mac/mainicon.icns rename to metaforce-gui/platforms/mac/mainicon.icns diff --git a/metaforce-gui/platforms/win/mainicon.ico b/metaforce-gui/platforms/win/mainicon.ico new file mode 100644 index 000000000..c299b92ce Binary files /dev/null and b/metaforce-gui/platforms/win/mainicon.ico differ diff --git a/metaforce-gui/platforms/win/metaforce-gui.manifest b/metaforce-gui/platforms/win/metaforce-gui.manifest new file mode 100644 index 000000000..096cf5d0c --- /dev/null +++ b/metaforce-gui/platforms/win/metaforce-gui.manifest @@ -0,0 +1,23 @@ + + + Metaforce + + + + + + + + + + + + + + + + + true/PM + + + diff --git a/metaforce-gui/platforms/win/metaforce-gui.rc b/metaforce-gui/platforms/win/metaforce-gui.rc new file mode 100644 index 000000000..33ccbfd40 --- /dev/null +++ b/metaforce-gui/platforms/win/metaforce-gui.rc @@ -0,0 +1,33 @@ +#include "winver.h" +#define IDI_ICON1 101 + +IDI_ICON1 ICON DISCARDABLE "mainicon.ico" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,0 + PRODUCTVERSION 1,0,0,0 + FILEFLAGS 0x0L + FILEFLAGSMASK 0x3fL + FILEOS 0x00040004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "AxioDL" + VALUE "FileDescription", "Metaforce" + VALUE "FileVersion", "@METAFORCE_WC_DESCRIBE@" + VALUE "LegalCopyright", "Copyright (C) 2015-@CURRENT_YEAR@ AxioDL Team" + VALUE "InternalName", "metaforce-gui" + VALUE "OriginalFilename", "metaforce-gui.exe" + VALUE "ProductName", "Metaforce" + VALUE "ProductVersion", "@METAFORCE_WC_DESCRIBE@" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/metaforce-gui/quazip/.editorconfig b/metaforce-gui/quazip/.editorconfig new file mode 100644 index 000000000..bae99d9c7 --- /dev/null +++ b/metaforce-gui/quazip/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +end_of_line = lf +indent_style = space +indent_size = 4 diff --git a/metaforce-gui/quazip/CMakeLists.txt b/metaforce-gui/quazip/CMakeLists.txt new file mode 100644 index 000000000..26be2c2e0 --- /dev/null +++ b/metaforce-gui/quazip/CMakeLists.txt @@ -0,0 +1,75 @@ +# require 3.15 for GNUInstallDirs +cmake_minimum_required(VERSION 3.15...3.18) + +project(QuaZip VERSION 1.1) + +set(CMAKE_CXX_STANDARD 14) + +set(QUAZIP_LIB_VERSION ${QuaZip_VERSION}) +set(QUAZIP_LIB_SOVERSION 1.0.0) + +option(BUILD_SHARED_LIBS "" ON) +option(QUAZIP_INSTALL "" ON) +set(QUAZIP_QT_MAJOR_VERSION 5 CACHE STRING "Qt version to use (4 or 5), defaults to 5") + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RELEASE) +endif() + +enable_testing() +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_DEBUG_POSTFIX d) + +set(QUAZIP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(QUAZIP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(QUAZIP_LIB_FILE_NAME quazip${QuaZip_VERSION_MAJOR}-qt${QUAZIP_QT_MAJOR_VERSION}) +set(QUAZIP_LIB_TARGET_NAME QuaZip) +set(QUAZIP_DIR_NAME QuaZip-Qt${QUAZIP_QT_MAJOR_VERSION}-${QUAZIP_LIB_VERSION}) +set(QUAZIP_PACKAGE_NAME QuaZip-Qt${QUAZIP_QT_MAJOR_VERSION}) +set(QUAZIP_ENABLE_TESTS OFF) +if(QUAZIP_QT_MAJOR_VERSION EQUAL 6) + find_package(Qt6 REQUIRED COMPONENTS Core Core5Compat + OPTIONAL_COMPONENTS Network Test) + set(QUAZIP_LIB_LIBRARIES Qt6::Core Qt6::Core5Compat) + set(QUAZIP_TEST_QT_LIBRARIES Qt6::Core Qt6::Core5Compat Qt6::Network Qt6::Test) + set(QUAZIP_PKGCONFIG_REQUIRES Qt6Core) + if (Qt6Network_FOUND AND Qt6Test_FOUND) + set(QUAZIP_ENABLE_TESTS ON) + endif() +elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 5) + find_package(Qt5 REQUIRED COMPONENTS Core + OPTIONAL_COMPONENTS Network Test) + set(QUAZIP_LIB_LIBRARIES Qt5::Core) + set(QUAZIP_TEST_QT_LIBRARIES Qt5::Core Qt5::Network Qt5::Test) + set(QUAZIP_PKGCONFIG_REQUIRES Qt5Core) + if (Qt5Network_FOUND AND Qt5Test_FOUND) + set(QUAZIP_ENABLE_TESTS ON) + endif() +elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 4) + find_package(Qt4 4.5.0 REQUIRED COMPONENTS QtCore + OPTIONAL_COMPONENTS QtNetwork QtTest) + set(QUAZIP_LIB_LIBRARIES Qt4::QtCore) + set(QUAZIP_TEST_QT_LIBRARIES Qt4::QtCore Qt4::QtNetwork Qt4::QtTest) + set(QUAZIP_PKGCONFIG_REQUIRES QtCore) + if (QT_QTNETWORK_FOUND AND QT_QTTEST_FOUND) + set(QUAZIP_ENABLE_TESTS ON) + endif() +else() + message(FATAL_ERROR "Qt version ${QUAZIP_QT_MAJOR_VERSION} is not supported") +endif() + +find_package(Qt${QUAZIP_QT_MAJOR_VERSION} QUIET OPTIONAL_COMPONENTS Zlib) +if (Qt${QUAZIP_QT_MAJOR_VERSION}Zlib_FOUND) + set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} Qt${QUAZIP_QT_MAJOR_VERSION}::Zlib) +else() + find_package(ZLIB REQUIRED) + set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} ZLIB::ZLIB) +endif() + +add_subdirectory(quazip) + +if(QUAZIP_ENABLE_TESTS) + add_subdirectory(qztest EXCLUDE_FROM_ALL) +endif() + diff --git a/metaforce-gui/quazip/CONTRIBUTING.md b/metaforce-gui/quazip/CONTRIBUTING.md new file mode 100644 index 000000000..223be93f9 --- /dev/null +++ b/metaforce-gui/quazip/CONTRIBUTING.md @@ -0,0 +1,56 @@ +Fixed a bug? Implemented a new feature? Want to have it included in QuaZip? +Here's what you need to do. + +0. If you don't have a GitHub account, create one. It's ridiculously easy. + +1. First, open an [issue](https://github.com/stachenov/quazip/issues). +Even if you have already fixed it. It helps to track things because +instead of a commit saying “fixed this and that” you have a reference +to a full issue description. + +2. Next, figure out the right branch to work on. *Usually* it's `master`, +but sometimes it's something different. For example, there was time +when new features went to `pre1.0`, and `master` was for 0.x bugfixes only. + +3. Next, send a PR (pull request). There are numerous articles how to do it, +but it's not exactly intuitive, just like anything with Git, so do +some research before attempting to create a PR. + +**Contribution guidelines** + +To avoid spending time on something that may never be accepted, here are +some guidelines. + +1. Changes should be backwards-compatible. Don't just change method names +and their signatures randomly. Don't just remove deprecated features—some +of them are there to keep compatibility with old Qt versions. Even Qt 4 is +still supported! Unless you're working on some sort of `pre2.0` branch +or something like that, you should keep ABI compatibility as well! Meaning, +no adding virtual functions, no changing parameter types, even if it's +a source-compatible change, and a lot of other things, really. + +2. If your change targets some new version of Qt, it's a very good idea +to keep various `#ifs` in `quazip_qt_compat.h`, which exists for this very +purpose. Don't just throw them into the code. Don't just replace deprecated +things with their newer alternatives—it would break support of the old +Qt versions. + +3. If your changes aren't limited to a small fix or a convenience method, +discussing them in the issue you just opened (if you didn't, do!) could +help to achieve some agreement on what exactly is a good idea in your case. + +4. Whether you're fixing a bug or adding a new feature, it's an awesome idea +to add a new test in the `qztest` subproject. This way you make sure the +bug stays fixed and the feature keeps working. This is *not* a mandatory +requirement, however, because adding tests to a project you're not familiar +with can be challenging, and it should not stop you from sending a PR. + +5. It would be nice if you also update NEWS.txt with whatever changes +you propose. Just add another line on top. + +6. QuaZip doesn't really have any policies on PR commits. Just use common sense. +Generally, it's better to keep separate things separate. If you made 2 changes, +and there are 6 commits for one change and 4 for another, that's OK. +Don't squash commits just to squash them. If your branch gets outdated before PR +is accepted, merge or rebase—it doesn't really mater, as long as there are no +conflicts. diff --git a/metaforce-gui/quazip/COPYING b/metaforce-gui/quazip/COPYING new file mode 100644 index 000000000..a11715ec0 --- /dev/null +++ b/metaforce-gui/quazip/COPYING @@ -0,0 +1,491 @@ +This file contains information about licensing information for the +QuaZip library. It is the definitive source of such information, and +takes priority over any copyright notices that might be found in the +source code. All of those copyright notices are there just to reference +this file, which they all should do, except the notices in the original +ZIP/UNZIP package (MiniZip), which is included in the QuaZip library in +a modified state, as its license permits. + +If some source file contains a copyright notice that neither marks that +file as clearly belonging to the MiniZip project nor references this +file, then it's a bug and should be reported to +https://github.com/stachenov/quazip/issues + +The QuaZip library is licensed under the GNU Lesser General Public +License V2.1 plus a static linking exception. + +The original ZIP/UNZIP package (MiniZip) is copyrighted by Gilles +Vollant and contributors, see quazip/(un)zip.h files for details. +Basically it's the zlib license. + +STATIC LINKING EXCEPTION + +The copyright holders give you permission to link this library with +independent modules to produce an executable, regardless of the license +terms of these independent modules, and to copy and distribute the +resulting executable under terms of your choice, provided that you also +meet, for each linked independent module, the terms and conditions of +the license of that module. An independent module is a module which is +not derived from or based on this library. If you modify this library, +you must extend this exception to your version of the library. + +The text of the GNU Lesser General Public License V2.1 follows. + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/metaforce-gui/quazip/Doxyfile b/metaforce-gui/quazip/Doxyfile new file mode 100644 index 000000000..42b53d367 --- /dev/null +++ b/metaforce-gui/quazip/Doxyfile @@ -0,0 +1,2553 @@ +# Doxyfile 1.8.19 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the configuration +# file that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# https://www.gnu.org/software/libiconv/ for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = QuaZip + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = quazip-1-1-x + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = doc + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all generated output in the proper direction. +# Possible values are: None, LTR, RTL and Context. +# The default value is: None. + +OUTPUT_TEXT_DIRECTION = None + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line +# such as +# /*************** +# as being the beginning of a Javadoc-style comment "banner". If set to NO, the +# Javadoc-style will behave just like regular comments and it will not be +# interpreted by doxygen. +# The default value is: NO. + +JAVADOC_BANNER = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines (in the resulting output). You can put ^^ in the value part of an +# alias to insert a newline as if a physical newline was in the original file. +# When you need a literal { or } or , in the value part of an alias you have to +# escape them by means of a backslash (\), this can lead to conflicts with the +# commands \{ and \} for these it is advised to use the version @{ and @} or use +# a double escape (\\{ and \\}) + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice +# sources only. Doxygen will then generate output that is more tailored for that +# language. For instance, namespaces will be presented as modules, types will be +# separated into more groups, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_SLICE = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, +# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice, VHDL, +# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: +# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser +# tries to guess whether the code is fixed or free formatted code, this is the +# default for Fortran type files). For instance to make doxygen treat .inc files +# as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See https://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 5. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 5 + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +# The NUM_PROC_THREADS specifies the number threads doxygen is allowed to use +# during processing. When set to 0 doxygen will based this on the number of +# cores available in the system. You can set it explicitly to a value larger +# than 0 to get more control over the balance between CPU load and processing +# speed. At this moment only the input processing can be done using multiple +# threads. Since this is still an experimental feature the default is set to 1, +# which efficively disables parallel processing. Please report any issues you +# encounter. Generating dot graphs in parallel is controlled by the +# DOT_NUM_THREADS setting. +# Minimum value: 0, maximum value: 32, default value: 1. + +NUM_PROC_THREADS = 1 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual +# methods of a class will be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIV_VIRTUAL = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# declarations. If set to NO, these declarations will be included in the +# documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES, upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# (including Cygwin) and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = NO + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. If +# EXTRACT_ALL is set to YES then this flag will automatically be disabled. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. +# The default value is: NO. + +WARN_AS_ERROR = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = quazip + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: https://www.gnu.org/software/libiconv/) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, +# *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment), +# *.doc (to be provided as doxygen C comment), *.txt (to be provided as doxygen +# C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, +# *.vhdl, *.ucf, *.qsf and *.ice. + +FILE_PATTERNS = *.cpp \ + *.h \ + *.dox + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = quazip/unzip.h \ + quazip/zip.h \ + quazip/ioapi.h \ + quazip/minizip_crypt.h \ + qztest/ + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = */.moc/* \ + */release/* \ + */debug/* \ + */moc_*.cpp + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# entity all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see https://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the +# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the +# cost of reduced performance. This can be particularly helpful with template +# rich C++ code for which doxygen's built-in parser lacks the necessary type +# information. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse_libclang=ON option for CMake. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + +# If clang assisted parsing is enabled you can provide the clang parser with the +# path to the directory containing a file called compile_commands.json. This +# file is the compilation database (see: +# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the +# options used when the source files were built. This is equivalent to +# specifying the "-p" option to a clang tool, such as clang-check. These options +# will then be passed to the parser. Any options specified with CLANG_OPTIONS +# will be added as well. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse_libclang=ON option for CMake. + +CLANG_DATABASE_PATH = + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = NO + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# https://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = YES + +# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML +# documentation will contain a main index with vertical navigation menus that +# are dynamically created via JavaScript. If disabled, the navigation index will +# consists of multiple levels of tabs that are statically embedded in every HTML +# page. Disable this option to support browsers that do not have JavaScript, +# like the Qt help browser. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_MENUS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: https://developer.apple.com/xcode/), introduced with OSX +# 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy +# genXcode/_index.html for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the main .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg +# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see +# https://inkscape.org) to generate formulas as SVG images instead of PNGs for +# the HTML output. These images will generally look nicer at scaled resolutions. +# Possible values are: png (the default) and svg (looks nicer but requires the +# pdf2svg or inkscape tool). +# The default value is: png. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FORMULA_FORMAT = png + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANSPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands +# to create new LaTeX commands to be used in formulas as building blocks. See +# the section "Including formulas" for details. + +FORMULA_MACROFILE = + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# https://www.mathjax.org) which uses client side JavaScript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from https://www.mathjax.org before deployment. +# The default value is: https://cdn.jsdelivr.net/npm/mathjax@2. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://www.mathjax.org/mathjax + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /