├── .clang-format ├── .gitattributes ├── .github └── workflows │ ├── cmake.yml │ └── codeql-analysis.yml ├── .gitignore ├── CHANGELOG ├── CMakeLists.txt ├── LICENSE ├── README.md ├── conformance_data ├── ds0_hm_06_b11.j2k ├── ds0_hm_06_b18.j2k ├── ds0_hm_15_b8.j2k ├── ds0_ht_01_b11.j2k ├── ds0_ht_02_b11.j2k ├── ds0_ht_02_b12.j2k ├── ds0_ht_03_b11.j2k ├── ds0_ht_03_b14.j2k ├── ds0_ht_04_b11.j2k ├── ds0_ht_04_b12.j2k ├── ds0_ht_05_b11.j2k ├── ds0_ht_05_b12.j2k ├── ds0_ht_06_b11.j2k ├── ds0_ht_06_b15.j2k ├── ds0_ht_06_b18.j2k ├── ds0_ht_07_b11.j2k ├── ds0_ht_07_b15.j2k ├── ds0_ht_07_b16.j2k ├── ds0_ht_08_b11.j2k ├── ds0_ht_08_b15.j2k ├── ds0_ht_08_b16.j2k ├── ds0_ht_09_b11.j2k ├── ds0_ht_10_b11.j2k ├── ds0_ht_11_b10.j2k ├── ds0_ht_12_b11.j2k ├── ds0_ht_13_b11.j2k ├── ds0_ht_14_b11.j2k ├── ds0_ht_15_b11.j2k ├── ds0_ht_15_b14.j2k ├── ds0_ht_16_b11.j2k ├── ds1_ht_01_b11.j2k ├── ds1_ht_01_b12.j2k ├── ds1_ht_02_b11.j2k ├── ds1_ht_02_b12.j2k ├── ds1_ht_03_b11.j2k ├── ds1_ht_03_b12.j2k ├── ds1_ht_04_b9.j2k ├── ds1_ht_05_b11.j2k ├── ds1_ht_06_b11.j2k ├── ds1_ht_07_b11.j2k ├── hifi_ht1_02.j2k ├── hifi_p1_02.j2k ├── p0_01.j2k ├── p0_02.j2k ├── p0_03.j2k ├── p0_04.j2k ├── p0_05.j2k ├── p0_06.j2k ├── p0_07.j2k ├── p0_08.j2k ├── p0_09.j2k ├── p0_10.j2k ├── p0_11.j2k ├── p0_12.j2k ├── p0_13.j2k ├── p0_14.j2k ├── p0_15.j2k ├── p0_16.j2k ├── p1_01.j2k ├── p1_02.j2k ├── p1_03.j2k ├── p1_04.j2k ├── p1_05.j2k ├── p1_06.j2k ├── p1_07.j2k └── references │ ├── c1p0_01-0.pgx │ ├── c1p0_02-0.pgx │ ├── c1p0_03-0.pgx │ ├── c1p0_04-0.pgx │ ├── c1p0_04-1.pgx │ ├── c1p0_04-2.pgx │ ├── c1p0_05-0.pgx │ ├── c1p0_05-1.pgx │ ├── c1p0_05-2.pgx │ ├── c1p0_05-3.pgx │ ├── c1p0_06-0.pgx │ ├── c1p0_06-1.pgx │ ├── c1p0_06-2.pgx │ ├── c1p0_06-3.pgx │ ├── c1p0_07-0.pgx │ ├── c1p0_07-1.pgx │ ├── c1p0_07-2.pgx │ ├── c1p0_08-0.pgx │ ├── c1p0_08-1.pgx │ ├── c1p0_08-2.pgx │ ├── c1p0_09-0.pgx │ ├── c1p0_10-0.pgx │ ├── c1p0_10-1.pgx │ ├── c1p0_10-2.pgx │ ├── c1p0_11-0.pgx │ ├── c1p0_12-0.pgx │ ├── c1p0_13-0.pgx │ ├── c1p0_13-1.pgx │ ├── c1p0_13-2.pgx │ ├── c1p0_13-3.pgx │ ├── c1p0_14-0.pgx │ ├── c1p0_14-1.pgx │ ├── c1p0_14-2.pgx │ ├── c1p0_15-0.pgx │ ├── c1p0_16-0.pgx │ ├── c1p1_01-0.pgx │ ├── c1p1_02-0.pgx │ ├── c1p1_02-1.pgx │ ├── c1p1_02-2.pgx │ ├── c1p1_03-0.pgx │ ├── c1p1_03-1.pgx │ ├── c1p1_03-2.pgx │ ├── c1p1_03-3.pgx │ ├── c1p1_04-0.pgx │ ├── c1p1_05-0.pgx │ ├── c1p1_05-1.pgx │ ├── c1p1_05-2.pgx │ ├── c1p1_06-0.pgx │ ├── c1p1_06-1.pgx │ ├── c1p1_06-2.pgx │ ├── c1p1_07-0.pgx │ ├── c1p1_07-1.pgx │ ├── hifi-0.pgx │ ├── hifi-1.pgx │ ├── hifi-2.pgx │ ├── kodim23.ppm │ └── kodim23odd.ppm ├── source ├── apps │ ├── decoder │ │ ├── CMakeLists.txt │ │ ├── dec_utils.hpp │ │ └── main_dec.cpp │ ├── encoder │ │ ├── CMakeLists.txt │ │ ├── enc_utils.hpp │ │ └── main_enc.cpp │ └── imgcmp │ │ ├── CMakeLists.txt │ │ ├── image_class.hpp │ │ └── main.cpp ├── core │ ├── codestream │ │ ├── CMakeLists.txt │ │ ├── codestream.hpp │ │ ├── codestream_destination.cpp │ │ ├── codestream_source.cpp │ │ ├── j2kmarkers.cpp │ │ ├── j2kmarkers.hpp │ │ └── marker_def.hpp │ ├── coding │ │ ├── CMakeLists.txt │ │ ├── EBCOTtables.hpp │ │ ├── block_decoding.cpp │ │ ├── block_decoding.hpp │ │ ├── coding_local.hpp │ │ ├── coding_units.cpp │ │ ├── coding_units.hpp │ │ ├── dec_CxtVLC_tables.hpp │ │ ├── enc_CxtVLC_tables.hpp │ │ ├── ht_block_decoding.cpp │ │ ├── ht_block_decoding.hpp │ │ ├── ht_block_decoding_avx2.cpp │ │ ├── ht_block_decoding_neon.cpp │ │ ├── ht_block_encoding.cpp │ │ ├── ht_block_encoding.hpp │ │ ├── ht_block_encoding_avx2.cpp │ │ ├── ht_block_encoding_avx2.hpp │ │ ├── ht_block_encoding_neon.cpp │ │ ├── ht_block_encoding_neon.hpp │ │ ├── mq_decoder.cpp │ │ └── mq_decoder.hpp │ ├── common │ │ ├── ThreadPool.hpp │ │ ├── open_htj2k_typedef.hpp │ │ ├── open_htj2k_version.hpp │ │ └── utils.hpp │ ├── interface │ │ ├── CMakeLists.txt │ │ ├── decoder.cpp │ │ ├── decoder.hpp │ │ ├── encoder.cpp │ │ └── encoder.hpp │ ├── jph │ │ ├── CMakeLists.txt │ │ ├── jph.cpp │ │ └── jph.hpp │ └── transform │ │ ├── CMakeLists.txt │ │ ├── color.cpp │ │ ├── color.hpp │ │ ├── color_avx2.cpp │ │ ├── color_neon.cpp │ │ ├── dwt.hpp │ │ ├── fdwt.cpp │ │ ├── fdwt_avx2.cpp │ │ ├── fdwt_neon.cpp │ │ ├── idwt.cpp │ │ ├── idwt_avx2.cpp │ │ └── idwt_neon.cpp ├── pkg-config.pc.cmake └── thirdparty │ ├── .gitignore │ └── highway │ ├── BUILD │ ├── CMakeLists.txt │ ├── CMakeLists.txt.in │ ├── CONTRIBUTING │ ├── LICENSE │ ├── README.md │ ├── WORKSPACE │ ├── debian │ ├── changelog │ ├── compat │ ├── control │ ├── copyright │ ├── rules │ └── source │ │ └── format │ ├── g3doc │ ├── design_philosophy.md │ ├── highway_intro.pdf │ ├── instruction_matrix.pdf │ ├── quick_reference.md │ └── release_testing_process.md │ ├── hwy │ ├── aligned_allocator.cc │ ├── aligned_allocator.h │ ├── aligned_allocator_test.cc │ ├── base.h │ ├── base_test.cc │ ├── cache_control.h │ ├── detect_compiler_arch.h │ ├── detect_targets.h │ ├── examples │ │ ├── benchmark.cc │ │ ├── skeleton-inl.h │ │ ├── skeleton.cc │ │ ├── skeleton.h │ │ └── skeleton_test.cc │ ├── foreach_target.h │ ├── highway.h │ ├── highway_test.cc │ ├── nanobenchmark.cc │ ├── nanobenchmark.h │ ├── nanobenchmark_test.cc │ ├── ops │ │ ├── arm_neon-inl.h │ │ ├── arm_sve-inl.h │ │ ├── generic_ops-inl.h │ │ ├── rvv-inl.h │ │ ├── scalar-inl.h │ │ ├── set_macros-inl.h │ │ ├── shared-inl.h │ │ ├── wasm_128-inl.h │ │ ├── x86_128-inl.h │ │ ├── x86_256-inl.h │ │ └── x86_512-inl.h │ ├── targets.cc │ ├── targets.h │ └── targets_test.cc │ ├── libhwy-contrib.pc.in │ ├── libhwy-test.pc.in │ ├── libhwy.pc.in │ ├── run_tests.bat │ └── run_tests.sh ├── subprojects ├── CMakeLists.txt ├── index.html └── src │ └── wrapper.cpp └── tests ├── decoder_conformance.cmake ├── encoder_test.cmake ├── ht_HF.cmake ├── ht_profile0.cmake ├── ht_profile1.cmake ├── part1_HF.cmake ├── part1_profile0.cmake └── part1_profile1.cmake /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | UseTab: Never 3 | IndentWidth: 2 4 | AccessModifierOffset: -1 5 | AlignConsecutiveAssignments: Consecutive 6 | AlignTrailingComments: true 7 | ColumnLimit: 108 8 | SortIncludes: Never 9 | BreakBeforeBinaryOperators: NonAssignment 10 | IndentPPDirectives: BeforeHash -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.c text 7 | *.h text 8 | *.cpp text 9 | *.hpp text 10 | 11 | # Declare files that will always have CRLF line endings on checkout. 12 | *.sln text eol=crlf 13 | 14 | # Denote all files that are truly binary and should not be modified. 15 | *.pgx binary 16 | *.j2k binary 17 | *.ppm binary 18 | -------------------------------------------------------------------------------- /.github/workflows/cmake.yml: -------------------------------------------------------------------------------- 1 | # This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. 2 | # See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml 3 | name: build and test 4 | 5 | on: 6 | push: 7 | branches: [ main ] 8 | pull_request: 9 | branches: [ main ] 10 | 11 | jobs: 12 | build: 13 | runs-on: ${{ matrix.os }} 14 | 15 | strategy: 16 | # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. 17 | fail-fast: false 18 | 19 | # Set up a matrix to run the following 3 configurations: 20 | # 1. 21 | # 2. 22 | # 3. 23 | # 4. 24 | # 25 | # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. 26 | matrix: 27 | os: [ubuntu-latest, windows-latest, macos-latest] 28 | # os: [ubuntu-latest, macos-latest] 29 | build_type: [Release] 30 | c_compiler: [gcc, clang, cl] 31 | include: 32 | - os: windows-latest 33 | c_compiler: cl 34 | cpp_compiler: cl 35 | - os: ubuntu-latest 36 | c_compiler: gcc 37 | cpp_compiler: g++ 38 | - os: ubuntu-latest 39 | c_compiler: clang 40 | cpp_compiler: clang++ 41 | - os: macos-latest 42 | c_compiler: clang 43 | cpp_compiler: clang++ 44 | exclude: 45 | - os: windows-latest 46 | c_compiler: gcc 47 | - os: windows-latest 48 | c_compiler: clang 49 | - os: ubuntu-latest 50 | c_compiler: cl 51 | - os: macos-latest 52 | c_compiler: gcc 53 | - os: macos-latest 54 | c_compiler: cl 55 | 56 | steps: 57 | - uses: actions/checkout@v4 58 | 59 | - name: Set reusable strings 60 | # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. 61 | id: strings 62 | shell: bash 63 | run: | 64 | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" 65 | 66 | - name: Configure CMake on Windows 67 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 68 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 69 | if: runner.os == 'Windows' 70 | run: > 71 | cmake -B ${{ steps.strings.outputs.build-output-dir }} 72 | -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} 73 | -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} 74 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} 75 | -S ${{ github.workspace }} 76 | -A "x64" 77 | 78 | - name: Configure CMake on Linux or macOS 79 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 80 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 81 | if: runner.os != 'Windows' 82 | run: > 83 | cmake -B ${{ steps.strings.outputs.build-output-dir }} 84 | -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} 85 | -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} 86 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} 87 | -S ${{ github.workspace }} 88 | 89 | - name: Build 90 | # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). 91 | run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} 92 | 93 | - name: Test 94 | working-directory: ${{ steps.strings.outputs.build-output-dir }} 95 | # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). 96 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 97 | run: ctest --build-config ${{ matrix.build_type }} -VV 98 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | #pull_request: 18 | # # The branches below must be a subset of the branches above 19 | # branches: [ main ] 20 | schedule: 21 | - cron: '29 13 * * 6' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'cpp' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v2 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | # - name: Autobuild 57 | # uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | - run: | 67 | cmake -B /home/runner/work/OpenHTJ2K/OpenHTJ2K/build -DCMAKE_BUILD_TYPE=Release 68 | cmake --build /home/runner/work/OpenHTJ2K/OpenHTJ2K/build --config Release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v2 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # VSCode 35 | .vscode/ 36 | 37 | # CLion 38 | .idea/ 39 | 40 | # Build directory 41 | build/ 42 | build*/ 43 | 44 | # Bin directory 45 | bin/ 46 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | # [0.2.8] - 2024-11-12 2 | 3 | * Fix incorrect packet parsing for RPCL, PCRL, CPRL 4 | * Introduce stride access into DWT 5 | * Change cmake configuration for MinGW environments 6 | 7 | # [0.2.7] - 2024-06-13 8 | 9 | * Refactor non-SIMD HT cleanup decoding 10 | 11 | # [0.2.6] - 2024-06-12 12 | 13 | * Fix unnecessary assignment of `pass_length` in packet header parsing 14 | * Remove CR (=0xd) from the delimiter in `imgcmp` 15 | 16 | # [0.2.5] - 2024-01-19 17 | 18 | * Fix memory leak in decoder with '-reduce' parameter greater than actual DWT levels 19 | * Fix buffer overrun with image width which is not multiple of vector length in IDWT and block-decoding for ARM NEON 20 | * Improve UI for WASM demo 21 | * Enable WASM SIMD (using NEON) 22 | * Fix wrong line break in encoder usage (#162) 23 | 24 | # [0.2.4] - 2023-12-22 25 | 26 | * small fix for wasm wrapper 27 | 28 | # [0.2.3] - 2023-12-22 29 | 30 | * Experimental support of emscripten 31 | * Fix compilation error on aarch64 with gcc 32 | * Small editorial changes 33 | 34 | # [0.2.2] - 2023-11-27 35 | 36 | * Fix compilation errors in aarch64 and gcc 9 or earlier 37 | 38 | # [0.2.1] - 2023-11-13 39 | 40 | * Add installation part to CMakeLists.txt 41 | * Allow space between comma separated input file names 42 | 43 | # [0.2.0] - 2023-11-02 44 | 45 | * Fix wrong treatment of bit-depth (Ssiz) for images having signed pixel values in the creation of the QCD marker at encoding. 46 | * Fix wrong shift-up for signed input 47 | * Fix wrong treatment of BPC parameter value in Image Header Box 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019 - 2021, Osamu Watanabe 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CMake](https://github.com/osamu620/OpenHTJ2K/actions/workflows/cmake.yml/badge.svg?branch=main)](https://github.com/osamu620/OpenHTJ2K/actions/workflows/cmake.yml) 2 | [![CodeQL](https://github.com/osamu620/OpenHTJ2K/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/osamu620/OpenHTJ2K/actions/workflows/codeql-analysis.yml) 3 | [![Packaging status](https://repology.org/badge/tiny-repos/openhtj2k.svg)](https://repology.org/project/openhtj2k/versions) 4 | # OpenHTJ2K 5 | OpenHTJ2K is an open source implementation of ITU-T Rec.814 | ISO/IEC 15444-15 (a.k.a. JPEG 2000 Part 15, High-Throughput JPEG 2000; HTJ2K) 6 | 7 | # What OpenHTJ2K provides 8 | OpenHTJ2K provides a shared liberary and sample applications having the following functionalities: 9 | - Decoding of ITU-T Rec.800 | ISO/IEC 15444-1 (JPEG 2000 Part 1) or ITU-T Rec.814 | ISO/IEC 15444-15 (JPEG 2000 Part 15.) compliant codestreams 10 | - fully compliant with conformance testing defined in ITU-T Rec.803 | ISO 15444-4. 11 | - Encoding an image into a codestream/JPH file which is compliant with HTJ2K 12 | - currently supports only HTJ2K. The optional markers like COC, POC, etc. are not implemented. 13 | - encoding of HT SigProp and MagRef passes are not implemented. 14 | - up to **12 bit** per component sample is currently supported. 15 | - **Quality control for lossy compression with ***Qfactor*** feature** 16 | 17 | # Requirements 18 | cmake (version 3.14 or later) and C++11 compliant compiler. 19 | 20 | # Building 21 | Type the following command. `./` is a root of cloned repository and `${BUILD_DIR}` is a build directory (for example, `../build` or `./build` and so on) 22 | 23 | - You can also specify `-DCMAKE_BUILD_TYPE=Debug` or `-DCMAKE_BUILD_TYPE=RelWithDebInfo` to build with debug information. 24 | - You can also specify `-G "Xcode"` to create a project for Xcode. 25 | - You can also specify `-G "Visual Studio 17 2022"` to create a project for Visual Studio 2022. For the older versions, 26 | see https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators 27 | 28 | ``` 29 | cd ./ 30 | cmake -G "Unix Makefiles" -B ${BUILD_DIR} -DCMAKE_BUILD_TYPE=Release 31 | cd ${BUILD_DIR} 32 | make 33 | ``` 34 | 35 | Then the executables should be found in `${BUILD_DIR}/bin` directory. 36 | 37 | # Usage 38 | ## Encoder 39 | Only Part 15 compliant encoding is supported. Both .j2c (codestream) and .jph (file format) are available. 40 | ```bash 41 | ./open_htj2k_enc -i inputimage(in PNM/PGX/(TIFF, libtiff required) format) -o output [options...] 42 | ``` 43 | The encoder can take comma-separated multiple files. For example, components in YCbCr color space can be encoded by 44 | ``` 45 | ./open_htj2k_enc -i inputY.pgx,inputCb.pgx,inputCr.pgx -o output 46 | ``` 47 | 48 | ### options 49 | - `Stiles=Size` 50 | - Size of tile "{height, width}", Default is equal to the image size 51 | - `Sorigin=Size` 52 | - origin of the input image in the reference grid, Default is {0,0} 53 | - `Stile_origin=Size` 54 | - origin of tiles in the reference grid, Default is {0,0} 55 | - `Clevels=Int` 56 | - Valid range for number of DWT levels is from 0 to 32 (Default is **5**) 57 | - `Creversible=yes or no` 58 | - `yes` for lossless mode, `no` for lossy mode, Default is **no** 59 | - `Cblk=Size` 60 | - Code-block size, Default is **64x64** 61 | - `Cprecincts=Size` 62 | - Precinct size 63 | - `Cycc=yes or no` 64 | - `yes` to use RGB->YCbCr, Default is **yes** 65 | - `Corder` 66 | - Progression order: LRCP, RLCP, RPCL, PCRL, CPRL, Default is **LRCP** 67 | - `Cuse_sop=yes or no` 68 | - Default is **no** 69 | - `Cuse_eph=yes or no` 70 | - Default is **no** 71 | - `Qstep=Float` 72 | - 0.0 < base step size <= 2.0 73 | - `Qguard=Int` 74 | - 0 to 7 for the number of guard bits, Default is **1** 75 | - `Qderived=yes or no` 76 | - `yes` switches the quantyzation style to **derived** (Default is `no`) 77 | - `Qfactor=Int` 78 | - 0 to 100 for the quality of the lossy compressed image 79 | - for YCbCr inputs, valid chroma subsampling formats are 4:4:4, 4:2:0, and 4:2:2 80 | - `-jph_color_space` 81 | - Color space of input components: RGB, YCC 82 | - if inputs are represented in YCbCr, use YCC 83 | - `-num_threads Int` 84 | - number of threads to use in encode or decode 85 | - 0, which is the default, indicates usage of all threads 86 | 87 | ## Decoder 88 | The both Part 1 and Part 15 compliant decoding are supported. 89 | ```bash 90 | ./open_htj2k_dec -i codestream -o outputimage [-reduce n: number of DWT level reduction] 91 | ``` 92 | To see a help, use `-h` option. 93 | 94 | ## Supported file types 95 | ### Encoder 96 | - input image formats: .pgm, .ppm, .pgx, .tif (libtiff required) 97 | - output codestreams: .jhc (Part 15 codestream, .j2k and .j2c can be used as aliases), .jph (Part 15 file format) 98 | - Note: Specifying .jph as the output triggers a JPH file creation, otherwise just a codestream will be generated. 99 | ### Decoder 100 | - input codestreams : .j2k, .j2c, .jhc 101 | - output image formats: .raw, .ppm, .pgm, .pgx 102 | -------------------------------------------------------------------------------- /conformance_data/ds0_hm_06_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_hm_06_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_hm_06_b18.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_hm_06_b18.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_hm_15_b8.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_hm_15_b8.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_01_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_01_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_02_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_02_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_02_b12.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_02_b12.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_03_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_03_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_03_b14.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_03_b14.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_04_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_04_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_04_b12.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_04_b12.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_05_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_05_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_05_b12.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_05_b12.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_06_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_06_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_06_b15.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_06_b15.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_06_b18.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_06_b18.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_07_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_07_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_07_b15.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_07_b15.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_07_b16.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_07_b16.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_08_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_08_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_08_b15.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_08_b15.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_08_b16.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_08_b16.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_09_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_09_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_10_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_10_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_11_b10.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_11_b10.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_12_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_12_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_13_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_13_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_14_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_14_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_15_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_15_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_15_b14.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_15_b14.j2k -------------------------------------------------------------------------------- /conformance_data/ds0_ht_16_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds0_ht_16_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_01_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_01_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_01_b12.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_01_b12.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_02_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_02_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_02_b12.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_02_b12.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_03_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_03_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_03_b12.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_03_b12.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_04_b9.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_04_b9.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_05_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_05_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_06_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_06_b11.j2k -------------------------------------------------------------------------------- /conformance_data/ds1_ht_07_b11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/ds1_ht_07_b11.j2k -------------------------------------------------------------------------------- /conformance_data/hifi_ht1_02.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/hifi_ht1_02.j2k -------------------------------------------------------------------------------- /conformance_data/hifi_p1_02.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/hifi_p1_02.j2k -------------------------------------------------------------------------------- /conformance_data/p0_01.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_01.j2k -------------------------------------------------------------------------------- /conformance_data/p0_02.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_02.j2k -------------------------------------------------------------------------------- /conformance_data/p0_03.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_03.j2k -------------------------------------------------------------------------------- /conformance_data/p0_04.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_04.j2k -------------------------------------------------------------------------------- /conformance_data/p0_05.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_05.j2k -------------------------------------------------------------------------------- /conformance_data/p0_06.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_06.j2k -------------------------------------------------------------------------------- /conformance_data/p0_07.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_07.j2k -------------------------------------------------------------------------------- /conformance_data/p0_08.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_08.j2k -------------------------------------------------------------------------------- /conformance_data/p0_09.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_09.j2k -------------------------------------------------------------------------------- /conformance_data/p0_10.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_10.j2k -------------------------------------------------------------------------------- /conformance_data/p0_11.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_11.j2k -------------------------------------------------------------------------------- /conformance_data/p0_12.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_12.j2k -------------------------------------------------------------------------------- /conformance_data/p0_13.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_13.j2k -------------------------------------------------------------------------------- /conformance_data/p0_14.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_14.j2k -------------------------------------------------------------------------------- /conformance_data/p0_15.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_15.j2k -------------------------------------------------------------------------------- /conformance_data/p0_16.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p0_16.j2k -------------------------------------------------------------------------------- /conformance_data/p1_01.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p1_01.j2k -------------------------------------------------------------------------------- /conformance_data/p1_02.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p1_02.j2k -------------------------------------------------------------------------------- /conformance_data/p1_03.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p1_03.j2k -------------------------------------------------------------------------------- /conformance_data/p1_04.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p1_04.j2k -------------------------------------------------------------------------------- /conformance_data/p1_05.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p1_05.j2k -------------------------------------------------------------------------------- /conformance_data/p1_06.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p1_06.j2k -------------------------------------------------------------------------------- /conformance_data/p1_07.j2k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/p1_07.j2k -------------------------------------------------------------------------------- /conformance_data/references/c1p0_01-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_01-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_02-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_02-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_03-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_03-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_04-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_04-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_04-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_04-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_04-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_04-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_05-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_05-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_05-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_05-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_05-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_05-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_05-3.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_05-3.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_06-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_06-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_06-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_06-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_06-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_06-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_06-3.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_06-3.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_07-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_07-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_07-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_07-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_07-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_07-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_08-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_08-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_08-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_08-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_08-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_08-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_09-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_09-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_10-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_10-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_10-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_10-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_10-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_10-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_11-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_11-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_12-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_12-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_13-0.pgx: -------------------------------------------------------------------------------- 1 | PG ML +8 1 1 2 | -------------------------------------------------------------------------------- /conformance_data/references/c1p0_13-1.pgx: -------------------------------------------------------------------------------- 1 | PG ML +8 1 1 2 |  -------------------------------------------------------------------------------- /conformance_data/references/c1p0_13-2.pgx: -------------------------------------------------------------------------------- 1 | PG ML +8 1 1 2 |  -------------------------------------------------------------------------------- /conformance_data/references/c1p0_13-3.pgx: -------------------------------------------------------------------------------- 1 | PG ML +8 1 1 2 |  -------------------------------------------------------------------------------- /conformance_data/references/c1p0_14-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_14-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_14-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_14-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_14-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_14-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_15-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_15-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p0_16-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p0_16-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_01-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_01-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_02-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_02-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_02-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_02-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_02-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_02-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_03-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_03-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_03-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_03-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_03-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_03-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_03-3.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_03-3.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_04-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_04-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_05-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_05-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_05-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_05-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_05-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_05-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_06-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_06-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_06-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_06-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_06-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_06-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_07-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_07-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/c1p1_07-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/c1p1_07-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/hifi-0.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/hifi-0.pgx -------------------------------------------------------------------------------- /conformance_data/references/hifi-1.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/hifi-1.pgx -------------------------------------------------------------------------------- /conformance_data/references/hifi-2.pgx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/hifi-2.pgx -------------------------------------------------------------------------------- /conformance_data/references/kodim23.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/kodim23.ppm -------------------------------------------------------------------------------- /conformance_data/references/kodim23odd.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/conformance_data/references/kodim23odd.ppm -------------------------------------------------------------------------------- /source/apps/decoder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0076 NEW) 2 | target_sources(open_htj2k_dec 3 | PRIVATE 4 | main_dec.cpp 5 | ) -------------------------------------------------------------------------------- /source/apps/encoder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0076 NEW) 2 | target_sources(open_htj2k_enc 3 | PRIVATE 4 | main_enc.cpp 5 | ) 6 | -------------------------------------------------------------------------------- /source/apps/imgcmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0076 NEW) 2 | target_sources(imgcmp 3 | PRIVATE 4 | main.cpp 5 | ) -------------------------------------------------------------------------------- /source/apps/imgcmp/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "image_class.hpp" 30 | #include 31 | #include 32 | #include 33 | 34 | int main(int argc, char *argv[]) { 35 | if (argc != 3 && argc != 5) { 36 | printf("\nusage: imgcmp file1 file2 [PAE MSE]\n"); 37 | printf(" (only accepts pnm or pgx files)\n"); 38 | printf(" - PAE and MSE are threshold for conformance testing.\n\n"); 39 | return EXIT_FAILURE; 40 | } 41 | image img0, img1; 42 | img0.read_pnmpgx(argv[1]); 43 | img1.read_pnmpgx(argv[2]); 44 | uint_fast32_t w, h; 45 | if (((w = img0.get_width()) != img1.get_width()) || (h = img0.get_height()) != img1.get_height()) { 46 | printf("width and height shall be the same\n"); 47 | return EXIT_FAILURE; 48 | } 49 | int_fast32_t *sp0, *sp1; 50 | sp0 = img0.access_pixels(); 51 | sp1 = img1.access_pixels(); 52 | 53 | uint_fast64_t PAE = 0, tmp, sum = 0; 54 | int_fast64_t d; 55 | const uint_fast32_t length = w * h * img0.get_num_components(); 56 | for (uint_fast32_t i = 0; i < length; ++i) { 57 | d = (int_fast64_t)sp0[i] - (int_fast64_t)sp1[i]; 58 | tmp = (d < 0) ? static_cast(-d) : static_cast(d); 59 | PAE = (tmp > PAE) ? tmp : PAE; 60 | sum += static_cast(d * d); 61 | } 62 | auto mse = static_cast(sum) / static_cast(length); 63 | auto maxval = static_cast(img0.get_maxval()); 64 | auto psnr = 10 * log10((maxval * maxval) / mse); 65 | if (mse < DBL_EPSILON) { 66 | psnr = INFINITY; 67 | } 68 | 69 | printf("%4llu, %12.6f, %12.6f\n", PAE, mse, psnr); 70 | 71 | if (argc == 5) { 72 | uint_fast64_t thPAE = static_cast(std::stoi(argv[3])); 73 | double thMSE = std::stof(argv[4]); 74 | if (PAE > thPAE || mse > thMSE) { 75 | printf("conformance test failure.\n"); 76 | exit(EXIT_FAILURE); 77 | } 78 | } 79 | return EXIT_SUCCESS; 80 | } 81 | -------------------------------------------------------------------------------- /source/core/codestream/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0076 NEW) 2 | target_sources(open_htj2k 3 | PRIVATE 4 | j2kmarkers.cpp 5 | codestream_source.cpp 6 | codestream_destination.cpp 7 | ) -------------------------------------------------------------------------------- /source/core/codestream/codestream_destination.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include 30 | #include "codestream.hpp" 31 | 32 | // MARK: j2c_dst_memory - 33 | int32_t j2c_dst_memory::put_byte(uint8_t byte) { 34 | buf.push_back(byte); 35 | pos++; 36 | return EXIT_SUCCESS; 37 | } 38 | 39 | int32_t j2c_dst_memory::put_word(uint16_t word) { 40 | auto upper_byte = static_cast(word >> 8); 41 | auto lower_byte = static_cast(word & 0xFF); 42 | put_byte(upper_byte); 43 | put_byte(lower_byte); 44 | return EXIT_SUCCESS; 45 | } 46 | 47 | int32_t j2c_dst_memory::put_dword(uint32_t dword) { 48 | auto upper_word = static_cast(dword >> 16); 49 | auto lower_word = static_cast(dword & 0xFFFF); 50 | put_word(upper_word); 51 | put_word(lower_word); 52 | return EXIT_SUCCESS; 53 | } 54 | 55 | int32_t j2c_dst_memory::put_N_bytes(uint8_t *src, uint32_t length) { 56 | buf.resize(pos + length); 57 | memcpy(buf.data() + pos, src, length); 58 | pos += length; 59 | // for (unsigned long i = 0; i < length; i++) { 60 | // buf.push_back(src[i]); 61 | // } 62 | return EXIT_SUCCESS; 63 | } 64 | 65 | int32_t j2c_dst_memory::flush(std::ofstream &dst) { 66 | dst.write((char *)&buf[0], static_cast(buf.size() * sizeof(buf[0]))); 67 | return EXIT_SUCCESS; 68 | } 69 | 70 | int32_t j2c_dst_memory::flush(std::vector *obuf) { 71 | if (is_flushed) { 72 | return EXIT_FAILURE; 73 | } 74 | obuf->resize(buf.size()); 75 | memcpy(obuf->data(), buf.data(), buf.size()); 76 | // for (size_t i = 0; i < buf.size(); ++i) { 77 | // *(obuf->data() + i) = buf[i]; 78 | // } 79 | is_flushed = true; 80 | return EXIT_SUCCESS; 81 | } 82 | 83 | size_t j2c_dst_memory::get_length() const { return buf.size(); } 84 | 85 | [[maybe_unused]] [[deprecated]] void j2c_dst_memory::print_bytes() { 86 | for (uint32_t i = 0; i < pos; i++) { 87 | if (i % 32 == 0) { 88 | printf("\n"); 89 | } 90 | printf("%02x ", buf[i]); 91 | } 92 | printf("\n"); 93 | } 94 | -------------------------------------------------------------------------------- /source/core/codestream/codestream_source.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "codestream.hpp" 30 | 31 | // MARK: j2c_src_memory - 32 | void j2c_src_memory::alloc_memory(uint32_t length) { 33 | buf = static_cast(malloc(sizeof(uint8_t) * length)); // MAKE_UNIQUE(length); 34 | pos = 0; 35 | len = length; 36 | } 37 | 38 | uint8_t j2c_src_memory::get_byte() { 39 | if (pos > len - 1) { 40 | printf("Codestream is shorter than the expected length\n"); 41 | throw std::exception(); 42 | } 43 | uint8_t out = buf[pos]; 44 | pos++; 45 | return out; 46 | } 47 | 48 | int j2c_src_memory::get_N_byte(uint8_t *out, uint32_t length) { 49 | memmove(out, buf + pos, length); // memcpy is not valid because src and dst may overlap 50 | pos += length; 51 | // for (unsigned long i = 0; i < length; i++) { 52 | // out[i] = get_byte(); 53 | // } 54 | return EXIT_SUCCESS; 55 | } 56 | 57 | uint16_t j2c_src_memory::get_word() { 58 | if (pos > len - 2) { 59 | printf("Codestream is shorter than the expected length\n"); 60 | throw std::exception(); 61 | } 62 | auto out = static_cast((get_byte() << 8) + get_byte()); 63 | return out; 64 | } 65 | 66 | int j2c_src_memory::rewind_2bytes() { 67 | if (pos < 2) { 68 | printf("Cannot rewind 2 bytes because the current position is less than 2\n"); 69 | throw std::exception(); 70 | } 71 | pos -= 2; 72 | return EXIT_SUCCESS; 73 | } 74 | 75 | int j2c_src_memory::forward_Nbytes(uint32_t N) { 76 | if (pos + N <= len) { 77 | pos += N; 78 | return EXIT_SUCCESS; 79 | } else { 80 | throw std::exception(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /source/core/codestream/marker_def.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | 31 | // Delimiting markers and marker segments 32 | #define _SOC 0xFF4F 33 | #define _SOT 0xFF90 34 | #define _SOD 0xFF93 35 | #define _EOC 0xFFD9 36 | 37 | // Fixed information marker segments 38 | #define _SIZ 0xFF51 39 | #define _PRF 0xFF56 40 | #define _CAP 0xFF50 41 | 42 | // Functional marker segments 43 | #define _COD 0xFF52 44 | #define _COC 0xFF53 45 | #define _RGN 0xFF5E 46 | #define _QCD 0xFF5C 47 | #define _QCC 0xFF5D 48 | #define _POC 0xFF5F 49 | 50 | // Pointer marker segments 51 | #define _TLM 0xFF55 52 | #define _PLM 0xFF57 53 | #define _PLT 0xFF58 54 | #define _PPM 0xFF60 55 | #define _PPT 0xFF61 56 | 57 | // In-bit-stream markers and marker segments 58 | #define _SOP 0xFF91 59 | #define _EPH 0xFF92 60 | 61 | // Informational marker segments 62 | #define _CRG 0xFF63 63 | #define _COM 0xFF64 64 | 65 | // Part 15 marker segment 66 | #define _CPF 0xFF59 67 | -------------------------------------------------------------------------------- /source/core/coding/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0076 NEW) 2 | target_sources(open_htj2k 3 | PRIVATE 4 | coding_units.cpp 5 | ht_block_decoding.cpp 6 | ht_block_decoding_neon.cpp 7 | ht_block_decoding_avx2.cpp 8 | ht_block_encoding.cpp 9 | ht_block_encoding_neon.cpp 10 | ht_block_encoding_avx2.cpp 11 | block_decoding.cpp 12 | mq_decoder.cpp 13 | ) -------------------------------------------------------------------------------- /source/core/coding/EBCOTtables.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | 31 | constexpr uint8_t sig_LUT[4][256] = { 32 | { 33 | 0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 34 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 35 | 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 36 | 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, 37 | 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 38 | 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, 39 | 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, 40 | 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, 41 | }, // LL 42 | { 43 | 0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 44 | 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 45 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 46 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 47 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 48 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 49 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 50 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 51 | }, // HL 52 | { 53 | 0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 54 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 55 | 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 56 | 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, 57 | 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 58 | 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, 59 | 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, 60 | 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, 61 | }, // LH 62 | { 63 | 0, 3, 3, 6, 3, 6, 6, 8, 3, 6, 6, 8, 6, 8, 8, 8, 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 64 | 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 65 | 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 66 | 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 67 | 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 68 | 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 69 | 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 70 | 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 71 | } // HH 72 | }; 73 | 74 | constexpr uint8_t sign_LUT[2][256] = { 75 | {9, 10, 10, 10, 12, 13, 13, 13, 12, 13, 13, 13, 12, 13, 13, 13, 0, 10, 0, 9, 0, 11, 0, 12, 0, 11, 76 | 0, 12, 0, 11, 0, 12, 0, 0, 10, 9, 0, 0, 11, 12, 0, 0, 11, 12, 0, 0, 11, 12, 0, 0, 0, 10, 77 | 0, 0, 0, 11, 0, 0, 0, 11, 0, 0, 0, 11, 0, 0, 0, 0, 12, 11, 11, 11, 0, 0, 0, 0, 9, 10, 78 | 10, 10, 0, 0, 0, 0, 0, 13, 0, 12, 0, 0, 0, 0, 0, 10, 0, 9, 0, 0, 0, 0, 0, 0, 13, 12, 79 | 0, 0, 0, 0, 0, 0, 10, 9, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 80 | 0, 0, 0, 0, 0, 0, 12, 11, 11, 11, 9, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 12, 81 | 0, 10, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 12, 0, 0, 10, 9, 0, 0, 0, 0, 0, 0, 82 | 0, 0, 0, 0, 0, 13, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 11, 11, 11, 83 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84 | 0, 0, 0, 0, 13, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13}, 85 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 86 | 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 87 | 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 88 | 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 89 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 90 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 91 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 92 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, 93 | }; 94 | -------------------------------------------------------------------------------- /source/core/coding/block_decoding.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | 31 | #include 32 | #include "coding_units.hpp" 33 | 34 | void j2k_decode(j2k_codeblock *block, uint8_t ROIshift); 35 | bool htj2k_decode(j2k_codeblock *block, uint8_t ROIshift); 36 | -------------------------------------------------------------------------------- /source/core/coding/coding_local.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | 31 | #define SHIFT_SIGMA 0 // J2K and HTJ2K 32 | #define SHIFT_SIGMA_ 1 // J2K only 33 | #define SHIFT_PI_ 2 // J2K and HTJ2K; used as refinement indicator for HTJ2K 34 | #define SHIFT_REF 3U // HTJ2K only 35 | #define SHIFT_SCAN 4 // HTJ2K only 36 | #define SHIFT_P 3U // J2K only 37 | #define SHIFT_SMAG 5 // HTJ2K enc only; used for HT SigProp and MagRef 38 | #define SHIFT_SSGN 6 // HTJ2K enc only; used for HT SigProp 39 | 40 | //// getters 41 | // inline uint8_t Sigma(uint8_t &data) { return static_cast((data >> SHIFT_SIGMA) & 1); } 42 | // inline uint8_t Sigma_(uint8_t &data) { return static_cast((data >> SHIFT_SIGMA_) & 1); } 43 | // inline uint8_t Pi_(uint8_t &data) { return static_cast((data >> SHIFT_PI_) & 1); } 44 | // inline uint8_t Scan(uint8_t &data) { return static_cast((data >> SHIFT_SCAN) & 1); } 45 | // inline uint8_t Refinement_value(uint8_t &data) { return static_cast((data >> SHIFT_REF) & 1); } 46 | // inline uint8_t Refinement_indicator(uint8_t &data) { return static_cast((data >> SHIFT_PI_) & 47 | // 1); } inline uint8_t Decoded_bitplane_index(uint8_t &data) { return static_cast(data >> 48 | // SHIFT_P); } 49 | // 50 | //// setters 51 | // inline void sigma(uint8_t &data, const uint8_t &val) { data |= val; } 52 | // inline void sigma_(uint8_t &data, const uint8_t &val) { data |= static_cast(val << 53 | // SHIFT_SIGMA_); } inline void pi_(uint8_t &data, const uint8_t &val) { 54 | // if (val) { 55 | // data |= static_cast(1 << SHIFT_PI_); 56 | // } else { 57 | // data &= static_cast(~(1 << SHIFT_PI_)); 58 | // } 59 | // } 60 | // inline void scan(uint8_t &data, const uint8_t &val) { data |= static_cast(val << SHIFT_SCAN); } 61 | // inline void refinement_value(uint8_t &data, const uint8_t &val) { 62 | // data |= static_cast(val << SHIFT_REF); 63 | // } 64 | // inline void refinement_indicator(uint8_t &data, const uint8_t &val) { 65 | // if (val) { 66 | // data |= static_cast(1 << SHIFT_PI_); 67 | // } else { 68 | // data &= static_cast(~(1 << SHIFT_PI_)); 69 | // } 70 | // } 71 | // inline void decoded_bitplane_index(uint8_t &data, const uint8_t &val) { 72 | // data &= 0x07; 73 | // data |= static_cast(val << SHIFT_P); 74 | // } 75 | -------------------------------------------------------------------------------- /source/core/coding/ht_block_encoding.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #if !defined(OPENHTJ2K_ENABLE_ARM_NEON) && (!defined(__AVX2__) || !defined(OPENHTJ2K_TRY_AVX2)) 30 | #pragma once 31 | #include 32 | 33 | #define MAX_Lcup 16834 34 | #define MAX_Scup 4079 35 | #define MAX_Lref 2046 36 | 37 | /******************************************************************************** 38 | * state_MS_enc: state class for MagSgn encoding 39 | *******************************************************************************/ 40 | class state_MS_enc { 41 | private: 42 | uint8_t *const buf; // buffer for MagSgn 43 | #ifdef MSNAIVE 44 | uint8_t bits; 45 | uint8_t max; 46 | uint8_t tmp; 47 | #else 48 | uint64_t Creg; // temporal buffer to store up to 4 codewords 49 | uint32_t ctreg; // number of used bits in Creg 50 | uint8_t last; // last byte in the buffer 51 | int32_t pos; // current position in the buffer 52 | void emit_dword(); // internal function to emit 4 code words 53 | #endif 54 | 55 | public: 56 | explicit state_MS_enc(uint8_t *p) 57 | : buf(p), 58 | Creg(0), 59 | #ifdef MSNAIVE 60 | bits(0), 61 | max(8), 62 | tmp(0) 63 | #else 64 | ctreg(0), 65 | last(0), 66 | pos(0) 67 | #endif 68 | { 69 | } 70 | #ifdef MSNAIVE 71 | void emitMagSgnBits(uint32_t cwd, uint8_t m_n); 72 | #else 73 | void emitMagSgnBits(uint32_t cwd, uint8_t m_n, uint8_t emb_1); 74 | #endif 75 | int32_t termMS(); 76 | }; 77 | 78 | class state_MEL_enc; // forward declaration for friend function "termMELandVLC()" 79 | /******************************************************************************** 80 | * state_VLC_enc: state class for VLC encoding 81 | *******************************************************************************/ 82 | class state_VLC_enc { 83 | private: 84 | uint8_t *const buf; 85 | uint8_t tmp; 86 | uint8_t last; 87 | uint8_t bits; 88 | int32_t pos; 89 | 90 | friend int32_t termMELandVLC(state_VLC_enc &, state_MEL_enc &); 91 | 92 | public: 93 | explicit state_VLC_enc(uint8_t *p) : buf(p), tmp(0xF), last(0xFF), bits(4), pos(MAX_Scup - 2) { 94 | buf[pos + 1] = 0xFF; 95 | } 96 | void emitVLCBits(uint16_t cwd, uint8_t len); 97 | }; 98 | 99 | /******************************************************************************** 100 | * state_MEL_enc: state class for MEL encoding 101 | *******************************************************************************/ 102 | class state_MEL_enc { 103 | private: 104 | int8_t MEL_k; 105 | uint8_t MEL_run; 106 | const uint8_t MEL_E[13]; 107 | uint8_t MEL_t; 108 | int32_t pos; 109 | uint8_t rem; 110 | uint8_t tmp; 111 | uint8_t *const buf; 112 | void emitMELbit(uint8_t bit); 113 | 114 | friend int32_t termMELandVLC(state_VLC_enc &, state_MEL_enc &); 115 | 116 | public: 117 | explicit state_MEL_enc(uint8_t *p) 118 | : MEL_k(0), 119 | MEL_run(0), 120 | MEL_E{0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5}, 121 | MEL_t(static_cast(1 << MEL_E[MEL_k])), 122 | pos(0), 123 | rem(8), 124 | tmp(0), 125 | buf(p) {} 126 | void encodeMEL(uint8_t smel); 127 | void termMEL(); 128 | }; 129 | 130 | class MR_enc; // forward declaration for friend function termSPandMR() 131 | /******************************************************************************** 132 | * SP_enc: state class for HT SigProp encoding 133 | *******************************************************************************/ 134 | class SP_enc { 135 | private: 136 | uint32_t pos; 137 | uint8_t bits; 138 | uint8_t max; 139 | uint8_t tmp; 140 | uint8_t *const buf; 141 | friend int32_t termSPandMR(SP_enc &, MR_enc &); 142 | 143 | public: 144 | explicit SP_enc(uint8_t *Dref) : pos(0), bits(0), max(8), tmp(0), buf(Dref) {} 145 | void emitSPBit(uint8_t bit) { 146 | tmp |= static_cast(bit << bits); 147 | bits++; 148 | if (bits == max) { 149 | buf[pos] = tmp; 150 | pos++; 151 | max = (tmp == 0xFF) ? 7 : 8; 152 | tmp = 0; 153 | bits = 0; 154 | } 155 | } 156 | void termSP() { 157 | if (tmp != 0) { 158 | buf[pos] = tmp; 159 | pos++; 160 | max = (tmp == 0xFF) ? 7 : 8; 161 | } 162 | if (max == 7) { 163 | buf[pos] = 0x00; 164 | pos++; // this prevents the appearance of a terminal 0xFF 165 | } 166 | } 167 | [[nodiscard]] uint32_t get_length() const { return pos; } 168 | }; 169 | /******************************************************************************** 170 | * MR_enc: state class for HT MagRef encoding 171 | *******************************************************************************/ 172 | class MR_enc { 173 | private: 174 | uint32_t pos; 175 | uint8_t bits; 176 | uint8_t tmp; 177 | uint8_t last; 178 | uint8_t *const buf; 179 | friend int32_t termSPandMR(SP_enc &, MR_enc &); 180 | 181 | public: 182 | explicit MR_enc(uint8_t *Dref) : pos(MAX_Lref), bits(0), tmp(0), last(255), buf(Dref) {} 183 | void emitMRBit(uint8_t bit) { 184 | tmp |= static_cast(bit << bits); 185 | bits++; 186 | if ((last > 0x8F) && (tmp == 0x7F)) { 187 | bits++; // this must leave MR_bits equal to 8 188 | } 189 | if (bits == 8) { 190 | buf[pos] = tmp; 191 | pos--; // MR buf gorws reverse order 192 | last = tmp; 193 | tmp = 0; 194 | bits = 0; 195 | } 196 | } 197 | [[nodiscard]] uint32_t get_length() const { return MAX_Lref - pos; } 198 | }; 199 | #endif -------------------------------------------------------------------------------- /source/core/coding/mq_decoder.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | 31 | #include 32 | 33 | //#define MQNAIVE 34 | //#define CDP 35 | 36 | class mq_decoder { 37 | public: 38 | int32_t A; // was uint16_t 39 | int32_t t; // was uint8_t 40 | // Lower-bound interval 41 | int32_t C; // was uint32_t 42 | #if defined(CDP) 43 | int32_t D; // only for CDP implementation 44 | #endif 45 | // Temporary byte register 46 | int32_t T; // was uint8_t 47 | // position in byte-stream 48 | uint32_t L; 49 | // start position in byte-stream 50 | [[maybe_unused]] uint32_t L_start; 51 | // position of current codeword segment boundary 52 | uint32_t Lmax; 53 | // dynamic table for context 54 | uint16_t dynamic_table[2][19]; 55 | // Byte-stream buffer 56 | uint8_t const *byte_buffer; 57 | explicit mq_decoder(const uint8_t *buf); 58 | void fill_LSBs(); 59 | void init(uint32_t buf_pos, uint32_t segment_length, bool is_bypass); 60 | void init_states_for_all_contexts(); 61 | void renormalize_once(); 62 | uint8_t decode(uint8_t label); 63 | uint8_t get_raw_symbol(); 64 | void finish(); 65 | }; 66 | -------------------------------------------------------------------------------- /source/core/common/ThreadPool.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021, Aaron Boxer 2 | // Copyright (c) 2022, Osamu Watanabe 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, 12 | // this list of conditions and the following disclaimer in the documentation 13 | // and/or other materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifdef OPENHTJ2K_THREAD 31 | #pragma once 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | class ThreadPool { 45 | public: 46 | inline explicit ThreadPool(size_t thread_count) : stop(false), thread_count_(thread_count) { 47 | // if (thread_count == 1) return; 48 | 49 | threads = std::make_unique(thread_count_); 50 | 51 | for (size_t i = 0; i < thread_count_; ++i) { 52 | threads[i] = std::thread(&ThreadPool::worker, this); 53 | } 54 | size_t t = 0; 55 | for (size_t i = 0; i < thread_count_; ++i) { 56 | id_map[threads[i].get_id()] = t; 57 | t++; 58 | } 59 | } 60 | 61 | /** 62 | * @brief Destruct the thread pool. Waits for all tasks to complete, then destroys all threads. 63 | * 64 | */ 65 | inline ~ThreadPool() { 66 | { 67 | // Lock task queue to prevent adding a new task. 68 | std::lock_guard lock(tasks_mutex); 69 | stop = true; 70 | } 71 | 72 | // Wake up all threads so that they may exist 73 | condition.notify_all(); 74 | 75 | for (size_t i = 0; i < thread_count_; ++i) { 76 | threads[i].join(); 77 | } 78 | } 79 | 80 | int thread_number(std::thread::id id) { 81 | if (id_map.find(id) != id_map.end()) return (int)id_map[id]; 82 | return -1; 83 | } 84 | 85 | size_t num_threads() const { return thread_count_; } 86 | 87 | #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) 88 | /** 89 | * @brief Enqueue a function with zero or more arguments and a return value into the task queue, 90 | * and get a future for its eventual returned value. 91 | */ 92 | template , std::decay_t...>> 94 | #else 95 | template (std::decay_t...)>::type> 97 | #endif 98 | std::future enqueue(F&& func, Args&&... args) { 99 | auto task = std::make_shared>([func, args...]() { return func(args...); }); 100 | auto future = task->get_future(); 101 | 102 | push_task([task]() { (*task)(); }); 103 | return future; 104 | } 105 | 106 | static ThreadPool* get() { return instance(0); } 107 | 108 | static ThreadPool* instance(size_t numthreads) { 109 | std::unique_lock lock(singleton_mutex); 110 | if (!singleton) { 111 | singleton = new ThreadPool(numthreads ? numthreads : std::thread::hardware_concurrency()); 112 | } 113 | return singleton; 114 | } 115 | 116 | static void release() { 117 | std::unique_lock lock(singleton_mutex); 118 | delete singleton; 119 | singleton = nullptr; 120 | } 121 | 122 | private: 123 | template 124 | inline void push_task(const F& task) { 125 | { 126 | const std::lock_guard lock(tasks_mutex); 127 | 128 | if (stop) { 129 | throw std::runtime_error("Cannot schedule new task after shutdown."); 130 | } 131 | 132 | tasks.push(std::function(task)); 133 | } 134 | 135 | condition.notify_one(); 136 | } 137 | 138 | /** 139 | * @brief A worker function to be assigned to each thread in the pool. 140 | * 141 | * Continuously pops tasks out of the queue and executes them, as long as the atomic variable running is 142 | * set to true. 143 | */ 144 | void worker() { 145 | for (;;) { 146 | std::function task; 147 | 148 | { 149 | std::unique_lock lock(tasks_mutex); 150 | condition.wait(lock, [&] { return !tasks.empty() || stop; }); 151 | 152 | if (stop && tasks.empty()) { 153 | return; 154 | } 155 | 156 | task = std::move(tasks.front()); 157 | tasks.pop(); 158 | } 159 | 160 | task(); 161 | } 162 | } 163 | 164 | private: 165 | /** 166 | * @brief A mutex to synchronize access to the task queue by different threads. 167 | */ 168 | mutable std::mutex tasks_mutex{}; 169 | 170 | /** 171 | * @brief An atomic variable indicating to the workers to keep running. 172 | * 173 | * When set to false, the workers permanently stop working. 174 | */ 175 | std::atomic stop; 176 | 177 | std::map id_map; 178 | 179 | /** 180 | * @brief A queue of tasks to be executed by the threads. 181 | */ 182 | std::queue> tasks; 183 | 184 | /** 185 | * @brief The number of threads in the pool. 186 | */ 187 | size_t thread_count_; 188 | 189 | /** 190 | * @brief A smart pointer to manage the memory allocated for the threads. 191 | */ 192 | std::unique_ptr threads; 193 | 194 | /** 195 | * @brief A condition variable used to notify worker threads of state changes. 196 | */ 197 | std::condition_variable condition; 198 | 199 | /** 200 | * @brief A singleton for the instance. 201 | */ 202 | static ThreadPool* singleton; 203 | 204 | /** 205 | * @brief A mutex to synchronize access to the instance. 206 | */ 207 | static std::mutex singleton_mutex; 208 | }; 209 | 210 | #endif 211 | -------------------------------------------------------------------------------- /source/core/common/open_htj2k_typedef.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | 31 | #include 32 | 33 | // calc BIBO gain? if not, LUT is used 34 | //#define BIBO 35 | 36 | // number of fractional bits for fixed-point representation 37 | constexpr int32_t FRACBITS = 13; 38 | 39 | // for 12 bit or higher sample precision, sprec_t == int16_t will lead overflow at quantization 40 | typedef int16_t sprec_t; 41 | typedef uint16_t usprec_t; 42 | 43 | #define SIMD_LEN_F32 8 44 | #define SIMD_LEN_I32 8 45 | 46 | #define BAND_LL 0 47 | #define BAND_HL 1 48 | #define BAND_LH 2 49 | #define BAND_HH 3 50 | 51 | #define BYPASS 0x001 52 | #define RESET 0x002 53 | #define RESTART 0x004 54 | #define CAUSAL 0x008 55 | // TODO: implementation of MQ decoding with ERTERM 56 | #define ERTERM 0x010 57 | #define SEGMARK 0x020 58 | #define HT 0x040 59 | #define HT_MIXED 0x080 60 | #define HT_PHLD 0x100 61 | 62 | class element_siz { 63 | public: 64 | uint32_t x; 65 | uint32_t y; 66 | element_siz() : x(0), y(0) {} 67 | element_siz(uint32_t x0, uint32_t y0) { 68 | x = x0; 69 | y = y0; 70 | } 71 | }; -------------------------------------------------------------------------------- /source/core/common/open_htj2k_version.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2023, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #define OPENHTJ2K_VERSION_MAJOR 0 30 | #define OPENHTJ2K_VERSION_MINOR 2 31 | #define OPENHTJ2K_VERSION_PATCH 8 32 | -------------------------------------------------------------------------------- /source/core/interface/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0076 NEW) 2 | target_sources(open_htj2k 3 | PRIVATE 4 | encoder.cpp 5 | decoder.cpp 6 | ) -------------------------------------------------------------------------------- /source/core/interface/decoder.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | #include 31 | #include 32 | #include 33 | #if defined(_MSC_VER) && !defined(OHTJ2K_STATIC) 34 | #define OPENHTJ2K_EXPORT __declspec(dllexport) 35 | #else 36 | #define OPENHTJ2K_EXPORT 37 | #endif 38 | namespace open_htj2k { 39 | class openhtj2k_decoder { 40 | private: 41 | std::unique_ptr impl; 42 | 43 | public: 44 | OPENHTJ2K_EXPORT openhtj2k_decoder(); 45 | OPENHTJ2K_EXPORT openhtj2k_decoder(const char *, uint8_t reduce_NL, uint32_t num_threads); 46 | OPENHTJ2K_EXPORT openhtj2k_decoder(const uint8_t *, size_t, uint8_t reduce_NL, uint32_t num_threads); 47 | OPENHTJ2K_EXPORT void init(const uint8_t *, size_t, uint8_t reduce_NL, uint32_t num_threads); 48 | OPENHTJ2K_EXPORT void parse(); 49 | OPENHTJ2K_EXPORT uint16_t get_num_component(); 50 | OPENHTJ2K_EXPORT uint32_t get_component_width(uint16_t); 51 | OPENHTJ2K_EXPORT uint32_t get_component_height(uint16_t); 52 | OPENHTJ2K_EXPORT uint8_t get_component_depth(uint16_t); 53 | OPENHTJ2K_EXPORT bool get_component_signedness(uint16_t); 54 | OPENHTJ2K_EXPORT uint8_t get_minumum_DWT_levels(); 55 | OPENHTJ2K_EXPORT void invoke(std::vector &, std::vector &, std::vector &, 56 | std::vector &, std::vector &); 57 | OPENHTJ2K_EXPORT void destroy(); 58 | OPENHTJ2K_EXPORT ~openhtj2k_decoder(); 59 | }; 60 | } // namespace open_htj2k 61 | -------------------------------------------------------------------------------- /source/core/interface/encoder.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #if defined(OPENHTJ2K_TIFF_SUPPORT) 36 | #include 37 | #endif 38 | namespace open_htj2k { 39 | class image { 40 | private: 41 | uint32_t width; 42 | uint32_t height; 43 | uint16_t num_components; 44 | std::vector component_width; 45 | std::vector component_height; 46 | std::unique_ptr[]> buf; 47 | std::vector bits_per_pixel; 48 | std::vector is_signed; 49 | 50 | public: 51 | #if defined(_MSC_VER) && !defined(OHTJ2K_STATIC) 52 | __declspec(dllexport) explicit image(const std::vector &filenames); 53 | __declspec(dllexport) int read_pnmpgx(const std::string &filename, const uint16_t nc); 54 | #if defined(OPENHTJ2K_TIFF_SUPPORT) 55 | __declspec(dllexport) int read_tiff(const std::string &filename, const uint16_t nc); 56 | #endif 57 | #else 58 | explicit image(const std::vector &filenames); 59 | int read_pnmpgx(const std::string &filename, uint16_t nc); 60 | #if defined(OPENHTJ2K_TIFF_SUPPORT) 61 | int read_tiff(const std::string &filename); 62 | #endif 63 | #endif 64 | 65 | [[nodiscard]] uint32_t get_width() const { return this->width; } 66 | [[nodiscard]] uint32_t get_height() const { return this->height; } 67 | [[nodiscard]] uint32_t get_component_width(uint16_t c) const { 68 | if (c > num_components) { 69 | printf("ERROR: component index %d is larger than maximum value %d.\n", c, num_components); 70 | throw std::exception(); 71 | } 72 | return this->component_width[c]; 73 | } 74 | [[nodiscard]] uint32_t get_component_height(uint16_t c) const { 75 | if (c > num_components) { 76 | printf("ERROR: component index %d is larger than maximum value %d.\n", c, num_components); 77 | throw std::exception(); 78 | } 79 | return this->component_height[c]; 80 | } 81 | [[nodiscard]] uint16_t get_num_components() const { return this->num_components; } 82 | uint8_t get_Ssiz_value(uint16_t c) { 83 | uint8_t val = static_cast(this->bits_per_pixel[c] - 1); 84 | if (this->is_signed[c]) { 85 | val = val | 0x80; 86 | } 87 | return val; 88 | } 89 | uint8_t get_max_bpp() { 90 | uint8_t max = 0; 91 | for (auto &v : bits_per_pixel) { 92 | max = (max < v) ? v : max; 93 | } 94 | return max; 95 | } 96 | int32_t *get_buf(uint16_t c) { return this->buf[c].get(); } 97 | }; 98 | 99 | struct siz_params { 100 | uint16_t Rsiz; 101 | uint32_t Xsiz; 102 | uint32_t Ysiz; 103 | uint32_t XOsiz; 104 | uint32_t YOsiz; 105 | uint32_t XTsiz; 106 | uint32_t YTsiz; 107 | uint32_t XTOsiz; 108 | uint32_t YTOsiz; 109 | uint16_t Csiz; 110 | std::vector Ssiz; 111 | std::vector XRsiz; 112 | std::vector YRsiz; 113 | // uint8_t bpp; 114 | }; 115 | 116 | struct cod_params { 117 | uint16_t blkwidth; 118 | uint16_t blkheight; 119 | bool is_max_precincts; 120 | bool use_SOP; 121 | bool use_EPH; 122 | uint8_t progression_order; 123 | uint16_t number_of_layers; 124 | uint8_t use_color_trafo; 125 | uint8_t dwt_levels; 126 | uint8_t codeblock_style; 127 | uint8_t transformation; 128 | std::vector PPx, PPy; 129 | }; 130 | 131 | struct qcd_params { 132 | uint8_t number_of_guardbits; 133 | bool is_derived; 134 | double base_step; 135 | }; 136 | 137 | class openhtj2k_encoder { 138 | private: 139 | std::unique_ptr impl; 140 | 141 | public: 142 | #if defined(_MSC_VER) && !defined(OHTJ2K_STATIC) 143 | __declspec(dllexport) 144 | openhtj2k_encoder(const char *, const std::vector &input_buf, siz_params &siz, 145 | cod_params &cod, qcd_params &qcd, uint8_t qfactor, bool isJPH, uint8_t color_space, 146 | uint32_t num_threads); 147 | __declspec(dllexport) void set_output_buffer(std::vector &output_buf); 148 | __declspec(dllexport) size_t invoke(); 149 | __declspec(dllexport) ~openhtj2k_encoder(); 150 | #else 151 | openhtj2k_encoder(const char *, const std::vector &input_buf, siz_params &siz, cod_params &cod, 152 | qcd_params &qcd, uint8_t qfactor, bool isJPH, uint8_t color_space, 153 | uint32_t num_threads); 154 | void set_output_buffer(std::vector &output_buf); 155 | size_t invoke(); 156 | ~openhtj2k_encoder(); 157 | #endif 158 | }; 159 | } // namespace open_htj2k 160 | -------------------------------------------------------------------------------- /source/core/jph/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0076 NEW) 2 | target_sources(open_htj2k 3 | PRIVATE 4 | jph.cpp 5 | ) -------------------------------------------------------------------------------- /source/core/jph/jph.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "jph.hpp" 30 | 31 | signature_box::signature_box() : box_base(12, 0x6A502020), signature(0x0D0A870A) {} 32 | 33 | size_t signature_box::write(j2c_dst_memory &dst) { 34 | base_write(dst); 35 | dst.put_dword(signature); 36 | return LBox; 37 | } 38 | 39 | file_type_box::file_type_box(uint8_t type) : box_base(16, 0x66747970), MinV(0) { 40 | if (type == 0) { 41 | // jp2 42 | BR = 0x6A703220; 43 | CLi.push_back(0x6A703220); 44 | } else if (type == 1) { 45 | // jph 46 | BR = 0x6A706820; 47 | CLi.push_back(0x6A706820); 48 | } else { 49 | printf("ERROR: unsupported type for file_type_box\n"); 50 | throw std::exception(); 51 | } 52 | for (size_t i = 0; i < CLi.size(); ++i) { 53 | LBox += 4; 54 | } 55 | } 56 | 57 | size_t file_type_box::write(j2c_dst_memory &dst) { 58 | base_write(dst); 59 | dst.put_dword(BR); 60 | dst.put_dword(MinV); 61 | for (auto &c : CLi) { 62 | dst.put_dword(c); 63 | } 64 | return LBox; 65 | } 66 | 67 | image_header_box::image_header_box(j2k_main_header &hdr) : box_base(22, 0x69686472), C(7), UnkC(0), IPR(0) { 68 | element_siz siz, Osiz; 69 | hdr.SIZ->get_image_size(siz); 70 | hdr.SIZ->get_image_origin(Osiz); 71 | HEIGHT = siz.y - Osiz.y; 72 | WIDTH = siz.x - Osiz.x; 73 | NC = hdr.SIZ->get_num_components(); 74 | uint8_t val = hdr.SIZ->get_bitdepth(0) - 1; 75 | for (uint16_t c = 1; c < NC; ++c) { 76 | if (val != hdr.SIZ->get_bitdepth(c) - 1) { 77 | val = 0xFF; 78 | break; 79 | } 80 | } 81 | BPC = val | static_cast((hdr.SIZ->is_signed(0)) ? 0x80 : 0); 82 | } 83 | bool image_header_box::needBPCC() { 84 | bool val = false; 85 | if (BPC == 0xFF) { 86 | val = true; 87 | } 88 | return val; 89 | } 90 | size_t image_header_box::write(j2c_dst_memory &dst) { 91 | base_write(dst); 92 | dst.put_dword(HEIGHT); 93 | dst.put_dword(WIDTH); 94 | dst.put_word(NC); 95 | dst.put_byte(BPC); 96 | dst.put_byte(C); 97 | dst.put_byte(UnkC); 98 | dst.put_byte(IPR); 99 | return LBox; 100 | } 101 | 102 | bits_per_component_box::bits_per_component_box(j2k_main_header &hdr) : box_base(8, 0x62706363) { 103 | for (uint16_t c = 0; c < hdr.SIZ->get_num_components(); ++c) { 104 | uint8_t val = static_cast(hdr.SIZ->get_bitdepth(c) - 1); 105 | val = val | static_cast((hdr.SIZ->is_signed(c)) ? 0x80 : 0); 106 | BPC.push_back(val); 107 | LBox++; 108 | } 109 | } 110 | size_t bits_per_component_box::write(j2c_dst_memory &dst) { 111 | base_write(dst); 112 | for (auto &b : BPC) { 113 | dst.put_byte(b); 114 | } 115 | return LBox; 116 | } 117 | 118 | colour_specification_box::colour_specification_box(j2k_main_header &hdr, bool isSRGB) 119 | : box_base(15, 0x636F6C72), METH(1), PREC(0), APPROX(0) { 120 | if (hdr.SIZ->get_num_components() == 3) { 121 | if (isSRGB) { 122 | EnumCS = 16; 123 | } else { 124 | EnumCS = 18; 125 | } 126 | } else if (hdr.SIZ->get_num_components() == 1) { 127 | EnumCS = 17; 128 | } else { 129 | printf("ERROR: invalid color space specification.\n"); 130 | throw std::exception(); 131 | } 132 | } 133 | size_t colour_specification_box::write(j2c_dst_memory &dst) { 134 | base_write(dst); 135 | dst.put_byte(METH); 136 | dst.put_byte(PREC); 137 | dst.put_byte(APPROX); 138 | dst.put_dword(EnumCS); 139 | return LBox; 140 | } 141 | 142 | header_box::header_box(j2k_main_header &hdr, bool isSRGB) 143 | : box_base(8, 0x6A703268), ihdr(hdr), bpcc(hdr), colr(hdr, isSRGB) { 144 | LBox += ihdr.LBox + colr.LBox; 145 | if (ihdr.needBPCC()) { 146 | LBox += bpcc.LBox; 147 | } 148 | } 149 | size_t header_box::write(j2c_dst_memory &dst) { 150 | base_write(dst); 151 | ihdr.write(dst); 152 | if (ihdr.needBPCC()) { 153 | bpcc.write(dst); 154 | } 155 | colr.write(dst); 156 | return LBox; 157 | } 158 | 159 | contiguous_codestream_box::contiguous_codestream_box(size_t len) 160 | : box_base(static_cast(len) + 8, 0x6A703263){}; 161 | 162 | size_t contiguous_codestream_box::write(j2c_dst_memory &dst) { 163 | // LBox = 0; 164 | base_write(dst); 165 | return LBox; 166 | } 167 | 168 | jph_boxes::jph_boxes(j2k_main_header &hdr, uint8_t type, bool isSRGB, size_t code_len) 169 | : sig(), ftyp(type), jp2h(hdr, isSRGB), jp2c(code_len) {} 170 | 171 | size_t jph_boxes::write(j2c_dst_memory &dst) { 172 | size_t len = 0; 173 | len += sig.write(dst); 174 | len += ftyp.write(dst); 175 | len += jp2h.write(dst); 176 | len += jp2c.write(dst); 177 | return len; 178 | } 179 | -------------------------------------------------------------------------------- /source/core/jph/jph.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #pragma once 30 | 31 | #include 32 | #include 33 | #include 34 | #include "j2kmarkers.hpp" 35 | #include "codestream.hpp" 36 | #include "open_htj2k_typedef.hpp" 37 | 38 | class box_base { 39 | public: 40 | uint32_t LBox; 41 | uint32_t TBox; 42 | uint64_t XLBox; 43 | 44 | public: 45 | box_base(uint32_t l, uint32_t t) : LBox(l), TBox(t), XLBox(0) {} 46 | virtual size_t write(j2c_dst_memory &dst) = 0; 47 | void base_write(j2c_dst_memory &dst) const { 48 | dst.put_dword(LBox); 49 | dst.put_dword(TBox); 50 | } 51 | }; 52 | 53 | class signature_box : public box_base { 54 | private: 55 | uint32_t signature; 56 | 57 | public: 58 | signature_box(); 59 | size_t write(j2c_dst_memory &dst) override; 60 | }; 61 | 62 | class file_type_box : public box_base { 63 | private: 64 | uint32_t BR; 65 | const uint32_t MinV; 66 | std::vector CLi; 67 | 68 | public: 69 | file_type_box(uint8_t type); 70 | size_t write(j2c_dst_memory &dst) override; 71 | }; 72 | 73 | class image_header_box : public box_base { 74 | private: 75 | uint32_t HEIGHT; 76 | uint32_t WIDTH; 77 | uint16_t NC; 78 | uint8_t BPC; 79 | const uint8_t C; 80 | uint8_t UnkC; 81 | uint8_t IPR; 82 | 83 | public: 84 | image_header_box(j2k_main_header &hdr); 85 | bool needBPCC(); 86 | size_t write(j2c_dst_memory &dst) override; 87 | }; 88 | 89 | class bits_per_component_box : public box_base { 90 | private: 91 | std::vector BPC; 92 | 93 | public: 94 | bits_per_component_box(j2k_main_header &hdr); 95 | size_t write(j2c_dst_memory &dst) override; 96 | }; 97 | 98 | class colour_specification_box : public box_base { 99 | private: 100 | uint8_t METH; 101 | uint8_t PREC; 102 | uint8_t APPROX; 103 | uint32_t EnumCS; 104 | [[maybe_unused]] uint8_t PROFILE; 105 | [[maybe_unused]] uint16_t COLPRIMS; 106 | [[maybe_unused]] uint16_t TRANSFC; 107 | [[maybe_unused]] uint16_t MATCOEFFS; 108 | [[maybe_unused]] bool VIDFRNG; 109 | [[maybe_unused]] uint8_t VIDFRNG_RSVD; 110 | 111 | public: 112 | colour_specification_box(j2k_main_header &hdr, bool isSRGB); 113 | size_t write(j2c_dst_memory &dst) override; 114 | }; 115 | 116 | class header_box : public box_base { 117 | private: 118 | image_header_box ihdr; 119 | bits_per_component_box bpcc; 120 | colour_specification_box colr; 121 | 122 | public: 123 | header_box(j2k_main_header &hdr, bool isSRGB); 124 | size_t write(j2c_dst_memory &dst) override; 125 | }; 126 | 127 | class contiguous_codestream_box : public box_base { 128 | public: 129 | contiguous_codestream_box(size_t len); 130 | size_t write(j2c_dst_memory &dst) override; 131 | }; 132 | 133 | class jph_boxes { 134 | private: 135 | signature_box sig; 136 | file_type_box ftyp; 137 | header_box jp2h; 138 | contiguous_codestream_box jp2c; 139 | 140 | public: 141 | jph_boxes(j2k_main_header &hdr, uint8_t type, bool isSRGB, size_t code_len); 142 | size_t write(j2c_dst_memory &dst); 143 | }; -------------------------------------------------------------------------------- /source/core/transform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0076 NEW) 2 | target_sources(open_htj2k 3 | PRIVATE 4 | idwt.cpp 5 | idwt_neon.cpp 6 | idwt_avx2.cpp 7 | fdwt.cpp 8 | fdwt_avx2.cpp 9 | fdwt_neon.cpp 10 | color.cpp 11 | color_avx2.cpp 12 | color_neon.cpp 13 | ) -------------------------------------------------------------------------------- /source/core/transform/color.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 - 2021, Osamu Watanabe 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #if not defined(OPENHTJ2K_TRY_AVX2) && not defined(OPENHTJ2K_ENABLE_ARM_NEON) 30 | #include "color.hpp" 31 | 32 | void cvt_rgb_to_ycbcr_rev(int32_t *sp0, int32_t *sp1, int32_t *sp2, uint32_t width, uint32_t height) { 33 | int32_t R, G, B; 34 | int32_t Y, Cb, Cr; 35 | for (uint32_t y = 0; y < height; ++y) { 36 | int32_t *p0 = sp0 + y * round_up(width, 32U); 37 | int32_t *p1 = sp1 + y * round_up(width, 32U); 38 | int32_t *p2 = sp2 + y * round_up(width, 32U); 39 | for (uint32_t n = 0; n < width; n++) { 40 | R = p0[n]; 41 | G = p1[n]; 42 | B = p2[n]; 43 | Y = (R + 2 * G + B) >> 2; 44 | Cb = B - G; 45 | Cr = R - G; 46 | p0[n] = Y; 47 | p1[n] = Cb; 48 | p2[n] = Cr; 49 | } 50 | } 51 | } 52 | 53 | void cvt_rgb_to_ycbcr_irrev(int32_t *sp0, int32_t *sp1, int32_t *sp2, uint32_t width, uint32_t height) { 54 | double fR, fG, fB; 55 | double fY, fCb, fCr; 56 | for (uint32_t y = 0; y < height; ++y) { 57 | int32_t *p0 = sp0 + y * round_up(width, 32U); 58 | int32_t *p1 = sp1 + y * round_up(width, 32U); 59 | int32_t *p2 = sp2 + y * round_up(width, 32U); 60 | for (uint32_t n = 0; n < width; n++) { 61 | fR = static_cast(p0[n]); 62 | fG = static_cast(p1[n]); 63 | fB = static_cast(p2[n]); 64 | fY = ALPHA_R * fR + ALPHA_G * fG + ALPHA_B * fB; 65 | fCb = (1.0 / CB_FACT_B) * (fB - fY); 66 | fCr = (1.0 / CR_FACT_R) * (fR - fY); 67 | p0[n] = round_d(fY); 68 | p1[n] = round_d(fCb); 69 | p2[n] = round_d(fCr); 70 | } 71 | } 72 | } 73 | 74 | void cvt_ycbcr_to_rgb_rev(int32_t *sp0, int32_t *sp1, int32_t *sp2, uint32_t width, uint32_t height) { 75 | int32_t R, G, B; 76 | int32_t Y, Cb, Cr; 77 | for (uint32_t y = 0; y < height; ++y) { 78 | int32_t *p0 = sp0 + y * round_up(width, 32U); 79 | int32_t *p1 = sp1 + y * round_up(width, 32U); 80 | int32_t *p2 = sp2 + y * round_up(width, 32U); 81 | for (uint32_t n = 0; n < width; n++) { 82 | Y = p0[n]; 83 | Cb = p1[n]; 84 | Cr = p2[n]; 85 | G = Y - ((Cb + Cr) >> 2); 86 | R = Cr + G; 87 | B = Cb + G; 88 | p0[n] = R; 89 | p1[n] = G; 90 | p2[n] = B; 91 | } 92 | } 93 | } 94 | 95 | void cvt_ycbcr_to_rgb_irrev(int32_t *sp0, int32_t *sp1, int32_t *sp2, uint32_t width, uint32_t height) { 96 | int32_t R, G, B; 97 | double fY, fCb, fCr; 98 | for (uint32_t y = 0; y < height; ++y) { 99 | int32_t *p0 = sp0 + y * round_up(width, 32U); 100 | int32_t *p1 = sp1 + y * round_up(width, 32U); 101 | int32_t *p2 = sp2 + y * round_up(width, 32U); 102 | for (uint32_t n = 0; n < width; n++) { 103 | fY = static_cast(p0[n]); 104 | fCb = static_cast(p1[n]); 105 | fCr = static_cast(p2[n]); 106 | R = static_cast(round_d(fY + CR_FACT_R * fCr)); 107 | B = static_cast(round_d(fY + CB_FACT_B * fCb)); 108 | G = static_cast(round_d(fY - CR_FACT_G * fCr - CB_FACT_G * fCb)); 109 | p0[n] = R; 110 | p1[n] = G; 111 | p2[n] = B; 112 | } 113 | } 114 | } 115 | #endif -------------------------------------------------------------------------------- /source/pkg-config.pc.cmake: -------------------------------------------------------------------------------- 1 | Name: ${PROJECT_NAME} 2 | Description: ${PROJECT_DESCRIPTION} 3 | Version: ${PROJECT_VERSION} 4 | Requires: ${PKG_CONFIG_REQUIRES} 5 | prefix=${CMAKE_INSTALL_PREFIX} 6 | includedir=${PKG_CONFIG_INCLUDEDIR} 7 | libdir=${PKG_CONFIG_LIBDIR} 8 | Libs: ${PKG_CONFIG_LIBS} 9 | Cflags: ${PKG_CONFIG_CFLAGS} -------------------------------------------------------------------------------- /source/thirdparty/.gitignore: -------------------------------------------------------------------------------- 1 | /highway/* 2 | -------------------------------------------------------------------------------- /source/thirdparty/highway/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.10) 16 | 17 | # Set PIE flags for POSITION_INDEPENDENT_CODE targets, added in 3.14. 18 | if(POLICY CMP0083) 19 | cmake_policy(SET CMP0083 NEW) 20 | endif() 21 | 22 | project(hwy VERSION 0.14.2) # Keep in sync with highway.h version 23 | 24 | set(CMAKE_CXX_STANDARD 11) 25 | set(CMAKE_CXX_EXTENSIONS OFF) 26 | set(CMAKE_CXX_STANDARD_REQUIRED YES) 27 | 28 | # Enabled PIE binaries by default if supported. 29 | include(CheckPIESupported OPTIONAL RESULT_VARIABLE CHECK_PIE_SUPPORTED) 30 | if(CHECK_PIE_SUPPORTED) 31 | check_pie_supported(LANGUAGES CXX) 32 | if(CMAKE_CXX_LINK_PIE_SUPPORTED) 33 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) 34 | endif() 35 | endif() 36 | 37 | include(GNUInstallDirs) 38 | 39 | if (NOT CMAKE_BUILD_TYPE) 40 | set(CMAKE_BUILD_TYPE RelWithDebInfo) 41 | endif() 42 | 43 | set(HWY_CMAKE_ARM7 OFF CACHE BOOL "Set copts for ARMv7 with NEON?") 44 | 45 | # Unconditionally adding -Werror risks breaking the build when new warnings 46 | # arise due to compiler/platform changes. Enable this in CI/tests. 47 | set(HWY_WARNINGS_ARE_ERRORS OFF CACHE BOOL "Add -Werror flag?") 48 | 49 | set(HWY_EXAMPLES_TESTS_INSTALL ON CACHE BOOL "Build examples, tests, install?") 50 | 51 | include(CheckCXXSourceCompiles) 52 | 53 | set(HWY_SOURCES 54 | hwy/aligned_allocator.cc 55 | hwy/aligned_allocator.h 56 | hwy/base.h 57 | hwy/cache_control.h 58 | hwy/detect_compiler_arch.h # private 59 | hwy/detect_targets.h # private 60 | hwy/foreach_target.h 61 | hwy/highway.h 62 | hwy/nanobenchmark.cc 63 | hwy/nanobenchmark.h 64 | hwy/ops/arm_neon-inl.h 65 | hwy/ops/arm_sve-inl.h 66 | hwy/ops/generic_ops-inl.h 67 | hwy/ops/scalar-inl.h 68 | hwy/ops/set_macros-inl.h 69 | hwy/ops/shared-inl.h 70 | hwy/ops/wasm_128-inl.h 71 | hwy/ops/x86_128-inl.h 72 | hwy/ops/x86_256-inl.h 73 | hwy/ops/x86_512-inl.h 74 | hwy/targets.cc 75 | hwy/targets.h 76 | ) 77 | 78 | 79 | if (MSVC) 80 | # TODO(janwas): add flags 81 | else() 82 | set(HWY_FLAGS 83 | # Avoid changing binaries based on the current time and date. 84 | -Wno-builtin-macro-redefined 85 | -D__DATE__="redacted" 86 | -D__TIMESTAMP__="redacted" 87 | -D__TIME__="redacted" 88 | 89 | # Optimizations 90 | -fmerge-all-constants 91 | 92 | # Warnings 93 | -Wall 94 | -Wextra 95 | # These are not included in Wall nor Wextra: 96 | -Wconversion 97 | -Wsign-conversion 98 | -Wvla 99 | -Wnon-virtual-dtor 100 | ) 101 | 102 | if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") 103 | list(APPEND HWY_FLAGS 104 | -Wfloat-overflow-conversion 105 | -Wfloat-zero-conversion 106 | -Wfor-loop-analysis 107 | -Wgnu-redeclared-enum 108 | -Winfinite-recursion 109 | -Wself-assign 110 | -Wstring-conversion 111 | -Wtautological-overlap-compare 112 | -Wthread-safety-analysis 113 | -Wundefined-func-template 114 | 115 | -fno-cxx-exceptions 116 | -fno-slp-vectorize 117 | -fno-vectorize 118 | 119 | # Use color in messages 120 | -fdiagnostics-show-option -fcolor-diagnostics 121 | ) 122 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) 123 | list(APPEND HWY_FLAGS -Wc++2a-extensions) 124 | endif() 125 | endif() 126 | 127 | if (WIN32) 128 | if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") 129 | list(APPEND HWY_FLAGS 130 | -Wno-global-constructors 131 | -Wno-language-extension-token 132 | -Wno-used-but-marked-unused 133 | -Wno-shadow-field-in-constructor 134 | -Wno-unused-member-function 135 | -Wno-unused-template 136 | -Wno-c++98-compat-pedantic 137 | -Wno-used-but-marked-unused 138 | -Wno-zero-as-null-pointer-constant 139 | ) 140 | endif() 141 | 142 | list(APPEND HWY_FLAGS 143 | -Wno-cast-align 144 | -Wno-double-promotion 145 | -Wno-float-equal 146 | -Wno-format-nonliteral 147 | -Wno-shadow 148 | -Wno-sign-conversion 149 | ) 150 | else() 151 | list(APPEND HWY_FLAGS 152 | -fmath-errno 153 | -fno-exceptions 154 | ) 155 | endif() # WIN32 156 | 157 | if (HWY_CMAKE_ARM7) 158 | list(APPEND HWY_FLAGS 159 | -march=armv7-a 160 | -mfpu=neon-vfpv4 161 | -mfloat-abi=hard # must match the toolchain specified as CXX= 162 | -mfp16-format=ieee # required for vcvt_f32_f16 163 | ) 164 | endif() # HWY_CMAKE_ARM7 165 | 166 | if (HWY_WARNINGS_ARE_ERRORS) 167 | list(APPEND HWY_FLAGS -Werror) 168 | endif() 169 | 170 | endif() # !MSVC 171 | 172 | add_library(hwy STATIC ${HWY_SOURCES}) 173 | target_compile_options(hwy PRIVATE ${HWY_FLAGS}) 174 | set_property(TARGET hwy PROPERTY POSITION_INDEPENDENT_CODE ON) 175 | target_include_directories(hwy PUBLIC ${CMAKE_CURRENT_LIST_DIR}) 176 | -------------------------------------------------------------------------------- /source/thirdparty/highway/CMakeLists.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | 3 | project(googletest-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(googletest 7 | GIT_REPOSITORY https://github.com/google/googletest.git 8 | GIT_TAG master 9 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" 10 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" 11 | CONFIGURE_COMMAND "" 12 | BUILD_COMMAND "" 13 | INSTALL_COMMAND "" 14 | TEST_COMMAND "" 15 | ) -------------------------------------------------------------------------------- /source/thirdparty/highway/CONTRIBUTING: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Testing 26 | 27 | This repository is used by JPEG XL, so major API changes will require 28 | coordination. Please get in touch with us beforehand, e.g. by raising an issue. 29 | 30 | ## Community Guidelines 31 | 32 | This project follows 33 | [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). 34 | -------------------------------------------------------------------------------- /source/thirdparty/highway/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "highway") 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | 5 | http_archive( 6 | name = "com_google_googletest", 7 | urls = ["https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip"], 8 | sha256 = "5cf189eb6847b4f8fc603a3ffff3b0771c08eec7dd4bd961bfd45477dd13eb73", 9 | strip_prefix = "googletest-609281088cfefc76f9d0ce82e1ff6c30cc3591e5", 10 | ) 11 | 12 | # See https://google.github.io/googletest/quickstart-bazel.html 13 | http_archive( 14 | name = "rules_cc", 15 | urls = ["https://github.com/bazelbuild/rules_cc/archive/40548a2974f1aea06215272d9c2b47a14a24e556.zip"], 16 | sha256 = "56ac9633c13d74cb71e0546f103ce1c58810e4a76aa8325da593ca4277908d72", 17 | strip_prefix = "rules_cc-40548a2974f1aea06215272d9c2b47a14a24e556", 18 | ) 19 | 20 | # Need recent version for config_setting_group 21 | http_archive( 22 | name = "bazel_skylib", 23 | urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/0.9.0/bazel_skylib-0.9.0.tar.gz"], 24 | ) 25 | -------------------------------------------------------------------------------- /source/thirdparty/highway/debian/changelog: -------------------------------------------------------------------------------- 1 | highway (0.14.2-1) UNRELEASED; urgency=medium 2 | 3 | * Add MaskedLoad 4 | * Fix non-glibc PPC, Windows GCC, MSVC 19.14 5 | * Opt-in for -Werror; separate design_philosophy.md 6 | 7 | -- Jan Wassenberg Tue, 24 Aug 2021 15:00:00 +0200 8 | 9 | highway (0.14.1-1) UNRELEASED; urgency=medium 10 | 11 | * Add LoadMaskBits, CompressBits[Store] 12 | * Fix CPU feature check (AES/F16C) and warnings 13 | * Improved DASSERT - disabled in optimized builds 14 | 15 | -- Jan Wassenberg Tue, 17 Aug 2021 14:00:00 +0200 16 | 17 | highway (0.14.0-1) UNRELEASED; urgency=medium 18 | 19 | * Add SVE, S-SSE3, AVX3_DL targets 20 | * Support partial vectors in all ops 21 | * Add PopulationCount, FindFirstTrue, Ne, TableLookupBytesOr0 22 | * Add AESRound, CLMul, MulOdd, HWY_CAP_FLOAT16 23 | 24 | -- Jan Wassenberg Thu, 29 Jul 2021 15:00:00 +0200 25 | 26 | highway (0.12.2-1) UNRELEASED; urgency=medium 27 | 28 | * fix scalar-only test and Windows macro conflict with Load/StoreFence 29 | * replace deprecated wasm intrinsics 30 | 31 | -- Jan Wassenberg Mon, 31 May 2021 16:00:00 +0200 32 | 33 | highway (0.12.1-1) UNRELEASED; urgency=medium 34 | 35 | * doc updates, ARM GCC support, fix s390/ppc, complete partial vectors 36 | * fix warnings, faster ARM div/sqrt, separate hwy_contrib library 37 | * add Abs(i64)/FirstN/Pause, enable AVX2 on MSVC 38 | 39 | -- Jan Wassenberg Wed, 19 May 2021 15:00:00 +0200 40 | 41 | highway (0.12.0-1) UNRELEASED; urgency=medium 42 | 43 | * Add Shift*8, Compress16, emulated Scatter/Gather, StoreInterleaved3/4 44 | * Remove deprecated HWY_*_LANES, deprecate HWY_GATHER_LANES 45 | * Proper IEEE rounding, reduce libstdc++ usage, inlined math 46 | 47 | -- Jan Wassenberg Thu, 15 Apr 2021 20:00:00 +0200 48 | 49 | highway (0.11.1-1) UNRELEASED; urgency=medium 50 | 51 | * Fix clang7 asan error, finish f16 conversions and add test 52 | 53 | -- Jan Wassenberg Thu, 25 Feb 2021 16:00:00 +0200 54 | 55 | highway (0.11.0-1) UNRELEASED; urgency=medium 56 | 57 | * Add RVV+mask logical ops, allow Shl/ShiftLeftSame on all targets, more math 58 | 59 | -- Jan Wassenberg Thu, 18 Feb 2021 20:00:00 +0200 60 | 61 | highway (0.7.0-1) UNRELEASED; urgency=medium 62 | 63 | * Added API stability notice, Compress[Store], contrib/, SignBit, CopySign 64 | 65 | -- Jan Wassenberg Tue, 5 Jan 2021 17:00:00 +0200 66 | 67 | highway (0.1-1) UNRELEASED; urgency=medium 68 | 69 | * Initial debian package. 70 | 71 | -- Alex Deymo Mon, 19 Oct 2020 16:48:07 +0200 72 | -------------------------------------------------------------------------------- /source/thirdparty/highway/debian/compat: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /source/thirdparty/highway/debian/control: -------------------------------------------------------------------------------- 1 | Source: highway 2 | Maintainer: JPEG XL Maintainers 3 | Section: misc 4 | Priority: optional 5 | Standards-Version: 3.9.8 6 | Build-Depends: cmake, 7 | debhelper (>= 9), 8 | libgtest-dev 9 | Homepage: https://github.com/google/highway 10 | 11 | Package: libhwy-dev 12 | Architecture: any 13 | Section: libdevel 14 | Depends: ${misc:Depends} 15 | Description: Efficient and performance-portable SIMD wrapper (developer files) 16 | This library provides type-safe and source-code portable wrappers over 17 | existing platform-specific intrinsics. Its design aims for simplicity, 18 | reliable efficiency across platforms, and immediate usability with current 19 | compilers. 20 | . 21 | This package installs the development files. There's no runtime library 22 | since most of Highway is implemented in headers and only a very small 23 | static library is needed. 24 | -------------------------------------------------------------------------------- /source/thirdparty/highway/debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: highway 3 | 4 | Files: * 5 | Copyright: 2020 Google LLC 6 | License: Apache-2.0 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | . 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | . 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | . 19 | On Debian systems, the complete text of the Apache License, Version 2 20 | can be found in "/usr/share/common-licenses/Apache-2.0". 21 | -------------------------------------------------------------------------------- /source/thirdparty/highway/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | %: 3 | dh $@ --buildsystem=cmake 4 | 5 | override_dh_auto_configure: 6 | dh_auto_configure -- -DHWY_SYSTEM_GTEST=ON 7 | -------------------------------------------------------------------------------- /source/thirdparty/highway/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /source/thirdparty/highway/g3doc/highway_intro.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/source/thirdparty/highway/g3doc/highway_intro.pdf -------------------------------------------------------------------------------- /source/thirdparty/highway/g3doc/instruction_matrix.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osamu620/OpenHTJ2K/db3c972b876aeba7ab33cdd4b1c04df58eb39900/source/thirdparty/highway/g3doc/instruction_matrix.pdf -------------------------------------------------------------------------------- /source/thirdparty/highway/g3doc/release_testing_process.md: -------------------------------------------------------------------------------- 1 | ## Release testing process 2 | 3 | We run the following before a release: 4 | 5 | ### Windows x86 6 | 7 | ``` 8 | run_tests.bat 9 | ``` 10 | 11 | ### Linux x86 12 | 13 | #### Default 14 | 15 | ``` 16 | ./run_tests.sh 17 | ``` 18 | 19 | #### GCC 20 | 21 | ``` 22 | for VER in 8 9 10; do 23 | rm -rf build_g$VER && mkdir build_g$VER && cd build_g$VER && CC=gcc-$VER CXX=g++-$VER cmake .. -DHWY_WARNINGS_ARE_ERRORS:BOOL=ON && make -j && make test && cd .. && rm -rf build_g$VER 24 | done 25 | ``` 26 | 27 | #### ARMv7 cross compile (GCC) 28 | 29 | ``` 30 | export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf 31 | rm -rf build_arm7 && mkdir build_arm7 && cd build_arm7 32 | CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ cmake .. -DHWY_CMAKE_ARM7:BOOL=ON -DHWY_WARNINGS_ARE_ERRORS:BOOL=ON 33 | make -j8 && ctest && cd .. 34 | ``` 35 | 36 | #### ARMv8 cross compile (GCC) 37 | 38 | ``` 39 | export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu 40 | rm -rf build_arm8 && mkdir build_arm8 && cd build_arm8 41 | CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ cmake .. -DHWY_WARNINGS_ARE_ERRORS:BOOL=ON 42 | make -j8 && ctest && cd .. 43 | ``` 44 | 45 | #### JPEG XL clang (debug, asan, msan) 46 | 47 | ``` 48 | for VER in 7 8 9 10 11; do 49 | rm -rf build_debug$VER && CC=clang-$VER CXX=clang++-$VER BUILD_DIR=build_debug$VER SKIP_TEST=1 ./ci.sh debug && ./ci.sh test -R PassesTest && rm -rf build_debug$VER 50 | rm -rf build_asan$VER && CC=clang-$VER CXX=clang++-$VER BUILD_DIR=build_asan$VER ./ci.sh asan && rm -rf build_asan$VER 51 | rm -rf build_msan$VER && CC=clang-$VER CXX=clang++-$VER BUILD_DIR=build_msan$VER ./ci.sh msan && rm -rf build_msan$VER 52 | done 53 | ``` 54 | 55 | #### JPEG XL tests 56 | 57 | ``` 58 | git -C third_party/highway pull -r origin master 59 | git diff 60 | vi deps.sh 61 | git commit -a -m"Highway test" 62 | git push git@gitlab.com:$USER/jpeg-xl.git HEAD:main --force 63 | ``` 64 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/aligned_allocator.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "hwy/aligned_allocator.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include // malloc 21 | 22 | #include 23 | #include 24 | 25 | #include "hwy/base.h" 26 | 27 | namespace hwy { 28 | namespace { 29 | 30 | #if HWY_ARCH_RVV && defined(__riscv_vector) 31 | // Not actually an upper bound on the size, but this value prevents crossing a 32 | // 4K boundary (relevant on Andes). 33 | constexpr size_t kAlignment = HWY_MAX(HWY_ALIGNMENT, 4096); 34 | #else 35 | constexpr size_t kAlignment = HWY_ALIGNMENT; 36 | #endif 37 | 38 | #if HWY_ARCH_X86 39 | // On x86, aliasing can only occur at multiples of 2K, but that's too wasteful 40 | // if this is used for single-vector allocations. 256 is more reasonable. 41 | constexpr size_t kAlias = kAlignment * 4; 42 | #else 43 | constexpr size_t kAlias = kAlignment; 44 | #endif 45 | 46 | #pragma pack(push, 1) 47 | struct AllocationHeader { 48 | void* allocated; 49 | size_t payload_size; 50 | }; 51 | #pragma pack(pop) 52 | 53 | // Returns a 'random' (cyclical) offset for AllocateAlignedBytes. 54 | size_t NextAlignedOffset() { 55 | static std::atomic next{0}; 56 | constexpr uint32_t kGroups = kAlias / kAlignment; 57 | const uint32_t group = next.fetch_add(1, std::memory_order_relaxed) % kGroups; 58 | const size_t offset = kAlignment * group; 59 | HWY_DASSERT((offset % kAlignment == 0) && offset <= kAlias); 60 | return offset; 61 | } 62 | 63 | } // namespace 64 | 65 | void* AllocateAlignedBytes(const size_t payload_size, AllocPtr alloc_ptr, 66 | void* opaque_ptr) { 67 | HWY_ASSERT(payload_size != 0); // likely a bug in caller 68 | if (payload_size >= std::numeric_limits::max() / 2) { 69 | HWY_DASSERT(false && "payload_size too large"); 70 | return nullptr; 71 | } 72 | 73 | size_t offset = NextAlignedOffset(); 74 | 75 | // What: | misalign | unused | AllocationHeader |payload 76 | // Size: |<= kAlias | offset |payload_size 77 | // ^allocated.^aligned.^header............^payload 78 | // The header must immediately precede payload, which must remain aligned. 79 | // To avoid wasting space, the header resides at the end of `unused`, 80 | // which therefore cannot be empty (offset == 0). 81 | if (offset == 0) { 82 | offset = kAlignment; // = RoundUpTo(sizeof(AllocationHeader), kAlignment) 83 | static_assert(sizeof(AllocationHeader) <= kAlignment, "Else: round up"); 84 | } 85 | 86 | const size_t allocated_size = kAlias + offset + payload_size; 87 | void* allocated; 88 | if (alloc_ptr == nullptr) { 89 | allocated = malloc(allocated_size); 90 | } else { 91 | allocated = (*alloc_ptr)(opaque_ptr, allocated_size); 92 | } 93 | if (allocated == nullptr) return nullptr; 94 | // Always round up even if already aligned - we already asked for kAlias 95 | // extra bytes and there's no way to give them back. 96 | uintptr_t aligned = reinterpret_cast(allocated) + kAlias; 97 | static_assert((kAlias & (kAlias - 1)) == 0, "kAlias must be a power of 2"); 98 | static_assert(kAlias >= kAlignment, "Cannot align to more than kAlias"); 99 | aligned &= ~(kAlias - 1); 100 | 101 | const uintptr_t payload = aligned + offset; // still aligned 102 | 103 | // Stash `allocated` and payload_size inside header for FreeAlignedBytes(). 104 | // The allocated_size can be reconstructed from the payload_size. 105 | AllocationHeader* header = reinterpret_cast(payload) - 1; 106 | header->allocated = allocated; 107 | header->payload_size = payload_size; 108 | 109 | return HWY_ASSUME_ALIGNED(reinterpret_cast(payload), kAlignment); 110 | } 111 | 112 | void FreeAlignedBytes(const void* aligned_pointer, FreePtr free_ptr, 113 | void* opaque_ptr) { 114 | if (aligned_pointer == nullptr) return; 115 | 116 | const uintptr_t payload = reinterpret_cast(aligned_pointer); 117 | HWY_DASSERT(payload % kAlignment == 0); 118 | const AllocationHeader* header = 119 | reinterpret_cast(payload) - 1; 120 | 121 | if (free_ptr == nullptr) { 122 | free(header->allocated); 123 | } else { 124 | (*free_ptr)(opaque_ptr, header->allocated); 125 | } 126 | } 127 | 128 | // static 129 | void AlignedDeleter::DeleteAlignedArray(void* aligned_pointer, FreePtr free_ptr, 130 | void* opaque_ptr, 131 | ArrayDeleter deleter) { 132 | if (aligned_pointer == nullptr) return; 133 | 134 | const uintptr_t payload = reinterpret_cast(aligned_pointer); 135 | HWY_DASSERT(payload % kAlignment == 0); 136 | const AllocationHeader* header = 137 | reinterpret_cast(payload) - 1; 138 | 139 | if (deleter) { 140 | (*deleter)(aligned_pointer, header->payload_size); 141 | } 142 | 143 | if (free_ptr == nullptr) { 144 | free(header->allocated); 145 | } else { 146 | (*free_ptr)(opaque_ptr, header->allocated); 147 | } 148 | } 149 | 150 | } // namespace hwy 151 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/base_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include "hwy/base.h" 21 | 22 | #undef HWY_TARGET_INCLUDE 23 | #define HWY_TARGET_INCLUDE "base_test.cc" 24 | #include "hwy/foreach_target.h" 25 | #include "hwy/highway.h" 26 | #include "hwy/tests/test_util-inl.h" 27 | 28 | HWY_BEFORE_NAMESPACE(); 29 | namespace hwy { 30 | namespace HWY_NAMESPACE { 31 | 32 | HWY_NOINLINE void TestAllLimits() { 33 | HWY_ASSERT_EQ(uint8_t(0), LimitsMin()); 34 | HWY_ASSERT_EQ(uint16_t(0), LimitsMin()); 35 | HWY_ASSERT_EQ(uint32_t(0), LimitsMin()); 36 | HWY_ASSERT_EQ(uint64_t(0), LimitsMin()); 37 | 38 | HWY_ASSERT_EQ(int8_t(-128), LimitsMin()); 39 | HWY_ASSERT_EQ(int16_t(-32768), LimitsMin()); 40 | HWY_ASSERT_EQ(int32_t(0x80000000u), LimitsMin()); 41 | HWY_ASSERT_EQ(int64_t(0x8000000000000000ull), LimitsMin()); 42 | 43 | HWY_ASSERT_EQ(uint8_t(0xFF), LimitsMax()); 44 | HWY_ASSERT_EQ(uint16_t(0xFFFF), LimitsMax()); 45 | HWY_ASSERT_EQ(uint32_t(0xFFFFFFFFu), LimitsMax()); 46 | HWY_ASSERT_EQ(uint64_t(0xFFFFFFFFFFFFFFFFull), LimitsMax()); 47 | 48 | HWY_ASSERT_EQ(int8_t(0x7F), LimitsMax()); 49 | HWY_ASSERT_EQ(int16_t(0x7FFF), LimitsMax()); 50 | HWY_ASSERT_EQ(int32_t(0x7FFFFFFFu), LimitsMax()); 51 | HWY_ASSERT_EQ(int64_t(0x7FFFFFFFFFFFFFFFull), LimitsMax()); 52 | } 53 | 54 | struct TestLowestHighest { 55 | template 56 | HWY_NOINLINE void operator()(T /*unused*/) const { 57 | HWY_ASSERT_EQ(std::numeric_limits::lowest(), LowestValue()); 58 | HWY_ASSERT_EQ(std::numeric_limits::max(), HighestValue()); 59 | } 60 | }; 61 | 62 | HWY_NOINLINE void TestAllLowestHighest() { ForAllTypes(TestLowestHighest()); } 63 | struct TestIsUnsigned { 64 | template 65 | HWY_NOINLINE void operator()(T /*unused*/) const { 66 | static_assert(!IsFloat(), "Expected !IsFloat"); 67 | static_assert(!IsSigned(), "Expected !IsSigned"); 68 | } 69 | }; 70 | 71 | struct TestIsSigned { 72 | template 73 | HWY_NOINLINE void operator()(T /*unused*/) const { 74 | static_assert(!IsFloat(), "Expected !IsFloat"); 75 | static_assert(IsSigned(), "Expected IsSigned"); 76 | } 77 | }; 78 | 79 | struct TestIsFloat { 80 | template 81 | HWY_NOINLINE void operator()(T /*unused*/) const { 82 | static_assert(IsFloat(), "Expected IsFloat"); 83 | static_assert(IsSigned(), "Floats are also considered signed"); 84 | } 85 | }; 86 | 87 | HWY_NOINLINE void TestAllType() { 88 | ForUnsignedTypes(TestIsUnsigned()); 89 | ForSignedTypes(TestIsSigned()); 90 | ForFloatTypes(TestIsFloat()); 91 | } 92 | 93 | struct TestIsSame { 94 | template 95 | HWY_NOINLINE void operator()(T /*unused*/) const { 96 | static_assert(IsSame(), "T == T"); 97 | static_assert(!IsSame, MakeUnsigned>(), "S != U"); 98 | static_assert(!IsSame, MakeSigned>(), "U != S"); 99 | } 100 | }; 101 | 102 | HWY_NOINLINE void TestAllIsSame() { ForAllTypes(TestIsSame()); } 103 | 104 | HWY_NOINLINE void TestAllPopCount() { 105 | HWY_ASSERT_EQ(size_t(0), PopCount(0u)); 106 | HWY_ASSERT_EQ(size_t(1), PopCount(1u)); 107 | HWY_ASSERT_EQ(size_t(1), PopCount(2u)); 108 | HWY_ASSERT_EQ(size_t(2), PopCount(3u)); 109 | HWY_ASSERT_EQ(size_t(1), PopCount(0x80000000u)); 110 | HWY_ASSERT_EQ(size_t(31), PopCount(0x7FFFFFFFu)); 111 | HWY_ASSERT_EQ(size_t(32), PopCount(0xFFFFFFFFu)); 112 | 113 | HWY_ASSERT_EQ(size_t(1), PopCount(0x80000000ull)); 114 | HWY_ASSERT_EQ(size_t(31), PopCount(0x7FFFFFFFull)); 115 | HWY_ASSERT_EQ(size_t(32), PopCount(0xFFFFFFFFull)); 116 | HWY_ASSERT_EQ(size_t(33), PopCount(0x10FFFFFFFFull)); 117 | HWY_ASSERT_EQ(size_t(63), PopCount(0xFFFEFFFFFFFFFFFFull)); 118 | HWY_ASSERT_EQ(size_t(64), PopCount(0xFFFFFFFFFFFFFFFFull)); 119 | } 120 | 121 | // NOLINTNEXTLINE(google-readability-namespace-comments) 122 | } // namespace HWY_NAMESPACE 123 | } // namespace hwy 124 | HWY_AFTER_NAMESPACE(); 125 | 126 | #if HWY_ONCE 127 | 128 | namespace hwy { 129 | HWY_BEFORE_TEST(BaseTest); 130 | HWY_EXPORT_AND_TEST_P(BaseTest, TestAllLimits); 131 | HWY_EXPORT_AND_TEST_P(BaseTest, TestAllLowestHighest); 132 | HWY_EXPORT_AND_TEST_P(BaseTest, TestAllType); 133 | HWY_EXPORT_AND_TEST_P(BaseTest, TestAllIsSame); 134 | HWY_EXPORT_AND_TEST_P(BaseTest, TestAllPopCount); 135 | } // namespace hwy 136 | 137 | // Ought not to be necessary, but without this, no tests run on RVV. 138 | int main(int argc, char **argv) { 139 | ::testing::InitGoogleTest(&argc, argv); 140 | return RUN_ALL_TESTS(); 141 | } 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/cache_control.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef HIGHWAY_HWY_CACHE_CONTROL_H_ 16 | #define HIGHWAY_HWY_CACHE_CONTROL_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "hwy/base.h" 22 | 23 | // Requires SSE2; fails to compile on 32-bit Clang 7 (see 24 | // https://github.com/gperftools/gperftools/issues/946). 25 | #if !defined(__SSE2__) || (HWY_COMPILER_CLANG && HWY_ARCH_X86_32) 26 | #undef HWY_DISABLE_CACHE_CONTROL 27 | #define HWY_DISABLE_CACHE_CONTROL 28 | #endif 29 | 30 | // intrin.h is sufficient on MSVC and already included by base.h. 31 | #if HWY_ARCH_X86 && !defined(HWY_DISABLE_CACHE_CONTROL) && !HWY_COMPILER_MSVC 32 | #include // SSE2 33 | #endif 34 | 35 | // Windows.h #defines these, which causes infinite recursion. Temporarily 36 | // undefine them in this header; these functions are anyway deprecated. 37 | // TODO(janwas): remove when these functions are removed. 38 | #pragma push_macro("LoadFence") 39 | #pragma push_macro("StoreFence") 40 | #undef LoadFence 41 | #undef StoreFence 42 | 43 | namespace hwy { 44 | 45 | // Even if N*sizeof(T) is smaller, Stream may write a multiple of this size. 46 | #define HWY_STREAM_MULTIPLE 16 47 | 48 | // The following functions may also require an attribute. 49 | #if HWY_ARCH_X86 && !defined(HWY_DISABLE_CACHE_CONTROL) && !HWY_COMPILER_MSVC 50 | #define HWY_ATTR_CACHE __attribute__((target("sse2"))) 51 | #else 52 | #define HWY_ATTR_CACHE 53 | #endif 54 | 55 | // Delays subsequent loads until prior loads are visible. On Intel CPUs, also 56 | // serves as a full fence (waits for all prior instructions to complete). 57 | // No effect on non-x86. 58 | // DEPRECATED due to differing behavior across architectures AND vendors. 59 | HWY_INLINE HWY_ATTR_CACHE void LoadFence() { 60 | #if HWY_ARCH_X86 && !defined(HWY_DISABLE_CACHE_CONTROL) 61 | _mm_lfence(); 62 | #endif 63 | } 64 | 65 | // Ensures values written by previous `Stream` calls are visible on the current 66 | // core. This is NOT sufficient for synchronizing across cores; when `Stream` 67 | // outputs are to be consumed by other core(s), the producer must publish 68 | // availability (e.g. via mutex or atomic_flag) after `FlushStream`. 69 | HWY_INLINE HWY_ATTR_CACHE void FlushStream() { 70 | #if HWY_ARCH_X86 && !defined(HWY_DISABLE_CACHE_CONTROL) 71 | _mm_sfence(); 72 | #endif 73 | } 74 | 75 | // DEPRECATED, replace with `FlushStream`. 76 | HWY_INLINE HWY_ATTR_CACHE void StoreFence() { FlushStream(); } 77 | 78 | // Optionally begins loading the cache line containing "p" to reduce latency of 79 | // subsequent actual loads. 80 | template 81 | HWY_INLINE HWY_ATTR_CACHE void Prefetch(const T* p) { 82 | #if HWY_ARCH_X86 && !defined(HWY_DISABLE_CACHE_CONTROL) 83 | _mm_prefetch(reinterpret_cast(p), _MM_HINT_T0); 84 | #elif HWY_COMPILER_GCC || HWY_COMPILER_CLANG 85 | // Hint=0 (NTA) behavior differs, but skipping outer caches is probably not 86 | // desirable, so use the default 3 (keep in caches). 87 | __builtin_prefetch(p, /*write=*/0, /*hint=*/3); 88 | #else 89 | (void)p; 90 | #endif 91 | } 92 | 93 | // Invalidates and flushes the cache line containing "p", if possible. 94 | HWY_INLINE HWY_ATTR_CACHE void FlushCacheline(const void* p) { 95 | #if HWY_ARCH_X86 && !defined(HWY_DISABLE_CACHE_CONTROL) 96 | _mm_clflush(p); 97 | #else 98 | (void)p; 99 | #endif 100 | } 101 | 102 | // When called inside a spin-loop, may reduce power consumption. 103 | HWY_INLINE HWY_ATTR_CACHE void Pause() { 104 | #if HWY_ARCH_X86 && !defined(HWY_DISABLE_CACHE_CONTROL) 105 | _mm_pause(); 106 | #endif 107 | } 108 | 109 | } // namespace hwy 110 | 111 | // TODO(janwas): remove when these functions are removed. (See above.) 112 | #pragma pop_macro("StoreFence") 113 | #pragma pop_macro("LoadFence") 114 | 115 | #endif // HIGHWAY_HWY_CACHE_CONTROL_H_ 116 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/detect_compiler_arch.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef HIGHWAY_HWY_DETECT_COMPILER_ARCH_H_ 16 | #define HIGHWAY_HWY_DETECT_COMPILER_ARCH_H_ 17 | 18 | // Detects compiler and arch from predefined macros. Zero dependencies for 19 | // inclusion by foreach_target.h. 20 | 21 | // Add to #if conditions to prevent IDE from graying out code. 22 | #if (defined __CDT_PARSER__) || (defined __INTELLISENSE__) || \ 23 | (defined Q_CREATOR_RUN) || (defined(__CLANGD__)) 24 | #define HWY_IDE 1 25 | #else 26 | #define HWY_IDE 0 27 | #endif 28 | 29 | //------------------------------------------------------------------------------ 30 | // Compiler 31 | 32 | // clang-cl defines _MSC_VER but doesn't behave like MSVC in other aspects like 33 | // used in HWY_DIAGNOSTICS(). We include a check that we are not clang for that 34 | // purpose. 35 | #if defined(_MSC_VER) && !defined(__clang__) 36 | #define HWY_COMPILER_MSVC _MSC_VER 37 | #else 38 | #define HWY_COMPILER_MSVC 0 39 | #endif 40 | 41 | #ifdef __INTEL_COMPILER 42 | #define HWY_COMPILER_ICC __INTEL_COMPILER 43 | #else 44 | #define HWY_COMPILER_ICC 0 45 | #endif 46 | 47 | #ifdef __GNUC__ 48 | #define HWY_COMPILER_GCC (__GNUC__ * 100 + __GNUC_MINOR__) 49 | #else 50 | #define HWY_COMPILER_GCC 0 51 | #endif 52 | 53 | // Clang can masquerade as MSVC/GCC, in which case both are set. 54 | #ifdef __clang__ 55 | #ifdef __APPLE__ 56 | // Apple LLVM version is unrelated to the actual Clang version, which we need 57 | // for enabling workarounds. Use the presence of warning flags to deduce it. 58 | // Adapted from https://github.com/simd-everywhere/simde/ simde-detect-clang.h. 59 | #if __has_warning("-Wformat-insufficient-args") 60 | #define HWY_COMPILER_CLANG 1200 61 | #elif __has_warning("-Wimplicit-const-int-float-conversion") 62 | #define HWY_COMPILER_CLANG 1100 63 | #elif __has_warning("-Wmisleading-indentation") 64 | #define HWY_COMPILER_CLANG 1000 65 | #elif defined(__FILE_NAME__) 66 | #define HWY_COMPILER_CLANG 900 67 | #elif __has_warning("-Wextra-semi-stmt") || \ 68 | __has_builtin(__builtin_rotateleft32) 69 | #define HWY_COMPILER_CLANG 800 70 | #elif __has_warning("-Wc++98-compat-extra-semi") 71 | #define HWY_COMPILER_CLANG 700 72 | #else // Anything older than 7.0 is not recommended for Highway. 73 | #define HWY_COMPILER_CLANG 600 74 | #endif // __has_warning chain 75 | #else // Non-Apple: normal version 76 | #define HWY_COMPILER_CLANG (__clang_major__ * 100 + __clang_minor__) 77 | #endif 78 | #else // Not clang 79 | #define HWY_COMPILER_CLANG 0 80 | #endif 81 | 82 | // More than one may be nonzero, but we want at least one. 83 | #if !HWY_COMPILER_MSVC && !HWY_COMPILER_ICC && !HWY_COMPILER_GCC && \ 84 | !HWY_COMPILER_CLANG 85 | #error "Unsupported compiler" 86 | #endif 87 | 88 | #ifdef __has_builtin 89 | #define HWY_HAS_BUILTIN(name) __has_builtin(name) 90 | #else 91 | #define HWY_HAS_BUILTIN(name) 0 92 | #endif 93 | 94 | #ifdef __has_attribute 95 | #define HWY_HAS_ATTRIBUTE(name) __has_attribute(name) 96 | #else 97 | #define HWY_HAS_ATTRIBUTE(name) 0 98 | #endif 99 | 100 | //------------------------------------------------------------------------------ 101 | // Architecture 102 | 103 | #if defined(HWY_EMULATE_SVE) 104 | 105 | #define HWY_ARCH_X86_32 0 106 | #define HWY_ARCH_X86_64 0 107 | #define HWY_ARCH_X86 0 108 | #define HWY_ARCH_PPC 0 109 | #define HWY_ARCH_ARM_A64 1 110 | #define HWY_ARCH_ARM_V7 0 111 | #define HWY_ARCH_ARM 1 112 | #define HWY_ARCH_WASM 0 113 | #define HWY_ARCH_RVV 0 114 | 115 | #else 116 | 117 | #if defined(__i386__) || defined(_M_IX86) 118 | #define HWY_ARCH_X86_32 1 119 | #else 120 | #define HWY_ARCH_X86_32 0 121 | #endif 122 | 123 | #if defined(__x86_64__) || defined(_M_X64) 124 | #define HWY_ARCH_X86_64 1 125 | #else 126 | #define HWY_ARCH_X86_64 0 127 | #endif 128 | 129 | #if HWY_ARCH_X86_32 && HWY_ARCH_X86_64 130 | #error "Cannot have both x86-32 and x86-64" 131 | #endif 132 | 133 | #if HWY_ARCH_X86_32 || HWY_ARCH_X86_64 134 | #define HWY_ARCH_X86 1 135 | #else 136 | #define HWY_ARCH_X86 0 137 | #endif 138 | 139 | #if defined(__powerpc64__) || defined(_M_PPC) 140 | #define HWY_ARCH_PPC 1 141 | #else 142 | #define HWY_ARCH_PPC 0 143 | #endif 144 | 145 | #if defined(__ARM_ARCH_ISA_A64) || defined(__aarch64__) || defined(_M_ARM64) 146 | #define HWY_ARCH_ARM_A64 1 147 | #else 148 | #define HWY_ARCH_ARM_A64 0 149 | #endif 150 | 151 | #if defined(__arm__) || defined(_M_ARM) 152 | #define HWY_ARCH_ARM_V7 1 153 | #else 154 | #define HWY_ARCH_ARM_V7 0 155 | #endif 156 | 157 | #if HWY_ARCH_ARM_A64 && HWY_ARCH_ARM_V7 158 | #error "Cannot have both A64 and V7" 159 | #endif 160 | 161 | #if HWY_ARCH_ARM_A64 || HWY_ARCH_ARM_V7 162 | #define HWY_ARCH_ARM 1 163 | #else 164 | #define HWY_ARCH_ARM 0 165 | #endif 166 | 167 | #if defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__WASM__) 168 | #define HWY_ARCH_WASM 1 169 | #else 170 | #define HWY_ARCH_WASM 0 171 | #endif 172 | 173 | #ifdef __riscv 174 | #define HWY_ARCH_RVV 1 175 | #else 176 | #define HWY_ARCH_RVV 0 177 | #endif 178 | 179 | #endif // defined(HWY_EMULATE_SVE) 180 | 181 | // It is an error to detect multiple architectures at the same time, but OK to 182 | // detect none of the above. 183 | #if (HWY_ARCH_X86 + HWY_ARCH_PPC + HWY_ARCH_ARM + HWY_ARCH_WASM + \ 184 | HWY_ARCH_RVV) > 1 185 | #error "Must not detect more than one architecture" 186 | #endif 187 | 188 | #endif // HIGHWAY_HWY_DETECT_COMPILER_ARCH_H_ 189 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/examples/skeleton-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Demo of functions that might be called from multiple SIMD modules (either 16 | // other -inl.h files, or a .cc file between begin/end_target-inl). This is 17 | // optional - all SIMD code can reside in .cc files. However, this allows 18 | // splitting code into different files while still inlining instead of requiring 19 | // calling through function pointers. 20 | 21 | // Include guard (still compiled once per target) 22 | #if defined(HIGHWAY_HWY_EXAMPLES_SKELETON_INL_H_) == defined(HWY_TARGET_TOGGLE) 23 | #ifdef HIGHWAY_HWY_EXAMPLES_SKELETON_INL_H_ 24 | #undef HIGHWAY_HWY_EXAMPLES_SKELETON_INL_H_ 25 | #else 26 | #define HIGHWAY_HWY_EXAMPLES_SKELETON_INL_H_ 27 | #endif 28 | 29 | // It is fine to #include normal or *-inl headers. 30 | #include 31 | 32 | #include "hwy/highway.h" 33 | 34 | HWY_BEFORE_NAMESPACE(); 35 | namespace skeleton { 36 | namespace HWY_NAMESPACE { 37 | 38 | using namespace hwy::HWY_NAMESPACE; 39 | 40 | // Example of a type-agnostic (caller-specified lane type) and width-agnostic 41 | // (uses best available instruction set) function in a header. 42 | // 43 | // Computes x[i] = mul_array[i] * x_array[i] + add_array[i] for i < size. 44 | template 45 | HWY_MAYBE_UNUSED void MulAddLoop(const D d, const T* HWY_RESTRICT mul_array, 46 | const T* HWY_RESTRICT add_array, 47 | const size_t size, T* HWY_RESTRICT x_array) { 48 | for (size_t i = 0; i < size; i += Lanes(d)) { 49 | const auto mul = Load(d, mul_array + i); 50 | const auto add = Load(d, add_array + i); 51 | auto x = Load(d, x_array + i); 52 | x = MulAdd(mul, x, add); 53 | Store(x, d, x_array + i); 54 | } 55 | } 56 | 57 | // NOLINTNEXTLINE(google-readability-namespace-comments) 58 | } // namespace HWY_NAMESPACE 59 | } // namespace skeleton 60 | HWY_AFTER_NAMESPACE(); 61 | 62 | #endif // include guard 63 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/examples/skeleton.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "hwy/examples/skeleton.h" 16 | 17 | #include 18 | 19 | // First undef to prevent error when re-included. 20 | #undef HWY_TARGET_INCLUDE 21 | // For runtime dispatch, specify the name of the current file (unfortunately 22 | // __FILE__ is not reliable) so that foreach_target.h can re-include it. 23 | #define HWY_TARGET_INCLUDE "hwy/examples/skeleton.cc" 24 | // Generates code for each enabled target by re-including this source file. 25 | #include "hwy/foreach_target.h" 26 | 27 | #include "hwy/highway.h" 28 | 29 | // Optional, can instead add HWY_ATTR to all functions. 30 | HWY_BEFORE_NAMESPACE(); 31 | namespace skeleton { 32 | namespace HWY_NAMESPACE { 33 | 34 | // Highway ops reside here; ADL does not find templates nor builtins. 35 | using namespace hwy::HWY_NAMESPACE; 36 | 37 | // For reasons unknown, optimized msan builds encounter long build times here; 38 | // work around it until a cause is found. 39 | #if HWY_COMPILER_CLANG && defined(MEMORY_SANITIZER) && defined(__OPTIMIZE__) 40 | #define ATTR_MSAN __attribute__((optnone)) 41 | #else 42 | #define ATTR_MSAN 43 | #endif 44 | 45 | // Computes log2 by converting to a vector of floats. Compiled once per target. 46 | template 47 | ATTR_MSAN void OneFloorLog2(const DF df, const uint8_t* HWY_RESTRICT values, 48 | uint8_t* HWY_RESTRICT log2) { 49 | // Type tags for converting to other element types (Rebind = same count). 50 | const Rebind d32; 51 | const Rebind d8; 52 | 53 | const auto u8 = Load(d8, values); 54 | const auto bits = BitCast(d32, ConvertTo(df, PromoteTo(d32, u8))); 55 | const auto exponent = Sub(ShiftRight<23>(bits), Set(d32, 127)); 56 | Store(DemoteTo(d8, exponent), d8, log2); 57 | } 58 | 59 | void CodepathDemo() { 60 | // Highway defaults to portability, but per-target codepaths may be selected 61 | // via #if HWY_TARGET == HWY_SSE4 or by testing capability macros: 62 | #if HWY_CAP_INTEGER64 63 | const char* gather = "Has int64"; 64 | #else 65 | const char* gather = "No int64"; 66 | #endif 67 | printf("Target %s: %s\n", hwy::TargetName(HWY_TARGET), gather); 68 | } 69 | 70 | void FloorLog2(const uint8_t* HWY_RESTRICT values, size_t count, 71 | uint8_t* HWY_RESTRICT log2) { 72 | CodepathDemo(); 73 | 74 | // Second argument is necessary on RVV until it supports fractional lengths. 75 | const ScalableTag df; 76 | 77 | const size_t N = Lanes(df); 78 | size_t i = 0; 79 | for (; i + N <= count; i += N) { 80 | OneFloorLog2(df, values + i, log2 + i); 81 | } 82 | // TODO(janwas): implement 83 | #if HWY_TARGET != HWY_RVV 84 | for (; i < count; ++i) { 85 | OneFloorLog2(HWY_CAPPED(float, 1)(), values + i, log2 + i); 86 | } 87 | #endif 88 | } 89 | 90 | // NOLINTNEXTLINE(google-readability-namespace-comments) 91 | } // namespace HWY_NAMESPACE 92 | } // namespace skeleton 93 | HWY_AFTER_NAMESPACE(); 94 | 95 | #if HWY_ONCE 96 | 97 | namespace skeleton { 98 | 99 | // This macro declares a static array used for dynamic dispatch; it resides in 100 | // the same outer namespace that contains FloorLog2. 101 | HWY_EXPORT(FloorLog2); 102 | 103 | // This function is optional and only needed in the case of exposing it in the 104 | // header file. Otherwise using HWY_DYNAMIC_DISPATCH(FloorLog2) in this module 105 | // is equivalent to inlining this function. 106 | void CallFloorLog2(const uint8_t* HWY_RESTRICT in, const size_t count, 107 | uint8_t* HWY_RESTRICT out) { 108 | return HWY_DYNAMIC_DISPATCH(FloorLog2)(in, count, out); 109 | } 110 | 111 | // Optional: anything to compile only once, e.g. non-SIMD implementations of 112 | // public functions provided by this module, can go inside #if HWY_ONCE. 113 | 114 | } // namespace skeleton 115 | #endif // HWY_ONCE 116 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/examples/skeleton.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Demo interface to target-specific code in skeleton.cc 16 | 17 | // Normal header with include guard and namespace. 18 | #ifndef HIGHWAY_HWY_EXAMPLES_SKELETON_H_ 19 | #define HIGHWAY_HWY_EXAMPLES_SKELETON_H_ 20 | 21 | #include 22 | 23 | // Platform-specific definitions used for declaring an interface, independent of 24 | // the SIMD instruction set. 25 | #include "hwy/base.h" // HWY_RESTRICT 26 | 27 | namespace skeleton { 28 | 29 | // Computes base-2 logarithm by converting to float. Supports dynamic dispatch. 30 | void CallFloorLog2(const uint8_t* HWY_RESTRICT in, const size_t count, 31 | uint8_t* HWY_RESTRICT out); 32 | 33 | } // namespace skeleton 34 | 35 | #endif // HIGHWAY_HWY_EXAMPLES_SKELETON_H_ 36 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/examples/skeleton_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Example of unit test for the "skeleton" library. 16 | 17 | #include "hwy/examples/skeleton.h" 18 | 19 | #include 20 | 21 | #undef HWY_TARGET_INCLUDE 22 | #define HWY_TARGET_INCLUDE "examples/skeleton_test.cc" 23 | #include "hwy/foreach_target.h" 24 | #include "hwy/highway.h" 25 | #include "hwy/tests/test_util-inl.h" 26 | 27 | // Optional: factor out parts of the implementation into *-inl.h 28 | #include "hwy/examples/skeleton-inl.h" 29 | 30 | HWY_BEFORE_NAMESPACE(); 31 | namespace skeleton { 32 | namespace HWY_NAMESPACE { 33 | 34 | using namespace hwy::HWY_NAMESPACE; 35 | 36 | // Calls function defined in skeleton.cc. 37 | struct TestFloorLog2 { 38 | template 39 | HWY_NOINLINE void operator()(T /*unused*/, DF df) { 40 | const size_t count = 5 * Lanes(df); 41 | auto in = hwy::AllocateAligned(count); 42 | auto expected = hwy::AllocateAligned(count); 43 | 44 | hwy::RandomState rng; 45 | for (size_t i = 0; i < count; ++i) { 46 | expected[i] = Random32(&rng) & 7; 47 | in[i] = static_cast(1u << expected[i]); 48 | } 49 | auto out = hwy::AllocateAligned(count); 50 | CallFloorLog2(in.get(), count, out.get()); 51 | int sum = 0; 52 | for (size_t i = 0; i < count; ++i) { 53 | // TODO(janwas): implement 54 | #if HWY_TARGET != HWY_RVV 55 | HWY_ASSERT_EQ(expected[i], out[i]); 56 | #endif 57 | sum += out[i]; 58 | } 59 | hwy::PreventElision(sum); 60 | } 61 | }; 62 | 63 | HWY_NOINLINE void TestAllFloorLog2() { 64 | ForPartialVectors()(float()); 65 | } 66 | 67 | // Calls function defined in skeleton-inl.h. 68 | struct TestSumMulAdd { 69 | template 70 | HWY_NOINLINE void operator()(T /*unused*/, D d) { 71 | hwy::RandomState rng; 72 | const size_t count = 4096; 73 | EXPECT_TRUE(count % Lanes(d) == 0); 74 | auto mul = hwy::AllocateAligned(count); 75 | auto x = hwy::AllocateAligned(count); 76 | auto add = hwy::AllocateAligned(count); 77 | for (size_t i = 0; i < count; ++i) { 78 | mul[i] = static_cast(Random32(&rng) & 0xF); 79 | x[i] = static_cast(Random32(&rng) & 0xFF); 80 | add[i] = static_cast(Random32(&rng) & 0xFF); 81 | } 82 | double expected_sum = 0.0; 83 | for (size_t i = 0; i < count; ++i) { 84 | expected_sum += mul[i] * x[i] + add[i]; 85 | } 86 | 87 | MulAddLoop(d, mul.get(), add.get(), count, x.get()); 88 | HWY_ASSERT_EQ(4344240.0, expected_sum); 89 | } 90 | }; 91 | 92 | HWY_NOINLINE void TestAllSumMulAdd() { 93 | ForFloatTypes(ForPartialVectors()); 94 | } 95 | 96 | // NOLINTNEXTLINE(google-readability-namespace-comments) 97 | } // namespace HWY_NAMESPACE 98 | } // namespace skeleton 99 | HWY_AFTER_NAMESPACE(); 100 | 101 | #if HWY_ONCE 102 | 103 | namespace skeleton { 104 | HWY_BEFORE_TEST(SkeletonTest); 105 | HWY_EXPORT_AND_TEST_P(SkeletonTest, TestAllFloorLog2); 106 | HWY_EXPORT_AND_TEST_P(SkeletonTest, TestAllSumMulAdd); 107 | } // namespace skeleton 108 | 109 | // Ought not to be necessary, but without this, no tests run on RVV. 110 | int main(int argc, char **argv) { 111 | ::testing::InitGoogleTest(&argc, argv); 112 | return RUN_ALL_TESTS(); 113 | } 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/foreach_target.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef HIGHWAY_HWY_FOREACH_TARGET_H_ 16 | #define HIGHWAY_HWY_FOREACH_TARGET_H_ 17 | 18 | // Re-includes the translation unit zero or more times to compile for any 19 | // targets except HWY_STATIC_TARGET. Defines unique HWY_TARGET each time so that 20 | // highway.h defines the corresponding macro/namespace. 21 | 22 | #include "hwy/detect_targets.h" 23 | 24 | // *_inl.h may include other headers, which requires include guards to prevent 25 | // repeated inclusion. The guards must be reset after compiling each target, so 26 | // the header is again visible. This is done by flipping HWY_TARGET_TOGGLE, 27 | // defining it if undefined and vice versa. This macro is initially undefined 28 | // so that IDEs don't gray out the contents of each header. 29 | #ifdef HWY_TARGET_TOGGLE 30 | #error "This macro must not be defined outside foreach_target.h" 31 | #endif 32 | 33 | #ifdef HWY_HIGHWAY_INCLUDED // highway.h include guard 34 | // Trigger fixup at the bottom of this header. 35 | #define HWY_ALREADY_INCLUDED 36 | 37 | // The next highway.h must re-include set_macros-inl.h because the first 38 | // highway.h chose the static target instead of what we will set below. 39 | #undef HWY_SET_MACROS_PER_TARGET 40 | #endif 41 | 42 | // Disable HWY_EXPORT in user code until we have generated all targets. Note 43 | // that a subsequent highway.h will not override this definition. 44 | #undef HWY_ONCE 45 | #define HWY_ONCE (0 || HWY_IDE) 46 | 47 | // Avoid warnings on #include HWY_TARGET_INCLUDE by hiding them from the IDE; 48 | // also skip if only 1 target defined (no re-inclusion will be necessary). 49 | #if !HWY_IDE && (HWY_TARGETS != HWY_STATIC_TARGET) 50 | 51 | #if !defined(HWY_TARGET_INCLUDE) 52 | #error ">1 target enabled => define HWY_TARGET_INCLUDE before foreach_target.h" 53 | #endif 54 | 55 | #if (HWY_TARGETS & HWY_SCALAR) && (HWY_STATIC_TARGET != HWY_SCALAR) 56 | #undef HWY_TARGET 57 | #define HWY_TARGET HWY_SCALAR 58 | #include HWY_TARGET_INCLUDE 59 | #ifdef HWY_TARGET_TOGGLE 60 | #undef HWY_TARGET_TOGGLE 61 | #else 62 | #define HWY_TARGET_TOGGLE 63 | #endif 64 | #endif 65 | 66 | #if (HWY_TARGETS & HWY_NEON) && (HWY_STATIC_TARGET != HWY_NEON) 67 | #undef HWY_TARGET 68 | #define HWY_TARGET HWY_NEON 69 | #include HWY_TARGET_INCLUDE 70 | #ifdef HWY_TARGET_TOGGLE 71 | #undef HWY_TARGET_TOGGLE 72 | #else 73 | #define HWY_TARGET_TOGGLE 74 | #endif 75 | #endif 76 | 77 | #if (HWY_TARGETS & HWY_SSSE3) && (HWY_STATIC_TARGET != HWY_SSSE3) 78 | #undef HWY_TARGET 79 | #define HWY_TARGET HWY_SSSE3 80 | #include HWY_TARGET_INCLUDE 81 | #ifdef HWY_TARGET_TOGGLE 82 | #undef HWY_TARGET_TOGGLE 83 | #else 84 | #define HWY_TARGET_TOGGLE 85 | #endif 86 | #endif 87 | 88 | #if (HWY_TARGETS & HWY_SSE4) && (HWY_STATIC_TARGET != HWY_SSE4) 89 | #undef HWY_TARGET 90 | #define HWY_TARGET HWY_SSE4 91 | #include HWY_TARGET_INCLUDE 92 | #ifdef HWY_TARGET_TOGGLE 93 | #undef HWY_TARGET_TOGGLE 94 | #else 95 | #define HWY_TARGET_TOGGLE 96 | #endif 97 | #endif 98 | 99 | #if (HWY_TARGETS & HWY_AVX2) && (HWY_STATIC_TARGET != HWY_AVX2) 100 | #undef HWY_TARGET 101 | #define HWY_TARGET HWY_AVX2 102 | #include HWY_TARGET_INCLUDE 103 | #ifdef HWY_TARGET_TOGGLE 104 | #undef HWY_TARGET_TOGGLE 105 | #else 106 | #define HWY_TARGET_TOGGLE 107 | #endif 108 | #endif 109 | 110 | #if (HWY_TARGETS & HWY_AVX3) && (HWY_STATIC_TARGET != HWY_AVX3) 111 | #undef HWY_TARGET 112 | #define HWY_TARGET HWY_AVX3 113 | #include HWY_TARGET_INCLUDE 114 | #ifdef HWY_TARGET_TOGGLE 115 | #undef HWY_TARGET_TOGGLE 116 | #else 117 | #define HWY_TARGET_TOGGLE 118 | #endif 119 | #endif 120 | 121 | #if (HWY_TARGETS & HWY_AVX3_DL) && (HWY_STATIC_TARGET != HWY_AVX3_DL) 122 | #undef HWY_TARGET 123 | #define HWY_TARGET HWY_AVX3_DL 124 | #include HWY_TARGET_INCLUDE 125 | #ifdef HWY_TARGET_TOGGLE 126 | #undef HWY_TARGET_TOGGLE 127 | #else 128 | #define HWY_TARGET_TOGGLE 129 | #endif 130 | #endif 131 | 132 | #if (HWY_TARGETS & HWY_WASM) && (HWY_STATIC_TARGET != HWY_WASM) 133 | #undef HWY_TARGET 134 | #define HWY_TARGET HWY_WASM 135 | #include HWY_TARGET_INCLUDE 136 | #ifdef HWY_TARGET_TOGGLE 137 | #undef HWY_TARGET_TOGGLE 138 | #else 139 | #define HWY_TARGET_TOGGLE 140 | #endif 141 | #endif 142 | 143 | #if (HWY_TARGETS & HWY_PPC8) && (HWY_STATIC_TARGET != HWY_PPC8) 144 | #undef HWY_TARGET 145 | #define HWY_TARGET HWY_PPC8 146 | #include HWY_TARGET_INCLUDE 147 | #ifdef HWY_TARGET_TOGGLE 148 | #undef HWY_TARGET_TOGGLE 149 | #else 150 | #define HWY_TARGET_TOGGLE 151 | #endif 152 | #endif 153 | 154 | #endif // !HWY_IDE && (HWY_TARGETS != HWY_STATIC_TARGET) 155 | 156 | // Now that all but the static target have been generated, re-enable HWY_EXPORT. 157 | #undef HWY_ONCE 158 | #define HWY_ONCE 1 159 | 160 | // If we re-include once per enabled target, the translation unit's 161 | // implementation would have to be skipped via #if to avoid redefining symbols. 162 | // We instead skip the re-include for HWY_STATIC_TARGET, and generate its 163 | // implementation when resuming compilation of the translation unit. 164 | #undef HWY_TARGET 165 | #define HWY_TARGET HWY_STATIC_TARGET 166 | 167 | #ifdef HWY_ALREADY_INCLUDED 168 | // Revert the previous toggle to prevent redefinitions for the static target. 169 | #ifdef HWY_TARGET_TOGGLE 170 | #undef HWY_TARGET_TOGGLE 171 | #else 172 | #define HWY_TARGET_TOGGLE 173 | #endif 174 | 175 | // Force re-inclusion of set_macros-inl.h now that HWY_TARGET is restored. 176 | #ifdef HWY_SET_MACROS_PER_TARGET 177 | #undef HWY_SET_MACROS_PER_TARGET 178 | #else 179 | #define HWY_SET_MACROS_PER_TARGET 180 | #endif 181 | #endif 182 | 183 | #endif // HIGHWAY_HWY_FOREACH_TARGET_H_ 184 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/nanobenchmark_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "hwy/nanobenchmark.h" 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include "hwy/tests/test_util-inl.h" 22 | 23 | namespace hwy { 24 | namespace { 25 | 26 | // Governs duration of test; avoid timeout in debug builds. 27 | #if HWY_IS_DEBUG_BUILD 28 | constexpr size_t kMaxEvals = 3; 29 | #else 30 | constexpr size_t kMaxEvals = 4; 31 | #endif 32 | 33 | FuncOutput Div(const void*, FuncInput in) { 34 | // Here we're measuring the throughput because benchmark invocations are 35 | // independent. Any dividend will do; the divisor is nonzero. 36 | return 0xFFFFF / in; 37 | } 38 | 39 | template 40 | void MeasureDiv(const FuncInput (&inputs)[N]) { 41 | printf("Measuring integer division (output on final two lines)\n"); 42 | Result results[N]; 43 | Params params; 44 | params.max_evals = kMaxEvals; 45 | const size_t num_results = Measure(&Div, nullptr, inputs, N, results, params); 46 | for (size_t i = 0; i < num_results; ++i) { 47 | printf("%5zu: %6.2f ticks; MAD=%4.2f%%\n", results[i].input, 48 | results[i].ticks, results[i].variability * 100.0); 49 | } 50 | } 51 | 52 | std::mt19937 rng; 53 | 54 | // A function whose runtime depends on rng. 55 | FuncOutput Random(const void* /*arg*/, FuncInput in) { 56 | const size_t r = rng() & 0xF; 57 | uint32_t ret = in; 58 | for (size_t i = 0; i < r; ++i) { 59 | ret /= ((rng() & 1) + 2); 60 | } 61 | return ret; 62 | } 63 | 64 | // Ensure the measured variability is high. 65 | template 66 | void MeasureRandom(const FuncInput (&inputs)[N]) { 67 | Result results[N]; 68 | Params p; 69 | p.max_evals = kMaxEvals; 70 | p.verbose = false; 71 | const size_t num_results = Measure(&Random, nullptr, inputs, N, results, p); 72 | for (size_t i = 0; i < num_results; ++i) { 73 | NANOBENCHMARK_CHECK(results[i].variability > 1E-3); 74 | } 75 | } 76 | 77 | TEST(NanobenchmarkTest, RunAll) { 78 | const int unpredictable = Unpredictable1(); // == 1, unknown to compiler. 79 | static const FuncInput inputs[] = {static_cast(unpredictable) + 2, 80 | static_cast(unpredictable + 9)}; 81 | 82 | MeasureDiv(inputs); 83 | MeasureRandom(inputs); 84 | } 85 | 86 | } // namespace 87 | } // namespace hwy 88 | 89 | // Ought not to be necessary, but without this, no tests run on RVV. 90 | int main(int argc, char** argv) { 91 | ::testing::InitGoogleTest(&argc, argv); 92 | return RUN_ALL_TESTS(); 93 | } 94 | -------------------------------------------------------------------------------- /source/thirdparty/highway/hwy/targets_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "hwy/targets.h" 16 | 17 | #include "hwy/tests/test_util-inl.h" 18 | 19 | namespace fake { 20 | 21 | #define DECLARE_FUNCTION(TGT) \ 22 | namespace N_##TGT { \ 23 | uint32_t FakeFunction(int) { return HWY_##TGT; } \ 24 | } 25 | 26 | DECLARE_FUNCTION(AVX3_DL) 27 | DECLARE_FUNCTION(AVX3) 28 | DECLARE_FUNCTION(AVX2) 29 | DECLARE_FUNCTION(SSE4) 30 | DECLARE_FUNCTION(SSSE3) 31 | DECLARE_FUNCTION(NEON) 32 | DECLARE_FUNCTION(SVE) 33 | DECLARE_FUNCTION(SVE2) 34 | DECLARE_FUNCTION(PPC8) 35 | DECLARE_FUNCTION(WASM) 36 | DECLARE_FUNCTION(RVV) 37 | DECLARE_FUNCTION(SCALAR) 38 | 39 | HWY_EXPORT(FakeFunction); 40 | 41 | void CheckFakeFunction() { 42 | #define CHECK_ARRAY_ENTRY(TGT) \ 43 | if ((HWY_TARGETS & HWY_##TGT) != 0) { \ 44 | hwy::SetSupportedTargetsForTest(HWY_##TGT); \ 45 | /* Calling Update() first to make &HWY_DYNAMIC_DISPATCH() return */ \ 46 | /* the pointer to the already cached function. */ \ 47 | hwy::chosen_target.Update(); \ 48 | EXPECT_EQ(uint32_t(HWY_##TGT), HWY_DYNAMIC_DISPATCH(FakeFunction)(42)); \ 49 | /* Calling DeInit() will test that the initializer function */ \ 50 | /* also calls the right function. */ \ 51 | hwy::chosen_target.DeInit(); \ 52 | EXPECT_EQ(uint32_t(HWY_##TGT), HWY_DYNAMIC_DISPATCH(FakeFunction)(42)); \ 53 | /* Second call uses the cached value from the previous call. */ \ 54 | EXPECT_EQ(uint32_t(HWY_##TGT), HWY_DYNAMIC_DISPATCH(FakeFunction)(42)); \ 55 | } 56 | CHECK_ARRAY_ENTRY(AVX3_DL) 57 | CHECK_ARRAY_ENTRY(AVX3) 58 | CHECK_ARRAY_ENTRY(AVX2) 59 | CHECK_ARRAY_ENTRY(SSE4) 60 | CHECK_ARRAY_ENTRY(SSSE3) 61 | CHECK_ARRAY_ENTRY(NEON) 62 | CHECK_ARRAY_ENTRY(SVE) 63 | CHECK_ARRAY_ENTRY(SVE2) 64 | CHECK_ARRAY_ENTRY(PPC8) 65 | CHECK_ARRAY_ENTRY(WASM) 66 | CHECK_ARRAY_ENTRY(RVV) 67 | CHECK_ARRAY_ENTRY(SCALAR) 68 | #undef CHECK_ARRAY_ENTRY 69 | } 70 | 71 | } // namespace fake 72 | 73 | namespace hwy { 74 | 75 | class HwyTargetsTest : public testing::Test { 76 | protected: 77 | void TearDown() override { 78 | SetSupportedTargetsForTest(0); 79 | DisableTargets(0); // Reset the mask. 80 | } 81 | }; 82 | 83 | // Test that the order in the HWY_EXPORT static array matches the expected 84 | // value of the target bits. This is only checked for the targets that are 85 | // enabled in the current compilation. 86 | TEST_F(HwyTargetsTest, ChosenTargetOrderTest) { fake::CheckFakeFunction(); } 87 | 88 | TEST_F(HwyTargetsTest, DisabledTargetsTest) { 89 | DisableTargets(~0u); 90 | // Check that the baseline can't be disabled. 91 | HWY_ASSERT(HWY_ENABLED_BASELINE == SupportedTargets()); 92 | 93 | DisableTargets(0); // Reset the mask. 94 | uint32_t current_targets = SupportedTargets(); 95 | if ((current_targets & ~uint32_t(HWY_ENABLED_BASELINE)) == 0) { 96 | // We can't test anything else if the only compiled target is the baseline. 97 | return; 98 | } 99 | // Get the lowest bit in the mask (the best target) and disable that one. 100 | uint32_t lowest_target = current_targets & (~current_targets + 1); 101 | // The lowest target shouldn't be one in the baseline. 102 | HWY_ASSERT((lowest_target & ~uint32_t(HWY_ENABLED_BASELINE)) != 0); 103 | DisableTargets(lowest_target); 104 | 105 | // Check that the other targets are still enabled. 106 | HWY_ASSERT((lowest_target ^ current_targets) == SupportedTargets()); 107 | DisableTargets(0); // Reset the mask. 108 | } 109 | 110 | } // namespace hwy 111 | 112 | // Ought not to be necessary, but without this, no tests run on RVV. 113 | int main(int argc, char **argv) { 114 | ::testing::InitGoogleTest(&argc, argv); 115 | return RUN_ALL_TESTS(); 116 | } 117 | -------------------------------------------------------------------------------- /source/thirdparty/highway/libhwy-contrib.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: libhwy-contrib 7 | Description: Additions to Highway: image and math library 8 | Version: @HWY_LIBRARY_VERSION@ 9 | Libs: -L${libdir} -lhwy_contrib 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /source/thirdparty/highway/libhwy-test.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ 3 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 4 | 5 | Name: libhwy-test 6 | Description: Efficient and performance-portable SIMD wrapper, test helpers. 7 | Requires: gtest 8 | Version: @HWY_LIBRARY_VERSION@ 9 | Libs: -L${libdir} -lhwy_test 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /source/thirdparty/highway/libhwy.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: libhwy 7 | Description: Efficient and performance-portable SIMD wrapper 8 | Version: @HWY_LIBRARY_VERSION@ 9 | Libs: -L${libdir} -lhwy 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /source/thirdparty/highway/run_tests.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM Switch directory of this batch file 3 | cd %~dp0 4 | 5 | if not exist build_win mkdir build_win 6 | 7 | cd build_win 8 | cmake .. -DHWY_WARNINGS_ARE_ERRORS:BOOL=ON -G Ninja || goto error 9 | ninja || goto error 10 | ctest -j || goto error 11 | 12 | cd .. 13 | echo Success 14 | goto end 15 | 16 | :error 17 | echo Failure 18 | exit /b 1 19 | 20 | :end 21 | -------------------------------------------------------------------------------- /source/thirdparty/highway/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Switch to directory of this script 4 | MYDIR=$(dirname $(realpath "$0")) 5 | cd "${MYDIR}" 6 | 7 | # Exit if anything fails 8 | set -e 9 | 10 | mkdir -p build 11 | cd build 12 | cmake .. -DHWY_WARNINGS_ARE_ERRORS:BOOL=ON 13 | make -j 14 | ctest -j 15 | echo Success 16 | -------------------------------------------------------------------------------- /subprojects/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | project ( 4 | open_htj2k 5 | LANGUAGES CXX 6 | ) 7 | 8 | message(STATUS "**** WASM BUILD") 9 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/html) 10 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/html) 11 | 12 | set(WASM_FLAGS "\ 13 | -03 -s WASM=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s ENVIRONMENT=web \ 14 | -s EXPORTED_FUNCTIONS=[_free,_malloc] \ 15 | -s EXPORTED_RUNTIME_METHODS=[ccall,cwrap,writeArrayToMemory,getValue] \ 16 | -s NO_EXIT_RUNTIME=1 \ 17 | -s ALLOW_MEMORY_GROWTH=1 \ 18 | -sASSERTIONS \ 19 | -sNO_DISABLE_EXCEPTION_CATCHING \ 20 | " 21 | ) 22 | add_subdirectory(".." open_htj2k EXCLUDE_FROM_ALL) 23 | add_executable(libopen_htj2k "src/wrapper.cpp") 24 | set_target_properties(libopen_htj2k PROPERTIES SUFFIX ".js" LINK_FLAGS ${WASM_FLAGS}) 25 | target_link_libraries(libopen_htj2k PRIVATE open_htj2k) 26 | 27 | add_executable(libopen_htj2k_simd "src/wrapper.cpp") 28 | target_compile_definitions(libopen_htj2k_simd PUBLIC "OPENHTJ2K_ENABLE_ARM_NEON") 29 | set_target_properties(libopen_htj2k_simd PROPERTIES COMPILE_FLAGS "-msimd128 -mfpu=neon") 30 | set_target_properties(libopen_htj2k_simd PROPERTIES SUFFIX ".js" LINK_FLAGS ${WASM_FLAGS}) 31 | target_link_libraries(libopen_htj2k_simd PRIVATE open_htj2k) -------------------------------------------------------------------------------- /subprojects/src/wrapper.cpp: -------------------------------------------------------------------------------- 1 | #ifdef __EMSCRIPTEN__ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "decoder.hpp" 11 | 12 | open_htj2k::openhtj2k_decoder* cpp_create_decoder(uint8_t* data, size_t size, uint8_t reduce_NL) { 13 | return new open_htj2k::openhtj2k_decoder(data, size, reduce_NL, 1); 14 | } 15 | 16 | void cpp_parse_j2c_data(open_htj2k::openhtj2k_decoder* dec) { dec->parse(); } 17 | void cpp_invoke_decoder(open_htj2k::openhtj2k_decoder* dec, int32_t* out) { 18 | const uint16_t num_components = dec->get_num_component(); 19 | std::vector buf; 20 | std::vector img_width; 21 | std::vector img_height; 22 | std::vector img_depth; 23 | std::vector img_signed; 24 | dec->invoke(buf, img_width, img_height, img_depth, img_signed); 25 | for (uint32_t y = 0; y < img_height[0]; ++y) { 26 | for (uint32_t x = 0; x < img_width[0]; ++x) { 27 | for (uint16_t c = 0; c < num_components; ++c) { 28 | out[y * img_width[0] * num_components + x * num_components + c] = buf[c][y * img_width[0] + x]; 29 | } 30 | } 31 | } 32 | } 33 | 34 | void cpp_release_j2c_data(open_htj2k::openhtj2k_decoder* dec) { delete dec; } 35 | 36 | uint16_t cpp_get_num_components(open_htj2k::openhtj2k_decoder* dec) { return dec->get_num_component(); }; 37 | 38 | uint32_t cpp_get_width(open_htj2k::openhtj2k_decoder* dec, uint16_t c) { 39 | return dec->get_component_width(c); 40 | } 41 | 42 | uint32_t cpp_get_height(open_htj2k::openhtj2k_decoder* dec, uint16_t c) { 43 | return dec->get_component_height(c); 44 | } 45 | 46 | uint8_t cpp_get_depth(open_htj2k::openhtj2k_decoder* dec, uint16_t c) { 47 | return dec->get_component_depth(c); 48 | } 49 | 50 | bool cpp_get_signed(open_htj2k::openhtj2k_decoder* dec, uint16_t c) { 51 | return dec->get_component_signedness(c); 52 | } 53 | 54 | uint8_t cpp_get_minimum_DWT_levels(open_htj2k::openhtj2k_decoder* dec) { 55 | return dec->get_minumum_DWT_levels(); 56 | } 57 | 58 | ////////////////////////////////////////////////////////////////////////////////////////////////// 59 | extern "C" { 60 | EMSCRIPTEN_KEEPALIVE 61 | open_htj2k::openhtj2k_decoder* create_decoder(uint8_t* data, size_t size, uint8_t reduce_NL) { 62 | return cpp_create_decoder(data, size, reduce_NL); 63 | } 64 | 65 | EMSCRIPTEN_KEEPALIVE 66 | void parse_j2c_data(open_htj2k::openhtj2k_decoder* dec) { cpp_parse_j2c_data(dec); } 67 | 68 | EMSCRIPTEN_KEEPALIVE 69 | void invoke_decoder(open_htj2k::openhtj2k_decoder* dec, int32_t* out) { cpp_invoke_decoder(dec, out); } 70 | 71 | EMSCRIPTEN_KEEPALIVE 72 | void release_j2c_data(open_htj2k::openhtj2k_decoder* dec) { cpp_release_j2c_data(dec); } 73 | 74 | EMSCRIPTEN_KEEPALIVE 75 | uint16_t get_num_components(open_htj2k::openhtj2k_decoder* dec) { return cpp_get_num_components(dec); } 76 | 77 | EMSCRIPTEN_KEEPALIVE 78 | uint32_t get_width(open_htj2k::openhtj2k_decoder* dec, uint16_t c) { return cpp_get_width(dec, c); } 79 | 80 | EMSCRIPTEN_KEEPALIVE 81 | uint32_t get_height(open_htj2k::openhtj2k_decoder* dec, uint16_t c) { return cpp_get_height(dec, c); } 82 | 83 | EMSCRIPTEN_KEEPALIVE 84 | uint32_t get_depth(open_htj2k::openhtj2k_decoder* dec, uint16_t c) { return cpp_get_depth(dec, c); } 85 | 86 | EMSCRIPTEN_KEEPALIVE 87 | uint32_t get_signed(open_htj2k::openhtj2k_decoder* dec, uint16_t c) { return cpp_get_signed(dec, c); } 88 | 89 | EMSCRIPTEN_KEEPALIVE 90 | uint32_t get_minimum_DWT_levels(open_htj2k::openhtj2k_decoder* dec) { 91 | return cpp_get_minimum_DWT_levels(dec); 92 | } 93 | } 94 | 95 | #endif -------------------------------------------------------------------------------- /tests/decoder_conformance.cmake: -------------------------------------------------------------------------------- 1 | # Conformance testing by Ctest 2 | enable_testing() 3 | set(CONFORMANCE_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/conformance_data") 4 | 5 | ## Conformance tests for HT 6 | # PROFILE 0 7 | include(${CMAKE_CURRENT_SOURCE_DIR}/tests/ht_profile0.cmake) 8 | # PROFILE 1 9 | include(${CMAKE_CURRENT_SOURCE_DIR}/tests/ht_profile1.cmake) 10 | # HiFi 11 | include(${CMAKE_CURRENT_SOURCE_DIR}/tests/ht_HF.cmake) 12 | ## Part 1 decoding tests 13 | # PROFILE 0 14 | include(${CMAKE_CURRENT_SOURCE_DIR}/tests/part1_profile0.cmake) 15 | # PROFILE 1 16 | include(${CMAKE_CURRENT_SOURCE_DIR}/tests/part1_profile1.cmake) 17 | # HiFi 18 | include(${CMAKE_CURRENT_SOURCE_DIR}/tests/part1_HF.cmake) -------------------------------------------------------------------------------- /tests/encoder_test.cmake: -------------------------------------------------------------------------------- 1 | # Conformance testing by Ctest 2 | enable_testing() 3 | set(CONFORMANCE_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/conformance_data/references") 4 | 5 | add_test(NAME enc_lossless COMMAND open_htj2k_enc -i ${CONFORMANCE_DATA_DIR}/kodim23.ppm -o kodim23lossless.j2c Creversible=yes) 6 | add_test(NAME dec_lossless COMMAND open_htj2k_dec -i kodim23lossless.j2c -o kodim23lossless.ppm) 7 | set_tests_properties(dec_lossless PROPERTIES DEPENDS enc_lossless) 8 | add_test(NAME comp_lossless COMMAND imgcmp kodim23lossless.ppm ${CONFORMANCE_DATA_DIR}/kodim23.ppm 0 0) 9 | set_tests_properties(comp_lossless PROPERTIES DEPENDS dec_lossless) 10 | 11 | add_test(NAME enc_lossy COMMAND open_htj2k_enc -i ${CONFORMANCE_DATA_DIR}/kodim23.ppm -o kodim23lossy.j2c Qfactor=90) 12 | add_test(NAME dec_lossy COMMAND open_htj2k_dec -i kodim23lossy.j2c -o kodim23lossy.ppm) 13 | set_tests_properties(dec_lossy PROPERTIES DEPENDS enc_lossy) 14 | add_test(NAME comp_lossy COMMAND imgcmp kodim23lossy.ppm ${CONFORMANCE_DATA_DIR}/kodim23.ppm 23 6) 15 | set_tests_properties(comp_lossy PROPERTIES DEPENDS dec_lossy) 16 | 17 | add_test(NAME enc_lossless_odd COMMAND open_htj2k_enc -i ${CONFORMANCE_DATA_DIR}/kodim23odd.ppm -o kodim23odd_lossless.j2c Creversible=yes) 18 | add_test(NAME dec_lossless_odd COMMAND open_htj2k_dec -i kodim23odd_lossless.j2c -o kodim23odd_lossless.ppm) 19 | set_tests_properties(dec_lossless_odd PROPERTIES DEPENDS enc_lossless_odd) 20 | add_test(NAME comp_lossless_odd COMMAND imgcmp kodim23odd_lossless.ppm ${CONFORMANCE_DATA_DIR}/kodim23odd.ppm 0 0) 21 | set_tests_properties(comp_lossless_odd PROPERTIES DEPENDS dec_lossless_odd) -------------------------------------------------------------------------------- /tests/ht_HF.cmake: -------------------------------------------------------------------------------- 1 | # Decoding 2 | add_test(NAME dec_HF_ht1_02 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/hifi_ht1_02.j2k -o HF_ht1_02.pgx) 3 | 4 | # calculate PAE and MSE 5 | # 1 6 | add_test(NAME comp_HF_ht1_02_0 COMMAND imgcmp HF_ht1_02_00.pgx ${CONFORMANCE_DATA_DIR}/references/hifi-0.pgx 47 82) 7 | add_test(NAME comp_HF_ht1_02_1 COMMAND imgcmp HF_ht1_02_01.pgx ${CONFORMANCE_DATA_DIR}/references/hifi-1.pgx 36 65) 8 | add_test(NAME comp_HF_ht1_02_2 COMMAND imgcmp HF_ht1_02_02.pgx ${CONFORMANCE_DATA_DIR}/references/hifi-2.pgx 42 86) 9 | set_tests_properties(comp_HF_ht1_02_0 comp_HF_ht1_02_1 comp_HF_ht1_02_2 PROPERTIES DEPENDS dec_HF_ht1_02) 10 | -------------------------------------------------------------------------------- /tests/ht_profile1.cmake: -------------------------------------------------------------------------------- 1 | # Decoding 2 | add_test(NAME dec_p1_ht_01_11 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_01_b11.j2k -o ht_p1_01_b11.pgx) 3 | add_test(NAME dec_p1_ht_01_12 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_01_b12.j2k -o ht_p1_01_b12.pgx) 4 | add_test(NAME dec_p1_ht_02_11 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_02_b11.j2k -o ht_p1_02_b11.pgx) 5 | add_test(NAME dec_p1_ht_02_12 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_02_b12.j2k -o ht_p1_02_b12.pgx) 6 | add_test(NAME dec_p1_ht_03_11 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_03_b11.j2k -o ht_p1_03_b11.pgx) 7 | add_test(NAME dec_p1_ht_03_12 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_03_b12.j2k -o ht_p1_03_b12.pgx) 8 | add_test(NAME dec_p1_ht_04_9 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_04_b9.j2k -o ht_p1_04_b9.pgx) 9 | add_test(NAME dec_p1_ht_05_11 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_05_b11.j2k -o ht_p1_05_b11.pgx) 10 | add_test(NAME dec_p1_ht_06_11 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_06_b11.j2k -o ht_p1_06_b11.pgx) 11 | add_test(NAME dec_p1_ht_07_11 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/ds1_ht_07_b11.j2k -o ht_p1_07_b11.pgx) 12 | 13 | # calculate PAE and MSE 14 | # 1 15 | add_test(NAME comp_p1_ht_01_11 COMMAND imgcmp ht_p1_01_b11_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_01-0.pgx 1 0.001) 16 | add_test(NAME comp_p1_ht_01_12 COMMAND imgcmp ht_p1_01_b12_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_01-0.pgx 0 0) 17 | set_tests_properties(comp_p1_ht_01_11 PROPERTIES DEPENDS dec_p1_ht_01_11) 18 | set_tests_properties(comp_p1_ht_01_12 PROPERTIES DEPENDS dec_p1_ht_01_12) 19 | # 2 20 | add_test(NAME comp_p1_ht_02_11r COMMAND imgcmp ht_p1_02_b11_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-0.pgx 7 0.865) 21 | add_test(NAME comp_p1_ht_02_11g COMMAND imgcmp ht_p1_02_b11_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-1.pgx 6 0.716) 22 | add_test(NAME comp_p1_ht_02_11b COMMAND imgcmp ht_p1_02_b11_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-2.pgx 8 1.151) 23 | add_test(NAME comp_p1_ht_02_12r COMMAND imgcmp ht_p1_02_b12_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-0.pgx 5 0.765) 24 | add_test(NAME comp_p1_ht_02_12g COMMAND imgcmp ht_p1_02_b12_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-1.pgx 4 0.616) 25 | add_test(NAME comp_p1_ht_02_12b COMMAND imgcmp ht_p1_02_b12_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-2.pgx 6 1.051) 26 | set_tests_properties(comp_p1_ht_02_11r comp_p1_ht_02_11g comp_p1_ht_02_11b PROPERTIES DEPENDS dec_p1_ht_02_11) 27 | set_tests_properties(comp_p1_ht_02_12r comp_p1_ht_02_12g comp_p1_ht_02_12b PROPERTIES DEPENDS dec_p1_ht_02_12) 28 | # 3 29 | add_test(NAME comp_p1_ht_03_11a COMMAND imgcmp ht_p1_03_b11_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-0.pgx 2 0.311) # plus 0 30 | add_test(NAME comp_p1_ht_03_11b COMMAND imgcmp ht_p1_03_b11_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-1.pgx 3 0.310) # plus 0.03 31 | add_test(NAME comp_p1_ht_03_11c COMMAND imgcmp ht_p1_03_b11_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-2.pgx 3 0.317) # plus 0.05 32 | add_test(NAME comp_p1_ht_03_11d COMMAND imgcmp ht_p1_03_b11_03.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-3.pgx 2 0.001) # plus 0.001 33 | add_test(NAME comp_p1_ht_03_12a COMMAND imgcmp ht_p1_03_b12_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-0.pgx 2 0.311) # 0.300 in old spec 34 | add_test(NAME comp_p1_ht_03_12b COMMAND imgcmp ht_p1_03_b12_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-1.pgx 2 0.280) # 0.210 in old spec 35 | add_test(NAME comp_p1_ht_03_12c COMMAND imgcmp ht_p1_03_b12_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-2.pgx 1 0.267) # 0.200 in old spec 36 | add_test(NAME comp_p1_ht_03_12d COMMAND imgcmp ht_p1_03_b12_03.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-3.pgx 0 0) 37 | set_tests_properties(comp_p1_ht_03_11a comp_p1_ht_03_11b comp_p1_ht_03_11c comp_p1_ht_03_11d PROPERTIES DEPENDS dec_p1_ht_03_11) 38 | set_tests_properties(comp_p1_ht_03_12a comp_p1_ht_03_12b comp_p1_ht_03_12c comp_p1_ht_03_12d PROPERTIES DEPENDS dec_p1_ht_03_12) 39 | set_tests_properties(comp_p1_ht_03_12b PROPERTIES WILL_FAIL false) 40 | set_tests_properties(comp_p1_ht_03_12c PROPERTIES WILL_FAIL false) 41 | # 4 42 | add_test(NAME comp_p1_ht_04_9 COMMAND imgcmp ht_p1_04_b9_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_04-0.pgx 624 3080) 43 | set_tests_properties(comp_p1_ht_04_9 PROPERTIES DEPENDS dec_p1_ht_04_9) 44 | # 5 45 | add_test(NAME comp_p1_ht_05_11r COMMAND imgcmp ht_p1_05_b11_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_05-0.pgx 40 8.458) 46 | add_test(NAME comp_p1_ht_05_11g COMMAND imgcmp ht_p1_05_b11_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_05-1.pgx 40 9.716) 47 | add_test(NAME comp_p1_ht_05_11b COMMAND imgcmp ht_p1_05_b11_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_05-2.pgx 40 10.154) 48 | set_tests_properties(comp_p1_ht_05_11r comp_p1_ht_05_11g comp_p1_ht_05_11b PROPERTIES DEPENDS dec_p1_ht_05_11) 49 | # 6 50 | add_test(NAME comp_p1_ht_06_11r COMMAND imgcmp ht_p1_06_b11_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_06-0.pgx 2 0.600) 51 | add_test(NAME comp_p1_ht_06_11g COMMAND imgcmp ht_p1_06_b11_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_06-1.pgx 2 0.600) 52 | add_test(NAME comp_p1_ht_06_11b COMMAND imgcmp ht_p1_06_b11_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_06-2.pgx 2 0.600) 53 | set_tests_properties(comp_p1_ht_06_11r comp_p1_ht_06_11g comp_p1_ht_06_11b PROPERTIES DEPENDS dec_p1_ht_06_11) 54 | # 7 55 | add_test(NAME comp_p1_ht_07_11a COMMAND imgcmp ht_p1_07_b11_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_07-0.pgx 0 0) 56 | add_test(NAME comp_p1_ht_07_11b COMMAND imgcmp ht_p1_07_b11_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_07-1.pgx 0 0) 57 | set_tests_properties(comp_p1_ht_07_11a comp_p1_ht_07_11b PROPERTIES DEPENDS dec_p1_ht_07_11) 58 | -------------------------------------------------------------------------------- /tests/part1_HF.cmake: -------------------------------------------------------------------------------- 1 | # Decoding 2 | add_test(NAME dec_HF_p1_02 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/hifi_p1_02.j2k -o HF_p1_02.pgx) 3 | 4 | # calculate PAE and MSE 5 | # 1 6 | add_test(NAME comp_HF_p1_02_0 COMMAND imgcmp HF_p1_02_00.pgx ${CONFORMANCE_DATA_DIR}/references/hifi-0.pgx 43 80) 7 | add_test(NAME comp_HF_p1_02_1 COMMAND imgcmp HF_p1_02_01.pgx ${CONFORMANCE_DATA_DIR}/references/hifi-1.pgx 33 62) 8 | add_test(NAME comp_HF_p1_02_2 COMMAND imgcmp HF_p1_02_02.pgx ${CONFORMANCE_DATA_DIR}/references/hifi-2.pgx 38 72) 9 | set_tests_properties(comp_HF_p1_02_0 comp_HF_p1_02_1 comp_HF_p1_02_2 PROPERTIES DEPENDS dec_HF_p1_02) 10 | -------------------------------------------------------------------------------- /tests/part1_profile0.cmake: -------------------------------------------------------------------------------- 1 | # Decoding 2 | add_test(NAME dec_p0_01 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_01.j2k -o p0_01.pgx) 3 | add_test(NAME dec_p0_02 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_02.j2k -o p0_02.pgx) 4 | add_test(NAME dec_p0_03 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_03.j2k -o p0_03.pgx) 5 | add_test(NAME dec_p0_04 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_04.j2k -o p0_04.pgx) 6 | add_test(NAME dec_p0_05 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_05.j2k -o p0_05.pgx) 7 | add_test(NAME dec_p0_06 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_06.j2k -o p0_06.pgx) 8 | add_test(NAME dec_p0_07 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_07.j2k -o p0_07.pgx) 9 | add_test(NAME dec_p0_08 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_08.j2k -o p0_08.pgx -reduce 1) 10 | add_test(NAME dec_p0_09 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_09.j2k -o p0_09.pgx) 11 | add_test(NAME dec_p0_10 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_10.j2k -o p0_10.pgx) 12 | add_test(NAME dec_p0_11 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_11.j2k -o p0_11.pgx) 13 | add_test(NAME dec_p0_12 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_12.j2k -o p0_12.pgx) 14 | add_test(NAME dec_p0_14 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_14.j2k -o p0_14.pgx) 15 | add_test(NAME dec_p0_15 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_15.j2k -o p0_15.pgx) 16 | add_test(NAME dec_p0_16 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p0_16.j2k -o p0_16.pgx) 17 | 18 | # calculate PAE and MSE 19 | # 1 20 | add_test(NAME comp_p0_01 COMMAND imgcmp p0_01_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_01-0.pgx 0 0) 21 | set_tests_properties(comp_p0_01 PROPERTIES DEPENDS dec_p0_01) 22 | # 2 23 | add_test(NAME comp_p0_02 COMMAND imgcmp p0_02_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_02-0.pgx 0 0) 24 | set_tests_properties(comp_p0_02 PROPERTIES DEPENDS dec_p0_02) 25 | # 3 26 | add_test(NAME comp_p0_03 COMMAND imgcmp p0_03_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_03-0.pgx 0 0) 27 | set_tests_properties(comp_p0_03 PROPERTIES DEPENDS dec_p0_03) 28 | # 4 29 | add_test(NAME comp_p0_04_r COMMAND imgcmp p0_04_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_04-0.pgx 5 0.776) 30 | add_test(NAME comp_p0_04_g COMMAND imgcmp p0_04_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_04-1.pgx 4 0.626) 31 | add_test(NAME comp_p0_04_b COMMAND imgcmp p0_04_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_04-2.pgx 6 1.070) 32 | set_tests_properties(comp_p0_04_r comp_p0_04_g comp_p0_04_b PROPERTIES DEPENDS dec_p0_04) 33 | # 5 34 | add_test(NAME comp_p0_05_a COMMAND imgcmp p0_05_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_05-0.pgx 2 0.319) # 0.302 in old spec 35 | add_test(NAME comp_p0_05_b COMMAND imgcmp p0_05_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_05-1.pgx 2 0.323) # 0.307 in old spec 36 | add_test(NAME comp_p0_05_c COMMAND imgcmp p0_05_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_05-2.pgx 2 0.317) # 0.269 in old spec 37 | add_test(NAME comp_p0_05_d COMMAND imgcmp p0_05_03.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_05-3.pgx 0 0) 38 | set_tests_properties(comp_p0_05_a comp_p0_05_b comp_p0_05_c comp_p0_05_d PROPERTIES DEPENDS dec_p0_05) 39 | # 6 40 | add_test(NAME comp_p0_06_a COMMAND imgcmp p0_06_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_06-0.pgx 635 11287) 41 | add_test(NAME comp_p0_06_b COMMAND imgcmp p0_06_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_06-1.pgx 403 6124) 42 | add_test(NAME comp_p0_06_c COMMAND imgcmp p0_06_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_06-2.pgx 378 3968) 43 | add_test(NAME comp_p0_06_d COMMAND imgcmp p0_06_03.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_06-3.pgx 0 0) 44 | set_tests_properties(comp_p0_06_a comp_p0_06_b comp_p0_06_c comp_p0_06_d PROPERTIES DEPENDS dec_p0_06) 45 | # 7 46 | add_test(NAME comp_p0_07_r COMMAND imgcmp p0_07_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_07-0.pgx 0 0) 47 | add_test(NAME comp_p0_07_g COMMAND imgcmp p0_07_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_07-1.pgx 0 0) 48 | add_test(NAME comp_p0_07_b COMMAND imgcmp p0_07_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_07-2.pgx 0 0) 49 | set_tests_properties(comp_p0_07_r comp_p0_07_g comp_p0_07_b PROPERTIES DEPENDS dec_p0_07) 50 | # 8 51 | add_test(NAME comp_p0_08_r COMMAND imgcmp p0_08_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_08-0.pgx 0 0) 52 | add_test(NAME comp_p0_08_g COMMAND imgcmp p0_08_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_08-1.pgx 0 0) 53 | add_test(NAME comp_p0_08_b COMMAND imgcmp p0_08_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_08-2.pgx 0 0) 54 | set_tests_properties(comp_p0_08_r comp_p0_08_g comp_p0_08_b PROPERTIES DEPENDS dec_p0_08) 55 | # 9 56 | add_test(NAME comp_p0_09 COMMAND imgcmp p0_09_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_09-0.pgx 0 0) 57 | set_tests_properties(comp_p0_09 PROPERTIES DEPENDS dec_p0_09) 58 | # 10 59 | add_test(NAME comp_p0_10_r COMMAND imgcmp p0_10_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_10-0.pgx 0 0) 60 | add_test(NAME comp_p0_10_g COMMAND imgcmp p0_10_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_10-1.pgx 0 0) 61 | add_test(NAME comp_p0_10_b COMMAND imgcmp p0_10_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_10-2.pgx 0 0) 62 | set_tests_properties(comp_p0_10_r comp_p0_10_g comp_p0_10_b PROPERTIES DEPENDS dec_p0_10) 63 | # 11 64 | add_test(NAME comp_p0_11 COMMAND imgcmp p0_11_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_11-0.pgx 0 0) 65 | set_tests_properties(comp_p0_11 PROPERTIES DEPENDS dec_p0_11) 66 | # 12 67 | add_test(NAME comp_p0_12 COMMAND imgcmp p0_12_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_12-0.pgx 0 0) 68 | set_tests_properties(comp_p0_12 PROPERTIES DEPENDS dec_p0_12) 69 | # 14 70 | add_test(NAME comp_p0_14_r COMMAND imgcmp p0_14_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_14-0.pgx 0 0) 71 | add_test(NAME comp_p0_14_g COMMAND imgcmp p0_14_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_14-1.pgx 0 0) 72 | add_test(NAME comp_p0_14_b COMMAND imgcmp p0_14_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_14-2.pgx 0 0) 73 | set_tests_properties(comp_p0_14_r comp_p0_14_g comp_p0_14_b PROPERTIES DEPENDS dec_p0_14) 74 | # 15 75 | add_test(NAME comp_p0_15 COMMAND imgcmp p0_15_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_15-0.pgx 0 0) 76 | set_tests_properties(comp_p0_15 PROPERTIES DEPENDS dec_p0_15) 77 | # 16 78 | add_test(NAME comp_p0_16 COMMAND imgcmp p0_16_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p0_16-0.pgx 0 0) 79 | set_tests_properties(comp_p0_16 PROPERTIES DEPENDS dec_p0_16) 80 | -------------------------------------------------------------------------------- /tests/part1_profile1.cmake: -------------------------------------------------------------------------------- 1 | # Decoding 2 | add_test(NAME dec_p1_01 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p1_01.j2k -o p1_01.pgx) 3 | add_test(NAME dec_p1_02 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p1_02.j2k -o p1_02.pgx) 4 | add_test(NAME dec_p1_03 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p1_03.j2k -o p1_03.pgx) 5 | add_test(NAME dec_p1_04 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p1_04.j2k -o p1_04.pgx) 6 | add_test(NAME dec_p1_05 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p1_05.j2k -o p1_05.pgx) 7 | add_test(NAME dec_p1_06 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p1_06.j2k -o p1_06.pgx) 8 | add_test(NAME dec_p1_07 COMMAND open_htj2k_dec -i ${CONFORMANCE_DATA_DIR}/p1_07.j2k -o p1_07.pgx) 9 | 10 | # calculate PAE and MSE 11 | # 1 12 | add_test(NAME comp_p1_01 COMMAND imgcmp p1_01_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_01-0.pgx 0 0) 13 | set_tests_properties(comp_p1_01 PROPERTIES DEPENDS dec_p1_01) 14 | # 2 15 | add_test(NAME comp_p1_02_r COMMAND imgcmp p1_02_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-0.pgx 5 0.765) 16 | add_test(NAME comp_p1_02_g COMMAND imgcmp p1_02_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-1.pgx 4 0.616) 17 | add_test(NAME comp_p1_02_b COMMAND imgcmp p1_02_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_02-2.pgx 6 1.051) 18 | set_tests_properties(comp_p1_02_r comp_p1_02_g comp_p1_02_b PROPERTIES DEPENDS dec_p1_02) 19 | # 3 20 | add_test(NAME comp_p1_03_a COMMAND imgcmp p1_03_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-0.pgx 2 0.311) # 0.300 in old spec 21 | add_test(NAME comp_p1_03_b COMMAND imgcmp p1_03_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-1.pgx 2 0.280) # 0.210 in old spec 22 | add_test(NAME comp_p1_03_c COMMAND imgcmp p1_03_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-2.pgx 1 0.267) # 0.200 in old spec 23 | add_test(NAME comp_p1_03_d COMMAND imgcmp p1_03_03.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_03-3.pgx 0 0) 24 | set_tests_properties(comp_p1_03_a comp_p1_03_b comp_p1_03_c comp_p1_03_d PROPERTIES DEPENDS dec_p1_03) 25 | set_tests_properties(comp_p1_03_b PROPERTIES WILL_FAIL false) 26 | set_tests_properties(comp_p1_03_c PROPERTIES WILL_FAIL false) 27 | # 4 28 | add_test(NAME comp_p1_04 COMMAND imgcmp p1_04_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_04-0.pgx 624 3080) 29 | set_tests_properties(comp_p1_04 PROPERTIES DEPENDS dec_p1_04) 30 | # 5 31 | add_test(NAME comp_p1_05_r COMMAND imgcmp p1_05_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_05-0.pgx 40 8.458) 32 | add_test(NAME comp_p1_05_g COMMAND imgcmp p1_05_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_05-1.pgx 40 9.716) 33 | add_test(NAME comp_p1_05_b COMMAND imgcmp p1_05_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_05-2.pgx 40 10.154) 34 | set_tests_properties(comp_p1_05_r comp_p1_05_g comp_p1_05_b PROPERTIES DEPENDS dec_p1_05) 35 | # 6 36 | add_test(NAME comp_p1_06_r COMMAND imgcmp p1_06_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_06-0.pgx 2 0.600) 37 | add_test(NAME comp_p1_06_g COMMAND imgcmp p1_06_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_06-1.pgx 2 0.600) 38 | add_test(NAME comp_p1_06_b COMMAND imgcmp p1_06_02.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_06-2.pgx 2 0.600) 39 | set_tests_properties(comp_p1_06_r comp_p1_06_g comp_p1_06_b PROPERTIES DEPENDS dec_p1_06) 40 | # 7 41 | add_test(NAME comp_p1_07_a COMMAND imgcmp p1_07_00.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_07-0.pgx 0 0) 42 | add_test(NAME comp_p1_07_b COMMAND imgcmp p1_07_01.pgx ${CONFORMANCE_DATA_DIR}/references/c1p1_07-1.pgx 0 0) 43 | set_tests_properties(comp_p1_07_a comp_p1_07_b PROPERTIES DEPENDS dec_p1_07) 44 | --------------------------------------------------------------------------------