Compare commits

..

1 Commits

Author SHA1 Message Date
Antonin Descampe bfdcca770b PR #894 (without BOOK implementation) 2017-03-03 17:00:57 +01:00
378 changed files with 100692 additions and 83584 deletions

View File

@ -1,30 +0,0 @@
<!--
IMPORTANT: Do NOT use GitHub to post any questions or support requests!
They will be closed immediately and ignored.
Questions should go to the OpenJPEG mailing list at
https://groups.google.com/g/openjpeg or other support forums.
GitHub issues are for bug reports and suggestions for new features.
The OpenJPEG project is made of contributions from various individuals and
organizations, each with their own focus. The issue you are facing is
not necessarily in the priority list of those contributors and consequently
there is no guarantee that it will be addressed in a timely manner.
-->
## Expected behavior and actual behavior.
...to fill...
## Steps to reproduce the problem.
...to fill...
## Operating system
...to fill...
## openjpeg version
...to fill...

View File

@ -1,24 +0,0 @@
name: ABI check
on: [push, pull_request, workflow_dispatch]
jobs:
abi_check:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Requirements
run: |
sudo apt update
sudo apt install -y gcc g++ libelf-dev elfutils texinfo exuberant-ctags libtiff-dev libwebp-dev libzstd-dev
- name: Build
run: |
./tools/travis-ci/install.sh
./tools/travis-ci/run.sh
./tools/travis-ci/abi-check.sh
env:
OPJ_CI_ABI_CHECK: 1

View File

@ -1,189 +0,0 @@
name: Build
on: [push, pull_request, workflow_dispatch]
jobs:
regular:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Requirements
run: |
sudo apt update
sudo apt install -y gcc g++ libtiff-dev libwebp-dev libzstd-dev
- name: Build and run tests
run: |
./tools/travis-ci/install.sh
./tools/travis-ci/run.sh
env:
OPJ_CI_ARCH: x86_64
OPJ_CI_BUILD_CONFIGURATION: Release
OPJ_CI_PERF_TESTS: 1
OPJ_CI_BUILD_FUZZERS: 1
OPJ_CI_INCLUDE_IF_DEPLOY: 1
OPJ_NONCOMMERCIAL: 1
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: build/openjpeg-*.tar.gz
asan:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Requirements
run: |
sudo apt update
sudo apt install -y gcc g++
- name: Build and run tests
run: |
./tools/travis-ci/install.sh
./tools/travis-ci/run.sh
env:
OPJ_CI_ARCH: x86_64
OPJ_CI_BUILD_CONFIGURATION: Debug
OPJ_CI_ASAN: 1
OPJ_NONCOMMERCIAL: 1
clang_32bit:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Requirements
run: |
sudo apt update
sudo apt install -y clang gcc-multilib
- name: Build and run tests
run: |
./tools/travis-ci/install.sh
./tools/travis-ci/run.sh
env:
OPJ_CI_CC: clang
OPJ_CI_CXX: clang++
OPJ_CI_INSTRUCTION_SETS: "-mavx2"
OPJ_CI_BUILD_CONFIGURATION: Release
OPJ_CI_ARCH: i386
OPJ_NUM_THREADS: 2
OPJ_NONCOMMERCIAL: 1
mingw_64:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Requirements
run: |
sudo apt update
sudo apt install -y gcc-mingw-w64-base binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64 gcc-mingw-w64 g++-mingw-w64-x86-64
- name: Build and run tests
run: |
./tools/travis-ci/install.sh
./tools/travis-ci/run.sh
env:
OPJ_CI_CC: x86_64-w64-mingw32-gcc
OPJ_CI_CXX: x86_64-w64-mingw32-g++
OPJ_CI_ARCH: x86_64
OPJ_CI_BUILD_CONFIGURATION: Release
OPJ_NONCOMMERCIAL: 1
macos:
runs-on: macos-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build and run tests
run: |
./tools/travis-ci/install.sh
./tools/travis-ci/run.sh
env:
OPJ_CI_ARCH: x86_64
OPJ_CI_BUILD_CONFIGURATION: Release
OPJ_CI_INCLUDE_IF_DEPLOY: 1
#OPJ_NONCOMMERCIAL: 1
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: build/openjpeg-*.zip
windows_build:
runs-on: windows-2019
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
include:
- VS_VER: 2019
OPJ_CI_ARCH: x64
OPJ_CI_INCLUDE_IF_DEPLOY: 1
- VS_VER: 2019
OPJ_CI_ARCH: x86
OPJ_CI_INCLUDE_IF_DEPLOY: 1
- VS_VER: 2019
OPJ_CI_ARCH: x64
# We do have specific failures noted in tools/travis-ci/knownfailures-windows-vs2015-x64-avx2-Release-3rdP.txt
# not sure why that happens
OPJ_CI_INSTRUCTION_SETS: "/arch:AVX2"
env:
VS_VER: ${{ matrix.VS_VER }}
OPJ_CI_ARCH: ${{ matrix.OPJ_CI_ARCH }}
OPJ_CI_INCLUDE_IF_DEPLOY: ${{ matrix.OPJ_CI_INCLUDE_IF_DEPLOY }}
OPJ_CI_INSTRUCTION_SETS: ${{ matrix.OPJ_CI_INSTRUCTION_SETS }}
#OPJ_NONCOMMERCIAL: 1
steps:
- name: Setup git
run: |
git config --global core.autocrlf false
git config --system core.longpaths true
- name: Checkout
uses: actions/checkout@v2
- name: Set compiler environment
shell: cmd
run: |
if "%VS_VER%" == "2019" CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=%OPJ_CI_ARCH%
echo PATH=%PATH%>> %GITHUB_ENV%
echo INCLUDE=%INCLUDE%>> %GITHUB_ENV%
echo LIB=%LIB%>> %GITHUB_ENV%
echo LIBPATH=%LIBPATH%>> %GITHUB_ENV%
- name: Install wget
shell: cmd
run: |
choco install wget --no-progress
- name: Build and run tests
run: |
./tools/travis-ci/install.sh
./tools/travis-ci/run.sh
shell: bash
- name: Release
uses: softprops/action-gh-release@v1
if: ${{startsWith(github.ref, 'refs/tags/') && env.OPJ_CI_INCLUDE_IF_DEPLOY == 1}}
with:
files: build/openjpeg-*.zip

View File

@ -1,26 +0,0 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'openjpeg'
dry-run: false
language: c
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'openjpeg'
fuzz-seconds: 600
dry-run: false
language: c
- name: Upload Crash
uses: actions/upload-artifact@v1
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
path: ./out/artifacts

View File

@ -1,26 +0,0 @@
name: Code Style
on: [push, pull_request, workflow_dispatch]
jobs:
code_style:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Requirements
run: |
sudo apt update
sudo apt install -y gcc g++ flip
- name: Run check
run: |
./tools/travis-ci/install.sh
./tools/travis-ci/run.sh
env:
OPJ_CI_CHECK_STYLE: 1
OPJ_CI_SKIP_TESTS: 1

4
.gitignore vendored
View File

@ -12,10 +12,6 @@ cmake_install.cmake
/src/bin/common/opj_apps_config.h
/src/lib/openjp2/opj_config.h
/src/lib/openjp2/opj_config_private.h
scripts/opjstyle*
# Ignore directories made by `make`.
/bin/
build
SDK
*.lha

View File

@ -1,118 +1,42 @@
language: cpp
language: c
matrix:
include:
# OSX
# OPJ_NONCOMMERCIAL=0 because Kakadu install hangs (cf https://travis-ci.org/github/uclouvain/openjpeg/builds/769447606)
# - os: osx
# compiler: clang
# env: OPJ_NONCOMMERCIAL=0 OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1
# Test code style
- os: osx
compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1
- os: linux
compiler: clang-3.8
env: OPJ_CI_CC=clang-3.8 OPJ_CI_CXX=clang-3.8 OPJ_CI_CHECK_STYLE=1 OPJ_CI_SKIP_TESTS=1
addons:
apt:
sources:
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
packages:
- clang-3.8
- flip
# Performance test with GCC
# Disabled because tests fail
# - os: linux
# compiler: g++
# dist: precise
# env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1 OPJ_CI_PERF_TESTS=1
# Test compilation with AVX2
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1
- os: linux
# "sudo: yes" and "dist: trusty" give us a worker with the AVX2 instruction set
sudo: yes
dist: trusty
compiler: clang-3.8
env: OPJ_CI_CC=clang-3.8 OPJ_CI_CXX=clang-3.8 OPJ_CI_INSTRUCTION_SETS="-mavx2" OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
sources:
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
packages:
- clang-3.8
# Test multi-threading
# Disabled because tests fail (cf https://travis-ci.org/github/uclouvain/openjpeg/builds/769447606)
# - os: linux
# compiler: g++
# dist: precise
# env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_NUM_THREADS=2
# Test 32-bit compilation
# Disabled because tests fail (cf https://travis-ci.org/github/uclouvain/openjpeg/builds/769447606)
# - os: linux
# compiler: g++
# env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
# dist: trusty
# addons:
# apt:
# packages:
# - gcc-multilib
# - g++-multilib
# Profile code (gcc -pg)
# Disabled because tests fail (cf https://travis-ci.org/github/uclouvain/openjpeg/builds/769447606)
# - os: linux
# compiler: g++
# env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_PROFILE=1
# dist: trusty
# addons:
# apt:
# packages:
# - valgrind
# Test under ASAN
# Temporarily disabled since broken. See https://github.com/uclouvain/openjpeg/issues/1091
# - os: linux
# compiler: clang
# env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_ASAN=1
# Test with CLang 3.8
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_NUM_THREADS=2
- os: linux
compiler: clang-3.8
env: OPJ_CI_CC=clang-3.8 OPJ_CI_CXX=clang-3.8 OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_PERF_TESTS=1 OPJ_CI_BUILD_FUZZERS=1
dist: trusty
addons:
apt:
sources:
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
packages:
- clang-3.8
# Test with mingw 32 bit
- os: linux
compiler: x86_64-w64-mingw32-g++
env: OPJ_CI_CC=x86_64-w64-mingw32-gcc OPJ_CI_CXX=x86_64-w64-mingw32-g++ OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
dist: trusty
compiler: gcc
env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
packages:
- gcc-mingw-w64-base
- binutils-mingw-w64-i686
- gcc-mingw-w64-i686
- gcc-mingw-w64
- g++-mingw-w64-i686
- gcc-multilib
- g++-multilib
# Test with mingw 64 bit
- os: linux
compiler: x86_64-w64-mingw32-g++
env: OPJ_CI_CC=x86_64-w64-mingw32-gcc OPJ_CI_CXX=x86_64-w64-mingw32-g++ OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
dist: trusty
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug
- os: linux
compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_ASAN=1
- os: linux
compiler: clang-3.8
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
sources:
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
packages:
- clang-3.8
- os: linux
compiler: x86_64-w64-mingw32-gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
packages:
@ -120,31 +44,36 @@ matrix:
- binutils-mingw-w64-x86-64
- gcc-mingw-w64-x86-64
- gcc-mingw-w64
- g++-mingw-w64-x86-64
# Test with gcc 4.8
- os: linux
compiler: g++-4.8
env: OPJ_CI_CC=gcc-4.8 OPJ_CI_CXX=g++-4.8 OPJ_CI_ABI_CHECK=1
dist: xenial
compiler: x86_64-w64-mingw32-gcc
env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
packages:
- gcc-mingw-w64-base
- binutils-mingw-w64-i686
- gcc-mingw-w64-i686
- gcc-mingw-w64
- os: linux
compiler: gcc-4.8
env: OPJ_CI_ABI_CHECK=1
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
- libelf-dev
- elfutils
- texinfo
- exuberant-ctags
install:
- "./tools/travis-ci/install.sh"
- ./tools/travis-ci/install.sh
script:
- "./tools/travis-ci/run.sh"
- "./tools/travis-ci/abi-check.sh"
- ./tools/travis-ci/run.sh
- ./tools/travis-ci/abi-check.sh
before_deploy:
- export OPJ_RELEASE_PKG_FILE=$(ls build/openjpeg-${TRAVIS_TAG}*)
@ -153,7 +82,7 @@ before_deploy:
deploy:
provider: releases
api_key:
secure: dJXdzoFwk9wYWIKztnXKlVIr1QDmeXtk3oK+2MEzy22fBTKPuphU/cYMvhi5B7sWDwm77f43vbAYO6z7IFmuThwhkuVMD/o+lUyCqGffGeiU1pKpxEvB+LbO/C5asdSnor3RfYdOyo3x4cNlhNtfhXIn7FcAg371yEY6VSIP87adoQcuE+taig0cYWcrNWYGHirHlzEz1utnKwCT/nlhV4nSIWxjwYUp3nt8PAw3RbqQkPPNBniW92g6JA25vLRc3HMD18ISCfNLC2fI6a/dTR+vd+bCySA7JvqeDZnv8SxbVIabu5T+A5CHzHbdp2l2kynPwqHOO47pGa+VfisXEwSsOpa+4EZsPLdwOhaFFnvDwKwR3EjI1TkRVd26IcK61Y5zVZQgalnXBowBEZoI4fT/oEPF7VZMjN3sy/do1U6d5kO0UGqCHCJIVwPeELhwq5z7Ld04K7dSFFVenZhhQKCwxI1o8vgkGNJUWD2Ii6ZLrZKYZ0lC65hr2d39e/KoK3Yh5KHF0cVn6ppBTcUjYr/tdHHO43rwoaf3r1CdAQAYpFvfi3900hl9I/GPwky0YJ6W2QDS2vincwaqWDQ0+WNGf4AKSdx5kCgQU45PSfDb/lxAyXkqmBuI3h/C2ellleaWVL9sGtNRWa/w6WseGMGwfCXgN82XRVM2bgP6pYg=
secure: Npi13uOffALCVNwea4p4q8v85Lo/WsRqaeZQcWrAkt8MxRnfvWQtmnuwmHnVB6Cig+T1lVUHrklOaJIApIb6nkGq3CS/9bD8+SCS2NEdAAP/QYWnBi0ubWXVMRyDLypmwRpzLNSZ0xLYGFUl2PjieZYKRcz1dd/J7S+FnXhPtdjXweq0FS63zTcMe7ggjfmzSOWUCEFmMjZPaM0Be+3PweieCO1dxlHuy7ugCkx2S7d+5hNsicIhQmTADjqtJAkHoMhYqu6/yLFxhjO/+f938PATFULdODTvjCsUwdN/ySWi1Oj4uPAntfytZP7H6YrzLh8dS73QCsdkhhDJIgJskHIBSbRyyEVUnOvQgD9VaBVGHtc1KtZQTwc41OUO3BGPHl97s3oX6bqWqo/L53dB3TPHGx+1+2HL/F0zaDZuHhAKMkPwe8LFPMPB/ur65zXMHjnWb2ZTVVdoIvkbQ7nu8ApI60ejxocYBsEyAuC2CPXU2ki4jdEhm0E1hIziWNE9/LTuM17ziQuJ6WpXOSMrfP4o5aVDmLp5ZGBSocrspOksgyI9XogHaO/r+Y6N3exy+giObFfMHkZVUpsKrKmtOJ7TC1Vg5HsYGlWW8RN8dkJV47bUXm9K4sMos9eYMUt/czykPAs+132cogpII3QxXpFZQqZg6SEPVfOiyqQzTUI=
file_glob: true
file: "${OPJ_RELEASE_PKG_FILE}"
skip_cleanup: true
@ -161,3 +90,4 @@ deploy:
repo: uclouvain/openjpeg
tags: true
condition: "$OPJ_CI_INCLUDE_IF_DEPLOY = 1"

View File

@ -1,449 +1,5 @@
# Changelog
## [v2.5.0](https://github.com/uclouvain/openjpeg/releases/v2.5.0) (2022-05-13)
[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.4.0...v2.5.0)
**Merged pull requests:**
- tools/travis-ci/install.sh: git clone with https:// to fix 'The unaut… [\#1419](https://github.com/uclouvain/openjpeg/pull/1419) ([rouault](https://github.com/rouault))
- Java Support 1.8 now... [\#1418](https://github.com/uclouvain/openjpeg/pull/1418) ([jiapei100](https://github.com/jiapei100))
- Separate fuzz targets to increase coverage [\#1416](https://github.com/uclouvain/openjpeg/pull/1416) ([Navidem](https://github.com/Navidem))
- CMakeLists.txt: do not set INSTALL\_NAME\_DIR for MacOS builds for CMake \>= 3.0 \(fixes \#1404\) [\#1410](https://github.com/uclouvain/openjpeg/pull/1410) ([rouault](https://github.com/rouault))
- Avoid integer overflows in DWT. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44544 [\#1408](https://github.com/uclouvain/openjpeg/pull/1408) ([rouault](https://github.com/rouault))
- Updated "added support for partial bitstream decoding" [\#1407](https://github.com/uclouvain/openjpeg/pull/1407) ([Neopallium](https://github.com/Neopallium))
- opj\_encoder\_set\_extra\_options\(\): add a GUARD\_BITS=value option [\#1403](https://github.com/uclouvain/openjpeg/pull/1403) ([rouault](https://github.com/rouault))
- More overflow related bug fixes [\#1402](https://github.com/uclouvain/openjpeg/pull/1402) ([Eharve14](https://github.com/Eharve14))
- opj\_j2k\_setup\_encoder\(\): validate number of tiles to avoid illegal values and potential overflow \(fixes \#1399\) [\#1401](https://github.com/uclouvain/openjpeg/pull/1401) ([rouault](https://github.com/rouault))
- Missed conversion from unsigned int to OPJ\_INT32 [\#1398](https://github.com/uclouvain/openjpeg/pull/1398) ([Eharve14](https://github.com/Eharve14))
- Added check for integer overflow in get\_num\_images [\#1397](https://github.com/uclouvain/openjpeg/pull/1397) ([Eharve14](https://github.com/Eharve14))
- Added overflow check for CVE-2021-29338 [\#1396](https://github.com/uclouvain/openjpeg/pull/1396) ([Eharve14](https://github.com/Eharve14))
- Fix integer overflow in num\_images [\#1395](https://github.com/uclouvain/openjpeg/pull/1395) ([baparham](https://github.com/baparham))
- Remove duplicate assignments in function tiftoimage [\#1392](https://github.com/uclouvain/openjpeg/pull/1392) ([stweil](https://github.com/stweil))
- Fix some typos \(found by codespell\) [\#1390](https://github.com/uclouvain/openjpeg/pull/1390) ([stweil](https://github.com/stweil))
- CI: Add CIFuzz action [\#1386](https://github.com/uclouvain/openjpeg/pull/1386) ([DavidKorczynski](https://github.com/DavidKorczynski))
- Feature/decimation [\#1384](https://github.com/uclouvain/openjpeg/pull/1384) ([msheby](https://github.com/msheby))
- API: deprecate 'bpp' member in favor of 'prec' [\#1383](https://github.com/uclouvain/openjpeg/pull/1383) ([rouault](https://github.com/rouault))
- Added support for high throughput \(HTJ2K\) decoding. [\#1381](https://github.com/uclouvain/openjpeg/pull/1381) ([rouault](https://github.com/rouault))
- verify-indentation.sh: fix for pull request from bar/master to foo/master [\#1380](https://github.com/uclouvain/openjpeg/pull/1380) ([rouault](https://github.com/rouault))
- Change integer for version libtiff 4.3.0 [\#1377](https://github.com/uclouvain/openjpeg/pull/1377) ([Jamaika1](https://github.com/Jamaika1))
- Port continuous integration to github actions [\#1376](https://github.com/uclouvain/openjpeg/pull/1376) ([rouault](https://github.com/rouault))
- Avoid integer overflows in DWT. [\#1375](https://github.com/uclouvain/openjpeg/pull/1375) ([rouault](https://github.com/rouault))
- LGTM warning: Comparison result is always the same [\#1373](https://github.com/uclouvain/openjpeg/pull/1373) ([DimitriPapadopoulos](https://github.com/DimitriPapadopoulos))
- A couple typos found by codespell [\#1371](https://github.com/uclouvain/openjpeg/pull/1371) ([DimitriPapadopoulos](https://github.com/DimitriPapadopoulos))
- cmake: add install interface include directory [\#1370](https://github.com/uclouvain/openjpeg/pull/1370) ([madebr](https://github.com/madebr))
- fix issues 1368: exist a issues of freeing uninitialized pointer in src/bin/jp2/opj\_decompress.cthat will cause a segfault [\#1369](https://github.com/uclouvain/openjpeg/pull/1369) ([xiaoxiaoafeifei](https://github.com/xiaoxiaoafeifei))
- opj\_j2k\_is\_imf\_compliant: Fix out of bounds access [\#1366](https://github.com/uclouvain/openjpeg/pull/1366) ([sebras](https://github.com/sebras))
- opj\_j2k\_is\_imf\_compliant: Fix argument formatting for warnings. [\#1365](https://github.com/uclouvain/openjpeg/pull/1365) ([sebras](https://github.com/sebras))
- CMakeLists.txt/appveyor.yml: update version number to 2.5.0… [\#1361](https://github.com/uclouvain/openjpeg/pull/1361) ([rouault](https://github.com/rouault))
- .travis.yml: try to fix gcc 4.8 config by updating to xenial [\#1360](https://github.com/uclouvain/openjpeg/pull/1360) ([rouault](https://github.com/rouault))
- Add support for enabling generation of TLM markers in encoder [\#1359](https://github.com/uclouvain/openjpeg/pull/1359) ([rouault](https://github.com/rouault))
- Fix various compiler warnings [\#1358](https://github.com/uclouvain/openjpeg/pull/1358) ([rouault](https://github.com/rouault))
- fix \#1345: don't remove big endian test for other platforms [\#1354](https://github.com/uclouvain/openjpeg/pull/1354) ([msabwat](https://github.com/msabwat))
- Remove obsolete components JPWL, JP3D and MJ2 [\#1350](https://github.com/uclouvain/openjpeg/pull/1350) ([rouault](https://github.com/rouault))
- tools/travis-ci/install.sh: fix links to Kakadu and jpylyzer binaries [\#1348](https://github.com/uclouvain/openjpeg/pull/1348) ([rouault](https://github.com/rouault))
- emscripten: disable big endian test [\#1345](https://github.com/uclouvain/openjpeg/pull/1345) ([msabwat](https://github.com/msabwat))
- Fix cmake file with DESTDIR [\#1321](https://github.com/uclouvain/openjpeg/pull/1321) ([ffontaine](https://github.com/ffontaine))
- CMakeLists.txt: Don't require a C++ compiler [\#1317](https://github.com/uclouvain/openjpeg/pull/1317) ([ffontaine](https://github.com/ffontaine))
- Import files tiff and yuv\(raw\) [\#1316](https://github.com/uclouvain/openjpeg/pull/1316) ([Jamaika1](https://github.com/Jamaika1))
- Fix year in NEWS [\#1312](https://github.com/uclouvain/openjpeg/pull/1312) ([stweil](https://github.com/stweil))
- Fix lcms2 static linking using pgk config [\#867](https://github.com/uclouvain/openjpeg/pull/867) ([pseiderer](https://github.com/pseiderer))
- fix static build only against tiff and its indirect dependencies [\#866](https://github.com/uclouvain/openjpeg/pull/866) ([tSed](https://github.com/tSed))
**Closed issues:**
- integer constant is too large for 'long' type [\#61](https://github.com/uclouvain/openjpeg/issues/61)
- Openjpeg3D lossy compression not working [\#501](https://github.com/uclouvain/openjpeg/issues/501)
- mj2: Array overflow [\#485](https://github.com/uclouvain/openjpeg/issues/485)
- OPJ fails to decode image that KDU manages correctly [\#419](https://github.com/uclouvain/openjpeg/issues/419)
- yuvtoimage\(\) bug in v1 and v2 for 16-Bit: please apply ASAP [\#384](https://github.com/uclouvain/openjpeg/issues/384)
- JP3D: Fix CVE-2013-4289 CVE-2013-4290 [\#298](https://github.com/uclouvain/openjpeg/issues/298)
- MJ2 libraries are installed in lib [\#204](https://github.com/uclouvain/openjpeg/issues/204)
- MJ2: realloc is misused and may leak memory [\#168](https://github.com/uclouvain/openjpeg/issues/168)
- MJ2 wrapper not functional [\#143](https://github.com/uclouvain/openjpeg/issues/143)
- JPWL is broken in trunk [\#137](https://github.com/uclouvain/openjpeg/issues/137)
- MJ2 files not using OPENJPEG API correctly [\#53](https://github.com/uclouvain/openjpeg/issues/53)
- Maximum bit depth supported by the OpenJPEG implementation of JP3D [\#9](https://github.com/uclouvain/openjpeg/issues/9)
- does openjpeg support either visually lossless or numerically lossless jpeg2000 compression? [\#1406](https://github.com/uclouvain/openjpeg/issues/1406)
- extract jpeg2000 tile without decompression [\#1405](https://github.com/uclouvain/openjpeg/issues/1405)
- openjpeg doesn't install a relocatable shared lib on macOS [\#1404](https://github.com/uclouvain/openjpeg/issues/1404)
- pull request - the cinema industry awaits! [\#1400](https://github.com/uclouvain/openjpeg/issues/1400)
- Integer overflows in j2K [\#1399](https://github.com/uclouvain/openjpeg/issues/1399)
- why lossly compression performance worse than jpeg when compress png [\#1393](https://github.com/uclouvain/openjpeg/issues/1393)
- cect [\#1389](https://github.com/uclouvain/openjpeg/issues/1389)
- the docs don't describe bpp and prec in opj\_image\_comp very well [\#1379](https://github.com/uclouvain/openjpeg/issues/1379)
- converting .png to .jp2 by opj\_compress is different from the original image [\#1378](https://github.com/uclouvain/openjpeg/issues/1378)
- Comparison result is always the same [\#1372](https://github.com/uclouvain/openjpeg/issues/1372)
- Exist a issues of freeing uninitialized pointer in src/bin/jp2/opj\_decompress.cthat will cause a segfault [\#1368](https://github.com/uclouvain/openjpeg/issues/1368)
- \[TEST NOT RUNNING\]: bigendian test [\#1355](https://github.com/uclouvain/openjpeg/issues/1355)
- opj\_decompress 2.4.0 built with library 2.3.0. [\#1352](https://github.com/uclouvain/openjpeg/issues/1352)
- New library htjpeg2000 [\#1351](https://github.com/uclouvain/openjpeg/issues/1351)
- Integer Overflow in num\_images [\#1338](https://github.com/uclouvain/openjpeg/issues/1338)
- All IMF Profile Selections Result in PART1 [\#1337](https://github.com/uclouvain/openjpeg/issues/1337)
- grayscale image [\#1334](https://github.com/uclouvain/openjpeg/issues/1334)
- error C2169: 'lrintf': intrinsic function, cannot be defined [\#1333](https://github.com/uclouvain/openjpeg/issues/1333)
- Generate lower-case extension [\#1332](https://github.com/uclouvain/openjpeg/issues/1332)
- color of reconstructed png file much darker [\#1330](https://github.com/uclouvain/openjpeg/issues/1330)
- CVE-2019-6988, CVE-2018-20846 and CVE-2018-16376 [\#1328](https://github.com/uclouvain/openjpeg/issues/1328)
- opj 2.4.0: opj\_free missing in opj3d [\#1327](https://github.com/uclouvain/openjpeg/issues/1327)
- Not able to compress volumetric data [\#1326](https://github.com/uclouvain/openjpeg/issues/1326)
- HTML documents are not installed in specified place [\#1322](https://github.com/uclouvain/openjpeg/issues/1322)
- Can't find openjpeg.h when cross-compile. [\#1320](https://github.com/uclouvain/openjpeg/issues/1320)
- OpenJPEG is available with EasyConfig [\#1319](https://github.com/uclouvain/openjpeg/issues/1319)
- Building Test Programs [\#1318](https://github.com/uclouvain/openjpeg/issues/1318)
- Builds are not reproducible [\#1275](https://github.com/uclouvain/openjpeg/issues/1275)
- strange behaviour of opj\_jp3d\_compress/decompress utility [\#1274](https://github.com/uclouvain/openjpeg/issues/1274)
- Potential heap-based buffer overflow in function t2\_encode\_packet in src/lib/openmj2/t2.c and src/lib/openjp3d/t2.c [\#1272](https://github.com/uclouvain/openjpeg/issues/1272)
- Function tgatoimage in src/bin/jpwl/convert.c need to check that the file is big enough to avoid excessive memory allocations [\#1271](https://github.com/uclouvain/openjpeg/issues/1271)
- memory & cpu are exhausted when converting jp2 file into png [\#1250](https://github.com/uclouvain/openjpeg/issues/1250)
- Cannot compress PGX into JP3D despite following the directions? [\#1134](https://github.com/uclouvain/openjpeg/issues/1134)
- sscanf buffer overflow in opj\_jp3d\_compress.c [\#1130](https://github.com/uclouvain/openjpeg/issues/1130)
- integer underflow may lead to writing garbage [\#1089](https://github.com/uclouvain/openjpeg/issues/1089)
- sscanf buffer overflow [\#1087](https://github.com/uclouvain/openjpeg/issues/1087)
- strcpy overflows [\#1086](https://github.com/uclouvain/openjpeg/issues/1086)
- sprintf buffer overflows [\#1084](https://github.com/uclouvain/openjpeg/issues/1084)
- strcpy buffer overflow [\#1083](https://github.com/uclouvain/openjpeg/issues/1083)
- integer overflow in malloc\(\) [\#1082](https://github.com/uclouvain/openjpeg/issues/1082)
- out of bounds writes [\#1078](https://github.com/uclouvain/openjpeg/issues/1078)
- out of bounds writes [\#1077](https://github.com/uclouvain/openjpeg/issues/1077)
- divide by zero, perhaps multiplication overflow [\#1076](https://github.com/uclouvain/openjpeg/issues/1076)
- missing format string parameter [\#1075](https://github.com/uclouvain/openjpeg/issues/1075)
- leaks from cppcheck in lib folder [\#1038](https://github.com/uclouvain/openjpeg/issues/1038)
- How to initialize DEBUG\_PROFILE in color.c? [\#958](https://github.com/uclouvain/openjpeg/issues/958)
- JP3D sample files [\#865](https://github.com/uclouvain/openjpeg/issues/865)
- BIG\_ENDIAN bug in jpwl.c [\#839](https://github.com/uclouvain/openjpeg/issues/839)
- OpenJPEG fails to decode partial j2c where kdu succeeds [\#715](https://github.com/uclouvain/openjpeg/issues/715)
- building mj2 binaries fails [\#652](https://github.com/uclouvain/openjpeg/issues/652)
- openmj2\mj2.c: Out of bounds [\#646](https://github.com/uclouvain/openjpeg/issues/646)
- bin\mj2\opj\_mj2\_decompress.c 101 wrong check / leak [\#608](https://github.com/uclouvain/openjpeg/issues/608)
## [v2.4.0](https://github.com/uclouvain/openjpeg/releases/v2.4.0) (2020-12-28)
[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.3.1...v2.4.0)
**Closed issues:**
- OPENJPEG\_INSTALL\_DOC\_DIR does not control a destination directory where HTML docs would be installed. [\#1309](https://github.com/uclouvain/openjpeg/issues/1309)
- Heap-buffer-overflow in lib/openjp2/pi.c:312 [\#1302](https://github.com/uclouvain/openjpeg/issues/1302)
- Heap-buffer-overflow in lib/openjp2/t2.c:973 [\#1299](https://github.com/uclouvain/openjpeg/issues/1299)
- Heap-buffer-overflow in lib/openjp2/pi.c:623 [\#1293](https://github.com/uclouvain/openjpeg/issues/1293)
- Global-buffer-overflow in lib/openjp2/dwt.c:1980 [\#1286](https://github.com/uclouvain/openjpeg/issues/1286)
- Heap-buffer-overflow in lib/openjp2/tcd.c:2417 [\#1284](https://github.com/uclouvain/openjpeg/issues/1284)
- Heap-buffer-overflow in lib/openjp2/mqc.c:499 [\#1283](https://github.com/uclouvain/openjpeg/issues/1283)
- Openjpeg could not encode 32bit RGB float image [\#1281](https://github.com/uclouvain/openjpeg/issues/1281)
- Openjpeg could not encode 32bit RGB float image [\#1280](https://github.com/uclouvain/openjpeg/issues/1280)
- ISO/IEC 15444-1:2019 \(E\) compared with 'cio.h' [\#1277](https://github.com/uclouvain/openjpeg/issues/1277)
- Test-suite failure due to hash mismatch [\#1264](https://github.com/uclouvain/openjpeg/issues/1264)
- Heap use-after-free [\#1261](https://github.com/uclouvain/openjpeg/issues/1261)
- Memory leak when failing to allocate object... [\#1259](https://github.com/uclouvain/openjpeg/issues/1259)
- Memory leak of Tier 1 handle when OpenJPEG fails to set it as TLS... [\#1257](https://github.com/uclouvain/openjpeg/issues/1257)
- Any plan to build release for CVE-2020-8112/CVE-2020-6851 [\#1247](https://github.com/uclouvain/openjpeg/issues/1247)
- failing to convert 16-bit file: opj\_t2\_encode\_packet\(\): only 5251 bytes remaining in output buffer. 5621 needed. [\#1243](https://github.com/uclouvain/openjpeg/issues/1243)
- CMake+VS2017 Compile OK, thirdparty Compile OK, but thirdparty not install [\#1239](https://github.com/uclouvain/openjpeg/issues/1239)
- New release to solve CVE-2019-6988 ? [\#1238](https://github.com/uclouvain/openjpeg/issues/1238)
- Many tests fail to pass after the update of libtiff to version 4.1.0 [\#1233](https://github.com/uclouvain/openjpeg/issues/1233)
- Another heap buffer overflow in libopenjp2 [\#1231](https://github.com/uclouvain/openjpeg/issues/1231)
- Heap buffer overflow in libopenjp2 [\#1228](https://github.com/uclouvain/openjpeg/issues/1228)
- Endianness of binary volume \(JP3D\) [\#1224](https://github.com/uclouvain/openjpeg/issues/1224)
- New release to resolve CVE-2019-12973 [\#1222](https://github.com/uclouvain/openjpeg/issues/1222)
- how to set the block size,like 128,256 ? [\#1216](https://github.com/uclouvain/openjpeg/issues/1216)
- compress YUV files to motion jpeg2000 standard [\#1213](https://github.com/uclouvain/openjpeg/issues/1213)
- Repair/update Java wrapper, and include in release [\#1208](https://github.com/uclouvain/openjpeg/issues/1208)
- abc [\#1206](https://github.com/uclouvain/openjpeg/issues/1206)
- Slow decoding [\#1202](https://github.com/uclouvain/openjpeg/issues/1202)
- Installation question [\#1201](https://github.com/uclouvain/openjpeg/issues/1201)
- Typo in test\_decode\_area - \*ptilew is assigned instead of \*ptileh [\#1195](https://github.com/uclouvain/openjpeg/issues/1195)
- Creating a J2K file with one POC is broken [\#1191](https://github.com/uclouvain/openjpeg/issues/1191)
- Make fails on Arch Linux [\#1174](https://github.com/uclouvain/openjpeg/issues/1174)
- Heap buffer overflow in opj\_t1\_clbl\_decode\_processor\(\) triggered with Ghostscript [\#1158](https://github.com/uclouvain/openjpeg/issues/1158)
- opj\_stream\_get\_number\_byte\_left: Assertion `p\_stream-\>m\_byte\_offset \>= 0' failed. [\#1151](https://github.com/uclouvain/openjpeg/issues/1151)
- The fuzzer ignores too many inputs [\#1079](https://github.com/uclouvain/openjpeg/issues/1079)
- out of bounds read [\#1068](https://github.com/uclouvain/openjpeg/issues/1068)
**Merged pull requests:**
- Change defined WIN32 [\#1310](https://github.com/uclouvain/openjpeg/pull/1310) ([Jamaika1](https://github.com/Jamaika1))
- docs: fix simple typo, producted -\> produced [\#1308](https://github.com/uclouvain/openjpeg/pull/1308) ([timgates42](https://github.com/timgates42))
- Set ${OPENJPEG\_INSTALL\_DOC\_DIR} to DESTINATION of HTMLs [\#1307](https://github.com/uclouvain/openjpeg/pull/1307) ([lemniscati](https://github.com/lemniscati))
- Use INC\_DIR for OPENJPEG\_INCLUDE\_DIRS \(fixes uclouvain\#1174\) [\#1306](https://github.com/uclouvain/openjpeg/pull/1306) ([matthew-sharp](https://github.com/matthew-sharp))
- pi.c: avoid out of bounds access with POC \(fixes \#1302\) [\#1304](https://github.com/uclouvain/openjpeg/pull/1304) ([rouault](https://github.com/rouault))
- Encoder: grow again buffer size [\#1303](https://github.com/uclouvain/openjpeg/pull/1303) ([zodf0055980](https://github.com/zodf0055980))
- opj\_j2k\_write\_sod\(\): avoid potential heap buffer overflow \(fixes \#1299\) \(probably master only\) [\#1301](https://github.com/uclouvain/openjpeg/pull/1301) ([rouault](https://github.com/rouault))
- pi.c: avoid out of bounds access with POC \(refs https://github.com/uclouvain/openjpeg/issues/1293\#issuecomment-737122836\) [\#1300](https://github.com/uclouvain/openjpeg/pull/1300) ([rouault](https://github.com/rouault))
- opj\_t2\_encode\_packet\(\): avoid out of bound access of \#1297, but likely not the proper fix [\#1298](https://github.com/uclouvain/openjpeg/pull/1298) ([rouault](https://github.com/rouault))
- opj\_t2\_encode\_packet\(\): avoid out of bound access of \#1294, but likely not the proper fix [\#1296](https://github.com/uclouvain/openjpeg/pull/1296) ([rouault](https://github.com/rouault))
- opj\_j2k\_setup\_encoder\(\): validate POC compno0 and compno1 \(fixes \#1293\) [\#1295](https://github.com/uclouvain/openjpeg/pull/1295) ([rouault](https://github.com/rouault))
- Encoder: avoid global buffer overflow on irreversible conversion when… [\#1292](https://github.com/uclouvain/openjpeg/pull/1292) ([rouault](https://github.com/rouault))
- Decoding: deal with some SPOT6 images that have tiles with a single tile-part with TPsot == 0 and TNsot == 0, and with missing EOC [\#1291](https://github.com/uclouvain/openjpeg/pull/1291) ([rouault](https://github.com/rouault))
- Free p\_tcd\_marker\_info to avoid memory leak [\#1288](https://github.com/uclouvain/openjpeg/pull/1288) ([zodf0055980](https://github.com/zodf0055980))
- Encoder: grow again buffer size [\#1287](https://github.com/uclouvain/openjpeg/pull/1287) ([zodf0055980](https://github.com/zodf0055980))
- Encoder: avoid uint32 overflow when allocating memory for codestream buffer \(fixes \#1243\) [\#1276](https://github.com/uclouvain/openjpeg/pull/1276) ([rouault](https://github.com/rouault))
- Java compatibility from 1.5 to 1.6 [\#1263](https://github.com/uclouvain/openjpeg/pull/1263) ([jiapei100](https://github.com/jiapei100))
- opj\_decompress: fix double-free on input directory with mix of valid and invalid images [\#1262](https://github.com/uclouvain/openjpeg/pull/1262) ([rouault](https://github.com/rouault))
- openjp2: Plug image leak when failing to allocate codestream index. [\#1260](https://github.com/uclouvain/openjpeg/pull/1260) ([sebras](https://github.com/sebras))
- openjp2: Plug memory leak when setting data as TLS fails. [\#1258](https://github.com/uclouvain/openjpeg/pull/1258) ([sebras](https://github.com/sebras))
- openjp2: Error out if failing to create Tier 1 handle. [\#1256](https://github.com/uclouvain/openjpeg/pull/1256) ([sebras](https://github.com/sebras))
- Testing for invalid values of width, height, numcomps [\#1254](https://github.com/uclouvain/openjpeg/pull/1254) ([szukw000](https://github.com/szukw000))
- Single-threaded performance improvements in forward DWT for 5-3 and 9-7 \(and other improvements\) [\#1253](https://github.com/uclouvain/openjpeg/pull/1253) ([rouault](https://github.com/rouault))
- Add support for multithreading in encoder [\#1248](https://github.com/uclouvain/openjpeg/pull/1248) ([rouault](https://github.com/rouault))
- Add support for generation of PLT markers in encoder [\#1246](https://github.com/uclouvain/openjpeg/pull/1246) ([rouault](https://github.com/rouault))
- Fix warnings about signed/unsigned casts in pi.c [\#1244](https://github.com/uclouvain/openjpeg/pull/1244) ([rouault](https://github.com/rouault))
- opj\_decompress: add sanity checks to avoid segfault in case of decoding error [\#1240](https://github.com/uclouvain/openjpeg/pull/1240) ([rouault](https://github.com/rouault))
- ignore wrong icc [\#1236](https://github.com/uclouvain/openjpeg/pull/1236) ([szukw000](https://github.com/szukw000))
- Implement writing of IMF profiles [\#1235](https://github.com/uclouvain/openjpeg/pull/1235) ([rouault](https://github.com/rouault))
- tests: add alternate checksums for libtiff 4.1 [\#1234](https://github.com/uclouvain/openjpeg/pull/1234) ([rouault](https://github.com/rouault))
- opj\_tcd\_init\_tile\(\): avoid integer overflow [\#1232](https://github.com/uclouvain/openjpeg/pull/1232) ([rouault](https://github.com/rouault))
- tests/fuzzers: link fuzz binaries using $LIB\_FUZZING\_ENGINE. [\#1230](https://github.com/uclouvain/openjpeg/pull/1230) ([Dor1s](https://github.com/Dor1s))
- opj\_j2k\_update\_image\_dimensions\(\): reject images whose coordinates are beyond INT\_MAX \(fixes \#1228\) [\#1229](https://github.com/uclouvain/openjpeg/pull/1229) ([rouault](https://github.com/rouault))
- Fix resource leaks [\#1226](https://github.com/uclouvain/openjpeg/pull/1226) ([dodys](https://github.com/dodys))
- abi-check.sh: fix false positive ABI error, and display output error log [\#1218](https://github.com/uclouvain/openjpeg/pull/1218) ([rouault](https://github.com/rouault))
- pi.c: avoid integer overflow, resulting in later invalid access to memory in opj\_t2\_decode\_packets\(\) [\#1217](https://github.com/uclouvain/openjpeg/pull/1217) ([rouault](https://github.com/rouault))
- Add check to validate SGcod/SPcoc/SPcod parameter values. [\#1211](https://github.com/uclouvain/openjpeg/pull/1211) ([sebras](https://github.com/sebras))
- Fix buffer overflow reading an image file less than four characters [\#1196](https://github.com/uclouvain/openjpeg/pull/1196) ([robert-ancell](https://github.com/robert-ancell))
- compression: emit POC marker when only one single POC is requested \(f… [\#1192](https://github.com/uclouvain/openjpeg/pull/1192) ([rouault](https://github.com/rouault))
- Fix several potential vulnerabilities [\#1185](https://github.com/uclouvain/openjpeg/pull/1185) ([Young-X](https://github.com/Young-X))
- openjp2/j2k: Report error if all wanted components are not decoded. [\#1164](https://github.com/uclouvain/openjpeg/pull/1164) ([sebras](https://github.com/sebras))
## [v2.3.1](https://github.com/uclouvain/openjpeg/releases/v2.3.1) (2019-04-02)
[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.3.0...v2.3.1)
**Closed issues:**
- v2.2.0 regression for decoding images where TNsot == 0 [\#1120](https://github.com/uclouvain/openjpeg/issues/1120)
- Int overflow in jp3d [\#1162](https://github.com/uclouvain/openjpeg/issues/1162)
- Heap buffer overflow in opj\_j2k\_update\_image\_data\(\) triggered with Ghostscript [\#1157](https://github.com/uclouvain/openjpeg/issues/1157)
- LINUX install doesn't work when building shared libraries is disabled [\#1155](https://github.com/uclouvain/openjpeg/issues/1155)
- OPENJPEG null ptr dereference in openjpeg-2.3.0/src/bin/jp2/convert.c:2243 [\#1152](https://github.com/uclouvain/openjpeg/issues/1152)
- How to drop certain subbands/layers in DWT [\#1147](https://github.com/uclouvain/openjpeg/issues/1147)
- where is the MQ-Coder ouput stream in t2.c? [\#1146](https://github.com/uclouvain/openjpeg/issues/1146)
- OpenJPEG 2.3 \(and 2.2?\) multi component image fails to decode with KDU v7.10 [\#1132](https://github.com/uclouvain/openjpeg/issues/1132)
- Missing checks for header\_info.height and header\_info.width in function pnmtoimage in src/bin/jpwl/convert.c, which can lead to heap buffer overflow [\#1126](https://github.com/uclouvain/openjpeg/issues/1126)
- Assertion Failure in jp2.c [\#1125](https://github.com/uclouvain/openjpeg/issues/1125)
- Division-by-zero vulnerabilities in the function pi\_next\_pcrl, pi\_next\_cprl and pi\_next\_rpcl in src/lib/openjp3d/pi.c [\#1123](https://github.com/uclouvain/openjpeg/issues/1123)
- Precinct switch \(-c\) doesn't right-shift last record to remaining resolution levels [\#1117](https://github.com/uclouvain/openjpeg/issues/1117)
- Sample: encode J2K a data using streams??? [\#1114](https://github.com/uclouvain/openjpeg/issues/1114)
- HIGH THROUGHPUT JPEG 2000 \(HTJ2K\) [\#1112](https://github.com/uclouvain/openjpeg/issues/1112)
- How to build openjpeg for arm linux? [\#1108](https://github.com/uclouvain/openjpeg/issues/1108)
- crash [\#1106](https://github.com/uclouvain/openjpeg/issues/1106)
- JP2000 returning OPJ\_CLRSPC\_UNKNOWN color space [\#1103](https://github.com/uclouvain/openjpeg/issues/1103)
- Compilation successful but install unsuccessful: Calling executables throws libraries missing error [\#1102](https://github.com/uclouvain/openjpeg/issues/1102)
- fprintf format string requires 1 parameter but only 0 are given [\#1093](https://github.com/uclouvain/openjpeg/issues/1093)
- fprintf format string requires 1 parameter but only 0 are given [\#1092](https://github.com/uclouvain/openjpeg/issues/1092)
- sprintf buffer overflow [\#1088](https://github.com/uclouvain/openjpeg/issues/1088)
- sprintf buffer overflow [\#1085](https://github.com/uclouvain/openjpeg/issues/1085)
- Infinite loop when reading jp2 [\#1081](https://github.com/uclouvain/openjpeg/issues/1081)
- missing format string parameter [\#1074](https://github.com/uclouvain/openjpeg/issues/1074)
- Excessive Iteration in opj\_t1\_encode\_cblks \(src/lib/openjp2/t1.c\) [\#1059](https://github.com/uclouvain/openjpeg/issues/1059)
- Out-of-bound left shift in opj\_j2k\_setup\_encoder \(src/lib/openjp2/j2k.c\) [\#1057](https://github.com/uclouvain/openjpeg/issues/1057)
- Encode image on Unsplash [\#1054](https://github.com/uclouvain/openjpeg/issues/1054)
- Integer overflow in opj\_t1\_encode\_cblks \(src/lib/openjp2/t1.c\) [\#1053](https://github.com/uclouvain/openjpeg/issues/1053)
- Signed Integer Overflow - 68065512 [\#1048](https://github.com/uclouvain/openjpeg/issues/1048)
- Similar vulnerable functions related to CVE-2017-14041 [\#1044](https://github.com/uclouvain/openjpeg/issues/1044)
- \[ERROR\] COD marker already read. No more than one COD marker per tile. [\#1043](https://github.com/uclouvain/openjpeg/issues/1043)
- failing to install latest version of openjpeg from source [\#1041](https://github.com/uclouvain/openjpeg/issues/1041)
- Trouble compressing large raw image [\#1032](https://github.com/uclouvain/openjpeg/issues/1032)
- Download and installed code from 2.3 archive. Installing 2.2? [\#1030](https://github.com/uclouvain/openjpeg/issues/1030)
- missing fclose [\#1029](https://github.com/uclouvain/openjpeg/issues/1029)
- NULL Pointer Access in function imagetopnm of convert.c\(jp2\):1289 [\#860](https://github.com/uclouvain/openjpeg/issues/860)
- NULL Pointer Access in function imagetopnm of convert.c:2226\(jp2\) [\#859](https://github.com/uclouvain/openjpeg/issues/859)
- Heap Buffer Overflow in function imagetotga of convert.c\(jp2\):942 [\#858](https://github.com/uclouvain/openjpeg/issues/858)
**Merged pull requests:**
- abi-check.sh: fix broken download URL [\#1188](https://github.com/uclouvain/openjpeg/pull/1188) ([rouault](https://github.com/rouault))
- opj\_t1\_encode\_cblks: fix UBSAN signed integer overflow [\#1187](https://github.com/uclouvain/openjpeg/pull/1187) ([rouault](https://github.com/rouault))
- convertbmp: detect invalid file dimensions early \(CVE-2018-6616\) [\#1172](https://github.com/uclouvain/openjpeg/pull/1172) ([hlef](https://github.com/hlef))
- color\_apply\_icc\_profile: avoid potential heap buffer overflow [\#1170](https://github.com/uclouvain/openjpeg/pull/1170) ([rouault](https://github.com/rouault))
- Fix multiple potential vulnerabilities and bugs [\#1168](https://github.com/uclouvain/openjpeg/pull/1168) ([Young-X](https://github.com/Young-X))
- Fix several memory and resource leaks [\#1163](https://github.com/uclouvain/openjpeg/pull/1163) ([nforro](https://github.com/nforro))
- Fix some potential overflow issues [\#1161](https://github.com/uclouvain/openjpeg/pull/1161) ([stweil](https://github.com/stweil))
- jp3d/jpwl convert: fix write stack buffer overflow [\#1160](https://github.com/uclouvain/openjpeg/pull/1160) ([hlef](https://github.com/hlef))
- Int overflow fixed [\#1159](https://github.com/uclouvain/openjpeg/pull/1159) ([ichlubna](https://github.com/ichlubna))
- Update knownfailures- files given current configurations [\#1149](https://github.com/uclouvain/openjpeg/pull/1149) ([rouault](https://github.com/rouault))
- CVE-2018-5785: fix issues with zero bitmasks [\#1148](https://github.com/uclouvain/openjpeg/pull/1148) ([hlef](https://github.com/hlef))
- openjp2/jp2: Fix two format strings [\#1143](https://github.com/uclouvain/openjpeg/pull/1143) ([stweil](https://github.com/stweil))
- Changes in pnmtoimage if image data are missing [\#1141](https://github.com/uclouvain/openjpeg/pull/1141) ([szukw000](https://github.com/szukw000))
- Relative path to header files is hardcoded in OpenJPEGConfig.cmake.in file [\#1140](https://github.com/uclouvain/openjpeg/pull/1140) ([bukatlib](https://github.com/bukatlib))
- Cast on uint ceildiv [\#1136](https://github.com/uclouvain/openjpeg/pull/1136) ([reverson](https://github.com/reverson))
- Add -DBUILD\_PKGCONFIG\_FILES to install instructions [\#1133](https://github.com/uclouvain/openjpeg/pull/1133) ([robe2](https://github.com/robe2))
- Fix some typos in code comments and documentation [\#1128](https://github.com/uclouvain/openjpeg/pull/1128) ([stweil](https://github.com/stweil))
- Fix regression in reading files with TNsot == 0 \(refs \#1120\) [\#1121](https://github.com/uclouvain/openjpeg/pull/1121) ([rouault](https://github.com/rouault))
- Use local type declaration for POSIX standard type only for MS compiler [\#1119](https://github.com/uclouvain/openjpeg/pull/1119) ([stweil](https://github.com/stweil))
- Fix Mac builds [\#1104](https://github.com/uclouvain/openjpeg/pull/1104) ([rouault](https://github.com/rouault))
- jp3d: Replace sprintf\(\) by snprintf\(\) in volumetobin\(\) [\#1101](https://github.com/uclouvain/openjpeg/pull/1101) ([kbabioch](https://github.com/kbabioch))
- opj\_mj2\_extract: Rename output\_location to output\_prefix [\#1096](https://github.com/uclouvain/openjpeg/pull/1096) ([kbabioch](https://github.com/kbabioch))
- mj2: Add missing variable to format string in fprintf\(\) invocation in meta\_out.c [\#1094](https://github.com/uclouvain/openjpeg/pull/1094) ([kbabioch](https://github.com/kbabioch))
- Convert files to UTF-8 encoding [\#1090](https://github.com/uclouvain/openjpeg/pull/1090) ([stweil](https://github.com/stweil))
- fix unchecked integer multiplication overflow [\#1080](https://github.com/uclouvain/openjpeg/pull/1080) ([setharnold](https://github.com/setharnold))
- Fixed typos [\#1062](https://github.com/uclouvain/openjpeg/pull/1062) ([radarhere](https://github.com/radarhere))
- Note that seek uses SEEK\_SET behavior. [\#1055](https://github.com/uclouvain/openjpeg/pull/1055) ([ideasman42](https://github.com/ideasman42))
- Some Doxygen tags are removed [\#1050](https://github.com/uclouvain/openjpeg/pull/1050) ([szukw000](https://github.com/szukw000))
- Fix resource leak \(CID 179466\) [\#1047](https://github.com/uclouvain/openjpeg/pull/1047) ([stweil](https://github.com/stweil))
- Changed cmake version test to allow for cmake 2.8.11.x [\#1042](https://github.com/uclouvain/openjpeg/pull/1042) ([radarhere](https://github.com/radarhere))
- Add missing fclose\(\) statement in error condition. [\#1037](https://github.com/uclouvain/openjpeg/pull/1037) ([gfiumara](https://github.com/gfiumara))
## [v2.3.0](https://github.com/uclouvain/openjpeg/releases/v2.3.0) (2017-10-04)
[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.2.0...v2.3.0)
**Implemented enhancements:**
- Sub-tile decoding: only decode precincts and codeblocks that intersect the window specified in opj_set_decode_area() [\#990](https://github.com/uclouvain/openjpeg/pull/990) ([rouault](https://github.com/rouault))
- Sub-tile decoding: only apply IDWT on areas that participate to the window of interest [\#1001](https://github.com/uclouvain/openjpeg/pull/1001) ([rouault](https://github.com/rouault))
- Sub-tile decoding: memory use reduction and perf improvements [\#1010](https://github.com/uclouvain/openjpeg/pull/1010) ([rouault](https://github.com/rouault))
- Add capability to decode only a subset of all components of an image. [\#1022](https://github.com/uclouvain/openjpeg/pull/1022) ([rouault](https://github.com/rouault))
**Fixed bugs:**
- Setting x offset of decode region to -1 causes opj\_decompress to go into infinite loop [\#736](https://github.com/uclouvain/openjpeg/issues/736)
- Problem decoding multiple tiles with get\_decoded\_tile when cmap/pclr/cdef boxes are present in jp2 file [\#484](https://github.com/uclouvain/openjpeg/issues/484)
- set reduce\_factor\_may\_fail [\#474](https://github.com/uclouvain/openjpeg/issues/474)
- opj\_compress.exe, command line parser, infinite loop [\#469](https://github.com/uclouvain/openjpeg/issues/469)
- Various memory access issues found via fuzzing [\#448](https://github.com/uclouvain/openjpeg/issues/448)
- Multiple warnings when building OpenJPEG \(trunk\) [\#442](https://github.com/uclouvain/openjpeg/issues/442)
- Bulk fuzz-testing report [\#427](https://github.com/uclouvain/openjpeg/issues/427)
- remove all printf from openjpeg / use proper function pointer for logging [\#371](https://github.com/uclouvain/openjpeg/issues/371)
- minor changes, clean-up [\#349](https://github.com/uclouvain/openjpeg/issues/349)
- image-\>numcomps \> 4 [\#333](https://github.com/uclouvain/openjpeg/issues/333)
- Improve support for region of interest [\#39](https://github.com/uclouvain/openjpeg/issues/39)
- Public function to tell kernel type used \(5x3 vs 9x7\) [\#3](https://github.com/uclouvain/openjpeg/issues/3)
- elf binary in source package ? [\#1026](https://github.com/uclouvain/openjpeg/issues/1026)
- opj\_cio\_open [\#1025](https://github.com/uclouvain/openjpeg/issues/1025)
- Building with Visual Studio 2015 [\#1023](https://github.com/uclouvain/openjpeg/issues/1023)
- tcd.cpp\>:1617:33: error: assigning to 'OPJ\_INT32 \*' \(aka 'int \*'\) from incompatible type 'void \*' [\#1021](https://github.com/uclouvain/openjpeg/issues/1021)
- j2k.cpp \> comparison of address of 'p\_j2k-\>m\_cp.tcps\[0\].m\_data' not equal to a null pointer is always true [\#1020](https://github.com/uclouvain/openjpeg/issues/1020)
- Openjpeg 2.2.0 always build shared library even though -DBUILD\_SHARED\_LIBS:bool=off [\#1019](https://github.com/uclouvain/openjpeg/issues/1019)
- missing fclose [\#1018](https://github.com/uclouvain/openjpeg/issues/1018)
- Use opj\_image\_data\_free instead of opj\_free for image-\>comps\[\].data [\#1014](https://github.com/uclouvain/openjpeg/issues/1014)
- malloc poison on some compilers - cross compiling [\#1013](https://github.com/uclouvain/openjpeg/issues/1013)
- Add OPJ\_VERSION\_MAJOR, OPJ\_VERSION\_MINOR, OPJ\_VERSION\_MICRO macros in openjpeg.h [\#1011](https://github.com/uclouvain/openjpeg/issues/1011)
- Encode: do not perform rate control for single-tile lossless [\#1009](https://github.com/uclouvain/openjpeg/issues/1009)
- opj\_set\_decoded\_resolution\_factor\(\): bad interaction with opj\_set\_decode\_area\(\) and/or opj\_decode\(\) [\#1006](https://github.com/uclouvain/openjpeg/issues/1006)
- memory allocation failure with .pgx file [\#999](https://github.com/uclouvain/openjpeg/issues/999)
- Unable to fuzz with raw image as input [\#998](https://github.com/uclouvain/openjpeg/issues/998)
- stack-based buffer overflow write in pgxtoimage \(/convert.c\) [\#997](https://github.com/uclouvain/openjpeg/issues/997)
- freeze with a crafted bmp [\#996](https://github.com/uclouvain/openjpeg/issues/996)
- invalid memory write in tgatoimage \(convert.c\) [\#995](https://github.com/uclouvain/openjpeg/issues/995)
- static build on Windows fails [\#994](https://github.com/uclouvain/openjpeg/issues/994)
- another heap-based buffer overflow in opj\_t2\_encode\_packet \(t2.c\) [\#993](https://github.com/uclouvain/openjpeg/issues/993)
- heap-based buffer overflow in opj\_t2\_encode\_packet \(t2.c\) [\#992](https://github.com/uclouvain/openjpeg/issues/992)
- heap-based buffer overflow in opj\_write\_bytes\_LE \(cio.c\) \(unfixed \#985\) [\#991](https://github.com/uclouvain/openjpeg/issues/991)
- heap overflow in opj\_compress [\#988](https://github.com/uclouvain/openjpeg/issues/988)
- heap overflow in opj\_decompress [\#987](https://github.com/uclouvain/openjpeg/issues/987)
- heap-based buffer overflow in opj\_bio\_byteout \(bio.c\) [\#986](https://github.com/uclouvain/openjpeg/issues/986)
- heap-based buffer overflow in opj\_write\_bytes\_LE \(cio.c\) [\#985](https://github.com/uclouvain/openjpeg/issues/985)
- memory allocation failure in opj\_aligned\_alloc\_n \(opj\_malloc.c\) [\#983](https://github.com/uclouvain/openjpeg/issues/983)
- heap-base buffer overflow in opj\_mqc\_flush \(mqc.c\) [\#982](https://github.com/uclouvain/openjpeg/issues/982)
- Decode fails for JP2s with ICC profile [\#981](https://github.com/uclouvain/openjpeg/issues/981)
- Unit tests failing on Ubuntu 17.04 [\#916](https://github.com/uclouvain/openjpeg/issues/916)
- Encoder crashes on small images [\#901](https://github.com/uclouvain/openjpeg/issues/901)
- openjpeg-1.5.3 fails to compile [\#830](https://github.com/uclouvain/openjpeg/issues/830)
- opj\_compress crops image \(win\) or creates a jp2 which cannot be decompressed \(lin\) [\#716](https://github.com/uclouvain/openjpeg/issues/716)
- -d flag is silently ignored when decoding a single tile [\#693](https://github.com/uclouvain/openjpeg/issues/693)
- transition away from dev-utils [\#628](https://github.com/uclouvain/openjpeg/issues/628)
- update instructions to build with Visual Studio and 64-Bit Visual C++ Toolset. [\#1028](https://github.com/uclouvain/openjpeg/pull/1028) ([quangnh89](https://github.com/quangnh89))
- Add missing newline at end of file [\#1024](https://github.com/uclouvain/openjpeg/pull/1024) ([stweil](https://github.com/stweil))
- merge master into coverity\_scan to update coverity results [\#1008](https://github.com/uclouvain/openjpeg/pull/1008) ([detonin](https://github.com/detonin))
- Use more const qualifiers [\#984](https://github.com/uclouvain/openjpeg/pull/984) ([stweil](https://github.com/stweil))
- Changes in converttif.c for PPC64 [\#980](https://github.com/uclouvain/openjpeg/pull/980) ([szukw000](https://github.com/szukw000))
## [v2.2.0](https://github.com/uclouvain/openjpeg/releases/v2.2.0) (2017-08-10)
[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.1.2...v2.2.0)
**Implemented enhancements:**
- Memory consumption reduction at decoding side [\#968](https://github.com/uclouvain/openjpeg/pull/968) ([rouault](https://github.com/rouault))
- T1 & DWT multithreading decoding optimizations [\#786](https://github.com/uclouvain/openjpeg/pull/786) ([rouault](https://github.com/rouault))
- Tier1 decoder speed optimizations [\#783](https://github.com/uclouvain/openjpeg/pull/783) ([rouault](https://github.com/rouault))
- Inverse DWT 5x3: lift implementation / SSE accelerated version [\#953](https://github.com/uclouvain/openjpeg/issues/953)
- install static libraries [\#969](https://github.com/uclouvain/openjpeg/pull/969) ([jeroen](https://github.com/jeroen))
- IDWT 5x3 single-pass lifting and SSE2/AVX2 implementation [\#957](https://github.com/uclouvain/openjpeg/pull/957) ([rouault](https://github.com/rouault))
- build both shared and static library [\#954](https://github.com/uclouvain/openjpeg/pull/954) ([jeroen](https://github.com/jeroen))
- T1 flag optimizations \(\#172\) [\#945](https://github.com/uclouvain/openjpeg/pull/945) ([rouault](https://github.com/rouault))
- CMake: add stronger warnings for openjp2 lib/bin by default, and error out on declaration-after-statement [\#936](https://github.com/uclouvain/openjpeg/pull/936) ([rouault](https://github.com/rouault))
- Quiet mode for opj\_decompress via -quiet long parameter. [\#928](https://github.com/uclouvain/openjpeg/pull/928) ([RussellMcOrmond](https://github.com/RussellMcOrmond))
- Implement predictive termination check [\#800](https://github.com/uclouvain/openjpeg/pull/800) ([rouault](https://github.com/rouault))
**Fixed bugs:**
- Several issues spotted by Google OSS Fuzz - [see here](https://github.com/search?l=&q=OSS+Fuzz+author-date%3A2017-07-04..2017-08-01+repo%3Auclouvain%2Fopenjpeg&ref=advsearch&type=Commits&utf8=%E2%9C%93)
- Missing fclose [\#976](https://github.com/uclouvain/openjpeg/issues/976)
- Heap buffer overflow read in openjpeg imagetopnm [\#970](https://github.com/uclouvain/openjpeg/issues/970)
- opj\_decompress opj\_j2k\_update\_image\_data\(\) Segment falut [\#948](https://github.com/uclouvain/openjpeg/issues/948)
- Generic Crash in 1.5.0 [\#941](https://github.com/uclouvain/openjpeg/issues/941)
- Segmentation Faults [\#940](https://github.com/uclouvain/openjpeg/issues/940)
- Assertions thrown [\#939](https://github.com/uclouvain/openjpeg/issues/939)
- Floating Point Errors [\#938](https://github.com/uclouvain/openjpeg/issues/938)
- Division by zero crash [\#937](https://github.com/uclouvain/openjpeg/issues/937)
- malformed jp2 can cause heap-buffer-overflow [\#909](https://github.com/uclouvain/openjpeg/issues/909)
- NULL dereference can cause by malformed file [\#908](https://github.com/uclouvain/openjpeg/issues/908)
- Out of bound read in opj\_j2k\_add\_mct [\#907](https://github.com/uclouvain/openjpeg/issues/907)
- Check bpno\_plus\_one in opj\_t1\_decode\_cblk [\#903](https://github.com/uclouvain/openjpeg/issues/903)
- Undefined-shift in opj\_j2k\_read\_siz [\#902](https://github.com/uclouvain/openjpeg/issues/902)
- opj\_compress v2.1.2 can create images opj\_decompress cannot read [\#891](https://github.com/uclouvain/openjpeg/issues/891)
- Improper usage of opj\_int\_ceildiv can cause overflows [\#889](https://github.com/uclouvain/openjpeg/issues/889)
- Undefined shift in opj\_get\_all\_encoding\_parameters [\#885](https://github.com/uclouvain/openjpeg/issues/885)
- Denial of service \(crash\) due to use-after-free when decoding an illegal JPEG2000 image file v2.1.2 \(2017-04 [\#880](https://github.com/uclouvain/openjpeg/issues/880)
- Denial of service \(crash\) when decoding an illegal JPEG2000 image file v2.1.2 \(2017-03\) [\#879](https://github.com/uclouvain/openjpeg/issues/879)
- bug png 2 j2k [\#868](https://github.com/uclouvain/openjpeg/issues/868)
- Inconsistent compression using cinema settings on folder of non-compliant image [\#864](https://github.com/uclouvain/openjpeg/issues/864)
- Openjpeg-2.1.2 Heap Buffer Overflow Vulnerability due to Insufficient check [\#862](https://github.com/uclouvain/openjpeg/issues/862)
- Heap Buffer Overflow in function pnmtoimage of convert.c [\#861](https://github.com/uclouvain/openjpeg/issues/861)
- CVE-2016-9112 FPE\(Floating Point Exception\) in lib/openjp2/pi.c:523 [\#855](https://github.com/uclouvain/openjpeg/issues/855)
- CVE-2016-5139, CVE-2016-5152, CVE-2016-5158, CVE-2016-5159 [\#854](https://github.com/uclouvain/openjpeg/issues/854)
- Undefined Reference error [\#853](https://github.com/uclouvain/openjpeg/issues/853)
- opj\_compress with lossy compression results in strange pixel values [\#851](https://github.com/uclouvain/openjpeg/issues/851)
- CVE-2016-1626 and CVE-2016-1628 [\#850](https://github.com/uclouvain/openjpeg/issues/850)
- Out-of-Bounds Write in opj\_mqc\_byteout of mqc.c [\#835](https://github.com/uclouvain/openjpeg/issues/835)
- WARNING in tgt\_create tree-\>numnodes == 0, no tree created. [\#794](https://github.com/uclouvain/openjpeg/issues/794)
- Potential overflow when precision is larger than 32 [\#781](https://github.com/uclouvain/openjpeg/issues/781)
- division-by-zero in function opj\_pi\_next\_rpcl of pi.c \(line 366\) [\#780](https://github.com/uclouvain/openjpeg/issues/780)
- division-by-zero in function opj\_pi\_next\_rpcl of pi.c \(line 363\) [\#779](https://github.com/uclouvain/openjpeg/issues/779)
- division-by-zero in function opj\_pi\_next\_pcrl of pi.c \(line 447\) [\#778](https://github.com/uclouvain/openjpeg/issues/778)
- division-by-zero in function opj\_pi\_next\_pcrl of pi.c \(line 444\) [\#777](https://github.com/uclouvain/openjpeg/issues/777)
- Encoding the following file with 32x32 tiling produces jp2 image with artifact [\#737](https://github.com/uclouvain/openjpeg/issues/737)
- division-by-zero \(SIGFPE\) error in opj\_pi\_next\_cprl function \(line 526 of pi.c\) [\#732](https://github.com/uclouvain/openjpeg/issues/732)
- division-by-zero \(SIGFPE\) error in opj\_pi\_next\_cprl function \(line 523 of pi.c\) [\#731](https://github.com/uclouvain/openjpeg/issues/731)
- OpenJpeg 2.1 and 1.4 fails to decompress this file correctly [\#721](https://github.com/uclouvain/openjpeg/issues/721)
- MQ Encode :uninitialized memory access when first pass does not output any bytes [\#709](https://github.com/uclouvain/openjpeg/issues/709)
- Out-of-bounds read in opj\_j2k\_update\_image\_data and opj\_tgt\_reset function [\#704](https://github.com/uclouvain/openjpeg/issues/704)
- Remove opj\_aligned\_malloc / opj\_aligned\_realloc / opj\_aligned\_free? [\#689](https://github.com/uclouvain/openjpeg/issues/689)
- There is an issue with rendering some type of jpeg file. Please ref the link. [\#672](https://github.com/uclouvain/openjpeg/issues/672)
- Null Dereference in tcd\_malloc\_decode\_tile [\#657](https://github.com/uclouvain/openjpeg/issues/657)
- ETS-C1P0-p0\_12.j2k-compare2ref & NR-C1P0-p0\_12.j2k-compare2base failing under windows [\#655](https://github.com/uclouvain/openjpeg/issues/655)
- Memory leak [\#631](https://github.com/uclouvain/openjpeg/issues/631)
- Test 481 reports error in valgrind memcheck [\#612](https://github.com/uclouvain/openjpeg/issues/612)
- reserved identifier violation [\#587](https://github.com/uclouvain/openjpeg/issues/587)
- Buffer overflow when compressing some 16 bits images of the test suite [\#539](https://github.com/uclouvain/openjpeg/issues/539)
- Heap-buffer-overflow in opj\_dwt\_decode\_1 [\#480](https://github.com/uclouvain/openjpeg/issues/480)
- Automated fuzz testing [\#468](https://github.com/uclouvain/openjpeg/issues/468)
- Expected to find EPH marker [\#425](https://github.com/uclouvain/openjpeg/issues/425)
- read: segment too long \(6182\) with max \(35872\) for codeblock 0 \(p=19, b=2, r=5, c=1\) [\#284](https://github.com/uclouvain/openjpeg/issues/284)
- building 64bit version has lots of warnings [\#244](https://github.com/uclouvain/openjpeg/issues/244)
- Wrong encoding of small tiles with high level number [\#239](https://github.com/uclouvain/openjpeg/issues/239)
- Errors raised in pi.c by VS11 analyzer [\#190](https://github.com/uclouvain/openjpeg/issues/190)
- Undocumented optimization found in v2 branch of openjpeg [\#183](https://github.com/uclouvain/openjpeg/issues/183)
- T1 optimisations jpeg2000 [\#172](https://github.com/uclouvain/openjpeg/issues/172)
- Remove OPJ\_NOSANITIZE in opj\_bio\_read\(\) and opj\_bio\_write\(\) \(\#761\) [\#955](https://github.com/uclouvain/openjpeg/pull/955) ([rouault](https://github.com/rouault))
- Fix bypass pterm termall and lossless decomposition issue \(\#891, \#892\) [\#949](https://github.com/uclouvain/openjpeg/pull/949) ([rouault](https://github.com/rouault))
- Escape quotes to ensure README renders on GitHub correctly [\#914](https://github.com/uclouvain/openjpeg/pull/914) ([alexwlchan](https://github.com/alexwlchan))
- Remove spurious .R macros from manpages [\#899](https://github.com/uclouvain/openjpeg/pull/899) ([jwilk](https://github.com/jwilk))
- Remove warnings related to empty tag-trees. [\#893](https://github.com/uclouvain/openjpeg/pull/893) ([rouault](https://github.com/rouault))
**Maintenance-related tasks:**
- Submit OpenJPEG to oss-fuzz [\#965](https://github.com/uclouvain/openjpeg/issues/965)
- Updates for Doxygen to suppress warnings [\#849](https://github.com/uclouvain/openjpeg/issues/849)
- Remove useless knownfailures \(since LAZY encoding is fixed\) [\#964](https://github.com/uclouvain/openjpeg/pull/964) ([rouault](https://github.com/rouault))
- Enable AVX2 at runtime on Travis-CI and AppVeyor [\#963](https://github.com/uclouvain/openjpeg/pull/963) ([rouault](https://github.com/rouault))
- Tests: test opj\_compress in VSC mode \(related to \#172\) [\#935](https://github.com/uclouvain/openjpeg/pull/935) ([rouault](https://github.com/rouault))
- Reformat: apply reformattin on .h files \(\#128\) [\#926](https://github.com/uclouvain/openjpeg/pull/926) ([rouault](https://github.com/rouault))
- Add mechanisms to reformat and check code style, and reformat whole codebase \(\#128\) [\#919](https://github.com/uclouvain/openjpeg/pull/919) ([rouault](https://github.com/rouault))
- Add profiling of CPU and memory usage \(\#912\) [\#918](https://github.com/uclouvain/openjpeg/pull/918) ([rouault](https://github.com/rouault))
- Add performance benchmarking scripts [\#917](https://github.com/uclouvain/openjpeg/pull/917) ([rouault](https://github.com/rouault))
- Fix retrieval of jpylyzer in AppVeyor [\#915](https://github.com/uclouvain/openjpeg/pull/915) ([rouault](https://github.com/rouault))
## [v2.1.2](https://github.com/uclouvain/openjpeg/releases/v2.1.2) (2016-09-28)
[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.1.1...v2.1.2)
@ -459,6 +15,7 @@
- Optimization when building library from source [\#799](https://github.com/uclouvain/openjpeg/issues/799)
- unsigned int16 on Solaris 11.2/sparc [\#796](https://github.com/uclouvain/openjpeg/issues/796)
- appveyor [\#793](https://github.com/uclouvain/openjpeg/issues/793)
- Please make a new release [\#782](https://github.com/uclouvain/openjpeg/issues/782)
- FFMpeg will not link to 2.1.1 release built as shared library [\#766](https://github.com/uclouvain/openjpeg/issues/766)
- API change since v2: opj\_event\_mgr\_t not available [\#754](https://github.com/uclouvain/openjpeg/issues/754)
- openjpeg.h needs dependencies [\#673](https://github.com/uclouvain/openjpeg/issues/673)
@ -672,7 +229,7 @@
- Migration guide v2 [\#160](https://github.com/uclouvain/openjpeg/issues/160)
- Cannot decompress JPEG2000Aware3.18.7.3Win32\_kdutranscode6.3.1.j2k [\#158](https://github.com/uclouvain/openjpeg/issues/158)
- Cannot decompress JPEG2000Aware3.18.7.3Win32.j2k [\#157](https://github.com/uclouvain/openjpeg/issues/157)
- openjpeg@googlegroups.com has disappeared [\#153](https://github.com/uclouvain/openjpeg/issues/153)
- openjpeg@googlegroups.com has disappeard [\#153](https://github.com/uclouvain/openjpeg/issues/153)
- OpenJPEG 1.5.0 crashes on a ridiculously big file... [\#151](https://github.com/uclouvain/openjpeg/issues/151)
- opj\_image vs free [\#146](https://github.com/uclouvain/openjpeg/issues/146)
- Windows .dll file invalid [\#140](https://github.com/uclouvain/openjpeg/issues/140)
@ -735,7 +292,7 @@
- Support unscaled 10 bit data for 2K cinema @ 48 FPS, as per DCI standard [\#671](https://github.com/uclouvain/openjpeg/issues/671)
- Use parallel jobs in ctest [\#664](https://github.com/uclouvain/openjpeg/issues/664)
- \[Security\]Multiple Memory error [\#663](https://github.com/uclouvain/openjpeg/issues/663)
- lossy encoding a 16 bit TIF file : severe artifacts in decompressed image [\#660](https://github.com/uclouvain/openjpeg/issues/660)
- lossy encoding a 16 bit TIF file : severe artifiacts in decompressed image [\#660](https://github.com/uclouvain/openjpeg/issues/660)
- opj\_compress and opj\_decompress : get\_next\_file method uses hard-coded unix path separator [\#630](https://github.com/uclouvain/openjpeg/issues/630)
- Uninitialized variable [\#629](https://github.com/uclouvain/openjpeg/issues/629)
- Use of enum variable for bit flags prevents compilation as C++ source [\#619](https://github.com/uclouvain/openjpeg/issues/619)
@ -772,7 +329,7 @@
- Correct abi-check.sh for PR [\#791](https://github.com/uclouvain/openjpeg/pull/791) ([mayeut](https://github.com/mayeut))
- Update tcd.c [\#790](https://github.com/uclouvain/openjpeg/pull/790) ([maddin200](https://github.com/maddin200))
- Update lcms2 [\#773](https://github.com/uclouvain/openjpeg/pull/773) ([mayeut](https://github.com/mayeut))
- Use lowercase for cmake commands consistently [\#769](https://github.com/uclouvain/openjpeg/pull/769) ([julienmalik](https://github.com/julienmalik))
- Use lowercase for cmake commands consistenly [\#769](https://github.com/uclouvain/openjpeg/pull/769) ([julienmalik](https://github.com/julienmalik))
- Ignore clang's summary warning [\#768](https://github.com/uclouvain/openjpeg/pull/768) ([julienmalik](https://github.com/julienmalik))
- Fix UBSan gcc warning for first arg to memset non null [\#767](https://github.com/uclouvain/openjpeg/pull/767) ([julienmalik](https://github.com/julienmalik))
- Update to libtiff-4.0.6 [\#764](https://github.com/uclouvain/openjpeg/pull/764) ([mayeut](https://github.com/mayeut))

View File

@ -7,7 +7,7 @@
# For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like
# e.g.:
# set(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
cmake_minimum_required(VERSION 2.8.5)
cmake_minimum_required(VERSION 2.8.2)
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0003 NEW)
@ -32,7 +32,7 @@ include_regular_expression("^.*$")
#-----------------------------------------------------------------------------
# OPENJPEG version number, useful for packaging and doxygen doc:
set(OPENJPEG_VERSION_MAJOR 2)
set(OPENJPEG_VERSION_MINOR 5)
set(OPENJPEG_VERSION_MINOR 2)
set(OPENJPEG_VERSION_BUILD 0)
set(OPENJPEG_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
@ -54,11 +54,7 @@ set(PACKAGE_VERSION
# 2.1 | 7
# 2.1.1 | 7
# 2.1.2 | 7
# 2.2.0 | 7
# 2.3.0 | 7
# 2.3.1 | 7
# 2.4.0 | 7
# 2.5.0 | 7
# 2.2.0 | 8
# above is the recommendation by the OPJ team. If you really need to override this default,
# you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
# cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
@ -105,42 +101,66 @@ endif()
# --------------------------------------------------------------------------
# Install directories
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME)
include(GNUInstallDirs)
# Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
set(OPENJPEG_INSTALL_SUBDIR "${PROJECT_NAME}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
string(TOLOWER ${PROJECT_NAME} projectname)
set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
if(NOT OPENJPEG_INSTALL_BIN_DIR)
set(OPENJPEG_INSTALL_BIN_DIR "bin")
endif()
if(NOT OPENJPEG_INSTALL_LIB_DIR)
set(OPENJPEG_INSTALL_LIB_DIR "lib")
endif()
if(NOT OPENJPEG_INSTALL_SHARE_DIR)
set(OPENJPEG_INSTALL_SHARE_DIR "share")
endif()
if(NOT OPENJPEG_INSTALL_DATA_DIR)
set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
endif()
if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
endif()
if(BUILD_DOC)
if(NOT OPENJPEG_INSTALL_MAN_DIR)
set(OPENJPEG_INSTALL_MAN_DIR "share/man/")
endif()
if(NOT OPENJPEG_INSTALL_DOC_DIR)
set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
endif()
endif()
if(NOT OPENJPEG_INSTALL_JNI_DIR)
if(WIN32)
set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_BINDIR})
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR})
else()
set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_LIBDIR})
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR})
endif()
endif()
if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
set(OPENJPEG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${OPENJPEG_INSTALL_SUBDIR}")
# We could install *.cmake files in share/ however those files contains
# hardcoded path to libraries on a multi-arch system (fedora/debian) those
# path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
endif()
if (APPLE)
if (${CMAKE_VERSION} VERSION_LESS 3.0)
# For cmake >= 3.0, we turn on CMP0042 and
# https://cmake.org/cmake/help/v3.0/policy/CMP0042.html mentions
# "Projects wanting @rpath in a targets install name may remove any setting of the INSTALL_NAME_DIR and CMAKE_INSTALL_NAME_DIR variables"
list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()
list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}")
option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
endif()
#-----------------------------------------------------------------------------
# Big endian test:
if (NOT EMSCRIPTEN)
include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
endif()
#-----------------------------------------------------------------------------
# Setup file for setting custom ctest vars
@ -153,7 +173,6 @@ configure_file(
#-----------------------------------------------------------------------------
# OpenJPEG build configuration options.
option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
option(BUILD_STATIC_LIBS "Build OpenJPEG static library." ON)
set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
@ -175,7 +194,6 @@ if(CMAKE_COMPILER_IS_GNUCC)
# set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
# Do not use ffast-math for all build, it would produce incorrect results, only set for release:
set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
set(OPENJP2_COMPILE_OPTIONS ${OPENJP2_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>" -Wall -Wextra -Wconversion -Wunused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement)
endif()
#-----------------------------------------------------------------------------
@ -234,23 +252,24 @@ if(BUILD_JPIP_SERVER)
endif()
add_subdirectory(src/lib)
option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
if(UNIX)
option(BUILD_UNIT_TESTS "Build unit tests (bench_dwt, test_sparse_array, etc..)" OFF)
endif()
#-----------------------------------------------------------------------------
# Build Applications
option(BUILD_CODEC "Build the CODEC executables" ON)
option(BUILD_MJ2 "Build the MJ2 executables." OFF)
option(BUILD_JPWL "Build the JPWL library and executables" OFF)
option(BUILD_JPIP "Build the JPIP library and executables." OFF)
if(BUILD_JPIP)
option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
endif()
option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
option(BUILD_JP3D "Build the JP3D comp" OFF)
mark_as_advanced(BUILD_VIEWER)
mark_as_advanced(BUILD_JAVA)
mark_as_advanced(BUILD_JP3D)
if(BUILD_CODEC)
if(BUILD_CODEC OR BUILD_MJ2)
# OFF: It will only build 3rd party libs if they are not found on the system
# ON: 3rd party libs will ALWAYS be build, and used
option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
@ -280,7 +299,7 @@ if(BUILD_DOC)
endif()
#-----------------------------------------------------------------------------
# Build Testing
# Buld Testing
option(BUILD_TESTING "Build the tests." OFF)
if(BUILD_TESTING)
if(BUILD_CODEC)
@ -304,68 +323,66 @@ if(BUILD_TESTING)
endif()
#-----------------------------------------------------------------------------
# install all targets referenced as OPENJPEGTargets (relocatable with CMake 3.0+)
# install all targets referenced as OPENJPEGTargets
install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
if (${CMAKE_VERSION} VERSION_LESS 3.0)
set(PACKAGE_INIT)
set(PACKAGE_CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR})
configure_file( ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/OpenJPEGConfig.cmake
@ONLY
)
else()
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/OpenJPEGConfig.cmake.in
${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
INSTALL_DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
endif()
configure_file( ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/OpenJPEGConfig.cmake
@ONLY
)
install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
)
#-----------------------------------------------------------------------------
# install CHANGES and LICENSE
if(BUILD_DOC)
if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
endif()
install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
endif()
include (cmake/OpenJPEGCPack.cmake)
#-----------------------------------------------------------------------------
# pkgconfig support
# enabled by default on Unix or if using GCC, disabled by default on other platforms
if(UNIX OR CMAKE_COMPILER_IS_GNUCC)
# enabled by default on Unix, disabled by default on other platforms
if(UNIX)
option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" ON)
else()
option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF)
endif()
if(BUILD_PKGCONFIG_FILES)
macro(set_variable_from_rel_or_absolute_path var root rel_or_abs_path)
if(IS_ABSOLUTE "${rel_or_abs_path}")
set(${var} "${rel_or_abs_path}")
else()
set(${var} "${root}/${rel_or_abs_path}")
endif()
endmacro()
set_variable_from_rel_or_absolute_path("bindir" "\\\${prefix}" "${CMAKE_INSTALL_BINDIR}")
set_variable_from_rel_or_absolute_path("mandir" "\\\${prefix}" "${CMAKE_INSTALL_MANDIR}")
set_variable_from_rel_or_absolute_path("docdir" "\\\${prefix}" "${CMAKE_INSTALL_DOCDIR}")
set_variable_from_rel_or_absolute_path("libdir" "\\\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
set_variable_from_rel_or_absolute_path("includedir" "\\\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR}")
# install in lib and not share (CMAKE_INSTALL_LIBDIR takes care of it for multi-arch)
# install in lib and not share (see multi-arch note above)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
${CMAKE_INSTALL_LIBDIR}/pkgconfig )
${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
#
if(BUILD_JPWL)
# install in lib and not share (see multi-arch note above)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpwl/libopenjpwl.pc.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc @ONLY)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc DESTINATION
${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
endif()
#
if(BUILD_JPIP)
# install in lib and not share (see multi-arch note above)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
${CMAKE_INSTALL_LIBDIR}/pkgconfig )
${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
endif()
#
if(BUILD_JP3D)
# install in lib and not share (see multi-arch note above)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp3d/libopenjp3d.pc.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc @ONLY)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc DESTINATION
${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
endif()
endif()
#-----------------------------------------------------------------------------
# build our version of astyle
SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")

View File

@ -1,32 +0,0 @@
Check-list OpenJPEG Release
* update MAJOR, MINOR, BUILD, SOVERSION in CMakeLists.txt
* update MAJOR, MINOR, BUILD in appveyor.yml
* update CHANGELOG with
`github_changelog_generator --token TOKEN_HERE --exclude-labels gcode_fixed,OpjVersion-1.x --release-url "https://github.com/uclouvain/openjpeg/releases/%s" --since-tag v2.3.1 --future-release v2.4.0 --output append2changelog.md --user uclouvain --project openjpeg --exclude-tags version.1.0` . TOKEN_HERE is created at https://github.com/settings/tokens
* update NEWS.md
* git tag -a v2.4.0 -m "OpenJPEG v2.4.0 release"
* git push origin --tags
* add post to OpenJPEG website in gh-pages branch in _posts/ subdirectory. See commit https://github.com/uclouvain/openjpeg/commit/6563d704f5fb896209dd862ccfc6b97eb9183c5c
* change binversion of openjpeg website in _config.yml in gh-pages branch
* update release description if needed
* update openjpeg.json with latest release
* update OPJ_LATEST_VERSION in abi-check.sh, uncomment and update OPJ_PREVIOUS_VERSION in abi-check.sh, and push
* locally run: OPJ_CI_ABI_CHECK=1 ./tools/travis-ci/abi-check.sh
* cd ~/abi-check/work/abi-check/
* put the sources of the new version in src/openjpeg/2.X.0/version.-2.X.0.tar.gz
* PATH=$PWD/../../tools/abi-tracker/bin:$PWD/../../tools/wdiff/bin:$PWD/../../tools:$PATH abi-monitor -v 2.X.0 -build ./openjpeg.json
* PATH=$PWD/../../tools/abi-tracker/bin:$PWD/../../tools/wdiff/bin:$PWD/../../tools:$PATH abi-tracker -build ./openjpeg.json
* rm -rf src/openjpeg/current
* rm -rf build_logs
* git add --all .
* git commit -m "Update ABI/API compatibility reports after 2.X.0 release"
* git push
* cd ~/openjpeg/openjpeg
* comment back OPJ_PREVIOUS_VERSION and push
* build doc and update Doxygen on website
* manual build on Windows:
- cmake .. -G "Visual Studio 15 2017" -A x64 -DCMAKE_CONFIGURATION_TYPES=Release -DBUILD_THIRDPARTY=ON -D CPACK_GENERATOR:STRING=ZIP -D CPACK_PACKAGE_FILE_NAME:STRING=openjpeg-v2.4.0-windows-x64
- cmake --build . --target package --config Release
* send email to ML opj, comp.compression, iiif
* tweet

View File

@ -9,7 +9,7 @@ To build the library, type from source tree directory:
```
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake ..
make
```
Binaries are then located in the 'bin' directory.
@ -30,9 +30,7 @@ Main available cmake flags:
* To specify the install path: '-DCMAKE\_INSTALL\_PREFIX=/path'
* To build the shared libraries and links the executables against it: '-DBUILD\_SHARED\_LIBS:bool=on' (default: 'ON')
> Note: when using this option, static libraries are not built and executables are dynamically linked.
* PKG_CONFIG files are by default built for Unix compile, you can force to build on other platforms by adding: '-DBUILD_PKGCONFIG_FILES=on'
* To build the CODEC executables: '-DBUILD\_CODEC:bool=on' (default: 'ON')
* To build opjstyle (internal version of astyle) for OpenJPEG development: '-DWITH_ASTYLE=ON'
* [OBSOLETE] To build the MJ2 executables: '-DBUILD\_MJ2:bool=on' (default: 'OFF')
* [OBSOLETE] To build the JPWL executables and JPWL library: '-DBUILD\_JPWL:bool=on' (default: 'OFF')
* [OBSOLETE] To build the JPIP client (java compiler recommended) library and executables: '-DBUILD\_JPIP:bool=on' (default: 'OFF')
@ -62,68 +60,7 @@ Note 4 : On MacOS, if it does not work, try adding the following flag to the cma
## MacOS (XCode) - WINDOWS (VisualStudio, etc)
You can use cmake to generate the project files for the IDE you are using (VC2010, XCode, etc).
Type `cmake --help` for available generators on your platform.
Examples for Windows with Visual Studio C++ compiler:
If using directly the cl compiler:
```
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" ..
```
To compile a 64-bit application, open 64-Bit Visual C\+\+ toolset on the command line and run cmake. For further information, please refer to: [How to: Enable a 64-Bit Visual C\+\+ Toolset on the Command Line](https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx).
If you do not want directly use the cl compiler, you could use:
```
cmake -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" ..
```
To create Visual Studio solution (.sln) and project files (.vcproj / .vcxproj):
```
cmake -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" ..
```
64-bit application:
```
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" ..
```
# Enabling CPU specific optimizations
For Intel/AMD processors, OpenJPEG implements optimizations using the SSE4.1
instruction set (for example, for the 9x7 inverse MCT transform) and the AVX2
instruction set (for example, for the 5x3 inverse discrete wavelet transform).
Currently, those optimizations are only available if OpenJPEG is built to
use those instruction sets (and the resulting binary will only run on compatible
CPUs)
With gcc/clang, it is possible to enable those instruction sets with the following :
```
cmake -DCMAKE_C_FLAGS="-O3 -msse4.1 -DNDEBUG" ..
```
```
cmake -DCMAKE_C_FLAGS="-O3 -mavx2 -DNDEBUG" ..
```
(AVX2 implies SSE4.1)
Or if the binary is dedicated to run on the machine where it has
been compiled :
```
cmake -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG" ..
```
# Modifying OpenJPEG
Before committing changes, run:
```scripts/prepare-commit.sh```
Type 'cmake --help' for available generators on your platform.
# Using OpenJPEG

View File

@ -1,55 +0,0 @@
USE_CLIB2=YES
ifeq ($(USE_CLIB2), YES)
LIBC=clib2
CODEC=OFF
else
LIBC=newlib
CODEC=ON
endif
all: build
build:
mkdir build && \
cd build && \
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CROSSCOMPILING=ON \
-DCMAKE_TOOLCHAIN_FILE=$(realpath amigaos4.cmake) \
-DCMAKE_C_FLAGS="-mcrt=${LIBC} -O2 -fPIC" \
-DCMAKE_MODULE_LINKER_FLAGS="-mcrt=${LIBC} -lpthread -athread=native" \
-DBUILD_TESTING=OFF \
-DBUILD_CODEC=${CODEC} \
-DBUILD_SHARED_LIBS=OFF && \
make
clean:
@echo "Clean the build"
@rm -rf build
cleanall: clean
@echo "Clean the build and the release files"
@rm -rf SDK
@rm libopenjpeg.lha
release:
@echo "Create release folders..."
@mkdir -p SDK/local/common/include
@mkdir -p SDK/local/clib2/lib
@mkdir -p SDK/local/newlib/lib SDK/local/newlib/bin
@echo "Building clib2 based libraries..."
@make -f Makefile.os4 USE_CLIB2=YES
@cp ./build/bin/libopenjp2.a SDK/local/clib2/lib/
@cp ./src/lib/openjp2/openjpeg.h SDK/local/common/include/
@echo "Clean build and libraries files..."
@make -f Makefile.os4 clean
@echo "Building newlib based libraries..."
@make -f Makefile.os4 USE_CLIB2=NO
@cp ./build/bin/libopenjp2.a SDK/local/newlib/lib/
@cp ./build/bin/opj_* SDK/local/newlib/bin/
@echo "Creating the lha release file..."
@lha -aeq libopenjpeg.lha SDK/

66
NEWS.md
View File

@ -1,77 +1,19 @@
# OpenJPEG NEWS
More details in the [CHANGELOG](https://github.com/uclouvain/openjpeg/blob/master/CHANGELOG.md)
More details in the [Changelog](https://github.com/uclouvain/openjpeg/blob/master/CHANGELOG.md)
## OpenJPEG 2.5.0 (May 2022)
No API/ABI break compared to v2.4.0, but additional symbols for subset of components decoding (hence the MINOR version bump).
* Encoder: add support for generation of TLM markers [\#1359](https://github.com/uclouvain/openjpeg/pull/1359)
* Decoder: add support for high throughput \(HTJ2K\) decoding. [\#1381](https://github.com/uclouvain/openjpeg/pull/1381)
* Decoder: add support for partial bitstream decoding [\#1407](https://github.com/uclouvain/openjpeg/pull/1407)
* Bug fixes (including security fixes)
## OpenJPEG 2.4.0 (December 2020)
No API/ABI break compared to v2.3.1, but additional symbols for subset of components decoding (hence the MINOR version bump).
* Encoder: add support for multithreading [\#1248](https://github.com/uclouvain/openjpeg/pull/1248)
* Encoder: add support for generation of PLT markers [\#1246](https://github.com/uclouvain/openjpeg/pull/1246)
* Encoder: single-threaded performance improvements in forward DWT for 5-3 and 9-7 (and other improvements) [\#1253](https://github.com/uclouvain/openjpeg/pull/1253)
* Encoder: support IMF profiles [\#1235](https://github.com/uclouvain/openjpeg/pull/1235)
* Many bug fixes (including security fixes)
## OpenJPEG 2.3.1 (April 2019)
No API/ABI break compared to v2.3.0
* Many bug fixes (including security fixes)
## OpenJPEG 2.3.0 (October 2017)
No API/ABI break compared to v2.2.0 but additional symbols for subset of components decoding (hence the MINOR version bump).
* Sub-tile decoding: when setting a window of interest through the API function opj_set_decode_area(), only codeblocks that intersect this window are now decoded (i.e. MCT, IDWT, and entropy decoding are only done on the window of interest). Moreover, memory allocation now depends on the size of the window of interest (instead of the full tile size).
[\#990](https://github.com/uclouvain/openjpeg/pull/990) [\#1001](https://github.com/uclouvain/openjpeg/pull/1001) [\#1010](https://github.com/uclouvain/openjpeg/pull/1010)
* Ability to decode only a subset of components. This adds the following function `opj_set_decoded_components(opj_codec_t p_codec, OPJ_UINT32 numcomps, const OPJ_UINT32 comps_indices, OPJ_BOOL apply_color_transforms)` and equivalent `opj_decompress -c compno[,compno]*`
option.
[\#1022](https://github.com/uclouvain/openjpeg/pull/1022)
* Many bug fixes (including security fixes)
## OpenJPEG 2.2.0 (August 2017)
No API/ABI break compared to v2.1.2 but additional symbols for multithreading support (hence the MINOR version bump).
### Codebase improvements
* Memory consumption reduction at decoding side [\#968](https://github.com/uclouvain/openjpeg/pull/968)
* Multi-threading support at decoding side [\#786](https://github.com/uclouvain/openjpeg/pull/786)
* Tier-1 speed optimizations (encoder and decoder) [\#945](https://github.com/uclouvain/openjpeg/pull/945)
* Tier-1 decoder further optimization [\#783](https://github.com/uclouvain/openjpeg/pull/783)
* Inverse 5x3 DWT speed optimization: single-pass lifting and SSE2/AVX2 implementation [\#957](https://github.com/uclouvain/openjpeg/pull/957)
* Fixed a bug that prevented OpenJPEG to compress losslessly in some situations [\#949](https://github.com/uclouvain/openjpeg/pull/949)
* Fixed BYPASS/LAZY, RESTART/TERMALL and PTERM mode switches
* Many other bug fixes (including security fixes)
### Maintenance improvements
* Benchmarking scripts to automatically compare the speed of latest OpenJPEG build with latest release and/or Kakadu binaries [\#917](https://github.com/uclouvain/openjpeg/pull/917)
* CPU and RAM usage profiling scripts [\#918](https://github.com/uclouvain/openjpeg/pull/918)
* Codebase reformatting (with astyle) and scripts to automatically check that new commits comply with formatting guidelines [\#919](https://github.com/uclouvain/openjpeg/pull/919)
* Register OpenJPEG at Google OSS Fuzz initiative, so as to automatically have OpenJPEG tested against Google fuzzer [\#965](https://github.com/uclouvain/openjpeg/issues/965)
## OpenJPEG 2.1.2 (September 2016)
## OpenJPEG 2.1.2
* Bug fixes (including security fixes)
* No API/ABI break compared to v2.1.1
## OpenJPEG 2.1.1 (July 2016)
## OpenJPEG 2.1.1
* Huge amount of critical bugfixes
* Speed improvements
* No API/ABI break compared to v2.1
## OpenJPEG 2.1.0 (April 2014)
## OpenJPEG 2.1.0
### New Features

View File

@ -29,12 +29,18 @@ The library is developed and maintained by the Image and Signal Processing Group
* src
* lib
* openjp2: contains the sources of the openjp2 library (Part 1 & 2)
* openjpwl: contains the additional sources if you want to build a JPWL-flavoured library.
* openjpip: complete client-server architecture for remote browsing of jpeg 2000 images.
* openjp3d: JP3D implementation
* openmj2: MJ2 implementation
* bin: contains all applications that use the openjpeg library
* common: common files to all applications
* jp2: a basic codec
* mj2: motion jpeg 2000 executables
* jpip: OpenJPIP applications (server and dec server)
* java: a Java client viewer for JPIP
* jp3d: JP3D applications
* tcltk: a test tool for JP3D
* wx
* OPJViewer: gui for displaying j2k files (based on wxWidget)
* wrapping
@ -43,7 +49,6 @@ The library is developed and maintained by the Image and Signal Processing Group
* doc: doxygen documentation setup file and man pages
* tests: configuration files and utilities for the openjpeg test suite. All test images are located in [openjpeg-data](https://github.com/uclouvain/openjpeg-data) repository.
* cmake: cmake related files
* scripts: scripts for developers
See [LICENSE][link-license] for license and copyright information.
@ -51,12 +56,6 @@ See [INSTALL](https://github.com/uclouvain/openjpeg/blob/master/INSTALL.md) for
See [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) for user visible changes in successive releases.
## Deprecated components
The openjpwl, openjp3d and openmj2 components have been removed after the
2.4.0 release. Their building and working state is unknown. People interested
in them should start from the 2.4.0 tag.
## API/ABI
An API/ABI timeline is automatically updated [here][link-api-timeline].
@ -72,10 +71,10 @@ On windows, MSVC directly supports export/hiding function and as such the only
API available is the one supported by OpenJPEG.
[comment-license]: https://img.shields.io/github/license/uclouvain/openjpeg.svg "https://img.shields.io/badge/license-BSD--2--Clause-blue.svg"
[badge-license]: https://img.shields.io/badge/license-BSD--2--Clause-blue.svg "BSD 2-clause \"Simplified\" License"
[link-license]: https://github.com/uclouvain/openjpeg/blob/master/LICENSE "BSD 2-clause \"Simplified\" License"
[badge-build]: https://github.com/uclouvain/openjpeg/actions/workflows/build.yml/badge.svg "Build Status"
[link-build]: https://github.com/uclouvain/openjpeg/actions/workflows/build.yml "Build Status"
[badge-license]: https://img.shields.io/badge/license-BSD--2--Clause-blue.svg "BSD 2-clause "Simplified" License"
[link-license]: https://github.com/uclouvain/openjpeg/blob/master/LICENSE "BSD 2-clause "Simplified" License"
[badge-build]: https://travis-ci.org/uclouvain/openjpeg.svg?branch=master "Build Status"
[link-build]: https://travis-ci.org/uclouvain/openjpeg "Build Status"
[badge-msvc-build]: https://ci.appveyor.com/api/projects/status/github/uclouvain/openjpeg?branch=master&svg=true "Windows Build Status"
[link-msvc-build]: https://ci.appveyor.com/project/detonin/openjpeg/branch/master "Windows Build Status"
[badge-coverity]: https://scan.coverity.com/projects/6383/badge.svg "Coverity Scan Build Status"

View File

@ -1,9 +0,0 @@
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR ppc)
SET(CMAKE_C_COMPILER /opt/ppc-amigaos/bin/ppc-amigaos-gcc)
SET(CMAKE_CXX_COMPILER /opt/ppc-amigaos/bin/ppc-amigaos-g++)
SET(CMAKE_FIND_LIBRARY_SUFFIXES "*.a")
SET(CMAKE_FIND_ROOT_PATH /opt/sdk)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -1,4 +1,4 @@
version: 2.5.0.{build}
version: 2.1.1.{build}
branches:
except:
- coverity_scan
@ -6,9 +6,6 @@ skip_tags: false
clone_depth: 50
environment:
matrix:
- OPJ_CI_ARCH: x64
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
OPJ_CI_INSTRUCTION_SETS: "/arch:AVX2"
- OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
OPJ_CI_INCLUDE_IF_DEPLOY: 1
@ -27,15 +24,15 @@ build_script:
test: off
#before_deploy:
#- cmd: c:\cygwin\bin\bash ./tools/travis-ci/before_deploy.sh
#deploy:
# #release: openjpeg-$(appveyor_repo_tag_name)
# description: 'OpenJPEG $(appveyor_repo_tag_name) has been released. More info [here](https://github.com/uclouvain/openjpeg/blob/$(appveyor_repo_tag_name)/NEWS) and a detailed view [here](https://github.com/uclouvain/openjpeg/blob/$(appveyor_repo_tag_name)/CHANGES).'
# provider: GitHub
# auth_token:
# secure: XUL+IoRRw8U/4tupa/fMpinxurft7WRQHZiWHMLO5iuFbwZ+C3vCjVVVM+5Ebky7 # your encrypted token from GitHub
# artifact: /.*\.zip/ # upload all zip packages to release assets
# draft: true
# prerelease: false
# on:
# appveyor_repo_tag: true # deploy on tag push only
# OPJ_CI_INCLUDE_IF_DEPLOY: 1
deploy:
#release: openjpeg-$(appveyor_repo_tag_name)
description: 'OpenJPEG $(appveyor_repo_tag_name) has been released. More info [here](https://github.com/uclouvain/openjpeg/blob/$(appveyor_repo_tag_name)/NEWS) and a detailed view [here](https://github.com/uclouvain/openjpeg/blob/$(appveyor_repo_tag_name)/CHANGES).'
provider: GitHub
auth_token:
secure: Huk03f1heCD/HMyA+4ZeVmICdmKn9rPxK5p8/KxzgL+FtJDHlqcllcCrtN9bDxRH # your encrypted token from GitHub
artifact: /.*\.zip/ # upload all zip packages to release assets
draft: false
prerelease: false
on:
appveyor_repo_tag: true # deploy on tag push only
OPJ_CI_INCLUDE_IF_DEPLOY: 1

View File

@ -5,7 +5,6 @@
# This file is configured by OPENJPEG and used by the UseOPENJPEG.cmake
# module to load OPENJPEG's settings for an external project.
@OPENJPEG_CONFIG_INSTALL_ONLY@
@PACKAGE_INIT@
# The OPENJPEG version number.
set(OPENJPEG_MAJOR_VERSION "@OPENJPEG_VERSION_MAJOR@")
set(OPENJPEG_MINOR_VERSION "@OPENJPEG_VERSION_MINOR@")
@ -27,9 +26,8 @@ get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
if(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake)
# This is an install tree
include(${SELF_DIR}/OpenJPEGTargets.cmake)
set(INC_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/@OPENJPEG_INSTALL_SUBDIR@")
get_filename_component(OPENJPEG_INCLUDE_DIRS "${INC_DIR}" ABSOLUTE)
get_filename_component(OPENJPEG_INCLUDE_ROOT "${SELF_DIR}/../../@OPENJPEG_INSTALL_INCLUDE_DIR@" ABSOLUTE)
set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG_INCLUDE_ROOT})
else()
if(EXISTS ${SELF_DIR}/OpenJPEGExports.cmake)

View File

@ -44,7 +44,7 @@ if(DOXYGEN_FOUND)
# install HTML documentation (install png files too):
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/html
DESTINATION ${CMAKE_INSTALL_DOCDIR}
DESTINATION share/doc
PATTERN ".svn" EXCLUDE
)
else()

View File

@ -47,6 +47,7 @@ IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
TYPEDEF_HIDES_STRUCT = NO
SYMBOL_CACHE_SIZE = 0
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
@ -78,6 +79,7 @@ GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = NO
SHOW_FILES = YES
SHOW_NAMESPACES = YES
FILE_VERSION_FILTER =
@ -144,6 +146,7 @@ HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = NO
HTML_ALIGN_MEMBERS = YES
HTML_DYNAMIC_SECTIONS = NO
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
@ -170,6 +173,7 @@ ECLIPSE_DOC_ID = org.doxygen.Project
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
USE_INLINE_TREES = NO
TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO
FORMULA_FONTSIZE = 10
@ -213,6 +217,8 @@ MAN_LINKS = NO
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output

View File

@ -49,7 +49,7 @@ Valid output image extensions are
.P
.B opj_compress \-h \fRPrint a help message and exit.
.P
See JPWL OPTIONS for special options
.R See JPWL OPTIONS for special options
.SH OPTIONS
.TP
.B \-\^b " n,n"

View File

@ -49,7 +49,7 @@ Valid output image extensions are
.P
.B opj_decompress \-h \fRPrint help message and exit
.P
See JPWL OPTIONS for special options
.R See JPWL OPTIONS for special options
.SH OPTIONS
.TP
.B \-\^i "name"

View File

@ -30,7 +30,7 @@
/*! \page openjpippage OpenJPIP v@OPENJPEG_VERSION@ Documentation
*
* \section Introduction
* \section intro Introduction
* This manual documents the low-level OpenJPIP C API.\n
* OpenJPIP software is an implementation of JPEG 2000 Part9: Interactivity tools, APIs and protocols (JPIP).\n
* ( For more info about JPIP, check the website: http://www.jpeg.org/jpeg2000/j2kpart9.html)\n
@ -42,7 +42,7 @@
* - opj_jpip_transcode.c To Convert JPT/JPP-stream to JP2 or J2K
* - opj_jpip_test.c To test index code format of a JP2 file
*
* \section License
* \section license License
* This software is released under the BSD license, anybody can use or modify the library, even for commercial applications.\n
* The only restriction is to retain the copyright in the sources or the binaries documentation.\n
* Neither the author, nor the university accept any responsibility for any kind of error or data loss which may occur during usage.
@ -88,7 +88,7 @@
* Before connecting to the JPIP server, every JPIP client checks local cache data of the requesting image with the image decoding server.
* If its cache exists, the image decoding server provides ChannelID (CID), which identifies the image and its cache model on the JPIP server, and the whole system can continue the session using the CID.
*
* \image html jpip_protocol.png "Message Sequence Chart of OpenJPIP implementation"
* \image html jpip_protocol.png "Message Sequence Chart of OpenJPIP impementation"
*
* \author Kaori Hagihara UCL/SST/ICTM/ELEN
*/

View File

@ -1,11 +0,0 @@
--convert-tabs
--lineend=linux
--indent=spaces=4
--style=kr
--add-braces
--max-code-length=80
--break-after-logical
--pad-header
--pad-oper
--unpad-paren
--suffix=none

View File

@ -1,117 +0,0 @@
#!/bin/bash
###########################################################################
# astyle.sh
# ---------------------
# Date : August 2008
# Copyright : (C) 2008 by Juergen E. Fischer
# Email : jef at norbit dot de
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
for ASTYLE in ${OPJSTYLE} $(dirname $0)/opjstyle $(dirname $0)/RelWithDebInfo/opjstyle
do
if type -p $ASTYLE >/dev/null; then
break
fi
ASTYLE=
done
if [ -z "$ASTYLE" ]; then
echo "opjstyle not found - please enable WITH_ASTYLE in cmake and build it" >&2
exit 1
fi
if type -p tput >/dev/null; then
elcr="$ASTYLEPROGRESS$(tput el)$(tput cr)"
else
elcr="$ASTYLEPROGRESS \r"
fi
if ! type -p flip >/dev/null; then
if type -p dos2unix >/dev/null; then
flip() {
dos2unix -k $2
}
else
echo "flip not found" >&2
flip() {
:
}
fi
fi
if ! type -p autopep8 >/dev/null; then
echo "autopep8 not found" >&2
autopep8() {
:
}
fi
ASTYLEOPTS=$(dirname $0)/astyle.options
if type -p cygpath >/dev/null; then
ASTYLEOPTS="$(cygpath -w $ASTYLEOPTS)"
fi
set -e
astyleit() {
$ASTYLE --options="$ASTYLEOPTS" "$1"
#modified=$1.unify_includes_modified
#cp "$1" "$modified"
#scripts/unify_includes.pl "$modified"
#scripts/doxygen_space.pl "$modified"
#diff "$1" "$modified" >/dev/null || mv "$modified" "$1"
#rm -f "$modified"
}
for f in "$@"; do
case "$f" in
thirdparty/*)
echo -ne "$f skipped $elcr"
continue
;;
*.cpp|*.h|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.hpp)
if [ -x "$f" ]; then
chmod a-x "$f"
fi
cmd=astyleit
;;
*.py)
#cmd="autopep8 --in-place --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701"
echo -ne "Formatting $f $elcr"
cmd="autopep8 --in-place --ignore=E261,E265,E402,E501"
;;
*)
echo -ne "$f skipped $elcr"
continue
;;
esac
if ! [ -f "$f" ]; then
echo "$f not found" >&2
continue
fi
if [[ -f $f && `head -c 3 $f` == $'\xef\xbb\xbf' ]]; then
mv $f $f.bom
tail -c +4 $f.bom > $f
echo "removed BOM from $f"
fi
modified=$f.flip_modified
cp "$f" "$modified"
flip -ub "$modified"
diff "$f" "$modified" >/dev/null || mv "$modified" "$f"
rm -f "$modified"
eval "$cmd '$f'"
done

View File

@ -1,112 +0,0 @@
#!/usr/bin/env bash
###########################################################################
# prepare-commit.sh
# ---------------------
# Date : August 2008
# Copyright : (C) 2008 by Juergen E. Fischer
# Email : jef at norbit dot de
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
TOPLEVEL=$(git rev-parse --show-toplevel)
PATH=$TOPLEVEL/scripts:$PATH
cd $TOPLEVEL
# GNU prefix command for mac os support (gsed, gsplit)
GP=
if [[ "$OSTYPE" =~ darwin* ]]; then
GP=g
fi
if ! type -p astyle.sh >/dev/null; then
echo astyle.sh not found
exit 1
fi
if ! type -p colordiff >/dev/null; then
colordiff()
{
cat "$@"
}
fi
if [ "$1" = "-c" ]; then
echo "Cleaning..."
remove_temporary_files.sh
fi
set -e
# determine changed files
MODIFIED=$(git status --porcelain| ${GP}sed -ne "s/^ *[MA] *//p" | sort -u)
#MODIFIED=$(find src -name "*.h")
if [ -z "$MODIFIED" ]; then
echo nothing was modified
exit 0
fi
# save original changes
REV=$(git log -n1 --pretty=%H)
git diff >sha-$REV.diff
ASTYLEDIFF=astyle.$REV.diff
>$ASTYLEDIFF
# reformat
i=0
N=$(echo $MODIFIED | wc -w)
for f in $MODIFIED; do
(( i++ )) || true
case "$f" in
thirdparty/*)
echo $f skipped
continue
;;
*.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py)
;;
*)
continue
;;
esac
m=$f.$REV.prepare
cp $f $m
ASTYLEPROGRESS=" [$i/$N]" astyle.sh $f
if diff -u $m $f >>$ASTYLEDIFF; then
# no difference found
rm $m
fi
done
if [ -s "$ASTYLEDIFF" ]; then
if tty -s; then
# review astyle changes
colordiff <$ASTYLEDIFF | less -r
else
echo "Files changed (see $ASTYLEDIFF)"
fi
exit 1
else
rm $ASTYLEDIFF
fi
# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached HEAD --
exit 0
# vim: set ts=8 noexpandtab :

View File

@ -1,41 +0,0 @@
#!/bin/bash
###########################################################################
# remove_git_confict_files.sh
# ---------------------
# Date : April 2012
# Copyright : (C) 2012 by Tim Sutton
# Email : tim at kartoza dot com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
#
# A simple script to get rid of QGIS related temporary files left in
# your QGIS source folder by git
# Tim Sutton, May 2008
find . \
\( \
-name "*.orig" \
-o -name "*.prepare" \
-o -name "*.sortinc" \
-o -name "*.unify_includes_modified" \
-o -name "*.nocopyright" \
-o -name "astyle*.diff" \
-o -name "sha-*.diff" \
-o -name "*.astyle" \
-o -name "sha*.diff" \
-o -name "*.bom" \
-o -name "*.bak" \
-o -name "*.rej" \
-o -name "*.orig" \
-o -name "*.new" \
-o -name "*~" \
\) \
-print \
-delete

View File

@ -1,87 +0,0 @@
#!/bin/bash
cd $(git rev-parse --show-toplevel)
export PATH=$PATH:$PWD/scripts
if [ -z "$TRAVIS_COMMIT_RANGE" -a -z "$GITHUB_SHA" ]; then
echo "No commit range given"
exit 0
fi
if ! type -p astyle.sh >/dev/null; then
echo astyle.sh not found
exit 1
fi
set -e
ASTYLEDIFF=/tmp/astyle.diff
>$ASTYLEDIFF
if [ ! -z $GITHUB_BASE_REF ] && [ ! -z $GITHUB_HEAD_REF ]; then
# on a PR
echo "GitHub PR COMMIT RANGE: ${GITHUB_BASE_REF}..${GITHUB_HEAD_REF}"
git branch tmp_${GITHUB_BASE_REF} origin/${GITHUB_BASE_REF}
BASE_SHA1=$(git rev-parse tmp_${GITHUB_BASE_REF})
FILES=$(git diff --diff-filter=AMR --name-only ${BASE_SHA1}..${GITHUB_SHA} | tr '\n' ' ' )
elif [ ! -z $GITHUB_SHA ]; then
echo "GitHub push COMMIT $GITHUB_SHA"
FILES=$(git diff --diff-filter=AMR --name-only ${GITHUB_SHA}~1..${GITHUB_SHA} | tr '\n' ' ' )
elif [ ! -z $TRAVIS_PULL_REQUEST_BRANCH ]; then
# if on a PR, just analyse the changed files
echo "TRAVIS PR BRANCH: $TRAVIS_PULL_REQUEST_BRANCH"
FILES=$(git diff --diff-filter=AMR --name-only $(git merge-base HEAD master) | tr '\n' ' ' )
elif [ ! -z $TRAVIS_COMMIT_RANGE ]; then
echo "TRAVIS COMMIT RANGE: $TRAVIS_COMMIT_RANGE"
FILES=$(git diff --diff-filter=AMR --name-only ${TRAVIS_COMMIT_RANGE/.../..} | tr '\n' ' ' )
fi
for f in $FILES; do
if ! [ -f "$f" ]; then
echo "$f was removed." >>/tmp/ctest-important.log
continue
fi
echo "Checking $f" >>/tmp/ctest-important.log
case "$f" in
thirdparty*)
echo "$f skipped"
continue
;;
*.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py)
;;
*)
continue
;;
esac
m="$f.prepare"
cp "$f" "$m"
astyle.sh "$f"
if diff -u "$m" "$f" >>$ASTYLEDIFF; then
rm "$m"
else
echo "File $f needs indentation"
fi
done
if [ -s "$ASTYLEDIFF" ]; then
echo
echo "Required indentation updates:"
cat "$ASTYLEDIFF"
cat <<EOF
Tips to prevent and resolve:
* Enable WITH_ASTYLE in your cmake configuration to format C++ code
* Install autopep8 (>= 1.2.1) to format python code
* Use "scripts/astyle.sh file" to fix the now badly indented files
* Consider using scripts/prepare-commit.sh as pre-commit hook to avoid this
in the future (ln -s scripts/prepare-commit.sh .git/hooks/pre-commit) or
run it manually before each commit.
EOF
exit 1
fi

View File

@ -4,9 +4,18 @@ add_subdirectory(common)
add_subdirectory(jp2)
# optionals components:
if(BUILD_JPWL)
add_subdirectory(jpwl)
endif()
if(BUILD_MJ2)
add_subdirectory(mj2)
endif()
if(BUILD_JPIP)
add_subdirectory(jpip)
endif()
if(BUILD_JP3D)
add_subdirectory(jp3d)
endif()
# wx apps:
add_subdirectory(wx)

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.

View File

@ -1,6 +1,6 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.

View File

@ -1,11 +1,11 @@
/*
* The copyright in this software is being made available under the 3-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 3-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -36,242 +36,220 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)opj_getopt.c 8.3 (Berkeley) 4/27/95";
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "opj_getopt.h"
int opj_opterr = 1, /* if error message should be printed */
opj_optind = 1, /* index into parent argv vector */
opj_optopt, /* character checked for validity */
opj_optreset; /* reset getopt */
char *opj_optarg; /* argument associated with option */
int opj_opterr = 1, /* if error message should be printed */
opj_optind = 1, /* index into parent argv vector */
opj_optopt, /* character checked for validity */
opj_optreset; /* reset getopt */
char *opj_optarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
static char EMSG[] = {""};
#define BADCH (int)'?'
#define BADARG (int)':'
static char EMSG[]={""};
/* As this class remembers its values from one Java call to the other, reset the values before each use */
void opj_reset_options_reading(void)
{
opj_opterr = 1;
opj_optind = 1;
void opj_reset_options_reading(void) {
opj_opterr = 1;
opj_optind = 1;
}
/*
* getopt --
* Parse argc/argv argument vector.
* Parse argc/argv argument vector.
*/
int opj_getopt(int nargc, char *const *nargv, const char *ostr)
{
int opj_getopt(int nargc, char *const *nargv, const char *ostr) {
# define __progname nargv[0]
static char *place = EMSG; /* option letter processing */
const char *oli = NULL; /* option letter list index */
static char *place = EMSG; /* option letter processing */
const char *oli = NULL; /* option letter list index */
if (opj_optreset || !*place) { /* update scanning pointer */
opj_optreset = 0;
if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
++opj_optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((opj_optopt = (int) * place++) == (int) ':' ||
!(oli = strchr(ostr, opj_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (opj_optopt == (int) '-') {
return (-1);
}
if (!*place) {
++opj_optind;
}
if (opj_opterr && *ostr != ':') {
fprintf(stderr,
"%s: illegal option -- %c\n", __progname, opj_optopt);
return (BADCH);
}
if (opj_optreset || !*place) { /* update scanning pointer */
opj_optreset = 0;
if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') {
place = EMSG;
return (-1);
}
if (*++oli != ':') { /* don't need argument */
opj_optarg = NULL;
if (!*place) {
++opj_optind;
}
} else { /* need an argument */
if (*place) { /* no white space */
opj_optarg = place;
} else if (nargc <= ++opj_optind) { /* no arg */
place = EMSG;
if (*ostr == ':') {
return (BADARG);
}
if (opj_opterr) {
fprintf(stderr,
"%s: option requires an argument -- %c\n",
__progname, opj_optopt);
return (BADCH);
}
} else { /* white space */
opj_optarg = nargv[opj_optind];
}
place = EMSG;
++opj_optind;
if (place[1] && *++place == '-') { /* found "--" */
++opj_optind;
place = EMSG;
return (-1);
}
return (opj_optopt); /* dump back option letter */
} /* option letter okay? */
if ((opj_optopt = (int) *place++) == (int) ':' ||
!(oli = strchr(ostr, opj_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (opj_optopt == (int) '-')
return (-1);
if (!*place)
++opj_optind;
if (opj_opterr && *ostr != ':') {
fprintf(stderr,
"%s: illegal option -- %c\n", __progname, opj_optopt);
return (BADCH);
}
}
if (*++oli != ':') { /* don't need argument */
opj_optarg = NULL;
if (!*place)
++opj_optind;
} else { /* need an argument */
if (*place) /* no white space */
opj_optarg = place;
else if (nargc <= ++opj_optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opj_opterr) {
fprintf(stderr,
"%s: option requires an argument -- %c\n",
__progname, opj_optopt);
return (BADCH);
}
} else /* white space */
opj_optarg = nargv[opj_optind];
place = EMSG;
++opj_optind;
}
return (opj_optopt); /* dump back option letter */
}
int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen)
{
static int lastidx, lastofs;
const char *tmp;
int i, len;
char param = 1;
const opj_option_t *longopts, int totlen) {
static int lastidx,lastofs;
const char *tmp;
int i,len;
char param = 1;
again:
if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind] != '-') {
return -1;
}
if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind]!='-')
return -1;
if (argv[opj_optind][0] == '-' && argv[opj_optind][1] == 0) {
if (opj_optind >= (argc - 1)) { /* no more input parameters */
param = 0;
} else { /* more input parameters */
if (argv[opj_optind + 1][0] == '-') {
param = 0; /* Missing parameter after '-' */
} else {
param = 2;
}
}
}
if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
if(opj_optind >= (argc - 1)){ /* no more input parameters */
param = 0;
}
else{ /* more input parameters */
if(argv[opj_optind + 1][0] == '-'){
param = 0; /* Missing parameter after '-' */
}
else{
param = 2;
}
}
}
if (param == 0) {
++opj_optind;
return (BADCH);
}
if (param == 0) {
++opj_optind;
return (BADCH);
}
if (argv[opj_optind][0] == '-') { /* long option */
char* arg;
const opj_option_t* o;
o = longopts;
len = sizeof(longopts[0]);
if (argv[opj_optind][0]=='-') { /* long option */
char* arg=argv[opj_optind]+1;
const opj_option_t* o;
o=longopts;
len=sizeof(longopts[0]);
if (param > 1) {
if (opj_optind + 1 >= argc) {
return -1;
}
arg = argv[opj_optind + 1];
opj_optind++;
} else {
arg = argv[opj_optind] + 1;
}
if (param > 1){
arg = argv[opj_optind+1];
opj_optind++;
}
else
arg = argv[opj_optind]+1;
if (strlen(arg) > 1) {
for (i = 0; i < totlen; i = i + len, o++) {
if (!strcmp(o->name, arg)) { /* match */
if (o->has_arg == 0) {
if ((argv[opj_optind + 1]) && (!(argv[opj_optind + 1][0] == '-'))) {
fprintf(stderr, "%s: option does not require an argument. Ignoring %s\n", arg,
argv[opj_optind + 1]);
++opj_optind;
}
} else {
opj_optarg = argv[opj_optind + 1];
if (opj_optarg) {
if (opj_optarg[0] ==
'-') { /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) {
fprintf(stderr, "%s: option requires an argument\n", arg);
return (BADCH);
}
}
}
if (!opj_optarg && o->has_arg == 1) { /* no argument there */
if (opj_opterr) {
fprintf(stderr, "%s: option requires an argument \n", arg);
return (BADCH);
}
}
++opj_optind;
}
++opj_optind;
if (o->flag) {
*(o->flag) = o->val;
} else {
return o->val;
}
return 0;
}
}/*(end for)String not found in the list*/
fprintf(stderr, "Invalid option %s\n", arg);
++opj_optind;
return (BADCH);
} else { /*Single character input parameter*/
if (*optstring == ':') {
return ':';
}
if (lastidx != opj_optind) {
lastidx = opj_optind;
lastofs = 0;
}
opj_optopt = argv[opj_optind][lastofs + 1];
if ((tmp = strchr(optstring, opj_optopt))) { /*Found input parameter in list*/
if (*tmp == 0) { /* apparently, we looked for \0, i.e. end of argument */
++opj_optind;
goto again;
}
if (tmp[1] == ':') { /* argument expected */
if (tmp[2] == ':' ||
argv[opj_optind][lastofs + 2]) { /* "-foo", return "oo" as opj_optarg */
if (!*(opj_optarg = argv[opj_optind] + lastofs + 2)) {
opj_optarg = 0;
}
goto found;
}
opj_optarg = argv[opj_optind + 1];
if (opj_optarg) {
if (opj_optarg[0] ==
'-') { /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) {
fprintf(stderr, "%s: option requires an argument\n", arg);
++opj_optind;
return (BADCH);
}
}
}
if (!opj_optarg) { /* missing argument */
if (opj_opterr) {
fprintf(stderr, "%s: option requires an argument\n", arg);
++opj_optind;
return (BADCH);
}
}
++opj_optind;
} else {/*Argument not expected*/
++lastofs;
return opj_optopt;
}
if(strlen(arg)>1){
for (i=0;i<totlen;i=i+len,o++) {
if (!strcmp(o->name,arg)) { /* match */
if (o->has_arg == 0) {
if ((argv[opj_optind+1])&&(!(argv[opj_optind+1][0]=='-'))){
fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[opj_optind+1]);
++opj_optind;
}
}else{
opj_optarg=argv[opj_optind+1];
if(opj_optarg){
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
}
if (!opj_optarg && o->has_arg==1) { /* no argument there */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument \n",arg);
return (BADCH);
}
}
++opj_optind;
}
++opj_optind;
if (o->flag)
*(o->flag)=o->val;
else
return o->val;
return 0;
}
}/*(end for)String not found in the list*/
fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind;
return (BADCH);
}else{ /*Single character input parameter*/
if (*optstring==':') return ':';
if (lastidx!=opj_optind) {
lastidx=opj_optind; lastofs=0;
}
opj_optopt=argv[opj_optind][lastofs+1];
if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/
if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */
++opj_optind;
goto again;
}
if (tmp[1]==':') { /* argument expected */
if (tmp[2]==':' || argv[opj_optind][lastofs+2]) { /* "-foo", return "oo" as opj_optarg */
if (!*(opj_optarg=argv[opj_optind]+lastofs+2)) opj_optarg=0;
goto found;
}
opj_optarg=argv[opj_optind+1];
if(opj_optarg){
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
}
if (!opj_optarg) { /* missing argument */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
++opj_optind;
}else {/*Argument not expected*/
++lastofs;
return opj_optopt;
}
found:
++opj_optind;
return opj_optopt;
} else { /* not found */
fprintf(stderr, "Invalid option %s\n", arg);
++opj_optind;
return (BADCH);
}/*end of not found*/
}/* end of single character*/
}/*end '-'*/
fprintf(stderr, "Invalid option\n");
++opj_optind;
return (BADCH);;
++opj_optind;
return opj_optopt;
} else { /* not found */
fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind;
return (BADCH);
}/*end of not found*/
}/* end of single character*/
}/*end '-'*/
fprintf(stderr,"Invalid option\n");
++opj_optind;
return (BADCH);;
}/*end function*/

View File

@ -3,16 +3,17 @@
#ifndef _GETOPT_H_
#define _GETOPT_H_
typedef struct opj_option {
const char *name;
int has_arg;
int *flag;
int val;
} opj_option_t;
typedef struct opj_option
{
const char *name;
int has_arg;
int *flag;
int val;
}opj_option_t;
#define NO_ARG 0
#define REQ_ARG 1
#define OPT_ARG 2
#define NO_ARG 0
#define REQ_ARG 1
#define OPT_ARG 2
extern int opj_opterr;
extern int opj_optind;
@ -22,7 +23,7 @@ extern char *opj_optarg;
extern int opj_getopt(int nargc, char *const *nargv, const char *ostr);
extern int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen);
const opj_option_t *longopts, int totlen);
extern void opj_reset_options_reading(void);
#endif /* _GETOPT_H_ */
#endif /* _GETOPT_H_ */

View File

@ -39,34 +39,34 @@
/* keep in mind there still is a buffer read overflow possible */
static size_t opj_strnlen_s(const char *src, size_t max_len)
{
size_t len;
if (src == NULL) {
return 0U;
}
for (len = 0U; (*src != '\0') && (len < max_len); src++, len++);
return len;
size_t len;
if (src == NULL) {
return 0U;
}
for (len = 0U; (*src != '\0') && (len < max_len); src++, len++);
return len;
}
/* should be equivalent to C11 function except for the handler */
/* keep in mind there still is a buffer read overflow possible */
static int opj_strcpy_s(char* dst, size_t dst_size, const char* src)
{
size_t src_len = 0U;
if ((dst == NULL) || (dst_size == 0U)) {
return EINVAL;
}
if (src == NULL) {
dst[0] = '\0';
return EINVAL;
}
src_len = opj_strnlen_s(src, dst_size);
if (src_len >= dst_size) {
return ERANGE;
}
memcpy(dst, src, src_len);
dst[src_len] = '\0';
return 0;
size_t src_len = 0U;
if ((dst == NULL) || (dst_size == 0U)) {
return EINVAL;
}
if (src == NULL) {
dst[0] = '\0';
return EINVAL;
}
src_len = opj_strnlen_s(src, dst_size);
if (src_len >= dst_size) {
return ERANGE;
}
memcpy(dst, src, src_len);
dst[src_len] = '\0';
return 0;
}
#endif /* OPJ_STRING_H */

View File

@ -44,9 +44,6 @@ endif()
# Loop over all executables:
foreach(exe opj_decompress opj_compress opj_dump)
add_executable(${exe} ${exe}.c ${common_SRCS})
if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12")
target_compile_options(${exe} PRIVATE ${OPENJP2_COMPILE_OPTIONS})
endif()
target_link_libraries(${exe} ${OPENJPEG_LIBRARY_NAME}
${PNG_LIBNAME} ${TIFF_LIBNAME} ${LCMS_LIBNAME}
)
@ -67,7 +64,7 @@ foreach(exe opj_decompress opj_compress opj_dump)
# Install exe
install(TARGETS ${exe}
EXPORT OpenJPEGTargets
DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
if(OPJ_USE_DSYMUTIL)
add_custom_command(TARGET ${exe} POST_BUILD
@ -83,6 +80,6 @@ install(
FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_compress.1
${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_decompress.1
${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_dump.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man1)
#
endif()

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -50,19 +50,19 @@ typedef struct raw_comp_cparameters {
/**@name RAW image encoding parameters */
/*@{*/
typedef struct raw_cparameters {
/** width of the raw image */
int rawWidth;
/** height of the raw image */
int rawHeight;
/** width of the raw image */
int rawWidth;
/** height of the raw image */
int rawHeight;
/** number of components of the raw image */
int rawComp;
int rawComp;
/** bit depth of the raw image */
int rawBitDepth;
/** signed/unsigned raw image */
OPJ_BOOL rawSigned;
/** raw components parameters */
raw_comp_cparameters_t *rawComps;
/*@}*/
/*@}*/
} raw_cparameters_t;
/* Component precision clipping */
@ -71,18 +71,14 @@ void clip_component(opj_image_comp_t* component, OPJ_UINT32 precision);
void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision);
/* planar / interleaved conversions */
typedef void (* convert_32s_CXPX)(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst,
OPJ_SIZE_T length);
typedef void (* convert_32s_CXPX)(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length);
extern const convert_32s_CXPX convert_32s_CXPX_LUT[5];
typedef void (* convert_32s_PXCX)(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst,
OPJ_SIZE_T length, OPJ_INT32 adjust);
typedef void (* convert_32s_PXCX)(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length, OPJ_INT32 adjust);
extern const convert_32s_PXCX convert_32s_PXCX_LUT[5];
/* bit depth conversions */
typedef void (* convert_XXx32s_C1R)(const OPJ_BYTE* pSrc, OPJ_INT32* pDst,
OPJ_SIZE_T length);
typedef void (* convert_XXx32s_C1R)(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length);
extern const convert_XXx32s_C1R convert_XXu32s_C1R_LUT[9]; /* up to 8bpp */
typedef void (* convert_32sXXx_C1R)(const OPJ_INT32* pSrc, OPJ_BYTE* pDst,
OPJ_SIZE_T length);
typedef void (* convert_32sXXx_C1R)(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length);
extern const convert_32sXXx_C1R convert_32sXXu_C1R_LUT[9]; /* up to 8bpp */
@ -95,8 +91,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters);
int imagetobmp(opj_image_t *image, const char *outfile);
/* TIFF conversion*/
opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters,
const unsigned int target_bitdepth);
opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters);
int imagetotif(opj_image_t *image, const char *outfile);
/**
Load a single image component encoded in PGX file format
@ -113,15 +108,12 @@ int imagetopnm(opj_image_t *image, const char *outfile, int force_split);
/* RAW conversion */
int imagetoraw(opj_image_t * image, const char *outfile);
int imagetorawl(opj_image_t * image, const char *outfile);
opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters,
raw_cparameters_t *raw_cp);
opj_image_t* rawltoimage(const char *filename, opj_cparameters_t *parameters,
raw_cparameters_t *raw_cp);
opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp);
opj_image_t* rawltoimage(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp);
/* PNG conversion*/
extern int imagetopng(opj_image_t *image, const char *write_idf);
extern opj_image_t* pngtoimage(const char *filename,
opj_cparameters_t *parameters);
extern opj_image_t* pngtoimage(const char *filename, opj_cparameters_t *parameters);
#endif /* __J2K_CONVERT_H */

File diff suppressed because it is too large Load Diff

View File

@ -54,501 +54,447 @@
/* PNG allows bits per sample: 1, 2, 4, 8, 16 */
static void convert_16u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst,
OPJ_SIZE_T length)
static void convert_16u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_INT32 val0 = *pSrc++;
OPJ_INT32 val1 = *pSrc++;
pDst[i] = val0 << 8 | val1;
}
}
static opj_image_t * pngtoimage_internal(opj_cparameters_t * params,
FILE *reader,
png_structp png,
png_infop info,
png_uint_32* pheight,
OPJ_BYTE*** prows,
OPJ_INT32** prow32s)
{
*pheight = 0;
*prows = NULL;
*prow32s = NULL;
if (setjmp(png_jmpbuf(png))) {
return NULL;
}
{
opj_image_t *image = NULL;
opj_image_cmptparm_t cmptparm[4];
OPJ_UINT32 nr_comp;
convert_XXx32s_C1R cvtXXTo32s = NULL;
convert_32s_CXPX cvtCxToPx = NULL;
OPJ_INT32* planes[4];
double gamma;
int bit_depth, interlace_type, compression_type, filter_type;
OPJ_UINT32 i;
png_uint_32 width, height = 0U;
int color_type;
OPJ_BYTE** rows = NULL;
OPJ_INT32* row32s = NULL;
png_init_io(png, reader);
png_set_sig_bytes(png, MAGIC_SIZE);
png_read_info(png, info);
if (png_get_IHDR(png, info, &width, &height,
&bit_depth, &color_type, &interlace_type,
&compression_type, &filter_type) == 0) {
return image;
}
*pheight = height;
/* png_set_expand():
* expand paletted images to RGB, expand grayscale images of
* less than 8-bit depth to 8-bit depth, and expand tRNS chunks
* to alpha channels.
*/
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_expand(png);
}
if (png_get_valid(png, info, PNG_INFO_tRNS)) {
png_set_expand(png);
}
/* We might want to expand background */
/*
if(png_get_valid(png, info, PNG_INFO_bKGD)) {
png_color_16p bgnd;
png_get_bKGD(png, info, &bgnd);
png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
}
*/
if (!png_get_gAMA(png, info, &gamma)) {
gamma = 1.0;
}
/* we're not displaying but converting, screen gamma == 1.0 */
png_set_gamma(png, 1.0, gamma);
png_read_update_info(png, info);
color_type = png_get_color_type(png, info);
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
nr_comp = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
nr_comp = 2;
break;
case PNG_COLOR_TYPE_RGB:
nr_comp = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
nr_comp = 4;
break;
default:
fprintf(stderr, "pngtoimage: colortype %d is not supported\n", color_type);
return image;
}
cvtCxToPx = convert_32s_CXPX_LUT[nr_comp];
bit_depth = png_get_bit_depth(png, info);
switch (bit_depth) {
case 1:
case 2:
case 4:
case 8:
cvtXXTo32s = convert_XXu32s_C1R_LUT[bit_depth];
break;
case 16: /* 16 bpp is specific to PNG */
cvtXXTo32s = convert_16u32s_C1R;
break;
default:
fprintf(stderr, "pngtoimage: bit depth %d is not supported\n", bit_depth);
return image;
}
rows = (OPJ_BYTE**)calloc(height + 1, sizeof(OPJ_BYTE*));
if (rows == NULL) {
fprintf(stderr, "pngtoimage: memory out\n");
return image;
}
*prows = rows;
for (i = 0; i < height; ++i) {
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png, info));
if (rows[i] == NULL) {
fprintf(stderr, "pngtoimage: memory out\n");
return image;
}
}
png_read_image(png, rows);
/* Create image */
memset(cmptparm, 0, sizeof(cmptparm));
for (i = 0; i < nr_comp; ++i) {
/* bits_per_pixel: 8 or 16 */
cmptparm[i].prec = (OPJ_UINT32)bit_depth;
cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy;
cmptparm[i].w = (OPJ_UINT32)width;
cmptparm[i].h = (OPJ_UINT32)height;
}
image = opj_image_create(nr_comp, &cmptparm[0],
(nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY);
if (image == NULL) {
return image;
}
image->x0 = (OPJ_UINT32)params->image_offset_x0;
image->y0 = (OPJ_UINT32)params->image_offset_y0;
image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)
params->subsampling_dx + 1);
image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)
params->subsampling_dy + 1);
row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32));
if (row32s == NULL) {
return image;
}
*prow32s = row32s;
/* Set alpha channel */
image->comps[nr_comp - 1U].alpha = 1U - (nr_comp & 1U);
for (i = 0; i < nr_comp; i++) {
planes[i] = image->comps[i].data;
}
for (i = 0; i < height; ++i) {
cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp);
cvtCxToPx(row32s, planes, width);
planes[0] += width;
planes[1] += width;
planes[2] += width;
planes[3] += width;
}
return image;
}
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_INT32 val0 = *pSrc++;
OPJ_INT32 val1 = *pSrc++;
pDst[i] = val0 << 8 | val1;
}
}
opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
{
png_structp png = NULL;
png_infop info = NULL;
OPJ_UINT32 i;
png_uint_32 height = 0U;
FILE *reader = NULL;
OPJ_BYTE** rows = NULL;
OPJ_INT32* row32s = NULL;
OPJ_BYTE sigbuf[8];
opj_image_t *image = NULL;
png_structp png = NULL;
png_infop info = NULL;
double gamma;
int bit_depth, interlace_type,compression_type, filter_type;
OPJ_UINT32 i;
png_uint_32 width, height = 0U;
int color_type;
FILE *reader = NULL;
OPJ_BYTE** rows = NULL;
OPJ_INT32* row32s = NULL;
/* j2k: */
opj_image_t *image = NULL;
opj_image_cmptparm_t cmptparm[4];
OPJ_UINT32 nr_comp;
OPJ_BYTE sigbuf[8];
convert_XXx32s_C1R cvtXXTo32s = NULL;
convert_32s_CXPX cvtCxToPx = NULL;
OPJ_INT32* planes[4];
if((reader = fopen(read_idf, "rb")) == NULL)
{
fprintf(stderr,"pngtoimage: can not open %s\n",read_idf);
return NULL;
}
if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0)
{
fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf);
goto fin;
}
if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL)) == NULL)
goto fin;
if((info = png_create_info_struct(png)) == NULL)
goto fin;
if(setjmp(png_jmpbuf(png)))
goto fin;
png_init_io(png, reader);
png_set_sig_bytes(png, MAGIC_SIZE);
png_read_info(png, info);
if(png_get_IHDR(png, info, &width, &height,
&bit_depth, &color_type, &interlace_type,
&compression_type, &filter_type) == 0)
goto fin;
/* png_set_expand():
* expand paletted images to RGB, expand grayscale images of
* less than 8-bit depth to 8-bit depth, and expand tRNS chunks
* to alpha channels.
*/
if(color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_expand(png);
}
if(png_get_valid(png, info, PNG_INFO_tRNS)) {
png_set_expand(png);
}
/* We might wan't to expand background */
/*
if(png_get_valid(png, info, PNG_INFO_bKGD)) {
png_color_16p bgnd;
png_get_bKGD(png, info, &bgnd);
png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
}
*/
if( !png_get_gAMA(png, info, &gamma))
gamma = 1.0;
/* we're not displaying but converting, screen gamma == 1.0 */
png_set_gamma(png, 1.0, gamma);
png_read_update_info(png, info);
color_type = png_get_color_type(png, info);
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
nr_comp = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
nr_comp = 2;
break;
case PNG_COLOR_TYPE_RGB:
nr_comp = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
nr_comp = 4;
break;
default:
fprintf(stderr,"pngtoimage: colortype %d is not supported\n", color_type);
goto fin;
}
cvtCxToPx = convert_32s_CXPX_LUT[nr_comp];
bit_depth = png_get_bit_depth(png, info);
switch (bit_depth) {
case 1:
case 2:
case 4:
case 8:
cvtXXTo32s = convert_XXu32s_C1R_LUT[bit_depth];
break;
case 16: /* 16 bpp is specific to PNG */
cvtXXTo32s = convert_16u32s_C1R;
break;
default:
fprintf(stderr,"pngtoimage: bit depth %d is not supported\n", bit_depth);
goto fin;
}
if ((reader = fopen(read_idf, "rb")) == NULL) {
fprintf(stderr, "pngtoimage: can not open %s\n", read_idf);
return NULL;
}
if (fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) {
fprintf(stderr, "pngtoimage: %s is no valid PNG file\n", read_idf);
goto fin;
}
if ((png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL)) == NULL) {
goto fin;
}
if ((info = png_create_info_struct(png)) == NULL) {
goto fin;
}
image = pngtoimage_internal(params, reader, png, info, &height, &rows, &row32s);
rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*));
if(rows == NULL){
fprintf(stderr, "pngtoimage: memory out\n");
goto fin;
}
for(i = 0; i < height; ++i){
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info));
if(rows[i] == NULL){
fprintf(stderr,"pngtoimage: memory out\n");
goto fin;
}
}
png_read_image(png, rows);
/* Create image */
memset(cmptparm, 0, sizeof(cmptparm));
for(i = 0; i < nr_comp; ++i)
{
cmptparm[i].prec = (OPJ_UINT32)bit_depth;
/* bits_per_pixel: 8 or 16 */
cmptparm[i].bpp = (OPJ_UINT32)bit_depth;
cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy;
cmptparm[i].w = (OPJ_UINT32)width;
cmptparm[i].h = (OPJ_UINT32)height;
}
image = opj_image_create(nr_comp, &cmptparm[0], (nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY);
if(image == NULL) goto fin;
image->x0 = (OPJ_UINT32)params->image_offset_x0;
image->y0 = (OPJ_UINT32)params->image_offset_y0;
image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)params->subsampling_dx + 1 + image->x0);
image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)params->subsampling_dy + 1 + image->y0);
row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32));
if(row32s == NULL) goto fin;
/* Set alpha channel */
image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U);
for(i = 0; i < nr_comp; i++)
{
planes[i] = image->comps[i].data;
}
for(i = 0; i < height; ++i)
{
cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp);
cvtCxToPx(row32s, planes, width);
planes[0] += width;
planes[1] += width;
planes[2] += width;
planes[3] += width;
}
fin:
if (rows) {
for (i = 0; i < height; ++i)
if (rows[i]) {
free(rows[i]);
}
free(rows);
}
if (row32s) {
free(row32s);
}
if (png) {
png_destroy_read_struct(&png, &info, NULL);
}
fclose(reader);
return image;
if(rows)
{
for(i = 0; i < height; ++i)
if(rows[i]) free(rows[i]);
free(rows);
}
if (row32s) {
free(row32s);
}
if(png)
png_destroy_read_struct(&png, &info, NULL);
fclose(reader);
return image;
}/* pngtoimage() */
static void convert_32s16u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst,
OPJ_SIZE_T length)
static void convert_32s16u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_UINT32 val = (OPJ_UINT32)pSrc[i];
*pDst++ = (OPJ_BYTE)(val >> 8);
*pDst++ = (OPJ_BYTE)val;
}
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_UINT32 val = (OPJ_UINT32)pSrc[i];
*pDst++ = (OPJ_BYTE)(val >> 8);
*pDst++ = (OPJ_BYTE)val;
}
}
int imagetopng(opj_image_t * image, const char *write_idf)
{
FILE * volatile writer = NULL;
png_structp png = NULL;
png_infop info = NULL;
png_bytep volatile row_buf = NULL;
int nr_comp, color_type;
volatile int prec;
png_color_8 sig_bit;
OPJ_INT32 const* planes[4];
int i;
OPJ_INT32* volatile buffer32s = NULL;
FILE * volatile writer = NULL;
png_structp png = NULL;
png_infop info = NULL;
png_bytep volatile row_buf = NULL;
int nr_comp, color_type;
volatile int prec;
png_color_8 sig_bit;
OPJ_INT32 const* planes[4];
int i;
OPJ_INT32* volatile buffer32s = NULL;
volatile int fails = 1;
memset(&sig_bit, 0, sizeof(sig_bit));
prec = (int)image->comps[0].prec;
planes[0] = image->comps[0].data;
nr_comp = (int)image->numcomps;
if (nr_comp > 4) {
nr_comp = 4;
}
for (i = 1; i < nr_comp; ++i) {
if (image->comps[0].dx != image->comps[i].dx) {
break;
}
if (image->comps[0].dy != image->comps[i].dy) {
break;
}
if (image->comps[0].prec != image->comps[i].prec) {
break;
}
if (image->comps[0].sgnd != image->comps[i].sgnd) {
break;
}
planes[i] = image->comps[i].data;
}
if (i != nr_comp) {
fprintf(stderr,"imagetopng: All components shall have the same subsampling, same bit depth, same sign.\n");
fprintf(stderr,"\tAborting\n");
return 1;
}
for (i = 0; i < nr_comp; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec);
}
if(prec > 8 && prec < 16)
{
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 16);
}
prec = 16;
}
else if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */
{
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 8);
}
prec = 8;
} else if((prec > 1) && (prec < 8) && ((prec == 6) || ((prec & 1)==1))) { /* GRAY with non native precision */
if ((prec == 5) || (prec == 6)) {
prec = 8;
} else {
prec++;
}
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), (OPJ_UINT32)prec);
}
}
if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16)
{
fprintf(stderr,"imagetopng: can not create %s\n\twrong bit_depth %d\n", write_idf, prec);
return fails;
}
writer = fopen(write_idf, "wb");
if(writer == NULL) return fails;
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also check that
* the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED.
*/
png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
/*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */
if(png == NULL) goto fin;
/* Allocate/initialize the image information data. REQUIRED
*/
info = png_create_info_struct(png);
if(info == NULL) goto fin;
/* Set error handling. REQUIRED if you are not supplying your own
* error handling functions in the png_create_write_struct() call.
*/
if(setjmp(png_jmpbuf(png))) goto fin;
/* I/O initialization functions is REQUIRED
*/
png_init_io(png, writer);
/* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE.
* REQUIRED
*
* ERRORS:
*
* color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8
* color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8
* color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8
* color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8
*
*/
png_set_compression_level(png, Z_BEST_COMPRESSION);
if(nr_comp >= 3) /* RGB(A) */
{
color_type = PNG_COLOR_TYPE_RGB;
sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec;
}
else /* GRAY(A) */
{
color_type = PNG_COLOR_TYPE_GRAY;
sig_bit.gray = (png_byte)prec;
}
if((nr_comp & 1) == 0) /* ALPHA */
{
color_type |= PNG_COLOR_MASK_ALPHA;
sig_bit.alpha = (png_byte)prec;
}
png_set_IHDR(png, info, image->comps[0].w, image->comps[0].h, prec, color_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_sBIT(png, info, &sig_bit);
/* png_set_gamma(png, 2.2, 1./2.2); */
/* png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); */
png_write_info(png, info);
/* setup conversion */
{
OPJ_SIZE_T rowStride;
png_size_t png_row_size;
png_row_size = png_get_rowbytes(png, info);
rowStride = ((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * (OPJ_SIZE_T)prec + 7U) / 8U;
if (rowStride != (OPJ_SIZE_T)png_row_size) {
fprintf(stderr, "Invalid PNG row size\n");
goto fin;
}
row_buf = (png_bytep)malloc(png_row_size);
if (row_buf == NULL) {
fprintf(stderr, "Can't allocate memory for PNG row\n");
goto fin;
}
buffer32s = (OPJ_INT32*)malloc((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * sizeof(OPJ_INT32));
if (buffer32s == NULL) {
fprintf(stderr, "Can't allocate memory for interleaved 32s row\n");
goto fin;
}
}
/* convert */
{
OPJ_SIZE_T width= image->comps[0].w;
OPJ_UINT32 y;
convert_32s_PXCX cvtPxToCx = convert_32s_PXCX_LUT[nr_comp];
convert_32sXXx_C1R cvt32sToPack = NULL;
OPJ_INT32 adjust = image->comps[0].sgnd ? 1 << (prec - 1) : 0;
png_bytep row_buf_cpy = row_buf;
OPJ_INT32* buffer32s_cpy = buffer32s;
volatile int fails = 1;
memset(&sig_bit, 0, sizeof(sig_bit));
prec = (int)image->comps[0].prec;
planes[0] = image->comps[0].data;
if (planes[0] == NULL) {
fprintf(stderr,
"imagetopng: planes[%d] == NULL.\n", 0);
fprintf(stderr, "\tAborting\n");
return 1;
}
nr_comp = (int)image->numcomps;
if (nr_comp > 4) {
nr_comp = 4;
}
for (i = 1; i < nr_comp; ++i) {
if (image->comps[0].dx != image->comps[i].dx) {
break;
}
if (image->comps[0].dy != image->comps[i].dy) {
break;
}
if (image->comps[0].prec != image->comps[i].prec) {
break;
}
if (image->comps[0].sgnd != image->comps[i].sgnd) {
break;
}
planes[i] = image->comps[i].data;
if (planes[i] == NULL) {
fprintf(stderr,
"imagetopng: planes[%d] == NULL.\n", i);
fprintf(stderr, "\tAborting\n");
return 1;
}
}
if (i != nr_comp) {
fprintf(stderr,
"imagetopng: All components shall have the same subsampling, same bit depth, same sign.\n");
fprintf(stderr, "\tAborting\n");
return 1;
}
for (i = 0; i < nr_comp; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec);
}
if (prec > 8 && prec < 16) {
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 16);
}
prec = 16;
} else if (prec < 8 && nr_comp > 1) { /* GRAY_ALPHA, RGB, RGB_ALPHA */
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 8);
}
prec = 8;
} else if ((prec > 1) && (prec < 8) && ((prec == 6) ||
((prec & 1) == 1))) { /* GRAY with non native precision */
if ((prec == 5) || (prec == 6)) {
prec = 8;
} else {
prec++;
}
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), (OPJ_UINT32)prec);
}
}
if (prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) {
fprintf(stderr, "imagetopng: can not create %s\n\twrong bit_depth %d\n",
write_idf, prec);
return fails;
}
writer = fopen(write_idf, "wb");
if (writer == NULL) {
return fails;
}
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also check that
* the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED.
*/
png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
/*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */
if (png == NULL) {
goto fin;
}
/* Allocate/initialize the image information data. REQUIRED
*/
info = png_create_info_struct(png);
if (info == NULL) {
goto fin;
}
/* Set error handling. REQUIRED if you are not supplying your own
* error handling functions in the png_create_write_struct() call.
*/
if (setjmp(png_jmpbuf(png))) {
goto fin;
}
/* I/O initialization functions is REQUIRED
*/
png_init_io(png, writer);
/* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE.
* REQUIRED
*
* ERRORS:
*
* color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8
* color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8
* color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8
* color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8
*
*/
png_set_compression_level(png, Z_BEST_COMPRESSION);
if (nr_comp >= 3) { /* RGB(A) */
color_type = PNG_COLOR_TYPE_RGB;
sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec;
} else { /* GRAY(A) */
color_type = PNG_COLOR_TYPE_GRAY;
sig_bit.gray = (png_byte)prec;
}
if ((nr_comp & 1) == 0) { /* ALPHA */
color_type |= PNG_COLOR_MASK_ALPHA;
sig_bit.alpha = (png_byte)prec;
}
png_set_IHDR(png, info, image->comps[0].w, image->comps[0].h, prec, color_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_sBIT(png, info, &sig_bit);
/* png_set_gamma(png, 2.2, 1./2.2); */
/* png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); */
png_write_info(png, info);
/* setup conversion */
{
OPJ_SIZE_T rowStride;
png_size_t png_row_size;
png_row_size = png_get_rowbytes(png, info);
rowStride = ((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp *
(OPJ_SIZE_T)prec + 7U) / 8U;
if (rowStride != (OPJ_SIZE_T)png_row_size) {
fprintf(stderr, "Invalid PNG row size\n");
goto fin;
}
row_buf = (png_bytep)malloc(png_row_size);
if (row_buf == NULL) {
fprintf(stderr, "Can't allocate memory for PNG row\n");
goto fin;
}
buffer32s = (OPJ_INT32*)malloc((OPJ_SIZE_T)image->comps[0].w *
(OPJ_SIZE_T)nr_comp * sizeof(OPJ_INT32));
if (buffer32s == NULL) {
fprintf(stderr, "Can't allocate memory for interleaved 32s row\n");
goto fin;
}
}
/* convert */
{
OPJ_SIZE_T width = image->comps[0].w;
OPJ_UINT32 y;
convert_32s_PXCX cvtPxToCx = convert_32s_PXCX_LUT[nr_comp];
convert_32sXXx_C1R cvt32sToPack = NULL;
OPJ_INT32 adjust = image->comps[0].sgnd ? 1 << (prec - 1) : 0;
png_bytep row_buf_cpy = row_buf;
OPJ_INT32* buffer32s_cpy = buffer32s;
switch (prec) {
case 1:
case 2:
case 4:
case 8:
cvt32sToPack = convert_32sXXu_C1R_LUT[prec];
break;
case 16:
cvt32sToPack = convert_32s16u_C1R;
break;
default:
/* never here */
break;
}
for (y = 0; y < image->comps[0].h; ++y) {
cvtPxToCx(planes, buffer32s_cpy, width, adjust);
cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp);
png_write_row(png, row_buf_cpy);
planes[0] += width;
planes[1] += width;
planes[2] += width;
planes[3] += width;
}
}
png_write_end(png, info);
fails = 0;
switch (prec) {
case 1:
case 2:
case 4:
case 8:
cvt32sToPack = convert_32sXXu_C1R_LUT[prec];
break;
case 16:
cvt32sToPack = convert_32s16u_C1R;
break;
default:
/* never here */
break;
}
for(y = 0; y < image->comps[0].h; ++y)
{
cvtPxToCx(planes, buffer32s_cpy, width, adjust);
cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp);
png_write_row(png, row_buf_cpy);
planes[0] += width;
planes[1] += width;
planes[2] += width;
planes[3] += width;
}
}
png_write_end(png, info);
fails = 0;
fin:
if (png) {
png_destroy_write_struct(&png, &info);
}
if (row_buf) {
free(row_buf);
}
if (buffer32s) {
free(buffer32s);
}
fclose(writer);
if (fails) {
(void)remove(write_idf); /* ignore return value */
}
return fails;
if(png) {
png_destroy_write_struct(&png, &info);
}
if(row_buf) {
free(row_buf);
}
if(buffer32s) {
free(buffer32s);
}
fclose(writer);
if(fails) (void)remove(write_idf); /* ignore return value */
return fails;
}/* imagetopng() */

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -42,415 +42,356 @@
/**
Write a structured index to a file
@param cstr_info Codestream information
@param cstr_info Codestream information
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
int write_index_file(opj_codestream_info_t *cstr_info, char *index)
{
int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL;
double total_disto = 0;
/* UniPG>> */
int tilepartno;
char disto_on, numpix_on;
int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL;
double total_disto = 0;
/* UniPG>> */
int tilepartno;
char disto_on, numpix_on;
#ifdef USE_JPWL
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME)) {
return 0;
}
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0;
#endif /* USE_JPWL */
/* <<UniPG */
/* <<UniPG */
if (!cstr_info) {
return 1;
}
if (!cstr_info)
return 1;
stream = fopen(index, "w");
if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1;
}
stream = fopen(index, "w");
if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1;
}
if (cstr_info->tile[0].distotile > 0.0)
disto_on = 1;
else
disto_on = 0;
if (cstr_info->tile[0].distotile > 0.0) {
disto_on = 1;
} else {
disto_on = 0;
}
if (cstr_info->tile[0].numpix)
numpix_on = 1;
else
numpix_on = 0;
if (cstr_info->tile[0].numpix) {
numpix_on = 1;
} else {
numpix_on = 0;
}
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);
fprintf(stream, "%d\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);
fprintf(stream, "%d\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
}
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]),
(1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
}
fprintf(stream, "\n");
/* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size);
fprintf(stream, "\nINFO ON TILES\n");
fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
if (disto_on)
fprintf(stream," disto");
if (numpix_on)
fprintf(stream," nbpix");
if (disto_on && numpix_on)
fprintf(stream," disto/nbpix");
fprintf(stream, "\n");
fprintf(stream, "\n");
/* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size);
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos,
cstr_info->tile[tileno].num_tps);
if (disto_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile);
if (numpix_on)
fprintf(stream," %9d", cstr_info->tile[tileno].numpix);
if (disto_on && numpix_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);
fprintf(stream, "\n");
}
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
OPJ_OFF_T start_pos, end_ph_pos, end_pos;
double disto = 0;
int max_numdecompos = 0;
pack_nb = 0;
fprintf(stream, "\nINFO ON TILES\n");
fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
if (disto_on) {
fprintf(stream, " disto");
}
if (numpix_on) {
fprintf(stream, " nbpix");
}
if (disto_on && numpix_on) {
fprintf(stream, " disto/nbpix");
}
fprintf(stream, "\n");
for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno])
max_numdecompos = cstr_info->numdecompos[compno];
}
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos,
cstr_info->tile[tileno].num_tps);
if (disto_on) {
fprintf(stream, " %9e", cstr_info->tile[tileno].distotile);
}
if (numpix_on) {
fprintf(stream, " %9d", cstr_info->tile[tileno].numpix);
}
if (disto_on && numpix_on) {
fprintf(stream, " %9e", cstr_info->tile[tileno].distotile /
cstr_info->tile[tileno].numpix);
}
fprintf(stream, "\n");
}
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
tilepartno, tileno,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,
cstr_info->tile[tileno].tp[tilepartno].tp_end_header,
cstr_info->tile[tileno].tp[tilepartno].tp_end_pos
);
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
OPJ_OFF_T start_pos, end_ph_pos, end_pos;
double disto = 0;
int max_numdecompos = 0;
pack_nb = 0;
if (cstr_info->prog == OPJ_LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno]) {
max_numdecompos = cstr_info->numdecompos[compno];
}
}
for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max;
if (resno > cstr_info->numdecompos[compno])
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %7d %5d %6d %6d %6" PRId64 " %6" PRId64 " %7" PRId64,
pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* LRCP */
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream,
"part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
tilepartno, tileno,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,
cstr_info->tile[tileno].tp[tilepartno].tp_end_header,
cstr_info->tile[tileno].tp[tilepartno].tp_end_pos
);
else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
if (cstr_info->prog == OPJ_LRCP) { /* LRCP */
fprintf(stream,
"LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on) {
fprintf(stream, " disto");
}
fprintf(stream, "\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max;
if (resno > cstr_info->numdecompos[compno])
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %7d %6d %6d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* RLCP */
for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max;
if (resno > cstr_info->numdecompos[compno]) {
break;
}
prec_max = cstr_info->tile[tileno].pw[resno] *
cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %7d %5d %6d %6d %6" PRId64 " %6" PRId64 " %7"
PRId64,
pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on) {
fprintf(stream, " %8e", disto);
}
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* LRCP */
else if (cstr_info->prog == OPJ_RPCL) { /* RPCL */
else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */
fprintf(stream,
"RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on) {
fprintf(stream, " disto");
}
fprintf(stream, "\n");
fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max;
if (resno > cstr_info->numdecompos[compno]) {
break;
}
prec_max = cstr_info->tile[tileno].pw[resno] *
cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %7d %6d %6d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on) {
fprintf(stream, " %8e", disto);
}
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* RLCP */
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) {
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (resno > cstr_info->numdecompos[compno])
break;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %6d %6d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* precno */
} /* compno */
} /* resno */
} /* RPCL */
else if (cstr_info->prog == OPJ_RPCL) { /* RPCL */
else if (cstr_info->prog == OPJ_PCRL) { /* PCRL */
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
fprintf(stream,
"RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
if (disto_on) {
fprintf(stream, " disto");
}
fprintf(stream, "\n");
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] *
cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) {
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno /
(float)cstr_info->tw) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor((float)tileno /
(float)cstr_info->tw) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow(2, cstr_info->tile[tileno].pdx[resno] +
cstr_info->numdecompos[compno] - resno);
int pcy = (int) pow(2, cstr_info->tile[tileno].pdy[resno] +
cstr_info->numdecompos[compno] - resno);
int precno_x = precno - (int) floor((float)precno / (float)pcnx) * pcnx;
int precno_y = (int) floor((float)precno / (float)pcnx);
if (resno > cstr_info->numdecompos[compno]) {
break;
}
for (y = y0; y < y1; y++) {
if (precno_y * pcy == y) {
for (x = x0; x < x1; x++) {
if (precno_x * pcx == x) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %6d %6d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) {
fprintf(stream, " %8e", disto);
}
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* precno */
} /* compno */
} /* resno */
} /* RPCL */
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
else if (cstr_info->prog == OPJ_PCRL) { /* PCRL */
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno /
(float)cstr_info->tw) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor((float)tileno /
(float)cstr_info->tw) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
for (precno = 0; precno < max_numprec; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* compno */
} /* precno */
} /* PCRL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] *
cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec) {
max_numprec = numprec;
}
}
else { /* CPRL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream,
"PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on) {
fprintf(stream, " disto");
}
fprintf(stream, "\n");
fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (precno = 0; precno < max_numprec; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] *
cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow(2, cstr_info->tile[tileno].pdx[resno] +
cstr_info->numdecompos[compno] - resno);
int pcy = (int) pow(2, cstr_info->tile[tileno].pdy[resno] +
cstr_info->numdecompos[compno] - resno);
int precno_x = precno - (int) floor((float)precno / (float)pcnx) * pcnx;
int precno_y = (int) floor((float)precno / (float)pcnx);
if (precno >= numprec) {
continue;
}
for (y = y0; y < y1; y++) {
if (precno_y * pcy == y) {
for (x = x0; x < x1; x++) {
if (precno_x * pcx == x) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) {
fprintf(stream, " %8e", disto);
}
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* compno */
} /* precno */
} /* PCRL */
for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
else { /* CPRL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] *
cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec) {
max_numprec = numprec;
}
}
for (precno = 0; precno < max_numprec; precno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
fprintf(stream,
"CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on) {
fprintf(stream, " disto");
}
fprintf(stream, "\n");
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* precno */
} /* compno */
} /* CPRL */
} /* tileno */
if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
}
/* UniPG>> */
/* print the markers' list */
if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n");
for (x = 0; x < cstr_info->marknum; x++)
fprintf(stream, "%X\t%9" PRId64 " %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
}
/* <<UniPG */
fclose(stream);
for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno /
(float)cstr_info->tw) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor((float)tileno /
(float)cstr_info->tw) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
fprintf(stderr,"Generated index file %s\n", index);
for (precno = 0; precno < max_numprec; precno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] *
cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow(2, cstr_info->tile[tileno].pdx[resno] +
cstr_info->numdecompos[compno] - resno);
int pcy = (int) pow(2, cstr_info->tile[tileno].pdy[resno] +
cstr_info->numdecompos[compno] - resno);
int precno_x = precno - (int) floor((float)precno / (float)pcnx) * pcnx;
int precno_y = (int) floor((float)precno / (float)pcnx);
if (precno >= numprec) {
continue;
}
for (y = y0; y < y1; y++) {
if (precno_y * pcy == y) {
for (x = x0; x < x1; x++) {
if (precno_x * pcx == x) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) {
fprintf(stream, " %8e", disto);
}
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* precno */
} /* compno */
} /* CPRL */
} /* tileno */
if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
}
/* UniPG>> */
/* print the markers' list */
if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n");
for (x = 0; x < cstr_info->marknum; x++) {
fprintf(stream, "%X\t%9" PRId64 " %9d\n", cstr_info->marker[x].type,
cstr_info->marker[x].pos, cstr_info->marker[x].len);
}
}
/* <<UniPG */
fclose(stream);
fprintf(stderr, "Generated index file %s\n", index);
return 0;
return 0;
}

View File

@ -1,6 +1,6 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -40,7 +40,7 @@ extern "C" {
/**
Write a structured index to a file
@param cstr_info Codestream information
@param cstr_info Codestream information
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
/*
* uce-dirent.h - operating system independent dirent implementation
*
*
* Copyright (C) 1998-2002 Toni Ronkko
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including
@ -11,10 +11,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@ -22,8 +22,8 @@
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
*
*
*
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
*
* $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $
@ -59,7 +59,7 @@
* Revision 1.1 1998/07/04 16:27:51 tr
* Initial revision
*
*
*
* MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle
* include directives inside #if..#endif block those are never entered.
@ -69,7 +69,7 @@
* handle inclusion of sys/dir.h in a part that is compiled only in Apollo
* operating system. To fix the problem you need to insert DIR.H into
* SYSINCL.DAT located in MSVC\BIN directory and restart visual C++.
* Consult manuals for more information about the problem.
* Consult manuals for more informaton about the problem.
*
* Since many UNIX systems have dirent.h we assume to have one also.
* However, if your UNIX system does not have dirent.h you can download one
@ -102,18 +102,18 @@
/*
* See what kind of dirent interface we have unless autoconf has already
* determined that.
* determinated that.
*/
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */
/* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */
/* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H
# define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */
/* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */
@ -172,7 +172,7 @@
#elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlying directory interface to be used */
/* figure out type of underlaying directory interface to be used */
# if defined(WIN32)
# define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS)
@ -181,7 +181,7 @@
# error "missing native dirent interface"
# endif
/*** WIN32 specifics ***/
/*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -189,11 +189,11 @@
# endif
/*** MS-DOS specifics ***/
/*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h>
/* Borland defines file length macros in dir.h */
/* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -203,7 +203,7 @@
# define _find_t find_t
# endif
/* Turbo C defines ffblk structure in dir.h */
/* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -211,13 +211,13 @@
# endif
# define DIRENT_USE_FFBLK
/* MSVC */
/* MSVC */
# elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12)
# endif
/* Watcom */
/* Watcom */
# elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__)
@ -230,7 +230,7 @@
# endif
# endif
/*** generic MS-DOS and MS-Windows stuff ***/
/*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN
# endif
@ -239,55 +239,53 @@
# endif
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE) /*WIN32*/
WIN32_FIND_DATA data;
# elif defined(DIRENT_MSDOS_INTERFACE) /*MS-DOS*/
# elif defined(DIRENT_MSDOS_INTERFACE) /*MSDOS*/
# if defined(DIRENT_USE_FFBLK)
struct ffblk data;
# else
struct _find_t data;
# endif
# endif
} dirent;
} dirent;
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
char *dirname; /* directory being scanned */
dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE)
# endif
} DIR;
} DIR;
# ifdef __cplusplus
extern "C" {
# endif
/* supply prototypes for dirent functions */
static DIR *opendir(const char *dirname);
static struct dirent *readdir(DIR *dirp);
static int closedir(DIR *dirp);
#ifdef unused
static void rewinddir(DIR *dirp);
#endif
static DIR *opendir (const char *dirname);
static struct dirent *readdir (DIR *dirp);
static int closedir (DIR *dirp);
static void rewinddir (DIR *dirp);
/*
* Implement dirent interface as static functions so that the user does not
@ -314,9 +312,9 @@ static void rewinddir(DIR *dirp);
# define _dos_findfirst(name,flags,dest) findfirst(name,dest,flags)
#endif
static int _initdir(DIR *p);
static const char *_getdirname(const struct dirent *dp);
static void _setdirname(struct DIR *dirp);
static int _initdir (DIR *p);
static const char *_getdirname (const struct dirent *dp);
static void _setdirname (struct DIR *dirp);
/*
* <function name="opendir">
@ -327,7 +325,7 @@ static void _setdirname(struct DIR *dirp);
* internal working area that is used for retrieving individual directory
* entries. The internal working area has no fields of your interest.
*
* <ret>Returns a pointer to the internal working area or NULL in case the
* <ret>Returns a pointer to the internal working area or NULL in case the
* directory stream could not be opened. Global `errno' variable will set
* in case of error as follows:
*
@ -346,45 +344,46 @@ static void _setdirname(struct DIR *dirp);
*/
static DIR *opendir(const char *dirname)
{
DIR *dirp;
assert(dirname != NULL);
dirp = (DIR*)malloc(sizeof(struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc(strlen(dirname) + 1 + strlen("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free(dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy(dirp->dirname, dirname);
p = strchr(dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
strcpy(p++, "\\");
}
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
strcpy(p, "*"); /*scan files with and without extension in win32*/
strcpy (p, "*"); /*scan files with and without extension in win32*/
# else
strcpy(p, "*.*"); /*scan files with and without extension in DOS*/
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif
/* open stream */
if (_initdir(dirp) == 0) {
/* initialization failed */
free(dirp->dirname);
free(dirp);
return NULL;
}
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
}
return dirp;
}
return dirp;
}
@ -435,57 +434,57 @@ static DIR *opendir(const char *dirname)
* </function>
*/
static struct dirent *
readdir(DIR *dirp)
readdir (DIR *dirp)
{
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
#endif
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, we have to
* save the first file when opening the stream and later we have to
* return the saved entry when the user tries to read the first entry.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, we have to
* save the first file when opening the stream and later we have to
* return the saved entry when the user tries to read the first entry.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile(dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose(dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext(&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
# endif
_setdirname(dirp);
assert(dirp->dirent_filled == 0);
}
return &dirp->current;
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
}
@ -509,44 +508,41 @@ readdir(DIR *dirp)
* </function>
*/
static int
closedir(DIR *dirp)
{
int retcode = 0;
closedir (DIR *dirp)
{
int retcode = 0;
/* make sure that dirp points to legal structure */
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) {
free(dirp->dirname);
}
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose(dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
}
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
}
#endif
}
#endif
/* clear dirp structure to make sure that it cannot be used anymore*/
memset(dirp, 0, sizeof(*dirp));
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE;
dirp->search_handle = INVALID_HANDLE_VALUE;
# endif
free(dirp);
return retcode;
free (dirp);
return retcode;
}
#ifdef unused
/*
* <function name="rewinddir">
* <intro>rewind directory stream to the beginning
@ -569,71 +565,72 @@ closedir(DIR *dirp)
* notice it later when you try to retrieve the first directory entry.
*/
static void
rewinddir(DIR *dirp)
{
/* make sure that dirp is legal */
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert(dirp->dirname != NULL);
/* close previous stream */
rewinddir (DIR *dirp)
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose(dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
}
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
}
}
#endif
/* re-open previous stream */
if (_initdir(dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory entry. */
/*EMPTY*/;
}
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
}
#endif
/*
* Open native directory stream object and retrieve first file.
* Be sure to close previous stream before opening new one.
*/
static int
_initdir(DIR *dirp)
{
assert(dirp != NULL);
assert(dirp->dirname != NULL);
dirp->dirent_filled = 0;
_initdir (DIR *dirp)
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile(dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst(dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) {
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
# endif
/* initialize DIR and it's first entry */
_setdirname(dirp);
dirp->dirent_filled = 1;
return 1;
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
}
@ -641,17 +638,17 @@ _initdir(DIR *dirp)
* Return implementation dependent name of the current directory entry.
*/
static const char *
_getdirname(const struct dirent *dp)
_getdirname (const struct dirent *dp)
{
#if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName;
return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name;
return dp->data.ff_name;
#else
return dp->data.name;
#endif
return dp->data.name;
#endif
}
@ -659,17 +656,16 @@ _getdirname(const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname(struct DIR *dirp)
{
/* make sure that d_name is long enough */
assert(strlen(_getdirname(&dirp->current)) <= NAME_MAX);
strncpy(dirp->current.d_name,
_getdirname(&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
}
# ifdef __cplusplus
}
# endif

View File

@ -0,0 +1,41 @@
# Build the demo app, small examples
# First thing define the common source:
set(common_SRCS
convert.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c
)
# Headers file are located here:
include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
${OPENJPEG_SOURCE_DIR}/src/lib/openjp3d
${LCMS_INCLUDE_DIRNAME}
${OPENJPEG_SOURCE_DIR}/src/bin/common
${Z_INCLUDE_DIRNAME}
${PNG_INCLUDE_DIRNAME}
${TIFF_INCLUDE_DIRNAME}
)
if(WIN32)
if(BUILD_SHARED_LIBS)
add_definitions(-DOPJ_EXPORTS)
else()
add_definitions(-DOPJ_STATIC)
endif()
endif()
# Loop over all executables:
foreach(exe opj_jp3d_compress opj_jp3d_decompress)
add_executable(${exe} ${exe}.c ${common_SRCS})
target_link_libraries(${exe} openjp3d)
# On unix you need to link to the math library:
if(UNIX)
target_link_libraries(${exe} m)
endif(UNIX)
# Install exe
install(TARGETS ${exe}
EXPORT OpenJP3DTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
endforeach()

1002
src/bin/jp3d/convert.c Executable file

File diff suppressed because it is too large Load Diff

51
src/bin/jp3d/convert.h Executable file
View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __JP3D_CONVERT_H
#define __JP3D_CONVERT_H
/**
Load a single volume component encoded in PGX file format
@param filename Name of the PGX file to load
@param parameters *List ?*
@return Returns a greyscale volume if successful, returns NULL otherwise
*/
opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters);
int volumetopgx(opj_volume_t *volume, char *outfile);
opj_volume_t* bintovolume(char *filename,char *fileimg, opj_cparameters_t *parameters);
int volumetobin(opj_volume_t *volume, char *outfile);
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters);
#endif /* __J2K_CONVERT_H */

109
src/bin/jp3d/getopt.c Executable file
View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* last review : october 29th, 2002 */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""
/*
* getopt --
* Parse argc/argv argument vector.
*/
int getopt(int nargc, char *const *nargv, const char *ostr) {
# define __progname nargv[0] /* program name */
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((optopt = (int) *place++) == (int) ':' || !(oli = strchr(ostr, optopt))) {
/* if the user didn't specify '-' as an option, assume it means -1. */
if (optopt == (int) '-')
return (-1);
if (!*place)
++optind;
if (opterr && *ostr != ':')
(void) fprintf(stdout,"[ERROR] %s: illegal option -- %c\n", __progname, optopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
} else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
(void) fprintf(stdout, "[ERROR] %s: option requires an argument -- %c\n", __progname, optopt);
return (BADCH);
} else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return (optopt); /* dump back option letter */
}

14
src/bin/jp3d/getopt.h Executable file
View File

@ -0,0 +1,14 @@
/* last review : october 29th, 2002 */
#ifndef _GETOPT_H_
#define _GETOPT_H_
extern int opterr;
extern int optind;
extern int optopt;
extern int optreset;
extern char *optarg;
extern int getopt(int nargc, char *const *nargv, const char *ostr);
#endif /* _GETOPT_H_ */

907
src/bin/jp3d/opj_jp3d_compress.c Executable file
View File

@ -0,0 +1,907 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "opj_config.h"
#include "openjp3d.h"
#include "opj_getopt.h"
#include "convert.h"
#ifdef _WIN32
#include <windows.h>
#else
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif /* _WIN32 */
/* ----------------------------------------------------------------------- */
void encode_help_display() {
fprintf(stdout,"List of parameters for the JPEG2000 Part 10 encoder:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");
fprintf(stdout,"Required Parameters (except with -h):\n");
fprintf(stdout,"\n");
fprintf(stdout,"-i : source file (-i source.bin or source*.pgx) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-m : source characteristics file (-m imgfile.img) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-o : destination file (-o dest.jp3d) \n");
fprintf(stdout,"\n");
fprintf(stdout,"Optional Parameters:\n");
fprintf(stdout,"\n");
fprintf(stdout,"-h : display the help information \n ");
fprintf(stdout,"\n");
fprintf(stdout,"-n : number of resolutions (-n 3,3,3) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-I : use the irreversible transforms: ICT + DWT 9-7 (-I) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-C : coding algorithm (-C 2EB) [2EB, 3EB] \n");
fprintf(stdout,"\n");
fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n ");
fprintf(stdout," - The rate specified for each quality level is the desired compression factor.\n");
fprintf(stdout," - Rate 1 means lossless compression\n");
fprintf(stdout," (options -r and -q cannot be used together)\n ");
fprintf(stdout,"\n");
fprintf(stdout,"-q : different psnr for successive layers (-q 30,40,50) \n ");
fprintf(stdout," (options -r and -q cannot be used together)\n ");
fprintf(stdout,"\n");
fprintf(stdout,"-b : size of code block (-b 32,32,32) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-c : size of precinct (-c 128,128,128) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-t : size of tile (-t 512,512,512) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n");
fprintf(stdout,"\n");
fprintf(stdout,"-s : subsampling factor (-s 2,2,2) [-s X,Y,Z] \n");
fprintf(stdout," - Remark: subsampling bigger than 2 can produce error\n");
fprintf(stdout,"\n");
fprintf(stdout,"-SOP : write SOP marker before each packet \n");
fprintf(stdout,"\n");
fprintf(stdout,"-EPH : write EPH marker after each header packet \n");
fprintf(stdout,"\n");
fprintf(stdout,"-M : code-block style (-M 0) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n");
fprintf(stdout," 8=VSC 16=PTERM 32=SEGSYM 64=3DCTXT] \n");
fprintf(stdout," Indicate multiple modes by adding their values. \n");
fprintf(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
fprintf(stdout,"\n");
fprintf(stdout,"-D : define DC offset (-D 12) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n");
fprintf(stdout," for component c=%%d [%%d = 0,1,2]\n");
fprintf(stdout," with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-d : offset of the origin of the volume (-d 150,300,100) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-l : offset of the origin of the tiles (-l 100,75,25) \n");
fprintf(stdout,"\n");
fprintf(stdout,"\n");
fprintf(stdout,"DEFAULT CODING:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");
fprintf(stdout," * Lossless\n");
fprintf(stdout," * 1 tile\n");
fprintf(stdout," * Size of precinct : 2^15 x 2^15 x 2^15 (means 1 precinct)\n");
fprintf(stdout," * Size of code-block : 64 x 64 x 64\n");
fprintf(stdout," * Number of resolutions in x, y and z axis: 3\n");
fprintf(stdout," * No SOP marker in the codestream\n");
fprintf(stdout," * No EPH marker in the codestream\n");
fprintf(stdout," * No sub-sampling in x, y or z direction\n");
fprintf(stdout," * No mode switch activated\n");
fprintf(stdout," * Progression order: LRCP\n");
fprintf(stdout," * No index file\n");
fprintf(stdout," * No ROI upshifted\n");
fprintf(stdout," * No offset of the origin of the volume\n");
fprintf(stdout," * No offset of the origin of the tiles\n");
fprintf(stdout," * Reversible DWT 5-3 on each 2D slice\n");
fprintf(stdout," * Coding algorithm: 2D-EBCOT \n");
fprintf(stdout,"\n");
fprintf(stdout,"REMARKS:\n");
fprintf(stdout,"---------\n");
fprintf(stdout,"\n");
fprintf(stdout,"- The markers written to the main_header are : SOC SIZ COD QCD COM.\n");
fprintf(stdout,"- COD and QCD markers will never appear in the tile_header.\n");
fprintf(stdout,"\n");
fprintf(stdout,"- You need enough disk space memory (twice the original) to encode \n");
fprintf(stdout,"the volume,i.e. for a 1.5 GB volume you need a minimum of 3GB of disk memory)\n");
fprintf(stdout,"\n");
fprintf(stdout,"- When loading *.pgx files, a relative path to directory is needed for input argument \n");
fprintf(stdout," followed by the common prefix of the slices and a '*' character representing sequential numeration.\n");
fprintf(stdout,"( -i relativepath/slices*.pgx )\n");
fprintf(stdout,"\n");
fprintf(stdout," - The index file has the structure below:\n");
fprintf(stdout,"\n");
fprintf(stdout,"\t Image_height Image_width Image_depth\n");
fprintf(stdout,"\t Progression order: 0 (LRCP)\n");
fprintf(stdout,"\t Tiles_size_X Tiles_size_Y Tiles_size_Z\n");
fprintf(stdout,"\t Components_nb\n");
fprintf(stdout,"\t Layers_nb\n");
fprintf(stdout,"\t Decomposition_levels\n");
fprintf(stdout,"\t [Precincts_size_X_res_Nr Precincts_size_Y_res_Nr Precincts_size_Z_res_Nr]\n\t ...\n");
fprintf(stdout,"\t [Precincts_size_X_res_0 Precincts_size_Y_res_0 Precincts_size_Z_res_0]\n");
fprintf(stdout,"\t Main_header_end_position\n");
fprintf(stdout,"\t Codestream_size\n");
fprintf(stdout,"\t Tile_0 [start_pos end_header end_pos TotalDisto NumPix MaxMSE]\n");
fprintf(stdout,"\t ...\n");
fprintf(stdout,"\t Tile_Nt [ '' '' '' '' '' '' ]\n");
fprintf(stdout,"\t Tpacket_0 [Tile layer res. comp. prec. start_pos end_pos disto]\n");
fprintf(stdout,"\t ...\n");
fprintf(stdout,"\t Tpacket_Np ['' '' '' '' '' '' '' '' ]\n");
fprintf(stdout,"\t MaxDisto\n");
fprintf(stdout,"\t TotalDisto\n\n");
fprintf(stdout,"\n");
}
OPJ_PROG_ORDER give_progression(char progression[4]) {
if(strncmp(progression, "LRCP", 4) == 0) {
return LRCP;
}
if(strncmp(progression, "RLCP", 4) == 0) {
return RLCP;
}
if(strncmp(progression, "RPCL", 4) == 0) {
return RPCL;
}
if(strncmp(progression, "PCRL", 4) == 0) {
return PCRL;
}
if(strncmp(progression, "CPRL", 4) == 0) {
return CPRL;
}
return PROG_UNKNOWN;
}
OPJ_TRANSFORM give_transform(char transform[4]) {
if(strncmp(transform, "2DWT", 4) == 0) {
return TRF_2D_DWT;
}
if(strncmp(transform, "3DWT", 4) == 0) {
return TRF_3D_DWT;
}
return TRF_UNKNOWN;
}
OPJ_ENTROPY_CODING give_coding(char coding[3]) {
if(strncmp(coding, "2EB", 3) == 0) {
return ENCOD_2EB;
}
if(strncmp(coding, "3EB", 3) == 0) {
return ENCOD_3EB;
}
/*if(strncmp(coding, "2GR", 3) == 0) {
return ENCOD_2GR;
}
if(strncmp(coding, "3GR", 3) == 0) {
return ENCOD_3GR;
}*/
return ENCOD_UNKNOWN;
}
int get_file_format(char *filename) {
int i;
static const char *extension[] = {"pgx", "bin", "img", "j3d", "jp3d", "j2k"};
static const int format[] = { PGX_DFMT, BIN_DFMT, IMG_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT};
char * ext = strrchr(filename, '.');
if (ext) {
ext++;
for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
if(strnicmp(ext, extension[i], 3) == 0) {
return format[i];
}
}
}
return -1;
}
/* ------------------------------------------------------------------------------------ */
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) {
int i, value;
/* parse the command line */
while (1) {
int c = opj_getopt(argc, argv, "i:m:o:r:q:f:t:n:c:b:x:p:s:d:hP:S:E:M:D:R:l:T:C:A:I");
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case PGX_DFMT:
case BIN_DFMT:
case IMG_DFMT:
break;
default:
fprintf(stdout, "[ERROR] Unrecognized format for infile : %s [accept only *.pgx or *.bin] !!\n\n", infile);
return 1;
break;
}
strncpy(parameters->infile, infile, MAX_PATH);
fprintf(stdout, "[INFO] Infile: %s \n", parameters->infile);
}
break;
/* ----------------------------------------------------- */
case 'm': /* input IMG file */
{
char *imgfile = opj_optarg;
int imgformat = get_file_format(imgfile);
switch(imgformat) {
case IMG_DFMT:
break;
default:
fprintf(stdout, "[ERROR] Unrecognized format for imgfile : %s [accept only *.img] !!\n\n", imgfile);
return 1;
break;
}
strncpy(parameters->imgfile, imgfile, MAX_PATH);
fprintf(stdout, "[INFO] Imgfile: %s Format: %d\n", parameters->imgfile, imgformat);
}
break;
/* ----------------------------------------------------- */
case 'o': /* output file */
{
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case J3D_CFMT:
case J2K_CFMT:
case LSE_CFMT:
break;
default:
fprintf(stdout, "[ERROR] Unknown output format volume %s [only *.j2k, *.lse3d or *.jp3d]!! \n", outfile);
return 1;
break;
}
strncpy(parameters->outfile, outfile, MAX_PATH);
fprintf(stdout, "[INFO] Outfile: %s \n", parameters->outfile);
}
break;
/* ----------------------------------------------------- */
case 'r': /* define compression rates for each layer */
{
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
while (*s && *s != ',') {
s++;
}
if (!*s)
break;
s++;
}
parameters->cp_disto_alloc = 1;
}
break;
/* ----------------------------------------------------- */
case 'q': /* define distorsion (PSNR) for each layer */
{
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
while (*s && *s != ',') {
s++;
}
if (!*s)
break;
s++;
}
parameters->cp_fixed_quality = 1;
}
break;
/* ----------------------------------------------------- */
case 'f':
{
fprintf(stdout, "/---------------------------------------------------\\\n");
fprintf(stdout, "| Fixed layer allocation option not implemented !! |\n");
fprintf(stdout, "\\---------------------------------------------------/\n");
/*int *row = NULL, *col = NULL;
int numlayers = 0, matrix_width = 0;
char *s = opj_optarg;
sscanf(s, "%d", &numlayers);
s++;
if (numlayers > 9)
s++;
parameters->tcp_numlayers = numlayers;
matrix_width = parameters->numresolution[0] + parameters->numresolution[1] + parameters->numresolution[2];
parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
s = s + 2;
for (i = 0; i < numlayers; i++) {
row = &parameters->cp_matrice[i * matrix_width];
col = row;
parameters->tcp_rates[i] = 1;
sscanf(s, "%d,", &col[0]);
s += 2;
if (col[0] > 9)
s++;
col[1] = 0;
col[2] = 0;
for (j = 1; j < matrix_width; j++) {
col += 3; j+=2;
sscanf(s, "%d,%d,%d", &col[0], &col[1], &col[2]);
s += 6;
if (col[0] > 9)
s++;
if (col[1] > 9)
s++;
if (col[2] > 9)
s++;
}
if (i < numlayers - 1)
s++;
}
parameters->cp_fixed_alloc = 1; */
}
break;
/* ----------------------------------------------------- */
case 't': /* tiles */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tdx, &parameters->cp_tdy, &parameters->cp_tdz) !=3) {
fprintf(stdout, "[ERROR] '-t' 'dimensions of tiles' argument error ! [-t tdx,tdy,tdz]\n");
return 1;
}
parameters->tile_size_on = true;
}
break;
/* ----------------------------------------------------- */
case 'n': /* resolution */
{
int aux;
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->numresolution[0], &parameters->numresolution[1], &parameters->numresolution[2]);
if (aux == 2)
parameters->numresolution[2] = 1;
else if (aux == 1) {
parameters->numresolution[1] = parameters->numresolution[0];
parameters->numresolution[2] = 1;
}else if (aux == 0){
parameters->numresolution[0] = 1;
parameters->numresolution[1] = 1;
parameters->numresolution[2] = 1;
}
}
break;
/* ----------------------------------------------------- */
case 'c': /* precinct dimension */
{
char sep;
int res_spec = 0;
int aux;
char *s = opj_optarg;
do {
sep = 0;
aux = sscanf(s, "[%d,%d,%d]%c", &parameters->prct_init[0][res_spec], &parameters->prct_init[1][res_spec], &parameters->prct_init[2][res_spec], &sep);
if (sep == ',' && aux != 4) {
fprintf(stdout, "[ERROR] '-c' 'dimensions of precincts' argument error ! [-c [prcx_res0,prcy_res0,prcz_res0],...,[prcx_resN,prcy_resN,prcz_resN]]\n");
return 1;
}
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
}
while (sep == ',');
parameters->res_spec = res_spec; /* number of precinct size specifications */
}
break;
/* ----------------------------------------------------- */
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0, cblockl_init = 0;
if (sscanf(opj_optarg, "%d,%d,%d", &cblockw_init, &cblockh_init, &cblockl_init) != 3) {
fprintf(stdout, "[ERROR] '-b' 'dimensions of codeblocks' argument error ! [-b cblkx,cblky,cblkz]\n");
return 1;
}
if (cblockw_init * cblockh_init * cblockl_init > (1<<18) || cblockw_init > 1024 || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4 || cblockl_init > 1024 || cblockl_init < 4) {
fprintf(stdout,"[ERROR] Size of code_block error (option -b) !!\n\nRestriction :\n * width*height*length<=4096\n * 4<=width,height,length<= 1024\n\n");
return 1;
}
parameters->cblock_init[0] = cblockw_init;
parameters->cblock_init[1] = cblockh_init;
parameters->cblock_init[2] = cblockl_init;
}
break;
/* ----------------------------------------------------- */
case 'x': /* creation of index file */
{
char *index = opj_optarg;
strncpy(parameters->index, index, MAX_PATH);
parameters->index_on = 1;
}
break;
/* ----------------------------------------------------- */
case 'p': /* progression order */
{
char progression[4];
strncpy(progression, opj_optarg, 4);
parameters->prog_order = give_progression(progression);
if (parameters->prog_order == -1) {
fprintf(stdout, "[ERROR] Unrecognized progression order [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->subsampling_dx, &parameters->subsampling_dy, &parameters->subsampling_dz) != 3) {
fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->volume_offset_x0, &parameters->volume_offset_y0, &parameters->volume_offset_z0) != 3) {
fprintf(stdout, "[ERROR] -d 'coordonnate of the reference grid' argument error !! [-d x0,y0,z0]\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 'h': /* display an help description */
{
encode_help_display();
return 1;
}
break;
/* ----------------------------------------------------- */
case 'P': /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
char *s = opj_optarg;
POC = parameters->POC;
fprintf(stdout, "/----------------------------------\\\n");
fprintf(stdout, "| POC option not fully tested !! |\n");
fprintf(stdout, "\\----------------------------------/\n");
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%s", &POC[numpocs].tile,
&POC[numpocs].resno0, &POC[numpocs].compno0,
&POC[numpocs].layno1, &POC[numpocs].resno1,
&POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
POC[numpocs].prg = give_progression(POC[numpocs].progorder);
/* POC[numpocs].tile; */
numpocs++;
while (*s && *s != '/') {
s++;
}
if (!*s) {
break;
}
s++;
}
parameters->numpocs = numpocs;
}
break;
/* ------------------------------------------------------ */
case 'S': /* SOP marker */
{
parameters->csty |= 0x02;
}
break;
/* ------------------------------------------------------ */
case 'E': /* EPH marker */
{
parameters->csty |= 0x04;
}
break;
/* ------------------------------------------------------ */
case 'M': /* Codification mode switch */
{
fprintf(stdout, "[INFO] Mode switch option not fully tested !!\n");
value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 6; i++) {
int cache = value & (1 << i);
if (cache)
parameters->mode |= (1 << i);
}
}
}
break;
/* ------------------------------------------------------ */
case 'D': /* DCO */
{
if (sscanf(opj_optarg, "%d", &parameters->dcoffset) != 1) {
fprintf(stdout, "[ERROR] DC offset error !! [-D %d]\n",parameters->dcoffset);
return 1;
}
}
break;
/* ------------------------------------------------------ */
case 'R': /* ROI */
{
if (sscanf(opj_optarg, "OI:c=%d,U=%d", &parameters->roi_compno, &parameters->roi_shift) != 2) {
fprintf(stdout, "[ERROR] ROI error !! [-ROI:c='compno',U='shift']\n");
return 1;
}
}
break;
/* ------------------------------------------------------ */
case 'l': /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tx0, &parameters->cp_ty0, &parameters->cp_tz0) != 3) {
fprintf(stdout, "[ERROR] -l 'tile offset' argument error !! [-l X0,Y0,Z0]");
return 1;
}
}
break;
/* ------------------------------------------------------
case 'T': // Tranformation of original data (2D-DWT/3D-DWT/3D-RLS/2D-DWT+1D-RLS)
{
char transform[4];
strncpy(transform, opj_optarg, 4);
parameters->transform_format = give_transform(transform);
if (parameters->transform_format == -1) {
fprintf(stdout, "[ERROR] -T 'Transform domain' argument error !! [-T 2DWT, 3DWT, 3RLS or 3LSE only]");
return 1;
}
}
break;
------------------------------------------------------ */
case 'C': /* Coding of transformed data */
{
char coding[3];
strncpy(coding, opj_optarg, 3);
parameters->encoding_format = give_coding(coding);
if (parameters->encoding_format == -1) {
fprintf(stdout, "[ERROR] -C 'Coding algorithm' argument error !! [-C 2EB, 3EB, 2GR, 3GR or GRI only]");
return 1;
}
}
break;
/* ------------------------------------------------------ */
case 'I': /* reversible or not */
{
parameters->irreversible = 1;
}
break;
default:
fprintf(stdout, "[ERROR] This option is not valid \"-%c %s\"\n", c, opj_optarg);
return 1;
}
}
/* check for possible errors */
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stdout, "usage: jp3d_vm_enc -i volume-file -o jp3d-file (+ options)\n");
return 1;
}
if((parameters->decod_format == BIN_DFMT) && (parameters->imgfile[0] == 0)) {
fprintf(stdout, "usage: jp3d_vm_enc -i bin-volume-file -m img-file -o jp3d-file (+ options)\n");
return 1;
}
if((parameters->decod_format != BIN_DFMT) && (parameters->decod_format != PGX_DFMT) && (parameters->decod_format != IMG_DFMT)) {
fprintf(stdout, "usage: jp3d_vm_enc -i input-volume-file [*.bin,*.pgx,*.img] -o jp3d-file [*.jp3d,*.j2k] (+ options)\n");
return 1;
}
if((parameters->cod_format != J3D_CFMT) && (parameters->cod_format != J2K_CFMT)) {
fprintf(stdout, "usage: jp3d_vm_enc -i input-volume-file [*.bin,*.pgx,*.img] -o jp3d-file [*.jp3d,*.j2k] (+ options)\n");
return 1;
}
if((parameters->encoding_format == ENCOD_2GR || parameters->encoding_format == ENCOD_3GR) && parameters->transform_format != TRF_3D_LSE && parameters->transform_format != TRF_3D_RLS) {
fprintf(stdout, "[ERROR] Entropy coding options -C [2GR,3GR] are only compatible with predictive-based transform algorithms: -T [3RLS,3LSE].\n");
return 1;
}
if (parameters->encoding_format == ENCOD_3EB)
parameters->mode |= (1 << 6);
if ((parameters->mode >> 6) & 1) {
parameters->encoding_format = ENCOD_3EB;
}
if((parameters->numresolution[2] == 0 || (parameters->numresolution[1] == 0) || (parameters->numresolution[0] == 0))) {
fprintf(stdout, "[ERROR] -n 'resolution levels' argument error ! Resolutions must be greater than 1 in order to perform DWT.\n");
return 1;
}
if (parameters->numresolution[1] != parameters->numresolution[0]) {
fprintf(stdout, "[ERROR] -n 'resolution levels' argument error ! Resolutions in X and Y axis must be the same in this implementation.\n");
return 1;
}
if (parameters->numresolution[2] > parameters->numresolution[0]) {
fprintf(stdout, "[ERROR] -n 'resolution levels' argument error ! Resolutions in Z axis must be lower than in X-Y axis.\n");
return 1;
}
if (parameters->dcoffset >= 128 && parameters->dcoffset <= -128) {
fprintf(stdout, "[ERROR] -D 'DC offset' argument error ! Value must be -128<=DCO<=128.\n");
return 1;
}
if(parameters->numresolution[2] != 1) {
parameters->transform_format = TRF_3D_DWT;
/*fprintf(stdout, "[Warning] Resolution level in axial dim > 1 : 3D-DWT will be performed... \n");*/
} else if (parameters->numresolution[2] == 1) {
parameters->transform_format = TRF_2D_DWT;
/*fprintf(stdout, "[Warning] Resolution level in axial dim == 1 : 2D-DWT will be performed... \n");*/
}
if ((parameters->cod_format == J2K_CFMT) && (parameters->transform_format != TRF_2D_DWT || parameters->encoding_format != ENCOD_2EB)) {
fprintf(stdout, "[WARNING] Incompatible options -o *.j2k and defined transform or encoding algorithm. Latter will be ignored\n");
parameters->transform_format = TRF_2D_DWT;
parameters->encoding_format = ENCOD_2EB;
}
if ((parameters->cp_disto_alloc || parameters->cp_fixed_alloc || parameters->cp_fixed_quality) && (!(parameters->cp_disto_alloc ^ parameters->cp_fixed_quality))) {
fprintf(stdout, "[ERROR] Options -r and -q cannot be used together !!\n");
return 1;
} /* mod fixed_quality */
/* if no rate entered, lossless by default */
if (parameters->tcp_numlayers == 0) {
parameters->tcp_rates[0] = 0.0; /* MOD antonin : losslessbug */
parameters->tcp_numlayers++;
parameters->cp_disto_alloc = 1;
}
if((parameters->cp_tx0 > parameters->volume_offset_x0) || (parameters->cp_ty0 > parameters->volume_offset_y0) || (parameters->cp_tz0 > parameters->volume_offset_z0)) {
fprintf(stdout, "[ERROR] Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) TZO(%d)<=IMG_Z0(%d)\n",
parameters->cp_tx0, parameters->volume_offset_x0, parameters->cp_ty0, parameters->volume_offset_y0,
parameters->cp_tz0, parameters->volume_offset_z0);
return 1;
}
for (i = 0; i < parameters->numpocs; i++) {
if (parameters->POC[i].prg == -1) {
fprintf(stdout,"[ERROR] Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n",i + 1);
}
}
return 0;
}
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
bool bSuccess;
bool delete_comment = true;
opj_cparameters_t parameters; /* compression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_volume_t *volume = NULL;
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters);
/* parse input and get user encoding parameters */
if(parse_cmdline_encoder(argc, argv, &parameters) == 1) {
return 0;
}
if(parameters.cp_comment == NULL) {
parameters.cp_comment = "Created by OpenJPEG version JP3D";
/* no need to delete parameters.cp_comment on exit */
delete_comment = false;
}
/* encode the destination volume */
/* ---------------------------- */
if (parameters.cod_format == J3D_CFMT || parameters.cod_format == J2K_CFMT) {
int codestream_length, pixels, bitsin;
opj_cio_t *cio = NULL;
FILE *f = NULL;
opj_cinfo_t* cinfo = NULL;
/* decode the source volume */
/* ----------------------- */
switch (parameters.decod_format) {
case PGX_DFMT:
fprintf(stdout, "[INFO] Loading pgx file(s)\n");
volume = pgxtovolume(parameters.infile, &parameters);
if (!volume) {
fprintf(stdout, "[ERROR] Unable to load pgx files\n");
return 1;
}
break;
case BIN_DFMT:
fprintf(stdout, "[INFO] Loading bin file\n");
volume = bintovolume(parameters.infile, parameters.imgfile, &parameters);
if (!volume) {
fprintf(stdout, "[ERROR] Unable to load bin file\n");
return 1;
}
break;
case IMG_DFMT:
fprintf(stdout, "[INFO] Loading img file\n");
volume = imgtovolume(parameters.infile, &parameters);
if (!volume) {
fprintf(stderr, "[ERROR] Unable to load img file\n");
return 1;
}
break;
}
/* get a JP3D or J2K compressor handle */
if (parameters.cod_format == J3D_CFMT)
cinfo = opj_create_compress(CODEC_J3D);
else if (parameters.cod_format == J2K_CFMT)
cinfo = opj_create_compress(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stdout);
/* setup the encoder parameters using the current volume and using user parameters */
opj_setup_encoder(cinfo, &parameters, volume);
/* open a byte stream for writing */
/* allocate memory for all tiles */
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the volume */
/*fprintf(stdout, "[INFO] Encode the volume\n");*/
bSuccess = opj_encode(cinfo, cio, volume, parameters.index);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stdout, "[ERROR] Failed to encode volume\n");
return 1;
}
codestream_length = cio_tell(cio);
pixels =(volume->x1 - volume->x0) * (volume->y1 - volume->y0) * (volume->z1 - volume->z0);
bitsin = pixels * volume->comps[0].prec;
fprintf(stdout, "[RESULT] Volume: %d x %d x %d (x %d bpv)\n Codestream: %d B, Ratio: %5.3f bpv, (%5.3f : 1) \n",
(volume->x1 - volume->x0),(volume->y1 - volume->y0),(volume->z1 - volume->z0),volume->comps[0].prec,
codestream_length, ((double)codestream_length * 8.0/(double)pixels), ((double)bitsin/(8.0*(double)codestream_length)));
/* write the buffer to disk */
f = fopen(parameters.outfile, "wb");
if (!f) {
fprintf(stdout, "[ERROR] Failed to open %s for writing\n", parameters.outfile);
return 1;
}
fwrite(cio->buffer, 1, codestream_length, f);
fclose(f);
/* close and free the byte stream */
opj_cio_close(cio);
/* free remaining compression structures */
opj_destroy_compress(cinfo);
} else {
fprintf(stdout, "[ERROR] Cod_format != JP3d !!! \n");
return 1;
}
/* free user parameters structure */
if(delete_comment) {
if(parameters.cp_comment) free(parameters.cp_comment);
}
if(parameters.cp_matrice) free(parameters.cp_matrice);
/* free volume data */
opj_volume_destroy(volume);
return 0;
}

View File

@ -0,0 +1,542 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "opj_config.h"
#include "openjp3d.h"
#include "opj_getopt.h"
#include "convert.h"
#ifdef _WIN32
#include <windows.h>
#else
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif /* _WIN32 */
/* ----------------------------------------------------------------------- */
static double calc_PSNR(opj_volume_t *original, opj_volume_t *decoded)
{
int max, i, k, compno = 0, size;
double sum, total = 0;
int global = 1;
max = (original->comps[compno].prec <= 8) ? 255 : (1 << original->comps[compno].prec) - 1;
if (global) {
size = (original->x1 - original->x0) * (original->y1 - original->y0) * (original->z1 - original->z0);
for (compno = 0; compno < original->numcomps; compno++) {
for(sum = 0, i = 0; i < size; ++i) {
if ((decoded->comps[compno].data[i] < 0) || (decoded->comps[compno].data[i] > max))
fprintf(stdout,"[WARNING] Data out of range during PSNR computing...\n");
else
sum += (original->comps[compno].data[i] - decoded->comps[compno].data[i]) * (original->comps[compno].data[i] - decoded->comps[compno].data[i]);
}
}
sum /= size;
total = ((sum==0.0) ? 0.0 : 10 * log10(max * max / sum));
} else {
size = (original->x1 - original->x0) * (original->y1 - original->y0);
for (k = 0; k < original->z1 - original->z0; k++) {
int offset = k * size;
for (sum = 0, compno = 0; compno < original->numcomps; compno++) {
for(i = 0; i < size; ++i) {
if ((decoded->comps[compno].data[i + offset] < 0) || (decoded->comps[compno].data[i + offset] > max))
fprintf(stdout,"[WARNING] Data out of range during PSNR computing...\n");
else
sum += (original->comps[compno].data[i + offset] - decoded->comps[compno].data[i + offset]) * (original->comps[compno].data[i + offset] - decoded->comps[compno].data[i + offset]);
}
}
sum /= size;
total = total + ((sum==0.0) ? 0.0 : 10 * log10(max * max / sum));
}
}
if(total == 0) /* perfect reconstruction, PSNR should return infinity */
return -1.0;
return total;
/*return 20 * log10((max - 1) / sqrt(sum));*/
}
static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
{
int max, i, compno = 0, size, sizeM;
double sum;
double mux = 0.0, muy = 0.0, sigmax = 0.0, sigmay = 0.0,
sigmaxy = 0.0/*, structx = 0.0, structy = 0.0*/;
double lcomp,ccomp,scomp;
double C1,C2,C3;
max = (original->comps[compno].prec <= 8) ? 255 : (1 << original->comps[compno].prec) - 1;
size = (original->x1 - original->x0) * (original->y1 - original->y0) * (original->z1 - original->z0);
/*MSSIM*/
/* sizeM = size / (original->z1 - original->z0);*/
sizeM = size;
for(sum = 0, i = 0; i < sizeM; ++i) {
/* First, the luminance of each signal is compared.*/
mux += original->comps[compno].data[i];
muy += decoded->comps[compno].data[i];
}
mux /= sizeM;
muy /= sizeM;
/*We use the standard deviation (the square root of variance) as an estimate of the signal contrast.*/
for(sum = 0, i = 0; i < sizeM; ++i) {
/* First, the luminance of each signal is compared.*/
sigmax += (original->comps[compno].data[i] - mux) * (original->comps[compno].data[i] - mux);
sigmay += (decoded->comps[compno].data[i] - muy) * (decoded->comps[compno].data[i] - muy);
sigmaxy += (original->comps[compno].data[i] - mux) * (decoded->comps[compno].data[i] - muy);
}
sigmax /= sizeM - 1;
sigmay /= sizeM - 1;
sigmaxy /= sizeM - 1;
sigmax = sqrt(sigmax);
sigmay = sqrt(sigmay);
sigmaxy = sqrt(sigmaxy);
/*Third, the signal is normalized (divided) by its own standard deviation, */
/*so that the two signals being compared have unit standard deviation.*/
/*Luminance comparison*/
C1 = (0.01 * max) * (0.01 * max);
lcomp = ((2 * mux * muy) + C1)/((mux*mux) + (muy*mux) + C1);
/*Constrast comparison*/
C2 = (0.03 * max) * (0.03 * max);
ccomp = ((2 * sigmax * sigmay) + C2)/((sigmax*sigmax) + (sigmay*sigmay) + C2);
/*Structure comparison*/
C3 = C2 / 2;
scomp = (sigmaxy + C3) / (sigmax * sigmay + C3);
/*Similarity measure*/
sum = lcomp * ccomp * scomp;
return sum;
}
void decode_help_display() {
fprintf(stdout,"HELP\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
fprintf(stdout,"List of parameters for the JPEG 2000 encoder:\n");
fprintf(stdout,"\n");
fprintf(stdout," Required arguments \n");
fprintf(stdout," ---------------------------- \n");
fprintf(stdout," -i <compressed file> ( *.jp3d, *.j3d )\n");
fprintf(stdout," Currently accepts J3D-files. The file type is identified based on its suffix.\n");
fprintf(stdout," -o <decompressed file> ( *.pgx, *.bin )\n");
fprintf(stdout," Currently accepts PGX-files and BIN-files. Binary data is written to the file (not ascii). \n");
fprintf(stdout," If a PGX filename is given, there will be as many output files as slices; \n");
fprintf(stdout," an indice starting from 0 will then be appended to the output filename,\n");
fprintf(stdout," just before the \"pgx\" extension.\n");
fprintf(stdout," -m <characteristics file> ( *.img ) \n");
fprintf(stdout," Required only for BIN-files. Ascii data of volume characteristics is written. \n");
fprintf(stdout,"\n");
fprintf(stdout," Optional \n");
fprintf(stdout," ---------------------------- \n");
fprintf(stdout," -h \n ");
fprintf(stdout," Display the help information\n");
fprintf(stdout," -r <RFx,RFy,RFz>\n");
fprintf(stdout," Set the number of highest resolution levels to be discarded on each dimension. \n");
fprintf(stdout," The volume resolution is effectively divided by 2 to the power of the\n");
fprintf(stdout," number of discarded levels. The reduce factor is limited by the\n");
fprintf(stdout," smallest total number of decomposition levels among tiles.\n");
fprintf(stdout," -l <number of quality layers to decode>\n");
fprintf(stdout," Set the maximum number of quality layers to decode. If there are\n");
fprintf(stdout," less quality layers than the specified number, all the quality layers\n");
fprintf(stdout," are decoded. \n");
fprintf(stdout," -O original-file \n");
fprintf(stdout," This option offers the possibility to compute some quality results \n");
fprintf(stdout," for the decompressed volume, like the PSNR value achieved or the global SSIM value. \n");
fprintf(stdout," Needs the original file in order to compare with the new one.\n");
fprintf(stdout," NOTE: Only valid when -r option is 0,0,0 (both original and decompressed volumes have same resolutions) \n");
fprintf(stdout," NOTE: If original file is .BIN file, the volume characteristics file shall be defined with the -m option. \n");
fprintf(stdout," (i.e. -O original-BIN-file -m original-IMG-file) \n");
fprintf(stdout," -BE \n");
fprintf(stdout," Define that the recovered volume data will be saved with big endian byte order.\n");
fprintf(stdout," By default, little endian byte order is used.\n");
fprintf(stdout,"\n");
}
/* -------------------------------------------------------------------------- */
int get_file_format(char *filename) {
int i;
static const char *extension[] = {"pgx", "bin", "j3d", "jp3d", "j2k", "img"};
static const int format[] = { PGX_DFMT, BIN_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT, IMG_DFMT};
char * ext = strrchr(filename, '.');
if(ext) {
ext++;
for(i = 0; i < sizeof(format) / sizeof(format[0]); i++) {
if(strnicmp(ext, extension[i], 3) == 0) {
return format[i];
}
}
}
return -1;
}
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters) {
/* parse the command line */
while (1) {
int c = opj_getopt(argc, argv, "i:o:O:r:l:B:m:h");
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case J3D_CFMT:
case J2K_CFMT:
break;
default:
fprintf(stdout, "[ERROR] Unknown format for infile %s [only *.j3d]!! \n", infile);
return 1;
break;
}
strncpy(parameters->infile, infile, MAX_PATH);
fprintf(stdout, "[INFO] Infile: %s \n", parameters->infile);
}
break;
case 'm': /* img file */
{
char *imgfile = opj_optarg;
int imgformat = get_file_format(imgfile);
switch(imgformat) {
case IMG_DFMT:
break;
default:
fprintf(stdout, "[ERROR] Unrecognized format for imgfile : %s [accept only *.img] !!\n\n", imgfile);
return 1;
break;
}
strncpy(parameters->imgfile, imgfile, MAX_PATH);
fprintf(stdout, "[INFO] Imgfile: %s Format: %d\n", parameters->imgfile, imgformat);
}
break;
/* ----------------------------------------------------- */
case 'o': /* output file */
{
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case PGX_DFMT:
case BIN_DFMT:
break;
default:
fprintf(stdout, "[ERROR] Unrecognized format for outfile : %s [accept only *.pgx or *.bin] !!\n\n", outfile);
return 1;
break;
}
strncpy(parameters->outfile, outfile, MAX_PATH);
fprintf(stdout, "[INFO] Outfile: %s \n", parameters->outfile);
}
break;
/* ----------------------------------------------------- */
case 'O': /* Original image for PSNR computing */
{
char *original = opj_optarg;
parameters->orig_format = get_file_format(original);
switch(parameters->orig_format) {
case PGX_DFMT:
case BIN_DFMT:
break;
default:
fprintf(stdout, "[ERROR] Unrecognized format for original file : %s [accept only *.pgx or *.bin] !!\n\n", original);
return 1;
break;
}
strncpy(parameters->original, original, MAX_PATH);
fprintf(stdout, "[INFO] Original file: %s \n", parameters->original);
}
break;
/* ----------------------------------------------------- */
case 'r': /* reduce option */
{
/*sscanf(opj_optarg, "%d, %d, %d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);*/
int aux;
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);
if (aux == 2)
parameters->cp_reduce[2] = 0;
else if (aux == 1) {
parameters->cp_reduce[1] = parameters->cp_reduce[0];
parameters->cp_reduce[2] = 0;
}else if (aux == 0){
parameters->cp_reduce[0] = 0;
parameters->cp_reduce[1] = 0;
parameters->cp_reduce[2] = 0;
}
}
break;
/* ----------------------------------------------------- */
case 'l': /* layering option */
{
sscanf(opj_optarg, "%d", &parameters->cp_layer);
}
break;
/* ----------------------------------------------------- */
case 'B': /* BIGENDIAN vs. LITTLEENDIAN */
{
parameters->bigendian = 1;
}
break;
/* ----------------------------------------------------- */
case 'L': /* BIGENDIAN vs. LITTLEENDIAN */
{
parameters->decod_format = LSE_CFMT;
}
break;
/* ----------------------------------------------------- */
case 'h': /* display an help description */
{
decode_help_display();
return 1;
}
break;
/* ----------------------------------------------------- */
default:
fprintf(stdout,"[WARNING] This option is not valid \"-%c %s\"\n",c, opj_optarg);
break;
}
}
/* check for possible errors */
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stdout,"[ERROR] At least one required argument is missing\n Check jp3d_to_volume -help for usage information\n");
return 1;
}
return 0;
}
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting no client object
*/
void info_callback(const char *msg, void *client_data) {
fprintf(stdout, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_volume_t *volume = NULL;
opj_volume_t *original = NULL;
opj_cparameters_t cparameters; /* original parameters */
FILE *fsrc = NULL;
unsigned char *src = NULL;
int file_length;
int decodeok;
double psnr, ssim;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL;
/* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* parse input and get user decoding parameters */
strcpy(parameters.original,"NULL");
strcpy(parameters.imgfile,"NULL");
if(parse_cmdline_decoder(argc, argv, &parameters) == 1) {
return 0;
}
/* read the input file and put it in memory */
/* ---------------------------------------- */
fprintf(stdout, "[INFO] Loading %s file \n",parameters.decod_format==J3D_CFMT ? ".jp3d" : ".j2k");
fsrc = fopen(parameters.infile, "rb");
if (!fsrc) {
fprintf(stdout, "[ERROR] Failed to open %s for reading\n", parameters.infile);
return 1;
}
fseek(fsrc, 0, SEEK_END);
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length);
fread(src, 1, file_length, fsrc);
fclose(fsrc);
/* decode the code-stream */
/* ---------------------- */
if (parameters.decod_format == J3D_CFMT || parameters.decod_format == J2K_CFMT) {
/* get a JP3D or J2K decoder handle */
if (parameters.decod_format == J3D_CFMT)
dinfo = opj_create_decompress(CODEC_J3D);
else if (parameters.decod_format == J2K_CFMT)
dinfo = opj_create_decompress(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the volume structure */
volume = opj_decode(dinfo, cio);
if(!volume) {
fprintf(stdout, "[ERROR] jp3d_to_volume: failed to decode volume!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
}
/* free the memory containing the code-stream */
free(src);
src = NULL;
/* create output volume */
/* ------------------- */
switch (parameters.cod_format) {
case PGX_DFMT: /* PGX */
decodeok = volumetopgx(volume, parameters.outfile);
if (decodeok)
fprintf(stdout,"[ERROR] Unable to write decoded volume into pgx files\n");
break;
case BIN_DFMT: /* BMP */
decodeok = volumetobin(volume, parameters.outfile);
if (decodeok)
fprintf(stdout,"[ERROR] Unable to write decoded volume into pgx files\n");
break;
}
switch (parameters.orig_format) {
case PGX_DFMT: /* PGX */
if (strcmp("NULL",parameters.original) != 0){
fprintf(stdout,"Loading original file %s \n",parameters.original);
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0;
original = pgxtovolume(parameters.original,&cparameters);
}
break;
case BIN_DFMT: /* BMP */
if (strcmp("NULL",parameters.original) != 0 && strcmp("NULL",parameters.imgfile) != 0){
fprintf(stdout,"Loading original file %s %s\n",parameters.original,parameters.imgfile);
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0;
original = bintovolume(parameters.original,parameters.imgfile,&cparameters);
}
break;
}
fprintf(stdout, "[RESULT] Volume: %d x %d x %d (x %d bpv)\n ",
(volume->comps[0].w >> volume->comps[0].factor[0]),
(volume->comps[0].h >> volume->comps[0].factor[1]),
(volume->comps[0].l >> volume->comps[0].factor[2]),
volume->comps[0].prec);
if(original){
psnr = calc_PSNR(original,volume);
ssim = calc_SSIM(original,volume);
if (psnr < 0.0)
fprintf(stdout, " PSNR: Inf , SSMI %f -- Perfect reconstruction!\n",ssim);
else
fprintf(stdout, " PSNR: %f , SSIM %f \n",psnr,ssim);
}
/* free remaining structures */
if(dinfo) {
opj_destroy_decompress(dinfo);
}
/* free volume data structure */
opj_volume_destroy(volume);
return 0;
}

View File

@ -0,0 +1,115 @@
#!/bin/sh
# The next line is executed by /bin/sh, but not tcl \
exec wish "$0" ${1+"$@"}
lappend auto_path /usr/share/tcltk/bwidget1.9.2
namespace eval jp3dVM {
variable _progress 0
variable _afterid ""
variable _status "Compute in progress..."
variable notebook
variable mainframe
variable dataout "Process execution information"
variable status
variable prgtext
variable prgindic
set pwd [pwd]
cd [file dirname [info script]]
variable VMDIR [pwd]
cd $pwd
foreach script {encoder.tcl decoder.tcl} {
namespace inscope :: source $VMDIR/$script
}
}
proc jp3dVM::create { } {
variable notebook
variable mainframe
variable dataout
bind all <F12> { catch {console show} }
# Menu description
set descmenu {
"&File" {} {} 0 {
{command "E&xit" {} "Exit BWidget jp3dVM" {} -command exit}
}
"&Options" {} {} 0 {
{command "&Encode" {} "Show encoder" {}
-command {$jp3dVM::notebook raise [$jp3dVM::notebook page 0]}
}
{command "&Decode" {} "Show decoder" {}
-command {$jp3dVM::notebook raise [$jp3dVM::notebook page 1]}
}
}
"&Help" {} {} 0 {
{command "&About authors..." {} "Show info about authors" {}
-command {MessageDlg .msgdlg -parent . -title "About authors" -message " Copyright @ LPI-UVA 2006 " -type ok -icon info}}
}
}
set mainframe [MainFrame .mainframe \
-menu $descmenu \
-textvariable jp3dVM::status \
-progressvar jp3dVM::prgindic]
$mainframe addindicator -text "JP3D Verification Model 1.0.0"
# NoteBook creation
set frame [$mainframe getframe]
set notebook [NoteBook $frame.nb]
set logo [frame $frame.logo]
#creo imagen logo
image create photo LPIimg -file logoLPI.gif
set logoimg [Label $logo.logoimg -image LPIimg]
set f0 [VMEncoder::create $notebook]
set f1 [VMDecoder::create $notebook]
set tfinfo [TitleFrame $frame.codinfo -text "Program Execution"]
set codinfo [$tfinfo getframe]
set sw [ScrolledWindow $codinfo.sw -relief sunken -borderwidth 2 -scrollbar both]
set sf [ScrollableFrame $codinfo.sf ]
$sw setwidget $sf
set subf [$sf getframe]
set labinfo [label $subf.labinfo -textvariable jp3dVM::dataout -justify left]
pack $labinfo -side left
pack $sw
$notebook compute_size
$notebook raise [$notebook page 0]
pack $logoimg -side left -fill x -expand yes
pack $notebook -expand yes
pack $logo $tfinfo -side left -expand yes
pack $mainframe -fill both -expand yes
update idletasks
}
proc jp3dVM::main {} {
variable VMDIR
lappend ::auto_path [file dirname $VMDIR]
namespace inscope :: package require BWidget
option add *TitleFrame.l.font {helvetica 11 bold italic}
wm withdraw .
wm title . "JP3D Verification Model @ LPI"
jp3dVM::create
BWidget::place . 0 0 center
wm deiconify .
raise .
focus -force .
}
jp3dVM::main
wm geom . [wm geom .]

13
src/bin/jp3d/tcltk/README Normal file
View File

@ -0,0 +1,13 @@
HOWTO USE THE TCL/TK APP IN 'jp3d/tcltk'
----------------------------------------
1. Download the 'BWidget-1.9.2'
http://www.sourceforge.net/projects/tcllib/
2. Install it e.g. in '/usr/local/BWidget-1.9.2/'
3. Add the lappend command in line 4
to jp3d/tcltk/LPI_JP3D_VM.tcl:
#!/bin/sh
# The next line is executed by /bin/sh, but not tcl \
exec wish "$0" ${1+"$@"}
lappend auto_path /usr/local/BWidget-1.9.2

BIN
src/bin/jp3d/tcltk/Thumbs.db Executable file

Binary file not shown.

272
src/bin/jp3d/tcltk/decoder.tcl Executable file
View File

@ -0,0 +1,272 @@
namespace eval VMDecoder {
variable var
variable JP3Ddecoder "../bin/jp3d_to_volume.exe"
#variable JP3Ddecoder "jp3d_to_volume.exe"
}
proc VMDecoder::create { nb } {
variable var
set frameD [$nb insert end VMDecoder -text "Decoder"]
set topfD [frame $frameD.topfD]
set medfD [frame $frameD.medfD]
set bottomfD [frame $frameD.bottomfD]
set srcfD [TitleFrame $topfD.srcfD -text "Source"]
set dstfD [TitleFrame $topfD.dstfD -text "Destination"]
set paramfD [TitleFrame $medfD.paramfD -text "Decoding parameters"]
set infofD [TitleFrame $medfD.infofD -text "Distortion measures"]
set frame1 [$srcfD getframe]
_sourceD $frame1
set frame2 [$dstfD getframe]
_destinationD $frame2
set frame3 [$infofD getframe]
_originalD $frame3
set frame4 [$paramfD getframe]
_paramsD $frame4
set butD [Button $bottomfD.butD -text "Decode!" \
-command "VMDecoder::_decode $frame1 $frame2 $frame3" \
-helptext "Decoding trigger button"]
set butR [Button $bottomfD.butR -text "Save info" \
-command "VMDecoder::_save $frame3" \
-helptext "Save information"]
pack $srcfD $dstfD -side left -fill both -padx 10 -ipadx 5 -expand yes
pack $topfD -pady 4 -fill x
pack $paramfD $infofD -side left -fill both -padx 10 -pady 2 -ipadx 5 -expand yes
pack $medfD -pady 4 -fill x
pack $butD $butR -side left -padx 4 -pady 5 -expand yes
pack $bottomfD -pady 4 -fill x
return $frameD
}
proc fileDialogD {w ent operation} {
variable file
if {$operation == "open"} {
#-----Type names---------Extension(s)---
set types {
{"JP3D Files" {.jp3d} }
{"All files" *}
}
set file [tk_getOpenFile -filetypes $types -parent $w ]
} elseif {$operation == "original"} {
#-----Type names---------Extension(s)---
set types {
{"BIN Raw Image Files" {.bin} }
{"PGX Raw Image Files" {.pgx} }
{"All files" *}
}
set file [tk_getOpenFile -filetypes $types -parent $w ]
} else {
#-----Type names---------Extension(s)---
set types {
{"BIN Raw Image Files" {.bin} }
{"PGX Raw Image Files" {.pgx} }
{"All files" *}
}
set file [tk_getSaveFile -filetypes $types -parent $w -initialfile Untitled -defaultextension "*.bin"]
}
if {[string compare $file ""]} {
$ent delete 0 end
$ent insert end $file
$ent xview moveto 1
}
}
proc VMDecoder::_sourceD { parent } {
variable var
set labsrcD [LabelFrame $parent.labsrcD -text "Select compressed file: " -side top \
-anchor w -relief flat -borderwidth 0]
set subsrcD [$labsrcD getframe]
set listD [entry $subsrcD.entrysrcD -width 40 -textvariable VMDecoder::var(sourceD)]
set labbrw [LabelFrame $parent.labbrw -side top -anchor w -relief flat -borderwidth 0]
set subbrw [$labbrw getframe]
set butbrw [button $subbrw.butbrw -image [Bitmap::get open] \
-relief raised -borderwidth 1 -padx 1 -pady 1 \
-command "fileDialogD . $subsrcD.entrysrcD open"]
pack $listD -side top
pack $butbrw -side top
pack $labsrcD $labbrw -side left -fill both -expand yes
}
proc VMDecoder::_destinationD { parent } {
variable var
set labdstD [LabelFrame $parent.labdstD -text "Save decompressed volume file(s) as: " -side top \
-anchor w -relief flat -borderwidth 0]
set subdstD [$labdstD getframe]
set listD [entry $subdstD.entrydstD -width 40 -textvariable VMDecoder::var(destinationD)]
set labbrw [LabelFrame $parent.labbrw -side top -anchor w -relief flat -borderwidth 0]
set subbrw [$labbrw getframe]
set butbrw [button $subbrw.butbrw -image [Bitmap::get save] \
-relief raised -borderwidth 1 -padx 1 -pady 1 \
-command "fileDialogD . $subdstD.entrydstD save"]
pack $listD -side top
pack $butbrw -side top
pack $labdstD $labbrw -side left -fill both -expand yes
}
proc VMDecoder::_originalD { parent } {
variable var
set laborgD [LabelFrame $parent.laborgD -text "Select original file: " -side top \
-anchor w -relief flat -borderwidth 0]
set suborgD [$laborgD getframe]
set listorgD [entry $suborgD.entryorgD -width 30 -textvariable VMDecoder::var(originalD)]
set labbrw2 [LabelFrame $parent.labbrw2 -side top -anchor w -relief flat -borderwidth 0]
set subbrw2 [$labbrw2 getframe]
set butbrw2 [button $subbrw2.butbrw2 -image [Bitmap::get open] \
-relief raised -borderwidth 1 -padx 1 -pady 1 \
-command "fileDialogD . $suborgD.entryorgD original"]
set infoD [Label $parent.infoD -relief sunken -textvariable VMDecoder::var(decodinfo) -justify left]
pack $listorgD -side left -anchor n
pack $butbrw2 -side left -anchor n
pack $infoD -side bottom -anchor nw -pady 4 -ipadx 150 -ipady 20 -expand yes
pack $laborgD $labbrw2 -side left -fill both
}
proc VMDecoder::_paramsD { parent } {
variable var
########### DECODING #############
set labcod [LabelFrame $parent.labcod -side top -anchor w -relief sunken -borderwidth 1]
set subcod [$labcod getframe]
set frameres [frame $subcod.frameres -borderwidth 1]
set labres [LabelEntry $frameres.labres -label "Resolutions to discard: " -labelwidth 20 -labelanchor w \
-textvariable VMDecoder::var(resdiscard) -editable 1 \
-helptext "Number of highest resolution levels to be discarded on each dimension" ]
set VMDecoder::var(resdiscard) "0,0,0"
set framelayer [frame $subcod.framelayer -borderwidth 1]
set lablayer [LabelEntry $framelayer.lablayer -label "Layers to decode: " -labelwidth 20 -labelanchor w \
-textvariable VMDecoder::var(layer) -editable 1 \
-helptext "Maximum number of quality layers to decode" ]
set VMDecoder::var(layer) "All"
set framebe [frame $subcod.framebe -borderwidth 1]
set chkbe [checkbutton $framebe.chkbe -text "Write decoded file with BigEndian byte order" \
-variable VMDecoder::var(be) -onvalue 1 -offvalue 0 ]
pack $labres -side left -padx 2 -anchor n
pack $lablayer -side left -padx 2 -anchor n
pack $chkbe -side left -padx 2 -anchor w
pack $frameres $framelayer $framebe -side top -anchor w
pack $subcod -anchor n
pack $labcod -side left -fill both -padx 4 -expand yes
}
proc VMDecoder::_decode { framesrc framedst frameinfo} {
variable var
set sourceD [$framesrc.labsrcD.f.entrysrcD get ]
set destinationD [$framedst.labdstD.f.entrydstD get ]
set originD [$frameinfo.laborgD.f.entryorgD get ]
set cond1 [string match *.pgx [string tolower $destinationD]]
set cond2 [string match *\**.pgx [string tolower $destinationD]]
set cond3 [string match *.bin [string tolower $destinationD]]
#comprobamos datos son correctos
if {($cond1 == 1) && ($cond2 == 0)} {
set pgx "*.pgx"
set pattern [string range $destinationD 0 [expr [string length $destinationD]-5]]
set destinationD $pattern$img
} elseif {$sourceD == ""} {
MessageDlg .msgdlg -parent . -message "Error : Source file is not defined !" -type ok -icon error
} elseif {$destinationD == ""} {
MessageDlg .msgdlg -parent . -message "Error : Destination file is not defined !" -type ok -icon error
} else {
#creamos datain a partir de los parametros de entrada
#set dirJP3Ddecoder [mk_relativepath $VMDecoder::JP3Ddecoder]
set dirJP3Ddecoder $VMDecoder::JP3Ddecoder
set datain [concat " $dirJP3Ddecoder -i [mk_relativepath $sourceD] "]
set datain [concat " $datain -o [mk_relativepath $destinationD] "]
if {$originD != ""} {
set datain [concat " $datain -O [mk_relativepath $originD] "]
if {$cond3 == 1} {
set img ".img"
set pattern [string range $originD 0 [expr [string length $originD]-5]]
set pattern $pattern$img
if {[file exists $pattern]} {
set datain [concat " $datain -m [mk_relativepath $pattern] "]
} else {
MessageDlg .msgdlg -parent . -message "Error : IMG file associated to original BIN volume file not found in same directory !" -type ok -icon info
}
}
}
if {$VMDecoder::var(resdiscard) != "0,0,0"} {
set datain [concat " $datain -r $VMDecoder::var(resdiscard) "]
}
if {$VMDecoder::var(layer) != "All" && $VMDecoder::var(layer) > 0} {
set datain [concat " $datain -l $VMDecoder::var(layer) "]
}
if {$VMDecoder::var(be) == 1} {
set datain [concat " $datain -BE"]
}
set VMDecoder::var(progval) 10
ProgressDlg .progress -parent . -title "Wait..." \
-type infinite \
-width 20 \
-textvariable "Compute in progress..."\
-variable VMDecoder::progval \
-stop "Stop" \
-command {destroy .progress}
after 200 set VMDecoder::var(progval) 2
set fp [open "| $datain " r+]
fconfigure $fp -buffering line
set jp3dVM::dataout [concat "EXECUTED PROGRAM:\n\t$datain"]
while {-1 != [gets $fp tmp]} {
set jp3dVM::dataout [concat "$jp3dVM::dataout\n$tmp"]
}
close $fp
destroy .progress
set cond [string first "ERROR" $jp3dVM::dataout]
set cond2 [string first "PSNR" $jp3dVM::dataout]
set cond3 [string first "RESULT" $jp3dVM::dataout]
if {$cond != -1} {
MessageDlg .msgdlg -parent . -message [string range $jp3dVM::dataout [expr $cond-1] end] -type ok -icon error
} elseif {$cond3 != -1} {
if {$cond2 != -1} {
set VMDecoder::var(decodinfo) [string range $jp3dVM::dataout [expr $cond2-1] end]
}
MessageDlg .msgdlg -parent . -message [string range $jp3dVM::dataout [expr $cond3-1] end] -type ok -icon info
}
}
}
proc VMDecoder::_save { frameinfo } {
}

470
src/bin/jp3d/tcltk/encoder.tcl Executable file
View File

@ -0,0 +1,470 @@
namespace eval VMEncoder {
variable var
variable JP3Dencoder "../bin/bin/volume_to_jp3d"
}
proc VMEncoder::create { nb } {
set frame [$nb insert end VMEncoder -text "Encoder"]
set topf [frame $frame.topf]
set midf [frame $frame.midf]
set bottomf [frame $frame.bottomf]
set srcf [TitleFrame $topf.srcf -text "Source"]
set dstf [TitleFrame $topf.dstf -text "Destination"]
set Tparf [TitleFrame $midf.parfT -text "Transform Parameters"]
set Cparf [TitleFrame $midf.parfC -text "Coding Parameters"]
set frame1 [$srcf getframe]
VMEncoder::_sourceE $frame1
set frame2 [$dstf getframe]
VMEncoder::_destinationE $frame2
set frame3 [$Tparf getframe]
VMEncoder::_transformE $frame3
set frame4 [$Cparf getframe]
VMEncoder::_codingE $frame4
set butE [Button $bottomf.butE -text "Encode!" \
-command "VMEncoder::_encode $frame1 $frame2" \
-helptext "Encoding trigger button"]
set butR [Button $bottomf.butR -text "Restore defaults" \
-command "VMEncoder::_reset $frame1 $frame2 $frame3 $frame4" \
-helptext "Reset to default values"]
pack $srcf $dstf -side left -fill y -padx 4 -expand yes
pack $topf -pady 2 -fill x
pack $Tparf $Cparf -side left -fill both -padx 4 -expand yes
pack $midf -pady 2 -fill x
pack $butE $butR -side left -padx 40 -pady 5 -fill y -expand yes
pack $bottomf -pady 2 -fill x
return $frame
}
proc VMEncoder::_sourceE { parent } {
variable var
set labsrc [LabelFrame $parent.labsrc -text "Select volume file to encode: " -side top \
-anchor w -relief flat -borderwidth 0]
set subsrc [$labsrc getframe]
set list [entry $subsrc.entrysrc -width 30 -textvariable VMDecoder::var(source)]
set labbrw [LabelFrame $parent.labbrw -side top -anchor w -relief flat -borderwidth 0]
set subbrw [$labbrw getframe]
set butbrw [button $subbrw.butbrw -image [Bitmap::get open] \
-relief raised -borderwidth 1 -padx 1 -pady 1 \
-command "fileDialogE . $subsrc.entrysrc open"]
pack $list -side top
pack $butbrw -side top
pack $labsrc $labbrw -side left -fill both -expand yes
}
proc VMEncoder::_destinationE { parent } {
variable var
set labdst [LabelFrame $parent.labdst -text "Save compressed volume as: " -side top \
-anchor w -relief flat -borderwidth 0]
set subdst [$labdst getframe]
set list [entry $subdst.entrydst -width 30 -textvariable VMDecoder::var(destination)]
set labbrw [LabelFrame $parent.labbrw -side top -anchor w -relief flat -borderwidth 0]
set subbrw [$labbrw getframe]
set butbrw [button $subbrw.butbrw -image [Bitmap::get save] \
-relief raised -borderwidth 1 -padx 1 -pady 1 \
-command "fileDialogE . $subdst.entrydst save"]
pack $list -side top
pack $butbrw -side top
pack $labdst $labbrw -side left -fill both -expand yes
}
proc VMEncoder::_codingE { parent } {
########### CODING #############
set labcod [LabelFrame $parent.labcod -side top -anchor w -relief sunken -borderwidth 1]
set subcod [$labcod getframe]
set framerate [frame $subcod.framerate -borderwidth 1]
set labrate [LabelEntry $framerate.labrate -label "Rates: " -labelwidth 9 -labelanchor w \
-textvariable VMEncoder::var(rate) -editable 1 \
-helptext "Compression ratios for different layers (R1, R2, R3,...). If R=1, lossless coding" ]
set VMEncoder::var(rate) "1"
set framecblk [frame $subcod.framecblk -borderwidth 1]
set labcblk [LabelEntry $framecblk.labcblk -label "Codeblock: " -labelwidth 9 -labelanchor w \
-textvariable VMEncoder::var(cblksize) -editable 1 \
-helptext "Codeblock size (X, Y, Z)" ]
set VMEncoder::var(cblksize) "64,64,64"
set frametile [frame $subcod.frametile -borderwidth 1]
set labtile [LabelEntry $frametile.labtile -label "Tile size: " -labelwidth 9 -labelanchor w \
-textvariable VMEncoder::var(tilesize) -editable 1 \
-helptext "Tile size (X, Y, Z)" ]
set VMEncoder::var(tilesize) "512,512,512"
set framesop [frame $subcod.framesop -borderwidth 1]
set chksop [checkbutton $framesop.chksop -text "Write SOP marker" \
-variable VMEncoder::var(sop) -onvalue 1 -offvalue 0 ]
set frameeph [frame $subcod.frameeph -borderwidth 1]
set chkeph [checkbutton $frameeph.chkeph -text "Write EPH marker" \
-variable VMEncoder::var(eph) -onvalue 1 -offvalue 0 ]
set framepoc [frame $subcod.framepoc -borderwidth 1]
set labpoc [label $framepoc.labpoc -text "Progression order: " ]
set progorder [ComboBox $framepoc.progorder \
-text {Choose a progression order} \
-width 10 \
-textvariable VMEncoder::var(progorder) \
-values {"LRCP" "RLCP" "RPCL" "PCRL" "CPRL"} \
-helptext "Progression order"]
set VMEncoder::var(progorder) "LRCP"
pack $labrate -side left -padx 2 -anchor n
pack $labcblk -side left -padx 2 -anchor n
pack $labpoc $progorder -side left -padx 2 -anchor w
#pack $labtile -side left -padx 2 -anchor n
pack $chksop -side left -padx 2 -anchor w
pack $chkeph -side left -padx 2 -anchor w
########### ENTROPY CODING #############
set labent [LabelFrame $parent.labent -text "Entropy Coding" -side top -anchor w -relief sunken -borderwidth 1]
set subent [$labent getframe]
foreach entval {2EB 3EB} entropy {2D_EBCOT 3D_EBCOT} {
set rad [radiobutton $subent.$entval \
-text $entropy \
-variable VMEncoder::var(encoding) \
-command "disableGR $entval $labcblk $progorder $labrate $chksop $chkeph" \
-value $entval ]
pack $rad -anchor w
}
$subent.2EB select
pack $subent -padx 2 -anchor n
pack $framerate $framecblk $framepoc $framesop $frameeph -side top -anchor w
pack $subcod -anchor n
pack $labent $labcod -side left -fill both -padx 4 -expand yes
}
proc VMEncoder::_transformE { parent } {
variable var
########### TRANSFORM #############
set labtrf [LabelFrame $parent.labtrf -text "Transform" -side top -anchor w -relief sunken -borderwidth 1]
set subtrf [$labtrf getframe]
set labres [LabelFrame $parent.labres -side top -anchor w -relief sunken -borderwidth 1]
set subres [$labres getframe]
########### ATK #############
set frameatk [frame $subres.frameatk -borderwidth 1]
set labatk [label $frameatk.labatk -text "Wavelet kernel: " -anchor w]
set atk [ComboBox $frameatk.atk \
-textvariable VMEncoder::var(atk) \
-width 20 \
-text {Choose a wavelet kernel} \
-editable false \
-values {"R5.3" "I9.7"} ]
set VMEncoder::var(atk) "R5.3"
pack $labatk $atk -side left -anchor w
########### RESOLUTIONS #############
set frameres1 [frame $subres.frameres1 -borderwidth 1]
set labresolution [label $frameres1.labresol -text "Resolutions: " -anchor w ]
set frameres2 [frame $subres.frameres2 -borderwidth 1]
set labresX [label $frameres2.labresX -text " X" -anchor w ]
set labresY [label $frameres2.labresY -text " Y" -anchor w ]
set labresZ [label $frameres2.labresZ -text " Z" -anchor w ]
set resX [SpinBox $frameres2.spinresX \
-range {1 6 1} -textvariable VMEncoder::var(resX) \
-helptext "Number of resolutions in X" \
-width 3 \
-editable false ]
set resY [SpinBox $frameres2.spinresY \
-range {1 6 1} -textvariable VMEncoder::var(resY) \
-helptext "Number of resolutions in Y" \
-width 3 \
-editable false ]
set resZ [SpinBox $frameres2.spinresZ \
-range {1 6 1} -textvariable VMEncoder::var(resZ) \
-helptext "Number of resolutions in Z" \
-width 3 \
-editable false \
-state disabled ]
set VMEncoder::var(resX) 3
set VMEncoder::var(resY) 3
set VMEncoder::var(resZ) 3
########### TRF #############
foreach trfval {2DWT 3DWT} trf {2D-DWT 3D-DWT} {
set rad [radiobutton $subtrf.$trfval -text $trf \
-variable VMEncoder::var(transform) \
-command "disable3RLS $trfval $atk $resX $resY $resZ"\
-value $trfval ]
pack $rad -anchor w
}
$subtrf.2DWT select
pack $subtrf -side left -padx 2 -pady 4
pack $labresolution -padx 2 -side left -anchor w
pack $labresX $resX -padx 2 -side left -anchor w
pack $labresY $resY -padx 2 -side left -anchor w
pack $labresZ $resZ -padx 2 -side left -anchor w
pack $frameres1 -side top -fill x
pack $frameres2 $frameatk -side top -padx 2 -pady 4 -anchor n
pack $subres -side left -padx 2 -pady 4
pack $labtrf $labres -side left -fill both -padx 4 -expand yes
}
proc VMEncoder::_encode { framesrc framedst } {
variable var
set source [$framesrc.labsrc.f.entrysrc get ]
set destination [$framedst.labdst.f.entrydst get ]
set cond1 [string match *.pgx [string tolower $source]]
set cond2 [string match *-*.pgx [string tolower $source]]
set cond3 [string match *.bin [string tolower $source]]
set img ".img"
set pattern [string range $source 0 [expr [string length $source]-5]]
set pattern $pattern$img
set exist [file exists $pattern]
#comprobamos datos son correctos
if {($cond1 == 1) && ($cond2 == 0)} {
MessageDlg .msgdlg -parent . -message "Info : Really want to encode an slice instead of a volume?.\n For a group of .pgx slices, name must contain a - denoting a sequential index!" -type ok -icon info
}
if {$source == ""} {
MessageDlg .msgdlg -parent . -message "Error : Source file is not defined !" -type ok -icon error
} elseif {$destination == ""} {
MessageDlg .msgdlg -parent . -message "Error : Destination file is not defined !" -type ok -icon error
} elseif { ($VMEncoder::var(transform) != "3RLS") && ($VMEncoder::var(atk) == "Choose a wavelet transformation kernel") } {
MessageDlg .msgdlg -parent . -title "Info" -message "Please choose a wavelet transformation kernel"\
-type ok -icon warning
} elseif {($exist == 0) && ($cond1 == 0) && ($cond3 == 1)} {
MessageDlg .msgdlg -parent . -message "Error : IMG file associated to BIN volume file not found in same directory !" -type ok -icon info
} else {
#creamos datain a partir de los parametros de entrada
# set dirJP3Dencoder [mk_relativepath $VMEncoder::JP3Dencoder]
set dirJP3Dencoder $VMEncoder::JP3Dencoder
set datain [concat " $dirJP3Dencoder -i [mk_relativepath $source] "]
if {$cond3 == 1} {
set datain [concat " $datain -m [mk_relativepath $pattern] "]
}
set datain [concat " $datain -o [mk_relativepath $destination] "]
if {$VMEncoder::var(encoding) != "2EB"} {
set datain [concat " $datain -C $VMEncoder::var(encoding) "]
}
if {$VMEncoder::var(transform) == "2DWT"} {
set datain [concat " $datain -n $VMEncoder::var(resX),$VMEncoder::var(resY) "]
} elseif {$VMEncoder::var(transform) == "3DWT"} {
set datain [concat " $datain -n $VMEncoder::var(resX),$VMEncoder::var(resY),$VMEncoder::var(resZ) "]
}
set datain [concat " $datain -r $VMEncoder::var(rate) "]
if {$VMEncoder::var(atk) == "I9.7"} {
set datain [concat " $datain -I "]
}
if {$VMEncoder::var(sop) == 1} {
set datain [concat " $datain -SOP "]
}
if {$VMEncoder::var(eph) == 1} {
set datain [concat " $datain -EPH "]
}
if {$VMEncoder::var(progorder) != "LRCP"} {
set datain [concat " $datain -p $VMEncoder::var(progorder) "]
}
if {$VMEncoder::var(cblksize) != "64,64,64"} {
set datain [concat " $datain -b $VMEncoder::var(cblksize) "]
}
#Making this work would be great !!!
set VMEncoder::var(progval) 10
ProgressDlg .progress -parent . -title "Wait..." \
-type infinite \
-width 20 \
-textvariable "Compute in progress..."\
-variable VMEncoder::progval \
-stop "Stop" \
-command {destroy .progress}
after 200 set VMEncoder::var(progval) 2
set fp [open "| $datain " r+]
fconfigure $fp -buffering line
set jp3dVM::dataout [concat "EXECUTED PROGRAM:\n\t$datain"]
while {-1 != [gets $fp tmp]} {
set jp3dVM::dataout [concat "$jp3dVM::dataout\n$tmp"]
}
destroy .progress
set cond [string first "ERROR" $jp3dVM::dataout]
set cond2 [string first "RESULT" $jp3dVM::dataout]
if {$cond != -1} {
MessageDlg .msgdlg -parent . -message [string range $jp3dVM::dataout [expr $cond-1] end] -type ok -icon error
} elseif {$cond2 != -1} {
MessageDlg .msgdlg -parent . -message [string range $jp3dVM::dataout [expr $cond2+7] end] -type ok -icon info
close $fp
} else {
#Must do something with this !!! [pid $fp]
close $fp
}
}
}
proc VMEncoder::_reset { framesrc framedst frametrf framecod} {
variable var
#Restore defaults values
set VMEncoder::var(transform) 2DWT
set VMEncoder::var(encoding) 2EB
set VMEncoder::var(atk) "R5.3"
set VMEncoder::var(progorder) "LRCP"
set atk $frametrf.labres.f.frameatk.atk
set resX $frametrf.labres.f.frameres2.spinresX
set resY $frametrf.labres.f.frameres2.spinresY
set resZ $frametrf.labres.f.frameres2.spinresZ
disable3RLS 2DWT $atk $resX $resY $resZ
set labcblk $framecod.labcod.f.framecblk.labcblk
set progorder $framecod.labcod.f.framepoc.progorder
set labrate $framecod.labcod.f.framerate.labrate
set chksop $framecod.labcod.f.framesop.chksop
set chkeph $framecod.labcod.f.frameeph.chkeph
disableGR 3EB $labcblk $progorder $labrate $chksop $chkeph
$framesrc.labsrc.f.entrysrc delete 0 end
$framedst.labdst.f.entrydst delete 0 end
}
proc fileDialogE {w ent operation} {
variable file
variable i j
if {$operation == "open"} {
set types {
{"Source Image Files" {.pgx .bin} }
{"All files" *}
}
set file [tk_getOpenFile -filetypes $types -parent $w]
if {[string compare $file ""]} {
$ent delete 0 end
$ent insert end $file
$ent xview moveto 1
}
} else {
set types {
{"JP3D Files" {.jp3d} }
{"JPEG2000 Files" {.j2k} }
{"All files" *}
}
set file [tk_getSaveFile -filetypes $types -parent $w \
-initialfile Untitled -defaultextension .jp3d]
if {[string compare $file ""]} {
$ent delete 0 end
$ent insert end $file
$ent xview moveto 1
}
}
}
proc mk_relativepath {abspath} {
set mydir [split [string trimleft [pwd] {/}] {/}]
set abspathcomps [split [string trimleft $abspath {/}] {/}]
set i 0
while {$i<[llength $mydir]} {
if {![string compare [lindex $abspathcomps $i] [lindex $mydir $i]]} {
incr i
} else {
break
}
}
set h [expr [llength $mydir]-$i]
set j [expr [llength $abspathcomps]-$i]
if {!$h} {
set relpath "./"
} else {
set relpath ""
while { $h > 0 } {
set relpath "../$relpath"
incr h -1
}
}
set h [llength $abspathcomps]
while { $h > $i } {
set relpath [concat $relpath[lindex $abspathcomps [expr [llength $abspathcomps]-$j]]/]
incr h -1
incr j -1
}
return [string trim $relpath {/}]
}
proc disable3RLS {flag atk resX resY resZ} {
if {$flag == "3RLS"} {
$atk configure -state disabled
$resX configure -state disabled
$resY configure -state disabled
$resZ configure -state disabled
} elseif {$flag == "2DWT"} {
$atk configure -state normal
$resX configure -state normal
$resY configure -state normal
$resZ configure -state disabled
} elseif {$flag == "3DWT"} {
$atk configure -state normal
$resX configure -state normal
$resY configure -state normal
$resZ configure -state normal
}
}
proc disableGR {flag labcblk progorder labrate chksop chkeph} {
if {$flag == "2EB"} {
$labcblk configure -state normal
$progorder configure -state normal
$labrate configure -state normal
$chksop configure -state normal
$chkeph configure -state normal
set VMEncoder::var(cblksize) "64,64,64"
set VMEncoder::var(tilesize) "512,512,512"
} elseif {$flag == "3EB"} {
$labcblk configure -state normal
$progorder configure -state normal
$labrate configure -state normal
$chksop configure -state normal
$chkeph configure -state normal
set VMEncoder::var(cblksize) "64,64,64"
set VMEncoder::var(tilesize) "512,512,512"
} else {
$labcblk configure -state disabled
$progorder configure -state disabled
$labrate configure -state disabled
$chksop configure -state disabled
$chkeph configure -state disabled
}
}

BIN
src/bin/jp3d/tcltk/logoLPI.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

678
src/bin/jp3d/windirent.h Normal file
View File

@ -0,0 +1,678 @@
/*
* uce-dirent.h - operating system independent dirent implementation
*
* Copyright (C) 1998-2002 Toni Ronkko
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
*
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
*
* $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $
*
* $Log: uce-dirent.h,v $
* Revision 1.7 2002/05/13 10:48:35 tr
* embedded some source code directly to the header so that no source
* modules need to be included in the MS Visual C project using the
* interface, removed all the dependencies to other headers of the `uce'
* library so that the header can be made public
*
* Revision 1.6 2002/04/12 16:22:04 tr
* Unified Compiling Environment (UCE) replaced `std' library
*
* Revision 1.5 2001/07/20 16:33:40 tr
* moved to `std' library and re-named defines accordingly
*
* Revision 1.4 2001/07/10 16:47:18 tronkko
* revised comments
*
* Revision 1.3 2001/01/11 13:16:43 tr
* using ``uce-machine.h'' for finding out defines such as `FREEBSD'
*
* Revision 1.2 2000/10/08 16:00:41 tr
* copy of FreeBSD man page
*
* Revision 1.1 2000/07/10 05:53:16 tr
* Initial revision
*
* Revision 1.2 1998/07/19 18:29:14 tr
* Added error reporting capabilities and some asserts.
*
* Revision 1.1 1998/07/04 16:27:51 tr
* Initial revision
*
*
* MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle
* include directives inside #if..#endif block those are never entered.
* Since this header ought to compile in many different operating systems,
* there had to be several conditional blocks that are compiled only in
* operating systems for what they were designed for. MSVC 1.0 cannot
* handle inclusion of sys/dir.h in a part that is compiled only in Apollo
* operating system. To fix the problem you need to insert DIR.H into
* SYSINCL.DAT located in MSVC\BIN directory and restart visual C++.
* Consult manuals for more informaton about the problem.
*
* Since many UNIX systems have dirent.h we assume to have one also.
* However, if your UNIX system does not have dirent.h you can download one
* for example at: http://ftp.uni-mannheim.de/ftp/GNU/dirent/dirent.tar.gz.
* You can also see if you have one of dirent.h, direct.h, dir.h, ndir.h,
* sys/dir.h and sys/ndir.h somewhere. Try defining HAVE_DIRENT_H,
* HAVE_DIRECT_H, HAVE_DIR_H, HAVE_NDIR_H, HAVE_SYS_DIR_H and
* HAVE_SYS_NDIR_H according to the files found.
*/
#ifndef DIRENT_H
#define DIRENT_H
#define DIRENT_H_INCLUDED
/* find out platform */
#if defined(MSDOS) /* MS-DOS */
#elif defined(__MSDOS__) /* Turbo C/Borland */
# define MSDOS
#elif defined(__DOS__) /* Watcom */
# define MSDOS
#endif
#if defined(WIN32) /* MS-Windows */
#elif defined(__NT__) /* Watcom */
# define WIN32
#elif defined(_WIN32) /* Microsoft */
# define WIN32
#elif defined(__WIN32__) /* Borland */
# define WIN32
#endif
/*
* See what kind of dirent interface we have unless autoconf has already
* determinated that.
*/
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H
# define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */
# define HAVE_SYS_DIR_H
# elif defined(__hpux) /* HP-UX */
# define HAVE_DIRENT_H
# elif defined(__alpha) || defined(__alpha__) /* Alpha OSF1 */
# error "not implemented"
# elif defined(__sgi) /* Silicon Graphics */
# define HAVE_DIRENT_H
# elif defined(sun) || defined(_sun) /* Sun Solaris */
# define HAVE_DIRENT_H
# elif defined(__FreeBSD__) /* FreeBSD */
# define HAVE_DIRENT_H
# elif defined(__linux__) /* Linux */
# define HAVE_DIRENT_H
# elif defined(__GNUC__) /* GNU C/C++ */
# define HAVE_DIRENT_H
# else
# error "not implemented"
# endif
#endif
/* include proper interface headers */
#if defined(HAVE_DIRENT_H)
# include <dirent.h>
# ifdef FREEBSD
# define NAMLEN(dp) ((int)((dp)->d_namlen))
# else
# define NAMLEN(dp) ((int)(strlen((dp)->d_name)))
# endif
#elif defined(HAVE_NDIR_H)
# include <ndir.h>
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(HAVE_SYS_NDIR_H)
# include <sys/ndir.h>
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(HAVE_DIRECT_H)
# include <direct.h>
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(HAVE_DIR_H)
# include <dir.h>
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(HAVE_SYS_DIR_H)
# include <sys/types.h>
# include <sys/dir.h>
# ifndef dirent
# define dirent direct
# endif
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlaying directory interface to be used */
# if defined(WIN32)
# define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS)
# define DIRENT_MSDOS_INTERFACE
# else
# error "missing native dirent interface"
# endif
/*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h>
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (MAX_PATH)
# endif
/*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h>
/* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT))
# endif
# if !defined(_find_t)
# define _find_t find_t
# endif
/* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT))
# endif
# define DIRENT_USE_FFBLK
/* MSVC */
# elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12)
# endif
/* Watcom */
# elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__)
# define DIRENT_MAXNAMLEN (255)
# else
# define DIRENT_MAXNAMLEN (12)
# endif
# endif
# endif
# endif
/*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN
# endif
# if NAME_MAX < DIRENT_MAXNAMLEN
# error "assertion failed: NAME_MAX >= DIRENT_MAXNAMLEN"
# endif
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE) /*WIN32*/
WIN32_FIND_DATA data;
# elif defined(DIRENT_MSDOS_INTERFACE) /*MSDOS*/
# if defined(DIRENT_USE_FFBLK)
struct ffblk data;
# else
struct _find_t data;
# endif
# endif
} dirent;
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
char *dirname; /* directory being scanned */
dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE)
# endif
} DIR;
# ifdef __cplusplus
extern "C" {
# endif
/* supply prototypes for dirent functions */
static DIR *opendir (const char *dirname);
static struct dirent *readdir (DIR *dirp);
static int closedir (DIR *dirp);
static void rewinddir (DIR *dirp);
/*
* Implement dirent interface as static functions so that the user does not
* need to change his project in any way to use dirent function. With this
* it is sufficient to include this very header from source modules using
* dirent functions and the functions will be pulled in automatically.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
/* use ffblk instead of _find_t if requested */
#if defined(DIRENT_USE_FFBLK)
# define _A_ARCH (FA_ARCH)
# define _A_HIDDEN (FA_HIDDEN)
# define _A_NORMAL (0)
# define _A_RDONLY (FA_RDONLY)
# define _A_SUBDIR (FA_DIREC)
# define _A_SYSTEM (FA_SYSTEM)
# define _A_VOLID (FA_LABEL)
# define _dos_findnext(dest) findnext(dest)
# define _dos_findfirst(name,flags,dest) findfirst(name,dest,flags)
#endif
static int _initdir (DIR *p);
static const char *_getdirname (const struct dirent *dp);
static void _setdirname (struct DIR *dirp);
/*
* <function name="opendir">
* <intro>open directory stream for reading
* <syntax>DIR *opendir (const char *dirname);
*
* <desc>Open named directory stream for read and return pointer to the
* internal working area that is used for retrieving individual directory
* entries. The internal working area has no fields of your interest.
*
* <ret>Returns a pointer to the internal working area or NULL in case the
* directory stream could not be opened. Global `errno' variable will set
* in case of error as follows:
*
* <table>
* [EACESS |Permission denied.
* [EMFILE |Too many open files used by the process.
* [ENFILE |Too many open files in system.
* [ENOENT |Directory does not exist.
* [ENOMEM |Insufficient memory.
* [ENOTDIR |dirname does not refer to directory. This value is not
* reliable on MS-DOS and MS-Windows platforms. Many
* implementations return ENOENT even when the name refers to a
* file.]
* </table>
* </function>
*/
static DIR *opendir(const char *dirname)
{
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
strcpy (p, "*"); /*scan files with and without extension in win32*/
# else
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
}
}
return dirp;
}
/*
* <function name="readdir">
* <intro>read a directory entry
* <syntax>struct dirent *readdir (DIR *dirp);
*
* <desc>Read individual directory entry and return pointer to a structure
* containing the name of the entry. Individual directory entries returned
* include normal files, sub-directories, pseudo-directories "." and ".."
* and also volume labels, hidden files and system files in MS-DOS and
* MS-Windows. You might want to use stat(2) function to determinate which
* one are you dealing with. Many dirent implementations already contain
* equivalent information in dirent structure but you cannot depend on
* this.
*
* The dirent structure contains several system dependent fields that
* generally have no interest to you. The only interesting one is char
* d_name[] that is also portable across different systems. The d_name
* field contains the name of the directory entry without leading path.
* While d_name is portable across different systems the actual storage
* capacity of d_name varies from system to system and there is no portable
* way to find out it at compile time as different systems define the
* capacity of d_name with different macros and some systems do not define
* capacity at all (besides actual declaration of the field). If you really
* need to find out storage capacity of d_name then you might want to try
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard although
* there are many MS-DOS and MS-Windows implementations those do not define
* it. There are also systems that declare d_name as "char d_name[1]" and
* then allocate suitable amount of memory at run-time. Thanks to Alain
* Decamps (Alain.Decamps@advalvas.be) for pointing it out to me.
*
* This all leads to the fact that it is difficult to allocate space
* for the directory names when the very same program is being compiled on
* number of operating systems. Therefore I suggest that you always
* allocate space for directory names dynamically.
*
* <ret>
* Returns a pointer to a structure containing name of the directory entry
* in `d_name' field or NULL if there was an error. In case of an error the
* global `errno' variable will set as follows:
*
* <table>
* [EBADF |dir parameter refers to an invalid directory stream. This value
* is not set reliably on all implementations.]
* </table>
* </function>
*/
static struct dirent *
readdir (DIR *dirp)
{
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
#endif
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, we have to
* save the first file when opening the stream and later we have to
* return the saved entry when the user tries to read the first entry.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
# endif
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
}
/*
* <function name="closedir">
* <intro>close directory stream.
* <syntax>int closedir (DIR *dirp);
*
* <desc>Close directory stream opened by the `opendir' function. Close of
* directory stream invalidates the DIR structure as well as previously read
* dirent entry.
*
* <ret>The function typically returns 0 on success and -1 on failure but
* the function may be declared to return void on same systems. At least
* Borland C/C++ and some UNIX implementations use void as a return type.
* The dirent wrapper tries to define VOID_CLOSEDIR whenever closedir is
* known to return nothing. The very same definition is made by the GNU
* autoconf if you happen to use it.
*
* The global `errno' variable will set to EBADF in case of error.
* </function>
*/
static int
closedir (DIR *dirp)
{
int retcode = 0;
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
}
}
#endif
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE;
# endif
free (dirp);
return retcode;
}
/*
* <function name="rewinddir">
* <intro>rewind directory stream to the beginning
* <syntax>void rewinddir (DIR *dirp);
*
* <desc>Rewind directory stream to the beginning so that the next call of
* readdir() returns the very first directory entry again. However, note
* that next call of readdir() may not return the same directory entry as it
* did in first time. The directory stream may have been affected by newly
* created files.
*
* Almost every dirent implementation ensure that rewinddir will update
* the directory stream to reflect any changes made to the directory entries
* since the previous ``opendir'' or ``rewinddir'' call. Keep an eye on
* this if your program depends on the feature. I know at least one dirent
* implementation where you are required to close and re-open the stream to
* see the changes.
*
* <ret>Returns nothing. If something went wrong while rewinding, you will
* notice it later when you try to retrieve the first directory entry.
*/
static void
rewinddir (DIR *dirp)
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
}
}
#endif
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
}
/*
* Open native directory stream object and retrieve first file.
* Be sure to close previous stream before opening new one.
*/
static int
_initdir (DIR *dirp)
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
# endif
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
}
/*
* Return implementation dependent name of the current directory entry.
*/
static const char *
_getdirname (const struct dirent *dp)
{
#if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name;
#else
return dp->data.name;
#endif
}
/*
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
}
# ifdef __cplusplus
}
# endif
# define NAMLEN(dp) ((int)(strlen((dp)->d_name)))
#else
# error "missing dirent interface"
#endif
#endif /*DIRENT_H*/

View File

@ -13,7 +13,7 @@ add_executable(opj_jpip_addxml opj_jpip_addxml.c)
# Install exe
install(TARGETS opj_jpip_addxml
EXPORT OpenJPEGTargets
DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
if(BUILD_JPIP_SERVER)
@ -38,7 +38,7 @@ if(BUILD_JPIP_SERVER)
# Install exe
install(TARGETS opj_server
EXPORT OpenJPEGTargets
DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
endif()
@ -52,19 +52,19 @@ add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} openjpip)
install(TARGETS ${exe}
EXPORT OpenJPEGTargets
DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
endforeach()
# Build the two java clients:
find_package(Java 1.8 COMPONENTS Development) # javac, jar
find_package(Java 1.5 COMPONENTS Development) # javac, jar
# User can override this:
if(NOT DEFINED JAVA_SOURCE_VERSION)
set(JAVA_SOURCE_VERSION 1.8)
set(JAVA_SOURCE_VERSION 1.5)
endif()
if(NOT DEFINED JAVA_TARGET_VERSION)
set(JAVA_TARGET_VERSION 1.8)
set(JAVA_TARGET_VERSION 1.5)
endif()
# Only build the java viewer if dev is found:
@ -123,7 +123,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
)
install(FILES ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} COMPONENT JavaModule
DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule
)
else()
# opj_viewer (simple, no xerces)
@ -153,9 +153,9 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
)
install(FILES ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} COMPONENT JavaModule
DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule
)
endif()
else()
message(WARNING "No java compiler found. Won't be able to build java viewer")
message(WARNING "No java compiler found. Wont be able to build java viewer")
endif()

View File

@ -92,7 +92,7 @@ Server:
For shutting down JPIP server:
%GET http://hostname/myFCGI?quitJPIP
Notice, http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
Request message "quitJPIP" can be changed in Makefile, modify -DQUIT_SIGNAL=\"quitJPIP\"
Requst message "quitJPIP" can be changed in Makfile, modify -DQUIT_SIGNAL=\"quitJPIP\"
Client:
1. Launch image decoding server, and keep it alive as long as image viewers are open

View File

@ -42,7 +42,7 @@
* quit\n
* Be sure all image viewers are closed.\n
* Cache file in JPT format is stored in the working directly before it quites.
*
*
*/
#include <stdio.h>
@ -54,45 +54,40 @@
WSADATA initialisation_win32;
#endif
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]){
dec_server_record_t *server_record;
client_t client;
int port = 50000;
int erreur;
(void)erreur;
dec_server_record_t *server_record;
client_t client;
int port = 50000;
int erreur;
(void)erreur;
if (argc > 1) {
port = atoi(argv[1]);
}
if( argc > 1)
port = atoi( argv[1]);
#ifdef _WIN32
erreur = WSAStartup(MAKEWORD(2, 2), &initialisation_win32);
if (erreur != 0) {
fprintf(stderr, "Erreur initialisation Winsock error : %d %d\n", erreur,
WSAGetLastError());
} else {
printf("Initialisation Winsock\n");
}
erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
printf( "Initialisation Winsock\n");
#endif /*_WIN32*/
server_record = init_dec_server(port);
while ((client = accept_connection(server_record)) != -1)
if (!handle_clientreq(client, server_record)) {
break;
}
terminate_dec_server(&server_record);
server_record = init_dec_server( port);
while(( client = accept_connection( server_record)) != -1 )
if(!handle_clientreq( client, server_record))
break;
terminate_dec_server( &server_record);
#ifdef _WIN32
if (WSACleanup() != 0) {
printf("\nError in WSACleanup : %d %d", erreur, WSAGetLastError());
} else {
printf("\nWSACleanup OK\n");
}
if( WSACleanup() != 0){
printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
}else{
printf("\nWSACleanup OK\n");
}
#endif
return 0;
return 0;
}

View File

@ -36,7 +36,7 @@
* -# Input/output image file in JP2 format, this JP2 file is being modified
* -# Input XML file with metadata contents\n
* % ./addXMLinJP2 image.jp2 metadata.xml\n
*
*
* Currently, this program does not parse XML file, and the XML file contents is directly embedded as a XML Box.\n
* The following is an example of XML file contents specifying Region Of Interests with target names.\n
* <xmlbox>\n
@ -60,7 +60,7 @@
* @param[in] filename file name string
* @return file descriptor
*/
FILE * open_jp2file(const char filename[]);
FILE * open_jp2file( const char filename[]);
/**
@ -70,118 +70,115 @@ FILE * open_jp2file(const char filename[]);
* @param[out] fsize file byte size
* @return pointer to the xml file content buffer
*/
char * read_xmlfile(const char filename[], long *fsize);
char * read_xmlfile( const char filename[], long *fsize);
int main(int argc, char *argv[])
{
FILE *fp;
char *xmldata, type[] = "xml ";
long fsize, boxsize;
FILE *fp;
char *xmldata, type[]="xml ";
long fsize, boxsize;
if (argc < 3) {
fprintf(stderr, "USAGE: %s modifying.jp2 adding.xml\n", argv[0]);
return -1;
}
if( argc<3){
fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] );
return -1;
}
fp = open_jp2file(argv[1]);
if (!fp) {
return -1;
}
fp = open_jp2file( argv[1]);
if( !fp)
return -1;
xmldata = read_xmlfile( argv[2], &fsize);
if( fsize < 0 ) return -1;
boxsize = fsize + 8;
xmldata = read_xmlfile(argv[2], &fsize);
if (fsize < 0) {
return -1;
}
boxsize = fsize + 8;
fputc((boxsize >> 24) & 0xff, fp);
fputc((boxsize >> 16) & 0xff, fp);
fputc((boxsize >> 8) & 0xff, fp);
fputc(boxsize & 0xff, fp);
fwrite(type, 4, 1, fp);
fwrite(xmldata, (size_t)fsize, 1, fp);
free(xmldata);
fclose(fp);
return 0;
fputc( (boxsize>>24)&0xff, fp);
fputc( (boxsize>>16)&0xff, fp);
fputc( (boxsize>>8)&0xff, fp);
fputc( boxsize&0xff, fp);
fwrite( type, 4, 1, fp);
fwrite( xmldata, (size_t)fsize, 1, fp);
free( xmldata);
fclose(fp);
return 0;
}
FILE * open_jp2file(const char filename[])
FILE * open_jp2file( const char filename[])
{
FILE *fp;
char *data;
if (!(fp = fopen(filename, "a+b"))) {
fprintf(stderr, "Original JP2 %s not found\n", filename);
return NULL;
}
/* Check resource is a JP family file. */
if (fseek(fp, 0, SEEK_SET) == -1) {
fclose(fp);
fprintf(stderr, "Original JP2 %s broken (fseek error)\n", filename);
return NULL;
}
data = (char *)malloc(12); /* size of header */
if (fread(data, 12, 1, fp) != 1) {
free(data);
fclose(fp);
fprintf(stderr, "Original JP2 %s broken (read error)\n", filename);
return NULL;
}
if (*data || *(data + 1) || *(data + 2) ||
*(data + 3) != 12 || strncmp(data + 4, "jP \r\n\x87\n", 8)) {
free(data);
fclose(fp);
fprintf(stderr, "No JPEG 2000 Signature box in target %s\n", filename);
return NULL;
}
free(data);
return fp;
}
char * read_xmlfile(const char filename[], long *fsize)
{
FILE *fp;
char *data;
/* fprintf( stderr, "open %s\n", filename);*/
if (!(fp = fopen(filename, "r"))) {
fprintf(stderr, "XML file %s not found\n", filename);
return NULL;
}
if (fseek(fp, 0, SEEK_END) == -1) {
fprintf(stderr, "XML file %s broken (seek error)\n", filename);
fclose(fp);
return NULL;
}
if ((*fsize = ftell(fp)) == -1) {
fprintf(stderr, "XML file %s broken (seek error)\n", filename);
fclose(fp);
return NULL;
}
assert(*fsize >= 0);
if (fseek(fp, 0, SEEK_SET) == -1) {
fprintf(stderr, "XML file %s broken (seek error)\n", filename);
fclose(fp);
return NULL;
}
data = (char *)malloc((size_t) * fsize);
if (fread(data, (size_t)*fsize, 1, fp) != 1) {
fprintf(stderr, "XML file %s broken (read error)\n", filename);
free(data);
fclose(fp);
return NULL;
}
FILE *fp;
char *data;
if( !(fp = fopen( filename, "a+b"))){
fprintf( stderr, "Original JP2 %s not found\n", filename);
return NULL;
}
/* Check resource is a JP family file. */
if( fseek( fp, 0, SEEK_SET)==-1){
fclose(fp);
return data;
fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename);
return NULL;
}
data = (char *)malloc( 12); /* size of header */
if( fread( data, 12, 1, fp) != 1){
free( data);
fclose(fp);
fprintf( stderr, "Original JP2 %s broken (read error)\n", filename);
return NULL;
}
if( *data || *(data + 1) || *(data + 2) ||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
free( data);
fclose(fp);
fprintf( stderr, "No JPEG 2000 Signature box in target %s\n", filename);
return NULL;
}
free( data);
return fp;
}
char * read_xmlfile( const char filename[], long *fsize)
{
FILE *fp;
char *data;
/* fprintf( stderr, "open %s\n", filename);*/
if(!(fp = fopen( filename, "r"))){
fprintf( stderr, "XML file %s not found\n", filename);
return NULL;
}
if( fseek( fp, 0, SEEK_END) == -1){
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
if( (*fsize = ftell( fp)) == -1){
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
assert( *fsize >= 0 );
if( fseek( fp, 0, SEEK_SET) == -1){
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
data = (char *)malloc( (size_t)*fsize);
if( fread( data, (size_t)*fsize, 1, fp) != 1){
fprintf( stderr, "XML file %s broken (read error)\n", filename);
free( data);
fclose(fp);
return NULL;
}
fclose( fp);
return data;
}

View File

@ -51,25 +51,23 @@
int
main(int argc, char *argv[])
{
int fd;
index_t *jp2idx;
if (argc < 2) {
return 1;
}
int fd;
index_t *jp2idx;
if( argc < 2 ) return 1;
if( (fd = open( argv[1], O_RDONLY)) == -1){
fprintf( stderr, "Error: Target %s not found\n", argv[1]);
return -1;
}
if ((fd = open(argv[1], O_RDONLY)) == -1) {
fprintf(stderr, "Error: Target %s not found\n", argv[1]);
return -1;
}
if( !(jp2idx = get_index_from_JP2file( fd))){
fprintf( stderr, "JP2 file broken\n");
return -1;
}
output_index( jp2idx);
destroy_index( &jp2idx);
close(fd);
if (!(jp2idx = get_index_from_JP2file(fd))) {
fprintf(stderr, "JP2 file broken\n");
return -1;
}
output_index(jp2idx);
destroy_index(&jp2idx);
close(fd);
return 0;
return 0;
} /* main */

View File

@ -44,27 +44,23 @@
*/
static int jpip_to_jp2(char *argv[])
{
jpip_dec_param_t *dec;
jpip_dec_param_t *dec;
dec = init_jpipdecoder( OPJ_TRUE);
if(!( fread_jpip( argv[1], dec)))
return 1;
decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec)))
return 1;
dec = init_jpipdecoder(OPJ_TRUE);
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */
if (!(fread_jpip(argv[1], dec))) {
destroy_jpipdecoder(&dec);
return 1;
}
destroy_jpipdecoder( &dec);
decode_jpip(dec);
if (!(fwrite_jp2k(argv[2], dec))) {
destroy_jpipdecoder(&dec);
return 1;
}
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */
destroy_jpipdecoder(&dec);
return 0;
return 0;
}
/*! \file
@ -80,50 +76,49 @@ static int jpip_to_jp2(char *argv[])
*/
static int jpip_to_j2k(char *argv[])
{
jpip_dec_param_t *dec;
dec = init_jpipdecoder(OPJ_FALSE);
if (!(fread_jpip(argv[1], dec))) {
destroy_jpipdecoder(&dec);
return 1;
}
decode_jpip(dec);
if (!(fwrite_jp2k(argv[2], dec))) {
destroy_jpipdecoder(&dec);
return 1;
}
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */
destroy_jpipdecoder(&dec);
return 0;
}
int main(int argc, char *argv[])
{
char *ext;
if (argc < 3) {
fprintf(stderr, "Too few arguments:\n");
fprintf(stderr, " - input jpt or jpp file\n");
fprintf(stderr, " - output j2k file\n");
return 1;
}
ext = strrchr(argv[2], '.');
if (ext) {
/* strcasecmp ? */
if (strcmp(ext, ".jp2") == 0) {
return jpip_to_jp2(argv);
}
if (strcmp(ext, ".j2k") == 0) {
return jpip_to_j2k(argv);
}
}
fprintf(stderr, "Invalid file extension for output file: %s\n", argv[2]);
jpip_dec_param_t *dec;
dec = init_jpipdecoder( OPJ_FALSE);
if(!( fread_jpip( argv[1], dec)))
return 1;
decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec)))
return 1;
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */
destroy_jpipdecoder( &dec);
return 0;
}
int main(int argc,char *argv[])
{
char *ext;
if( argc < 3){
fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output j2k file\n");
return 1;
}
ext = strrchr( argv[2], '.' );
if( ext )
{
/* strcasecmp ? */
if( strcmp(ext, ".jp2" ) == 0 )
{
return jpip_to_jp2(argv);
}
if( strcmp(ext, ".j2k" ) == 0 )
{
return jpip_to_j2k(argv);
}
}
fprintf( stderr, "Invalid file extension for output file: %s\n", argv[2]);
return 1;
}

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* Copyright (c) 2010-2011, Kaori Hagihara
* Copyright (c) 2011, Lucian Corlaciu, GSoC
* All rights reserved.
*
@ -41,7 +41,7 @@
*
* Note: JP2 files are stored in the working directory of opj_server\n
* Check README for the JP2 Encoding\n
*
*
* We tested this software with a virtual server running on the same Linux machine as the clients.
*/
@ -60,72 +60,69 @@ WSADATA initialisation_win32;
#endif /*_WIN32*/
int main(void)
{
server_record_t *server_record;
{
server_record_t *server_record;
#ifdef SERVER
char *query_string;
char *query_string;
#endif
#ifdef _WIN32
int erreur = WSAStartup(MAKEWORD(2, 2), &initialisation_win32);
if (erreur != 0) {
fprintf(stderr, "Erreur initialisation Winsock error : %d %d\n", erreur,
WSAGetLastError());
} else {
fprintf(stderr, "Initialisation Winsock\n");
}
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
fprintf( stderr, "Initialisation Winsock\n");
#endif /*_WIN32*/
server_record = init_JPIPserver(60000, 0);
server_record = init_JPIPserver( 60000, 0);
#ifdef SERVER
while (FCGI_Accept() >= 0)
while(FCGI_Accept() >= 0)
#else
char query_string[128];
while (fgets(query_string, 128, stdin) && query_string[0] != '\n')
char query_string[128];
while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
#endif
{
QR_t *qr;
OPJ_BOOL parse_status;
QR_t *qr;
OPJ_BOOL parse_status;
#ifdef SERVER
query_string = getenv("QUERY_STRING");
#ifdef SERVER
query_string = getenv("QUERY_STRING");
#endif /*SERVER*/
if (strcmp(query_string, QUIT_SIGNAL) == 0) {
break;
}
qr = parse_querystring(query_string);
parse_status = process_JPIPrequest(server_record, qr);
if( strcmp( query_string, QUIT_SIGNAL) == 0)
break;
qr = parse_querystring( query_string);
parse_status = process_JPIPrequest( server_record, qr);
#ifndef SERVER
local_log(OPJ_TRUE, OPJ_TRUE, parse_status, OPJ_FALSE, qr, server_record);
local_log( OPJ_TRUE, OPJ_TRUE, parse_status, OPJ_FALSE, qr, server_record);
#endif
if (parse_status) {
send_responsedata(server_record, qr);
} else {
fprintf(FCGI_stderr, "Error: JPIP request failed\n");
fprintf(FCGI_stdout, "\r\n");
}
end_QRprocess(server_record, &qr);
if( parse_status)
send_responsedata( server_record, qr);
else{
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
fprintf( FCGI_stdout, "\r\n");
}
end_QRprocess( server_record, &qr);
}
fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
fprintf(FCGI_stderr, "JPIP server terminated by a client request\n");
terminate_JPIPserver(&server_record);
terminate_JPIPserver( &server_record);
#ifdef _WIN32
if (WSACleanup() != 0) {
fprintf(stderr, "\nError in WSACleanup : %d %d", erreur, WSAGetLastError());
} else {
fprintf(stderr, "\nWSACleanup OK\n");
}
if( WSACleanup() != 0){
fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
}else{
fprintf( stderr, "\nWSACleanup OK\n");
}
#endif
return 0;
return 0;
}

View File

@ -0,0 +1,62 @@
# jpwl apps
# First thing define the common source:
set(common_SRCS
convert.c
index.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c
)
# Headers file are located here:
include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h
${OPENJPEG_SOURCE_DIR}/src/lib/openmj2
${OPENJPEG_SOURCE_DIR}/src/bin/common
${LCMS_INCLUDE_DIRNAME}
${Z_INCLUDE_DIRNAME}
${PNG_INCLUDE_DIRNAME}
${TIFF_INCLUDE_DIRNAME}
)
if(WIN32)
if(BUILD_SHARED_LIBS)
add_definitions(-DOPJ_EXPORTS)
else()
add_definitions(-DOPJ_STATIC)
endif()
endif()
add_definitions(-DOPJ_USE_LEGACY)
foreach(exe decompress compress)
set(jpwl_exe opj_jpwl_${exe})
set(jp2_exe opj_${exe})
add_executable(${jpwl_exe}
#../jp2/${jp2_exe}.c
${jpwl_exe}.c
${common_SRCS}
)
set_property(
TARGET ${jpwl_exe}
APPEND PROPERTY COMPILE_DEFINITIONS USE_JPWL
)
target_link_libraries(${jpwl_exe} openjpwl
${LCMS_LIBNAME} ${PNG_LIBNAME} ${TIFF_LIBNAME})
# To support universal exe:
if(ZLIB_FOUND AND APPLE)
target_link_libraries(${jpwl_exe} z)
else(ZLIB_FOUND AND APPLE)
target_link_libraries(${jpwl_exe} ${Z_LIBNAME})
endif()
if(UNIX)
target_link_libraries(${jpwl_exe} m)
endif()
install(TARGETS ${jpwl_exe}
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
endforeach()

3572
src/bin/jpwl/convert.c Normal file

File diff suppressed because it is too large Load Diff

88
src/bin/jpwl/convert.h Normal file
View File

@ -0,0 +1,88 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __J2K_CONVERT_H
#define __J2K_CONVERT_H
/**@name RAW image encoding parameters */
/*@{*/
typedef struct raw_cparameters {
/** width of the raw image */
int rawWidth;
/** height of the raw image */
int rawHeight;
/** components of the raw image */
int rawComp;
/** bit depth of the raw image */
int rawBitDepth;
/** signed/unsigned raw image */
opj_bool rawSigned;
/*@}*/
} raw_cparameters_t;
/* TGA conversion */
opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters);
int imagetotga(opj_image_t * image, const char *outfile);
/* BMP conversion */
opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters);
int imagetobmp(opj_image_t *image, const char *outfile);
/* TIFF conversion*/
opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters);
int imagetotif(opj_image_t *image, const char *outfile);
/**
Load a single image component encoded in PGX file format
@param filename Name of the PGX file to load
@param parameters *List ?*
@return Returns a greyscale image if successful, returns NULL otherwise
*/
opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters);
int imagetopgx(opj_image_t *image, const char *outfile);
opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters);
int imagetopnm(opj_image_t *image, const char *outfile);
/* RAW conversion */
int imagetoraw(opj_image_t * image, const char *outfile);
opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp);
/* PNG conversion*/
extern int imagetopng(opj_image_t *image, const char *write_idf);
extern opj_image_t* pngtoimage(const char *filename, opj_cparameters_t *parameters);
#endif /* __J2K_CONVERT_H */

396
src/bin/jpwl/index.c Normal file
View File

@ -0,0 +1,396 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "openjpeg.h"
#include "index.h"
/* ------------------------------------------------------------------------------------ */
/**
Write a structured index to a file
@param cstr_info Codestream information
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL;
double total_disto = 0;
/* UniPG>> */
int tilepartno;
char disto_on, numpix_on;
#ifdef USE_JPWL
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0;
#endif /* USE_JPWL */
/* <<UniPG */
if (!cstr_info)
return 1;
stream = fopen(index, "w");
if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1;
}
if (cstr_info->tile[0].distotile)
disto_on = 1;
else
disto_on = 0;
if (cstr_info->tile[0].numpix)
numpix_on = 1;
else
numpix_on = 0;
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);
fprintf(stream, "%d\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
}
fprintf(stream, "\n");
/* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size);
fprintf(stream, "\nINFO ON TILES\n");
fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
if (disto_on)
fprintf(stream," disto");
if (numpix_on)
fprintf(stream," nbpix");
if (disto_on && numpix_on)
fprintf(stream," disto/nbpix");
fprintf(stream, "\n");
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos,
cstr_info->tile[tileno].num_tps);
if (disto_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile);
if (numpix_on)
fprintf(stream," %9d", cstr_info->tile[tileno].numpix);
if (disto_on && numpix_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);
fprintf(stream, "\n");
}
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
int start_pos, end_ph_pos, end_pos;
double disto = 0;
int max_numdecompos = 0;
pack_nb = 0;
for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno])
max_numdecompos = cstr_info->numdecompos[compno];
}
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
tilepartno, tileno,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,
cstr_info->tile[tileno].tp[tilepartno].tp_end_header,
cstr_info->tile[tileno].tp[tilepartno].tp_end_pos
);
if (cstr_info->prog == LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max;
if (resno > cstr_info->numdecompos[compno])
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %7d %5d %6d %6d %6d %6d %7d",
pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* LRCP */
else if (cstr_info->prog == RLCP) { /* RLCP */
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max;
if (resno > cstr_info->numdecompos[compno])
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %7d",
pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* RLCP */
else if (cstr_info->prog == RPCL) { /* RPCL */
fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) {
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (resno > cstr_info->numdecompos[compno])
break;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %7d",
pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* precno */
} /* compno */
} /* resno */
} /* RPCL */
else if (cstr_info->prog == PCRL) { /* PCRL */
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (precno = 0; precno < max_numprec; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d",
pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* compno */
} /* precno */
} /* PCRL */
else { /* CPRL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
for (precno = 0; precno < max_numprec; precno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d",
pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* precno */
} /* compno */
} /* CPRL */
} /* tileno */
if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
}
/* UniPG>> */
/* print the markers' list */
if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n");
for (x = 0; x < cstr_info->marknum; x++)
fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
}
/* <<UniPG */
fclose(stream);
fprintf(stderr,"Generated index file %s\n", index);
return 0;
}

View File

@ -1,10 +1,12 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2017, IntoPIX SA <support@intopix.com>
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -28,20 +30,25 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OPJ_COMMMON_H
#define OPJ_COMMMON_H
/*
==========================================================
Common constants shared among several modules
==========================================================
#ifndef __J2K_INDEX_H
#define __J2K_INDEX_H
#ifdef __cplusplus
extern "C" {
#endif
/**
Write a structured index to a file
@param cstr_info Codestream information
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
#define OPJ_COMMON_CBLK_DATA_EXTRA 2 /**< Margin for a fake FFFF marker */
int write_index_file(opj_codestream_info_t *cstr_info, char *index);
#ifdef __cplusplus
}
#endif
#define OPJ_COMP_PARAM_DEFAULT_CBLOCKW 64
#define OPJ_COMP_PARAM_DEFAULT_CBLOCKH 64
#define OPJ_COMP_PARAM_DEFAULT_PROG_ORDER OPJ_LRCP
#define OPJ_COMP_PARAM_DEFAULT_NUMRESOLUTION 6
#endif /* __J2K_INDEX_H */
#endif /* OPJ_COMMMON_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,860 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifdef _WIN32
#include "windirent.h"
#else
#include <dirent.h>
#endif /* _WIN32 */
#ifdef _WIN32
#include <windows.h>
#else
#include <strings.h>
#define _stricmp strcasecmp
#define _strnicmp strncasecmp
#endif /* _WIN32 */
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "opj_getopt.h"
#include "convert.h"
#include "index.h"
#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#endif
#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
#endif
#include "color.h"
#include "format_defs.h"
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
char *filename_buf;
/** Pointer to the buffer*/
char **filename;
}dircnt_t;
typedef struct img_folder{
/** The directory path of the folder containing input images*/
char *imgdirpath;
/** Output format*/
const char *out_format;
/** Enable option*/
char set_imgdir;
/** Enable Cod Format for output*/
char set_out_format;
}img_fol_t;
void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
/* UniPG>> */
fprintf(stdout,"List of parameters for the JPEG 2000 "
#ifdef USE_JPWL
"+ JPWL "
#endif /* USE_JPWL */
"decoder:\n");
/* <<UniPG */
fprintf(stdout,"\n");
fprintf(stdout,"\n");
fprintf(stdout," -ImgDir \n");
fprintf(stdout," Image file Directory path \n");
fprintf(stdout," -OutFor \n");
fprintf(stdout," REQUIRED only if -ImgDir is used\n");
fprintf(stdout," Need to specify only format without filename <BMP> \n");
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, PNG, BMP, TIF, RAW and TGA formats\n");
fprintf(stdout," -i <compressed file>\n");
fprintf(stdout," REQUIRED only if an Input image directory not specified\n");
fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n");
fprintf(stdout," is identified based on its suffix.\n");
fprintf(stdout," -o <decompressed file>\n");
fprintf(stdout," REQUIRED\n");
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, PNG, BMP, TIF, RAW and TGA files\n");
fprintf(stdout," Binary data is written to the file (not ascii). If a PGX\n");
fprintf(stdout," filename is given, there will be as many output files as there are\n");
fprintf(stdout," components: an indice starting from 0 will then be appended to the\n");
fprintf(stdout," output filename, just before the \"pgx\" extension. If a PGM filename\n");
fprintf(stdout," is given and there are more than one component, only the first component\n");
fprintf(stdout," will be written to the file.\n");
fprintf(stdout," -r <reduce factor>\n");
fprintf(stdout," Set the number of highest resolution levels to be discarded. The\n");
fprintf(stdout," image resolution is effectively divided by 2 to the power of the\n");
fprintf(stdout," number of discarded levels. The reduce factor is limited by the\n");
fprintf(stdout," smallest total number of decomposition levels among tiles.\n");
fprintf(stdout," -l <number of quality layers to decode>\n");
fprintf(stdout," Set the maximum number of quality layers to decode. If there are\n");
fprintf(stdout," less quality layers than the specified number, all the quality layers\n");
fprintf(stdout," are decoded.\n");
fprintf(stdout," -x \n");
fprintf(stdout," Create an index file *.Idx (-x index_name.Idx) \n");
fprintf(stdout,"\n");
/* UniPG>> */
#ifdef USE_JPWL
fprintf(stdout," -W <options>\n");
fprintf(stdout," Activates the JPWL correction capability, if the codestream complies.\n");
fprintf(stdout," Options can be a comma separated list of <param=val> tokens:\n");
fprintf(stdout," c, c=numcomps\n");
fprintf(stdout," numcomps is the number of expected components in the codestream\n");
fprintf(stdout," (search of first EPB rely upon this, default is %d)\n", JPWL_EXPECTED_COMPONENTS);
#endif /* USE_JPWL */
/* <<UniPG */
fprintf(stdout,"\n");
}
/* -------------------------------------------------------------------------- */
int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
int num_images = 0;
/*Reading the input images from given input directory*/
dir= opendir(imgdirpath);
if(!dir){
fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0;
}
while((content=readdir(dir))!=NULL){
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue;
num_images++;
}
return num_images;
}
int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
/*Reading the input images from given input directory*/
dir= opendir(imgdirpath);
if(!dir){
fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1;
}else {
fprintf(stderr,"Folder opened successfully\n");
}
while((content=readdir(dir))!=NULL){
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue;
strcpy(dirptr->filename[i],content->d_name);
i++;
}
return 0;
}
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
char * ext = strrchr(filename, '.');
if (ext == NULL)
return -1;
ext++;
if(ext) {
for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
if(_strnicmp(ext, extension[i], 3) == 0) {
return format[i];
}
}
}
return -1;
}
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]="";
strcpy(image_filename,dirptr->filename[imageno]);
fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename);
parameters->decod_format = get_file_format(image_filename);
if (parameters->decod_format == -1)
return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
strncpy(parameters->infile, infilename, sizeof(infilename));
/*Set output file*/
strcpy(temp_ofname,strtok(image_filename,"."));
while((temp_p = strtok(NULL,".")) != NULL){
strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p);
}
if(img_fol->set_out_format==1){
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
strncpy(parameters->outfile, outfilename, sizeof(outfilename));
}
return 0;
}
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
/* parse the command line */
int totlen, c;
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'},
};
const char optlist[] = "i:o:r:l:x:"
/* UniPG>> */
#ifdef USE_JPWL
"W:"
#endif /* USE_JPWL */
/* <<UniPG */
"h" ;
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case J2K_CFMT:
case JP2_CFMT:
case JPT_CFMT:
break;
default:
fprintf(stderr,
"!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n",
infile);
return 1;
}
strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
}
break;
/* ----------------------------------------------------- */
case 'o': /* output file */
{
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case PGX_DFMT:
case PXM_DFMT:
case BMP_DFMT:
case TIF_DFMT:
case RAW_DFMT:
case TGA_DFMT:
case PNG_DFMT:
break;
default:
fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outfile);
return 1;
}
strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
}
break;
/* ----------------------------------------------------- */
case 'O': /* output format */
{
char outformat[50];
char *of = opj_optarg;
sprintf(outformat,".%s",of);
img_fol->set_out_format = 1;
parameters->cod_format = get_file_format(outformat);
switch(parameters->cod_format) {
case PGX_DFMT:
img_fol->out_format = "pgx";
break;
case PXM_DFMT:
img_fol->out_format = "ppm";
break;
case BMP_DFMT:
img_fol->out_format = "bmp";
break;
case TIF_DFMT:
img_fol->out_format = "tif";
break;
case RAW_DFMT:
img_fol->out_format = "raw";
break;
case TGA_DFMT:
img_fol->out_format = "raw";
break;
case PNG_DFMT:
img_fol->out_format = "png";
break;
default:
fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outformat);
return 1;
break;
}
}
break;
/* ----------------------------------------------------- */
case 'r': /* reduce option */
{
sscanf(opj_optarg, "%d", &parameters->cp_reduce);
}
break;
/* ----------------------------------------------------- */
case 'l': /* layering option */
{
sscanf(opj_optarg, "%d", &parameters->cp_layer);
}
break;
/* ----------------------------------------------------- */
case 'h': /* display an help description */
decode_help_display();
return 1;
/* ------------------------------------------------------ */
case 'y': /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */
case 'x': /* Creation of index file */
{
char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
}
break;
/* ----------------------------------------------------- */
/* UniPG>> */
#ifdef USE_JPWL
case 'W': /* activate JPWL correction */
{
char *token = NULL;
token = strtok(opj_optarg, ",");
while(token != NULL) {
/* search expected number of components */
if (*token == 'c') {
static int compno;
compno = JPWL_EXPECTED_COMPONENTS; /* predefined no. of components */
if(sscanf(token, "c=%d", &compno) == 1) {
/* Specified */
if ((compno < 1) || (compno > 256)) {
fprintf(stderr, "ERROR -> invalid number of components c = %d\n", compno);
return 1;
}
parameters->jpwl_exp_comps = compno;
} else if (!strcmp(token, "c")) {
/* default */
parameters->jpwl_exp_comps = compno; /* auto for default size */
} else {
fprintf(stderr, "ERROR -> invalid components specified = %s\n", token);
return 1;
};
}
/* search maximum number of tiles */
if (*token == 't') {
static int tileno;
tileno = JPWL_MAXIMUM_TILES; /* maximum no. of tiles */
if(sscanf(token, "t=%d", &tileno) == 1) {
/* Specified */
if ((tileno < 1) || (tileno > JPWL_MAXIMUM_TILES)) {
fprintf(stderr, "ERROR -> invalid number of tiles t = %d\n", tileno);
return 1;
}
parameters->jpwl_max_tiles = tileno;
} else if (!strcmp(token, "t")) {
/* default */
parameters->jpwl_max_tiles = tileno; /* auto for default size */
} else {
fprintf(stderr, "ERROR -> invalid tiles specified = %s\n", token);
return 1;
};
}
/* next token or bust */
token = strtok(NULL, ",");
};
parameters->jpwl_correct = OPJ_TRUE;
fprintf(stdout, "JPWL correction capability activated\n");
fprintf(stdout, "- expecting %d components\n", parameters->jpwl_exp_comps);
}
break;
#endif /* USE_JPWL */
/* <<UniPG */
/* ----------------------------------------------------- */
default:
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
break;
}
}while(c != -1);
/* check for possible errors */
if(img_fol->set_imgdir==1){
if(!(parameters->infile[0]==0)){
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
return 1;
}
if(img_fol->set_out_format == 0){
fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
return 1;
}
if(!((parameters->outfile[0] == 0))){
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
return 1;
}
}else{
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "Example: %s -i image.j2k -o image.pgm\n",argv[0]);
fprintf(stderr, " Try: %s -h\n",argv[0]);
return 1;
}
}
return 0;
}
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting no client object
*/
void info_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
opj_dparameters_t parameters; /* decompression parameters */
img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *image = NULL;
FILE *fsrc = NULL;
unsigned char *src = NULL;
int file_length;
int num_images;
int i,imageno;
dircnt_t *dirptr = NULL;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL;
opj_codestream_info_t cstr_info; /* Codestream information structure */
char indexfilename[OPJ_PATH_LEN]; /* index file name */
/* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* Initialize indexfilename and img_fol */
*indexfilename = 0;
memset(&img_fol,0,sizeof(img_fol_t));
/* parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol, indexfilename) == 1) {
return 1;
}
/* Initialize reading of directory */
if(img_fol.set_imgdir==1){
num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
if(!dirptr->filename_buf){
return 1;
}
for(i=0;i<num_images;i++){
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
}
}
if(load_images(dirptr,img_fol.imgdirpath)==1){
return 1;
}
if (num_images==0){
fprintf(stdout,"Folder is empty\n");
return 1;
}
}else{
num_images=1;
}
/*Encoding image one by one*/
for(imageno = 0; imageno < num_images ; imageno++) {
image = NULL;
fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n");
continue;
}
}
/* read the input file and put it in memory */
/* ---------------------------------------- */
fsrc = fopen(parameters.infile, "rb");
if (!fsrc) {
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
return 1;
}
fseek(fsrc, 0, SEEK_END);
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length);
if (fread(src, 1, file_length, fsrc) != (size_t)file_length)
{
free(src);
fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
return 1;
}
fclose(fsrc);
/* decode the code-stream */
/* ---------------------- */
switch(parameters.decod_format) {
case J2K_CFMT:
{
/* JPEG-2000 codestream */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
if (*indexfilename) /* If need to extract codestream information*/
image = opj_decode_with_info(dinfo, cio, &cstr_info);
else
image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
free(src);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
}
}
}
break;
case JP2_CFMT:
{
/* JPEG 2000 compressed image data */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_JP2);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using the current image and user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
if (*indexfilename) /* If need to extract codestream information*/
image = opj_decode_with_info(dinfo, cio, &cstr_info);
else
image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
free(src);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
}
}
}
break;
case JPT_CFMT:
{
/* JPEG 2000, JPIP */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_JPT);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
if (*indexfilename) /* If need to extract codestream information*/
image = opj_decode_with_info(dinfo, cio, &cstr_info);
else
image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
free(src);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
}
}
}
break;
default:
fprintf(stderr, "skipping file..\n");
continue;
}
/* free the memory containing the code-stream */
free(src);
src = NULL;
if(image->color_space == CLRSPC_SYCC)
{
color_sycc_to_rgb(image);
}
if(image->icc_profile_buf)
{
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(image);
#endif
free(image->icc_profile_buf);
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
}
/* create output image */
/* ------------------- */
switch (parameters.cod_format) {
case PXM_DFMT: /* PNM PGM PPM */
if (imagetopnm(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
case PGX_DFMT: /* PGX */
if(imagetopgx(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
case BMP_DFMT: /* BMP */
if(imagetobmp(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)){
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
case TGA_DFMT: /* TGA */
if(imagetotga(image, parameters.outfile)){
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* OPJ_HAVE_LIBPNG */
/* Can happen if output file is TIFF or PNG
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
default:
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
}
/* free remaining structures */
if(dinfo) {
opj_destroy_decompress(dinfo);
}
/* free codestream information structure */
if (*indexfilename)
opj_destroy_cstr_info(&cstr_info);
/* free image data structure */
opj_image_destroy(image);
}
return 0;
}
/*end main*/

679
src/bin/jpwl/windirent.h Normal file
View File

@ -0,0 +1,679 @@
/*
* uce-dirent.h - operating system independent dirent implementation
*
* Copyright (C) 1998-2002 Toni Ronkko
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
*
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
*
* $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $
*
* $Log: uce-dirent.h,v $
* Revision 1.7 2002/05/13 10:48:35 tr
* embedded some source code directly to the header so that no source
* modules need to be included in the MS Visual C project using the
* interface, removed all the dependencies to other headers of the `uce'
* library so that the header can be made public
*
* Revision 1.6 2002/04/12 16:22:04 tr
* Unified Compiling Environment (UCE) replaced `std' library
*
* Revision 1.5 2001/07/20 16:33:40 tr
* moved to `std' library and re-named defines accordingly
*
* Revision 1.4 2001/07/10 16:47:18 tronkko
* revised comments
*
* Revision 1.3 2001/01/11 13:16:43 tr
* using ``uce-machine.h'' for finding out defines such as `FREEBSD'
*
* Revision 1.2 2000/10/08 16:00:41 tr
* copy of FreeBSD man page
*
* Revision 1.1 2000/07/10 05:53:16 tr
* Initial revision
*
* Revision 1.2 1998/07/19 18:29:14 tr
* Added error reporting capabilities and some asserts.
*
* Revision 1.1 1998/07/04 16:27:51 tr
* Initial revision
*
*
* MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle
* include directives inside #if..#endif block those are never entered.
* Since this header ought to compile in many different operating systems,
* there had to be several conditional blocks that are compiled only in
* operating systems for what they were designed for. MSVC 1.0 cannot
* handle inclusion of sys/dir.h in a part that is compiled only in Apollo
* operating system. To fix the problem you need to insert DIR.H into
* SYSINCL.DAT located in MSVC\BIN directory and restart visual C++.
* Consult manuals for more informaton about the problem.
*
* Since many UNIX systems have dirent.h we assume to have one also.
* However, if your UNIX system does not have dirent.h you can download one
* for example at: http://ftp.uni-mannheim.de/ftp/GNU/dirent/dirent.tar.gz.
* You can also see if you have one of dirent.h, direct.h, dir.h, ndir.h,
* sys/dir.h and sys/ndir.h somewhere. Try defining HAVE_DIRENT_H,
* HAVE_DIRECT_H, HAVE_DIR_H, HAVE_NDIR_H, HAVE_SYS_DIR_H and
* HAVE_SYS_NDIR_H according to the files found.
*/
#ifndef DIRENT_H
#define DIRENT_H
#define DIRENT_H_INCLUDED
/* find out platform */
#if defined(MSDOS) /* MS-DOS */
#elif defined(__MSDOS__) /* Turbo C/Borland */
# define MSDOS
#elif defined(__DOS__) /* Watcom */
# define MSDOS
#endif
#if defined(WIN32) /* MS-Windows */
#elif defined(__NT__) /* Watcom */
# define WIN32
#elif defined(_WIN32) /* Microsoft */
# define WIN32
#elif defined(__WIN32__) /* Borland */
# define WIN32
#endif
/*
* See what kind of dirent interface we have unless autoconf has already
* determinated that.
*/
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H
# define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */
# define HAVE_SYS_DIR_H
# elif defined(__hpux) /* HP-UX */
# define HAVE_DIRENT_H
# elif (defined(__alpha) || defined(__alpha__)) && !defined(__linux__) /* Alpha OSF1 */
# error "not implemented"
# elif defined(__sgi) /* Silicon Graphics */
# define HAVE_DIRENT_H
# elif defined(sun) || defined(__sun) /* Sun Solaris */
# define HAVE_DIRENT_H
# elif defined(__FreeBSD__) /* FreeBSD */
# define HAVE_DIRENT_H
# elif defined(__linux__) /* Linux */
# define HAVE_DIRENT_H
# elif defined(__GNUC__) /* GNU C/C++ */
# define HAVE_DIRENT_H
# else
# error "not implemented"
# endif
#endif
/* include proper interface headers */
#if defined(HAVE_DIRENT_H)
# include <dirent.h>
# ifdef FREEBSD
# define NAMLEN(dp) ((int)((dp)->d_namlen))
# else
# define NAMLEN(dp) ((int)(strlen((dp)->d_name)))
# endif
#elif defined(HAVE_NDIR_H)
# include <ndir.h>
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(HAVE_SYS_NDIR_H)
# include <sys/ndir.h>
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(HAVE_DIRECT_H)
# include <direct.h>
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(HAVE_DIR_H)
# include <dir.h>
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(HAVE_SYS_DIR_H)
# include <sys/types.h>
# include <sys/dir.h>
# ifndef dirent
# define dirent direct
# endif
# define NAMLEN(dp) ((int)((dp)->d_namlen))
#elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlaying directory interface to be used */
# if defined(WIN32)
# define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS)
# define DIRENT_MSDOS_INTERFACE
# else
# error "missing native dirent interface"
# endif
/*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h>
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (MAX_PATH)
# endif
/*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h>
/* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT))
# endif
# if !defined(_find_t)
# define _find_t find_t
# endif
/* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT))
# endif
# define DIRENT_USE_FFBLK
/* MSVC */
# elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12)
# endif
/* Watcom */
# elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__)
# define DIRENT_MAXNAMLEN (255)
# else
# define DIRENT_MAXNAMLEN (12)
# endif
# endif
# endif
# endif
/*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN
# endif
# if NAME_MAX < DIRENT_MAXNAMLEN
# error "assertion failed: NAME_MAX >= DIRENT_MAXNAMLEN"
# endif
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE) /*WIN32*/
WIN32_FIND_DATA data;
# elif defined(DIRENT_MSDOS_INTERFACE) /*MSDOS*/
# if defined(DIRENT_USE_FFBLK)
struct ffblk data;
# else
struct _find_t data;
# endif
# endif
} dirent;
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
char *dirname; /* directory being scanned */
dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE)
# endif
} DIR;
# ifdef __cplusplus
extern "C" {
# endif
/* supply prototypes for dirent functions */
static DIR *opendir (const char *dirname);
static struct dirent *readdir (DIR *dirp);
static int closedir (DIR *dirp);
static void rewinddir (DIR *dirp);
/*
* Implement dirent interface as static functions so that the user does not
* need to change his project in any way to use dirent function. With this
* it is sufficient to include this very header from source modules using
* dirent functions and the functions will be pulled in automatically.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
/* use ffblk instead of _find_t if requested */
#if defined(DIRENT_USE_FFBLK)
# define _A_ARCH (FA_ARCH)
# define _A_HIDDEN (FA_HIDDEN)
# define _A_NORMAL (0)
# define _A_RDONLY (FA_RDONLY)
# define _A_SUBDIR (FA_DIREC)
# define _A_SYSTEM (FA_SYSTEM)
# define _A_VOLID (FA_LABEL)
# define _dos_findnext(dest) findnext(dest)
# define _dos_findfirst(name,flags,dest) findfirst(name,dest,flags)
#endif
static int _initdir (DIR *p);
static const char *_getdirname (const struct dirent *dp);
static void _setdirname (struct DIR *dirp);
/*
* <function name="opendir">
* <intro>open directory stream for reading
* <syntax>DIR *opendir (const char *dirname);
*
* <desc>Open named directory stream for read and return pointer to the
* internal working area that is used for retrieving individual directory
* entries. The internal working area has no fields of your interest.
*
* <ret>Returns a pointer to the internal working area or NULL in case the
* directory stream could not be opened. Global `errno' variable will set
* in case of error as follows:
*
* <table>
* [EACESS |Permission denied.
* [EMFILE |Too many open files used by the process.
* [ENFILE |Too many open files in system.
* [ENOENT |Directory does not exist.
* [ENOMEM |Insufficient memory.
* [ENOTDIR |dirname does not refer to directory. This value is not
* reliable on MS-DOS and MS-Windows platforms. Many
* implementations return ENOENT even when the name refers to a
* file.]
* </table>
* </function>
*/
static DIR *opendir(const char *dirname)
{
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
strcpy (p, "*"); /*scan files with and without extension in win32*/
# else
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
}
}
return dirp;
}
/*
* <function name="readdir">
* <intro>read a directory entry
* <syntax>struct dirent *readdir (DIR *dirp);
*
* <desc>Read individual directory entry and return pointer to a structure
* containing the name of the entry. Individual directory entries returned
* include normal files, sub-directories, pseudo-directories "." and ".."
* and also volume labels, hidden files and system files in MS-DOS and
* MS-Windows. You might want to use stat(2) function to determinate which
* one are you dealing with. Many dirent implementations already contain
* equivalent information in dirent structure but you cannot depend on
* this.
*
* The dirent structure contains several system dependent fields that
* generally have no interest to you. The only interesting one is char
* d_name[] that is also portable across different systems. The d_name
* field contains the name of the directory entry without leading path.
* While d_name is portable across different systems the actual storage
* capacity of d_name varies from system to system and there is no portable
* way to find out it at compile time as different systems define the
* capacity of d_name with different macros and some systems do not define
* capacity at all (besides actual declaration of the field). If you really
* need to find out storage capacity of d_name then you might want to try
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard although
* there are many MS-DOS and MS-Windows implementations those do not define
* it. There are also systems that declare d_name as "char d_name[1]" and
* then allocate suitable amount of memory at run-time. Thanks to Alain
* Decamps (Alain.Decamps@advalvas.be) for pointing it out to me.
*
* This all leads to the fact that it is difficult to allocate space
* for the directory names when the very same program is being compiled on
* number of operating systems. Therefore I suggest that you always
* allocate space for directory names dynamically.
*
* <ret>
* Returns a pointer to a structure containing name of the directory entry
* in `d_name' field or NULL if there was an error. In case of an error the
* global `errno' variable will set as follows:
*
* <table>
* [EBADF |dir parameter refers to an invalid directory stream. This value
* is not set reliably on all implementations.]
* </table>
* </function>
*/
static struct dirent *
readdir (DIR *dirp)
{
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
#endif
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, we have to
* save the first file when opening the stream and later we have to
* return the saved entry when the user tries to read the first entry.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
# endif
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
}
/*
* <function name="closedir">
* <intro>close directory stream.
* <syntax>int closedir (DIR *dirp);
*
* <desc>Close directory stream opened by the `opendir' function. Close of
* directory stream invalidates the DIR structure as well as previously read
* dirent entry.
*
* <ret>The function typically returns 0 on success and -1 on failure but
* the function may be declared to return void on same systems. At least
* Borland C/C++ and some UNIX implementations use void as a return type.
* The dirent wrapper tries to define VOID_CLOSEDIR whenever closedir is
* known to return nothing. The very same definition is made by the GNU
* autoconf if you happen to use it.
*
* The global `errno' variable will set to EBADF in case of error.
* </function>
*/
static int
closedir (DIR *dirp)
{
int retcode = 0;
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
}
}
#endif
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE;
# endif
free (dirp);
return retcode;
}
/*
* <function name="rewinddir">
* <intro>rewind directory stream to the beginning
* <syntax>void rewinddir (DIR *dirp);
*
* <desc>Rewind directory stream to the beginning so that the next call of
* readdir() returns the very first directory entry again. However, note
* that next call of readdir() may not return the same directory entry as it
* did in first time. The directory stream may have been affected by newly
* created files.
*
* Almost every dirent implementation ensure that rewinddir will update
* the directory stream to reflect any changes made to the directory entries
* since the previous ``opendir'' or ``rewinddir'' call. Keep an eye on
* this if your program depends on the feature. I know at least one dirent
* implementation where you are required to close and re-open the stream to
* see the changes.
*
* <ret>Returns nothing. If something went wrong while rewinding, you will
* notice it later when you try to retrieve the first directory entry.
*/
static void
rewinddir (DIR *dirp)
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
}
}
#endif
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
}
/*
* Open native directory stream object and retrieve first file.
* Be sure to close previous stream before opening new one.
*/
static int
_initdir (DIR *dirp)
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
# endif
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
}
/*
* Return implementation dependent name of the current directory entry.
*/
static const char *
_getdirname (const struct dirent *dp)
{
#if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name;
#else
return dp->data.name;
#endif
}
/*
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
}
# ifdef __cplusplus
}
# endif
# define NAMLEN(dp) ((int)(strlen((dp)->d_name)))
#else
# error "missing dirent interface"
#endif
#endif /*DIRENT_H*/

View File

@ -0,0 +1,47 @@
# Makefile for the MJ2 codecs of the OpenJPEG library: frames_to_mj2, mj2_to_frames, extract_j2k_from_mj2 and wrap_j2k_in_mj2
set(common_SRCS ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c)
if(WIN32)
if(BUILD_SHARED_LIBS)
add_definitions(-DOPJ_EXPORTS)
else()
add_definitions(-DOPJ_STATIC)
endif()
endif()
# Headers file are located here:
include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h
${OPENJPEG_SOURCE_DIR}/src/lib/openmj2
${OPENJPEG_SOURCE_DIR}/src/bin/common
${LCMS_INCLUDE_DIRNAME}
)
foreach(exe
opj_mj2_wrap
opj_mj2_extract
opj_mj2_decompress
opj_mj2_compress
)
add_definitions(-DOPJ_USE_LEGACY)
add_executable(${exe}
${exe}.c
${common_SRCS}
${MJ2_SRCS}
${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c
)
set_property(
TARGET ${exe}
APPEND PROPERTY COMPILE_DEFINITIONS USE_MJ2
)
target_link_libraries(${exe} ${LCMS_LIBNAME} openmj2)
if(UNIX)
target_link_libraries(${exe} m)
endif()
install(TARGETS ${exe}
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR})
endforeach()

2181
src/bin/mj2/meta_out.c Normal file

File diff suppressed because it is too large Load Diff

13
src/bin/mj2/meta_out.h Normal file
View File

@ -0,0 +1,13 @@
/* meta_out.h */
/* Dump MJ2, JP2 metadata (partial so far) to xml file */
/* Callable from mj2_to_metadata */
/* Contributed to Open JPEG by Glenn Pearson, U.S. National Library of Medicine */
#define BOOL int
#define FALSE 0
#define TRUE 1
void xml_write_init(BOOL n, BOOL t, BOOL r, BOOL d);
int xml_write_struct(FILE *file, FILE *xmlout, opj_mj2_t * movie, unsigned int sampleframe, char* stringDTD, opj_event_mgr_t *event_mgr);

View File

@ -0,0 +1,312 @@
/* mj2_to_metadata.c */
/* Dump MJ2, JP2 metadata (partial so far) to xml file */
/* Contributed to Open JPEG by Glenn Pearson, contract software developer, U.S. National Library of Medicine.
The base code in this file was developed by the author as part of a video archiving
project for the U.S. National Library of Medicine, Bethesda, MD.
It is the policy of NLM (and U.S. government) to not assert copyright.
A non-exclusive copy of this code has been contributed to the Open JPEG project.
Except for copyright, inclusion of the code within Open JPEG for distribution and use
can be bound by the Open JPEG open-source license and disclaimer, expressed elsewhere.
*/
#include "opj_includes.h"
#include "mj2.h"
#include "mj2_to_metadata.h"
#include <string.h>
#include "opj_getopt.h"
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
/* ------------- */
void help_display()
{
/* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */
fprintf(stdout," Help for the 'mj2_to_metadata' Program\n");
fprintf(stdout," ======================================\n");
fprintf(stdout,"The -h option displays this information on screen.\n\n");
fprintf(stdout,"mj2_to_metadata generates an XML file from a Motion JPEG 2000 file.\n");
fprintf(stdout,"The generated XML shows the structural, but not (yet) curatorial,\n");
fprintf(stdout,"metadata from the movie header and from the JPEG 2000 image and tile\n");
fprintf(stdout,"headers of a sample frame. Excluded: low-level packed-bits image data.\n\n");
fprintf(stdout,"By Default\n");
fprintf(stdout,"----------\n");
fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Metadata values are shown in 'raw' form (e.g., hexadecimal) as stored in the\n");
fprintf(stdout,"file, and, if apt, in a 'derived' form that is more quickly grasped.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n");
fprintf(stdout," meaning of non-obvious tag abbreviations;\n");
fprintf(stdout," range and precision of valid values;\n");
fprintf(stdout," interpretations of values, such as enumerations; and\n");
fprintf(stdout," current implementation limitations.\n");
fprintf(stdout,"\n");
fprintf(stdout,"The sample-size and chunk-offset tables, each with 1 row per frame, are not reported.\n");
fprintf(stdout,"\n");
fprintf(stdout,"The file is self-contained and no verification (e.g., against a DTD) is requested.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Required Parameters (except with -h)\n");
fprintf(stdout,"------------------------------------\n");
fprintf(stdout,"[Caution: file strings that contain spaces should be wrapped with quotes.]\n");
fprintf(stdout,"-i input.mj2 : where 'input' is any source file name or path.\n");
fprintf(stdout," MJ2 files created with 'frames_to_mj2' are supported so far.\n");
fprintf(stdout," These are silent, single-track, 'MJ2 Simple Profile' videos.\n");
fprintf(stdout,"-o output.xml : where 'output' is any destination file name or path.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Optional Parameters\n");
fprintf(stdout,"-------------------\n");
fprintf(stdout,"-h : Display this help information.\n");
fprintf(stdout,"-n : Suppress all mj2_to_metadata notes.\n");
fprintf(stdout,"-t : Include sample-size and chunk-offset tables.\n");
fprintf(stdout,"-f n : where n > 0. Include jp2 header info for frame n [default=1].\n");
fprintf(stdout,"-f 0 : No jp2 header info.\n");
fprintf(stdout,"-r : Suppress all 'raw' data for which a 'derived' form exists.\n");
fprintf(stdout,"-d : Suppress all 'derived' data.\n");
fprintf(stdout," (If both -r and -d given, -r will be ignored.)\n");
fprintf(stdout,"-v string : Verify against the DTD file located by the string.\n");
fprintf(stdout," Prepend quoted 'string' with either SYSTEM or PUBLIC keyword.\n");
fprintf(stdout," Thus, for the distributed DTD placed in the same directory as\n");
fprintf(stdout," the output file: -v \"SYSTEM mj2_to_metadata.dtd\"\n");
fprintf(stdout," \"PUBLIC\" is used with an access protocol (e.g., http:) + URL.\n");
/* More to come */
fprintf(stdout,"\n");
/* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */
}
/* ------------- */
int main(int argc, char *argv[]) {
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
FILE *file, *xmlout;
/* char xmloutname[50]; */
opj_mj2_t *movie;
char* infile = 0;
char* outfile = 0;
char* s, S1, S2, S3;
int len;
unsigned int sampleframe = 1; /* First frame */
char* stringDTD = NULL;
BOOL notes = TRUE;
BOOL sampletables = FALSE;
BOOL raw = TRUE;
BOOL derived = TRUE;
mj2_dparameters_t parameters;
while (TRUE) {
/* ':' after letter means it takes an argument */
int c = getopt(argc, argv, "i:o:f:v:hntrd");
/* FUTURE: Reserve 'p' for pruning file (which will probably make -t redundant) */
if (c == -1)
break;
switch (c) {
case 'i': /* IN file */
infile = optarg;
s = optarg;
while (*s) { s++; } /* Run to filename end */
s--;
S3 = *s;
s--;
S2 = *s;
s--;
S1 = *s;
if ((S1 == 'm' && S2 == 'j' && S3 == '2')
|| (S1 == 'M' && S2 == 'J' && S3 == '2')) {
break;
}
fprintf(stderr, "Input file name must have .mj2 extension, not .%c%c%c.\n", S1, S2, S3);
return 1;
/* ----------------------------------------------------- */
case 'o': /* OUT file */
outfile = optarg;
while (*outfile) { outfile++; } /* Run to filename end */
outfile--;
S3 = *outfile;
outfile--;
S2 = *outfile;
outfile--;
S1 = *outfile;
outfile = optarg;
if ((S1 == 'x' && S2 == 'm' && S3 == 'l')
|| (S1 == 'X' && S2 == 'M' && S3 == 'L'))
break;
fprintf(stderr,
"Output file name must have .xml extension, not .%c%c%c\n", S1, S2, S3);
return 1;
/* ----------------------------------------------------- */
case 'f': /* Choose sample frame. 0 = none */
sscanf(optarg, "%u", &sampleframe);
break;
/* ----------------------------------------------------- */
case 'v': /* Verification by DTD. */
stringDTD = optarg;
/* We will not insist upon last 3 chars being "dtd", since non-file
access protocol may be used. */
if(strchr(stringDTD,'"') != NULL) {
fprintf(stderr, "-D's string must not contain any embedded double-quote characters.\n");
return 1;
}
if (strncmp(stringDTD,"PUBLIC ",7) == 0 || strncmp(stringDTD,"SYSTEM ",7) == 0)
break;
fprintf(stderr, "-D's string must start with \"PUBLIC \" or \"SYSTEM \"\n");
return 1;
/* ----------------------------------------------------- */
case 'n': /* Suppress comments */
notes = FALSE;
break;
/* ----------------------------------------------------- */
case 't': /* Show sample size and chunk offset tables */
sampletables = TRUE;
break;
/* ----------------------------------------------------- */
case 'h': /* Display an help description */
help_display();
return 0;
/* ----------------------------------------------------- */
case 'r': /* Suppress raw data */
raw = FALSE;
break;
/* ----------------------------------------------------- */
case 'd': /* Suppress derived data */
derived = FALSE;
break;
/* ----------------------------------------------------- */
default:
return 1;
} /* switch */
} /* while */
if(!raw && !derived)
raw = TRUE; /* At least one of 'raw' and 'derived' must be true */
/* Error messages */
/* -------------- */
if (!infile || !outfile) {
fprintf(stderr,"Correct usage: mj2_to_metadata -i mj2-file -o xml-file (plus options)\n");
return 1;
}
/* was:
if (argc != 3) {
printf("Bad syntax: Usage: MJ2_to_metadata inputfile.mj2 outputfile.xml\n");
printf("Example: MJ2_to_metadata foreman.mj2 foreman.xml\n");
return 1;
}
*/
len = strlen(infile);
if(infile[0] == ' ')
{
infile++; /* There may be a leading blank if user put space after -i */
}
file = fopen(infile, "rb"); /* was: argv[1] */
if (!file) {
fprintf(stderr, "Failed to open %s for reading.\n", infile); /* was: argv[1] */
return 1;
}
len = strlen(outfile);
if(outfile[0] == ' ')
{
outfile++; /* There may be a leading blank if user put space after -o */
}
// Checking output file
xmlout = fopen(outfile, "w"); /* was: argv[2] */
if (!xmlout) {
fprintf(stderr, "Failed to open %s for writing.\n", outfile); /* was: argv[2] */
return 1;
}
// Leave it open
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(dinfo->mj2_handle, &parameters);
if (mj2_read_struct(file, movie)) // Creating the movie structure
{
fclose(xmlout);
return 1;
}
xml_write_init(notes, sampletables, raw, derived);
xml_write_struct(file, xmlout, movie, sampleframe, stringDTD, &event_mgr);
fclose(xmlout);
fprintf(stderr,"Metadata correctly extracted to XML file \n");;
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
return 0;
}

View File

@ -0,0 +1,425 @@
<!--
Preliminary DTD for Open JPEG "mj2_to_metadata" function.
Last revised: April 20, 2005
Author: Glenn Pearson, at U.S. National Library of Medicine.
See mj2_to_metadata.c regarding copyright, license, disclaimer status.
While the vocabulary of this DTD is based on the relevant portions of the
ISO/IEC JPEG 200 standard, the detailed representation is the author's own.
It is neither an ISO/IEC nor NLM official or consensus representation.
Furthermore, it deviates from a pure representation of the ISO/IEC standard
in these aspects:
- it is incomplete in a number of ways (which to some extent may be
addressed over time);
- it has extensions for "derived" data and "statistics";
- it is more flexible. That is, some elements are marked as optional
not because they are optional in an MJ2 file, but because reporting
of them is optional based on current or projected mj2_to_metadata
command-line flags.
-->
<!ELEMENT MJ2_File (JP2?, FileType?, MovieBox?)>
<!ELEMENT JP2 EMPTY>
<!ATTLIST JP2 BoxType CDATA #FIXED "jP[space][space]">
<!ATTLIST JP2 Signature CDATA #FIXED "0x0d0a870a">
<!ELEMENT FileType (Brand, MinorVersion, CompatibilityList)>
<!ATTLIST FileType BoxType CDATA #FIXED "ftyp">
<!ELEMENT Brand (#PCDATA)> <!-- 4 characters max -->
<!ELEMENT MinorVersion (#PCDATA)> <!-- 4 chararcters max -->
<!ELEMENT CompatibilityList (CompatibleBrand)*>
<!ATTLIST CompatibilityList Count CDATA #REQUIRED> <!-- Count >= 0 -->
<!ELEMENT CompatibleBrand (#PCDATA)> <!-- 4 characters max -->
<!ELEMENT MovieBox (MovieHeader, Statistics?, Track*)>
<!ATTLIST MovieBox BoxType CDATA #FIXED "moov">
<!ELEMENT MovieHeader (CreationTime, ModificationTime, Timescale, Rate, Duration, Volume, TransformationMatrix)>
<!ATTLIST MovieHeader BoxType CDATA #FIXED "mvhd">
<!ELEMENT CreationTime (InSeconds?,AsLocalTime?)>
<!ELEMENT InSeconds (#PCDATA)>
<!ELEMENT AsLocalTime (#PCDATA)>
<!ELEMENT ModificationTime (InSeconds?,AsLocalTime?)>
<!ELEMENT Timescale (#PCDATA)> <!-- Timescale defines time units in one second -->
<!ELEMENT Rate (AsHex | (AsHex, AsDecimal) | AsDecimal)> <!-- Decimal is Approximation; Optional on input. -->
<!ELEMENT AsHex (#PCDATA)>
<!ELEMENT AsDecimal (#PCDATA)>
<!ELEMENT Duration (InTimeUnits | (InTimeUnits, InSeconds) | InSeconds)> <!-- InSeconds Optional on input. -->
<!ELEMENT InTimeUnits (#PCDATA)>
<!ELEMENT Volume (AsHex | (AsHex, AsDecimal) | AsDecimal)> <!-- hex default = 0x0100 -->
<!-- Fixed 8.8 value of audio volume. Full, normal value is 1.0 (0x0100) -->
<!ELEMENT TransformationMatrix (TMa,TMb,TMu,TMc,TMd,TMv,TMx,TMy,TMw)> <!-- for video -->
<!-- 3 x 3 Video Transformation Matrix {a,b,u,c,d,v,x,y,w}. Required: u=0, v=0, w=1 -->
<!-- Maps decompressed point (p,q) to rendered point (ap + cq + x, bp + dq + y) -->
<!-- Stored as Fixed Point Hex: all are 16.16, except u,v,w are 2.30 -->
<!-- Unity = 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 -->
<!ELEMENT TMa (#PCDATA)>
<!ELEMENT TMb (#PCDATA)>
<!ELEMENT TMu (#PCDATA)> <!--Always "0x00000000" -->
<!ELEMENT TMc (#PCDATA)>
<!ELEMENT TMd (#PCDATA)>
<!ELEMENT TMv (#PCDATA)> <!--Always "0x00000000" -->
<!ELEMENT TMx (#PCDATA)>
<!ELEMENT TMy (#PCDATA)>
<!ELEMENT TMw (#PCDATA)> <!--Always "0x40000000" -->
<!ELEMENT Statistics (TracksFound)>
<!ELEMENT TracksFound (Video,Audio,Hint)>
<!ELEMENT Video (#PCDATA)>
<!ELEMENT Audio (#PCDATA)>
<!ELEMENT Hint (#PCDATA)>
<!-- For now, output info on at most one video track -->
<!ELEMENT Track (TrackHeader, TrackReferenceContainer?, EditListContainer?, Media, JP2_Frame?)> <!-- JP2_Frame is mj2_to_metadata extension -->
<!ATTLIST Track BoxType CDATA #FIXED "trak">
<!ATTLIST Track Instance CDATA #REQUIRED>
<!ELEMENT TrackHeader (TrackID, TrackLayer?, Volume?, TransformationMatrix?, Width?, Height?)>
<!ATTLIST TrackHeader BoxType CDATA #FIXED "tkhd">
<!-- Not shown here: CreationTime, ModificationTime, Duration. -->
<!-- These 3 fields are reported under MediaHeader below. When reading these 3, -->
<!-- m2j_to_metadata currently doesn't distinguish between TrackHeader and MediaHeader source. -->
<!-- If both found, value read from MediaHeader is used. -->
<!ELEMENT TrackID (#PCDATA)>
<!ELEMENT TrackLayer (#PCDATA)> <!-- front-to-back ordering of video tracks. 0 = normal, -1 is closer, etc. -->
<!-- "Volume" element described above; here it is for particular audio track. Full, normal (default = 0x0100) -->
<!-- "TransformationMatrix" element described above; matrix here is applied before MovieHeader one. -->
<!ELEMENT Width (AsHex | (AsHex, AsDecimal) | AsDecimal)>
<!ELEMENT Height (AsHex | (AsHex, AsDecimal) | AsDecimal)>
<!-- AsHex, AsDecimal already defined above -->
<!-- Width and Height are for the presentation; frames will be scaled to this -->
<!-- /TrackHeader -->
<!ELEMENT TrackReferenceContainer ANY> <!-- TO DO: TrackReferenceContainer 'tref' just used in hint track -->
<!ELEMENT EditListContainer ANY> <!-- TO DO: EditListContainer 'edts', contains EditList 'elst' with media-time, segment-duration, media-rate -->
<!ELEMENT Media (MediaHeader, HandlerReference,MediaInfoContainer)>
<!ATTLIST Media BoxType CDATA #FIXED "mdia">
<!ELEMENT MediaHeader (CreationTime,ModificationTime,Timescale,Duration,Language)>
<!ATTLIST MediaHeader BoxType CDATA #FIXED "mdhd">
<!-- Elements already defined above: CreationTime, ModificationTime, Timescale, Duration -->
<!ELEMENT Language (#PCDATA)> <!-- 3 chars max. There's an enumeration available -->
<!ELEMENT HandlerReference (HandlerType)>
<!ATTLIST HandlerReference BoxType CDATA #FIXED "hdlr">
<!ELEMENT HandlerType (#PCDATA)>
<!ATTLIST HandlerType Code ( vide | soun | hint ) "vide">
<!-- make the media headers multiple? -->
<!ELEMENT MediaInfoContainer ((VideoMediaHeader | SoundMediaHeader | HintMediaHeader), DataInfo, SampleTable)>
<!ATTLIST MediaInfoContainer BoxType CDATA #FIXED "minf">
<!ELEMENT VideoMediaHeader (GraphicsMode, Opcolor)>
<!ATTLIST VideoMediaHeader BoxType CDATA #FIXED "vmhd">
<!ELEMENT GraphicsMode (#PCDATA)>
<!-- Enumerated values of graphics mode: -->
<!-- 0x00 = copy (over existing image); -->
<!-- 0x24 = transparent; 'blue-screen' this image using opcolor; -->
<!-- 0x100 = alpha; alpha-blend this image -->
<!-- 0x101 = whitealpha; alpha-blend this image, which has been blended with white; -->
<!-- 0x102 = blackalpha; alpha-blend this image, which has been blended with black. -->
<!ELEMENT Opcolor (Red,Green,Blue)>
<!ELEMENT Red (#PCDATA)>
<!ELEMENT Green (#PCDATA)>
<!ELEMENT Blue (#PCDATA)>
<!ELEMENT SoundMediaHeader (Balance)>
<!ATTLIST SoundMediaHeader BoxType CDATA #FIXED "smhd">
<!ELEMENT Balance (#PCDATA)>
<!-- Fixed Point 8.8, fixes mono track in stereo space. -->
<!-- 0.0 = center, -1.0 = full left, 1.0 = full right -->
<!ELEMENT HintMediaHeader (MaxPDU_Size, AvgPDU_Size, MaxBitRate, AvgBitRate, SlidingAvgBitRate)>
<!ATTLIST HintMediaHeader BoxType CDATA #FIXED "hmhd">
<!ELEMENT MaxPDU_Size (#PCDATA)>
<!-- Size in bytes of largest PDU in this hint stream. -->
<!ELEMENT AvgPDU_Size (#PCDATA)>
<!-- Average size in bytes of a PDU over the entire presentation. -->
<!ELEMENT MaxBitRate (#PCDATA)>
<!-- Maximum rate in bits per second over any window of 1 second. -->
<!ELEMENT AvgBitRate (#PCDATA)>
<!-- Averate rate in bits per second over the entire presentation. -->
<!ELEMENT SlidingAvgBit (#PCDATA)>
<!-- Maximum rate in bits per second over any window of one minute. -->
<!ELEMENT DataInfo (DataReference)>
<!ATTLIST DataInfo BoxType CDATA #FIXED "dinf">
<!ELEMENT DataReference (DataEntryUrlBox | DataEntryUrnBox )*>
<!ATTLIST DataReference BoxType CDATA #FIXED "dref">
<!ATTLIST DataReference URL_Count CDATA #REQUIRED>
<!ATTLIST DataReference URN_Count CDATA #REQUIRED> <!-- table w. flags, URLs, URNs -->
<!-- // Data structure does not distinguish between single URL, single URN, or DREF table or URLs & URNs.
// We could infer those, but for now just present everything as a DREF table.
-->
<!-- No entries here mean that file is self-contained, as required by Simple Profile. -->
<!ELEMENT DataEntryUrlBox (Location)>
<!ATTLIST DataEntryUrlBox BoxType CDATA #FIXED "url[space]"> <!-- table w. flags, URLs, URNs -->
<!-- Only the first 16 bytes of URL location are recorded in mj2_to_metadata data structure. -->
<!ELEMENT DataEntryUrnBox (Name, Location?)>
<!ATTLIST DataEntryUrnBox BoxType CDATA #FIXED "urn[space]\">
<!-- Only the first 16 bytes each of URN name and optional location are recorded in mj2_to_metadata data structure. -->
<!ELEMENT SampleTable (VisualSampleEntry,TimeToSample,SampleToChunk,SampleSize,ChunkOffset)> <!-- structure doesn't do non-visual sample entry yet -->
<!ATTLIST SampleTable BoxType CDATA #FIXED "stbl"> <!-- to add: entry count -->
<!-- Next are instances of generic SampleDescription BoxType=\"stsd\" -->
<!-- There could be multiple instances of this, but "entry_count" is just a local at read-time.
And it's used wrong, too, as count of just visual type, when it's really all 3 types.
This is referred to as "smj2" within mj2.c -->
<!ELEMENT VisualSampleEntry (WidthAsInteger, HeightAsInteger, HorizontalRes, VerticalRes, CompressorName, Depth, JP2Header?, FieldCoding?, MJP2_Profile?, MJP2_Prefix?, MJP2_SubSampling?, MJP2_OriginalFormat?)>
<!ATTLIST VisualSampleEntry BoxType CDATA #FIXED "mjp2">
<!-- If multiple instances of this, only first is shown here. -->
<!ELEMENT WidthAsInteger (#PCDATA)>
<!ELEMENT HeightAsInteger (#PCDATA)>
<!ELEMENT HorizontalRes (AsHex | (AsHex, AsDecimal) | AsDecimal)>
<!ELEMENT VerticalRes (AsHex | (AsHex, AsDecimal) | AsDecimal)>
<!-- Typical value for both resolution is 72 (0x00480000) -->
<!ELEMENT CompressorName (#PCDATA)>
<!-- Compressor name for debugging. Standard restricts max length to 31 bytes. -->
<!-- Usually blank or \"Motion JPEG2000\" -->
<!ELEMENT Depth (#PCDATA)>
<!-- Depth is: -->
<!-- 0x20: alpha channels present (color or grayscale) -->
<!-- 0x28: grayscale without alpha -->
<!-- 0x18: color without alpha -->
<!-- TODO somewhere: tk->jp2_struct.numcomps -->
<!ELEMENT JP2Header (ImageHeader, ColourSpecification)>
<!ATTLIST JP2Header BoxType CDATA #FIXED "jp2h">
<!ELEMENT ImageHeader (HEIGHT, WIDTH, NC, BPC, C, UnkC, IPR)>
<!ATTLIST ImageHeader BoxType CDATA #FIXED "ihdr">
<!ELEMENT HEIGHT (#PCDATA)> <!-- If 2 fields/frame, total deinterlaced height -->
<!ELEMENT WIDTH (#PCDATA)>
<!ELEMENT NC (#PCDATA)> <!-- number of components -->
<!ELEMENT BPC (AsHex | (AsHex,BitsPerPixel,Signed) | (BitsPerPixel,Signed))>
<!ELEMENT BitsPerPixel (#PCDATA)>
<!ELEMENT Signed (#PCDATA)>
<!ELEMENT C (#PCDATA)> <!-- Compression type. Only "7" defined -->
<!ELEMENT UnkC (#PCDATA)> <!-- Colourspace Unknown. 1 = unknown, 0 = known -->
<!ELEMENT IPR (#PCDATA)> <!-- 1 = frame has Intellectual Prop. box; otherwise 0 -->
<!ELEMENT ColourSpecification (METH, PREC, APPROX, EnumCS)>
<!ATTLIST ColourSpecification BoxType CDATA #FIXED "colr">
<!ELEMENT METH (#PCDATA)> <!-- 1 = EnumCS field; 2 = PROFILE field (not yet generated) -->
<!ELEMENT PREC (#PCDATA)> <!-- precedence must be 0 so far -->
<!ELEMENT APPROX (#PCDATA)> <!-- colourspace approximation must be 0 so far -->
<!ELEMENT EnumCS (#PCDATA)> <!-- Valid enumerated MJ2 colourspaces: 16 (sRGB), 17 (grey sRGB), 18 (YCC) -->
<!-- Following subboxes are optional -->
<!ELEMENT FieldCoding (FieldCount, FieldOrder)>
<!ATTLIST FieldCoding BoxType CDATA #FIXED "fiel">
<!ELEMENT FieldCount (#PCDATA)>
<!-- Must be either 1 or 2 -->
<!ELEMENT FieldOrder (#PCDATA)>
<!-- When FieldCount=2, FieldOrder means: -->
<!-- 0: Field coding unknown -->
<!-- 1: Field with topmost line is stored first in sample; fields are in temporal order -->
<!-- 6: Field with topmost line is stored second in sample; fields are in temporal order -->
<!-- Defaults: FieldCount=1, FieldOrder=0 if FieldCoding box not present -->
<!-- Current implementation doesn't retain whether box was actually present. -->
<!ELEMENT MJP2_Profile (CompatibleBrand*)>
<!ATTLIST MJP2_Profile BoxType CDATA #FIXED "jp2p">
<!ATTLIST MJP2_Profile Count CDATA #REQUIRED>
<!ELEMENT MJP2_Prefix (Data*)>
<!ATTLIST MJP2_Prefix BoxType CDATA #FIXED "jp2x">
<!ATTLIST MJP2_Prefix Count CDATA #REQUIRED>
<!-- We'll probably need better formatting than this -->
<!ELEMENT Data (#PCDATA)> <!-- Multiple. Each entry is single byte -->
<!ELEMENT MJP2_SubSampling (HorizontalSub, VerticalSub, HorizontalOffset, VerticalOffset)>
<!ATTLIST MJP2_SubSampling BoxType CDATA #FIXED "jsub">
<!-- These values are all 1 byte -->
<!-- Typical subsample value is 2 for 4:2:0 -->
<!ELEMENT HorizontalSub (#PCDATA)>
<!ELEMENT VerticalSub (#PCDATA)>
<!ELEMENT HorizontalOffset (#PCDATA)>
<!ELEMENT VerticalOffset (#PCDATA)>
<!ELEMENT MJP2_OriginalFormat (OriginalFieldCount, OriginalFieldOrder)>
<!ATTLIST MJP2_OriginalFormat BoxType CDATA #FIXED "orfo"> <!-- Part III Appx. 2 -->
<!ELEMENT OriginalFieldCount (#PCDATA)>
<!-- In original material before encoding. Must be either 1 or 2 -->
<!ELEMENT OriginalFieldOrder (#PCDATA)>
<!-- When FieldCount=2, FieldOrder means: -->
<!-- 0: Field coding unknown -->
<!-- 11: Topmost line came from the earlier field; -->
<!-- 16: Topmost line came form the later field. -->
<!-- Defaults: FieldCount=1, FieldOrder=0 if FieldCoding box not present -->
<!-- Current implementation doesn't retain whether box was actually present. -->
<!-- mj2_to_metadata's data structure doesn't record Audio and Hint sample data currently. -->
<!-- Within SampleTable: -->
<!ELEMENT TimeToSample (SampleStatistics, SampleEntries)>
<!ATTLIST TimeToSample BoxType CDATA #FIXED "stts">
<!ELEMENT SampleStatistics (TotalSamples)> <!-- Not part of standard -->
<!ELEMENT TotalSamples (#PCDATA)>
<!-- For video, gives the total frames in the track, by summing all entries in the Sample Table -->
<!ELEMENT SampleEntries (Table*)>
<!ATTLIST SampleEntries EntryCount CDATA #REQUIRED>
<!ELEMENT Table EMPTY> <!-- Multiple. Attributes have values -->
<!ATTLIST Table Entry CDATA #REQUIRED>
<!ATTLIST Table SampleCount CDATA #REQUIRED>
<!ATTLIST Table SampleDelta CDATA #REQUIRED>
<!-- Within SampleTable: -->
<!ELEMENT SampleToChunk (FirstChunk,SamplesPerChunk,SampleDescrIndex)>
<!ATTLIST SampleToChunk BoxType CDATA #FIXED "stsc">
<!ATTLIST SampleToChunk Count CDATA #REQUIRED>
<!ELEMENT FirstChunk (#PCDATA)>
<!ELEMENT SamplesPerChunk (#PCDATA)>
<!ELEMENT SampleDescrIndex (#PCDATA)>
<!ELEMENT SampleSize (Sample_Size,Sample_Count,EntrySize*)>
<!ATTLIST SampleSize BoxType CDATA #FIXED "stsz">
<!ELEMENT Sample_Size (#PCDATA)>
<!ELEMENT Sample_Count (#PCDATA)>
<!ELEMENT EntrySize (#PCDATA)> <!-- appears multiply, but only with mj2_to_metadata option -t -->
<!ATTLIST EntrySize Num CDATA #REQUIRED>
<!ELEMENT ChunkOffset (EntryCount, Chunk_Offset*)>
<!ATTLIST ChunkOffset BoxType CDATA #FIXED "stco">
<!ELEMENT EntryCount (#PCDATA)>
<!ELEMENT Chunk_Offset (#PCDATA)> <!-- appears multiply, but only with mj2_to_metadata option -t -->
<!ATTLIST Chunk_Offset Num CDATA #REQUIRED>
<!-- </SampleTable> </MediaInfoContainer> </Media> -->
<!-- TO DO: optional UserData 'udat', can contain multiple Copyright 'cprt' -->
<!-- Optional, and only for Visual Track: given individual frame -->
<!ELEMENT JP2_Frame (MainHeader, TilePartHeaders)>
<!ATTLIST JP2_Frame Num CDATA #REQUIRED>
<!ELEMENT MainHeader (StartOfCodestream,ImageAndFileSize,CodingStyleDefault,QuantizationDefault,QuantizationComponent*,RegionOfInterest?,ProgressionOrderChange*)>
<!ELEMENT StartOfCodestream EMPTY>
<!ATTLIST StartOfCodestream Marker CDATA #FIXED "SOC">
<!ELEMENT ImageAndFileSize (Xsiz,Ysiz,XOsiz,YOsiz,XTsiz,YTsiz,XTOsiz,YTOsiz,Csiz,Component+)>
<!ATTLIST ImageAndFileSize Marker CDATA #FIXED "SIZ">
<!ELEMENT Xsiz (#PCDATA)>
<!ELEMENT Ysiz (#PCDATA)> <!-- Xsiz, Ysiz is the size of the reference grid. -->
<!ELEMENT XOsiz (#PCDATA)>
<!ELEMENT YOsiz (#PCDATA)> <!-- XOsiz, YOsiz are offsets from grid origin to image origin. -->
<!ELEMENT XTsiz (#PCDATA)>
<!ELEMENT YTsiz (#PCDATA)> <!-- XTsiz, YTsiz is the size of one tile with respect to the grid. -->
<!ELEMENT XTOsiz (#PCDATA)>
<!ELEMENT YTOsiz (#PCDATA)> <!-- XTOsiz, YTOsiz are offsets from grid origin to first tile origin. -->
<!ELEMENT Csiz (#PCDATA)> <!-- Csiz is the number of components in the image. -->
<!-- For image components next -->
<!ELEMENT Component (Ssiz,XRsiz,YRsiz,WidthOfData,HeightOfData)>
<!ATTLIST Component Num CDATA #REQUIRED>
<!ELEMENT Ssiz (AsHex | (AsHex,Signed,PrecisionInBits) | (Signed,PrecisionInBits))>
<!-- Signed already defined -->
<!ELEMENT PrecisionInBits (#PCDATA)> <!-- Bits per pixel (bpp) or pixel depth. -->
<!ELEMENT XRsiz (#PCDATA)>
<!ELEMENT YRsiz (#PCDATA)> <!-- XRsiz, YRsiz denote pixel-sample-spacing on the grid, per Part I Annex B. -->
<!ELEMENT WidthOfData (#PCDATA)>
<!ELEMENT HeightOfData (#PCDATA)> <!-- WidthOfData and HeightOfData are calculated values, e.g.: w = roundup((Xsiz - XOsiz)/ XRsiz) -->
<!-- -->
<!ELEMENT CodingStyleDefault (Scod,SGcod,SPcod)>
<!ATTLIST CodingStyleDefault Marker CDATA #FIXED "COD">
<!ELEMENT Scod (#PCDATA)>
<!-- For Scod, specific bits mean (where bit 0 is lowest or rightmost): -->
<!-- bit 0: Defines entropy coder precincts -->
<!-- 0 = (PPx=15, PPy=15); 1 = precincts defined below. -->
<!-- bit 1: 1 = SOP marker may be used; 0 = not. -->
<!-- bit 2: 1 = EPH marker may be used; 0 = not. -->
<!ELEMENT SGcod (ProgressionOrder,NumberOfLayers,MultipleComponentTransformation)>
<!ELEMENT ProgressionOrder (#PCDATA)>
<!-- Defined Progression Order Values are: -->
<!-- 0 = LRCP; 1 = RLCP; 2 = RPCL; 3 = PCRL; 4 = CPRL -->
<!-- where L = "layer", R = "resolution level", C = "component", P = "position". -->
<!ELEMENT NumberOfLayers (#PCDATA)>
<!ELEMENT MultipleComponentTransformation (#PCDATA)>
<!-- For MCT, 0 = none, 1 = transform first 3 components for efficiency, per Part I Annex G -->
<!ELEMENT SPcod (NumberOfDecompositionLevels,CodeblockWidth,CodeblockHeight,CodeblockStyle,Transformation)>
<!ELEMENT NumberOfDecompositionLevels (#PCDATA)>
<!ELEMENT CodeblockWidth (#PCDATA)> <!-- CBW and CBH are non-negative, and summed cannot exceed 8 -->
<!ELEMENT CodeblockHeight (#PCDATA)> <!-- Codeblock dimension is 2^(value + 2) -->
<!ELEMENT CodeblockStyle (#PCDATA)>
<!-- For CodeblockStyle, bits mean (with value 1=feature on, 0=off): -->
<!-- bit 0: Selective arithmetic coding bypass. -->
<!-- bit 1: Reset context probabilities on coding pass boundaries. -->
<!-- bit 2: Termination on each coding pass. -->
<!-- bit 3: Vertically causal context. -->
<!-- bit 4: Predictable termination. -->
<!-- bit 5: Segmentation symbols are used. -->
<!ELEMENT Transformation (#PCDATA)> <!-- For Transformation, 0="9-7 irreversible filter", 1="5-3 reversible filter" -->
<!-- mj2_to_metadata implementation always reports component[0] as using default COD, -->
<!-- and any other component, with main-header style values different from [0], as COC. -->
<!ELEMENT QuantizationDefault (Sqcd,SPqcd)>
<!ATTLIST QuantizationDefault Marker CDATA #FIXED "QCD">
<!ELEMENT Sqcd (AsHex | (AsHex,QuantizationStyle,NumberOfGuardBits) | (QuantizationStyle,NumberOfGuardBits))>
<!ELEMENT QuantizationStyle (#PCDATA)> <!-- Default quantization style for all components. -->
<!-- Quantization style (in Sqcd's low 5 bits) may be: -->
<!-- 0 = No quantization. SPqcd size = 8 bits-->
<!-- 1 = Scalar derived (values signaled for N(L)LL subband only). Use Eq. E.5. SPqcd size = 16. -->
<!-- 2 = Scalar expounded (values signaled for each subband). SPqcd size = 16. -->
<!ELEMENT NumberOfGuardBits (#PCDATA)> <!-- 0-7 guard bits allowed (stored in Sqcd's high 3 bits) -->
<!ELEMENT SPqcd (ReversibleStepSizeValue | QuantizationStepSizeValues )> <!-- TO DO: Irreversible choices -->
<!ELEMENT ReversibleStepSizeValue (DynamicRangeExponent+)>
<!-- Current mj2_to_metadata implementation dumps entire internal table, -->
<!-- until an exponent with zero value is reached. -->
<!-- Exponent epsilon(b) of reversible dynamic range. -->
<!-- Hex value is as stored, in high-order 5 bits. -->
<!ELEMENT DynamicRangeExponent (AsHex | (AsHex, AsDecimal) | AsDecimal)>
<!ATTLIST DynamicRangeExponent Subband CDATA #REQUIRED>
<!ELEMENT QuantizationStepSizeValues (QuantizationValues+, CalculatedExponent*)> <!-- Calculated exponents iff only subband 0 reported -->
<!ELEMENT QuantizationValues (AsHex | (AsHex,Exponent,Mantissa) | (Exponent,Mantissa))>
<!ATTLIST QuantizationValues Subband CDATA #REQUIRED>
<!ELEMENT Exponent (#PCDATA)>
<!ELEMENT Mantissa (#PCDATA)>
<!ELEMENT CalculatedExponent (#PCDATA)>
<!ATTLIST CalculatedExponent Subband CDATA #REQUIRED>
<!-- /QuantizationDefault -->
<!-- mj2_to_metadata implementation always reports component[0] as using default QCD, -->
<!-- and any other component, with main-header quantization values different from [0], as QCC. -->
<!ELEMENT QuantizationComponent (Sqcc,SPqcc)>
<!ATTLIST QuantizationComponent Marker CDATA #FIXED "QCC">
<!ATTLIST QuantizationComponent Component CDATA #REQUIRED>
<!ELEMENT Sqcc (AsHex | (AsHex,QuantizationStyle,NumberOfGuardBits) | (QuantizationStyle,NumberOfGuardBits))>
<!ELEMENT SPqcc (ReversibleStepSizeValue | QuantizationStepSizeValues )> <!-- TO DO: Irreversible choices -->
<!-- /QuantizationComponent -->
<!-- Don't know if MJ2 files can have regions of interest. Assume yes -->
<!ELEMENT RegionOfInterest (Srgn,Crgn,Sprgn)> <!-- Optional in main header, at most 1 per component -->
<!ATTLIST RegionOfInterest Marker CDATA #FIXED "RGN">
<!ELEMENT Srgn (#PCDATA)> <!-- ROI style. Only style=0 defined: Implicit ROI (max. shift) -->
<!ELEMENT Crgn (#PCDATA)> <!-- Zero-based component number. -->
<!ELEMENT SPrgn (#PCDATA)> <!-- Implicit ROI shift, i.e., binary shifting of ROI coefficients above background. -->
<!-- </RegionOfInterest> -->
<!ELEMENT ProgressionOrderChange (Progression+)> <!-- Optional in main header, at most 1 per component (but impl allows more?) -->
<!ATTLIST ProgressionOrderChange Marker CDATA #REQUIRED>
<!ELEMENT Progression (RSpoc,CSpoc,LYEpoc,REpoc,CEpoc,Ppoc)>
<!ATTLIST Progression Num CDATA #REQUIRED>
<!ELEMENT RSpoc (#PCDATA)> <!-- Resolution level index (inclusive) for progression start. Range: 0 to 33 -->
<!ELEMENT CSpoc (#PCDATA)> <!-- Component index (inclusive) for progression start. -->
<!ELEMENT LYEpoc (#PCDATA)> <!-- Layer index (exclusive) for progression end. -->
<!ELEMENT REpoc (#PCDATA)> <!-- Resolution level index (exclusive) for progression end. Range: RSpoc to 33 -->
<!ELEMENT CEpoc (#PCDATA)> <!-- Component index (exclusive) for progression end. Minimum: CSpoc -->
<!ELEMENT Ppoc (#PCDATA)> <!-- Defined Progression Order Values are: -->
<!-- 0 = LRCP; 1 = RLCP; 2 = RPCL; 3 = PCRL; 4 = CPRL -->
<!-- where L = "layer", R = "resolution level", C = "component", P = "position". -->
<!-- </Progression>, </ProgressionOrderChange -->
<!-- /MainHeader -->
<!ELEMENT TilePartHeaders (TilePartHeader+)>
<!ATTLIST TilePartHeaders Count CDATA #REQUIRED>
<!ELEMENT TilePartHeader (StartOfTilePart,CodingStyleDefault,QuantizationDefault,QuantizationComponent*,RegionOfInterest?,ProgressionOrderChange*,StartOfData)>
<!ATTLIST TilePartHeader Num CDATA #REQUIRED>
<!ATTLIST TilePartHeader ID CDATA #REQUIRED>
<!ELEMENT StartOfTilePart EMPTY>
<!ATTLIST StartOfTilePart Marker CDATA #FIXED "SOT">
<!-- CodingStyleDefault, QuantizationDefault, QuantizationComponent already defined -->
<!-- mj2_to_metadata implementation always reports component[0] as using default QCD, -->
<!-- and any other component, with tile-part-header quantization values different from [0], as QCC. -->
<!ELEMENT StartOfData EMPTY> <!-- always empty for now -->
<!ATTLIST StartOfData Marker CDATA #FIXED "SOD">
<!-- Tile-part bitstream, not shown, follows tile-part header and SOD marker. -->
<!-- /TilePartHeader, /TilePartHeaders, /JP2_Frame -->
<!-- </Track> -->
<!-- to come:
<MovieExtends mvek> // possibly not in Simple Profile
<UserDataBox udat> contains <CopyrightBox cprt>
-->
<!-- /MovieBox -->
<!-- To come:
<mdat>
<moof> // probably not in Simple Profile
<free>
<skip>
-->
<!-- </MJ2_File> -->

View File

@ -0,0 +1,9 @@
/* mj2_to_metadata.h */
/* Dump MJ2, JP2 metadata (partial so far) to xml file */
/* Contributed to Open JPEG by Glenn Pearson, U.S. National Library of Medicine */
#define BOOL int
#define FALSE 0
#define TRUE 1
#include "meta_out.h"

View File

@ -0,0 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mj2_to_metadata", "mj2_to_metadata.vcproj", "{69BE42AB-E7CE-4DA1-BBD2-39FEA2C91E0B}"
ProjectSection(ProjectDependencies) = postProject
{0B1B7713-35B6-40A7-9BFF-A7D0EB06A8BD} = {0B1B7713-35B6-40A7-9BFF-A7D0EB06A8BD}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibOpenJPEG", "..\LibOpenJPEG.vcproj", "{0B1B7713-35B6-40A7-9BFF-A7D0EB06A8BD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{69BE42AB-E7CE-4DA1-BBD2-39FEA2C91E0B}.Debug|Win32.ActiveCfg = Debug|Win32
{69BE42AB-E7CE-4DA1-BBD2-39FEA2C91E0B}.Debug|Win32.Build.0 = Debug|Win32
{69BE42AB-E7CE-4DA1-BBD2-39FEA2C91E0B}.Release|Win32.ActiveCfg = Release|Win32
{69BE42AB-E7CE-4DA1-BBD2-39FEA2C91E0B}.Release|Win32.Build.0 = Release|Win32
{0B1B7713-35B6-40A7-9BFF-A7D0EB06A8BD}.Debug|Win32.ActiveCfg = Debug|Win32
{0B1B7713-35B6-40A7-9BFF-A7D0EB06A8BD}.Debug|Win32.Build.0 = Debug|Win32
{0B1B7713-35B6-40A7-9BFF-A7D0EB06A8BD}.Release|Win32.ActiveCfg = Release|Win32
{0B1B7713-35B6-40A7-9BFF-A7D0EB06A8BD}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,349 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="mj2_to_metadata"
ProjectGUID="{69BE42AB-E7CE-4DA1-BBD2-39FEA2C91E0B}"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\mj2_to_metadata___Win32_Debug0"
IntermediateDirectory=".\mj2_to_metadata___Win32_Debug0"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../libopenjpeg"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;OPJ_STATIC;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.pch"
AssemblerListingLocation=".\mj2_to_metadata___Win32_Debug0/"
ObjectFile=".\mj2_to_metadata___Win32_Debug0/"
ProgramDataBaseFileName=".\mj2_to_metadata___Win32_Debug0/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="2057"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
IgnoreDefaultLibraryNames="LIBCMT"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/mj2_to_metadata.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="../libopenjpeg"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;OPJ_STATIC;_CRT_SECURE_NO_DEPRECATE"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release/mj2_to_metadata.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="2057"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Release/mj2_to_metadata.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
IgnoreDefaultLibraryNames="libcmtd"
ProgramDatabaseFile=".\Release/mj2_to_metadata.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/mj2_to_metadata.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="MJ2"
>
<Filter
Name="MJ2 Header Files"
>
<File
RelativePath="compat\opj_getopt.h"
>
</File>
<File
RelativePath="meta_out.h"
>
</File>
<File
RelativePath="mj2.h"
>
</File>
<File
RelativePath="mj2_convert.h"
>
</File>
<File
RelativePath="mj2_to_metadata.h"
>
</File>
</Filter>
<Filter
Name="MJ2 Source Files"
>
<File
RelativePath="compat\opj_getopt.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="meta_out.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="mj2.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="mj2_convert.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="mj2_to_metadata.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

Binary file not shown.

View File

@ -0,0 +1,834 @@
/*
* Copyright (c) 2003-2004, Francois-Olivier Devaux
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "j2k_lib.h"
#include "cio.h"
#include "j2k.h"
#include "jp2.h"
#include "mj2.h"
#include "mj2_convert.h"
#include "opj_getopt.h"
/**
Size of memory first allocated for MOOV box
*/
#define TEMP_BUF 10000
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/* -------------------------------------------------------------------------- */
static void help_display()
{
fprintf(stdout,"HELP for frames_to_mj2\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
fprintf(stdout,"List of parameters for the MJ2 encoder:\n");
fprintf(stdout,"\n");
fprintf(stdout,"REMARKS:\n");
fprintf(stdout,"---------\n");
fprintf(stdout,"\n");
fprintf
(stdout,"The markers written to the main_header are : SOC SIZ COD QCD COM.\n");
fprintf
(stdout,"COD and QCD never appear in the tile_header.\n");
fprintf(stdout,"\n");
fprintf(stdout,"By default:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");
fprintf(stdout," * Lossless\n");
fprintf(stdout," * 1 tile\n");
fprintf(stdout," * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n");
fprintf(stdout," * Size of code-block : 64 x 64\n");
fprintf(stdout," * Number of resolutions: 6\n");
fprintf(stdout," * No SOP marker in the codestream\n");
fprintf(stdout," * No EPH marker in the codestream\n");
fprintf(stdout," * No sub-sampling in x or y direction\n");
fprintf(stdout," * No mode switch activated\n");
fprintf(stdout," * Progression order: LRCP\n");
fprintf(stdout," * No index file\n");
fprintf(stdout," * No ROI upshifted\n");
fprintf(stdout," * No offset of the origin of the image\n");
fprintf(stdout," * No offset of the origin of the tiles\n");
fprintf(stdout," * Reversible DWT 5-3\n");
fprintf(stdout,"\n");
fprintf(stdout,"Parameters:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");
fprintf
(stdout,"Required Parameters (except with -h):\n");
fprintf
(stdout,"-i : source file (-i source.yuv) \n");
fprintf
(stdout,"-o : destination file (-o dest.mj2) \n");
fprintf
(stdout,"Optional Parameters:\n");
fprintf(stdout,"-h : display the help information \n");
fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n");
fprintf(stdout," - The rate specified for each quality level is the desired \n");
fprintf(stdout," compression factor.\n");
fprintf(stdout," Example: -r 20,10,1 means quality 1: compress 20x, \n");
fprintf(stdout," quality 2: compress 10x and quality 3: compress lossless\n");
fprintf(stdout," (options -r and -q cannot be used together)\n");
fprintf(stdout,"-q : different psnr for successive layers (-q 30,40,50) \n");
fprintf(stdout," (options -r and -q cannot be used together)\n");
fprintf(stdout,"-n : number of resolutions (-n 3) \n");
fprintf(stdout,"-b : size of code block (-b 32,32) \n");
fprintf(stdout,"-c : size of precinct (-c 128,128) \n");
fprintf(stdout,"-t : size of tile (-t 512,512) \n");
fprintf
(stdout,"-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n");
fprintf
(stdout,"-s : subsampling factor (-s 2,2) [-s X,Y] \n");
fprintf(stdout," Remark: subsampling bigger than 2 can produce error\n");
fprintf
(stdout,"-S : write SOP marker before each packet \n");
fprintf
(stdout,"-E : write EPH marker after each header packet \n");
fprintf
(stdout,"-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n");
fprintf
(stdout," 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] \n");
fprintf
(stdout," Indicate multiple modes by adding their values. \n");
fprintf
(stdout," Example: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
fprintf
(stdout,"-R : c=%%d,U=%%d : quantization indices upshifted \n");
fprintf
(stdout," for component c=%%d [%%d = 0,1,2]\n");
fprintf
(stdout," with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) \n");
fprintf
(stdout,"-d : offset of the origin of the image (-d 150,300) \n");
fprintf
(stdout,"-T : offset of the origin of the tiles (-T 100,75) \n");
fprintf(stdout,"-I : use the irreversible DWT 9-7 (-I) \n");
fprintf(stdout,"-W : image width, height and the dx and dy subsampling \n");
fprintf(stdout," of the Cb and Cr components for YUV files \n");
fprintf(stdout," (default is '352,288,2,2' for CIF format's 352x288 and 4:2:0)\n");
fprintf(stdout,"-F : video frame rate (set to 25 by default)\n");
fprintf(stdout,"-D : depth, precision in bits [8 .. 16]; default:8\n");
fprintf(stdout,"-C : comment\n");
fprintf(stdout,"\n");
fprintf(stdout,"IMPORTANT:\n");
fprintf(stdout,"-----------\n");
fprintf(stdout,"\n");
fprintf(stdout,"The index file has the structure below:\n");
fprintf(stdout,"---------------------------------------\n");
fprintf(stdout,"\n");
fprintf(stdout,"Image_height Image_width\n");
fprintf(stdout,"progression order\n");
fprintf(stdout,"Tiles_size_X Tiles_size_Y\n");
fprintf(stdout,"Components_nb\n");
fprintf(stdout,"Layers_nb\n");
fprintf(stdout,"decomposition_levels\n");
fprintf(stdout,"[Precincts_size_X_res_Nr Precincts_size_Y_res_Nr]...\n");
fprintf(stdout," [Precincts_size_X_res_0 Precincts_size_Y_res_0]\n");
fprintf(stdout,"Main_header_end_position\n");
fprintf(stdout,"Codestream_size\n");
fprintf(stdout,"Tile_0 start_pos end_Theader end_pos TotalDisto NumPix MaxMSE\n");
fprintf(stdout,"Tile_1 '' '' '' '' '' ''\n");
fprintf(stdout,"...\n");
fprintf(stdout,"Tile_Nt '' '' '' '' '' ''\n");
fprintf(stdout,"Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n");
fprintf(stdout,"...\n");
fprintf(stdout,"Tpacket_Np '' '' '' '' '' '' '' ''\n");
fprintf(stdout,"MaxDisto\n");
fprintf(stdout,"TotalDisto\n\n");
}
static OPJ_PROG_ORDER give_progression(const char progression[5])
{
if (progression[0] == 'L' && progression[1] == 'R'
&& progression[2] == 'C' && progression[3] == 'P') {
return LRCP;
} else {
if (progression[0] == 'R' && progression[1] == 'L'
&& progression[2] == 'C' && progression[3] == 'P') {
return RLCP;
} else {
if (progression[0] == 'R' && progression[1] == 'P'
&& progression[2] == 'C' && progression[3] == 'L') {
return RPCL;
} else {
if (progression[0] == 'P' && progression[1] == 'C'
&& progression[2] == 'R' && progression[3] == 'L') {
return PCRL;
} else {
if (progression[0] == 'C' && progression[1] == 'P'
&& progression[2] == 'R' && progression[3] == 'L') {
return CPRL;
} else {
return PROG_UNKNOWN;
}
}
}
}
}
}
int main(int argc, char **argv)
{
mj2_cparameters_t mj2_parameters; /* MJ2 compression parameters */
opj_cparameters_t *j2k_parameters; /* J2K compression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_cio_t *cio;
int value;
opj_mj2_t *movie;
opj_image_t *img;
int i, j;
char *s, S1, S2, S3;
unsigned char *buf;
int x1, y1, len;
long mdat_initpos, offset;
FILE *mj2file;
int sampleno;
opj_cinfo_t* cinfo;
opj_bool bSuccess;
int numframes;
int prec = 8;/* DEFAULT */
double total_time = 0;
memset(&mj2_parameters, 0, sizeof(mj2_cparameters_t));
/* default value */
/* ------------- */
mj2_parameters.w = 352; /* CIF default value*/
mj2_parameters.h = 288; /* CIF default value*/
mj2_parameters.CbCr_subsampling_dx = 2; /* CIF default value*/
mj2_parameters.CbCr_subsampling_dy = 2; /* CIF default value*/
mj2_parameters.frame_rate = 25;
mj2_parameters.prec = 8; /* DEFAULT */
mj2_parameters.enumcs = ENUMCS_SYCC; /* FIXME: ENUMCS_YUV420 */
mj2_parameters.meth = 1; /* enumerated color space */
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = NULL;
/* set J2K encoding parameters to default values */
opj_set_default_encoder_parameters(&mj2_parameters.j2k_parameters);
j2k_parameters = &mj2_parameters.j2k_parameters;
/* Create comment for codestream */
if(j2k_parameters->cp_comment == NULL) {
const char comment[] = "Created by OpenJPEG version ";
const size_t clen = strlen(comment);
const char *version = opj_version();
j2k_parameters->cp_comment = (char*)malloc(clen+strlen(version)+1);
sprintf(j2k_parameters->cp_comment,"%s%s", comment, version);
}
while (1) {
int c = opj_getopt(argc, argv,
"i:o:r:q:f:t:n:c:b:p:s:d:P:S:E:M:R:T:C:I:W:F:D:h");
if (c == -1)
break;
switch (c) {
case 'i': /* IN fill */
{
char *infile = opj_optarg;
s = opj_optarg;
while (*s) {
s++;
}
s--;
S3 = *s;
s--;
S2 = *s;
s--;
S1 = *s;
if ((S1 == 'y' && S2 == 'u' && S3 == 'v')
|| (S1 == 'Y' && S2 == 'U' && S3 == 'V')) {
mj2_parameters.decod_format = YUV_DFMT;
}
else {
fprintf(stderr,
"!! Unrecognized format for infile : %c%c%c [accept only *.yuv] !!\n\n",
S1, S2, S3);
return 1;
}
strncpy(mj2_parameters.infile, infile, sizeof(mj2_parameters.infile)-1);
}
break;
/* ----------------------------------------------------- */
case 'o': /* OUT fill */
{
char *outfile = opj_optarg;
while (*outfile) {
outfile++;
}
outfile--;
S3 = *outfile;
outfile--;
S2 = *outfile;
outfile--;
S1 = *outfile;
outfile = opj_optarg;
if ((S1 == 'm' && S2 == 'j' && S3 == '2')
|| (S1 == 'M' && S2 == 'J' && S3 == '2'))
mj2_parameters.cod_format = MJ2_CFMT;
else {
fprintf(stderr,
"Unknown output format image *.%c%c%c [only *.mj2]!! \n",
S1, S2, S3);
return 1;
}
strncpy(mj2_parameters.outfile, outfile, sizeof(mj2_parameters.outfile)-1);
}
break;
/* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */
{
float rate;
s = opj_optarg;
while (sscanf(s, "%f", &rate) == 1) {
j2k_parameters->tcp_rates[j2k_parameters->tcp_numlayers] = rate * 2;
j2k_parameters->tcp_numlayers++;
while (*s && *s != ',') {
s++;
}
if (!*s)
break;
s++;
}
j2k_parameters->cp_disto_alloc = 1;
}
break;
/* ----------------------------------------------------- */
case 'q': /* add fixed_quality */
s = opj_optarg;
while (sscanf(s, "%f", &j2k_parameters->tcp_distoratio[j2k_parameters->tcp_numlayers]) == 1) {
j2k_parameters->tcp_numlayers++;
while (*s && *s != ',') {
s++;
}
if (!*s)
break;
s++;
}
j2k_parameters->cp_fixed_quality = 1;
break;
/* dda */
/* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
s = opj_optarg;
sscanf(s, "%d", &numlayers);
s++;
if (numlayers > 9)
s++;
j2k_parameters->tcp_numlayers = numlayers;
numresolution = j2k_parameters->numresolution;
matrix_width = numresolution * 3;
j2k_parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
s = s + 2;
for (i = 0; i < numlayers; i++) {
row = &j2k_parameters->cp_matrice[i * matrix_width];
col = row;
j2k_parameters->tcp_rates[i] = 1;
sscanf(s, "%d,", &col[0]);
s += 2;
if (col[0] > 9)
s++;
col[1] = 0;
col[2] = 0;
for (j = 1; j < numresolution; j++) {
col += 3;
sscanf(s, "%d,%d,%d", &col[0], &col[1], &col[2]);
s += 6;
if (col[0] > 9)
s++;
if (col[1] > 9)
s++;
if (col[2] > 9)
s++;
}
if (i < numlayers - 1)
s++;
}
j2k_parameters->cp_fixed_alloc = 1;
}
break;
/* ----------------------------------------------------- */
case 't': /* tiles */
sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tdx, &j2k_parameters->cp_tdy);
j2k_parameters->tile_size_on = OPJ_TRUE;
break;
/* ----------------------------------------------------- */
case 'n': /* resolution */
sscanf(opj_optarg, "%d", &j2k_parameters->numresolution);
break;
/* ----------------------------------------------------- */
case 'c': /* precinct dimension */
{
char sep;
int res_spec = 0;
char *s = opj_optarg;
do {
sep = 0;
sscanf(s, "[%d,%d]%c", &j2k_parameters->prcw_init[res_spec],
&j2k_parameters->prch_init[res_spec], &sep);
j2k_parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
}
while (sep == ',');
j2k_parameters->res_spec = res_spec;
}
break;
/* ----------------------------------------------------- */
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
|| cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
fprintf(stderr,
"!! Size of code_block error (option -b) !!\n\nRestriction :\n"
" * width*height<=4096\n * 4<=width,height<= 1024\n\n");
return 1;
}
j2k_parameters->cblockw_init = cblockw_init;
j2k_parameters->cblockh_init = cblockh_init;
}
break;
/* ----------------------------------------------------- */
case 'p': /* progression order */
{
char progression[5];
strncpy(progression, opj_optarg, 5);
j2k_parameters->prog_order = give_progression(progression);
if (j2k_parameters->prog_order == -1) {
fprintf(stderr, "Unrecognized progression order "
"[LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->subsampling_dx,
&j2k_parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->image_offset_x0,
&j2k_parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
"error !! [-d x0,y0]\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 'h': /* Display an help description */
help_display();
return 0;
break;
/* ----------------------------------------------------- */
case 'P': /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
char *s = opj_optarg;
POC = j2k_parameters->POC;
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
&POC[numpocs].resno0, &POC[numpocs].compno0,
&POC[numpocs].layno1, &POC[numpocs].resno1,
&POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
POC[numpocs].prg1 = give_progression(POC[numpocs].progorder);
numpocs++;
while (*s && *s != '/') {
s++;
}
if (!*s) {
break;
}
s++;
}
j2k_parameters->numpocs = numpocs;
}
break;
/* ------------------------------------------------------ */
case 'S': /* SOP marker */
j2k_parameters->csty |= 0x02;
break;
/* ------------------------------------------------------ */
case 'E': /* EPH marker */
j2k_parameters->csty |= 0x04;
break;
/* ------------------------------------------------------ */
case 'M': /* Mode switch pas tous au point !! */
if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
int cache = value & (1 << i);
if (cache)
j2k_parameters->mode |= (1 << i);
}
}
break;
/* ------------------------------------------------------ */
case 'R': /* ROI */
{
if (sscanf(opj_optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno,
&j2k_parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
return 1;
}
}
break;
/* ------------------------------------------------------ */
case 'T': /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
}
}
break;
/* ------------------------------------------------------ */
case 'C': /* Add a comment */
{
j2k_parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(j2k_parameters->cp_comment) {
strcpy(j2k_parameters->cp_comment, opj_optarg);
}
}
break;
/* ------------------------------------------------------ */
case 'I': /* reversible or not */
{
j2k_parameters->irreversible = 1;
}
break;
/* ------------------------------------------------------ */
case 'W': /* Width and Height and Cb and Cr subsampling in case of YUV format files */
if (sscanf
(opj_optarg, "%d,%d,%d,%d", &mj2_parameters.w, &mj2_parameters.h, &mj2_parameters.CbCr_subsampling_dx,
&mj2_parameters.CbCr_subsampling_dy) != 4) {
fprintf(stderr, "-W argument error");
return 1;
}
break;
/* ------------------------------------------------------ */
case 'F': /* Video frame rate */
if (sscanf(opj_optarg, "%d", &mj2_parameters.frame_rate) != 1) {
fprintf(stderr, "-F argument error");
return 1;
}
break;
/* ------------------------------------------------------ */
case 'D': /* Depth: the precision */
if(sscanf(opj_optarg, "%d", &prec) != 1) prec = 0;
break;
default:
return 1;
}
}
/* Error messages */
/* -------------- */
if (!mj2_parameters.cod_format || !mj2_parameters.decod_format) {
fprintf(stderr,
"Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]);
return 1;
}
if(prec < 1 || prec > 16)
{
fprintf(stderr, "Error: Depth %d must be in the range 8 .. 16\n",prec);
return 1;
}
if ((j2k_parameters->cp_disto_alloc || j2k_parameters->cp_fixed_alloc || j2k_parameters->cp_fixed_quality)
&& (!(j2k_parameters->cp_disto_alloc ^ j2k_parameters->cp_fixed_alloc ^ j2k_parameters->cp_fixed_quality))) {
fprintf(stderr, "Error: options -r -q and -f cannot be used together !!\n");
return 1;
} /* mod fixed_quality */
/* if no rate entered, lossless by default */
if (j2k_parameters->tcp_numlayers == 0) {
j2k_parameters->tcp_rates[0] = 0; /* MOD antonin : losslessbug */
j2k_parameters->tcp_numlayers++;
j2k_parameters->cp_disto_alloc = 1;
}
if((j2k_parameters->cp_tx0 > j2k_parameters->image_offset_x0) || (j2k_parameters->cp_ty0 > j2k_parameters->image_offset_y0)) {
fprintf(stderr,
"Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
j2k_parameters->cp_tx0, j2k_parameters->image_offset_x0, j2k_parameters->cp_ty0, j2k_parameters->image_offset_y0);
return 1;
}
for (i = 0; i < j2k_parameters->numpocs; i++) {
if (j2k_parameters->POC[i].prg == -1) {
fprintf(stderr,
"Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n",
i + 1);
}
}
if (j2k_parameters->cp_tdx > mj2_parameters.Dim[0] || j2k_parameters->cp_tdy > mj2_parameters.Dim[1]) {
fprintf(stderr,
"Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
j2k_parameters->cp_tdx, mj2_parameters.Dim[0], j2k_parameters->cp_tdy, mj2_parameters.Dim[1]);
return 1;
}
/* to respect profile - 0 */
/* ---------------------- */
x1 = !mj2_parameters.Dim[0] ? (mj2_parameters.w - 1) * j2k_parameters->subsampling_dx
+ 1 : mj2_parameters.Dim[0] + (mj2_parameters.w - 1) * j2k_parameters->subsampling_dx + 1;
y1 = !mj2_parameters.Dim[1] ? (mj2_parameters.h - 1) * j2k_parameters->subsampling_dy
+ 1 : mj2_parameters.Dim[1] + (mj2_parameters.h - 1) * j2k_parameters->subsampling_dy + 1;
mj2_parameters.numcomps = 3; /* YUV files only have 3 components */
mj2_parameters.prec = prec;
j2k_parameters->tcp_mct = 0;
mj2file = fopen(mj2_parameters.outfile, "wb");
if (!mj2file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
movie = (opj_mj2_t*)cinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup encoder parameters */
mj2_setup_encoder(movie, &mj2_parameters);
movie->tk[0].num_samples =
yuv_num_frames(&movie->tk[0],mj2_parameters.infile);
if (movie->tk[0].num_samples == 0) {
return 1;
}
/* One sample per chunk*/
movie->tk[0].chunk = (mj2_chunk_t*)
malloc(movie->tk[0].num_samples * sizeof(mj2_chunk_t));
movie->tk[0].sample = (mj2_sample_t*)
malloc(movie->tk[0].num_samples * sizeof(mj2_sample_t));
if (mj2_init_stdmovie(movie)) {
fprintf(stderr, "Error with movie initialization");
return 1;
}
/* Writing JP, FTYP and MDAT boxes */
/* Assuming that the JP and FTYP boxes won't be longer than 300 bytes:*/
buf = (unsigned char*)
malloc (300 * sizeof(unsigned char));
cio = opj_cio_open((opj_common_ptr)movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
offset = cio_tell(cio);
opj_cio_close(cio);
free(buf);
for(i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++)
{
if(movie->tk[i].track_type != 0)
{
fprintf(stderr, "Unable to write sound or hint tracks\n");
}
else
{
mj2_tk_t *tk;
int buflen = 0;
tk = &movie->tk[i];
tk->num_chunks = tk->num_samples;
numframes = tk->num_samples;
tk->depth = prec;
fprintf(stderr, "Video Track number %d\n", i);
img = mj2_image_create(tk, j2k_parameters);
buflen = 2 * (tk->w * tk->h * 8);
buf = (unsigned char *) malloc(buflen*sizeof(unsigned char));
for(sampleno = 0; sampleno < numframes; sampleno++)
{
double init_time = opj_clock();
double elapsed_time;
if(yuvtoimage(tk, img, sampleno, j2k_parameters,
mj2_parameters.infile))
{
fprintf(stderr, "Error with frame number %d in YUV file\n", sampleno);
return 1;
}
/* setup the encoder parameters using the current image and user parameters */
opj_setup_encoder(cinfo, j2k_parameters, img);
cio = opj_cio_open((opj_common_ptr)movie->cinfo, buf, buflen);
cio_skip(cio, 4);
cio_write(cio, JP2_JP2C, 4); /* JP2C*/
/* encode the image */
bSuccess = opj_encode(cinfo, cio, img, NULL);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
return 1;
}
len = cio_tell(cio) - 8;
cio_seek(cio, 0);
cio_write(cio, len+8,4);
opj_cio_close(cio);
tk->sample[sampleno].sample_size = len+8;
tk->sample[sampleno].offset = offset;
tk->chunk[sampleno].offset = offset; /* There is one sample per chunk */
fwrite(buf, 1, len+8, mj2file);
offset += len+8;
elapsed_time = opj_clock()-init_time;
fprintf(stderr, "Frame number %d/%d encoded in %.2f mseconds\n",
sampleno + 1, numframes, elapsed_time*1000);
total_time += elapsed_time;
} /* for(sampleno */
free(buf);
opj_image_destroy(img);
}
}/* for(i */
fseek(mj2file, mdat_initpos, SEEK_SET);
buf = (unsigned char*) malloc(4*sizeof(unsigned char));
/* Init a cio to write box length variable in a little endian way */
cio = opj_cio_open(NULL, buf, 4);
cio_write(cio, offset - mdat_initpos, 4);
fwrite(buf, 4, 1, mj2file);
fseek(mj2file,0,SEEK_END);
free(buf);
/* Writing MOOV box */
buf = (unsigned char*)
malloc ((TEMP_BUF+numframes*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+numframes*20));
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
fprintf(stdout,"Total encoding time: %.2f s for %d frames (%.1f fps)\n",
total_time, numframes, (float)numframes/total_time);
/* Ending program */
fclose(mj2file);
/* free remaining compression structures */
mj2_destroy_compress(movie);
free(cinfo);
if(j2k_parameters->cp_comment) free(j2k_parameters->cp_comment);
if(j2k_parameters->cp_matrice) free(j2k_parameters->cp_matrice);
opj_cio_close(cio);
return 0;
}

View File

@ -0,0 +1,245 @@
/*
* Copyright (c) 2003-2004, Francois-Olivier Devaux
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "j2k_lib.h"
#include "cio.h"
#include "j2k.h"
#include "jp2.h"
#include "mj2.h"
#include "mj2_convert.h"
#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#endif
#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
#endif
#include "color.h"
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) {
mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
opj_cio_t *cio = NULL;
unsigned int tnum, snum;
opj_mj2_t *movie;
mj2_tk_t *track;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *file, *outfile;
char outfilename[50];
opj_image_t *img = NULL;
unsigned int max_codstrm_size = 0;
double total_time = 0;
unsigned int numframes = 0;
if (argc != 3) {
printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]);
return 1;
}
file = fopen(argv[1], "rb");
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
/* Checking output file */
outfile = fopen(argv[2], "w");
if (!file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
fclose(outfile);
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = NULL;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
movie = (opj_mj2_t*)dinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
memset(&mj2_parameters, 0, sizeof(mj2_dparameters_t));
/* set J2K decoding parameters to default values */
opj_set_default_decoder_parameters(&mj2_parameters.j2k_parameters);
/* setup the decoder decoding parameters using user parameters */
mj2_setup_decoder(movie, &mj2_parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure */
return 1;
/* Decode first video track */
for (tnum=0; tnum < (unsigned int)(movie->num_htk + movie->num_stk + movie->num_vtk); tnum++) {
if (movie->tk[tnum].track_type == 0)
break;
}
if (movie->tk[tnum].track_type != 0) {
printf("Error. Movie does not contain any video track\n");
return 1;
}
track = &movie->tk[tnum];
/* Output info on first video tracl */
fprintf(stdout,"The first video track contains %d frames.\nWidth: %d, Height: %d \n\n",
track->num_samples, track->w, track->h);
max_codstrm_size = track->sample[0].sample_size-8;
frame_codestream = (unsigned char*) malloc(max_codstrm_size * sizeof(unsigned char));
numframes = track->num_samples;
for (snum=0; snum < numframes; snum++)
{
double init_time = opj_clock();
double elapsed_time;
sample = &track->sample[snum];
if (sample->sample_size-8 > max_codstrm_size) {
max_codstrm_size = sample->sample_size-8;
if ((frame_codestream = (unsigned char*)
realloc(frame_codestream, max_codstrm_size)) == NULL) {
printf("Error reallocation memory\n");
return 1;
};
}
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream, sample->sample_size-8, 1, file); /* Assuming that jp and ftyp markers size do */
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
img = opj_decode(dinfo, cio); /* Decode J2K to image */
#ifdef WANT_SYCC_TO_RGB
if(img->color_space == CLRSPC_SYCC)
{
color_sycc_to_rgb(img);
}
#endif
if(img->icc_profile_buf)
{
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(img);
#endif
free(img->icc_profile_buf);
img->icc_profile_buf = NULL; img->icc_profile_len = 0;
}
if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2)
&& (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))
|| (img->numcomps == 1)) {
if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */
return 1;
}
else if ((img->numcomps == 3) &&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[2].dx == 1))/* If YUV 4:4:4 input --> to bmp */
{
fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n");
sprintf(outfilename,"output_%d.bmp",snum);
if (imagetobmp(img, outfilename)) /* Convert image to BMP */
return 1;
}
else {
fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");
sprintf(outfilename,"output_%d.j2k",snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
}
/* close the byte stream */
opj_cio_close(cio);
/* free image data structure */
opj_image_destroy(img);
elapsed_time = opj_clock()-init_time;
fprintf(stderr, "Frame number %d/%d decoded in %.2f mseconds\n", snum + 1, numframes, elapsed_time*1000);
total_time += elapsed_time;
}
free(frame_codestream);
fclose(file);
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
free(dinfo);
fprintf(stdout, "%d frame(s) correctly decompressed\n", snum);
fprintf(stdout,"Total decoding time: %.2f seconds (%.1f fps)\n", total_time, (float)numframes/total_time);
return 0;
}

View File

@ -0,0 +1,155 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "openjpeg.h"
#include "cio.h"
#include "j2k.h"
#include "jp2.h"
#include "mj2.h"
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) {
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
int tnum;
unsigned int snum;
opj_mj2_t *movie;
mj2_tk_t *track;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *file, *outfile;
char outfilename[50];
mj2_dparameters_t parameters;
if (argc != 3) {
printf("Usage: %s mj2filename output_location\n",argv[0]);
printf("Example: %s foreman.mj2 output/foreman\n",argv[0]);
return 1;
}
file = fopen(argv[1], "rb");
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_dparameters_t));
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(movie, &parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure*/
return 1;
/* Decode first video track */
tnum = 0;
while (movie->tk[tnum].track_type != 0)
tnum ++;
track = &movie->tk[tnum];
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++)
{
sample = &track->sample[snum];
frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream,sample->sample_size-8,1, file); /* Assuming that jp and ftyp markers size do*/
sprintf(outfilename,"%s_%05d.j2k",argv[2],snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
free(frame_codestream);
}
fclose(file);
fprintf(stdout, "%d frames correctly extracted\n", snum);
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
return 0;
}

526
src/bin/mj2/opj_mj2_wrap.c Normal file
View File

@ -0,0 +1,526 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "openjpeg.h"
#include "cio.h"
#include "j2k.h"
#include "jp2.h"
#include "mj2.h"
static int int_ceildiv(int a, int b) {
return (a + b - 1) / b;
}
/**
Size of memory first allocated for MOOV box
*/
#define TEMP_BUF 10000
#define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51"
/* -------------------------------------------------------------------------- */
static int test_image(const char *fname, mj2_cparameters_t *cp)
{
FILE *reader;
opj_image_t *image;
unsigned char *src;
opj_dinfo_t *dinfo;
opj_cio_t *cio;
opj_dparameters_t dparameters;
int success;
long src_len;
success = 0;
if((reader = fopen(fname, "rb")) == NULL) return success;
fseek(reader, 0, SEEK_END);
src_len = ftell(reader);
fseek(reader, 0, SEEK_SET);
src = (unsigned char*) malloc(src_len);
fread(src, 1, src_len, reader);
fclose(reader);
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0)
{
free(src); return success;
}
memset(&dparameters, 0, sizeof(opj_dparameters_t));
opj_set_default_decoder_parameters(&dparameters);
dinfo = opj_create_decompress(CODEC_J2K);
opj_setup_decoder(dinfo, &dparameters);
cio = opj_cio_open((opj_common_ptr)dinfo, src, src_len);
image = opj_decode(dinfo, cio);
free(src); cio->buffer = NULL;
opj_cio_close(cio);
if(image == NULL) goto fin;
cp->numcomps = image->numcomps;
cp->w = image->comps[0].w;
cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec;
if(image->numcomps > 2 )
{
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))/* horizontal and vertical*/
{
/* Y420*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 2;
}
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))/* horizontal only*/
{
/* Y422*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 1;
}
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
{
/* Y444 or RGB */
if(image->color_space == CLRSPC_SRGB)
{
cp->enumcs = ENUMCS_SRGB;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
}
else
{
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1;
}
}
else
{
goto fin;
}
}
else
{
cp->enumcs = ENUMCS_GRAY;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
}
if(image->icc_profile_buf)
{
cp->meth = 2;
free(image->icc_profile_buf); image->icc_profile_buf = NULL;
}
else cp->meth = 1;
success = 1;
fin:
if(dinfo)
opj_destroy_decompress(dinfo);
if(image)
opj_image_destroy(image);
return success;
}
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
static void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
static void read_siz_marker(FILE *file, opj_image_t *image)
{
int len,i;
char buf, buf2[2];
unsigned char *siz_buffer;
opj_cio_t *cio;
fseek(file, 0, SEEK_SET);
do {
fread(&buf,1,1, file);
if (buf==(char)0xff)
fread(&buf,1,1, file);
}
while (!(buf==(char)0x51));
fread(buf2,2,1,file); /* Lsiz */
len = ((buf2[0])<<8) + buf2[1];
siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char));
fread(siz_buffer,len, 1, file);
cio = opj_cio_open(NULL, siz_buffer, len);
cio_read(cio, 2); /* Rsiz (capabilities) */
image->x1 = cio_read(cio, 4); /* Xsiz */
image->y1 = cio_read(cio, 4); /* Ysiz */
image->x0 = cio_read(cio, 4); /* X0siz */
image->y0 = cio_read(cio, 4); /* Y0siz */
cio_skip(cio, 16); /* XTsiz, YTsiz, XT0siz, YT0siz */
image->numcomps = cio_read(cio,2); /* Csiz */
image->comps =
(opj_image_comp_t *) malloc(image->numcomps * sizeof(opj_image_comp_t));
for (i = 0; i < image->numcomps; i++) {
int tmp;
tmp = cio_read(cio,1); /* Ssiz_i */
image->comps[i].prec = (tmp & 0x7f) + 1;
image->comps[i].sgnd = tmp >> 7;
image->comps[i].dx = cio_read(cio,1); /* XRsiz_i */
image->comps[i].dy = cio_read(cio,1); /* YRsiz_i */
image->comps[i].resno_decoded = 0; /* number of resolution decoded */
image->comps[i].factor = 0; /* reducing factor by component */
}
fseek(file, 0, SEEK_SET);
opj_cio_close(cio);
free(siz_buffer);
}
static void setparams(opj_mj2_t *movie, opj_image_t *image) {
int i, depth_0, depth, sign;
movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
mj2_init_stdmovie(movie);
movie->tk[0].depth = image->comps[0].prec;
if (image->numcomps==3) {
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1;
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
}
movie->tk[0].sample_rate = 25;
movie->tk[0].jp2_struct.numcomps = image->numcomps; /* NC */
/* Init Standard jp2 structure */
movie->tk[0].jp2_struct.comps =
(opj_jp2_comps_t *) malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.precedence = 0; /* PRECEDENCE*/
movie->tk[0].jp2_struct.approx = 0; /* APPROX*/
movie->tk[0].jp2_struct.brand = JP2_JP2; /* BR */
movie->tk[0].jp2_struct.minversion = 0; /* MinV */
movie->tk[0].jp2_struct.numcl = 1;
movie->tk[0].jp2_struct.cl = (unsigned int *) malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl[0] = JP2_JP2; /* CL0 : JP2 */
movie->tk[0].jp2_struct.C = 7; /* C : Always 7*/
movie->tk[0].jp2_struct.UnkC = 0; /* UnkC, colorspace specified in colr box*/
movie->tk[0].jp2_struct.IPR = 0; /* IPR, no intellectual property*/
movie->tk[0].jp2_struct.w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].jp2_struct.h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
movie->tk[0].jp2_struct.bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
movie->tk[0].jp2_struct.bpc = 255;
}
for (i = 0; i < image->numcomps; i++)
movie->tk[0].jp2_struct.comps[i].bpcc =
image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
if ((image->numcomps == 1 || image->numcomps == 3)
&& (movie->tk[0].jp2_struct.bpc != 255))
movie->tk[0].jp2_struct.meth = 1;
else
movie->tk[0].jp2_struct.meth = 2;
if (image->numcomps == 1)
movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
else
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
}
int main(int argc, char *argv[]) {
opj_cinfo_t* cinfo;
opj_event_mgr_t event_mgr; /* event manager */
unsigned int snum;
opj_mj2_t *movie;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *mj2file, *j2kfile;
char *j2kfilename;
unsigned char *buf;
int offset, mdat_initpos;
opj_image_t img;
opj_cio_t *cio;
mj2_cparameters_t parameters;
if (argc != 3) {
printf("Usage: %s source_location mj2_filename\n",argv[0]);
printf("Example: %s input/input output.mj2\n",argv[0]);
return 1;
}
mj2file = fopen(argv[2], "wb");
if (!mj2file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
memset(&img, 0, sizeof(opj_image_t));
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the decoder encoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_cparameters_t));
movie = (opj_mj2_t*) cinfo->mj2_handle;
j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
parameters.frame_rate = 25; /* DEFAULT */
mj2_setup_encoder(movie, &parameters);
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio,MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1)
{
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
}
else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}
}
/* Calculating offset for samples and chunks */
offset += cio_tell(cio);
sample->offset = offset;
movie->tk[0].chunk[snum].offset = offset; /* There will be one sample per chunk */
/* Calculating sample size */
fseek(j2kfile,0,SEEK_END);
sample->sample_size = ftell(j2kfile) + 8; /* Sample size is codestream + JP2C box header */
fseek(j2kfile,0,SEEK_SET);
/* Reading siz marker of j2k image for the first codestream */
if (snum==0)
read_siz_marker(j2kfile, &img);
/* Writing JP2C box header */
frame_codestream = (unsigned char*) malloc (sample->sample_size+8);
cio = opj_cio_open(movie->cinfo, frame_codestream, sample->sample_size);
cio_write(cio,sample->sample_size, 4); /* Sample size */
cio_write(cio,JP2_JP2C, 4); /* JP2C */
/* Writing codestream from J2K file to MJ2 file */
fread(frame_codestream+8,sample->sample_size-8,1,j2kfile);
fwrite(frame_codestream,sample->sample_size,1,mj2file);
cio_skip(cio, sample->sample_size-8);
/* Ending loop */
fclose(j2kfile);
snum++;
new_sample = (mj2_sample_t*)
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
new_chunk = (mj2_chunk_t*)
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
if (new_sample && new_chunk) {
movie->tk[0].sample = new_sample;
movie->tk[0].chunk = new_chunk;
} else {
fprintf(stderr, "Failed to allocate enough memory to read %s\n", j2kfilename);
return 1;
}
free(frame_codestream);
}
/* Writing the MDAT box length in header */
offset += cio_tell(cio);
buf = (unsigned char*) malloc (4 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 4);
cio_write(cio,offset-mdat_initpos,4);
fseek(mj2file,(long)mdat_initpos,SEEK_SET);
fwrite(buf,4,1,mj2file);
fseek(mj2file,0,SEEK_END);
free(buf);
/* Setting movie parameters */
movie->tk[0].num_samples=snum;
movie->tk[0].num_chunks=snum;
setparams(movie, &img);
/* Writing MOOV box */
buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20));
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);
/* Ending program */
free(img.comps);
opj_cio_close(cio);
fin:
fclose(mj2file);
mj2_destroy_compress(movie);
free(j2kfilename);
return 0;
}

3
src/bin/mj2/readme.txt Normal file
View File

@ -0,0 +1,3 @@
Attention : the motion jpeg 2000 files currently only work with OpenJPEG v0.97 that you can find here :
http://www.openjpeg.org/openjpeg_v097.tar.gz

View File

@ -1,6 +1,6 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -36,7 +36,7 @@
/////////////////////////////////////////////////////////////////////
OPJEncoThread::OPJEncoThread(OPJCanvas *canvas)
: wxThread()
: wxThread()
{
m_count = 0;
m_canvas = canvas;
@ -49,14 +49,14 @@ void OPJEncoThread::WriteText(const wxString& text)
// before doing any GUI calls we must ensure that this thread is the only
// one doing it!
#ifndef __WXGTK__
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif // __WXGTK__
msg << text;
m_canvas->WriteText(msg);
#ifndef __WXGTK__
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif // __WXGTK__
}
@ -68,7 +68,8 @@ void OPJEncoThread::OnExit()
wxArrayThread& ethreads = wxGetApp().m_enco_threads;
ethreads.Remove(this);
if (ethreads.IsEmpty()) {
if (ethreads.IsEmpty() )
{
// signal the main thread that there are no more threads left if it is
// waiting for us
if (wxGetApp().m_enco_waitingUntilAllDone) {
@ -82,54 +83,50 @@ void *OPJEncoThread::Entry()
{
wxString text;
srand(GetId());
//int m_countnum = rand() % 9;
srand(GetId());
//int m_countnum = rand() % 9;
//text.Printf(wxT("Deco thread 0x%lx started (priority = %u, time = %d)."),
// GetId(), GetPriority(), m_countnum);
text.Printf(wxT("Enco thread %d started"), m_canvas->m_childframe->m_winnumber);
WriteText(text);
// set handler properties
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(
wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_subsampling = wxGetApp().m_subsampling;
jpeg2000handler->m_origin = wxGetApp().m_origin;
jpeg2000handler->m_rates = wxGetApp().m_rates;
jpeg2000handler->m_quality = wxGetApp().m_quality;
jpeg2000handler->m_enablequality = wxGetApp().m_enablequality;
jpeg2000handler->m_multicomp = wxGetApp().m_multicomp;
jpeg2000handler->m_irreversible = wxGetApp().m_irreversible;
jpeg2000handler->m_resolutions = wxGetApp().m_resolutions;
jpeg2000handler->m_progression = wxGetApp().m_progression;
jpeg2000handler->m_cbsize = wxGetApp().m_cbsize;
jpeg2000handler->m_prsize = wxGetApp().m_prsize;
jpeg2000handler->m_tsize = wxGetApp().m_tsize;
jpeg2000handler->m_torigin = wxGetApp().m_torigin;
jpeg2000handler->m_enablesop = wxGetApp().m_enablesop;
jpeg2000handler->m_enableeph = wxGetApp().m_enableeph;
jpeg2000handler->m_enablebypass = wxGetApp().m_enablebypass;
jpeg2000handler->m_enablerestart = wxGetApp().m_enablerestart;
jpeg2000handler->m_enablereset = wxGetApp().m_enablereset;
jpeg2000handler->m_enablesegmark = wxGetApp().m_enablesegmark;
jpeg2000handler->m_enableerterm = wxGetApp().m_enableerterm;
jpeg2000handler->m_enablevsc = wxGetApp().m_enablevsc;
jpeg2000handler->m_enableidx = wxGetApp().m_enableidx;
jpeg2000handler->m_index = m_canvas->m_savename.GetPath(
wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index;
jpeg2000handler->m_enablecomm = wxGetApp().m_enablecomm;
jpeg2000handler->m_comment = wxGetApp().m_comment;
jpeg2000handler->m_enablepoc = wxGetApp().m_enablepoc;
jpeg2000handler->m_poc = wxGetApp().m_poc;
// set handler properties
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_subsampling = wxGetApp().m_subsampling;
jpeg2000handler->m_origin = wxGetApp().m_origin;
jpeg2000handler->m_rates = wxGetApp().m_rates;
jpeg2000handler->m_quality = wxGetApp().m_quality;
jpeg2000handler->m_enablequality = wxGetApp().m_enablequality;
jpeg2000handler->m_multicomp = wxGetApp().m_multicomp;
jpeg2000handler->m_irreversible = wxGetApp().m_irreversible;
jpeg2000handler->m_resolutions = wxGetApp().m_resolutions;
jpeg2000handler->m_progression = wxGetApp().m_progression;
jpeg2000handler->m_cbsize = wxGetApp().m_cbsize;
jpeg2000handler->m_prsize = wxGetApp().m_prsize;
jpeg2000handler->m_tsize = wxGetApp().m_tsize;
jpeg2000handler->m_torigin = wxGetApp().m_torigin;
jpeg2000handler->m_enablesop = wxGetApp().m_enablesop;
jpeg2000handler->m_enableeph = wxGetApp().m_enableeph;
jpeg2000handler->m_enablebypass = wxGetApp().m_enablebypass;
jpeg2000handler->m_enablerestart = wxGetApp().m_enablerestart;
jpeg2000handler->m_enablereset = wxGetApp().m_enablereset;
jpeg2000handler->m_enablesegmark = wxGetApp().m_enablesegmark;
jpeg2000handler->m_enableerterm = wxGetApp().m_enableerterm;
jpeg2000handler->m_enablevsc = wxGetApp().m_enablevsc;
jpeg2000handler->m_enableidx = wxGetApp().m_enableidx;
jpeg2000handler->m_index = m_canvas->m_savename.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index;
jpeg2000handler->m_enablecomm = wxGetApp().m_enablecomm;
jpeg2000handler->m_comment = wxGetApp().m_comment;
jpeg2000handler->m_enablepoc = wxGetApp().m_enablepoc;
jpeg2000handler->m_poc = wxGetApp().m_poc;
// save the file
if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(),
(wxBitmapType) wxBITMAP_TYPE_JPEG2000)) {
WriteText(wxT("Can't save image"));
return NULL;
}
// save the file
if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(), (wxBitmapType) wxBITMAP_TYPE_JPEG2000)) {
WriteText(wxT("Can't save image"));
return NULL;
}
text.Printf(wxT("Enco thread %d finished"),
m_canvas->m_childframe->m_winnumber);
text.Printf(wxT("Enco thread %d finished"), m_canvas->m_childframe->m_winnumber);
WriteText(text);
return NULL;
}
@ -139,7 +136,7 @@ void *OPJEncoThread::Entry()
// Decoding thread class
/////////////////////////////////////////////////////////////////////
OPJDecoThread::OPJDecoThread(OPJCanvas *canvas)
: wxThread()
: wxThread()
{
m_count = 0;
m_canvas = canvas;
@ -148,29 +145,29 @@ OPJDecoThread::OPJDecoThread(OPJCanvas *canvas)
void OPJDecoThread::WriteText(const wxString& text)
{
wxString msg;
// we use a fake event and post it for inter-thread gui communication
// we use a fake event and post it for inter-thread gui communication
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_THREADLOGMSG);
event.SetInt(-1);
msg << text;
event.SetString(msg);
event.SetInt(-1);
msg << text;
event.SetString(msg);
wxPostEvent(this->m_canvas->m_childframe->m_frame, event);
/*
// before doing any GUI calls we must ensure that this thread is the only
// one doing it!
/*
// before doing any GUI calls we must ensure that this thread is the only
// one doing it!
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif // __WXGTK__
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif // __WXGTK__
msg << text;
m_canvas->WriteText(msg);
msg << text;
m_canvas->WriteText(msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif // __WXGTK__
*/
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif // __WXGTK__
*/
}
void OPJDecoThread::OnExit()
@ -180,7 +177,8 @@ void OPJDecoThread::OnExit()
wxArrayThread& dthreads = wxGetApp().m_deco_threads;
dthreads.Remove(this);
if (dthreads.IsEmpty()) {
if (dthreads.IsEmpty() )
{
// signal the main thread that there are no more threads left if it is
// waiting for us
if (wxGetApp().m_deco_waitingUntilAllDone) {
@ -195,98 +193,95 @@ void *OPJDecoThread::Entry()
wxString text;
//srand(GetId());
//int m_countnum = rand() % 9;
//srand(GetId());
//int m_countnum = rand() % 9;
//text.Printf(wxT("Deco thread 0x%lx started (priority = %u, time = %d)."),
// GetId(), GetPriority(), m_countnum);
// we have started
// we have started
text.Printf(wxT("Deco thread %d started"), m_canvas->m_childframe->m_winnumber);
WriteText(text);
// prepare dummy wximage
// prepare dummy wximage
wxBitmap bitmap(100, 100);
wxImage image(100, 100, true); //= bitmap.ConvertToImage();
image.Destroy();
// show image full name
WriteText(m_canvas->m_fname.GetFullPath());
// show image full name
WriteText(m_canvas->m_fname.GetFullPath());
// set handler properties
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(
wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_reducefactor = wxGetApp().m_reducefactor;
jpeg2000handler->m_qualitylayers = wxGetApp().m_qualitylayers;
jpeg2000handler->m_components = wxGetApp().m_components;
jpeg2000handler->m_framenum = wxGetApp().m_framenum;
// set handler properties
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_reducefactor = wxGetApp().m_reducefactor;
jpeg2000handler->m_qualitylayers = wxGetApp().m_qualitylayers;
jpeg2000handler->m_components = wxGetApp().m_components;
jpeg2000handler->m_framenum = wxGetApp().m_framenum;
#ifdef USE_JPWL
jpeg2000handler->m_enablejpwl = wxGetApp().m_enablejpwl;
jpeg2000handler->m_expcomps = wxGetApp().m_expcomps;
jpeg2000handler->m_maxtiles = wxGetApp().m_maxtiles;
jpeg2000handler->m_enablejpwl = wxGetApp().m_enablejpwl;
jpeg2000handler->m_expcomps = wxGetApp().m_expcomps;
jpeg2000handler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL
#ifdef USE_MXF
wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler(
wxBITMAP_TYPE_MXF);
mxfffhandler->m_reducefactor = wxGetApp().m_reducefactor;
mxfffhandler->m_qualitylayers = wxGetApp().m_qualitylayers;
mxfffhandler->m_components = wxGetApp().m_components;
mxfffhandler->m_framenum = wxGetApp().m_framenum;
mxfffhandler->m_filename = m_canvas->m_fname;
wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler(wxBITMAP_TYPE_MXF);
mxfffhandler->m_reducefactor = wxGetApp().m_reducefactor;
mxfffhandler->m_qualitylayers = wxGetApp().m_qualitylayers;
mxfffhandler->m_components = wxGetApp().m_components;
mxfffhandler->m_framenum = wxGetApp().m_framenum;
mxfffhandler->m_filename = m_canvas->m_fname;
#ifdef USE_JPWL
mxfffhandler->m_enablejpwl = wxGetApp().m_enablejpwl;
mxfffhandler->m_expcomps = wxGetApp().m_expcomps;
mxfffhandler->m_maxtiles = wxGetApp().m_maxtiles;
mxfffhandler->m_enablejpwl = wxGetApp().m_enablejpwl;
mxfffhandler->m_expcomps = wxGetApp().m_expcomps;
mxfffhandler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL
#endif // USE_MXF
// if decoding is enabled...
if (wxGetApp().m_enabledeco) {
// if decoding is enabled...
if (wxGetApp().m_enabledeco) {
// load the file
if (!image.LoadFile(m_canvas->m_fname.GetFullPath(), wxBITMAP_TYPE_ANY, 0)) {
WriteText(wxT("Can't load image!"));
return NULL;
}
// load the file
if (!image.LoadFile(m_canvas->m_fname.GetFullPath(), wxBITMAP_TYPE_ANY, 0)) {
WriteText(wxT("Can't load image!"));
return NULL;
}
} else {
} else {
// display a warning
if (!image.Create(300, 5, false)) {
WriteText(wxT("Can't create image!"));
return NULL;
}
// display a warning
if (!image.Create(300, 5, false)) {
WriteText(wxT("Can't create image!"));
return NULL;
}
}
}
// assign 100% image
// assign 100% image
m_canvas->m_image100 = wxBitmap(image);
// signal the frame to refresh the canvas
// signal the frame to refresh the canvas
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_VIEWFIT);
event.SetString(wxT("Fit me"));
event.SetInt(m_canvas->m_childframe->m_winnumber);
event.SetString(wxT("Fit me"));
event.SetInt(m_canvas->m_childframe->m_winnumber);
wxPostEvent(m_canvas->m_childframe->m_frame, event);
// find a fit-to-width zoom
/*int zooml, wzooml, hzooml;
wxSize clientsize = m_canvas->GetClientSize();
wzooml = (int) floor(100.0 * (double) clientsize.GetWidth() / (double) (2 * OPJ_CANVAS_BORDER + image.GetWidth()));
hzooml = (int) floor(100.0 * (double) clientsize.GetHeight() / (double) (2 * OPJ_CANVAS_BORDER + image.GetHeight()));
zooml = wxMin(100, wxMin(wzooml, hzooml));*/
// find a fit-to-width zoom
/*int zooml, wzooml, hzooml;
wxSize clientsize = m_canvas->GetClientSize();
wzooml = (int) floor(100.0 * (double) clientsize.GetWidth() / (double) (2 * OPJ_CANVAS_BORDER + image.GetWidth()));
hzooml = (int) floor(100.0 * (double) clientsize.GetHeight() / (double) (2 * OPJ_CANVAS_BORDER + image.GetHeight()));
zooml = wxMin(100, wxMin(wzooml, hzooml));*/
// fit to width
// fit to width
#ifndef __WXGTK__
//m_canvas->m_childframe->m_frame->Rescale(zooml, m_canvas->m_childframe);
//m_canvas->m_childframe->m_frame->Rescale(zooml, m_canvas->m_childframe);
#endif // __WXGTK__
//m_canvas->m_image = m_canvas->m_image100;
//m_canvas->Refresh();
//m_canvas->SetScrollbars(20, 20, (int)(0.5 + (double) image.GetWidth() / 20.0), (int)(0.5 + (double) image.GetHeight() / 20.0));
//m_canvas->m_image = m_canvas->m_image100;
//m_canvas->Refresh();
//m_canvas->SetScrollbars(20, 20, (int)(0.5 + (double) image.GetWidth() / 20.0), (int)(0.5 + (double) image.GetHeight() / 20.0));
//text.Printf(wxT("Deco thread 0x%lx finished."), GetId());
text.Printf(wxT("Deco thread %d finished"),
m_canvas->m_childframe->m_winnumber);
text.Printf(wxT("Deco thread %d finished"), m_canvas->m_childframe->m_winnumber);
WriteText(text);
return NULL;
@ -297,37 +292,37 @@ void *OPJDecoThread::Entry()
/////////////////////////////////////////////////////////////////////
OPJParseThread::OPJParseThread(OPJMarkerTree *tree, wxTreeItemId parentid)
: wxThread()
: wxThread()
{
m_count = 0;
m_tree = tree;
m_parentid = parentid;
m_parentid = parentid;
}
void OPJParseThread::WriteText(const wxString& text)
{
wxString msg;
// we use a fake event and post it for inter-thread gui communication
// we use a fake event and post it for inter-thread gui communication
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_THREADLOGMSG);
event.SetInt(-1);
msg << text;
event.SetString(msg);
event.SetInt(-1);
msg << text;
event.SetString(msg);
wxPostEvent(this->m_tree->m_childframe->m_frame, event);
/* // before doing any GUI calls we must ensure that this thread is the only
// one doing it!
/* // before doing any GUI calls we must ensure that this thread is the only
// one doing it!
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif // __WXGTK
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif // __WXGTK
msg << text;
m_tree->WriteText(msg);
msg << text;
m_tree->WriteText(msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif // __WXGTK*/
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif // __WXGTK*/
}
void OPJParseThread::OnExit()
@ -350,14 +345,14 @@ void OPJParseThread::OnExit()
void *OPJParseThread::Entry()
{
printf("Entering\n\n");
printf("Entering\n\n");
wxString text;
srand(GetId());
int m_countnum = rand() % 9;
srand(GetId());
int m_countnum = rand() % 9;
text.Printf(wxT("Parse thread 0x%lx started (priority = %u, time = %d)."),
GetId(), GetPriority(), m_countnum);
GetId(), GetPriority(), m_countnum);
WriteText(text);
LoadFile(m_tree->m_fname);
text.Printf(wxT("Parse thread 0x%lx finished."), GetId());
@ -366,8 +361,8 @@ void *OPJParseThread::Entry()
//wxLogMessage(wxT("Entering\n")); //test wxLog thread safeness
//wxBusyCursor wait;
//wxBusyInfo wait(wxT("Decoding image ..."));
//wxBusyCursor wait;
//wxBusyInfo wait(wxT("Decoding image ..."));
/*for ( m_count = 0; m_count < m_countnum; m_count++ )
@ -385,7 +380,7 @@ void *OPJParseThread::Entry()
// wxLogMessage(text); -- test wxLog thread safeness
printf("Exiting\n\n");
printf("Exiting\n\n");
return NULL;
}
@ -398,7 +393,7 @@ void *OPJParseThread::Entry()
#if USE_GENERIC_TREECTRL
BEGIN_EVENT_TABLE(OPJMarkerTree, wxGenericTreeCtrl)
#else
BEGIN_EVENT_TABLE(OPJMarkerTree, wxTreeCtrl)
BEGIN_EVENT_TABLE(OPJMarkerTree, wxTreeCtrl)
#endif
/*EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginDrag)
EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginRDrag)
@ -420,7 +415,7 @@ BEGIN_EVENT_TABLE(OPJMarkerTree, wxGenericTreeCtrl)
/*EVT_TREE_KEY_DOWN(TreeTest_Ctrl, OPJMarkerTree::OnTreeKeyDown)*/
/*EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, OPJMarkerTree::OnItemActivated)*/
// so many different ways to handle right mouse button clicks...
// so many differents ways to handle right mouse button clicks...
/*EVT_CONTEXT_MENU(OPJMarkerTree::OnContextMenu)*/
// EVT_TREE_ITEM_MENU is the preferred event for creating context menus
// on a tree control, because it includes the point of the click or item,
@ -440,16 +435,14 @@ IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxGenericTreeCtrl)
IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxTreeCtrl)
#endif
OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe,
wxFileName fname, wxString name, const wxWindowID id,
const wxPoint& pos, const wxSize& size, long style)
: wxTreeCtrl(parent, id, pos, size, style)
OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id,
const wxPoint& pos, const wxSize& size, long style)
: wxTreeCtrl(parent, id, pos, size, style)
{
m_reverseSort = false;
m_fname = fname;
m_fname = fname;
m_peektextCtrl = ((OPJFrame *)(
parent->GetParent()->GetParent()))->m_textCtrlbrowse;
m_peektextCtrl = ((OPJFrame *) (parent->GetParent()->GetParent()))->m_textCtrlbrowse;
CreateImageList();
// Add some items to the tree
@ -460,13 +453,12 @@ OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe,
new OPJMarkerData(name));
OPJParseThread *pthread = CreateParseThread(0x00, subframe);
if (pthread->Run() != wxTHREAD_NO_ERROR) {
if (pthread->Run() != wxTHREAD_NO_ERROR)
wxLogMessage(wxT("Can't start parse thread!"));
} else {
wxLogMessage(wxT("New parse thread started."));
}
else
wxLogMessage(wxT("New parse thread started."));
m_childframe = subframe;
m_childframe = subframe;
}
void OPJMarkerTree::CreateImageList(int size)
@ -475,11 +467,10 @@ void OPJMarkerTree::CreateImageList(int size)
SetImageList(NULL);
return;
}
if (size == 0) {
if (size == 0)
size = m_imageSize;
} else {
else
m_imageSize = size;
}
// Make an image list containing small icons
wxImageList *images = new wxImageList(size, size, true);
@ -508,7 +499,7 @@ void OPJMarkerTree::CreateImageList(int size)
#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
void OPJMarkerTree::CreateButtonsImageList(int size)
{
if (size == -1) {
if ( size == -1 ) {
SetButtonsImageList(NULL);
return;
}
@ -524,9 +515,9 @@ void OPJMarkerTree::CreateButtonsImageList(int size)
icons[2] = wxIcon(icon5_xpm); // open
icons[3] = wxIcon(icon5_xpm); // open, selected
for (size_t i = 0; i < WXSIZEOF(icons); i++) {
for ( size_t i = 0; i < WXSIZEOF(icons); i++ ) {
int sizeOrig = icons[i].GetWidth();
if (size == sizeOrig) {
if ( size == sizeOrig ) {
images->Add(icons[i]);
} else {
images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
@ -542,79 +533,77 @@ void OPJMarkerTree::CreateButtonsImageList(int WXUNUSED(size))
void OPJParseThread::LoadFile(wxFileName fname)
{
wxTreeItemId rootid;
wxTreeItemId rootid;
// this is the root node
int image = wxGetApp().ShowImages() ? m_tree->TreeCtrlIcon_Folder : -1;
// this is the root node
int image = wxGetApp().ShowImages() ? m_tree->TreeCtrlIcon_Folder : -1;
if (this->m_parentid) {
// leaf of a tree
rootid = m_parentid;
m_tree->SetItemText(rootid, wxT("Parsing..."));
if (this->m_parentid) {
// leaf of a tree
rootid = m_parentid;
m_tree->SetItemText(rootid, wxT("Parsing..."));
} else {
} else {
// delete the existing tree hierarchy
m_tree->DeleteAllItems();
// delete the existing tree hierarchy
m_tree->DeleteAllItems();
// new tree
rootid = m_tree->AddRoot(wxT("Parsing..."),
image,
image,
new OPJMarkerData(fname.GetFullPath())
);
//m_tree->SetItemFont(rootid, *wxITALIC_FONT);
m_tree->SetItemBold(rootid);
}
// new tree
rootid = m_tree->AddRoot(wxT("Parsing..."),
image,
image,
new OPJMarkerData(fname.GetFullPath())
);
//m_tree->SetItemFont(rootid, *wxITALIC_FONT);
m_tree->SetItemBold(rootid);
}
// open the file
wxFile m_file(fname.GetFullPath().c_str(), wxFile::read);
// open the file
wxFile m_file(fname.GetFullPath().c_str(), wxFile::read);
// parsing enabled?
if (wxGetApp().m_enableparse) {
// parsing enabled?
if (wxGetApp().m_enableparse) {
// what is the extension?
if ((fname.GetExt() == wxT("j2k")) || (fname.GetExt() == wxT("j2c"))) {
// what is the extension?
if ((fname.GetExt() == wxT("j2k")) || (fname.GetExt() == wxT("j2c"))) {
// parse the file
ParseJ2KFile(&m_file, 0, m_file.Length(), rootid);
// parse the file
ParseJ2KFile(&m_file, 0, m_file.Length(), rootid);
} else if ((fname.GetExt() == wxT("jp2")) || (fname.GetExt() == wxT("mj2"))) {
} else if ((fname.GetExt() == wxT("jp2")) || (fname.GetExt() == wxT("mj2"))) {
// parse the file
if (this->m_parentid) {
//WriteText(wxT("Only a subsection of jp2"));
OPJMarkerData *data = (OPJMarkerData *) m_tree->GetItemData(rootid);
ParseJ2KFile(&m_file, data->m_start, data->m_length, rootid);
m_tree->Expand(rootid);
// parse the file
if (this->m_parentid) {
//WriteText(wxT("Only a subsection of jp2"));
OPJMarkerData *data = (OPJMarkerData *) m_tree->GetItemData(rootid);
ParseJ2KFile(&m_file, data->m_start, data->m_length, rootid);
m_tree->Expand(rootid);
} else {
// as usual
ParseJP2File(&m_file, 0, m_file.Length(), rootid);
}
} else {
// as usual
ParseJP2File(&m_file, 0, m_file.Length(), rootid);
}
} else {
} else {
// unknown extension
WriteText(wxT("Unknown file format!"));
// unknown extension
WriteText(wxT("Unknown file format!"));
}
}
}
}
// this is the root node
if (this->m_parentid) {
m_tree->SetItemText(rootid, wxT("Codestream"));
} else
//m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length()));
{
m_tree->SetItemText(rootid, fname.GetFullName());
}
// this is the root node
if (this->m_parentid)
m_tree->SetItemText(rootid, wxT("Codestream"));
else
//m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length()));
m_tree->SetItemText(rootid, fname.GetFullName());
// close the file
m_file.Close();
// close the file
m_file.Close();
WriteText(wxT("Parsing finished!"));
WriteText(wxT("Parsing finished!"));
}
/*int OPJMarkerTree::OnCompareItems(const wxTreeItemId& item1,
@ -749,22 +738,19 @@ void OPJMarkerTree::LogEvent(const wxChar *name, const wxTreeEvent& event)
{
wxTreeItemId item = event.GetItem();
wxString text;
if (item.IsOk()) {
if ( item.IsOk() )
text << wxT('"') << GetItemText(item).c_str() << wxT('"');
} else {
else
text = wxT("invalid item");
}
wxLogMessage(wxT("%s(%s)"), name, text.c_str());
}
OPJParseThread *OPJMarkerTree::CreateParseThread(wxTreeItemId parentid,
OPJChildFrame *subframe)
OPJParseThread *OPJMarkerTree::CreateParseThread(wxTreeItemId parentid, OPJChildFrame *subframe)
{
OPJParseThread *pthread = new OPJParseThread(this, parentid);
if (pthread->Create() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("Can't create parse thread!"));
}
if (pthread->Create() != wxTHREAD_NO_ERROR)
wxLogError(wxT("Can't create parse thread!"));
wxCriticalSectionLocker enter(wxGetApp().m_parse_critsect);
wxGetApp().m_parse_threads.Add(pthread);
@ -796,122 +782,114 @@ TREE_EVENT_HANDLER(OnSelChanging)*/
void OPJMarkerTree::OnItemExpanding(wxTreeEvent& event)
{
wxTreeItemId item = event.GetItem();
OPJMarkerData* data = (OPJMarkerData *) GetItemData(item);
wxString text;
wxTreeItemId item = event.GetItem();
OPJMarkerData* data = (OPJMarkerData *) GetItemData(item);
wxString text;
if (item.IsOk()) {
text << wxT('"') << GetItemText(item).c_str() << wxT('"');
} else {
text = wxT("invalid item");
}
if (item.IsOk())
text << wxT('"') << GetItemText(item).c_str() << wxT('"');
else
text = wxT("invalid item");
if (wxStrcmp(data->GetDesc1(), wxT("INFO-CSTREAM"))) {
return;
}
if (wxStrcmp(data->GetDesc1(), wxT("INFO-CSTREAM")))
return;
wxLogMessage(wxT("Expanding... (%s -> %s, %s, %d, %d)"),
text.c_str(), data->GetDesc1(), data->GetDesc2(),
data->m_start, data->m_length);
wxLogMessage(wxT("Expanding... (%s -> %s, %s, %d, %d)"),
text.c_str(), data->GetDesc1(), data->GetDesc2(),
data->m_start, data->m_length);
// the codestream box is being asked for expansion
wxTreeItemIdValue cookie;
if (!GetFirstChild(item, cookie).IsOk()) {
OPJParseThread *pthread = CreateParseThread(item);
if (pthread->Run() != wxTHREAD_NO_ERROR) {
wxLogMessage(wxT("Can't start parse thread!"));
} else {
wxLogMessage(wxT("New parse thread started."));
}
}
// the codestream box is being asked for expansion
wxTreeItemIdValue cookie;
if (!GetFirstChild(item, cookie).IsOk()) {
OPJParseThread *pthread = CreateParseThread(item);
if (pthread->Run() != wxTHREAD_NO_ERROR)
wxLogMessage(wxT("Can't start parse thread!"));
else
wxLogMessage(wxT("New parse thread started."));
}
}
void OPJMarkerTree::OnSelChanged(wxTreeEvent& event)
{
int bunch_linesize = 16;
int bunch_numlines = 7;
int bunch_linesize = 16;
int bunch_numlines = 7;
wxTreeItemId item = event.GetItem();
OPJMarkerData* data = (OPJMarkerData *) GetItemData(item);
wxString text;
int l, c, pos = 0, pre_pos;
wxTreeItemId item = event.GetItem();
OPJMarkerData* data = (OPJMarkerData *) GetItemData(item);
wxString text;
int l, c, pos = 0, pre_pos;
m_peektextCtrl->Clear();
m_peektextCtrl->Clear();
/*text << wxString::Format(wxT("Selected... (%s -> %s, %s, %d, %d)"),
text.c_str(), data->GetDesc1(), data->GetDesc2(),
data->m_start, data->m_length) << wxT("\n");*/
/*text << wxString::Format(wxT("Selected... (%s -> %s, %s, %d, %d)"),
text.c_str(), data->GetDesc1(), data->GetDesc2(),
data->m_start, data->m_length) << wxT("\n");*/
// open the file and browse a little
wxFile *fp = new wxFile(m_fname.GetFullPath().c_str(), wxFile::read);
// open the file and browse a little
wxFile *fp = new wxFile(m_fname.GetFullPath().c_str(), wxFile::read);
// go to position claimed
fp->Seek(data->m_start, wxFromStart);
// go to position claimed
fp->Seek(data->m_start, wxFromStart);
// read a bunch
int max_read = wxMin(wxFileOffset(bunch_linesize * bunch_numlines),
data->m_length - data->m_start + 1);
if (data->m_desc == wxT("MARK (65380)")) {
/*wxLogMessage(data->m_desc);*/
max_read = data->m_length - data->m_start + 1;
bunch_numlines = (int) ceil((float) max_read / (float) bunch_linesize);
}
unsigned char *buffer = new unsigned char[bunch_linesize * bunch_numlines];
fp->Read(buffer, max_read);
// read a bunch
int max_read = wxMin(wxFileOffset(bunch_linesize * bunch_numlines), data->m_length - data->m_start + 1);
if (data->m_desc == wxT("MARK (65380)")) {
/*wxLogMessage(data->m_desc);*/
max_read = data->m_length - data->m_start + 1;
bunch_numlines = (int) ceil((float) max_read / (float) bunch_linesize);
}
unsigned char *buffer = new unsigned char[bunch_linesize * bunch_numlines];
fp->Read(buffer, max_read);
// write the file data between start and stop
pos = 0;
for (l = 0; l < bunch_numlines; l++) {
// write the file data between start and stop
pos = 0;
for (l = 0; l < bunch_numlines; l++) {
text << wxString::Format(wxT("%010d:"), data->m_start + pos);
text << wxString::Format(wxT("%010d:"), data->m_start + pos);
pre_pos = pos;
pre_pos = pos;
// add hex browsing text
for (c = 0; c < bunch_linesize; c++) {
// add hex browsing text
for (c = 0; c < bunch_linesize; c++) {
if (!(c % 8)) {
text << wxT(" ");
}
if (!(c % 8))
text << wxT(" ");
if (pos < max_read) {
text << wxString::Format(wxT("%02X "), buffer[pos]);
} else {
text << wxT(" ");
}
pos++;
}
if (pos < max_read) {
text << wxString::Format(wxT("%02X "), buffer[pos]);
} else
text << wxT(" ");
pos++;
}
text << wxT(" ");
text << wxT(" ");
// add char browsing text
for (c = 0; c < bunch_linesize; c++) {
// add char browsing text
for (c = 0; c < bunch_linesize; c++) {
if (pre_pos < max_read) {
if ((buffer[pre_pos] == '\n') ||
(buffer[pre_pos] == '\t') ||
(buffer[pre_pos] == '\0') ||
(buffer[pre_pos] == 0x0D) ||
(buffer[pre_pos] == 0x0B)) {
buffer[pre_pos] = ' ';
}
text << wxString::FromAscii((char) buffer[pre_pos]) << wxT(".");
} else {
text << wxT(" ");
}
pre_pos++;
}
if (pre_pos < max_read) {
if ((buffer[pre_pos] == '\n') ||
(buffer[pre_pos] == '\t') ||
(buffer[pre_pos] == '\0') ||
(buffer[pre_pos] == 0x0D) ||
(buffer[pre_pos] == 0x0B))
buffer[pre_pos] = ' ';
text << wxString::FromAscii((char) buffer[pre_pos]) << wxT(".");
} else
text << wxT(" ");
pre_pos++;
}
text << wxT("\n");
text << wxT("\n");
}
}
// close the file
fp->Close();
// close the file
fp->Close();
m_peektextCtrl->WriteText(text);
m_peektextCtrl->WriteText(text);
delete [] buffer;
delete [] buffer;
}
/*void LogKeyEvent(const wxChar *name, const wxKeyEvent& event)
@ -1170,7 +1148,7 @@ void OPJMarkerTree::OnItemMenu(wxTreeEvent& event)
wxLogMessage(wxT("OnItemMenu for item \"%s\""), item ? item->GetDesc()
: _T(""));*/
//wxLogMessage(wxT("EEEEEEEEEE"));
//wxLogMessage(wxT("EEEEEEEEEE"));
//event.Skip();
}
@ -1291,3 +1269,5 @@ void OPJMarkerData::ShowInfo(wxTreeCtrl *tree)
unsigned(tree->GetChildrenCount(GetId())),
unsigned(tree->GetChildrenCount(GetId(), false)));
}

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -136,10 +136,10 @@ typedef unsigned long long int8byte;
#endif
#define OPJ_APPLICATION wxT("OPJViewer")
#define OPJ_APPLICATION_NAME wxT("OpenJPEG Viewer")
#define OPJ_APPLICATION_VERSION wxT("0.4 beta")
#define OPJ_APPLICATION_TITLEBAR OPJ_APPLICATION_NAME wxT(" ") OPJ_APPLICATION_VERSION
#define OPJ_APPLICATION_COPYRIGHT wxT("(C) 2007-2008, Giuseppe Baruffa")
#define OPJ_APPLICATION_NAME wxT("OpenJPEG Viewer")
#define OPJ_APPLICATION_VERSION wxT("0.4 beta")
#define OPJ_APPLICATION_TITLEBAR OPJ_APPLICATION_NAME wxT(" ") OPJ_APPLICATION_VERSION
#define OPJ_APPLICATION_COPYRIGHT wxT("(C) 2007-2008, Giuseppe Baruffa")
#define OPJ_APPLICATION_VENDOR wxT("OpenJPEG")
#ifdef __WXMSW__
@ -180,86 +180,73 @@ class OPJChildFrame;
//////////////////////////////////
class OPJViewerApp: public wxApp
{
// public methods and variables
public:
// public methods and variables
public:
// class constructor
OPJViewerApp()
{
m_showImages = true;
m_showButtons = false;
}
// class constructor
OPJViewerApp() { m_showImages = true; m_showButtons = false; }
// other methods
bool OnInit(void);
int OnExit(void);
void SetShowImages(bool show)
{
m_showImages = show;
}
bool ShowImages() const
{
return m_showImages;
}
void ShowCmdLine(const wxCmdLineParser& parser);
// other methods
bool OnInit(void);
int OnExit(void);
void SetShowImages(bool show) { m_showImages = show; }
bool ShowImages() const { return m_showImages; }
void ShowCmdLine(const wxCmdLineParser& parser);
// all the threads currently alive - as soon as the thread terminates, it's
// removed from the array
wxArrayThread m_deco_threads, m_parse_threads, m_enco_threads;
// all the threads currently alive - as soon as the thread terminates, it's
// removed from the array
wxArrayThread m_deco_threads, m_parse_threads, m_enco_threads;
// crit section protects access to all of the arrays below
wxCriticalSection m_deco_critsect, m_parse_critsect, m_enco_critsect;
// crit section protects access to all of the arrays below
wxCriticalSection m_deco_critsect, m_parse_critsect, m_enco_critsect;
// semaphore used to wait for the threads to exit, see OPJFrame::OnQuit()
wxSemaphore m_deco_semAllDone, m_parse_semAllDone, m_enco_semAllDone;
// semaphore used to wait for the threads to exit, see OPJFrame::OnQuit()
wxSemaphore m_deco_semAllDone, m_parse_semAllDone, m_enco_semAllDone;
// the last exiting thread should post to m_semAllDone if this is true
// (protected by the same m_critsect)
bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone,
m_enco_waitingUntilAllDone;
// the last exiting thread should post to m_semAllDone if this is true
// (protected by the same m_critsect)
bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone, m_enco_waitingUntilAllDone;
// the list of all filenames written in the command line
wxArrayString m_filelist;
// the list of all filenames written in the command line
wxArrayString m_filelist;
// displaying engine parameters
int m_resizemethod;
// displaying engine parameters
int m_resizemethod;
// decoding engine parameters
bool m_enabledeco, m_enableparse;
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
// decoding engine parameters
bool m_enabledeco, m_enableparse;
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
#ifdef USE_JPWL
bool m_enablejpwl, m_enablejpwle;
int m_expcomps, m_maxtiles;
bool m_enablejpwl, m_enablejpwle;
int m_expcomps, m_maxtiles;
#endif // USE_JPWL
int m_framewidth, m_frameheight;
int m_framewidth, m_frameheight;
// encoding engine parameters
wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality;
wxString m_cbsize, m_prsize, m_tsize, m_torigin, m_poc;
bool m_enablecomm, m_enableidx, m_multicomp, m_irreversible, m_enablesop,
m_enableeph;
bool m_enablebypass, m_enablereset, m_enablerestart, m_enablevsc,
m_enableerterm;
bool m_enablesegmark, m_enablepoc;
bool m_enablequality;
int m_resolutions, m_progression;
// encoding engine parameters
wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality;
wxString m_cbsize, m_prsize, m_tsize, m_torigin, m_poc;
bool m_enablecomm, m_enableidx, m_multicomp, m_irreversible, m_enablesop, m_enableeph;
bool m_enablebypass, m_enablereset, m_enablerestart, m_enablevsc, m_enableerterm;
bool m_enablesegmark, m_enablepoc;
bool m_enablequality;
int m_resolutions, m_progression;
#ifdef USE_JPWL
int m_hprotsel[MYJPWL_MAX_NO_TILESPECS], m_pprotsel[MYJPWL_MAX_NO_TILESPECS];
int m_htileval[MYJPWL_MAX_NO_TILESPECS], m_ptileval[MYJPWL_MAX_NO_TILESPECS],
m_ppackval[MYJPWL_MAX_NO_TILESPECS];
int m_sensisel[MYJPWL_MAX_NO_TILESPECS], m_stileval[MYJPWL_MAX_NO_TILESPECS];
int m_hprotsel[MYJPWL_MAX_NO_TILESPECS], m_pprotsel[MYJPWL_MAX_NO_TILESPECS];
int m_htileval[MYJPWL_MAX_NO_TILESPECS], m_ptileval[MYJPWL_MAX_NO_TILESPECS],
m_ppackval[MYJPWL_MAX_NO_TILESPECS];
int m_sensisel[MYJPWL_MAX_NO_TILESPECS], m_stileval[MYJPWL_MAX_NO_TILESPECS];
#endif // USE_JPWL
// some layout settings
bool m_showtoolbar, m_showbrowser, m_showpeeker;
int m_browserwidth, m_peekerheight;
// some layout settings
bool m_showtoolbar, m_showbrowser, m_showpeeker;
int m_browserwidth, m_peekerheight;
// application configuration
wxConfig *OPJconfig;
// application configuration
wxConfig *OPJconfig;
// private methods and variables
private:
bool m_showImages, m_showButtons;
// private methods and variables
private:
bool m_showImages, m_showButtons;
};
@ -270,39 +257,37 @@ DECLARE_APP(OPJViewerApp)
///////////////////////////////////////////
class OPJCanvas: public wxScrolledWindow
{
// public methods and variables
public:
// public methods and variables
public:
// class constructor
OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos,
const wxSize& size);
// class constructor
OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size);
virtual void OnDraw(wxDC& dc);
void OnEvent(wxMouseEvent& event);
void WriteText(const wxString& text)
{
#ifndef __WXGTK__
wxMutexGuiEnter();
virtual void OnDraw(wxDC& dc);
void OnEvent(wxMouseEvent& event);
void WriteText(const wxString& text) {
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif //__WXGTK__
wxLogMessage(text);
#ifndef __WXGTK__
wxMutexGuiLeave();
wxLogMessage(text);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif //__WXGTK__
}
}
void OnThreadSignal(wxCommandEvent& event);
void OnThreadSignal(wxCommandEvent& event);
OPJDecoThread *CreateDecoThread(void);
OPJEncoThread *CreateEncoThread(void);
OPJDecoThread *CreateDecoThread(void);
OPJEncoThread *CreateEncoThread(void);
OPJChildFrame *m_childframe;
OPJChildFrame *m_childframe;
wxBitmap m_image, m_image100;
wxFileName m_fname, m_savename;
long m_zooml;
wxBitmap m_image, m_image100;
wxFileName m_fname, m_savename;
long m_zooml;
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
///////////////////////////////////////////////////
@ -310,40 +295,29 @@ public:
///////////////////////////////////////////////////
class OPJMarkerData : public wxTreeItemData
{
// public methods and variables
public:
// public methods and variables
public:
// class constructor
OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""),
wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc),
m_filestring(fname)
{
m_start = start;
m_length = length;
}
// class constructor
OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname) { m_start = start; m_length = length; }
void ShowInfo(wxTreeCtrl *tree);
const wxChar *GetDesc1() const
{
return m_desc.c_str();
}
const wxChar *GetDesc2() const
{
return m_filestring.c_str();
}
wxFileOffset m_start, m_length;
wxString m_desc;
void ShowInfo(wxTreeCtrl *tree);
const wxChar *GetDesc1() const { return m_desc.c_str(); }
const wxChar *GetDesc2() const { return m_filestring.c_str(); }
wxFileOffset m_start, m_length;
wxString m_desc;
// private methods and variables
private:
wxString m_filestring;
// private methods and variables
private:
wxString m_filestring;
};
class OPJMarkerTree : public wxTreeCtrl
{
public:
enum {
enum
{
TreeCtrlIcon_File,
TreeCtrlIcon_FileSelected,
TreeCtrlIcon_Folder,
@ -352,23 +326,16 @@ public:
};
OPJMarkerTree() { };
OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname,
wxString name, const wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style);
virtual ~OPJMarkerTree() {};
OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00,
OPJChildFrame *subframe = NULL);
void WriteText(const wxString& text)
{
wxMutexGuiEnter();
wxLogMessage(text);
wxMutexGuiLeave();
}
OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style);
virtual ~OPJMarkerTree(){};
OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00, OPJChildFrame *subframe = NULL);
void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave(); }
wxFileName m_fname;
wxTextCtrl *m_peektextCtrl;
OPJChildFrame *m_childframe;
wxFileName m_fname;
wxTextCtrl *m_peektextCtrl;
OPJChildFrame *m_childframe;
/*void OnBeginDrag(wxTreeEvent& event);
void OnBeginRDrag(wxTreeEvent& event);
@ -405,15 +372,9 @@ public:
/*void DoToggleIcon(const wxTreeItemId& item);*/
/*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/
int ImageSize(void) const
{
return m_imageSize;
}
int ImageSize(void) const { return m_imageSize; }
void SetLastItem(wxTreeItemId id)
{
m_lastItem = id;
}
void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
protected:
/*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/
@ -447,23 +408,20 @@ private:
};
// this hash map stores all the trees of currently opened images, with an integer key
WX_DECLARE_HASH_MAP(int, OPJMarkerTree*, wxIntegerHash, wxIntegerEqual,
OPJMarkerTreeHash);
WX_DECLARE_HASH_MAP(int, OPJMarkerTree*, wxIntegerHash, wxIntegerEqual, OPJMarkerTreeHash);
// this hash map stores all the children of currently opened images, with an integer key
WX_DECLARE_HASH_MAP(int, OPJChildFrame*, wxIntegerHash, wxIntegerEqual,
OPJChildFrameHash);
WX_DECLARE_HASH_MAP(int, OPJChildFrame*, wxIntegerHash, wxIntegerEqual, OPJChildFrameHash);
// Define a new frame
class OPJFrame: public wxMDIParentFrame
{
public:
public:
OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size, const long style);
OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
~OPJFrame(void);
void OnSize(wxSizeEvent& WXUNUSED(event));
void OnSize(wxSizeEvent& WXUNUSED(event));
void OnAbout(wxCommandEvent& WXUNUSED(event));
void OnFileOpen(wxCommandEvent& WXUNUSED(event));
void OnFileSaveAs(wxCommandEvent& WXUNUSED(event));
@ -471,43 +429,43 @@ public:
void OnQuit(wxCommandEvent& WXUNUSED(event));
void OnClose(wxCommandEvent& WXUNUSED(event));
void OnZoom(wxCommandEvent& WXUNUSED(event));
void OnFit(wxCommandEvent& event);
void OnToggleBrowser(wxCommandEvent& WXUNUSED(event));
void OnTogglePeeker(wxCommandEvent& WXUNUSED(event));
void OnToggleToolbar(wxCommandEvent& WXUNUSED(event));
void OnReload(wxCommandEvent& event);
void OnPrevFrame(wxCommandEvent& event);
void OnHomeFrame(wxCommandEvent& event);
void OnNextFrame(wxCommandEvent& event);
void OnLessLayers(wxCommandEvent& event);
void OnAllLayers(wxCommandEvent& event);
void OnMoreLayers(wxCommandEvent& event);
void OnLessRes(wxCommandEvent& event);
void OnFullRes(wxCommandEvent& event);
void OnMoreRes(wxCommandEvent& event);
void OnPrevComp(wxCommandEvent& event);
void OnAllComps(wxCommandEvent& event);
void OnNextComp(wxCommandEvent& event);
void OnSetsEnco(wxCommandEvent& event);
void OnSetsDeco(wxCommandEvent& event);
void OnSashDrag(wxSashEvent& event);
void OpenFiles(wxArrayString paths, wxArrayString filenames);
void SaveFile(wxArrayString paths, wxArrayString filenames);
void OnNotebook(wxNotebookEvent& event);
void Rescale(int scale, OPJChildFrame *child);
void OnThreadLogmsg(wxCommandEvent& event);
void OnFit(wxCommandEvent& event);
void OnToggleBrowser(wxCommandEvent& WXUNUSED(event));
void OnTogglePeeker(wxCommandEvent& WXUNUSED(event));
void OnToggleToolbar(wxCommandEvent& WXUNUSED(event));
void OnReload(wxCommandEvent& event);
void OnPrevFrame(wxCommandEvent& event);
void OnHomeFrame(wxCommandEvent& event);
void OnNextFrame(wxCommandEvent& event);
void OnLessLayers(wxCommandEvent& event);
void OnAllLayers(wxCommandEvent& event);
void OnMoreLayers(wxCommandEvent& event);
void OnLessRes(wxCommandEvent& event);
void OnFullRes(wxCommandEvent& event);
void OnMoreRes(wxCommandEvent& event);
void OnPrevComp(wxCommandEvent& event);
void OnAllComps(wxCommandEvent& event);
void OnNextComp(wxCommandEvent& event);
void OnSetsEnco(wxCommandEvent& event);
void OnSetsDeco(wxCommandEvent& event);
void OnSashDrag(wxSashEvent& event);
void OpenFiles(wxArrayString paths, wxArrayString filenames);
void SaveFile(wxArrayString paths, wxArrayString filenames);
void OnNotebook(wxNotebookEvent& event);
void Rescale(int scale, OPJChildFrame *child);
void OnThreadLogmsg(wxCommandEvent& event);
OPJMarkerTreeHash m_treehash;
OPJChildFrameHash m_childhash;
OPJMarkerTreeHash m_treehash;
OPJChildFrameHash m_childhash;
wxSashLayoutWindow* markerTreeWindow;
wxSashLayoutWindow* loggingWindow;
wxToolBar* tool_bar;
wxToolBar* tool_bar;
void Resize(int number);
wxNotebook *m_bookCtrl;
wxNotebook *m_bookCtrlbottom;
wxNotebook *m_bookCtrl;
wxNotebook *m_bookCtrlbottom;
wxTextCtrl *m_textCtrlbrowse;
private:
private:
void TogStyle(int id, long flag);
void DoSort(bool reverse = false);
@ -521,71 +479,70 @@ protected:
wxSashLayoutWindow* m_topWindow;
wxSashLayoutWindow* m_leftWindow2;
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
class OPJChildFrame: public wxMDIChildFrame
{
public:
public:
OPJCanvas *m_canvas;
OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber,
const wxString& title, const wxPoint& pos, const wxSize& size,
const long style);
OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
~OPJChildFrame(void);
void OnActivate(wxActivateEvent& event);
/*void OnQuit(wxCommandEvent& WXUNUSED(event));*/
void OnClose(wxCloseEvent& event);
void OnGotFocus(wxFocusEvent& event);
void OnLostFocus(wxFocusEvent& event);
/*void OnQuit(wxCommandEvent& WXUNUSED(event));*/
void OnClose(wxCloseEvent& event);
void OnGotFocus(wxFocusEvent& event);
void OnLostFocus(wxFocusEvent& event);
OPJFrame *m_frame;
wxFileName m_fname;
int m_winnumber;
wxFileName m_fname;
int m_winnumber;
unsigned long m_twidth, m_theight, m_tx, m_ty;
unsigned long m_twidth, m_theight, m_tx, m_ty;
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
// frame and main menu ids
enum {
OPJFRAME_FILEEXIT = wxID_EXIT,
OPJFRAME_HELPABOUT = wxID_ABOUT,
OPJFRAME_FILEOPEN,
OPJFRAME_MEMORYOPEN,
OPJFRAME_FILESAVEAS,
OPJFRAME_FILETOGGLEB,
OPJFRAME_FILETOGGLEP,
OPJFRAME_FILETOGGLET,
OPJFRAME_VIEWZOOM,
OPJFRAME_VIEWFIT,
OPJFRAME_VIEWRELOAD,
OPJFRAME_VIEWPREVFRAME,
OPJFRAME_VIEWHOMEFRAME,
OPJFRAME_VIEWNEXTFRAME,
OPJFRAME_VIEWLESSLAYERS,
OPJFRAME_VIEWALLLAYERS,
OPJFRAME_VIEWMORELAYERS,
OPJFRAME_VIEWLESSRES,
OPJFRAME_VIEWFULLRES,
OPJFRAME_VIEWMORERES,
OPJFRAME_VIEWPREVCOMP,
OPJFRAME_VIEWALLCOMPS,
OPJFRAME_VIEWNEXTCOMP,
OPJFRAME_FILECLOSE,
OPJFRAME_SETSENCO,
OPJFRAME_SETSDECO,
OPJFRAME_FILEEXIT = wxID_EXIT,
OPJFRAME_HELPABOUT = wxID_ABOUT,
OPJFRAME_FILEOPEN,
OPJFRAME_MEMORYOPEN,
OPJFRAME_FILESAVEAS,
OPJFRAME_FILETOGGLEB,
OPJFRAME_FILETOGGLEP,
OPJFRAME_FILETOGGLET,
OPJFRAME_VIEWZOOM,
OPJFRAME_VIEWFIT,
OPJFRAME_VIEWRELOAD,
OPJFRAME_VIEWPREVFRAME,
OPJFRAME_VIEWHOMEFRAME,
OPJFRAME_VIEWNEXTFRAME,
OPJFRAME_VIEWLESSLAYERS,
OPJFRAME_VIEWALLLAYERS,
OPJFRAME_VIEWMORELAYERS,
OPJFRAME_VIEWLESSRES,
OPJFRAME_VIEWFULLRES,
OPJFRAME_VIEWMORERES,
OPJFRAME_VIEWPREVCOMP,
OPJFRAME_VIEWALLCOMPS,
OPJFRAME_VIEWNEXTCOMP,
OPJFRAME_FILECLOSE,
OPJFRAME_SETSENCO,
OPJFRAME_SETSDECO,
OPJFRAME_BROWSEWIN = 10000,
OPJFRAME_LOGWIN,
OPJFRAME_TOOLBAR,
OPJFRAME_BROWSEWIN = 10000,
OPJFRAME_LOGWIN,
OPJFRAME_TOOLBAR,
OPJFRAME_THREADLOGMSG,
OPJCANVAS_THREADSIGNAL
OPJFRAME_THREADLOGMSG,
OPJCANVAS_THREADSIGNAL
};
// menu and control ids
enum {
enum
{
TreeTest_Quit = wxID_EXIT,
TreeTest_About = wxID_ABOUT,
TreeTest_TogButtons = wxID_HIGHEST,
@ -630,8 +587,8 @@ enum {
TreeTest_Unselect,
TreeTest_SelectRoot,
TreeTest_Ctrl = 1000,
BOTTOM_NOTEBOOK_ID,
LEFT_NOTEBOOK_ID
BOTTOM_NOTEBOOK_ID,
LEFT_NOTEBOOK_ID
};
class OPJEncoThread : public wxThread
@ -688,23 +645,19 @@ public:
// write something to the text control
void WriteText(const wxString& text);
void LoadFile(wxFileName fname);
void ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length,
wxTreeItemId parentid);
void ParseJP2File(wxFile *fileid, wxFileOffset filepoint,
wxFileOffset filelimit, wxTreeItemId parentid);
void LoadFile(wxFileName fname);
void ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length, wxTreeItemId parentid);
void ParseJP2File(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, wxTreeItemId parentid);
unsigned m_count;
OPJMarkerTree *m_tree;
wxTreeItemId m_parentid;
wxTreeItemId m_parentid;
private:
int jpeg2000parse(wxFile *fileid, wxFileOffset filepoint,
wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
int box_handler_function(int boxtype, wxFile *fileid, wxFileOffset filepoint,
wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
int jpeg2000parse(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
int box_handler_function(int boxtype, wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
};
@ -713,10 +666,7 @@ private:
class OPJDnDFile: public wxFileDropTarget
{
public:
OPJDnDFile(OPJFrame *pOwner)
{
m_pOwner = pOwner;
}
OPJDnDFile(OPJFrame *pOwner) { m_pOwner = pOwner; }
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
private:
@ -728,139 +678,137 @@ private:
// Property sheet dialog: encoder
class OPJEncoderDialog: public wxPropertySheetDialog
{
DECLARE_CLASS(OPJEncoderDialog)
DECLARE_CLASS(OPJEncoderDialog)
public:
OPJEncoderDialog(wxWindow* parent, int dialogType);
~OPJEncoderDialog();
wxBookCtrlBase* m_settingsNotebook;
wxBookCtrlBase* m_settingsNotebook;
wxPanel* CreateMainSettingsPage(wxWindow* parent);
wxPanel* CreatePart1_1SettingsPage(wxWindow* parent);
wxPanel* CreatePart1_2SettingsPage(wxWindow* parent);
/* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/
void OnEnableComm(wxCommandEvent& event);
void OnEnableIdx(wxCommandEvent& event);
void OnEnablePoc(wxCommandEvent& event);
void OnRadioQualityRate(wxCommandEvent& event);
/* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/
void OnEnableComm(wxCommandEvent& event);
void OnEnableIdx(wxCommandEvent& event);
void OnEnablePoc(wxCommandEvent& event);
void OnRadioQualityRate(wxCommandEvent& event);
#ifdef USE_JPWL
void OnEnableJPWL(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent);
/*wxCheckBox *m_enablejpwlCheck;*/
wxChoice *m_hprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_htileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_pprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ptileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ppackCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_sensiChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_stileCtrl[MYJPWL_MAX_NO_TILESPECS];
void OnHprotSelect(wxCommandEvent& event);
void OnPprotSelect(wxCommandEvent& event);
void OnSensiSelect(wxCommandEvent& event);
void OnEnableJPWL(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent);
/*wxCheckBox *m_enablejpwlCheck;*/
wxChoice *m_hprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_htileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_pprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ptileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ppackCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_sensiChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_stileCtrl[MYJPWL_MAX_NO_TILESPECS];
void OnHprotSelect(wxCommandEvent& event);
void OnPprotSelect(wxCommandEvent& event);
void OnSensiSelect(wxCommandEvent& event);
#endif // USE_JPWL
wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl;
wxRadioButton *m_rateRadio, *m_qualityRadio;
wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl,
*m_pocCtrl;
wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl;
wxRadioBox *progressionBox;
wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_mctCheck, *m_irrevCheck;
wxCheckBox *m_sopCheck, *m_ephCheck, *m_enablebypassCheck, *m_enableresetCheck,
*m_enablerestartCheck, *m_enablevscCheck, *m_enableertermCheck,
*m_enablesegmarkCheck;
wxCheckBox *m_enablepocCheck, *m_enablejpwlCheck;
wxSpinCtrl *m_resolutionsCtrl;
wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl;
wxRadioButton *m_rateRadio, *m_qualityRadio;
wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl, *m_pocCtrl;
wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl;
wxRadioBox *progressionBox;
wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_mctCheck, *m_irrevCheck;
wxCheckBox *m_sopCheck, *m_ephCheck, *m_enablebypassCheck, *m_enableresetCheck,
*m_enablerestartCheck, *m_enablevscCheck, *m_enableertermCheck, *m_enablesegmarkCheck;
wxCheckBox *m_enablepocCheck, *m_enablejpwlCheck;
wxSpinCtrl *m_resolutionsCtrl;
protected:
enum {
OPJENCO_ENABLEJPWL = 100,
OPJENCO_RATEFACTOR,
OPJENCO_RATERADIO,
OPJENCO_QUALITYFACTOR,
OPJENCO_QUALITYRADIO,
OPJENCO_RESNUMBER,
OPJENCO_CODEBLOCKSIZE,
OPJENCO_PRECINCTSIZE,
OPJENCO_TILESIZE,
OPJENCO_PROGRESSION,
OPJENCO_SUBSAMPLING,
OPJENCO_ENABLESOP,
OPJENCO_ENABLEEPH,
OPJENCO_ENABLEBYPASS,
OPJENCO_ENABLERESET,
OPJENCO_ENABLERESTART,
OPJENCO_ENABLEVSC,
OPJENCO_ENABLEERTERM,
OPJENCO_ENABLESEGMARK,
OPJENCO_ENABLEPOC,
OPJENCO_ROICOMP,
OPJENCO_ROISHIFT,
OPJENCO_IMORIG,
OPJENCO_TILORIG,
OPJENCO_ENABLEMCT,
OPJENCO_ENABLEIRREV,
OPJENCO_ENABLEINDEX,
OPJENCO_INDEXNAME,
OPJENCO_POCSPEC,
OPJENCO_ENABLECOMM,
OPJENCO_COMMENTTEXT,
OPJENCO_HPROT,
OPJENCO_HTILE,
OPJENCO_PPROT,
OPJENCO_PTILE,
OPJENCO_PPACK,
OPJENCO_SENSI,
OPJENCO_STILE
OPJENCO_ENABLEJPWL = 100,
OPJENCO_RATEFACTOR,
OPJENCO_RATERADIO,
OPJENCO_QUALITYFACTOR,
OPJENCO_QUALITYRADIO,
OPJENCO_RESNUMBER,
OPJENCO_CODEBLOCKSIZE,
OPJENCO_PRECINCTSIZE,
OPJENCO_TILESIZE,
OPJENCO_PROGRESSION,
OPJENCO_SUBSAMPLING,
OPJENCO_ENABLESOP,
OPJENCO_ENABLEEPH,
OPJENCO_ENABLEBYPASS,
OPJENCO_ENABLERESET,
OPJENCO_ENABLERESTART,
OPJENCO_ENABLEVSC,
OPJENCO_ENABLEERTERM,
OPJENCO_ENABLESEGMARK,
OPJENCO_ENABLEPOC,
OPJENCO_ROICOMP,
OPJENCO_ROISHIFT,
OPJENCO_IMORIG,
OPJENCO_TILORIG,
OPJENCO_ENABLEMCT,
OPJENCO_ENABLEIRREV,
OPJENCO_ENABLEINDEX,
OPJENCO_INDEXNAME,
OPJENCO_POCSPEC,
OPJENCO_ENABLECOMM,
OPJENCO_COMMENTTEXT,
OPJENCO_HPROT,
OPJENCO_HTILE,
OPJENCO_PPROT,
OPJENCO_PTILE,
OPJENCO_PPACK,
OPJENCO_SENSI,
OPJENCO_STILE
};
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
// Property sheet dialog: decoder
class OPJDecoderDialog: public wxPropertySheetDialog
{
DECLARE_CLASS(OPJDecoderDialog)
DECLARE_CLASS(OPJDecoderDialog)
public:
OPJDecoderDialog(wxWindow* parent, int dialogType);
~OPJDecoderDialog();
wxBookCtrlBase* m_settingsNotebook;
wxCheckBox *m_enabledecoCheck, *m_enableparseCheck;
wxSpinCtrl *m_reduceCtrl, *m_layerCtrl, *m_numcompsCtrl;
wxRadioBox* m_resizeBox;
wxBookCtrlBase* m_settingsNotebook;
wxCheckBox *m_enabledecoCheck, *m_enableparseCheck;
wxSpinCtrl *m_reduceCtrl, *m_layerCtrl, *m_numcompsCtrl;
wxRadioBox* m_resizeBox;
void OnEnableDeco(wxCommandEvent& event);
void OnEnableDeco(wxCommandEvent& event);
wxPanel* CreateMainSettingsPage(wxWindow* parent);
wxPanel* CreatePart1SettingsPage(wxWindow* parent);
wxPanel* CreatePart3SettingsPage(wxWindow* parent);
#ifdef USE_JPWL
void OnEnableJPWL(wxCommandEvent& event);
void OnEnableJPWL(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent);
wxSpinCtrl *m_expcompsCtrl, *m_maxtilesCtrl;
wxCheckBox *m_enablejpwlCheck;
wxSpinCtrl *m_expcompsCtrl, *m_maxtilesCtrl;
wxCheckBox *m_enablejpwlCheck;
#endif // USE_JPWL
wxSpinCtrl *m_framenumCtrl;
wxSpinCtrl *m_framenumCtrl;
protected:
enum {
OPJDECO_RESMETHOD = 100,
OPJDECO_REDUCEFACTOR,
OPJDECO_QUALITYLAYERS,
OPJDECO_NUMCOMPS,
OPJDECO_ENABLEDECO,
OPJDECO_ENABLEPARSE,
OPJDECO_ENABLEJPWL,
OPJDECO_EXPCOMPS,
OPJDECO_MAXTILES,
OPJDECO_FRAMENUM
OPJDECO_RESMETHOD = 100,
OPJDECO_REDUCEFACTOR,
OPJDECO_QUALITYLAYERS,
OPJDECO_NUMCOMPS,
OPJDECO_ENABLEDECO,
OPJDECO_ENABLEPARSE,
OPJDECO_ENABLEJPWL,
OPJDECO_EXPCOMPS,
OPJDECO_MAXTILES,
OPJDECO_FRAMENUM
};
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
#endif //__OPJ_VIEWER_H__

View File

@ -1,56 +1,54 @@
wxString htmlaboutpage = wxT(
"<html>"
"<body bgcolor=#FFFFFF>"
"<table cellspacing=7 cellpadding=1 border=0 width=100%>"
"<tr>"
"<td rowspan=3 valign=top align=center width=70>"
"<img src=\"memory:opj_logo.xpm\"><br><br>"
"</td>"
"<td align=center>"
"<font size=+0 color=#000000><b>"
OPJ_APPLICATION " " OPJ_APPLICATION_VERSION
"</b></font><br>"
"<font size=-1 color=#000000><b>A JPEG 2000 image viewer</b></font><br>"
"<font size=-2 color=#000000><b>" OPJ_APPLICATION_PLATFORM " version</b></font>"
"</td>"
"</tr>"
"<tr height=3 valign=center>"
"<td valign=center bgcolor=#cc3300></td>"
"</tr>"
"<tr>"
"<td align=justify>"
"<center><font size=+0 color=#000000><a href=\"http://www.openjpeg.org/\">OpenJPEG</a></font></center>"
"<p><font size=-1 color=#000000>The OpenJPEG library is an open-source JPEG 2000 codec written in C language. "
"In addition to the basic codec, various other features are under development.</font></p><br>"
"<font size=-2 color=red>* Build: ")
"<html>"
"<body bgcolor=#FFFFFF>"
"<table cellspacing=7 cellpadding=1 border=0 width=100%>"
"<tr>"
"<td rowspan=3 valign=top align=center width=70>"
"<img src=\"memory:opj_logo.xpm\"><br><br>"
"</td>"
"<td align=center>"
"<font size=+0 color=#000000><b>"
OPJ_APPLICATION " " OPJ_APPLICATION_VERSION
"</b></font><br>"
"<font size=-1 color=#000000><b>A JPEG 2000 image viewer</b></font><br>"
"<font size=-2 color=#000000><b>" OPJ_APPLICATION_PLATFORM " version</b></font>"
"</td>"
"</tr>"
"<tr height=3 valign=center>"
"<td valign=center bgcolor=#cc3300></td>"
"</tr>"
"<tr>"
"<td align=justify>"
"<center><font size=+0 color=#000000><a href=\"http://www.openjpeg.org/\">OpenJPEG</a></font></center>"
"<p><font size=-1 color=#000000>The OpenJPEG library is an open-source JPEG 2000 codec written in C language. "
"In addition to the basic codec, various other features are under development.</font></p><br>"
"<font size=-2 color=red>* Build: ")
#include "build.h"
wxT(", " __DATE__ ", " __TIME__ "</font><br>")
wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>")
wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (")
wxT(", " __DATE__ ", " __TIME__ "</font><br>")
wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>")
wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (")
#ifdef USE_JPWL
wxT("<font size=-2 color=green>JPWL</font> ")
wxT("<font size=-2 color=green>JPWL</font> ")
#endif // USE_JPWL
#ifdef USE_JPSEC
wxT("<font size=-2 color=green>JPSEC</font> ")
wxT("<font size=-2 color=green>JPSEC</font> ")
#endif // USE_JPSEC
wxT(")</font><br>")
wxT(")</font><br>")
#ifdef USE_MXF
wxT("<font size=-2 color=red>* MXFLib " MXFLIB_VERSION_MAJOR "."
MXFLIB_VERSION_MINOR "." MXFLIB_VERSION_TWEAK " (" MXFLIB_VERSION_BUILD
")</font><br>")
wxT("<font size=-2 color=red>* MXFLib " MXFLIB_VERSION_MAJOR "." MXFLIB_VERSION_MINOR "." MXFLIB_VERSION_TWEAK " (" MXFLIB_VERSION_BUILD ")</font><br>")
#endif // USE_MXF
wxT("</td>"
"</tr>"
"<tr>"
"<td colspan=2 bgcolor=#CC3300 height=3 valign=center></td>"
"</tr>"
"<tr>"
"<td colspan=2>"
"<font size=-2 color=#444444>OpenJPEG is &copy; 2002-2008 <a href=\"http://www.tele.ucl.ac.be/\">TELE</a> - <a href=\"http://www.uclouvain.be/\">Universite' Catholique de Louvain</a></font><br>"
"<font size=-2 color=#444444>OPJViewer is &copy; 2007-2008 <a href=\"http://dsplab.diei.unipg.it/\">DSPLab</a> - <a href=\"http://www.unipg.it/\">Universita' degli studi di Perugia</a></font>"
"</td>"
"</tr>"
"</table>"
"</body>"
"</html>"
);
wxT("</td>"
"</tr>"
"<tr>"
"<td colspan=2 bgcolor=#CC3300 height=3 valign=center></td>"
"</tr>"
"<tr>"
"<td colspan=2>"
"<font size=-2 color=#444444>OpenJPEG is &copy; 2002-2008 <a href=\"http://www.tele.ucl.ac.be/\">TELE</a> - <a href=\"http://www.uclouvain.be/\">Universite' Catholique de Louvain</a></font><br>"
"<font size=-2 color=#444444>OPJViewer is &copy; 2007-2008 <a href=\"http://dsplab.diei.unipg.it/\">DSPLab</a> - <a href=\"http://www.unipg.it/\">Universita' degli studi di Perugia</a></font>"
"</td>"
"</tr>"
"</table>"
"</body>"
"</html>"
);

View File

@ -1 +1 @@
wxT("491")
wxT("491")

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -52,7 +52,7 @@
#include "openjp2/openjpeg.h"
#include "jp2/index.h"
#define wxBITMAP_TYPE_JPEG2000 50
#define wxBITMAP_TYPE_JPEG2000 50
class WXDLLEXPORT wxJPEG2000Handler: public wxImageHandler
{
@ -64,117 +64,115 @@ public:
m_type = wxBITMAP_TYPE_JPEG2000;
m_mime = wxT("image/mj2");
/* decoding */
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
/* decoding */
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
#ifdef USE_JPWL
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL
/* encoding */
m_subsampling = wxT("1,1");
m_origin = wxT("0,0");
m_rates = wxT("20,10,5");
m_quality = wxT("30,35,40");
m_enablequality = false;
m_multicomp = false;
m_irreversible = false;
m_resolutions = 6;
m_progression = 0;
m_cbsize = wxT("32,32");
m_prsize = wxT("[128,128],[128,128]");
m_tsize = wxT("");
m_torigin = wxT("0,0");
/*m_progression
m_resilience*/
m_enablesop = false;
m_enableeph = false;
m_enablereset = false;
m_enablesegmark = false;
m_enablevsc = false;
m_enablerestart = false;
m_enableerterm = false;
m_enablebypass = false;
/*m_roicompo
m_roiup
m_indexfname*/
m_enableidx = false;
m_index = wxT("index.txt");
m_enablepoc = false;
m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL");
m_enablecomm = true;
/* encoding */
m_subsampling = wxT("1,1");
m_origin = wxT("0,0");
m_rates = wxT("20,10,5");
m_quality = wxT("30,35,40");
m_enablequality = false;
m_multicomp = false;
m_irreversible = false;
m_resolutions = 6;
m_progression = 0;
m_cbsize = wxT("32,32");
m_prsize = wxT("[128,128],[128,128]");
m_tsize = wxT("");
m_torigin = wxT("0,0");
/*m_progression
m_resilience*/
m_enablesop = false;
m_enableeph = false;
m_enablereset = false;
m_enablesegmark = false;
m_enablevsc = false;
m_enablerestart = false;
m_enableerterm = false;
m_enablebypass = false;
/*m_roicompo
m_roiup
m_indexfname*/
m_enableidx = false;
m_index = wxT("index.txt");
m_enablepoc = false;
m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL");
m_enablecomm = true;
#if defined __WXMSW__
m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG version ");
m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG version ");
#elif defined __WXGTK__
m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version ");
m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version ");
#else
m_comment = wxT("Created by OPJViewer - OpenJPEG version ");
m_comment = wxT("Created by OPJViewer - OpenJPEG version ");
#endif
#ifdef USE_JPWL
m_comment += wxString::Format(wxT("%s with JPWL"), (char *) opj_version());
m_comment += wxString::Format(wxT("%s with JPWL"), (char *) opj_version());
#else
m_comment += wxString::Format(wxT("%s"), (char *) opj_version());
m_comment += wxString::Format(wxT("%s"), (char *) opj_version());
#endif
}
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
#ifdef USE_JPWL
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
#endif // USE_JPWL
// encoding engine parameters
wxString m_subsampling;
wxString m_origin;
wxString m_rates;
wxString m_quality;
bool m_enablequality;
bool m_multicomp;
bool m_irreversible;
int m_resolutions;
int m_progression;
wxString m_cbsize;
wxString m_prsize;
wxString m_tsize;
wxString m_torigin;
/*m_progression
m_resilience*/
bool m_enablesop;
bool m_enableeph;
bool m_enablebypass;
bool m_enableerterm;
bool m_enablerestart;
bool m_enablereset;
bool m_enablesegmark;
bool m_enablevsc;
/*m_roicompo
m_roiup
m_indexfname*/
bool m_enableidx;
wxString m_index;
bool m_enablecomm;
wxString m_comment;
bool m_enablepoc;
wxString m_poc;
// encoding engine parameters
wxString m_subsampling;
wxString m_origin;
wxString m_rates;
wxString m_quality;
bool m_enablequality;
bool m_multicomp;
bool m_irreversible;
int m_resolutions;
int m_progression;
wxString m_cbsize;
wxString m_prsize;
wxString m_tsize;
wxString m_torigin;
/*m_progression
m_resilience*/
bool m_enablesop;
bool m_enableeph;
bool m_enablebypass;
bool m_enableerterm;
bool m_enablerestart;
bool m_enablereset;
bool m_enablesegmark;
bool m_enablevsc;
/*m_roicompo
m_roiup
m_indexfname*/
bool m_enableidx;
wxString m_index;
bool m_enablecomm;
wxString m_comment;
bool m_enablepoc;
wxString m_poc;
#if wxUSE_STREAMS
virtual bool LoadFile(wxImage *image, wxInputStream& stream,
bool verbose = true, int index = -1);
virtual bool SaveFile(wxImage *image, wxOutputStream& stream,
bool verbose = true);
virtual bool LoadFile(wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1);
virtual bool SaveFile(wxImage *image, wxOutputStream& stream, bool verbose=true);
protected:
virtual bool DoCanRead(wxInputStream& stream);
#endif
private:
OPJ_PROG_ORDER give_progression(char progression[4]);
OPJ_PROG_ORDER give_progression(char progression[4]);
DECLARE_DYNAMIC_CLASS(wxJPEG2000Handler)
};

View File

@ -1,6 +1,6 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -54,7 +54,7 @@
#include "wx/image.h"
#include "libopenjpeg/openjpeg.h"
#define wxBITMAP_TYPE_MXF 51
#define wxBITMAP_TYPE_MXF 51
class WXDLLEXPORT wxMXFHandler: public wxImageHandler
{
@ -66,32 +66,30 @@ public:
m_type = wxBITMAP_TYPE_MXF;
m_mime = wxT("image/mxf");
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
m_filename = wxT("");
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
m_filename = wxT("");
#ifdef USE_JPWL
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL
}
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
wxFileName m_filename;
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
wxFileName m_filename;
#ifdef USE_JPWL
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
#endif // USE_JPWL
#if wxUSE_STREAMS
virtual bool LoadFile(wxImage *image, wxInputStream& stream,
bool verbose = true, int index = -1);
virtual bool SaveFile(wxImage *image, wxOutputStream& stream,
bool verbose = true);
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
protected:
virtual bool DoCanRead(wxInputStream& stream);
virtual bool DoCanRead( wxInputStream& stream );
#endif
private:

View File

@ -2,6 +2,16 @@
# Part 1 & 2:
add_subdirectory(openjp2)
# optionals components:
if(BUILD_JPWL)
add_subdirectory(openjpwl)
endif()
if(BUILD_MJ2)
add_subdirectory(openmj2)
endif()
if(BUILD_JPIP)
add_subdirectory(openjpip)
endif()
if(BUILD_JP3D)
add_subdirectory(openjp3d)
endif()

View File

@ -2,7 +2,7 @@ include_regular_expression("^.*$")
#
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR} COMPONENT Headers)
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers)
include_directories(
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h
@ -19,7 +19,6 @@ set(OPENJPEG_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/dwt.h
${CMAKE_CURRENT_SOURCE_DIR}/event.c
${CMAKE_CURRENT_SOURCE_DIR}/event.h
${CMAKE_CURRENT_SOURCE_DIR}/ht_dec.c
${CMAKE_CURRENT_SOURCE_DIR}/image.c
${CMAKE_CURRENT_SOURCE_DIR}/image.h
${CMAKE_CURRENT_SOURCE_DIR}/invert.c
@ -39,6 +38,8 @@ set(OPENJPEG_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.h
${CMAKE_CURRENT_SOURCE_DIR}/pi.c
${CMAKE_CURRENT_SOURCE_DIR}/pi.h
${CMAKE_CURRENT_SOURCE_DIR}/raw.c
${CMAKE_CURRENT_SOURCE_DIR}/raw.h
${CMAKE_CURRENT_SOURCE_DIR}/t1.c
${CMAKE_CURRENT_SOURCE_DIR}/t1.h
${CMAKE_CURRENT_SOURCE_DIR}/t2.c
@ -55,8 +56,6 @@ set(OPENJPEG_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.c
${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_stdint.h
${CMAKE_CURRENT_SOURCE_DIR}/sparse_array.c
${CMAKE_CURRENT_SOURCE_DIR}/sparse_array.h
)
if(BUILD_JPIP)
add_definitions(-DUSE_JPIP)
@ -89,55 +88,40 @@ if(WIN32)
else()
add_definitions(-DOPJ_STATIC)
endif()
add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME})
else()
if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
# Builds both static and dynamic libs
add_library(${OPENJPEG_LIBRARY_NAME} SHARED ${OPENJPEG_SRCS})
add_library(openjp2_static STATIC ${OPENJPEG_SRCS})
set_target_properties(openjp2_static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME})
set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME} openjp2_static)
target_include_directories(openjp2_static PUBLIC $<INSTALL_INTERFACE:${OPENJPEG_INSTALL_INCLUDE_DIR}>)
else()
add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME})
endif()
endif()
target_include_directories(${OPENJPEG_LIBRARY_NAME} PUBLIC $<INSTALL_INTERFACE:${OPENJPEG_INSTALL_INCLUDE_DIR}>)
add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
if(UNIX)
target_link_libraries(${OPENJPEG_LIBRARY_NAME} m)
endif()
set_target_properties(${OPENJPEG_LIBRARY_NAME} PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12")
target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJP2_COMPILE_OPTIONS})
if(${CMAKE_VERSION} VERSION_GREATER "2.8.11")
target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJPEG_LIBRARY_COMPILE_OPTIONS})
endif()
# Install library
install(TARGETS ${INSTALL_LIBS}
install(TARGETS ${OPENJPEG_LIBRARY_NAME}
EXPORT OpenJPEGTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
RUNTIME DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
LIBRARY DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
ARCHIVE DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
)
# Install includes files
install(FILES openjpeg.h opj_stdint.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR} COMPONENT Headers
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers
)
if(BUILD_DOC)
# install man page of the library
install(
FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man3/libopenjp2.3
DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man3)
endif()
if(BUILD_LUTS_GENERATOR)
# internal utility to generate t1_luts.h and t1_ht_luts.h (part of the jp2 lib)
# internal utility to generate t1_luts.h (part of the jp2 lib)
# no need to install:
add_executable(t1_generate_luts t1_generate_luts.c t1_ht_generate_luts.c)
add_executable(t1_generate_luts t1_generate_luts.c)
if(UNIX)
target_link_libraries(t1_generate_luts m)
endif()
@ -201,21 +185,3 @@ endif(OPJ_USE_THREAD AND NOT Threads_FOUND)
if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME} ${CMAKE_THREAD_LIBS_INIT})
endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
if(BUILD_UNIT_TESTS AND UNIX)
add_executable(bench_dwt bench_dwt.c)
if(UNIX)
target_link_libraries(bench_dwt m ${OPENJPEG_LIBRARY_NAME})
endif()
if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
target_link_libraries(bench_dwt ${CMAKE_THREAD_LIBS_INIT})
endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
add_executable(test_sparse_array test_sparse_array.c)
if(UNIX)
target_link_libraries(test_sparse_array m ${OPENJPEG_LIBRARY_NAME})
endif()
if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
target_link_libraries(test_sparse_array ${CMAKE_THREAD_LIBS_INIT})
endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
endif(BUILD_UNIT_TESTS AND UNIX)

View File

@ -1,353 +0,0 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2017, IntoPix SA <contact@intopix.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/times.h>
#endif /* _WIN32 */
OPJ_INT32 getValue(OPJ_UINT32 i)
{
return ((OPJ_INT32)i % 511) - 256;
}
void init_tilec(opj_tcd_tilecomp_t * l_tilec,
OPJ_INT32 x0,
OPJ_INT32 y0,
OPJ_INT32 x1,
OPJ_INT32 y1,
OPJ_UINT32 numresolutions,
OPJ_BOOL irreversible)
{
opj_tcd_resolution_t* l_res;
OPJ_UINT32 resno, l_level_no;
size_t i, nValues;
memset(l_tilec, 0, sizeof(*l_tilec));
l_tilec->x0 = x0;
l_tilec->y0 = y0;
l_tilec->x1 = x1;
l_tilec->y1 = y1;
nValues = (size_t)(l_tilec->x1 - l_tilec->x0) *
(size_t)(l_tilec->y1 - l_tilec->y0);
l_tilec->data = (OPJ_INT32*) opj_malloc(sizeof(OPJ_INT32) * nValues);
for (i = 0; i < nValues; i++) {
OPJ_INT32 val = getValue((OPJ_UINT32)i);
if (irreversible) {
OPJ_FLOAT32 fVal = (OPJ_FLOAT32)val;
memcpy(&l_tilec->data[i], &fVal, sizeof(OPJ_FLOAT32));
} else {
l_tilec->data[i] = val;
}
}
l_tilec->numresolutions = numresolutions;
l_tilec->minimum_num_resolutions = numresolutions;
l_tilec->resolutions = (opj_tcd_resolution_t*) opj_calloc(
l_tilec->numresolutions,
sizeof(opj_tcd_resolution_t));
l_level_no = l_tilec->numresolutions;
l_res = l_tilec->resolutions;
/* Adapted from opj_tcd_init_tile() */
for (resno = 0; resno < l_tilec->numresolutions; ++resno) {
--l_level_no;
/* border for each resolution level (global) */
l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)l_level_no);
l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no);
l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)l_level_no);
l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)l_level_no);
++l_res;
}
}
void free_tilec(opj_tcd_tilecomp_t * l_tilec)
{
opj_free(l_tilec->data);
opj_free(l_tilec->resolutions);
}
void usage(void)
{
printf(
"bench_dwt [-decode|encode] [-I] [-size value] [-check] [-display]\n");
printf(
" [-num_resolutions val] [-offset x y] [-num_threads val]\n");
exit(1);
}
OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq, t ;
/* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter(& t) ;
return freq.QuadPart ? (t.QuadPart / (OPJ_FLOAT64) freq.QuadPart) : 0 ;
#else
/* Unix or Linux: use resource usage */
struct rusage t;
OPJ_FLOAT64 procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0, &t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
/* (2b) More precisely! Get the microseconds part ! */
return (procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) *
1e-6) ;
#endif
}
static OPJ_FLOAT64 opj_wallclock(void)
{
#ifdef _WIN32
return opj_clock();
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return (OPJ_FLOAT64)tv.tv_sec + 1e-6 * (OPJ_FLOAT64)tv.tv_usec;
#endif
}
int main(int argc, char** argv)
{
int num_threads = 0;
opj_tcd_t tcd;
opj_tcd_image_t tcd_image;
opj_tcd_tile_t tcd_tile;
opj_tcd_tilecomp_t tilec;
opj_image_t image;
opj_image_comp_t image_comp;
opj_thread_pool_t* tp;
OPJ_INT32 i, j, k;
OPJ_BOOL display = OPJ_FALSE;
OPJ_BOOL check = OPJ_FALSE;
OPJ_INT32 size = 16384 - 1;
OPJ_FLOAT64 start, stop;
OPJ_FLOAT64 start_wc, stop_wc;
OPJ_UINT32 offset_x = ((OPJ_UINT32)size + 1) / 2 - 1;
OPJ_UINT32 offset_y = ((OPJ_UINT32)size + 1) / 2 - 1;
OPJ_UINT32 num_resolutions = 6;
OPJ_BOOL bench_decode = OPJ_TRUE;
OPJ_BOOL irreversible = OPJ_FALSE;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-encode") == 0) {
bench_decode = OPJ_FALSE;
} else if (strcmp(argv[i], "-decode") == 0) {
bench_decode = OPJ_TRUE;
} else if (strcmp(argv[i], "-display") == 0) {
display = OPJ_TRUE;
} else if (strcmp(argv[i], "-check") == 0) {
check = OPJ_TRUE;
} else if (strcmp(argv[i], "-I") == 0) {
irreversible = OPJ_TRUE;
} else if (strcmp(argv[i], "-size") == 0 && i + 1 < argc) {
size = atoi(argv[i + 1]);
i ++;
} else if (strcmp(argv[i], "-num_threads") == 0 && i + 1 < argc) {
num_threads = atoi(argv[i + 1]);
i ++;
} else if (strcmp(argv[i], "-num_resolutions") == 0 && i + 1 < argc) {
num_resolutions = (OPJ_UINT32)atoi(argv[i + 1]);
if (num_resolutions == 0 || num_resolutions > 32) {
fprintf(stderr,
"Invalid value for num_resolutions. Should be >= 1 and <= 32\n");
exit(1);
}
i ++;
} else if (strcmp(argv[i], "-offset") == 0 && i + 2 < argc) {
offset_x = (OPJ_UINT32)atoi(argv[i + 1]);
offset_y = (OPJ_UINT32)atoi(argv[i + 2]);
i += 2;
} else {
usage();
}
}
if (irreversible && check) {
/* Due to irreversible inverse DWT not being symmetric of forward */
/* See BUG_WEIRD_TWO_INVK in dwt.c */
printf("-I and -check aren't compatible\n");
exit(1);
}
tp = opj_thread_pool_create(num_threads);
init_tilec(&tilec, (OPJ_INT32)offset_x, (OPJ_INT32)offset_y,
(OPJ_INT32)offset_x + size, (OPJ_INT32)offset_y + size,
num_resolutions, irreversible);
if (display) {
printf("Before\n");
k = 0;
for (j = 0; j < tilec.y1 - tilec.y0; j++) {
for (i = 0; i < tilec.x1 - tilec.x0; i++) {
if (irreversible) {
printf("%f ", ((OPJ_FLOAT32*)tilec.data)[k]);
} else {
printf("%d ", tilec.data[k]);
}
k ++;
}
printf("\n");
}
}
memset(&tcd, 0, sizeof(tcd));
tcd.thread_pool = tp;
tcd.whole_tile_decoding = OPJ_TRUE;
tcd.win_x0 = (OPJ_UINT32)tilec.x0;
tcd.win_y0 = (OPJ_UINT32)tilec.y0;
tcd.win_x1 = (OPJ_UINT32)tilec.x1;
tcd.win_y1 = (OPJ_UINT32)tilec.y1;
tcd.tcd_image = &tcd_image;
memset(&tcd_image, 0, sizeof(tcd_image));
tcd_image.tiles = &tcd_tile;
memset(&tcd_tile, 0, sizeof(tcd_tile));
tcd_tile.x0 = tilec.x0;
tcd_tile.y0 = tilec.y0;
tcd_tile.x1 = tilec.x1;
tcd_tile.y1 = tilec.y1;
tcd_tile.numcomps = 1;
tcd_tile.comps = &tilec;
tcd.image = &image;
memset(&image, 0, sizeof(image));
image.numcomps = 1;
image.comps = &image_comp;
memset(&image_comp, 0, sizeof(image_comp));
image_comp.dx = 1;
image_comp.dy = 1;
start = opj_clock();
start_wc = opj_wallclock();
if (bench_decode) {
if (irreversible) {
opj_dwt_decode_real(&tcd, &tilec, tilec.numresolutions);
} else {
opj_dwt_decode(&tcd, &tilec, tilec.numresolutions);
}
} else {
if (irreversible) {
opj_dwt_encode_real(&tcd, &tilec);
} else {
opj_dwt_encode(&tcd, &tilec);
}
}
stop = opj_clock();
stop_wc = opj_wallclock();
printf("time for %s: total = %.03f s, wallclock = %.03f s\n",
bench_decode ? "dwt_decode" : "dwt_encode",
stop - start,
stop_wc - start_wc);
if (display) {
if (bench_decode) {
printf("After IDWT\n");
} else {
printf("After FDWT\n");
}
k = 0;
for (j = 0; j < tilec.y1 - tilec.y0; j++) {
for (i = 0; i < tilec.x1 - tilec.x0; i++) {
if (irreversible) {
printf("%f ", ((OPJ_FLOAT32*)tilec.data)[k]);
} else {
printf("%d ", tilec.data[k]);
}
k ++;
}
printf("\n");
}
}
if ((display || check) && !irreversible) {
if (bench_decode) {
opj_dwt_encode(&tcd, &tilec);
} else {
opj_dwt_decode(&tcd, &tilec, tilec.numresolutions);
}
if (display && !irreversible) {
if (bench_decode) {
printf("After FDWT\n");
} else {
printf("After IDWT\n");
}
k = 0;
for (j = 0; j < tilec.y1 - tilec.y0; j++) {
for (i = 0; i < tilec.x1 - tilec.x0; i++) {
if (irreversible) {
printf("%f ", ((OPJ_FLOAT32*)tilec.data)[k]);
} else {
printf("%d ", tilec.data[k]);
}
k ++;
}
printf("\n");
}
}
}
if (check) {
size_t idx;
size_t nValues = (size_t)(tilec.x1 - tilec.x0) *
(size_t)(tilec.y1 - tilec.y0);
for (idx = 0; idx < nValues; idx++) {
if (tilec.data[idx] != getValue((OPJ_UINT32)idx)) {
printf("Difference found at idx = %u\n", (OPJ_UINT32)idx);
exit(1);
}
}
}
free_tilec(&tilec);
opj_thread_pool_destroy(tp);
return 0;
}

Some files were not shown because too many files have changed in this diff Show More