Compare commits

..

No commits in common. "main" and "version.1.0" have entirely different histories.

575 changed files with 5932 additions and 267342 deletions

17
.gitignore vendored
View File

@ -1,17 +0,0 @@
# Ignore files and directories made by `cmake .`.
CMakeFiles/
Makefile
cmake_install.cmake
/CMakeCache.txt
/CPackConfig.cmake
/CPackSourceConfig.cmake
/CTestCustom.cmake
/LICENSE.txt
/OpenJPEGConfig.cmake
/libopenjp2.pc
/src/bin/common/opj_apps_config.h
/src/lib/openjp2/opj_config.h
/src/lib/openjp2/opj_config_private.h
# Ignore directories made by `make`.
/bin/

View File

@ -1,93 +0,0 @@
language: c
matrix:
include:
- os: osx
compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_NUM_THREADS=2
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
packages:
- gcc-multilib
- os: linux
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:
- gcc-mingw-w64-base
- binutils-mingw-w64-x86-64
- gcc-mingw-w64-x86-64
- gcc-mingw-w64
- os: linux
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
- libelf-dev
- elfutils
- texinfo
- exuberant-ctags
install:
- ./tools/travis-ci/install.sh
script:
- ./tools/travis-ci/run.sh
- ./tools/travis-ci/abi-check.sh
before_deploy:
- export OPJ_RELEASE_PKG_FILE=$(ls build/openjpeg-${TRAVIS_TAG}*)
- echo "deploying $OPJ_RELEASE_PKG_FILE to GitHub releases"
deploy:
provider: releases
api_key:
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
on:
repo: uclouvain/openjpeg
tags: true
condition: "$OPJ_CI_INCLUDE_IF_DEPLOY = 1"

View File

@ -1,21 +0,0 @@
# Authors of OpenJPEG
See also [THANKS](https://github.com/uclouvain/openjpeg/blob/master/THANKS.md)
David Janssens designed and implemented the first version of OpenJPEG.
Kaori Hagihara designed and implemented the first version of OpenJPIP.
Jerome Fimes implemented the alpha version of OpenJPEG 2.0.
Giuseppe Baruffa added the JPWL functionalities.
Mickaël Savinaud implemented the final OpenJPEG 2.0 version based on a big merge between 1.5 version and alpha version of 2.0.
Mathieu Malaterre participated to the OpenJPEG 2.0 version and improved the libraries and utilities.
Yannick Verschueren,
Herve Drolon,
Francois-Olivier Devaux,
Antonin Descampe
improved the libraries and utilities.

View File

@ -1,446 +0,0 @@
# Changelog
## [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)
**Closed issues:**
- null ptr dereference in convert.c:1331 [\#843](https://github.com/uclouvain/openjpeg/issues/843)
- Out-of-Bounds Read in function bmp24toimage of convertbmp.c [\#833](https://github.com/uclouvain/openjpeg/issues/833)
- Disable automatic compilation of t1\_generate\_luts in CMakeLists.txt [\#831](https://github.com/uclouvain/openjpeg/issues/831)
- CVE-2016-7163 Integer overflow in opj\_pi\_create\_decode [\#826](https://github.com/uclouvain/openjpeg/issues/826)
- Security Advisory for OpenJPEG [\#810](https://github.com/uclouvain/openjpeg/issues/810)
- Add dashboard with static lib [\#804](https://github.com/uclouvain/openjpeg/issues/804)
- hidden visibility for the static library / building with -DOPJ\_STATIC against shared lib [\#802](https://github.com/uclouvain/openjpeg/issues/802)
- 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)
- "master" does not build on ubuntu [\#658](https://github.com/uclouvain/openjpeg/issues/658)
- Package 'openjp2', required by 'libopenjpip', not found [\#594](https://github.com/uclouvain/openjpeg/issues/594)
**Merged pull requests:**
- Fix PNM file reading [\#847](https://github.com/uclouvain/openjpeg/pull/847) ([mayeut](https://github.com/mayeut))
- Fix some issues reported by Coverity Scan [\#846](https://github.com/uclouvain/openjpeg/pull/846) ([stweil](https://github.com/stweil))
- Fix potential out-of-bounds read \(coverity\) [\#844](https://github.com/uclouvain/openjpeg/pull/844) ([stweil](https://github.com/stweil))
- Remove TODO for overflow check [\#842](https://github.com/uclouvain/openjpeg/pull/842) ([mayeut](https://github.com/mayeut))
- Add overflow checks for opj\_aligned\_malloc [\#841](https://github.com/uclouvain/openjpeg/pull/841) ([mayeut](https://github.com/mayeut))
- Flags in T1 shall be unsigned [\#840](https://github.com/uclouvain/openjpeg/pull/840) ([mayeut](https://github.com/mayeut))
- Fix some warnings [\#838](https://github.com/uclouvain/openjpeg/pull/838) ([mayeut](https://github.com/mayeut))
- Fix issue 833. [\#834](https://github.com/uclouvain/openjpeg/pull/834) ([trylab](https://github.com/trylab))
- Add overflow checks for opj\_aligned\_malloc [\#832](https://github.com/uclouvain/openjpeg/pull/832) ([mayeut](https://github.com/mayeut))
- Add test for issue 820 [\#829](https://github.com/uclouvain/openjpeg/pull/829) ([mayeut](https://github.com/mayeut))
- Add test for issue 826 [\#827](https://github.com/uclouvain/openjpeg/pull/827) ([mayeut](https://github.com/mayeut))
- Fix coverity 113065 \(CWE-484\) [\#824](https://github.com/uclouvain/openjpeg/pull/824) ([mayeut](https://github.com/mayeut))
- Add sanity check for tile coordinates [\#823](https://github.com/uclouvain/openjpeg/pull/823) ([mayeut](https://github.com/mayeut))
- Add test for PR 818 [\#822](https://github.com/uclouvain/openjpeg/pull/822) ([mayeut](https://github.com/mayeut))
- Update to libpng 1.6.25 [\#821](https://github.com/uclouvain/openjpeg/pull/821) ([mayeut](https://github.com/mayeut))
- CVE-2016-8332: fix incrementing of "l\_tcp-\>m\_nb\_mcc\_records" in opj\_j2k\_read\_mcc [\#820](https://github.com/uclouvain/openjpeg/pull/820) ([mayeut](https://github.com/mayeut))
- Add overflow check in opj\_tcd\_init\_tile [\#819](https://github.com/uclouvain/openjpeg/pull/819) ([mayeut](https://github.com/mayeut))
- Fix leak & invalid behavior of opj\_jp2\_read\_ihdr [\#818](https://github.com/uclouvain/openjpeg/pull/818) ([mayeut](https://github.com/mayeut))
- Add overflow check in opj\_j2k\_update\_image\_data [\#817](https://github.com/uclouvain/openjpeg/pull/817) ([mayeut](https://github.com/mayeut))
- Change 'restrict' define to 'OPJ\_RESTRICT' [\#816](https://github.com/uclouvain/openjpeg/pull/816) ([mayeut](https://github.com/mayeut))
- Switch to clang 3.8 [\#814](https://github.com/uclouvain/openjpeg/pull/814) ([mayeut](https://github.com/mayeut))
- Fix an integer overflow issue [\#809](https://github.com/uclouvain/openjpeg/pull/809) ([trylab](https://github.com/trylab))
- Update to lcms 2.8 [\#808](https://github.com/uclouvain/openjpeg/pull/808) ([mayeut](https://github.com/mayeut))
- Update to libpng 1.6.24 [\#807](https://github.com/uclouvain/openjpeg/pull/807) ([mayeut](https://github.com/mayeut))
- Reenable clang-3.9 build on travis [\#806](https://github.com/uclouvain/openjpeg/pull/806) ([mayeut](https://github.com/mayeut))
- Bit fields type [\#805](https://github.com/uclouvain/openjpeg/pull/805) ([smuehlst](https://github.com/smuehlst))
- Add compilation test for standalone inclusion of openjpeg.h [\#798](https://github.com/uclouvain/openjpeg/pull/798) ([mayeut](https://github.com/mayeut))
- jpwl: Remove non-portable data type u\_int16\_t \(fix issue \#796\) [\#797](https://github.com/uclouvain/openjpeg/pull/797) ([stweil](https://github.com/stweil))
- Fix dependency for pkg-config \(issue \#594\) [\#795](https://github.com/uclouvain/openjpeg/pull/795) ([stweil](https://github.com/stweil))
- Add .gitignore [\#787](https://github.com/uclouvain/openjpeg/pull/787) ([stweil](https://github.com/stweil))
## [v2.1.1](https://github.com/uclouvain/openjpeg/releases/tag/v2.1.1) (2016-07-05)
[Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.2.1...v2.1.1)
**Implemented enhancements:**
- opj\_malloc replacement [\#625](https://github.com/uclouvain/openjpeg/issues/625)
- backport "-p" and "-force-rgb" options in 1.5 [\#606](https://github.com/uclouvain/openjpeg/issues/606)
- Use travis-ci matrix build [\#581](https://github.com/uclouvain/openjpeg/issues/581)
- Add Coverity Scan analysis [\#580](https://github.com/uclouvain/openjpeg/issues/580)
- Unnecessary rate distortion calculations [\#479](https://github.com/uclouvain/openjpeg/issues/479)
- Add images from various security issues to test suite [\#415](https://github.com/uclouvain/openjpeg/issues/415)
- Coding speed for 9/7 on 32bits platforms \(x86/ARM\) can be improved with a quick fix [\#220](https://github.com/uclouvain/openjpeg/issues/220)
**Fixed bugs:**
- Out-of-Bounds Access in function opj\_tgt\_reset of tgt.c [\#775](https://github.com/uclouvain/openjpeg/issues/775)
- Heap Buffer Overflow in function color\_cmyk\_to\_rgb of color.c [\#774](https://github.com/uclouvain/openjpeg/issues/774)
- division-by-zero \(SIGFPE\) error in opj\_tcd\_init\_tile function \(line 730 of tcd.c\) [\#733](https://github.com/uclouvain/openjpeg/issues/733)
- Out-Of-Bounds Read in sycc422\_to\_rgb function [\#726](https://github.com/uclouvain/openjpeg/issues/726)
- Heap Corruption in opj\_free function [\#725](https://github.com/uclouvain/openjpeg/issues/725)
- Out-Of-Bounds Read in opj\_tcd\_free\_tile function [\#724](https://github.com/uclouvain/openjpeg/issues/724)
- Cannot handle box of undefined size [\#653](https://github.com/uclouvain/openjpeg/issues/653)
- Compilation fails without platform-supplied aligned malloc [\#642](https://github.com/uclouvain/openjpeg/issues/642)
- HP compiler warns about redeclaration of static function [\#640](https://github.com/uclouvain/openjpeg/issues/640)
- Implementation-defined behavior of malloc causes different behavior on Linux and AIX [\#635](https://github.com/uclouvain/openjpeg/issues/635)
- Build on AIX fails because "opj\_includes.h" is included after system headers [\#633](https://github.com/uclouvain/openjpeg/issues/633)
- Compiling with SSE2 on Linux 32-bit causes crashes in OpenJPEG [\#624](https://github.com/uclouvain/openjpeg/issues/624)
- Build on AIX fails because of "restrict" pointers [\#620](https://github.com/uclouvain/openjpeg/issues/620)
- bug in new tif conversion code [\#609](https://github.com/uclouvain/openjpeg/issues/609)
- bin/jp2/convert.c line 1085 Resource leak [\#607](https://github.com/uclouvain/openjpeg/issues/607)
- bin/jp2/convert.c memory leak [\#601](https://github.com/uclouvain/openjpeg/issues/601)
- Resource leak in opj\_j2k\_create\_cstr\_index in case of failure [\#599](https://github.com/uclouvain/openjpeg/issues/599)
- Resource leak in opj\_j2k\_encode in case of failure [\#598](https://github.com/uclouvain/openjpeg/issues/598)
- Resource leak in opj\_j2k\_decode\_one\_tile in case of failure [\#597](https://github.com/uclouvain/openjpeg/issues/597)
- Resource Leak [\#573](https://github.com/uclouvain/openjpeg/issues/573)
- opj\_compress fails to compress lossless on gcc/x86 \(-m32\) [\#571](https://github.com/uclouvain/openjpeg/issues/571)
- Use-after-free in opj\_j2k\_write\_mco [\#563](https://github.com/uclouvain/openjpeg/issues/563)
- openjpeg-master-2015-07-30 failed to compile on LINUX [\#556](https://github.com/uclouvain/openjpeg/issues/556)
- PNG images are always read as RGB\(A\) images [\#536](https://github.com/uclouvain/openjpeg/issues/536)
- g4\_colr.j2c not handled properly [\#532](https://github.com/uclouvain/openjpeg/issues/532)
- Bigendian: opj\_compress + opj\_decompress fails [\#518](https://github.com/uclouvain/openjpeg/issues/518)
- Suspicious code in j2k.c [\#517](https://github.com/uclouvain/openjpeg/issues/517)
- Decode times almost double\(!!\) on Visual Studio 2013, 2015 [\#505](https://github.com/uclouvain/openjpeg/issues/505)
- opj\_data/input/nonregression/issue226.j2k [\#500](https://github.com/uclouvain/openjpeg/issues/500)
- opj\_setup\_encoder always returns true [\#497](https://github.com/uclouvain/openjpeg/issues/497)
- Double free in j2k\_read\_ppm\_v3 parsing \(\(presumably invalid\) image. [\#496](https://github.com/uclouvain/openjpeg/issues/496)
- Invalid write in opj\_j2k\_update\_image\_data [\#495](https://github.com/uclouvain/openjpeg/issues/495)
- Undefined printf format specifier %ud used in code [\#494](https://github.com/uclouvain/openjpeg/issues/494)
- Potential double free on malloc failure in opj\_j2k\_copy\_default\_tcp\_and\_create\_tcp\(\) [\#492](https://github.com/uclouvain/openjpeg/issues/492)
- Do not link with -ffast-math [\#488](https://github.com/uclouvain/openjpeg/issues/488)
- Heap-buffer-overflow in opj\_dwt\_decode [\#486](https://github.com/uclouvain/openjpeg/issues/486)
- opj\_dump fails on Windows 7, 64 bits [\#482](https://github.com/uclouvain/openjpeg/issues/482)
- SIGSEGV in opj\_j2k\_update\_image\_data via pdfium\_test [\#481](https://github.com/uclouvain/openjpeg/issues/481)
- Heap-buffer-overflow in opj\_j2k\_tcp\_destroy [\#477](https://github.com/uclouvain/openjpeg/issues/477)
- Invalid image causes write past end of heap buffer [\#476](https://github.com/uclouvain/openjpeg/issues/476)
- Assertion `l\_res-\>x0 \>= 0' fails when parsing invalid images [\#475](https://github.com/uclouvain/openjpeg/issues/475)
- Bug on opj\_write\_bytes\_BE function [\#472](https://github.com/uclouvain/openjpeg/issues/472)
- Refactor j2k\_read\_ppm\_v3 function [\#470](https://github.com/uclouvain/openjpeg/issues/470)
- compression: strange precinct dimensions [\#466](https://github.com/uclouvain/openjpeg/issues/466)
- \(:- Console message in opj\_decompress -:\) [\#465](https://github.com/uclouvain/openjpeg/issues/465)
- opj\_decompress fails to decompress any files [\#463](https://github.com/uclouvain/openjpeg/issues/463)
- bio-\>ct is unnecessarily set to zero in opj\_bio\_flush method [\#461](https://github.com/uclouvain/openjpeg/issues/461)
- Maximal unsigned short is 65535, not 65536 [\#460](https://github.com/uclouvain/openjpeg/issues/460)
- OpenJpeg fails to encode components with different precision properly [\#459](https://github.com/uclouvain/openjpeg/issues/459)
- component precision upscaling isn't correct in opj\_decompress [\#458](https://github.com/uclouvain/openjpeg/issues/458)
- Multiple precision components won't get encoded to jp2 if 1 component is unsigned 1 bit [\#457](https://github.com/uclouvain/openjpeg/issues/457)
- Incorrect code in ../bin/jp2/convert.c, function rawtoimage\_common\(...\) [\#456](https://github.com/uclouvain/openjpeg/issues/456)
- \[OpenJPEG-trunk\] opj\_stream\_get\_number\_byte\_left throws assert [\#455](https://github.com/uclouvain/openjpeg/issues/455)
- NR-DEC-kodak\_2layers\_lrcp.j2c-31-decode-md5 fails randomly when running tests in parallel [\#454](https://github.com/uclouvain/openjpeg/issues/454)
- compare\_raw\_files doesn't report an error on invalid arguments / missing input files [\#453](https://github.com/uclouvain/openjpeg/issues/453)
- Forward discrete wavelet transform: implement periodic symmetric extension at boundaries [\#452](https://github.com/uclouvain/openjpeg/issues/452)
- Bug in tiff reading method in convert.c [\#449](https://github.com/uclouvain/openjpeg/issues/449)
- Image in pdf don't display [\#447](https://github.com/uclouvain/openjpeg/issues/447)
- Multiple issues causing opj\_decompress to segfault [\#446](https://github.com/uclouvain/openjpeg/issues/446)
- opj\_compress: 40% of encode time is spent freeing data [\#445](https://github.com/uclouvain/openjpeg/issues/445)
- Multiple warnings when configuring OpenJPEG on MacOS with CMake 3.x \(trunk\) [\#443](https://github.com/uclouvain/openjpeg/issues/443)
- valgrind memleak found [\#437](https://github.com/uclouvain/openjpeg/issues/437)
- global-buffer-overflow src/lib/openjp2/t1.c:1146 opj\_t1\_getwmsedec [\#436](https://github.com/uclouvain/openjpeg/issues/436)
- Warning introduced on trunk r2923 & r2924 [\#435](https://github.com/uclouvain/openjpeg/issues/435)
- heap-buffer-overflow in opj\_t1\_decode\_cblks [\#432](https://github.com/uclouvain/openjpeg/issues/432)
- Heap-buffer-overflow in opj\_tcd\_init\_decode\_tile [\#431](https://github.com/uclouvain/openjpeg/issues/431)
- Heap-buffer-overflow in opj\_j2k\_tcp\_destroy [\#430](https://github.com/uclouvain/openjpeg/issues/430)
- Heap-buffer-overflow in opj\_jp2\_apply\_pclr [\#429](https://github.com/uclouvain/openjpeg/issues/429)
- issue412 revisited [\#428](https://github.com/uclouvain/openjpeg/issues/428)
- Image distorted \(sides look cankered\) [\#423](https://github.com/uclouvain/openjpeg/issues/423)
- openjpeg-2.x-trunk-r2918 is broken in color.c [\#422](https://github.com/uclouvain/openjpeg/issues/422)
- Heap-buffer-overflow in opj\_tcd\_init\_decode\_tile [\#420](https://github.com/uclouvain/openjpeg/issues/420)
- Heap-use-after-free in opj\_t1\_decode\_cblks [\#418](https://github.com/uclouvain/openjpeg/issues/418)
- UNKNOWN in opj\_read\_bytes\_LE [\#417](https://github.com/uclouvain/openjpeg/issues/417)
- Transparency problem [\#416](https://github.com/uclouvain/openjpeg/issues/416)
- Image with per channel alpha \(cdef\) does not decode properly [\#414](https://github.com/uclouvain/openjpeg/issues/414)
- OpenJPEG crashes with attached image [\#413](https://github.com/uclouvain/openjpeg/issues/413)
- Palette image with cdef fails to decompress [\#412](https://github.com/uclouvain/openjpeg/issues/412)
- Invalid member values from opj\_read\_header or opj\_decode ? [\#411](https://github.com/uclouvain/openjpeg/issues/411)
- MD5 Checksum hangs under valgrind on MacOS X [\#410](https://github.com/uclouvain/openjpeg/issues/410)
- Heap-buffer-overflow in opj\_tcd\_get\_decoded\_tile\_size [\#408](https://github.com/uclouvain/openjpeg/issues/408)
- C++ style comments in trunk/src/lib/openjp2/j2k.c [\#407](https://github.com/uclouvain/openjpeg/issues/407)
- Backport bugfixes from trunk to 2.1 branch [\#405](https://github.com/uclouvain/openjpeg/issues/405)
- Heap-buffer-overflow in parse\_cmdline\_encoder [\#403](https://github.com/uclouvain/openjpeg/issues/403)
- Heap-buffer-overflow in opj\_v4dwt\_interleave\_h [\#400](https://github.com/uclouvain/openjpeg/issues/400)
- Heap-buffer-overflow in opj\_dwt\_decode [\#399](https://github.com/uclouvain/openjpeg/issues/399)
- Heap-use-after-free in opj\_t1\_decode\_cblks [\#398](https://github.com/uclouvain/openjpeg/issues/398)
- Heap-buffer-overflow in opj\_jp2\_apply\_cdef [\#397](https://github.com/uclouvain/openjpeg/issues/397)
- Heap-buffer-overflow in opj\_t2\_read\_packet\_header [\#396](https://github.com/uclouvain/openjpeg/issues/396)
- Heap-buffer-overflow in opj\_t2\_read\_packet\_header [\#395](https://github.com/uclouvain/openjpeg/issues/395)
- Heap-buffer-overflow in opj\_dwt\_decode\_1 [\#394](https://github.com/uclouvain/openjpeg/issues/394)
- Heap-double-free in j2k\_read\_ppm\_v3 [\#393](https://github.com/uclouvain/openjpeg/issues/393)
- Security hole in j2k.c [\#392](https://github.com/uclouvain/openjpeg/issues/392)
- Security: double-free in opj\_tcd\_code\_block\_dec\_deallocate [\#391](https://github.com/uclouvain/openjpeg/issues/391)
- check for negative-size params in code [\#390](https://github.com/uclouvain/openjpeg/issues/390)
- Heap-buffer-overflow in opj\_t2\_read\_packet\_header [\#389](https://github.com/uclouvain/openjpeg/issues/389)
- Heap overflow in OpenJpeg 1.5.2 [\#388](https://github.com/uclouvain/openjpeg/issues/388)
- openjpip.so.6 file too short [\#387](https://github.com/uclouvain/openjpeg/issues/387)
- Corrupted JP3D file [\#386](https://github.com/uclouvain/openjpeg/issues/386)
- variable assigned to itself [\#383](https://github.com/uclouvain/openjpeg/issues/383)
- Null pointer dereferencing [\#382](https://github.com/uclouvain/openjpeg/issues/382)
- bad use of case statement [\#381](https://github.com/uclouvain/openjpeg/issues/381)
- Release 2.1 as a Ubuntu package [\#380](https://github.com/uclouvain/openjpeg/issues/380)
- Bug in libopenjpwl.pc [\#374](https://github.com/uclouvain/openjpeg/issues/374)
- inconsistent tile numbering in decode output message [\#370](https://github.com/uclouvain/openjpeg/issues/370)
- error in code block calculations [\#369](https://github.com/uclouvain/openjpeg/issues/369)
- r2872 fails to compile due to "attempt to use poisoned malloc" error in j2k.c [\#368](https://github.com/uclouvain/openjpeg/issues/368)
- OSX build gives libopenjp2.6.dylib with not-absolute install name id [\#367](https://github.com/uclouvain/openjpeg/issues/367)
- opj\_decompress gives error but successfully decompress in OPJ 2.1 [\#366](https://github.com/uclouvain/openjpeg/issues/366)
- pngtoimage\(\) and imagetopng\(\) have wrong byte order for 16-Bit image [\#365](https://github.com/uclouvain/openjpeg/issues/365)
- PDF crash in chrome - part2 \(due to attachment limit\) [\#364](https://github.com/uclouvain/openjpeg/issues/364)
- PDF crash in chrome - part1 [\#363](https://github.com/uclouvain/openjpeg/issues/363)
- PDF crash in chrome - part0 [\#362](https://github.com/uclouvain/openjpeg/issues/362)
- Compilation fails on Windows with mingw32 gcc4.8 [\#361](https://github.com/uclouvain/openjpeg/issues/361)
- security issue [\#360](https://github.com/uclouvain/openjpeg/issues/360)
- improve memory management [\#359](https://github.com/uclouvain/openjpeg/issues/359)
- how to compress a yuv420 raw data using opj\_compress [\#357](https://github.com/uclouvain/openjpeg/issues/357)
- Some memory allocation are not checked [\#355](https://github.com/uclouvain/openjpeg/issues/355)
- Static library symbols shall be marked as hidden [\#354](https://github.com/uclouvain/openjpeg/issues/354)
- opj\_compress rejects valid bmp files [\#353](https://github.com/uclouvain/openjpeg/issues/353)
- opj\_compress crashes when number of resolutions is set to zero [\#352](https://github.com/uclouvain/openjpeg/issues/352)
- Compilation error under Visual Studio 2003 [\#351](https://github.com/uclouvain/openjpeg/issues/351)
- opj\_compress description example error \[Low priority\] [\#350](https://github.com/uclouvain/openjpeg/issues/350)
- opj\_write\_bytes\_BE is wrong in trunk [\#345](https://github.com/uclouvain/openjpeg/issues/345)
- PART1ONLY option in release.sh doesn't work properly [\#332](https://github.com/uclouvain/openjpeg/issues/332)
- openjpeg crash error [\#330](https://github.com/uclouvain/openjpeg/issues/330)
- openjpeg decompress error [\#329](https://github.com/uclouvain/openjpeg/issues/329)
- openjpeg decompress issue [\#326](https://github.com/uclouvain/openjpeg/issues/326)
- limited tif support [\#322](https://github.com/uclouvain/openjpeg/issues/322)
- asoc value of 65536 is allowed [\#321](https://github.com/uclouvain/openjpeg/issues/321)
- opj\_skip\_from\_file error [\#314](https://github.com/uclouvain/openjpeg/issues/314)
- Heavy quota usage in openjpeg [\#309](https://github.com/uclouvain/openjpeg/issues/309)
- Verify -help actually match letter [\#307](https://github.com/uclouvain/openjpeg/issues/307)
- g3\_colr.j2c not handled [\#288](https://github.com/uclouvain/openjpeg/issues/288)
- reopen/fix issue 165 [\#280](https://github.com/uclouvain/openjpeg/issues/280)
- kakadu conformance tests [\#279](https://github.com/uclouvain/openjpeg/issues/279)
- missing break after case statement in opj\_dwt\_decode\_real [\#274](https://github.com/uclouvain/openjpeg/issues/274)
- Run Coverity on trunk [\#270](https://github.com/uclouvain/openjpeg/issues/270)
- NR-ENC-random-issue-0005.tif-12-encode [\#259](https://github.com/uclouvain/openjpeg/issues/259)
- Use new add\_test signature to handle cross compilation [\#258](https://github.com/uclouvain/openjpeg/issues/258)
- Loss decoding quality in 2.0.0 [\#254](https://github.com/uclouvain/openjpeg/issues/254)
- Decompress that worked in 1.5.1 fails in 2.0 [\#252](https://github.com/uclouvain/openjpeg/issues/252)
- Expected endianness with raw input is not documented leading to SEGFAULT [\#251](https://github.com/uclouvain/openjpeg/issues/251)
- OpenJPEG writes to stderr [\#246](https://github.com/uclouvain/openjpeg/issues/246)
- Inconsistent logging of tile index [\#245](https://github.com/uclouvain/openjpeg/issues/245)
- patch for openjpeg-trunk-r2347 and BIG\_ENDIAN [\#242](https://github.com/uclouvain/openjpeg/issues/242)
- CMAP: MTYP == 0 \(direct use\) not handled properly [\#235](https://github.com/uclouvain/openjpeg/issues/235)
- Black Pixel [\#233](https://github.com/uclouvain/openjpeg/issues/233)
- opj\_compress runtime error after fresh Linux install due to apparent failure to execute ldconfig [\#219](https://github.com/uclouvain/openjpeg/issues/219)
- openjp2 debug works, release build does not [\#217](https://github.com/uclouvain/openjpeg/issues/217)
- openjpeg-branch15-r2299 and openjpeg-trunk-r2299 fail to decode a JP2 file [\#212](https://github.com/uclouvain/openjpeg/issues/212)
- openjpeg-trunk issue with Win7 [\#201](https://github.com/uclouvain/openjpeg/issues/201)
- undefined reference to `opj\_version' [\#200](https://github.com/uclouvain/openjpeg/issues/200)
- In tgt.c we used fprintf not the openjpeg message reporter [\#184](https://github.com/uclouvain/openjpeg/issues/184)
- Windows binaries not working under WinXP [\#176](https://github.com/uclouvain/openjpeg/issues/176)
- add ability to use intel ipp \(performance primitive\) within OpenJPEG [\#164](https://github.com/uclouvain/openjpeg/issues/164)
- 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 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)
- Problem with second layer of a 2 layer coded LRCP \(with precincts\) [\#135](https://github.com/uclouvain/openjpeg/issues/135)
- version 1.4 crashes when opening PDF file with JPEG2000 images [\#133](https://github.com/uclouvain/openjpeg/issues/133)
- Setup a win64 dashboard [\#132](https://github.com/uclouvain/openjpeg/issues/132)
- J2KP4files/codestreams\_profile0/p0\_13.j2k question jpeg2000 [\#131](https://github.com/uclouvain/openjpeg/issues/131)
- Out of memory: Kill process 11204 \(opj\_server\) score 917 or sacrifice child [\#123](https://github.com/uclouvain/openjpeg/issues/123)
- FILE\* in opj API is unsafe [\#120](https://github.com/uclouvain/openjpeg/issues/120)
- third-party lib order [\#119](https://github.com/uclouvain/openjpeg/issues/119)
- openjpeg-1.5.0-Darwin-powerpc.dmg is huge ! [\#113](https://github.com/uclouvain/openjpeg/issues/113)
- misleading info in JP2 box lead to wrong number of components [\#110](https://github.com/uclouvain/openjpeg/issues/110)
- Image\_to\_j2k says that j2k files is generated but no file is on the HDD [\#109](https://github.com/uclouvain/openjpeg/issues/109)
- Error in openjpegV1.4 on compiling image\_to\_j2k: crash on reading bmp file [\#108](https://github.com/uclouvain/openjpeg/issues/108)
- Update to abi-compliance-checker 1.96 [\#106](https://github.com/uclouvain/openjpeg/issues/106)
- Decode error on the attached JPEG...works in KDU and with JASPER...please help! [\#101](https://github.com/uclouvain/openjpeg/issues/101)
- Mac binaries v1.4 is broken [\#95](https://github.com/uclouvain/openjpeg/issues/95)
- jp2\_read\_boxhdr\(\) has size bug in version 1 [\#92](https://github.com/uclouvain/openjpeg/issues/92)
- Support for Java JAI Imageio [\#90](https://github.com/uclouvain/openjpeg/issues/90)
- encoding test failing [\#86](https://github.com/uclouvain/openjpeg/issues/86)
- source archive on demand [\#85](https://github.com/uclouvain/openjpeg/issues/85)
- CMakeLists.txt and Makefile.am for JPIP are buggy [\#84](https://github.com/uclouvain/openjpeg/issues/84)
- pclr-cmap-cdef [\#82](https://github.com/uclouvain/openjpeg/issues/82)
- Error when compiling openjpeg\_v1\_4\_sources\_r697 [\#79](https://github.com/uclouvain/openjpeg/issues/79)
- J2K codec issue on Windows Mobile [\#77](https://github.com/uclouvain/openjpeg/issues/77)
- image\_to\_j2k.exe crashes on large .bmp file [\#75](https://github.com/uclouvain/openjpeg/issues/75)
- fatal error C1900 building the project on windows [\#65](https://github.com/uclouvain/openjpeg/issues/65)
- same option but different size [\#54](https://github.com/uclouvain/openjpeg/issues/54)
- Missing openjpegConfigure.h [\#38](https://github.com/uclouvain/openjpeg/issues/38)
- Not an issue in openjpeg, but ... [\#37](https://github.com/uclouvain/openjpeg/issues/37)
- OpenJPEG-1.3.0 pclr, cmap and cdef [\#27](https://github.com/uclouvain/openjpeg/issues/27)
- realloc maybe too big \(t2.c\) [\#26](https://github.com/uclouvain/openjpeg/issues/26)
- libopenjpeg/opj\_malloc.h breaks on FreeBSD/Darwin systems [\#20](https://github.com/uclouvain/openjpeg/issues/20)
- image\_to\_j2k not outputting to win32 console properly [\#18](https://github.com/uclouvain/openjpeg/issues/18)
- \[OpenJPEG\] OpenJPEG\_v13: tiled image part 2 [\#17](https://github.com/uclouvain/openjpeg/issues/17)
- JP2 Color Space modification by Matteo Italia [\#13](https://github.com/uclouvain/openjpeg/issues/13)
- Patch submission \( exotic video formats, and a few things \) [\#12](https://github.com/uclouvain/openjpeg/issues/12)
- 16 bits lossy compression [\#10](https://github.com/uclouvain/openjpeg/issues/10)
- pnm file formats not accepting bitdepth greater than 8 bpp [\#8](https://github.com/uclouvain/openjpeg/issues/8)
- Heap corruption in j2k encoder [\#5](https://github.com/uclouvain/openjpeg/issues/5)
- JPWL crash in marker reallocation\(+patch\), segfault while decoding image with main header protection [\#4](https://github.com/uclouvain/openjpeg/issues/4)
- a couple of small errors in libopenjpeg detected by coverity [\#1](https://github.com/uclouvain/openjpeg/issues/1)
**Closed issues:**
- Shared library build broken on ubuntu [\#728](https://github.com/uclouvain/openjpeg/issues/728)
- opj\_includes.h shouldn't define `\_\_attribute\_\_` [\#727](https://github.com/uclouvain/openjpeg/issues/727)
- Possible website problems due to Jekyll upgrade [\#713](https://github.com/uclouvain/openjpeg/issues/713)
- Stable Release? [\#712](https://github.com/uclouvain/openjpeg/issues/712)
- Meta Issue : try to fix some of these critical bugs before thinking about optimizing the library [\#710](https://github.com/uclouvain/openjpeg/issues/710)
- Tiled encoding broken for images with non power of 2 dimensions [\#702](https://github.com/uclouvain/openjpeg/issues/702)
- install\_name \(still\) not set on OS X [\#700](https://github.com/uclouvain/openjpeg/issues/700)
- Add section in wiki describing where one can get test images [\#699](https://github.com/uclouvain/openjpeg/issues/699)
- Make EvenManager into singleton [\#698](https://github.com/uclouvain/openjpeg/issues/698)
- Remove old branches from repo [\#696](https://github.com/uclouvain/openjpeg/issues/696)
- MQ Coder encode: Conditional jump or move depends on uninitialised value\(s\) [\#695](https://github.com/uclouvain/openjpeg/issues/695)
- Can we add these files to our test suite ? [\#688](https://github.com/uclouvain/openjpeg/issues/688)
- -t and -d command line flags for decode are not documented on OpenJPEG website [\#685](https://github.com/uclouvain/openjpeg/issues/685)
- Decoding at the precinct level [\#676](https://github.com/uclouvain/openjpeg/issues/676)
- 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 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)
- Serious problem with quantization during lossy encoding [\#615](https://github.com/uclouvain/openjpeg/issues/615)
- Decompression does not work with sequential data source [\#613](https://github.com/uclouvain/openjpeg/issues/613)
- potential overflow in opj\_tcd\_tile\_t [\#605](https://github.com/uclouvain/openjpeg/issues/605)
- Logical condition [\#596](https://github.com/uclouvain/openjpeg/issues/596)
- file9.jp2 does not dump correctly on 1.5 [\#595](https://github.com/uclouvain/openjpeg/issues/595)
- opj\_compress man page is missing documentation of -jpip option [\#593](https://github.com/uclouvain/openjpeg/issues/593)
- opj\_compress fails to compress lossless on gcc/x86 \(-m32\) in 1.5 branch [\#591](https://github.com/uclouvain/openjpeg/issues/591)
- Example: opj\_compress -i image.j2k -o image.pgm [\#577](https://github.com/uclouvain/openjpeg/issues/577)
- Mismatching delete [\#575](https://github.com/uclouvain/openjpeg/issues/575)
- Compilation fails on Win7 [\#546](https://github.com/uclouvain/openjpeg/issues/546)
- NR-JP2-file5.jp2-compare2base fails with third party libcms [\#540](https://github.com/uclouvain/openjpeg/issues/540)
- CTest spits out an error at the end of the test run [\#516](https://github.com/uclouvain/openjpeg/issues/516)
- opj\_uint\_adds\(\) is questionable [\#515](https://github.com/uclouvain/openjpeg/issues/515)
- Might consider renaming this method: [\#491](https://github.com/uclouvain/openjpeg/issues/491)
- opj\_compress run twice gives different fiile sizes for same file [\#490](https://github.com/uclouvain/openjpeg/issues/490)
- Android Support [\#483](https://github.com/uclouvain/openjpeg/issues/483)
- Add SSE2/SSE41 implementations for mct.c [\#451](https://github.com/uclouvain/openjpeg/issues/451)
- Reduce encoder code block memory usage for non 64x64 code block sizes [\#444](https://github.com/uclouvain/openjpeg/issues/444)
- valgrind "Uninitialized Memory Read" & "Uninitialized Memory Conditional" found [\#438](https://github.com/uclouvain/openjpeg/issues/438)
- No way to debug opj\_tcd\_init\_encode\_tile or opj\_tcd\_init\_decode\_tile [\#433](https://github.com/uclouvain/openjpeg/issues/433)
- Add option to call dsymutil on built binaries [\#409](https://github.com/uclouvain/openjpeg/issues/409)
- Allow opj\_compress and opj\_decompress to read/write images over stdin/stdout [\#379](https://github.com/uclouvain/openjpeg/issues/379)
- reduce memory significantly for single tile RGB encoding [\#375](https://github.com/uclouvain/openjpeg/issues/375)
- Switch code repo to github and start using pull request workflow [\#373](https://github.com/uclouvain/openjpeg/issues/373)
- This is a BigTIFF file. This format not supported [\#125](https://github.com/uclouvain/openjpeg/issues/125)
- Add a test suite to check the convert functions [\#99](https://github.com/uclouvain/openjpeg/issues/99)
- Add build config to the dashboard to verify the autotools build [\#88](https://github.com/uclouvain/openjpeg/issues/88)
**Merged pull requests:**
- 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 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))
- Fix warnings [\#763](https://github.com/uclouvain/openjpeg/pull/763) ([mayeut](https://github.com/mayeut))
- Check SSIZ is valid in opj\_j2k\_read\_siz [\#762](https://github.com/uclouvain/openjpeg/pull/762) ([mayeut](https://github.com/mayeut))
- Fix unsigned int overflow reported by UBSan [\#761](https://github.com/uclouvain/openjpeg/pull/761) ([mayeut](https://github.com/mayeut))
- Fix unsigned int overflow reported by UBSan [\#759](https://github.com/uclouvain/openjpeg/pull/759) ([mayeut](https://github.com/mayeut))
- Fix negative shift left reported by UBSan [\#758](https://github.com/uclouvain/openjpeg/pull/758) ([mayeut](https://github.com/mayeut))
- Fix negative shift left reported by UBSan [\#757](https://github.com/uclouvain/openjpeg/pull/757) ([mayeut](https://github.com/mayeut))
- Add clang 3.9 build to Travis matrix [\#753](https://github.com/uclouvain/openjpeg/pull/753) ([julienmalik](https://github.com/julienmalik))
- Fix implicit floating bool conversion [\#752](https://github.com/uclouvain/openjpeg/pull/752) ([julienmalik](https://github.com/julienmalik))
- Do not define \_\_attribute\_\_ in opj\_includes.h [\#751](https://github.com/uclouvain/openjpeg/pull/751) ([mayeut](https://github.com/mayeut))
- Allow to read/write 3/5/7/9/11/13/15 bpp TIF files [\#750](https://github.com/uclouvain/openjpeg/pull/750) ([mayeut](https://github.com/mayeut))
- Fix heap-buffer-overflow in color\_esycc\_to\_rgb [\#748](https://github.com/uclouvain/openjpeg/pull/748) ([mayeut](https://github.com/mayeut))
- update libpng to from 1.6.17 to 1.6.21 [\#747](https://github.com/uclouvain/openjpeg/pull/747) ([julienmalik](https://github.com/julienmalik))
- Update cmake & jpylyzer for travis builds [\#746](https://github.com/uclouvain/openjpeg/pull/746) ([julienmalik](https://github.com/julienmalik))
- Fix Out-Of-Bounds Read in sycc42x\_to\_rgb function [\#745](https://github.com/uclouvain/openjpeg/pull/745) ([mayeut](https://github.com/mayeut))
- cppcheck fix for openjp2 [\#740](https://github.com/uclouvain/openjpeg/pull/740) ([julienmalik](https://github.com/julienmalik))
- Fix uninitialized variable reported by cppcheck [\#735](https://github.com/uclouvain/openjpeg/pull/735) ([julienmalik](https://github.com/julienmalik))
- Remove dead code in opj\_dump [\#734](https://github.com/uclouvain/openjpeg/pull/734) ([julienmalik](https://github.com/julienmalik))
- issue \#695 MQ Encode: ensure that bp pointer never points to uninitialized memory [\#708](https://github.com/uclouvain/openjpeg/pull/708) ([boxerab](https://github.com/boxerab))
- Fix issue 135 [\#706](https://github.com/uclouvain/openjpeg/pull/706) ([mayeut](https://github.com/mayeut))
- Fix implementation of opj\_calloc [\#705](https://github.com/uclouvain/openjpeg/pull/705) ([stweil](https://github.com/stweil))
- \[git/2.1 regression\] Fix opj\_write\_tile\(\) failure when numresolutions=1 [\#690](https://github.com/uclouvain/openjpeg/pull/690) ([rouault](https://github.com/rouault))
- Fix fatal crash on 64 bit Linux [\#687](https://github.com/uclouvain/openjpeg/pull/687) ([stweil](https://github.com/stweil))
- \[libtiff\] Add missing include statement for ssize\_t [\#686](https://github.com/uclouvain/openjpeg/pull/686) ([mayeut](https://github.com/mayeut))
- Fix duplicate article in comments [\#684](https://github.com/uclouvain/openjpeg/pull/684) ([stweil](https://github.com/stweil))
- Fix grammar in comment [\#679](https://github.com/uclouvain/openjpeg/pull/679) ([stweil](https://github.com/stweil))
- Remove whitespace and CR at line endings [\#678](https://github.com/uclouvain/openjpeg/pull/678) ([stweil](https://github.com/stweil))
- Fix typos [\#665](https://github.com/uclouvain/openjpeg/pull/665) ([jwilk](https://github.com/jwilk))
- Add missing source for the JPIP library and executables \(issue \#658\) [\#659](https://github.com/uclouvain/openjpeg/pull/659) ([stweil](https://github.com/stweil))
- Fix undefined size jp2 box handling [\#654](https://github.com/uclouvain/openjpeg/pull/654) ([mayeut](https://github.com/mayeut))
- opj\_decompress: Update error message [\#651](https://github.com/uclouvain/openjpeg/pull/651) ([stweil](https://github.com/stweil))
- Fix support of posix\_memalloc for Linux [\#648](https://github.com/uclouvain/openjpeg/pull/648) ([stweil](https://github.com/stweil))
- Fix typo in comments [\#647](https://github.com/uclouvain/openjpeg/pull/647) ([stweil](https://github.com/stweil))
- Avoid pointer arithmetic with \(void \*\) pointers [\#644](https://github.com/uclouvain/openjpeg/pull/644) ([smuehlst](https://github.com/smuehlst))
- Fix HP compiler warning about redeclaration of function \(\#640\) [\#641](https://github.com/uclouvain/openjpeg/pull/641) ([smuehlst](https://github.com/smuehlst))
- Fix format strings and unneeded assignment [\#638](https://github.com/uclouvain/openjpeg/pull/638) ([stweil](https://github.com/stweil))
- Fix repository for JPEG2000 test data [\#637](https://github.com/uclouvain/openjpeg/pull/637) ([stweil](https://github.com/stweil))
- Update allocation functions [\#636](https://github.com/uclouvain/openjpeg/pull/636) ([mayeut](https://github.com/mayeut))
- Fix OpenJPEG GitHub issue \#633. [\#634](https://github.com/uclouvain/openjpeg/pull/634) ([smuehlst](https://github.com/smuehlst))
- travis-ci: Include add ons in matrix [\#632](https://github.com/uclouvain/openjpeg/pull/632) ([mayeut](https://github.com/mayeut))
- Add Appveyor [\#627](https://github.com/uclouvain/openjpeg/pull/627) ([mayeut](https://github.com/mayeut))
- Use Travis-ci to run ABI check [\#626](https://github.com/uclouvain/openjpeg/pull/626) ([mayeut](https://github.com/mayeut))
- Fix warnings for C++ [\#623](https://github.com/uclouvain/openjpeg/pull/623) ([stweil](https://github.com/stweil))
- Fixed problem that C++ compilation failed because of enum variable. [\#622](https://github.com/uclouvain/openjpeg/pull/622) ([smuehlst](https://github.com/smuehlst))
- Added missing casts for return values of opj\_malloc\(\)/opj\_calloc\(\). [\#618](https://github.com/uclouvain/openjpeg/pull/618) ([smuehlst](https://github.com/smuehlst))
- Add check for seek support before trying TPsot==TNsot workaround [\#617](https://github.com/uclouvain/openjpeg/pull/617) ([mayeut](https://github.com/mayeut))
- Fix some typos found by codespell [\#610](https://github.com/uclouvain/openjpeg/pull/610) ([stweil](https://github.com/stweil))
- Correct leak in color\_cielab\_to\_rgb [\#590](https://github.com/uclouvain/openjpeg/pull/590) ([mayeut](https://github.com/mayeut))
- Add Travis-ci build matrix [\#584](https://github.com/uclouvain/openjpeg/pull/584) ([mayeut](https://github.com/mayeut))
- Correct lossless issue on linux x86 [\#579](https://github.com/uclouvain/openjpeg/pull/579) ([mayeut](https://github.com/mayeut))
- Travis-ci update [\#578](https://github.com/uclouvain/openjpeg/pull/578) ([mayeut](https://github.com/mayeut))
- Correct CMake version requirements [\#572](https://github.com/uclouvain/openjpeg/pull/572) ([mayeut](https://github.com/mayeut))
- Add tests for CMYK/esYCC/CIELab [\#567](https://github.com/uclouvain/openjpeg/pull/567) ([mayeut](https://github.com/mayeut))
- Add support for CIELab, EYCC and CMYK [\#559](https://github.com/uclouvain/openjpeg/pull/559) ([szukw000](https://github.com/szukw000))
- Remove printf/fprintf to stdout/stderr throughout openjp2 lib [\#558](https://github.com/uclouvain/openjpeg/pull/558) ([mayeut](https://github.com/mayeut))
- better -ffast-math handling [\#555](https://github.com/uclouvain/openjpeg/pull/555) ([rdieter](https://github.com/rdieter))
- Add jpylyzer tests for JP2 compression [\#552](https://github.com/uclouvain/openjpeg/pull/552) ([mayeut](https://github.com/mayeut))
- Add COC/QCC in main header when needed [\#551](https://github.com/uclouvain/openjpeg/pull/551) ([mayeut](https://github.com/mayeut))
- Use \_\_emul under msvc x86 for fast 64 = 32 \* 32 [\#550](https://github.com/uclouvain/openjpeg/pull/550) ([mayeut](https://github.com/mayeut))
- Update convert for PNG output [\#549](https://github.com/uclouvain/openjpeg/pull/549) ([mayeut](https://github.com/mayeut))
- Remove some warnings when building [\#548](https://github.com/uclouvain/openjpeg/pull/548) ([mayeut](https://github.com/mayeut))
- Switch to libpng-1.6.17 [\#547](https://github.com/uclouvain/openjpeg/pull/547) ([mayeut](https://github.com/mayeut))
- Add some missing static keywords [\#545](https://github.com/uclouvain/openjpeg/pull/545) ([mayeut](https://github.com/mayeut))
- Switch to libcms2 mm2/Little-CMS@0e8234e090d6aab33f90e2eb0296f30aa0705e57 [\#544](https://github.com/uclouvain/openjpeg/pull/544) ([mayeut](https://github.com/mayeut))
- Prevent overflow when coding 16 bits images [\#543](https://github.com/uclouvain/openjpeg/pull/543) ([mayeut](https://github.com/mayeut))
- Switch to libcms2-2.6 [\#542](https://github.com/uclouvain/openjpeg/pull/542) ([mayeut](https://github.com/mayeut))
- Update PNG support [\#538](https://github.com/uclouvain/openjpeg/pull/538) ([mayeut](https://github.com/mayeut))
- Various Minor fixes [\#537](https://github.com/uclouvain/openjpeg/pull/537) ([mayeut](https://github.com/mayeut))
- Update TIFF conversion to support more bit depth. [\#535](https://github.com/uclouvain/openjpeg/pull/535) ([mayeut](https://github.com/mayeut))
- Add checks for odd looking cmap & for cmap outside jp2h box [\#534](https://github.com/uclouvain/openjpeg/pull/534) ([mayeut](https://github.com/mayeut))
- Refactor opj\_j2k\_read\_ppm & opj\_j2k\_read\_ppt [\#533](https://github.com/uclouvain/openjpeg/pull/533) ([mayeut](https://github.com/mayeut))
- Add option to force component splitting in imagetopnm [\#531](https://github.com/uclouvain/openjpeg/pull/531) ([mayeut](https://github.com/mayeut))
- fix Suspicious code in j2k.c \#517 [\#529](https://github.com/uclouvain/openjpeg/pull/529) ([renevanderark](https://github.com/renevanderark))
- Update zlib to version 1.2.8 [\#528](https://github.com/uclouvain/openjpeg/pull/528) ([mayeut](https://github.com/mayeut))
- Fix opj\_write\_bytes\_BE \(\#518\) [\#521](https://github.com/uclouvain/openjpeg/pull/521) ([manisandro](https://github.com/manisandro))
- Correctly decode files with incorrect tile-part header fields \(TPsot==TNsot\) [\#514](https://github.com/uclouvain/openjpeg/pull/514) ([mayeut](https://github.com/mayeut))
- Fixed typos [\#510](https://github.com/uclouvain/openjpeg/pull/510) ([radarhere](https://github.com/radarhere))
- Formatted the readme file [\#507](https://github.com/uclouvain/openjpeg/pull/507) ([htmfilho](https://github.com/htmfilho))
## [version.2.1](https://github.com/uclouvain/openjpeg/releases/tag/version.2.1) (2014-04-29)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.2.0.1...version.2.1)
## [version.2.0.1](https://github.com/uclouvain/openjpeg/releases/tag/version.2.0.1) (2014-04-22)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.5.2...version.2.0.1)
## [version.1.5.2](https://github.com/uclouvain/openjpeg/releases/tag/version.1.5.2) (2014-03-28)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.2.0...version.1.5.2)
## [version.2.0](https://github.com/uclouvain/openjpeg/releases/tag/version.2.0) (2014-03-28)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.5.1...version.2.0)
## [version.1.5.1](https://github.com/uclouvain/openjpeg/releases/tag/version.1.5.1) (2012-09-13)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.5...version.1.5.1)
## [version.1.5](https://github.com/uclouvain/openjpeg/releases/tag/version.1.5) (2012-02-07)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.3...version.1.5)
## [version.1.3](https://github.com/uclouvain/openjpeg/releases/tag/version.1.3) (2011-07-03)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.4...version.1.3)
## [version.1.4](https://github.com/uclouvain/openjpeg/releases/tag/version.1.4) (2011-07-03)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.2...version.1.4)
## [version.1.2](https://github.com/uclouvain/openjpeg/releases/tag/version.1.2) (2007-06-04)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.1...version.1.2)
## [version.1.1](https://github.com/uclouvain/openjpeg/releases/tag/version.1.1) (2007-01-31)
List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.0...version.1.1)
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

View File

@ -1,388 +0,0 @@
# Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org)
# Written by Mathieu Malaterre
# This CMake project will by default create a library called openjpeg
# But if you want to use this project within your own (CMake) project
# you will eventually like to prefix the library to avoid linking confusion
# 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.2)
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0003 NEW)
if (NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
cmake_policy(SET CMP0042 NEW)
endif()
endif()
if(NOT OPENJPEG_NAMESPACE)
set(OPENJPEG_NAMESPACE "OPENJPEG")
set(OPENJPEG_STANDALONE 1)
endif()
# In all cases:
#string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
set(OPENJPEG_LIBRARY_NAME openjp2)
project(${OPENJPEG_NAMESPACE} C)
# Do full dependency headers.
include_regular_expression("^.*$")
#-----------------------------------------------------------------------------
# OPENJPEG version number, useful for packaging and doxygen doc:
set(OPENJPEG_VERSION_MAJOR 2)
set(OPENJPEG_VERSION_MINOR 2)
set(OPENJPEG_VERSION_BUILD 0)
set(OPENJPEG_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
set(PACKAGE_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
# Because autotools does not support X.Y notation for SOVERSION, we have to use
# two numbering, one for the openjpeg version and one for openjpeg soversion
# version | soversion
# 1.0 | 0
# 1.1 | 1
# 1.2 | 2
# 1.3 | 3
# 1.4 | 4
# 1.5 | 5
# 1.5.1 | 5
# 2.0 | 6
# 2.0.1 | 6
# 2.1 | 7
# 2.1.1 | 7
# 2.1.2 | 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
if(NOT OPENJPEG_SOVERSION)
set(OPENJPEG_SOVERSION 7)
endif(NOT OPENJPEG_SOVERSION)
set(OPENJPEG_LIBRARY_PROPERTIES
VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
SOVERSION "${OPENJPEG_SOVERSION}"
)
# --------------------------------------------------------------------------
# Path to additional CMake modules
set(CMAKE_MODULE_PATH
${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake
${CMAKE_MODULE_PATH})
# --------------------------------------------------------------------------
# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
# warnings
if(WIN32)
if(NOT BORLAND)
if(NOT CYGWIN)
if(NOT MINGW)
if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
add_definitions(
-D_CRT_FAR_MAPPINGS_NO_DEPRECATE
-D_CRT_IS_WCTYPE_NO_DEPRECATE
-D_CRT_MANAGED_FP_NO_DEPRECATE
-D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_SECURE_NO_DEPRECATE
-D_CRT_SECURE_NO_DEPRECATE_GLOBALS
-D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
-D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
-D_CRT_VCCLRIT_NO_DEPRECATE
-D_SCL_SECURE_NO_DEPRECATE
)
endif()
endif()
endif()
endif()
endif()
# --------------------------------------------------------------------------
# Install directories
# Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
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 ${OPENJPEG_INSTALL_BIN_DIR})
else()
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR})
endif()
endif()
if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
# 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)
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:
include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
#-----------------------------------------------------------------------------
# Setup file for setting custom ctest vars
configure_file(
${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake
@ONLY
)
#-----------------------------------------------------------------------------
# OpenJPEG build configuration options.
option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." 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)
#-----------------------------------------------------------------------------
# configure name mangling to allow multiple libraries to coexist
# peacefully
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
@ONLY)
endif()
#-----------------------------------------------------------------------------
# Compiler specific flags:
if(CMAKE_COMPILER_IS_GNUCC)
# For all builds, make sure openjpeg is std99 compliant:
# 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>")
endif()
#-----------------------------------------------------------------------------
# opj_config.h generation (1/2)
# Check if some include files are provided by the system
include(EnsureFileInclude)
# These files are mandatory
ensure_file_include("string.h" HAVE_STRING_H YES)
ensure_file_include("memory.h" HAVE_MEMORY_H YES)
ensure_file_include("stdlib.h" HAVE_STDLIB_H YES)
ensure_file_include("stdio.h" HAVE_STDIO_H YES)
ensure_file_include("math.h" HAVE_MATH_H YES)
ensure_file_include("float.h" HAVE_FLOAT_H YES)
ensure_file_include("time.h" HAVE_TIME_H YES)
ensure_file_include("stdarg.h" HAVE_STDARG_H YES)
ensure_file_include("ctype.h" HAVE_CTYPE_H YES)
ensure_file_include("assert.h" HAVE_ASSERT_H YES)
# For the following files, we provide an alternative, they are not mandatory
ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO)
ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO)
# why check this one ? for openjpip ?
include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
# Enable Large file support
include(TestLargeFiles)
OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
# Allocating Aligned Memory Blocks
include(CheckIncludeFiles)
check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
include(CheckSymbolExists)
# _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC)
# posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux)
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN)
unset(CMAKE_REQUIRED_DEFINITIONS)
# memalign (obsolete)
check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN)
#-----------------------------------------------------------------------------
# Build Library
if(BUILD_JPIP_SERVER)
find_package(CURL REQUIRED)
find_package(FCGI REQUIRED)
find_package(Threads REQUIRED)
if(NOT CMAKE_USE_PTHREADS_INIT)
message(FATAL_ERROR "Only pthread are supported")
endif()
endif()
add_subdirectory(src/lib)
option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
#-----------------------------------------------------------------------------
# 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 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)
add_subdirectory(thirdparty)
add_subdirectory(src/bin)
endif ()
add_subdirectory(wrapping)
#-----------------------------------------------------------------------------
# opj_config.h generation (2/2)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
@ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
@ONLY
)
#-----------------------------------------------------------------------------
# build documentation in doc subdir:
if(BUILD_DOC)
add_subdirectory(doc)
endif()
#-----------------------------------------------------------------------------
# Buld Testing
option(BUILD_TESTING "Build the tests." OFF)
if(BUILD_TESTING)
if(BUILD_CODEC)
enable_testing()
include(CTest)
# Search openjpeg data needed for the tests
# They could be found via git on the OpenJPEG GitHub code project
# git clone https://github.com/uclouvain/openjpeg-data.git
find_path(OPJ_DATA_ROOT README-OPJ-Data
PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
)
# Add repository where to find tests
add_subdirectory(tests)
else()
message(FATAL_ERROR "You need build codec to run the tests")
endif()
endif()
#-----------------------------------------------------------------------------
# install all targets referenced as OPENJPEGTargets
install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
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, 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)
# 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
${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
${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()
#-----------------------------------------------------------------------------

View File

@ -1,7 +0,0 @@
set(CTEST_PROJECT_NAME "OPENJPEG")
set(CTEST_NIGHTLY_START_TIME "3:00:00 UTC")
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=OPENJPEG")
set(CTEST_DROP_SITE_CDASH TRUE)

View File

@ -1,75 +0,0 @@
# OpenJPEG installation
The build method maintained by OpenJPEG is [CMake](https://cmake.org/).
## UNIX/LINUX - MacOS (terminal) - WINDOWS (cygwin, MinGW)
To build the library, type from source tree directory:
```
mkdir build
cd build
cmake ..
make
```
Binaries are then located in the 'bin' directory.
To install the library, type with root privileges:
```
make install
make clean
```
To build the html documentation, you need doxygen to be installed on your system.
It will create an "html" directory in TOP\_LEVEL/build/doc)
```
make doc
```
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.
* To build the CODEC executables: '-DBUILD\_CODEC:bool=on' (default: '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')
* [OBSOLETE] To build the JPIP server (need fcgi) library and executables: '-DBUILD\_JPIP\_SERVER:bool=on' (default: 'OFF')
* To enable testing (and automatic result upload to http://my.cdash.org/index.php?project=OPENJPEG):
```
cmake . -DBUILD_TESTING:BOOL=ON -DOPJ_DATA_ROOT:PATH='path/to/the/data/directory' -DBUILDNAME:STRING='name_of_the_build'
make
make Experimental
```
Note : test data is available on the following github repo: https://github.com/uclouvain/openjpeg-data
If '-DOPJ\_DATA\_ROOT:PATH' option is omitted, test files will be automatically searched in '${CMAKE\_SOURCE\_DIR}/../data'.
Note 2 : to execute the encoding test suite, kakadu binaries are needed to decode encoded image and compare it to the baseline. Kakadu binaries are freely available for non-commercial purposes at http://www.kakadusoftware.com. kdu\_expand will need to be in your PATH for cmake to find it.
Note 3 : OpenJPEG encoder and decoder (not the library itself !) depends on several libraries: png, tiff, lcms, z. If these libraries are not found on the system, they are automatically built from the versions available in the source tree. You can force the use of these embedded version with BUILD\_THIRDPARTY:BOOL=ON. On a Debian-like system you can also simply install these libraries with:
```
sudo apt-get install liblcms2-dev libtiff-dev libpng-dev libz-dev
```
Note 4 : On MacOS, if it does not work, try adding the following flag to the cmake command :
```
-DCMAKE_OSX_ARCHITECTURES:STRING=i386
```
## 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.
# Using OpenJPEG
To use openjpeg exported cmake file, simply create your application doing:
```
$ cat CMakeLists.txt
find_package(OpenJPEG REQUIRED)
include_directories(${OPENJPEG_INCLUDE_DIRS})
add_executable(myapp myapp.c)
target_link_libraries(myapp ${OPENJPEG_LIBRARIES})
```

39
LICENSE
View File

@ -1,39 +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) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2003-2009, Francois-Olivier Devaux
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* Copyright (c) 2012, CS Systemes d'Information, France
*
* 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.
*/

72
NEWS.md
View File

@ -1,72 +0,0 @@
# OpenJPEG NEWS
More details in the [Changelog](https://github.com/uclouvain/openjpeg/blob/master/CHANGELOG.md)
## OpenJPEG 2.1.2
* Bug fixes (including security fixes)
* No API/ABI break compared to v2.1.1
## OpenJPEG 2.1.1
* Huge amount of critical bugfixes
* Speed improvements
* No API/ABI break compared to v2.1
## OpenJPEG 2.1.0
### New Features
* Digital Cinema profiles have been fixed and updated
* New option to disable MCT if needed
* extended RAW support: it is now possible to input raw images
with subsampled color components (422, 420, etc)
* New way to deal with profiles
### API/ABI modifications
(see [here](http://www.openjpeg.org/abi-check/timeline/openjpeg/) for details)
* Removed deprecated functions
* opj_stream_create_default_file_stream(FILE*,...)
* opj_stream_create_file_stream(FILE*,...)
* opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data)
* Added
* opj_stream_create_default_file_stream(char*,...)
* opj_stream_create_file_stream(char*,...)
* opj_stream_destroy(opj_stream_t*)
* opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data,
... opj_stream_free_user_data_fn p_function)
* JPEG 2000 profiles and Part-2 extensions defined through '#define'
* Changed
* 'alpha' field added to 'opj_image_comp' structure
* 'OPJ_CLRSPC_EYCC' added to enum COLOR_SPACE
* 'OPJ_CLRSPC_CMYK' added to enum COLOR_SPACE
* 'OPJ_CODEC_JPP' and 'OPJ_CODEC_JPX' added to CODEC_FORMAT
(not yet used in use)
* 'max_cs_size' and 'rsiz' fields added to opj_cparameters_t
### Misc
* OpenJPEG is now officially conformant with JPEG 2000 Part-1
and will soon become official reference software at the
JPEG committee.
* Huge amount of bug fixes. See CHANGES for details.
## OpenJPEG 2.0.0
### New Features
* streaming capabilities
* merge JP3D
### API modifications
(see [here](http://www.openjpeg.org/abi-check/timeline/openjpeg/) for details)
* Use a 64bits capable API
### Misc
* removed autotools build system
* folders hierarchies reorganisation
* Huge amount of bug fixes. See CHANGES for details.

View File

@ -1,82 +0,0 @@
# OPENJPEG Library and Applications
## What is OpenJPEG ?
OpenJPEG is an open-source JPEG 2000 codec written in C language. It has been developed in order to promote the use of [JPEG 2000](http://www.jpeg.org/jpeg2000), a still-image compression standard from the Joint Photographic Experts Group ([JPEG](http://www.jpeg.org)). Since April 2015, it is officially recognized by ISO/IEC and ITU-T as a [JPEG 2000 Reference Software](http://www.itu.int/rec/T-REC-T.804-201504-I!Amd2).
## Who can use the code ?
[![badge-license]][link-license]
Anyone. As the OpenJPEG code is released under the [BSD 2-clause "Simplified" License][link-license], anyone can use or modify the code, even for commercial applications. The only restriction is to retain the copyright in the sources or in the binaries documentation. Of course, if you modified the code in a way that might be of interest for other users, you are encouraged to share it (through a [github pull request](https://github.com/uclouvain/openjpeg/pulls) or by filling an [issue](https://github.com/uclouvain/openjpeg/issues)) but this is not a requirement.
## How to install and use OpenJPEG ?
API Documentation needs a major refactoring. Meanwhile, you can check [installation](https://github.com/uclouvain/openjpeg/wiki/Installation) instructions and [codec documentation](https://github.com/uclouvain/openjpeg/wiki/DocJ2KCodec).
## Current Status
[![badge-build]][link-build]
[![badge-msvc-build]][link-msvc-build]
[![badge-coverity]][link-coverity]
## Who are the developers ?
The library is developed and maintained by the Image and Signal Processing Group ([ISPGroup](http://sites.uclouvain.be/ispgroup/)), in the Université catholique de Louvain ([UCL](http://www.uclouvain.be/en-index.html), with the support of the [CNES](https://cnes.fr/), the [CS](http://www.c-s.fr/) company and the [intoPIX](http://www.intopix.com) company. The JPWL module has been developed by the Digital Signal Processing Lab ([DSPLab](http://dsplab.diei.unipg.it/)) of the University of Perugia, Italy ([UNIPG](http://www.unipg.it/)).
## Details on folders hierarchy
* 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
* java: java jni to use openjpeg in a java program
* thirdparty: thirdparty libraries used by some applications. These libraries will be built only if there are not found on the system. Note that libopenjpeg itself does not have any dependency.
* 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
See [LICENSE][link-license] for license and copyright information.
See [INSTALL](https://github.com/uclouvain/openjpeg/blob/master/INSTALL.md) for installation procedures.
See [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) for user visible changes in successive releases.
## API/ABI
An API/ABI timeline is automatically updated [here][link-api-timeline].
OpenJPEG strives to provide a stable API/ABI for your applications. As such it
only exposes a limited subset of its functions. It uses a mechanism of
exporting/hiding functions. If you are unsure which functions you can use in
your applications, you should compile OpenJPEG using something similar to gcc:
`-fvisibility=hidden` compilation flag.
See also: http://gcc.gnu.org/wiki/Visibility
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://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"
[link-coverity]: https://scan.coverity.com/projects/uclouvain-openjpeg "Coverity Scan Build Status"
[link-api-timeline]: http://www.openjpeg.org/abi-check/timeline/openjpeg "OpenJPEG API/ABI timeline"

View File

@ -1,39 +0,0 @@
# OpenJPEG THANKS file
Many people have contributed to OpenJPEG by reporting problems, suggesting various improvements,
or submitting actual code. Here is a list of these people. Help me keep
it complete and exempt of errors.
* Giuseppe Baruffa
* Ben Boeckel
* Aaron Boxer
* David Burken
* Matthieu Darbois
* Rex Dieter
* Herve Drolon
* Antonin Descampe
* Francois-Olivier Devaux
* Parvatha Elangovan
* Jerôme Fimes
* Bob Friesenhahn
* Kaori Hagihara
* Luc Hermitte
* Luis Ibanez
* David Janssens
* Hans Johnson
* Callum Lerwick
* Ke Liu (Tencent's Xuanwu LAB)
* Sebastien Lugan
* Benoit Macq
* Mathieu Malaterre
* Julien Malik
* Arnaud Maye
* Vincent Nicolas
* Aleksander Nikolic (Cisco Talos)
* Glenn Pearson
* Even Rouault
* Dzonatas Sol
* Winfried Szukalski
* Vincent Torri
* Yannick Verschueren
* Peter Wimmer

View File

@ -1,38 +0,0 @@
version: 2.1.1.{build}
branches:
except:
- coverity_scan
skip_tags: false
clone_depth: 50
environment:
matrix:
- OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
OPJ_CI_INCLUDE_IF_DEPLOY: 1
- OPJ_CI_ARCH: x64
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
OPJ_CI_INCLUDE_IF_DEPLOY: 1
- OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS100COMNTOOLS)
install:
- cmd: c:\cygwin\bin\bash ./tools/travis-ci/install.sh
build_script:
- cmd: >-
"%OPJ_CI_VSCOMNTOOLS%..\..\VC\vcvarsall.bat" %OPJ_CI_ARCH%
bash ./tools/travis-ci/run.sh
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: 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

@ -1,40 +0,0 @@
#----------------------------------------------------------------------
#
# For further details regarding this file,
# see http://www.cmake.org/Wiki/CMake_Testing_With_CTest#Customizing_CTest
#
# and
# http://www.kitware.com/blog/home/post/27
#
#----------------------------------------------------------------------
set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 1000000)
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS 50)
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 2000)
set(CTEST_CUSTOM_COVERAGE_EXCLUDE
${CTEST_CUSTOM_COVERAGE_EXCLUDE}
# Exclude files from the Testing directories
".*/tests/.*"
# Exclude files from the ThirdParty Utilities directories
".*/thirdparty/.*"
)
set(CTEST_CUSTOM_WARNING_EXCEPTION
${CTEST_CUSTOM_WARNING_EXCEPTION}
# Ignore clang's summary warning, assuming prior text has matched some
# other warning expression:
"[0-9,]+ warnings? generated."
# Suppress warning caused by intentional messages about deprecation
".*warning,.* is deprecated"
# java also warns about deprecated API
".*java.*deprecation"
".*deprecation.*"
# suppress warnings caused by 3rd party libs:
".*thirdparty.*"
"libtiff.*has no symbols"
"libpng.*has no symbols"
)

View File

@ -1,26 +0,0 @@
# Ensure that an include file is provided by the system
# Add the check about the mandatory status to the check_include_file macro
# provided by cmake
include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
macro(ensure_file_include INCLUDE_FILENAME VARIABLE_NAME MANDATORY_STATUS)
#message(WARNING "INCLUDE_FILENAME=${INCLUDE_FILENAME} \n"
# "VARIABLE_NAME=${VARIABLE_NAME} \n"
# "MANDATORY_STATUS=${MANDATORY_STATUS}")
CHECK_INCLUDE_FILE(${INCLUDE_FILENAME} ${VARIABLE_NAME})
#message(WARNING "INCLUDE_FILENAME=${INCLUDE_FILENAME} \n"
# "VARIABLE_NAME=${VARIABLE_NAME} \n"
# "VARIABLE_NAME_VALUE=${${VARIABLE_NAME}} \n"
# "MANDATORY_STATUS=${MANDATORY_STATUS}")
if (NOT ${${VARIABLE_NAME}})
if (${MANDATORY_STATUS})
message(FATAL_ERROR "The file ${INCLUDE_FILENAME} is mandatory but not found on your system")
endif()
endif()
endmacro()

View File

@ -1,16 +0,0 @@
# cppcheck
#
# Copyright (c) 2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
find_program(CPPCHECK_EXECUTABLE
cppcheck
)
mark_as_advanced(
CPPCHECK_EXECUTABLE
)

View File

@ -1,20 +0,0 @@
# Look for the header file.
find_path(FCGI_INCLUDE_DIR NAMES fastcgi.h)
# Look for the library.
find_library(FCGI_LIBRARY NAMES fcgi)
# Handle the QUIETLY and REQUIRED arguments and set FCGI_FOUND to TRUE if all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FCGI DEFAULT_MSG FCGI_LIBRARY FCGI_INCLUDE_DIR)
# Copy the results to the output variables.
if(FCGI_FOUND)
set(FCGI_LIBRARIES ${FCGI_LIBRARY})
set(FCGI_INCLUDE_DIRS ${FCGI_INCLUDE_DIR})
else()
set(FCGI_LIBRARIES)
set(FCGI_INCLUDE_DIRS)
endif()
mark_as_advanced(FCGI_INCLUDE_DIR FCGI_LIBRARY)

View File

@ -1,12 +0,0 @@
#
# this module looks for JPYLYZER
# http://jpylyzer.openpreservation.org
#
find_program(JPYLYZER_EXECUTABLE
jpylyzer
)
mark_as_advanced(
JPYLYZER_EXECUTABLE
)

View File

@ -1,24 +0,0 @@
#
# this module looks for KAKADU
# http://www.kakadusoftware.com/
#
#
# Copyright (c) 2006-2014 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
find_program(KDU_EXPAND_EXECUTABLE
kdu_expand
)
find_program(KDU_COMPRESS_EXECUTABLE
kdu_compress
)
mark_as_advanced(
KDU_EXPAND_EXECUTABLE
KDU_COMPRESS_EXECUTABLE
)

View File

@ -1,31 +0,0 @@
# - Find LCMS library
# Find the native LCMS includes and library
# Once done this will define
#
# LCMS_INCLUDE_DIR - Where to find lcms.h, etc.
# LCMS_LIBRARIES - Libraries to link against to use LCMS.
# LCMS_FOUND - If false, do not try to use LCMS.
#
# also defined, but not for general use are
# LCMS_LIBRARY, where to find the LCMS library.
#=============================================================================
#=============================================================================
find_path(LCMS_INCLUDE_DIR lcms.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include)
set(LCMS_NAMES ${LCMS_NAMES} lcms liblcms liblcms_static)
find_library(LCMS_LIBRARY NAMES ${LCMS_NAMES} )
mark_as_advanced(LCMS_INCLUDE_DIR LCMS_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set LCMS_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS DEFAULT_MSG LCMS_LIBRARY LCMS_INCLUDE_DIR)
if(LCMS_FOUND)
set( LCMS_INCLUDE_DIRS ${LCMS_INCLUDE_DIR})
set( LCMS_LIBRARIES ${LCMS_LIBRARY} )
endif()

View File

@ -1,31 +0,0 @@
# - Find LCMS2 library
# Find the native LCMS2 includes and library
# Once done this will define
#
# LCMS2_INCLUDE_DIR - Where to find lcms2.h, etc.
# LCMS2_LIBRARIES - Libraries to link against to use LCMS2.
# LCMS2_FOUND - If false, do not try to use LCMS2.
#
# also defined, but not for general use are
# LCMS2_LIBRARY - Where to find the LCMS2 library.
#=============================================================================
#=============================================================================
find_path(LCMS2_INCLUDE_DIR lcms2.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include)
set(LCMS2_NAMES ${LCMS2_NAMES} lcms2 liblcms2 liblcms2_static)
find_library(LCMS2_LIBRARY NAMES ${LCMS2_NAMES} )
mark_as_advanced(LCMS2_INCLUDE_DIR LCMS2_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set LCMS2_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS2 DEFAULT_MSG LCMS2_LIBRARY LCMS2_INCLUDE_DIR)
if(LCMS2_FOUND)
set( LCMS2_INCLUDE_DIRS ${LCMS2_INCLUDE_DIR})
set( LCMS2_LIBRARIES ${LCMS2_LIBRARY} )
endif()

View File

@ -1,9 +0,0 @@
# JPIP test driver
#message(STATUS "${D_URL}")
file(DOWNLOAD
"${D_URL}"
"${D_FILE}"
LOG log
EXPECTED_MD5 "${EXPECTED_MD5}"
)
message(STATUS "LOG: ${log}")

View File

@ -1,72 +0,0 @@
# package bundler
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
if(EXISTS "${CMAKE_ROOT}/Modules/InstallRequiredSystemLibraries.cmake")
set(CMAKE_INSTALL_MFC_LIBRARIES 0)
set(CMAKE_INSTALL_DEBUG_LIBRARIES 0)
if(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
endif()
include(${CMAKE_ROOT}/Modules/InstallRequiredSystemLibraries.cmake)
endif()
set(OPJ_PACKAGE_DESCRIPTION_SUMMARY "OpenJPEG - OpenJPEG a JPEG 2000 implementation.")
set(OPJ_PACKAGE_CONTACT "openjpeg users <openjpeg@googlegroups.com>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${OPJ_PACKAGE_DESCRIPTION_SUMMARY})
set(CPACK_PACKAGE_VENDOR "OpenJPEG Team")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
"${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" COPYONLY
)
# For PackageMaker on MacOSX it is important to have a file extension:
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${OPENJPEG_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${OPENJPEG_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${OPENJPEG_VERSION_BUILD}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "OpenJPEG ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "openjpeg-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
# Make this explicit here, rather than accepting the CPack default value,
# so we can refer to it:
set(CPACK_PACKAGE_NAME "${OPENJPEG_LIBRARY_NAME}")
if(NOT DEFINED CPACK_SYSTEM_NAME)
# make sure package is not Cygwin-unknown, for Cygwin just
# cygwin is good for the system name
if("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
set(CPACK_SYSTEM_NAME Cygwin)
else()
set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR})
endif()
endif()
if(${CPACK_SYSTEM_NAME} MATCHES Windows)
if(CMAKE_CL_64)
set(CPACK_SYSTEM_NAME win64-x64)
else()
set(CPACK_SYSTEM_NAME win32-x86)
endif()
endif()
if(NOT DEFINED CPACK_PACKAGE_FILE_NAME)
# if the CPACK_PACKAGE_FILE_NAME is not defined by the cache
# default to source package - system, on cygwin system is not
# needed
if(CYGWIN)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}")
else()
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_SOURCE_PACKAGE_FILE_NAME}-${CPACK_SYSTEM_NAME}")
endif()
endif()
set(CPACK_BUNDLE_NAME "OpenJPEG ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
if(APPLE)
configure_file(${CMAKE_ROOT}/Templates/AppleInfo.plist
${CMAKE_CURRENT_BINARY_DIR}/opj.plist)
set(CPACK_BUNDLE_PLIST
${CMAKE_CURRENT_BINARY_DIR}/opj.plist)
#include(BundleUtilities)
endif()
include(CPack)
endiF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")

View File

@ -1,48 +0,0 @@
#-----------------------------------------------------------------------------
#
# OPENJPEGConfig.cmake - CMake configuration file for external projects.
#
# 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@
# The OPENJPEG version number.
set(OPENJPEG_MAJOR_VERSION "@OPENJPEG_VERSION_MAJOR@")
set(OPENJPEG_MINOR_VERSION "@OPENJPEG_VERSION_MINOR@")
set(OPENJPEG_BUILD_VERSION "@OPENJPEG_VERSION_BUILD@")
# The libraries.
set(OPENJPEG_LIBRARIES "@OPENJPEG_LIBRARY_NAME@")
# The CMake macros dir.
set(OPENJPEG_CMAKE_DIR "@OPENJPEG_INSTALL_PACKAGE_DIR@")
# The configuration options.
set(OPENJPEG_BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@")
# The "use" file.
set(OPENJPEG_USE_FILE "@OPENJPEG_USE_FILE_CONFIG@")
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)
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)
# This is a build tree
set( OPENJPEG_INCLUDE_DIRS @OPENJPEG_INCLUDE_PATH@)
include(${SELF_DIR}/OpenJPEGExports.cmake)
else()
message(FATAL_ERROR "ooops")
endif()
endif()
set(OPENJPEG_USE_FILE ${SELF_DIR}/UseOPENJPEG.cmake)
# Backward compatible part:
set(OPENJPEG_FOUND TRUE)

View File

@ -1,11 +0,0 @@
#include <sys/types.h>
/* Cause a compile-time error if off_t is smaller than 64 bits */
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
int main(int argc, char **argv)
{
return 0;
}

View File

@ -1,23 +0,0 @@
#cmakedefine _LARGEFILE_SOURCE
#cmakedefine _LARGE_FILES
#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
/* Cause a compile-time error if off_t is smaller than 64 bits,
* and make sure we have ftello / fseeko.
*/
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
FILE *fp = fopen(argv[0],"r");
off_t offset = ftello( fp );
fseeko( fp, offset, SEEK_CUR );
fclose(fp);
return 0;
}

View File

@ -1,134 +0,0 @@
# - Define macro to check large file support
#
# OPJ_TEST_LARGE_FILES(VARIABLE)
#
# VARIABLE will be set to true if off_t is 64 bits, and fseeko/ftello present.
# This macro will also defines the necessary variable enable large file support, for instance
# _LARGE_FILES
# _LARGEFILE_SOURCE
# _FILE_OFFSET_BITS 64
# OPJ_HAVE_FSEEKO
#
# However, it is YOUR job to make sure these defines are set in a #cmakedefine so they
# end up in a config.h file that is included in your source if necessary!
#
# Adapted from Gromacs project (http://www.gromacs.org/)
# by Julien Malik
#
macro(OPJ_TEST_LARGE_FILES VARIABLE)
if(NOT DEFINED ${VARIABLE})
# On most platforms it is probably overkill to first test the flags for 64-bit off_t,
# and then separately fseeko. However, in the future we might have 128-bit filesystems
# (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
message(STATUS "Checking for 64-bit off_t")
# First check without any special flags
try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c")
if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present")
endif()
if(NOT FILE64_OK)
# Test with _FILE_OFFSET_BITS=64
try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" )
if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
set(_FILE_OFFSET_BITS 64)
endif()
endif()
if(NOT FILE64_OK)
# Test with _LARGE_FILES
try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_LARGE_FILES" )
if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
set(_LARGE_FILES 1)
endif()
endif()
if(NOT FILE64_OK)
# Test with _LARGEFILE_SOURCE
try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
set(_LARGEFILE_SOURCE 1)
endif()
endif()
#if(NOT FILE64_OK)
# # now check for Windows stuff
# try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
# "${PROJECT_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
# if(FILE64_OK)
# message(STATUS "Checking for 64-bit off_t - present with _fseeki64")
# set(HAVE__FSEEKI64 1)
# endif()
#endif()
if(NOT FILE64_OK)
message(STATUS "Checking for 64-bit off_t - not present")
endif()
set(_FILE_OFFSET_BITS ${_FILE_OFFSET_BITS} CACHE INTERNAL "Result of test for needed _FILE_OFFSET_BITS=64")
set(_LARGE_FILES ${_LARGE_FILES} CACHE INTERNAL "Result of test for needed _LARGE_FILES")
set(_LARGEFILE_SOURCE ${_LARGEFILE_SOURCE} CACHE INTERNAL "Result of test for needed _LARGEFILE_SOURCE")
# Set the flags we might have determined to be required above
configure_file("${PROJECT_SOURCE_DIR}/cmake/TestLargeFiles.c.cmake.in"
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
message(STATUS "Checking for fseeko/ftello")
# Test if ftello/fseeko are available
try_compile(FSEEKO_COMPILE_OK
"${PROJECT_BINARY_DIR}"
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
if(FSEEKO_COMPILE_OK)
message(STATUS "Checking for fseeko/ftello - present")
endif()
if(NOT FSEEKO_COMPILE_OK)
# glibc 2.2 needs _LARGEFILE_SOURCE for fseeko (but not for 64-bit off_t...)
try_compile(FSEEKO_COMPILE_OK
"${PROJECT_BINARY_DIR}"
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
if(FSEEKO_COMPILE_OK)
message(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
set(_LARGEFILE_SOURCE ${_LARGEFILE_SOURCE} CACHE INTERNAL "Result of test for needed _LARGEFILE_SOURCE")
endif()
endif()
if(FSEEKO_COMPILE_OK)
set(OPJ_HAVE_FSEEKO ON CACHE INTERNAL "Result of test for fseeko/ftello")
else()
message(STATUS "Checking for fseeko/ftello - not found")
set(OPJ_HAVE_FSEEKO OFF CACHE INTERNAL "Result of test for fseeko/ftello")
endif()
if(FILE64_OK AND FSEEKO_COMPILE_OK)
message(STATUS "Large File support - found")
set(${VARIABLE} ON CACHE INTERNAL "Result of test for large file support")
else()
message(STATUS "Large File support - not found")
set(${VARIABLE} OFF CACHE INTERNAL "Result of test for large file support")
endif()
endif()
endmacro()

View File

@ -1,11 +0,0 @@
#include <stdio.h>
int main()
{
__int64 off=0;
_fseeki64(NULL, off, SEEK_SET);
return 0;
}

View File

@ -1,39 +0,0 @@
{
<Appears with libpng uses with Ubuntu10.04 (hulk)>
Memcheck:Cond
fun:deflate
obj:/lib/libpng12.so.0.42.0
obj:/lib/libpng12.so.0.42.0
obj:/lib/libpng12.so.0.42.0
fun:png_write_row
fun:imagetopng
fun:main
}
{
<Appears with libpng uses with Ubuntu10.04 (hulk)>
Memcheck:Value8
fun:crc32
obj:/lib/libpng12.so.0.42.0
fun:png_write_chunk
obj:/lib/libpng12.so.0.42.0
obj:/lib/libpng12.so.0.42.0
obj:/lib/libpng12.so.0.42.0
obj:/lib/libpng12.so.0.42.0
fun:png_write_row
fun:imagetopng
fun:main
}
{
<Appears with libpng uses with Ubuntu10.04 (hulk)>
Memcheck:Param
write(buf)
fun:__write_nocancel
fun:_IO_file_write@@GLIBC_2.2.5
fun:_IO_do_write@@GLIBC_2.2.5
fun:_IO_file_close_it@@GLIBC_2.2.5
fun:fclose@@GLIBC_2.2.5
fun:imagetopng
fun:main
}

51
codec/CMakeLists.txt Normal file
View File

@ -0,0 +1,51 @@
# Build the demo app, small examples
# First thing define the common source:
SET(common_SRCS
convert.c
)
# Then check if getopt is present:
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
SET(DONT_HAVE_GETOPT 1)
IF(UNIX) #I am pretty sure only *nix sys have this anyway
CHECK_INCLUDE_FILE("getopt.h" CMAKE_HAVE_GETOPT_H)
# Seems like we need the contrary:
IF(CMAKE_HAVE_GETOPT_H)
SET(DONT_HAVE_GETOPT 0)
ENDIF(CMAKE_HAVE_GETOPT_H)
ENDIF(UNIX)
# If not getopt was found then add it to the lib:
IF(DONT_HAVE_GETOPT)
ADD_DEFINITIONS(-DDONT_HAVE_GETOPT)
SET(common_SRCS
${common_SRCS}
compat/getopt.c
)
ENDIF(DONT_HAVE_GETOPT)
# Headers file are located here:
INCLUDE_DIRECTORIES(
${OPENJPEG_SOURCE_DIR}/libopenjpeg
)
# Do the proper thing when building static...if only there was configured
# headers or def files instead
IF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(NOT BUILD_SHARED_LIBS)
# Loop over all executables:
FOREACH(exe j2k_to_image image_to_j2k)
ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS})
TARGET_LINK_LIBRARIES(${exe} ${OPJ_PREFIX}openjpeg)
# On unix you need to link to the math library:
IF(UNIX)
TARGET_LINK_LIBRARIES(${exe} -lm)
ENDIF(UNIX)
# Install exe
INSTALL_TARGETS(/bin/ ${exe})
ENDFOREACH(exe)

25
src/bin/jp3d/getopt.c → codec/compat/getopt.c Executable file → Normal file
View File

@ -45,7 +45,7 @@ int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */ optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */ optopt, /* character checked for validity */
optreset; /* reset getopt */ optreset; /* reset getopt */
char *optarg; /* argument associated with option */ const char *optarg; /* argument associated with option */
#define BADCH (int)'?' #define BADCH (int)'?'
#define BADARG (int)':' #define BADARG (int)':'
@ -56,10 +56,8 @@ char *optarg; /* argument associated with option */
* Parse argc/argv argument vector. * Parse argc/argv argument vector.
*/ */
int getopt(int nargc, char *const *nargv, const char *ostr) { int getopt(int nargc, char *const *nargv, const char *ostr) {
# define __progname nargv[0]
# define __progname nargv[0] /* program name */ static const char *place = EMSG; /* option letter processing */
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */ char *oli; /* option letter list index */
if (optreset || !*place) { /* update scanning pointer */ if (optreset || !*place) { /* update scanning pointer */
@ -74,18 +72,21 @@ int getopt(int nargc, char *const *nargv, const char *ostr) {
return (-1); return (-1);
} }
} /* option letter okay? */ } /* option letter okay? */
if ((optopt = (int) *place++) == (int) ':' ||
if ((optopt = (int) *place++) == (int) ':' || !(oli = strchr(ostr, optopt))) { !(oli = strchr(ostr, optopt))) {
/* if the user didn't specify '-' as an option, assume it means -1. */ /*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (optopt == (int) '-') if (optopt == (int) '-')
return (-1); return (-1);
if (!*place) if (!*place)
++optind; ++optind;
if (opterr && *ostr != ':') if (opterr && *ostr != ':')
(void) fprintf(stdout,"[ERROR] %s: illegal option -- %c\n", __progname, optopt); (void) fprintf(stderr,
"%s: illegal option -- %c\n", __progname, optopt);
return (BADCH); return (BADCH);
} }
if (*++oli != ':') { /* don't need argument */ if (*++oli != ':') { /* don't need argument */
optarg = NULL; optarg = NULL;
if (!*place) if (!*place)
@ -98,7 +99,9 @@ int getopt(int nargc, char *const *nargv, const char *ostr) {
if (*ostr == ':') if (*ostr == ':')
return (BADARG); return (BADARG);
if (opterr) if (opterr)
(void) fprintf(stdout, "[ERROR] %s: option requires an argument -- %c\n", __progname, optopt); (void) fprintf(stderr,
"%s: option requires an argument -- %c\n",
__progname, optopt);
return (BADCH); return (BADCH);
} else /* white space */ } else /* white space */
optarg = nargv[optind]; optarg = nargv[optind];

0
src/bin/jp3d/getopt.h → codec/compat/getopt.h Executable file → Normal file
View File

1065
codec/convert.c Normal file

File diff suppressed because it is too large Load Diff

25
src/bin/jp3d/convert.h → codec/convert.h Executable file → Normal file
View File

@ -2,9 +2,8 @@
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, HervŽ Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * 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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -28,24 +27,26 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef __JP3D_CONVERT_H #ifndef __J2K_CONVERT_H
#define __JP3D_CONVERT_H #define __J2K_CONVERT_H
opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters);
int imagetobmp(opj_image_t *image, const char *outfile);
/** /**
Load a single volume component encoded in PGX file format Load a single image component encoded in PGX file format
@param filename Name of the PGX file to load @param filename Name of the PGX file to load
@param parameters *List ?* @param parameters *List ?*
@return Returns a greyscale volume if successful, returns NULL otherwise @return Returns a greyscale image if successful, returns NULL otherwise
*/ */
opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters); opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters);
int volumetopgx(opj_volume_t *volume, char *outfile); int imagetopgx(opj_image_t *image, const char *outfile);
opj_volume_t* bintovolume(char *filename,char *fileimg, opj_cparameters_t *parameters); opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters);
int volumetobin(opj_volume_t *volume, char *outfile); int imagetopnm(opj_image_t *image, const char *outfile);
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters);
#endif /* __J2K_CONVERT_H */ #endif /* __J2K_CONVERT_H */

803
codec/image_to_j2k.c Normal file
View File

@ -0,0 +1,803 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, 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 <string.h>
#include <stdlib.h>
#include "openjpeg.h"
#include "compat/getopt.h"
#include "convert.h"
#ifndef WIN32
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif
/* ----------------------------------------------------------------------- */
#define J2K_CFMT 0
#define JP2_CFMT 1
#define JPT_CFMT 2
#define MJ2_CFMT 3
#define PXM_DFMT 0
#define PGX_DFMT 1
#define BMP_DFMT 2
#define YUV_DFMT 3
/* ----------------------------------------------------------------------- */
void encode_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,"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,"- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n");
fprintf(stdout,"color image. You need enough disk space memory (twice the original) to encode \n");
fprintf(stdout,"the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\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,"\n");
fprintf(stdout,"-i : source file (-i source.pnm also *.pgm, *.ppm) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-o : destination file (-o dest.j2k or .jp2) \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,"-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,"\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,"-n : number of resolutions (-n 3) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-b : size of code block (-b 32,32) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-c : size of precinct (-c 128,128) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-t : size of tile (-t 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) [-s X,Y] \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 : 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," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\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 image (-d 150,300) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-T : offset of the origin of the tiles (-T 100,75) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-I : use the irreversible DWT 9-7 (-I) \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");
}
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;
}
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "bmp", "j2k", "jp2"
};
static const int format[] = {
PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, J2K_CFMT, JP2_CFMT
};
char * ext = strrchr(filename, '.') + 1;
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, j;
/* parse the command line */
while (1) {
int c = getopt(argc, argv, "i:o:r:q:f:t:n:c:b:x:p:s:d:hP:S:E:M:R:T:C:I");
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
char *infile = optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case PGX_DFMT:
case PXM_DFMT:
case BMP_DFMT:
break;
default:
fprintf(stderr,
"!! Unrecognized format for infile : %s "
"[accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n",
infile);
return 1;
}
strncpy(parameters->infile, infile, MAX_PATH);
}
break;
/* ----------------------------------------------------- */
case 'o': /* output file */
{
char *outfile = optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case J2K_CFMT:
case JP2_CFMT:
break;
default:
fprintf(stderr, "Unknown output format image %s [only *.j2k, *.jp2]!! \n", outfile);
return 1;
}
strncpy(parameters->outfile, outfile, MAX_PATH);
}
break;
/* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */
{
char *s = 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': /* add fixed_quality */
{
char *s = 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;
/* dda */
/* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
char *s = optarg;
sscanf(s, "%d", &numlayers);
s++;
if (numlayers > 9)
s++;
parameters->tcp_numlayers = numlayers;
numresolution = parameters->numresolution;
matrix_width = numresolution * 3;
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 < 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++;
}
parameters->cp_fixed_alloc = 1;
}
break;
/* ----------------------------------------------------- */
case 't': /* tiles */
{
sscanf(optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = true;
}
break;
/* ----------------------------------------------------- */
case 'n': /* resolution */
{
sscanf(optarg, "%d", &parameters->numresolution);
}
break;
/* ----------------------------------------------------- */
case 'c': /* precinct dimension */
{
char sep;
int res_spec = 0;
char *s = optarg;
do {
sep = 0;
sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
&parameters->prch_init[res_spec], &sep);
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
}
while (sep == ',');
parameters->res_spec = res_spec;
}
break;
/* ----------------------------------------------------- */
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0;
sscanf(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;
}
parameters->cblockw_init = cblockw_init;
parameters->cblockh_init = cblockh_init;
}
break;
/* ----------------------------------------------------- */
case 'x': /* creation of index file */
{
char *index = optarg;
strncpy(parameters->index, index, MAX_PATH);
parameters->index_on = 1;
}
break;
/* ----------------------------------------------------- */
case 'p': /* progression order */
{
char progression[4];
strncpy(progression, optarg, 4);
parameters->prog_order = give_progression(progression);
if (parameters->prog_order == -1) {
fprintf(stderr, "Unrecognized progression order "
"[LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
{
if (sscanf(optarg, "%d,%d", &parameters->subsampling_dx,
&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(optarg, "%d,%d", &parameters->image_offset_x0,
&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 */
encode_help_display();
return 1;
/* ----------------------------------------------------- */
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 = optarg;
POC = parameters->POC;
fprintf(stderr, "/----------------------------------\\\n");
fprintf(stderr, "| POC option not fully tested !! |\n");
fprintf(stderr, "\\----------------------------------/\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': /* Mode switch pas tous au point !! */
{
int value = 0;
if (sscanf(optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
int cache = value & (1 << i);
if (cache)
parameters->mode |= (1 << i);
}
}
}
break;
/* ------------------------------------------------------ */
case 'R': /* ROI */
{
if (sscanf(optarg, "OI:c=%d,U=%d", &parameters->roi_compno,
&parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
return 1;
}
}
break;
/* ------------------------------------------------------ */
case 'T': /* Tile offset */
{
if (sscanf(optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
}
}
break;
/* ------------------------------------------------------ */
case 'C': /* add a comment */
{
parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);
if(parameters->cp_comment) {
strcpy(parameters->cp_comment, optarg);
}
}
break;
/* ------------------------------------------------------ */
case 'I': /* reversible or not */
{
parameters->irreversible = 1;
}
break;
/* ------------------------------------------------------ */
default:
fprintf(stderr, "ERROR -> this option is not valid \"-%c %s\"\n", c, optarg);
return 1;
}
}
/* check for possible errors */
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "usage: image_to_j2k -i image-file -o j2k/jp2-file (+ options)\n");
return 1;
}
if ((parameters->cp_disto_alloc || parameters->cp_fixed_alloc || parameters->cp_fixed_quality)
&& (!(parameters->cp_disto_alloc ^ parameters->cp_fixed_alloc ^ 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 (parameters->tcp_numlayers == 0) {
parameters->tcp_rates[0] = 0; /* MOD antonin : losslessbug */
parameters->tcp_numlayers++;
parameters->cp_disto_alloc = 1;
}
if((parameters->cp_tx0 > parameters->image_offset_x0) || (parameters->cp_ty0 > parameters->image_offset_y0)) {
fprintf(stderr,
"Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
parameters->cp_tx0, parameters->image_offset_x0, parameters->cp_ty0, parameters->image_offset_y0);
return 1;
}
for (i = 0; i < parameters->numpocs; i++) {
if (parameters->POC[i].prg == -1) {
fprintf(stderr,
"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;
opj_cparameters_t parameters; /* compression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *image = 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) {
const char comment[] = "Created by OpenJPEG version ";
const size_t clen = strlen(comment);
const char *version = opj_version();
parameters.cp_comment = (char*)malloc(clen+strlen(version)+1);
strncpy(parameters.cp_comment, comment, clen); /* clen bytes */
strcpy(parameters.cp_comment+clen, version); /* strlen(version) + \0 */
}
/* decode the source image */
/* ----------------------- */
switch (parameters.decod_format) {
case PGX_DFMT:
image = pgxtoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, " unable to load pgx file\n");
return 1;
}
break;
case PXM_DFMT:
image = pnmtoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, " not a pnm file\n");
return 1;
}
break;
case BMP_DFMT:
image = bmptoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, " not a bmp file\n");
return 1;
}
break;
}
/* encode the destination image */
/* ---------------------------- */
if (parameters.cod_format == J2K_CFMT) { /* J2K format output */
int codestream_length;
opj_cio_t *cio = NULL;
FILE *f = NULL;
/* get a J2K compressor handle */
opj_cinfo_t* 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, stderr);
/* setup the encoder parameters using the current image and user parameters */
opj_setup_encoder(cinfo, &parameters, image);
/* open a byte stream for writing */
/* allocate memory for all tiles */
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
bSuccess = opj_encode(cinfo, cio, image, parameters.index);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
return 1;
}
codestream_length = cio_tell(cio);
/* write the buffer to disk */
f = fopen(parameters.outfile, "wb");
if (!f) {
fprintf(stderr, "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 { /* JP2 format output */
int codestream_length;
opj_cio_t *cio = NULL;
FILE *f = NULL;
/* get a JP2 compressor handle */
opj_cinfo_t* cinfo = opj_create_compress(CODEC_JP2);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the encoder parameters using the current image and using user parameters */
opj_setup_encoder(cinfo, &parameters, image);
/* open a byte stream for writing */
/* allocate memory for all tiles */
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
bSuccess = opj_encode(cinfo, cio, image, parameters.index);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
return 1;
}
codestream_length = cio_tell(cio);
/* write the buffer to disk */
f = fopen(parameters.outfile, "wb");
if (!f) {
fprintf(stderr, "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);
}
/* free user parameters structure */
if(parameters.cp_comment) free(parameters.cp_comment);
if(parameters.cp_matrice) free(parameters.cp_matrice);
/* free image data */
opj_image_destroy(image);
return 0;
}

107
codec/image_to_j2k.dsp Normal file
View File

@ -0,0 +1,107 @@
# Microsoft Developer Studio Project File - Name="image_to_j2k" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=image_to_j2k - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "image_to_j2k.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "image_to_j2k.mak" CFG="image_to_j2k - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "image_to_j2k - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "image_to_j2k - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "image_to_j2k - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x40c /d "NDEBUG"
# ADD RSC /l 0x40c /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "image_to_j2k - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x40c /d "_DEBUG"
# ADD RSC /l 0x40c /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "image_to_j2k - Win32 Release"
# Name "image_to_j2k - Win32 Debug"
# Begin Source File
SOURCE=.\convert.c
# End Source File
# Begin Source File
SOURCE=.\convert.h
# End Source File
# Begin Source File
SOURCE=.\compat\getopt.c
# End Source File
# Begin Source File
SOURCE=.\compat\getopt.h
# End Source File
# Begin Source File
SOURCE=.\image_to_j2k.c
# End Source File
# End Target
# End Project

44
codec/image_to_j2k.dsw Normal file
View File

@ -0,0 +1,44 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "LibOpenJPEG"=..\LibOpenJPEG.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "image_to_j2k"=.\image_to_j2k.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name LibOpenJPEG
End Project Dependency
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

391
codec/j2k_to_image.c Normal file
View File

@ -0,0 +1,391 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, 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 <string.h>
#include <stdlib.h>
#include "openjpeg.h"
#include "compat/getopt.h"
#include "convert.h"
#ifndef WIN32
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif
/* ----------------------------------------------------------------------- */
#define J2K_CFMT 0
#define JP2_CFMT 1
#define JPT_CFMT 2
#define MJ2_CFMT 3
#define PXM_DFMT 0
#define PGX_DFMT 1
#define BMP_DFMT 2
#define YUV_DFMT 3
/* ----------------------------------------------------------------------- */
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," -i <compressed file>\n");
fprintf(stdout," REQUIRED\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-files, PPM-files, PNM-files, PGX-files and\n");
fprintf(stdout," BMP-files. 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,"\n");
}
/* -------------------------------------------------------------------------- */
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "j2k", "jp2", "jpt" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT };
char * ext = strrchr(filename, '.') + 1;
if(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_decoder(int argc, char **argv, opj_dparameters_t *parameters) {
/* parse the command line */
while (1) {
int c = getopt(argc, argv, "i:o:r:l:h");
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
char *infile = 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, MAX_PATH);
}
break;
/* ----------------------------------------------------- */
case 'o': /* output file */
{
char *outfile = optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case PGX_DFMT:
case PXM_DFMT:
case BMP_DFMT:
break;
default:
fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp]!! \n", outfile);
return 1;
}
strncpy(parameters->outfile, outfile, MAX_PATH);
}
break;
/* ----------------------------------------------------- */
case 'r': /* reduce option */
{
sscanf(optarg, "%d", &parameters->cp_reduce);
}
break;
/* ----------------------------------------------------- */
case 'l': /* layering option */
{
sscanf(optarg, "%d", &parameters->cp_layer);
}
break;
/* ----------------------------------------------------- */
case 'h': /* display an help description */
decode_help_display();
return 1;
/* ----------------------------------------------------- */
default:
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);
break;
}
}
/* check for possible errors */
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr,"ERROR -> At least one required argument is missing\nCheck j2k_to_image -h 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) {
(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_image_t *image = NULL;
FILE *fsrc = NULL;
unsigned char *src = NULL;
int file_length;
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 */
if(parse_cmdline_decoder(argc, argv, &parameters) == 1) {
return 0;
}
/* 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);
fread(src, 1, file_length, fsrc);
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 */
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);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
}
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 */
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);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
}
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 */
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);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
}
break;
default:
fprintf(stderr, "ERROR -> j2k_to_image : Unknown input image format\n");
return 1;
}
/* free the memory containing the code-stream */
free(src);
src = NULL;
/* create output image */
/* ------------------- */
switch (parameters.cod_format) {
case PXM_DFMT: /* PNM PGM PPM */
imagetopnm(image, parameters.outfile);
break;
case PGX_DFMT: /* PGX */
imagetopgx(image, parameters.outfile);
break;
case BMP_DFMT: /* BMP */
imagetobmp(image, parameters.outfile);
break;
}
/* free remaining structures */
if(dinfo) {
opj_destroy_decompress(dinfo);
}
/* free image data structure */
opj_image_destroy(image);
return 0;
}

106
codec/j2k_to_image.dsp Normal file
View File

@ -0,0 +1,106 @@
# Microsoft Developer Studio Project File - Name="j2k_to_image" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=j2k_to_image - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "j2k_to_image.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "j2k_to_image.mak" CFG="j2k_to_image - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "j2k_to_image - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "j2k_to_image - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "j2k_to_image - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x40c /d "NDEBUG"
# ADD RSC /l 0x40c /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "j2k_to_image - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /YX /FD /GZ /c
# ADD BASE RSC /l 0x40c /d "_DEBUG"
# ADD RSC /l 0x40c /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "j2k_to_image - Win32 Release"
# Name "j2k_to_image - Win32 Debug"
# Begin Source File
SOURCE=.\convert.c
# End Source File
# Begin Source File
SOURCE=.\convert.h
# End Source File
# Begin Source File
SOURCE=.\compat\getopt.c
# End Source File
# Begin Source File
SOURCE=.\compat\getopt.h
# End Source File
# Begin Source File
SOURCE=.\j2k_to_image.c
# End Source File
# End Target
# End Project

44
codec/j2k_to_image.dsw Normal file
View File

@ -0,0 +1,44 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "LibOpenJPEG"=..\LibOpenJPEG.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "j2k_to_image"=.\j2k_to_image.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name LibOpenJPEG
End Project Dependency
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@ -1,52 +0,0 @@
# Generate target to build the html documentation through CMake tool
# After having configured the project with the BUILD_DOC option you can run make doc
# to generate the html documentation in the doc/html repository of the build folder.
# Try to find the doxygen tool
find_package(Doxygen)
if(DOXYGEN_FOUND)
# Configure the doxygen config file with variable from CMake and move it
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.dox.cmake.in
${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox @ONLY)
# Configure the html mainpage file of the doxygen documentation with variable
# from CMake and move it
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mainpage.dox.in
${CMAKE_BINARY_DIR}/doc/mainpage.dox @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpip.dox.in
${CMAKE_BINARY_DIR}/doc/openjpip.dox @ONLY)
# copy png file to make local (binary tree) documentation valid:
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jpip_architect.png
${CMAKE_BINARY_DIR}/doc/html/jpip_architect.png COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jpip_protocol.png
${CMAKE_BINARY_DIR}/doc/html/jpip_protocol.png COPYONLY)
file(GLOB headers
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2/*.h
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2/*.c
${OPENJPEG_SOURCE_DIR}/src/lib/openjpip/*.h
${OPENJPEG_SOURCE_DIR}/src/lib/openjpip/*.c
)
# Generate new target to build the html documentation
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox
DEPENDS ${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox
${CMAKE_BINARY_DIR}/doc/mainpage.dox
${CMAKE_BINARY_DIR}/doc/openjpip.dox
${headers}
)
add_custom_target(doc ALL
DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html
COMMENT "Building doxygen documentation"
)
# install HTML documentation (install png files too):
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/html
DESTINATION share/doc
PATTERN ".svn" EXCLUDE
)
else()
message(STATUS "Doxygen not found, we cannot generate the documentation")
endif()

View File

@ -1,285 +0,0 @@
# Doxyfile 1.7.1
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = OpenJPEG
PROJECT_NUMBER = @OPENJPEG_VERSION@
OUTPUT_DIRECTORY = @OPENJPEG_BINARY_DIR@/doc
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF = "The $name class" \
"The $name widget" \
"The $name file" \
is \
provides \
specifies \
contains \
represents \
a \
an \
the
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH = C://
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = YES
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
EXTENSION_MAPPING =
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
TYPEDEF_HIDES_STRUCT = NO
SYMBOL_CACHE_SIZE = 0
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = NO
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
FORCE_LOCAL_INCLUDES = NO
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_MEMBERS_CTORS_1ST = NO
SORT_GROUP_NAMES = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
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 =
LAYOUT_FILE =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = @OPENJPEG_SOURCE_DIR@/src/lib/openjp2 \
@OPENJPEG_SOURCE_DIR@/src/lib/openjpip \
@OPENJPEG_BINARY_DIR@/doc
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.h \
*.c \
*.dox
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = */.svn/*
EXCLUDE_SYMBOLS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS = *
EXAMPLE_RECURSIVE = NO
IMAGE_PATH = @OPENJPEG_SOURCE_DIR@/doc
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = ./html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
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"
DOCSET_BUNDLE_ID = org.doxygen.Project
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
DOCSET_PUBLISHER_NAME = Publisher
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
CHM_INDEX_ENCODING =
BINARY_TOC = NO
TOC_EXPAND = NO
GENERATE_QHP = NO
QCH_FILE =
QHP_NAMESPACE = org.doxygen.Project
QHP_VIRTUAL_FOLDER = doc
QHP_CUST_FILTER_NAME =
QHP_CUST_FILTER_ATTRS =
QHP_SECT_FILTER_ATTRS =
QHG_LOCATION =
GENERATE_ECLIPSEHELP = NO
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
FORMULA_TRANSPARENT = YES
SEARCHENGINE = NO
SERVER_BASED_SEARCH = NO
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
LATEX_SOURCE_CODE = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = USE_JPWL \
USE_JPSEC
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
DOT_NUM_THREADS = 0
DOT_FONTNAME = Helvetica
DOT_FONTSIZE = 10
DOT_FONTPATH =
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 1000
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

View File

@ -1,62 +0,0 @@
/*
* $Id$
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
* 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.
*/
/*! \mainpage OpenJPEG v@OPENJPEG_VERSION@ Documentation
*
* \section intro Introduction
* This manual documents the low-level OpenJPEG C API.\n
* The OpenJPEG library is an open-source JPEG 2000 library developed in order to promote the use of JPEG 2000.\n
* This documents is focused on the main part of the library which try to implement Part 1 and Part 2 of the JPEG2000 norm.\n
*
* \section home Home page
*
* The Home Page of the OpenJPEG project can be found at:
*
* http://www.openjpeg.org/
*
* The source code repository is available here:
*
* http://github.com/uclouvain/openjpeg
*
* The OpenJPEG mailing list is located here:
*
* http://groups.google.com/group/openjpeg
*
* The test files repository is available here:
*
* http://github.com/uclouvain/openjpeg-data
*
* \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.
*
* \author OpenJPEG Team
*
*/

View File

@ -1,222 +0,0 @@
'\" t
'\" The line above instructs most `man' programs to invoke tbl
'\"
'\" Separate paragraphs; not the same as PP which resets indent level.
.de SP
.if t .sp .5
.if n .sp
..
'\"
'\" Replacement em-dash for nroff (default is too short).
.ie n .ds m " -
.el .ds m \(em
'\"
'\" Placeholder macro for if longer nroff arrow is needed.
.ds RA \(->
'\"
'\" Decimal point set slightly raised
.if t .ds d \v'-.15m'.\v'+.15m'
.if n .ds d .
'\"
'\" Enclosure macro for examples
.de EX
.SP
.nf
.ft CW
..
.de EE
.ft R
.SP
.fi
..
.TH opj_compress 1 "Version 2.1.1" "opj_compress" "converts to jpeg2000 files"
.P
.SH NAME
opj_compress \-
This program reads in an image of a certain type and converts it to a
jpeg2000 file. It is part of the OpenJPEG library.
.SP
Valid input image extensions are
.B .bmp, .pgm, .pgx, .png, .pnm, .ppm, .raw, .tga, .tif \fR. For PNG resp. TIF it needs libpng resp. libtiff .
.SP
Valid output image extensions are
.B .j2k, .jp2
.SH SYNOPSIS
.P
.B opj_compress \-i \fRinfile.bmp \fB-o \fRoutfile.j2k
.P
.B opj_compress \-ImgDir \fRdirectory_name \fB-OutFor \fRjp2
.P
.B opj_compress \-h \fRPrint a help message and exit.
.P
.R See JPWL OPTIONS for special options
.SH OPTIONS
.TP
.B \-\^b " n,n"
(Size of code block (e.g. \-b 32,32). Default: 64 x 64)
.TP
.B \-\^c " n"
(Size of precinct (e.g. \-c 128,128). Default: 2^15 x 2^15)
.TP
.B \-\^cinema2K " fps"
Digital Cinema 2K profile compliant codestream. Valid \fBfps\fR values are 24 or 48.
.TP
.B \-\^cinema4K
Digital Cinema 4K profile compliant codestream. Does not need an fps: default is 24 fps.
.TP
.B \-\^d " X,Y"
(Offset of image origin (e.g. \-d 150,300))
.TP
.B \-\^h
Print a help message and exit.
.TP
.B \-\^i " name"
(input file name)
.TP
.B \-\^n " n"
(Number of resolutions. Default: 6)
.TP
.B \-\^o " name"
(output file name)
.TP
.B \-\^p " name"
Progression order. \fBname\fR can be one out of:LRCP, RLCP, RPCL, PCRL, CPRL. Default: LRCP.
.TP
.B \-\^q " n"
different psnr for successive layers
.br
.B Note: \fR(options \-r and \-q cannot be used together)
.TP
.B \-\^r " n"
different compression ratio(s) for successive layers. The rate specified for each quality level is the desired compression factor.
.br
.B Note: \fR(options \-r and \-q cannot be used together)
.TP
.B \-\^s " X,Y"
sub-sampling factor (e.g. \-s 2,2). Default: No sub-sampling in x or y direction.
.br
.B Remark: \fRsub-sampling bigger than 2 can produce errors.
.TP
.B \-\^t " W,H"
(Size of tile (e.g. \-t 512,512) )
.TP
.B \-\^x " name"
(Create index file and fill it. Default: no index file)
.TP
.B \-\^EPH
(Write EPH marker after each header packet. Default:no EPH)
.TP
.B \-\^F " rawWidth,rawHeight,rawComp,rawBitDepth,s_or_u"
characteristics of the raw input image
.TP
.B \-\^I
(Use the irreversible DWT 9-7. Default: Reversible DWT 5-3)
.TP
.B \-\^ImgDir " directory_name"
(directory containing input files)
.TP
.B \-\^M " n"
mode switch with values: 1, 2, 4, 8, 16, 32. Default:No mode switch activated.
.br
\fIMeaning:\fR
.br
BYPASS(1)
.br
RESET(2)
.br
RESTART(4)
.br
VSC(8)
.br
ERTERM(16)
.br
SEGMARK(32)
.br
Values can be added: RESTART(4) + RESET(2) + SEGMARK(32) = \-M 38
.TP
.B \-\^OutFor "ext"
(extension for output files)
.TP
.B \-\^POC "TtileNr=resolutionStart, componentStart, layerEnd, resolutionEnd, componentEnd, progressionOrder"
(see Examples)
.TP
.B \-\^ROI "c=n,U=n"
quantization indices upshifted for component c (0 or 1 or 2) with a value of U (>= 0 and <= 37)
.br
e.g. \fB-ROI c=0,U=25\fR
.TP
.B \-\^SOP
(Write SOP marker before each packet. Default: No SOP marker in the codestream.)
.TP
.B \-\^T "X,Y"
(Offset of the origin of the tiles (e.g. \-T 100,75) )
.TP
.B \-\^W
(see JPWL OPTIONS)
.P
.SH JPWL OPTIONS
Options usable only if the library has been compiled with \fB-DUSE_JPWL\fR
.P
.B \-W h<tilepart><=type>, s<tilepart><=method>, a=<addr>, z=<size>, g=<range>, p<tilepart:pack><=type>
.P
.B h\fR selects the header error protection (EPB): \fBtype\fR can be
[0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]
if \fBtilepart\fR is absent, it is for main and tile headers
if \fBtilepart\fR is present, it applies from that tile
onwards, up to the next h<> spec, or to the last tilepart
in the codestream (max. 16 specs)
.P
.B p \fRselects the packet error protection (EEP/UEP with EPBs)
to be applied to raw data: \fBtype\fR can be
[0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]
if \fBtilepart:pack\fR is absent, it is from tile 0, packet 0
if \fBtilepart:pack\fR is present, it applies from that tile
and that packet onwards, up to the next packet spec
or to the last packet in the last tilepart in the stream
(max. 16 specs)
.P
.B s \fRenables sensitivity data insertion (ESD): \fBmethod\fR can be
[\-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR
4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]
if \fBtilepart\fR is absent, it is for main header only
if \fBtilepart\fR is present, it applies from that tile
onwards, up to the next s<> spec, or to the last tilepart
in the codestream (max. 16 specs)
.P
.B g \fRdetermines the addressing mode: \fBrange\fR can be
[0=PACKET 1=BYTE RANGE 2=PACKET RANGE]
.P
.B a \fRdetermines the size of data addressing: \fBaddr\fR can be
2/4 bytes (small/large codestreams). If not set, auto-mode
.P
.B z \fRdetermines the size of sensitivity values: \fBsize\fR can be
1/2 bytes, for the transformed pseudo-floating point value
.P
.SH EXAMPLES
.P
.B opj_compress \-i \fRfile.bmp \fB-o \fRfile.j2k \fB-r \fR20,10,1 (compress 20x, then 10x, then lossless).
.P
.B opj_compress \-i \fRfile.ppm \fB-o \fRfile.j2k \fB-q \fR30,40,50
.P
.B opj_compress \-i \fRfile.pgx \fB-o \fRfile.j2k \fB-POC \fRT1=0,0,1,5,3,CPRL
.P
.B opj_compress \-i \fRlena.raw \fB-o \fRlena.j2k \fB-F \fR512,512,3,8,u
.P
.SH AUTHORS
Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
.br
Copyright (c) 2002-2014, Professor Benoit Macq
.br
Copyright (c) 2001-2003, David Janssens
.br
Copyright (c) 2002-2003, Yannick Verschueren
.br
Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
.br
Copyright (c) 2005, Herve Drolon, FreeImage Team
.br
Copyright (c) 2006-2007, Parvatha Elangovan
.P
.SH "SEE ALSO"
opj_decompress(1) opj_dump(1)

View File

@ -1,119 +0,0 @@
'\" t
'\" The line above instructs most `man' programs to invoke tbl
'\"
'\" Separate paragraphs; not the same as PP which resets indent level.
.de SP
.if t .sp .5
.if n .sp
..
'\"
'\" Replacement em-dash for nroff (default is too short).
.ie n .ds m " -
.el .ds m \(em
'\"
'\" Placeholder macro for if longer nroff arrow is needed.
.ds RA \(->
'\"
'\" Decimal point set slightly raised
.if t .ds d \v'-.15m'.\v'+.15m'
.if n .ds d .
'\"
'\" Enclosure macro for examples
.de EX
.SP
.nf
.ft CW
..
.de EE
.ft R
.SP
.fi
..
.TH opj_decompress 1 "Version 2.1.1" "opj_decompress" "converts jpeg2000 files"
.P
.SH NAME
opj_decompress \-
This program reads in a jpeg2000 image and converts it to another
image type. It is part of the OpenJPEG library.
.SP
Valid input image extensions are
.B .j2k, .jp2, .j2c, .jpt
.SP
Valid output image extensions are
.B .bmp, .pgm, .pgx, .png, .pnm, .ppm, .raw, .tga, .tif \fR. For PNG resp. TIF it needs libpng resp. libtiff .
.SH SYNOPSIS
.P
.B opj_decompress \-i \fRinfile.j2k \fB-o \fRoutfile.png
.P
.B opj_decompress \-ImgDir \fRimages/ \fB-OutFor \fRbmp
.P
.B opj_decompress \-h \fRPrint help message and exit
.P
.R See JPWL OPTIONS for special options
.SH OPTIONS
.TP
.B \-\^i "name"
(jpeg2000 input file name)
.TP
.B \-\^l "n"
n is the maximum number of quality layers to decode. See LAYERS below)
.TP
.B \-\^o "name"
(output file name with extension)
.TP
.B \-\^r "n"
(n is the highest resolution level to be discarded. See REDUCTION below)
.TP
.B \-\^x "name"
(use name as index file and fill it)
.TP
.B \-\^ImgDir "directory_name"
(directory containing input files)
.TP
.B \-\^OutFor "ext"
(extension for output files)
.P
.SH JPIP OPTIONS
Options usable only if the library has been compiled with
.B BUILD_JPIP
.TP
.B -jpip
Embed index table box into the output JP2 file (compulsory for JPIP)
.TP
.B -TP R
Partition a tile into tile parts of different resolution levels (compulsory for JPT-stream)
.P
.SH JPWL OPTIONS
Options usable only if the library has been compiled with
.B BUILD_JPWL
.TP
.B -W c\fR[=Nc] (Nc is the number of expected components in the codestream; default:3)
.TP
.B -W t\fR[=Nt] (Nt is the maximum number of tiles in the codestream; default:8192)
.TP
.B -W c\fR[=Nc]\fB, t\fR[=Nt] \fR(same as above)
.P
.SH REDUCTION
Set the number of highest resolution levels to be discarded.
The image resolution is effectively divided by 2 to the power of the number of discarded levels. The reduce factor is limited by the smallest total number of decomposition levels among tiles.
.SH TILES
Set the maximum number of quality layers to decode. If there are less quality layers than the specified number, all the quality layers are decoded.
.P
'\".SH BUGS
.SH AUTHORS
Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
.br
Copyright (c) 2002-2014, Professor Benoit Macq
.br
Copyright (c) 2001-2003, David Janssens
.br
Copyright (c) 2002-2003, Yannick Verschueren
.br
Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
.br
Copyright (c) 2005, Herve Drolon, FreeImage Team
.br
Copyright (c) 2006-2007, Parvatha Elangovan
.P
.SH "SEE ALSO"
opj_compress(1) opj_dump(1)

View File

@ -1,62 +0,0 @@
'\" t
'\" The line above instructs most `man' programs to invoke tbl
'\"
'\" Separate paragraphs; not the same as PP which resets indent level.
.de SP
.if t .sp .5
.if n .sp
..
'\"
'\" Replacement em-dash for nroff (default is too short).
.ie n .ds m " -
.el .ds m \(em
'\"
'\" Placeholder macro for if longer nroff arrow is needed.
.ds RA \(->
'\"
'\" Decimal point set slightly raised
.if t .ds d \v'-.15m'.\v'+.15m'
.if n .ds d .
'\"
'\" Enclosure macro for examples
.de EX
.SP
.nf
.ft CW
..
.de EE
.ft R
.SP
.fi
..
.TH opj_dump 1 "Version 2.1.1" "opj_dump" "dumps jpeg2000 files"
.P
.SH NAME
opj_dump \-
This program reads in a jpeg2000 image and dumps the contents to stdout. It is part of the OpenJPEG library.
.SP
Valid input image extensions are
.B .j2k, .jp2, .jpt
.SP
.SH SYNOPSIS
.P
.B opj_dump \-i \fRinfile.j2k
.P
.B opj_dump \-ImgDir \fRimages/ \fRDump all files in images/
.P
.B opj_dump \-h \fRPrint help message and exit
.P
.SH OPTIONS
.TP
.B \-\^i "name"
(jpeg2000 input file name)
.TP
.B \-\^ImgDir "directory_name"
(directory containing jpeg2000 input files)
.P
'\".SH BUGS
.SH AUTHORS
Copyright (c) 2010, Mathieu Malaterre
.P
.SH "SEE ALSO"
opj_compress(1) opj_decompress(1)

View File

@ -1,337 +0,0 @@
'\" t
'\" The line above instructs most `man' programs to invoke tbl
'\"
'\" Separate paragraphs; not the same as PP which resets indent level.
.de SP
.if t .sp .5
.if n .sp
..
'\"
'\" Replacement em-dash for nroff (default is too short).
.ie n .ds m " -
.el .ds m \(em
'\"
'\" Placeholder macro for if longer nroff arrow is needed.
.ds RA \(->
'\"
'\" Decimal point set slightly raised
.if t .ds d \v'-.15m'.\v'+.15m'
.if n .ds d .
'\"
'\" Enclosure macro for examples
.de EX
.SP
.nf
.ft CW
..
.de EE
.ft R
.SP
.fi
..
.TH libopenjp2 3 "Oct 2010" "Version 1.4.0" "Oct 2010"
.P
.SH NAME
libopenjp2 -
a library for reading and writing JPEG2000 image files.
.SP
.SH SYNOPSIS
.P
.B #include <openjpeg.h>
.P
.SS CONVERSION FORMATS
.B PGX: imagetopgx() \fR/\fB pgxtoimage()
.P
.B PXM: imagetopnm() \fR/\fB pnmtoimage()
.P
.B BMP: imagetobmp() \fR/\fB bmptoimage()
.P
.B TIF: imagetotif() \fR/\fB tiftoimage()
.P
.B RAW: imagetoraw() \fR/\fB rawtoimage()
.P
.B TGA: imagetotga() \fR/\fB tgatoimage()
.P
.B PNG: imagetopng() \fR/\fB pngtoimage()
.P
.B YUV: imagetoyuv() \fR/\fB yuvtoimage() \fR(MJ2)
.P
.SS READ
.B opj_set_default_decoder_parameters(opj_dparameters_t *\fIparams\fB);
.P
.B opj_dinfo_t *opj_create_decompress(OPJ_CODEC_FORMAT \fIformat\fB);
.P
.B opj_event_mgr_t *opj_set_event_mgr(opj_common_ptr \fIinfo\fB, opj_event_mgr_t *\fIevent_mgr\fB, void *\fIcontext\fB);
.P
.B void opj_setup_decoder(opj_dinfo_t *\fIdinfo\fB, opj_dparameters_t * \fIparams\fB);
.P
.B opj_cio_t *opj_cio_open(opj_common_ptr \fIinfo\fB, unsigned char *\fIbuf\fB, int \fIbuf_len\fB);
.P
.B opj_image_t *opj_decode(opj_dinfo_t *\fIdinfo\fB, opj_cio_t *\fIcio\fB);
.P
.B void opj_cio_close(opj_cio_t *\fIcio\fB);
.P
.B void opj_destroy_decompress(opj_dinfo_t *\fIdinfo\fB);
.P
.B void opj_image_destroy(opj_image_t *\fIimage\fB);
.P
.SS WRITE
.B void opj_set_default_encoder_parameters(opj_cparameters_t *\fIparams\fB);
.P
/*
.B opj_image_t *FORMATtoimage(const char *\fIfname\fB, opj_cparameters_t *\fIparams\fB);
.P
*/
.br
.B opj_cinfo_t* opj_create_compress(OPJ_CODEC_FORMAT \fIformat\fB);
.P
.B opj_event_mgr_t *opj_set_event_mgr(opj_common_ptr \fIinfo\fB, opj_event_mgr_t *\fIevent_mgr\fB, void *\fIcontext\fB);
.P
.B void opj_setup_encoder(opj_cinfo_t *\fIcinfo\fB, opj_cparameters_t *\fIparams\fB, opj_image_t *\fIimage\fB);
.P
.B opj_cio_t *opj_cio_open(opj_common_ptr \fIcinfo\fB, \fINULL\fB, \fI0\fB);
.P
.B bool opj_encode(opj_cinfo_t *\fIcinfo\fB, opj_cio_t *\fIcio\fB, opj_image_t *\fIimage\fB, char *\fIindex\fB);
.P
.B void opj_cio_close(opj_cio_t *\fIcio\fB);
.P
.B void opj_destroy_compress(opj_cinfo_t *\fIcinfo\fB);
.P
.B void opj_image_destroy(opj_image_t *\fIimage\fB);
.P
.SS GENERAL
.P
.B void opj_image_create(int \fInumcmpts\fB, opj_image_cmptparm_t *\fIcmptparms\fB, OPJ_COLOR_SPACE \fIclrspc\fB);
.P
.B int cio_tell(opj_cio_t *\fIcio\fB);
.P
.B void cio_seek(opj_cio_t *\fIcio\fB, int \fIpos\fB);
.P
.B opj_image_t *opj_decode_with_info(opj_dinfo_t *\fIdinfo\fB, opj_cio_t *\fIcio\fB, opj_codestream_info_t *\fIcstr_info\fB);
.P
.B bool opj_encode_with_info(opj_cinfo_t *\fIcinfo\fB, opj_cio_t *\fIcio\fB, opj_image_t *\fIimage\fB, opj_codestream_info_t *\fIcstr_info\fB);
.P
.B void opj_destroy_cstr_info(opj_codestream_info_t *\fIcstr_info\fB);
.P
.B const char *opj_version(\fIvoid\fB);
.P
.SH OPJ_CODEC_FORMAT
.P
.B CODEC_J2K\fR or \fBCODEC_JPT\fR or \fBCODEC_JP2
.P
.SH OPJ_COLOR_SPACE
.P
.B CLRSPC_UNKNOWN\fR or \fBCLRSPC_UNSPECIFIED\fR or \fBCLRSPC_SRGB\fR or \fBCLRSPC_GRAY\fR or \fBCLRSPC_SYCC
.P
.SH DECOMPRESSION PARAMETERS
.p
typedef struct opj_dparameters
.br
{
/*
Set the number of highest resolution levels to be discarded.
The image resolution is effectively divided by 2 to the power
of the number of discarded levels.
The reduce factor is limited by the smallest total number of
decomposition levels among tiles.
if != 0, then original dimension divided by 2^(reduce);
if == 0 or not used, image is decoded to the full resolution
*/
\fBint\fR cp_reduce;
/*
Set the maximum number of quality layers to decode.
If there are less quality layers than the specified number,
all the quality layers are decoded.
if != 0, then only the first "layer" layers are decoded;
if == 0 or not used, all the quality layers are decoded
*/
\fBint\fR cp_layer;
/*command line encoder parameters (not used inside the library) */
/* input file name */
\fBchar\fR infile[OPJ_PATH_LEN];
/* output file name */
\fBchar\fR outfile[OPJ_PATH_LEN];
/* input file format: see OPJ_CODEC_FORMAT */
\fBint\fR decod_format;
/* output file format */
\fBint\fR cod_format;
/*JPWL decoding parameters */
/* activates the JPWL correction capabilities */
\fBbool\fR jpwl_correct;
/* expected number of components */
\fBint\fR jpwl_exp_comps;
/* maximum number of tiles */
\fBint\fR jpwl_max_tiles;
/*
Specify whether the decoding should be done on the entire
codestream, or be limited to the main header
Limiting the decoding to the main header makes it possible
to extract the characteristics of the codestream
if == NO_LIMITATION, the entire codestream is decoded;
if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
*/
\fBOPJ_LIMIT_DECODING\fR cp_limit_decoding;
.br
} opj_dparameters_t;
.SH COMPRESSION PARAMETERS
.P
typedef struct opj_cparameters
.br
{
/* size of tile: tile_size_on = false (not in argument)
or tile_size_on = true (in argument) */
\fBbool\fR tile_size_on;
/* XTOsiz */
\fBint\fR cp_tx0;
/* YTOsiz */
\fBint\fR cp_ty0;
/* XTsiz */
\fBint\fR cp_tdx;
/* YTsiz */
\fBint\fR cp_tdy;
/* allocation by rate/distortion */
\fBint\fR cp_disto_alloc;
/* allocation by fixed layer */
\fBint\fR cp_fixed_alloc;
/* add fixed_quality */
\fBint\fR cp_fixed_quality;
/* fixed layer */
\fBint *\fRcp_matrice;
/* comment for coding */
\fBchar *\fRcp_comment;
/* coding style */
\fBint\fR csty;
/* progression order:
PROG_UNKNOWN, LRCP(default), RLCP, RPCL, PCRL, CPRL */
\fBOPJ_PROG_ORDER\fR prog_order;
/* progression order changes */
\fBopj_poc_t\fR POC[32];
/* number of progression order changes (POC), default: 0 */
\fBint\fR numpocs;
/* number of layers */
\fBint\fR tcp_numlayers;
/* rates of layers */
\fBfloat\fR tcp_rates[100];
/* different psnr for successive layers */
\fBfloat\fR tcp_distoratio[100];
/* number of resolutions */
\fBint\fR numresolution;
/* initial code block width, default: 64 */
\fBint\fR cblockw_init;
/* initial code block height, default: 64 */
\fBint\fR cblockh_init;
/* mode switch (cblk_style) */
/* 1 : use the irreversible DWT 9-7,
0 : use lossless compression (default) */
\fBint\fR irreversible;
/* region of interest: affected component in [0..3],
-1 means no ROI */
\fBint\fR roi_compno;
/* region of interest: upshift value */
\fBint\fR roi_shift;
/* number of precinct size specifications */
\fBint\fR res_spec;
/* initial precinct width */
\fBint\fR prcw_init[J2K_MAXRLVLS];
/* initial precinct height */
\fBint\fR prch_init[J2K_MAXRLVLS];
/*command line encoder parameters (not used inside the library) */
/* input file name */
\fBchar\fR infile[OPJ_PATH_LEN];
/* output file name */
\fBchar\fR outfile[OPJ_PATH_LEN];
/* DEPRECATED. Index generation is now handeld with the
opj_encode_with_info() function. Set to NULL */
\fBint\fR index_on;
/* DEPRECATED. Index generation is now handeld with the
opj_encode_with_info() function. Set to NULL */
\fBchar\fR index[OPJ_PATH_LEN];
/* subimage encoding: origin image offset in x direction */
\fBint\fR image_offset_x0;
/* subimage encoding: origin image offset in y direction */
\fBint\fR image_offset_y0;
/* subsampling value for dx */
\fBint\fR subsampling_dx;
/* subsampling value for dy */
\fBint\fR subsampling_dy;
/* input file format */
\fBint\fR decod_format;
/* output file format: see OPJ_CODEC_FORMAT */
\fBint\fR cod_format;
/*JPWL encoding parameters */
/* enables writing of EPC in MH, thus activating JPWL */
\fBbool\fR jpwl_epc_on;
/* error protection method for MH (0,1,16,32,37-128) */
\fBint\fR jpwl_hprot_MH;
/* tile number of header protection specification (>=0) */
\fBint\fR jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/* error protection methods for TPHs (0,1,16,32,37-128) */
\fBint\fR jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
/* tile number of packet protection specification (>=0) */
\fBint\fR jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/* packet number of packet protection specification (>=0) */
\fBint\fR jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
/* error protection methods for packets (0,1,16,32,37-128) */
\fBint\fR jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
/* enables writing of ESD, (0=no/1/2 bytes) */
\fBint\fR jpwl_sens_size;
/* sensitivity addressing size (0=auto/2/4 bytes) */
\fBint\fR jpwl_sens_addr;
/* sensitivity range (0-3) */
\fBint\fR jpwl_sens_range;
/* sensitivity method for MH (-1=no,0-7) */
\fBint\fR jpwl_sens_MH;
/* tile number of sensitivity specification (>=0) */
\fBint\fR jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/* sensitivity methods for TPHs (-1=no,0-7) */
\fBint\fR jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
/* Digital Cinema compliance: OFF-not compliant,
CINEMA2K_24, CINEMA2K_48, CINEMA4K_24 */
\fBOPJ_CINEMA_MODE\fR cp_cinema;
/* Maximum rate for each component.
If == 0, component size limitation is not considered */
\fBint\fR max_comp_size;
/* Profile name*/
\fBOPJ_RSIZ_CAPABILITIES\fR cp_rsiz;
/* Tile part generation*/
\fBchar\fR tp_on;
/* Flag for Tile part generation*/
\fBchar\fR tp_flag;
/* MCT (multiple component transform) */
\fBchar\fR tcp_mct;
.br
} opj_cparameters_t;
'\".SH OPTIONS
'\".SH BUGS
.SH AUTHORS
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 and Antonin Descampe
Copyright (c) 2005, Herve Drolon, FreeImage Team
Copyright (c) 2006-2007, Parvatha Elangovan
.P
.SH "SEE ALSO"
\fBimage_to_j2k\fR(1) \fBj2k_to_image\fR(1) \fBj2k_dump\fR(1)
\fBJPWL_image_to_j2k\fR(1) \fBJPWL_j2k_to_image\fR(1)
\fBextract_j2k_from_mj2\fR(1) \fBwrap_j2k_in_mj2\fR(1)
\fBframes_to_mj2\fR(1) \fBmj2_to_frames\fR(1)

View File

@ -1,94 +0,0 @@
/*
* $Id$
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* 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.
*/
/*! \page openjpippage OpenJPIP v@OPENJPEG_VERSION@ Documentation
*
* \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
*
* This whole documents covers the following six programs.\n
* - opj_server.c JPIP server supporting HTTP connection and JPT/JPP-stream
* - opj_dec_server.c Server to decode JPT/JPP-stream and communicate locally with JPIP client, which is coded in java
* - opj_jpip_addxml.c To Embed metadata into JP2 file
* - 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 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.
*
*
* \section reqlibs Required libraries
* - OpenJPEG library
* - FastCGI development kit (C libraries) at server (http://www.fastcgi.com)
* - libcURL library
*
* We tested this software with a virtual server running on the same Linux machine as the clients.
*
*
* \section compilenotes Compiling Notes
* When you are making opj_server, set anything (e.g. yes) to the parameter jpipserver to define itself in the Makefile, which enables to make it in server mode.\n
* Otherwise do not define (or do not set to) the parameter jpipserver.\n
* Be sure that any object files and library file libopenjpip.a are not reused to compile in the two different mode (server mode and non server mode).\n
* In other words, do make clean before making new targets which are in different modes as previous make.\n
*
*
* \section sysarchtect System Architecture
* JPIP protocol is implemented between the JPIP server program (opj_server) and the JPIP client java program (opj_viewer).\n
* Figure below represents the overview of our system architecture.\n
* The JPIP server parses JPIP query and sends corresponding JPT/JPP-stream.
* The JPIP client viewer is an image viewer with GUI to publish JPIP requests and receive JPT/JPP-stream.\n
* Particularly, our system has the image decoding module implemented on a server (opj_dec_server, Image decoding Server).
* Image decoding Server and JPIP client viewer communicate closely.
* This specific architecture enables sharing cache of image codestream data among all viewers connected to the same Image decoding Server not only locally but also remotely.
*
* \image html jpip_architect.png "OpenJPIP system architecture"
*
* JPIP server follows up the client cache during a session. \n
* Concretely, the JPIP server models cache in each session, to which Channel IDs are associated.
* A Channel ID identifies a JPIP client viewer.
* And, new viewers can belong to a session by referring to one of its channel ID.
* The Image decoding Server maintains the association between channel IDs and targets, and provides a reference channel ID to a Viewer on demand.\n
*
* Typical requests and replies among JPIP server, JPIP client, and Image decoding server is presented below.\n
* The JPIP server parses HTTP query and sends corresponding JPT/JPP-stream back to the JPIP client (Viewer).
* JPT/JPP-stream is unreadable by JPIP client, and it is directly passed to Image decoding Server, and which provides the image in raw format (PGM or PPM) to the JPIP client.
* The Image decoding Server handles the decoding and caching of JPT/JPP-stream.
* JPIP client can read PGM and PPM images natively.
* 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 impementation"
*
* \author Kaori Hagihara UCL/SST/ICTM/ELEN
*/

View File

@ -0,0 +1,40 @@
INCLUDE_REGULAR_EXPRESSION("^.*$")
# Defines the source code for the library
SET(OPENJPEG_SRCS
bio.c
cio.c
dwt.c
event.c
image.c
j2k.c
j2k_lib.c
jp2.c
jpt.c
mct.c
mqc.c
openjpeg.c
pi.c
raw.c
t1.c
t2.c
tcd.c
tgt.c
)
# Pass proper definition to preprocessor to generate shared lib
IF(WIN32)
IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_EXPORTS)
ELSE(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(BUILD_SHARED_LIBS)
ENDIF(WIN32)
# Create the library
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
# Install library
INSTALL_TARGETS(/lib/ ${OPENJPEG_LIBRARY_NAME})
# Install includes files
INSTALL_FILES(/include .h)

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -70,7 +65,6 @@ static int bio_bytein(opj_bio_t *bio);
/*@}*/ /*@}*/
/* /*
========================================================== ==========================================================
local functions local functions
@ -105,9 +99,7 @@ static void bio_putbit(opj_bio_t *bio, int b) {
bio->buf |= b << bio->ct; bio->buf |= b << bio->ct;
} }
/* MOD antonin */
static int bio_getbit(opj_bio_t *bio) { static int bio_getbit(opj_bio_t *bio) {
/* DOM */
if (bio->ct == 0) { if (bio->ct == 0) {
bio_bytein(bio); bio_bytein(bio);
} }

View File

@ -1,16 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -70,7 +63,7 @@ typedef struct opj_bio {
Create a new BIO handle Create a new BIO handle
@return Returns a new BIO handle if successful, returns NULL otherwise @return Returns a new BIO handle if successful, returns NULL otherwise
*/ */
opj_bio_t* bio_create(void); opj_bio_t* bio_create();
/** /**
Destroy a previously created BIO handle Destroy a previously created BIO handle
@param bio BIO handle to destroy @param bio BIO handle to destroy

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -52,18 +47,19 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
/* allocate a buffer for the encoded image */ /* allocate a buffer for the encoded image */
cio->openmode = OPJ_STREAM_WRITE; cio->openmode = OPJ_STREAM_WRITE;
switch(cinfo->codec_format) { switch(cinfo->codec_format) {
case CODEC_J3D:
case CODEC_J2K: case CODEC_J2K:
cp = ((opj_j3d_t*)cinfo->j3d_handle)->cp; cp = ((opj_j2k_t*)cinfo->j2k_handle)->cp;
break;
case CODEC_JP2:
cp = ((opj_jp2_t*)cinfo->jp2_handle)->j2k->cp;
break; break;
default: default:
opj_free(cio); opj_free(cio);
return NULL; return NULL;
} }
cio->length = cp->tdx * cp->tdy * cp->tdz * cp->tw * cp->th * cp->tl * 4; cio->length = cp->tdx * cp->tdy * cp->tw * cp->th * 4;
cio->buffer = (unsigned char *)opj_malloc(cio->length); cio->buffer = (unsigned char *)opj_malloc(cio->length);
if(!cio->buffer) { if(!cio->buffer) {
opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n");
opj_free(cio); opj_free(cio);
return NULL; return NULL;
} }
@ -128,7 +124,7 @@ unsigned char *cio_getbp(opj_cio_t *cio) {
/* /*
* Write a byte. * Write a byte.
*/ */
static bool cio_byteout(opj_cio_t *cio, unsigned char v) { bool cio_byteout(opj_cio_t *cio, unsigned char v) {
if (cio->bp >= cio->end) { if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n"); opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
return false; return false;
@ -140,7 +136,7 @@ static bool cio_byteout(opj_cio_t *cio, unsigned char v) {
/* /*
* Read a byte. * Read a byte.
*/ */
static unsigned char cio_bytein(opj_cio_t *cio) { unsigned char cio_bytein(opj_cio_t *cio) {
if (cio->bp >= cio->end) { if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n"); opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
return 0; return 0;
@ -189,35 +185,5 @@ void cio_skip(opj_cio_t *cio, int n) {
cio->bp += n; cio->bp += n;
} }
/*
* Write some bytes.
*
* v : value to write
* n : number of bytes to write
*/
int cio_write_int(opj_cio_t *cio, int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) )
return 0;
}
return n;
}
/*
* Read some bytes.
*
* n : number of bytes to read
*
* return : value of the n bytes read
*/
int cio_read_int(opj_cio_t *cio, int n) {
int i;
int v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += cio_bytein(cio) << (i << 3);
}
return v;
}

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -45,7 +40,7 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/** @defgroup CIO CIO - byte input-output stream */ /** @defgroup CIO CIO - byte input-output stream */
/*@{*/ /*@{*/
/** @name Funciones generales (see also openjp3d.h) */ /** @name Exported functions (see also openjpeg.h) */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
@ -65,7 +60,7 @@ Write some bytes
@param cio CIO handle @param cio CIO handle
@param v Value to write @param v Value to write
@param n Number of bytes to write @param n Number of bytes to write
@return Returns the number of bytes written or 0 if an error occurred @return Returns the number of bytes written or 0 if an error occured
*/ */
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n); unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n);
/** /**
@ -81,21 +76,6 @@ Skip some bytes
@param n Number of bytes to skip @param n Number of bytes to skip
*/ */
void cio_skip(opj_cio_t *cio, int n); void cio_skip(opj_cio_t *cio, int n);
/**
Write some bytes
@param cio CIO handle
@param v Signed integer value to write
@param n Number of bytes to write
@return Returns the number of bytes written or 0 if an error occurred
*/
int cio_write_int(opj_cio_t *cio, int v, int n);
/**
Read some bytes
@param cio CIO handle
@param n Number of bytes to read
@return Returns the value of the n bytes read
*/
int cio_read_int(opj_cio_t *cio, int n);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@ -1,18 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2007, Jonathan Ballard <dzonatas@dzonux.net>
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -37,55 +28,33 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __SSE__ /*
#include <xmmintrin.h> * NOTE:
#endif * This is a modified version of the openjpeg dwt.c file.
* Average speed improvement compared to the original file (measured on
* my own machine, a P4 running at 3.0 GHz):
* 5x3 wavelets about 2 times faster
* 9x7 wavelets about 3 times faster
* for both, encoding and decoding.
*
* The better performance is caused by doing the 1-dimensional DWT
* within a temporary buffer where the data can be accessed sequential
* for both directions, horizontal and vertical. The 2d vertical DWT was
* the major bottleneck in the former version.
*
* I have also removed the "Add Patrick" part because it is not longer
* needed.
*
* 6/6/2005
* -Ive (aka Reiner Wahler)
* mail: ive@lilysoft.com
*/
#include "opj_includes.h" #include "opj_includes.h"
/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ /** @defgroup DWT DWT - Implementation of a discrete wavelet transform */
/*@{*/ /*@{*/
#define WS(i) v->mem[(i)*2]
#define WD(i) v->mem[(1+(i)*2)]
/** @name Local data structures */
/*@{*/
typedef struct dwt_local {
int* mem;
int dn;
int sn;
int cas;
} dwt_t;
typedef union {
float f[4];
} v4;
typedef struct v4dwt_local {
v4* wavelet ;
int dn ;
int sn ;
int cas ;
} v4dwt_t ;
static const float dwt_alpha = 1.586134342f; /* 12994 */
static const float dwt_beta = 0.052980118f; /* 434 */
static const float dwt_gamma = -0.882911075f; /* -7233 */
static const float dwt_delta = -0.443506852f; /* -3633 */
static const float K = 1.230174105f; /* 10078 */
/* FIXME: What is this constant? */
static const float c13318 = 1.625732422f;
/*@}*/
/**
Virtual function type for wavelet transform in 1-D
*/
typedef void (*DWT1DFN)(dwt_t* v);
/** @name Local static functions */ /** @name Local static functions */
/*@{*/ /*@{*/
@ -100,31 +69,31 @@ static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas);
/** /**
Inverse lazy transform (horizontal) Inverse lazy transform (horizontal)
*/ */
static void dwt_interleave_h(dwt_t* h, int *a); static void dwt_interleave_h(int *a, int *b, int dn, int sn, int cas);
/** /**
Inverse lazy transform (vertical) Inverse lazy transform (vertical)
*/ */
static void dwt_interleave_v(dwt_t* v, int *a, int x); static void dwt_interleave_v(int *a, int *b, int dn, int sn, int x, int cas);
/** /**
Forward 5-3 wavelet transform in 1-D Forward 5-3 wavelet tranform in 1-D
*/ */
static void dwt_encode_1(int *a, int dn, int sn, int cas); static void dwt_encode_1(int *a, int dn, int sn, int cas);
/** /**
Inverse 5-3 wavelet transform in 1-D Inverse 5-3 wavelet tranform in 1-D
*/ */
static void dwt_decode_1(dwt_t *v); static void dwt_decode_1(int *a, int dn, int sn, int cas);
/** /**
Forward 9-7 wavelet transform in 1-D Forward 9-7 wavelet transform in 1-D
*/ */
static void dwt_encode_1_real(int *a, int dn, int sn, int cas); static void dwt_encode_1_real(int *a, int dn, int sn, int cas);
/** /**
Explicit calculation of the Quantization Stepsizes Inverse 9-7 wavelet transform in 1-D
*/
static void dwt_decode_1_real(int *a, int dn, int sn, int cas);
/**
FIXME : comment ???
*/ */
static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize); static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize);
/**
Inverse wavelet transform in 2-D.
*/
static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int i, DWT1DFN fn);
/*@}*/ /*@}*/
@ -185,39 +154,43 @@ static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
/* <summary> */ /* <summary> */
/* Inverse lazy transform (horizontal). */ /* Inverse lazy transform (horizontal). */
/* </summary> */ /* </summary> */
static void dwt_interleave_h(dwt_t* h, int *a) { static void dwt_interleave_h(int *a, int *b, int dn, int sn, int cas) {
int *ai = a; int i;
int *bi = h->mem + h->cas; int *ai = NULL;
int i = h->sn; int *bi = NULL;
while( i-- ) { ai = a;
*bi = *(ai++); bi = b + cas;
for (i = 0; i < sn; i++) {
*bi = *ai;
bi += 2; bi += 2;
ai++;
} }
ai = a + h->sn; ai = a + sn;
bi = h->mem + 1 - h->cas; bi = b + 1 - cas;
i = h->dn ; for (i = 0; i < dn; i++) {
while( i-- ) { *bi = *ai;
*bi = *(ai++);
bi += 2; bi += 2;
ai++;
} }
} }
/* <summary> */ /* <summary> */
/* Inverse lazy transform (vertical). */ /* Inverse lazy transform (vertical). */
/* </summary> */ /* </summary> */
static void dwt_interleave_v(dwt_t* v, int *a, int x) { static void dwt_interleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
int *ai = a; int i;
int *bi = v->mem + v->cas; int *ai = NULL;
int i = v->sn; int *bi = NULL;
while( i-- ) { ai = a;
bi = b + cas;
for (i = 0; i < sn; i++) {
*bi = *ai; *bi = *ai;
bi += 2; bi += 2;
ai += x; ai += x;
} }
ai = a + (v->sn * x); ai = a + (sn * x);
bi = v->mem + 1 - v->cas; bi = b + 1 - cas;
i = v->dn ; for (i = 0; i < dn; i++) {
while( i-- ) {
*bi = *ai; *bi = *ai;
bi += 2; bi += 2;
ai += x; ai += x;
@ -226,7 +199,7 @@ static void dwt_interleave_v(dwt_t* v, int *a, int x) {
/* <summary> */ /* <summary> */
/* Forward 5-3 wavelet transform in 1-D. */ /* Forward 5-3 wavelet tranform in 1-D. */
/* </summary> */ /* </summary> */
static void dwt_encode_1(int *a, int dn, int sn, int cas) { static void dwt_encode_1(int *a, int dn, int sn, int cas) {
int i; int i;
@ -247,9 +220,9 @@ static void dwt_encode_1(int *a, int dn, int sn, int cas) {
} }
/* <summary> */ /* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */ /* Inverse 5-3 wavelet tranform in 1-D. */
/* </summary> */ /* </summary> */
static void dwt_decode_1_(int *a, int dn, int sn, int cas) { static void dwt_decode_1(int *a, int dn, int sn, int cas) {
int i; int i;
if (!cas) { if (!cas) {
@ -267,13 +240,6 @@ static void dwt_decode_1_(int *a, int dn, int sn, int cas) {
} }
} }
/* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */
static void dwt_decode_1(dwt_t *v) {
dwt_decode_1_(v->mem, v->dn, v->sn, v->cas);
}
/* <summary> */ /* <summary> */
/* Forward 9-7 wavelet transform in 1-D. */ /* Forward 9-7 wavelet transform in 1-D. */
/* </summary> */ /* </summary> */
@ -312,6 +278,44 @@ static void dwt_encode_1_real(int *a, int dn, int sn, int cas) {
} }
} }
/* <summary> */
/* Inverse 9-7 wavelet transform in 1-D. */
/* </summary> */
static void dwt_decode_1_real(int *a, int dn, int sn, int cas) {
int i;
if (!cas) {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
for (i = 0; i < sn; i++)
S(i) = fix_mul(S(i), 10078); /* 10076 */
for (i = 0; i < dn; i++)
D(i) = fix_mul(D(i), 13318); /* 13320 */
for (i = 0; i < sn; i++)
S(i) -= fix_mul(D_(i - 1) + D_(i), 3633);
for (i = 0; i < dn; i++)
D(i) -= fix_mul(S_(i) + S_(i + 1), 7233);
for (i = 0; i < sn; i++)
S(i) += fix_mul(D_(i - 1) + D_(i), 434);
for (i = 0; i < dn; i++)
D(i) += fix_mul(S_(i) + S_(i + 1), 12994); /* 12993 */
}
} else {
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
for (i = 0; i < sn; i++)
D(i) = fix_mul(D(i), 10078); /* 10076 */
for (i = 0; i < dn; i++)
S(i) = fix_mul(S(i), 13318); /* 13320 */
for (i = 0; i < sn; i++)
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 3633);
for (i = 0; i < dn; i++)
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 7233);
for (i = 0; i < sn; i++)
D(i) += fix_mul(SS_(i) + SS_(i + 1), 434);
for (i = 0; i < dn; i++)
S(i) += fix_mul(DD_(i) + DD_(i - 1), 12994); /* 12993 */
}
}
}
static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize) { static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize) {
int p, n; int p, n;
p = int_floorlog2(stepsize) - 13; p = int_floorlog2(stepsize) - 13;
@ -327,7 +331,7 @@ static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno
*/ */
/* <summary> */ /* <summary> */
/* Forward 5-3 wavelet transform in 2-D. */ /* Forward 5-3 wavelet tranform in 2-D. */
/* </summary> */ /* </summary> */
void dwt_encode(opj_tcd_tilecomp_t * tilec) { void dwt_encode(opj_tcd_tilecomp_t * tilec) {
int i, j, k; int i, j, k;
@ -342,7 +346,7 @@ void dwt_encode(opj_tcd_tilecomp_t * tilec) {
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
int rw; /* width of the resolution level computed */ int rw; /* width of the resolution level computed */
int rh; /* height of the resolution level computed */ int rh; /* heigth of the resolution level computed */
int rw1; /* width of the resolution level once lower than computed one */ int rw1; /* width of the resolution level once lower than computed one */
int rh1; /* height of the resolution level once lower than computed one */ int rh1; /* height of the resolution level once lower than computed one */
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
@ -383,10 +387,58 @@ void dwt_encode(opj_tcd_tilecomp_t * tilec) {
/* <summary> */ /* <summary> */
/* Inverse 5-3 wavelet transform in 2-D. */ /* Inverse 5-3 wavelet tranform in 2-D. */
/* </summary> */ /* </summary> */
void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres) { void dwt_decode(opj_tcd_tilecomp_t * tilec, int stop) {
dwt_decode_tile(tilec, numres, &dwt_decode_1); int i, j, k;
int *a = NULL;
int *aj = NULL;
int *bj = NULL;
int w, l;
w = tilec->x1-tilec->x0;
l = tilec->numresolutions-1;
a = tilec->data;
for (i = l - 1; i >= stop; i--) {
int rw; /* width of the resolution level computed */
int rh; /* heigth of the resolution level computed */
int rw1; /* width of the resolution level once lower than computed one */
int rh1; /* height of the resolution level once lower than computed one */
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
int dn, sn;
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
cas_row = tilec->resolutions[l - i].x0 % 2;
cas_col = tilec->resolutions[l - i].y0 % 2;
sn = rw1;
dn = rw - rw1;
bj = (int*)opj_malloc(rw * sizeof(int));
for (j = 0; j < rh; j++) {
aj = a + j*w;
dwt_interleave_h(aj, bj, dn, sn, cas_row);
dwt_decode_1(bj, dn, sn, cas_row);
for (k = 0; k < rw; k++) aj[k] = bj[k];
}
opj_free(bj);
sn = rh1;
dn = rh - rh1;
bj = (int*)opj_malloc(rh * sizeof(int));
for (j = 0; j < rw; j++) {
aj = a + j;
dwt_interleave_v(aj, bj, dn, sn, w, cas_col);
dwt_decode_1(bj, dn, sn, cas_col);
for (k = 0; k < rh; k++) aj[k * w] = bj[k];
}
opj_free(bj);
}
} }
@ -425,7 +477,7 @@ void dwt_encode_real(opj_tcd_tilecomp_t * tilec) {
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
int rw; /* width of the resolution level computed */ int rw; /* width of the resolution level computed */
int rh; /* height of the resolution level computed */ int rh; /* heigth of the resolution level computed */
int rw1; /* width of the resolution level once lower than computed one */ int rw1; /* width of the resolution level once lower than computed one */
int rh1; /* height of the resolution level once lower than computed one */ int rh1; /* height of the resolution level once lower than computed one */
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
@ -465,6 +517,62 @@ void dwt_encode_real(opj_tcd_tilecomp_t * tilec) {
} }
/* <summary> */
/* Inverse 9-7 wavelet transform in 2-D. */
/* </summary> */
void dwt_decode_real(opj_tcd_tilecomp_t * tilec, int stop) {
int i, j, k;
int *a = NULL;
int *aj = NULL;
int *bj = NULL;
int w, l;
w = tilec->x1-tilec->x0;
l = tilec->numresolutions-1;
a = tilec->data;
for (i = l-1; i >= stop; i--) {
int rw; /* width of the resolution level computed */
int rh; /* heigth of the resolution level computed */
int rw1; /* width of the resolution level once lower than computed one */
int rh1; /* height of the resolution level once lower than computed one */
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
int dn, sn;
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
cas_col = tilec->resolutions[l - i].x0 % 2; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
cas_row = tilec->resolutions[l - i].y0 % 2; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
sn = rw1;
dn = rw-rw1;
bj = (int*)opj_malloc(rw * sizeof(int));
for (j = 0; j < rh; j++) {
aj = a + j * w;
dwt_interleave_h(aj, bj, dn, sn, cas_col);
dwt_decode_1_real(bj, dn, sn, cas_col);
for (k = 0; k < rw; k++) aj[k] = bj[k];
}
opj_free(bj);
sn = rh1;
dn = rh-rh1;
bj = (int*)opj_malloc(rh * sizeof(int));
for (j = 0; j < rw; j++) {
aj = a + j;
dwt_interleave_v(aj, bj, dn, sn, w, cas_row);
dwt_decode_1_real(bj, dn, sn, cas_row);
for (k = 0; k < rh; k++) aj[k * w] = bj[k];
}
opj_free(bj);
}
}
/* <summary> */ /* <summary> */
/* Get gain of 9-7 wavelet transform. */ /* Get gain of 9-7 wavelet transform. */
/* </summary> */ /* </summary> */
@ -500,365 +608,3 @@ void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) {
dwt_encode_stepsize((int) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]); dwt_encode_stepsize((int) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]);
} }
} }
/* <summary> */
/* Determine maximum computed resolution level for inverse wavelet transform */
/* </summary> */
static int dwt_decode_max_resolution(opj_tcd_resolution_t* restrict r, int i) {
int mr = 1;
int w;
while( --i ) {
r++;
if( mr < ( w = r->x1 - r->x0 ) )
mr = w ;
if( mr < ( w = r->y1 - r->y0 ) )
mr = w ;
}
return mr ;
}
/* <summary> */
/* Inverse wavelet transform in 2-D. */
/* </summary> */
static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1D) {
dwt_t h;
dwt_t v;
opj_tcd_resolution_t* tr = tilec->resolutions;
int rw = tr->x1 - tr->x0; /* width of the resolution level computed */
int rh = tr->y1 - tr->y0; /* height of the resolution level computed */
int w = tilec->x1 - tilec->x0;
h.mem = (int*)opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int));
v.mem = h.mem;
while( --numres) {
int * restrict tiledp = tilec->data;
int j;
++tr;
h.sn = rw;
v.sn = rh;
rw = tr->x1 - tr->x0;
rh = tr->y1 - tr->y0;
h.dn = rw - h.sn;
h.cas = tr->x0 % 2;
for(j = 0; j < rh; ++j) {
dwt_interleave_h(&h, &tiledp[j*w]);
(dwt_1D)(&h);
memcpy(&tiledp[j*w], h.mem, rw * sizeof(int));
}
v.dn = rh - v.sn;
v.cas = tr->y0 % 2;
for(j = 0; j < rw; ++j){
int k;
dwt_interleave_v(&v, &tiledp[j], w);
(dwt_1D)(&v);
for(k = 0; k < rh; ++k) {
tiledp[k * w + j] = v.mem[k];
}
}
}
opj_aligned_free(h.mem);
}
static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, int size){
float* restrict bi = (float*) (w->wavelet + w->cas);
int count = w->sn;
int i, k;
for(k = 0; k < 2; ++k){
if (count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0) {
/* Fast code path */
for(i = 0; i < count; ++i){
int j = i;
bi[i*8 ] = a[j];
j += x;
bi[i*8 + 1] = a[j];
j += x;
bi[i*8 + 2] = a[j];
j += x;
bi[i*8 + 3] = a[j];
}
} else {
/* Slow code path */
for(i = 0; i < count; ++i){
int j = i;
bi[i*8 ] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 1] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 2] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 3] = a[j];
}
}
bi = (float*) (w->wavelet + 1 - w->cas);
a += w->sn;
size -= w->sn;
count = w->dn;
}
}
static void v4dwt_interleave_v(v4dwt_t* restrict v , float* restrict a , int x){
v4* restrict bi = v->wavelet + v->cas;
int i;
for(i = 0; i < v->sn; ++i){
memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float));
}
a += v->sn * x;
bi = v->wavelet + 1 - v->cas;
for(i = 0; i < v->dn; ++i){
memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float));
}
}
#ifdef __SSE__
static void v4dwt_decode_step1_sse(v4* w, int count, const __m128 c){
__m128* restrict vw = (__m128*) w;
int i;
/* 4x unrolled loop */
for(i = 0; i < count >> 2; ++i){
*vw = _mm_mul_ps(*vw, c);
vw += 2;
*vw = _mm_mul_ps(*vw, c);
vw += 2;
*vw = _mm_mul_ps(*vw, c);
vw += 2;
*vw = _mm_mul_ps(*vw, c);
vw += 2;
}
count &= 3;
for(i = 0; i < count; ++i){
*vw = _mm_mul_ps(*vw, c);
vw += 2;
}
}
static void v4dwt_decode_step2_sse(v4* l, v4* w, int k, int m, __m128 c){
__m128* restrict vl = (__m128*) l;
__m128* restrict vw = (__m128*) w;
int i;
__m128 tmp1, tmp2, tmp3;
tmp1 = vl[0];
for(i = 0; i < m; ++i){
tmp2 = vw[-1];
tmp3 = vw[ 0];
vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c));
tmp1 = tmp3;
vw += 2;
}
vl = vw - 2;
if(m >= k){
return;
}
c = _mm_add_ps(c, c);
c = _mm_mul_ps(c, vl[0]);
for(; m < k; ++m){
__m128 tmp = vw[-1];
vw[-1] = _mm_add_ps(tmp, c);
vw += 2;
}
}
#else
static void v4dwt_decode_step1(v4* w, int count, const float c){
float* restrict fw = (float*) w;
int i;
for(i = 0; i < count; ++i){
float tmp1 = fw[i*8 ];
float tmp2 = fw[i*8 + 1];
float tmp3 = fw[i*8 + 2];
float tmp4 = fw[i*8 + 3];
fw[i*8 ] = tmp1 * c;
fw[i*8 + 1] = tmp2 * c;
fw[i*8 + 2] = tmp3 * c;
fw[i*8 + 3] = tmp4 * c;
}
}
static void v4dwt_decode_step2(v4* l, v4* w, int k, int m, float c){
float* restrict fl = (float*) l;
float* restrict fw = (float*) w;
int i;
for(i = 0; i < m; ++i){
float tmp1_1 = fl[0];
float tmp1_2 = fl[1];
float tmp1_3 = fl[2];
float tmp1_4 = fl[3];
float tmp2_1 = fw[-4];
float tmp2_2 = fw[-3];
float tmp2_3 = fw[-2];
float tmp2_4 = fw[-1];
float tmp3_1 = fw[0];
float tmp3_2 = fw[1];
float tmp3_3 = fw[2];
float tmp3_4 = fw[3];
fw[-4] = tmp2_1 + ((tmp1_1 + tmp3_1) * c);
fw[-3] = tmp2_2 + ((tmp1_2 + tmp3_2) * c);
fw[-2] = tmp2_3 + ((tmp1_3 + tmp3_3) * c);
fw[-1] = tmp2_4 + ((tmp1_4 + tmp3_4) * c);
fl = fw;
fw += 8;
}
if(m < k){
float c1;
float c2;
float c3;
float c4;
c += c;
c1 = fl[0] * c;
c2 = fl[1] * c;
c3 = fl[2] * c;
c4 = fl[3] * c;
for(; m < k; ++m){
float tmp1 = fw[-4];
float tmp2 = fw[-3];
float tmp3 = fw[-2];
float tmp4 = fw[-1];
fw[-4] = tmp1 + c1;
fw[-3] = tmp2 + c2;
fw[-2] = tmp3 + c3;
fw[-1] = tmp4 + c4;
fw += 8;
}
}
}
#endif
/* <summary> */
/* Inverse 9-7 wavelet transform in 1-D. */
/* </summary> */
static void v4dwt_decode(v4dwt_t* restrict dwt){
int a, b;
if(dwt->cas == 0) {
if(!((dwt->dn > 0) || (dwt->sn > 1))){
return;
}
a = 0;
b = 1;
}else{
if(!((dwt->sn > 0) || (dwt->dn > 1))) {
return;
}
a = 1;
b = 0;
}
#ifdef __SSE__
v4dwt_decode_step1_sse(dwt->wavelet+a, dwt->sn, _mm_set1_ps(K));
v4dwt_decode_step1_sse(dwt->wavelet+b, dwt->dn, _mm_set1_ps(c13318));
v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_delta));
v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_gamma));
v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_beta));
v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_alpha));
#else
v4dwt_decode_step1(dwt->wavelet+a, dwt->sn, K);
v4dwt_decode_step1(dwt->wavelet+b, dwt->dn, c13318);
v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_delta);
v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_gamma);
v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_beta);
v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_alpha);
#endif
}
/* <summary> */
/* Inverse 9-7 wavelet transform in 2-D. */
/* </summary> */
void dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres){
v4dwt_t h;
v4dwt_t v;
opj_tcd_resolution_t* res = tilec->resolutions;
int rw = res->x1 - res->x0; /* width of the resolution level computed */
int rh = res->y1 - res->y0; /* height of the resolution level computed */
int w = tilec->x1 - tilec->x0;
h.wavelet = (v4*) opj_aligned_malloc((dwt_decode_max_resolution(res, numres)+5) * sizeof(v4));
v.wavelet = h.wavelet;
while( --numres) {
float * restrict aj = (float*) tilec->data;
int bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0);
int j;
h.sn = rw;
v.sn = rh;
++res;
rw = res->x1 - res->x0; /* width of the resolution level computed */
rh = res->y1 - res->y0; /* height of the resolution level computed */
h.dn = rw - h.sn;
h.cas = res->x0 % 2;
for(j = rh; j > 3; j -= 4){
int k;
v4dwt_interleave_h(&h, aj, w, bufsize);
v4dwt_decode(&h);
for(k = rw; --k >= 0;){
aj[k ] = h.wavelet[k].f[0];
aj[k+w ] = h.wavelet[k].f[1];
aj[k+w*2] = h.wavelet[k].f[2];
aj[k+w*3] = h.wavelet[k].f[3];
}
aj += w*4;
bufsize -= w*4;
}
if (rh & 0x03) {
int k;
j = rh & 0x03;
v4dwt_interleave_h(&h, aj, w, bufsize);
v4dwt_decode(&h);
for(k = rw; --k >= 0;){
switch(j) {
case 3: aj[k+w*2] = h.wavelet[k].f[2];
case 2: aj[k+w ] = h.wavelet[k].f[1];
case 1: aj[k ] = h.wavelet[k].f[0];
}
}
}
v.dn = rh - v.sn;
v.cas = res->y0 % 2;
aj = (float*) tilec->data;
for(j = rw; j > 3; j -= 4){
int k;
v4dwt_interleave_v(&v, aj, w);
v4dwt_decode(&v);
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(float));
}
aj += 4;
}
if (rw & 0x03){
int k;
j = rw & 0x03;
v4dwt_interleave_v(&v, aj, w);
v4dwt_decode(&v);
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(float));
}
}
}
opj_aligned_free(h.wavelet);
}

View File

@ -1,16 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -54,18 +47,18 @@ DWT.C are used by some function in TCD.C.
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
Forward 5-3 wavelet transform in 2-D. Forward 5-3 wavelet tranform in 2-D.
Apply a reversible DWT transform to a component of an image. Apply a reversible DWT transform to a component of an image.
@param tilec Tile component information (current tile) @param tilec Tile component information (current tile)
*/ */
void dwt_encode(opj_tcd_tilecomp_t * tilec); void dwt_encode(opj_tcd_tilecomp_t * tilec);
/** /**
Inverse 5-3 wavelet transform in 2-D. Inverse 5-3 wavelet tranform in 2-D.
Apply a reversible inverse DWT transform to a component of an image. Apply a reversible inverse DWT transform to a component of an image.
@param tilec Tile component information (current tile) @param tilec Tile component information (current tile)
@param numres Number of resolution levels to decode @param stop FIXME Number of decoded resolution levels ?
*/ */
void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres); void dwt_decode(opj_tcd_tilecomp_t * tilec, int stop);
/** /**
Get the gain of a subband for the reversible 5-3 DWT. Get the gain of a subband for the reversible 5-3 DWT.
@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH) @param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
@ -89,9 +82,9 @@ void dwt_encode_real(opj_tcd_tilecomp_t * tilec);
Inverse 9-7 wavelet transform in 2-D. Inverse 9-7 wavelet transform in 2-D.
Apply an irreversible inverse DWT transform to a component of an image. Apply an irreversible inverse DWT transform to a component of an image.
@param tilec Tile component information (current tile) @param tilec Tile component information (current tile)
@param numres Number of resolution levels to decode @param stop FIXME Number of decoded resolution levels ?
*/ */
void dwt_decode_real(opj_tcd_tilecomp_t* tilec, int numres); void dwt_decode_real(opj_tcd_tilecomp_t * tilec, int stop);
/** /**
Get the gain of a subband for the irreversible 9-7 DWT. Get the gain of a subband for the irreversible 9-7 DWT.
@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH) @param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
@ -106,9 +99,9 @@ Get the norm of a wavelet function of a subband at a specified level for the irr
*/ */
double dwt_getnorm_real(int level, int orient); double dwt_getnorm_real(int level, int orient);
/** /**
Explicit calculation of the Quantization Stepsizes FIXME : comment ???
@param tccp Tile-component coding parameters @param tccp
@param prec Precint analyzed @param prec
*/ */
void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec); void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */

View File

@ -1,10 +1,5 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -32,10 +27,10 @@
#include "opj_includes.h" #include "opj_includes.h"
/* ========================================================== /* ==========================================================
// Utility functions Utility functions
// ==========================================================*/ ==========================================================*/
#ifndef _WIN32 #if !defined(_MSC_VER) && !defined(__MINGW32__)
static char* static char*
i2a(unsigned i, char *a, unsigned r) { i2a(unsigned i, char *a, unsigned r) {
if (i/r > 0) a = i2a(i/r,a,r); if (i/r > 0) a = i2a(i/r,a,r);
@ -62,7 +57,7 @@ _itoa(int i, char *a, int r) {
return a; return a;
} }
#endif /* !_WIN32 */ #endif /* !WIN32 */
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */

View File

@ -1,10 +1,5 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -44,7 +39,7 @@ The functions in EVENT.C have for goal to send output messages (errors, warnings
/** @defgroup EVENT EVENT - Implementation of a event callback system */ /** @defgroup EVENT EVENT - Implementation of a event callback system */
/*@{*/ /*@{*/
/** @name Funciones generales (see also openjp3d.h) */ /** @name Exported functions (see also openjpeg.h) */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -57,7 +52,7 @@ Multiply two fixed-precision rational numbers.
@param b @param b
@return Returns a * b @return Returns a * b
*/ */
static int fix_mul(int a, int b) { static INLINE int fix_mul(int a, int b) {
int64 temp = (int64) a * (int64) b >> 12; int64 temp = (int64) a * (int64) b >> 12;
return (int) ((temp >> 1) + (temp & 1)) ; return (int) ((temp >> 1) + (temp & 1)) ;
} }

View File

@ -1,10 +1,5 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -31,8 +26,8 @@
#include "opj_includes.h" #include "opj_includes.h"
opj_image_t* opj_image_create0(void) { opj_image_t* opj_image_create0() {
opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t)); opj_image_t *image = (opj_image_t*)opj_malloc(sizeof(opj_image_t));
return image; return image;
} }
@ -40,14 +35,13 @@ opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *c
int compno; int compno;
opj_image_t *image = NULL; opj_image_t *image = NULL;
image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t)); image = (opj_image_t*)opj_malloc(sizeof(opj_image_t));
if(image) { if(image) {
image->color_space = clrspc; image->color_space = clrspc;
image->numcomps = numcmpts; image->numcomps = numcmpts;
/* allocate memory for the per-component information */ /* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t)); image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) { if(!image->comps) {
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image); opj_image_destroy(image);
return NULL; return NULL;
} }
@ -63,9 +57,8 @@ opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *c
comp->prec = cmptparms[compno].prec; comp->prec = cmptparms[compno].prec;
comp->bpp = cmptparms[compno].bpp; comp->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd; comp->sgnd = cmptparms[compno].sgnd;
comp->data = (int*) opj_calloc(comp->w * comp->h, sizeof(int)); comp->data = (int*)opj_malloc(comp->w * comp->h * sizeof(int));
if(!comp->data) { if(!comp->data) {
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image); opj_image_destroy(image);
return NULL; return NULL;
} }

View File

@ -1,10 +1,5 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,7 +40,7 @@ Create an empty image
@todo this function should be removed @todo this function should be removed
@return returns an empty image if successful, returns NULL otherwise @return returns an empty image if successful, returns NULL otherwise
*/ */
opj_image_t* opj_image_create0(void); opj_image_t* opj_image_create0();
/*@}*/ /*@}*/

View File

@ -1,16 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -51,12 +43,12 @@ The functions in J2K.C have for goal to read/write the several parts of the code
#define J2K_CP_CSTY_SOP 0x02 #define J2K_CP_CSTY_SOP 0x02
#define J2K_CP_CSTY_EPH 0x04 #define J2K_CP_CSTY_EPH 0x04
#define J2K_CCP_CSTY_PRT 0x01 #define J2K_CCP_CSTY_PRT 0x01
#define J2K_CCP_CBLKSTY_LAZY 0x01 /**< Selective arithmetic coding bypass */ #define J2K_CCP_CBLKSTY_LAZY 0x01
#define J2K_CCP_CBLKSTY_RESET 0x02 /**< Reset context probabilities on coding pass boundaries */ #define J2K_CCP_CBLKSTY_RESET 0x02
#define J2K_CCP_CBLKSTY_TERMALL 0x04 /**< Termination on each coding pass */ #define J2K_CCP_CBLKSTY_TERMALL 0x04
#define J2K_CCP_CBLKSTY_VSC 0x08 /**< Vertically stripe causal context */ #define J2K_CCP_CBLKSTY_VSC 0x08
#define J2K_CCP_CBLKSTY_PTERM 0x10 /**< Predictable termination */ #define J2K_CCP_CBLKSTY_PTERM 0x10
#define J2K_CCP_CBLKSTY_SEGSYM 0x20 /**< Segmentation symbols are used */ #define J2K_CCP_CBLKSTY_SEGSYM 0x20
#define J2K_CCP_QNTSTY_NOQNT 0 #define J2K_CCP_QNTSTY_NOQNT 0
#define J2K_CCP_QNTSTY_SIQNT 1 #define J2K_CCP_QNTSTY_SIQNT 1
#define J2K_CCP_QNTSTY_SEQNT 2 #define J2K_CCP_QNTSTY_SEQNT 2
@ -83,19 +75,6 @@ The functions in J2K.C have for goal to read/write the several parts of the code
#define J2K_MS_EPH 0xff92 /**< EPH marker value */ #define J2K_MS_EPH 0xff92 /**< EPH marker value */
#define J2K_MS_CRG 0xff63 /**< CRG marker value */ #define J2K_MS_CRG 0xff63 /**< CRG marker value */
#define J2K_MS_COM 0xff64 /**< COM marker value */ #define J2K_MS_COM 0xff64 /**< COM marker value */
/* UniPG>> */
#ifdef USE_JPWL
#define J2K_MS_EPC 0xff68 /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_EPB 0xff66 /**< EPB marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_ESD 0xff67 /**< ESD marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_RED 0xff69 /**< RED marker value (Part 11: JPEG 2000 for Wireless) */
#endif /* USE_JPWL */
#ifdef USE_JPSEC
#define J2K_MS_SEC 0xff65 /**< SEC marker value (Part 8: Secure JPEG 2000) */
#define J2K_MS_INSEC 0xff94 /**< INSEC marker value (Part 8: Secure JPEG 2000) */
#endif /* USE_JPSEC */
/* <<UniPG */
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@ -110,20 +89,11 @@ typedef enum J2K_STATUS {
J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */ J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */
J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */ J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */ J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */
J2K_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */ J2K_STATE_NEOC = 0x0040 /**< the decoding process must not expect a EOC marker because the codestream is truncated */
J2K_STATE_ERR = 0x0080 /**< the decoding process has encountered an error */
} J2K_STATUS; } J2K_STATUS;
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/**
T2 encoding mode
*/
typedef enum T2_MODE {
THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/
}J2K_T2_MODE;
/** /**
Quantization stepsize Quantization stepsize
*/ */
@ -208,20 +178,6 @@ typedef struct opj_tcp {
Coding parameters Coding parameters
*/ */
typedef struct opj_cp { typedef struct opj_cp {
/** Digital cinema profile*/
OPJ_CINEMA_MODE cinema;
/** Maximum rate for each component. If == 0, component size limitation is not considered */
int max_comp_size;
/** Size of the image in bits*/
int img_size;
/** Rsiz*/
OPJ_RSIZ_CAPABILITIES rsiz;
/** Enabling Tile part generation*/
char tp_on;
/** Flag determining tile part generation*/
char tp_flag;
/** Position of tile part flag in progression order*/
int tp_pos;
/** allocation by rate/distortion */ /** allocation by rate/distortion */
int disto_alloc; int disto_alloc;
/** allocation by fixed layer */ /** allocation by fixed layer */
@ -232,8 +188,8 @@ typedef struct opj_cp {
int reduce; int reduce;
/** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
int layer; int layer;
/** if == NO_LIMITATION, decode entire codestream; if == LIMIT_TO_MAIN_HEADER then only decode the main header */ /** 0 = no index || 1 = index */
OPJ_LIMIT_DECODING limit_decoding; int index_on;
/** XTOsiz */ /** XTOsiz */
int tx0; int tx0;
/** YTOsiz */ /** YTOsiz */
@ -268,52 +224,94 @@ typedef struct opj_cp {
opj_tcp_t *tcps; opj_tcp_t *tcps;
/** fixed layer */ /** fixed layer */
int *matrice; int *matrice;
/* UniPG>> */
#ifdef USE_JPWL
/** enables writing of EPC in MH, thus activating JPWL */
opj_bool epc_on;
/** enables writing of EPB, in case of activated JPWL */
opj_bool epb_on;
/** enables writing of ESD, in case of activated JPWL */
opj_bool esd_on;
/** enables writing of informative techniques of ESD, in case of activated JPWL */
opj_bool info_on;
/** enables writing of RED, in case of activated JPWL */
opj_bool red_on;
/** error protection method for MH (0,1,16,32,37-128) */
int hprot_MH;
/** tile number of header protection specification (>=0) */
int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** error protection methods for TPHs (0,1,16,32,37-128) */
int hprot_TPH[JPWL_MAX_NO_TILESPECS];
/** tile number of packet protection specification (>=0) */
int pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/** packet number of packet protection specification (>=0) */
int pprot_packno[JPWL_MAX_NO_PACKSPECS];
/** error protection methods for packets (0,1,16,32,37-128) */
int pprot[JPWL_MAX_NO_PACKSPECS];
/** enables writing of ESD, (0/2/4 bytes) */
int sens_size;
/** sensitivity addressing size (0=auto/2/4 bytes) */
int sens_addr;
/** sensitivity range (0-3) */
int sens_range;
/** sensitivity method for MH (-1,0-7) */
int sens_MH;
/** tile number of sensitivity specification (>=0) */
int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** sensitivity methods for TPHs (-1,0-7) */
int sens_TPH[JPWL_MAX_NO_TILESPECS];
/** enables JPWL correction at the decoder */
opj_bool correct;
/** expected number of components at the decoder */
int exp_comps;
/** maximum number of tiles at the decoder */
int max_tiles;
#endif /* USE_JPWL */
/* <<UniPG */
} opj_cp_t; } opj_cp_t;
/**
Information concerning a packet inside tile
*/
typedef struct opj_packet_info {
/** start position */
int start_pos;
/** end position */
int end_pos;
/** ADD for Marcela */
double disto;
} opj_packet_info_t;
/**
Index structure : information regarding tiles inside image
*/
typedef struct opj_tile_info {
/** value of thresh for each layer by tile cfr. Marcela */
double *thresh;
/** number of tile */
int num_tile;
/** start position */
int start_pos;
/** end position of the header */
int end_header;
/** end position */
int end_pos;
/** precinct number for each resolution level (width) */
int pw[33];
/** precinct number for each resolution level (height) */
int ph[33];
/** precinct size (in power of 2), in X for each resolution level */
int pdx[33];
/** precinct size (in power of 2), in Y for each resolution level */
int pdy[33];
/** information concerning packets inside tile */
opj_packet_info_t *packet;
/** add fixed_quality */
int nbpix;
/** add fixed_quality */
double distotile;
} opj_tile_info_t;
/**
Index structure
*/
typedef struct opj_image_info {
/** 0 = no index || 1 = index */
int index_on;
/** maximum distortion reduction on the whole image (add for Marcela) */
double D_max;
/** packet number */
int num;
/** writing the packet in the index with t2_encode_packets */
int index_write;
/** image width */
int image_w;
/** image height */
int image_h;
/** progression order */
OPJ_PROG_ORDER prog;
/** tile size in x */
int tile_x;
/** tile size in y */
int tile_y;
/** */
int tile_Ox;
/** */
int tile_Oy;
/** number of tiles in X */
int tw;
/** number of tiles in Y */
int th;
/** component numbers */
int comp;
/** number of layer */
int layer;
/** number of decomposition */
int decomposition;
/** main header position */
int main_head_end;
/** codestream's size */
int codestream_size;
/** information regarding tiles inside image */
opj_tile_info_t *tile;
} opj_image_info_t;
/** /**
JPEG-2000 codestream reader/writer JPEG-2000 codestream reader/writer
*/ */
@ -325,20 +323,6 @@ typedef struct opj_j2k {
int state; int state;
/** number of the tile curently concern by coding/decoding */ /** number of the tile curently concern by coding/decoding */
int curtileno; int curtileno;
/** Tile part number*/
int tp_num;
/** Tilepart number currently coding*/
int cur_tp_num;
/** Total number of tileparts of the current tile*/
int *cur_totnum_tp;
/**
locate the start position of the TLM marker
after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length.
*/
int tlm_start;
/** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/
/** used in TLMmarker*/
int totnum_tp;
/** /**
locate the position of the end of the tile in the codestream, locate the position of the end of the tile in the codestream,
used to detect a truncated codestream (in j2k_read_sod) used to detect a truncated codestream (in j2k_read_sod)
@ -369,7 +353,7 @@ typedef struct opj_j2k {
/** pointer to the coding parameters */ /** pointer to the coding parameters */
opj_cp_t *cp; opj_cp_t *cp;
/** helper used to write the index file */ /** helper used to write the index file */
opj_codestream_info_t *cstr_info; opj_image_info_t *image_info;
/** pointer to the byte i/o stream */ /** pointer to the byte i/o stream */
opj_cio_t *cio; opj_cio_t *cio;
} opj_j2k_t; } opj_j2k_t;
@ -399,18 +383,16 @@ void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
Decode an image from a JPEG-2000 codestream Decode an image from a JPEG-2000 codestream
@param j2k J2K decompressor handle @param j2k J2K decompressor handle
@param cio Input buffer stream @param cio Input buffer stream
@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise @return Returns a decoded image if successful, returns NULL otherwise
*/ */
opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info); opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio);
/** /**
Decode an image form a JPT-stream (JPEG 2000, JPIP) Decode an image form a JPT-stream (JPEG 2000, JPIP)
@param j2k J2K decompressor handle @param j2k J2K decompressor handle
@param cio Input buffer stream @param cio Input buffer stream
@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise @return Returns a decoded image if successful, returns NULL otherwise
*/ */
opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info); opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio);
/** /**
Creates a J2K compression structure Creates a J2K compression structure
@param cinfo Codec context info @param cinfo Codec context info
@ -431,19 +413,14 @@ Coding parameters are returned in j2k->cp.
*/ */
void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image); void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image);
/** /**
Converts an enum type progression order to string type
*/
char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order);
/**
Encode an image into a JPEG-2000 codestream Encode an image into a JPEG-2000 codestream
@param j2k J2K compressor handle @param j2k J2K compressor handle
@param cio Output buffer stream @param cio Output buffer stream
@param image Image to encode @param image Image to encode
@param cstr_info Codestream information structure if required, NULL otherwise @param index Name of the index file if required, NULL otherwise
@return Returns true if successful, returns false otherwise @return Returns true if successful, returns false otherwise
*/ */
opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@ -1,10 +1,5 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -29,18 +24,18 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef _WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/times.h> #include <sys/times.h>
#endif /* _WIN32 */ #endif /* WIN32 */
#include "opj_includes.h" #include "opj_includes.h"
double OPJ_CALLCONV opj_clock(void) { double opj_clock() {
#ifdef _WIN32 #ifdef WIN32
/* _WIN32: use QueryPerformance (very accurate) */ /* WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ; LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */ /* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ; QueryPerformanceFrequency(&freq) ;
@ -62,3 +57,20 @@ double OPJ_CALLCONV opj_clock(void) {
#endif #endif
} }
void* opj_malloc( size_t size ) {
void *memblock = malloc(size);
if(memblock) {
memset(memblock, 0, size);
}
return memblock;
}
void* opj_realloc( void *memblock, size_t size ) {
return realloc(memblock, size);
}
void opj_free( void *memblock ) {
free(memblock);
}

View File

@ -1,10 +1,5 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -28,19 +23,19 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef __J3D_LIB_H #ifndef __J2K_LIB_H
#define __J3D_LIB_H #define __J2K_LIB_H
/** /**
@file jp3d_lib.h @file j2k_lib.h
@brief Internal functions @brief Internal functions
The functions in JP3D_LIB.C are internal utilities mainly used for memory management. The functions in J2K_LIB.C are internal utilities mainly used for memory management.
*/ */
/** @defgroup MISC MISC - Miscellaneous internal functions */ /** @defgroup MISC MISC - Miscellaneous internal functions */
/*@{*/ /*@{*/
/** @name Funciones generales */ /** @name Exported functions */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@ -48,7 +43,7 @@ The functions in JP3D_LIB.C are internal utilities mainly used for memory manage
Difference in successive opj_clock() calls tells you the elapsed time Difference in successive opj_clock() calls tells you the elapsed time
@return Returns time in seconds @return Returns time in seconds
*/ */
double opj_clock(void); double opj_clock();
/** /**
Allocate a memory block with elements initialized to 0 Allocate a memory block with elements initialized to 0
@ -76,5 +71,5 @@ void opj_free( void *memblock );
/*@}*/ /*@}*/
#endif /* __J3D_LIB_H */ #endif /* __J2K_LIB_H */

704
libopenjpeg/jp2.c Normal file
View File

@ -0,0 +1,704 @@
/*
* Copyright (c) 2004, Yannick Verschueren
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, 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 "opj_includes.h"
/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
/*@{*/
/** @name Local static functions */
/*@{*/
/**
Read box headers
@param cinfo Codec context info
@param cio Input stream
@param box
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box);
/*static void jp2_write_url(opj_cio_t *cio, char *Idx_file);*/
/**
Read the IHDR box - Image Header box
@param jp2 JP2 handle
@param cio Input buffer stream
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio);
static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio);
static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
static bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio);
static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Write the JP2H box - JP2 Header box
@param jp2 JP2 handle
@param cio Output buffer stream
*/
static void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Read the JP2H box - JP2 Header box
@param jp2 JP2 handle
@param cio Input buffer stream
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Write the FTYP box - File type box
@param jp2 JP2 handle
@param cio Output buffer stream
*/
static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Read the FTYP box - File type box
@param jp2 JP2 handle
@param cio Input buffer stream
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index);
static bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset);
static void jp2_write_jp(opj_cio_t *cio);
/**
Read the JP box - JPEG 2000 signature
@param jp2 JP2 handle
@param cio Input buffer stream
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Decode the structure of a JP2 file
@param jp2 JP2 handle
@param cio Input buffer stream
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio);
/*@}*/
/*@}*/
/* ----------------------------------------------------------------------- */
static bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box) {
box->init_pos = cio_tell(cio);
box->length = cio_read(cio, 4);
box->type = cio_read(cio, 4);
if (box->length == 1) {
if (cio_read(cio, 4) != 0) {
opj_event_msg(cinfo, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n");
return false;
}
box->length = cio_read(cio, 4);
if (box->length == 0)
box->length = cio_numbytesleft(cio) + 12;
}
else if (box->length == 0) {
box->length = cio_numbytesleft(cio) + 8;
}
return true;
}
#if 0
static void jp2_write_url(opj_cio_t *cio, char *Idx_file) {
unsigned int i;
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_URL, 4); /* DBTL */
cio_write(cio, 0, 1); /* VERS */
cio_write(cio, 0, 3); /* FLAG */
if(Idx_file) {
for (i = 0; i < strlen(Idx_file); i++) {
cio_write(cio, Idx_file[i], 1);
}
}
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
#endif
static bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
opj_common_ptr cinfo = jp2->cinfo;
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_IHDR != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected IHDR Marker\n");
return false;
}
jp2->h = cio_read(cio, 4); /* HEIGHT */
jp2->w = cio_read(cio, 4); /* WIDTH */
jp2->numcomps = cio_read(cio, 2); /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
jp2->bpc = cio_read(cio, 1); /* BPC */
jp2->C = cio_read(cio, 1); /* C */
jp2->UnkC = cio_read(cio, 1); /* UnkC */
jp2->IPR = cio_read(cio, 1); /* IPR */
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with IHDR Box\n");
return false;
}
return true;
}
static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_IHDR, 4); /* IHDR */
cio_write(cio, jp2->h, 4); /* HEIGHT */
cio_write(cio, jp2->w, 4); /* WIDTH */
cio_write(cio, jp2->numcomps, 2); /* NC */
cio_write(cio, jp2->bpc, 1); /* BPC */
cio_write(cio, jp2->C, 1); /* C : Always 7 */
cio_write(cio, jp2->UnkC, 1); /* UnkC, colorspace unknown */
cio_write(cio, jp2->IPR, 1); /* IPR, no intellectual property */
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) {
unsigned int i;
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_BPCC, 4); /* BPCC */
for (i = 0; i < jp2->numcomps; i++) {
cio_write(cio, jp2->comps[i].bpcc, 1);
}
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
static bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) {
unsigned int i;
opj_jp2_box_t box;
opj_common_ptr cinfo = jp2->cinfo;
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_BPCC != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected BPCC Marker\n");
return false;
}
for (i = 0; i < jp2->numcomps; i++) {
jp2->comps[i].bpcc = cio_read(cio, 1);
}
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with BPCC Box\n");
return false;
}
return true;
}
static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_COLR, 4); /* COLR */
cio_write(cio, jp2->meth, 1); /* METH */
cio_write(cio, jp2->precedence, 1); /* PRECEDENCE */
cio_write(cio, jp2->approx, 1); /* APPROX */
if (jp2->meth == 1) {
cio_write(cio, jp2->enumcs, 4); /* EnumCS */
} else {
cio_write(cio, 0, 1); /* PROFILE (??) */
}
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
int skip_len;
opj_common_ptr cinfo = jp2->cinfo;
jp2_read_boxhdr(cinfo, cio, &box);
do {
if (JP2_COLR != box.type) {
cio_skip(cio, box.length - 8);
jp2_read_boxhdr(cinfo, cio, &box);
}
} while(JP2_COLR != box.type);
jp2->meth = cio_read(cio, 1); /* METH */
jp2->precedence = cio_read(cio, 1); /* PRECEDENCE */
jp2->approx = cio_read(cio, 1); /* APPROX */
if (jp2->meth == 1) {
jp2->enumcs = cio_read(cio, 4); /* EnumCS */
} else {
/* skip PROFILE */
skip_len = box.init_pos + box.length - cio_tell(cio);
if (skip_len < 0) {
opj_event_msg(cinfo, EVT_ERROR, "Error with JP2H box size\n");
return false;
}
cio_skip(cio, box.init_pos + box.length - cio_tell(cio));
}
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with BPCC Box\n");
return false;
}
return true;
}
static void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_JP2H, 4); /* JP2H */
jp2_write_ihdr(jp2, cio);
if (jp2->bpc == 255) {
jp2_write_bpcc(jp2, cio);
}
jp2_write_colr(jp2, cio);
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
static bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
int skip_len;
opj_common_ptr cinfo = jp2->cinfo;
jp2_read_boxhdr(cinfo, cio, &box);
do {
if (JP2_JP2H != box.type) {
if (box.type == JP2_JP2C) {
opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n");
return false;
}
cio_skip(cio, box.length - 8);
jp2_read_boxhdr(cinfo, cio, &box);
}
} while(JP2_JP2H != box.type);
if (!jp2_read_ihdr(jp2, cio))
return false;
if (jp2->bpc == 255) {
if (!jp2_read_bpcc(jp2, cio))
return false;
}
if (!jp2_read_colr(jp2, cio))
return false;
skip_len = box.init_pos + box.length - cio_tell(cio);
if (skip_len < 0) {
opj_event_msg(cinfo, EVT_ERROR, "Error with JP2H Box\n");
return false;
}
cio_skip(cio, box.init_pos + box.length - cio_tell(cio));
return true;
}
static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
unsigned int i;
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_FTYP, 4); /* FTYP */
cio_write(cio, jp2->brand, 4); /* BR */
cio_write(cio, jp2->minversion, 4); /* MinV */
for (i = 0; i < jp2->numcl; i++) {
cio_write(cio, jp2->cl[i], 4); /* CL */
}
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
int i;
opj_jp2_box_t box;
opj_common_ptr cinfo = jp2->cinfo;
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_FTYP != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected FTYP Marker\n");
return false;
}
jp2->brand = cio_read(cio, 4); /* BR */
jp2->minversion = cio_read(cio, 4); /* MinV */
jp2->numcl = (box.length - 16) / 4;
jp2->cl = (unsigned int *) opj_malloc(jp2->numcl * sizeof(unsigned int));
for (i = 0; i < (int)jp2->numcl; i++) {
jp2->cl[i] = cio_read(cio, 4); /* CLi */
}
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with FTYP Box\n");
return false;
}
return true;
}
static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
unsigned int j2k_codestream_offset, j2k_codestream_length;
opj_jp2_box_t box;
opj_j2k_t *j2k = jp2->j2k;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_JP2C, 4); /* JP2C */
/* J2K encoding */
j2k_codestream_offset = cio_tell(cio);
if(!j2k_encode(j2k, cio, image, index)) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Failed to encode image\n");
return 0;
}
j2k_codestream_length = cio_tell(cio) - j2k_codestream_offset;
jp2->j2k_codestream_offset = j2k_codestream_offset;
jp2->j2k_codestream_length = j2k_codestream_length;
box.length = 8 + jp2->j2k_codestream_length;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
return box.length;
}
static bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset) {
opj_jp2_box_t box;
opj_common_ptr cinfo = jp2->cinfo;
jp2_read_boxhdr(cinfo, cio, &box);
do {
if(JP2_JP2C != box.type) {
cio_skip(cio, box.length - 8);
jp2_read_boxhdr(cinfo, cio, &box);
}
} while(JP2_JP2C != box.type);
*j2k_codestream_offset = cio_tell(cio);
*j2k_codestream_length = box.length - 8;
return true;
}
static void jp2_write_jp(opj_cio_t *cio) {
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_JP, 4); /* JP2 signature */
cio_write(cio, 0x0d0a870a, 4);
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
static bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
opj_common_ptr cinfo = jp2->cinfo;
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_JP != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected JP Marker\n");
return false;
}
if (0x0d0a870a != cio_read(cio, 4)) {
opj_event_msg(cinfo, EVT_ERROR, "Error with JP Marker\n");
return false;
}
if (cio_tell(cio) - box.init_pos != box.length) {
opj_event_msg(cinfo, EVT_ERROR, "Error with JP Box size\n");
return false;
}
return true;
}
static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio) {
if (!jp2_read_jp(jp2, cio))
return false;
if (!jp2_read_ftyp(jp2, cio))
return false;
if (!jp2_read_jp2h(jp2, cio))
return false;
if (!jp2_read_jp2c(jp2, cio, &jp2->j2k_codestream_length, &jp2->j2k_codestream_offset))
return false;
return true;
}
/* ----------------------------------------------------------------------- */
/* JP2 decoder interface */
/* ----------------------------------------------------------------------- */
opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo) {
opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
if(jp2) {
jp2->cinfo = cinfo;
/* create the J2K codec */
jp2->j2k = j2k_create_decompress(cinfo);
if(jp2->j2k == NULL) {
jp2_destroy_decompress(jp2);
return NULL;
}
}
return jp2;
}
void jp2_destroy_decompress(opj_jp2_t *jp2) {
if(jp2) {
/* destroy the J2K codec */
j2k_destroy_decompress(jp2->j2k);
if(jp2->comps) {
opj_free(jp2->comps);
}
if(jp2->cl) {
opj_free(jp2->cl);
}
opj_free(jp2);
}
}
void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) {
/* setup the J2K codec */
j2k_setup_decoder(jp2->j2k, parameters);
/* further JP2 initializations go here */
}
opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_common_ptr cinfo;
opj_image_t *image = NULL;
if(!jp2 || !cio) {
return NULL;
}
cinfo = jp2->cinfo;
/* JP2 decoding */
if(!jp2_read_struct(jp2, cio)) {
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode jp2 structure\n");
return NULL;
}
/* J2K decoding */
image = j2k_decode(jp2->j2k, cio);
if(!image) {
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode J2K image\n");
}
return image;
}
/* ----------------------------------------------------------------------- */
/* JP2 encoder interface */
/* ----------------------------------------------------------------------- */
opj_jp2_t* jp2_create_compress(opj_common_ptr cinfo) {
opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
if(jp2) {
jp2->cinfo = cinfo;
/* create the J2K codec */
jp2->j2k = j2k_create_compress(cinfo);
if(jp2->j2k == NULL) {
jp2_destroy_compress(jp2);
return NULL;
}
}
return jp2;
}
void jp2_destroy_compress(opj_jp2_t *jp2) {
if(jp2) {
/* destroy the J2K codec */
j2k_destroy_compress(jp2->j2k);
if(jp2->comps) {
opj_free(jp2->comps);
}
if(jp2->cl) {
opj_free(jp2->cl);
}
opj_free(jp2);
}
}
void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image) {
int i;
int depth_0, sign;
if(!jp2 || !parameters || !image)
return;
/* setup the J2K codec */
/* ------------------- */
j2k_setup_encoder(jp2->j2k, parameters, image);
/* setup the JP2 codec */
/* ------------------- */
/* Profile box */
jp2->brand = JP2_JP2; /* BR */
jp2->minversion = 0; /* MinV */
jp2->numcl = 1;
jp2->cl = (unsigned int*) opj_malloc(jp2->numcl * sizeof(unsigned int));
jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
/* Image Header box */
jp2->numcomps = image->numcomps; /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
jp2->h = image->y1 - image->y0; /* HEIGHT */
jp2->w = image->x1 - image->x0; /* WIDTH */
/* BPC */
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
jp2->bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
int depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
jp2->bpc = 255;
}
jp2->C = 7; /* C : Always 7 */
jp2->UnkC = 0; /* UnkC, colorspace specified in colr box */
jp2->IPR = 0; /* IPR, no intellectual property */
/* BitsPerComponent box */
for (i = 0; i < image->numcomps; i++) {
jp2->comps[i].bpcc = image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
}
/* Colour Specification box */
if ((image->numcomps == 1 || image->numcomps == 3) && (jp2->bpc != 255)) {
jp2->meth = 1; /* METH: Enumerated colourspace */
} else {
jp2->meth = 2; /* METH: Restricted ICC profile */
}
if (jp2->meth == 1) {
if (image->color_space == 1)
jp2->enumcs = 16; /* sRGB as defined by IEC 6196621 */
else if (image->color_space == 2)
jp2->enumcs = 17; /* greyscale */
else if (image->color_space == 3)
jp2->enumcs = 18; /* YUV */
} else {
jp2->enumcs = 0; /* PROFILE (??) */
}
jp2->precedence = 0; /* PRECEDENCE */
jp2->approx = 0; /* APPROX */
}
bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
/* JP2 encoding */
/* JPEG 2000 Signature box */
jp2_write_jp(cio);
/* File Type box */
jp2_write_ftyp(jp2, cio);
/* JP2 Header box */
jp2_write_jp2h(jp2, cio);
/* J2K encoding */
if(!jp2_write_jp2c(jp2, cio, image, index)) {
opj_event_msg(jp2->cinfo, EVT_ERROR, "Failed to encode image\n");
return false;
}
return true;
}

View File

@ -1,13 +1,7 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2004, Yannick Verschueren
* BSD License, included below. This software may be subject to other third * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* party and contributor rights, including patent rights, and no such rights * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -42,6 +36,8 @@
/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */ /** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
/*@{*/ /*@{*/
#define JPIP_JPIP 0x6a706970
#define JP2_JP 0x6a502020 /**< JPEG 2000 signature box */ #define JP2_JP 0x6a502020 /**< JPEG 2000 signature box */
#define JP2_FTYP 0x66747970 /**< File type box */ #define JP2_FTYP 0x66747970 /**< File type box */
#define JP2_JP2H 0x6a703268 /**< JP2 header box */ #define JP2_JP2H 0x6a703268 /**< JP2 header box */
@ -49,64 +45,11 @@
#define JP2_COLR 0x636f6c72 /**< Colour specification box */ #define JP2_COLR 0x636f6c72 /**< Colour specification box */
#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */ #define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */
#define JP2_URL 0x75726c20 /**< URL box */ #define JP2_URL 0x75726c20 /**< URL box */
#define JP2_DTBL 0x6474626c /**< Data Reference box */ #define JP2_DBTL 0x6474626c /**< ??? */
#define JP2_BPCC 0x62706363 /**< Bits per component box */ #define JP2_BPCC 0x62706363 /**< Bits per component box */
#define JP2_JP2 0x6a703220 /**< File type fields */ #define JP2_JP2 0x6a703220 /**< File type fields */
#define JP2_PCLR 0x70636c72 /**< Palette box */
#define JP2_CMAP 0x636d6170 /**< Component Mapping box */
#define JP2_CDEF 0x63646566 /**< Channel Definition box */
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/**
Channel description: channel index, type, association
*/
typedef struct opj_jp2_cdef_info
{
unsigned short cn, typ, asoc;
} opj_jp2_cdef_info_t;
/**
Channel descriptions and number of descriptions
*/
typedef struct opj_jp2_cdef
{
opj_jp2_cdef_info_t *info;
unsigned short n;
} opj_jp2_cdef_t;
/**
Component mappings: channel index, mapping type, palette index
*/
typedef struct opj_jp2_cmap_comp
{
unsigned short cmp;
unsigned char mtyp, pcol;
} opj_jp2_cmap_comp_t;
/**
Palette data: table entries, palette columns
*/
typedef struct opj_jp2_pclr
{
unsigned int *entries;
unsigned char *channel_sign;
unsigned char *channel_size;
opj_jp2_cmap_comp_t *cmap;
unsigned short nr_entries, nr_channels;
} opj_jp2_pclr_t;
/**
Collector for ICC profile, palette, component mapping, channel description
*/
typedef struct opj_jp2_color
{
unsigned char *icc_profile_buf;
int icc_profile_len;
opj_jp2_cdef_t *jp2_cdef;
opj_jp2_pclr_t *jp2_pclr;
unsigned char jp2_has_colr;
} opj_jp2_color_t;
/** /**
JP2 component JP2 component
@ -143,7 +86,6 @@ typedef struct opj_jp2 {
opj_jp2_comps_t *comps; opj_jp2_comps_t *comps;
unsigned int j2k_codestream_offset; unsigned int j2k_codestream_offset;
unsigned int j2k_codestream_length; unsigned int j2k_codestream_length;
opj_bool ignore_pclr_cmap_cdef;
} opj_jp2_t; } opj_jp2_t;
/** /**
@ -159,20 +101,6 @@ typedef struct opj_jp2_box {
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
Write the JP2H box - JP2 Header box (used in MJ2)
@param jp2 JP2 handle
@param cio Output buffer stream
*/
void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio);
/**
Read the JP2H box - JP2 Header box (used in MJ2)
@param jp2 JP2 handle
@param cio Input buffer stream
@param ext Collector for profile, cdef and pclr data
@return Returns true if successful, returns false otherwise
*/
opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color);
/**
Creates a JP2 decompression structure Creates a JP2 decompression structure
@param cinfo Codec context info @param cinfo Codec context info
@return Returns a handle to a JP2 decompressor if successful, returns NULL otherwise @return Returns a handle to a JP2 decompressor if successful, returns NULL otherwise
@ -194,10 +122,9 @@ void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters);
Decode an image from a JPEG-2000 file stream Decode an image from a JPEG-2000 file stream
@param jp2 JP2 decompressor handle @param jp2 JP2 decompressor handle
@param cio Input buffer stream @param cio Input buffer stream
@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise @return Returns a decoded image if successful, returns NULL otherwise
*/ */
opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info); opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio);
/** /**
Creates a JP2 compression structure Creates a JP2 compression structure
@param cinfo Codec context info @param cinfo Codec context info
@ -222,11 +149,10 @@ Encode an image into a JPEG-2000 file stream
@param jp2 JP2 compressor handle @param jp2 JP2 compressor handle
@param cio Output buffer stream @param cio Output buffer stream
@param image Image to encode @param image Image to encode
@param cstr_info Codestream information structure if required, NULL otherwise @param index Name of the index file if required, NULL otherwise
@return Returns true if successful, returns false otherwise @return Returns true if successful, returns false otherwise
*/ */
opj_bool opj_jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@ -1,13 +1,7 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2004, Yannick Verschueren
* BSD License, included below. This software may be subject to other third * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* party and contributor rights, including patent rights, and no such rights * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -39,7 +33,7 @@
* Store information (7 bits) in value * Store information (7 bits) in value
* *
*/ */
static unsigned int jpt_read_VBAS_info(opj_cio_t *cio, unsigned int value) { unsigned int jpt_read_VBAS_info(opj_cio_t *cio, unsigned int value) {
unsigned char elmt; unsigned char elmt;
elmt = cio_read(cio, 1); elmt = cio_read(cio, 1);
@ -74,7 +68,7 @@ void jpt_init_msg_header(opj_jpt_msg_header_t * header) {
* Only parameters always present in message header * Only parameters always present in message header
* *
*/ */
static void jpt_reinit_msg_header(opj_jpt_msg_header_t * header) { void jpt_reinit_msg_header(opj_jpt_msg_header_t * header) {
header->Id = 0; /* In-class Identifier */ header->Id = 0; /* In-class Identifier */
header->last_byte = 0; /* Last byte information */ header->last_byte = 0; /* Last byte information */
header->Msg_offset = 0; /* Message offset */ header->Msg_offset = 0; /* Message offset */

View File

@ -1,13 +1,7 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2004, Yannick Verschueren
* BSD License, included below. This software may be subject to other third * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* party and contributor rights, including patent rights, and no such rights * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -46,7 +41,7 @@ static const double mct_norms[3] = { 1.732, .8292, .8292 };
static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 }; static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 };
/* <summary> */ /* <summary> */
/* Forward reversible MCT. */ /* Foward reversible MCT. */
/* </summary> */ /* </summary> */
void mct_encode(int *c0, int *c1, int *c2, int n) { void mct_encode(int *c0, int *c1, int *c2, int n) {
int i; int i;
@ -91,7 +86,7 @@ double mct_getnorm(int compno) {
} }
/* <summary> */ /* <summary> */
/* Forward irreversible MCT. */ /* Foward irreversible MCT. */
/* </summary> */ /* </summary> */
void mct_encode_real(int *c0, int *c1, int *c2, int n) { void mct_encode_real(int *c0, int *c1, int *c2, int n) {
int i; int i;

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -46,7 +41,7 @@ transform. The functions in MCT.C are used by some function in TCD.C.
/** @defgroup MCT MCT - Implementation of a multi-component transform */ /** @defgroup MCT MCT - Implementation of a multi-component transform */
/*@{*/ /*@{*/
/** @name Funciones generales */ /** @name Exported functions */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -68,13 +63,13 @@ Fill mqc->c with 1's for flushing
*/ */
static void mqc_setbits(opj_mqc_t *mqc); static void mqc_setbits(opj_mqc_t *mqc);
/** /**
Exchange MPS with LPS FIXME: documentation ???
@param mqc MQC handle @param mqc MQC handle
@return @return
*/ */
static int mqc_mpsexchange(opj_mqc_t *mqc); static int mqc_mpsexchange(opj_mqc_t *mqc);
/** /**
Exchange LPS with MPS FIXME: documentation ???
@param mqc MQC handle @param mqc MQC handle
@return @return
*/ */
@ -448,13 +443,6 @@ void mqc_reset_enc(opj_mqc_t *mqc) {
mqc_setstate(mqc, 1, 0, 4); mqc_setstate(mqc, 1, 0, 4);
} }
void mqc_reset_enc_3(opj_mqc_t *mqc) {
mqc_resetstates(mqc);
mqc_setstate(mqc, T1_3D_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_3D_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_3D_CTXNO_ZC, 0, 4);
}
int mqc_restart_enc(opj_mqc_t *mqc) { int mqc_restart_enc(opj_mqc_t *mqc) {
int correction = 1; int correction = 1;

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -83,7 +78,7 @@ typedef struct opj_mqc {
Create a new MQC handle Create a new MQC handle
@return Returns a new MQC handle if successful, returns NULL otherwise @return Returns a new MQC handle if successful, returns NULL otherwise
*/ */
opj_mqc_t* mqc_create(void); opj_mqc_t* mqc_create();
/** /**
Destroy a previously created MQC handle Destroy a previously created MQC handle
@param mqc MQC handle to destroy @param mqc MQC handle to destroy
@ -160,11 +155,6 @@ RESET mode switch
*/ */
void mqc_reset_enc(opj_mqc_t *mqc); void mqc_reset_enc(opj_mqc_t *mqc);
/** /**
RESET mode switch
@param mqc MQC handle
*/
void mqc_reset_enc_3(opj_mqc_t *mqc);
/**
RESTART mode switch (TERMALL) RESTART mode switch (TERMALL)
@param mqc MQC handle @param mqc MQC handle
@return Returns 1 (always) @return Returns 1 (always)

View File

@ -1,10 +1,5 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -29,22 +24,17 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef _WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#endif /* _WIN32 */ #endif /* WIN32 */
#include "opj_config_private.h"
#include "opj_includes.h" #include "opj_includes.h"
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
#ifdef _WIN32 #ifdef WIN32
#ifndef OPJ_STATIC #ifndef OPJ_STATIC
BOOL APIENTRY BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
OPJ_ARG_NOT_USED(lpReserved);
OPJ_ARG_NOT_USED(hModule);
switch (ul_reason_for_call) { switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH : case DLL_PROCESS_ATTACH :
break; break;
@ -58,19 +48,19 @@ DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
return TRUE; return TRUE;
} }
#endif /* OPJ_STATIC */ #endif /* OPJ_STATIC */
#endif /* _WIN32 */ #endif /* WIN32 */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
const char* OPJ_CALLCONV opj_version(void) { const char* OPJ_CALLCONV opj_version() {
return OPJ_PACKAGE_VERSION; return OPENJPEG_VERSION;
} }
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) { opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t)); opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
if(!dinfo) return NULL; if(!dinfo) return NULL;
dinfo->is_decompressor = OPJ_TRUE; dinfo->is_decompressor = true;
switch(format) { switch(format) {
case CODEC_J2K: case CODEC_J2K:
case CODEC_JPT: case CODEC_JPT:
@ -126,18 +116,9 @@ void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *paramete
/* default decoding parameters */ /* default decoding parameters */
parameters->cp_layer = 0; parameters->cp_layer = 0;
parameters->cp_reduce = 0; parameters->cp_reduce = 0;
parameters->cp_limit_decoding = NO_LIMITATION;
parameters->decod_format = -1; parameters->decod_format = -1;
parameters->cod_format = -1; parameters->cod_format = -1;
parameters->flags = 0;
/* UniPG>> */
#ifdef USE_JPWL
parameters->jpwl_correct = OPJ_FALSE;
parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
#endif /* USE_JPWL */
/* <<UniPG */
} }
} }
@ -159,30 +140,27 @@ void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *param
} }
opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) { opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
return opj_decode_with_info(dinfo, cio, NULL);
}
opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
if(dinfo && cio) { if(dinfo && cio) {
switch(dinfo->codec_format) { switch(dinfo->codec_format) {
case CODEC_J2K: case CODEC_J2K:
return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info); return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio);
case CODEC_JPT: case CODEC_JPT:
return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info); return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio);
case CODEC_JP2: case CODEC_JP2:
return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info); return jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio);
case CODEC_UNKNOWN: case CODEC_UNKNOWN:
default: default:
break; break;
} }
} }
return NULL; return NULL;
} }
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) { opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t)); opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
if(!cinfo) return NULL; if(!cinfo) return NULL;
cinfo->is_decompressor = OPJ_FALSE; cinfo->is_decompressor = false;
switch(format) { switch(format) {
case CODEC_J2K: case CODEC_J2K:
/* get a J2K coder handle */ /* get a J2K coder handle */
@ -217,10 +195,10 @@ void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
/* destroy the codec */ /* destroy the codec */
switch(cinfo->codec_format) { switch(cinfo->codec_format) {
case CODEC_J2K: case CODEC_J2K:
j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle); j2k_destroy_decompress((opj_j2k_t*)cinfo->j2k_handle);
break; break;
case CODEC_JP2: case CODEC_JP2:
jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle); jp2_destroy_decompress((opj_jp2_t*)cinfo->jp2_handle);
break; break;
case CODEC_JPT: case CODEC_JPT:
case CODEC_UNKNOWN: case CODEC_UNKNOWN:
@ -236,56 +214,16 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete
if(parameters) { if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t)); memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */ /* default coding parameters */
parameters->cp_cinema = OFF;
parameters->max_comp_size = 0;
parameters->numresolution = 6; parameters->numresolution = 6;
parameters->cp_rsiz = STD_RSIZ;
parameters->cblockw_init = 64; parameters->cblockw_init = 64;
parameters->cblockh_init = 64; parameters->cblockh_init = 64;
parameters->prog_order = LRCP; parameters->prog_order = LRCP;
parameters->roi_compno = -1; /* no ROI */ parameters->roi_compno = -1; /* no ROI */
parameters->subsampling_dx = 1; parameters->subsampling_dx = 1;
parameters->subsampling_dy = 1; parameters->subsampling_dy = 1;
parameters->tp_on = 0;
parameters->decod_format = -1; parameters->decod_format = -1;
parameters->cod_format = -1; parameters->cod_format = -1;
parameters->tcp_rates[0] = 0;
parameters->tcp_numlayers = 0;
parameters->cp_disto_alloc = 0;
parameters->cp_fixed_alloc = 0;
parameters->cp_fixed_quality = 0;
/* UniPG>> */
#ifdef USE_JPWL
parameters->jpwl_epc_on = OPJ_FALSE;
parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
{
int i;
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
parameters->jpwl_hprot_TPH[i] = 0; /* absent */
}
};
{
int i;
for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
parameters->jpwl_pprot[i] = 0; /* absent */
}
};
parameters->jpwl_sens_size = 0; /* 0 means no ESD */
parameters->jpwl_sens_addr = 0; /* 0 means auto */
parameters->jpwl_sens_range = 0; /* 0 means packet */
parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
{
int i;
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
parameters->jpwl_sens_TPH[i] = -1; /* absent */
}
};
#endif /* USE_JPWL */
/* <<UniPG */
} }
} }
@ -306,42 +244,21 @@ void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *param
} }
} }
opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) { bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
if (index != NULL)
opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
"To extract the index, use the opj_encode_with_info() function.\n"
"No index will be generated during this encoding\n");
return opj_encode_with_info(cinfo, cio, image, NULL);
}
opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
if(cinfo && cio && image) { if(cinfo && cio && image) {
switch(cinfo->codec_format) { switch(cinfo->codec_format) {
case CODEC_J2K: case CODEC_J2K:
return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info); return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, index);
case CODEC_JP2: case CODEC_JP2:
return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info); return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, index);
case CODEC_JPT: case CODEC_JPT:
case CODEC_UNKNOWN: case CODEC_UNKNOWN:
default: default:
break; break;
} }
} }
return OPJ_FALSE;
return false;
} }
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
if (cstr_info) {
int tileno;
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
opj_free(tile_info->thresh);
opj_free(tile_info->packet);
opj_free(tile_info->tp);
opj_free(tile_info->marker);
}
opj_free(cstr_info->tile);
opj_free(cstr_info->marker);
opj_free(cstr_info->numdecompos);
}
}

View File

@ -1,18 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006-2007, Parvatha Elangovan
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -39,21 +30,16 @@
#ifndef OPENJPEG_H #ifndef OPENJPEG_H
#define OPENJPEG_H #define OPENJPEG_H
#define OPENJPEG_VERSION "1.0.0"
/* /*
========================================================== ==========================================================
Compiler directives Compiler directives
========================================================== ==========================================================
*/ */
#if defined(OPJ_STATIC) || !defined(_WIN32) #if defined(OPJ_STATIC) || !(defined(WIN32) || defined(__WIN32__))
/* http://gcc.gnu.org/wiki/Visibility */
#if __GNUC__ >= 4
#define OPJ_API __attribute__ ((visibility ("default")))
#define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define OPJ_API #define OPJ_API
#define OPJ_LOCAL
#endif
#define OPJ_CALLCONV #define OPJ_CALLCONV
#else #else
#define OPJ_CALLCONV __stdcall #define OPJ_CALLCONV __stdcall
@ -62,71 +48,61 @@ The following ifdef block is the standard way of creating macros which make expo
from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
symbol defined on the command line. this symbol should not be defined on any project symbol defined on the command line. this symbol should not be defined on any project
that uses this DLL. This way any other project whose source files include this file see that uses this DLL. This way any other project whose source files include this file see
OPJ_API functions as being imported from a DLL, whereas this DLL sees symbols OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
defined with this macro as being exported. defined with this macro as being exported.
*/ */
#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT) #ifdef OPJ_EXPORTS
#define OPJ_API __declspec(dllexport) #define OPJ_API __declspec(dllexport)
#else #else
#define OPJ_API __declspec(dllimport) #define OPJ_API __declspec(dllimport)
#endif /* OPJ_EXPORTS */ #endif /* OPJ_EXPORTS */
#endif /* !OPJ_STATIC || !_WIN32 */ #endif /* !OPJ_STATIC || !WIN32 */
typedef int opj_bool; #ifndef __cplusplus
#define OPJ_TRUE 1 #if defined(HAVE_STDBOOL_H)
#define OPJ_FALSE 0 /*
The C language implementation does correctly provide the standard header
file "stdbool.h".
*/
#include <stdbool.h>
#else
/*
The C language implementation does not provide the standard header file
"stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
braindamage below.
*/
#if !defined(bool)
#define bool int
#endif
#if !defined(true)
#define true 1
#endif
#if !defined(false)
#define false 0
#endif
#endif
#endif /* __cplusplus */
/* Avoid compile-time warning because parameter is not used */
#define OPJ_ARG_NOT_USED(x) (void)(x)
/* /*
========================================================== ==========================================================
Useful constant definitions Useful constant definitions
========================================================== ==========================================================
*/ */
#define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */ #ifndef MAX_PATH
#define MAX_PATH 260 /**< Maximum allowed size for filenames */
#endif /* MAX_PATH */
#define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */ #define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
#define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */ #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
/* UniPG>> */
#define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
#define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
#define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
#define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
#define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
#define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
#define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
#define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
/* <<UniPG */
/* /*
========================================================== ==========================================================
enum definitions enum definitions
========================================================== ==========================================================
*/ */
/**
Rsiz Capabilities
*/
typedef enum RSIZ_CAPABILITIES {
STD_RSIZ = 0, /** Standard JPEG2000 profile*/
CINEMA2K = 3, /** Profile name for a 2K image*/
CINEMA4K = 4 /** Profile name for a 4K image*/
} OPJ_RSIZ_CAPABILITIES;
/** /** Progression order */
Digital cinema operation mode
*/
typedef enum CINEMA_MODE {
OFF = 0, /** Not Digital Cinema*/
CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
}OPJ_CINEMA_MODE;
/**
Progression order
*/
typedef enum PROG_ORDER { typedef enum PROG_ORDER {
PROG_UNKNOWN = -1, /**< place-holder */ PROG_UNKNOWN = -1, /**< place-holder */
LRCP = 0, /**< layer-resolution-component-precinct order */ LRCP = 0, /**< layer-resolution-component-precinct order */
@ -140,17 +116,12 @@ typedef enum PROG_ORDER {
Supported image color spaces Supported image color spaces
*/ */
typedef enum COLOR_SPACE { typedef enum COLOR_SPACE {
CLRSPC_UNKNOWN = -1, /**< not supported by the library */ CLRSPC_UNKNOWN = -1, /**< place-holder */
CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
CLRSPC_SRGB = 1, /**< sRGB */ CLRSPC_SRGB = 1, /**< sRGB */
CLRSPC_GRAY = 2, /**< grayscale */ CLRSPC_GRAY = 2, /**< grayscale */
CLRSPC_SYCC = 3 /**< YUV */ CLRSPC_SYCC = 3 /**< YUV */
} OPJ_COLOR_SPACE; } OPJ_COLOR_SPACE;
#define ENUMCS_SRGB 16
#define ENUMCS_GRAY 17
#define ENUMCS_SYCC 18
/** /**
Supported codec Supported codec
*/ */
@ -161,15 +132,6 @@ typedef enum CODEC_FORMAT {
CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */ CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
} OPJ_CODEC_FORMAT; } OPJ_CODEC_FORMAT;
/**
Limit decoding to certain portions of the codestream.
*/
typedef enum LIMIT_DECODING {
NO_LIMITATION = 0, /**< No limitation for the decoding. The entire codestream will de decoded */
LIMIT_TO_MAIN_HEADER = 1, /**< The decoding is limited to the Main Header */
DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
} OPJ_LIMIT_DECODING;
/* /*
========================================================== ==========================================================
event manager typedef definitions event manager typedef definitions
@ -212,28 +174,11 @@ typedef struct opj_event_mgr {
Progression order changes Progression order changes
*/ */
typedef struct opj_poc { typedef struct opj_poc {
/** Resolution num start, Component num start, given by POC */
int resno0, compno0; int resno0, compno0;
/** Layer num end,Resolution num end, Component num end, given by POC */
int layno1, resno1, compno1; int layno1, resno1, compno1;
/** Layer num start,Precinct num start, Precinct num end */ OPJ_PROG_ORDER prg;
int layno0, precno0, precno1;
/** Progression order enum*/
OPJ_PROG_ORDER prg1,prg;
/** Progression order string*/
char progorder[5];
/** Tile number */
int tile; int tile;
/** Start and end values for Tile width and height*/ char progorder[4];
int tx0,tx1,ty0,ty1;
/** Start value, initialised in pi_initialise_encode*/
int layS, resS, compS, prcS;
/** End value, initialised in pi_initialise_encode */
int layE, resE, compE, prcE;
/** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
int txS,txE,tyS,tyE,dx,dy;
/** Temporary values for Tile parts, initialised in pi_create_encode */
int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
} opj_poc_t; } opj_poc_t;
/** /**
@ -241,7 +186,7 @@ Compression parameters
*/ */
typedef struct opj_cparameters { typedef struct opj_cparameters {
/** size of tile: tile_size_on = false (not in argument) or = true (in argument) */ /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
opj_bool tile_size_on; bool tile_size_on;
/** XTOsiz */ /** XTOsiz */
int cp_tx0; int cp_tx0;
/** YTOsiz */ /** YTOsiz */
@ -298,13 +243,13 @@ typedef struct opj_cparameters {
/**@name command line encoder parameters (not used inside the library) */ /**@name command line encoder parameters (not used inside the library) */
/*@{*/ /*@{*/
/** input file name */ /** input file name */
char infile[OPJ_PATH_LEN]; char infile[MAX_PATH];
/** output file name */ /** output file name */
char outfile[OPJ_PATH_LEN]; char outfile[MAX_PATH];
/** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */ /** creation of an index file, default to 0 (false) */
int index_on; int index_on;
/** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */ /** index file name */
char index[OPJ_PATH_LEN]; char index[MAX_PATH];
/** subimage encoding: origin image offset in x direction */ /** subimage encoding: origin image offset in x direction */
int image_offset_x0; int image_offset_x0;
/** subimage encoding: origin image offset in y direction */ /** subimage encoding: origin image offset in y direction */
@ -313,60 +258,13 @@ typedef struct opj_cparameters {
int subsampling_dx; int subsampling_dx;
/** subsampling value for dy */ /** subsampling value for dy */
int subsampling_dy; int subsampling_dy;
/** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/ /** input file format 0: PGX, 1: PxM, 2: BMP */
int decod_format; int decod_format;
/** output file format 0: J2K, 1: JP2, 2: JPT */ /** output file format 0: J2K, 1: JP2, 2: JPT */
int cod_format; int cod_format;
/*@}*/ /*@}*/
/* UniPG>> */
/**@name JPWL encoding parameters */
/*@{*/
/** enables writing of EPC in MH, thus activating JPWL */
opj_bool jpwl_epc_on;
/** error protection method for MH (0,1,16,32,37-128) */
int jpwl_hprot_MH;
/** tile number of header protection specification (>=0) */
int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** error protection methods for TPHs (0,1,16,32,37-128) */
int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
/** tile number of packet protection specification (>=0) */
int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/** packet number of packet protection specification (>=0) */
int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
/** error protection methods for packets (0,1,16,32,37-128) */
int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
/** enables writing of ESD, (0=no/1/2 bytes) */
int jpwl_sens_size;
/** sensitivity addressing size (0=auto/2/4 bytes) */
int jpwl_sens_addr;
/** sensitivity range (0-3) */
int jpwl_sens_range;
/** sensitivity method for MH (-1=no,0-7) */
int jpwl_sens_MH;
/** tile number of sensitivity specification (>=0) */
int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** sensitivity methods for TPHs (-1=no,0-7) */
int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
/*@}*/
/* <<UniPG */
/** Digital Cinema compliance 0-not compliant, 1-compliant*/
OPJ_CINEMA_MODE cp_cinema;
/** Maximum rate for each component. If == 0, component size limitation is not considered */
int max_comp_size;
/** Profile name*/
OPJ_RSIZ_CAPABILITIES cp_rsiz;
/** Tile part generation*/
char tp_on;
/** Flag for Tile part generation*/
char tp_flag;
/** MCT (multiple component transform) */
char tcp_mct;
} opj_cparameters_t; } opj_cparameters_t;
#define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
/** /**
Decompression parameters Decompression parameters
*/ */
@ -390,36 +288,14 @@ typedef struct opj_dparameters {
/**@name command line encoder parameters (not used inside the library) */ /**@name command line encoder parameters (not used inside the library) */
/*@{*/ /*@{*/
/** input file name */ /** input file name */
char infile[OPJ_PATH_LEN]; char infile[MAX_PATH];
/** output file name */ /** output file name */
char outfile[OPJ_PATH_LEN]; char outfile[MAX_PATH];
/** input file format 0: J2K, 1: JP2, 2: JPT */ /** input file format 0: J2K, 1: JP2, 2: JPT */
int decod_format; int decod_format;
/** output file format 0: PGX, 1: PxM, 2: BMP */ /** output file format 0: PGX, 1: PxM, 2: BMP */
int cod_format; int cod_format;
/*@}*/ /*@}*/
/* UniPG>> */
/**@name JPWL decoding parameters */
/*@{*/
/** activates the JPWL correction capabilities */
opj_bool jpwl_correct;
/** expected number of components */
int jpwl_exp_comps;
/** maximum number of tiles */
int jpwl_max_tiles;
/*@}*/
/* <<UniPG */
/**
Specify whether the decoding should be done on the entire codestream, or be limited to the main header
Limiting the decoding to the main header makes it possible to extract the characteristics of the codestream
if == NO_LIMITATION, the entire codestream is decoded;
if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
*/
OPJ_LIMIT_DECODING cp_limit_decoding;
unsigned int flags;
} opj_dparameters_t; } opj_dparameters_t;
/** Common fields between JPEG-2000 compression and decompression master structs. */ /** Common fields between JPEG-2000 compression and decompression master structs. */
@ -427,11 +303,10 @@ typedef struct opj_dparameters {
#define opj_common_fields \ #define opj_common_fields \
opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\ opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
void * client_data; /**< Available for use by application */\ void * client_data; /**< Available for use by application */\
opj_bool is_decompressor; /**< So common code can tell which is which */\ bool is_decompressor; /**< So common code can tell which is which */\
OPJ_CODEC_FORMAT codec_format; /**< selected codec */\ OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
void *j2k_handle; /**< pointer to the J2K codec */\ void *j2k_handle; /**< pointer to the J2K codec */\
void *jp2_handle; /**< pointer to the JP2 codec */\ void *jp2_handle /**< pointer to the JP2 codec */
void *mj2_handle /**< pointer to the MJ2 codec */
/* Routines that are to be used by both halves of the library are declared /* Routines that are to be used by both halves of the library are declared
* to receive a pointer to this structure. There are no actual instances of * to receive a pointer to this structure. There are no actual instances of
@ -555,10 +430,6 @@ typedef struct opj_image {
OPJ_COLOR_SPACE color_space; OPJ_COLOR_SPACE color_space;
/** image components */ /** image components */
opj_image_comp_t *comps; opj_image_comp_t *comps;
/** 'restricted' ICC profile */
unsigned char *icc_profile_buf;
/** size of ICC profile */
int icc_profile_len;
} opj_image_t; } opj_image_t;
/** /**
@ -585,149 +456,6 @@ typedef struct opj_image_comptparm {
int sgnd; int sgnd;
} opj_image_cmptparm_t; } opj_image_cmptparm_t;
/*
==========================================================
Information on the JPEG 2000 codestream
==========================================================
*/
/**
Index structure : Information concerning a packet inside tile
*/
typedef struct opj_packet_info {
/** packet start position (including SOP marker if it exists) */
int start_pos;
/** end of packet header position (including EPH marker if it exists)*/
int end_ph_pos;
/** packet end position */
int end_pos;
/** packet distorsion */
double disto;
} opj_packet_info_t;
/* UniPG>> */
/**
Marker structure
*/
typedef struct opj_marker_info_t {
/** marker type */
unsigned short int type;
/** position in codestream */
int pos;
/** length, marker val included */
int len;
} opj_marker_info_t;
/* <<UniPG */
/**
Index structure : Information concerning tile-parts
*/
typedef struct opj_tp_info {
/** start position of tile part */
int tp_start_pos;
/** end position of tile part header */
int tp_end_header;
/** end position of tile part */
int tp_end_pos;
/** start packet of tile part */
int tp_start_pack;
/** number of packets of tile part */
int tp_numpacks;
} opj_tp_info_t;
/**
Index structure : information regarding tiles
*/
typedef struct opj_tile_info {
/** value of thresh for each layer by tile cfr. Marcela */
double *thresh;
/** number of tile */
int tileno;
/** start position */
int start_pos;
/** end position of the header */
int end_header;
/** end position */
int end_pos;
/** precinct number for each resolution level (width) */
int pw[33];
/** precinct number for each resolution level (height) */
int ph[33];
/** precinct size (in power of 2), in X for each resolution level */
int pdx[33];
/** precinct size (in power of 2), in Y for each resolution level */
int pdy[33];
/** information concerning packets inside tile */
opj_packet_info_t *packet;
/** add fixed_quality */
int numpix;
/** add fixed_quality */
double distotile;
/** number of markers */
int marknum;
/** list of markers */
opj_marker_info_t *marker;
/** actual size of markers array */
int maxmarknum;
/** number of tile parts */
int num_tps;
/** information concerning tile parts */
opj_tp_info_t *tp;
} opj_tile_info_t;
/**
Index structure of the codestream
*/
typedef struct opj_codestream_info {
/** maximum distortion reduction on the whole image (add for Marcela) */
double D_max;
/** packet number */
int packno;
/** writing the packet in the index with t2_encode_packets */
int index_write;
/** image width */
int image_w;
/** image height */
int image_h;
/** progression order */
OPJ_PROG_ORDER prog;
/** tile size in x */
int tile_x;
/** tile size in y */
int tile_y;
/** */
int tile_Ox;
/** */
int tile_Oy;
/** number of tiles in X */
int tw;
/** number of tiles in Y */
int th;
/** component numbers */
int numcomps;
/** number of layer */
int numlayers;
/** number of decomposition for each component */
int *numdecompos;
/* UniPG>> */
/** number of markers */
int marknum;
/** list of markers */
opj_marker_info_t *marker;
/** actual size of markers array */
int maxmarknum;
/* <<UniPG */
/** main header position */
int main_head_start;
/** main header position */
int main_head_end;
/** codestream's size */
int codestream_size;
/** information regarding tiles inside image */
opj_tile_info_t *tile;
} opj_codestream_info_t;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -739,7 +467,7 @@ extern "C" {
========================================================== ==========================================================
*/ */
OPJ_API const char * OPJ_CALLCONV opj_version(void); OPJ_API const char * OPJ_CALLCONV opj_version();
/* /*
========================================================== ==========================================================
@ -843,15 +571,6 @@ Decode an image from a JPEG-2000 codestream
@return Returns a decoded image if successful, returns NULL otherwise @return Returns a decoded image if successful, returns NULL otherwise
*/ */
OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio); OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
/**
Decode an image from a JPEG-2000 codestream and extract the codestream information
@param dinfo decompressor handle
@param cio Input buffer stream
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
@return Returns a decoded image if successful, returns NULL otherwise
*/
OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
/** /**
Creates a J2K/JP2 compression structure Creates a J2K/JP2 compression structure
@param format Coder to select @param format Coder to select
@ -887,35 +606,20 @@ Set encoding parameters to default values, that means :
OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters); OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
/** /**
Setup the encoder parameters using the current image and using user parameters. Setup the encoder parameters using the current image and using user parameters.
@param cinfo Compressor handle @param cinfo compressor handle
@param parameters Compression parameters @param parameters compression parameters
@param image Input filled image @param image input filled image
*/ */
OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image); OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
/** /**
Encode an image into a JPEG-2000 codestream Encode an image into a JPEG-2000 codestream
3@param cinfo compressor handle
@param cio Output buffer stream
@param image Image to encode
@param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
@return Returns true if successful, returns false otherwise
*/
OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
/**
Encode an image into a JPEG-2000 codestream and extract the codestream information
@param cinfo compressor handle @param cinfo compressor handle
@param cio Output buffer stream @param cio Output buffer stream
@param image Image to encode @param image Image to encode
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise @param index Name of the index file if required, NULL otherwise
@return Returns true if successful, returns false otherwise @return Returns true if successful, returns false otherwise
*/ */
OPJ_API opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
/**
Destroy Codestream information after compression or decompression
@param cstr_info Codestream information structure
*/
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,10 +1,5 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,13 +40,13 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <ctype.h> #include <ctype.h>
#include <assert.h>
/* /*
========================================================== ==========================================================
OpenJPEG interface OpenJPEG interface
========================================================== ==========================================================
*/ */
#include "openjp3d.h" #include "openjpeg.h"
/* /*
========================================================== ==========================================================
@ -59,12 +54,31 @@
========================================================== ==========================================================
*/ */
#include "jp3d_lib.h" /*
The inline keyword is supported by C99 but not by C90.
Most compilers implement their own version of this keyword ...
*/
#ifndef INLINE
#if defined(_MSC_VER)
#define INLINE __inline
#elif defined(__GNUC__)
#define INLINE __inline__
#elif defined(__MWERKS__)
#define INLINE inline
#else
/* add other compilers here ... */
#define INLINE
#endif /* defined(<Compiler>) */
#endif /* INLINE */
#include "j2k_lib.h"
#include "event.h" #include "event.h"
#include "cio.h" #include "cio.h"
#include "volume.h" #include "image.h"
#include "jp3d.h" #include "j2k.h"
#include "jp2.h"
#include "jpt.h"
#include "mqc.h" #include "mqc.h"
#include "raw.h" #include "raw.h"
@ -72,7 +86,6 @@
#include "tgt.h" #include "tgt.h"
#include "tcd.h" #include "tcd.h"
#include "t1.h" #include "t1.h"
#include "t1_3d.h"
#include "dwt.h" #include "dwt.h"
#include "pi.h" #include "pi.h"
#include "t2.h" #include "t2.h"
@ -80,4 +93,5 @@
#include "int.h" #include "int.h"
#include "fix.h" #include "fix.h"
#endif /* OPJ_INCLUDES_H */ #endif /* OPJ_INCLUDES_H */

560
libopenjpeg/pi.c Normal file
View File

@ -0,0 +1,560 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, 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 "opj_includes.h"
/** @defgroup PI PI - Implementation of a packet iterator */
/*@{*/
/** @name Local static functions */
/*@{*/
/**
Get next packet in layer-resolution-component-precinct order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_lrcp(opj_pi_iterator_t * pi);
/**
Get next packet in resolution-layer-component-precinct order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_rlcp(opj_pi_iterator_t * pi);
/**
Get next packet in resolution-precinct-component-layer order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_rpcl(opj_pi_iterator_t * pi);
/**
Get next packet in precinct-component-resolution-layer order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_pcrl(opj_pi_iterator_t * pi);
/**
Get next packet in component-precinct-resolution-layer order.
@param pi packet iterator to modify
@return returns false if pi pointed to the last packet or else returns true
*/
static bool pi_next_cprl(opj_pi_iterator_t * pi);
/*@}*/
/*@}*/
/*
==========================================================
local functions
==========================================================
*/
static bool pi_next_lrcp(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
if (!pi->first) {
comp = &pi->comps[pi->compno];
res = &comp->resolutions[pi->resno];
goto LABEL_SKIP;
} else {
pi->first = 0;
}
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
pi->resno++) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
comp = &pi->comps[pi->compno];
if (pi->resno >= comp->numresolutions) {
continue;
}
res = &comp->resolutions[pi->resno];
for (pi->precno = 0; pi->precno < res->pw * res->ph; pi->precno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
return false;
}
static bool pi_next_rlcp(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
if (!pi->first) {
comp = &pi->comps[pi->compno];
res = &comp->resolutions[pi->resno];
goto LABEL_SKIP;
} else {
pi->first = 0;
}
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
comp = &pi->comps[pi->compno];
if (pi->resno >= comp->numresolutions) {
continue;
}
res = &comp->resolutions[pi->resno];
for (pi->precno = 0; pi->precno < res->pw * res->ph; pi->precno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
return false;
}
static bool pi_next_rpcl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
if (!pi->first) {
goto LABEL_SKIP;
} else {
int compno, resno;
pi->first = 0;
pi->dx = 0;
pi->dy = 0;
for (compno = 0; compno < pi->numcomps; compno++) {
comp = &pi->comps[compno];
for (resno = 0; resno < comp->numresolutions; resno++) {
int dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
}
}
}
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
int levelno;
int trx0, try0;
int trx1, try1;
int rpx, rpy;
int prci, prcj;
comp = &pi->comps[pi->compno];
if (pi->resno >= comp->numresolutions) {
continue;
}
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
continue;
}
if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
continue;
}
if ((res->pw==0)||(res->pw==0)) continue;
if ((trx0==trx1)||(try0==try1)) continue;
prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- int_floordivpow2(trx0, res->pdx);
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
}
return false;
}
static bool pi_next_pcrl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
if (!pi->first) {
comp = &pi->comps[pi->compno];
goto LABEL_SKIP;
} else {
int compno, resno;
pi->first = 0;
pi->dx = 0;
pi->dy = 0;
for (compno = 0; compno < pi->numcomps; compno++) {
comp = &pi->comps[compno];
for (resno = 0; resno < comp->numresolutions; resno++) {
int dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
}
}
}
for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
comp = &pi->comps[pi->compno];
for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
int levelno;
int trx0, try0;
int trx1, try1;
int rpx, rpy;
int prci, prcj;
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
continue;
}
if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
continue;
}
if ((res->pw==0)||(res->pw==0)) continue;
if ((trx0==trx1)||(try0==try1)) continue;
prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- int_floordivpow2(trx0, res->pdx);
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
}
return false;
}
static bool pi_next_cprl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
long index = 0;
if (!pi->first) {
comp = &pi->comps[pi->compno];
goto LABEL_SKIP;
} else {
pi->first = 0;
}
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
int resno;
comp = &pi->comps[pi->compno];
pi->dx = 0;
pi->dy = 0;
for (resno = 0; resno < comp->numresolutions; resno++) {
int dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
}
for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
int levelno;
int trx0, try0;
int trx1, try1;
int rpx, rpy;
int prci, prcj;
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
continue;
}
if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
continue;
}
if ((res->pw==0)||(res->pw==0)) continue;
if ((trx0==trx1)||(try0==try1)) continue;
prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- int_floordivpow2(trx0, res->pdx);
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
pi->include[index] = 1;
return true;
}
LABEL_SKIP:;
}
}
}
}
}
return false;
}
/*
==========================================================
Packet iterator interface
==========================================================
*/
opj_pi_iterator_t *pi_create(opj_image_t *image, opj_cp_t *cp, int tileno) {
int p, q;
int compno, resno, pino;
opj_pi_iterator_t *pi = NULL;
opj_tcp_t *tcp = NULL;
opj_tccp_t *tccp = NULL;
size_t array_size;
tcp = &cp->tcps[tileno];
array_size = (tcp->numpocs + 1) * sizeof(opj_pi_iterator_t);
pi = (opj_pi_iterator_t *) opj_malloc(array_size);
if(!pi) {
/* TODO: throw an error */
return NULL;
}
for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */
int maxres = 0;
int maxprec = 0;
p = tileno % cp->tw;
q = tileno / cp->tw;
pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
pi[pino].numcomps = image->numcomps;
array_size = image->numcomps * sizeof(opj_pi_comp_t);
pi[pino].comps = (opj_pi_comp_t *) opj_malloc(array_size);
if(!pi[pino].comps) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
return NULL;
}
memset(pi[pino].comps, 0, array_size);
for (compno = 0; compno < pi->numcomps; compno++) {
int tcx0, tcy0, tcx1, tcy1;
opj_pi_comp_t *comp = &pi[pino].comps[compno];
tccp = &tcp->tccps[compno];
comp->dx = image->comps[compno].dx;
comp->dy = image->comps[compno].dy;
comp->numresolutions = tccp->numresolutions;
array_size = comp->numresolutions * sizeof(opj_pi_resolution_t);
comp->resolutions = (opj_pi_resolution_t *) opj_malloc(array_size);
if(!comp->resolutions) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
return NULL;
}
tcx0 = int_ceildiv(pi->tx0, comp->dx);
tcy0 = int_ceildiv(pi->ty0, comp->dy);
tcx1 = int_ceildiv(pi->tx1, comp->dx);
tcy1 = int_ceildiv(pi->ty1, comp->dy);
if (comp->numresolutions > maxres) {
maxres = comp->numresolutions;
}
for (resno = 0; resno < comp->numresolutions; resno++) {
int levelno;
int rx0, ry0, rx1, ry1;
int px0, py0, px1, py1;
opj_pi_resolution_t *res = &comp->resolutions[resno];
if (tccp->csty & J2K_CCP_CSTY_PRT) {
res->pdx = tccp->prcw[resno];
res->pdy = tccp->prch[resno];
} else {
res->pdx = 15;
res->pdy = 15;
}
levelno = comp->numresolutions - 1 - resno;
rx0 = int_ceildivpow2(tcx0, levelno);
ry0 = int_ceildivpow2(tcy0, levelno);
rx1 = int_ceildivpow2(tcx1, levelno);
ry1 = int_ceildivpow2(tcy1, levelno);
px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx);
res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy);
if (res->pw*res->ph > maxprec) {
maxprec = res->pw*res->ph;
}
}
}
tccp = &tcp->tccps[0];
pi[pino].step_p = 1;
pi[pino].step_c = maxprec * pi[pino].step_p;
pi[pino].step_r = image->numcomps * pi[pino].step_c;
pi[pino].step_l = maxres * pi[pino].step_r;
if (pino == 0) {
array_size = image->numcomps * maxres * tcp->numlayers * maxprec * sizeof(short int);
pi[pino].include = (short int *) opj_malloc(array_size);
if(!pi[pino].include) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
return NULL;
}
}
else {
pi[pino].include = pi[pino - 1].include;
}
if (tcp->POC == 0) {
pi[pino].first = 1;
pi[pino].poc.resno0 = 0;
pi[pino].poc.compno0 = 0;
pi[pino].poc.layno1 = tcp->numlayers;
pi[pino].poc.resno1 = maxres;
pi[pino].poc.compno1 = image->numcomps;
pi[pino].poc.prg = tcp->prg;
} else {
pi[pino].first = 1;
pi[pino].poc.resno0 = tcp->pocs[pino].resno0;
pi[pino].poc.compno0 = tcp->pocs[pino].compno0;
pi[pino].poc.layno1 = tcp->pocs[pino].layno1;
pi[pino].poc.resno1 = tcp->pocs[pino].resno1;
pi[pino].poc.compno1 = tcp->pocs[pino].compno1;
pi[pino].poc.prg = tcp->pocs[pino].prg;
}
}
return pi;
}
void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) {
int compno, pino;
opj_tcp_t *tcp = &cp->tcps[tileno];
if(pi) {
for (pino = 0; pino < tcp->numpocs + 1; pino++) {
if(pi[pino].comps) {
for (compno = 0; compno < pi->numcomps; compno++) {
opj_pi_comp_t *comp = &pi[pino].comps[compno];
if(comp->resolutions) {
opj_free(comp->resolutions);
}
}
opj_free(pi[pino].comps);
}
}
if(pi->include) {
opj_free(pi->include);
}
opj_free(pi);
}
}
bool pi_next(opj_pi_iterator_t * pi) {
switch (pi->poc.prg) {
case LRCP:
return pi_next_lrcp(pi);
case RLCP:
return pi_next_rlcp(pi);
case RPCL:
return pi_next_rpcl(pi);
case PCRL:
return pi_next_pcrl(pi);
case CPRL:
return pi_next_cprl(pi);
case PROG_UNKNOWN:
return false;
}
return false;
}

View File

@ -1,16 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -71,9 +64,7 @@ typedef struct opj_pi_comp {
Packet iterator Packet iterator
*/ */
typedef struct opj_pi_iterator { typedef struct opj_pi_iterator {
/** Enabling Tile part generation*/ /** precise if the packet has been already used (usefull for progression order change) */
char tp_on;
/** precise if the packet has been already used (useful for progression order change) */
short int *include; short int *include;
/** layer step used to localize the packet in the include vector */ /** layer step used to localize the packet in the include vector */
int step_l; int step_l;
@ -95,9 +86,9 @@ typedef struct opj_pi_iterator {
int first; int first;
/** progression order change information */ /** progression order change information */
opj_poc_t poc; opj_poc_t poc;
/** number of components in the image */ /** */
int numcomps; int numcomps;
/** Components*/ /** */
opj_pi_comp_t *comps; opj_pi_comp_t *comps;
int tx0, ty0, tx1, ty1; int tx0, ty0, tx1, ty1;
int x, y, dx, dy; int x, y, dx, dy;
@ -107,37 +98,14 @@ typedef struct opj_pi_iterator {
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
Create a packet iterator for Encoder Create a packet iterator
@param image Raw image for which the packets will be listed
@param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
@return Returns a packet iterator that points to the first packet of the tile
@see pi_destroy
*/
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno,J2K_T2_MODE t2_mode);
/**
Modify the packet iterator for enabling tile part generation
@param pi Handle to the packet iterator generated in pi_initialise_encode
@param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets
@param pino Iterator index for pi
@param tpnum Tile part number of the current tile
@param tppos The position of the tile part flag in the progression order
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
@param cur_totnum_tp The total number of tile parts in the current tile
@return Returns true if an error is detected
*/
opj_bool pi_create_encode(opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp);
/**
Create a packet iterator for Decoder
@param image Raw image for which the packets will be listed @param image Raw image for which the packets will be listed
@param cp Coding parameters @param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets @param tileno Number that identifies the tile for which to list the packets
@return Returns a packet iterator that points to the first packet of the tile @return Returns a packet iterator that points to the first packet of the tile
@see pi_destroy @see pi_destroy
*/ */
opj_pi_iterator_t *pi_create_decode(opj_image_t * image, opj_cp_t * cp, int tileno); opj_pi_iterator_t *pi_create(opj_image_t * image, opj_cp_t * cp, int tileno);
/** /**
Destroy a packet iterator Destroy a packet iterator
@ -153,7 +121,7 @@ Modify the packet iterator to point to the next packet
@param pi Packet iterator to modify @param pi Packet iterator to modify
@return Returns false if pi pointed to the last packet or else returns true @return Returns false if pi pointed to the last packet or else returns true
*/ */
opj_bool pi_next(opj_pi_iterator_t * pi); bool pi_next(opj_pi_iterator_t * pi);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@ -1,11 +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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *

View File

@ -1,14 +1,7 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* BSD License, included below. This software may be subject to other third * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* party and contributor rights, including patent rights, and no such rights * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* 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-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -73,7 +66,7 @@ typedef struct opj_raw {
Create a new RAW handle Create a new RAW handle
@return Returns a new RAW handle if successful, returns NULL otherwise @return Returns a new RAW handle if successful, returns NULL otherwise
*/ */
opj_raw_t* raw_create(void); opj_raw_t* raw_create();
/** /**
Destroy a previously created RAW handle Destroy a previously created RAW handle
@param raw RAW handle to destroy @param raw RAW handle to destroy

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -59,11 +54,11 @@ static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int
/** /**
Encode significant pass Encode significant pass
*/ */
static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty); static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int bpno, int orient, int *nmsedec, char type, int cblksty);
/** /**
Decode significant pass Decode significant pass
*/ */
static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty); static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int bpno, int orient, char type, int cblksty);
/** /**
Encode refinement pass Encode refinement pass
*/ */
@ -75,11 +70,11 @@ static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int
/** /**
Encode refinement pass Encode refinement pass
*/ */
static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty); static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int bpno, int *nmsedec, char type, int cblksty);
/** /**
Decode refinement pass Decode refinement pass
*/ */
static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char type, int cblksty); static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int bpno, char type, int cblksty);
/** /**
Encode clean-up pass Encode clean-up pass
*/ */
@ -91,11 +86,12 @@ static void t1_dec_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int
/** /**
Encode clean-up pass Encode clean-up pass
*/ */
static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty); static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int bpno, int orient, int *nmsedec, int cblksty);
/** /**
Decode clean-up pass Decode clean-up pass
*/ */
static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int cblksty); static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int bpno, int orient, int cblksty);
static double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, double stepsize, int numcomps);
/** /**
Encode 1 code-block Encode 1 code-block
@param t1 T1 handle @param t1 T1 handle
@ -103,13 +99,13 @@ Encode 1 code-block
@param orient @param orient
@param compno Component number @param compno Component number
@param level @param level
@param dwtid @param qmfbid
@param stepsize @param stepsize
@param cblksty Code-block style @param cblksty Code-block style
@param numcomps @param numcomps
@param tile @param tile
*/ */
static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile); static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level, int qmfbid, double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile);
/** /**
Decode 1 code-block Decode 1 code-block
@param t1 T1 handle @param t1 T1 handle
@ -119,7 +115,6 @@ Decode 1 code-block
@param cblksty Code-block style @param cblksty Code-block style
*/ */
static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty); static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty);
static int t1_init_ctxno_zc(int f, int orient); static int t1_init_ctxno_zc(int f, int orient);
static int t1_init_ctxno_sc(int f); static int t1_init_ctxno_sc(int f);
static int t1_init_ctxno_mag(int f); static int t1_init_ctxno_mag(int f);
@ -248,34 +243,30 @@ static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty) { static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int bpno, int orient, int *nmsedec, char type, int cblksty) {
int i, j, k, m, one, vsc; int i, j, k, one, vsc;
*nmsedec = 0; *nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS); one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
for (m = 0; m < l; m++) {
for (k = 0; k < h; k += 4) { for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
for (j = k; j < k + 4 && j < h; j++) { for (j = k; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, bpno, one, nmsedec, type, vsc); t1_enc_sigpass_step(t1, &t1->flags[1 + j][1 + i], &t1->data[j][i], orient, bpno, one, nmsedec, type, vsc);
}
} }
} }
} }
} }
static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty) { static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int bpno, int orient, char type, int cblksty) {
int i, j, k, m, one, half, oneplushalf, vsc; int i, j, k, one, half, oneplushalf, vsc;
one = 1 << bpno; one = 1 << bpno;
half = one >> 1; half = one >> 1;
oneplushalf = one | half; oneplushalf = one | half;
for (m = 0; m < l; m++) {
for (k = 0; k < h; k += 4) { for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
for (j = k; j < k + 4 && j < h; j++) { for (j = k; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, type, vsc); t1_dec_sigpass_step(t1, &t1->flags[1 + j][1 + i], &t1->data[j][i], orient, oneplushalf, type, vsc);
}
} }
} }
} }
@ -322,35 +313,31 @@ static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty) { static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int bpno, int *nmsedec, char type, int cblksty) {
int i, j, k, m, one, vsc; int i, j, k, one, vsc;
*nmsedec = 0; *nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS); one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
for (m = 0; m < l; m++) {
for (k = 0; k < h; k += 4) { for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
for (j = k; j < k + 4 && j < h; j++) { for (j = k; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], bpno, one, nmsedec, type, vsc); t1_enc_refpass_step(t1, &t1->flags[1 + j][1 + i], &t1->data[j][i], bpno, one, nmsedec, type, vsc);
}
} }
} }
} }
} }
static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char type, int cblksty) { static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int bpno, char type, int cblksty) {
int i, j, k, m, one, poshalf, neghalf; int i, j, k, one, poshalf, neghalf;
int vsc; int vsc;
one = 1 << bpno; one = 1 << bpno;
poshalf = one >> 1; poshalf = one >> 1;
neghalf = bpno > 0 ? -poshalf : -1; neghalf = bpno > 0 ? -poshalf : -1;
for (m = 0; m < l; m++) {
for (k = 0; k < h; k += 4) { for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
for (j = k; j < k + 4 && j < h; j++) { for (j = k; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], poshalf, neghalf, type, vsc); t1_dec_refpass_step(t1, &t1->flags[1 + j][1 + i], &t1->data[j][i], poshalf, neghalf, type, vsc);
}
} }
} }
} }
@ -405,35 +392,34 @@ LABEL_PARTIAL:
*fp &= ~T1_VISIT; *fp &= ~T1_VISIT;
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty) { static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int bpno, int orient, int *nmsedec, int cblksty) {
int i, j, k, m, one, agg, runlen, vsc; int i, j, k, one, agg, runlen, vsc;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
*nmsedec = 0; *nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS); one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
for (m = 0; m < l; m++) {
for (k = 0; k < h; k += 4) { for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
if (k + 3 < h) { if (k + 3 < h) {
if (cblksty & J3D_CCP_CBLKSTY_VSC) { if (cblksty & J2K_CCP_CBLKSTY_VSC) {
agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) agg = !(t1->flags[1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) || t1->flags[1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) || t1->flags[1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| (t1->flags[1 + m][1 + k + 3][1 + i] || (t1->flags[1 + k + 3][1 + i]
& (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
} else { } else {
agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) agg = !(t1->flags[1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) || t1->flags[1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) || t1->flags[1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)); || t1->flags[1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH));
} }
} else { } else {
agg = 0; agg = 0;
} }
if (agg) { if (agg) {
for (runlen = 0; runlen < 4; runlen++) { for (runlen = 0; runlen < 4; runlen++) {
if (int_abs(t1->data[m][k + runlen][i]) & one) if (int_abs(t1->data[k + runlen][i]) & one)
break; break;
} }
mqc_setcurctx(mqc, T1_CTXNO_AGG); mqc_setcurctx(mqc, T1_CTXNO_AGG);
@ -448,38 +434,36 @@ static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orie
runlen = 0; runlen = 0;
} }
for (j = k + runlen; j < k + 4 && j < h; j++) { for (j = k + runlen; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_clnpass_step(t1, &(t1->flags[1 + m][1 + j][1 + i]), &(t1->data[m][j][i]), orient, bpno, one, nmsedec, agg && (j == k + runlen), vsc); t1_enc_clnpass_step(t1, &t1->flags[1 + j][1 + i], &t1->data[j][i], orient, bpno, one, nmsedec, agg && (j == k + runlen), vsc);
}
} }
} }
} }
} }
static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int cblksty) { static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int bpno, int orient, int cblksty) {
int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc; int i, j, k, one, half, oneplushalf, agg, runlen, vsc;
int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM; int segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
one = 1 << bpno; one = 1 << bpno;
half = one >> 1; half = one >> 1;
oneplushalf = one | half; oneplushalf = one | half;
for (m = 0; m < l; m++) {
for (k = 0; k < h; k += 4) { for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
if (k + 3 < h) { if (k + 3 < h) {
if (cblksty & J3D_CCP_CBLKSTY_VSC) { if (cblksty & J2K_CCP_CBLKSTY_VSC) {
agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) agg = !(t1->flags[1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) || t1->flags[1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) || t1->flags[1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| (t1->flags[1 + m][1 + k + 3][1 + i] || (t1->flags[1 + k + 3][1 + i]
& (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
} else { } else {
agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) agg = !(t1->flags[1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) || t1->flags[1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) || t1->flags[1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1->flags[1 + m][1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)); || t1->flags[1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH));
} }
} else { } else {
agg = 0; agg = 0;
@ -496,9 +480,8 @@ static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orie
runlen = 0; runlen = 0;
} }
for (j = k + runlen; j < k + 4 && j < h; j++) { for (j = k + runlen; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_clnpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, agg && (j == k + runlen), vsc); t1_dec_clnpass_step(t1, &t1->flags[1 + j][1 + i], &t1->data[j][i], orient, oneplushalf, agg && (j == k + runlen), vsc);
}
} }
} }
} }
@ -518,9 +501,26 @@ static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orie
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile) { /** mod fixed_quality */
int i, j, k; static double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, double stepsize, int numcomps) {
int w, h, l; double w1, w2, wmsedec;
if (qmfbid == 1) {
w1 = (numcomps > 1) ? mct_getnorm(compno) : 1;
w2 = dwt_getnorm(level, orient);
} else { /* if (qmfbid == 0) */
w1 = (numcomps > 1) ? mct_getnorm_real(compno) : 1;
w2 = dwt_getnorm_real(level, orient);
}
wmsedec = w1 * w2 * stepsize * (1 << bpno);
wmsedec *= wmsedec * nmsedec / 8192.0;
return wmsedec;
}
/** mod fixed_quality */
static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level, int qmfbid, double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile) {
int i, j;
int w, h;
int passno; int passno;
int bpno, passtype; int bpno, passtype;
int max; int max;
@ -532,62 +532,58 @@ static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
w = cblk->x1 - cblk->x0; w = cblk->x1 - cblk->x0;
h = cblk->y1 - cblk->y0; h = cblk->y1 - cblk->y0;
l = cblk->z1 - cblk->z0;
max = 0; max = 0;
for (k = 0; k < l; k++) {
for (j = 0; j < h; j++) { for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
max = int_max(max, int_abs(t1->data[k][j][i])); max = int_max(max, int_abs(t1->data[j][i]));
}
}
}
for (k = 0; k <= l; k++) {
for (j = 0; j <= h; j++) {
for (i = 0; i <= w; i++) {
t1->flags[k][j][i] = 0;
}
} }
} }
cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0;
/* Changed by Dmitry Kolyadin */
for (i = 0; i <= w; i++) {
for (j = 0; j <= h; j++) {
t1->flags[j][i] = 0;
}
}
bpno = cblk->numbps - 1; bpno = cblk->numbps - 1;
passtype = 2; passtype = 2;
mqc_reset_enc(mqc); mqc_resetstates(mqc);
mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
mqc_init_enc(mqc, cblk->data); mqc_init_enc(mqc, cblk->data);
for (passno = 0; bpno >= 0; passno++) { for (passno = 0; bpno >= 0; passno++) {
opj_tcd_pass_t *pass = &cblk->passes[passno]; opj_tcd_pass_t *pass = &cblk->passes[passno];
int correction = 3; int correction = 3;
double tmpwmsedec; type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
/*fprintf(stdout,"passno %d passtype %d w %d h %d l %d bpno %d orient %d type %d cblksty %d\n",passno,passtype,w,h,l,bpno,orient,type,cblksty);*/
switch (passtype) { switch (passtype) {
case 0: case 0:
t1_enc_sigpass(t1, w, h, l, bpno, orient, &nmsedec, type, cblksty); t1_enc_sigpass(t1, w, h, bpno, orient, &nmsedec, type, cblksty);
break; break;
case 1: case 1:
t1_enc_refpass(t1, w, h, l, bpno, &nmsedec, type, cblksty); t1_enc_refpass(t1, w, h, bpno, &nmsedec, type, cblksty);
break; break;
case 2: case 2:
/*fprintf(stdout,"w %d h %d l %d bpno %d orient %d \n",w,h,l,bpno,orient);*/ t1_enc_clnpass(t1, w, h, bpno, orient, &nmsedec, cblksty);
t1_enc_clnpass(t1, w, h, l, bpno, orient, &nmsedec, cblksty);
/* code switch SEGMARK (i.e. SEGSYM) */ /* code switch SEGMARK (i.e. SEGSYM) */
if (cblksty & J3D_CCP_CBLKSTY_SEGSYM) if (cblksty & J2K_CCP_CBLKSTY_SEGSYM)
mqc_segmark_enc(mqc); mqc_segmark_enc(mqc);
break; break;
} }
/* fixed_quality */ /* fixed_quality */
tmpwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, stepsize, numcomps, dwtid); cumwmsedec += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps);
cumwmsedec += tmpwmsedec; tile->distotile += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps);
tile->distotile += tmpwmsedec;
/* Code switch "RESTART" (i.e. TERMALL) */ /* Code switch "RESTART" (i.e. TERMALL) */
if ((cblksty & J3D_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { if ((cblksty & J2K_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) {
if (type == T1_TYPE_RAW) { if (type == T1_TYPE_RAW) {
mqc_flush(mqc); mqc_flush(mqc);
correction = 1; correction = 1;
@ -599,7 +595,7 @@ static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
pass->term = 1; pass->term = 1;
} else { } else {
if (((bpno < (cblk->numbps - 4) && (passtype > 0)) if (((bpno < (cblk->numbps - 4) && (passtype > 0))
|| ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) { || ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) {
if (type == T1_TYPE_RAW) { if (type == T1_TYPE_RAW) {
mqc_flush(mqc); mqc_flush(mqc);
correction = 1; correction = 1;
@ -620,7 +616,7 @@ static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
} }
if (pass->term && bpno > 0) { if (pass->term && bpno > 0) {
type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
if (type == T1_TYPE_RAW) if (type == T1_TYPE_RAW)
mqc_bypass_init_enc(mqc); mqc_bypass_init_enc(mqc);
else else
@ -632,21 +628,21 @@ static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate);
/* Code-switch "RESET" */ /* Code-switch "RESET" */
if (cblksty & J3D_CCP_CBLKSTY_RESET) if (cblksty & J2K_CCP_CBLKSTY_RESET)
mqc_reset_enc(mqc); mqc_reset_enc(mqc);
} }
/* Code switch "ERTERM" (i.e. PTERM) */ /* Code switch "ERTERM" (i.e. PTERM) */
if (cblksty & J3D_CCP_CBLKSTY_PTERM) if (cblksty & J2K_CCP_CBLKSTY_PTERM)
mqc_erterm_enc(mqc); mqc_erterm_enc(mqc);
else /* Default coding */ if (!(cblksty & J3D_CCP_CBLKSTY_LAZY)) else /* Default coding */ if (!(cblksty & J2K_CCP_CBLKSTY_LAZY))
mqc_flush(mqc); mqc_flush(mqc);
cblk->totalpasses = passno; cblk->totalpasses = passno;
} }
static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty) { static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty) {
int i, j, k, w, h, l; int i, j, w, h;
int bpno, passtype; int bpno, passtype;
int segno, passno; int segno, passno;
char type = T1_TYPE_MQ; /* BYPASS mode */ char type = T1_TYPE_MQ; /* BYPASS mode */
@ -656,34 +652,34 @@ static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
w = cblk->x1 - cblk->x0; w = cblk->x1 - cblk->x0;
h = cblk->y1 - cblk->y0; h = cblk->y1 - cblk->y0;
l = cblk->z1 - cblk->z0;
for (k = 0; k < l; k++) { /* Changed by Dmitry Kolyadin */
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
t1->data[k][j][i] = 0;
}
}
}
for (k = 0; k <= l; k++) {
for (j = 0; j <= h; j++) { for (j = 0; j <= h; j++) {
for (i = 0; i <= w; i++) { for (i = 0; i <= w; i++) {
t1->flags[k][j][i] = 0; t1->flags[j][i] = 0;
} }
} }
/* Changed by Dmitry Kolyadin */
for (i = 0; i < w; i++) {
for (j = 0; j < h; j++){
t1->data[j][i] = 0;
}
} }
bpno = roishift + cblk->numbps - 1; bpno = roishift + cblk->numbps - 1;
passtype = 2; passtype = 2;
mqc_reset_enc(mqc); mqc_resetstates(mqc);
mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
for (segno = 0; segno < cblk->numsegs; segno++) { for (segno = 0; segno < cblk->numsegs; segno++) {
opj_tcd_seg_t *seg = &cblk->segs[segno]; opj_tcd_seg_t *seg = &cblk->segs[segno];
/* BYPASS mode */ /* BYPASS mode */
type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
if (type == T1_TYPE_RAW) { if (type == T1_TYPE_RAW) {
raw_init_dec(raw, seg->data, seg->len); raw_init_dec(raw, seg->data, seg->len);
} else { } else {
@ -693,18 +689,21 @@ static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
for (passno = 0; passno < seg->numpasses; passno++) { for (passno = 0; passno < seg->numpasses; passno++) {
switch (passtype) { switch (passtype) {
case 0: case 0:
t1_dec_sigpass(t1, w, h, l, bpno+1, orient, type, cblksty); t1_dec_sigpass(t1, w, h, bpno+1, orient, type, cblksty);
break; break;
case 1: case 1:
t1_dec_refpass(t1, w, h, l, bpno+1, type, cblksty); t1_dec_refpass(t1, w, h, bpno+1, type, cblksty);
break; break;
case 2: case 2:
t1_dec_clnpass(t1, w, h, l, bpno+1, orient, cblksty); t1_dec_clnpass(t1, w, h, bpno+1, orient, cblksty);
break; break;
} }
if ((cblksty & J3D_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) {
mqc_reset_enc(mqc); mqc_resetstates(mqc);
mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
} }
if (++passtype == 3) { if (++passtype == 3) {
passtype = 0; passtype = 0;
@ -928,122 +927,77 @@ void t1_destroy(opj_t1_t *t1) {
/* destroy MQC and RAW handles */ /* destroy MQC and RAW handles */
mqc_destroy(t1->mqc); mqc_destroy(t1->mqc);
raw_destroy(t1->raw); raw_destroy(t1->raw);
/*opj_free(t1->data);*/
/*opj_free(t1->flags);*/
opj_free(t1); opj_free(t1);
} }
} }
void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
int compno, resno, bandno, precno, cblkno; int compno, resno, bandno, precno, cblkno;
int x, y, z, i, j, k, orient; int x, y, i, j, orient;
int n=0;
int level[3];
FILE *fid = NULL;
/* char filename[10];*/
tile->distotile = 0; /* fixed_quality */ tile->distotile = 0; /* fixed_quality */
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
for (resno = 0; resno < tilec->numresolution[0]; resno++) { for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno]; opj_tcd_resolution_t *res = &tilec->resolutions[resno];
/* Weighted first order entropy
sprintf(filename,"res%d.txt",resno);
if ((fid = fopen(filename,"w")) == 0){
fprintf(stdout,"Error while opening %s\n", filename);
exit(1);
}
*/
for (bandno = 0; bandno < res->numbands; bandno++) { for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno]; opj_tcd_band_t *band = &res->bands[bandno];
for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) {
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
/*fprintf(stdout,"Precno %d Cblkno %d \n",precno,cblkno);*/
if (band->bandno == 0) { if (band->bandno == 0) {
x = cblk->x0 - band->x0; x = cblk->x0 - band->x0;
y = cblk->y0 - band->y0; y = cblk->y0 - band->y0;
z = cblk->z0 - band->z0;
} else if (band->bandno == 1) { } else if (band->bandno == 1) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0; x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = cblk->y0 - band->y0; y = cblk->y0 - band->y0;
z = cblk->z0 - band->z0;
} else if (band->bandno == 2) { } else if (band->bandno == 2) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0; x = cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0; y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
z = cblk->z0 - band->z0; } else { /* if (band->bandno == 3) */
} else if (band->bandno == 3) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0; x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0; y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
z = cblk->z0 - band->z0;
} else if (band->bandno == 4) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
z = pres->z1 - pres->z0 + cblk->z0 - band->z0;
} else if (band->bandno == 5) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
z = pres->z1 - pres->z0 + cblk->z0 - band->z0;
} else if (band->bandno == 6) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
z = pres->z1 - pres->z0 + cblk->z0 - band->z0;
} else if (band->bandno == 7) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
z = pres->z1 - pres->z0 + cblk->z0 - band->z0;
} }
if (tcp->tccps[compno].reversible == 1) { if (tcp->tccps[compno].qmfbid == 1) {
for (k = 0; k < cblk->z1 - cblk->z0; k++) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
t1->data[k][j][i] = t1->data[j][i] =
tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] << T1_NMSEDEC_FRACBITS; tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0)] << T1_NMSEDEC_FRACBITS;
/*fprintf(fid," %d",t1->data[k][j][i]);*/
} }
} }
} } else if (tcp->tccps[compno].qmfbid == 0) {
} else if (tcp->tccps[compno].reversible == 0) {
for (k = 0; k < cblk->z1 - cblk->z0; k++) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
t1->data[k][j][i] = fix_mul( t1->data[j][i] =
tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)], fix_mul(
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)],
8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS); 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS);
} }
} }
} }
}
orient = band->bandno; /* FIXME */ orient = band->bandno; /* FIXME */
if (orient == 2) { if (orient == 2) {
orient = 1; orient = 1;
} else if (orient == 1) { } else if (orient == 1) {
orient = 2; orient = 2;
} }
for (i = 0; i < 3; i++)
level[i] = tilec->numresolution[i] - 1 - resno; t1_encode_cblk(t1, cblk, orient, compno, tilec->numresolutions - 1 - resno, tcp->tccps[compno].qmfbid, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps, tile);
/*fprintf(stdout,"t1_encode_cblk(t1, cblk, %d, %d, %d %d %d, %d, %f, %d, %d, tile);\n", orient, compno, level[0], level[1], level[2], tcp->tccps[compno].reversible, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps);*/
t1_encode_cblk(t1, cblk, orient, compno, level, tcp->tccps[compno].dwtid, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps, tile);
} /* cblkno */ } /* cblkno */
} /* precno */ } /* precno */
/*fprintf(fid,"\n");*/
} /* bandno */ } /* bandno */
/*fclose(fid);*/
} /* resno */ } /* resno */
} /* compno */ } /* compno */
} }
@ -1054,17 +1008,17 @@ void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
for (resno = 0; resno < tilec->numresolution[0]; resno++) { for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno]; opj_tcd_resolution_t *res = &tilec->resolutions[resno];
for (bandno = 0; bandno < res->numbands; bandno++) { for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno]; opj_tcd_band_t *band = &res->bands[bandno];
for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int x, y, k, i, j, z, orient; int x, y, i, j, orient;
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
orient = band->bandno; /* FIXME */ orient = band->bandno; /* FIXME */
@ -1079,81 +1033,51 @@ void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
if (band->bandno == 0) { if (band->bandno == 0) {
x = cblk->x0 - band->x0; x = cblk->x0 - band->x0;
y = cblk->y0 - band->y0; y = cblk->y0 - band->y0;
z = cblk->z0 - band->z0;
} else if (band->bandno == 1) { } else if (band->bandno == 1) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0; x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = cblk->y0 - band->y0; y = cblk->y0 - band->y0;
z = cblk->z0 - band->z0;
} else if (band->bandno == 2) { } else if (band->bandno == 2) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0; x = cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0; y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
z = cblk->z0 - band->z0; } else { /* if (band->bandno == 3) */
} else if (band->bandno == 3) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0; x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0; y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
z = cblk->z0 - band->z0;
} else if (band->bandno == 4) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
z = pres->z1 - pres->z0 + cblk->z0 - band->z0;
} else if (band->bandno == 5) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
z = pres->z1 - pres->z0 + cblk->z0 - band->z0;
} else if (band->bandno == 6) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
z = pres->z1 - pres->z0 + cblk->z0 - band->z0;
} else if (band->bandno == 7) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
z = pres->z1 - pres->z0 + cblk->z0 - band->z0;
} }
if (tcp->tccps[compno].roishift) { if (tcp->tccps[compno].roishift) {
int thresh, val, mag; int thresh, val, mag;
thresh = 1 << tcp->tccps[compno].roishift; thresh = 1 << tcp->tccps[compno].roishift;
for (k = 0; k < cblk->z1 - cblk->z0; k++) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
val = t1->data[k][j][i]; val = t1->data[j][i];
mag = int_abs(val); mag = int_abs(val);
if (mag >= thresh) { if (mag >= thresh) {
mag >>= tcp->tccps[compno].roishift; mag >>= tcp->tccps[compno].roishift;
t1->data[k][j][i] = val < 0 ? -mag : mag; t1->data[j][i] = val < 0 ? -mag : mag;
}
} }
} }
} }
} }
if (tcp->tccps[compno].reversible == 1) { if (tcp->tccps[compno].qmfbid == 1) {
for (k = 0; k < cblk->z1 - cblk->z0; k++) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
int tmp = t1->data[k][j][i]; int tmp = t1->data[j][i];
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = tmp/2; tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = tmp/2;
} }
} }
} } else { /* if (tcp->tccps[compno].qmfbid == 0) */
} else { /* if (tcp->tccps[compno].reversible == 0) */
for (k = 0; k < cblk->z1 - cblk->z0; k++) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
double tmp = (double)(t1->data[k][j][i] * band->stepsize * 4096.0); double tmp = (double)(t1->data[j][i] * band->stepsize * 4096.0);
if (t1->data[k][j][i] >> 1 == 0) { if (t1->data[j][i] >> 1 == 0) {
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = 0; tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = 0;
} else { } else {
int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2); int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2);
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = ((tmp<0)?-tmp2:tmp2); tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = ((tmp<0)?-tmp2:tmp2);
}
} }
} }
} }
@ -1165,22 +1089,3 @@ void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
} /* compno */ } /* compno */
} }
/** mod fixed_quality */
double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3]) {
double w1, w2, wmsedec;
if (dwtid[0] == 1 || dwtid[1] == 1 || dwtid[2] == 1) {
w1 = (numcomps > 1) ? mct_getnorm_real(compno) : 1;
} else {
w1 = (numcomps > 1) ? mct_getnorm(compno) : 1;
}
w2 = dwt_getnorm(orient, level, dwtid);
/*fprintf(stdout,"nmsedec %d level %d %d %d orient %d bpno %d stepsize %f \n",nmsedec ,level[0],level[1],level[2],orient,bpno,stepsize);*/
wmsedec = w1 * w2 * stepsize * (1 << bpno);
wmsedec *= wmsedec * nmsedec / 8192.0;
return wmsedec;
}
/** mod fixed_quality */

View File

@ -1,16 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -50,6 +43,9 @@ in T1.C are used by some function in TCD.C.
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
#define T1_NMSEDEC_BITS 7 #define T1_NMSEDEC_BITS 7
#define T1_MAXCBLKW 1024 /**< Maximum size of code-block (width) */
#define T1_MAXCBLKH 1024 /**< Maximum size of code-block (heigth) */
#define T1_SIG_NE 0x0001 /**< Context orientation : North-East direction */ #define T1_SIG_NE 0x0001 /**< Context orientation : North-East direction */
#define T1_SIG_SE 0x0002 /**< Context orientation : South-East direction */ #define T1_SIG_SE 0x0002 /**< Context orientation : South-East direction */
#define T1_SIG_SW 0x0004 /**< Context orientation : South-West direction */ #define T1_SIG_SW 0x0004 /**< Context orientation : South-West direction */
@ -71,17 +67,17 @@ in T1.C are used by some function in TCD.C.
#define T1_REFINE 0x2000 #define T1_REFINE 0x2000
#define T1_VISIT 0x4000 #define T1_VISIT 0x4000
#define T1_NUMCTXS_ZC 9
#define T1_NUMCTXS_SC 5
#define T1_NUMCTXS_MAG 3
#define T1_NUMCTXS_AGG 1 #define T1_NUMCTXS_AGG 1
#define T1_NUMCTXS_ZC 9
#define T1_NUMCTXS_MAG 3
#define T1_NUMCTXS_SC 5
#define T1_NUMCTXS_UNI 1 #define T1_NUMCTXS_UNI 1
#define T1_CTXNO_ZC 0 #define T1_CTXNO_AGG 0
#define T1_CTXNO_SC (T1_CTXNO_ZC+T1_NUMCTXS_ZC) #define T1_CTXNO_ZC (T1_CTXNO_AGG+T1_NUMCTXS_AGG)
#define T1_CTXNO_MAG (T1_CTXNO_SC+T1_NUMCTXS_SC) #define T1_CTXNO_MAG (T1_CTXNO_ZC+T1_NUMCTXS_ZC)
#define T1_CTXNO_AGG (T1_CTXNO_MAG+T1_NUMCTXS_MAG) #define T1_CTXNO_SC (T1_CTXNO_MAG+T1_NUMCTXS_MAG)
#define T1_CTXNO_UNI (T1_CTXNO_AGG+T1_NUMCTXS_AGG) #define T1_CTXNO_UNI (T1_CTXNO_SC+T1_NUMCTXS_SC)
#define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI) #define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI)
#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1) #define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1)
@ -91,8 +87,6 @@ in T1.C are used by some function in TCD.C.
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
typedef short flag_t;
/** /**
Tier-1 coding (coding of code-block coefficients) Tier-1 coding (coding of code-block coefficients)
*/ */
@ -105,16 +99,19 @@ typedef struct opj_t1 {
/** RAW component */ /** RAW component */
opj_raw_t *raw; opj_raw_t *raw;
int *data; int lut_ctxno_zc[1024];
flag_t *flags; int lut_ctxno_sc[256];
int w; int lut_ctxno_mag[4096];
int h; int lut_spb[256];
int datasize; int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int flagssize; int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int flags_stride; int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
} opj_t1_t; int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
#define MACRO_t1_flags(x,y) t1->flags[((x)*(t1->flags_stride))+(y)] int data[T1_MAXCBLKH][T1_MAXCBLKW];
int flags[T1_MAXCBLKH + 2][T1_MAXCBLKH + 2];
} opj_t1_t;
/** @name Exported functions */ /** @name Exported functions */
/*@{*/ /*@{*/
@ -141,10 +138,10 @@ void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/** /**
Decode the code-blocks of a tile Decode the code-blocks of a tile
@param t1 T1 handle @param t1 T1 handle
@param tilec The tile to decode @param tile The tile to decode
@param tccp Tile coding parameters @param tcp Tile coding parameters
*/ */
void t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp); void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@ -1,13 +1,8 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
@ -57,17 +52,15 @@ Encode a packet of a tile to a destination buffer
@param pi Packet identity @param pi Packet identity
@param dest Destination buffer @param dest Destination buffer
@param len Length of the destination buffer @param len Length of the destination buffer
@param volume_info Structure to create an index file @param image_info Structure to create an index file
@param tileno Number of the tile encoded @param tileno Number of the tile encoded
@param cp Coding parameters @return
@return Number of bytes encoded from the packet
*/ */
static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_volume_info_t *volume_info, int tileno, opj_cp_t *cp); static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_image_info_t *image_info, int tileno);
/** /**
Initialize the segment decoder @param seg
@param seg Segment instance @param cblksty
@param cblksty Codeblock style @param first
@param first Is first segment
*/ */
static void t2_init_seg(opj_tcd_seg_t *seg, int cblksty, int first); static void t2_init_seg(opj_tcd_seg_t *seg, int cblksty, int first);
/** /**
@ -78,9 +71,9 @@ Decode a packet of a tile from a source buffer
@param tile Tile for which to write the packets @param tile Tile for which to write the packets
@param tcp Tile coding parameters @param tcp Tile coding parameters
@param pi Packet identity @param pi Packet identity
@return Number of bytes decoded from the packet @return
*/ */
int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi); static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi);
/*@}*/ /*@}*/
@ -89,6 +82,7 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* #define RESTART 0x04 */ /* #define RESTART 0x04 */
static void t2_putcommacode(opj_bio_t *bio, int n) { static void t2_putcommacode(opj_bio_t *bio, int n) {
while (--n >= 0) { while (--n >= 0) {
bio_write(bio, 1, 1); bio_write(bio, 1, 1);
@ -131,7 +125,7 @@ static int t2_getnumpasses(opj_bio_t *bio) {
return (37 + bio_read(bio, 7)); return (37 + bio_read(bio, 7));
} }
static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_volume_info_t * volume_info, int tileno, opj_cp_t *cp) { static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int length, opj_image_info_t * image_info, int tileno) {
int bandno, cblkno; int bandno, cblkno;
unsigned char *sop = 0, *eph = 0; unsigned char *sop = 0, *eph = 0;
unsigned char *c = dest; unsigned char *c = dest;
@ -147,14 +141,14 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
opj_bio_t *bio = NULL; /* BIO component */ opj_bio_t *bio = NULL; /* BIO component */
/* <SOP 0xff91> */ /* <SOP 0xff91> */
if ((tcp->csty & J3D_CP_CSTY_SOP)) { if (tcp->csty & J2K_CP_CSTY_SOP) {
sop = (unsigned char *) opj_malloc(6 * sizeof(unsigned char)); sop = (unsigned char *) opj_malloc(6 * sizeof(unsigned char));
sop[0] = 255; sop[0] = 255;
sop[1] = 145; sop[1] = 145;
sop[2] = 0; sop[2] = 0;
sop[3] = 4; sop[3] = 4;
sop[4] = (volume_info) ? (volume_info->num % 65536) / 256 : (0 % 65536) / 256 ; sop[4] = (image_info->num % 65536) / 256;
sop[5] = (volume_info) ? (volume_info->num % 65536) % 256 : (0 % 65536) % 256 ; sop[5] = (image_info->num % 65536) % 256;
memcpy(c, sop, 6); memcpy(c, sop, 6);
opj_free(sop); opj_free(sop);
c += 6; c += 6;
@ -167,7 +161,7 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
tgt_reset(prc->incltree); tgt_reset(prc->incltree);
tgt_reset(prc->imsbtree); tgt_reset(prc->imsbtree);
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
cblk->numpasses = 0; cblk->numpasses = 0;
tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps);
@ -176,22 +170,21 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
} }
bio = bio_create(); bio = bio_create();
bio_init_enc(bio, c, len); bio_init_enc(bio, c, length);
bio_write(bio, 1, 1); /* Empty header bit */ bio_write(bio, 1, 1); /* Empty header bit */
/* Writing Packet header */ /* Writing Packet header */
for (bandno = 0; bandno < res->numbands; bandno++) { for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno]; opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno]; opj_tcd_layer_t *layer = &cblk->layers[layno];
if (!cblk->numpasses && layer->numpasses) { if (!cblk->numpasses && layer->numpasses) {
tgt_setvalue(prc->incltree, cblkno, layno); tgt_setvalue(prc->incltree, cblkno, layno);
} }
} }
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) {
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno]; opj_tcd_layer_t *layer = &cblk->layers[layno];
int increment = 0; int increment = 0;
@ -242,11 +235,9 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
nump = 0; nump = 0;
} }
} }
} }
} }
if (bio_flush(bio)) { if (bio_flush(bio)) {
return -999; /* modified to eliminate longjmp !! */ return -999; /* modified to eliminate longjmp !! */
} }
@ -256,7 +247,7 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
bio_destroy(bio); bio_destroy(bio);
/* <EPH 0xff92> */ /* <EPH 0xff92> */
if (tcp->csty & J3D_CP_CSTY_EPH) { if (tcp->csty & J2K_CP_CSTY_EPH) {
eph = (unsigned char *) opj_malloc(2 * sizeof(unsigned char)); eph = (unsigned char *) opj_malloc(2 * sizeof(unsigned char));
eph[0] = 255; eph[0] = 255;
eph[1] = 146; eph[1] = 146;
@ -271,13 +262,13 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
for (bandno = 0; bandno < res->numbands; bandno++) { for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno]; opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno]; opj_tcd_layer_t *layer = &cblk->layers[layno];
if (!layer->numpasses) { if (!layer->numpasses) {
continue; continue;
} }
if (c + layer->len > dest + len) { if (c + layer->len > dest + length) {
return -999; return -999;
} }
@ -285,12 +276,12 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
cblk->numpasses += layer->numpasses; cblk->numpasses += layer->numpasses;
c += layer->len; c += layer->len;
/* ADD for index Cfr. Marcela --> delta disto by packet */ /* ADD for index Cfr. Marcela --> delta disto by packet */
if(volume_info && volume_info->index_write && volume_info->index_on) { if(image_info && image_info->index_write && image_info->index_on) {
opj_tile_info_t *info_TL = &volume_info->tile[tileno]; opj_tile_info_t *info_TL = &image_info->tile[tileno];
opj_packet_info_t *info_PK = &info_TL->packet[volume_info->num]; opj_packet_info_t *info_PK = &info_TL->packet[image_info->num];
info_PK->disto += layer->disto; info_PK->disto += layer->disto;
if (volume_info->D_max < info_PK->disto) { if (image_info->D_max < info_PK->disto) {
volume_info->D_max = info_PK->disto; image_info->D_max = info_PK->disto;
} }
} }
/* </ADD> */ /* </ADD> */
@ -303,10 +294,10 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first) { static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first) {
seg->numpasses = 0; seg->numpasses = 0;
seg->len = 0; seg->len = 0;
if (cblksty & J3D_CCP_CBLKSTY_TERMALL) { if (cblksty & J2K_CCP_CBLKSTY_TERMALL) {
seg->maxpasses = 1; seg->maxpasses = 1;
} }
else if (cblksty & J3D_CCP_CBLKSTY_LAZY) { else if (cblksty & J2K_CCP_CBLKSTY_LAZY) {
if (first) { if (first) {
seg->maxpasses = 10; seg->maxpasses = 10;
} else { } else {
@ -317,7 +308,7 @@ static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first) {
} }
} }
int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi) { static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi) {
int bandno, cblkno; int bandno, cblkno;
unsigned char *c = src; unsigned char *c = src;
@ -341,11 +332,11 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
opj_tcd_band_t *band = &res->bands[bandno]; opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
tgt_reset(prc->incltree); tgt_reset(prc->incltree);
tgt_reset(prc->imsbtree); tgt_reset(prc->imsbtree);
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
cblk->numsegs = 0; cblk->numsegs = 0;
} }
@ -354,7 +345,7 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
/* SOP markers */ /* SOP markers */
if (tcp->csty & J3D_CP_CSTY_SOP) { if (tcp->csty & J2K_CP_CSTY_SOP) {
if ((*c) != 0xff || (*(c + 1) != 0x91)) { if ((*c) != 0xff || (*(c + 1) != 0x91)) {
opj_event_msg(t2->cinfo, EVT_WARNING, "Expected SOP marker\n"); opj_event_msg(t2->cinfo, EVT_WARNING, "Expected SOP marker\n");
} else { } else {
@ -393,7 +384,7 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
/* EPH markers */ /* EPH markers */
if (tcp->csty & J3D_CP_CSTY_EPH) { if (tcp->csty & J2K_CP_CSTY_EPH) {
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
printf("Error : expected EPH marker\n"); printf("Error : expected EPH marker\n");
} else { } else {
@ -419,9 +410,9 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
opj_tcd_band_t *band = &res->bands[bandno]; opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int included, increment, n; int included, increment, n;
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
opj_tcd_seg_t *seg = NULL; opj_tcd_seg_t *seg = NULL;
@ -440,7 +431,9 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
/* if cblk not yet included --> zero-bitplane tagtree */ /* if cblk not yet included --> zero-bitplane tagtree */
if (!cblk->numsegs) { if (!cblk->numsegs) {
int i, numimsbs; int i, numimsbs;
for (i = 0; !tgt_decode(bio, prc->imsbtree, cblkno, i); i++); for (i = 0; !tgt_decode(bio, prc->imsbtree, cblkno, i); i++) {
;
}
numimsbs = i - 1; numimsbs = i - 1;
cblk->numbps = band->numbps - numimsbs; cblk->numbps = band->numbps - numimsbs;
cblk->numlenbits = 3; cblk->numlenbits = 3;
@ -481,10 +474,9 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
bio_destroy(bio); bio_destroy(bio);
/* EPH markers */ /* EPH markers */
if (tcp->csty & J3D_CP_CSTY_EPH) { if (tcp->csty & J2K_CP_CSTY_EPH) {
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n"); opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n");
return -999;
} else { } else {
hd += 2; hd += 2;
} }
@ -504,9 +496,9 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
opj_tcd_band_t *band = &res->bands[bandno]; opj_tcd_band_t *band = &res->bands[bandno];
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
opj_tcd_seg_t *seg = NULL; opj_tcd_seg_t *seg = NULL;
if (!cblk->numnewpasses) if (!cblk->numnewpasses)
@ -550,31 +542,30 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info) { int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info) {
unsigned char *c = dest; unsigned char *c = dest;
int e = 0; int e = 0;
opj_pi_iterator_t *pi = NULL; opj_pi_iterator_t *pi = NULL;
int pino; int pino;
opj_volume_t *volume = t2->volume; opj_image_t *image = t2->image;
opj_cp_t *cp = t2->cp; opj_cp_t *cp = t2->cp;
/* create a packet iterator */ /* create a packet iterator */
pi = pi_create(volume, cp, tileno); pi = pi_create(image, cp, tileno);
if(!pi) { if(!pi) {
fprintf(stdout,"[ERROR] Failed to create a pi structure\n"); /* TODO: throw an error */
return -999; return -999;
} }
if(volume_info) { if(image_info) {
volume_info->num = 0; image_info->num = 0;
} }
for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) { for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
while (pi_next(&pi[pino])) { while (pi_next(&pi[pino])) {
if (pi[pino].layno < maxlayers) { if (pi[pino].layno < maxlayers) {
e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, volume_info, tileno, cp); e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, image_info, tileno);
/*opj_event_msg(t2->cinfo, EVT_INFO, " t2_encode_packet: %d bytes coded\n",e);*/
if (e == -999) { if (e == -999) {
break; break;
} else { } else {
@ -582,19 +573,19 @@ int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlay
} }
/* INDEX >> */ /* INDEX >> */
if(volume_info && volume_info->index_on) { if(image_info && image_info->index_on) {
if(volume_info->index_write) { if(image_info->index_write) {
opj_tile_info_t *info_TL = &volume_info->tile[tileno]; opj_tile_info_t *info_TL = &image_info->tile[tileno];
opj_packet_info_t *info_PK = &info_TL->packet[volume_info->num]; opj_packet_info_t *info_PK = &info_TL->packet[image_info->num];
if (!volume_info->num) { if (!image_info->num) {
info_PK->start_pos = info_TL->end_header + 1; info_PK->start_pos = info_TL->end_header + 1;
} else { } else {
info_PK->start_pos = info_TL->packet[volume_info->num - 1].end_pos + 1; info_PK->start_pos = info_TL->packet[image_info->num - 1].end_pos + 1;
} }
info_PK->end_pos = info_PK->start_pos + e - 1; info_PK->end_pos = info_PK->start_pos + e - 1;
} }
volume_info->num++; image_info->num++;
} }
/* << INDEX */ /* << INDEX */
} }
@ -615,13 +606,13 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
unsigned char *c = src; unsigned char *c = src;
opj_pi_iterator_t *pi; opj_pi_iterator_t *pi;
int pino, e = 0; int pino, e = 0;
int n = 0,i; int n = 0;
opj_volume_t *volume = t2->volume; opj_image_t *image = t2->image;
opj_cp_t *cp = t2->cp; opj_cp_t *cp = t2->cp;
/* create a packet iterator */ /* create a packet iterator */
pi = pi_create(volume, cp, tileno); pi = pi_create(image, cp, tileno);
if(!pi) { if(!pi) {
/* TODO: throw an error */ /* TODO: throw an error */
return -999; return -999;
@ -636,15 +627,15 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
} }
/* progression in resolution */ /* progression in resolution */
for (i = 0; i < 3; i++){ image->comps[pi[pino].compno].resno_decoded =
volume->comps[pi[pino].compno].resno_decoded[i] = (e > 0) ? int_max(pi[pino].resno, volume->comps[pi[pino].compno].resno_decoded[i]) : volume->comps[pi[pino].compno].resno_decoded[i]; (e > 0) ?
} int_max(pi[pino].resno, image->comps[pi[pino].compno].resno_decoded)
: image->comps[pi[pino].compno].resno_decoded;
n++; n++;
if (e == -999) { /* ADD */ if (e == -999) { /* ADD */
break; break;
} else { } else {
opj_event_msg(t2->cinfo, EVT_INFO, " t2_decode_packet: %d bytes decoded\n",e);
c += e; c += e;
} }
} }
@ -662,12 +653,12 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp) { opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp) {
/* create the tcd structure */ /* create the tcd structure */
opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t)); opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t));
if(!t2) return NULL; if(!t2) return NULL;
t2->cinfo = cinfo; t2->cinfo = cinfo;
t2->volume = volume; t2->image = image;
t2->cp = cp; t2->cp = cp;
return t2; return t2;

View File

@ -1,15 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * 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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -48,15 +42,16 @@
Tier-2 coding Tier-2 coding
*/ */
typedef struct opj_t2 { typedef struct opj_t2 {
/** Codec context */ /** codec context */
opj_common_ptr cinfo; opj_common_ptr cinfo;
/** Encoding: pointer to the src volume. Decoding: pointer to the dst volume. */
opj_volume_t *volume; /** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
/** Pointer to the volume coding parameters */ opj_image_t *image;
/** pointer to the image coding parameters */
opj_cp_t *cp; opj_cp_t *cp;
} opj_t2_t; } opj_t2_t;
/** @name Funciones generales */ /** @name Exported functions */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@ -68,10 +63,9 @@ Encode the packets of a tile to a destination buffer
@param maxlayers maximum number of layers @param maxlayers maximum number of layers
@param dest the destination buffer @param dest the destination buffer
@param len the length of the destination buffer @param len the length of the destination buffer
@param volume_info structure to create an index file @param image_info structure to create an index file
@return Number of bytes written from packets
*/ */
int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info); int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info);
/** /**
Decode the packets of a tile from a source buffer Decode the packets of a tile from a source buffer
@ -80,18 +74,17 @@ Decode the packets of a tile from a source buffer
@param len length of the source buffer @param len length of the source buffer
@param tileno number that identifies the tile for which to decode the packets @param tileno number that identifies the tile for which to decode the packets
@param tile tile for which to decode the packets @param tile tile for which to decode the packets
@return Number of bytes read from packets
*/ */
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile); int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile);
/** /**
Create a T2 handle Create a T2 handle
@param cinfo Codec context info @param cinfo Codec context info
@param volume Source or destination volume @param image Source or destination image
@param cp Volume coding parameters @param cp Image coding parameters
@return Returns a new T2 handle if successful, returns NULL otherwise @return Returns a new T2 handle if successful, returns NULL otherwise
*/ */
opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp); opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp);
/** /**
Destroy a T2 handle Destroy a T2 handle
@param t2 T2 handle to destroy @param t2 T2 handle to destroy

View File

@ -1,17 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -36,11 +28,10 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#define _ISOC99_SOURCE /* lrintf is C99 */
#include "opj_includes.h" #include "opj_includes.h"
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) { void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) {
int tileno, compno, resno, bandno, precno;/*, cblkno;*/ int tileno, compno, resno, bandno, precno, cblkno;
fprintf(fd, "image {\n"); fprintf(fd, "image {\n");
fprintf(fd, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", fprintf(fd, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n",
@ -75,7 +66,6 @@ void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) {
fprintf(fd, fprintf(fd,
" x0=%d, y0=%d, x1=%d, y1=%d, cw=%d, ch=%d\n", " x0=%d, y0=%d, x1=%d, y1=%d, cw=%d, ch=%d\n",
prec->x0, prec->y0, prec->x1, prec->y1, prec->cw, prec->ch); prec->x0, prec->y0, prec->x1, prec->y1, prec->cw, prec->ch);
/*
for (cblkno = 0; cblkno < prec->cw * prec->ch; cblkno++) { for (cblkno = 0; cblkno < prec->cw * prec->ch; cblkno++) {
opj_tcd_cblk_t *cblk = &prec->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prec->cblks[cblkno];
fprintf(fd, " cblk {\n"); fprintf(fd, " cblk {\n");
@ -84,7 +74,6 @@ void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) {
cblk->x0, cblk->y0, cblk->x1, cblk->y1); cblk->x0, cblk->y0, cblk->x1, cblk->y1);
fprintf(fd, " }\n"); fprintf(fd, " }\n");
} }
*/
fprintf(fd, " }\n"); fprintf(fd, " }\n");
} }
fprintf(fd, " }\n"); fprintf(fd, " }\n");
@ -160,13 +149,6 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
/* Modification of the RATE >> */ /* Modification of the RATE >> */
for (j = 0; j < tcp->numlayers; j++) { for (j = 0; j < tcp->numlayers; j++) {
tcp->rates[j] = tcp->rates[j] ? tcp->rates[j] = tcp->rates[j] ?
cp->tp_on ?
(((float) (tile->numcomps
* (tile->x1 - tile->x0)
* (tile->y1 - tile->y0)
* image->comps[0].prec))
/(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - (((tcd->cur_totnum_tp - 1) * 14 )/ tcp->numlayers)
:
((float) (tile->numcomps ((float) (tile->numcomps
* (tile->x1 - tile->x0) * (tile->x1 - tile->x0)
* (tile->y1 - tile->y0) * (tile->y1 - tile->y0)
@ -181,10 +163,6 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
if (!j && tcp->rates[j] < 30) if (!j && tcp->rates[j] < 30)
tcp->rates[j] = 30; tcp->rates[j] = 30;
} }
if(j == (tcp->numlayers-1)){
tcp->rates[j] = tcp->rates[j]- 2;
}
} }
} }
/* << Modification of the RATE */ /* << Modification of the RATE */
@ -201,7 +179,7 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy);
tilec->data = (int *) opj_aligned_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int)); tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int));
tilec->numresolutions = tccp->numresolutions; tilec->numresolutions = tccp->numresolutions;
tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t)); tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t));
@ -297,7 +275,6 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
for (i = 0; i < res->pw * res->ph * 3; i++) { for (i = 0; i < res->pw * res->ph * 3; i++) {
band->precincts[i].imsbtree = NULL; band->precincts[i].imsbtree = NULL;
band->precincts[i].incltree = NULL; band->precincts[i].incltree = NULL;
band->precincts[i].cblks.enc = NULL;
} }
for (precno = 0; precno < res->pw * res->ph; precno++) { for (precno = 0; precno < res->pw * res->ph; precno++) {
@ -323,7 +300,7 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn;
prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;
prc->cblks.enc = (opj_tcd_cblk_enc_t*) opj_calloc((prc->cw * prc->ch), sizeof(opj_tcd_cblk_enc_t)); prc->cblks = (opj_tcd_cblk_t *) opj_malloc((prc->cw * prc->ch) * sizeof(opj_tcd_cblk_t));
prc->incltree = tgt_create(prc->cw, prc->ch); prc->incltree = tgt_create(prc->cw, prc->ch);
prc->imsbtree = tgt_create(prc->cw, prc->ch); prc->imsbtree = tgt_create(prc->cw, prc->ch);
@ -333,20 +310,13 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
int cblkxend = cblkxstart + (1 << cblkwidthexpn); int cblkxend = cblkxstart + (1 << cblkwidthexpn);
int cblkyend = cblkystart + (1 << cblkheightexpn); int cblkyend = cblkystart + (1 << cblkheightexpn);
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
/* code-block size (global) */ /* code-block size (global) */
cblk->x0 = int_max(cblkxstart, prc->x0); cblk->x0 = int_max(cblkxstart, prc->x0);
cblk->y0 = int_max(cblkystart, prc->y0); cblk->y0 = int_max(cblkystart, prc->y0);
cblk->x1 = int_min(cblkxend, prc->x1); cblk->x1 = int_min(cblkxend, prc->x1);
cblk->y1 = int_min(cblkyend, prc->y1); cblk->y1 = int_min(cblkyend, prc->y1);
cblk->data = (unsigned char*) opj_calloc(9728+2, sizeof(unsigned char));
/* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */
cblk->data[0] = 0;
cblk->data[1] = 0;
cblk->data += 2;
cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
} }
} }
} }
@ -358,7 +328,7 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
} }
void tcd_free_encode(opj_tcd_t *tcd) { void tcd_free_encode(opj_tcd_t *tcd) {
int tileno, compno, resno, bandno, precno, cblkno; int tileno, compno, resno, bandno, precno;
for (tileno = 0; tileno < 1; tileno++) { for (tileno = 0; tileno < 1; tileno++) {
opj_tcd_tile_t *tile = tcd->tcd_image->tiles; opj_tcd_tile_t *tile = tcd->tcd_image->tiles;
@ -383,12 +353,8 @@ void tcd_free_encode(opj_tcd_t *tcd) {
tgt_destroy(prc->imsbtree); tgt_destroy(prc->imsbtree);
prc->imsbtree = NULL; prc->imsbtree = NULL;
} }
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { opj_free(prc->cblks);
opj_free(prc->cblks.enc[cblkno].data - 2); prc->cblks = NULL;
opj_free(prc->cblks.enc[cblkno].layers);
opj_free(prc->cblks.enc[cblkno].passes);
}
opj_free(prc->cblks.enc);
} /* for (precno */ } /* for (precno */
opj_free(band->precincts); opj_free(band->precincts);
band->precincts = NULL; band->precincts = NULL;
@ -428,13 +394,6 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur
/* Modification of the RATE >> */ /* Modification of the RATE >> */
for (j = 0; j < tcp->numlayers; j++) { for (j = 0; j < tcp->numlayers; j++) {
tcp->rates[j] = tcp->rates[j] ? tcp->rates[j] = tcp->rates[j] ?
cp->tp_on ?
(((float) (tile->numcomps
* (tile->x1 - tile->x0)
* (tile->y1 - tile->y0)
* image->comps[0].prec))
/(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - (((tcd->cur_totnum_tp - 1) * 14 )/ tcp->numlayers)
:
((float) (tile->numcomps ((float) (tile->numcomps
* (tile->x1 - tile->x0) * (tile->x1 - tile->x0)
* (tile->y1 - tile->y0) * (tile->y1 - tile->y0)
@ -465,7 +424,7 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur
tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy);
tilec->data = (int *) opj_aligned_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int)); tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int));
tilec->numresolutions = tccp->numresolutions; tilec->numresolutions = tccp->numresolutions;
/* tilec->resolutions=(opj_tcd_resolution_t*)opj_realloc(tilec->resolutions,tilec->numresolutions*sizeof(opj_tcd_resolution_t)); */ /* tilec->resolutions=(opj_tcd_resolution_t*)opj_realloc(tilec->resolutions,tilec->numresolutions*sizeof(opj_tcd_resolution_t)); */
for (resno = 0; resno < tilec->numresolutions; resno++) { for (resno = 0; resno < tilec->numresolutions; resno++) {
@ -575,8 +534,8 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur
prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn;
prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;
opj_free(prc->cblks.enc); opj_free(prc->cblks);
prc->cblks.enc = (opj_tcd_cblk_enc_t*) opj_calloc(prc->cw * prc->ch, sizeof(opj_tcd_cblk_enc_t)); prc->cblks = (opj_tcd_cblk_t *) opj_malloc(prc->cw * prc->ch * sizeof(opj_tcd_cblk_t));
if (prc->incltree != NULL) { if (prc->incltree != NULL) {
tgt_destroy(prc->incltree); tgt_destroy(prc->incltree);
@ -594,20 +553,13 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur
int cblkxend = cblkxstart + (1 << cblkwidthexpn); int cblkxend = cblkxstart + (1 << cblkwidthexpn);
int cblkyend = cblkystart + (1 << cblkheightexpn); int cblkyend = cblkystart + (1 << cblkheightexpn);
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
/* code-block size (global) */ /* code-block size (global) */
cblk->x0 = int_max(cblkxstart, prc->x0); cblk->x0 = int_max(cblkxstart, prc->x0);
cblk->y0 = int_max(cblkystart, prc->y0); cblk->y0 = int_max(cblkystart, prc->y0);
cblk->x1 = int_min(cblkxend, prc->x1); cblk->x1 = int_min(cblkxend, prc->x1);
cblk->y1 = int_min(cblkyend, prc->y1); cblk->y1 = int_min(cblkyend, prc->y1);
cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char));
/* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */
cblk->data[0] = 0;
cblk->data[1] = 0;
cblk->data += 2;
cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
} }
} /* precno */ } /* precno */
} /* bandno */ } /* bandno */
@ -619,40 +571,21 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur
} }
void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) { void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
int i, j, tileno, p, q; int tileno, compno, resno, bandno, precno, cblkno, i, j, p, q;
unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h; unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h;
tcd->image = image; tcd->image = image;
tcd->cp = cp;
tcd->tcd_image->tw = cp->tw; tcd->tcd_image->tw = cp->tw;
tcd->tcd_image->th = cp->th; tcd->tcd_image->th = cp->th;
tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(cp->tw * cp->th, sizeof(opj_tcd_tile_t)); tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tcd_tile_t));
/* for (i = 0; i < cp->tileno_size; i++) {
Allocate place to store the decoded data = final image opj_tcp_t *tcp = &(cp->tcps[cp->tileno[i]]);
Place limited by the tile really present in the codestream opj_tcd_tile_t *tile = &(tcd->tcd_image->tiles[cp->tileno[i]]);
*/
for (j = 0; j < cp->tileno_size; j++) {
opj_tcd_tile_t *tile;
tileno = cp->tileno[j];
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tile->numcomps = image->numcomps;
tile->comps = (opj_tcd_tilecomp_t*) opj_calloc(image->numcomps, sizeof(opj_tcd_tilecomp_t));
}
for (i = 0; i < image->numcomps; i++) {
for (j = 0; j < cp->tileno_size; j++) {
opj_tcd_tile_t *tile;
opj_tcd_tilecomp_t *tilec;
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ /* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
tileno = cp->tileno[i];
tileno = cp->tileno[j];
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tilec = &tile->comps[i];
p = tileno % cp->tw; /* si numerotation matricielle .. */ p = tileno % cp->tw; /* si numerotation matricielle .. */
q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */
@ -662,57 +595,19 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
tilec->x0 = int_ceildiv(tile->x0, image->comps[i].dx); tile->numcomps = image->numcomps;
tilec->y0 = int_ceildiv(tile->y0, image->comps[i].dy); tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(image->numcomps * sizeof(opj_tcd_tilecomp_t));
tilec->x1 = int_ceildiv(tile->x1, image->comps[i].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[i].dy);
x0 = j == 0 ? tilec->x0 : int_min(x0, (unsigned int) tilec->x0);
y0 = j == 0 ? tilec->y0 : int_min(y0, (unsigned int) tilec->y0);
x1 = j == 0 ? tilec->x1 : int_max(x1, (unsigned int) tilec->x1);
y1 = j == 0 ? tilec->y1 : int_max(y1, (unsigned int) tilec->y1);
}
w = int_ceildivpow2(x1 - x0, image->comps[i].factor);
h = int_ceildivpow2(y1 - y0, image->comps[i].factor);
image->comps[i].w = w;
image->comps[i].h = h;
image->comps[i].x0 = x0;
image->comps[i].y0 = y0;
}
}
void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info) {
int compno, resno, bandno, precno, cblkno;
opj_tcp_t *tcp;
opj_tcd_tile_t *tile;
OPJ_ARG_NOT_USED(cstr_info);
tcd->cp = cp;
tcp = &(cp->tcps[cp->tileno[tileno]]);
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tileno = cp->tileno[tileno];
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
opj_tccp_t *tccp = &tcp->tccps[compno]; opj_tccp_t *tccp = &tcp->tccps[compno];
opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
if (tccp->numresolutions <= 0)
{
cp->tileno[tileno] = -1;
return;
}
/* border of each tile component (global) */ /* border of each tile component (global) */
tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx); tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx);
tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy); tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy);
tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy);
tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int));
tilec->numresolutions = tccp->numresolutions; tilec->numresolutions = tccp->numresolutions;
tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t)); tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t));
@ -797,7 +692,7 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1]; ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1];
gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno); gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
numbps = image->comps[compno].prec + gain; numbps = image->comps[compno].prec + gain;
band->stepsize = (float)(((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)) * 0.5); band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
band->precincts = (opj_tcd_precinct_t *) opj_malloc(res->pw * res->ph * sizeof(opj_tcd_precinct_t)); band->precincts = (opj_tcd_precinct_t *) opj_malloc(res->pw * res->ph * sizeof(opj_tcd_precinct_t));
@ -823,7 +718,7 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn;
prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;
prc->cblks.dec = (opj_tcd_cblk_dec_t*) opj_malloc(prc->cw * prc->ch * sizeof(opj_tcd_cblk_dec_t)); prc->cblks = (opj_tcd_cblk_t *) opj_malloc(prc->cw * prc->ch * sizeof(opj_tcd_cblk_t));
prc->incltree = tgt_create(prc->cw, prc->ch); prc->incltree = tgt_create(prc->cw, prc->ch);
prc->imsbtree = tgt_create(prc->cw, prc->ch); prc->imsbtree = tgt_create(prc->cw, prc->ch);
@ -834,21 +729,48 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
int cblkxend = cblkxstart + (1 << cblkwidthexpn); int cblkxend = cblkxstart + (1 << cblkwidthexpn);
int cblkyend = cblkystart + (1 << cblkheightexpn); int cblkyend = cblkystart + (1 << cblkheightexpn);
opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno];
cblk->data = NULL;
cblk->segs = NULL;
/* code-block size (global) */ /* code-block size (global) */
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
cblk->x0 = int_max(cblkxstart, prc->x0); cblk->x0 = int_max(cblkxstart, prc->x0);
cblk->y0 = int_max(cblkystart, prc->y0); cblk->y0 = int_max(cblkystart, prc->y0);
cblk->x1 = int_min(cblkxend, prc->x1); cblk->x1 = int_min(cblkxend, prc->x1);
cblk->y1 = int_min(cblkyend, prc->y1); cblk->y1 = int_min(cblkyend, prc->y1);
cblk->numsegs = 0;
} }
} /* precno */ } /* precno */
} /* bandno */ } /* bandno */
} /* resno */ } /* resno */
} /* compno */ } /* compno */
} /* i = 0..cp->tileno_size */
/* tcd_dump(stdout, tcd, &tcd->tcd_image); */ /* tcd_dump(stdout, tcd, &tcd->tcd_image); */
/*
Allocate place to store the decoded data = final image
Place limited by the tile really present in the codestream
*/
for (i = 0; i < image->numcomps; i++) {
for (j = 0; j < cp->tileno_size; j++) {
tileno = cp->tileno[j];
x0 = j == 0 ? tcd->tcd_image->tiles[tileno].comps[i].x0 : int_min(x0,
(unsigned int) tcd->tcd_image->tiles[tileno].comps[i].x0);
y0 = j == 0 ? tcd->tcd_image->tiles[tileno].comps[i].y0 : int_min(y0,
(unsigned int) tcd->tcd_image->tiles[tileno].comps[i].y0);
x1 = j == 0 ? tcd->tcd_image->tiles[tileno].comps[i].x1 : int_max(x1,
(unsigned int) tcd->tcd_image->tiles[tileno].comps[i].x1);
y1 = j == 0 ? tcd->tcd_image->tiles[tileno].comps[i].y1 : int_max(y1,
(unsigned int) tcd->tcd_image->tiles[tileno].comps[i].y1);
}
w = x1 - x0;
h = y1 - y0;
image->comps[i].data = (int *) opj_malloc(w * h * sizeof(int));
image->comps[i].w = w;
image->comps[i].h = h;
image->comps[i].x0 = x0;
image->comps[i].y0 = y0;
}
} }
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) { void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) {
@ -882,7 +804,7 @@ void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) {
for (precno = 0; precno < res->pw * res->ph; precno++) { for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno]; opj_tcd_layer_t *layer = &cblk->layers[layno];
int n; int n;
int imsb = tcd->image->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */ int imsb = tcd->image->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */
@ -963,7 +885,7 @@ void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) {
for (precno = 0; precno < res->pw * res->ph; precno++) { for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno]; opj_tcd_layer_t *layer = &cblk->layers[layno];
int n; int n;
@ -1017,7 +939,7 @@ void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) {
} }
} }
opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) { bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_info_t * image_info) {
int compno, resno, bandno, precno, cblkno, passno, layno; int compno, resno, bandno, precno, cblkno, passno, layno;
double min, max; double min, max;
double cumdisto[100]; /* fixed_quality */ double cumdisto[100]; /* fixed_quality */
@ -1031,11 +953,11 @@ opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_code
min = DBL_MAX; min = DBL_MAX;
max = 0; max = 0;
tcd_tile->numpix = 0; /* fixed_quality */ tcd_tile->nbpix = 0; /* fixed_quality */
for (compno = 0; compno < tcd_tile->numcomps; compno++) { for (compno = 0; compno < tcd_tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
tilec->numpix = 0; tilec->nbpix = 0;
for (resno = 0; resno < tilec->numresolutions; resno++) { for (resno = 0; resno < tilec->numresolutions; resno++) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno]; opj_tcd_resolution_t *res = &tilec->resolutions[resno];
@ -1047,7 +969,7 @@ opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_code
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
for (passno = 0; passno < cblk->totalpasses; passno++) { for (passno = 0; passno < cblk->totalpasses; passno++) {
opj_tcd_pass_t *pass = &cblk->passes[passno]; opj_tcd_pass_t *pass = &cblk->passes[passno];
@ -1073,8 +995,8 @@ opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_code
} /* passno */ } /* passno */
/* fixed_quality */ /* fixed_quality */
tcd_tile->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); tcd_tile->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0));
tilec->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); tilec->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0));
} /* cbklno */ } /* cbklno */
} /* precno */ } /* precno */
} /* bandno */ } /* bandno */
@ -1082,13 +1004,13 @@ opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_code
maxSE += (((double)(1 << tcd->image->comps[compno].prec) - 1.0) maxSE += (((double)(1 << tcd->image->comps[compno].prec) - 1.0)
* ((double)(1 << tcd->image->comps[compno].prec) -1.0)) * ((double)(1 << tcd->image->comps[compno].prec) -1.0))
* ((double)(tilec->numpix)); * ((double)(tilec->nbpix));
} /* compno */ } /* compno */
/* index file */ /* index file */
if(cstr_info) { if(image_info && image_info->index_on) {
opj_tile_info_t *tile_info = &cstr_info->tile[tcd->tcd_tileno]; opj_tile_info_t *tile_info = &image_info->tile[tcd->tcd_tileno];
tile_info->numpix = tcd_tile->numpix; tile_info->nbpix = tcd_tile->nbpix;
tile_info->distotile = tcd_tile->distotile; tile_info->distotile = tcd_tile->distotile;
tile_info->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double)); tile_info->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double));
} }
@ -1097,59 +1019,35 @@ opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_code
double lo = min; double lo = min;
double hi = max; double hi = max;
int success = 0; int success = 0;
/* TODO: remove maxlen */
int maxlen = tcd_tcp->rates[layno] ? int_min(((int) ceil(tcd_tcp->rates[layno])), len) : len; int maxlen = tcd_tcp->rates[layno] ? int_min(((int) ceil(tcd_tcp->rates[layno])), len) : len;
double goodthresh = 0; double goodthresh = 0;
double stable_thresh = 0;
int i; int i;
double distotarget; /* fixed_quality */ double distotarget; /* fixed_quality */
/* fixed_quality */ /* fixed_quality */
distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10)); distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10));
/* Don't try to find an optimal threshold but rather take everything not included yet, if if ((tcd_tcp->rates[layno]) || (cp->disto_alloc == 0)) {
-r xx,yy,zz,0 (disto_alloc == 1 and rates == 0)
-q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0)
==> possible to have some lossy layers and the last layer for sure lossless */
if ( ((cp->disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) {
opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->image, cp); opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->image, cp);
double thresh = 0;
for (i = 0; i < 128; i++) { for (i = 0; i < 32; i++) {
double thresh = (lo + hi) / 2;
int l = 0; int l = 0;
double distoachieved = 0; /* fixed_quality */ double distoachieved = 0; /* fixed_quality */
thresh = (lo + hi) / 2;
tcd_makelayer(tcd, layno, thresh, 0); tcd_makelayer(tcd, layno, thresh, 0);
if (cp->fixed_quality) { /* fixed_quality */ if (cp->fixed_quality) { /* fixed_quality */
if(cp->cinema){
l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC, tcd->cur_totnum_tp);
if (l == -999) {
lo = thresh;
continue;
}else{
distoachieved = layno == 0 ?
tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno];
if (distoachieved < distotarget) {
hi=thresh;
stable_thresh = thresh;
continue;
}else{
lo=thresh;
}
}
}else{
distoachieved = (layno == 0) ? distoachieved = (layno == 0) ?
tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]); tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
if (distoachieved < distotarget) { if (distoachieved < distotarget) {
hi = thresh; hi = thresh;
stable_thresh = thresh;
continue; continue;
} }
lo = thresh; lo = thresh;
}
} else { } else {
l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC, tcd->cur_totnum_tp); l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info);
/* TODO: what to do with l ??? seek / tell ??? */ /* TODO: what to do with l ??? seek / tell ??? */
/* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */ /* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */
if (l == -999) { if (l == -999) {
@ -1157,11 +1055,11 @@ opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_code
continue; continue;
} }
hi = thresh; hi = thresh;
stable_thresh = thresh;
}
} }
success = 1; success = 1;
goodthresh = stable_thresh == 0? thresh : stable_thresh; goodthresh = thresh;
}
t2_destroy(t2); t2_destroy(t2);
} else { } else {
success = 1; success = 1;
@ -1169,11 +1067,11 @@ opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_code
} }
if (!success) { if (!success) {
return OPJ_FALSE; return false;
} }
if(cstr_info) { /* Threshold for Marcela Index */ if(image_info && image_info->index_on) { /* Threshold for Marcela Index */
cstr_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh; image_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh;
} }
tcd_makelayer(tcd, layno, goodthresh, 1); tcd_makelayer(tcd, layno, goodthresh, 1);
@ -1181,12 +1079,13 @@ opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_code
cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]); cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
} }
return OPJ_TRUE; return true;
} }
int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) { int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_image_info_t * image_info) {
int compno; int compno;
int l, i, numpacks = 0; int l, i, npck = 0;
double encoding_time;
opj_tcd_tile_t *tile = NULL; opj_tcd_tile_t *tile = NULL;
opj_tcp_t *tcd_tcp = NULL; opj_tcp_t *tcd_tcp = NULL;
opj_cp_t *cp = NULL; opj_cp_t *cp = NULL;
@ -1206,27 +1105,26 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
tcd_tcp = tcd->tcp; tcd_tcp = tcd->tcp;
cp = tcd->cp; cp = tcd->cp;
if(tcd->cur_tp_num == 0){
tcd->encoding_time = opj_clock(); /* time needed to encode a tile */
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */ /* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
if(cstr_info) { if(image_info && image_info->index_on) {
opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */ opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */
for (i = 0; i < tilec_idx->numresolutions; i++) { for (i = 0; i < tilec_idx->numresolutions; i++) {
opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i]; opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i];
cstr_info->tile[tileno].pw[i] = res_idx->pw; image_info->tile[tileno].pw[i] = res_idx->pw;
cstr_info->tile[tileno].ph[i] = res_idx->ph; image_info->tile[tileno].ph[i] = res_idx->ph;
numpacks += res_idx->pw * res_idx->ph; npck += res_idx->pw * res_idx->ph;
cstr_info->tile[tileno].pdx[i] = tccp->prcw[i]; image_info->tile[tileno].pdx[i] = tccp->prcw[i];
cstr_info->tile[tileno].pdy[i] = tccp->prch[i]; image_info->tile[tileno].pdy[i] = tccp->prch[i];
} }
cstr_info->tile[tileno].packet = (opj_packet_info_t*) opj_calloc(cstr_info->numcomps * cstr_info->numlayers * numpacks, sizeof(opj_packet_info_t)); image_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(image_info->comp * image_info->layer * npck * sizeof(opj_packet_info_t));
} }
/* << INDEX */ /* << INDEX */
/*---------------TILE-------------------*/ /*---------------TILE-------------------*/
encoding_time = opj_clock(); /* time needed to encode a tile */
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
int x, y; int x, y;
@ -1258,9 +1156,8 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
/* start of the dst tile scanline */ /* start of the dst tile scanline */
int *tile_data = &tilec->data[(y - tilec->y0) * tw]; int *tile_data = &tilec->data[(y - tilec->y0) * tw];
for (x = tilec->x0; x < tilec->x1; x++) { for (x = tilec->x0; x < tilec->x1; x++) {
*tile_data++ = (*data++ - adjust) << 11; *tile_data++ = (*data++ - adjust) << 13;
} }
} }
} }
} }
@ -1294,46 +1191,43 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
/*-----------RATE-ALLOCATE------------------*/ /*-----------RATE-ALLOCATE------------------*/
/* INDEX */ /* INDEX */
if(cstr_info) { if(image_info) {
cstr_info->index_write = 0; image_info->index_write = 0;
} }
if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */ if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */
/* Normal Rate/distortion allocation */ /* Normal Rate/distortion allocation */
tcd_rateallocate(tcd, dest, len, cstr_info); tcd_rateallocate(tcd, dest, len, image_info);
} else { } else {
/* Fixed layer allocation */ /* Fixed layer allocation */
tcd_rateallocate_fixed(tcd); tcd_rateallocate_fixed(tcd);
} }
}
/*--------------TIER2------------------*/ /*--------------TIER2------------------*/
/* INDEX */ /* INDEX */
if(cstr_info) { if(image_info) {
cstr_info->index_write = 1; image_info->index_write = 1;
} }
t2 = t2_create(tcd->cinfo, image, cp); t2 = t2_create(tcd->cinfo, image, cp);
l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, cstr_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,FINAL_PASS,tcd->cur_totnum_tp); l = t2_encode_packets(t2, tileno, tile, tcd_tcp->numlayers, dest, len, image_info);
t2_destroy(t2); t2_destroy(t2);
/*---------------CLEAN-------------------*/ /*---------------CLEAN-------------------*/
encoding_time = opj_clock() - encoding_time;
if(tcd->cur_tp_num == tcd->cur_totnum_tp - 1){ opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", encoding_time);
tcd->encoding_time = opj_clock() - tcd->encoding_time;
opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", tcd->encoding_time);
/* cleaning memory */ /* cleaning memory */
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
opj_aligned_free(tilec->data); opj_free(tilec->data);
}
} }
return l; return l;
} }
opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info) { bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) {
int l; int l;
int compno; int compno;
int eof = 0; int eof = 0;
@ -1351,67 +1245,22 @@ opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno
tile_time = opj_clock(); /* time needed to decode a tile */ tile_time = opj_clock(); /* time needed to decode a tile */
opj_event_msg(tcd->cinfo, EVT_INFO, "tile %d of %d\n", tileno + 1, tcd->cp->tw * tcd->cp->th); opj_event_msg(tcd->cinfo, EVT_INFO, "tile %d of %d\n", tileno + 1, tcd->cp->tw * tcd->cp->th);
/* INDEX >> */
if(cstr_info) {
int resno, compno, numprec = 0;
for (compno = 0; compno < cstr_info->numcomps; compno++) {
opj_tcp_t *tcp = &tcd->cp->tcps[0];
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_tcd_tilecomp_t *tilec_idx = &tile->comps[compno];
for (resno = 0; resno < tilec_idx->numresolutions; resno++) {
opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[resno];
cstr_info->tile[tileno].pw[resno] = res_idx->pw;
cstr_info->tile[tileno].ph[resno] = res_idx->ph;
numprec += res_idx->pw * res_idx->ph;
if (tccp->csty & J2K_CP_CSTY_PRT) {
cstr_info->tile[tileno].pdx[resno] = tccp->prcw[resno];
cstr_info->tile[tileno].pdy[resno] = tccp->prch[resno];
}
else {
cstr_info->tile[tileno].pdx[resno] = 15;
cstr_info->tile[tileno].pdy[resno] = 15;
}
}
}
cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->numlayers * numprec * sizeof(opj_packet_info_t));
cstr_info->packno = 0;
}
/* << INDEX */
/*--------------TIER2------------------*/ /*--------------TIER2------------------*/
t2 = t2_create(tcd->cinfo, tcd->image, tcd->cp); t2 = t2_create(tcd->cinfo, tcd->image, tcd->cp);
l = t2_decode_packets(t2, src, len, tileno, tile, cstr_info); l = t2_decode_packets(t2, src, len, tileno, tile);
t2_destroy(t2); t2_destroy(t2);
if (l == -999) { if (l == -999) {
eof = 1; eof = 1;
opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: incomplete bitstream\n"); opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: incomplete bistream\n");
} }
/*------------------TIER1-----------------*/ /*------------------TIER1-----------------*/
t1_time = opj_clock(); /* time needed to decode a tile */ t1_time = opj_clock(); /* time needed to decode a tile */
t1 = t1_create(tcd->cinfo); t1 = t1_create(tcd->cinfo);
if (t1 == NULL) t1_decode_cblks(t1, tile, tcd->tcp);
{
opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n");
t1_destroy(t1);
return OPJ_FALSE;
}
for (compno = 0; compno < tile->numcomps; ++compno) {
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
/* The +3 is headroom required by the vectorized DWT */
tilec->data = (int*) opj_aligned_malloc((((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int));
if (tilec->data == NULL)
{
opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n");
return OPJ_FALSE;
}
t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]);
}
t1_destroy(t1); t1_destroy(t1);
t1_time = opj_clock() - t1_time; t1_time = opj_clock() - t1_time;
opj_event_msg(tcd->cinfo, EVT_INFO, "- tiers-1 took %f s\n", t1_time); opj_event_msg(tcd->cinfo, EVT_INFO, "- tiers-1 took %f s\n", t1_time);
@ -1421,27 +1270,19 @@ opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno
dwt_time = opj_clock(); /* time needed to decode a tile */ dwt_time = opj_clock(); /* time needed to decode a tile */
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
int numres2decode;
if (tcd->cp->reduce != 0) { if (tcd->cp->reduce != 0) {
if ( tile->comps[compno].numresolutions < ( tcd->cp->reduce - 1 ) ) {
opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. The number of resolutions to remove [%d+1] is higher than the number "
" of resolutions in the original codestream [%d]\nModify the cp_reduce parameter.\n", tcd->cp->reduce, tile->comps[compno].numresolutions);
return OPJ_FALSE;
}
else {
tcd->image->comps[compno].resno_decoded = tcd->image->comps[compno].resno_decoded =
tile->comps[compno].numresolutions - tcd->cp->reduce - 1; tile->comps[compno].numresolutions - tcd->cp->reduce - 1;
} }
if (tcd->tcp->tccps[compno].qmfbid == 1) {
dwt_decode(tilec, tilec->numresolutions - 1 - tcd->image->comps[compno].resno_decoded);
} else {
dwt_decode_real(tilec, tilec->numresolutions - 1 - tcd->image->comps[compno].resno_decoded);
} }
numres2decode = tcd->image->comps[compno].resno_decoded + 1; if (tile->comps[compno].numresolutions > 0) {
if(numres2decode > 0){ tcd->image->comps[compno].factor = tile->comps[compno].numresolutions - (tcd->image->comps[compno].resno_decoded + 1);
if (tcd->tcp->tccps[compno].qmfbid == 1) {
dwt_decode(tilec, numres2decode);
} else {
dwt_decode_real(tilec, numres2decode);
}
} }
} }
dwt_time = opj_clock() - dwt_time; dwt_time = opj_clock() - dwt_time;
@ -1450,101 +1291,73 @@ opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno
/*----------------MCT-------------------*/ /*----------------MCT-------------------*/
if (tcd->tcp->mct) { if (tcd->tcp->mct) {
int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0);
if (tile->numcomps >= 3 ){
if (tcd->tcp->tccps[0].qmfbid == 1) { if (tcd->tcp->tccps[0].qmfbid == 1) {
mct_decode( mct_decode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data,
tile->comps[0].data, (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0));
tile->comps[1].data,
tile->comps[2].data,
n);
} else { } else {
mct_decode_real( mct_decode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data,
(float*)tile->comps[0].data, (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0));
(float*)tile->comps[1].data,
(float*)tile->comps[2].data,
n);
}
} else{
opj_event_msg(tcd->cinfo, EVT_WARNING,"Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",tile->numcomps);
} }
} }
/*---------------TILE-------------------*/ /*---------------TILE-------------------*/
for (compno = 0; compno < tile->numcomps; ++compno) { for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
opj_image_comp_t* imagec = &tcd->image->comps[compno]; opj_tcd_resolution_t *res = &tilec->resolutions[tcd->image->comps[compno].resno_decoded];
opj_tcd_resolution_t* res = &tilec->resolutions[imagec->resno_decoded]; int adjust = tcd->image->comps[compno].sgnd ? 0 : 1 << (tcd->image->comps[compno].prec - 1);
int adjust = imagec->sgnd ? 0 : 1 << (imagec->prec - 1); int min = tcd->image->comps[compno].sgnd ?
int min = imagec->sgnd ? -(1 << (imagec->prec - 1)) : 0; -(1 << (tcd->image->comps[compno].prec - 1)) : 0;
int max = imagec->sgnd ? (1 << (imagec->prec - 1)) - 1 : (1 << imagec->prec) - 1; int max = tcd->image->comps[compno].sgnd ?
(1 << (tcd->image->comps[compno].prec - 1)) - 1 : (1 << tcd->image->comps[compno].prec) - 1;
int tw = tilec->x1 - tilec->x0; int tw = tilec->x1 - tilec->x0;
int w = imagec->w; int w = tcd->image->comps[compno].w;
int offset_x = int_ceildivpow2(imagec->x0, imagec->factor);
int offset_y = int_ceildivpow2(imagec->y0, imagec->factor);
int i, j; int i, j;
if(!imagec->data){ int offset_x = int_ceildivpow2(tcd->image->comps[compno].x0, tcd->image->comps[compno].factor);
imagec->data = (int*) opj_malloc(imagec->w * imagec->h * sizeof(int)); int offset_y = int_ceildivpow2(tcd->image->comps[compno].y0, tcd->image->comps[compno].factor);
for (j = res->y0; j < res->y1; j++) {
for (i = res->x0; i < res->x1; i++) {
int v;
float tmp = (float)((tilec->data[i - res->x0 + (j - res->y0) * tw]) / 8192.0);
if (tcd->tcp->tccps[compno].qmfbid == 1) {
v = tilec->data[i - res->x0 + (j - res->y0) * tw];
} else {
int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2);
v = ((tmp < 0) ? -tmp2:tmp2);
} }
if (!imagec->data)
{
opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n");
return OPJ_FALSE;
}
if(tcd->tcp->tccps[compno].qmfbid == 1) {
for(j = res->y0; j < res->y1; ++j) {
for(i = res->x0; i < res->x1; ++i) {
int v = tilec->data[i - res->x0 + (j - res->y0) * tw];
v += adjust; v += adjust;
imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max);
tcd->image->comps[compno].data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max);
} }
} }
}else{
for(j = res->y0; j < res->y1; ++j) {
for(i = res->x0; i < res->x1; ++i) {
float tmp = ((float*)tilec->data)[i - res->x0 + (j - res->y0) * tw];
int v = lrintf(tmp);
v += adjust;
imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max);
}
}
}
opj_aligned_free(tilec->data);
} }
tile_time = opj_clock() - tile_time; /* time needed to decode a tile */ tile_time = opj_clock() - tile_time; /* time needed to decode a tile */
opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time); opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time);
if (eof) { for (compno = 0; compno < tile->numcomps; compno++) {
return OPJ_FALSE; opj_free(tcd->tcd_image->tiles[tileno].comps[compno].data);
tcd->tcd_image->tiles[tileno].comps[compno].data = NULL;
} }
return OPJ_TRUE; if (eof) {
return false;
}
return true;
} }
void tcd_free_decode(opj_tcd_t *tcd) { void tcd_free_decode(opj_tcd_t *tcd) {
opj_tcd_image_t *tcd_image = tcd->tcd_image; int tileno,compno,resno,bandno,precno;
int i = 0;
for (i = 0; i < tcd_image->tw * tcd_image->th; i++)
{
tcd_free_decode_tile(tcd, i);
}
opj_free(tcd_image->tiles);
}
void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
int compno,resno,bandno,precno,cblkno;
opj_tcd_image_t *tcd_image = tcd->tcd_image; opj_tcd_image_t *tcd_image = tcd->tcd_image;
for (tileno = 0; tileno < tcd_image->tw * tcd_image->th; tileno++) {
opj_tcd_tile_t *tile = &tcd_image->tiles[tileno]; opj_tcd_tile_t *tile = &tcd_image->tiles[tileno];
if (tile->comps != NULL) {
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
for (resno = 0; resno < tilec->numresolutions; resno++) { for (resno = 0; resno < tilec->numresolutions; resno++) {
@ -1553,28 +1366,18 @@ void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
opj_tcd_band_t *band = &res->bands[bandno]; opj_tcd_band_t *band = &res->bands[bandno];
for (precno = 0; precno < res->ph * res->pw; precno++) { for (precno = 0; precno < res->ph * res->pw; precno++) {
opj_tcd_precinct_t *prec = &band->precincts[precno]; opj_tcd_precinct_t *prec = &band->precincts[precno];
if (prec->cblks.dec != NULL) { if (prec->cblks != NULL) opj_free(prec->cblks);
for (cblkno = 0; cblkno < prec->cw * prec->ch; ++cblkno) {
opj_tcd_cblk_dec_t* cblk = &prec->cblks.dec[cblkno];
opj_free(cblk->data);
opj_free(cblk->segs);
}
opj_free(prec->cblks.dec);
}
if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree); if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree);
if (prec->incltree != NULL) tgt_destroy(prec->incltree); if (prec->incltree != NULL) tgt_destroy(prec->incltree);
}
if (band->precincts != NULL) opj_free(band->precincts);
}
}
if (tilec->resolutions != NULL) opj_free(tilec->resolutions);
}
if (tile->comps != NULL) opj_free(tile->comps);
}
if (tcd_image->tiles != NULL) opj_free(tcd_image->tiles);
}
opj_free(band->precincts);
}
}
opj_free(tilec->resolutions);
}
opj_free(tile->comps);
tile->comps = NULL;
}
} }

View File

@ -1,16 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -51,10 +44,9 @@ each other. The functions in TCD.C are used by some function in J2K.C.
FIXME: documentation FIXME: documentation
*/ */
typedef struct opj_tcd_seg { typedef struct opj_tcd_seg {
unsigned char** data;
int dataindex;
int numpasses; int numpasses;
int len; int len;
unsigned char *data;
int maxpasses; int maxpasses;
int numnewpasses; int numnewpasses;
int newlen; int newlen;
@ -82,28 +74,21 @@ typedef struct opj_tcd_layer {
/** /**
FIXME: documentation FIXME: documentation
*/ */
typedef struct opj_tcd_cblk_enc { typedef struct opj_tcd_cblk {
unsigned char* data; /* Data */
opj_tcd_layer_t* layers; /* layer information */
opj_tcd_pass_t* passes; /* information about the passes */
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
int numbps;
int numlenbits;
int numpasses; /* number of pass already done for the code-blocks */
int numpassesinlayers; /* number of passes in the layer */
int totalpasses; /* total number of passes */
} opj_tcd_cblk_enc_t;
typedef struct opj_tcd_cblk_dec {
unsigned char* data; /* Data */
opj_tcd_seg_t* segs; /* segments informations */
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
int numbps; int numbps;
int numlenbits; int numlenbits;
int len; /* length */ int len; /* length */
int numpasses; /* number of pass already done for the code-blocks */
int numnewpasses; /* number of pass added to the code-blocks */ int numnewpasses; /* number of pass added to the code-blocks */
int numsegs; /* number of segments */ int numsegs; /* number of segments */
} opj_tcd_cblk_dec_t; opj_tcd_seg_t segs[100]; /* segments informations */
unsigned char data[8192]; /* Data */
int numpassesinlayers; /* number of passes in the layer */
opj_tcd_layer_t layers[100]; /* layer information */
int totalpasses; /* total number of passes */
opj_tcd_pass_t passes[100]; /* information about the passes */
} opj_tcd_cblk_t;
/** /**
FIXME: documentation FIXME: documentation
@ -111,10 +96,7 @@ FIXME: documentation
typedef struct opj_tcd_precinct { typedef struct opj_tcd_precinct {
int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */ int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
int cw, ch; /* number of precinct in width and heigth */ int cw, ch; /* number of precinct in width and heigth */
union{ /* code-blocks informations */ opj_tcd_cblk_t *cblks; /* code-blocks informations */
opj_tcd_cblk_enc_t* enc;
opj_tcd_cblk_dec_t* dec;
} cblks;
opj_tgt_tree_t *incltree; /* inclusion tree */ opj_tgt_tree_t *incltree; /* inclusion tree */
opj_tgt_tree_t *imsbtree; /* IMSB tree */ opj_tgt_tree_t *imsbtree; /* IMSB tree */
} opj_tcd_precinct_t; } opj_tcd_precinct_t;
@ -148,7 +130,7 @@ typedef struct opj_tcd_tilecomp {
int numresolutions; /* number of resolutions level */ int numresolutions; /* number of resolutions level */
opj_tcd_resolution_t *resolutions; /* resolutions information */ opj_tcd_resolution_t *resolutions; /* resolutions information */
int *data; /* data of the component */ int *data; /* data of the component */
int numpix; /* add fixed_quality */ int nbpix; /* add fixed_quality */
} opj_tcd_tilecomp_t; } opj_tcd_tilecomp_t;
/** /**
@ -158,11 +140,9 @@ typedef struct opj_tcd_tile {
int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */ int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
int numcomps; /* number of components in tile */ int numcomps; /* number of components in tile */
opj_tcd_tilecomp_t *comps; /* Components information */ opj_tcd_tilecomp_t *comps; /* Components information */
int numpix; /* add fixed_quality */ int nbpix; /* add fixed_quality */
double distotile; /* add fixed_quality */ double distotile; /* add fixed_quality */
double distolayer[100]; /* add fixed_quality */ double distolayer[100]; /* add fixed_quality */
/** packet number */
int packno;
} opj_tcd_tile_t; } opj_tcd_tile_t;
/** /**
@ -177,16 +157,6 @@ typedef struct opj_tcd_image {
Tile coder/decoder Tile coder/decoder
*/ */
typedef struct opj_tcd { typedef struct opj_tcd {
/** Position of the tilepart flag in Progression order*/
int tp_pos;
/** Tile part number*/
int tp_num;
/** Current tile part number*/
int cur_tp_num;
/** Total number of tileparts of the current tile*/
int cur_totnum_tp;
/** Current Packet iterator number */
int cur_pino;
/** codec context */ /** codec context */
opj_common_ptr cinfo; opj_common_ptr cinfo;
@ -202,8 +172,6 @@ typedef struct opj_tcd {
opj_tcp_t *tcp; opj_tcp_t *tcp;
/** current encoded/decoded tile */ /** current encoded/decoded tile */
int tcd_tileno; int tcd_tileno;
/** Time taken to encode a tile*/
double encoding_time;
} opj_tcd_t; } opj_tcd_t;
/** @name Exported functions */ /** @name Exported functions */
@ -253,36 +221,33 @@ Initialize the tile decoder
@param cp Coding parameters @param cp Coding parameters
*/ */
void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp); void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp);
void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info);
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final); void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
void tcd_rateallocate_fixed(opj_tcd_t *tcd); void tcd_rateallocate_fixed(opj_tcd_t *tcd);
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final); void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info); bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_info_t * image_info);
/** /**
Encode a tile from the raw image into a buffer Encode a tile from the raw image into a buffer
@param tcd TCD handle @param tcd TCD handle
@param tileno Number that identifies one of the tiles to be encoded @param tileno Number that identifies one of the tiles to be encoded
@param dest Destination buffer @param dest Destination buffer
@param len Length of destination buffer @param len Length of destination buffer
@param cstr_info Codestream information structure @param image_info Creation of index file
@return @return
*/ */
int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info); int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_image_info_t * image_info);
/** /**
Decode a tile from a buffer into a raw image Decode a tile from a buffer into a raw image
@param tcd TCD handle @param tcd TCD handle
@param src Source buffer @param src Source buffer
@param len Length of source buffer @param len Length of source buffer
@param tileno Number that identifies one of the tiles to be decoded @param tileno Number that identifies one of the tiles to be decoded
@param cstr_info Codestream information structure
*/ */
opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info); bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno);
/** /**
Free the memory allocated for decoding Free the memory allocated for decoding
@param tcd TCD handle @param tcd TCD handle
*/ */
void tcd_free_decode(opj_tcd_t *tcd); void tcd_free_decode(opj_tcd_t *tcd);
void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@ -1,16 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -77,7 +70,7 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv) {
return NULL; return NULL;
} }
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t)); tree->nodes = (opj_tgt_node_t *) opj_malloc(tree->numnodes * sizeof(opj_tgt_node_t));
if(!tree->nodes) { if(!tree->nodes) {
opj_free(tree); opj_free(tree);
return NULL; return NULL;

View File

@ -1,16 +1,9 @@
/* /*
* 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) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Hervé Drolon, FreeImage Team
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -1,12 +0,0 @@
# required dep for server:
#if(BUILD_JPIP_SERVER)
# find_package(CURL REQUIRED)
# find_package(FCGI REQUIRED)
# find_package(Threads REQUIRED)
# if(NOT CMAKE_USE_PTHREADS_INIT)
# message(FATAL_ERROR "Only pthread are supported")
# endif()
#endif()
#add_subdirectory(lib)
#add_subdirectory(bin)

View File

@ -1,21 +0,0 @@
# source code for openjpeg apps:
add_subdirectory(common)
# Part 1 & 2:
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)

View File

@ -1,7 +0,0 @@
#-----------------------------------------------------------------------------
# opj_apps_config.h generation
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/opj_apps_config.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/opj_apps_config.h
@ONLY
)

View File

@ -1,965 +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) 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.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "color.h"
#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#endif
#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
#endif
#ifdef OPJ_USE_LEGACY
#define OPJ_CLRSPC_GRAY CLRSPC_GRAY
#define OPJ_CLRSPC_SRGB CLRSPC_SRGB
#endif
/*--------------------------------------------------------
Matrix for sYCC, Amendment 1 to IEC 61966-2-1
Y : 0.299 0.587 0.114 :R
Cb: -0.1687 -0.3312 0.5 :G
Cr: 0.5 -0.4187 -0.0812 :B
Inverse:
R: 1 -3.68213e-05 1.40199 :Y
G: 1.00003 -0.344125 -0.714128 :Cb - 2^(prec - 1)
B: 0.999823 1.77204 -8.04142e-06 :Cr - 2^(prec - 1)
-----------------------------------------------------------*/
static void sycc_to_rgb(int offset, int upb, int y, int cb, int cr,
int *out_r, int *out_g, int *out_b)
{
int r, g, b;
cb -= offset; cr -= offset;
r = y + (int)(1.402 * (float)cr);
if(r < 0) r = 0; else if(r > upb) r = upb; *out_r = r;
g = y - (int)(0.344 * (float)cb + 0.714 * (float)cr);
if(g < 0) g = 0; else if(g > upb) g = upb; *out_g = g;
b = y + (int)(1.772 * (float)cb);
if(b < 0) b = 0; else if(b > upb) b = upb; *out_b = b;
}
static void sycc444_to_rgb(opj_image_t *img)
{
int *d0, *d1, *d2, *r, *g, *b;
const int *y, *cb, *cr;
size_t maxw, maxh, max, i;
int offset, upb;
upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1); upb = (1<<upb)-1;
maxw = (size_t)img->comps[0].w; maxh = (size_t)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
cb = img->comps[1].data;
cr = img->comps[2].data;
d0 = r = (int*)malloc(sizeof(int) * max);
d1 = g = (int*)malloc(sizeof(int) * max);
d2 = b = (int*)malloc(sizeof(int) * max);
if(r == NULL || g == NULL || b == NULL) goto fails;
for(i = 0U; i < max; ++i)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++cb; ++cr; ++r; ++g; ++b;
}
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
img->color_space = OPJ_CLRSPC_SRGB;
return;
fails:
free(r);
free(g);
free(b);
}/* sycc444_to_rgb() */
static void sycc422_to_rgb(opj_image_t *img)
{
int *d0, *d1, *d2, *r, *g, *b;
const int *y, *cb, *cr;
size_t maxw, maxh, max, offx, loopmaxw;
int offset, upb;
size_t i;
upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1); upb = (1<<upb)-1;
maxw = (size_t)img->comps[0].w; maxh = (size_t)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
cb = img->comps[1].data;
cr = img->comps[2].data;
d0 = r = (int*)malloc(sizeof(int) * max);
d1 = g = (int*)malloc(sizeof(int) * max);
d2 = b = (int*)malloc(sizeof(int) * max);
if(r == NULL || g == NULL || b == NULL) goto fails;
/* if img->x0 is odd, then first column shall use Cb/Cr = 0 */
offx = img->x0 & 1U;
loopmaxw = maxw - offx;
for(i=0U; i < maxh; ++i)
{
size_t j;
if (offx > 0U) {
sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b);
++y; ++r; ++g; ++b;
}
for(j=0U; j < (loopmaxw & ~(size_t)1U); j += 2U)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
if (j < loopmaxw) {
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
}
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
img->comps[1].w = img->comps[2].w = img->comps[0].w;
img->comps[1].h = img->comps[2].h = img->comps[0].h;
img->comps[1].dx = img->comps[2].dx = img->comps[0].dx;
img->comps[1].dy = img->comps[2].dy = img->comps[0].dy;
img->color_space = OPJ_CLRSPC_SRGB;
return;
fails:
free(r);
free(g);
free(b);
}/* sycc422_to_rgb() */
static void sycc420_to_rgb(opj_image_t *img)
{
int *d0, *d1, *d2, *r, *g, *b, *nr, *ng, *nb;
const int *y, *cb, *cr, *ny;
size_t maxw, maxh, max, offx, loopmaxw, offy, loopmaxh;
int offset, upb;
size_t i;
upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1); upb = (1<<upb)-1;
maxw = (size_t)img->comps[0].w; maxh = (size_t)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
cb = img->comps[1].data;
cr = img->comps[2].data;
d0 = r = (int*)malloc(sizeof(int) * max);
d1 = g = (int*)malloc(sizeof(int) * max);
d2 = b = (int*)malloc(sizeof(int) * max);
if (r == NULL || g == NULL || b == NULL) goto fails;
/* if img->x0 is odd, then first column shall use Cb/Cr = 0 */
offx = img->x0 & 1U;
loopmaxw = maxw - offx;
/* if img->y0 is odd, then first line shall use Cb/Cr = 0 */
offy = img->y0 & 1U;
loopmaxh = maxh - offy;
if (offy > 0U) {
size_t j;
for(j=0; j < maxw; ++j)
{
sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b);
++y; ++r; ++g; ++b;
}
}
for(i=0U; i < (loopmaxh & ~(size_t)1U); i += 2U)
{
size_t j;
ny = y + maxw;
nr = r + maxw; ng = g + maxw; nb = b + maxw;
if (offx > 0U) {
sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb;
}
for(j=0; j < (loopmaxw & ~(size_t)1U); j += 2U)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
if(j < loopmaxw)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
y += maxw; r += maxw; g += maxw; b += maxw;
}
if(i < loopmaxh)
{
size_t j;
for(j=0U; j < (maxw & ~(size_t)1U); j += 2U)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
if(j < maxw)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
}
}
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
img->comps[1].w = img->comps[2].w = img->comps[0].w;
img->comps[1].h = img->comps[2].h = img->comps[0].h;
img->comps[1].dx = img->comps[2].dx = img->comps[0].dx;
img->comps[1].dy = img->comps[2].dy = img->comps[0].dy;
img->color_space = OPJ_CLRSPC_SRGB;
return;
fails:
free(r);
free(g);
free(b);
}/* sycc420_to_rgb() */
void color_sycc_to_rgb(opj_image_t *img)
{
if(img->numcomps < 3)
{
img->color_space = OPJ_CLRSPC_GRAY;
return;
}
if((img->comps[0].dx == 1)
&& (img->comps[1].dx == 2)
&& (img->comps[2].dx == 2)
&& (img->comps[0].dy == 1)
&& (img->comps[1].dy == 2)
&& (img->comps[2].dy == 2))/* horizontal and vertical sub-sample */
{
sycc420_to_rgb(img);
}
else
if((img->comps[0].dx == 1)
&& (img->comps[1].dx == 2)
&& (img->comps[2].dx == 2)
&& (img->comps[0].dy == 1)
&& (img->comps[1].dy == 1)
&& (img->comps[2].dy == 1))/* horizontal sub-sample only */
{
sycc422_to_rgb(img);
}
else
if((img->comps[0].dx == 1)
&& (img->comps[1].dx == 1)
&& (img->comps[2].dx == 1)
&& (img->comps[0].dy == 1)
&& (img->comps[1].dy == 1)
&& (img->comps[2].dy == 1))/* no sub-sample */
{
sycc444_to_rgb(img);
}
else
{
fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__);
return;
}
}/* color_sycc_to_rgb() */
#if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1)
#ifdef OPJ_HAVE_LIBLCMS1
/* Bob Friesenhahn proposed:*/
#define cmsSigXYZData icSigXYZData
#define cmsSigLabData icSigLabData
#define cmsSigCmykData icSigCmykData
#define cmsSigYCbCrData icSigYCbCrData
#define cmsSigLuvData icSigLuvData
#define cmsSigGrayData icSigGrayData
#define cmsSigRgbData icSigRgbData
#define cmsUInt32Number DWORD
#define cmsColorSpaceSignature icColorSpaceSignature
#define cmsGetHeaderRenderingIntent cmsTakeRenderingIntent
#endif /* OPJ_HAVE_LIBLCMS1 */
/*#define DEBUG_PROFILE*/
void color_apply_icc_profile(opj_image_t *image)
{
cmsHPROFILE in_prof, out_prof;
cmsHTRANSFORM transform;
cmsColorSpaceSignature in_space, out_space;
cmsUInt32Number intent, in_type, out_type;
int *r, *g, *b;
size_t nr_samples, i, max, max_w, max_h;
int prec, ok = 0;
OPJ_COLOR_SPACE new_space;
in_prof = cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len);
#ifdef DEBUG_PROFILE
FILE *icm = fopen("debug.icm","wb");
fwrite( image->icc_profile_buf,1, image->icc_profile_len,icm);
fclose(icm);
#endif
if(in_prof == NULL) return;
in_space = cmsGetPCS(in_prof);
out_space = cmsGetColorSpace(in_prof);
intent = cmsGetHeaderRenderingIntent(in_prof);
max_w = image->comps[0].w;
max_h = image->comps[0].h;
prec = (int)image->comps[0].prec;
if(out_space == cmsSigRgbData) /* enumCS 16 */
{
if( prec <= 8 )
{
in_type = TYPE_RGB_8;
out_type = TYPE_RGB_8;
}
else
{
in_type = TYPE_RGB_16;
out_type = TYPE_RGB_16;
}
out_prof = cmsCreate_sRGBProfile();
new_space = OPJ_CLRSPC_SRGB;
}
else if(out_space == cmsSigGrayData) /* enumCS 17 */
{
in_type = TYPE_GRAY_8;
out_type = TYPE_RGB_8;
out_prof = cmsCreate_sRGBProfile();
new_space = OPJ_CLRSPC_SRGB;
}
else if(out_space == cmsSigYCbCrData) /* enumCS 18 */
{
in_type = TYPE_YCbCr_16;
out_type = TYPE_RGB_16;
out_prof = cmsCreate_sRGBProfile();
new_space = OPJ_CLRSPC_SRGB;
}
else
{
#ifdef DEBUG_PROFILE
fprintf(stderr,"%s:%d: color_apply_icc_profile\n\tICC Profile has unknown "
"output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n",
__FILE__,__LINE__,out_space,
(out_space>>24) & 0xff,(out_space>>16) & 0xff,
(out_space>>8) & 0xff, out_space & 0xff);
#endif
cmsCloseProfile(in_prof);
return;
}
if(out_prof == NULL)
{
cmsCloseProfile(in_prof);
return;
}
#ifdef DEBUG_PROFILE
fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)"
"\n\tprofile: in(%p) out(%p)\n",__FILE__,__LINE__,image->numcomps,prec,
max_w,max_h, (void*)in_prof,(void*)out_prof);
fprintf(stderr,"\trender_intent (%u)\n\t"
"color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t"
" type: in(%u) out:(%u)\n",
intent,
in_space,
(in_space>>24) & 0xff,(in_space>>16) & 0xff,
(in_space>>8) & 0xff, in_space & 0xff,
out_space,
(out_space>>24) & 0xff,(out_space>>16) & 0xff,
(out_space>>8) & 0xff, out_space & 0xff,
in_type,out_type
);
#else
(void)prec;
(void)in_space;
#endif /* DEBUG_PROFILE */
transform = cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0);
#ifdef OPJ_HAVE_LIBLCMS2
/* Possible for: LCMS_VERSION >= 2000 :*/
cmsCloseProfile(in_prof);
cmsCloseProfile(out_prof);
#endif
if(transform == NULL)
{
#ifdef DEBUG_PROFILE
fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
"ICC Profile ignored.\n",__FILE__,__LINE__);
#endif
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in_prof);
cmsCloseProfile(out_prof);
#endif
return;
}
if(image->numcomps > 2)/* RGB, RGBA */
{
if( prec <= 8 )
{
unsigned char *inbuf, *outbuf, *in, *out;
max = max_w * max_h;
nr_samples = (size_t)(max * 3U * sizeof(unsigned char));
in = inbuf = (unsigned char*)malloc(nr_samples);
out = outbuf = (unsigned char*)malloc(nr_samples);
if(inbuf == NULL || outbuf == NULL) goto fails0;
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0U; i < max; ++i)
{
*in++ = (unsigned char)*r++;
*in++ = (unsigned char)*g++;
*in++ = (unsigned char)*b++;
}
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0U; i < max; ++i)
{
*r++ = (int)*out++;
*g++ = (int)*out++;
*b++ = (int)*out++;
}
ok = 1;
fails0:
free(inbuf);
free(outbuf);
}
else /* prec > 8 */
{
unsigned short *inbuf, *outbuf, *in, *out;
max = max_w * max_h;
nr_samples = (size_t)(max * 3U * sizeof(unsigned short));
in = inbuf = (unsigned short*)malloc(nr_samples);
out = outbuf = (unsigned short*)malloc(nr_samples);
if(inbuf == NULL || outbuf == NULL) goto fails1;
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0U ; i < max; ++i)
{
*in++ = (unsigned short)*r++;
*in++ = (unsigned short)*g++;
*in++ = (unsigned short)*b++;
}
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i)
{
*r++ = (int)*out++;
*g++ = (int)*out++;
*b++ = (int)*out++;
}
ok = 1;
fails1:
free(inbuf);
free(outbuf);
}
}
else /* image->numcomps <= 2 : GRAY, GRAYA */
{
if(prec <= 8)
{
unsigned char *in, *inbuf, *out, *outbuf;
opj_image_comp_t *new_comps;
max = max_w * max_h;
nr_samples = (size_t)(max * 3 * sizeof(unsigned char));
in = inbuf = (unsigned char*)malloc(nr_samples);
out = outbuf = (unsigned char*)malloc(nr_samples);
g = (int*)calloc((size_t)max, sizeof(int));
b = (int*)calloc((size_t)max, sizeof(int));
if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails2;
new_comps = (opj_image_comp_t*)realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t));
if(new_comps == NULL) goto fails2;
image->comps = new_comps;
if(image->numcomps == 2)
image->comps[3] = image->comps[1];
image->comps[1] = image->comps[0];
image->comps[2] = image->comps[0];
image->comps[1].data = g;
image->comps[2].data = b;
image->numcomps += 2;
r = image->comps[0].data;
for(i = 0U; i < max; ++i)
{
*in++ = (unsigned char)*r++;
}
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0U; i < max; ++i)
{
*r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++;
}
r = g = b = NULL;
ok = 1;
fails2:
free(inbuf);
free(outbuf);
free(g);
free(b);
}
else /* prec > 8 */
{
unsigned short *in, *inbuf, *out, *outbuf;
opj_image_comp_t *new_comps;
max = max_w * max_h;
nr_samples = (size_t)(max * 3U * sizeof(unsigned short));
in = inbuf = (unsigned short*)malloc(nr_samples);
out = outbuf = (unsigned short*)malloc(nr_samples);
g = (int*)calloc((size_t)max, sizeof(int));
b = (int*)calloc((size_t)max, sizeof(int));
if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails3;
new_comps = (opj_image_comp_t*)realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t));
if(new_comps == NULL) goto fails3;
image->comps = new_comps;
if(image->numcomps == 2)
image->comps[3] = image->comps[1];
image->comps[1] = image->comps[0];
image->comps[2] = image->comps[0];
image->comps[1].data = g;
image->comps[2].data = b;
image->numcomps += 2;
r = image->comps[0].data;
for(i = 0U; i < max; ++i)
{
*in++ = (unsigned short)*r++;
}
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i)
{
*r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++;
}
r = g = b = NULL;
ok = 1;
fails3:
free(inbuf);
free(outbuf);
free(g);
free(b);
}
}/* if(image->numcomps > 2) */
cmsDeleteTransform(transform);
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in_prof);
cmsCloseProfile(out_prof);
#endif
if(ok)
{
image->color_space = new_space;
}
}/* color_apply_icc_profile() */
void color_cielab_to_rgb(opj_image_t *image)
{
int *row;
int enumcs, numcomps;
OPJ_COLOR_SPACE new_space;
numcomps = (int)image->numcomps;
if(numcomps != 3)
{
fprintf(stderr,"%s:%d:\n\tnumcomps %d not handled. Quitting.\n",
__FILE__,__LINE__,numcomps);
return;
}
row = (int*)image->icc_profile_buf;
enumcs = row[0];
if(enumcs == 14) /* CIELab */
{
int *L, *a, *b, *red, *green, *blue;
int *src0, *src1, *src2, *dst0, *dst1, *dst2;
double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2;
double minL, maxL, mina, maxa, minb, maxb;
unsigned int default_type;
unsigned int i, max;
cmsHPROFILE in, out;
cmsHTRANSFORM transform;
cmsUInt16Number RGB[3];
cmsCIELab Lab;
in = cmsCreateLab4Profile(NULL);
if(in == NULL){
return;
}
out = cmsCreate_sRGBProfile();
if(out == NULL){
cmsCloseProfile(in);
return;
}
transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, INTENT_PERCEPTUAL, 0);
#ifdef OPJ_HAVE_LIBLCMS2
cmsCloseProfile(in);
cmsCloseProfile(out);
#endif
if(transform == NULL)
{
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in);
cmsCloseProfile(out);
#endif
return;
}
new_space = OPJ_CLRSPC_SRGB;
prec0 = (double)image->comps[0].prec;
prec1 = (double)image->comps[1].prec;
prec2 = (double)image->comps[2].prec;
default_type = (unsigned int)row[1];
if(default_type == 0x44454600)/* DEF : default */
{
rl = 100; ra = 170; rb = 200;
ol = 0;
oa = pow(2, prec1 - 1);
ob = pow(2, prec2 - 2) + pow(2, prec2 - 3);
}
else
{
rl = row[2]; ra = row[4]; rb = row[6];
ol = row[3]; oa = row[5]; ob = row[7];
}
L = src0 = image->comps[0].data;
a = src1 = image->comps[1].data;
b = src2 = image->comps[2].data;
max = image->comps[0].w * image->comps[0].h;
red = dst0 = (int*)malloc(max * sizeof(int));
green = dst1 = (int*)malloc(max * sizeof(int));
blue = dst2 = (int*)malloc(max * sizeof(int));
if(red == NULL || green == NULL || blue == NULL) goto fails;
minL = -(rl * ol)/(pow(2, prec0)-1);
maxL = minL + rl;
mina = -(ra * oa)/(pow(2, prec1)-1);
maxa = mina + ra;
minb = -(rb * ob)/(pow(2, prec2)-1);
maxb = minb + rb;
for(i = 0; i < max; ++i)
{
Lab.L = minL + (double)(*L) * (maxL - minL)/(pow(2, prec0)-1); ++L;
Lab.a = mina + (double)(*a) * (maxa - mina)/(pow(2, prec1)-1); ++a;
Lab.b = minb + (double)(*b) * (maxb - minb)/(pow(2, prec2)-1); ++b;
cmsDoTransform(transform, &Lab, RGB, 1);
*red++ = RGB[0];
*green++ = RGB[1];
*blue++ = RGB[2];
}
cmsDeleteTransform(transform);
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in);
cmsCloseProfile(out);
#endif
free(src0); image->comps[0].data = dst0;
free(src1); image->comps[1].data = dst1;
free(src2); image->comps[2].data = dst2;
image->color_space = new_space;
image->comps[0].prec = 16;
image->comps[1].prec = 16;
image->comps[2].prec = 16;
return;
fails:
cmsDeleteTransform(transform);
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in);
cmsCloseProfile(out);
#endif
if(red) free(red);
if(green) free(green);
if(blue) free(blue);
return;
}
fprintf(stderr,"%s:%d:\n\tenumCS %d not handled. Ignoring.\n", __FILE__,__LINE__, enumcs);
}/* color_cielab_to_rgb() */
#endif /* OPJ_HAVE_LIBLCMS2 || OPJ_HAVE_LIBLCMS1 */
void color_cmyk_to_rgb(opj_image_t *image)
{
float C, M, Y, K;
float sC, sM, sY, sK;
unsigned int w, h, max, i;
w = image->comps[0].w;
h = image->comps[0].h;
if (
(image->numcomps < 4)
|| (image->comps[0].dx != image->comps[1].dx) || (image->comps[0].dx != image->comps[2].dx) || (image->comps[0].dx != image->comps[3].dx)
|| (image->comps[0].dy != image->comps[1].dy) || (image->comps[0].dy != image->comps[2].dy) || (image->comps[0].dy != image->comps[3].dy)
) {
fprintf(stderr,"%s:%d:color_cmyk_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__);
return;
}
max = w * h;
sC = 1.0F / (float)((1 << image->comps[0].prec) - 1);
sM = 1.0F / (float)((1 << image->comps[1].prec) - 1);
sY = 1.0F / (float)((1 << image->comps[2].prec) - 1);
sK = 1.0F / (float)((1 << image->comps[3].prec) - 1);
for(i = 0; i < max; ++i)
{
/* CMYK values from 0 to 1 */
C = (float)(image->comps[0].data[i]) * sC;
M = (float)(image->comps[1].data[i]) * sM;
Y = (float)(image->comps[2].data[i]) * sY;
K = (float)(image->comps[3].data[i]) * sK;
/* Invert all CMYK values */
C = 1.0F - C;
M = 1.0F - M;
Y = 1.0F - Y;
K = 1.0F - K;
/* CMYK -> RGB : RGB results from 0 to 255 */
image->comps[0].data[i] = (int)(255.0F * C * K); /* R */
image->comps[1].data[i] = (int)(255.0F * M * K); /* G */
image->comps[2].data[i] = (int)(255.0F * Y * K); /* B */
}
free(image->comps[3].data); image->comps[3].data = NULL;
image->comps[0].prec = 8;
image->comps[1].prec = 8;
image->comps[2].prec = 8;
image->numcomps -= 1;
image->color_space = OPJ_CLRSPC_SRGB;
for (i = 3; i < image->numcomps; ++i) {
memcpy(&(image->comps[i]), &(image->comps[i+1]), sizeof(image->comps[i]));
}
}/* color_cmyk_to_rgb() */
/*
* This code has been adopted from sjpx_openjpeg.c of ghostscript
*/
void color_esycc_to_rgb(opj_image_t *image)
{
int y, cb, cr, sign1, sign2, val;
unsigned int w, h, max, i;
int flip_value = (1 << (image->comps[0].prec-1));
int max_value = (1 << image->comps[0].prec) - 1;
if (
(image->numcomps < 3)
|| (image->comps[0].dx != image->comps[1].dx) || (image->comps[0].dx != image->comps[2].dx)
|| (image->comps[0].dy != image->comps[1].dy) || (image->comps[0].dy != image->comps[2].dy)
) {
fprintf(stderr,"%s:%d:color_esycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__);
return;
}
w = image->comps[0].w;
h = image->comps[0].h;
sign1 = (int)image->comps[1].sgnd;
sign2 = (int)image->comps[2].sgnd;
max = w * h;
for(i = 0; i < max; ++i)
{
y = image->comps[0].data[i]; cb = image->comps[1].data[i]; cr = image->comps[2].data[i];
if( !sign1) cb -= flip_value;
if( !sign2) cr -= flip_value;
val = (int)
((float)y - (float)0.0000368 * (float)cb
+ (float)1.40199 * (float)cr + (float)0.5);
if(val > max_value) val = max_value; else if(val < 0) val = 0;
image->comps[0].data[i] = val;
val = (int)
((float)1.0003 * (float)y - (float)0.344125 * (float)cb
- (float)0.7141128 * (float)cr + (float)0.5);
if(val > max_value) val = max_value; else if(val < 0) val = 0;
image->comps[1].data[i] = val;
val = (int)
((float)0.999823 * (float)y + (float)1.77204 * (float)cb
- (float)0.000008 *(float)cr + (float)0.5);
if(val > max_value) val = max_value; else if(val < 0) val = 0;
image->comps[2].data[i] = val;
}
image->color_space = OPJ_CLRSPC_SRGB;
}/* color_esycc_to_rgb() */

View File

@ -1,47 +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) 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 _OPJ_COLOR_H_
#define _OPJ_COLOR_H_
extern void color_sycc_to_rgb(opj_image_t *img);
extern void color_apply_icc_profile(opj_image_t *image);
extern void color_cielab_to_rgb(opj_image_t *image);
extern void color_cmyk_to_rgb(opj_image_t *image);
extern void color_esycc_to_rgb(opj_image_t *image);
#endif /* _OPJ_COLOR_H_ */

View File

@ -1,55 +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) 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 _OPJ_FORMAT_DEFS_H_
#define _OPJ_FORMAT_DEFS_H_
#define J2K_CFMT 0
#define JP2_CFMT 1
#define JPT_CFMT 2
#define PXM_DFMT 10
#define PGX_DFMT 11
#define BMP_DFMT 12
#define YUV_DFMT 13
#define TIF_DFMT 14
#define RAW_DFMT 15 /* MSB / Big Endian */
#define TGA_DFMT 16
#define PNG_DFMT 17
#define RAWL_DFMT 18 /* LSB / Little Endian */
#endif /* _OPJ_FORMAT_DEFS_H_ */

View File

@ -1,15 +0,0 @@
#include "opj_config_private.h"
/* create opj_apps_config.h for CMake */
#cmakedefine OPJ_HAVE_LIBPNG @HAVE_LIBPNG@
#cmakedefine OPJ_HAVE_PNG_H @HAVE_PNG_H@
#cmakedefine OPJ_HAVE_LIBTIFF @HAVE_LIBTIFF@
#cmakedefine OPJ_HAVE_TIFF_H @HAVE_TIFF_H@
#cmakedefine OPJ_HAVE_LIBLCMS1
#cmakedefine OPJ_HAVE_LIBLCMS2
#cmakedefine OPJ_HAVE_LCMS1_H
#cmakedefine OPJ_HAVE_LCMS2_H

View File

@ -1,255 +0,0 @@
/*
* 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.
*
* 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. 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[] = "@(#)opj_getopt.c 8.3 (Berkeley) 4/27/95";
#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 */
#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;
}
/*
* getopt --
* Parse argc/argv argument vector.
*/
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 */
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 (*++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;
again:
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 (param == 0) {
++opj_optind;
return (BADCH);
}
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){
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);
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);;
}/*end function*/

View File

@ -1,29 +0,0 @@
/* last review : october 29th, 2002 */
#ifndef _GETOPT_H_
#define _GETOPT_H_
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
extern int opj_opterr;
extern int opj_optind;
extern int opj_optopt;
extern int opj_optreset;
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);
extern void opj_reset_options_reading(void);
#endif /* _GETOPT_H_ */

View File

@ -1,72 +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) 2015, Matthieu Darbois
* 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 OPJ_STRING_H
#define OPJ_STRING_H
#include <errno.h>
#include <string.h>
/* strnlen is not standard, strlen_s is C11... */
/* 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;
}
/* 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;
}
#endif /* OPJ_STRING_H */

View File

@ -1,85 +0,0 @@
# Build the demo app, small examples
# First thing define the common source:
set(common_SRCS
convert.c
convert.h
convertbmp.c
index.c
index.h
${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/color.h
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_string.h
)
if(OPJ_HAVE_LIBTIFF)
list(APPEND common_SRCS converttif.c)
endif()
if(OPJ_HAVE_LIBPNG)
list(APPEND common_SRCS convertpng.c)
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/openjp2
${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()
# Loop over all executables:
foreach(exe opj_decompress opj_compress opj_dump)
add_executable(${exe} ${exe}.c ${common_SRCS})
target_link_libraries(${exe} ${OPENJPEG_LIBRARY_NAME}
${PNG_LIBNAME} ${TIFF_LIBNAME} ${LCMS_LIBNAME}
)
# To support universal exe:
if(ZLIB_FOUND AND APPLE)
target_link_libraries(${exe} z)
else(ZLIB_FOUND AND APPLE)
target_link_libraries(${exe} ${Z_LIBNAME})
endif()
# On unix you need to link to the math library:
if(UNIX)
target_link_libraries(${exe} m)
IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
target_link_libraries(${exe} rt)
endif()
endif()
# Install exe
install(TARGETS ${exe}
EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
if(OPJ_USE_DSYMUTIL)
add_custom_command(TARGET ${exe} POST_BUILD
COMMAND "dsymutil" "$<TARGET_FILE:${exe}>"
COMMENT "dsymutil $<TARGET_FILE:${exe}>"
DEPENDS ${exe})
endif()
endforeach()
if(BUILD_DOC)
# Install man pages
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 ${OPENJPEG_INSTALL_MAN_DIR}/man1)
#
endif()

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