Compare commits

..

5 Commits

Author SHA1 Message Date
Antonin Descampe
0febbff19e processed all c/h files through astyle with opj_astyle.cfg 2016-01-25 23:22:06 +01:00
Antonin Descampe
bede1568b1 Merge branch 'master' into codingstyle 2016-01-25 22:43:03 +01:00
Antonin Descampe
6ec68a27f8 modified astyle config 2016-01-25 15:03:21 +01:00
Antonin Descampe
4b927ecea3 modified style cfg 2016-01-24 19:00:31 +01:00
Antonin Descampe
0efb2f5293 adding astyle and uncrustify config files 2016-01-24 18:54:13 +01:00
393 changed files with 75998 additions and 80905 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

@@ -4,13 +4,10 @@ matrix:
include: include:
- os: osx - os: osx
compiler: clang compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1 env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
- os: linux - os: linux
compiler: gcc compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1 env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_NUM_THREADS=2
- os: linux - os: linux
compiler: gcc compiler: gcc
env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
@@ -24,16 +21,6 @@ matrix:
- os: linux - os: linux
compiler: clang compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_ASAN=1 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 - os: linux
compiler: x86_64-w64-mingw32-gcc compiler: x86_64-w64-mingw32-gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
@@ -74,20 +61,3 @@ install:
script: script:
- ./tools/travis-ci/run.sh - ./tools/travis-ci/run.sh
- ./tools/travis-ci/abi-check.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,18 +1,12 @@
# Authors of OpenJPEG Authors of OpenJPEG
See also [THANKS](https://github.com/uclouvain/openjpeg/blob/master/THANKS.md) See also the files THANKS and CHANGES
David Janssens designed and implemented the first version of OpenJPEG. David Janssens designed and implemented the first version of OpenJPEG.
Kaori Hagihara designed and implemented the first version of OpenJPIP. Kaori Hagihara designed and implemented the first version of OpenJPIP.
Jerome Fimes implemented the alpha version of OpenJPEG 2.0. Jerome Fimes implemented the alpha version of OpenJPEG 2.0.
Giuseppe Baruffa added the JPWL functionalities. 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.
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. Mathieu Malaterre participated to the OpenJPEG 2.0 version and improved the libraries and utilities.
Yannick Verschueren, Yannick Verschueren,
Herve Drolon, Herve Drolon,
Francois-Olivier Devaux, Francois-Olivier Devaux,

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

@@ -32,7 +32,7 @@ include_regular_expression("^.*$")
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# OPENJPEG version number, useful for packaging and doxygen doc: # OPENJPEG version number, useful for packaging and doxygen doc:
set(OPENJPEG_VERSION_MAJOR 2) set(OPENJPEG_VERSION_MAJOR 2)
set(OPENJPEG_VERSION_MINOR 2) set(OPENJPEG_VERSION_MINOR 1)
set(OPENJPEG_VERSION_BUILD 0) set(OPENJPEG_VERSION_BUILD 0)
set(OPENJPEG_VERSION set(OPENJPEG_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}") "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
@@ -52,14 +52,11 @@ set(PACKAGE_VERSION
# 2.0 | 6 # 2.0 | 6
# 2.0.1 | 6 # 2.0.1 | 6
# 2.1 | 7 # 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, # 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: # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
# cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
if(NOT OPENJPEG_SOVERSION) if(NOT OPENJPEG_SOVERSION)
set(OPENJPEG_SOVERSION 7) SET(OPENJPEG_SOVERSION 7)
endif(NOT OPENJPEG_SOVERSION) endif(NOT OPENJPEG_SOVERSION)
set(OPENJPEG_LIBRARY_PROPERTIES set(OPENJPEG_LIBRARY_PROPERTIES
VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}" VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
@@ -69,7 +66,7 @@ set(OPENJPEG_LIBRARY_PROPERTIES
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Path to additional CMake modules # Path to additional CMake modules
set(CMAKE_MODULE_PATH set(CMAKE_MODULE_PATH
${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR}/cmake
${CMAKE_MODULE_PATH}) ${CMAKE_MODULE_PATH})
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
@@ -165,8 +162,8 @@ TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Setup file for setting custom ctest vars # Setup file for setting custom ctest vars
configure_file( configure_file(
${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in ${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake.in
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake ${CMAKE_BINARY_DIR}/CTestCustom.cmake
@ONLY @ONLY
) )
@@ -193,7 +190,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
# For all builds, make sure openjpeg is std99 compliant: # 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. # 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: # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>") SET(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
endif() endif()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
@@ -228,7 +225,7 @@ CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
include(TestLargeFiles) include(TestLargeFiles)
OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES) OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
# Allocating Aligned Memory Blocks # Allocating Aligned Memory Blocks
include(CheckIncludeFiles) include(CheckIncludeFiles)
check_include_files(malloc.h OPJ_HAVE_MALLOC_H) check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
include(CheckSymbolExists) include(CheckSymbolExists)
@@ -251,7 +248,6 @@ if(BUILD_JPIP_SERVER)
endif() endif()
endif() endif()
add_subdirectory(src/lib) add_subdirectory(src/lib)
option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Build Applications # Build Applications
@@ -285,7 +281,7 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
@ONLY @ONLY
) )
configure_file( configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
@@ -325,8 +321,8 @@ endif()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# install all targets referenced as OPENJPEGTargets # install all targets referenced as OPENJPEGTargets
install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}) install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
configure_file( ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in configure_file( ${OPENJPEG_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/OpenJPEGConfig.cmake ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
@ONLY @ONLY
) )
install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake

69
INSTALL Normal file
View File

@@ -0,0 +1,69 @@
How to build and install openjpeg binaries
==========================================
UNIX/LINUX/MacOSX/Windows systems
--------------------------
Using cmake (see www.cmake.org)
Type:
cmake .
make
If you are root:
make install
else if you have sudo power:
sudo make install
else
DESTDIR=$HOME/local make install
To build the Doxygen documentation (Doxygen needs to be found on the system):
(A 'html' directory is generated in the 'doc' directory)
make doc
Binaries are located in the 'bin' directory.
Main available cmake flags:
* To specify the install path: '-DCMAKE_INSTALL_PREFIX=/path', or use DESTDIR env variable (see above)
* 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')
* To build the documentation: '-DBUILD_DOC:bool=on' (default: 'OFF')
* To build the MJ2 executables: '-DBUILD_MJ2:bool=on' (default: 'OFF')
* To build the JPWL executables and JPWL library: '-DBUILD_JPWL:bool=on' (default: 'OFF')
* To build the JPIP library and utilities: '-DBUILD_JPIP:bool=on' (default: 'OFF')
** To build the JPIP server: '-DBUILD_JPIP_SERVER:bool=on' (default: 'OFF')
* To build the JP3D library and utilities: '-DBUILD_JP3D:bool=on' (default: 'OFF') (experimental)
* To build the Java binding: '-DBUILD_JAVA:bool=on' (default: 'OFF') (experimental).
** to choose which java implementation, you can set your JAVA_HOME env var.
* To build the wxWidgets/C++ viewer: 'BUILD_VIEWER:BOOL=ON' (default OFF) (experimental)
* 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'
make
make Experimental
Note : JPEG2000 test files are available with 'git clone https://github.com/uclouvain/openjpeg-data.git'.
If '-DOPJ_DATA_ROOT:PATH' option is omitted, test files will be automatically searched in '${CMAKE_SOURCE_DIR}/../data',
corresponding to the location of the data directory when compiling from the trunk (and assuming the data directory has
been checked out of course).
MACOSX
------
The same building procedures as above work for MACOSX.
The xcode project file can also be used.
If it does not work, try adding the following flag to the cmake command :
'-DCMAKE_OSX_ARCHITECTURES:STRING=i386'
WINDOWS
-------
You can use cmake to generate project files for the IDE you are using (VS2010, NMake, etc).
Type 'cmake --help' for available generators on your platform.
Make sure to build the third party libs (png, zlib ...):
'-DBUILD_THIRDPARTY:BOOL=ON'

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})
```

61
NEWS Normal file
View File

@@ -0,0 +1,61 @@
OpenJPEG NEWS - user visible changes
====================================
Changes from OpenJPEG 2.0.0 to OpenJPEG 2.X.X
----------------------------------------------
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 abi_compat_report in dev-utils/scripts)
* 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.
Changes from OpenJPEG 1.5.x to OpenJPEG 2.0.0
----------------------------------------------
New Features:
* streaming capabilities
* merge JP3D
API modifications:
* Use a 64bits capable API
Misc:
* removed autotools build system
* folders hierarchies reorganisation
* Huge amount of bug fixes. See CHANGES for details.

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,7 +1,7 @@
# OPENJPEG Library and Applications # OPENJPEG Library and Applications
## What is OpenJPEG ? ## 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). 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).
@@ -52,14 +52,12 @@ The library is developed and maintained by the Image and Signal Processing Group
See [LICENSE][link-license] for license and copyright information. See [LICENSE][link-license] for license and copyright information.
See [INSTALL](https://github.com/uclouvain/openjpeg/blob/master/INSTALL.md) for installation procedures. See [INSTALL](https://github.com/uclouvain/openjpeg/blob/master/INSTALL) for installation procedures.
See [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) for user visible changes in successive releases. See [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS) for user visible changes in successive releases.
## API/ABI ## 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 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 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 exporting/hiding functions. If you are unsure which functions you can use in
@@ -79,4 +77,3 @@ API available is the one supported by OpenJPEG.
[link-msvc-build]: https://ci.appveyor.com/project/detonin/openjpeg/branch/master "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" [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-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"

35
THANKS Normal file
View File

@@ -0,0 +1,35 @@
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
Sebastien Lugan
Benoit Macq
Arnaud Maye
Julien Malik
Vincent Nicolas
Glenn Pearson
Dzonatas Sol
Winfried Szukalski
Vincent Torri
Yannick Verschueren
Peter Wimmer

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

@@ -2,16 +2,14 @@ version: 2.1.1.{build}
branches: branches:
except: except:
- coverity_scan - coverity_scan
skip_tags: false skip_tags: true
clone_depth: 50 clone_depth: 50
environment: environment:
matrix: matrix:
- OPJ_CI_ARCH: x86 - OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS) OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
OPJ_CI_INCLUDE_IF_DEPLOY: 1
- OPJ_CI_ARCH: x64 - OPJ_CI_ARCH: x64
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS) OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
OPJ_CI_INCLUDE_IF_DEPLOY: 1
- OPJ_CI_ARCH: x86 - OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS100COMNTOOLS) OPJ_CI_VSCOMNTOOLS: $(VS100COMNTOOLS)
install: install:
@@ -22,17 +20,4 @@ build_script:
bash ./tools/travis-ci/run.sh bash ./tools/travis-ci/run.sh
test: off test: off
#before_deploy: deploy: off
#- 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

@@ -25,9 +25,6 @@ set(CTEST_CUSTOM_COVERAGE_EXCLUDE
set(CTEST_CUSTOM_WARNING_EXCEPTION set(CTEST_CUSTOM_WARNING_EXCEPTION
${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 # Suppress warning caused by intentional messages about deprecation
".*warning,.* is deprecated" ".*warning,.* is deprecated"
# java also warns about deprecated API # java also warns about deprecated API

View File

@@ -1,5 +1,5 @@
# Ensure that an include file is provided by the system # Ensure that an include file is provided by the system
# Add the check about the mandatory status to the check_include_file macro # Add the check about the mandatory status to the check_include_file macro
# provided by cmake # provided by cmake
include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
@@ -23,4 +23,4 @@ if (NOT ${${VARIABLE_NAME}})
endif() endif()
endif() endif()
endmacro() endmacro()

View File

@@ -2,10 +2,10 @@
/* Cause a compile-time error if off_t is smaller than 64 bits */ /* 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)) #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 off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
return 0; return 0;
} }

View File

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

View File

@@ -145,7 +145,7 @@ HTML_STYLESHEET =
HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80 HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = NO HTML_TIMESTAMP = NO
HTML_ALIGN_MEMBERS = YES HTML_ALIGN_MEMBERS = YES
HTML_DYNAMIC_SECTIONS = NO HTML_DYNAMIC_SECTIONS = NO
GENERATE_DOCSET = NO GENERATE_DOCSET = NO

View File

@@ -32,7 +32,7 @@
.TH opj_compress 1 "Version 2.1.1" "opj_compress" "converts to jpeg2000 files" .TH opj_compress 1 "Version 2.1.1" "opj_compress" "converts to jpeg2000 files"
.P .P
.SH NAME .SH NAME
opj_compress \- opj_compress -
This program reads in an image of a certain type and converts it to a This program reads in an image of a certain type and converts it to a
jpeg2000 file. It is part of the OpenJPEG library. jpeg2000 file. It is part of the OpenJPEG library.
.SP .SP
@@ -43,20 +43,20 @@ Valid output image extensions are
.B .j2k, .jp2 .B .j2k, .jp2
.SH SYNOPSIS .SH SYNOPSIS
.P .P
.B opj_compress \-i \fRinfile.bmp \fB-o \fRoutfile.j2k .B opj_compress -i \fRinfile.bmp \fB-o \fRoutfile.j2k
.P .P
.B opj_compress \-ImgDir \fRdirectory_name \fB-OutFor \fRjp2 .B opj_compress -ImgDir \fRdirectory_name \fB-OutFor \fRjp2
.P .P
.B opj_compress \-h \fRPrint a help message and exit. .B opj_compress -h \fRPrint a help message and exit.
.P .P
.R See JPWL OPTIONS for special options .R See JPWL OPTIONS for special options
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-\^b " n,n" .B \-\^b " n,n"
(Size of code block (e.g. \-b 32,32). Default: 64 x 64) (Size of code block (e.g. -b 32,32). Default: 64 x 64)
.TP .TP
.B \-\^c " n" .B \-\^c " n"
(Size of precinct (e.g. \-c 128,128). Default: 2^15 x 2^15) (Size of precinct (e.g. -c 128,128). Default: 2^15 x 2^15)
.TP .TP
.B \-\^cinema2K " fps" .B \-\^cinema2K " fps"
Digital Cinema 2K profile compliant codestream. Valid \fBfps\fR values are 24 or 48. Digital Cinema 2K profile compliant codestream. Valid \fBfps\fR values are 24 or 48.
@@ -65,7 +65,7 @@ Digital Cinema 2K profile compliant codestream. Valid \fBfps\fR values are 24 or
Digital Cinema 4K profile compliant codestream. Does not need an fps: default is 24 fps. Digital Cinema 4K profile compliant codestream. Does not need an fps: default is 24 fps.
.TP .TP
.B \-\^d " X,Y" .B \-\^d " X,Y"
(Offset of image origin (e.g. \-d 150,300)) (Offset of image origin (e.g. -d 150,300))
.TP .TP
.B \-\^h .B \-\^h
Print a help message and exit. Print a help message and exit.
@@ -85,20 +85,20 @@ Progression order. \fBname\fR can be one out of:LRCP, RLCP, RPCL, PCRL, CPRL. De
.B \-\^q " n" .B \-\^q " n"
different psnr for successive layers different psnr for successive layers
.br .br
.B Note: \fR(options \-r and \-q cannot be used together) .B Note: \fR(options -r and -q cannot be used together)
.TP .TP
.B \-\^r " n" .B \-\^r " n"
different compression ratio(s) for successive layers. The rate specified for each quality level is the desired compression factor. different compression ratio(s) for successive layers. The rate specified for each quality level is the desired compression factor.
.br .br
.B Note: \fR(options \-r and \-q cannot be used together) .B Note: \fR(options -r and -q cannot be used together)
.TP .TP
.B \-\^s " X,Y" .B \-\^s " X,Y"
sub-sampling factor (e.g. \-s 2,2). Default: No sub-sampling in x or y direction. sub-sampling factor (e.g. -s 2,2). Default: No sub-sampling in x or y direction.
.br .br
.B Remark: \fRsub-sampling bigger than 2 can produce errors. .B Remark: \fRsub-sampling bigger than 2 can produce errors.
.TP .TP
.B \-\^t " W,H" .B \-\^t " W,H"
(Size of tile (e.g. \-t 512,512) ) (Size of tile (e.g. -t 512,512) )
.TP .TP
.B \-\^x " name" .B \-\^x " name"
(Create index file and fill it. Default: no index file) (Create index file and fill it. Default: no index file)
@@ -132,7 +132,7 @@ ERTERM(16)
.br .br
SEGMARK(32) SEGMARK(32)
.br .br
Values can be added: RESTART(4) + RESET(2) + SEGMARK(32) = \-M 38 Values can be added: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38
.TP .TP
.B \-\^OutFor "ext" .B \-\^OutFor "ext"
(extension for output files) (extension for output files)
@@ -149,7 +149,7 @@ e.g. \fB-ROI c=0,U=25\fR
(Write SOP marker before each packet. Default: No SOP marker in the codestream.) (Write SOP marker before each packet. Default: No SOP marker in the codestream.)
.TP .TP
.B \-\^T "X,Y" .B \-\^T "X,Y"
(Offset of the origin of the tiles (e.g. \-T 100,75) ) (Offset of the origin of the tiles (e.g. -T 100,75) )
.TP .TP
.B \-\^W .B \-\^W
(see JPWL OPTIONS) (see JPWL OPTIONS)
@@ -157,7 +157,7 @@ e.g. \fB-ROI c=0,U=25\fR
.SH JPWL OPTIONS .SH JPWL OPTIONS
Options usable only if the library has been compiled with \fB-DUSE_JPWL\fR Options usable only if the library has been compiled with \fB-DUSE_JPWL\fR
.P .P
.B \-W h<tilepart><=type>, s<tilepart><=method>, a=<addr>, z=<size>, g=<range>, p<tilepart:pack><=type> .B -W h<tilepart><=type>, s<tilepart><=method>, a=<addr>, z=<size>, g=<range>, p<tilepart:pack><=type>
.P .P
.B h\fR selects the header error protection (EPB): \fBtype\fR can be .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] [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]
@@ -176,7 +176,7 @@ Options usable only if the library has been compiled with \fB-DUSE_JPWL\fR
(max. 16 specs) (max. 16 specs)
.P .P
.B s \fRenables sensitivity data insertion (ESD): \fBmethod\fR can be .B s \fRenables sensitivity data insertion (ESD): \fBmethod\fR can be
[\-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR [-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR
4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED] 4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]
if \fBtilepart\fR is absent, it is for main header only if \fBtilepart\fR is absent, it is for main header only
if \fBtilepart\fR is present, it applies from that tile if \fBtilepart\fR is present, it applies from that tile
@@ -194,13 +194,13 @@ Options usable only if the library has been compiled with \fB-DUSE_JPWL\fR
.P .P
.SH EXAMPLES .SH EXAMPLES
.P .P
.B opj_compress \-i \fRfile.bmp \fB-o \fRfile.j2k \fB-r \fR20,10,1 (compress 20x, then 10x, then lossless). .B opj_compress -i \fRfile.bmp \fB-o \fRfile.j2k \fB-r \fR20,10,1 (compress 20x, then 10x, then lossless).
.P .P
.B opj_compress \-i \fRfile.ppm \fB-o \fRfile.j2k \fB-q \fR30,40,50 .B opj_compress -i \fRfile.ppm \fB-o \fRfile.j2k \fB-q \fR30,40,50
.P .P
.B opj_compress \-i \fRfile.pgx \fB-o \fRfile.j2k \fB-POC \fRT1=0,0,1,5,3,CPRL .B opj_compress -i \fRfile.pgx \fB-o \fRfile.j2k \fB-POC \fRT1=0,0,1,5,3,CPRL
.P .P
.B opj_compress \-i \fRlena.raw \fB-o \fRlena.j2k \fB-F \fR512,512,3,8,u .B opj_compress -i \fRlena.raw \fB-o \fRlena.j2k \fB-F \fR512,512,3,8,u
.P .P
.SH AUTHORS .SH AUTHORS
Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium

View File

@@ -32,7 +32,7 @@
.TH opj_decompress 1 "Version 2.1.1" "opj_decompress" "converts jpeg2000 files" .TH opj_decompress 1 "Version 2.1.1" "opj_decompress" "converts jpeg2000 files"
.P .P
.SH NAME .SH NAME
opj_decompress \- opj_decompress -
This program reads in a jpeg2000 image and converts it to another This program reads in a jpeg2000 image and converts it to another
image type. It is part of the OpenJPEG library. image type. It is part of the OpenJPEG library.
.SP .SP
@@ -43,11 +43,11 @@ 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 . .B .bmp, .pgm, .pgx, .png, .pnm, .ppm, .raw, .tga, .tif \fR. For PNG resp. TIF it needs libpng resp. libtiff .
.SH SYNOPSIS .SH SYNOPSIS
.P .P
.B opj_decompress \-i \fRinfile.j2k \fB-o \fRoutfile.png .B opj_decompress -i \fRinfile.j2k \fB-o \fRoutfile.png
.P .P
.B opj_decompress \-ImgDir \fRimages/ \fB-OutFor \fRbmp .B opj_decompress -ImgDir \fRimages/ \fB-OutFor \fRbmp
.P .P
.B opj_decompress \-h \fRPrint help message and exit .B opj_decompress -h \fRPrint help message and exit
.P .P
.R See JPWL OPTIONS for special options .R See JPWL OPTIONS for special options
.SH OPTIONS .SH OPTIONS

View File

@@ -32,7 +32,7 @@
.TH opj_dump 1 "Version 2.1.1" "opj_dump" "dumps jpeg2000 files" .TH opj_dump 1 "Version 2.1.1" "opj_dump" "dumps jpeg2000 files"
.P .P
.SH NAME .SH NAME
opj_dump \- opj_dump -
This program reads in a jpeg2000 image and dumps the contents to stdout. It is part of the OpenJPEG library. This program reads in a jpeg2000 image and dumps the contents to stdout. It is part of the OpenJPEG library.
.SP .SP
Valid input image extensions are Valid input image extensions are
@@ -40,11 +40,11 @@ Valid input image extensions are
.SP .SP
.SH SYNOPSIS .SH SYNOPSIS
.P .P
.B opj_dump \-i \fRinfile.j2k .B opj_dump -i \fRinfile.j2k
.P .P
.B opj_dump \-ImgDir \fRimages/ \fRDump all files in images/ .B opj_dump -ImgDir \fRimages/ \fRDump all files in images/
.P .P
.B opj_dump \-h \fRPrint help message and exit .B opj_dump -h \fRPrint help message and exit
.P .P
.SH OPTIONS .SH OPTIONS
.TP .TP

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@@ -3,13 +3,12 @@
#ifndef _GETOPT_H_ #ifndef _GETOPT_H_
#define _GETOPT_H_ #define _GETOPT_H_
typedef struct opj_option typedef struct opj_option {
{ const char *name;
const char *name; int has_arg;
int has_arg; int *flag;
int *flag; int val;
int val; } opj_option_t;
}opj_option_t;
#define NO_ARG 0 #define NO_ARG 0
#define REQ_ARG 1 #define REQ_ARG 1
@@ -23,7 +22,7 @@ extern char *opj_optarg;
extern int opj_getopt(int nargc, char *const *nargv, const char *ostr); 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, extern int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen); const opj_option_t *longopts, int totlen);
extern void opj_reset_options_reading(void); extern void opj_reset_options_reading(void);
#endif /* _GETOPT_H_ */ #endif /* _GETOPT_H_ */

View File

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

View File

@@ -13,7 +13,7 @@ set(common_SRCS
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_string.h ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_string.h
) )
if(OPJ_HAVE_LIBTIFF) if(OPJ_HAVE_LIBTIFF)
list(APPEND common_SRCS converttif.c) list(APPEND common_SRCS converttif.c)
endif() endif()
@@ -57,9 +57,6 @@ foreach(exe opj_decompress opj_compress opj_dump)
# On unix you need to link to the math library: # On unix you need to link to the math library:
if(UNIX) if(UNIX)
target_link_libraries(${exe} m) target_link_libraries(${exe} m)
IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
target_link_libraries(${exe} rt)
endif()
endif() endif()
# Install exe # Install exe
install(TARGETS ${exe} install(TARGETS ${exe}
@@ -67,7 +64,7 @@ foreach(exe opj_decompress opj_compress opj_dump)
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
) )
if(OPJ_USE_DSYMUTIL) if(OPJ_USE_DSYMUTIL)
add_custom_command(TARGET ${exe} POST_BUILD add_custom_command(TARGET ${exe} POST_BUILD
COMMAND "dsymutil" "$<TARGET_FILE:${exe}>" COMMAND "dsymutil" "$<TARGET_FILE:${exe}>"
COMMENT "dsymutil $<TARGET_FILE:${exe}>" COMMENT "dsymutil $<TARGET_FILE:${exe}>"
DEPENDS ${exe}) DEPENDS ${exe})

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -50,19 +50,19 @@ typedef struct raw_comp_cparameters {
/**@name RAW image encoding parameters */ /**@name RAW image encoding parameters */
/*@{*/ /*@{*/
typedef struct raw_cparameters { typedef struct raw_cparameters {
/** width of the raw image */ /** width of the raw image */
int rawWidth; int rawWidth;
/** height of the raw image */ /** height of the raw image */
int rawHeight; int rawHeight;
/** number of components of the raw image */ /** number of components of the raw image */
int rawComp; int rawComp;
/** bit depth of the raw image */ /** bit depth of the raw image */
int rawBitDepth; int rawBitDepth;
/** signed/unsigned raw image */ /** signed/unsigned raw image */
OPJ_BOOL rawSigned; OPJ_BOOL rawSigned;
/** raw components parameters */ /** raw components parameters */
raw_comp_cparameters_t *rawComps; raw_comp_cparameters_t *rawComps;
/*@}*/ /*@}*/
} raw_cparameters_t; } raw_cparameters_t;
/* Component precision clipping */ /* Component precision clipping */

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2010, Mathieu Malaterre, GDCM * Copyright (c) 2010, Mathieu Malaterre, GDCM
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -59,26 +59,26 @@
#include "format_defs.h" #include "format_defs.h"
#include "opj_string.h" #include "opj_string.h"
typedef struct dircnt{ typedef struct dircnt {
/** Buffer for holding images read from Directory*/ /** Buffer for holding images read from Directory*/
char *filename_buf; char *filename_buf;
/** Pointer to the buffer*/ /** Pointer to the buffer*/
char **filename; char **filename;
}dircnt_t; } dircnt_t;
typedef struct img_folder{ typedef struct img_folder {
/** The directory path of the folder containing input images*/ /** The directory path of the folder containing input images*/
char *imgdirpath; char *imgdirpath;
/** Output format*/ /** Output format*/
const char *out_format; const char *out_format;
/** Enable option*/ /** Enable option*/
char set_imgdir; char set_imgdir;
/** Enable Cod Format for output*/ /** Enable Cod Format for output*/
char set_out_format; char set_out_format;
int flag; int flag;
}img_fol_t; } img_fol_t;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* Declarations */ /* Declarations */
@@ -91,7 +91,8 @@ static int infile_format(const char *fname);
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol); static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static void decode_help_display(void) { static void decode_help_display(void)
{
fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n" fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n"
"It dumps JPEG 2000 codestream info to stdout or a given file.\n" "It dumps JPEG 2000 codestream info to stdout or a given file.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version()); "It has been compiled against openjp2 library v%s.\n\n",opj_version());
@@ -100,120 +101,124 @@ static void decode_help_display(void) {
fprintf(stdout,"-----------\n"); fprintf(stdout,"-----------\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout," -ImgDir <directory>\n"); fprintf(stdout," -ImgDir <directory>\n");
fprintf(stdout," Image file Directory path \n"); fprintf(stdout," Image file Directory path \n");
fprintf(stdout," -i <compressed file>\n"); fprintf(stdout," -i <compressed file>\n");
fprintf(stdout," REQUIRED only if an Input image directory not specified\n"); fprintf(stdout," REQUIRED only if an Input image directory not specified\n");
fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n"); fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n");
fprintf(stdout," is identified based on its suffix.\n"); fprintf(stdout," is identified based on its suffix.\n");
fprintf(stdout," -o <output file>\n"); fprintf(stdout," -o <output file>\n");
fprintf(stdout," OPTIONAL\n"); fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Output file where file info will be dump.\n"); fprintf(stdout," Output file where file info will be dump.\n");
fprintf(stdout," By default it will be in the stdout.\n"); fprintf(stdout," By default it will be in the stdout.\n");
fprintf(stdout," -v "); /* FIXME WIP_MSD */ fprintf(stdout," -v "); /* FIXME WIP_MSD */
fprintf(stdout," OPTIONAL\n"); fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Enable informative messages\n"); fprintf(stdout," Enable informative messages\n");
fprintf(stdout," By default verbose mode is off.\n"); fprintf(stdout," By default verbose mode is off.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int get_num_images(char *imgdirpath){ static int get_num_images(char *imgdirpath)
DIR *dir; {
struct dirent* content; DIR *dir;
int num_images = 0; struct dirent* content;
int num_images = 0;
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0; return 0;
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
num_images++; num_images++;
} }
closedir(dir); closedir(dir);
return num_images; return num_images;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int load_images(dircnt_t *dirptr, char *imgdirpath){ static int load_images(dircnt_t *dirptr, char *imgdirpath)
DIR *dir; {
struct dirent* content; DIR *dir;
int i = 0; struct dirent* content;
int i = 0;
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1; return 1;
}else { } else {
fprintf(stderr,"Folder opened successfully\n"); fprintf(stderr,"Folder opened successfully\n");
} }
while((content=readdir(dir))!=NULL){
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue;
strcpy(dirptr->filename[i],content->d_name); while((content=readdir(dir))!=NULL) {
i++; if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
} continue;
closedir(dir);
return 0; strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int get_file_format(const char *filename) { static int get_file_format(const char *filename)
unsigned int i; {
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; unsigned int i;
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
const char *ext = strrchr(filename, '.'); static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
if (ext == NULL) const char *ext = strrchr(filename, '.');
return -1; if (ext == NULL)
ext++; return -1;
if(ext) { ext++;
for(i = 0; i < sizeof(format)/sizeof(*format); i++) { if(ext) {
if(_strnicmp(ext, extension[i], 3) == 0) { for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
return format[i]; if(_strnicmp(ext, extension[i], 3) == 0) {
} return format[i];
} }
} }
}
return -1; return -1;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters)
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; {
char *temp_p, temp1[OPJ_PATH_LEN]=""; char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]="";
strcpy(image_filename,dirptr->filename[imageno]); strcpy(image_filename,dirptr->filename[imageno]);
fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename); fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename);
parameters->decod_format = get_file_format(image_filename); parameters->decod_format = get_file_format(image_filename);
if (parameters->decod_format == -1) if (parameters->decod_format == -1)
return 1; return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename); sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) { if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
return 1; return 1;
} }
/*Set output file*/ /*Set output file*/
strcpy(temp_ofname,strtok(image_filename,".")); strcpy(temp_ofname,strtok(image_filename,"."));
while((temp_p = strtok(NULL,".")) != NULL){ while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1); strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p); sprintf(temp1,".%s",temp_p);
} }
if(img_fol->set_out_format==1){ if(img_fol->set_out_format==1) {
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) { if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
return 1; return 1;
} }
} }
return 0; return 0;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@@ -224,172 +229,164 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_d
static int infile_format(const char *fname) static int infile_format(const char *fname)
{ {
FILE *reader; FILE *reader;
const char *s, *magic_s; const char *s, *magic_s;
int ext_format, magic_format; int ext_format, magic_format;
unsigned char buf[12]; unsigned char buf[12];
size_t l_nb_read; size_t l_nb_read;
reader = fopen(fname, "rb"); reader = fopen(fname, "rb");
if (reader == NULL) if (reader == NULL)
return -1; return -1;
memset(buf, 0, 12); memset(buf, 0, 12);
l_nb_read = fread(buf, 1, 12, reader); l_nb_read = fread(buf, 1, 12, reader);
fclose(reader); fclose(reader);
if (l_nb_read != 12) if (l_nb_read != 12)
return -1; return -1;
ext_format = get_file_format(fname); ext_format = get_file_format(fname);
if (ext_format == JPT_CFMT) if (ext_format == JPT_CFMT)
return JPT_CFMT; return JPT_CFMT;
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
magic_format = JP2_CFMT; magic_format = JP2_CFMT;
magic_s = ".jp2"; magic_s = ".jp2";
} } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { magic_format = J2K_CFMT;
magic_format = J2K_CFMT; magic_s = ".j2k or .jpc or .j2c";
magic_s = ".j2k or .jpc or .j2c"; } else
} return -1;
else
return -1;
if (magic_format == ext_format) if (magic_format == ext_format)
return ext_format; return ext_format;
s = fname + strlen(fname) - 4; s = fname + strlen(fname) - 4;
fputs("\n===========================================\n", stderr); fputs("\n===========================================\n", stderr);
fprintf(stderr, "The extension of this file is incorrect.\n" fprintf(stderr, "The extension of this file is incorrect.\n"
"FOUND %s. SHOULD BE %s\n", s, magic_s); "FOUND %s. SHOULD BE %s\n", s, magic_s);
fputs("===========================================\n", stderr); fputs("===========================================\n", stderr);
return magic_format; return magic_format;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/** /**
* Parse the command line * Parse the command line
*/ */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) { static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol)
int totlen, c; {
opj_option_t long_option[]={ int totlen, c;
opj_option_t long_option[]= {
{"ImgDir",REQ_ARG, NULL ,'y'} {"ImgDir",REQ_ARG, NULL ,'y'}
}; };
const char optlist[] = "i:o:f:hv"; const char optlist[] = "i:o:f:hv";
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format = 0; img_fol->set_out_format = 0;
do { do {
c = opj_getopt_long(argc, argv,optlist,long_option,totlen); c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{ char *infile = opj_optarg;
char *infile = opj_optarg; parameters->decod_format = infile_format(infile);
parameters->decod_format = infile_format(infile); switch(parameters->decod_format) {
switch(parameters->decod_format) { case J2K_CFMT:
case J2K_CFMT: break;
break; case JP2_CFMT:
case JP2_CFMT: break;
break; case JPT_CFMT:
case JPT_CFMT: break;
break; default:
default: fprintf(stderr,
fprintf(stderr, "[ERROR] Unknown input file format: %s \n"
"[ERROR] Unknown input file format: %s \n" " Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n",
" Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n", infile);
infile); return 1;
return 1; }
} if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) { fprintf(stderr, "[ERROR] Path is too long\n");
fprintf(stderr, "[ERROR] Path is too long\n"); return 1;
return 1; }
} }
}
break;
/* ------------------------------------------------------ */
case 'o': /* output file */
{
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 'f': /* flag */
img_fol->flag = atoi(opj_optarg);
break; break;
/* ----------------------------------------------------- */
case 'h': /* display an help description */ /* ------------------------------------------------------ */
decode_help_display();
return 1;
/* ------------------------------------------------------ */ case 'o': { /* output file */
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
return 1;
}
}
break;
case 'y': /* Image Directory path */ /* ----------------------------------------------------- */
{ case 'f': /* flag */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); img_fol->flag = atoi(opj_optarg);
if(img_fol->imgdirpath == NULL){ break;
return 1; /* ----------------------------------------------------- */
}
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */ case 'h': /* display an help description */
decode_help_display();
return 1;
case 'v': /* Verbose mode */ /* ------------------------------------------------------ */
{
parameters->m_verbose = 1; case 'y': { /* Image Directory path */
} img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
break; strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
/* ----------------------------------------------------- */ }
break;
/* ----------------------------------------------------- */
case 'v': { /* Verbose mode */
parameters->m_verbose = 1;
}
break;
/* ----------------------------------------------------- */
default: default:
fprintf(stderr, "[WARNING] An invalid option has been ignored.\n"); fprintf(stderr, "[WARNING] An invalid option has been ignored.\n");
break; break;
} }
}while(c != -1); } while(c != -1);
/* check for possible errors */ /* check for possible errors */
if(img_fol->set_imgdir==1){ if(img_fol->set_imgdir==1) {
if(!(parameters->infile[0]==0)){ if(!(parameters->infile[0]==0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n"); fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n");
return 1; return 1;
} }
if(img_fol->set_out_format == 0){ if(img_fol->set_out_format == 0) {
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n"); fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n" fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n");
return 1; return 1;
} }
if(!(parameters->outfile[0] == 0)){ if(!(parameters->outfile[0] == 0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n"); fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n");
return 1; return 1;
} }
}else{ } else {
if(parameters->infile[0] == 0) { if(parameters->infile[0] == 0) {
fprintf(stderr, "[ERROR] Required parameter is missing\n"); fprintf(stderr, "[ERROR] Required parameter is missing\n");
fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]); fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
fprintf(stderr, " Help: %s -h\n",argv[0]); fprintf(stderr, " Help: %s -h\n",argv[0]);
return 1; return 1;
} }
} }
return 0; return 0;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@@ -397,23 +394,26 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/** /**
sample error debug callback expecting no client object sample error debug callback expecting no client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
(void)client_data; {
fprintf(stdout, "[ERROR] %s", msg); (void)client_data;
fprintf(stdout, "[ERROR] %s", msg);
} }
/** /**
sample warning debug callback expecting no client object sample warning debug callback expecting no client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
(void)client_data; {
fprintf(stdout, "[WARNING] %s", msg); (void)client_data;
fprintf(stdout, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
(void)client_data; {
fprintf(stdout, "[INFO] %s", msg); (void)client_data;
fprintf(stdout, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@@ -423,188 +423,174 @@ static void info_callback(const char *msg, void *client_data) {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
FILE *fout = NULL; FILE *fout = NULL;
opj_dparameters_t parameters; /* Decompression parameters */ opj_dparameters_t parameters; /* Decompression parameters */
opj_image_t* image = NULL; /* Image structure */ opj_image_t* image = NULL; /* Image structure */
opj_codec_t* l_codec = NULL; /* Handle to a decompressor */ opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
opj_stream_t *l_stream = NULL; /* Stream */ opj_stream_t *l_stream = NULL; /* Stream */
opj_codestream_info_v2_t* cstr_info = NULL; opj_codestream_info_v2_t* cstr_info = NULL;
opj_codestream_index_t* cstr_index = NULL; opj_codestream_index_t* cstr_index = NULL;
OPJ_INT32 num_images, imageno; OPJ_INT32 num_images, imageno;
img_fol_t img_fol; img_fol_t img_fol;
dircnt_t *dirptr = NULL; dircnt_t *dirptr = NULL;
/* Set decoding parameters to default values */ #ifdef MSD
opj_set_default_decoder_parameters(&parameters); OPJ_BOOL l_go_on = OPJ_TRUE;
OPJ_UINT32 l_max_data_size = 1000;
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
#endif
/* Initialize img_fol */ /* Set decoding parameters to default values */
memset(&img_fol,0,sizeof(img_fol_t)); opj_set_default_decoder_parameters(&parameters);
img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND;
/* Parse input and get user encoding parameters */ /* Initialize img_fol */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) { memset(&img_fol,0,sizeof(img_fol_t));
if(img_fol.imgdirpath) free(img_fol.imgdirpath); img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND;
return EXIT_FAILURE; /* Parse input and get user encoding parameters */
} if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
return EXIT_FAILURE;
}
/* Initialize reading of directory */ /* Initialize reading of directory */
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
int it_image; int it_image;
num_images=get_num_images(img_fol.imgdirpath); num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(!dirptr){ if(dirptr) {
return EXIT_FAILURE; dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
} dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
if(!dirptr->filename_buf){
free(dirptr);
return EXIT_FAILURE;
}
dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename){ if(!dirptr->filename_buf) {
goto fails; return EXIT_FAILURE;
} }
for(it_image=0;it_image<num_images;it_image++){ for(it_image=0; it_image<num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
} }
}
if(load_images(dirptr,img_fol.imgdirpath)==1){ if(load_images(dirptr,img_fol.imgdirpath)==1) {
goto fails; return EXIT_FAILURE;
} }
if (num_images==0){ if (num_images==0) {
fprintf(stdout,"Folder is empty\n"); fprintf(stdout,"Folder is empty\n");
goto fails; return EXIT_FAILURE;
} }
}else{ } else {
num_images=1; num_images=1;
} }
/* Try to open for writing the output file if necessary */ /* Try to open for writing the output file if necessary */
if (parameters.outfile[0] != 0){ if (parameters.outfile[0] != 0) {
fout = fopen(parameters.outfile,"w"); fout = fopen(parameters.outfile,"w");
if (!fout){ if (!fout) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile); fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
goto fails; return EXIT_FAILURE;
} }
} } else
else fout = stdout;
fout = stdout;
/* Read the header of each image one by one */ /* Read the header of each image one by one */
for(imageno = 0; imageno < num_images ; imageno++){ for(imageno = 0; imageno < num_images ; imageno++) {
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) { if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n"); fprintf(stderr,"skipping file...\n");
continue; continue;
} }
} }
/* Read the input file and put it in memory */ /* Read the input file and put it in memory */
/* ---------------------------------------- */ /* ---------------------------------------- */
l_stream = opj_stream_create_default_file_stream(parameters.infile,1); l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream){ if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile); fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
goto fails; return EXIT_FAILURE;
} }
/* Read the JPEG2000 stream */ /* Read the JPEG2000 stream */
/* ------------------------ */ /* ------------------------ */
switch(parameters.decod_format) { switch(parameters.decod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */ case J2K_CFMT: { /* JPEG-2000 codestream */
{ /* Get a decoder handle */
/* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_J2K);
l_codec = opj_create_decompress(OPJ_CODEC_J2K); break;
break; }
} case JP2_CFMT: { /* JPEG 2000 compressed image data */
case JP2_CFMT: /* JPEG 2000 compressed image data */ /* Get a decoder handle */
{ l_codec = opj_create_decompress(OPJ_CODEC_JP2);
/* Get a decoder handle */ break;
l_codec = opj_create_decompress(OPJ_CODEC_JP2); }
break; case JPT_CFMT: { /* JPEG 2000, JPIP */
} /* Get a decoder handle */
case JPT_CFMT: /* JPEG 2000, JPIP */ l_codec = opj_create_decompress(OPJ_CODEC_JPT);
{ break;
/* Get a decoder handle */ }
l_codec = opj_create_decompress(OPJ_CODEC_JPT); default:
break; fprintf(stderr, "skipping file..\n");
} opj_stream_destroy(l_stream);
default: continue;
fprintf(stderr, "skipping file..\n"); }
opj_stream_destroy(l_stream);
continue;
}
/* catch events using our callbacks and give a local context */ /* catch events using our callbacks and give a local context */
opj_set_info_handler(l_codec, info_callback,00); opj_set_info_handler(l_codec, info_callback,00);
opj_set_warning_handler(l_codec, warning_callback,00); opj_set_warning_handler(l_codec, warning_callback,00);
opj_set_error_handler(l_codec, error_callback,00); opj_set_error_handler(l_codec, error_callback,00);
/* Setup the decoder decoding parameters using user parameters */ /* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &parameters) ){ if ( !opj_setup_decoder(l_codec, &parameters) ) {
fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n"); fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
fclose(fout); fclose(fout);
goto fails; return EXIT_FAILURE;
} }
/* Read the main header of the codestream and if necessary the JP2 boxes*/ /* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(l_stream, l_codec, &image)){ if(! opj_read_header(l_stream, l_codec, &image)) {
fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n"); fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n");
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
opj_image_destroy(image); opj_image_destroy(image);
fclose(fout); fclose(fout);
goto fails; return EXIT_FAILURE;
} }
opj_dump_codec(l_codec, img_fol.flag, fout ); opj_dump_codec(l_codec, img_fol.flag, fout );
cstr_info = opj_get_cstr_info(l_codec); cstr_info = opj_get_cstr_info(l_codec);
cstr_index = opj_get_cstr_index(l_codec); cstr_index = opj_get_cstr_index(l_codec);
/* close the byte stream */ /* close the byte stream */
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
/* free remaining structures */ /* free remaining structures */
if (l_codec) { if (l_codec) {
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
} }
/* destroy the image header */ /* destroy the image header */
opj_image_destroy(image); opj_image_destroy(image);
/* destroy the codestream index */ /* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index); opj_destroy_cstr_index(&cstr_index);
/* destroy the codestream info */ /* destroy the codestream info */
opj_destroy_cstr_info(&cstr_info); opj_destroy_cstr_info(&cstr_info);
} }
/* Close the output file */ /* Close the output file */
fclose(fout); fclose(fout);
return EXIT_SUCCESS; return EXIT_SUCCESS;
fails:
if(dirptr){
if(dirptr->filename) free(dirptr->filename);
if(dirptr->filename_buf) free(dirptr->filename_buf);
free(dirptr);
}
return EXIT_FAILURE;
} }

View File

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

View File

@@ -1,7 +1,7 @@
# Build the demo app, small examples # Build the demo app, small examples
# First thing define the common source: # First thing define the common source:
set(common_SRCS SET(common_SRCS
convert.c convert.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c
) )
@@ -26,15 +26,15 @@ if(WIN32)
endif() endif()
# Loop over all executables: # Loop over all executables:
foreach(exe opj_jp3d_compress opj_jp3d_decompress) FOREACH(exe opj_jp3d_compress opj_jp3d_decompress)
add_executable(${exe} ${exe}.c ${common_SRCS}) ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS})
target_link_libraries(${exe} openjp3d) TARGET_LINK_LIBRARIES(${exe} openjp3d)
# On unix you need to link to the math library: # On unix you need to link to the math library:
if(UNIX) IF(UNIX)
target_link_libraries(${exe} m) TARGET_LINK_LIBRARIES(${exe} m)
endif(UNIX) ENDIF(UNIX)
# Install exe # Install exe
install(TARGETS ${exe} INSTALL(TARGETS ${exe}
EXPORT OpenJP3DTargets EXPORT OpenJP3DTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
) )

File diff suppressed because it is too large Load Diff

View File

@@ -1,51 +1,51 @@
/* /*
* 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, Herve 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<72>a, Image Processing Laboratory, University of Valladolid, Spain * Copyright (c) 2006, M<>nica D<>ez Garc<72>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
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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 * 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 __JP3D_CONVERT_H
#define __JP3D_CONVERT_H #define __JP3D_CONVERT_H
/** /**
Load a single volume component encoded in PGX file format Load a single volume 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 volume if successful, returns NULL otherwise
*/ */
opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters); opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters);
int volumetopgx(opj_volume_t *volume, char *outfile); int volumetopgx(opj_volume_t *volume, char *outfile);
opj_volume_t* bintovolume(char *filename,char *fileimg, opj_cparameters_t *parameters); opj_volume_t* bintovolume(char *filename,char *fileimg, opj_cparameters_t *parameters);
int volumetobin(opj_volume_t *volume, char *outfile); int volumetobin(opj_volume_t *volume, char *outfile);
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters); opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters);
#endif /* __J2K_CONVERT_H */ #endif /* __J2K_CONVERT_H */

View File

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

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -60,7 +60,7 @@ endforeach()
find_package(Java 1.5 COMPONENTS Development) # javac, jar find_package(Java 1.5 COMPONENTS Development) # javac, jar
# User can override this: # User can override this:
if(NOT DEFINED JAVA_SOURCE_VERSION) if(NOT DEFINED JAVA_SOURCE_VERSION)
set(JAVA_SOURCE_VERSION 1.5) set(JAVA_SOURCE_VERSION 1.5)
endif() endif()
if(NOT DEFINED JAVA_TARGET_VERSION) if(NOT DEFINED JAVA_TARGET_VERSION)

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -40,17 +40,17 @@
/**@name RAW image encoding parameters */ /**@name RAW image encoding parameters */
/*@{*/ /*@{*/
typedef struct raw_cparameters { typedef struct raw_cparameters {
/** width of the raw image */ /** width of the raw image */
int rawWidth; int rawWidth;
/** height of the raw image */ /** height of the raw image */
int rawHeight; int rawHeight;
/** components of the raw image */ /** components of the raw image */
int rawComp; int rawComp;
/** bit depth of the raw image */ /** bit depth of the raw image */
int rawBitDepth; int rawBitDepth;
/** signed/unsigned raw image */ /** signed/unsigned raw image */
opj_bool rawSigned; opj_bool rawSigned;
/*@}*/ /*@}*/
} raw_cparameters_t; } raw_cparameters_t;
/* TGA conversion */ /* TGA conversion */

View File

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

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -37,11 +37,11 @@ foreach(exe
APPEND PROPERTY COMPILE_DEFINITIONS USE_MJ2 APPEND PROPERTY COMPILE_DEFINITIONS USE_MJ2
) )
target_link_libraries(${exe} ${LCMS_LIBNAME} openmj2) target_link_libraries(${exe} ${LCMS_LIBNAME} openmj2)
if(UNIX) if(UNIX)
target_link_libraries(${exe} m) target_link_libraries(${exe} m)
endif() endif()
install(TARGETS ${exe} install(TARGETS ${exe}
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR}) DESTINATION ${OPENJPEG_INSTALL_BIN_DIR})
endforeach() endforeach()

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -50,196 +50,194 @@
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[ERROR] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[WARNING] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
mj2_dparameters_t mj2_parameters; /* decompression parameters */ {
opj_dinfo_t* dinfo; mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */ opj_dinfo_t* dinfo;
opj_cio_t *cio = NULL; opj_event_mgr_t event_mgr; /* event manager */
unsigned int tnum, snum; opj_cio_t *cio = NULL;
opj_mj2_t *movie; unsigned int tnum, snum;
mj2_tk_t *track; opj_mj2_t *movie;
mj2_sample_t *sample; mj2_tk_t *track;
unsigned char* frame_codestream; mj2_sample_t *sample;
FILE *file, *outfile; unsigned char* frame_codestream;
char outfilename[50]; FILE *file, *outfile;
opj_image_t *img = NULL; char outfilename[50];
unsigned int max_codstrm_size = 0; opj_image_t *img = NULL;
double total_time = 0; unsigned int max_codstrm_size = 0;
unsigned int numframes = 0; double total_time = 0;
unsigned int numframes = 0;
if (argc != 3) {
printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]);
return 1;
}
file = fopen(argv[1], "rb");
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
/* Checking output file */
outfile = fopen(argv[2], "w");
if (!file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
fclose(outfile);
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = NULL;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
movie = (opj_mj2_t*)dinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
memset(&mj2_parameters, 0, sizeof(mj2_dparameters_t)); if (argc != 3) {
/* set J2K decoding parameters to default values */ printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]);
opj_set_default_decoder_parameters(&mj2_parameters.j2k_parameters); return 1;
}
/* setup the decoder decoding parameters using user parameters */
mj2_setup_decoder(movie, &mj2_parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure */
return 1;
/* Decode first video track */
for (tnum=0; tnum < (unsigned int)(movie->num_htk + movie->num_stk + movie->num_vtk); tnum++) {
if (movie->tk[tnum].track_type == 0)
break;
}
if (movie->tk[tnum].track_type != 0) {
printf("Error. Movie does not contain any video track\n");
return 1;
}
track = &movie->tk[tnum];
/* Output info on first video tracl */
fprintf(stdout,"The first video track contains %d frames.\nWidth: %d, Height: %d \n\n",
track->num_samples, track->w, track->h);
max_codstrm_size = track->sample[0].sample_size-8;
frame_codestream = (unsigned char*) malloc(max_codstrm_size * sizeof(unsigned char));
numframes = track->num_samples; file = fopen(argv[1], "rb");
for (snum=0; snum < numframes; snum++)
{
double init_time = opj_clock();
double elapsed_time;
sample = &track->sample[snum]; if (!file) {
if (sample->sample_size-8 > max_codstrm_size) { fprintf(stderr, "failed to open %s for reading\n", argv[1]);
max_codstrm_size = sample->sample_size-8; return 1;
if ((frame_codestream = (unsigned char*) }
realloc(frame_codestream, max_codstrm_size)) == NULL) {
printf("Error reallocation memory\n"); /* Checking output file */
return 1; outfile = fopen(argv[2], "w");
}; if (!file) {
} fprintf(stderr, "failed to open %s for writing\n", argv[2]);
fseek(file,sample->offset+8,SEEK_SET); return 1;
fread(frame_codestream, sample->sample_size-8, 1, file); /* Assuming that jp and ftyp markers size do */ }
fclose(outfile);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8); /*
configure the event callbacks (not required)
img = opj_decode(dinfo, cio); /* Decode J2K to image */ setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = NULL;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
movie = (opj_mj2_t*)dinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
memset(&mj2_parameters, 0, sizeof(mj2_dparameters_t));
/* set J2K decoding parameters to default values */
opj_set_default_decoder_parameters(&mj2_parameters.j2k_parameters);
/* setup the decoder decoding parameters using user parameters */
mj2_setup_decoder(movie, &mj2_parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure */
return 1;
/* Decode first video track */
for (tnum=0; tnum < (unsigned int)(movie->num_htk + movie->num_stk + movie->num_vtk); tnum++) {
if (movie->tk[tnum].track_type == 0)
break;
}
if (movie->tk[tnum].track_type != 0) {
printf("Error. Movie does not contain any video track\n");
return 1;
}
track = &movie->tk[tnum];
/* Output info on first video tracl */
fprintf(stdout,"The first video track contains %d frames.\nWidth: %d, Height: %d \n\n",
track->num_samples, track->w, track->h);
max_codstrm_size = track->sample[0].sample_size-8;
frame_codestream = (unsigned char*) malloc(max_codstrm_size * sizeof(unsigned char));
numframes = track->num_samples;
for (snum=0; snum < numframes; snum++) {
double init_time = opj_clock();
double elapsed_time;
sample = &track->sample[snum];
if (sample->sample_size-8 > max_codstrm_size) {
max_codstrm_size = sample->sample_size-8;
if ((frame_codestream = (unsigned char*)
realloc(frame_codestream, max_codstrm_size)) == NULL) {
printf("Error reallocation memory\n");
return 1;
};
}
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream, sample->sample_size-8, 1, file); /* Assuming that jp and ftyp markers size do */
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
img = opj_decode(dinfo, cio); /* Decode J2K to image */
#ifdef WANT_SYCC_TO_RGB #ifdef WANT_SYCC_TO_RGB
if(img->color_space == CLRSPC_SYCC) if(img->color_space == CLRSPC_SYCC) {
{ color_sycc_to_rgb(img);
color_sycc_to_rgb(img); }
}
#endif #endif
if(img->icc_profile_buf) if(img->icc_profile_buf) {
{
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(img); color_apply_icc_profile(img);
#endif #endif
free(img->icc_profile_buf); free(img->icc_profile_buf);
img->icc_profile_buf = NULL; img->icc_profile_len = 0; img->icc_profile_buf = NULL;
} img->icc_profile_len = 0;
}
if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2) if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2)
&& (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1)) && (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))
|| (img->numcomps == 1)) { || (img->numcomps == 1)) {
if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */
return 1;
}
else if ((img->numcomps == 3) &&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[2].dx == 1))/* If YUV 4:4:4 input --> to bmp */
{
fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n");
sprintf(outfilename,"output_%d.bmp",snum);
if (imagetobmp(img, outfilename)) /* Convert image to BMP */
return 1;
}
else {
fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");
sprintf(outfilename,"output_%d.j2k",snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
}
/* close the byte stream */
opj_cio_close(cio);
/* free image data structure */
opj_image_destroy(img);
elapsed_time = opj_clock()-init_time;
fprintf(stderr, "Frame number %d/%d decoded in %.2f mseconds\n", snum + 1, numframes, elapsed_time*1000);
total_time += elapsed_time;
} if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */
return 1;
free(frame_codestream); } else if ((img->numcomps == 3) &&
fclose(file); (img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[2].dx == 1)) { /* If YUV 4:4:4 input --> to bmp */
fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n");
sprintf(outfilename,"output_%d.bmp",snum);
if (imagetobmp(img, outfilename)) /* Convert image to BMP */
return 1;
/* free remaining structures */ } else {
if(dinfo) { fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle); fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");
}
free(dinfo); sprintf(outfilename,"output_%d.j2k",snum);
outfile = fopen(outfilename, "wb");
fprintf(stdout, "%d frame(s) correctly decompressed\n", snum); if (!outfile) {
fprintf(stdout,"Total decoding time: %.2f seconds (%.1f fps)\n", total_time, (float)numframes/total_time); fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
return 0; }
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
}
/* close the byte stream */
opj_cio_close(cio);
/* free image data structure */
opj_image_destroy(img);
elapsed_time = opj_clock()-init_time;
fprintf(stderr, "Frame number %d/%d decoded in %.2f mseconds\n", snum + 1, numframes, elapsed_time*1000);
total_time += elapsed_time;
}
free(frame_codestream);
fclose(file);
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
free(dinfo);
fprintf(stdout, "%d frame(s) correctly decompressed\n", snum);
fprintf(stdout,"Total decoding time: %.2f seconds (%.1f fps)\n", total_time, (float)numframes/total_time);
return 0;
} }

View File

@@ -1,12 +1,12 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* 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
@@ -46,110 +46,113 @@
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[ERROR] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[WARNING] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[INFO] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
opj_dinfo_t* dinfo; {
opj_event_mgr_t event_mgr; /* event manager */ opj_dinfo_t* dinfo;
int tnum; opj_event_mgr_t event_mgr; /* event manager */
unsigned int snum; int tnum;
opj_mj2_t *movie; unsigned int snum;
mj2_tk_t *track; opj_mj2_t *movie;
mj2_sample_t *sample; mj2_tk_t *track;
unsigned char* frame_codestream; mj2_sample_t *sample;
FILE *file, *outfile; unsigned char* frame_codestream;
char outfilename[50]; FILE *file, *outfile;
mj2_dparameters_t parameters; char outfilename[50];
mj2_dparameters_t parameters;
if (argc != 3) { if (argc != 3) {
printf("Usage: %s mj2filename output_location\n",argv[0]); printf("Usage: %s mj2filename output_location\n",argv[0]);
printf("Example: %s foreman.mj2 output/foreman\n",argv[0]); printf("Example: %s foreman.mj2 output/foreman\n",argv[0]);
return 1; return 1;
}
file = fopen(argv[1], "rb");
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_dparameters_t));
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(movie, &parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure*/
return 1;
/* Decode first video track */
tnum = 0;
while (movie->tk[tnum].track_type != 0)
tnum ++;
track = &movie->tk[tnum];
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++)
{
sample = &track->sample[snum];
frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream,sample->sample_size-8,1, file); /* Assuming that jp and ftyp markers size do*/
sprintf(outfilename,"%s_%05d.j2k",argv[2],snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
} }
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile); file = fopen(argv[1], "rb");
free(frame_codestream);
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
} }
fclose(file);
fprintf(stdout, "%d frames correctly extracted\n", snum); /*
configure the event callbacks (not required)
/* free remaining structures */ setting of each callback is optionnal
if(dinfo) { */
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
} event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
return 0; event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_dparameters_t));
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(movie, &parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure*/
return 1;
/* Decode first video track */
tnum = 0;
while (movie->tk[tnum].track_type != 0)
tnum ++;
track = &movie->tk[tnum];
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++) {
sample = &track->sample[snum];
frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream,sample->sample_size-8,1, file); /* Assuming that jp and ftyp markers size do*/
sprintf(outfilename,"%s_%05d.j2k",argv[2],snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
free(frame_codestream);
}
fclose(file);
fprintf(stdout, "%d frames correctly extracted\n", snum);
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
return 0;
} }

View File

@@ -1,12 +1,12 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* 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
@@ -41,14 +41,15 @@
#include "jp2.h" #include "jp2.h"
#include "mj2.h" #include "mj2.h"
static int int_ceildiv(int a, int b) { static int int_ceildiv(int a, int b)
return (a + b - 1) / b; {
return (a + b - 1) / b;
} }
/** /**
Size of memory first allocated for MOOV box Size of memory first allocated for MOOV box
*/ */
#define TEMP_BUF 10000 #define TEMP_BUF 10000
#define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51" #define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51"
@@ -56,153 +57,141 @@ Size of memory first allocated for MOOV box
static int test_image(const char *fname, mj2_cparameters_t *cp) static int test_image(const char *fname, mj2_cparameters_t *cp)
{ {
FILE *reader; FILE *reader;
opj_image_t *image; opj_image_t *image;
unsigned char *src; unsigned char *src;
opj_dinfo_t *dinfo; opj_dinfo_t *dinfo;
opj_cio_t *cio; opj_cio_t *cio;
opj_dparameters_t dparameters; opj_dparameters_t dparameters;
int success; int success;
long src_len; long src_len;
success = 0; success = 0;
if((reader = fopen(fname, "rb")) == NULL) return success; if((reader = fopen(fname, "rb")) == NULL) return success;
fseek(reader, 0, SEEK_END); fseek(reader, 0, SEEK_END);
src_len = ftell(reader); src_len = ftell(reader);
fseek(reader, 0, SEEK_SET); fseek(reader, 0, SEEK_SET);
src = (unsigned char*) malloc(src_len); src = (unsigned char*) malloc(src_len);
fread(src, 1, src_len, reader); fread(src, 1, src_len, reader);
fclose(reader); fclose(reader);
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) {
{ free(src);
free(src); return success; return success;
} }
memset(&dparameters, 0, sizeof(opj_dparameters_t)); memset(&dparameters, 0, sizeof(opj_dparameters_t));
opj_set_default_decoder_parameters(&dparameters); opj_set_default_decoder_parameters(&dparameters);
dinfo = opj_create_decompress(CODEC_J2K); dinfo = opj_create_decompress(CODEC_J2K);
opj_setup_decoder(dinfo, &dparameters); opj_setup_decoder(dinfo, &dparameters);
cio = opj_cio_open((opj_common_ptr)dinfo, src, src_len); cio = opj_cio_open((opj_common_ptr)dinfo, src, src_len);
image = opj_decode(dinfo, cio); image = opj_decode(dinfo, cio);
free(src); cio->buffer = NULL; free(src);
opj_cio_close(cio); cio->buffer = NULL;
opj_cio_close(cio);
if(image == NULL) goto fin; if(image == NULL) goto fin;
cp->numcomps = image->numcomps; cp->numcomps = image->numcomps;
cp->w = image->comps[0].w; cp->w = image->comps[0].w;
cp->h = image->comps[0].h; cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec; cp->prec = image->comps[0].prec;
if(image->numcomps > 2 ) if(image->numcomps > 2 ) {
{ if((image->comps[0].dx == 1)
if((image->comps[0].dx == 1) && (image->comps[1].dx == 2)
&& (image->comps[1].dx == 2) && (image->comps[2].dx == 2)
&& (image->comps[2].dx == 2) && (image->comps[0].dy == 1)
&& (image->comps[0].dy == 1) && (image->comps[1].dy == 2)
&& (image->comps[1].dy == 2) && (image->comps[2].dy == 2)) { /* horizontal and vertical*/
&& (image->comps[2].dy == 2))/* horizontal and vertical*/ /* Y420*/
{ cp->enumcs = ENUMCS_SYCC;
/* Y420*/ cp->CbCr_subsampling_dx = 2;
cp->enumcs = ENUMCS_SYCC; cp->CbCr_subsampling_dy = 2;
cp->CbCr_subsampling_dx = 2; } else if((image->comps[0].dx == 1)
cp->CbCr_subsampling_dy = 2; && (image->comps[1].dx == 2)
} && (image->comps[2].dx == 2)
else && (image->comps[0].dy == 1)
if((image->comps[0].dx == 1) && (image->comps[1].dy == 1)
&& (image->comps[1].dx == 2) && (image->comps[2].dy == 1)) { /* horizontal only*/
&& (image->comps[2].dx == 2) /* Y422*/
&& (image->comps[0].dy == 1) cp->enumcs = ENUMCS_SYCC;
&& (image->comps[1].dy == 1) cp->CbCr_subsampling_dx = 2;
&& (image->comps[2].dy == 1))/* horizontal only*/ cp->CbCr_subsampling_dy = 1;
{ } else if((image->comps[0].dx == 1)
/* Y422*/ && (image->comps[1].dx == 1)
cp->enumcs = ENUMCS_SYCC; && (image->comps[2].dx == 1)
cp->CbCr_subsampling_dx = 2; && (image->comps[0].dy == 1)
cp->CbCr_subsampling_dy = 1; && (image->comps[1].dy == 1)
} && (image->comps[2].dy == 1)) {
else /* Y444 or RGB */
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
{
/* Y444 or RGB */
if(image->color_space == CLRSPC_SRGB) if(image->color_space == CLRSPC_SRGB) {
{ cp->enumcs = ENUMCS_SRGB;
cp->enumcs = ENUMCS_SRGB;
/* cp->CbCr_subsampling_dx = 0; */ /* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */ /* cp->CbCr_subsampling_dy = 0; */
} } else {
else cp->enumcs = ENUMCS_SYCC;
{
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 1; cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1; cp->CbCr_subsampling_dy = 1;
} }
} } else {
else goto fin;
{ }
goto fin; } else {
} cp->enumcs = ENUMCS_GRAY;
} /* cp->CbCr_subsampling_dx = 0; */
else /* cp->CbCr_subsampling_dy = 0; */
{ }
cp->enumcs = ENUMCS_GRAY; if(image->icc_profile_buf) {
/* cp->CbCr_subsampling_dx = 0; */ cp->meth = 2;
/* cp->CbCr_subsampling_dy = 0; */ free(image->icc_profile_buf);
} image->icc_profile_buf = NULL;
if(image->icc_profile_buf) } else cp->meth = 1;
{
cp->meth = 2;
free(image->icc_profile_buf); image->icc_profile_buf = NULL;
}
else cp->meth = 1;
success = 1; success = 1;
fin: fin:
if(dinfo) if(dinfo)
opj_destroy_decompress(dinfo); opj_destroy_decompress(dinfo);
if(image) if(image)
opj_image_destroy(image); opj_image_destroy(image);
return success; return success;
} }
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[ERROR] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[WARNING] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[INFO] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@@ -211,316 +200,311 @@ static void info_callback(const char *msg, void *client_data) {
static void read_siz_marker(FILE *file, opj_image_t *image) static void read_siz_marker(FILE *file, opj_image_t *image)
{ {
int len,i; int len,i;
char buf, buf2[2]; char buf, buf2[2];
unsigned char *siz_buffer; unsigned char *siz_buffer;
opj_cio_t *cio; opj_cio_t *cio;
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
do { do {
fread(&buf,1,1, file); fread(&buf,1,1, file);
if (buf==(char)0xff) if (buf==(char)0xff)
fread(&buf,1,1, file); fread(&buf,1,1, file);
} } while (!(buf==(char)0x51));
while (!(buf==(char)0x51));
fread(buf2,2,1,file); /* Lsiz */
fread(buf2,2,1,file); /* Lsiz */ len = ((buf2[0])<<8) + buf2[1];
len = ((buf2[0])<<8) + buf2[1];
siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char));
siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char)); fread(siz_buffer,len, 1, file);
fread(siz_buffer,len, 1, file); cio = opj_cio_open(NULL, siz_buffer, len);
cio = opj_cio_open(NULL, siz_buffer, len);
cio_read(cio, 2); /* Rsiz (capabilities) */
cio_read(cio, 2); /* Rsiz (capabilities) */ image->x1 = cio_read(cio, 4); /* Xsiz */
image->x1 = cio_read(cio, 4); /* Xsiz */ image->y1 = cio_read(cio, 4); /* Ysiz */
image->y1 = cio_read(cio, 4); /* Ysiz */ image->x0 = cio_read(cio, 4); /* X0siz */
image->x0 = cio_read(cio, 4); /* X0siz */ image->y0 = cio_read(cio, 4); /* Y0siz */
image->y0 = cio_read(cio, 4); /* Y0siz */ cio_skip(cio, 16); /* XTsiz, YTsiz, XT0siz, YT0siz */
cio_skip(cio, 16); /* XTsiz, YTsiz, XT0siz, YT0siz */
image->numcomps = cio_read(cio,2); /* Csiz */
image->numcomps = cio_read(cio,2); /* Csiz */ image->comps =
image->comps = (opj_image_comp_t *) malloc(image->numcomps * sizeof(opj_image_comp_t));
(opj_image_comp_t *) malloc(image->numcomps * sizeof(opj_image_comp_t));
for (i = 0; i < image->numcomps; i++) {
for (i = 0; i < image->numcomps; i++) { int tmp;
int tmp; tmp = cio_read(cio,1); /* Ssiz_i */
tmp = cio_read(cio,1); /* Ssiz_i */ image->comps[i].prec = (tmp & 0x7f) + 1;
image->comps[i].prec = (tmp & 0x7f) + 1; image->comps[i].sgnd = tmp >> 7;
image->comps[i].sgnd = tmp >> 7; image->comps[i].dx = cio_read(cio,1); /* XRsiz_i */
image->comps[i].dx = cio_read(cio,1); /* XRsiz_i */ image->comps[i].dy = cio_read(cio,1); /* YRsiz_i */
image->comps[i].dy = cio_read(cio,1); /* YRsiz_i */ image->comps[i].resno_decoded = 0; /* number of resolution decoded */
image->comps[i].resno_decoded = 0; /* number of resolution decoded */ image->comps[i].factor = 0; /* reducing factor by component */
image->comps[i].factor = 0; /* reducing factor by component */ }
} fseek(file, 0, SEEK_SET);
fseek(file, 0, SEEK_SET); opj_cio_close(cio);
opj_cio_close(cio); free(siz_buffer);
free(siz_buffer);
} }
static void setparams(opj_mj2_t *movie, opj_image_t *image) { static void setparams(opj_mj2_t *movie, opj_image_t *image)
int i, depth_0, depth, sign; {
int i, depth_0, depth, sign;
movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy); movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
mj2_init_stdmovie(movie); movie->tk[0].h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
mj2_init_stdmovie(movie);
movie->tk[0].depth = image->comps[0].prec;
movie->tk[0].depth = image->comps[0].prec;
if (image->numcomps==3) {
if ((image->comps[0].dx == 1) if (image->numcomps==3) {
&& (image->comps[1].dx == 1) if ((image->comps[0].dx == 1)
&& (image->comps[2].dx == 1)) && (image->comps[1].dx == 1)
movie->tk[0].CbCr_subsampling_dx = 1; && (image->comps[2].dx == 1))
else movie->tk[0].CbCr_subsampling_dx = 1;
if ((image->comps[0].dx == 1) else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2) && (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)) && (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2; movie->tk[0].CbCr_subsampling_dx = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
}
movie->tk[0].sample_rate = 25;
movie->tk[0].jp2_struct.numcomps = image->numcomps; /* NC */
/* Init Standard jp2 structure */
movie->tk[0].jp2_struct.comps =
(opj_jp2_comps_t *) malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.precedence = 0; /* PRECEDENCE*/
movie->tk[0].jp2_struct.approx = 0; /* APPROX*/
movie->tk[0].jp2_struct.brand = JP2_JP2; /* BR */
movie->tk[0].jp2_struct.minversion = 0; /* MinV */
movie->tk[0].jp2_struct.numcl = 1;
movie->tk[0].jp2_struct.cl = (unsigned int *) malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl[0] = JP2_JP2; /* CL0 : JP2 */
movie->tk[0].jp2_struct.C = 7; /* C : Always 7*/
movie->tk[0].jp2_struct.UnkC = 0; /* UnkC, colorspace specified in colr box*/
movie->tk[0].jp2_struct.IPR = 0; /* IPR, no intellectual property*/
movie->tk[0].jp2_struct.w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].jp2_struct.h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
movie->tk[0].jp2_struct.bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
movie->tk[0].jp2_struct.bpc = 255;
}
for (i = 0; i < image->numcomps; i++)
movie->tk[0].jp2_struct.comps[i].bpcc =
image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
if ((image->numcomps == 1 || image->numcomps == 3)
&& (movie->tk[0].jp2_struct.bpc != 255))
movie->tk[0].jp2_struct.meth = 1;
else else
fprintf(stderr,"Image component sizes are incoherent\n"); movie->tk[0].jp2_struct.meth = 2;
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
}
movie->tk[0].sample_rate = 25;
movie->tk[0].jp2_struct.numcomps = image->numcomps; /* NC */
/* Init Standard jp2 structure */
movie->tk[0].jp2_struct.comps =
(opj_jp2_comps_t *) malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.precedence = 0; /* PRECEDENCE*/
movie->tk[0].jp2_struct.approx = 0; /* APPROX*/
movie->tk[0].jp2_struct.brand = JP2_JP2; /* BR */
movie->tk[0].jp2_struct.minversion = 0; /* MinV */
movie->tk[0].jp2_struct.numcl = 1;
movie->tk[0].jp2_struct.cl = (unsigned int *) malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl[0] = JP2_JP2; /* CL0 : JP2 */
movie->tk[0].jp2_struct.C = 7; /* C : Always 7*/
movie->tk[0].jp2_struct.UnkC = 0; /* UnkC, colorspace specified in colr box*/
movie->tk[0].jp2_struct.IPR = 0; /* IPR, no intellectual property*/
movie->tk[0].jp2_struct.w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].jp2_struct.h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
movie->tk[0].jp2_struct.bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
movie->tk[0].jp2_struct.bpc = 255;
}
for (i = 0; i < image->numcomps; i++)
movie->tk[0].jp2_struct.comps[i].bpcc =
image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
if ((image->numcomps == 1 || image->numcomps == 3)
&& (movie->tk[0].jp2_struct.bpc != 255))
movie->tk[0].jp2_struct.meth = 1;
else
movie->tk[0].jp2_struct.meth = 2;
if (image->numcomps == 1) if (image->numcomps == 1)
movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */ movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */
else else if ((image->comps[0].dx == 1)
if ((image->comps[0].dx == 1) && (image->comps[1].dx == 1)
&& (image->comps[1].dx == 1) && (image->comps[2].dx == 1)
&& (image->comps[2].dx == 1) && (image->comps[0].dy == 1)
&& (image->comps[0].dy == 1) && (image->comps[1].dy == 1)
&& (image->comps[1].dy == 1) && (image->comps[2].dy == 1))
&& (image->comps[2].dy == 1)) movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else if ((image->comps[0].dx == 1)
else && (image->comps[1].dx == 2)
if ((image->comps[0].dx == 1) && (image->comps[2].dx == 2)
&& (image->comps[1].dx == 2) && (image->comps[0].dy == 1)
&& (image->comps[2].dx == 2) && (image->comps[1].dy == 2)
&& (image->comps[0].dy == 1) && (image->comps[2].dy == 2))
&& (image->comps[1].dy == 2) movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
&& (image->comps[2].dy == 2))
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */ else
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
else
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
opj_cinfo_t* cinfo; {
opj_event_mgr_t event_mgr; /* event manager */ opj_cinfo_t* cinfo;
unsigned int snum; opj_event_mgr_t event_mgr; /* event manager */
opj_mj2_t *movie; unsigned int snum;
mj2_sample_t *sample; opj_mj2_t *movie;
unsigned char* frame_codestream; mj2_sample_t *sample;
FILE *mj2file, *j2kfile; unsigned char* frame_codestream;
char *j2kfilename; FILE *mj2file, *j2kfile;
unsigned char *buf; char *j2kfilename;
int offset, mdat_initpos; unsigned char *buf;
opj_image_t img; int offset, mdat_initpos;
opj_cio_t *cio; opj_image_t img;
mj2_cparameters_t parameters; opj_cio_t *cio;
mj2_cparameters_t parameters;
if (argc != 3) {
printf("Usage: %s source_location mj2_filename\n",argv[0]);
printf("Example: %s input/input output.mj2\n",argv[0]);
return 1;
}
mj2file = fopen(argv[2], "wb");
if (!mj2file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
memset(&img, 0, sizeof(opj_image_t));
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */ if (argc != 3) {
cinfo = mj2_create_compress(); printf("Usage: %s source_location mj2_filename\n",argv[0]);
printf("Example: %s input/input output.mj2\n",argv[0]);
/* catch events using our callbacks and give a local context */ return 1;
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the decoder encoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_cparameters_t));
movie = (opj_mj2_t*) cinfo->mj2_handle;
j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
parameters.frame_rate = 25; /* DEFAULT */
mj2_setup_encoder(movie, &parameters);
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio,MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1)
{
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
}
else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}
} }
/* Calculating offset for samples and chunks */ mj2file = fopen(argv[2], "wb");
offset += cio_tell(cio);
sample->offset = offset; if (!mj2file) {
movie->tk[0].chunk[snum].offset = offset; /* There will be one sample per chunk */ fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
/* Calculating sample size */
fseek(j2kfile,0,SEEK_END);
sample->sample_size = ftell(j2kfile) + 8; /* Sample size is codestream + JP2C box header */
fseek(j2kfile,0,SEEK_SET);
/* Reading siz marker of j2k image for the first codestream */
if (snum==0)
read_siz_marker(j2kfile, &img);
/* Writing JP2C box header */
frame_codestream = (unsigned char*) malloc (sample->sample_size+8);
cio = opj_cio_open(movie->cinfo, frame_codestream, sample->sample_size);
cio_write(cio,sample->sample_size, 4); /* Sample size */
cio_write(cio,JP2_JP2C, 4); /* JP2C */
/* Writing codestream from J2K file to MJ2 file */
fread(frame_codestream+8,sample->sample_size-8,1,j2kfile);
fwrite(frame_codestream,sample->sample_size,1,mj2file);
cio_skip(cio, sample->sample_size-8);
/* Ending loop */
fclose(j2kfile);
snum++;
new_sample = (mj2_sample_t*)
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
new_chunk = (mj2_chunk_t*)
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
if (new_sample && new_chunk) {
movie->tk[0].sample = new_sample;
movie->tk[0].chunk = new_chunk;
} else {
fprintf(stderr, "Failed to allocate enough memory to read %s\n", j2kfilename);
return 1;
} }
free(frame_codestream); memset(&img, 0, sizeof(opj_image_t));
} /*
configure the event callbacks (not required)
/* Writing the MDAT box length in header */ setting of each callback is optionnal
offset += cio_tell(cio); */
buf = (unsigned char*) malloc (4 * sizeof(unsigned char)); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
cio = opj_cio_open(movie->cinfo, buf, 4); event_mgr.error_handler = error_callback;
cio_write(cio,offset-mdat_initpos,4); event_mgr.warning_handler = warning_callback;
fseek(mj2file,(long)mdat_initpos,SEEK_SET); event_mgr.info_handler = info_callback;
fwrite(buf,4,1,mj2file);
fseek(mj2file,0,SEEK_END); /* get a MJ2 decompressor handle */
free(buf); cinfo = mj2_create_compress();
/* Setting movie parameters */ /* catch events using our callbacks and give a local context */
movie->tk[0].num_samples=snum; opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
movie->tk[0].num_chunks=snum;
setparams(movie, &img); /* setup the decoder encoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_cparameters_t));
/* Writing MOOV box */ movie = (opj_mj2_t*) cinfo->mj2_handle;
buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20)); j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
mj2_write_moov(movie, cio); sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
fwrite(buf,cio_tell(cio),1,mj2file);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
/* Ending program */
free(img.comps); parameters.frame_rate = 25; /* DEFAULT */
opj_cio_close(cio);
mj2_setup_encoder(movie, &parameters);
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio,MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1) {
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
} else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}
}
/* Calculating offset for samples and chunks */
offset += cio_tell(cio);
sample->offset = offset;
movie->tk[0].chunk[snum].offset = offset; /* There will be one sample per chunk */
/* Calculating sample size */
fseek(j2kfile,0,SEEK_END);
sample->sample_size = ftell(j2kfile) + 8; /* Sample size is codestream + JP2C box header */
fseek(j2kfile,0,SEEK_SET);
/* Reading siz marker of j2k image for the first codestream */
if (snum==0)
read_siz_marker(j2kfile, &img);
/* Writing JP2C box header */
frame_codestream = (unsigned char*) malloc (sample->sample_size+8);
cio = opj_cio_open(movie->cinfo, frame_codestream, sample->sample_size);
cio_write(cio,sample->sample_size, 4); /* Sample size */
cio_write(cio,JP2_JP2C, 4); /* JP2C */
/* Writing codestream from J2K file to MJ2 file */
fread(frame_codestream+8,sample->sample_size-8,1,j2kfile);
fwrite(frame_codestream,sample->sample_size,1,mj2file);
cio_skip(cio, sample->sample_size-8);
/* Ending loop */
fclose(j2kfile);
snum++;
new_sample = (mj2_sample_t*)
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
new_chunk = (mj2_chunk_t*)
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
if (new_sample && new_chunk) {
movie->tk[0].sample = new_sample;
movie->tk[0].chunk = new_chunk;
} else {
fprintf(stderr, "Failed to allocate enough memory to read %s\n", j2kfilename);
return 1;
}
free(frame_codestream);
}
/* Writing the MDAT box length in header */
offset += cio_tell(cio);
buf = (unsigned char*) malloc (4 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 4);
cio_write(cio,offset-mdat_initpos,4);
fseek(mj2file,(long)mdat_initpos,SEEK_SET);
fwrite(buf,4,1,mj2file);
fseek(mj2file,0,SEEK_END);
free(buf);
/* Setting movie parameters */
movie->tk[0].num_samples=snum;
movie->tk[0].num_chunks=snum;
setparams(movie, &img);
/* Writing MOOV box */
buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20));
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);
/* Ending program */
free(img.comps);
opj_cio_close(cio);
fin: fin:
fclose(mj2file); fclose(mj2file);
mj2_destroy_compress(movie); mj2_destroy_compress(movie);
free(j2kfilename); free(j2kfilename);
return 0; return 0;
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -66,23 +66,23 @@ public:
m_type = wxBITMAP_TYPE_MXF; m_type = wxBITMAP_TYPE_MXF;
m_mime = wxT("image/mxf"); m_mime = wxT("image/mxf");
m_reducefactor = 0; m_reducefactor = 0;
m_qualitylayers = 0; m_qualitylayers = 0;
m_components = 0; m_components = 0;
m_filename = wxT(""); m_filename = wxT("");
#ifdef USE_JPWL #ifdef USE_JPWL
m_enablejpwl = true; m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS; m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES; m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL #endif // USE_JPWL
} }
// decoding engine parameters // decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum; int m_reducefactor, m_qualitylayers, m_components, m_framenum;
wxFileName m_filename; wxFileName m_filename;
#ifdef USE_JPWL #ifdef USE_JPWL
bool m_enablejpwl; bool m_enablejpwl;
int m_expcomps, m_maxtiles; int m_expcomps, m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL
#if wxUSE_STREAMS #if wxUSE_STREAMS

View File

@@ -5,12 +5,10 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers) DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers)
include_directories( include_directories(
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h
) )
# Defines the source code for the library # Defines the source code for the library
set(OPENJPEG_SRCS set(OPENJPEG_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/thread.c
${CMAKE_CURRENT_SOURCE_DIR}/thread.h
${CMAKE_CURRENT_SOURCE_DIR}/bio.c ${CMAKE_CURRENT_SOURCE_DIR}/bio.c
${CMAKE_CURRENT_SOURCE_DIR}/bio.h ${CMAKE_CURRENT_SOURCE_DIR}/bio.h
${CMAKE_CURRENT_SOURCE_DIR}/cio.c ${CMAKE_CURRENT_SOURCE_DIR}/cio.c
@@ -31,7 +29,6 @@ set(OPENJPEG_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/mct.h ${CMAKE_CURRENT_SOURCE_DIR}/mct.h
${CMAKE_CURRENT_SOURCE_DIR}/mqc.c ${CMAKE_CURRENT_SOURCE_DIR}/mqc.c
${CMAKE_CURRENT_SOURCE_DIR}/mqc.h ${CMAKE_CURRENT_SOURCE_DIR}/mqc.h
${CMAKE_CURRENT_SOURCE_DIR}/mqc_inl.h
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c ${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
@@ -76,11 +73,6 @@ if(OPJ_DISABLE_TPSOT_FIX)
add_definitions(-DOPJ_DISABLE_TPSOT_FIX) add_definitions(-DOPJ_DISABLE_TPSOT_FIX)
endif() endif()
# Special case for old i586-mingw32msvc-gcc cross compiler
if(NOT WIN32 AND CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER MATCHES ".*mingw32msvc.*" )
set(WIN32 YES)
endif()
# Build the library # Build the library
if(WIN32) if(WIN32)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
@@ -118,18 +110,16 @@ install(
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man3) DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man3)
endif() endif()
if(BUILD_LUTS_GENERATOR) # internal utilities to generate t1_luts.h (part of the jp2 lib)
# internal utility to generate t1_luts.h (part of the jp2 lib)
# no need to install: # no need to install:
add_executable(t1_generate_luts t1_generate_luts.c) add_executable(t1_generate_luts t1_generate_luts.c)
if(UNIX) if(UNIX)
target_link_libraries(t1_generate_luts m) target_link_libraries(t1_generate_luts m)
endif()
endif() endif()
# Experimental option; let's how cppcheck performs # Experimental option; let's how cppcheck performs
# Implementation details: # Implementation details:
# I could not figure out how to easily upload a file to CDash. Instead simply # I could not figure out how to easily upload a file to CDash. Instead simply
# pretend cppcheck is part of the Build step. Technically cppcheck can even # pretend cppcheck is part of the Build step. Technically cppcheck can even
# output gcc formatted error/warning report # output gcc formatted error/warning report
# Another implementation detail: I could not redirect error to the error # Another implementation detail: I could not redirect error to the error
@@ -146,42 +136,9 @@ endif()
if(OPJ_USE_DSYMUTIL) if(OPJ_USE_DSYMUTIL)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME} POST_BUILD add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME} POST_BUILD
COMMAND "dsymutil" "$<TARGET_SONAME_FILE:${OPENJPEG_LIBRARY_NAME}>" COMMAND "dsymutil" "$<TARGET_SONAME_FILE:${OPENJPEG_LIBRARY_NAME}>"
COMMENT "dsymutil $<TARGET_SONAME_FILE:${OPENJPEG_LIBRARY_NAME}>" COMMENT "dsymutil $<TARGET_SONAME_FILE:${OPENJPEG_LIBRARY_NAME}>"
DEPENDS ${OPENJPEG_LIBRARY_NAME}) DEPENDS ${OPENJPEG_LIBRARY_NAME})
endif() endif()
endif() endif()
#################################################################################
# threading configuration
#################################################################################
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
option(OPJ_USE_THREAD "Build with thread/mutex support " ON)
if(NOT OPJ_USE_THREAD)
add_definitions( -DMUTEX_stub)
endif(NOT OPJ_USE_THREAD)
find_package(Threads QUIET)
if(OPJ_USE_THREAD AND WIN32 AND NOT Threads_FOUND )
add_definitions( -DMUTEX_win32)
set(Threads_FOUND YES)
endif()
if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_WIN32_THREADS_INIT )
add_definitions( -DMUTEX_win32)
endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_WIN32_THREADS_INIT )
if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT )
add_definitions( -DMUTEX_pthread)
endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT )
if(OPJ_USE_THREAD AND NOT Threads_FOUND)
message(FATAL_ERROR "No thread library found and thread/mutex support is required by OPJ_USE_THREAD option")
endif(OPJ_USE_THREAD AND NOT Threads_FOUND)
if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME} ${CMAKE_THREAD_LIBS_INIT})
endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -72,132 +72,133 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
/*@}*/ /*@}*/
/* /*
========================================================== ==========================================================
local functions local functions
========================================================== ==========================================================
*/ */
static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) { static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio)
bio->buf = (bio->buf << 8) & 0xffff; {
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->buf = (bio->buf << 8) & 0xffff;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { bio->ct = bio->buf == 0xff00 ? 7 : 8;
return OPJ_FALSE; if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
} return OPJ_FALSE;
*bio->bp++ = (OPJ_BYTE)(bio->buf >> 8); }
return OPJ_TRUE; *bio->bp++ = (OPJ_BYTE)(bio->buf >> 8);
return OPJ_TRUE;
} }
static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) { static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio)
bio->buf = (bio->buf << 8) & 0xffff; {
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->buf = (bio->buf << 8) & 0xffff;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { bio->ct = bio->buf == 0xff00 ? 7 : 8;
return OPJ_FALSE; if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
} return OPJ_FALSE;
bio->buf |= *bio->bp++; }
return OPJ_TRUE; bio->buf |= *bio->bp++;
return OPJ_TRUE;
} }
static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) { static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b)
if (bio->ct == 0) { {
opj_bio_byteout(bio); /* MSD: why not check the return value of this function ? */ if (bio->ct == 0) {
} opj_bio_byteout(bio); /* MSD: why not check the return value of this function ? */
bio->ct--; }
bio->buf |= b << bio->ct; bio->ct--;
bio->buf |= b << bio->ct;
} }
static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) { static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio)
if (bio->ct == 0) { {
opj_bio_bytein(bio); /* MSD: why not check the return value of this function ? */ if (bio->ct == 0) {
} opj_bio_bytein(bio); /* MSD: why not check the return value of this function ? */
bio->ct--; }
return (bio->buf >> bio->ct) & 1; bio->ct--;
return (bio->buf >> bio->ct) & 1;
} }
/* /*
========================================================== ==========================================================
Bit Input/Output interface Bit Input/Output interface
========================================================== ==========================================================
*/ */
opj_bio_t* opj_bio_create(void) { opj_bio_t* opj_bio_create(void)
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); {
return bio; opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
} }
void opj_bio_destroy(opj_bio_t *bio) { void opj_bio_destroy(opj_bio_t *bio)
if(bio) { {
opj_free(bio); if(bio) {
} opj_free(bio);
}
} }
ptrdiff_t opj_bio_numbytes(opj_bio_t *bio) { ptrdiff_t opj_bio_numbytes(opj_bio_t *bio)
return (bio->bp - bio->start); {
return (bio->bp - bio->start);
} }
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
bio->start = bp; {
bio->end = bp + len; bio->start = bp;
bio->bp = bp; bio->end = bp + len;
bio->buf = 0; bio->bp = bp;
bio->ct = 8; bio->buf = 0;
bio->ct = 8;
} }
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
bio->start = bp; {
bio->end = bp + len; bio->start = bp;
bio->bp = bp; bio->end = bp + len;
bio->buf = 0; bio->bp = bp;
bio->ct = 0; bio->buf = 0;
bio->ct = 0;
} }
OPJ_NOSANITIZE("unsigned-integer-overflow") void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n)
void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) { {
OPJ_UINT32 i; OPJ_UINT32 i;
for (i = n - 1; i < n; i--) {
assert((n > 0U) && (n <= 32U)); opj_bio_putbit(bio, (v >> i) & 1);
for (i = n - 1; i < n; i--) { /* overflow used for end-loop condition */ }
opj_bio_putbit(bio, (v >> i) & 1);
}
} }
OPJ_NOSANITIZE("unsigned-integer-overflow") OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n)
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) { {
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_UINT32 v; OPJ_UINT32 v;
v = 0;
assert((n > 0U) /* && (n <= 32U)*/); for (i = n - 1; i < n; i--) {
#ifdef OPJ_UBSAN_BUILD v += opj_bio_getbit(bio) << i;
/* This assert fails for some corrupted images which are gracefully rejected */ }
/* Add this assert only for ubsan build. */ return v;
/* This is the condition for overflow not to occur below which is needed because of OPJ_NOSANITIZE */
assert(n <= 32U);
#endif
v = 0U;
for (i = n - 1; i < n; i--) { /* overflow used for end-loop condition */
v |= opj_bio_getbit(bio) << i; /* can't overflow, opj_bio_getbit returns 0 or 1 */
}
return v;
} }
OPJ_BOOL opj_bio_flush(opj_bio_t *bio) { OPJ_BOOL opj_bio_flush(opj_bio_t *bio)
if (! opj_bio_byteout(bio)) { {
return OPJ_FALSE; if (! opj_bio_byteout(bio)) {
} return OPJ_FALSE;
if (bio->ct == 7) { }
if (! opj_bio_byteout(bio)) { if (bio->ct == 7) {
return OPJ_FALSE; if (! opj_bio_byteout(bio)) {
} return OPJ_FALSE;
} }
return OPJ_TRUE; }
return OPJ_TRUE;
} }
OPJ_BOOL opj_bio_inalign(opj_bio_t *bio) { OPJ_BOOL opj_bio_inalign(opj_bio_t *bio)
if ((bio->buf & 0xff) == 0xff) { {
if (! opj_bio_bytein(bio)) { if ((bio->buf & 0xff) == 0xff) {
return OPJ_FALSE; if (! opj_bio_bytein(bio)) {
} return OPJ_FALSE;
} }
bio->ct = 0; }
return OPJ_TRUE; bio->ct = 0;
return OPJ_TRUE;
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -40,7 +40,7 @@
#include <stddef.h> /* ptrdiff_t */ #include <stddef.h> /* ptrdiff_t */
/** /**
@file bio.h @file bio.h
@brief Implementation of an individual bit input-output (BIO) @brief Implementation of an individual bit input-output (BIO)
@@ -54,23 +54,23 @@ The functions in BIO.C have for goal to realize an individual bit input - output
Individual bit input-output stream (BIO) Individual bit input-output stream (BIO)
*/ */
typedef struct opj_bio { typedef struct opj_bio {
/** pointer to the start of the buffer */ /** pointer to the start of the buffer */
OPJ_BYTE *start; OPJ_BYTE *start;
/** pointer to the end of the buffer */ /** pointer to the end of the buffer */
OPJ_BYTE *end; OPJ_BYTE *end;
/** pointer to the present position in the buffer */ /** pointer to the present position in the buffer */
OPJ_BYTE *bp; OPJ_BYTE *bp;
/** temporary place where each byte is read or written */ /** temporary place where each byte is read or written */
OPJ_UINT32 buf; OPJ_UINT32 buf;
/** coder : number of bits free to write. decoder : number of bits read */ /** coder : number of bits free to write. decoder : number of bits read */
OPJ_UINT32 ct; OPJ_UINT32 ct;
} opj_bio_t; } opj_bio_t;
/** @name Exported functions */ /** @name Exported functions */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
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* opj_bio_create(void); opj_bio_t* opj_bio_create(void);
@@ -89,14 +89,14 @@ ptrdiff_t opj_bio_numbytes(opj_bio_t *bio);
Init encoder Init encoder
@param bio BIO handle @param bio BIO handle
@param bp Output buffer @param bp Output buffer
@param len Output buffer length @param len Output buffer length
*/ */
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len); void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len);
/** /**
Init decoder Init decoder
@param bio BIO handle @param bio BIO handle
@param bp Input buffer @param bp Input buffer
@param len Input buffer length @param len Input buffer length
*/ */
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len); void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len);
/** /**
@@ -109,7 +109,7 @@ void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n);
/** /**
Read bits Read bits
@param bio BIO handle @param bio BIO handle
@param n Number of bits to read @param n Number of bits to read
@return Returns the corresponding read number @return Returns the corresponding read number
*/ */
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n); OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n);

View File

@@ -32,7 +32,7 @@
#include "opj_includes.h" #include "opj_includes.h"
/* /*
* Write CPTR Codestream finder box * Write CPTR Codestream finder box
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -41,201 +41,197 @@
*/ */
void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio, void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen, int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
int i; int i;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
OPJ_UINT32 len; OPJ_UINT32 len;
opj_jp2_box_t *box; opj_jp2_box_t *box;
int num_box = 0; int num_box = 0;
OPJ_BOOL EPHused; OPJ_BOOL EPHused;
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
lenp = -1; lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
if(box == NULL){
return 0; for (i=0; i<2; i++) {
}
for (i=0;i<2;i++){ if(i)
opj_stream_seek(cio,lenp,p_manager);
if(i)
opj_stream_seek(cio,lenp,p_manager);
lenp = opj_stream_tell (cio); lenp = opj_stream_tell (cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */ opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_cptr( offset, cstr_info.codestream_size, cio,p_manager); opj_write_cptr( offset, cstr_info.codestream_size, cio,p_manager);
opj_write_manf( i, num_box, box, cio,p_manager); opj_write_manf( i, num_box, box, cio,p_manager);
num_box = 0;
box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager);
box[num_box].type = JPIP_MHIX;
num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager); num_box = 0;
box[num_box].type = JPIP_TPIX; box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager);
num_box++; box[num_box].type = JPIP_MHIX;
num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager);
box[num_box].type = JPIP_THIX;
num_box++;
EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager); box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
box[num_box].type = JPIP_TPIX;
box[num_box].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager); num_box++;
box[num_box].type = JPIP_PPIX;
num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PHIX;
num_box++;
len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
}
opj_free( box); box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager);
box[num_box].type = JPIP_THIX;
return (int)len; num_box++;
EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager);
box[num_box].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PPIX;
num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PHIX;
num_box++;
len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
}
opj_free( box);
return (int)len;
} }
void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio, void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [3*8]; OPJ_BYTE l_data_header [3*8];
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = opj_stream_tell(cio); lenp = opj_stream_tell(cio);
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */ opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */
opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */ opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */
opj_write_bytes( l_data_header+6, 0, 2); /* CONT */ opj_write_bytes( l_data_header+6, 0, 2); /* CONT */
opj_write_bytes( l_data_header+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */ opj_write_bytes( l_data_header+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */
opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */ opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */
opj_stream_write_data(cio,l_data_header,3*8,p_manager); opj_stream_write_data(cio,l_data_header,3*8,p_manager);
len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp); len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
opj_stream_seek(cio,lenp,p_manager); opj_stream_seek(cio,lenp,p_manager);
opj_write_bytes(l_data_header, len, 4); /* L */ opj_write_bytes(l_data_header, len, 4); /* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
} }
void opj_write_manf(int second, void opj_write_manf(int second,
int v, int v,
opj_jp2_box_t *box, opj_jp2_box_t *box,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
int i; int i;
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = opj_stream_tell(cio);
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */
opj_stream_write_data(cio,l_data_header,4,p_manager);
if (second){ /* Write only during the second pass */ lenp = opj_stream_tell(cio);
for( i=0; i<v; i++){ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */ opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
opj_stream_write_data(cio,l_data_header,4,p_manager); if (second) { /* Write only during the second pass */
for( i=0; i<v; i++) {
opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
opj_stream_write_data(cio,l_data_header,4,p_manager);
}
} }
}
len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp); len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
opj_stream_seek(cio,lenp,p_manager); opj_stream_seek(cio,lenp,p_manager);
opj_write_bytes(l_data_header, len, 4);/* L */ opj_write_bytes(l_data_header, len, 4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio,lenp+len,p_manager); opj_stream_seek(cio,lenp+len,p_manager);
} }
int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = opj_stream_tell (cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */ lenp = opj_stream_tell (cio);
opj_stream_write_data(cio,l_data_header,8,p_manager); opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */
opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8);
opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, (OPJ_UINT32)cstr_info.marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager);
}
len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp); opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */
opj_stream_seek(cio, lenp,p_manager); opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++) { /* Marker restricted to 1 apparition, skip SOC marker */
opj_stream_seek(cio, lenp+len,p_manager); opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2);
return (int)len; opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8);
opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, (OPJ_UINT32)cstr_info.marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager);
}
len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return (int)len;
} }
OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio, OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
OPJ_BOOL EPHused = OPJ_FALSE; OPJ_BOOL EPHused = OPJ_FALSE;
int i=0; int i=0;
OPJ_OFF_T org_pos; OPJ_OFF_T org_pos;
unsigned int Scod; unsigned int Scod;
for(i = 0; i < marknum; i++) for(i = 0; i < marknum; i++) {
{ if( markers[i].type == J2K_MS_COD) {
if( markers[i].type == J2K_MS_COD) org_pos = opj_stream_tell(cio);
{ opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
org_pos = opj_stream_tell(cio);
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
opj_stream_read_data(cio,l_data_header,1,p_manager); opj_stream_read_data(cio,l_data_header,1,p_manager);
opj_read_bytes(l_data_header,&Scod,1); opj_read_bytes(l_data_header,&Scod,1);
if( ((Scod >> 2) & 1)) if( ((Scod >> 2) & 1))
EPHused = OPJ_TRUE; EPHused = OPJ_TRUE;
opj_stream_seek( cio, org_pos, p_manager); opj_stream_seek( cio, org_pos, p_manager);
break; break;
} }
} }
return EPHused; return EPHused;
} }

View File

@@ -40,7 +40,7 @@
#include "openjpeg.h" #include "openjpeg.h"
/* /*
* Write Codestream index box (superbox) * Write Codestream index box (superbox)
* *
* @param[in] offset offset of j2k codestream * @param[in] offset offset of j2k codestream
@@ -51,9 +51,9 @@
* @return length of cidx box * @return length of cidx box
*/ */
int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen, int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
* Check if EPH option is used * Check if EPH option is used
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -63,6 +63,6 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t
* @return true if EPH is used * @return true if EPH is used
*/ */
OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio, OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
#endif /* !CIDX_MANAGER_H_ */ #endif /* !CIDX_MANAGER_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -54,19 +54,19 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
#if defined(OPJ_BIG_ENDIAN) #if defined(OPJ_BIG_ENDIAN)
#define opj_write_bytes opj_write_bytes_BE #define opj_write_bytes opj_write_bytes_BE
#define opj_read_bytes opj_read_bytes_BE #define opj_read_bytes opj_read_bytes_BE
#define opj_write_double opj_write_double_BE #define opj_write_double opj_write_double_BE
#define opj_read_double opj_read_double_BE #define opj_read_double opj_read_double_BE
#define opj_write_float opj_write_float_BE #define opj_write_float opj_write_float_BE
#define opj_read_float opj_read_float_BE #define opj_read_float opj_read_float_BE
#else #else
#define opj_write_bytes opj_write_bytes_LE #define opj_write_bytes opj_write_bytes_LE
#define opj_read_bytes opj_read_bytes_LE #define opj_read_bytes opj_read_bytes_LE
#define opj_write_double opj_write_double_LE #define opj_write_double opj_write_double_LE
#define opj_read_double opj_read_double_LE #define opj_read_double opj_read_double_LE
#define opj_write_float opj_write_float_LE #define opj_write_float opj_write_float_LE
#define opj_read_float opj_read_float_LE #define opj_read_float opj_read_float_LE
#endif #endif
@@ -78,87 +78,86 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/** /**
Byte input-output stream. Byte input-output stream.
*/ */
typedef struct opj_stream_private typedef struct opj_stream_private {
{ /**
/** * User data, be it files, ... The actual data depends on the type of the stream.
* User data, be it files, ... The actual data depends on the type of the stream. */
*/ void * m_user_data;
void * m_user_data;
/** /**
* Pointer to function to free m_user_data (NULL at initialization) * Pointer to function to free m_user_data (NULL at initialization)
* when destroying the stream. If pointer is NULL the function is not * when destroying the stream. If pointer is NULL the function is not
* called and the m_user_data is not freed (even if non-NULL). * called and the m_user_data is not freed (even if non-NULL).
*/ */
opj_stream_free_user_data_fn m_free_user_data_fn; opj_stream_free_user_data_fn m_free_user_data_fn;
/** /**
* User data length * User data length
*/ */
OPJ_UINT64 m_user_data_length; OPJ_UINT64 m_user_data_length;
/** /**
* Pointer to actual read function (NULL at the initialization of the cio. * Pointer to actual read function (NULL at the initialization of the cio.
*/ */
opj_stream_read_fn m_read_fn; opj_stream_read_fn m_read_fn;
/** /**
* Pointer to actual write function (NULL at the initialization of the cio. * Pointer to actual write function (NULL at the initialization of the cio.
*/ */
opj_stream_write_fn m_write_fn; opj_stream_write_fn m_write_fn;
/** /**
* Pointer to actual skip function (NULL at the initialization of the cio. * Pointer to actual skip function (NULL at the initialization of the cio.
* There is no seek function to prevent from back and forth slow procedures. * There is no seek function to prevent from back and forth slow procedures.
*/ */
opj_stream_skip_fn m_skip_fn; opj_stream_skip_fn m_skip_fn;
/** /**
* Pointer to actual seek function (if available). * Pointer to actual seek function (if available).
*/ */
opj_stream_seek_fn m_seek_fn; opj_stream_seek_fn m_seek_fn;
/** /**
* Actual data stored into the stream if readed from. Data is read by chunk of fixed size. * Actual data stored into the stream if readed from. Data is read by chunk of fixed size.
* you should never access this data directly. * you should never access this data directly.
*/ */
OPJ_BYTE * m_stored_data; OPJ_BYTE * m_stored_data;
/** /**
* Pointer to the current read data. * Pointer to the current read data.
*/ */
OPJ_BYTE * m_current_data; OPJ_BYTE * m_current_data;
/** /**
* FIXME DOC. * FIXME DOC.
*/ */
OPJ_OFF_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_OFF_T , struct opj_event_mgr *); OPJ_OFF_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_OFF_T , struct opj_event_mgr *);
/** /**
* FIXME DOC. * FIXME DOC.
*/ */
OPJ_BOOL (* m_opj_seek) (struct opj_stream_private * , OPJ_OFF_T , struct opj_event_mgr *); OPJ_BOOL (* m_opj_seek) (struct opj_stream_private * , OPJ_OFF_T , struct opj_event_mgr *);
/** /**
* number of bytes containing in the buffer. * number of bytes containing in the buffer.
*/ */
OPJ_SIZE_T m_bytes_in_buffer; OPJ_SIZE_T m_bytes_in_buffer;
/** /**
* The number of bytes read/written from the beginning of the stream * The number of bytes read/written from the beginning of the stream
*/ */
OPJ_OFF_T m_byte_offset; OPJ_OFF_T m_byte_offset;
/** /**
* The size of the buffer. * The size of the buffer.
*/ */
OPJ_SIZE_T m_buffer_size; OPJ_SIZE_T m_buffer_size;
/** /**
* Flags to tell the status of the stream. * Flags to tell the status of the stream.
* Used with OPJ_STREAM_STATUS_* defines. * Used with OPJ_STREAM_STATUS_* defines.
*/ */
OPJ_UINT32 m_status; OPJ_UINT32 m_status;
} }
opj_stream_private_t; opj_stream_private_t;

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -63,11 +63,10 @@ OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec);
/** /**
Inverse 5-3 wavelet transform in 2-D. Inverse 5-3 wavelet transform 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 tp Thread pool
@param tilec Tile component information (current tile) @param tilec Tile component information (current tile)
@param numres Number of resolution levels to decode @param numres Number of resolution levels to decode
*/ */
OPJ_BOOL opj_dwt_decode(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres); OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres);
/** /**
Get the gain of a subband for the reversible 5-3 DWT. Get the gain of a subband for the reversible 5-3 DWT.
@@ -83,18 +82,18 @@ Get the norm of a wavelet function of a subband at a specified level for the rev
*/ */
OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient); OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient);
/** /**
Forward 9-7 wavelet transform in 2-D. Forward 9-7 wavelet transform in 2-D.
Apply an irreversible DWT transform to a component of an image. Apply an irreversible DWT transform to a component of an image.
@param tilec Tile component information (current tile) @param tilec Tile component information (current tile)
*/ */
OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec); OPJ_BOOL opj_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 numres Number of resolution levels to decode
*/ */
OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32 numres); OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres);
/** /**
Get the gain of a subband for the irreversible 9-7 DWT. Get the gain of a subband for the irreversible 9-7 DWT.
@@ -110,7 +109,7 @@ Get the norm of a wavelet function of a subband at a specified level for the irr
*/ */
OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient); OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient);
/** /**
Explicit calculation of the Quantization Stepsizes Explicit calculation of the Quantization Stepsizes
@param tccp Tile-component coding parameters @param tccp Tile-component coding parameters
@param prec Precint analyzed @param prec Precint analyzed
*/ */

View File

@@ -1,11 +1,11 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -40,14 +40,15 @@
#ifdef OPJ_CODE_NOT_USED #ifdef OPJ_CODE_NOT_USED
#ifndef _WIN32 #ifndef _WIN32
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); {
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; if (i/r > 0) a = i2a(i/r,a,r);
return a+1; *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
} }
/** /**
Transforms integer i into an ascii string and stores the result in a; Transforms integer i into an ascii string and stores the result in a;
string is encoded in the base indicated by r. string is encoded in the base indicated by r.
@param i Number to be converted @param i Number to be converted
@param a String result @param a String result
@@ -55,14 +56,14 @@ i2a(unsigned i, char *a, unsigned r) {
@return Returns a @return Returns a
*/ */
static char * static char *
_itoa(int i, char *a, int r) { _itoa(int i, char *a, int r)
r = ((r < 2) || (r > 36)) ? 10 : r; {
if(i < 0) { r = ((r < 2) || (r > 36)) ? 10 : r;
*a = '-'; if(i < 0) {
*i2a(-i, a+1, r) = 0; *a = '-';
} *i2a(-i, a+1, r) = 0;
else *i2a(i, a, r) = 0; } else *i2a(i, a, r) = 0;
return a; return a;
} }
#endif /* !_WIN32 */ #endif /* !_WIN32 */
@@ -83,64 +84,65 @@ static void opj_default_callback (const char *msg, void *client_data)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) { OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...)
{
#define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ #define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = 00; opj_msg_callback msg_handler = 00;
void * l_data = 00; void * l_data = 00;
if(p_event_mgr != 00) { if(p_event_mgr != 00) {
switch(event_type) { switch(event_type) {
case EVT_ERROR: case EVT_ERROR:
msg_handler = p_event_mgr->error_handler; msg_handler = p_event_mgr->error_handler;
l_data = p_event_mgr->m_error_data; l_data = p_event_mgr->m_error_data;
break; break;
case EVT_WARNING: case EVT_WARNING:
msg_handler = p_event_mgr->warning_handler; msg_handler = p_event_mgr->warning_handler;
l_data = p_event_mgr->m_warning_data; l_data = p_event_mgr->m_warning_data;
break; break;
case EVT_INFO: case EVT_INFO:
msg_handler = p_event_mgr->info_handler; msg_handler = p_event_mgr->info_handler;
l_data = p_event_mgr->m_info_data; l_data = p_event_mgr->m_info_data;
break; break;
default: default:
break; break;
} }
if(msg_handler == 00) { if(msg_handler == 00) {
return OPJ_FALSE; return OPJ_FALSE;
} }
} else { } else {
return OPJ_FALSE; return OPJ_FALSE;
} }
if ((fmt != 00) && (p_event_mgr != 00)) { if ((fmt != 00) && (p_event_mgr != 00)) {
va_list arg; va_list arg;
size_t str_length/*, i, j*/; /* UniPG */ size_t str_length/*, i, j*/; /* UniPG */
char message[OPJ_MSG_SIZE]; char message[OPJ_MSG_SIZE];
memset(message, 0, OPJ_MSG_SIZE); memset(message, 0, OPJ_MSG_SIZE);
/* initialize the optional parameter list */ /* initialize the optional parameter list */
va_start(arg, fmt); va_start(arg, fmt);
/* check the length of the format string */ /* check the length of the format string */
str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt); str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
(void)str_length; (void)str_length;
/* parse the format string and put the result in 'message' */ /* parse the format string and put the result in 'message' */
vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */ vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */
/* deinitialize the optional parameter list */ /* deinitialize the optional parameter list */
va_end(arg); va_end(arg);
/* output the message to the user program */ /* output the message to the user program */
msg_handler(message, l_data); msg_handler(message, l_data);
} }
return OPJ_TRUE; return OPJ_TRUE;
} }
void opj_set_default_event_handler(opj_event_mgr_t * p_manager) void opj_set_default_event_handler(opj_event_mgr_t * p_manager)
{ {
p_manager->m_error_data = 00; p_manager->m_error_data = 00;
p_manager->m_warning_data = 00; p_manager->m_warning_data = 00;
p_manager->m_info_data = 00; p_manager->m_info_data = 00;
p_manager->error_handler = opj_default_callback; p_manager->error_handler = opj_default_callback;
p_manager->info_handler = opj_default_callback; p_manager->info_handler = opj_default_callback;
p_manager->warning_handler = opj_default_callback; p_manager->warning_handler = opj_default_callback;
} }

View File

@@ -1,11 +1,11 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -40,27 +40,26 @@ The functions in EVENT.C have for goal to send output messages (errors, warnings
*/ */
/** /**
Message handler object Message handler object
used for used for
<ul> <ul>
<li>Error messages <li>Error messages
<li>Warning messages <li>Warning messages
<li>Debugging messages <li>Debugging messages
</ul> </ul>
*/ */
typedef struct opj_event_mgr typedef struct opj_event_mgr {
{ /** Data to call the event manager upon */
/** Data to call the event manager upon */ void * m_error_data;
void * m_error_data; /** Data to call the event manager upon */
/** Data to call the event manager upon */ void * m_warning_data;
void * m_warning_data; /** Data to call the event manager upon */
/** Data to call the event manager upon */ void * m_info_data;
void * m_info_data; /** Error message callback if available, NULL otherwise */
/** Error message callback if available, NULL otherwise */ opj_msg_callback error_handler;
opj_msg_callback error_handler; /** Warning message callback if available, NULL otherwise */
/** Warning message callback if available, NULL otherwise */ opj_msg_callback warning_handler;
opj_msg_callback warning_handler; /** Debug message callback if available, NULL otherwise */
/** Debug message callback if available, NULL otherwise */ opj_msg_callback info_handler;
opj_msg_callback info_handler;
} opj_event_mgr_t; } opj_event_mgr_t;

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -38,80 +38,72 @@
opj_procedure_list_t * opj_procedure_list_create() opj_procedure_list_t * opj_procedure_list_create()
{ {
/* memory allocation */ /* memory allocation */
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t)); opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation) if (! l_validation) {
{ return 00;
return 00; }
} /* initialization */
/* initialization */ l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE; l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure)); if (! l_validation->m_procedures) {
if (! l_validation->m_procedures) opj_free(l_validation);
{ return 00;
opj_free(l_validation); }
return 00; return l_validation;
}
return l_validation;
} }
void opj_procedure_list_destroy(opj_procedure_list_t * p_list) void opj_procedure_list_destroy(opj_procedure_list_t * p_list)
{ {
if (! p_list) if (! p_list) {
{ return;
return; }
} /* initialization */
/* initialization */ if (p_list->m_procedures) {
if (p_list->m_procedures) opj_free(p_list->m_procedures);
{ }
opj_free(p_list->m_procedures); opj_free(p_list);
}
opj_free(p_list);
} }
OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager ) OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager )
{ {
assert(p_manager != NULL);
if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures)
{
opj_procedure * new_procedures;
p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE; assert(p_manager != NULL);
new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_procedures, if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) {
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure)); opj_procedure * new_procedures;
if (! new_procedures)
{ p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE;
opj_free(p_validation_list->m_procedures); new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_nb_max_procedures = 0; p_validation_list->m_procedures,
p_validation_list->m_nb_procedures = 0; p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n"); if (! new_procedures) {
return OPJ_FALSE; opj_free(p_validation_list->m_procedures);
} p_validation_list->m_nb_max_procedures = 0;
else p_validation_list->m_nb_procedures = 0;
{ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
p_validation_list->m_procedures = new_procedures; return OPJ_FALSE;
} } else {
p_validation_list->m_procedures = new_procedures;
} }
p_validation_list->m_procedures[p_validation_list->m_nb_procedures] = p_procedure; }
++p_validation_list->m_nb_procedures; p_validation_list->m_procedures[p_validation_list->m_nb_procedures] = p_procedure;
++p_validation_list->m_nb_procedures;
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_UINT32 opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list) OPJ_UINT32 opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list)
{ {
return p_validation_list->m_nb_procedures; return p_validation_list->m_nb_procedures;
} }
opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list) opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list)
{ {
return p_validation_list->m_procedures; return p_validation_list->m_procedures;
} }
void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list) void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list)
{ {
p_validation_list->m_nb_procedures = 0; p_validation_list->m_nb_procedures = 0;
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -32,7 +32,7 @@
#ifndef __FUNCTION_LIST_H #ifndef __FUNCTION_LIST_H
#define __FUNCTION_LIST_H #define __FUNCTION_LIST_H
/** /**
* @file function_list.h * @file function_list.h
* @brief Implementation of a list of procedures. * @brief Implementation of a list of procedures.
@@ -54,20 +54,19 @@ typedef void (*opj_procedure)(void);
/** /**
* A list of procedures. * A list of procedures.
*/ */
typedef struct opj_procedure_list typedef struct opj_procedure_list {
{ /**
/** * The number of validation procedures.
* The number of validation procedures. */
*/ OPJ_UINT32 m_nb_procedures;
OPJ_UINT32 m_nb_procedures; /**
/** * The number of the array of validation procedures.
* The number of the array of validation procedures. */
*/ OPJ_UINT32 m_nb_max_procedures;
OPJ_UINT32 m_nb_max_procedures; /**
/** * The array of procedures.
* The array of procedures. */
*/ opj_procedure * m_procedures;
opj_procedure * m_procedures;
} opj_procedure_list_t; } opj_procedure_list_t;

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -31,73 +31,76 @@
#include "opj_includes.h" #include "opj_includes.h"
opj_image_t* opj_image_create0(void) { opj_image_t* opj_image_create0(void)
opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t)); {
return image; opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
return image;
} }
opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
OPJ_UINT32 compno; {
opj_image_t *image = NULL; OPJ_UINT32 compno;
opj_image_t *image = NULL;
image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t)); image = (opj_image_t*) opj_calloc(1, 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_calloc(1,image->numcomps * sizeof(opj_image_comp_t)); image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) { if(!image->comps) {
/* TODO replace with event manager, breaks API */ /* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */ /* fprintf(stderr,"Unable to allocate memory for image.\n"); */
opj_image_destroy(image); opj_image_destroy(image);
return NULL; return NULL;
} }
/* create the individual image components */ /* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) { for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno]; opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx; comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy; comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w; comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h; comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0; comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0; comp->y0 = cmptparms[compno].y0;
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 = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32)); comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32));
if(!comp->data) { if(!comp->data) {
/* TODO replace with event manager, breaks API */ /* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */ /* fprintf(stderr,"Unable to allocate memory for image.\n"); */
opj_image_destroy(image); opj_image_destroy(image);
return NULL; return NULL;
} }
} }
} }
return image; return image;
} }
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) { void OPJ_CALLCONV opj_image_destroy(opj_image_t *image)
if(image) { {
if(image->comps) { if(image) {
OPJ_UINT32 compno; if(image->comps) {
OPJ_UINT32 compno;
/* image components */ /* image components */
for(compno = 0; compno < image->numcomps; compno++) { for(compno = 0; compno < image->numcomps; compno++) {
opj_image_comp_t *image_comp = &(image->comps[compno]); opj_image_comp_t *image_comp = &(image->comps[compno]);
if(image_comp->data) { if(image_comp->data) {
opj_free(image_comp->data); opj_free(image_comp->data);
} }
} }
opj_free(image->comps); opj_free(image->comps);
} }
if(image->icc_profile_buf) { if(image->icc_profile_buf) {
opj_free(image->icc_profile_buf); opj_free(image->icc_profile_buf);
} }
opj_free(image); opj_free(image);
} }
} }
/** /**
@@ -108,32 +111,32 @@ void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
*/ */
void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp * p_cp) void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp * p_cp)
{ {
OPJ_UINT32 i, l_width, l_height; OPJ_UINT32 i, l_width, l_height;
OPJ_UINT32 l_x0, l_y0, l_x1, l_y1; OPJ_UINT32 l_x0, l_y0, l_x1, l_y1;
OPJ_UINT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1; OPJ_UINT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1;
opj_image_comp_t* l_img_comp = NULL; opj_image_comp_t* l_img_comp = NULL;
l_x0 = opj_uint_max(p_cp->tx0 , p_image_header->x0); l_x0 = opj_uint_max(p_cp->tx0 , p_image_header->x0);
l_y0 = opj_uint_max(p_cp->ty0 , p_image_header->y0); l_y0 = opj_uint_max(p_cp->ty0 , p_image_header->y0);
l_x1 = p_cp->tx0 + (p_cp->tw - 1U) * p_cp->tdx; /* validity of p_cp members used here checked in opj_j2k_read_siz. Can't overflow. */ l_x1 = p_cp->tx0 + (p_cp->tw - 1U) * p_cp->tdx; /* validity of p_cp members used here checked in opj_j2k_read_siz. Can't overflow. */
l_y1 = p_cp->ty0 + (p_cp->th - 1U) * p_cp->tdy; /* can't overflow */ l_y1 = p_cp->ty0 + (p_cp->th - 1U) * p_cp->tdy; /* can't overflow */
l_x1 = opj_uint_min(opj_uint_adds(l_x1, p_cp->tdx), p_image_header->x1); /* use add saturated to prevent overflow */ l_x1 = opj_uint_min(opj_uint_adds(l_x1, p_cp->tdx), p_image_header->x1); /* use add saturated to prevent overflow */
l_y1 = opj_uint_min(opj_uint_adds(l_y1, p_cp->tdy), p_image_header->y1); /* use add saturated to prevent overflow */ l_y1 = opj_uint_min(opj_uint_adds(l_y1, p_cp->tdy), p_image_header->y1); /* use add saturated to prevent overflow */
l_img_comp = p_image_header->comps; l_img_comp = p_image_header->comps;
for (i = 0; i < p_image_header->numcomps; ++i) { for (i = 0; i < p_image_header->numcomps; ++i) {
l_comp_x0 = opj_uint_ceildiv(l_x0, l_img_comp->dx); l_comp_x0 = opj_uint_ceildiv(l_x0, l_img_comp->dx);
l_comp_y0 = opj_uint_ceildiv(l_y0, l_img_comp->dy); l_comp_y0 = opj_uint_ceildiv(l_y0, l_img_comp->dy);
l_comp_x1 = opj_uint_ceildiv(l_x1, l_img_comp->dx); l_comp_x1 = opj_uint_ceildiv(l_x1, l_img_comp->dx);
l_comp_y1 = opj_uint_ceildiv(l_y1, l_img_comp->dy); l_comp_y1 = opj_uint_ceildiv(l_y1, l_img_comp->dy);
l_width = opj_uint_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor); l_width = opj_uint_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor);
l_height = opj_uint_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor); l_height = opj_uint_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor);
l_img_comp->w = l_width; l_img_comp->w = l_width;
l_img_comp->h = l_height; l_img_comp->h = l_height;
l_img_comp->x0 = l_comp_x0; l_img_comp->x0 = l_comp_x0;
l_img_comp->y0 = l_comp_y0; l_img_comp->y0 = l_comp_y0;
++l_img_comp; ++l_img_comp;
} }
} }
@@ -147,96 +150,95 @@ void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj
*/ */
void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_dest) void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_dest)
{ {
OPJ_UINT32 compno; OPJ_UINT32 compno;
/* preconditions */ /* preconditions */
assert(p_image_src != 00); assert(p_image_src != 00);
assert(p_image_dest != 00); assert(p_image_dest != 00);
p_image_dest->x0 = p_image_src->x0; p_image_dest->x0 = p_image_src->x0;
p_image_dest->y0 = p_image_src->y0; p_image_dest->y0 = p_image_src->y0;
p_image_dest->x1 = p_image_src->x1; p_image_dest->x1 = p_image_src->x1;
p_image_dest->y1 = p_image_src->y1; p_image_dest->y1 = p_image_src->y1;
if (p_image_dest->comps){ if (p_image_dest->comps) {
for(compno = 0; compno < p_image_dest->numcomps; compno++) { for(compno = 0; compno < p_image_dest->numcomps; compno++) {
opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]); opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]);
if(image_comp->data) { if(image_comp->data) {
opj_free(image_comp->data); opj_free(image_comp->data);
} }
} }
opj_free(p_image_dest->comps); opj_free(p_image_dest->comps);
p_image_dest->comps = NULL; p_image_dest->comps = NULL;
} }
p_image_dest->numcomps = p_image_src->numcomps; p_image_dest->numcomps = p_image_src->numcomps;
p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t)); p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t));
if (!p_image_dest->comps){ if (!p_image_dest->comps) {
p_image_dest->comps = NULL; p_image_dest->comps = NULL;
p_image_dest->numcomps = 0; p_image_dest->numcomps = 0;
return; return;
} }
for (compno=0; compno < p_image_dest->numcomps; compno++){ for (compno=0; compno < p_image_dest->numcomps; compno++) {
memcpy( &(p_image_dest->comps[compno]), memcpy( &(p_image_dest->comps[compno]),
&(p_image_src->comps[compno]), &(p_image_src->comps[compno]),
sizeof(opj_image_comp_t)); sizeof(opj_image_comp_t));
p_image_dest->comps[compno].data = NULL; p_image_dest->comps[compno].data = NULL;
} }
p_image_dest->color_space = p_image_src->color_space; p_image_dest->color_space = p_image_src->color_space;
p_image_dest->icc_profile_len = p_image_src->icc_profile_len; p_image_dest->icc_profile_len = p_image_src->icc_profile_len;
if (p_image_dest->icc_profile_len) { if (p_image_dest->icc_profile_len) {
p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc(p_image_dest->icc_profile_len); p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc(p_image_dest->icc_profile_len);
if (!p_image_dest->icc_profile_buf){ if (!p_image_dest->icc_profile_buf) {
p_image_dest->icc_profile_buf = NULL; p_image_dest->icc_profile_buf = NULL;
p_image_dest->icc_profile_len = 0; p_image_dest->icc_profile_len = 0;
return; return;
} }
memcpy( p_image_dest->icc_profile_buf, memcpy( p_image_dest->icc_profile_buf,
p_image_src->icc_profile_buf, p_image_src->icc_profile_buf,
p_image_src->icc_profile_len); p_image_src->icc_profile_len);
} } else
else p_image_dest->icc_profile_buf = NULL;
p_image_dest->icc_profile_buf = NULL;
return; return;
} }
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
OPJ_UINT32 compno; {
opj_image_t *image = 00; OPJ_UINT32 compno;
opj_image_t *image = 00;
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t)); image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
if (image) if (image) {
{
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
if (!image->comps) {
opj_image_destroy(image);
return 00;
}
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec;
comp->sgnd = cmptparms[compno].sgnd;
comp->data = 0;
}
}
return image; image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
if (!image->comps) {
opj_image_destroy(image);
return 00;
}
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec;
comp->sgnd = cmptparms[compno].sgnd;
comp->data = 0;
}
}
return image;
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *

View File

@@ -56,7 +56,7 @@
#define JPIP_PHLD 0x70686c64 /* Place holder */ #define JPIP_PHLD 0x70686c64 /* Place holder */
/* /*
* Write tile-part Index table box (superbox) * Write tile-part Index table box (superbox)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -66,10 +66,10 @@
* @return length of tpix box * @return length of tpix box
*/ */
int opj_write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio, int opj_write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
* Write tile header index table box (superbox) * Write tile header index table box (superbox)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -80,7 +80,7 @@ int opj_write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_s
int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ); int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, opj_event_mgr_t * p_manager );
/* /*
* Write precinct packet index table box (superbox) * Write precinct packet index table box (superbox)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -91,10 +91,10 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
* @return length of ppix box * @return length of ppix box
*/ */
int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
* Write packet header index table box (superbox) * Write packet header index table box (superbox)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -105,9 +105,9 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
* @return length of ppix box * @return length of ppix box
*/ */
int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
* Write manifest box (box) * Write manifest box (box)
* *
* @param[in] second number to be visited * @param[in] second number to be visited
@@ -116,13 +116,13 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
* @param[in] cio file output handle * @param[in] cio file output handle
*/ */
void opj_write_manf(int second, void opj_write_manf(int second,
int v, int v,
opj_jp2_box_t *box, opj_jp2_box_t *box,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
* Write main header index table (box) * Write main header index table (box)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -131,18 +131,18 @@ void opj_write_manf(int second,
* @return length of mainmhix box * @return length of mainmhix box
*/ */
int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio, int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio, int opj_write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
#endif /* !INDEXBOX_MANAGER_H_ */ #endif /* !INDEXBOX_MANAGER_H_ */

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -31,24 +31,24 @@
#include "opj_includes.h" #include "opj_includes.h"
/** /**
* LUP decomposition * LUP decomposition
*/ */
static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix, static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,
OPJ_UINT32 * permutations, OPJ_UINT32 * permutations,
OPJ_FLOAT32 * p_swap_area, OPJ_FLOAT32 * p_swap_area,
OPJ_UINT32 nb_compo); OPJ_UINT32 nb_compo);
/** /**
* LUP solving * LUP solving
*/ */
static void opj_lupSolve(OPJ_FLOAT32 * pResult, static void opj_lupSolve(OPJ_FLOAT32 * pResult,
OPJ_FLOAT32* pMatrix, OPJ_FLOAT32* pMatrix,
OPJ_FLOAT32* pVector, OPJ_FLOAT32* pVector,
OPJ_UINT32* pPermutations, OPJ_UINT32* pPermutations,
OPJ_UINT32 nb_compo, OPJ_UINT32 nb_compo,
OPJ_FLOAT32 * p_intermediate_data); OPJ_FLOAT32 * p_intermediate_data);
/** /**
*LUP inversion (call with the result of lupDecompose) *LUP inversion (call with the result of lupDecompose)
*/ */
static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix, static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix,
@@ -68,32 +68,32 @@ static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix,
* Matrix inversion. * Matrix inversion.
*/ */
OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix, OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo) OPJ_UINT32 nb_compo)
{ {
OPJ_BYTE * l_data = 00; OPJ_BYTE * l_data = 00;
OPJ_UINT32 l_permutation_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_UINT32); OPJ_UINT32 l_permutation_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_UINT32);
OPJ_UINT32 l_swap_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 l_swap_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_UINT32 l_total_size = l_permutation_size + 3 * l_swap_size; OPJ_UINT32 l_total_size = l_permutation_size + 3 * l_swap_size;
OPJ_UINT32 * lPermutations = 00; OPJ_UINT32 * lPermutations = 00;
OPJ_FLOAT32 * l_double_data = 00; OPJ_FLOAT32 * l_double_data = 00;
l_data = (OPJ_BYTE *) opj_malloc(l_total_size); l_data = (OPJ_BYTE *) opj_malloc(l_total_size);
if (l_data == 0) { if (l_data == 0) {
return OPJ_FALSE; return OPJ_FALSE;
} }
lPermutations = (OPJ_UINT32 *) l_data; lPermutations = (OPJ_UINT32 *) l_data;
l_double_data = (OPJ_FLOAT32 *) (l_data + l_permutation_size); l_double_data = (OPJ_FLOAT32 *) (l_data + l_permutation_size);
memset(lPermutations,0,l_permutation_size); memset(lPermutations,0,l_permutation_size);
if(! opj_lupDecompose(pSrcMatrix,lPermutations,l_double_data,nb_compo)) {
opj_free(l_data);
return OPJ_FALSE;
}
if(! opj_lupDecompose(pSrcMatrix,lPermutations,l_double_data,nb_compo)) {
opj_free(l_data);
return OPJ_FALSE;
}
opj_lupInvert(pSrcMatrix,pDestMatrix,nb_compo,lPermutations,l_double_data,l_double_data + nb_compo,l_double_data + 2*nb_compo); opj_lupInvert(pSrcMatrix,pDestMatrix,nb_compo,lPermutations,l_double_data,l_double_data + nb_compo,l_double_data + 2*nb_compo);
opj_free(l_data); opj_free(l_data);
return OPJ_TRUE; return OPJ_TRUE;
} }
@@ -104,191 +104,189 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
========================================================== ==========================================================
*/ */
static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations, static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
OPJ_FLOAT32 * p_swap_area, OPJ_FLOAT32 * p_swap_area,
OPJ_UINT32 nb_compo) OPJ_UINT32 nb_compo)
{ {
OPJ_UINT32 * tmpPermutations = permutations; OPJ_UINT32 * tmpPermutations = permutations;
OPJ_UINT32 * dstPermutations; OPJ_UINT32 * dstPermutations;
OPJ_UINT32 k2=0,t; OPJ_UINT32 k2=0,t;
OPJ_FLOAT32 temp; OPJ_FLOAT32 temp;
OPJ_UINT32 i,j,k; OPJ_UINT32 i,j,k;
OPJ_FLOAT32 p; OPJ_FLOAT32 p;
OPJ_UINT32 lLastColum = nb_compo - 1; OPJ_UINT32 lLastColum = nb_compo - 1;
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_FLOAT32 * lTmpMatrix = matrix; OPJ_FLOAT32 * lTmpMatrix = matrix;
OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix; OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix;
OPJ_UINT32 offset = 1; OPJ_UINT32 offset = 1;
OPJ_UINT32 lStride = nb_compo-1; OPJ_UINT32 lStride = nb_compo-1;
/*initialize permutations */ /*initialize permutations */
for (i = 0; i < nb_compo; ++i) for (i = 0; i < nb_compo; ++i) {
{ *tmpPermutations++ = i;
*tmpPermutations++ = i; }
} /* now make a pivot with column switch */
/* now make a pivot with column switch */ tmpPermutations = permutations;
tmpPermutations = permutations; for (k = 0; k < lLastColum; ++k) {
for (k = 0; k < lLastColum; ++k) { p = 0.0;
p = 0.0;
/* take the middle element */ /* take the middle element */
lColumnMatrix = lTmpMatrix + k; lColumnMatrix = lTmpMatrix + k;
/* make permutation with the biggest value in the column */ /* make permutation with the biggest value in the column */
for (i = k; i < nb_compo; ++i) { for (i = k; i < nb_compo; ++i) {
temp = ((*lColumnMatrix > 0) ? *lColumnMatrix : -(*lColumnMatrix)); temp = ((*lColumnMatrix > 0) ? *lColumnMatrix : -(*lColumnMatrix));
if (temp > p) { if (temp > p) {
p = temp; p = temp;
k2 = i; k2 = i;
} }
/* next line */ /* next line */
lColumnMatrix += nb_compo; lColumnMatrix += nb_compo;
} }
/* a whole rest of 0 -> non singular */ /* a whole rest of 0 -> non singular */
if (p == 0.0) { if (p == 0.0) {
return OPJ_FALSE; return OPJ_FALSE;
} }
/* should we permute ? */ /* should we permute ? */
if (k2 != k) { if (k2 != k) {
/*exchange of line */ /*exchange of line */
/* k2 > k */ /* k2 > k */
dstPermutations = tmpPermutations + k2 - k; dstPermutations = tmpPermutations + k2 - k;
/* swap indices */ /* swap indices */
t = *tmpPermutations; t = *tmpPermutations;
*tmpPermutations = *dstPermutations; *tmpPermutations = *dstPermutations;
*dstPermutations = t; *dstPermutations = t;
/* and swap entire line. */ /* and swap entire line. */
lColumnMatrix = lTmpMatrix + (k2 - k) * nb_compo; lColumnMatrix = lTmpMatrix + (k2 - k) * nb_compo;
memcpy(p_swap_area,lColumnMatrix,lSwapSize); memcpy(p_swap_area,lColumnMatrix,lSwapSize);
memcpy(lColumnMatrix,lTmpMatrix,lSwapSize); memcpy(lColumnMatrix,lTmpMatrix,lSwapSize);
memcpy(lTmpMatrix,p_swap_area,lSwapSize); memcpy(lTmpMatrix,p_swap_area,lSwapSize);
} }
/* now update data in the rest of the line and line after */ /* now update data in the rest of the line and line after */
lDestMatrix = lTmpMatrix + k; lDestMatrix = lTmpMatrix + k;
lColumnMatrix = lDestMatrix + nb_compo; lColumnMatrix = lDestMatrix + nb_compo;
/* take the middle element */ /* take the middle element */
temp = *(lDestMatrix++); temp = *(lDestMatrix++);
/* now compute up data (i.e. coeff up of the diagonal). */ /* now compute up data (i.e. coeff up of the diagonal). */
for (i = offset; i < nb_compo; ++i) { for (i = offset; i < nb_compo; ++i) {
/*lColumnMatrix; */ /*lColumnMatrix; */
/* divide the lower column elements by the diagonal value */ /* divide the lower column elements by the diagonal value */
/* matrix[i][k] /= matrix[k][k]; */
/* p = matrix[i][k] */
p = *lColumnMatrix / temp;
*(lColumnMatrix++) = p;
/* matrix[i][k] /= matrix[k][k]; */
/* p = matrix[i][k] */
p = *lColumnMatrix / temp;
*(lColumnMatrix++) = p;
for (j = /* k + 1 */ offset; j < nb_compo; ++j) { for (j = /* k + 1 */ offset; j < nb_compo; ++j) {
/* matrix[i][j] -= matrix[i][k] * matrix[k][j]; */ /* matrix[i][j] -= matrix[i][k] * matrix[k][j]; */
*(lColumnMatrix++) -= p * (*(lDestMatrix++)); *(lColumnMatrix++) -= p * (*(lDestMatrix++));
} }
/* come back to the k+1th element */ /* come back to the k+1th element */
lDestMatrix -= lStride; lDestMatrix -= lStride;
/* go to kth element of the next line */ /* go to kth element of the next line */
lColumnMatrix += k; lColumnMatrix += k;
} }
/* offset is now k+2 */ /* offset is now k+2 */
++offset; ++offset;
/* 1 element less for stride */ /* 1 element less for stride */
--lStride; --lStride;
/* next line */ /* next line */
lTmpMatrix+=nb_compo; lTmpMatrix+=nb_compo;
/* next permutation element */ /* next permutation element */
++tmpPermutations; ++tmpPermutations;
} }
return OPJ_TRUE; return OPJ_TRUE;
} }
static void opj_lupSolve (OPJ_FLOAT32 * pResult, static void opj_lupSolve (OPJ_FLOAT32 * pResult,
OPJ_FLOAT32 * pMatrix, OPJ_FLOAT32 * pMatrix,
OPJ_FLOAT32 * pVector, OPJ_FLOAT32 * pVector,
OPJ_UINT32* pPermutations, OPJ_UINT32* pPermutations,
OPJ_UINT32 nb_compo,OPJ_FLOAT32 * p_intermediate_data) OPJ_UINT32 nb_compo,OPJ_FLOAT32 * p_intermediate_data)
{ {
OPJ_INT32 k; OPJ_INT32 k;
OPJ_UINT32 i,j; OPJ_UINT32 i,j;
OPJ_FLOAT32 sum; OPJ_FLOAT32 sum;
OPJ_FLOAT32 u; OPJ_FLOAT32 u;
OPJ_UINT32 lStride = nb_compo+1; OPJ_UINT32 lStride = nb_compo+1;
OPJ_FLOAT32 * lCurrentPtr; OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lIntermediatePtr; OPJ_FLOAT32 * lIntermediatePtr;
OPJ_FLOAT32 * lDestPtr; OPJ_FLOAT32 * lDestPtr;
OPJ_FLOAT32 * lTmpMatrix; OPJ_FLOAT32 * lTmpMatrix;
OPJ_FLOAT32 * lLineMatrix = pMatrix; OPJ_FLOAT32 * lLineMatrix = pMatrix;
OPJ_FLOAT32 * lBeginPtr = pResult + nb_compo - 1; OPJ_FLOAT32 * lBeginPtr = pResult + nb_compo - 1;
OPJ_FLOAT32 * lGeneratedData; OPJ_FLOAT32 * lGeneratedData;
OPJ_UINT32 * lCurrentPermutationPtr = pPermutations; OPJ_UINT32 * lCurrentPermutationPtr = pPermutations;
lIntermediatePtr = p_intermediate_data;
lGeneratedData = p_intermediate_data + nb_compo - 1;
lIntermediatePtr = p_intermediate_data;
lGeneratedData = p_intermediate_data + nb_compo - 1;
for (i = 0; i < nb_compo; ++i) { for (i = 0; i < nb_compo; ++i) {
sum = 0.0; sum = 0.0;
lCurrentPtr = p_intermediate_data; lCurrentPtr = p_intermediate_data;
lTmpMatrix = lLineMatrix; lTmpMatrix = lLineMatrix;
for (j = 1; j <= i; ++j) for (j = 1; j <= i; ++j) {
{ /* sum += matrix[i][j-1] * y[j-1]; */
/* sum += matrix[i][j-1] * y[j-1]; */ sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
} }
/*y[i] = pVector[pPermutations[i]] - sum; */ /*y[i] = pVector[pPermutations[i]] - sum; */
*(lIntermediatePtr++) = pVector[*(lCurrentPermutationPtr++)] - sum; *(lIntermediatePtr++) = pVector[*(lCurrentPermutationPtr++)] - sum;
lLineMatrix += nb_compo; lLineMatrix += nb_compo;
} }
/* we take the last point of the matrix */ /* we take the last point of the matrix */
lLineMatrix = pMatrix + nb_compo*nb_compo - 1; lLineMatrix = pMatrix + nb_compo*nb_compo - 1;
/* and we take after the last point of the destination vector */ /* and we take after the last point of the destination vector */
lDestPtr = pResult + nb_compo; lDestPtr = pResult + nb_compo;
assert(nb_compo != 0); assert(nb_compo != 0);
for (k = (OPJ_INT32)nb_compo - 1; k != -1 ; --k) { for (k = (OPJ_INT32)nb_compo - 1; k != -1 ; --k) {
sum = 0.0; sum = 0.0;
lTmpMatrix = lLineMatrix; lTmpMatrix = lLineMatrix;
u = *(lTmpMatrix++); u = *(lTmpMatrix++);
lCurrentPtr = lDestPtr--; lCurrentPtr = lDestPtr--;
for (j = (OPJ_UINT32)(k + 1); j < nb_compo; ++j) { for (j = (OPJ_UINT32)(k + 1); j < nb_compo; ++j) {
/* sum += matrix[k][j] * x[j] */ /* sum += matrix[k][j] * x[j] */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++)); sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
} }
/*x[k] = (y[k] - sum) / u; */ /*x[k] = (y[k] - sum) / u; */
*(lBeginPtr--) = (*(lGeneratedData--) - sum) / u; *(lBeginPtr--) = (*(lGeneratedData--) - sum) / u;
lLineMatrix -= lStride; lLineMatrix -= lStride;
} }
} }
static void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix, static void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix, OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo, OPJ_UINT32 nb_compo,
OPJ_UINT32 * pPermutations, OPJ_UINT32 * pPermutations,
OPJ_FLOAT32 * p_src_temp, OPJ_FLOAT32 * p_src_temp,
OPJ_FLOAT32 * p_dest_temp, OPJ_FLOAT32 * p_dest_temp,
OPJ_FLOAT32 * p_swap_area ) OPJ_FLOAT32 * p_swap_area )
{ {
OPJ_UINT32 j,i; OPJ_UINT32 j,i;
OPJ_FLOAT32 * lCurrentPtr; OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lLineMatrix = pDestMatrix; OPJ_FLOAT32 * lLineMatrix = pDestMatrix;
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
for (j = 0; j < nb_compo; ++j) { for (j = 0; j < nb_compo; ++j) {
lCurrentPtr = lLineMatrix++; lCurrentPtr = lLineMatrix++;
memset(p_src_temp,0,lSwapSize); memset(p_src_temp,0,lSwapSize);
p_src_temp[j] = 1.0; p_src_temp[j] = 1.0;
opj_lupSolve(p_dest_temp,pSrcMatrix,p_src_temp, pPermutations, nb_compo , p_swap_area); opj_lupSolve(p_dest_temp,pSrcMatrix,p_src_temp, pPermutations, nb_compo , p_swap_area);
for (i = 0; i < nb_compo; ++i) { for (i = 0; i < nb_compo; ++i) {
*(lCurrentPtr) = p_dest_temp[i]; *(lCurrentPtr) = p_dest_temp[i];
lCurrentPtr+=nb_compo; lCurrentPtr+=nb_compo;
} }
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -49,16 +49,16 @@ The function in INVERT.H compute a matrix inversion with a LUP method
* The function does not take ownership of any memory block, data must be fred by the user. * The function does not take ownership of any memory block, data must be fred by the user.
* *
* @param pSrcMatrix the matrix to invert. * @param pSrcMatrix the matrix to invert.
* @param pDestMatrix data to store the inverted matrix. * @param pDestMatrix data to store the inverted matrix.
* @param n size of the matrix * @param n size of the matrix
* @return OPJ_TRUE if the inversion is successful, OPJ_FALSE if the matrix is singular. * @return OPJ_TRUE if the inversion is successful, OPJ_FALSE if the matrix is singular.
*/ */
OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix, OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo); OPJ_UINT32 nb_compo);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/
/*@}*/ /*@}*/
#endif /* __INVERT_H */ #endif /* __INVERT_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,12 +8,12 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan * Copyright (c) 2006-2007, Parvatha Elangovan
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr> * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* *
* All rights reserved. * All rights reserved.
@@ -99,8 +99,8 @@ The functions in J2K.C have for goal to read/write the several parts of the code
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
#define J2K_MS_EPC 0xff68 /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */ #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_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_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) */ #define J2K_MS_RED 0xff69 /**< RED marker value (Part 11: JPEG 2000 for Wireless) */
#endif /* USE_JPWL */ #endif /* USE_JPWL */
#ifdef USE_JPSEC #ifdef USE_JPSEC
@@ -116,91 +116,88 @@ The functions in J2K.C have for goal to read/write the several parts of the code
* These values may be combined with a | operator. * These values may be combined with a | operator.
* */ * */
typedef enum J2K_STATUS { typedef enum J2K_STATUS {
J2K_STATE_NONE = 0x0000, /**< a SOC marker is expected */ J2K_STATE_NONE = 0x0000, /**< a SOC marker is expected */
J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */ J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */
J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */ J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */
J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */ J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */
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_EOC = 0x0100, /**< the decoding process has encountered the EOC marker */ J2K_STATE_EOC = 0x0100, /**< the decoding process has encountered the EOC marker */
J2K_STATE_ERR = 0x8000 /**< the decoding process has encountered an error (FIXME warning V1 = 0x0080)*/ J2K_STATE_ERR = 0x8000 /**< the decoding process has encountered an error (FIXME warning V1 = 0x0080)*/
} J2K_STATUS; } J2K_STATUS;
/** /**
* Type of elements storing in the MCT data * Type of elements storing in the MCT data
*/ */
typedef enum MCT_ELEMENT_TYPE typedef enum MCT_ELEMENT_TYPE {
{ MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/
MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/ MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/
MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/ MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/
MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/ MCT_TYPE_DOUBLE = 3 /** MCT data is stored as doubles*/
MCT_TYPE_DOUBLE = 3 /** MCT data is stored as doubles*/
} J2K_MCT_ELEMENT_TYPE; } J2K_MCT_ELEMENT_TYPE;
/** /**
* Type of MCT array * Type of MCT array
*/ */
typedef enum MCT_ARRAY_TYPE typedef enum MCT_ARRAY_TYPE {
{ MCT_TYPE_DEPENDENCY = 0,
MCT_TYPE_DEPENDENCY = 0, MCT_TYPE_DECORRELATION = 1,
MCT_TYPE_DECORRELATION = 1, MCT_TYPE_OFFSET = 2
MCT_TYPE_OFFSET = 2
} J2K_MCT_ARRAY_TYPE; } J2K_MCT_ARRAY_TYPE;
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
T2 encoding mode T2 encoding mode
*/ */
typedef enum T2_MODE { typedef enum T2_MODE {
THRESH_CALC = 0, /** Function called in Rate allocation process*/ THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/ FINAL_PASS = 1 /** Function called in Tier 2 process*/
}J2K_T2_MODE; } J2K_T2_MODE;
/** /**
* Quantization stepsize * Quantization stepsize
*/ */
typedef struct opj_stepsize { typedef struct opj_stepsize {
/** exponent */ /** exponent */
OPJ_INT32 expn; OPJ_INT32 expn;
/** mantissa */ /** mantissa */
OPJ_INT32 mant; OPJ_INT32 mant;
} opj_stepsize_t; } opj_stepsize_t;
/** /**
Tile-component coding parameters Tile-component coding parameters
*/ */
typedef struct opj_tccp typedef struct opj_tccp {
{ /** coding style */
/** coding style */ OPJ_UINT32 csty;
OPJ_UINT32 csty; /** number of resolutions */
/** number of resolutions */ OPJ_UINT32 numresolutions;
OPJ_UINT32 numresolutions; /** code-blocks width */
/** code-blocks width */ OPJ_UINT32 cblkw;
OPJ_UINT32 cblkw; /** code-blocks height */
/** code-blocks height */ OPJ_UINT32 cblkh;
OPJ_UINT32 cblkh; /** code-block coding style */
/** code-block coding style */ OPJ_UINT32 cblksty;
OPJ_UINT32 cblksty; /** discrete wavelet transform identifier */
/** discrete wavelet transform identifier */ OPJ_UINT32 qmfbid;
OPJ_UINT32 qmfbid; /** quantisation style */
/** quantisation style */ OPJ_UINT32 qntsty;
OPJ_UINT32 qntsty; /** stepsizes used for quantization */
/** stepsizes used for quantization */ opj_stepsize_t stepsizes[OPJ_J2K_MAXBANDS];
opj_stepsize_t stepsizes[OPJ_J2K_MAXBANDS]; /** number of guard bits */
/** number of guard bits */ OPJ_UINT32 numgbits;
OPJ_UINT32 numgbits; /** Region Of Interest shift */
/** Region Of Interest shift */ OPJ_INT32 roishift;
OPJ_INT32 roishift; /** precinct width */
/** precinct width */ OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS]; /** precinct height */
/** precinct height */ OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS]; /** the dc_level_shift **/
/** the dc_level_shift **/ OPJ_INT32 m_dc_level_shift;
OPJ_INT32 m_dc_level_shift;
} }
opj_tccp_t; opj_tccp_t;
@@ -209,33 +206,30 @@ opj_tccp_t;
/** /**
* FIXME DOC * FIXME DOC
*/ */
typedef struct opj_mct_data typedef struct opj_mct_data {
{ J2K_MCT_ELEMENT_TYPE m_element_type;
J2K_MCT_ELEMENT_TYPE m_element_type; J2K_MCT_ARRAY_TYPE m_array_type;
J2K_MCT_ARRAY_TYPE m_array_type; OPJ_UINT32 m_index;
OPJ_UINT32 m_index; OPJ_BYTE * m_data;
OPJ_BYTE * m_data; OPJ_UINT32 m_data_size;
OPJ_UINT32 m_data_size;
} }
opj_mct_data_t; opj_mct_data_t;
/** /**
* FIXME DOC * FIXME DOC
*/ */
typedef struct opj_simple_mcc_decorrelation_data typedef struct opj_simple_mcc_decorrelation_data {
{ OPJ_UINT32 m_index;
OPJ_UINT32 m_index; OPJ_UINT32 m_nb_comps;
OPJ_UINT32 m_nb_comps; opj_mct_data_t * m_decorrelation_array;
opj_mct_data_t * m_decorrelation_array; opj_mct_data_t * m_offset_array;
opj_mct_data_t * m_offset_array; OPJ_UINT32 m_is_irreversible : 1;
OPJ_BITFIELD m_is_irreversible : 1;
} }
opj_simple_mcc_decorrelation_data_t; opj_simple_mcc_decorrelation_data_t;
typedef struct opj_ppx_struct typedef struct opj_ppx_struct {
{ OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */
OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */ OPJ_UINT32 m_data_size;
OPJ_UINT32 m_data_size;
} opj_ppx; } opj_ppx;
/** /**
@@ -243,106 +237,103 @@ Tile coding parameters :
this structure is used to store coding/decoding parameters common to all this structure is used to store coding/decoding parameters common to all
tiles (information like COD, COC in main header) tiles (information like COD, COC in main header)
*/ */
typedef struct opj_tcp typedef struct opj_tcp {
{ /** coding style */
/** coding style */ OPJ_UINT32 csty;
OPJ_UINT32 csty; /** progression order */
/** progression order */ OPJ_PROG_ORDER prg;
OPJ_PROG_ORDER prg; /** number of layers */
/** number of layers */ OPJ_UINT32 numlayers;
OPJ_UINT32 numlayers; OPJ_UINT32 num_layers_to_decode;
OPJ_UINT32 num_layers_to_decode; /** multi-component transform identifier */
/** multi-component transform identifier */ OPJ_UINT32 mct;
OPJ_UINT32 mct; /** rates of layers */
/** rates of layers */ OPJ_FLOAT32 rates[100];
OPJ_FLOAT32 rates[100]; /** number of progression order changes */
/** number of progression order changes */ OPJ_UINT32 numpocs;
OPJ_UINT32 numpocs; /** progression order changes */
/** progression order changes */ opj_poc_t pocs[32];
opj_poc_t pocs[32];
/** number of ppt markers (reserved size) */
/** number of ppt markers (reserved size) */ OPJ_UINT32 ppt_markers_count;
OPJ_UINT32 ppt_markers_count; /** ppt markers data (table indexed by Zppt) */
/** ppt markers data (table indexed by Zppt) */ opj_ppx* ppt_markers;
opj_ppx* ppt_markers;
/** packet header store there for future use in t2_decode_packet */
/** packet header store there for future use in t2_decode_packet */ OPJ_BYTE *ppt_data;
OPJ_BYTE *ppt_data; /** used to keep a track of the allocated memory */
/** used to keep a track of the allocated memory */ OPJ_BYTE *ppt_buffer;
OPJ_BYTE *ppt_buffer; /** Number of bytes stored inside ppt_data*/
/** Number of bytes stored inside ppt_data*/ OPJ_UINT32 ppt_data_size;
OPJ_UINT32 ppt_data_size; /** size of ppt_data*/
/** size of ppt_data*/ OPJ_UINT32 ppt_len;
OPJ_UINT32 ppt_len; /** add fixed_quality */
/** add fixed_quality */ OPJ_FLOAT32 distoratio[100];
OPJ_FLOAT32 distoratio[100]; /** tile-component coding parameters */
/** tile-component coding parameters */ opj_tccp_t *tccps;
opj_tccp_t *tccps; /** number of tile parts for the tile. */
/** number of tile parts for the tile. */ OPJ_UINT32 m_nb_tile_parts;
OPJ_UINT32 m_nb_tile_parts; /** data for the tile */
/** data for the tile */ OPJ_BYTE * m_data;
OPJ_BYTE * m_data; /** size of data */
/** size of data */ OPJ_UINT32 m_data_size;
OPJ_UINT32 m_data_size; /** encoding norms */
/** encoding norms */ OPJ_FLOAT64 * mct_norms;
OPJ_FLOAT64 * mct_norms; /** the mct decoding matrix */
/** the mct decoding matrix */ OPJ_FLOAT32 * m_mct_decoding_matrix;
OPJ_FLOAT32 * m_mct_decoding_matrix; /** the mct coding matrix */
/** the mct coding matrix */ OPJ_FLOAT32 * m_mct_coding_matrix;
OPJ_FLOAT32 * m_mct_coding_matrix; /** mct records */
/** mct records */ opj_mct_data_t * m_mct_records;
opj_mct_data_t * m_mct_records; /** the number of mct records. */
/** the number of mct records. */ OPJ_UINT32 m_nb_mct_records;
OPJ_UINT32 m_nb_mct_records; /** the max number of mct records. */
/** the max number of mct records. */ OPJ_UINT32 m_nb_max_mct_records;
OPJ_UINT32 m_nb_max_mct_records; /** mcc records */
/** mcc records */ opj_simple_mcc_decorrelation_data_t * m_mcc_records;
opj_simple_mcc_decorrelation_data_t * m_mcc_records; /** the number of mct records. */
/** the number of mct records. */ OPJ_UINT32 m_nb_mcc_records;
OPJ_UINT32 m_nb_mcc_records; /** the max number of mct records. */
/** the max number of mct records. */ OPJ_UINT32 m_nb_max_mcc_records;
OPJ_UINT32 m_nb_max_mcc_records;
/***** FLAGS *******/ /***** FLAGS *******/
/** If cod == 1 --> there was a COD marker for the present tile */ /** If cod == 1 --> there was a COD marker for the present tile */
OPJ_BITFIELD cod : 1; OPJ_UINT32 cod : 1;
/** If ppt == 1 --> there was a PPT marker for the present tile */ /** If ppt == 1 --> there was a PPT marker for the present tile */
OPJ_BITFIELD ppt : 1; OPJ_UINT32 ppt : 1;
/** indicates if a POC marker has been used O:NO, 1:YES */ /** indicates if a POC marker has been used O:NO, 1:YES */
OPJ_BITFIELD POC : 1; OPJ_UINT32 POC : 1;
} opj_tcp_t; } opj_tcp_t;
typedef struct opj_encoding_param typedef struct opj_encoding_param {
{ /** Maximum rate for each component. If == 0, component size limitation is not considered */
/** Maximum rate for each component. If == 0, component size limitation is not considered */ OPJ_UINT32 m_max_comp_size;
OPJ_UINT32 m_max_comp_size; /** Position of tile part flag in progression order*/
/** Position of tile part flag in progression order*/ OPJ_INT32 m_tp_pos;
OPJ_INT32 m_tp_pos; /** fixed layer */
/** fixed layer */ OPJ_INT32 *m_matrice;
OPJ_INT32 *m_matrice; /** Flag determining tile part generation*/
/** Flag determining tile part generation*/ OPJ_BYTE m_tp_flag;
OPJ_BYTE m_tp_flag; /** allocation by rate/distortion */
/** allocation by rate/distortion */ OPJ_UINT32 m_disto_alloc : 1;
OPJ_BITFIELD m_disto_alloc : 1; /** allocation by fixed layer */
/** allocation by fixed layer */ OPJ_UINT32 m_fixed_alloc : 1;
OPJ_BITFIELD m_fixed_alloc : 1; /** add fixed_quality */
/** add fixed_quality */ OPJ_UINT32 m_fixed_quality : 1;
OPJ_BITFIELD m_fixed_quality : 1; /** Enabling Tile part generation*/
/** Enabling Tile part generation*/ OPJ_UINT32 m_tp_on : 1;
OPJ_BITFIELD m_tp_on : 1;
} }
opj_encoding_param_t; opj_encoding_param_t;
typedef struct opj_decoding_param typedef struct opj_decoding_param {
{ /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
/** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */ OPJ_UINT32 m_reduce;
OPJ_UINT32 m_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 */ OPJ_UINT32 m_layer;
OPJ_UINT32 m_layer;
} }
opj_decoding_param_t; opj_decoding_param_t;
@@ -350,199 +341,195 @@ opj_decoding_param_t;
/** /**
* Coding parameters * Coding parameters
*/ */
typedef struct opj_cp typedef struct opj_cp {
{ /** Size of the image in bits*/
/** Size of the image in bits*/ /*int img_size;*/
/*int img_size;*/ /** Rsiz*/
/** Rsiz*/
OPJ_UINT16 rsiz; OPJ_UINT16 rsiz;
/** XTOsiz */ /** XTOsiz */
OPJ_UINT32 tx0; /* MSD see norm */ OPJ_UINT32 tx0; /* MSD see norm */
/** YTOsiz */ /** YTOsiz */
OPJ_UINT32 ty0; /* MSD see norm */ OPJ_UINT32 ty0; /* MSD see norm */
/** XTsiz */ /** XTsiz */
OPJ_UINT32 tdx; OPJ_UINT32 tdx;
/** YTsiz */ /** YTsiz */
OPJ_UINT32 tdy; OPJ_UINT32 tdy;
/** comment */ /** comment */
OPJ_CHAR *comment; OPJ_CHAR *comment;
/** number of tiles in width */ /** number of tiles in width */
OPJ_UINT32 tw; OPJ_UINT32 tw;
/** number of tiles in heigth */ /** number of tiles in heigth */
OPJ_UINT32 th; OPJ_UINT32 th;
/** number of ppm markers (reserved size) */ /** number of ppm markers (reserved size) */
OPJ_UINT32 ppm_markers_count; OPJ_UINT32 ppm_markers_count;
/** ppm markers data (table indexed by Zppm) */ /** ppm markers data (table indexed by Zppm) */
opj_ppx* ppm_markers; opj_ppx* ppm_markers;
/** packet header store there for future use in t2_decode_packet */
OPJ_BYTE *ppm_data;
/** size of the ppm_data*/
OPJ_UINT32 ppm_len;
/** size of the ppm_data*/
OPJ_UINT32 ppm_data_read;
OPJ_BYTE *ppm_data_current; /** packet header store there for future use in t2_decode_packet */
OPJ_BYTE *ppm_data;
/** size of the ppm_data*/
OPJ_UINT32 ppm_len;
/** size of the ppm_data*/
OPJ_UINT32 ppm_data_read;
/** packet header storage original buffer */ OPJ_BYTE *ppm_data_current;
OPJ_BYTE *ppm_buffer;
/** pointer remaining on the first byte of the first header if ppm is used */
OPJ_BYTE *ppm_data_first;
/** Number of bytes actually stored inside the ppm_data */
OPJ_UINT32 ppm_data_size;
/** use in case of multiple marker PPM (number of info already store) */
OPJ_INT32 ppm_store;
/** use in case of multiple marker PPM (case on non-finished previous info) */
OPJ_INT32 ppm_previous;
/** tile coding parameters */ /** packet header storage original buffer */
opj_tcp_t *tcps; OPJ_BYTE *ppm_buffer;
/** pointer remaining on the first byte of the first header if ppm is used */
OPJ_BYTE *ppm_data_first;
/** Number of bytes actually stored inside the ppm_data */
OPJ_UINT32 ppm_data_size;
/** use in case of multiple marker PPM (number of info already store) */
OPJ_INT32 ppm_store;
/** use in case of multiple marker PPM (case on non-finished previous info) */
OPJ_INT32 ppm_previous;
union /** tile coding parameters */
{ opj_tcp_t *tcps;
opj_decoding_param_t m_dec;
opj_encoding_param_t m_enc; union {
} opj_decoding_param_t m_dec;
m_specific_param; opj_encoding_param_t m_enc;
}
m_specific_param;
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
/** enables writing of EPC in MH, thus activating JPWL */ /** enables writing of EPC in MH, thus activating JPWL */
OPJ_BOOL epc_on; OPJ_BOOL epc_on;
/** enables writing of EPB, in case of activated JPWL */ /** enables writing of EPB, in case of activated JPWL */
OPJ_BOOL epb_on; OPJ_BOOL epb_on;
/** enables writing of ESD, in case of activated JPWL */ /** enables writing of ESD, in case of activated JPWL */
OPJ_BOOL esd_on; OPJ_BOOL esd_on;
/** enables writing of informative techniques of ESD, in case of activated JPWL */ /** enables writing of informative techniques of ESD, in case of activated JPWL */
OPJ_BOOL info_on; OPJ_BOOL info_on;
/** enables writing of RED, in case of activated JPWL */ /** enables writing of RED, in case of activated JPWL */
OPJ_BOOL red_on; OPJ_BOOL red_on;
/** error protection method for MH (0,1,16,32,37-128) */ /** error protection method for MH (0,1,16,32,37-128) */
int hprot_MH; int hprot_MH;
/** tile number of header protection specification (>=0) */ /** tile number of header protection specification (>=0) */
int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS]; int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** error protection methods for TPHs (0,1,16,32,37-128) */ /** error protection methods for TPHs (0,1,16,32,37-128) */
int hprot_TPH[JPWL_MAX_NO_TILESPECS]; int hprot_TPH[JPWL_MAX_NO_TILESPECS];
/** tile number of packet protection specification (>=0) */ /** tile number of packet protection specification (>=0) */
int pprot_tileno[JPWL_MAX_NO_PACKSPECS]; int pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/** packet number of packet protection specification (>=0) */ /** packet number of packet protection specification (>=0) */
int pprot_packno[JPWL_MAX_NO_PACKSPECS]; int pprot_packno[JPWL_MAX_NO_PACKSPECS];
/** error protection methods for packets (0,1,16,32,37-128) */ /** error protection methods for packets (0,1,16,32,37-128) */
int pprot[JPWL_MAX_NO_PACKSPECS]; int pprot[JPWL_MAX_NO_PACKSPECS];
/** enables writing of ESD, (0/2/4 bytes) */ /** enables writing of ESD, (0/2/4 bytes) */
int sens_size; int sens_size;
/** sensitivity addressing size (0=auto/2/4 bytes) */ /** sensitivity addressing size (0=auto/2/4 bytes) */
int sens_addr; int sens_addr;
/** sensitivity range (0-3) */ /** sensitivity range (0-3) */
int sens_range; int sens_range;
/** sensitivity method for MH (-1,0-7) */ /** sensitivity method for MH (-1,0-7) */
int sens_MH; int sens_MH;
/** tile number of sensitivity specification (>=0) */ /** tile number of sensitivity specification (>=0) */
int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS]; int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** sensitivity methods for TPHs (-1,0-7) */ /** sensitivity methods for TPHs (-1,0-7) */
int sens_TPH[JPWL_MAX_NO_TILESPECS]; int sens_TPH[JPWL_MAX_NO_TILESPECS];
/** enables JPWL correction at the decoder */ /** enables JPWL correction at the decoder */
OPJ_BOOL correct; OPJ_BOOL correct;
/** expected number of components at the decoder */ /** expected number of components at the decoder */
int exp_comps; int exp_comps;
/** maximum number of tiles at the decoder */ /** maximum number of tiles at the decoder */
OPJ_UINT32 max_tiles; OPJ_UINT32 max_tiles;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/******** FLAGS *********/ /******** FLAGS *********/
/** if ppm == 1 --> there was a PPM marker*/ /** if ppm == 1 --> there was a PPM marker*/
OPJ_BITFIELD ppm : 1; OPJ_UINT32 ppm : 1;
/** tells if the parameter is a coding or decoding one */ /** tells if the parameter is a coding or decoding one */
OPJ_BITFIELD m_is_decoder : 1; OPJ_UINT32 m_is_decoder : 1;
/* <<UniPG */ /* <<UniPG */
} opj_cp_t; } opj_cp_t;
typedef struct opj_j2k_dec typedef struct opj_j2k_dec {
{ /** locate in which part of the codestream the decoder is (main header, tile header, end) */
/** locate in which part of the codestream the decoder is (main header, tile header, end) */ OPJ_UINT32 m_state;
OPJ_UINT32 m_state; /**
/** * store decoding parameters common to all tiles (information like COD, COC in main header)
* store decoding parameters common to all tiles (information like COD, COC in main header) */
*/ opj_tcp_t *m_default_tcp;
opj_tcp_t *m_default_tcp; OPJ_BYTE *m_header_data;
OPJ_BYTE *m_header_data; OPJ_UINT32 m_header_data_size;
OPJ_UINT32 m_header_data_size; /** to tell the tile part length */
/** to tell the tile part length */ OPJ_UINT32 m_sot_length;
OPJ_UINT32 m_sot_length; /** Only tiles index in the correct range will be decoded.*/
/** Only tiles index in the correct range will be decoded.*/ OPJ_UINT32 m_start_tile_x;
OPJ_UINT32 m_start_tile_x; OPJ_UINT32 m_start_tile_y;
OPJ_UINT32 m_start_tile_y; OPJ_UINT32 m_end_tile_x;
OPJ_UINT32 m_end_tile_x; OPJ_UINT32 m_end_tile_y;
OPJ_UINT32 m_end_tile_y; /**
/** * Decoded area set by the user
* Decoded area set by the user */
*/ OPJ_UINT32 m_DA_x0;
OPJ_UINT32 m_DA_x0; OPJ_UINT32 m_DA_y0;
OPJ_UINT32 m_DA_y0; OPJ_UINT32 m_DA_x1;
OPJ_UINT32 m_DA_x1; OPJ_UINT32 m_DA_y1;
OPJ_UINT32 m_DA_y1;
/** Index of the tile to decode (used in get_tile) */ /** Index of the tile to decode (used in get_tile) */
OPJ_INT32 m_tile_ind_to_dec; OPJ_INT32 m_tile_ind_to_dec;
/** Position of the last SOT marker read */ /** Position of the last SOT marker read */
OPJ_OFF_T m_last_sot_read_pos; OPJ_OFF_T m_last_sot_read_pos;
/** /**
* Indicate that the current tile-part is assume as the last tile part of the codestream. * Indicate that the current tile-part is assume as the last tile part of the codestream.
* It is useful in the case of PSot is equal to zero. The sot length will be compute in the * It is useful in the case of PSot is equal to zero. The sot length will be compute in the
* SOD reader function. FIXME NOT USED for the moment * SOD reader function. FIXME NOT USED for the moment
*/ */
OPJ_BOOL m_last_tile_part; OPJ_BOOL m_last_tile_part;
/** to tell that a tile can be decoded. */ /** to tell that a tile can be decoded. */
OPJ_BITFIELD m_can_decode : 1; OPJ_UINT32 m_can_decode : 1;
OPJ_BITFIELD m_discard_tiles : 1; OPJ_UINT32 m_discard_tiles : 1;
OPJ_BITFIELD m_skip_data : 1; OPJ_UINT32 m_skip_data : 1;
/** TNsot correction : see issue 254 **/ /** TNsot correction : see issue 254 **/
OPJ_BITFIELD m_nb_tile_parts_correction_checked : 1; OPJ_UINT32 m_nb_tile_parts_correction_checked : 1;
OPJ_BITFIELD m_nb_tile_parts_correction : 1; OPJ_UINT32 m_nb_tile_parts_correction : 1;
} opj_j2k_dec_t; } opj_j2k_dec_t;
typedef struct opj_j2k_enc typedef struct opj_j2k_enc {
{ /** Tile part number, regardless of poc, for each new poc, tp is reset to 1*/
/** Tile part number, regardless of poc, for each new poc, tp is reset to 1*/ OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */
OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */
/** Tile part number currently coding, taking into account POC. m_current_tile_part_number holds the total number of tile parts while encoding the last tile part.*/ /** Tile part number currently coding, taking into account POC. m_current_tile_part_number holds the total number of tile parts while encoding the last tile part.*/
OPJ_UINT32 m_current_tile_part_number; /*cur_tp_num */ OPJ_UINT32 m_current_tile_part_number; /*cur_tp_num */
/** /**
locate the start position of the TLM marker 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. after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length.
*/ */
OPJ_OFF_T m_tlm_start; OPJ_OFF_T m_tlm_start;
/** /**
* Stores the sizes of the tlm. * Stores the sizes of the tlm.
*/ */
OPJ_BYTE * m_tlm_sot_offsets_buffer; OPJ_BYTE * m_tlm_sot_offsets_buffer;
/** /**
* The current offset of the tlm buffer. * The current offset of the tlm buffer.
*/ */
OPJ_BYTE * m_tlm_sot_offsets_current; OPJ_BYTE * m_tlm_sot_offsets_current;
/** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/ /** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/
/** used in TLMmarker*/ /** used in TLMmarker*/
OPJ_UINT32 m_total_tile_parts; /* totnum_tp */ OPJ_UINT32 m_total_tile_parts; /* totnum_tp */
/* encoded data for a tile */ /* encoded data for a tile */
OPJ_BYTE * m_encoded_tile_data; OPJ_BYTE * m_encoded_tile_data;
/* size of the encoded_data */ /* size of the encoded_data */
OPJ_UINT32 m_encoded_tile_size; OPJ_UINT32 m_encoded_tile_size;
/* encoded data for a tile */ /* encoded data for a tile */
OPJ_BYTE * m_header_tile_data; OPJ_BYTE * m_header_tile_data;
/* size of the encoded_data */ /* size of the encoded_data */
OPJ_UINT32 m_header_tile_data_size; OPJ_UINT32 m_header_tile_data_size;
} opj_j2k_enc_t; } opj_j2k_enc_t;
@@ -553,48 +540,40 @@ struct opj_tcd;
/** /**
JPEG-2000 codestream reader/writer JPEG-2000 codestream reader/writer
*/ */
typedef struct opj_j2k typedef struct opj_j2k {
{ /* J2K codestream is decoded*/
/* J2K codestream is decoded*/ OPJ_BOOL m_is_decoder;
OPJ_BOOL m_is_decoder;
/* FIXME DOC*/ /* FIXME DOC*/
union union {
{ opj_j2k_dec_t m_decoder;
opj_j2k_dec_t m_decoder; opj_j2k_enc_t m_encoder;
opj_j2k_enc_t m_encoder; }
} m_specific_param;
m_specific_param;
/** pointer to the internal/private encoded / decoded image */ /** pointer to the internal/private encoded / decoded image */
opj_image_t* m_private_image; opj_image_t* m_private_image;
/* pointer to the output image (decoded)*/ /* pointer to the output image (decoded)*/
opj_image_t* m_output_image; opj_image_t* m_output_image;
/** Coding parameters */ /** Coding parameters */
opj_cp_t m_cp; opj_cp_t m_cp;
/** the list of procedures to exec **/ /** the list of procedures to exec **/
opj_procedure_list_t * m_procedure_list; opj_procedure_list_t * m_procedure_list;
/** the list of validation procedures to follow to make sure the code is valid **/ /** the list of validation procedures to follow to make sure the code is valid **/
opj_procedure_list_t * m_validation_list; opj_procedure_list_t * m_validation_list;
/** helper used to write the index file */ /** helper used to write the index file */
opj_codestream_index_t *cstr_index; opj_codestream_index_t *cstr_index;
/** number of the tile curently concern by coding/decoding */ /** number of the tile curently concern by coding/decoding */
OPJ_UINT32 m_current_tile_number; OPJ_UINT32 m_current_tile_number;
/** the current tile coder/decoder **/ /** the current tile coder/decoder **/
struct opj_tcd * m_tcd; struct opj_tcd * m_tcd;
/** Number of threads to use */
int m_num_threads;
/** Thread pool */
opj_thread_pool_t* m_tp;
} }
opj_j2k_t; opj_j2k_t;
@@ -607,14 +586,12 @@ opj_j2k_t;
/** /**
Setup the decoder decoding parameters using user parameters. Setup the decoder decoding parameters using user parameters.
Decoding parameters are returned in j2k->cp. Decoding parameters are returned in j2k->cp.
@param j2k J2K decompressor handle @param j2k J2K decompressor handle
@param parameters decompression parameters @param parameters decompression parameters
*/ */
void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters); void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads);
/** /**
* Creates a J2K compression structure * Creates a J2K compression structure
* *
@@ -624,9 +601,9 @@ opj_j2k_t* opj_j2k_create_compress(void);
OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_cparameters_t *parameters, opj_cparameters_t *parameters,
opj_image_t *image, opj_image_t *image,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
Converts an enum type progression order to string type Converts an enum type progression order to string type
@@ -733,10 +710,10 @@ OPJ_BOOL opj_j2k_read_tile_header ( opj_j2k_t * p_j2k,
* @return true if the area could be set. * @return true if the area could be set.
*/ */
OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
opj_image_t* p_image, opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Creates a J2K decompression structure. * Creates a J2K decompression structure.
@@ -809,14 +786,14 @@ OPJ_BOOL opj_j2k_decode(opj_j2k_t *j2k,
OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t* p_image, opj_image_t* p_image,
opj_event_mgr_t * p_manager, opj_event_mgr_t * p_manager,
OPJ_UINT32 tile_index ); OPJ_UINT32 tile_index );
OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
OPJ_UINT32 res_factor, OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
@@ -829,18 +806,18 @@ OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
* @param p_manager the user event manager. * @param p_manager the user event manager.
*/ */
OPJ_BOOL opj_j2k_write_tile ( opj_j2k_t * p_j2k, OPJ_BOOL opj_j2k_write_tile ( opj_j2k_t * p_j2k,
OPJ_UINT32 p_tile_index, OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data, OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size, OPJ_UINT32 p_data_size,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Encodes an image into a JPEG-2000 codestream * Encodes an image into a JPEG-2000 codestream
*/ */
OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k, OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Starts a compression scheme, i.e. validates the codec parameters, writes the header. * Starts a compression scheme, i.e. validates the codec parameters, writes the header.
@@ -853,17 +830,17 @@ OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
* @return true if the codec is valid. * @return true if the codec is valid.
*/ */
OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t * p_image, opj_image_t * p_image,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
* Ends the compression procedures and possibiliy add data to be read after the * Ends the compression procedures and possibiliy add data to be read after the
* codestream. * codestream.
*/ */
OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
OPJ_BOOL opj_j2k_setup_mct_encoding (opj_tcp_t * p_tcp, opj_image_t * p_image); OPJ_BOOL opj_j2k_setup_mct_encoding (opj_tcp_t * p_tcp, opj_image_t * p_image);

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -70,56 +70,50 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
typedef enum typedef enum {
{ JP2_STATE_NONE = 0x0,
JP2_STATE_NONE = 0x0, JP2_STATE_SIGNATURE = 0x1,
JP2_STATE_SIGNATURE = 0x1, JP2_STATE_FILE_TYPE = 0x2,
JP2_STATE_FILE_TYPE = 0x2, JP2_STATE_HEADER = 0x4,
JP2_STATE_HEADER = 0x4, JP2_STATE_CODESTREAM = 0x8,
JP2_STATE_CODESTREAM = 0x8, JP2_STATE_END_CODESTREAM = 0x10,
JP2_STATE_END_CODESTREAM = 0x10, JP2_STATE_UNKNOWN = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
JP2_STATE_UNKNOWN = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
} }
JP2_STATE; JP2_STATE;
typedef enum typedef enum {
{ JP2_IMG_STATE_NONE = 0x0,
JP2_IMG_STATE_NONE = 0x0, JP2_IMG_STATE_UNKNOWN = 0x7fffffff
JP2_IMG_STATE_UNKNOWN = 0x7fffffff
} }
JP2_IMG_STATE; JP2_IMG_STATE;
/** /**
Channel description: channel index, type, association Channel description: channel index, type, association
*/ */
typedef struct opj_jp2_cdef_info typedef struct opj_jp2_cdef_info {
{
OPJ_UINT16 cn, typ, asoc; OPJ_UINT16 cn, typ, asoc;
} opj_jp2_cdef_info_t; } opj_jp2_cdef_info_t;
/** /**
Channel descriptions and number of descriptions Channel descriptions and number of descriptions
*/ */
typedef struct opj_jp2_cdef typedef struct opj_jp2_cdef {
{
opj_jp2_cdef_info_t *info; opj_jp2_cdef_info_t *info;
OPJ_UINT16 n; OPJ_UINT16 n;
} opj_jp2_cdef_t; } opj_jp2_cdef_t;
/** /**
Component mappings: channel index, mapping type, palette index Component mappings: channel index, mapping type, palette index
*/ */
typedef struct opj_jp2_cmap_comp typedef struct opj_jp2_cmap_comp {
{
OPJ_UINT16 cmp; OPJ_UINT16 cmp;
OPJ_BYTE mtyp, pcol; OPJ_BYTE mtyp, pcol;
} opj_jp2_cmap_comp_t; } opj_jp2_cmap_comp_t;
/** /**
Palette data: table entries, palette columns Palette data: table entries, palette columns
*/ */
typedef struct opj_jp2_pclr typedef struct opj_jp2_pclr {
{
OPJ_UINT32 *entries; OPJ_UINT32 *entries;
OPJ_BYTE *channel_sign; OPJ_BYTE *channel_sign;
OPJ_BYTE *channel_size; OPJ_BYTE *channel_size;
@@ -128,11 +122,10 @@ typedef struct opj_jp2_pclr
OPJ_BYTE nr_channels; OPJ_BYTE nr_channels;
} opj_jp2_pclr_t; } opj_jp2_pclr_t;
/** /**
Collector for ICC profile, palette, component mapping, channel description Collector for ICC profile, palette, component mapping, channel description
*/ */
typedef struct opj_jp2_color typedef struct opj_jp2_color {
{
OPJ_BYTE *icc_profile_buf; OPJ_BYTE *icc_profile_buf;
OPJ_UINT32 icc_profile_len; OPJ_UINT32 icc_profile_len;
@@ -141,59 +134,58 @@ typedef struct opj_jp2_color
OPJ_BYTE jp2_has_colr; OPJ_BYTE jp2_has_colr;
} opj_jp2_color_t; } opj_jp2_color_t;
/** /**
JP2 component JP2 component
*/ */
typedef struct opj_jp2_comps { typedef struct opj_jp2_comps {
OPJ_UINT32 depth; OPJ_UINT32 depth;
OPJ_UINT32 sgnd; OPJ_UINT32 sgnd;
OPJ_UINT32 bpcc; OPJ_UINT32 bpcc;
} opj_jp2_comps_t; } opj_jp2_comps_t;
/** /**
JPEG-2000 file format reader/writer JPEG-2000 file format reader/writer
*/ */
typedef struct opj_jp2 typedef struct opj_jp2 {
{ /** handle to the J2K codec */
/** handle to the J2K codec */ opj_j2k_t *j2k;
opj_j2k_t *j2k; /** list of validation procedures */
/** list of validation procedures */ struct opj_procedure_list * m_validation_list;
struct opj_procedure_list * m_validation_list; /** list of execution procedures */
/** list of execution procedures */ struct opj_procedure_list * m_procedure_list;
struct opj_procedure_list * m_procedure_list;
/* width of image */ /* width of image */
OPJ_UINT32 w; OPJ_UINT32 w;
/* height of image */ /* height of image */
OPJ_UINT32 h; OPJ_UINT32 h;
/* number of components in the image */ /* number of components in the image */
OPJ_UINT32 numcomps; OPJ_UINT32 numcomps;
OPJ_UINT32 bpc; OPJ_UINT32 bpc;
OPJ_UINT32 C; OPJ_UINT32 C;
OPJ_UINT32 UnkC; OPJ_UINT32 UnkC;
OPJ_UINT32 IPR; OPJ_UINT32 IPR;
OPJ_UINT32 meth; OPJ_UINT32 meth;
OPJ_UINT32 approx; OPJ_UINT32 approx;
OPJ_UINT32 enumcs; OPJ_UINT32 enumcs;
OPJ_UINT32 precedence; OPJ_UINT32 precedence;
OPJ_UINT32 brand; OPJ_UINT32 brand;
OPJ_UINT32 minversion; OPJ_UINT32 minversion;
OPJ_UINT32 numcl; OPJ_UINT32 numcl;
OPJ_UINT32 *cl; OPJ_UINT32 *cl;
opj_jp2_comps_t *comps; opj_jp2_comps_t *comps;
/* FIXME: The following two variables are used to save offset /* FIXME: The following two variables are used to save offset
as we write out a JP2 file to disk. This mecanism is not flexible as we write out a JP2 file to disk. This mecanism is not flexible
as codec writers will need to extand those fields as new part as codec writers will need to extand those fields as new part
of the standard are implemented. of the standard are implemented.
*/ */
OPJ_OFF_T j2k_codestream_offset; OPJ_OFF_T j2k_codestream_offset;
OPJ_OFF_T jpip_iptr_offset; OPJ_OFF_T jpip_iptr_offset;
OPJ_BOOL jpip_on; OPJ_BOOL jpip_on;
OPJ_UINT32 jp2_state; OPJ_UINT32 jp2_state;
OPJ_UINT32 jp2_img_state; OPJ_UINT32 jp2_img_state;
opj_jp2_color_t color;
opj_jp2_color_t color;
OPJ_BOOL ignore_pclr_cmap_cdef; OPJ_BOOL ignore_pclr_cmap_cdef;
} }
opj_jp2_t; opj_jp2_t;
@@ -207,28 +199,26 @@ typedef struct opj_jp2_box {
OPJ_INT32 init_pos; OPJ_INT32 init_pos;
} opj_jp2_box_t; } opj_jp2_box_t;
typedef struct opj_jp2_header_handler typedef struct opj_jp2_header_handler {
{ /* marker value */
/* marker value */ OPJ_UINT32 id;
OPJ_UINT32 id; /* action linked to the marker */
/* action linked to the marker */ OPJ_BOOL (*handler) ( opj_jp2_t *jp2,
OPJ_BOOL (*handler) ( opj_jp2_t *jp2, OPJ_BYTE *p_header_data,
OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size,
OPJ_UINT32 p_header_size, opj_event_mgr_t * p_manager);
opj_event_mgr_t * p_manager);
} }
opj_jp2_header_handler_t; opj_jp2_header_handler_t;
typedef struct opj_jp2_img_header_writer_handler typedef struct opj_jp2_img_header_writer_handler {
{ /* action to perform */
/* action to perform */ OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size); /* result of the action : data */
/* result of the action : data */ OPJ_BYTE* m_data;
OPJ_BYTE* m_data; /* size of data */
/* size of data */ OPJ_UINT32 m_size;
OPJ_UINT32 m_size; }
}
opj_jp2_img_header_writer_handler_t; opj_jp2_img_header_writer_handler_t;
/** @name Exported functions */ /** @name Exported functions */
@@ -243,8 +233,6 @@ Decoding parameters are returned in jp2->j2k->cp.
*/ */
void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters); void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters);
OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads);
/** /**
* 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
@@ -256,12 +244,12 @@ OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads);
*/ */
OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t* p_image, opj_image_t* p_image,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
* Setup the encoder parameters using the current image and using user parameters. * Setup the encoder parameters using the current image and using user parameters.
* Coding parameters are returned in jp2->j2k->cp. * Coding parameters are returned in jp2->j2k->cp.
* *
* @param jp2 JP2 compressor handle * @param jp2 JP2 compressor handle
* @param parameters compression parameters * @param parameters compression parameters
@@ -269,10 +257,10 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
* @param p_manager FIXME DOC * @param p_manager FIXME DOC
* @return OPJ_TRUE if successful, OPJ_FALSE otherwise * @return OPJ_TRUE if successful, OPJ_FALSE otherwise
*/ */
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2, OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_cparameters_t *parameters, opj_cparameters_t *parameters,
opj_image_t *image, opj_image_t *image,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
Encode an image into a JPEG-2000 file stream Encode an image into a JPEG-2000 file stream
@@ -281,9 +269,9 @@ Encode an image into a JPEG-2000 file stream
@param p_manager event manager @param p_manager event manager
@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_BOOL opj_jp2_encode( opj_jp2_t *jp2,
opj_stream_private_t *stream, opj_stream_private_t *stream,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
@@ -307,8 +295,8 @@ OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
* codestream. * codestream.
*/ */
OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2, OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@@ -316,7 +304,7 @@ OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2,
* Ends the decompression procedures and possibiliy add data to be read after the * Ends the decompression procedures and possibiliy add data to be read after the
* codestream. * codestream.
*/ */
OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
@@ -331,9 +319,9 @@ OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2,
* @return true if the box is valid. * @return true if the box is valid.
*/ */
OPJ_BOOL opj_jp2_read_header( opj_stream_private_t *p_stream, OPJ_BOOL opj_jp2_read_header( opj_stream_private_t *p_stream,
opj_jp2_t *jp2, opj_jp2_t *jp2,
opj_image_t ** p_image, opj_image_t ** p_image,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Reads a tile header. * Reads a tile header.
@@ -372,11 +360,11 @@ OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
* @param p_manager the user event manager. * @param p_manager the user event manager.
*/ */
OPJ_BOOL opj_jp2_write_tile ( opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_write_tile ( opj_jp2_t *p_jp2,
OPJ_UINT32 p_tile_index, OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data, OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size, OPJ_UINT32 p_data_size,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Decode tile data. * Decode tile data.
@@ -424,14 +412,14 @@ void opj_jp2_destroy(opj_jp2_t *jp2);
* @return true if the area could be set. * @return true if the area could be set.
*/ */
OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2,
opj_image_t* p_image, opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* *
*/ */
OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t* p_image, opj_image_t* p_image,
@@ -440,11 +428,11 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
/** /**
* *
*/ */
OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2,
OPJ_UINT32 res_factor, OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/* TODO MSD: clean these 3 functions */ /* TODO MSD: clean these 3 functions */

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -61,12 +61,12 @@ static const OPJ_FLOAT64 opj_mct_norms_real[3] = { 1.732, 1.805, 1.573 };
const OPJ_FLOAT64 * opj_mct_get_mct_norms () const OPJ_FLOAT64 * opj_mct_get_mct_norms ()
{ {
return opj_mct_norms; return opj_mct_norms;
} }
const OPJ_FLOAT64 * opj_mct_get_mct_norms_real () const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
{ {
return opj_mct_norms_real; return opj_mct_norms_real;
} }
/* <summary> */ /* <summary> */
@@ -74,67 +74,67 @@ const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
/* </summary> */ /* </summary> */
#ifdef __SSE2__ #ifdef __SSE2__
void opj_mct_encode( void opj_mct_encode(
OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* restrict c0,
OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* restrict c1,
OPJ_INT32* OPJ_RESTRICT c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
const OPJ_SIZE_T len = n; const OPJ_SIZE_T len = n;
/* buffer are aligned on 16 bytes */ /* buffer are aligned on 16 bytes */
assert( ((size_t)c0 & 0xf) == 0 ); assert( ((size_t)c0 & 0xf) == 0 );
assert( ((size_t)c1 & 0xf) == 0 ); assert( ((size_t)c1 & 0xf) == 0 );
assert( ((size_t)c2 & 0xf) == 0 ); assert( ((size_t)c2 & 0xf) == 0 );
for(i = 0; i < (len & ~3U); i += 4) { for(i = 0; i < (len & ~3U); i += 4) {
__m128i y, u, v; __m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i])); __m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i])); __m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i])); __m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
y = _mm_add_epi32(g, g); y = _mm_add_epi32(g, g);
y = _mm_add_epi32(y, b); y = _mm_add_epi32(y, b);
y = _mm_add_epi32(y, r); y = _mm_add_epi32(y, r);
y = _mm_srai_epi32(y, 2); y = _mm_srai_epi32(y, 2);
u = _mm_sub_epi32(b, g); u = _mm_sub_epi32(b, g);
v = _mm_sub_epi32(r, g); v = _mm_sub_epi32(r, g);
_mm_store_si128((__m128i *)&(c0[i]), y); _mm_store_si128((__m128i *)&(c0[i]), y);
_mm_store_si128((__m128i *)&(c1[i]), u); _mm_store_si128((__m128i *)&(c1[i]), u);
_mm_store_si128((__m128i *)&(c2[i]), v); _mm_store_si128((__m128i *)&(c2[i]), v);
} }
for(; i < len; ++i) { for(; i < len; ++i) {
OPJ_INT32 r = c0[i]; OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i]; OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i]; OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2; OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g; OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g; OPJ_INT32 v = r - g;
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
} }
} }
#else #else
void opj_mct_encode( void opj_mct_encode(
OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* restrict c0,
OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* restrict c1,
OPJ_INT32* OPJ_RESTRICT c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
const OPJ_SIZE_T len = n; const OPJ_SIZE_T len = n;
for(i = 0; i < len; ++i) { for(i = 0; i < len; ++i) {
OPJ_INT32 r = c0[i]; OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i]; OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i]; OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2; OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g; OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g; OPJ_INT32 v = r - g;
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
} }
} }
#endif #endif
@@ -143,66 +143,67 @@ void opj_mct_encode(
/* </summary> */ /* </summary> */
#ifdef __SSE2__ #ifdef __SSE2__
void opj_mct_decode( void opj_mct_decode(
OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* restrict c0,
OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* restrict c1,
OPJ_INT32* OPJ_RESTRICT c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
const OPJ_SIZE_T len = n; const OPJ_SIZE_T len = n;
for(i = 0; i < (len & ~3U); i += 4) { for(i = 0; i < (len & ~3U); i += 4) {
__m128i r, g, b; __m128i r, g, b;
__m128i y = _mm_load_si128((const __m128i *)&(c0[i])); __m128i y = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i u = _mm_load_si128((const __m128i *)&(c1[i])); __m128i u = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i v = _mm_load_si128((const __m128i *)&(c2[i])); __m128i v = _mm_load_si128((const __m128i *)&(c2[i]));
g = y; g = y;
g = _mm_sub_epi32(g, _mm_srai_epi32(_mm_add_epi32(u, v), 2)); g = _mm_sub_epi32(g, _mm_srai_epi32(_mm_add_epi32(u, v), 2));
r = _mm_add_epi32(v, g); r = _mm_add_epi32(v, g);
b = _mm_add_epi32(u, g); b = _mm_add_epi32(u, g);
_mm_store_si128((__m128i *)&(c0[i]), r); _mm_store_si128((__m128i *)&(c0[i]), r);
_mm_store_si128((__m128i *)&(c1[i]), g); _mm_store_si128((__m128i *)&(c1[i]), g);
_mm_store_si128((__m128i *)&(c2[i]), b); _mm_store_si128((__m128i *)&(c2[i]), b);
} }
for (; i < len; ++i) { for (; i < len; ++i) {
OPJ_INT32 y = c0[i]; OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i]; OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i]; OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2); OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g; OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g; OPJ_INT32 b = u + g;
c0[i] = r; c0[i] = r;
c1[i] = g; c1[i] = g;
c2[i] = b; c2[i] = b;
} }
} }
#else #else
void opj_mct_decode( void opj_mct_decode(
OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* restrict c0,
OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* restrict c1,
OPJ_INT32* OPJ_RESTRICT c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_UINT32 i; OPJ_UINT32 i;
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
OPJ_INT32 y = c0[i]; OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i]; OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i]; OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2); OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g; OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g; OPJ_INT32 b = u + g;
c0[i] = r; c0[i] = r;
c1[i] = g; c1[i] = g;
c2[i] = b; c2[i] = b;
} }
} }
#endif #endif
/* <summary> */ /* <summary> */
/* Get norm of basis function of reversible MCT. */ /* Get norm of basis function of reversible MCT. */
/* </summary> */ /* </summary> */
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) { OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno)
return opj_mct_norms[compno]; {
return opj_mct_norms[compno];
} }
/* <summary> */ /* <summary> */
@@ -210,164 +211,164 @@ OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
/* </summary> */ /* </summary> */
#ifdef __SSE4_1__ #ifdef __SSE4_1__
void opj_mct_encode_real( void opj_mct_encode_real(
OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* restrict c0,
OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* restrict c1,
OPJ_INT32* OPJ_RESTRICT c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
const OPJ_SIZE_T len = n; const OPJ_SIZE_T len = n;
const __m128i ry = _mm_set1_epi32(2449); const __m128i ry = _mm_set1_epi32(2449);
const __m128i gy = _mm_set1_epi32(4809); const __m128i gy = _mm_set1_epi32(4809);
const __m128i by = _mm_set1_epi32(934); const __m128i by = _mm_set1_epi32(934);
const __m128i ru = _mm_set1_epi32(1382); const __m128i ru = _mm_set1_epi32(1382);
const __m128i gu = _mm_set1_epi32(2714); const __m128i gu = _mm_set1_epi32(2714);
/* const __m128i bu = _mm_set1_epi32(4096); */ /* const __m128i bu = _mm_set1_epi32(4096); */
/* const __m128i rv = _mm_set1_epi32(4096); */ /* const __m128i rv = _mm_set1_epi32(4096); */
const __m128i gv = _mm_set1_epi32(3430); const __m128i gv = _mm_set1_epi32(3430);
const __m128i bv = _mm_set1_epi32(666); const __m128i bv = _mm_set1_epi32(666);
const __m128i mulround = _mm_shuffle_epi32(_mm_cvtsi32_si128(4096), _MM_SHUFFLE(1, 0, 1, 0)); const __m128i mulround = _mm_shuffle_epi32(_mm_cvtsi32_si128(4096), _MM_SHUFFLE(1, 0, 1, 0));
for(i = 0; i < (len & ~3U); i += 4) { for(i = 0; i < (len & ~3U); i += 4) {
__m128i lo, hi; __m128i lo, hi;
__m128i y, u, v; __m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i])); __m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i])); __m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i])); __m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
lo = r; lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ry); lo = _mm_mul_epi32(lo, ry);
hi = _mm_mul_epi32(hi, ry); hi = _mm_mul_epi32(hi, ry);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
y = _mm_blend_epi16(lo, hi, 0xCC); y = _mm_blend_epi16(lo, hi, 0xCC);
lo = g; lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gy); lo = _mm_mul_epi32(lo, gy);
hi = _mm_mul_epi32(hi, gy); hi = _mm_mul_epi32(hi, gy);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC)); y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
lo = b; lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, by); lo = _mm_mul_epi32(lo, by);
hi = _mm_mul_epi32(hi, by); hi = _mm_mul_epi32(hi, by);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC)); y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c0[i]), y); _mm_store_si128((__m128i *)&(c0[i]), y);
/*lo = b; /*lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround); lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/ hi = _mm_mul_epi32(hi, mulround);*/
lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 2, 0))); lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 2, 0)));
hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 3, 1))); hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 3, 1)));
lo = _mm_slli_epi64(lo, 12); lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12); hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
u = _mm_blend_epi16(lo, hi, 0xCC); u = _mm_blend_epi16(lo, hi, 0xCC);
lo = r; lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ru); lo = _mm_mul_epi32(lo, ru);
hi = _mm_mul_epi32(hi, ru); hi = _mm_mul_epi32(hi, ru);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC)); u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
lo = g; lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gu); lo = _mm_mul_epi32(lo, gu);
hi = _mm_mul_epi32(hi, gu); hi = _mm_mul_epi32(hi, gu);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC)); u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c1[i]), u); _mm_store_si128((__m128i *)&(c1[i]), u);
/*lo = r; /*lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround); lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/ hi = _mm_mul_epi32(hi, mulround);*/
lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 2, 0))); lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 2, 0)));
hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 3, 1))); hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 3, 1)));
lo = _mm_slli_epi64(lo, 12); lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12); hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
v = _mm_blend_epi16(lo, hi, 0xCC); v = _mm_blend_epi16(lo, hi, 0xCC);
lo = g; lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gv); lo = _mm_mul_epi32(lo, gv);
hi = _mm_mul_epi32(hi, gv); hi = _mm_mul_epi32(hi, gv);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC)); v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
lo = b; lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, bv); lo = _mm_mul_epi32(lo, bv);
hi = _mm_mul_epi32(hi, bv); hi = _mm_mul_epi32(hi, bv);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC)); v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c2[i]), v); _mm_store_si128((__m128i *)&(c2[i]), v);
} }
for(; i < len; ++i) { for(; i < len; ++i) {
OPJ_INT32 r = c0[i]; OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i]; OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i]; OPJ_INT32 b = c2[i];
OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934); OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934);
OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096); OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096);
OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666); OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666);
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
} }
} }
#else #else
void opj_mct_encode_real( void opj_mct_encode_real(
OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* restrict c0,
OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* restrict c1,
OPJ_INT32* OPJ_RESTRICT c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_UINT32 i; OPJ_UINT32 i;
for(i = 0; i < n; ++i) { for(i = 0; i < n; ++i) {
OPJ_INT32 r = c0[i]; OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i]; OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i]; OPJ_INT32 b = c2[i];
OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934); OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934);
OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096); OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096);
OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666); OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666);
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
} }
} }
#endif #endif
@@ -375,183 +376,184 @@ void opj_mct_encode_real(
/* Inverse irreversible MCT. */ /* Inverse irreversible MCT. */
/* </summary> */ /* </summary> */
void opj_mct_decode_real( void opj_mct_decode_real(
OPJ_FLOAT32* OPJ_RESTRICT c0, OPJ_FLOAT32* restrict c0,
OPJ_FLOAT32* OPJ_RESTRICT c1, OPJ_FLOAT32* restrict c1,
OPJ_FLOAT32* OPJ_RESTRICT c2, OPJ_FLOAT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_UINT32 i; OPJ_UINT32 i;
#ifdef __SSE__ #ifdef __SSE__
__m128 vrv, vgu, vgv, vbu; __m128 vrv, vgu, vgv, vbu;
vrv = _mm_set1_ps(1.402f); vrv = _mm_set1_ps(1.402f);
vgu = _mm_set1_ps(0.34413f); vgu = _mm_set1_ps(0.34413f);
vgv = _mm_set1_ps(0.71414f); vgv = _mm_set1_ps(0.71414f);
vbu = _mm_set1_ps(1.772f); vbu = _mm_set1_ps(1.772f);
for (i = 0; i < (n >> 3); ++i) { for (i = 0; i < (n >> 3); ++i) {
__m128 vy, vu, vv; __m128 vy, vu, vv;
__m128 vr, vg, vb; __m128 vr, vg, vb;
vy = _mm_load_ps(c0); vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1); vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2); vv = _mm_load_ps(c2);
vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv)); vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv)); vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu)); vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr); _mm_store_ps(c0, vr);
_mm_store_ps(c1, vg); _mm_store_ps(c1, vg);
_mm_store_ps(c2, vb); _mm_store_ps(c2, vb);
c0 += 4; c0 += 4;
c1 += 4; c1 += 4;
c2 += 4; c2 += 4;
vy = _mm_load_ps(c0); vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1); vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2); vv = _mm_load_ps(c2);
vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv)); vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv)); vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu)); vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr); _mm_store_ps(c0, vr);
_mm_store_ps(c1, vg); _mm_store_ps(c1, vg);
_mm_store_ps(c2, vb); _mm_store_ps(c2, vb);
c0 += 4; c0 += 4;
c1 += 4; c1 += 4;
c2 += 4; c2 += 4;
} }
n &= 7; n &= 7;
#endif #endif
for(i = 0; i < n; ++i) { for(i = 0; i < n; ++i) {
OPJ_FLOAT32 y = c0[i]; OPJ_FLOAT32 y = c0[i];
OPJ_FLOAT32 u = c1[i]; OPJ_FLOAT32 u = c1[i];
OPJ_FLOAT32 v = c2[i]; OPJ_FLOAT32 v = c2[i];
OPJ_FLOAT32 r = y + (v * 1.402f); OPJ_FLOAT32 r = y + (v * 1.402f);
OPJ_FLOAT32 g = y - (u * 0.34413f) - (v * (0.71414f)); OPJ_FLOAT32 g = y - (u * 0.34413f) - (v * (0.71414f));
OPJ_FLOAT32 b = y + (u * 1.772f); OPJ_FLOAT32 b = y + (u * 1.772f);
c0[i] = r; c0[i] = r;
c1[i] = g; c1[i] = g;
c2[i] = b; c2[i] = b;
} }
} }
/* <summary> */ /* <summary> */
/* Get norm of basis function of irreversible MCT. */ /* Get norm of basis function of irreversible MCT. */
/* </summary> */ /* </summary> */
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) { OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno)
return opj_mct_norms_real[compno]; {
return opj_mct_norms_real[compno];
} }
OPJ_BOOL opj_mct_encode_custom( OPJ_BOOL opj_mct_encode_custom(
OPJ_BYTE * pCodingdata, OPJ_BYTE * pCodingdata,
OPJ_UINT32 n, OPJ_UINT32 n,
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned) OPJ_UINT32 isSigned)
{ {
OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata; OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata;
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_UINT32 j; OPJ_UINT32 j;
OPJ_UINT32 k; OPJ_UINT32 k;
OPJ_UINT32 lNbMatCoeff = pNbComp * pNbComp; OPJ_UINT32 lNbMatCoeff = pNbComp * pNbComp;
OPJ_INT32 * lCurrentData = 00; OPJ_INT32 * lCurrentData = 00;
OPJ_INT32 * lCurrentMatrix = 00; OPJ_INT32 * lCurrentMatrix = 00;
OPJ_INT32 ** lData = (OPJ_INT32 **) pData; OPJ_INT32 ** lData = (OPJ_INT32 **) pData;
OPJ_UINT32 lMultiplicator = 1 << 13; OPJ_UINT32 lMultiplicator = 1 << 13;
OPJ_INT32 * lMctPtr; OPJ_INT32 * lMctPtr;
OPJ_ARG_NOT_USED(isSigned); OPJ_ARG_NOT_USED(isSigned);
lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32)); lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32));
if (! lCurrentData) { if (! lCurrentData) {
return OPJ_FALSE; return OPJ_FALSE;
} }
lCurrentMatrix = lCurrentData + pNbComp; lCurrentMatrix = lCurrentData + pNbComp;
for (i =0;i<lNbMatCoeff;++i) { for (i =0; i<lNbMatCoeff; ++i) {
lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator); lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator);
} }
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
lMctPtr = lCurrentMatrix; lMctPtr = lCurrentMatrix;
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentData[j] = (*(lData[j])); lCurrentData[j] = (*(lData[j]));
} }
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
*(lData[j]) = 0; *(lData[j]) = 0;
for (k=0;k<pNbComp;++k) { for (k=0; k<pNbComp; ++k) {
*(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]); *(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]);
++lMctPtr; ++lMctPtr;
} }
++lData[j]; ++lData[j];
} }
} }
opj_free(lCurrentData); opj_free(lCurrentData);
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_BOOL opj_mct_decode_custom( OPJ_BOOL opj_mct_decode_custom(
OPJ_BYTE * pDecodingData, OPJ_BYTE * pDecodingData,
OPJ_UINT32 n, OPJ_UINT32 n,
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned) OPJ_UINT32 isSigned)
{ {
OPJ_FLOAT32 * lMct; OPJ_FLOAT32 * lMct;
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_UINT32 j; OPJ_UINT32 j;
OPJ_UINT32 k; OPJ_UINT32 k;
OPJ_FLOAT32 * lCurrentData = 00; OPJ_FLOAT32 * lCurrentData = 00;
OPJ_FLOAT32 * lCurrentResult = 00; OPJ_FLOAT32 * lCurrentResult = 00;
OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData; OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData;
OPJ_ARG_NOT_USED(isSigned); OPJ_ARG_NOT_USED(isSigned);
lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32)); lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
if (! lCurrentData) { if (! lCurrentData) {
return OPJ_FALSE; return OPJ_FALSE;
} }
lCurrentResult = lCurrentData + pNbComp; lCurrentResult = lCurrentData + pNbComp;
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
lMct = (OPJ_FLOAT32 *) pDecodingData; lMct = (OPJ_FLOAT32 *) pDecodingData;
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j])); lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
} }
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentResult[j] = 0; lCurrentResult[j] = 0;
for (k=0;k<pNbComp;++k) { for (k=0; k<pNbComp; ++k) {
lCurrentResult[j] += *(lMct++) * lCurrentData[k]; lCurrentResult[j] += *(lMct++) * lCurrentData[k];
} }
*(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]); *(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]);
} }
} }
opj_free(lCurrentData); opj_free(lCurrentData);
return OPJ_TRUE; return OPJ_TRUE;
} }
void opj_calculate_norms( OPJ_FLOAT64 * pNorms, void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_UINT32 pNbComps, OPJ_UINT32 pNbComps,
OPJ_FLOAT32 * pMatrix) OPJ_FLOAT32 * pMatrix)
{ {
OPJ_UINT32 i,j,lIndex; OPJ_UINT32 i,j,lIndex;
OPJ_FLOAT32 lCurrentValue; OPJ_FLOAT32 lCurrentValue;
OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms; OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms;
OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix; OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix;
for (i=0;i<pNbComps;++i) { for (i=0; i<pNbComps; ++i) {
lNorms[i] = 0; lNorms[i] = 0;
lIndex = i; lIndex = i;
for (j=0;j<pNbComps;++j) { for (j=0; j<pNbComps; ++j) {
lCurrentValue = lMatrix[lIndex]; lCurrentValue = lMatrix[lIndex];
lIndex += pNbComps; lIndex += pNbComps;
lNorms[i] += lCurrentValue * lCurrentValue; lNorms[i] += lCurrentValue * lCurrentValue;
} }
lNorms[i] = sqrt(lNorms[i]); lNorms[i] = sqrt(lNorms[i]);
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -60,7 +60,7 @@ Apply a reversible multi-component transform to an image
@param c2 Samples blue component @param c2 Samples blue component
@param n Number of samples for each component @param n Number of samples for each component
*/ */
void opj_mct_encode(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* OPJ_RESTRICT c2, OPJ_UINT32 n); void opj_mct_encode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
/** /**
Apply a reversible multi-component inverse transform to an image Apply a reversible multi-component inverse transform to an image
@param c0 Samples for luminance component @param c0 Samples for luminance component
@@ -68,11 +68,11 @@ Apply a reversible multi-component inverse transform to an image
@param c2 Samples for blue chrominance component @param c2 Samples for blue chrominance component
@param n Number of samples for each component @param n Number of samples for each component
*/ */
void opj_mct_decode(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* OPJ_RESTRICT c2, OPJ_UINT32 n); void opj_mct_decode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
/** /**
Get norm of the basis function used for the reversible multi-component transform Get norm of the basis function used for the reversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V) @param compno Number of the component (0->Y, 1->U, 2->V)
@return @return
*/ */
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno); OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno);
@@ -83,7 +83,7 @@ Apply an irreversible multi-component transform to an image
@param c2 Samples blue component @param c2 Samples blue component
@param n Number of samples for each component @param n Number of samples for each component
*/ */
void opj_mct_encode_real(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* OPJ_RESTRICT c2, OPJ_UINT32 n); void opj_mct_encode_real(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
/** /**
Apply an irreversible multi-component inverse transform to an image Apply an irreversible multi-component inverse transform to an image
@param c0 Samples for luminance component @param c0 Samples for luminance component
@@ -91,11 +91,11 @@ Apply an irreversible multi-component inverse transform to an image
@param c2 Samples for blue chrominance component @param c2 Samples for blue chrominance component
@param n Number of samples for each component @param n Number of samples for each component
*/ */
void opj_mct_decode_real(OPJ_FLOAT32* OPJ_RESTRICT c0, OPJ_FLOAT32* OPJ_RESTRICT c1, OPJ_FLOAT32* OPJ_RESTRICT c2, OPJ_UINT32 n); void opj_mct_decode_real(OPJ_FLOAT32* c0, OPJ_FLOAT32* c1, OPJ_FLOAT32* c2, OPJ_UINT32 n);
/** /**
Get norm of the basis function used for the irreversible multi-component transform Get norm of the basis function used for the irreversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V) @param compno Number of the component (0->Y, 1->U, 2->V)
@return @return
*/ */
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno); OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno);
@@ -109,11 +109,11 @@ FIXME DOC
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise @return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
*/ */
OPJ_BOOL opj_mct_encode_custom( OPJ_BOOL opj_mct_encode_custom(
OPJ_BYTE * p_coding_data, OPJ_BYTE * p_coding_data,
OPJ_UINT32 n, OPJ_UINT32 n,
OPJ_BYTE ** p_data, OPJ_BYTE ** p_data,
OPJ_UINT32 p_nb_comp, OPJ_UINT32 p_nb_comp,
OPJ_UINT32 is_signed); OPJ_UINT32 is_signed);
/** /**
FIXME DOC FIXME DOC
@param pDecodingData MCT data @param pDecodingData MCT data
@@ -124,27 +124,27 @@ FIXME DOC
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise @return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
*/ */
OPJ_BOOL opj_mct_decode_custom( OPJ_BOOL opj_mct_decode_custom(
OPJ_BYTE * pDecodingData, OPJ_BYTE * pDecodingData,
OPJ_UINT32 n, OPJ_UINT32 n,
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned); OPJ_UINT32 isSigned);
/** /**
FIXME DOC FIXME DOC
@param pNorms MCT data @param pNorms MCT data
@param p_nb_comps size of components @param p_nb_comps size of components
@param pMatrix components @param pMatrix components
@return @return
*/ */
void opj_calculate_norms( OPJ_FLOAT64 * pNorms, void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_UINT32 p_nb_comps, OPJ_UINT32 p_nb_comps,
OPJ_FLOAT32 * pMatrix); OPJ_FLOAT32 * pMatrix);
/** /**
FIXME DOC FIXME DOC
*/ */
const OPJ_FLOAT64 * opj_mct_get_mct_norms (void); const OPJ_FLOAT64 * opj_mct_get_mct_norms (void);
/** /**
FIXME DOC FIXME DOC
*/ */
const OPJ_FLOAT64 * opj_mct_get_mct_norms_real (void); const OPJ_FLOAT64 * opj_mct_get_mct_norms_real (void);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr> * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
@@ -70,6 +70,28 @@ Fill mqc->c with 1's for flushing
@param mqc MQC handle @param mqc MQC handle
*/ */
static void opj_mqc_setbits(opj_mqc_t *mqc); static void opj_mqc_setbits(opj_mqc_t *mqc);
/**
FIXME DOC
@param mqc MQC handle
@return
*/
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc);
/**
FIXME DOC
@param mqc MQC handle
@return
*/
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc);
/**
Input a byte
@param mqc MQC handle
*/
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc);
/**
Renormalize mqc->a and mqc->c while decoding
@param mqc MQC handle
*/
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc);
/*@}*/ /*@}*/
/*@}*/ /*@}*/
@@ -78,369 +100,466 @@ static void opj_mqc_setbits(opj_mqc_t *mqc);
/* This array defines all the possible states for a context. */ /* This array defines all the possible states for a context. */
/* </summary> */ /* </summary> */
static opj_mqc_state_t mqc_states[47 * 2] = { static opj_mqc_state_t mqc_states[47 * 2] = {
{0x5601, 0, &mqc_states[2], &mqc_states[3]}, {0x5601, 0, &mqc_states[2], &mqc_states[3]},
{0x5601, 1, &mqc_states[3], &mqc_states[2]}, {0x5601, 1, &mqc_states[3], &mqc_states[2]},
{0x3401, 0, &mqc_states[4], &mqc_states[12]}, {0x3401, 0, &mqc_states[4], &mqc_states[12]},
{0x3401, 1, &mqc_states[5], &mqc_states[13]}, {0x3401, 1, &mqc_states[5], &mqc_states[13]},
{0x1801, 0, &mqc_states[6], &mqc_states[18]}, {0x1801, 0, &mqc_states[6], &mqc_states[18]},
{0x1801, 1, &mqc_states[7], &mqc_states[19]}, {0x1801, 1, &mqc_states[7], &mqc_states[19]},
{0x0ac1, 0, &mqc_states[8], &mqc_states[24]}, {0x0ac1, 0, &mqc_states[8], &mqc_states[24]},
{0x0ac1, 1, &mqc_states[9], &mqc_states[25]}, {0x0ac1, 1, &mqc_states[9], &mqc_states[25]},
{0x0521, 0, &mqc_states[10], &mqc_states[58]}, {0x0521, 0, &mqc_states[10], &mqc_states[58]},
{0x0521, 1, &mqc_states[11], &mqc_states[59]}, {0x0521, 1, &mqc_states[11], &mqc_states[59]},
{0x0221, 0, &mqc_states[76], &mqc_states[66]}, {0x0221, 0, &mqc_states[76], &mqc_states[66]},
{0x0221, 1, &mqc_states[77], &mqc_states[67]}, {0x0221, 1, &mqc_states[77], &mqc_states[67]},
{0x5601, 0, &mqc_states[14], &mqc_states[13]}, {0x5601, 0, &mqc_states[14], &mqc_states[13]},
{0x5601, 1, &mqc_states[15], &mqc_states[12]}, {0x5601, 1, &mqc_states[15], &mqc_states[12]},
{0x5401, 0, &mqc_states[16], &mqc_states[28]}, {0x5401, 0, &mqc_states[16], &mqc_states[28]},
{0x5401, 1, &mqc_states[17], &mqc_states[29]}, {0x5401, 1, &mqc_states[17], &mqc_states[29]},
{0x4801, 0, &mqc_states[18], &mqc_states[28]}, {0x4801, 0, &mqc_states[18], &mqc_states[28]},
{0x4801, 1, &mqc_states[19], &mqc_states[29]}, {0x4801, 1, &mqc_states[19], &mqc_states[29]},
{0x3801, 0, &mqc_states[20], &mqc_states[28]}, {0x3801, 0, &mqc_states[20], &mqc_states[28]},
{0x3801, 1, &mqc_states[21], &mqc_states[29]}, {0x3801, 1, &mqc_states[21], &mqc_states[29]},
{0x3001, 0, &mqc_states[22], &mqc_states[34]}, {0x3001, 0, &mqc_states[22], &mqc_states[34]},
{0x3001, 1, &mqc_states[23], &mqc_states[35]}, {0x3001, 1, &mqc_states[23], &mqc_states[35]},
{0x2401, 0, &mqc_states[24], &mqc_states[36]}, {0x2401, 0, &mqc_states[24], &mqc_states[36]},
{0x2401, 1, &mqc_states[25], &mqc_states[37]}, {0x2401, 1, &mqc_states[25], &mqc_states[37]},
{0x1c01, 0, &mqc_states[26], &mqc_states[40]}, {0x1c01, 0, &mqc_states[26], &mqc_states[40]},
{0x1c01, 1, &mqc_states[27], &mqc_states[41]}, {0x1c01, 1, &mqc_states[27], &mqc_states[41]},
{0x1601, 0, &mqc_states[58], &mqc_states[42]}, {0x1601, 0, &mqc_states[58], &mqc_states[42]},
{0x1601, 1, &mqc_states[59], &mqc_states[43]}, {0x1601, 1, &mqc_states[59], &mqc_states[43]},
{0x5601, 0, &mqc_states[30], &mqc_states[29]}, {0x5601, 0, &mqc_states[30], &mqc_states[29]},
{0x5601, 1, &mqc_states[31], &mqc_states[28]}, {0x5601, 1, &mqc_states[31], &mqc_states[28]},
{0x5401, 0, &mqc_states[32], &mqc_states[28]}, {0x5401, 0, &mqc_states[32], &mqc_states[28]},
{0x5401, 1, &mqc_states[33], &mqc_states[29]}, {0x5401, 1, &mqc_states[33], &mqc_states[29]},
{0x5101, 0, &mqc_states[34], &mqc_states[30]}, {0x5101, 0, &mqc_states[34], &mqc_states[30]},
{0x5101, 1, &mqc_states[35], &mqc_states[31]}, {0x5101, 1, &mqc_states[35], &mqc_states[31]},
{0x4801, 0, &mqc_states[36], &mqc_states[32]}, {0x4801, 0, &mqc_states[36], &mqc_states[32]},
{0x4801, 1, &mqc_states[37], &mqc_states[33]}, {0x4801, 1, &mqc_states[37], &mqc_states[33]},
{0x3801, 0, &mqc_states[38], &mqc_states[34]}, {0x3801, 0, &mqc_states[38], &mqc_states[34]},
{0x3801, 1, &mqc_states[39], &mqc_states[35]}, {0x3801, 1, &mqc_states[39], &mqc_states[35]},
{0x3401, 0, &mqc_states[40], &mqc_states[36]}, {0x3401, 0, &mqc_states[40], &mqc_states[36]},
{0x3401, 1, &mqc_states[41], &mqc_states[37]}, {0x3401, 1, &mqc_states[41], &mqc_states[37]},
{0x3001, 0, &mqc_states[42], &mqc_states[38]}, {0x3001, 0, &mqc_states[42], &mqc_states[38]},
{0x3001, 1, &mqc_states[43], &mqc_states[39]}, {0x3001, 1, &mqc_states[43], &mqc_states[39]},
{0x2801, 0, &mqc_states[44], &mqc_states[38]}, {0x2801, 0, &mqc_states[44], &mqc_states[38]},
{0x2801, 1, &mqc_states[45], &mqc_states[39]}, {0x2801, 1, &mqc_states[45], &mqc_states[39]},
{0x2401, 0, &mqc_states[46], &mqc_states[40]}, {0x2401, 0, &mqc_states[46], &mqc_states[40]},
{0x2401, 1, &mqc_states[47], &mqc_states[41]}, {0x2401, 1, &mqc_states[47], &mqc_states[41]},
{0x2201, 0, &mqc_states[48], &mqc_states[42]}, {0x2201, 0, &mqc_states[48], &mqc_states[42]},
{0x2201, 1, &mqc_states[49], &mqc_states[43]}, {0x2201, 1, &mqc_states[49], &mqc_states[43]},
{0x1c01, 0, &mqc_states[50], &mqc_states[44]}, {0x1c01, 0, &mqc_states[50], &mqc_states[44]},
{0x1c01, 1, &mqc_states[51], &mqc_states[45]}, {0x1c01, 1, &mqc_states[51], &mqc_states[45]},
{0x1801, 0, &mqc_states[52], &mqc_states[46]}, {0x1801, 0, &mqc_states[52], &mqc_states[46]},
{0x1801, 1, &mqc_states[53], &mqc_states[47]}, {0x1801, 1, &mqc_states[53], &mqc_states[47]},
{0x1601, 0, &mqc_states[54], &mqc_states[48]}, {0x1601, 0, &mqc_states[54], &mqc_states[48]},
{0x1601, 1, &mqc_states[55], &mqc_states[49]}, {0x1601, 1, &mqc_states[55], &mqc_states[49]},
{0x1401, 0, &mqc_states[56], &mqc_states[50]}, {0x1401, 0, &mqc_states[56], &mqc_states[50]},
{0x1401, 1, &mqc_states[57], &mqc_states[51]}, {0x1401, 1, &mqc_states[57], &mqc_states[51]},
{0x1201, 0, &mqc_states[58], &mqc_states[52]}, {0x1201, 0, &mqc_states[58], &mqc_states[52]},
{0x1201, 1, &mqc_states[59], &mqc_states[53]}, {0x1201, 1, &mqc_states[59], &mqc_states[53]},
{0x1101, 0, &mqc_states[60], &mqc_states[54]}, {0x1101, 0, &mqc_states[60], &mqc_states[54]},
{0x1101, 1, &mqc_states[61], &mqc_states[55]}, {0x1101, 1, &mqc_states[61], &mqc_states[55]},
{0x0ac1, 0, &mqc_states[62], &mqc_states[56]}, {0x0ac1, 0, &mqc_states[62], &mqc_states[56]},
{0x0ac1, 1, &mqc_states[63], &mqc_states[57]}, {0x0ac1, 1, &mqc_states[63], &mqc_states[57]},
{0x09c1, 0, &mqc_states[64], &mqc_states[58]}, {0x09c1, 0, &mqc_states[64], &mqc_states[58]},
{0x09c1, 1, &mqc_states[65], &mqc_states[59]}, {0x09c1, 1, &mqc_states[65], &mqc_states[59]},
{0x08a1, 0, &mqc_states[66], &mqc_states[60]}, {0x08a1, 0, &mqc_states[66], &mqc_states[60]},
{0x08a1, 1, &mqc_states[67], &mqc_states[61]}, {0x08a1, 1, &mqc_states[67], &mqc_states[61]},
{0x0521, 0, &mqc_states[68], &mqc_states[62]}, {0x0521, 0, &mqc_states[68], &mqc_states[62]},
{0x0521, 1, &mqc_states[69], &mqc_states[63]}, {0x0521, 1, &mqc_states[69], &mqc_states[63]},
{0x0441, 0, &mqc_states[70], &mqc_states[64]}, {0x0441, 0, &mqc_states[70], &mqc_states[64]},
{0x0441, 1, &mqc_states[71], &mqc_states[65]}, {0x0441, 1, &mqc_states[71], &mqc_states[65]},
{0x02a1, 0, &mqc_states[72], &mqc_states[66]}, {0x02a1, 0, &mqc_states[72], &mqc_states[66]},
{0x02a1, 1, &mqc_states[73], &mqc_states[67]}, {0x02a1, 1, &mqc_states[73], &mqc_states[67]},
{0x0221, 0, &mqc_states[74], &mqc_states[68]}, {0x0221, 0, &mqc_states[74], &mqc_states[68]},
{0x0221, 1, &mqc_states[75], &mqc_states[69]}, {0x0221, 1, &mqc_states[75], &mqc_states[69]},
{0x0141, 0, &mqc_states[76], &mqc_states[70]}, {0x0141, 0, &mqc_states[76], &mqc_states[70]},
{0x0141, 1, &mqc_states[77], &mqc_states[71]}, {0x0141, 1, &mqc_states[77], &mqc_states[71]},
{0x0111, 0, &mqc_states[78], &mqc_states[72]}, {0x0111, 0, &mqc_states[78], &mqc_states[72]},
{0x0111, 1, &mqc_states[79], &mqc_states[73]}, {0x0111, 1, &mqc_states[79], &mqc_states[73]},
{0x0085, 0, &mqc_states[80], &mqc_states[74]}, {0x0085, 0, &mqc_states[80], &mqc_states[74]},
{0x0085, 1, &mqc_states[81], &mqc_states[75]}, {0x0085, 1, &mqc_states[81], &mqc_states[75]},
{0x0049, 0, &mqc_states[82], &mqc_states[76]}, {0x0049, 0, &mqc_states[82], &mqc_states[76]},
{0x0049, 1, &mqc_states[83], &mqc_states[77]}, {0x0049, 1, &mqc_states[83], &mqc_states[77]},
{0x0025, 0, &mqc_states[84], &mqc_states[78]}, {0x0025, 0, &mqc_states[84], &mqc_states[78]},
{0x0025, 1, &mqc_states[85], &mqc_states[79]}, {0x0025, 1, &mqc_states[85], &mqc_states[79]},
{0x0015, 0, &mqc_states[86], &mqc_states[80]}, {0x0015, 0, &mqc_states[86], &mqc_states[80]},
{0x0015, 1, &mqc_states[87], &mqc_states[81]}, {0x0015, 1, &mqc_states[87], &mqc_states[81]},
{0x0009, 0, &mqc_states[88], &mqc_states[82]}, {0x0009, 0, &mqc_states[88], &mqc_states[82]},
{0x0009, 1, &mqc_states[89], &mqc_states[83]}, {0x0009, 1, &mqc_states[89], &mqc_states[83]},
{0x0005, 0, &mqc_states[90], &mqc_states[84]}, {0x0005, 0, &mqc_states[90], &mqc_states[84]},
{0x0005, 1, &mqc_states[91], &mqc_states[85]}, {0x0005, 1, &mqc_states[91], &mqc_states[85]},
{0x0001, 0, &mqc_states[90], &mqc_states[86]}, {0x0001, 0, &mqc_states[90], &mqc_states[86]},
{0x0001, 1, &mqc_states[91], &mqc_states[87]}, {0x0001, 1, &mqc_states[91], &mqc_states[87]},
{0x5601, 0, &mqc_states[92], &mqc_states[92]}, {0x5601, 0, &mqc_states[92], &mqc_states[92]},
{0x5601, 1, &mqc_states[93], &mqc_states[93]}, {0x5601, 1, &mqc_states[93], &mqc_states[93]},
}; };
/* /*
========================================================== ==========================================================
local functions local functions
========================================================== ==========================================================
*/ */
static void opj_mqc_byteout(opj_mqc_t *mqc) { static void opj_mqc_byteout(opj_mqc_t *mqc)
/* avoid accessing uninitialized memory*/ {
if (mqc->bp == mqc->start-1) { if (*mqc->bp == 0xff) {
mqc->bp++; mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19); *mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0x7ffff; mqc->c &= 0xfffff;
mqc->ct = 8; mqc->ct = 7;
} } else {
else if (*mqc->bp == 0xff) { if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */
mqc->bp++; mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20); *mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0xfffff; mqc->c &= 0x7ffff;
mqc->ct = 7; mqc->ct = 8;
} else { } else {
if ((mqc->c & 0x8000000) == 0) { (*mqc->bp)++;
mqc->bp++; if (*mqc->bp == 0xff) {
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19); mqc->c &= 0x7ffffff;
mqc->c &= 0x7ffff; mqc->bp++;
mqc->ct = 8; *mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
} else { mqc->c &= 0xfffff;
(*mqc->bp)++; mqc->ct = 7;
if (*mqc->bp == 0xff) { } else {
mqc->c &= 0x7ffffff; mqc->bp++;
mqc->bp++; *mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20); mqc->c &= 0x7ffff;
mqc->c &= 0xfffff; mqc->ct = 8;
mqc->ct = 7; }
} else { }
mqc->bp++; }
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
}
}
}
} }
static void opj_mqc_renorme(opj_mqc_t *mqc) { static void opj_mqc_renorme(opj_mqc_t *mqc)
do { {
mqc->a <<= 1; do {
mqc->c <<= 1; mqc->a <<= 1;
mqc->ct--; mqc->c <<= 1;
if (mqc->ct == 0) { mqc->ct--;
opj_mqc_byteout(mqc); if (mqc->ct == 0) {
} opj_mqc_byteout(mqc);
} while ((mqc->a & 0x8000) == 0); }
} while ((mqc->a & 0x8000) == 0);
} }
static void opj_mqc_codemps(opj_mqc_t *mqc) { static void opj_mqc_codemps(opj_mqc_t *mqc)
mqc->a -= (*mqc->curctx)->qeval; {
if ((mqc->a & 0x8000) == 0) { mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) { if ((mqc->a & 0x8000) == 0) {
mqc->a = (*mqc->curctx)->qeval; if (mqc->a < (*mqc->curctx)->qeval) {
} else { mqc->a = (*mqc->curctx)->qeval;
mqc->c += (*mqc->curctx)->qeval; } else {
} mqc->c += (*mqc->curctx)->qeval;
*mqc->curctx = (*mqc->curctx)->nmps; }
opj_mqc_renorme(mqc); *mqc->curctx = (*mqc->curctx)->nmps;
} else { opj_mqc_renorme(mqc);
mqc->c += (*mqc->curctx)->qeval; } else {
} mqc->c += (*mqc->curctx)->qeval;
}
} }
static void opj_mqc_codelps(opj_mqc_t *mqc) { static void opj_mqc_codelps(opj_mqc_t *mqc)
mqc->a -= (*mqc->curctx)->qeval; {
if (mqc->a < (*mqc->curctx)->qeval) { mqc->a -= (*mqc->curctx)->qeval;
mqc->c += (*mqc->curctx)->qeval; if (mqc->a < (*mqc->curctx)->qeval) {
} else { mqc->c += (*mqc->curctx)->qeval;
mqc->a = (*mqc->curctx)->qeval; } else {
} mqc->a = (*mqc->curctx)->qeval;
*mqc->curctx = (*mqc->curctx)->nlps; }
opj_mqc_renorme(mqc); *mqc->curctx = (*mqc->curctx)->nlps;
opj_mqc_renorme(mqc);
} }
static void opj_mqc_setbits(opj_mqc_t *mqc) { static void opj_mqc_setbits(opj_mqc_t *mqc)
OPJ_UINT32 tempc = mqc->c + mqc->a; {
mqc->c |= 0xffff; OPJ_UINT32 tempc = mqc->c + mqc->a;
if (mqc->c >= tempc) { mqc->c |= 0xffff;
mqc->c -= 0x8000; if (mqc->c >= tempc) {
} mqc->c -= 0x8000;
}
} }
/* static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc)
{
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
} else {
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
}
return d;
}
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc)
{
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
} else {
mqc->a = (*mqc->curctx)->qeval;
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
}
return d;
}
#ifdef MQC_PERF_OPT
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc)
{
unsigned int i = *((unsigned int *) mqc->bp);
mqc->c += i & 0xffff00;
mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04;
}
#else
static void opj_mqc_bytein(opj_mqc_t *const mqc)
{
if (mqc->bp != mqc->end) {
OPJ_UINT32 c;
if (mqc->bp + 1 != mqc->end) {
c = *(mqc->bp + 1);
} else {
c = 0xff;
}
if (*mqc->bp == 0xff) {
if (c > 0x8f) {
mqc->c += 0xff00;
mqc->ct = 8;
} else {
mqc->bp++;
mqc->c += c << 9;
mqc->ct = 7;
}
} else {
mqc->bp++;
mqc->c += c << 8;
mqc->ct = 8;
}
} else {
mqc->c += 0xff00;
mqc->ct = 8;
}
}
#endif
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc)
{
do {
if (mqc->ct == 0) {
opj_mqc_bytein(mqc);
}
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
} while (mqc->a < 0x8000);
}
/*
========================================================== ==========================================================
MQ-Coder interface MQ-Coder interface
========================================================== ==========================================================
*/ */
opj_mqc_t* opj_mqc_create(void) { opj_mqc_t* opj_mqc_create(void)
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); {
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
if (mqc) { if (mqc) {
mqc->buffer = NULL; mqc->buffer = NULL;
} }
#endif #endif
return mqc; return mqc;
} }
void opj_mqc_destroy(opj_mqc_t *mqc) { void opj_mqc_destroy(opj_mqc_t *mqc)
if(mqc) { {
if(mqc) {
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
if (mqc->buffer) { if (mqc->buffer) {
opj_free(mqc->buffer); opj_free(mqc->buffer);
} }
#endif #endif
opj_free(mqc); opj_free(mqc);
} }
} }
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc)
const ptrdiff_t diff = mqc->bp - mqc->start; {
const ptrdiff_t diff = mqc->bp - mqc->start;
#if 0 #if 0
assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */ assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
#endif #endif
return (OPJ_UINT32)diff; return (OPJ_UINT32)diff;
} }
void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) { void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp)
{
/* TODO MSD: need to take a look to the v2 version */ /* TODO MSD: need to take a look to the v2 version */
opj_mqc_setcurctx(mqc, 0); opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000; mqc->a = 0x8000;
mqc->c = 0; mqc->c = 0;
mqc->bp = bp - 1; mqc->bp = bp - 1;
mqc->ct = 12; mqc->ct = 12;
mqc->start = bp; if (*mqc->bp == 0xff) {
mqc->ct = 13;
}
mqc->start = bp;
} }
void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) { void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d)
if ((*mqc->curctx)->mps == d) { {
opj_mqc_codemps(mqc); if ((*mqc->curctx)->mps == d) {
} else { opj_mqc_codemps(mqc);
opj_mqc_codelps(mqc); } else {
} opj_mqc_codelps(mqc);
}
} }
void opj_mqc_flush(opj_mqc_t *mqc) { void opj_mqc_flush(opj_mqc_t *mqc)
opj_mqc_setbits(mqc); {
mqc->c <<= mqc->ct; opj_mqc_setbits(mqc);
opj_mqc_byteout(mqc); mqc->c <<= mqc->ct;
mqc->c <<= mqc->ct; opj_mqc_byteout(mqc);
opj_mqc_byteout(mqc); mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc);
if (*mqc->bp != 0xff) {
mqc->bp++; if (*mqc->bp != 0xff) {
} mqc->bp++;
}
} }
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) { void opj_mqc_bypass_init_enc(opj_mqc_t *mqc)
mqc->c = 0; {
mqc->ct = 8; mqc->c = 0;
/*if (*mqc->bp == 0xff) { mqc->ct = 8;
mqc->ct = 7; /*if (*mqc->bp == 0xff) {
mqc->ct = 7;
} */ } */
} }
void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) { void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d)
mqc->ct--; {
mqc->c = mqc->c + (d << mqc->ct); mqc->ct--;
if (mqc->ct == 0) { mqc->c = mqc->c + (d << mqc->ct);
mqc->bp++; if (mqc->ct == 0) {
*mqc->bp = (OPJ_BYTE)mqc->c; mqc->bp++;
mqc->ct = 8; *mqc->bp = (OPJ_BYTE)mqc->c;
if (*mqc->bp == 0xff) { mqc->ct = 8;
mqc->ct = 7; if (*mqc->bp == 0xff) {
} mqc->ct = 7;
mqc->c = 0; }
} mqc->c = 0;
}
} }
OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc)
OPJ_BYTE bit_padding; {
OPJ_BYTE bit_padding;
bit_padding = 0;
bit_padding = 0;
if (mqc->ct != 0) {
while (mqc->ct > 0) { if (mqc->ct != 0) {
mqc->ct--; while (mqc->ct > 0) {
mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct); mqc->ct--;
bit_padding = (bit_padding + 1) & 0x01; mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct);
} bit_padding = (bit_padding + 1) & 0x01;
mqc->bp++; }
*mqc->bp = (OPJ_BYTE)mqc->c; mqc->bp++;
mqc->ct = 8; *mqc->bp = (OPJ_BYTE)mqc->c;
mqc->c = 0; mqc->ct = 8;
} mqc->c = 0;
}
return 1;
return 1;
} }
void opj_mqc_reset_enc(opj_mqc_t *mqc) { void opj_mqc_reset_enc(opj_mqc_t *mqc)
opj_mqc_resetstates(mqc); {
opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); opj_mqc_resetstates(mqc);
opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
} }
OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc)
OPJ_UINT32 correction = 1; {
OPJ_UINT32 correction = 1;
/* <flush part> */
OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct); /* <flush part> */
mqc->c <<= mqc->ct; OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct);
while (n > 0) { mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc); while (n > 0) {
n -= (OPJ_INT32)mqc->ct; opj_mqc_byteout(mqc);
mqc->c <<= mqc->ct; n -= (OPJ_INT32)mqc->ct;
} mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc); }
opj_mqc_byteout(mqc);
return correction;
return correction;
} }
void opj_mqc_restart_init_enc(opj_mqc_t *mqc) { void opj_mqc_restart_init_enc(opj_mqc_t *mqc)
/* <Re-init part> */ {
opj_mqc_setcurctx(mqc, 0); /* <Re-init part> */
mqc->a = 0x8000; opj_mqc_setcurctx(mqc, 0);
mqc->c = 0; mqc->a = 0x8000;
mqc->ct = 12; mqc->c = 0;
mqc->bp--; mqc->ct = 12;
if (*mqc->bp == 0xff) { mqc->bp--;
mqc->ct = 13; if (*mqc->bp == 0xff) {
} mqc->ct = 13;
}
} }
void opj_mqc_erterm_enc(opj_mqc_t *mqc) { void opj_mqc_erterm_enc(opj_mqc_t *mqc)
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1); {
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1);
while (k > 0) {
mqc->c <<= mqc->ct; while (k > 0) {
mqc->ct = 0; mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc); mqc->ct = 0;
k -= (OPJ_INT32)mqc->ct; opj_mqc_byteout(mqc);
} k -= (OPJ_INT32)mqc->ct;
}
if (*mqc->bp != 0xff) {
opj_mqc_byteout(mqc); if (*mqc->bp != 0xff) {
} opj_mqc_byteout(mqc);
}
} }
void opj_mqc_segmark_enc(opj_mqc_t *mqc) { void opj_mqc_segmark_enc(opj_mqc_t *mqc)
OPJ_UINT32 i; {
opj_mqc_setcurctx(mqc, 18); OPJ_UINT32 i;
opj_mqc_setcurctx(mqc, 18);
for (i = 1; i < 5; i++) {
opj_mqc_encode(mqc, i % 2); for (i = 1; i < 5; i++) {
} opj_mqc_encode(mqc, i % 2);
}
} }
OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) { OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len)
opj_mqc_setcurctx(mqc, 0); {
mqc->start = bp; opj_mqc_setcurctx(mqc, 0);
mqc->end = bp + len; mqc->start = bp;
mqc->bp = bp; mqc->end = bp + len;
if (len==0) mqc->c = 0xff << 16; mqc->bp = bp;
else mqc->c = (OPJ_UINT32)(*mqc->bp << 16); if (len==0) mqc->c = 0xff << 16;
else mqc->c = (OPJ_UINT32)(*mqc->bp << 16);
#ifdef MQC_PERF_OPT /* TODO_MSD: check this option and put in experimental */ #ifdef MQC_PERF_OPT /* TODO_MSD: check this option and put in experimental */
{ {
OPJ_UINT32 c; OPJ_UINT32 c;
OPJ_UINT32 *ip; OPJ_UINT32 *ip;
OPJ_BYTE *end = mqc->end - 1; OPJ_BYTE *end = mqc->end - 1;
void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(OPJ_UINT32)); void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(OPJ_UINT32));
if (! new_buffer) { if (! new_buffer) {
opj_free(mqc->buffer); opj_free(mqc->buffer);
@@ -448,54 +567,76 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
return OPJ_FALSE; return OPJ_FALSE;
} }
mqc->buffer = new_buffer; mqc->buffer = new_buffer;
ip = (OPJ_UINT32 *) mqc->buffer; ip = (OPJ_UINT32 *) mqc->buffer;
while (bp < end) { while (bp < end) {
c = *(bp + 1); c = *(bp + 1);
if (*bp == 0xff) { if (*bp == 0xff) {
if (c > 0x8f) { if (c > 0x8f) {
break; break;
} else { } else {
*ip = 0x00000017 | (c << 9); *ip = 0x00000017 | (c << 9);
} }
} else { } else {
*ip = 0x00000018 | (c << 8); *ip = 0x00000018 | (c << 8);
} }
bp++; bp++;
ip++; ip++;
} }
/* Handle last byte of data */ /* Handle last byte of data */
c = 0xff; c = 0xff;
if (*bp == 0xff) { if (*bp == 0xff) {
*ip = 0x0000ff18; *ip = 0x0000ff18;
} else { } else {
bp++; bp++;
*ip = 0x00000018 | (c << 8); *ip = 0x00000018 | (c << 8);
} }
ip++; ip++;
*ip = 0x0000ff08; *ip = 0x0000ff08;
mqc->bp = mqc->buffer; mqc->bp = mqc->buffer;
} }
#endif #endif
opj_mqc_bytein(mqc); opj_mqc_bytein(mqc);
mqc->c <<= 7; mqc->c <<= 7;
mqc->ct -= 7; mqc->ct -= 7;
mqc->a = 0x8000; mqc->a = 0x8000;
return OPJ_TRUE; return OPJ_TRUE;
} }
void opj_mqc_resetstates(opj_mqc_t *mqc) { OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc)
OPJ_UINT32 i; {
for (i = 0; i < MQC_NUMCTXS; i++) { OPJ_INT32 d;
mqc->ctxs[i] = mqc_states; mqc->a -= (*mqc->curctx)->qeval;
} if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
d = opj_mqc_lpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
mqc->c -= (*mqc->curctx)->qeval << 16;
if ((mqc->a & 0x8000) == 0) {
d = opj_mqc_mpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
d = (OPJ_INT32)(*mqc->curctx)->mps;
}
}
return d;
} }
void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) { void opj_mqc_resetstates(opj_mqc_t *mqc)
mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)]; {
OPJ_UINT32 i;
for (i = 0; i < MQC_NUMCTXS; i++) {
mqc->ctxs[i] = mqc_states;
}
}
void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob)
{
mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)];
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * 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 * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * 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-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr> * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
@@ -53,14 +53,14 @@ in MQC.C are used by some function in T1.C.
This struct defines the state of a context. This struct defines the state of a context.
*/ */
typedef struct opj_mqc_state { typedef struct opj_mqc_state {
/** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */ /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
OPJ_UINT32 qeval; OPJ_UINT32 qeval;
/** the Most Probable Symbol (0 or 1) */ /** the Most Probable Symbol (0 or 1) */
OPJ_UINT32 mps; OPJ_UINT32 mps;
/** next state if the next encoded symbol is the MPS */ /** next state if the next encoded symbol is the MPS */
struct opj_mqc_state *nmps; struct opj_mqc_state *nmps;
/** next state if the next encoded symbol is the LPS */ /** next state if the next encoded symbol is the LPS */
struct opj_mqc_state *nlps; struct opj_mqc_state *nlps;
} opj_mqc_state_t; } opj_mqc_state_t;
#define MQC_NUMCTXS 19 #define MQC_NUMCTXS 19
@@ -69,27 +69,24 @@ typedef struct opj_mqc_state {
MQ coder MQ coder
*/ */
typedef struct opj_mqc { typedef struct opj_mqc {
OPJ_UINT32 c; OPJ_UINT32 c;
OPJ_UINT32 a; OPJ_UINT32 a;
OPJ_UINT32 ct; OPJ_UINT32 ct;
OPJ_BYTE *bp; OPJ_BYTE *bp;
OPJ_BYTE *start; OPJ_BYTE *start;
OPJ_BYTE *end; OPJ_BYTE *end;
opj_mqc_state_t *ctxs[MQC_NUMCTXS]; opj_mqc_state_t *ctxs[MQC_NUMCTXS];
opj_mqc_state_t **curctx; opj_mqc_state_t **curctx;
const OPJ_BYTE *lut_ctxno_zc_orient; /* lut_ctxno_zc shifted by 256 * bandno */
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
unsigned char *buffer; unsigned char *buffer;
#endif #endif
} opj_mqc_t; } opj_mqc_t;
#include "mqc_inl.h"
/** @name Exported functions */ /** @name Exported functions */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
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* opj_mqc_create(void); opj_mqc_t* opj_mqc_create(void);
@@ -105,7 +102,7 @@ Return the number of bytes written/read since initialisation
*/ */
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc); OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc);
/** /**
Reset the states of all the context of the coder/decoder Reset the states of all the context of the coder/decoder
(each context is set to a state where 0 and 1 are more or less equiprobable) (each context is set to a state where 0 and 1 are more or less equiprobable)
@param mqc MQC handle @param mqc MQC handle
*/ */
@@ -142,15 +139,15 @@ Flush the encoder, so that all remaining data is written
*/ */
void opj_mqc_flush(opj_mqc_t *mqc); void opj_mqc_flush(opj_mqc_t *mqc);
/** /**
BYPASS mode switch, initialization operation. BYPASS mode switch, initialization operation.
JPEG 2000 p 505. JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2> <h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle @param mqc MQC handle
*/ */
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc); void opj_mqc_bypass_init_enc(opj_mqc_t *mqc);
/** /**
BYPASS mode switch, coding operation. BYPASS mode switch, coding operation.
JPEG 2000 p 505. JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2> <h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle @param mqc MQC handle
@param d The symbol to be encoded (0 or 1) @param d The symbol to be encoded (0 or 1)
@@ -201,7 +198,7 @@ Decode a symbol
@param mqc MQC handle @param mqc MQC handle
@return Returns the decoded symbol (0 or 1) @return Returns the decoded symbol (0 or 1)
*/ */
static INLINE OPJ_INT32 opj_mqc_decode(opj_mqc_t * const mqc); OPJ_INT32 opj_mqc_decode(opj_mqc_t * const mqc);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@@ -1,159 +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
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@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.
*/
#ifndef __MQC_INL_H
#define __MQC_INL_H
/**
FIXME DOC
@param mqc MQC handle
@return
*/
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) {
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
} else {
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
}
return d;
}
/**
FIXME DOC
@param mqc MQC handle
@return
*/
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
} else {
mqc->a = (*mqc->curctx)->qeval;
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
}
return d;
}
/**
Input a byte
@param mqc MQC handle
*/
#ifdef MQC_PERF_OPT
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) {
unsigned int i = *((unsigned int *) mqc->bp);
mqc->c += i & 0xffff00;
mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04;
}
#else
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) {
if (mqc->bp != mqc->end) {
OPJ_UINT32 c;
if (mqc->bp + 1 != mqc->end) {
c = *(mqc->bp + 1);
} else {
c = 0xff;
}
if (*mqc->bp == 0xff) {
if (c > 0x8f) {
mqc->c += 0xff00;
mqc->ct = 8;
} else {
mqc->bp++;
mqc->c += c << 9;
mqc->ct = 7;
}
} else {
mqc->bp++;
mqc->c += c << 8;
mqc->ct = 8;
}
} else {
mqc->c += 0xff00;
mqc->ct = 8;
}
}
#endif
/**
Renormalize mqc->a and mqc->c while decoding
@param mqc MQC handle
*/
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
do {
if (mqc->ct == 0) {
opj_mqc_bytein(mqc);
}
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
} while (mqc->a < 0x8000);
}
/**
Decode a symbol
@param mqc MQC handle
@return Returns the decoded symbol (0 or 1)
*/
static INLINE OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) {
OPJ_INT32 d;
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
d = opj_mqc_lpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
mqc->c -= (*mqc->curctx)->qeval << 16;
if ((mqc->a & 0x8000) == 0) {
d = opj_mqc_mpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
d = (OPJ_INT32)(*mqc->curctx)->mps;
}
}
return d;
}
#endif /* __MQC_INL_H */

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