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:
- os: osx
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
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_NUM_THREADS=2
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
@@ -24,16 +21,6 @@ matrix:
- os: linux
compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_ASAN=1
- os: linux
compiler: clang-3.8
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
sources:
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
packages:
- clang-3.8
- os: linux
compiler: x86_64-w64-mingw32-gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
@@ -74,20 +61,3 @@ install:
script:
- ./tools/travis-ci/run.sh
- ./tools/travis-ci/abi-check.sh
before_deploy:
- export OPJ_RELEASE_PKG_FILE=$(ls build/openjpeg-${TRAVIS_TAG}*)
- echo "deploying $OPJ_RELEASE_PKG_FILE to GitHub releases"
deploy:
provider: releases
api_key:
secure: Npi13uOffALCVNwea4p4q8v85Lo/WsRqaeZQcWrAkt8MxRnfvWQtmnuwmHnVB6Cig+T1lVUHrklOaJIApIb6nkGq3CS/9bD8+SCS2NEdAAP/QYWnBi0ubWXVMRyDLypmwRpzLNSZ0xLYGFUl2PjieZYKRcz1dd/J7S+FnXhPtdjXweq0FS63zTcMe7ggjfmzSOWUCEFmMjZPaM0Be+3PweieCO1dxlHuy7ugCkx2S7d+5hNsicIhQmTADjqtJAkHoMhYqu6/yLFxhjO/+f938PATFULdODTvjCsUwdN/ySWi1Oj4uPAntfytZP7H6YrzLh8dS73QCsdkhhDJIgJskHIBSbRyyEVUnOvQgD9VaBVGHtc1KtZQTwc41OUO3BGPHl97s3oX6bqWqo/L53dB3TPHGx+1+2HL/F0zaDZuHhAKMkPwe8LFPMPB/ur65zXMHjnWb2ZTVVdoIvkbQ7nu8ApI60ejxocYBsEyAuC2CPXU2ki4jdEhm0E1hIziWNE9/LTuM17ziQuJ6WpXOSMrfP4o5aVDmLp5ZGBSocrspOksgyI9XogHaO/r+Y6N3exy+giObFfMHkZVUpsKrKmtOJ7TC1Vg5HsYGlWW8RN8dkJV47bUXm9K4sMos9eYMUt/czykPAs+132cogpII3QxXpFZQqZg6SEPVfOiyqQzTUI=
file_glob: true
file: "${OPJ_RELEASE_PKG_FILE}"
skip_cleanup: true
on:
repo: uclouvain/openjpeg
tags: true
condition: "$OPJ_CI_INCLUDE_IF_DEPLOY = 1"

View File

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

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:
set(OPENJPEG_VERSION_MAJOR 2)
set(OPENJPEG_VERSION_MINOR 2)
set(OPENJPEG_VERSION_MINOR 1)
set(OPENJPEG_VERSION_BUILD 0)
set(OPENJPEG_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
@@ -52,14 +52,11 @@ set(PACKAGE_VERSION
# 2.0 | 6
# 2.0.1 | 6
# 2.1 | 7
# 2.1.1 | 7
# 2.1.2 | 7
# 2.2.0 | 8
# above is the recommendation by the OPJ team. If you really need to override this default,
# you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
# cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
if(NOT OPENJPEG_SOVERSION)
set(OPENJPEG_SOVERSION 7)
SET(OPENJPEG_SOVERSION 7)
endif(NOT OPENJPEG_SOVERSION)
set(OPENJPEG_LIBRARY_PROPERTIES
VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
@@ -69,7 +66,7 @@ set(OPENJPEG_LIBRARY_PROPERTIES
# --------------------------------------------------------------------------
# Path to additional CMake modules
set(CMAKE_MODULE_PATH
${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake
${CMAKE_SOURCE_DIR}/cmake
${CMAKE_MODULE_PATH})
# --------------------------------------------------------------------------
@@ -165,8 +162,8 @@ TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
#-----------------------------------------------------------------------------
# Setup file for setting custom ctest vars
configure_file(
${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake
${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake.in
${CMAKE_BINARY_DIR}/CTestCustom.cmake
@ONLY
)
@@ -193,7 +190,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
# For all builds, make sure openjpeg is std99 compliant:
# set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
# Do not use ffast-math for all build, it would produce incorrect results, only set for release:
set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
SET(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
endif()
#-----------------------------------------------------------------------------
@@ -228,7 +225,7 @@ CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
include(TestLargeFiles)
OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
# Allocating Aligned Memory Blocks
# Allocating Aligned Memory Blocks
include(CheckIncludeFiles)
check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
include(CheckSymbolExists)
@@ -251,7 +248,6 @@ if(BUILD_JPIP_SERVER)
endif()
endif()
add_subdirectory(src/lib)
option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
#-----------------------------------------------------------------------------
# Build Applications
@@ -325,8 +321,8 @@ endif()
#-----------------------------------------------------------------------------
# install all targets referenced as OPENJPEGTargets
install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
configure_file( ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/OpenJPEGConfig.cmake
configure_file( ${OPENJPEG_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
@ONLY
)
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

@@ -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 [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
An API/ABI timeline is automatically updated [here][link-api-timeline].
OpenJPEG strives to provide a stable API/ABI for your applications. As such it
only exposes a limited subset of its functions. It uses a mechanism of
exporting/hiding functions. If you are unsure which functions you can use in
@@ -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"
[badge-coverity]: https://scan.coverity.com/projects/6383/badge.svg "Coverity Scan Build Status"
[link-coverity]: https://scan.coverity.com/projects/uclouvain-openjpeg "Coverity Scan Build Status"
[link-api-timeline]: http://www.openjpeg.org/abi-check/timeline/openjpeg "OpenJPEG API/ABI timeline"

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:
except:
- coverity_scan
skip_tags: false
skip_tags: true
clone_depth: 50
environment:
matrix:
- OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
OPJ_CI_INCLUDE_IF_DEPLOY: 1
- OPJ_CI_ARCH: x64
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
OPJ_CI_INCLUDE_IF_DEPLOY: 1
- OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS100COMNTOOLS)
install:
@@ -22,17 +20,4 @@ build_script:
bash ./tools/travis-ci/run.sh
test: off
#before_deploy:
#- cmd: c:\cygwin\bin\bash ./tools/travis-ci/before_deploy.sh
deploy:
#release: openjpeg-$(appveyor_repo_tag_name)
description: 'OpenJPEG $(appveyor_repo_tag_name) has been released. More info [here](https://github.com/uclouvain/openjpeg/blob/$(appveyor_repo_tag_name)/NEWS) and a detailed view [here](https://github.com/uclouvain/openjpeg/blob/$(appveyor_repo_tag_name)/CHANGES).'
provider: GitHub
auth_token:
secure: Huk03f1heCD/HMyA+4ZeVmICdmKn9rPxK5p8/KxzgL+FtJDHlqcllcCrtN9bDxRH # your encrypted token from GitHub
artifact: /.*\.zip/ # upload all zip packages to release assets
draft: false
prerelease: false
on:
appveyor_repo_tag: true # deploy on tag push only
OPJ_CI_INCLUDE_IF_DEPLOY: 1
deploy: off

View File

@@ -25,9 +25,6 @@ set(CTEST_CUSTOM_COVERAGE_EXCLUDE
set(CTEST_CUSTOM_WARNING_EXCEPTION
${CTEST_CUSTOM_WARNING_EXCEPTION}
# Ignore clang's summary warning, assuming prior text has matched some
# other warning expression:
"[0-9,]+ warnings? generated."
# Suppress warning caused by intentional messages about deprecation
".*warning,.* is deprecated"
# java also warns about deprecated API

View File

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

View File

@@ -32,7 +32,7 @@
.TH opj_decompress 1 "Version 2.1.1" "opj_decompress" "converts jpeg2000 files"
.P
.SH NAME
opj_decompress \-
opj_decompress -
This program reads in a jpeg2000 image and converts it to another
image type. It is part of the OpenJPEG library.
.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 .
.SH SYNOPSIS
.P
.B opj_decompress \-i \fRinfile.j2k \fB-o \fRoutfile.png
.B opj_decompress -i \fRinfile.j2k \fB-o \fRoutfile.png
.P
.B opj_decompress \-ImgDir \fRimages/ \fB-OutFor \fRbmp
.B opj_decompress -ImgDir \fRimages/ \fB-OutFor \fRbmp
.P
.B opj_decompress \-h \fRPrint help message and exit
.B opj_decompress -h \fRPrint help message and exit
.P
.R See JPWL OPTIONS for special options
.SH OPTIONS

View File

@@ -32,7 +32,7 @@
.TH opj_dump 1 "Version 2.1.1" "opj_dump" "dumps jpeg2000 files"
.P
.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.
.SP
Valid input image extensions are
@@ -40,11 +40,11 @@ Valid input image extensions are
.SP
.SH SYNOPSIS
.P
.B opj_dump \-i \fRinfile.j2k
.B opj_dump -i \fRinfile.j2k
.P
.B opj_dump \-ImgDir \fRimages/ \fRDump all files in images/
.B opj_dump -ImgDir \fRimages/ \fRDump all files in images/
.P
.B opj_dump \-h \fRPrint help message and exit
.B opj_dump -h \fRPrint help message and exit
.P
.SH OPTIONS
.TP

File diff suppressed because it is too large Load Diff

View File

@@ -54,7 +54,8 @@ int opj_opterr = 1, /* if error message should be printed */
static char EMSG[]= {""};
/* As this class remembers its values from one Java call to the other, reset the values before each use */
void opj_reset_options_reading(void) {
void opj_reset_options_reading(void)
{
opj_opterr = 1;
opj_optind = 1;
}
@@ -63,7 +64,8 @@ void opj_reset_options_reading(void) {
* getopt --
* Parse argc/argv argument vector.
*/
int opj_getopt(int nargc, char *const *nargv, const char *ostr) {
int opj_getopt(int nargc, char *const *nargv, const char *ostr)
{
# define __progname nargv[0]
static char *place = EMSG; /* option letter processing */
const char *oli = NULL; /* option letter list index */
@@ -123,7 +125,8 @@ int opj_getopt(int nargc, char *const *nargv, const char *ostr) {
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;
int i,len;
@@ -136,12 +139,10 @@ again:
if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
if(opj_optind >= (argc - 1)) { /* no more input parameters */
param = 0;
}
else{ /* more input parameters */
} else { /* more input parameters */
if(argv[opj_optind + 1][0] == '-') {
param = 0; /* Missing parameter after '-' */
}
else{
} else {
param = 2;
}
}
@@ -161,8 +162,7 @@ again:
if (param > 1) {
arg = argv[opj_optind+1];
opj_optind++;
}
else
} else
arg = argv[opj_optind]+1;
if(strlen(arg)>1) {
@@ -205,7 +205,8 @@ again:
} else { /*Single character input parameter*/
if (*optstring==':') return ':';
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*/

View File

@@ -3,8 +3,7 @@
#ifndef _GETOPT_H_
#define _GETOPT_H_
typedef struct opj_option
{
typedef struct opj_option {
const char *name;
int has_arg;
int *flag;

View File

@@ -57,9 +57,6 @@ foreach(exe opj_decompress opj_compress opj_dump)
# On unix you need to link to the math library:
if(UNIX)
target_link_libraries(${exe} m)
IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
target_link_libraries(${exe} rt)
endif()
endif()
# Install exe
install(TARGETS ${exe}

File diff suppressed because it is too large Load Diff

View File

@@ -91,8 +91,7 @@ static void opj_applyLUT8u_8u32s_C1R(
for (y = height; y != 0U; --y) {
OPJ_UINT32 x;
for(x = 0; x < width; x++)
{
for(x = 0; x < width; x++) {
pDst[x] = (OPJ_INT32)pLUT[pSrc[x]];
}
pSrc += srcStride;
@@ -117,8 +116,7 @@ static void opj_applyLUT8u_8u32s_C1P3R(
for (y = height; y != 0U; --y) {
OPJ_UINT32 x;
for(x = 0; x < width; x++)
{
for(x = 0; x < width; x++) {
OPJ_UINT8 idx = pSrc[x];
pR[x] = (OPJ_INT32)pLUT_R[idx];
pG[x] = (OPJ_INT32)pLUT_G[idx];
@@ -143,10 +141,8 @@ static void bmp24toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t*
index = 0;
pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++)
{
for(x = 0; x < width; x++)
{
for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) {
image->comps[0].data[index] = (OPJ_INT32)pSrc[3*x+2]; /* R */
image->comps[1].data[index] = (OPJ_INT32)pSrc[3*x+1]; /* G */
image->comps[2].data[index] = (OPJ_INT32)pSrc[3*x+0]; /* B */
@@ -172,7 +168,8 @@ static void bmp_mask_get_shift_and_prec(OPJ_UINT32 mask, OPJ_UINT32* shift, OPJ_
l_prec++;
}
}
*shift = l_shift; *prec = l_prec;
*shift = l_shift;
*prec = l_prec;
}
static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t* image, OPJ_UINT32 redMask, OPJ_UINT32 greenMask, OPJ_UINT32 blueMask, OPJ_UINT32 alphaMask)
@@ -181,7 +178,7 @@ static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_imag
OPJ_UINT32 width, height;
OPJ_UINT32 x, y;
const OPJ_UINT8 *pSrc = NULL;
OPJ_BOOL hasAlpha;
OPJ_BOOL hasAlpha = OPJ_FALSE;
OPJ_UINT32 redShift, redPrec;
OPJ_UINT32 greenShift, greenPrec;
OPJ_UINT32 blueShift, bluePrec;
@@ -210,10 +207,8 @@ static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_imag
index = 0;
pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++)
{
for(x = 0; x < width; x++)
{
for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) {
OPJ_UINT32 value = 0U;
value |= ((OPJ_UINT32)pSrc[4*x+0]) << 0;
@@ -239,7 +234,7 @@ static void bmpmask16toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_imag
OPJ_UINT32 width, height;
OPJ_UINT32 x, y;
const OPJ_UINT8 *pSrc = NULL;
OPJ_BOOL hasAlpha;
OPJ_BOOL hasAlpha = OPJ_FALSE;
OPJ_UINT32 redShift, redPrec;
OPJ_UINT32 greenShift, greenPrec;
OPJ_UINT32 blueShift, bluePrec;
@@ -268,10 +263,8 @@ static void bmpmask16toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_imag
index = 0;
pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++)
{
for(x = 0; x < width; x++)
{
for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) {
OPJ_UINT32 value = 0U;
value |= ((OPJ_UINT32)pSrc[2*x+0]) << 0;
@@ -300,13 +293,16 @@ static opj_image_t* bmp8toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_i
pSrc = pData + (height - 1U) * stride;
if (image->numcomps == 1U) {
opj_applyLUT8u_8u32s_C1R(pSrc, -(OPJ_INT32)stride, image->comps[0].data, (OPJ_INT32)width, pLUT[0], width, height);
}
else {
} else {
OPJ_INT32* pDst[3];
OPJ_INT32 pDstStride[3];
pDst[0] = image->comps[0].data; pDst[1] = image->comps[1].data; pDst[2] = image->comps[2].data;
pDstStride[0] = (OPJ_INT32)width; pDstStride[1] = (OPJ_INT32)width; pDstStride[2] = (OPJ_INT32)width;
pDst[0] = image->comps[0].data;
pDst[1] = image->comps[1].data;
pDst[2] = image->comps[2].data;
pDstStride[0] = (OPJ_INT32)width;
pDstStride[1] = (OPJ_INT32)width;
pDstStride[2] = (OPJ_INT32)width;
opj_applyLUT8u_8u32s_C1P3R(pSrc, -(OPJ_INT32)stride, pDst, pDstStride, pLUT, width, height);
}
return image;
@@ -489,8 +485,7 @@ static OPJ_BOOL bmp_read_raw_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride,
{
OPJ_ARG_NOT_USED(width);
if ( fread(pData, sizeof(OPJ_UINT8), stride * height, IN) != (stride * height) )
{
if ( fread(pData, sizeof(OPJ_UINT8), stride * height, IN) != (stride * height) ) {
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return OPJ_FALSE;
}
@@ -507,8 +502,7 @@ static OPJ_BOOL bmp_read_rle8_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
pix = pData;
x = y = 0U;
while (y < height)
{
while (y < height) {
int c = getc(IN);
if (c) {
@@ -518,29 +512,23 @@ static OPJ_BOOL bmp_read_rle8_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
*pix = c1;
}
}
else {
} else {
c = getc(IN);
if (c == 0x00) { /* EOL */
x = 0;
++y;
pix = pData + y * stride + x;
}
else if (c == 0x01) { /* EOP */
} else if (c == 0x01) { /* EOP */
break;
}
else if (c == 0x02) { /* MOVE by dxdy */
} else if (c == 0x02) { /* MOVE by dxdy */
c = getc(IN);
x += (OPJ_UINT32)c;
c = getc(IN);
y += (OPJ_UINT32)c;
pix = pData + y * stride + x;
}
else /* 03 .. 255 */
{
} else { /* 03 .. 255 */
int j;
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++)
{
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
OPJ_UINT8 c1 = (OPJ_UINT8)getc(IN);
*pix = c1;
}
@@ -562,8 +550,7 @@ static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
beyond = pData + stride * height;
pix = pData;
x = y = 0U;
while(y < height)
{
while(y < height) {
int c = getc(IN);
if(c == EOF) break;
@@ -574,23 +561,23 @@ static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
*pix = (OPJ_UINT8)((j&1) ? (c1 & 0x0fU) : ((c1>>4)&0x0fU));
}
}
else { /* absolute mode */
} else { /* absolute mode */
c = getc(IN);
if(c == EOF) break;
if(c == 0x00) { /* EOL */
x = 0; y++; pix = pData + y * stride;
}
else if(c == 0x01) { /* EOP */
x = 0;
y++;
pix = pData + y * stride;
} else if(c == 0x01) { /* EOP */
break;
}
else if(c == 0x02) { /* MOVE by dxdy */
c = getc(IN); x += (OPJ_UINT32)c;
c = getc(IN); y += (OPJ_UINT32)c;
} else if(c == 0x02) { /* MOVE by dxdy */
c = getc(IN);
x += (OPJ_UINT32)c;
c = getc(IN);
y += (OPJ_UINT32)c;
pix = pData + y * stride + x;
}
else { /* 03 .. 255 : absolute mode */
} else { /* 03 .. 255 : absolute mode */
int j;
OPJ_UINT8 c1 = 0U;
@@ -623,11 +610,12 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
OPJ_UINT8* pData = NULL;
OPJ_UINT32 stride;
pLUT[0] = lut_R; pLUT[1] = lut_G; pLUT[2] = lut_B;
pLUT[0] = lut_R;
pLUT[1] = lut_G;
pLUT[2] = lut_B;
IN = fopen(filename, "rb");
if (!IN)
{
if (!IN) {
fprintf(stderr, "Failed to open %s for reading !!\n", filename);
return NULL;
}
@@ -642,8 +630,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
}
/* Load palette */
if (Info_h.biBitCount <= 8U)
{
if (Info_h.biBitCount <= 8U) {
memset(&lut_R[0], 0, sizeof(lut_R));
memset(&lut_G[0], 0, sizeof(lut_G));
memset(&lut_B[0], 0, sizeof(lut_B));
@@ -675,28 +662,10 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
}
}
if (Info_h.biWidth == 0 || Info_h.biHeight == 0) {
fclose(IN);
return NULL;
}
if (Info_h.biBitCount > (((OPJ_UINT32)-1) - 31) / Info_h.biWidth) {
fclose(IN);
return NULL;
}
stride = ((Info_h.biWidth * Info_h.biBitCount + 31U) / 32U) * 4U; /* rows are aligned on 32bits */
if (Info_h.biBitCount == 4 && Info_h.biCompression == 2) { /* RLE 4 gets decoded as 8 bits data for now... */
if (8 > (((OPJ_UINT32)-1) - 31) / Info_h.biWidth) {
fclose(IN);
return NULL;
}
stride = ((Info_h.biWidth * 8U + 31U) / 32U) * 4U;
}
if (stride > ((OPJ_UINT32)-1) / sizeof(OPJ_UINT8) / Info_h.biHeight) {
fclose(IN);
return NULL;
}
pData = (OPJ_UINT8 *) calloc(1, stride * Info_h.biHeight * sizeof(OPJ_UINT8));
if (pData == NULL) {
fclose(IN);
@@ -733,8 +702,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
/* create the image */
memset(&cmptparm[0], 0, sizeof(cmptparm));
for(i = 0; i < 4U; i++)
{
for(i = 0; i < 4U; i++) {
cmptparm[i].prec = 8;
cmptparm[i].bpp = 8;
cmptparm[i].sgnd = 0;
@@ -763,34 +731,26 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
/* Read the data */
if (Info_h.biBitCount == 24 && Info_h.biCompression == 0) { /*RGB */
bmp24toimage(pData, stride, image);
}
else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) { /* RGB 8bpp Indexed */
} else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) { /* RGB 8bpp Indexed */
bmp8toimage(pData, stride, image, pLUT);
}
else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) { /*RLE8*/
} else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) { /*RLE8*/
bmp8toimage(pData, stride, image, pLUT);
}
else if (Info_h.biBitCount == 4 && Info_h.biCompression == 2) { /*RLE4*/
} else if (Info_h.biBitCount == 4 && Info_h.biCompression == 2) { /*RLE4*/
bmp8toimage(pData, stride, image, pLUT); /* RLE 4 gets decoded as 8 bits data for now */
}
else if (Info_h.biBitCount == 32 && Info_h.biCompression == 0) { /* RGBX */
} else if (Info_h.biBitCount == 32 && Info_h.biCompression == 0) { /* RGBX */
bmpmask32toimage(pData, stride, image, 0x00FF0000U, 0x0000FF00U, 0x000000FFU, 0x00000000U);
}
else if (Info_h.biBitCount == 32 && Info_h.biCompression == 3) { /* bitmask */
} else if (Info_h.biBitCount == 32 && Info_h.biCompression == 3) { /* bitmask */
bmpmask32toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, Info_h.biBlueMask, Info_h.biAlphaMask);
}
else if (Info_h.biBitCount == 16 && Info_h.biCompression == 0) { /* RGBX */
} else if (Info_h.biBitCount == 16 && Info_h.biCompression == 0) { /* RGBX */
bmpmask16toimage(pData, stride, image, 0x7C00U, 0x03E0U, 0x001FU, 0x0000U);
}
else if (Info_h.biBitCount == 16 && Info_h.biCompression == 3) { /* bitmask */
} else if (Info_h.biBitCount == 16 && Info_h.biCompression == 3) { /* bitmask */
if ((Info_h.biRedMask == 0U) && (Info_h.biGreenMask == 0U) && (Info_h.biBlueMask == 0U)) {
Info_h.biRedMask = 0xF800U;
Info_h.biGreenMask = 0x07E0U;
Info_h.biBlueMask = 0x001FU;
}
bmpmask16toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, Info_h.biBlueMask, Info_h.biAlphaMask);
}
else {
} else {
opj_image_destroy(image);
image = NULL;
fprintf(stderr, "Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n", Info_h.biBitCount);
@@ -800,7 +760,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
return image;
}
int imagetobmp(opj_image_t * image, const char *outfile) {
int imagetobmp(opj_image_t * image, const char *outfile)
{
int w, h;
int i, pad;
FILE *fdest = NULL;
@@ -868,20 +829,17 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
if (image->comps[0].prec > 8) {
adjustR = (int)image->comps[0].prec - 8;
printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec);
}
else
} else
adjustR = 0;
if (image->comps[1].prec > 8) {
adjustG = (int)image->comps[1].prec - 8;
printf("BMP CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec);
}
else
} else
adjustG = 0;
if (image->comps[2].prec > 8) {
adjustB = (int)image->comps[2].prec - 8;
printf("BMP CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec);
}
else
} else
adjustB = 0;
for (i = 0; i < w * h; i++) {
@@ -891,25 +849,28 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
r = ((r >> adjustR)+((r >> (adjustR-1))%2));
if(r > 255) r = 255; else if(r < 0) r = 0;
if(r > 255) r = 255;
else if(r < 0) r = 0;
rc = (OPJ_UINT8)r;
g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
g = ((g >> adjustG)+((g >> (adjustG-1))%2));
if(g > 255) g = 255; else if(g < 0) g = 0;
if(g > 255) g = 255;
else if(g < 0) g = 0;
gc = (OPJ_UINT8)g;
b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
b = ((b >> adjustB)+((b >> (adjustB-1))%2));
if(b > 255) b = 255; else if(b < 0) b = 0;
if(b > 255) b = 255;
else if(b < 0) b = 0;
bc = (OPJ_UINT8)b;
fprintf(fdest, "%c%c%c", bc, gc, rc);
if ((i + 1) % w == 0) {
for (pad = ((3 * w) % 4) ? (4 - (3 * w) % 4) : 0; pad > 0; pad--) /* ADD */
for (pad = (3 * w) % 4 ? 4 - (3 * w) % 4 : 0; pad > 0; pad--) /* ADD */
fprintf(fdest, "%c", 0);
}
}
@@ -980,12 +941,13 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
r = ((r >> adjustR)+((r >> (adjustR-1))%2));
if(r > 255) r = 255; else if(r < 0) r = 0;
if(r > 255) r = 255;
else if(r < 0) r = 0;
fprintf(fdest, "%c", (OPJ_UINT8)r);
if ((i + 1) % w == 0) {
for (pad = (w % 4) ? (4 - w % 4) : 0; pad > 0; pad--) /* ADD */
for (pad = w % 4 ? 4 - w % 4 : 0; pad > 0; pad--) /* ADD */
fprintf(fdest, "%c", 0);
}
}

View File

@@ -85,15 +85,13 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
convert_32s_CXPX cvtCxToPx = NULL;
OPJ_INT32* planes[4];
if((reader = fopen(read_idf, "rb")) == NULL)
{
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)
{
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) {
fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf);
goto fin;
}
@@ -185,23 +183,14 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*));
if(rows == NULL){
fprintf(stderr, "pngtoimage: memory out\n");
goto fin;
}
for(i = 0; i < height; ++i){
for(i = 0; i < height; ++i)
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info));
if(rows[i] == NULL){
fprintf(stderr,"pngtoimage: memory out\n");
goto fin;
}
}
png_read_image(png, rows);
/* Create image */
memset(cmptparm, 0, sizeof(cmptparm));
for(i = 0; i < nr_comp; ++i)
{
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;
@@ -225,13 +214,11 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
/* Set alpha channel */
image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U);
for(i = 0; i < nr_comp; i++)
{
for(i = 0; i < nr_comp; i++) {
planes[i] = image->comps[i].data;
}
for(i = 0; i < height; ++i)
{
for(i = 0; i < height; ++i) {
cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp);
cvtCxToPx(row32s, planes, width);
planes[0] += width;
@@ -240,10 +227,9 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
planes[3] += width;
}
fin:
if(rows)
{
if(rows) {
for(i = 0; i < height; ++i)
if(rows[i]) free(rows[i]);
free(rows[i]);
free(rows);
}
if (row32s) {
@@ -314,15 +300,12 @@ int imagetopng(opj_image_t * image, const char *write_idf)
for (i = 0; i < nr_comp; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec);
}
if(prec > 8 && prec < 16)
{
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 */
{
} 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);
}
@@ -338,8 +321,7 @@ int imagetopng(opj_image_t * image, const char *write_idf)
}
}
if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16)
{
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;
}
@@ -394,18 +376,14 @@ int imagetopng(opj_image_t * image, const char *write_idf)
*/
png_set_compression_level(png, Z_BEST_COMPRESSION);
if(nr_comp >= 3) /* RGB(A) */
{
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) */
{
} else { /* GRAY(A) */
color_type = PNG_COLOR_TYPE_GRAY;
sig_bit.gray = (png_byte)prec;
}
if((nr_comp & 1) == 0) /* ALPHA */
{
if((nr_comp & 1) == 0) { /* ALPHA */
color_type |= PNG_COLOR_MASK_ALPHA;
sig_bit.alpha = (png_byte)prec;
}
@@ -466,8 +444,7 @@ int imagetopng(opj_image_t * image, const char *write_idf)
break;
}
for(y = 0; y < image->comps[0].h; ++y)
{
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);

File diff suppressed because it is too large Load Diff

View File

@@ -46,7 +46,8 @@ Write a structured index to a file
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
int write_index_file(opj_codestream_info_t *cstr_info, char *index)
{
int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL;
double total_disto = 0;
@@ -69,7 +70,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
return 1;
}
if (cstr_info->tile[0].distotile > 0.0)
if (cstr_info->tile[0].distotile)
disto_on = 1;
else
disto_on = 0;

View File

@@ -89,7 +89,8 @@ typedef struct img_folder{
char set_out_format;
} img_fol_t;
static void encode_help_display(void) {
static void encode_help_display(void)
{
fprintf(stdout,"\nThis is the opj_compress utility from the OpenJPEG project.\n"
"It compresses various image formats with the JPEG 2000 algorithm.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version());
@@ -236,7 +237,7 @@ static void encode_help_display(void) {
fprintf(stdout,"-I\n");
fprintf(stdout," Use the irreversible DWT 9-7.\n");
fprintf(stdout,"-mct <0|1|2>\n");
fprintf(stdout," Explicitly specifies if a Multiple Component Transform has to be used.\n");
fprintf(stdout," Explicitely specifies if a Multiple Component Transform has to be used.\n");
fprintf(stdout," 0: no MCT ; 1: RGB->YCC conversion ; 2: custom MCT.\n");
fprintf(stdout," If custom MCT, \"-m\" option has to be used (see hereunder).\n");
fprintf(stdout," By default, RGB->YCC conversion is used if there are 3 components or more,\n");
@@ -353,7 +354,8 @@ static void encode_help_display(void) {
#endif /*FIXME_INDEX*/
}
static OPJ_PROG_ORDER give_progression(const char progression[4]) {
static OPJ_PROG_ORDER give_progression(const char progression[4])
{
if(strncmp(progression, "LRCP", 4) == 0) {
return OPJ_LRCP;
}
@@ -373,7 +375,8 @@ static OPJ_PROG_ORDER give_progression(const char progression[4]) {
return OPJ_PROG_UNKNOWN;
}
static unsigned int get_num_images(char *imgdirpath){
static unsigned int get_num_images(char *imgdirpath)
{
DIR *dir;
struct dirent* content;
unsigned int num_images = 0;
@@ -396,7 +399,8 @@ static unsigned int get_num_images(char *imgdirpath){
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;
int i = 0;
@@ -422,7 +426,8 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
return 0;
}
static int get_file_format(char *filename) {
static int get_file_format(char *filename)
{
unsigned int i;
static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc"
@@ -442,12 +447,14 @@ static int get_file_format(char *filename) {
return -1;
}
static char * get_file_name(char *name){
static char * get_file_name(char *name)
{
char *fname = strtok(name,".");
return fname;
}
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_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]="";
@@ -479,7 +486,8 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
/* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size) {
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size)
{
OPJ_UINT32 i, j;
int totlen, c;
opj_option_t long_option[]= {
@@ -512,8 +520,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
case 'i': { /* input file */
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -541,8 +548,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'o': /* output file */
{
case 'o': { /* output file */
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -560,8 +566,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
break;
/* ----------------------------------------------------- */
case 'O': /* output format */
{
case 'O': { /* output format */
char outformat[50];
char *of = opj_optarg;
sprintf(outformat,".%s",of);
@@ -583,8 +588,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */
{
case 'r': { /* rates rates/distorsion */
char *s = opj_optarg;
parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
@@ -603,8 +607,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'F': /* Raw image format parameters */
{
case 'F': { /* Raw image format parameters */
OPJ_BOOL wrong = OPJ_FALSE;
char *substr1;
char *substr2;
@@ -647,10 +650,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
raw_cp->rawBitDepth = bitdepth;
raw_cp->rawSigned = raw_signed;
raw_cp->rawComps = (raw_comp_cparameters_t*) malloc(((OPJ_UINT32)(ncomp))*sizeof(raw_comp_cparameters_t));
if(raw_cp->rawComps == NULL){
free(substr1);
return 1;
}
for (compno = 0; compno < ncomp && !wrong; compno++) {
if (substr2 == NULL) {
raw_cp->rawComps[compno].dx = lastdx;
@@ -695,8 +694,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'q': /* add fixed_quality */
{
case 'q': { /* add fixed_quality */
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
@@ -714,8 +712,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* dda */
/* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */
{
case 'f': { /* mod fixed_quality (before : -q) */
int *row = NULL, *col = NULL;
OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0;
@@ -729,9 +726,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
numresolution = (OPJ_UINT32)parameters->numresolution;
matrix_width = numresolution * 3;
parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
if(parameters->cp_matrice == NULL){
return 1;
}
s = s + 2;
for (i = 0; i < numlayers; i++) {
@@ -764,8 +758,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 't': /* tiles */
{
case 't': { /* tiles */
sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE;
}
@@ -773,15 +766,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'n': /* resolution */
{
case 'n': { /* resolution */
sscanf(opj_optarg, "%d", &parameters->numresolution);
}
break;
/* ----------------------------------------------------- */
case 'c': /* precinct dimension */
{
case 'c': { /* precinct dimension */
char sep;
int res_spec = 0;
@@ -791,8 +782,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
sep = 0;
ret = sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
&parameters->prch_init[res_spec], &sep);
if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') )
{
if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') ) {
fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep);
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n");
return 1;
@@ -800,16 +790,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
}
while (sep == ',');
} while (sep == ',');
parameters->res_spec = res_spec;
}
break;
/* ----------------------------------------------------- */
case 'b': /* code-block dimension */
{
case 'b': { /* code-block dimension */
int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@@ -826,8 +814,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'x': /* creation of index file */
{
case 'x': { /* creation of index file */
if (opj_strcpy_s(indexfilename, indexfilename_size, opj_optarg) != 0) {
return 1;
}
@@ -841,8 +828,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'p': /* progression order */
{
case 'p': { /* progression order */
char progression[4];
strncpy(progression, opj_optarg, 4);
@@ -857,8 +843,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
{
case 's': { /* subsampling factor */
if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,
&parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@@ -869,8 +854,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */
{
case 'd': { /* coordonnate of the reference grid */
if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,
&parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@@ -888,8 +872,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'P': /* POC */
{
case 'P': { /* POC */
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@@ -916,24 +899,21 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'S': /* SOP marker */
{
case 'S': { /* SOP marker */
parameters->csty |= 0x02;
}
break;
/* ------------------------------------------------------ */
case 'E': /* EPH marker */
{
case 'E': { /* EPH marker */
parameters->csty |= 0x04;
}
break;
/* ------------------------------------------------------ */
case 'M': /* Mode switch pas tous au point !! */
{
case 'M': { /* Mode switch pas tous au point !! */
int value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
@@ -947,8 +927,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'R': /* ROI */
{
case 'R': { /* ROI */
if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,
&parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
@@ -959,8 +938,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'T': /* Tile offset */
{
case 'T': { /* Tile offset */
if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
@@ -970,8 +948,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'C': /* add a comment */
{
case 'C': { /* add a comment */
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) {
strcpy(parameters->cp_comment, opj_optarg);
@@ -982,16 +959,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'I': /* reversible or not */
{
case 'I': { /* reversible or not */
parameters->irreversible = 1;
}
break;
/* ------------------------------------------------------ */
case 'u': /* Tile part generation*/
{
case 'u': { /* Tile part generation*/
parameters->tp_flag = opj_optarg[0];
parameters->tp_on = 1;
}
@@ -999,12 +974,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'z': /* Image Directory path */
{
case 'z': { /* Image Directory path */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
if(img_fol->imgdirpath == NULL){
return 1;
}
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
@@ -1012,8 +983,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'w': /* Digital Cinema 2K profile compliance*/
{
case 'w': { /* Digital Cinema 2K profile compliance*/
int fps=0;
sscanf(opj_optarg,"%d",&fps);
if(fps == 24) {
@@ -1029,25 +999,23 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1;
}
fprintf(stdout,"CINEMA 2K profile activated\n"
"Other options specified could be overridden\n");
"Other options specified could be overriden\n");
}
break;
/* ------------------------------------------------------ */
case 'y': /* Digital Cinema 4K profile compliance*/
{
case 'y': { /* Digital Cinema 4K profile compliance*/
parameters->rsiz = OPJ_PROFILE_CINEMA_4K;
fprintf(stdout,"CINEMA 4K profile activated\n"
"Other options specified could be overridden\n");
"Other options specified could be overriden\n");
}
break;
/* ------------------------------------------------------ */
case 'Y': /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/
{
case 'Y': { /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/
int mct_mode=0;
sscanf(opj_optarg,"%d",&mct_mode);
if(mct_mode < 0 || mct_mode > 2) {
@@ -1061,8 +1029,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'm': /* mct input file */
{
case 'm': { /* mct input file */
char *lFilename = opj_optarg;
char *lMatrix;
char *lCurrentPtr ;
@@ -1146,8 +1113,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#ifdef USE_JPWL
/* ------------------------------------------------------ */
case 'W': /* JPWL capabilities switched on */
{
case 'W': { /* JPWL capabilities switched on */
char *token = NULL;
int hprot, pprot, sens, addr, size, range;
@@ -1465,8 +1431,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* <<UniPG */
/* ------------------------------------------------------ */
case 'J': /* jpip on */
{
case 'J': { /* jpip on */
parameters->jpip_on = OPJ_TRUE;
}
break;
@@ -1550,7 +1515,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
}
return 0;
}
/* -------------------------------------------------------------------------- */
@@ -1558,26 +1522,30 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/**
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);
}
/**
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);
}
/**
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);
}
OPJ_FLOAT64 opj_clock(void) {
OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
@@ -1607,7 +1575,8 @@ OPJ_FLOAT64 opj_clock(void) {
* OPJ_COMPRESS MAIN
*/
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
opj_cparameters_t parameters; /* compression parameters */
@@ -1646,7 +1615,7 @@ int main(int argc, char **argv) {
/* parse input and get user encoding parameters */
parameters.tcp_mct = (char) 255; /* This will be set later according to the input image or the provided option */
if(parse_cmdline_encoder(argc, argv, &parameters,&img_fol, &raw_cp, indexfilename, sizeof(indexfilename)) == 1) {
goto fails;
return 1;
}
/* Read directory if necessary */
@@ -1807,14 +1776,12 @@ int main(int argc, char **argv) {
/* ---------------------------- */
switch(parameters.cod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */
{
case J2K_CFMT: { /* JPEG-2000 codestream */
/* Get a decoder handle */
l_codec = opj_create_compress(OPJ_CODEC_J2K);
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_compress(OPJ_CODEC_JP2);
break;
@@ -1859,9 +1826,7 @@ int main(int argc, char **argv) {
OPJ_BYTE *l_data;
OPJ_UINT32 l_data_size = 512*512*3;
l_data = (OPJ_BYTE*) calloc( 1,l_data_size);
if(l_data == NULL){
goto fails;
}
assert( l_data );
for (i=0; i<l_nb_tiles; ++i) {
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i);
@@ -1872,8 +1837,7 @@ int main(int argc, char **argv) {
}
}
free(l_data);
}
else {
} else {
bSuccess = bSuccess && opj_encode(l_codec, l_stream);
if (!bSuccess) {
fprintf(stderr, "failed to encode image: opj_encode\n");
@@ -1917,16 +1881,4 @@ int main(int argc, char **argv) {
}
return 0;
fails:
if(parameters.cp_comment) free(parameters.cp_comment);
if(parameters.cp_matrice) free(parameters.cp_matrice);
if(raw_cp.rawComps) free(raw_cp.rawComps);
if(img_fol.imgdirpath) free(img_fol.imgdirpath);
if(dirptr){
if(dirptr->filename_buf) free(dirptr->filename_buf);
if(dirptr->filename) free(dirptr->filename);
free(dirptr);
}
return 1;
}

View File

@@ -43,7 +43,6 @@
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifdef _WIN32
#include "windirent.h"
@@ -98,20 +97,17 @@ typedef struct img_folder{
} img_fol_t;
typedef enum opj_prec_mode
{
typedef enum opj_prec_mode {
OPJ_PREC_MODE_CLIP,
OPJ_PREC_MODE_SCALE
} opj_precision_mode;
typedef struct opj_prec
{
typedef struct opj_prec {
OPJ_UINT32 prec;
opj_precision_mode mode;
} opj_precision;
typedef struct opj_decompress_params
{
typedef struct opj_decompress_params {
/** core library parameters */
opj_dparameters_t core;
@@ -151,8 +147,6 @@ typedef struct opj_decompress_params
int upsample;
/* split output components to different files */
int split_pnm;
/** number of threads */
int num_threads;
} opj_decompress_parameters;
/* -------------------------------------------------------------------------- */
@@ -169,7 +163,8 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi
static opj_image_t* convert_gray_to_rgb(opj_image_t* original);
/* -------------------------------------------------------------------------- */
static void decode_help_display(void) {
static void decode_help_display(void)
{
fprintf(stdout,"\nThis is the opj_decompress utility from the OpenJPEG project.\n"
"It decompresses JPEG 2000 codestreams to various image formats.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version());
@@ -227,11 +222,8 @@ static void decode_help_display(void) {
" -upsample\n"
" Downsampled components will be upsampled to image size\n"
" -split-pnm\n"
" Split output components to different files when writing to PNM\n");
if( opj_has_thread_support() ) {
fprintf(stdout," -threads <num_threads>\n"
" Number of threads to use for decoding.\n");
}
" Split output components to different files when writing to PNM\n"
"\n");
/* UniPG>> */
#ifdef USE_JPWL
fprintf(stdout," -W <options>\n"
@@ -259,8 +251,7 @@ static OPJ_BOOL parse_precision(const char* option, opj_decompress_parameters* p
}
parameters->nb_precision = 0U;
for(;;)
{
for(;;) {
int prec;
char mode;
char comma;
@@ -352,7 +343,8 @@ static OPJ_BOOL parse_precision(const char* option, opj_decompress_parameters* p
/* -------------------------------------------------------------------------- */
int get_num_images(char *imgdirpath){
int get_num_images(char *imgdirpath)
{
DIR *dir;
struct dirent* content;
int num_images = 0;
@@ -375,7 +367,8 @@ int get_num_images(char *imgdirpath){
}
/* -------------------------------------------------------------------------- */
int load_images(dircnt_t *dirptr, char *imgdirpath){
int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir;
struct dirent* content;
int i = 0;
@@ -402,7 +395,8 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
}
/* -------------------------------------------------------------------------- */
int get_file_format(const char *filename) {
int get_file_format(const char *filename)
{
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
@@ -428,7 +422,8 @@ const char* path_separator = "/";
#endif
/* -------------------------------------------------------------------------- */
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_decompress_parameters *parameters){
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_decompress_parameters *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]="";
@@ -492,12 +487,10 @@ static int infile_format(const char *fname)
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
magic_format = JP2_CFMT;
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_s = ".j2k or .jpc or .j2c";
}
else
} else
return -1;
if (magic_format == ext_format)
@@ -518,7 +511,8 @@ static int infile_format(const char *fname)
* Parse the command line
*/
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol) {
int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol)
{
/* parse the command line */
int totlen, c;
opj_option_t long_option[]= {
@@ -526,8 +520,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
{"OutFor", REQ_ARG, NULL,'O'},
{"force-rgb", NO_ARG, NULL, 1},
{"upsample", NO_ARG, NULL, 1},
{"split-pnm", NO_ARG, NULL, 1},
{"threads", REQ_ARG, NULL, 'T'}
{"split-pnm", NO_ARG, NULL, 1}
};
const char optlist[] = "i:o:r:l:x:d:t:p:"
@@ -552,8 +545,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
switch (c) {
case 0: /* long opt with flag */
break;
case 'i': /* input file */
{
case 'i': { /* input file */
char *infile = opj_optarg;
parameters->decod_format = infile_format(infile);
switch(parameters->decod_format) {
@@ -584,8 +576,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */
case 'o': /* output file */
{
case 'o': { /* output file */
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -618,8 +609,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */
case 'O': /* output format */
{
case 'O': { /* output format */
char outformat[50];
char *of = opj_optarg;
sprintf(outformat,".%s",of);
@@ -661,8 +651,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */
case 'r': /* reduce option */
{
case 'r': { /* reduce option */
sscanf(opj_optarg, "%u", &(parameters->core.cp_reduce));
}
break;
@@ -670,8 +659,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */
case 'l': /* layering option */
{
case 'l': { /* layering option */
sscanf(opj_optarg, "%u", &(parameters->core.cp_layer));
}
break;
@@ -684,12 +672,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */
case 'y': /* Image Directory path */
{
case 'y': { /* Image Directory path */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
if(img_fol->imgdirpath == NULL){
return 1;
}
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
@@ -697,8 +681,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */
case 'd': /* Input decode ROI */
{
case 'd': { /* Input decode ROI */
size_t size_optarg = (size_t)strlen(opj_optarg) + 1U;
char *ROI_values = (char*) malloc(size_optarg);
if (ROI_values == NULL) {
@@ -716,8 +699,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */
case 't': /* Input tile index */
{
case 't': { /* Input tile index */
sscanf(opj_optarg, "%u", &parameters->tile_index);
parameters->nb_tile_to_decode = 1;
}
@@ -725,8 +707,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */
case 'x': /* Creation of index file */
{
case 'x': { /* Creation of index file */
if (opj_strcpy_s(parameters->indexfilename, sizeof(parameters->indexfilename), opj_optarg) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
return 1;
@@ -735,10 +716,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
break;
/* ----------------------------------------------------- */
case 'p': /* Force precision */
{
if (!parse_precision(opj_optarg, parameters))
{
case 'p': { /* Force precision */
if (!parse_precision(opj_optarg, parameters)) {
return 1;
}
}
@@ -748,8 +727,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* UniPG>> */
#ifdef USE_JPWL
case 'W': /* activate JPWL correction */
{
case 'W': { /* activate JPWL correction */
char *token = NULL;
token = strtok(opj_optarg, ",");
@@ -816,22 +794,6 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
#endif /* USE_JPWL */
/* <<UniPG */
/* ----------------------------------------------------- */
case 'T': /* Number of threads */
{
if( strcmp(opj_optarg, "ALL_CPUS") == 0 )
{
parameters->num_threads = opj_get_num_cpus();
if( parameters->num_threads == 1 )
parameters->num_threads = 0;
}
else
{
sscanf(opj_optarg, "%d", &parameters->num_threads);
}
}
break;
/* ----------------------------------------------------- */
default:
@@ -890,15 +852,17 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi
if (it != 4) {
return EXIT_FAILURE;
}
else{
*DA_x0 = (OPJ_UINT32)values[0]; *DA_y0 = (OPJ_UINT32)values[1];
*DA_x1 = (OPJ_UINT32)values[2]; *DA_y1 = (OPJ_UINT32)values[3];
} else {
*DA_x0 = (OPJ_UINT32)values[0];
*DA_y0 = (OPJ_UINT32)values[1];
*DA_x1 = (OPJ_UINT32)values[2];
*DA_y1 = (OPJ_UINT32)values[3];
return EXIT_SUCCESS;
}
}
OPJ_FLOAT64 opj_clock(void) {
OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
@@ -908,13 +872,8 @@ OPJ_FLOAT64 opj_clock(void) {
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ;
return freq.QuadPart ? (t.QuadPart / (OPJ_FLOAT64)freq.QuadPart) : 0;
#elif defined(__linux)
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return( (OPJ_FLOAT64)ts.tv_sec + (OPJ_FLOAT64)ts.tv_nsec * 1e-9 );
#else
/* Unix : use resource usage */
/* FIXME: this counts the total CPU time, instead of the user perceived time */
/* Unix or Linux: use resource usage */
struct rusage t;
OPJ_FLOAT64 procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
@@ -932,21 +891,24 @@ OPJ_FLOAT64 opj_clock(void) {
/**
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)
{
(void)client_data;
fprintf(stdout, "[ERROR] %s", msg);
}
/**
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)
{
(void)client_data;
fprintf(stdout, "[WARNING] %s", msg);
}
/**
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);
}
@@ -1194,8 +1156,7 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
l_dst += l_new_cmp->w;
}
}
}
else {
} else {
memcpy(l_new_cmp->data, l_org_cmp->data, l_org_cmp->w * l_org_cmp->h * sizeof(OPJ_INT32));
}
}
@@ -1231,7 +1192,8 @@ int main(int argc, char **argv)
/* parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
failed = 1; goto fin;
destroy_parameters(&parameters);
return EXIT_FAILURE;
}
/* Initialize reading of directory */
@@ -1240,30 +1202,26 @@ int main(int argc, char **argv)
num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(!dirptr){
destroy_parameters(&parameters);
return EXIT_FAILURE;
}
if(dirptr) {
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){
failed = 1; goto fin;
}
dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename){
failed = 1; goto fin;
if(!dirptr->filename_buf) {
destroy_parameters(&parameters);
return EXIT_FAILURE;
}
for(it_image=0; it_image<num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
}
}
if(load_images(dirptr,img_fol.imgdirpath)==1) {
failed = 1; goto fin;
destroy_parameters(&parameters);
return EXIT_FAILURE;
}
if (num_images==0) {
fprintf(stdout,"Folder is empty\n");
failed = 1; goto fin;
destroy_parameters(&parameters);
return EXIT_FAILURE;
}
} else {
num_images=1;
@@ -1288,27 +1246,25 @@ int main(int argc, char **argv)
l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile);
failed = 1; goto fin;
destroy_parameters(&parameters);
return EXIT_FAILURE;
}
/* decode the JPEG2000 stream */
/* ---------------------- */
switch(parameters.decod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */
{
case J2K_CFMT: { /* JPEG-2000 codestream */
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_J2K);
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);
break;
}
case JPT_CFMT: /* JPEG 2000, JPIP */
{
case JPT_CFMT: { /* JPEG 2000, JPIP */
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JPT);
break;
@@ -1330,25 +1286,21 @@ int main(int argc, char **argv)
/* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &(parameters.core)) ) {
fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n");
destroy_parameters(&parameters);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
failed = 1; goto fin;
return EXIT_FAILURE;
}
if( parameters.num_threads >= 1 && !opj_codec_set_threads(l_codec, parameters.num_threads) ) {
fprintf(stderr, "ERROR -> opj_decompress: failed to set number of threads\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
failed = 1; goto fin;
}
/* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(l_stream, l_codec, &image)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
destroy_parameters(&parameters);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
failed = 1; goto fin;
return EXIT_FAILURE;
}
if (!parameters.nb_tile_to_decode) {
@@ -1356,22 +1308,23 @@ int main(int argc, char **argv)
if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0,
(OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n");
destroy_parameters(&parameters);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
failed = 1; goto fin;
return EXIT_FAILURE;
}
/* Get the decoded image */
if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec, l_stream))) {
fprintf(stderr,"ERROR -> opj_decompress: failed to decode image!\n");
destroy_parameters(&parameters);
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
failed = 1; goto fin;
return EXIT_FAILURE;
}
}
else {
} else {
/* It is just here to illustrate how to use the resolution after set parameters */
/*if (!opj_set_decoded_resolution_factor(l_codec, 5)) {
@@ -1379,15 +1332,16 @@ int main(int argc, char **argv)
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
failed = 1; goto fin;
return EXIT_FAILURE;
}*/
if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to decode tile!\n");
destroy_parameters(&parameters);
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
failed = 1; goto fin;
return EXIT_FAILURE;
}
fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index);
}
@@ -1407,11 +1361,9 @@ int main(int argc, char **argv)
if(image->color_space == OPJ_CLRSPC_SYCC) {
color_sycc_to_rgb(image);
}
else if((image->color_space == OPJ_CLRSPC_CMYK) && (parameters.cod_format != TIF_DFMT)){
} else if((image->color_space == OPJ_CLRSPC_CMYK) && (parameters.cod_format != TIF_DFMT)) {
color_cmyk_to_rgb(image);
}
else if(image->color_space == OPJ_CLRSPC_EYCC){
} else if(image->color_space == OPJ_CLRSPC_EYCC) {
color_esycc_to_rgb(image);
}
@@ -1423,16 +1375,15 @@ int main(int argc, char **argv)
color_cielab_to_rgb(image);
#endif
free(image->icc_profile_buf);
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
image->icc_profile_buf = NULL;
image->icc_profile_len = 0;
}
/* Force output precision */
/* ---------------------- */
if (parameters.precision != NULL)
{
if (parameters.precision != NULL) {
OPJ_UINT32 compno;
for (compno = 0; compno < image->numcomps; ++compno)
{
for (compno = 0; compno < image->numcomps; ++compno) {
OPJ_UINT32 precno = compno;
OPJ_UINT32 prec;
@@ -1461,20 +1412,19 @@ int main(int argc, char **argv)
/* Upsample components */
/* ------------------- */
if (parameters.upsample)
{
if (parameters.upsample) {
image = upsample_image_components(image);
if (image == NULL) {
fprintf(stderr, "ERROR -> opj_decompress: failed to upsample image components!\n");
destroy_parameters(&parameters);
opj_destroy_codec(l_codec);
failed = 1; goto fin;
return EXIT_FAILURE;
}
}
/* Force RGB output */
/* ---------------- */
if (parameters.force_rgb)
{
if (parameters.force_rgb) {
switch (image->color_space) {
case OPJ_CLRSPC_SRGB:
break;
@@ -1489,8 +1439,9 @@ int main(int argc, char **argv)
}
if (image == NULL) {
fprintf(stderr, "ERROR -> opj_decompress: failed to convert to RGB image!\n");
destroy_parameters(&parameters);
opj_destroy_codec(l_codec);
failed = 1; goto fin;
return EXIT_FAILURE;
}
}
@@ -1501,8 +1452,7 @@ int main(int argc, char **argv)
if (imagetopnm(image, parameters.outfile, parameters.split_pnm)) {
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
} else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -1511,8 +1461,7 @@ int main(int argc, char **argv)
if(imagetopgx(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
} else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -1521,8 +1470,7 @@ int main(int argc, char **argv)
if(imagetobmp(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
} else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -1531,8 +1479,7 @@ int main(int argc, char **argv)
if(imagetotif(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
} else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -1541,8 +1488,7 @@ int main(int argc, char **argv)
if(imagetoraw(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Error generating raw file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
} else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -1551,8 +1497,7 @@ int main(int argc, char **argv)
if(imagetorawl(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Error generating rawl file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
} else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -1561,8 +1506,7 @@ int main(int argc, char **argv)
if(imagetotga(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Error generating tga file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
} else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -1571,8 +1515,7 @@ int main(int argc, char **argv)
if(imagetopng(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Error generating png file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
} else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -1599,17 +1542,10 @@ int main(int argc, char **argv)
if(failed) (void)remove(parameters.outfile); /* ignore return value */
}
fin:
destroy_parameters(&parameters);
if(failed && img_fol.imgdirpath) free(img_fol.imgdirpath);
if(dirptr){
if(dirptr->filename) free(dirptr->filename);
if(dirptr->filename_buf) free(dirptr->filename_buf);
free(dirptr);
}
if (numDecompressedImages) {
fprintf(stdout, "decode time: %d ms\n", (int)( (tCumulative * 1000.0) / (OPJ_FLOAT64)numDecompressedImages));
}
return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}
/*end main()*/
/*end main*/

View File

@@ -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 void decode_help_display(void) {
static void decode_help_display(void)
{
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 has been compiled against openjp2 library v%s.\n\n",opj_version());
@@ -117,7 +118,8 @@ static void decode_help_display(void) {
}
/* -------------------------------------------------------------------------- */
static int get_num_images(char *imgdirpath){
static int get_num_images(char *imgdirpath)
{
DIR *dir;
struct dirent* content;
int num_images = 0;
@@ -140,7 +142,8 @@ static int get_num_images(char *imgdirpath){
}
/* -------------------------------------------------------------------------- */
static int load_images(dircnt_t *dirptr, char *imgdirpath){
static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir;
struct dirent* content;
int i = 0;
@@ -167,7 +170,8 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
}
/* -------------------------------------------------------------------------- */
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" };
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 };
@@ -187,7 +191,8 @@ static int get_file_format(const char *filename) {
}
/* -------------------------------------------------------------------------- */
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]="";
@@ -251,12 +256,10 @@ static int infile_format(const char *fname)
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
magic_format = JP2_CFMT;
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_s = ".j2k or .jpc or .j2c";
}
else
} else
return -1;
if (magic_format == ext_format)
@@ -276,7 +279,8 @@ static int infile_format(const char *fname)
* 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[]= {
{"ImgDir",REQ_ARG, NULL ,'y'}
@@ -290,8 +294,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
case 'i': { /* input file */
char *infile = opj_optarg;
parameters->decod_format = infile_format(infile);
switch(parameters->decod_format) {
@@ -317,8 +320,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ------------------------------------------------------ */
case 'o': /* output file */
{
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;
@@ -338,12 +340,8 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ------------------------------------------------------ */
case 'y': /* Image Directory path */
{
case 'y': { /* Image Directory path */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
if(img_fol->imgdirpath == NULL){
return 1;
}
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
@@ -351,8 +349,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ----------------------------------------------------- */
case 'v': /* Verbose mode */
{
case 'v': { /* Verbose mode */
parameters->m_verbose = 1;
}
break;
@@ -397,21 +394,24 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/**
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);
}
/**
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);
}
/**
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);
}
@@ -436,6 +436,12 @@ int main(int argc, char *argv[])
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
#ifdef MSD
OPJ_BOOL l_go_on = OPJ_TRUE;
OPJ_UINT32 l_max_data_size = 1000;
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
#endif
/* Set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
@@ -445,8 +451,6 @@ int main(int argc, char *argv[])
/* Parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
if(img_fol.imgdirpath) free(img_fol.imgdirpath);
return EXIT_FAILURE;
}
@@ -456,31 +460,25 @@ int main(int argc, char *argv[])
num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(!dirptr){
return EXIT_FAILURE;
}
if(dirptr) {
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){
goto fails;
if(!dirptr->filename_buf) {
return EXIT_FAILURE;
}
for(it_image=0; it_image<num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
}
}
if(load_images(dirptr,img_fol.imgdirpath)==1) {
goto fails;
return EXIT_FAILURE;
}
if (num_images==0) {
fprintf(stdout,"Folder is empty\n");
goto fails;
return EXIT_FAILURE;
}
} else {
num_images=1;
@@ -491,10 +489,9 @@ int main(int argc, char *argv[])
fout = fopen(parameters.outfile,"w");
if (!fout) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
goto fails;
return EXIT_FAILURE;
}
}
else
} else
fout = stdout;
/* Read the header of each image one by one */
@@ -515,27 +512,24 @@ int main(int argc, char *argv[])
l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
goto fails;
return EXIT_FAILURE;
}
/* Read the JPEG2000 stream */
/* ------------------------ */
switch(parameters.decod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */
{
case J2K_CFMT: { /* JPEG-2000 codestream */
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_J2K);
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);
break;
}
case JPT_CFMT: /* JPEG 2000, JPIP */
{
case JPT_CFMT: { /* JPEG 2000, JPIP */
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JPT);
break;
@@ -557,7 +551,7 @@ int main(int argc, char *argv[])
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
fclose(fout);
goto fails;
return EXIT_FAILURE;
}
/* Read the main header of the codestream and if necessary the JP2 boxes*/
@@ -567,7 +561,7 @@ int main(int argc, char *argv[])
opj_destroy_codec(l_codec);
opj_image_destroy(image);
fclose(fout);
goto fails;
return EXIT_FAILURE;
}
opj_dump_codec(l_codec, img_fol.flag, fout );
@@ -599,12 +593,4 @@ int main(int argc, char *argv[])
fclose(fout);
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

@@ -365,8 +365,7 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
@@ -619,8 +618,7 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_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
* more entries could be retrieved. */
return 0;
@@ -656,7 +654,8 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
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);

View File

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

View File

@@ -45,7 +45,8 @@
void dump_volume(FILE *fd, opj_volume_t * vol) {
void dump_volume(FILE *fd, opj_volume_t * vol)
{
int compno;
fprintf(fd, "volume {\n");
fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, vol->z0,vol->x1, vol->y1, vol->z1);
@@ -66,7 +67,8 @@ void dump_volume(FILE *fd, opj_volume_t * vol) {
*
* log2(a)
*/
static int int_floorlog2(int a) {
static int int_floorlog2(int a)
{
int l;
for (l = 0; a > 1; l++) {
a >>= 1;
@@ -79,7 +81,8 @@ static int int_floorlog2(int a) {
*
* a divided by 2^b
*/
static int int_ceildivpow2(int a, int b) {
static int int_ceildivpow2(int a, int b)
{
return (a + (1 << b) - 1) >> b;
}
@@ -88,7 +91,8 @@ static int int_ceildivpow2(int a, int b) {
*
* a divided by b
*/
static int int_ceildiv(int a, int b) {
static int int_ceildiv(int a, int b)
{
return (a + b - 1) / b;
}
@@ -150,7 +154,8 @@ static unsigned int LongSwap (unsigned int i)
}
/*****************************************/
opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
{
FILE *f = NULL;
int w, h, prec;
@@ -196,7 +201,8 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
/*Fetch only the path */
strcpy(tmpdirpath,relpath);
if ((tmp = strrchr(tmpdirpath,'/')) != NULL) {
tmp++; *tmp='\0';
tmp++;
*tmp='\0';
strcpy(dirpath,tmpdirpath);
} else {
strcpy(dirpath,"./");
@@ -222,8 +228,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
}
/*Read all .pgx files of directory */
while ( (direntp = readdir( dirp )) != NULL )
{
while ( (direntp = readdir( dirp )) != NULL ) {
/* Found a directory, but ignore . and .. */
if(strcmp(".",direntp->d_name) == 0 || strcmp("..",direntp->d_name) == 0)
continue;
@@ -241,7 +246,8 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
tmpno[i++] = *tmp2;
point = tmp2;
tmp2 = strpbrk (tmp2+1,"0123456789");
}tmpno[i]='\0';
}
tmpno[i]='\0';
/*Comprobamos que no estamos leyendo algo raro como pattern.jp3d*/
if ((point = strpbrk (point,".")) == NULL) {
@@ -270,8 +276,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
return NULL;
}*/
for (s=0;s<sliceno;s++)
{
for (s=0; s<sliceno; s++) {
int pos = maxslice == sliceno ? s: pgxslicepos[s];
f = fopen(pgxfiles[pos], "rb");
if (!f) {
@@ -379,7 +384,8 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
}
int volumetopgx(opj_volume_t * volume, char *outfile) {
int volumetopgx(opj_volume_t * volume, char *outfile)
{
int w, wr, wrr, h, hr, hrr, l, lr, lrr;
int i, j, compno, offset, sliceno;
FILE *fdest = NULL;
@@ -466,7 +472,8 @@ BIN IMAGE FORMAT
<<-- <<-- <<-- <<-- */
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 subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy;
int subsampling_dz = parameters->subsampling_dz;
@@ -678,7 +685,8 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
return volume;
}
int volumetobin(opj_volume_t * volume, char *outfile) {
int volumetobin(opj_volume_t * volume, char *outfile)
{
int w, wr, wrr, h, hr, hrr, l, lr, lrr, max;
int i,j, compno, nbytes;
int offset, sliceno;
@@ -764,7 +772,8 @@ int volumetobin(opj_volume_t * volume, char *outfile) {
IMG IMAGE FORMAT
<<-- <<-- <<-- <<-- */
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters)
{
int subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy;
int subsampling_dz = parameters->subsampling_dz;
@@ -795,7 +804,8 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
/*Fetch only the path */
strcpy(tmpdirpath,fileimg);
if ((tmp = strrchr(tmpdirpath,'/')) != NULL) {
tmp++; *tmp='\0';
tmp++;
*tmp='\0';
strcpy(dirpath,tmpdirpath);
} else {
strcpy(dirpath,"./");

View File

@@ -55,7 +55,8 @@ char *optarg; /* argument associated with option */
* getopt --
* 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 */

View File

@@ -46,7 +46,8 @@
/* ----------------------------------------------------------------------- */
void encode_help_display() {
void encode_help_display()
{
fprintf(stdout,"List of parameters for the JPEG2000 Part 10 encoder:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");
@@ -166,7 +167,8 @@ void encode_help_display() {
}
OPJ_PROG_ORDER give_progression(char progression[4]) {
OPJ_PROG_ORDER give_progression(char progression[4])
{
if(strncmp(progression, "LRCP", 4) == 0) {
return LRCP;
}
@@ -186,7 +188,8 @@ OPJ_PROG_ORDER give_progression(char progression[4]) {
return PROG_UNKNOWN;
}
OPJ_TRANSFORM give_transform(char transform[4]) {
OPJ_TRANSFORM give_transform(char transform[4])
{
if(strncmp(transform, "2DWT", 4) == 0) {
return TRF_2D_DWT;
}
@@ -196,7 +199,8 @@ OPJ_TRANSFORM give_transform(char transform[4]) {
return TRF_UNKNOWN;
}
OPJ_ENTROPY_CODING give_coding(char coding[3]) {
OPJ_ENTROPY_CODING give_coding(char coding[3])
{
if(strncmp(coding, "2EB", 3) == 0) {
return ENCOD_2EB;
@@ -214,7 +218,8 @@ OPJ_ENTROPY_CODING give_coding(char coding[3]) {
return ENCOD_UNKNOWN;
}
int get_file_format(char *filename) {
int get_file_format(char *filename)
{
int i;
static const char *extension[] = {"pgx", "bin", "img", "j3d", "jp3d", "j2k"};
static const int format[] = { PGX_DFMT, BIN_DFMT, IMG_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT};
@@ -233,7 +238,8 @@ int get_file_format(char *filename) {
/* ------------------------------------------------------------------------------------ */
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) {
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
{
int i, value;
/* parse the command line */
@@ -243,8 +249,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
case 'i': { /* input file */
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -264,8 +269,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break;
/* ----------------------------------------------------- */
case 'm': /* input IMG file */
{
case 'm': { /* input IMG file */
char *imgfile = opj_optarg;
int imgformat = get_file_format(imgfile);
switch(imgformat) {
@@ -282,8 +286,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break;
/* ----------------------------------------------------- */
case 'o': /* output file */
{
case 'o': { /* output file */
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -303,8 +306,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'r': /* define compression rates for each layer */
{
case 'r': { /* define compression rates for each layer */
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
@@ -321,8 +323,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'q': /* define distorsion (PSNR) for each layer */
{
case 'q': { /* define distorsion (PSNR) for each layer */
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
@@ -339,8 +340,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'f':
{
case 'f': {
fprintf(stdout, "/---------------------------------------------------\\\n");
fprintf(stdout, "| Fixed layer allocation option not implemented !! |\n");
fprintf(stdout, "\\---------------------------------------------------/\n");
@@ -388,8 +388,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 't': /* tiles */
{
case 't': { /* tiles */
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tdx, &parameters->cp_tdy, &parameters->cp_tdz) !=3) {
fprintf(stdout, "[ERROR] '-t' 'dimensions of tiles' argument error ! [-t tdx,tdy,tdz]\n");
return 1;
@@ -400,8 +399,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'n': /* resolution */
{
case 'n': { /* resolution */
int aux;
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->numresolution[0], &parameters->numresolution[1], &parameters->numresolution[2]);
if (aux == 2)
@@ -418,8 +416,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break;
/* ----------------------------------------------------- */
case 'c': /* precinct dimension */
{
case 'c': { /* precinct dimension */
char sep;
int res_spec = 0;
int aux;
@@ -434,16 +431,14 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
}
while (sep == ',');
} while (sep == ',');
parameters->res_spec = res_spec; /* number of precinct size specifications */
}
break;
/* ----------------------------------------------------- */
case 'b': /* code-block dimension */
{
case 'b': { /* code-block dimension */
int cblockw_init = 0, cblockh_init = 0, cblockl_init = 0;
if (sscanf(opj_optarg, "%d,%d,%d", &cblockw_init, &cblockh_init, &cblockl_init) != 3) {
fprintf(stdout, "[ERROR] '-b' 'dimensions of codeblocks' argument error ! [-b cblkx,cblky,cblkz]\n");
@@ -461,8 +456,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'x': /* creation of index file */
{
case 'x': { /* creation of index file */
char *index = opj_optarg;
strncpy(parameters->index, index, MAX_PATH);
parameters->index_on = 1;
@@ -471,8 +465,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'p': /* progression order */
{
case 'p': { /* progression order */
char progression[4];
strncpy(progression, opj_optarg, 4);
@@ -486,8 +479,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
{
case 's': { /* subsampling factor */
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->subsampling_dx, &parameters->subsampling_dy, &parameters->subsampling_dz) != 3) {
fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n");
return 1;
@@ -497,8 +489,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */
{
case 'd': { /* coordonnate of the reference grid */
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->volume_offset_x0, &parameters->volume_offset_y0, &parameters->volume_offset_z0) != 3) {
fprintf(stdout, "[ERROR] -d 'coordonnate of the reference grid' argument error !! [-d x0,y0,z0]\n");
return 1;
@@ -508,8 +499,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'h': /* display an help description */
{
case 'h': { /* display an help description */
encode_help_display();
return 1;
}
@@ -517,8 +507,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'P': /* POC */
{
case 'P': { /* POC */
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@@ -550,24 +539,21 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'S': /* SOP marker */
{
case 'S': { /* SOP marker */
parameters->csty |= 0x02;
}
break;
/* ------------------------------------------------------ */
case 'E': /* EPH marker */
{
case 'E': { /* EPH marker */
parameters->csty |= 0x04;
}
break;
/* ------------------------------------------------------ */
case 'M': /* Codification mode switch */
{
case 'M': { /* Codification mode switch */
fprintf(stdout, "[INFO] Mode switch option not fully tested !!\n");
value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) {
@@ -582,8 +568,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'D': /* DCO */
{
case 'D': { /* DCO */
if (sscanf(opj_optarg, "%d", &parameters->dcoffset) != 1) {
fprintf(stdout, "[ERROR] DC offset error !! [-D %d]\n",parameters->dcoffset);
return 1;
@@ -593,8 +578,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'R': /* ROI */
{
case 'R': { /* ROI */
if (sscanf(opj_optarg, "OI:c=%d,U=%d", &parameters->roi_compno, &parameters->roi_shift) != 2) {
fprintf(stdout, "[ERROR] ROI error !! [-ROI:c='compno',U='shift']\n");
return 1;
@@ -604,8 +588,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'l': /* Tile offset */
{
case 'l': { /* Tile offset */
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tx0, &parameters->cp_ty0, &parameters->cp_tz0) != 3) {
fprintf(stdout, "[ERROR] -l 'tile offset' argument error !! [-l X0,Y0,Z0]");
return 1;
@@ -630,8 +613,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
------------------------------------------------------ */
case 'C': /* Coding of transformed data */
{
case 'C': { /* Coding of transformed data */
char coding[3];
strncpy(coding, opj_optarg, 3);
@@ -645,8 +627,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'I': /* reversible or not */
{
case 'I': { /* reversible or not */
parameters->irreversible = 1;
}
break;
@@ -754,28 +735,32 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/**
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);
}
/**
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);
}
/**
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);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
bool bSuccess;
bool delete_comment = true;
opj_cparameters_t parameters; /* compression parameters */

View File

@@ -149,7 +149,8 @@ static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
return sum;
}
void decode_help_display() {
void decode_help_display()
{
fprintf(stdout,"HELP\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@@ -195,7 +196,8 @@ void decode_help_display() {
/* -------------------------------------------------------------------------- */
int get_file_format(char *filename) {
int get_file_format(char *filename)
{
int i;
static const char *extension[] = {"pgx", "bin", "j3d", "jp3d", "j2k", "img"};
static const int format[] = { PGX_DFMT, BIN_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT, IMG_DFMT};
@@ -214,7 +216,8 @@ int get_file_format(char *filename) {
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters) {
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
{
/* parse the command line */
while (1) {
@@ -222,8 +225,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
case 'i': { /* input file */
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -241,8 +243,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
}
break;
case 'm': /* img file */
{
case 'm': { /* img file */
char *imgfile = opj_optarg;
int imgformat = get_file_format(imgfile);
switch(imgformat) {
@@ -260,8 +261,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */
case 'o': /* output file */
{
case 'o': { /* output file */
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -281,8 +281,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */
case 'O': /* Original image for PSNR computing */
{
case 'O': { /* Original image for PSNR computing */
char *original = opj_optarg;
parameters->orig_format = get_file_format(original);
switch(parameters->orig_format) {
@@ -301,8 +300,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */
case 'r': /* reduce option */
{
case 'r': { /* reduce option */
/*sscanf(opj_optarg, "%d, %d, %d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);*/
int aux;
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);
@@ -321,32 +319,28 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */
case 'l': /* layering option */
{
case 'l': { /* layering option */
sscanf(opj_optarg, "%d", &parameters->cp_layer);
}
break;
/* ----------------------------------------------------- */
case 'B': /* BIGENDIAN vs. LITTLEENDIAN */
{
case 'B': { /* BIGENDIAN vs. LITTLEENDIAN */
parameters->bigendian = 1;
}
break;
/* ----------------------------------------------------- */
case 'L': /* BIGENDIAN vs. LITTLEENDIAN */
{
case 'L': { /* BIGENDIAN vs. LITTLEENDIAN */
parameters->decod_format = LSE_CFMT;
}
break;
/* ----------------------------------------------------- */
case 'h': /* display an help description */
{
case 'h': { /* display an help description */
decode_help_display();
return 1;
}
@@ -375,27 +369,31 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/**
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);
}
/**
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);
}
/**
sample debug callback expecting no client object
*/
void info_callback(const char *msg, void *client_data) {
void info_callback(const char *msg, void *client_data)
{
fprintf(stdout, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
@@ -499,8 +497,12 @@ int main(int argc, char **argv) {
case PGX_DFMT: /* PGX */
if (strcmp("NULL",parameters.original) != 0) {
fprintf(stdout,"Loading original file %s \n",parameters.original);
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0;
cparameters.subsampling_dx = 1;
cparameters.subsampling_dy = 1;
cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;
cparameters.volume_offset_y0 = 0;
cparameters.volume_offset_z0 = 0;
original = pgxtovolume(parameters.original,&cparameters);
}
break;
@@ -508,8 +510,12 @@ int main(int argc, char **argv) {
case BIN_DFMT: /* BMP */
if (strcmp("NULL",parameters.original) != 0 && strcmp("NULL",parameters.imgfile) != 0) {
fprintf(stdout,"Loading original file %s %s\n",parameters.original,parameters.imgfile);
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0;
cparameters.subsampling_dx = 1;
cparameters.subsampling_dy = 1;
cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;
cparameters.volume_offset_y0 = 0;
cparameters.volume_offset_z0 = 0;
original = bintovolume(parameters.original,parameters.imgfile,&cparameters);
}
break;

View File

@@ -364,8 +364,7 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
@@ -618,8 +617,7 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_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
* more entries could be retrieved. */
return 0;
@@ -655,7 +653,8 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
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);

View File

@@ -54,7 +54,8 @@
WSADATA initialisation_win32;
#endif
int main(int argc, char *argv[]){
int main(int argc, char *argv[])
{
dec_server_record_t *server_record;
client_t client;

View File

@@ -106,15 +106,12 @@ int main(int argc,char *argv[])
}
ext = strrchr( argv[2], '.' );
if( ext )
{
if( ext ) {
/* strcasecmp ? */
if( strcmp(ext, ".jp2" ) == 0 )
{
if( strcmp(ext, ".jp2" ) == 0 ) {
return jpip_to_jp2(argv);
}
if( strcmp(ext, ".j2k" ) == 0 )
{
if( strcmp(ext, ".j2k" ) == 0 ) {
return jpip_to_j2k(argv);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -45,7 +45,8 @@ Write a structured index to a file
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
int write_index_file(opj_codestream_info_t *cstr_info, char *index)
{
int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL;
double total_disto = 0;

View File

@@ -88,7 +88,8 @@ typedef struct img_folder{
float *rates;
} img_fol_t;
static void encode_help_display(void) {
static void encode_help_display(void)
{
fprintf(stdout,"HELP for opj_jpwl_compress\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@@ -327,7 +328,8 @@ static void encode_help_display(void) {
fprintf(stdout,"TotalDisto\n\n");
}
static OPJ_PROG_ORDER give_progression(const char progression[4]) {
static OPJ_PROG_ORDER give_progression(const char progression[4])
{
if(strncmp(progression, "LRCP", 4) == 0) {
return LRCP;
}
@@ -347,7 +349,8 @@ static OPJ_PROG_ORDER give_progression(const char progression[4]) {
return PROG_UNKNOWN;
}
static unsigned int get_num_images(char *imgdirpath){
static unsigned int get_num_images(char *imgdirpath)
{
DIR *dir;
struct dirent* content;
unsigned int num_images = 0;
@@ -369,7 +372,8 @@ static unsigned int get_num_images(char *imgdirpath){
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;
int i = 0;
@@ -394,7 +398,8 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
return 0;
}
static int get_file_format(char *filename) {
static int get_file_format(char *filename)
{
unsigned int i;
static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "j2c", "jpc"
@@ -414,14 +419,16 @@ static int get_file_format(char *filename) {
return -1;
}
static char * get_file_name(char *name){
static char * get_file_name(char *name)
{
char *fname;
fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char));
fname= strtok(name,".");
return fname;
}
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_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]="";
@@ -446,7 +453,8 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
return 0;
}
static int initialise_4K_poc(opj_poc_t *POC, int numres){
static int initialise_4K_poc(opj_poc_t *POC, int numres)
{
POC[0].tile = 1;
POC[0].resno0 = 0;
POC[0].compno0 = 0;
@@ -464,7 +472,8 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres){
return 2;
}
static void cinema_parameters(opj_cparameters_t *parameters){
static void cinema_parameters(opj_cparameters_t *parameters)
{
parameters->tile_size_on = OPJ_FALSE;
parameters->cp_tdx=1;
parameters->cp_tdy=1;
@@ -490,14 +499,16 @@ static void cinema_parameters(opj_cparameters_t *parameters){
/* No ROI */
parameters->roi_compno = -1;
parameters->subsampling_dx = 1; parameters->subsampling_dy = 1;
parameters->subsampling_dx = 1;
parameters->subsampling_dy = 1;
/* 9-7 transform */
parameters->irreversible = 1;
}
static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){
static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol)
{
int i;
float temp_rate;
@@ -583,7 +594,8 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag
/* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename)
{
int i, j, totlen, c;
opj_option_t long_option[]= {
{"cinema2K",REQ_ARG, NULL ,'w'},
@@ -614,8 +626,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
case 'i': { /* input file */
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -640,8 +651,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'o': /* output file */
{
case 'o': { /* output file */
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -657,8 +667,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
break;
/* ----------------------------------------------------- */
case 'O': /* output format */
{
case 'O': { /* output format */
char outformat[50];
char *of = opj_optarg;
sprintf(outformat,".%s",of);
@@ -680,8 +689,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */
{
case 'r': { /* rates rates/distorsion */
char *s = opj_optarg;
parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
@@ -700,28 +708,24 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'F': /* Raw image format parameters */
{
case 'F': { /* Raw image format parameters */
char signo;
char *s = opj_optarg;
if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) {
if (signo == 's') {
raw_cp->rawSigned = OPJ_TRUE;
fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Signed\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth);
}
else if (signo == 'u') {
} else if (signo == 'u') {
raw_cp->rawSigned = OPJ_FALSE;
fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Unsigned\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth);
}
else {
} else {
fprintf(stderr,"\nError: invalid raw image parameters: Unknown sign of raw file\n");
fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
fprintf(stderr,"Aborting\n");
}
}
else {
} else {
fprintf(stderr,"\nError: invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
@@ -734,8 +738,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'q': /* add fixed_quality */
{
case 'q': { /* add fixed_quality */
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
@@ -753,8 +756,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* dda */
/* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */
{
case 'f': { /* mod fixed_quality (before : -q) */
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
@@ -800,8 +802,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 't': /* tiles */
{
case 't': { /* tiles */
sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE;
}
@@ -809,15 +810,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'n': /* resolution */
{
case 'n': { /* resolution */
sscanf(opj_optarg, "%d", &parameters->numresolution);
}
break;
/* ----------------------------------------------------- */
case 'c': /* precinct dimension */
{
case 'c': { /* precinct dimension */
char sep;
int res_spec = 0;
@@ -829,16 +828,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
}
while (sep == ',');
} while (sep == ',');
parameters->res_spec = res_spec;
}
break;
/* ----------------------------------------------------- */
case 'b': /* code-block dimension */
{
case 'b': { /* code-block dimension */
int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@@ -855,8 +852,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'x': /* creation of index file */
{
case 'x': { /* creation of index file */
char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
}
@@ -864,8 +860,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'p': /* progression order */
{
case 'p': { /* progression order */
char progression[4];
strncpy(progression, opj_optarg, 4);
@@ -880,8 +875,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
{
case 's': { /* subsampling factor */
if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,
&parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@@ -892,8 +886,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */
{
case 'd': { /* coordonnate of the reference grid */
if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,
&parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@@ -911,8 +904,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'P': /* POC */
{
case 'P': { /* POC */
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@@ -939,24 +931,21 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'S': /* SOP marker */
{
case 'S': { /* SOP marker */
parameters->csty |= 0x02;
}
break;
/* ------------------------------------------------------ */
case 'E': /* EPH marker */
{
case 'E': { /* EPH marker */
parameters->csty |= 0x04;
}
break;
/* ------------------------------------------------------ */
case 'M': /* Mode switch pas tous au point !! */
{
case 'M': { /* Mode switch pas tous au point !! */
int value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
@@ -970,8 +959,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'R': /* ROI */
{
case 'R': { /* ROI */
if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,
&parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
@@ -982,8 +970,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'T': /* Tile offset */
{
case 'T': { /* Tile offset */
if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
@@ -993,8 +980,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'C': /* add a comment */
{
case 'C': { /* add a comment */
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) {
strcpy(parameters->cp_comment, opj_optarg);
@@ -1005,16 +991,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'I': /* reversible or not */
{
case 'I': { /* reversible or not */
parameters->irreversible = 1;
}
break;
/* ------------------------------------------------------ */
case 'u': /* Tile part generation*/
{
case 'u': { /* Tile part generation*/
parameters->tp_flag = opj_optarg[0];
parameters->tp_on = 1;
}
@@ -1022,8 +1006,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'z': /* Image Directory path */
{
case 'z': { /* Image Directory path */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
@@ -1032,8 +1015,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'w': /* Digital Cinema 2K profile compliance*/
{
case 'w': { /* Digital Cinema 2K profile compliance*/
int fps=0;
sscanf(opj_optarg,"%d",&fps);
if(fps == 24) {
@@ -1052,8 +1034,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'y': /* Digital Cinema 4K profile compliance*/
{
case 'y': { /* Digital Cinema 4K profile compliance*/
parameters->cp_cinema = CINEMA4K_24;
fprintf(stdout,"CINEMA 4K compliant codestream\n");
parameters->cp_rsiz = CINEMA4K;
@@ -1066,8 +1047,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#ifdef USE_JPWL
/* ------------------------------------------------------ */
case 'W': /* JPWL capabilities switched on */
{
case 'W': { /* JPWL capabilities switched on */
char *token = NULL;
int hprot, pprot, sens, addr, size, range;
@@ -1383,8 +1363,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* <<UniPG */
/* ------------------------------------------------------ */
case 'J': /* jpip on */
{
case 'J': { /* jpip on */
/*parameters->jpip_on = OPJ_TRUE;*/
}
break;
@@ -1472,28 +1451,32 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/**
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);
}
/**
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);
}
/**
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);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
opj_bool bSuccess;
opj_cparameters_t parameters; /* compression parameters */
img_fol_t img_fol;
@@ -1670,8 +1653,7 @@ int main(int argc, char **argv) {
/* Can happen if input file is TIFF or PNG
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
if( !image)
{
if( !image) {
fprintf(stderr, "Unable to load file: got no image\n");
return 1;
}

View File

@@ -91,7 +91,8 @@ typedef struct img_folder{
} img_fol_t;
void decode_help_display(void) {
void decode_help_display(void)
{
fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@@ -150,7 +151,8 @@ void decode_help_display(void) {
/* -------------------------------------------------------------------------- */
int get_num_images(char *imgdirpath){
int get_num_images(char *imgdirpath)
{
DIR *dir;
struct dirent* content;
int num_images = 0;
@@ -171,7 +173,8 @@ int get_num_images(char *imgdirpath){
return num_images;
}
int load_images(dircnt_t *dirptr, char *imgdirpath){
int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir;
struct dirent* content;
int i = 0;
@@ -196,7 +199,8 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
return 0;
}
int get_file_format(char *filename) {
int get_file_format(char *filename)
{
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
@@ -215,7 +219,8 @@ int get_file_format(char *filename) {
return -1;
}
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
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]="";
@@ -241,7 +246,8 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
}
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename)
{
/* parse the command line */
int totlen, c;
opj_option_t long_option[]= {
@@ -264,8 +270,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
case 'i': { /* input file */
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -285,8 +290,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
case 'o': /* output file */
{
case 'o': { /* output file */
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -308,8 +312,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
case 'O': /* output format */
{
case 'O': { /* output format */
char outformat[50];
char *of = opj_optarg;
sprintf(outformat,".%s",of);
@@ -348,8 +351,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
case 'r': /* reduce option */
{
case 'r': { /* reduce option */
sscanf(opj_optarg, "%d", &parameters->cp_reduce);
}
break;
@@ -357,8 +359,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
case 'l': /* layering option */
{
case 'l': { /* layering option */
sscanf(opj_optarg, "%d", &parameters->cp_layer);
}
break;
@@ -371,16 +372,14 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ------------------------------------------------------ */
case 'y': /* Image Directory path */
{
case 'y': { /* Image Directory path */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */
case 'x': /* Creation of index file */
{
case 'x': { /* Creation of index file */
char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
}
@@ -389,8 +388,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* UniPG>> */
#ifdef USE_JPWL
case 'W': /* activate JPWL correction */
{
case 'W': { /* activate JPWL correction */
char *token = NULL;
token = strtok(opj_optarg, ",");
@@ -496,28 +494,32 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/**
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);
}
/**
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);
}
/**
sample debug callback expecting no client object
*/
void info_callback(const char *msg, void *client_data) {
void info_callback(const char *msg, void *client_data)
{
(void)client_data;
fprintf(stdout, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
opj_dparameters_t parameters; /* decompression parameters */
img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */
@@ -601,8 +603,7 @@ int main(int argc, char **argv) {
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length);
if (fread(src, 1, file_length, fsrc) != (size_t)file_length)
{
if (fread(src, 1, file_length, fsrc) != (size_t)file_length) {
free(src);
fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
@@ -614,8 +615,7 @@ int main(int argc, char **argv) {
/* ---------------------- */
switch(parameters.decod_format) {
case J2K_CFMT:
{
case J2K_CFMT: {
/* JPEG-2000 codestream */
/* get a decoder handle */
@@ -657,8 +657,7 @@ int main(int argc, char **argv) {
}
break;
case JP2_CFMT:
{
case JP2_CFMT: {
/* JPEG 2000 compressed image data */
/* get a decoder handle */
@@ -700,8 +699,7 @@ int main(int argc, char **argv) {
}
break;
case JPT_CFMT:
{
case JPT_CFMT: {
/* JPEG 2000, JPIP */
/* get a decoder handle */
@@ -752,19 +750,18 @@ int main(int argc, char **argv) {
free(src);
src = NULL;
if(image->color_space == CLRSPC_SYCC)
{
if(image->color_space == CLRSPC_SYCC) {
color_sycc_to_rgb(image);
}
if(image->icc_profile_buf)
{
if(image->icc_profile_buf) {
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(image);
#endif
free(image->icc_profile_buf);
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
image->icc_profile_buf = NULL;
image->icc_profile_len = 0;
}
/* create output image */
@@ -773,8 +770,7 @@ int main(int argc, char **argv) {
case PXM_DFMT: /* PNM PGM PPM */
if (imagetopnm(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
} else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -782,8 +778,7 @@ int main(int argc, char **argv) {
case PGX_DFMT: /* PGX */
if(imagetopgx(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
} else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -791,8 +786,7 @@ int main(int argc, char **argv) {
case BMP_DFMT: /* BMP */
if(imagetobmp(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
} else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -800,8 +794,7 @@ int main(int argc, char **argv) {
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
} else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -809,8 +802,7 @@ int main(int argc, char **argv) {
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)) {
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
}
else {
} else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
@@ -818,8 +810,7 @@ int main(int argc, char **argv) {
case TGA_DFMT: /* TGA */
if(imagetotga(image, parameters.outfile)) {
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
}
else {
} else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
@@ -827,8 +818,7 @@ int main(int argc, char **argv) {
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)) {
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
}
else {
} else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;

View File

@@ -365,8 +365,7 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
@@ -619,8 +618,7 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_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
* more entries could be retrieved. */
return 0;
@@ -656,7 +654,8 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
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);

View File

@@ -89,10 +89,10 @@ void xml_write_init(BOOL n, BOOL t, BOOL r, BOOL d)
derived = d;
}
int xml_write_struct(FILE* file, FILE *xmlout, opj_mj2_t * movie, unsigned int sampleframe, char* stringDTD, opj_event_mgr_t *event_mgr) {
if(stringDTD != NULL)
int xml_write_struct(FILE* file, FILE *xmlout, opj_mj2_t * movie, unsigned int sampleframe, char* stringDTD, opj_event_mgr_t *event_mgr)
{
if(stringDTD != NULL) {
fprintf(xmlout,"<?xml version=\"1.0\" standalone=\"no\"?>\n");
/* stringDTD is known to start with "SYSTEM " or "PUBLIC " */
/* typical: SYSTEM mj2_to_metadata.dtd */
@@ -123,8 +123,7 @@ int xml_write_overall_header(FILE *file, FILE *xmlout, opj_mj2_t * movie, unsign
fprintf(xmlout, " <Brand>%s</Brand>\n", buf); /* 4 character; BR */
fprintf(xmlout, " <MinorVersion>%u</MinorVersion>\n", movie->minversion); /* 4 char; MinV */
fprintf(xmlout, " <CompatibilityList Count=\"%d\">\n",movie->num_cl);
for (i = movie->num_cl - 1; i > -1; i--) /* read routine stored in reverse order, so let's undo damage */
{
for (i = movie->num_cl - 1; i > -1; i--) { /* read routine stored in reverse order, so let's undo damage */
uint_to_chars(movie->cl[i], buf);
fprintf(xmlout, " <CompatibleBrand>%s</CompatibleBrand>\n", buf); /*4 characters, each CLi */
}
@@ -264,8 +263,7 @@ void uint_to_chars(unsigned int value, char* buf)
{
/* buf is at least char[5] */
int i;
for (i = 3; i >= 0; i--)
{
for (i = 3; i >= 0; i--) {
buf[i] = (value & 0x000000ff);
value = (value >> 8);
}
@@ -319,7 +317,8 @@ void xml_time_out(FILE* xmlout, time_t t)
/* ------------- */
void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie) {
void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie)
{
/* Compare with xml_write_udta */
#ifdef NOTYET
/* NO-OP so far. Optional UserData 'udta' (zero or one in moov or each trak)
@@ -346,7 +345,8 @@ void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie) {
#endif
}
void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie) {
void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie)
{
#ifdef NOTYET
/* NO-OP so far. There can be zero or more instances of free and/or skip
at the top level of the file. This may be a place where the user squirrel's metadata.
@@ -374,7 +374,8 @@ void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie) {
#endif
}
void xml_write_uuid(FILE* xmlout, opj_mj2_t * movie) {
void xml_write_uuid(FILE* xmlout, opj_mj2_t * movie)
{
/* Universal Unique IDs of 16 bytes. */
#ifdef NOTYET
/* NO-OP so far. There can be zero or more instances of private uuid boxes in a file.
@@ -411,8 +412,7 @@ void xml_write_trak(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
/* sampleframe is from user option -f. 1 = first frame */
/* sampleframe of 0 is a user requests: no jp2 header */
/* Treat out-of-bounds values in the same way */
if(sampleframe > 0 && sampleframe <= track->num_samples)
{
if(sampleframe > 0 && sampleframe <= track->num_samples) {
mj2_sample_t *sample;
unsigned int snum;
@@ -439,14 +439,12 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <!-- If both found, value read from MediaHeader is used. -->\n");
}
fprintf(xmlout, " <TrackID>%u</TrackID>\n", track->track_ID);
if(track->track_type==0) /* For visual track */
{
if(track->track_type==0) { /* For visual track */
fprintf(xmlout, " <TrackLayer>%d</TrackLayer>\n", track->layer);
if(notes)
fprintf(xmlout," <!-- front-to-back ordering of video tracks. 0 = normal, -1 is closer, etc. -->\n");
}
if(track->track_type!=0) /* volume irrelevant for visual track */
{
if(track->track_type!=0) { /* volume irrelevant for visual track */
#ifdef CURRENTSTRUCT
track->volume = track->volume << 8;
#endif
@@ -466,8 +464,7 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
track->volume = track->volume >> 8;
#endif
}
if(track->track_type==0)
{
if(track->track_type==0) {
/* Transformation matrix for video */
fprintf(xmlout, " <TransformationMatrix>\n");
if(notes) {
@@ -518,7 +515,8 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
/* ------------- */
void xml_write_udta(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum) {
void xml_write_udta(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum)
{
/* NO-OP so far. Optional UserData 'udta' (zero or one in moov or each trak)
can contain multiple Copyright 'cprt' with different language codes */
/* There may be nested non-standard boxes within udta */
@@ -590,14 +588,16 @@ void xml_write_mdia(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <Language>%s</Language>\n", buf); /* 3 chars */
fprintf(xmlout, " </MediaHeader>\n");
fprintf(xmlout, " <HandlerReference BoxType=\"hdlr\">\n");
switch(track->track_type)
{
switch(track->track_type) {
case 0:
fprintf(xmlout, " <HandlerType Code=\"vide\">video media track</HandlerType>\n"); break;
fprintf(xmlout, " <HandlerType Code=\"vide\">video media track</HandlerType>\n");
break;
case 1:
fprintf(xmlout, " <HandlerType Code=\"soun\">Sound</HandlerType>\n"); break;
fprintf(xmlout, " <HandlerType Code=\"soun\">Sound</HandlerType>\n");
break;
case 2:
fprintf(xmlout, " <HandlerType Code=\"hint\">Hint</HandlerType>\n"); break;
fprintf(xmlout, " <HandlerType Code=\"hint\">Hint</HandlerType>\n");
break;
}
if(notes) {
fprintf(xmlout, " <!-- String value shown is not actually read from file. -->\n");
@@ -605,8 +605,7 @@ void xml_write_mdia(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
}
fprintf(xmlout, " </HandlerReference>\n");
fprintf(xmlout, " <MediaInfoContainer BoxType=\"minf\">\n");
switch(track->track_type)
{
switch(track->track_type) {
case 0:
fprintf(xmlout, " <VideoMediaHeader BoxType=\"vmhd\">\n");
fprintf(xmlout, " <GraphicsMode>0x%02x</GraphicsMode>\n", track->graphicsmode);
@@ -724,8 +723,7 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <SampleTable BoxType=\"stbl\">\n");
if(notes)
fprintf(xmlout, " <!-- What follows are specific instances of generic SampleDescription BoxType=\"stsd\" -->\n");
switch(track->track_type)
{
switch(track->track_type) {
case 0:
// There could be multiple instances of this, but "entry_count" is just a local at read-time.
// And it's used wrong, too, as count of just visual type, when it's really all 3 types.
@@ -797,16 +795,15 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " </FieldCoding>\n");
fprintf(xmlout, " <MJP2_Profile BoxType=\"jp2p\" Count=\"%d\">\n",track->num_br);
for (i = 0; i < track->num_br; i++) /* read routine stored in reverse order, so let's undo damage */
{
for (i = 0; i < track->num_br; i++) { /* read routine stored in reverse order, so let's undo damage */
uint_to_chars(track->br[i], buf);
fprintf(xmlout, " <CompatibleBrand>%s</CompatibleBrand>\n", buf); /*4 characters, each CLi */
}
fprintf(xmlout, " </MJP2_Profile>\n");
fprintf(xmlout, " <MJP2_Prefix BoxType=\"jp2x\" Count=\"%d\">\n",track->num_jp2x);
for (i = 0; i < track->num_jp2x; i++)
{ // We'll probably need better formatting than this
for (i = 0; i < track->num_jp2x; i++) {
// We'll probably need better formatting than this
fprintf(xmlout, " <Data>0x%02x</Data>\n", track->jp2xdata[i]); /* Each entry is single byte */
}
fprintf(xmlout, " </MJP2_Prefix>\n");
@@ -843,9 +840,11 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " </MJP2_OriginalFormat>\n");
fprintf(xmlout, " </VisualSampleEntry>\n");
break;
case 1: case 2:
case 1:
case 2:
if(notes)
fprintf(xmlout, " <!-- mj2_to_metadata's data structure doesn't record this currently. -->\n"); break;
fprintf(xmlout, " <!-- mj2_to_metadata's data structure doesn't record this currently. -->\n");
break;
}
fprintf(xmlout, " <TimeToSample BoxType=\"stts\">\n");
fprintf(xmlout, " <SampleStatistics>\n");
@@ -1031,13 +1030,11 @@ int xml_out_frame(FILE* file, FILE* xmlout, mj2_sample_t *sample, unsigned int s
&& (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))
|| (img->numcomps == 1)) {
fprintf(xmlout, " <!-- file to a YUV movie in the normal manner. -->\n");
}
else if ((img->numcomps == 3) &&
} 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(xmlout, " <!-- YUV 4:4:4 file to a series of .bmp files. -->\n");
}
else {
} else {
fprintf(xmlout, " <!-- file whose image component dimension are unknown, to a series of .j2k files. -->\n");
}
}
@@ -1056,8 +1053,7 @@ void int16_to_3packedchars(short int value, char* buf)
/* This is to retrieve the 3-letter ASCII language code */
/* Each char is packed into 5 bits, as difference from 0x60 */
int i;
for (i = 2; i >= 0; i--)
{
for (i = 2; i >= 0; i--) {
buf[i] = (value & 0x001f) + 0x60;
value = (value >>5);
}
@@ -1144,7 +1140,8 @@ void xml_out_frame_cod(FILE* xmlout, opj_tcp_t *tcp)
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */
s++;
s++; /* shorten s to 10 spaces if main */
}
tccp = &(tcp->tccps[0]);
@@ -1225,7 +1222,8 @@ void xml_out_frame_coc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) /* Optional i
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */
s++;
s++; /* shorten s to 10 spaces if main */
}
firstcomp_tccp = &(tcp->tccps[0]);
@@ -1241,8 +1239,7 @@ void xml_out_frame_coc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) /* Optional i
else
fprintf(xmlout, "%s<!-- and any other component, with tile-part-header style values different from [0], as COC. -->\n", s);
}
for (compno = 1; compno < numcomps; compno++) /* spec says components are zero-based */
{
for (compno = 1; compno < numcomps; compno++) { /* spec says components are zero-based */
tccp = &tcp->tccps[compno];
if(same_component_style(firstcomp_tccp, tccp))
continue;
@@ -1344,7 +1341,8 @@ void xml_out_frame_qcd(FILE* xmlout, opj_tcp_t *tcp)
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */
s++;
s++; /* shorten s to 10 spaces if main */
}
/* Compare j2k_read_qcx */
@@ -1477,7 +1475,8 @@ void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */
s++;
s++; /* shorten s to 10 spaces if main */
}
firstcomp_tccp = &(tcp->tccps[0]);
@@ -1493,8 +1492,7 @@ void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
else
fprintf(xmlout, "%s<!-- and any other component, with tile-part-header quantization values different from [0], as QCC. -->\n", s);
}
for (compno = 1; compno < numcomps; compno++) /* spec says components are zero-based */
{
for (compno = 1; compno < numcomps; compno++) { /* spec says components are zero-based */
tccp = &(tcp->tccps[compno]);
if(same_component_quantization(firstcomp_tccp, tccp))
continue;
@@ -1661,7 +1659,8 @@ void xml_out_frame_rgn(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */
s++;
s++; /* shorten s to 10 spaces if main */
}
for(compno = 0; compno < numcomps; compno++) {
@@ -1686,14 +1685,16 @@ void xml_out_frame_rgn(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
/* ------------- */
void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) { /* Progression Order Change */
void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) /* Progression Order Change */
{
/* Compare j2k_read_poc() */
int i;
opj_poc_t *poc;
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */
s++;
s++; /* shorten s to 10 spaces if main */
}
if(tcp->POC != 1)
@@ -1739,7 +1740,8 @@ void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) { /* Progression Order Chan
/* Suppress PPM and PPT since we're not showing data from the third option, namely within the codestream, and
that's evidently what frames_to_mj2 uses. And a hex dump isn't so useful anyway */
void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) { /* For main header, not tile-part (which uses PPT instead). */
void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) /* For main header, not tile-part (which uses PPT instead). */
{
/* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */
/* Use of PPM and PPT are mutually exclusive. */
/* Compare j2k_read_ppm() */
@@ -1770,7 +1772,8 @@ void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) { /* For main header, not til
/* ------------- */
void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) { /* For tile-part header, not main (which uses PPM instead). */
void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) /* For tile-part header, not main (which uses PPM instead). */
{
/* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */
/* Use of PPM and PPT are mutually exclusive. */
/* Compare j2k_read_ppt() */
@@ -1803,7 +1806,8 @@ void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) { /* For tile-part header,
/* ------------- */
void xml_out_frame_tlm(FILE* xmlout) { /* opt, main header only. May be multiple. */
void xml_out_frame_tlm(FILE* xmlout) /* opt, main header only. May be multiple. */
{
/* Compare j2k_read_tlm()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
/* Main header indents are 10 spaces */
@@ -1811,7 +1815,8 @@ void xml_out_frame_tlm(FILE* xmlout) { /* opt, main header only. May be multipl
/* ------------- */
void xml_out_frame_plm(FILE* xmlout) { /* opt, main header only; can be used in conjunction with tile-part's PLT */
void xml_out_frame_plm(FILE* xmlout) /* opt, main header only; can be used in conjunction with tile-part's PLT */
{
/* NO-OP. PLM NOT SAVED IN DATA STRUCTURE */
/* Compare j2k_read_plm()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
@@ -1820,7 +1825,8 @@ void xml_out_frame_plm(FILE* xmlout) { /* opt, main header only; can be used in
/* ------------- */
void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) { /* opt, tile-part headers only; can be used in conjunction with main header's PLM */
void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) /* opt, tile-part headers only; can be used in conjunction with main header's PLM */
{
/* NO-OP. PLT NOT SAVED IN DATA STRUCTURE */
/* Compare j2k_read_plt()... which doesn't retain anything! */
/* Tile-part header indents are 12 spaces */
@@ -1828,11 +1834,14 @@ void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) { /* opt, tile-part headers
/* ------------- */
void xml_out_frame_crg(FILE* xmlout) { /* NO-OP. CRG NOT SAVED IN DATA STRUCTURE */ /* opt, main header only; */
void xml_out_frame_crg(FILE* xmlout)
{
/* NO-OP. CRG NOT SAVED IN DATA STRUCTURE */ /* opt, main header only; */
/* Compare j2k_read_crg()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
#ifdef NOTYET
THIS PSEUDOCODE IMAGINES THESE EXIST: j2k_default_tcp->crg, j2k_default_tcp->crg_i, j2k_default_tcp->crg_xcrg*, j2k_default_tcp->crg_ycrg*
THIS PSEUDOCODE IMAGINES THESE EXIST:
j2k_default_tcp->crg, j2k_default_tcp->crg_i, j2k_default_tcp->crg_xcrg*, j2k_default_tcp->crg_ycrg*
(POSSIBLY DON'T NEED crg_i, CAN GET NUMBER OR COMPONENTS FROM ELSEWHERE)
if(j2k_default_tcp->crg != 1 || j2k_default_tcp->crg_i == 0)
return; /* Not present */
@@ -1875,15 +1884,19 @@ void xml_out_frame_crg(FILE* xmlout) { /* NO-OP. CRG NOT SAVED IN DATA STRUCTUR
/* ------------- */
/* Regrettably from a metadata point of view, j2k_read_com() skips over any comments in main header or tile-part-header */
void xml_out_frame_com(FILE* xmlout, opj_tcp_t *tcp) { /* NO-OP. COM NOT SAVED IN DATA STRUCTURE */ /* opt in main or tile-part headers; */
void xml_out_frame_com(FILE* xmlout, opj_tcp_t *tcp)
{
/* NO-OP. COM NOT SAVED IN DATA STRUCTURE */ /* opt in main or tile-part headers; */
/* Compare j2k_read_com()... which doesn't retain anything! */
#ifdef NOTYET
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == &j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */
s++;
s++; /* shorten s to 10 spaces if main */
}
THIS PSEUDOCODE IMAGINES THESE EXIST: tcp->com, tcp->com_len, tcp->com_data array
THIS PSEUDOCODE IMAGINES THESE EXIST:
tcp->com, tcp->com_len, tcp->com_data array
if(tcp->com != 1)
return; /* Not present */
@@ -1893,7 +1906,8 @@ void xml_out_frame_com(FILE* xmlout, opj_tcp_t *tcp) { /* NO-OP. COM NOT SAVED
#endif
}
void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s) {
void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s)
{
/* s is a string of spaces for indent */
int i;
@@ -1909,7 +1923,8 @@ void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s) {
/* Define this as an even number: */
#define BYTES_PER_DUMP_LINE 40
/* Current total width for Hex and ASCII is : 11 spaces lead + (3 * BPDL) + 2 spaces + BPDL */
void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s) {
void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s)
{
/* s is a string of spaces for indent */
int i,j;
@@ -1944,7 +1959,8 @@ void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s)
/* ------------- */
void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */
void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) /* JP2 Header */
{
/* Compare jp2_read_jp2h(opj_jp2_t * jp2_struct) */
int i;
@@ -1987,8 +2003,7 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */
fprintf(xmlout, " <!-- IPR is 1 if frame contains an Intellectual Property box; 0 otherwise. -->\n"); /* 2 bytes */
fprintf(xmlout, " </ImageHeader>\n");
if (jp2_struct->bpc == 255)
{
if (jp2_struct->bpc == 255) {
fprintf(xmlout, " <BitsPerComponent BoxType=\"bpcc\">\n");
if(notes)
fprintf(xmlout, " <!-- Pixel depth (range 1 to 38) is low 7 bits of hex value + 1 -->\n");
@@ -2029,9 +2044,7 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */
fprintf(xmlout, " <!-- 18: sRGB YCC (from JPEG 2000 Part II). -->\n");
fprintf(xmlout, " <!-- (Additional JPX values are defined in Part II). -->\n");
}
}
else
if(notes)
} else if(notes)
fprintf(xmlout, " <!-- PROFILE is not handled by current OpenJPEG implementation. -->\n");
/* only 1 byte is read and nothing stored */
fprintf(xmlout, " </ColourSpecification>\n");
@@ -2048,15 +2061,15 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */
#ifdef NOTYET
IMAGE these use cp structure, extended... but we could use a new data structure instead
void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp) {
void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp)
{
/* IntellectualProperty 'jp2i' (no restrictions on location) */
int i;
IMAGE cp->jp2i, cp->jp2i_count, cp->jp2i_data (array of chars), cp->cp2i_len (array of ints)
if(cp->jp2i != 1)
return; /* Not present */
for(i = 0; i < cp->jp2i_count; i++)
{
for(i = 0; i < cp->jp2i_count; i++) {
fprintf(xmlout, " <IntellectualProperty BoxType=\"jp2i\">\n");
/* I think this can be anything, including binary, so do a dump */
/* Is it better to indent or not indent this content? Indent is better for reading, but
@@ -2066,7 +2079,8 @@ void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp) {
}
}
void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp) {
void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp)
{
/* XML 'xml\040' (0x786d6c20). Can appear multiply, before or after jp2c codestreams */
IMAGE cp->xml, cp->xml_count, cp->xml_data (array of chars)
MAYBE WE DON'T NEED cp->xml_len (array of ints) IF WE ASSUME xml_data IS NULL-TERMINATED.
@@ -2085,7 +2099,8 @@ void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp) {
}
}
void xml_out_frame_uuid(FILE* xmlout, opj_cp_t *cp) {
void xml_out_frame_uuid(FILE* xmlout, opj_cp_t *cp)
{
/* UUID 'uuid' (top level only) */
/* Part I 1.7.2 says: may appear multiply in JP2 file, anywhere except before File Type box */
/* Part III 5.2.1 says: Private extensions shall be achieved through the 'uuid' type. */

View File

@@ -23,21 +23,24 @@ can be bound by the Open JPEG open-source license and disclaimer, expressed else
/**
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);
}
/**
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);
}
/**
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);
}
@@ -107,7 +110,8 @@ void help_display()
/* ------------- */
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
@@ -138,7 +142,9 @@ int main(int argc, char *argv[]) {
case 'i': /* IN file */
infile = optarg;
s = optarg;
while (*s) { s++; } /* Run to filename end */
while (*s) {
s++; /* Run to filename end */
}
s--;
S3 = *s;
s--;
@@ -156,7 +162,9 @@ int main(int argc, char *argv[]) {
/* ----------------------------------------------------- */
case 'o': /* OUT file */
outfile = optarg;
while (*outfile) { outfile++; } /* Run to filename end */
while (*outfile) {
outfile++; /* Run to filename end */
}
outfile--;
S3 = *outfile;
outfile--;
@@ -244,8 +252,7 @@ int main(int argc, char *argv[]) {
}
*/
len = strlen(infile);
if(infile[0] == ' ')
{
if(infile[0] == ' ') {
infile++; /* There may be a leading blank if user put space after -i */
}
@@ -257,8 +264,7 @@ int main(int argc, char *argv[]) {
}
len = strlen(outfile);
if(outfile[0] == ' ')
{
if(outfile[0] == ' ') {
outfile++; /* There may be a leading blank if user put space after -o */
}
@@ -289,8 +295,7 @@ int main(int argc, char *argv[]) {
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(dinfo->mj2_handle, &parameters);
if (mj2_read_struct(file, movie)) // Creating the movie structure
{
if (mj2_read_struct(file, movie)) { // Creating the movie structure
fclose(xmlout);
return 1;
}

View File

@@ -50,14 +50,16 @@ Size of memory first allocated for MOOV box
/**
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);
}
/**
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);
}
@@ -285,8 +287,7 @@ int main(int argc, char **argv)
if (c == -1)
break;
switch (c) {
case 'i': /* IN fill */
{
case 'i': { /* IN fill */
char *infile = opj_optarg;
s = opj_optarg;
while (*s) {
@@ -302,8 +303,7 @@ int main(int argc, char **argv)
if ((S1 == 'y' && S2 == 'u' && S3 == 'v')
|| (S1 == 'Y' && S2 == 'U' && S3 == 'V')) {
mj2_parameters.decod_format = YUV_DFMT;
}
else {
} else {
fprintf(stderr,
"!! Unrecognized format for infile : %c%c%c [accept only *.yuv] !!\n\n",
S1, S2, S3);
@@ -313,8 +313,7 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 'o': /* OUT fill */
{
case 'o': { /* OUT fill */
char *outfile = opj_optarg;
while (*outfile) {
outfile++;
@@ -341,8 +340,7 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */
{
case 'r': { /* rates rates/distorsion */
float rate;
s = opj_optarg;
while (sscanf(s, "%f", &rate) == 1) {
@@ -374,8 +372,7 @@ int main(int argc, char **argv)
break;
/* dda */
/* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */
{
case 'f': { /* mod fixed_quality (before : -q) */
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
@@ -428,8 +425,7 @@ int main(int argc, char **argv)
sscanf(opj_optarg, "%d", &j2k_parameters->numresolution);
break;
/* ----------------------------------------------------- */
case 'c': /* precinct dimension */
{
case 'c': { /* precinct dimension */
char sep;
int res_spec = 0;
@@ -441,15 +437,13 @@ int main(int argc, char **argv)
j2k_parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
}
while (sep == ',');
} while (sep == ',');
j2k_parameters->res_spec = res_spec;
}
break;
/* ----------------------------------------------------- */
case 'b': /* code-block dimension */
{
case 'b': { /* code-block dimension */
int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@@ -464,8 +458,7 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 'p': /* progression order */
{
case 'p': { /* progression order */
char progression[5];
strncpy(progression, opj_optarg, 5);
@@ -478,8 +471,7 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
{
case 's': { /* subsampling factor */
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->subsampling_dx,
&j2k_parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@@ -488,8 +480,7 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */
{
case 'd': { /* coordonnate of the reference grid */
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->image_offset_x0,
&j2k_parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@@ -504,8 +495,7 @@ int main(int argc, char **argv)
return 0;
break;
/* ----------------------------------------------------- */
case 'P': /* POC */
{
case 'P': { /* POC */
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@@ -548,8 +538,7 @@ int main(int argc, char **argv)
}
break;
/* ------------------------------------------------------ */
case 'R': /* ROI */
{
case 'R': { /* ROI */
if (sscanf(opj_optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno,
&j2k_parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
@@ -558,8 +547,7 @@ int main(int argc, char **argv)
}
break;
/* ------------------------------------------------------ */
case 'T': /* Tile offset */
{
case 'T': { /* Tile offset */
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
@@ -567,8 +555,7 @@ int main(int argc, char **argv)
}
break;
/* ------------------------------------------------------ */
case 'C': /* Add a comment */
{
case 'C': { /* Add a comment */
j2k_parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(j2k_parameters->cp_comment) {
strcpy(j2k_parameters->cp_comment, opj_optarg);
@@ -576,8 +563,7 @@ int main(int argc, char **argv)
}
break;
/* ------------------------------------------------------ */
case 'I': /* reversible or not */
{
case 'I': { /* reversible or not */
j2k_parameters->irreversible = 1;
}
break;
@@ -614,8 +600,7 @@ int main(int argc, char **argv)
"Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]);
return 1;
}
if(prec < 1 || prec > 16)
{
if(prec < 1 || prec > 16) {
fprintf(stderr, "Error: Depth %d must be in the range 8 .. 16\n",prec);
return 1;
}
@@ -723,14 +708,10 @@ int main(int argc, char **argv)
opj_cio_close(cio);
free(buf);
for(i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++)
{
if(movie->tk[i].track_type != 0)
{
for(i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++) {
if(movie->tk[i].track_type != 0) {
fprintf(stderr, "Unable to write sound or hint tracks\n");
}
else
{
} else {
mj2_tk_t *tk;
int buflen = 0;
@@ -746,14 +727,12 @@ int main(int argc, char **argv)
buflen = 2 * (tk->w * tk->h * 8);
buf = (unsigned char *) malloc(buflen*sizeof(unsigned char));
for(sampleno = 0; sampleno < numframes; sampleno++)
{
for(sampleno = 0; sampleno < numframes; sampleno++) {
double init_time = opj_clock();
double elapsed_time;
if(yuvtoimage(tk, img, sampleno, j2k_parameters,
mj2_parameters.infile))
{
mj2_parameters.infile)) {
fprintf(stderr, "Error with frame number %d in YUV file\n", sampleno);
return 1;
}

View File

@@ -50,14 +50,16 @@
/**
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);
}
/**
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);
}
@@ -65,7 +67,8 @@ static void warning_callback(const char *msg, void *client_data) {
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
@@ -150,8 +153,7 @@ int main(int argc, char *argv[]) {
numframes = track->num_samples;
for (snum=0; snum < numframes; snum++)
{
for (snum=0; snum < numframes; snum++) {
double init_time = opj_clock();
double elapsed_time;
@@ -173,20 +175,19 @@ int main(int argc, char *argv[]) {
img = opj_decode(dinfo, cio); /* Decode J2K to image */
#ifdef WANT_SYCC_TO_RGB
if(img->color_space == CLRSPC_SYCC)
{
if(img->color_space == CLRSPC_SYCC) {
color_sycc_to_rgb(img);
}
#endif
if(img->icc_profile_buf)
{
if(img->icc_profile_buf) {
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(img);
#endif
free(img->icc_profile_buf);
img->icc_profile_buf = NULL; img->icc_profile_len = 0;
img->icc_profile_buf = NULL;
img->icc_profile_len = 0;
}
if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2)
@@ -195,18 +196,15 @@ int main(int argc, char *argv[]) {
if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */
return 1;
}
else if ((img->numcomps == 3) &&
} 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 */
{
(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 {
} 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");

View File

@@ -46,21 +46,24 @@
/**
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);
}
/**
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);
}
/**
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);
}
@@ -68,7 +71,8 @@ void info_callback(const char *msg, void *client_data) {
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
int tnum;
@@ -126,8 +130,7 @@ int main(int argc, char *argv[]) {
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++)
{
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);

View File

@@ -41,7 +41,8 @@
#include "jp2.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;
}
@@ -76,9 +77,9 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
fread(src, 1, src_len, reader);
fclose(reader);
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0)
{
free(src); return success;
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) {
free(src);
return success;
}
memset(&dparameters, 0, sizeof(opj_dparameters_t));
@@ -92,7 +93,8 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
image = opj_decode(dinfo, cio);
free(src); cio->buffer = NULL;
free(src);
cio->buffer = NULL;
opj_cio_close(cio);
if(image == NULL) goto fin;
@@ -102,75 +104,59 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec;
if(image->numcomps > 2 )
{
if(image->numcomps > 2 ) {
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))/* horizontal and vertical*/
{
&& (image->comps[2].dy == 2)) { /* horizontal and vertical*/
/* Y420*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 2;
}
else
if((image->comps[0].dx == 1)
} else if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))/* horizontal only*/
{
&& (image->comps[2].dy == 1)) { /* horizontal only*/
/* Y422*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 1;
}
else
if((image->comps[0].dx == 1)
} else if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
{
&& (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->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
}
else
{
} else {
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1;
}
}
else
{
} else {
goto fin;
}
}
else
{
} else {
cp->enumcs = ENUMCS_GRAY;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
}
if(image->icc_profile_buf)
{
if(image->icc_profile_buf) {
cp->meth = 2;
free(image->icc_profile_buf); image->icc_profile_buf = NULL;
}
else cp->meth = 1;
free(image->icc_profile_buf);
image->icc_profile_buf = NULL;
} else cp->meth = 1;
success = 1;
fin:
@@ -186,21 +172,24 @@ fin:
/**
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);
}
/**
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);
}
/**
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);
}
@@ -221,8 +210,7 @@ static void read_siz_marker(FILE *file, opj_image_t *image)
fread(&buf,1,1, file);
if (buf==(char)0xff)
fread(&buf,1,1, file);
}
while (!(buf==(char)0x51));
} while (!(buf==(char)0x51));
fread(buf2,2,1,file); /* Lsiz */
len = ((buf2[0])<<8) + buf2[1];
@@ -257,7 +245,8 @@ static void read_siz_marker(FILE *file, opj_image_t *image)
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;
movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
@@ -271,8 +260,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1;
else
if ((image->comps[0].dx == 1)
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
@@ -283,8 +271,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else
if ((image->comps[0].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;
@@ -337,8 +324,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
if (image->numcomps == 1)
movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */
else
if ((image->comps[0].dx == 1)
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
@@ -346,8 +332,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
&& (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else
if ((image->comps[0].dx == 1)
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
@@ -359,7 +344,8 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
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 */
unsigned int snum;
@@ -432,8 +418,7 @@ int main(int argc, char *argv[]) {
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1)
{
while(1) {
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
@@ -443,8 +428,7 @@ int main(int argc, char *argv[]) {
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 */
} else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}

View File

@@ -184,13 +184,23 @@ class OPJViewerApp: public wxApp
public:
// class constructor
OPJViewerApp() { m_showImages = true; m_showButtons = false; }
OPJViewerApp()
{
m_showImages = true;
m_showButtons = false;
}
// other methods
bool OnInit(void);
int OnExit(void);
void SetShowImages(bool show) { m_showImages = show; }
bool ShowImages() const { return m_showImages; }
void SetShowImages(bool show)
{
m_showImages = show;
}
bool ShowImages() const
{
return m_showImages;
}
void ShowCmdLine(const wxCmdLineParser& parser);
// all the threads currently alive - as soon as the thread terminates, it's
@@ -265,7 +275,8 @@ class OPJCanvas: public wxScrolledWindow
virtual void OnDraw(wxDC& dc);
void OnEvent(wxMouseEvent& event);
void WriteText(const wxString& text) {
void WriteText(const wxString& text)
{
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif //__WXGTK__
@@ -299,11 +310,21 @@ class OPJMarkerData : public wxTreeItemData
public:
// class constructor
OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname) { m_start = start; m_length = length; }
OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname)
{
m_start = start;
m_length = length;
}
void ShowInfo(wxTreeCtrl *tree);
const wxChar *GetDesc1() const { return m_desc.c_str(); }
const wxChar *GetDesc2() const { return m_filestring.c_str(); }
const wxChar *GetDesc1() const
{
return m_desc.c_str();
}
const wxChar *GetDesc2() const
{
return m_filestring.c_str();
}
wxFileOffset m_start, m_length;
wxString m_desc;
@@ -316,8 +337,7 @@ class OPJMarkerData : public wxTreeItemData
class OPJMarkerTree : public wxTreeCtrl
{
public:
enum
{
enum {
TreeCtrlIcon_File,
TreeCtrlIcon_FileSelected,
TreeCtrlIcon_Folder,
@@ -331,7 +351,12 @@ public:
long style);
virtual ~OPJMarkerTree() {};
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;
wxTextCtrl *m_peektextCtrl;
@@ -372,9 +397,15 @@ public:
/*void DoToggleIcon(const wxTreeItemId& item);*/
/*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/
int ImageSize(void) const { return m_imageSize; }
int ImageSize(void) const
{
return m_imageSize;
}
void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
void SetLastItem(wxTreeItemId id)
{
m_lastItem = id;
}
protected:
/*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/
@@ -541,8 +572,7 @@ enum {
// menu and control ids
enum
{
enum {
TreeTest_Quit = wxID_EXIT,
TreeTest_About = wxID_ABOUT,
TreeTest_TogButtons = wxID_HIGHEST,
@@ -666,7 +696,10 @@ private:
class OPJDnDFile: public wxFileDropTarget
{
public:
OPJDnDFile(OPJFrame *pOwner) { m_pOwner = pOwner; }
OPJDnDFile(OPJFrame *pOwner)
{
m_pOwner = pOwner;
}
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
private:

View File

@@ -5,12 +5,10 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers)
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
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.h
${CMAKE_CURRENT_SOURCE_DIR}/cio.c
@@ -31,7 +29,6 @@ set(OPENJPEG_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/mct.h
${CMAKE_CURRENT_SOURCE_DIR}/mqc.c
${CMAKE_CURRENT_SOURCE_DIR}/mqc.h
${CMAKE_CURRENT_SOURCE_DIR}/mqc_inl.h
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
@@ -76,11 +73,6 @@ if(OPJ_DISABLE_TPSOT_FIX)
add_definitions(-DOPJ_DISABLE_TPSOT_FIX)
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
if(WIN32)
if(BUILD_SHARED_LIBS)
@@ -118,18 +110,16 @@ install(
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man3)
endif()
if(BUILD_LUTS_GENERATOR)
# internal utility to generate t1_luts.h (part of the jp2 lib)
# internal utilities to generate t1_luts.h (part of the jp2 lib)
# no need to install:
add_executable(t1_generate_luts t1_generate_luts.c)
if(UNIX)
target_link_libraries(t1_generate_luts m)
endif()
endif()
# Experimental option; let's how cppcheck performs
# 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
# output gcc formatted error/warning report
# Another implementation detail: I could not redirect error to the error
@@ -152,36 +142,3 @@ if(OPJ_USE_DSYMUTIL)
DEPENDS ${OPENJPEG_LIBRARY_NAME})
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

@@ -78,7 +78,8 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
==========================================================
*/
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;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
@@ -88,7 +89,8 @@ static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
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;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
@@ -98,7 +100,8 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) {
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 ? */
}
@@ -106,7 +109,8 @@ static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) {
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 ? */
}
@@ -120,22 +124,26 @@ static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) {
==========================================================
*/
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;
}
void opj_bio_destroy(opj_bio_t *bio) {
void opj_bio_destroy(opj_bio_t *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);
}
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->bp = bp;
@@ -143,7 +151,8 @@ void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
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->bp = bp;
@@ -151,36 +160,27 @@ void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
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;
assert((n > 0U) && (n <= 32U));
for (i = n - 1; i < n; i--) { /* overflow used for end-loop condition */
for (i = n - 1; i < n; i--) {
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 v;
assert((n > 0U) /* && (n <= 32U)*/);
#ifdef OPJ_UBSAN_BUILD
/* This assert fails for some corrupted images which are gracefully rejected */
/* Add this assert only for ubsan build. */
/* 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 */
v = 0;
for (i = n - 1; i < n; i--) {
v += opj_bio_getbit(bio) << i;
}
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;
}
@@ -192,7 +192,8 @@ OPJ_BOOL opj_bio_flush(opj_bio_t *bio) {
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)) {
return OPJ_FALSE;

View File

@@ -60,9 +60,7 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t
lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
if(box == NULL){
return 0;
}
for (i=0; i<2; i++) {
if(i)
@@ -221,10 +219,8 @@ OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, op
OPJ_OFF_T org_pos;
unsigned int Scod;
for(i = 0; i < marknum; i++)
{
if( markers[i].type == J2K_MS_COD)
{
for(i = 0; i < marknum; i++) {
if( markers[i].type == J2K_MS_COD) {
org_pos = opj_stream_tell(cio);
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);

View File

@@ -169,8 +169,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l
l_stream->m_status |= OPJ_STREAM_STATUS_INPUT;
l_stream->m_opj_skip = opj_stream_read_skip;
l_stream->m_opj_seek = opj_stream_read_seek;
}
else {
} else {
l_stream->m_status |= OPJ_STREAM_STATUS_OUTPUT;
l_stream->m_opj_skip = opj_stream_write_skip;
l_stream->m_opj_seek = opj_stream_write_seek;
@@ -294,8 +293,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0;
}
else {
} else {
/* case where we are already at the end of the buffer
so reset the m_current_data to point to the start of the
stored buffer to get ready to read from disk*/
@@ -316,8 +314,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_stream->m_status |= OPJ_STREAM_STATUS_END;
/* end of stream */
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
}
else if (p_stream->m_bytes_in_buffer < p_size) {
} else if (p_stream->m_bytes_in_buffer < p_size) {
/* not enough data */
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer);
@@ -326,8 +323,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0;
}
else {
} else {
l_read_nb_bytes += p_size;
memcpy(p_buffer,p_stream->m_current_data,p_size);
p_stream->m_current_data += p_size;
@@ -335,8 +331,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_stream->m_byte_offset += (OPJ_OFF_T)p_size;
return l_read_nb_bytes;
}
}
else {
} else {
/* direct read on the dest buffer */
p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_buffer,p_size,p_stream->m_user_data);
@@ -348,8 +343,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_stream->m_status |= OPJ_STREAM_STATUS_END;
/* end of stream */
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
}
else if (p_stream->m_bytes_in_buffer < p_size) {
} else if (p_stream->m_bytes_in_buffer < p_size) {
/* not enough data */
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
p_stream->m_current_data = p_stream->m_stored_data;
@@ -357,8 +351,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0;
}
else {
} else {
/* we have read the exact size */
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
@@ -570,8 +563,7 @@ OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
if( !(p_stream->m_seek_fn(p_size,p_stream->m_user_data)) ) {
p_stream->m_status |= OPJ_STREAM_STATUS_END;
return OPJ_FALSE;
}
else {
} else {
/* reset stream status */
p_stream->m_status &= (~OPJ_STREAM_STATUS_END);
p_stream->m_byte_offset = p_size;
@@ -594,8 +586,7 @@ OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
if (! p_stream->m_seek_fn(p_size,p_stream->m_user_data)) {
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
return OPJ_FALSE;
}
else {
} else {
p_stream->m_byte_offset = p_size;
}

View File

@@ -78,8 +78,7 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/**
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.
*/

View File

@@ -124,21 +124,21 @@ static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_st
/**
Inverse wavelet transform in 2-D.
*/
static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i, DWT1DFN fn);
static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i, DWT1DFN fn);
static OPJ_BOOL opj_dwt_encode_procedure( opj_tcd_tilecomp_t * tilec,
void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) );
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, OPJ_UINT32 i);
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i);
/* <summary> */
/* Inverse 9-7 wavelet transform in 1-D. */
/* </summary> */
static void opj_v4dwt_decode(opj_v4dwt_t* OPJ_RESTRICT dwt);
static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt);
static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT w, OPJ_FLOAT32* OPJ_RESTRICT a, OPJ_INT32 x, OPJ_INT32 size);
static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size);
static void opj_v4dwt_interleave_v(opj_v4dwt_t* OPJ_RESTRICT v , OPJ_FLOAT32* OPJ_RESTRICT a , OPJ_INT32 x, OPJ_INT32 nb_elts_read);
static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read);
#ifdef __SSE__
static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c);
@@ -193,7 +193,8 @@ static const OPJ_FLOAT64 opj_dwt_norms_real[4][10] = {
/* <summary> */
/* Forward lazy transform (horizontal). */
/* </summary> */
static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
OPJ_INT32 i;
OPJ_INT32 * l_dest = b;
OPJ_INT32 * l_src = a+cas;
@@ -215,7 +216,8 @@ static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ
/* <summary> */
/* Forward lazy transform (vertical). */
/* </summary> */
static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas) {
static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas)
{
OPJ_INT32 i = sn;
OPJ_INT32 * l_dest = b;
OPJ_INT32 * l_src = a+cas;
@@ -240,7 +242,8 @@ static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ
/* <summary> */
/* Inverse lazy transform (horizontal). */
/* </summary> */
static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) {
static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a)
{
OPJ_INT32 *ai = a;
OPJ_INT32 *bi = h->mem + h->cas;
OPJ_INT32 i = h->sn;
@@ -260,7 +263,8 @@ static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) {
/* <summary> */
/* Inverse lazy transform (vertical). */
/* </summary> */
static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) {
static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x)
{
OPJ_INT32 *ai = a;
OPJ_INT32 *bi = v->mem + v->cas;
OPJ_INT32 i = v->sn;
@@ -283,7 +287,8 @@ static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) {
/* <summary> */
/* Forward 5-3 wavelet transform in 1-D. */
/* </summary> */
static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
OPJ_INT32 i;
if (!cas) {
@@ -304,7 +309,8 @@ static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32
/* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */
static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
OPJ_INT32 i;
if (!cas) {
@@ -325,14 +331,16 @@ static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT3
/* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */
static void opj_dwt_decode_1(opj_dwt_t *v) {
static void opj_dwt_decode_1(opj_dwt_t *v)
{
opj_dwt_decode_1_(v->mem, v->dn, v->sn, v->cas);
}
/* <summary> */
/* Forward 9-7 wavelet transform in 1-D. */
/* </summary> */
static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
OPJ_INT32 i;
if (!cas) {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
@@ -367,7 +375,8 @@ static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_
}
}
static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize) {
static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize)
{
OPJ_INT32 p, n;
p = opj_int_floorlog2(stepsize) - 13;
n = 11 - opj_int_floorlog2(stepsize);
@@ -395,7 +404,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void
OPJ_INT32 rw; /* width of the resolution level computed */
OPJ_INT32 rh; /* height of the resolution level computed */
size_t l_data_size;
OPJ_UINT32 l_data_size;
opj_tcd_resolution_t * l_cur_res = 0;
opj_tcd_resolution_t * l_last_res = 0;
@@ -407,14 +416,8 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void
l_cur_res = tilec->resolutions + l;
l_last_res = l_cur_res - 1;
l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions);
/* overflow check */
if (l_data_size > (SIZE_MAX / sizeof(OPJ_INT32))) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
l_data_size *= sizeof(OPJ_INT32);
bj = (OPJ_INT32*)opj_malloc(l_data_size);
l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32);
bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size);
/* l_data_size is equal to 0 when numresolutions == 1 but bj is not used */
/* in that case, so do not error out */
if (l_data_size != 0 && ! bj) {
@@ -479,15 +482,17 @@ OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec)
/* <summary> */
/* Inverse 5-3 wavelet transform in 2-D. */
/* </summary> */
OPJ_BOOL opj_dwt_decode(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) {
return opj_dwt_decode_tile(tp, tilec, numres, &opj_dwt_decode_1);
OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres)
{
return opj_dwt_decode_tile(tilec, numres, &opj_dwt_decode_1);
}
/* <summary> */
/* Get gain of 5-3 wavelet transform. */
/* </summary> */
OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) {
OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient)
{
if (orient == 0)
return 0;
if (orient == 1 || orient == 2)
@@ -498,7 +503,8 @@ OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) {
/* <summary> */
/* Get norm of 5-3 wavelet. */
/* </summary> */
OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) {
OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient)
{
return opj_dwt_norms[orient][level];
}
@@ -513,7 +519,8 @@ OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec)
/* <summary> */
/* Get gain of 9-7 wavelet transform. */
/* </summary> */
OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient) {
OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient)
{
(void)orient;
return 0;
}
@@ -521,11 +528,13 @@ OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient) {
/* <summary> */
/* Get norm of 9-7 wavelet. */
/* </summary> */
OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient) {
OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient)
{
return opj_dwt_norms_real[orient][level];
}
void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) {
void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec)
{
OPJ_UINT32 numbands, bandno;
numbands = 3 * tccp->numresolutions - 2;
for (bandno = 0; bandno < numbands; bandno++) {
@@ -549,7 +558,8 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) {
/* <summary> */
/* Determine maximum computed resolution level for inverse wavelet transform */
/* </summary> */
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, OPJ_UINT32 i) {
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i)
{
OPJ_UINT32 mr = 0;
OPJ_UINT32 w;
while( --i ) {
@@ -562,72 +572,10 @@ static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, O
return mr ;
}
typedef struct
{
opj_dwt_t h;
DWT1DFN dwt_1D;
OPJ_UINT32 rw;
OPJ_UINT32 w;
OPJ_INT32 * OPJ_RESTRICT tiledp;
OPJ_UINT32 min_j;
OPJ_UINT32 max_j;
} opj_dwd_decode_h_job_t;
static void opj_dwt_decode_h_func(void* user_data, opj_tls_t* tls)
{
OPJ_UINT32 j;
opj_dwd_decode_h_job_t* job;
(void)tls;
job = (opj_dwd_decode_h_job_t*)user_data;
for( j = job->min_j; j < job->max_j; j++ )
{
opj_dwt_interleave_h(&job->h, &job->tiledp[j*job->w]);
(job->dwt_1D)(&job->h);
memcpy(&job->tiledp[j*job->w], job->h.mem, job->rw * sizeof(OPJ_INT32));
}
opj_aligned_free(job->h.mem);
opj_free(job);
}
typedef struct
{
opj_dwt_t v;
DWT1DFN dwt_1D;
OPJ_UINT32 rh;
OPJ_UINT32 w;
OPJ_INT32 * OPJ_RESTRICT tiledp;
OPJ_UINT32 min_j;
OPJ_UINT32 max_j;
} opj_dwd_decode_v_job_t;
static void opj_dwt_decode_v_func(void* user_data, opj_tls_t* tls)
{
OPJ_UINT32 j;
opj_dwd_decode_v_job_t* job;
(void)tls;
job = (opj_dwd_decode_v_job_t*)user_data;
for( j = job->min_j; j < job->max_j; j++ )
{
OPJ_UINT32 k;
opj_dwt_interleave_v(&job->v, &job->tiledp[j], (OPJ_INT32)job->w);
(job->dwt_1D)(&job->v);
for(k = 0; k < job->rh; ++k) {
job->tiledp[k * job->w + j] = job->v.mem[k];
}
}
opj_aligned_free(job->v.mem);
opj_free(job);
}
/* <summary> */
/* Inverse wavelet transform in 2-D. */
/* </summary> */
static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D)
static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D)
{
opj_dwt_t h;
opj_dwt_t v;
@@ -638,21 +586,11 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
OPJ_UINT32 rh = (OPJ_UINT32)(tr->y1 - tr->y0); /* height of the resolution level computed */
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
size_t h_mem_size;
int num_threads;
if (numres == 1U) {
return OPJ_TRUE;
}
num_threads = opj_thread_pool_get_thread_count(tp);
h_mem_size = opj_dwt_max_resolution(tr, numres);
/* overflow check */
if (h_mem_size > (SIZE_MAX / sizeof(OPJ_INT32))) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
h_mem_size *= sizeof(OPJ_INT32);
h.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size);
h.mem = (OPJ_INT32*)opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
if (! h.mem) {
/* FIXME event manager error callback */
return OPJ_FALSE;
@@ -661,7 +599,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
v.mem = h.mem;
while( --numres) {
OPJ_INT32 * OPJ_RESTRICT tiledp = tilec->data;
OPJ_INT32 * restrict tiledp = tilec->data;
OPJ_UINT32 j;
++tr;
@@ -674,71 +612,17 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
h.dn = (OPJ_INT32)(rw - (OPJ_UINT32)h.sn);
h.cas = tr->x0 % 2;
if( num_threads <= 1 || rh <= 1 )
{
for(j = 0; j < rh; ++j) {
opj_dwt_interleave_h(&h, &tiledp[j*w]);
(dwt_1D)(&h);
memcpy(&tiledp[j*w], h.mem, rw * sizeof(OPJ_INT32));
}
}
else
{
OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads;
OPJ_UINT32 step_j;
if( rh < num_jobs ) {
num_jobs = rh;
}
step_j = (rh / num_jobs);
for(j = 0; j < num_jobs; j++)
{
opj_dwd_decode_h_job_t* job;
job = (opj_dwd_decode_h_job_t*) opj_malloc(sizeof(opj_dwd_decode_h_job_t));
if( !job )
{
/* It would be nice to fallback to single thread case, but */
/* unfortunately some jobs may be launched and have modified */
/* tiledp, so it is not practical to recover from that error */
/* FIXME event manager error callback */
opj_thread_pool_wait_completion(tp, 0);
opj_aligned_free(h.mem);
return OPJ_FALSE;
}
job->h = h;
job->dwt_1D = dwt_1D;
job->rw = rw;
job->w = w;
job->tiledp = tiledp;
job->min_j = j * step_j;
job->max_j = (j + 1U) * step_j; /* this can overflow */
if( j == (num_jobs - 1U) ) { /* this will take care of the overflow */
job->max_j = rh;
}
job->h.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size);
if (!job->h.mem)
{
/* FIXME event manager error callback */
opj_thread_pool_wait_completion(tp, 0);
opj_free(job);
opj_aligned_free(h.mem);
return OPJ_FALSE;
}
opj_thread_pool_submit_job( tp, opj_dwt_decode_h_func, job );
}
opj_thread_pool_wait_completion(tp, 0);
}
v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn);
v.cas = tr->y0 % 2;
if( num_threads <= 1 || rw <= 1 )
{
for(j = 0; j < rw; ++j) {
OPJ_UINT32 k;
opj_dwt_interleave_v(&v, &tiledp[j], (OPJ_INT32)w);
(dwt_1D)(&v);
for(k = 0; k < rh; ++k) {
@@ -746,62 +630,13 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
}
}
}
else
{
OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads;
OPJ_UINT32 step_j;
if( rw < num_jobs ) {
num_jobs = rw;
}
step_j = (rw / num_jobs);
for( j = 0; j < num_jobs; j++ )
{
opj_dwd_decode_v_job_t* job;
job = (opj_dwd_decode_v_job_t*) opj_malloc(sizeof(opj_dwd_decode_v_job_t));
if( !job )
{
/* It would be nice to fallback to single thread case, but */
/* unfortunately some jobs may be launched and have modified */
/* tiledp, so it is not practical to recover from that error */
/* FIXME event manager error callback */
opj_thread_pool_wait_completion(tp, 0);
opj_aligned_free(v.mem);
return OPJ_FALSE;
}
job->v = v;
job->dwt_1D = dwt_1D;
job->rh = rh;
job->w = w;
job->tiledp = tiledp;
job->min_j = j * step_j;
job->max_j = (j + 1U) * step_j; /* this can overflow */
if( j == (num_jobs - 1U) ) { /* this will take care of the overflow */
job->max_j = rw;
}
job->v.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size);
if (!job->v.mem)
{
/* FIXME event manager error callback */
opj_thread_pool_wait_completion(tp, 0);
opj_free(job);
opj_aligned_free(v.mem);
return OPJ_FALSE;
}
opj_thread_pool_submit_job( tp, opj_dwt_decode_v_func, job );
}
opj_thread_pool_wait_completion(tp, 0);
}
}
opj_aligned_free(h.mem);
return OPJ_TRUE;
}
static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT w, OPJ_FLOAT32* OPJ_RESTRICT a, OPJ_INT32 x, OPJ_INT32 size)
static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size)
{
OPJ_FLOAT32* OPJ_RESTRICT bi = (OPJ_FLOAT32*) (w->wavelet + w->cas);
OPJ_FLOAT32* restrict bi = (OPJ_FLOAT32*) (w->wavelet + w->cas);
OPJ_INT32 count = w->sn;
OPJ_INT32 i, k;
@@ -818,8 +653,7 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT w, OPJ_FLOAT32* OPJ
j += x;
bi[i*8 + 3] = a[j];
}
}
else {
} else {
/* Slow code path */
for(i = 0; i < count; ++i) {
OPJ_INT32 j = i;
@@ -843,8 +677,9 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT w, OPJ_FLOAT32* OPJ
}
}
static void opj_v4dwt_interleave_v(opj_v4dwt_t* OPJ_RESTRICT v , OPJ_FLOAT32* OPJ_RESTRICT a , OPJ_INT32 x, OPJ_INT32 nb_elts_read){
opj_v4_t* OPJ_RESTRICT bi = v->wavelet + v->cas;
static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read)
{
opj_v4_t* restrict bi = v->wavelet + v->cas;
OPJ_INT32 i;
for(i = 0; i < v->sn; ++i) {
@@ -861,8 +696,9 @@ static void opj_v4dwt_interleave_v(opj_v4dwt_t* OPJ_RESTRICT v , OPJ_FLOAT32* OP
#ifdef __SSE__
static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c){
__m128* OPJ_RESTRICT vw = (__m128*) w;
static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c)
{
__m128* restrict vw = (__m128*) w;
OPJ_INT32 i;
/* 4x unrolled loop */
for(i = 0; i < count >> 2; ++i) {
@@ -882,9 +718,10 @@ static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m12
}
}
void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c){
__m128* OPJ_RESTRICT vl = (__m128*) l;
__m128* OPJ_RESTRICT vw = (__m128*) w;
void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c)
{
__m128* restrict vl = (__m128*) l;
__m128* restrict vw = (__m128*) w;
OPJ_INT32 i;
__m128 tmp1, tmp2, tmp3;
tmp1 = vl[0];
@@ -912,7 +749,7 @@ void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32
static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT32 c)
{
OPJ_FLOAT32* OPJ_RESTRICT fw = (OPJ_FLOAT32*) w;
OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w;
OPJ_INT32 i;
for(i = 0; i < count; ++i) {
OPJ_FLOAT32 tmp1 = fw[i*8 ];
@@ -980,7 +817,7 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
/* <summary> */
/* Inverse 9-7 wavelet transform in 1-D. */
/* </summary> */
static void opj_v4dwt_decode(opj_v4dwt_t* OPJ_RESTRICT dwt)
static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt)
{
OPJ_INT32 a, b;
if(dwt->cas == 0) {
@@ -1017,7 +854,7 @@ static void opj_v4dwt_decode(opj_v4dwt_t* OPJ_RESTRICT dwt)
/* <summary> */
/* Inverse 9-7 wavelet transform in 2-D. */
/* </summary> */
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)
{
opj_v4dwt_t h;
opj_v4dwt_t v;
@@ -1029,21 +866,7 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
size_t l_data_size;
l_data_size = opj_dwt_max_resolution(res, numres);
/* overflow check */
if (l_data_size > (SIZE_MAX - 5U)) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
l_data_size += 5U;
/* overflow check */
if (l_data_size > (SIZE_MAX / sizeof(opj_v4_t))) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
h.wavelet = (opj_v4_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v4_t));
h.wavelet = (opj_v4_t*) opj_aligned_malloc((opj_dwt_max_resolution(res, numres)+5) * sizeof(opj_v4_t));
if (!h.wavelet) {
/* FIXME event manager error callback */
return OPJ_FALSE;
@@ -1051,7 +874,7 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32
v.wavelet = h.wavelet;
while( --numres) {
OPJ_FLOAT32 * OPJ_RESTRICT aj = (OPJ_FLOAT32*) tilec->data;
OPJ_FLOAT32 * restrict aj = (OPJ_FLOAT32*) tilec->data;
OPJ_UINT32 bufsize = (OPJ_UINT32)((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0));
OPJ_INT32 j;
@@ -1089,9 +912,12 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32
opj_v4dwt_decode(&h);
for(k = (OPJ_INT32)rw; --k >= 0;) {
switch(j) {
case 3: aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2];
case 2: aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1];
case 1: aj[k ] = h.wavelet[k].f[0];
case 3:
aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2];
case 2:
aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1];
case 1:
aj[k ] = h.wavelet[k].f[0];
}
}
}

View File

@@ -63,11 +63,10 @@ OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec);
/**
Inverse 5-3 wavelet transform in 2-D.
Apply a reversible inverse DWT transform to a component of an image.
@param tp Thread pool
@param tilec Tile component information (current tile)
@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.
@@ -94,7 +93,7 @@ Apply an irreversible inverse DWT transform to a component of an image.
@param tilec Tile component information (current tile)
@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.

View File

@@ -40,7 +40,8 @@
#ifdef OPJ_CODE_NOT_USED
#ifndef _WIN32
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];
return a+1;
@@ -55,13 +56,13 @@ i2a(unsigned i, char *a, unsigned r) {
@return Returns a
*/
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) {
*a = '-';
*i2a(-i, a+1, r) = 0;
}
else *i2a(i, a, r) = 0;
} else *i2a(i, a, r) = 0;
return a;
}
@@ -83,7 +84,8 @@ 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 */
opj_msg_callback msg_handler = 00;
void * l_data = 00;

View File

@@ -47,8 +47,7 @@ used for
<li>Debugging messages
</ul>
*/
typedef struct opj_event_mgr
{
typedef struct opj_event_mgr {
/** Data to call the event manager upon */
void * m_error_data;
/** Data to call the event manager upon */

View File

@@ -40,15 +40,13 @@ opj_procedure_list_t * opj_procedure_list_create()
{
/* memory allocation */
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;
}
/* initialization */
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
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;
}
@@ -57,13 +55,11 @@ opj_procedure_list_t * opj_procedure_list_create()
void opj_procedure_list_destroy(opj_procedure_list_t * p_list)
{
if (! p_list)
{
if (! p_list) {
return;
}
/* initialization */
if (p_list->m_procedures)
{
if (p_list->m_procedures) {
opj_free(p_list->m_procedures);
}
opj_free(p_list);
@@ -74,24 +70,20 @@ OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_l
assert(p_manager != NULL);
if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures)
{
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;
new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_procedures,
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
if (! new_procedures)
{
if (! new_procedures) {
opj_free(p_validation_list->m_procedures);
p_validation_list->m_nb_max_procedures = 0;
p_validation_list->m_nb_procedures = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
return OPJ_FALSE;
}
else
{
} else {
p_validation_list->m_procedures = new_procedures;
}
}

View File

@@ -54,8 +54,7 @@ typedef void (*opj_procedure)(void);
/**
* A list of procedures.
*/
typedef struct opj_procedure_list
{
typedef struct opj_procedure_list {
/**
* The number of validation procedures.
*/

View File

@@ -31,12 +31,14 @@
#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* 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;
@@ -77,7 +79,8 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptpa
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) {
OPJ_UINT32 compno;
@@ -198,20 +201,19 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
memcpy( p_image_dest->icc_profile_buf,
p_image_src->icc_profile_buf,
p_image_src->icc_profile_len);
}
else
} else
p_image_dest->icc_profile_buf = NULL;
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;
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
if (image)
{
if (image) {
image->color_space = clrspc;
image->numcomps = numcmpts;

View File

@@ -121,8 +121,7 @@ static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
OPJ_UINT32 lStride = nb_compo-1;
/*initialize permutations */
for (i = 0; i < nb_compo; ++i)
{
for (i = 0; i < nb_compo; ++i) {
*tmpPermutations++ = i;
}
/* now make a pivot with column switch */
@@ -232,8 +231,7 @@ static void opj_lupSolve (OPJ_FLOAT32 * pResult,
sum = 0.0;
lCurrentPtr = p_intermediate_data;
lTmpMatrix = lLineMatrix;
for (j = 1; j <= i; ++j)
{
for (j = 1; j <= i; ++j) {
/* sum += matrix[i][j-1] * y[j-1]; */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
}

File diff suppressed because it is too large Load Diff

View File

@@ -132,8 +132,7 @@ typedef enum J2K_STATUS {
/**
* 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_INT32 = 1, /** MCT data is stored as signed integers*/
MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/
@@ -143,8 +142,7 @@ typedef enum MCT_ELEMENT_TYPE
/**
* Type of MCT array
*/
typedef enum MCT_ARRAY_TYPE
{
typedef enum MCT_ARRAY_TYPE {
MCT_TYPE_DEPENDENCY = 0,
MCT_TYPE_DECORRELATION = 1,
MCT_TYPE_OFFSET = 2
@@ -173,8 +171,7 @@ typedef struct opj_stepsize {
/**
Tile-component coding parameters
*/
typedef struct opj_tccp
{
typedef struct opj_tccp {
/** coding style */
OPJ_UINT32 csty;
/** number of resolutions */
@@ -209,8 +206,7 @@ opj_tccp_t;
/**
* FIXME DOC
*/
typedef struct opj_mct_data
{
typedef struct opj_mct_data {
J2K_MCT_ELEMENT_TYPE m_element_type;
J2K_MCT_ARRAY_TYPE m_array_type;
OPJ_UINT32 m_index;
@@ -222,18 +218,16 @@ opj_mct_data_t;
/**
* FIXME DOC
*/
typedef struct opj_simple_mcc_decorrelation_data
{
typedef struct opj_simple_mcc_decorrelation_data {
OPJ_UINT32 m_index;
OPJ_UINT32 m_nb_comps;
opj_mct_data_t * m_decorrelation_array;
opj_mct_data_t * m_offset_array;
OPJ_BITFIELD m_is_irreversible : 1;
OPJ_UINT32 m_is_irreversible : 1;
}
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_UINT32 m_data_size;
} opj_ppx;
@@ -243,8 +237,7 @@ Tile coding parameters :
this structure is used to store coding/decoding parameters common to all
tiles (information like COD, COC in main header)
*/
typedef struct opj_tcp
{
typedef struct opj_tcp {
/** coding style */
OPJ_UINT32 csty;
/** progression order */
@@ -306,18 +299,17 @@ typedef struct opj_tcp
/***** FLAGS *******/
/** 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 */
OPJ_BITFIELD ppt : 1;
OPJ_UINT32 ppt : 1;
/** indicates if a POC marker has been used O:NO, 1:YES */
OPJ_BITFIELD POC : 1;
OPJ_UINT32 POC : 1;
} 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 */
OPJ_UINT32 m_max_comp_size;
/** Position of tile part flag in progression order*/
@@ -327,18 +319,17 @@ typedef struct opj_encoding_param
/** Flag determining tile part generation*/
OPJ_BYTE m_tp_flag;
/** allocation by rate/distortion */
OPJ_BITFIELD m_disto_alloc : 1;
OPJ_UINT32 m_disto_alloc : 1;
/** allocation by fixed layer */
OPJ_BITFIELD m_fixed_alloc : 1;
OPJ_UINT32 m_fixed_alloc : 1;
/** add fixed_quality */
OPJ_BITFIELD m_fixed_quality : 1;
OPJ_UINT32 m_fixed_quality : 1;
/** Enabling Tile part generation*/
OPJ_BITFIELD m_tp_on : 1;
OPJ_UINT32 m_tp_on : 1;
}
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 */
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 */
@@ -350,8 +341,7 @@ opj_decoding_param_t;
/**
* Coding parameters
*/
typedef struct opj_cp
{
typedef struct opj_cp {
/** Size of the image in bits*/
/*int img_size;*/
/** Rsiz*/
@@ -399,8 +389,7 @@ typedef struct opj_cp
/** tile coding parameters */
opj_tcp_t *tcps;
union
{
union {
opj_decoding_param_t m_dec;
opj_encoding_param_t m_enc;
}
@@ -453,15 +442,14 @@ typedef struct opj_cp
/******** FLAGS *********/
/** 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 */
OPJ_BITFIELD m_is_decoder : 1;
OPJ_UINT32 m_is_decoder : 1;
/* <<UniPG */
} 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) */
OPJ_UINT32 m_state;
/**
@@ -497,17 +485,16 @@ typedef struct opj_j2k_dec
*/
OPJ_BOOL m_last_tile_part;
/** to tell that a tile can be decoded. */
OPJ_BITFIELD m_can_decode : 1;
OPJ_BITFIELD m_discard_tiles : 1;
OPJ_BITFIELD m_skip_data : 1;
OPJ_UINT32 m_can_decode : 1;
OPJ_UINT32 m_discard_tiles : 1;
OPJ_UINT32 m_skip_data : 1;
/** TNsot correction : see issue 254 **/
OPJ_BITFIELD m_nb_tile_parts_correction_checked : 1;
OPJ_BITFIELD m_nb_tile_parts_correction : 1;
OPJ_UINT32 m_nb_tile_parts_correction_checked : 1;
OPJ_UINT32 m_nb_tile_parts_correction : 1;
} 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*/
OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */
@@ -553,14 +540,12 @@ struct opj_tcd;
/**
JPEG-2000 codestream reader/writer
*/
typedef struct opj_j2k
{
typedef struct opj_j2k {
/* J2K codestream is decoded*/
OPJ_BOOL m_is_decoder;
/* FIXME DOC*/
union
{
union {
opj_j2k_dec_t m_decoder;
opj_j2k_enc_t m_encoder;
}
@@ -589,12 +574,6 @@ typedef struct opj_j2k
/** the current tile coder/decoder **/
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;
@@ -613,8 +592,6 @@ Decoding parameters are returned in j2k->cp.
*/
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
*

View File

@@ -410,15 +410,13 @@ static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_i
*/
static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id );
static const opj_jp2_header_handler_t jp2_header [] =
{
static const opj_jp2_header_handler_t jp2_header [] = {
{JP2_JP,opj_jp2_read_jp},
{JP2_FTYP,opj_jp2_read_ftyp},
{JP2_JP2H,opj_jp2_read_jp2h}
};
static const opj_jp2_header_handler_t jp2_img_header [] =
{
static const opj_jp2_header_handler_t jp2_img_header [] = {
{JP2_IHDR,opj_jp2_read_ihdr},
{JP2_COLR,opj_jp2_read_colr},
{JP2_BPCC,opj_jp2_read_bpcc},
@@ -481,8 +479,7 @@ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box,
opj_read_bytes(l_data_header,&(box->length), 4);
opj_read_bytes(l_data_header+4,&(box->type), 4);
if(box->length == 0)/* last box */
{
if(box->length == 0) { /* last box */
const OPJ_OFF_T bleft = opj_stream_get_number_byte_left(cio);
if (bleft > (OPJ_OFF_T)(0xFFFFFFFFU - 8U)) {
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n");
@@ -519,7 +516,8 @@ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box,
}
#if 0
static void jp2_write_url(opj_cio_t *cio, char *Idx_file) {
static void jp2_write_url(opj_cio_t *cio, char *Idx_file)
{
OPJ_UINT32 i;
opj_jp2_box_t box;
@@ -552,11 +550,6 @@ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
assert(jp2 != 00);
assert(p_manager != 00);
if (jp2->comps != NULL) {
opj_event_msg(p_manager, EVT_WARNING, "Ignoring ihdr box. First ihdr box already read\n");
return OPJ_TRUE;
}
if (p_image_header_size != 14) {
opj_event_msg(p_manager, EVT_ERROR, "Bad image header box (bad size)\n");
return OPJ_FALSE;
@@ -569,11 +562,6 @@ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
opj_read_bytes(p_image_header_data,&(jp2->numcomps),2); /* NC */
p_image_header_data += 2;
if ((jp2->numcomps - 1U) >= 16384U) { /* unsigned underflow is well defined: 1U <= jp2->numcomps <= 16384U */
opj_event_msg(p_manager, EVT_ERROR, "Invalid number of components (ihdr)\n");
return OPJ_FALSE;
}
/* allocate memory for components */
jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t));
if (jp2->comps == 0) {
@@ -656,13 +644,12 @@ static OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2,
{
OPJ_UINT32 i;
/* room for 8 bytes for box and 1 byte for each component */
OPJ_UINT32 l_bpcc_size;
OPJ_UINT32 l_bpcc_size = 8 + jp2->numcomps;
OPJ_BYTE * l_bpcc_data,* l_current_bpcc_ptr;
/* preconditions */
assert(jp2 != 00);
assert(p_nb_bytes_written != 00);
l_bpcc_size = 8 + jp2->numcomps;
l_bpcc_data = (OPJ_BYTE *) opj_calloc(1,l_bpcc_size);
if (l_bpcc_data == 00) {
@@ -817,7 +804,8 @@ static OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2,
++l_current_colr_ptr;
if (jp2->meth == 1) { /* Meth value is restricted to 1 or 2 (Table I.9 of part 1) */
opj_write_bytes(l_current_colr_ptr, jp2->enumcs,4); } /* EnumCS */
opj_write_bytes(l_current_colr_ptr, jp2->enumcs,4);
} /* EnumCS */
else {
if (jp2->meth == 2) { /* ICC profile */
OPJ_UINT32 i;
@@ -841,7 +829,8 @@ static void opj_jp2_free_pclr(opj_jp2_color_t *color)
if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap);
opj_free(color->jp2_pclr); color->jp2_pclr = NULL;
opj_free(color->jp2_pclr);
color->jp2_pclr = NULL;
}
static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, opj_event_mgr_t *p_manager)
@@ -874,8 +863,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
/* issue 397 */
/* ISO 15444-1 states that if cdef is present, it shall contain a complete list of channel definitions. */
while (nr_channels > 0)
{
while (nr_channels > 0) {
for(i = 0; i < n; ++i) {
if ((OPJ_UINT32)info[i].cn == (nr_channels - 1U)) {
break;
@@ -916,18 +904,15 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
if (pcol >= nr_channels) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid component/palette index for direct mapping %d.\n", pcol);
is_sane = OPJ_FALSE;
}
else if (pcol_usage[pcol] && cmap[i].mtyp == 1) {
} else if (pcol_usage[pcol] && cmap[i].mtyp == 1) {
opj_event_msg(p_manager, EVT_ERROR, "Component %d is mapped twice.\n", pcol);
is_sane = OPJ_FALSE;
}
else if (cmap[i].mtyp == 0 && cmap[i].pcol != 0) {
} else if (cmap[i].mtyp == 0 && cmap[i].pcol != 0) {
/* I.5.3.5 PCOL: If the value of the MTYP field for this channel is 0, then
* the value of this field shall be 0. */
opj_event_msg(p_manager, EVT_ERROR, "Direct use at #%d however pcol=%d.\n", i, pcol);
is_sane = OPJ_FALSE;
}
else
} else
pcol_usage[pcol] = OPJ_TRUE;
}
/* verify that all components are targeted at least once */
@@ -990,7 +975,8 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
return;
}
for(i = 0; i < nr_channels; ++i) {
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
pcol = cmap[i].pcol;
cmp = cmap[i].cmp;
/* Direct use */
if(cmap[i].mtyp == 0) {
@@ -1019,7 +1005,8 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
for(i = 0; i < nr_channels; ++i) {
/* Palette mapping: */
cmp = cmap[i].cmp; pcol = cmap[i].pcol;
cmp = cmap[i].cmp;
pcol = cmap[i].pcol;
src = old_comps[cmp].data;
assert( src );
max = new_comps[pcol].w * new_comps[pcol].h;
@@ -1032,14 +1019,14 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
for(j = 0; j < max; ++j) {
dst[j] = src[j];
}
}
else {
} else {
assert( i == pcol );
dst = new_comps[pcol].data;
assert( dst );
for(j = 0; j < max; ++j) {
/* The index */
if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
if((k = src[j]) < 0) k = 0;
else if(k > top_k) k = top_k;
/* The colour */
dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol];
@@ -1109,22 +1096,19 @@ static OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
if (!entries)
return OPJ_FALSE;
channel_size = (OPJ_BYTE*) opj_malloc(nr_channels);
if (!channel_size)
{
if (!channel_size) {
opj_free(entries);
return OPJ_FALSE;
}
channel_sign = (OPJ_BYTE*) opj_malloc(nr_channels);
if (!channel_sign)
{
if (!channel_sign) {
opj_free(entries);
opj_free(channel_size);
return OPJ_FALSE;
}
jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t));
if (!jp2_pclr)
{
if (!jp2_pclr) {
opj_free(entries);
opj_free(channel_size);
opj_free(channel_sign);
@@ -1235,33 +1219,28 @@ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_e
info = color->jp2_cdef->info;
n = color->jp2_cdef->n;
for(i = 0; i < n; ++i)
{
for(i = 0; i < n; ++i) {
/* WATCH: acn = asoc - 1 ! */
asoc = info[i].asoc;
cn = info[i].cn;
if( cn >= image->numcomps)
{
if( cn >= image->numcomps) {
opj_event_msg(manager, EVT_WARNING, "opj_jp2_apply_cdef: cn=%d, numcomps=%d\n", cn, image->numcomps);
continue;
}
if(asoc == 0 || asoc == 65535)
{
if(asoc == 0 || asoc == 65535) {
image->comps[cn].alpha = info[i].typ;
continue;
}
acn = (OPJ_UINT16)(asoc - 1);
if( acn >= image->numcomps )
{
if( acn >= image->numcomps ) {
opj_event_msg(manager, EVT_WARNING, "opj_jp2_apply_cdef: acn=%d, numcomps=%d\n", acn, image->numcomps);
continue;
}
/* Swap only if color channel */
if((cn != acn) && (info[i].typ == 0))
{
if((cn != acn) && (info[i].typ == 0)) {
opj_image_comp_t saved;
OPJ_UINT16 j;
@@ -1270,12 +1249,10 @@ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_e
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
/* Swap channels in following channel definitions, don't bother with j <= i that are already processed */
for (j = (OPJ_UINT16)(i + 1U); j < n ; ++j)
{
for (j = (OPJ_UINT16)(i + 1U); j < n ; ++j) {
if (info[j].cn == cn) {
info[j].cn = acn;
}
else if (info[j].cn == acn) {
} else if (info[j].cn == acn) {
info[j].cn = cn;
}
/* asoc is related to color index. Do not update. */
@@ -1287,7 +1264,8 @@ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_e
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
opj_free(color->jp2_cdef); color->jp2_cdef = NULL;
opj_free(color->jp2_cdef);
color->jp2_cdef = NULL;
}/* jp2_apply_cdef() */
@@ -1334,8 +1312,7 @@ static OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2,
return OPJ_FALSE;
jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
if(!jp2->color.jp2_cdef)
{
if(!jp2->color.jp2_cdef) {
opj_free(cdef_info);
return OPJ_FALSE;
}
@@ -1409,16 +1386,11 @@ static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
p_colr_header_data += 4;
if(jp2->enumcs == 14)/* CIELab */
{
if(jp2->enumcs == 14) { /* CIELab */
OPJ_UINT32 *cielab;
OPJ_UINT32 rl, ol, ra, oa, rb, ob, il;
cielab = (OPJ_UINT32*)opj_malloc(9 * sizeof(OPJ_UINT32));
if(cielab == NULL){
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory for cielab\n");
return OPJ_FALSE;
}
cielab[0] = 14; /* enumcs */
/* default values */
@@ -1426,8 +1398,7 @@ static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
il = 0x00443530; /* D50 */
cielab[1] = 0x44454600;/* DEF */
if(p_colr_header_size == 35)
{
if(p_colr_header_size == 35) {
opj_read_bytes(p_colr_header_data, &rl, 4);
p_colr_header_data += 4;
opj_read_bytes(p_colr_header_data, &ol, 4);
@@ -1444,44 +1415,41 @@ static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
p_colr_header_data += 4;
cielab[1] = 0;
}
else if(p_colr_header_size != 7)
{
} else if(p_colr_header_size != 7) {
opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header box (CIELab, bad size: %d)\n", p_colr_header_size);
}
cielab[2] = rl; cielab[4] = ra; cielab[6] = rb;
cielab[3] = ol; cielab[5] = oa; cielab[7] = ob;
cielab[2] = rl;
cielab[4] = ra;
cielab[6] = rb;
cielab[3] = ol;
cielab[5] = oa;
cielab[7] = ob;
cielab[8] = il;
jp2->color.icc_profile_buf = (OPJ_BYTE*)cielab;
jp2->color.icc_profile_len = 0;
}
jp2->color.jp2_has_colr = 1;
}
else if (jp2->meth == 2) {
} else if (jp2->meth == 2) {
/* ICC profile */
OPJ_INT32 it_icc_value = 0;
OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1,(size_t)icc_len);
if (!jp2->color.icc_profile_buf)
{
if (!jp2->color.icc_profile_buf) {
jp2->color.icc_profile_len = 0;
return OPJ_FALSE;
}
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
{
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value) {
opj_read_bytes(p_colr_header_data,&l_value,1); /* icc values */
++p_colr_header_data;
jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value;
}
jp2->color.jp2_has_colr = 1;
}
else if (jp2->meth > 2)
{
} else if (jp2->meth > 2) {
/* ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values:
conforming JP2 reader shall ignore the entire Colour Specification box.*/
opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), "
@@ -1574,8 +1542,7 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
l_writers[0].handler = opj_jp2_write_ihdr;
l_writers[1].handler = opj_jp2_write_bpcc;
l_writers[2].handler = opj_jp2_write_colr;
}
else {
} else {
l_nb_pass = 2;
l_writers[0].handler = opj_jp2_write_ihdr;
l_writers[1].handler = opj_jp2_write_colr;
@@ -1654,7 +1621,7 @@ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
opj_event_mgr_t * p_manager )
{
OPJ_UINT32 i;
OPJ_UINT32 l_ftyp_size;
OPJ_UINT32 l_ftyp_size = 16 + 4 * jp2->numcl;
OPJ_BYTE * l_ftyp_data, * l_current_data_ptr;
OPJ_BOOL l_result;
@@ -1662,7 +1629,6 @@ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
assert(cio != 00);
assert(jp2 != 00);
assert(p_manager != 00);
l_ftyp_size = 16 + 4 * jp2->numcl;
l_ftyp_data = (OPJ_BYTE *) opj_calloc(1,l_ftyp_size);
@@ -1690,8 +1656,7 @@ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
}
l_result = (opj_stream_write_data(cio,l_ftyp_data,l_ftyp_size,p_manager) == l_ftyp_size);
if (! l_result)
{
if (! l_result) {
opj_event_msg(p_manager, EVT_ERROR, "Error while writing ftyp data to stream\n");
}
@@ -1777,11 +1742,6 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters)
jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
}
OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads)
{
return opj_j2k_set_threads(jp2->j2k, num_threads);
}
/* ----------------------------------------------------------------------- */
/* JP2 encoder interface */
/* ----------------------------------------------------------------------- */
@@ -1825,6 +1785,7 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->numcl = 1;
jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
if (!jp2->cl) {
jp2->cl = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return OPJ_FALSE;
}
@@ -1835,6 +1796,7 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->numcomps = image->numcomps; /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
if (!jp2->comps) {
jp2->comps = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
/* Memory of jp2->cl will be freed by opj_jp2_destroy */
return OPJ_FALSE;
@@ -1865,8 +1827,7 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
if(image->icc_profile_len) {
jp2->meth = 2;
jp2->enumcs = 0;
}
else {
} else {
jp2->meth = 1;
if (image->color_space == 1)
jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */
@@ -2024,8 +1985,7 @@ static OPJ_BOOL opj_jp2_setup_end_header_writing (opj_jp2_t *jp2, opj_event_mgr_
}
/* DEVELOPER CORNER, add your custom procedures */
#ifdef USE_JPIP
if( jp2->jpip_on )
{
if( jp2->jpip_on ) {
if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_cidx, p_manager)) {
return OPJ_FALSE;
}
@@ -2137,14 +2097,12 @@ static OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
jp2->jp2_state |= JP2_STATE_CODESTREAM;
opj_free(l_current_data);
return OPJ_TRUE;
}
else {
} else {
opj_event_msg(p_manager, EVT_ERROR, "bad placed jpeg codestream\n");
opj_free(l_current_data);
return OPJ_FALSE;
}
}
else if (box.length == 0) {
} else if (box.length == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
opj_free(l_current_data);
return OPJ_FALSE;
@@ -2205,8 +2163,7 @@ static OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
opj_free(l_current_data);
return OPJ_FALSE;
}
}
else {
} else {
if (!(jp2->jp2_state & JP2_STATE_SIGNATURE)) {
opj_event_msg(p_manager, EVT_ERROR, "Malformed JP2 file format: first box must be JPEG 2000 signature box\n");
opj_free(l_current_data);
@@ -2327,8 +2284,7 @@ static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id)
static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_id)
{
OPJ_UINT32 i, l_handler_size = sizeof(jp2_img_header) / sizeof(opj_jp2_header_handler_t);
for (i=0;i<l_handler_size;++i)
{
for (i=0; i<l_handler_size; ++i) {
if (jp2_img_header[i].id == p_id) {
return &jp2_img_header[i];
}
@@ -2442,8 +2398,7 @@ static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2,
}
}
for (i = 0; i < jp2->numcl; ++i)
{
for (i = 0; i < jp2->numcl; ++i) {
opj_read_bytes(p_header_data,&jp2->cl[i],4); /* CLi */
p_header_data += 4;
}
@@ -2544,8 +2499,7 @@ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
if (! l_current_handler->handler(jp2,p_header_data,l_current_data_size,p_manager)) {
return OPJ_FALSE;
}
}
else {
} else {
jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN;
}
@@ -2625,8 +2579,7 @@ static OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box,
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
return OPJ_FALSE;
}
}
else if (box->length == 0) {
} else if (box->length == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
return OPJ_FALSE;
}
@@ -2937,8 +2890,7 @@ opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder)
/* create the J2K codec */
if (! p_is_decoder) {
jp2->j2k = opj_j2k_create_compress();
}
else {
} else {
jp2->j2k = opj_j2k_create_decompress();
}

View File

@@ -70,8 +70,7 @@
/* ----------------------------------------------------------------------- */
typedef enum
{
typedef enum {
JP2_STATE_NONE = 0x0,
JP2_STATE_SIGNATURE = 0x1,
JP2_STATE_FILE_TYPE = 0x2,
@@ -82,8 +81,7 @@ typedef enum
}
JP2_STATE;
typedef enum
{
typedef enum {
JP2_IMG_STATE_NONE = 0x0,
JP2_IMG_STATE_UNKNOWN = 0x7fffffff
}
@@ -92,16 +90,14 @@ JP2_IMG_STATE;
/**
Channel description: channel index, type, association
*/
typedef struct opj_jp2_cdef_info
{
typedef struct opj_jp2_cdef_info {
OPJ_UINT16 cn, typ, asoc;
} opj_jp2_cdef_info_t;
/**
Channel descriptions and number of descriptions
*/
typedef struct opj_jp2_cdef
{
typedef struct opj_jp2_cdef {
opj_jp2_cdef_info_t *info;
OPJ_UINT16 n;
} opj_jp2_cdef_t;
@@ -109,8 +105,7 @@ typedef struct opj_jp2_cdef
/**
Component mappings: channel index, mapping type, palette index
*/
typedef struct opj_jp2_cmap_comp
{
typedef struct opj_jp2_cmap_comp {
OPJ_UINT16 cmp;
OPJ_BYTE mtyp, pcol;
} opj_jp2_cmap_comp_t;
@@ -118,8 +113,7 @@ typedef struct opj_jp2_cmap_comp
/**
Palette data: table entries, palette columns
*/
typedef struct opj_jp2_pclr
{
typedef struct opj_jp2_pclr {
OPJ_UINT32 *entries;
OPJ_BYTE *channel_sign;
OPJ_BYTE *channel_size;
@@ -131,8 +125,7 @@ typedef struct opj_jp2_pclr
/**
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_UINT32 icc_profile_len;
@@ -153,8 +146,7 @@ typedef struct opj_jp2_comps {
/**
JPEG-2000 file format reader/writer
*/
typedef struct opj_jp2
{
typedef struct opj_jp2 {
/** handle to the J2K codec */
opj_j2k_t *j2k;
/** list of validation procedures */
@@ -207,8 +199,7 @@ typedef struct opj_jp2_box {
OPJ_INT32 init_pos;
} opj_jp2_box_t;
typedef struct opj_jp2_header_handler
{
typedef struct opj_jp2_header_handler {
/* marker value */
OPJ_UINT32 id;
/* action linked to the marker */
@@ -220,8 +211,7 @@ typedef struct opj_jp2_header_handler
opj_jp2_header_handler_t;
typedef struct opj_jp2_img_header_writer_handler
{
typedef struct opj_jp2_img_header_writer_handler {
/* action to perform */
OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
/* result of the action : data */
@@ -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);
OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads);
/**
* Decode an image from a JPEG-2000 file stream
* @param jp2 JP2 decompressor handle

View File

@@ -74,9 +74,9 @@ const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
/* </summary> */
#ifdef __SSE2__
void opj_mct_encode(
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
@@ -116,9 +116,9 @@ void opj_mct_encode(
}
#else
void opj_mct_encode(
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
@@ -143,9 +143,9 @@ void opj_mct_encode(
/* </summary> */
#ifdef __SSE2__
void opj_mct_decode(
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
@@ -178,9 +178,9 @@ void opj_mct_decode(
}
#else
void opj_mct_decode(
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
@@ -201,7 +201,8 @@ void opj_mct_decode(
/* <summary> */
/* Get norm of basis function of reversible MCT. */
/* </summary> */
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno)
{
return opj_mct_norms[compno];
}
@@ -210,9 +211,9 @@ OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
/* </summary> */
#ifdef __SSE4_1__
void opj_mct_encode_real(
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
@@ -351,9 +352,9 @@ void opj_mct_encode_real(
}
#else
void opj_mct_encode_real(
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
@@ -375,9 +376,9 @@ void opj_mct_encode_real(
/* Inverse irreversible MCT. */
/* </summary> */
void opj_mct_decode_real(
OPJ_FLOAT32* OPJ_RESTRICT c0,
OPJ_FLOAT32* OPJ_RESTRICT c1,
OPJ_FLOAT32* OPJ_RESTRICT c2,
OPJ_FLOAT32* restrict c0,
OPJ_FLOAT32* restrict c1,
OPJ_FLOAT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
@@ -435,7 +436,8 @@ void opj_mct_decode_real(
/* <summary> */
/* Get norm of basis function of irreversible MCT. */
/* </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];
}

View File

@@ -60,7 +60,7 @@ Apply a reversible multi-component transform to an image
@param c2 Samples blue 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
@param c0 Samples for luminance component
@@ -68,7 +68,7 @@ Apply a reversible multi-component inverse transform to an image
@param c2 Samples for blue chrominance 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
@param compno Number of the component (0->Y, 1->U, 2->V)
@@ -83,7 +83,7 @@ Apply an irreversible multi-component transform to an image
@param c2 Samples blue 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
@param c0 Samples for luminance component
@@ -91,7 +91,7 @@ Apply an irreversible multi-component inverse transform to an image
@param c2 Samples for blue chrominance 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
@param compno Number of the component (0->Y, 1->U, 2->V)

View File

@@ -70,6 +70,28 @@ Fill mqc->c with 1's for flushing
@param mqc MQC handle
*/
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);
/*@}*/
/*@}*/
@@ -180,21 +202,15 @@ static opj_mqc_state_t mqc_states[47 * 2] = {
==========================================================
*/
static void opj_mqc_byteout(opj_mqc_t *mqc) {
/* avoid accessing uninitialized memory*/
if (mqc->bp == mqc->start-1) {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
}
else if (*mqc->bp == 0xff) {
static void opj_mqc_byteout(opj_mqc_t *mqc)
{
if (*mqc->bp == 0xff) {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
if ((mqc->c & 0x8000000) == 0) {
if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
@@ -217,7 +233,8 @@ static void opj_mqc_byteout(opj_mqc_t *mqc) {
}
}
static void opj_mqc_renorme(opj_mqc_t *mqc) {
static void opj_mqc_renorme(opj_mqc_t *mqc)
{
do {
mqc->a <<= 1;
mqc->c <<= 1;
@@ -228,7 +245,8 @@ static void opj_mqc_renorme(opj_mqc_t *mqc) {
} 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) {
if (mqc->a < (*mqc->curctx)->qeval) {
@@ -243,7 +261,8 @@ static void opj_mqc_codemps(opj_mqc_t *mqc) {
}
}
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->c += (*mqc->curctx)->qeval;
@@ -254,7 +273,8 @@ static void opj_mqc_codelps(opj_mqc_t *mqc) {
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;
if (mqc->c >= tempc) {
@@ -262,13 +282,95 @@ static void opj_mqc_setbits(opj_mqc_t *mqc) {
}
}
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
==========================================================
*/
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));
#ifdef MQC_PERF_OPT
if (mqc) {
@@ -278,7 +380,8 @@ opj_mqc_t* opj_mqc_create(void) {
return mqc;
}
void opj_mqc_destroy(opj_mqc_t *mqc) {
void opj_mqc_destroy(opj_mqc_t *mqc)
{
if(mqc) {
#ifdef MQC_PERF_OPT
if (mqc->buffer) {
@@ -289,7 +392,8 @@ void opj_mqc_destroy(opj_mqc_t *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;
#if 0
assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
@@ -297,17 +401,22 @@ OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) {
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 */
opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->bp = bp - 1;
mqc->ct = 12;
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);
} else {
@@ -315,7 +424,8 @@ void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) {
}
}
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_byteout(mqc);
@@ -327,7 +437,8 @@ void opj_mqc_flush(opj_mqc_t *mqc) {
}
}
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;
/*if (*mqc->bp == 0xff) {
@@ -335,7 +446,8 @@ void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) {
} */
}
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);
if (mqc->ct == 0) {
@@ -349,7 +461,8 @@ void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
}
}
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;
bit_padding = 0;
@@ -369,14 +482,16 @@ OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) {
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_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;
/* <flush part> */
@@ -392,7 +507,8 @@ OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) {
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);
mqc->a = 0x8000;
@@ -404,7 +520,8 @@ void opj_mqc_restart_init_enc(opj_mqc_t *mqc) {
}
}
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);
while (k > 0) {
@@ -419,7 +536,8 @@ void opj_mqc_erterm_enc(opj_mqc_t *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);
@@ -428,7 +546,8 @@ void opj_mqc_segmark_enc(opj_mqc_t *mqc) {
}
}
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;
mqc->end = bp + len;
@@ -487,14 +606,36 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
return OPJ_TRUE;
}
void opj_mqc_resetstates(opj_mqc_t *mqc) {
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;
}
void opj_mqc_resetstates(opj_mqc_t *mqc)
{
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) {
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

@@ -77,14 +77,11 @@ typedef struct opj_mqc {
OPJ_BYTE *end;
opj_mqc_state_t *ctxs[MQC_NUMCTXS];
opj_mqc_state_t **curctx;
const OPJ_BYTE *lut_ctxno_zc_orient; /* lut_ctxno_zc shifted by 256 * bandno */
#ifdef MQC_PERF_OPT
unsigned char *buffer;
#endif
} opj_mqc_t;
#include "mqc_inl.h"
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
@@ -201,7 +198,7 @@ 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 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 */

View File

@@ -132,7 +132,8 @@ static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
#ifdef _WIN32
#ifndef OPJ_STATIC
BOOL APIENTRY
DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
OPJ_ARG_NOT_USED(lpReserved);
OPJ_ARG_NOT_USED(hModule);
@@ -154,7 +155,8 @@ DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
/* ---------------------------------------------------------------------- */
const char* OPJ_CALLCONV opj_version(void) {
const char* OPJ_CALLCONV opj_version(void)
{
return OPJ_PACKAGE_VERSION;
}
@@ -239,9 +241,6 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
OPJ_UINT32 res_factor,
struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_resolution_factor;
l_codec->opj_set_threads =
(OPJ_BOOL (*) ( void * p_codec, OPJ_UINT32 num_threads )) opj_j2k_set_threads;
l_codec->m_codec = opj_j2k_create_decompress();
if (! l_codec->m_codec) {
@@ -318,9 +317,6 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager)) opj_jp2_set_decoded_resolution_factor;
l_codec->opj_set_threads =
(OPJ_BOOL (*) ( void * p_codec, OPJ_UINT32 num_threads )) opj_jp2_set_threads;
l_codec->m_codec = opj_jp2_create(OPJ_TRUE);
if (! l_codec->m_codec) {
@@ -340,7 +336,8 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
return (opj_codec_t*) l_codec;
}
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters)
{
if(parameters) {
memset(parameters, 0, sizeof(opj_dparameters_t));
/* default decoding parameters */
@@ -360,18 +357,6 @@ void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *paramete
}
}
OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec,
int num_threads)
{
if (p_codec && (num_threads >= 0)) {
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
return l_codec->opj_set_threads(l_codec->m_codec, (OPJ_UINT32)num_threads);
}
return OPJ_FALSE;
}
OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
opj_dparameters_t *parameters
)
@@ -649,7 +634,8 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
return (opj_codec_t*) l_codec;
}
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters)
{
if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */
@@ -861,8 +847,7 @@ void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec)
if (l_codec->is_decompressor) {
l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec);
}
else {
} else {
l_codec->m_codec_data.m_compression.opj_destroy(l_codec->m_codec);
}
@@ -900,7 +885,8 @@ opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
return NULL;
}
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) {
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info)
{
if (cstr_info) {
if ((*cstr_info)->m_default_tile_info.tccp_info) {
@@ -953,7 +939,8 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (
return NULL;
}
if(p_is_read_stream) mode = "rb"; else mode = "wb";
if(p_is_read_stream) mode = "rb";
else mode = "wb";
p_file = fopen(fname, mode);

View File

@@ -855,8 +855,7 @@ typedef struct opj_codestream_info {
/**
* Tile-component coding parameters information
*/
typedef struct opj_tccp_info
{
typedef struct opj_tccp_info {
/** component index */
OPJ_UINT32 compno;
/** coding style */
@@ -1262,25 +1261,6 @@ OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
opj_dparameters_t *parameters );
/**
* Allocates worker threads for the compressor/decompressor.
*
* By default, only the main thread is used. If this function is not used,
* but the OPJ_NUM_THREADS environment variable is set, its value will be
* used to initialize the number of threads. The value can be either an integer
* number, or "ALL_CPUS". If OPJ_NUM_THREADS is set and this function is called,
* this function will override the behaviour of the environment variable.
*
* Note: currently only has effect on the decompressor.
*
* @param p_codec decompressor handler
* @param num_threads number of threads.
*
* @return OPJ_TRUE if the decoder is correctly set
*/
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec,
int num_threads);
/**
* Decodes an image header.
*
@@ -1573,19 +1553,6 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
OPJ_INT32 * p_dc_shift,
OPJ_UINT32 pNbComp);
/*
==========================================================
Thread functions
==========================================================
*/
/** Returns if the library is built with thread support.
* OPJ_TRUE if mutex, condition, thread, thread pool are available.
*/
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void);
/** Return the number of virtual CPUs */
OPJ_API int OPJ_CALLCONV opj_get_num_cpus(void);
#ifdef __cplusplus

View File

@@ -39,7 +39,8 @@
#include <sys/times.h>
#endif /* _WIN32 */
OPJ_FLOAT64 opj_clock(void) {
OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;

View File

@@ -39,16 +39,13 @@
/**
* Main codec handler used for compression or decompression.
*/
typedef struct opj_codec_private
{
typedef struct opj_codec_private {
/** FIXME DOC */
union
{
union {
/**
* Decompression handler.
*/
struct opj_decompression
{
struct opj_decompression {
/** Main header reading function handler */
OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
void * p_codec,
@@ -113,14 +110,12 @@ typedef struct opj_codec_private
OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec,
OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager);
} m_decompression;
/**
* Compression handler. FIXME DOC
*/
struct opj_compression
{
struct opj_compression {
OPJ_BOOL (* opj_start_compress) ( void *p_codec,
struct opj_stream_private * cio,
struct opj_image * p_image,
@@ -158,9 +153,6 @@ typedef struct opj_codec_private
void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
/** Set number of threads */
OPJ_BOOL (*opj_set_threads) ( void * p_codec, OPJ_UINT32 num_threads );
}
opj_codec_private_t;

View File

@@ -54,7 +54,6 @@
#include <stdarg.h>
#include <ctype.h>
#include <assert.h>
#include <limits.h>
/*
Use fseeko() and ftello() if they are available since they use
@@ -103,39 +102,29 @@
==========================================================
*/
/* Ignore GCC attributes if this is not GCC */
#ifndef __GNUC__
#define __attribute__(x) /* __attribute__(x) */
#endif
/* Are restricted pointers available? (C99) */
#if (__STDC_VERSION__ >= 199901L)
#define OPJ_RESTRICT restrict
#else
#if (__STDC_VERSION__ != 199901L)
/* Not a C99 compiler */
#if defined(__GNUC__)
#define OPJ_RESTRICT __restrict__
/*
vc14 (2015) outputs wrong results.
Need to check OPJ_RESTRICT usage (or a bug in vc14)
#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
#define OPJ_RESTRICT __restrict
*/
#ifdef __GNUC__
#define restrict __restrict__
#else
#define OPJ_RESTRICT /* restrict */
#define restrict /* restrict */
#endif
#endif
#ifdef __has_attribute
#if __has_attribute(no_sanitize)
#define OPJ_NOSANITIZE(kind) __attribute__((no_sanitize(kind)))
#endif
#endif
#ifndef OPJ_NOSANITIZE
#define OPJ_NOSANITIZE(kind)
#endif
/* MSVC before 2013 and Borland C do not have lrintf */
#if defined(_MSC_VER)
#include <intrin.h>
static INLINE long opj_lrintf(float f){
static INLINE long opj_lrintf(float f)
{
#ifdef _M_X64
return _mm_cvt_ss2si(_mm_load_ss(&f));
@@ -154,7 +143,8 @@ static INLINE long opj_lrintf(float f){
#endif
}
#elif defined(__BORLANDC__)
static INLINE long opj_lrintf(float f) {
static INLINE long opj_lrintf(float f)
{
#ifdef _M_X64
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
#else
@@ -169,7 +159,8 @@ static INLINE long opj_lrintf(float f) {
#endif
}
#else
static INLINE long opj_lrintf(float f) {
static INLINE long opj_lrintf(float f)
{
return lrintf(f);
}
#endif
@@ -184,9 +175,6 @@ static INLINE long opj_lrintf(float f) {
# pragma intrinsic(__emul)
#endif
/* Type to use for bit-fields in internal headers */
typedef unsigned int OPJ_BITFIELD;
#include "opj_inttypes.h"
#include "opj_clock.h"
#include "opj_malloc.h"
@@ -195,9 +183,6 @@ typedef unsigned int OPJ_BITFIELD;
#include "bio.h"
#include "cio.h"
#include "thread.h"
#include "tls_keys.h"
#include "image.h"
#include "invert.h"
#include "j2k.h"

View File

@@ -53,7 +53,8 @@ The functions in OPJ_INTMATH.H have for goal to realize operations on integers.
Get the minimum of two integers
@return Returns a if a < b else b
*/
static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) {
static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b)
{
return a < b ? a : b;
}
@@ -61,7 +62,8 @@ static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) {
Get the minimum of two integers
@return Returns a if a < b else b
*/
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b)
{
return a < b ? a : b;
}
@@ -69,7 +71,8 @@ static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
Get the maximum of two integers
@return Returns a if a > b else b
*/
static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) {
static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b)
{
return (a > b) ? a : b;
}
@@ -77,7 +80,8 @@ static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) {
Get the maximum of two integers
@return Returns a if a > b else b
*/
static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) {
static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b)
{
return (a > b) ? a : b;
}
@@ -85,7 +89,8 @@ static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) {
Get the saturated sum of two unsigned integers
@return Returns saturated sum of a+b
*/
static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) {
static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b)
{
OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b;
return (OPJ_UINT32)(-(OPJ_INT32)(sum >> 32)) | (OPJ_UINT32)sum;
}
@@ -99,7 +104,8 @@ Clamp an integer inside an interval
<li>Returns min if (a < min)
</ul>
*/
static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max) {
static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max)
{
if (a < min)
return min;
if (a > max)
@@ -109,14 +115,16 @@ static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max)
/**
@return Get absolute value of integer
*/
static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a) {
static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a)
{
return a < 0 ? -a : a;
}
/**
Divide an integer and round upwards
@return Returns a divided by b
*/
static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b)
{
assert(b);
return (a + b - 1) / b;
}
@@ -125,7 +133,8 @@ static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
Divide an integer and round upwards
@return Returns a divided by b
*/
static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) {
static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b)
{
assert(b);
return (a + b - 1) / b;
}
@@ -134,7 +143,8 @@ static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) {
Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b)
{
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
}
@@ -142,7 +152,8 @@ static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
Divide a 64bits integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) {
static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b)
{
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
}
@@ -150,7 +161,8 @@ static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) {
Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) {
static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b)
{
return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b);
}
@@ -158,14 +170,16 @@ static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) {
Divide an integer by a power of 2 and round downwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) {
static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b)
{
return a >> b;
}
/**
Get logarithm of an integer and round downwards
@return Returns log2(a)
*/
static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) {
static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a)
{
OPJ_INT32 l;
for (l = 0; a > 1; l++) {
a >>= 1;
@@ -176,10 +190,10 @@ static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) {
Get logarithm of an integer and round downwards
@return Returns log2(a)
*/
static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a) {
OPJ_UINT32 l;
for (l = 0; a > 1; ++l)
static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a)
{
OPJ_UINT32 l;
for (l = 0; a > 1; ++l) {
a >>= 1;
}
return l;
@@ -191,7 +205,8 @@ Multiply two fixed-precision rational numbers.
@param b
@return Returns a * b
*/
static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b);
#else
@@ -203,7 +218,8 @@ static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
return (OPJ_INT32) (temp >> 13);
}
static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) {
static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b);
#else

View File

@@ -58,8 +58,7 @@ static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size)
* This function was introduced in POSIX 1003.1d. Although this function is
* superseded by aligned_alloc, it is more portable to older POSIX systems
* that do not support ISO C11. */
if (posix_memalign (&ptr, alignment, size))
{
if (posix_memalign (&ptr, alignment, size)) {
ptr = NULL;
}
/* older linux */
@@ -164,8 +163,7 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t ne
if (newmem == oldmem) {
r_ptr = ptr;
}
else {
} else {
size_t old_offset;
size_t new_offset;
@@ -196,10 +194,10 @@ void * opj_malloc(size_t size)
}
void * opj_calloc(size_t num, size_t size)
{
if (num == 0 || size == 0) {
/* prevent implementation defined behavior of realloc */
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
/* according to C89 standard, num == 0 shall return a valid pointer */
return calloc(num, size);
}

View File

@@ -57,9 +57,7 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
OPJ_OFF_T lenp = 0;
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
if(box == NULL){
return 0;
}
for( i=0; i<2; i++) {
if (i)
opj_stream_seek( cio, lenp, p_manager);
@@ -109,8 +107,7 @@ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
if( j2klen > pow( 2, 32)) {
size_of_coding = 8;
version = 1;
}
else{
} else {
size_of_coding = 4;
version = 0;
}

View File

@@ -230,7 +230,8 @@ static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
==========================================================
*/
static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) {
static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -261,7 +262,8 @@ static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) {
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:;
LABEL_SKIP:
;
}
}
}
@@ -270,7 +272,8 @@ LABEL_SKIP:;
return OPJ_FALSE;
}
static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) {
static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -300,7 +303,8 @@ static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) {
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:;
LABEL_SKIP:
;
}
}
}
@@ -309,7 +313,8 @@ LABEL_SKIP:;
return OPJ_FALSE;
}
static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) {
static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -382,7 +387,8 @@ if (!pi->tp_on){
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:;
LABEL_SKIP:
;
}
}
}
@@ -392,7 +398,8 @@ LABEL_SKIP:;
return OPJ_FALSE;
}
static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -463,7 +470,8 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:;
LABEL_SKIP:
;
}
}
}
@@ -473,7 +481,8 @@ LABEL_SKIP:;
return OPJ_FALSE;
}
static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -542,7 +551,8 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:;
LABEL_SKIP:
;
}
}
}
@@ -747,12 +757,10 @@ static void opj_get_all_encoding_parameters( const opj_image_t *p_image,
}
/* use custom size for precincts*/
l_level_no = l_tccp->numresolutions;
l_level_no = l_tccp->numresolutions - 1;
for (resno = 0; resno < l_tccp->numresolutions; ++resno) {
OPJ_UINT32 l_dx, l_dy;
--l_level_no;
/* precinct width and height*/
l_pdx = l_tccp->prcw[resno];
l_pdy = l_tccp->prch[resno];
@@ -784,6 +792,7 @@ static void opj_get_all_encoding_parameters( const opj_image_t *p_image,
*p_max_prec = l_product;
}
--l_level_no;
}
++l_tccp;
++l_img_comp;
@@ -1195,15 +1204,13 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_tmp_data = (OPJ_UINT32*)opj_malloc(
l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
if
(! l_tmp_data)
{
(! l_tmp_data) {
return 00;
}
l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
p_image->numcomps * sizeof(OPJ_UINT32 *));
if
(! l_tmp_ptr)
{
(! l_tmp_ptr) {
opj_free(l_tmp_data);
return 00;
}
@@ -1219,8 +1226,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_encoding_value_ptr = l_tmp_data;
/* update pointer array */
for
(compno = 0; compno < p_image->numcomps; ++compno)
{
(compno = 0; compno < p_image->numcomps; ++compno) {
l_tmp_ptr[compno] = l_encoding_value_ptr;
l_encoding_value_ptr += l_data_stride;
}
@@ -1237,16 +1243,9 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_current_pi = l_pi;
/* memory allocation for include */
/* prevent an integer overflow issue */
/* 0 < l_tcp->numlayers < 65536 c.f. opj_j2k_read_cod in j2k.c */
l_current_pi->include = 00;
if (l_step_l <= (SIZE_MAX / (l_tcp->numlayers + 1U)))
{
l_current_pi->include = (OPJ_INT16*) opj_calloc((size_t)(l_tcp->numlayers + 1U) * l_step_l, sizeof(OPJ_INT16));
}
if (!l_current_pi->include)
{
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
if
(!l_current_pi->include) {
opj_free(l_tmp_data);
opj_free(l_tmp_ptr);
opj_pi_destroy(l_pi, l_bound);
@@ -1273,8 +1272,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
/* allocation for components and number of components has already been calculated by opj_pi_create */
for
(compno = 0; compno < l_current_pi->numcomps; ++compno)
{
(compno = 0; compno < l_current_pi->numcomps; ++compno) {
opj_pi_resolution_t *l_res = l_current_comp->resolutions;
l_encoding_value_ptr = l_tmp_ptr[compno];
@@ -1282,8 +1280,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_current_comp->dy = l_img_comp->dy;
/* resolutions have already been initialized */
for
(resno = 0; resno < l_current_comp->numresolutions; resno++)
{
(resno = 0; resno < l_current_comp->numresolutions; resno++) {
l_res->pdx = *(l_encoding_value_ptr++);
l_res->pdy = *(l_encoding_value_ptr++);
l_res->pw = *(l_encoding_value_ptr++);
@@ -1296,8 +1293,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
}
++l_current_pi;
for (pino = 1 ; pino<l_bound ; ++pino )
{
for (pino = 1 ; pino<l_bound ; ++pino ) {
l_current_comp = l_current_pi->comps;
l_img_comp = p_image->comps;
l_tccp = l_tcp->tccps;
@@ -1315,8 +1311,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
/* allocation for components and number of components has already been calculated by opj_pi_create */
for
(compno = 0; compno < l_current_pi->numcomps; ++compno)
{
(compno = 0; compno < l_current_pi->numcomps; ++compno) {
opj_pi_resolution_t *l_res = l_current_comp->resolutions;
l_encoding_value_ptr = l_tmp_ptr[compno];
@@ -1324,8 +1319,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_current_comp->dy = l_img_comp->dy;
/* resolutions have already been initialized */
for
(resno = 0; resno < l_current_comp->numresolutions; resno++)
{
(resno = 0; resno < l_current_comp->numresolutions; resno++) {
l_res->pdx = *(l_encoding_value_ptr++);
l_res->pdy = *(l_encoding_value_ptr++);
l_res->pw = *(l_encoding_value_ptr++);
@@ -1345,12 +1339,9 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
opj_free(l_tmp_ptr);
l_tmp_ptr = 00;
if
(l_tcp->POC)
{
(l_tcp->POC) {
opj_pi_update_decode_poc (l_pi,l_tcp,l_max_prec,l_max_res);
}
else
{
} else {
opj_pi_update_decode_not_poc(l_pi,l_tcp,l_max_prec,l_max_res);
}
return l_pi;
@@ -1535,8 +1526,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) {
opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
}
else {
} else {
opj_pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
}
@@ -1769,15 +1759,18 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
incr_top=1;resetX=1;
incr_top=1;
resetX=1;
} else {
incr_top=0;resetX=0;
incr_top=0;
resetX=0;
}
} else {
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
incr_top=0;resetX=1;
incr_top=0;
resetX=1;
}
if(resetX==1) {
tcp->tx0_t = tcp->txS;
@@ -1858,13 +1851,13 @@ void opj_pi_update_encoding_parameters( const opj_image_t *p_image,
if (l_tcp->POC) {
opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
}
else {
} else {
opj_pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
}
}
OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi) {
OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi)
{
switch (pi->poc.prg) {
case OPJ_LRCP:
return opj_pi_next_lrcp(pi);

View File

@@ -61,9 +61,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
if(box == NULL){
return 0;
}
for (i=0; i<2; i++) {
if (i)
@@ -114,8 +112,7 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
if( j2klen > pow( 2, 32)) {
size_of_coding = 8;
version = 1;
}
else{
} else {
size_of_coding = 4;
version = 0;
}

View File

@@ -48,24 +48,28 @@
==========================================================
*/
opj_raw_t* opj_raw_create(void) {
opj_raw_t* opj_raw_create(void)
{
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw;
}
void opj_raw_destroy(opj_raw_t *raw) {
void opj_raw_destroy(opj_raw_t *raw)
{
if(raw) {
opj_free(raw);
}
}
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw) {
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw)
{
const ptrdiff_t diff = raw->bp - raw->start;
assert( diff <= (ptrdiff_t)0xffffffff && diff >= 0 ); /* UINT32_MAX */
return (OPJ_UINT32)diff;
}
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) {
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len)
{
raw->start = bp;
raw->lenmax = len;
raw->len = 0;
@@ -73,7 +77,8 @@ void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) {
raw->ct = 0;
}
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw) {
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw)
{
OPJ_UINT32 d;
if (raw->ct == 0) {
raw->ct = 8;
@@ -88,7 +93,7 @@ OPJ_UINT32 opj_raw_decode(opj_raw_t *raw) {
}
}
raw->ct--;
d = ((OPJ_UINT32)raw->c >> raw->ct) & 0x01U;
d = (raw->c >> raw->ct) & 0x01;
return d;
}

File diff suppressed because it is too large Load Diff

View File

@@ -50,30 +50,26 @@ in T1.C are used by some function in TCD.C.
/* ----------------------------------------------------------------------- */
#define T1_NMSEDEC_BITS 7
/* CAUTION: the value of those constants must not be changed, otherwise the */
/* optimization of opj_t1_updateflags() will break! */
/* BEGINNING of flags that apply to opj_flag_t */
#define T1_SIG_NE 0x0001U /**< Context orientation : North-East direction */
#define T1_SIG_SE 0x0002U /**< Context orientation : South-East direction */
#define T1_SIG_SW 0x0004U /**< Context orientation : South-West direction */
#define T1_SIG_NW 0x0008U /**< Context orientation : North-West direction */
#define T1_SIG_N 0x0010U /**< Context orientation : North direction */
#define T1_SIG_E 0x0020U /**< Context orientation : East direction */
#define T1_SIG_S 0x0040U /**< Context orientation : South direction */
#define T1_SIG_W 0x0080U /**< Context orientation : West direction */
#define T1_SIG_NE 0x0001 /**< Context orientation : North-East direction */
#define T1_SIG_SE 0x0002 /**< Context orientation : South-East direction */
#define T1_SIG_SW 0x0004 /**< Context orientation : South-West direction */
#define T1_SIG_NW 0x0008 /**< Context orientation : North-West direction */
#define T1_SIG_N 0x0010 /**< Context orientation : North direction */
#define T1_SIG_E 0x0020 /**< Context orientation : East direction */
#define T1_SIG_S 0x0040 /**< Context orientation : South direction */
#define T1_SIG_W 0x0080 /**< Context orientation : West direction */
#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW)
#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W)
#define T1_SGN_N 0x0100U
#define T1_SGN_E 0x0200U
#define T1_SGN_S 0x0400U
#define T1_SGN_W 0x0800U
#define T1_SGN_N 0x0100
#define T1_SGN_E 0x0200
#define T1_SGN_S 0x0400
#define T1_SGN_W 0x0800
#define T1_SGN (T1_SGN_N|T1_SGN_E|T1_SGN_S|T1_SGN_W)
#define T1_SIG 0x1000U /**< No longer used by decoder */
#define T1_REFINE 0x2000U /**< No longer used by decoder */
#define T1_VISIT 0x4000U /**< No longer used by decoder */
/* END of flags that apply to opj_flag_t */
#define T1_SIG 0x1000
#define T1_REFINE 0x2000
#define T1_VISIT 0x4000
#define T1_NUMCTXS_ZC 9
#define T1_NUMCTXS_SC 5
@@ -93,31 +89,9 @@ in T1.C are used by some function in TCD.C.
#define T1_TYPE_MQ 0 /**< Normal coding using entropy coder */
#define T1_TYPE_RAW 1 /**< No encoding the information is store under raw format in codestream (mode switch RAW)*/
/* Those flags are used by opj_colflag_t */
#define T1_COLFLAG_RBS 4U /* RBS = Row Bit Shift */
#define T1_COLFLAG_SIG_OTHER_ROW_0 (1U << 0U) /**< This sample has at least one significant neighbour */
#define T1_COLFLAG_SIG_ROW_0 (1U << 1U) /**< This sample is significant */
#define T1_COLFLAG_VISIT_ROW_0 (1U << 2U) /**< This sample has been visited */
#define T1_COLFLAG_REFINE_ROW_0 (1U << 3U) /**< This sample has been refined */
#define T1_COLFLAG_SIG_OTHER_ROW_1 (T1_COLFLAG_SIG_OTHER_ROW_0 << (1U * T1_COLFLAG_RBS))
#define T1_COLFLAG_SIG_ROW_1 (T1_COLFLAG_SIG_ROW_0 << (1U * T1_COLFLAG_RBS))
#define T1_COLFLAG_VISIT_ROW_1 (T1_COLFLAG_VISIT_ROW_0 << (1U * T1_COLFLAG_RBS))
#define T1_COLFLAG_REFINE_ROW_1 (T1_COLFLAG_REFINE_ROW_0 << (1U * T1_COLFLAG_RBS))
#define T1_COLFLAG_SIG_OTHER_ROW_2 (T1_COLFLAG_SIG_OTHER_ROW_0 << (2U * T1_COLFLAG_RBS))
#define T1_COLFLAG_SIG_ROW_2 (T1_COLFLAG_SIG_ROW_0 << (2U * T1_COLFLAG_RBS))
#define T1_COLFLAG_VISIT_ROW_2 (T1_COLFLAG_VISIT_ROW_0 << (2U * T1_COLFLAG_RBS))
#define T1_COLFLAG_REFINE_ROW_2 (T1_COLFLAG_REFINE_ROW_0 << (2U * T1_COLFLAG_RBS))
#define T1_COLFLAG_SIG_OTHER_ROW_3 (T1_COLFLAG_SIG_OTHER_ROW_0 << (3U * T1_COLFLAG_RBS))
#define T1_COLFLAG_SIG_ROW_3 (T1_COLFLAG_SIG_ROW_0 << (3U * T1_COLFLAG_RBS))
#define T1_COLFLAG_VISIT_ROW_3 (T1_COLFLAG_VISIT_ROW_0 << (3U * T1_COLFLAG_RBS))
#define T1_COLFLAG_REFINE_ROW_3 (T1_COLFLAG_REFINE_ROW_0 << (3U * T1_COLFLAG_RBS))
/* ----------------------------------------------------------------------- */
typedef OPJ_UINT16 opj_flag_t;
/** Flags for 4 consecutive rows of a column */
typedef OPJ_UINT16 opj_colflag_t;
typedef OPJ_INT16 opj_flag_t;
/**
Tier-1 coding (coding of code-block coefficients)
@@ -131,17 +105,11 @@ typedef struct opj_t1 {
OPJ_INT32 *data;
opj_flag_t *flags;
/** Addition flag array such that colflags[1+0] is for state of col=0,row=0..3,
colflags[1+1] for col=1, row=0..3, colflags[1+flags_stride] for col=0,row=4..7, ...
This array avoids too much cache trashing when processing by 4 vertical samples
as done in the various decoding steps. */
opj_colflag_t* colflags;
OPJ_UINT32 w;
OPJ_UINT32 h;
OPJ_UINT32 datasize;
OPJ_UINT32 flagssize;
OPJ_UINT32 flags_stride;
OPJ_UINT32 colflags_size;
OPJ_UINT32 data_stride;
OPJ_BOOL encoder;
} opj_t1_t;
@@ -172,8 +140,7 @@ Decode the code-blocks of a tile
@param tilec The tile to decode
@param tccp Tile coding parameters
*/
void opj_t1_decode_cblks( opj_thread_pool_t* tp,
volatile OPJ_BOOL* pret,
OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
opj_tcd_tilecomp_t* tilec,
opj_tccp_t* tccp);

View File

@@ -38,21 +38,19 @@
#include "opj_includes.h"
static int t1_init_ctxno_zc(unsigned int f, unsigned int orient) {
static int t1_init_ctxno_zc(int f, int orient)
{
int h, v, d, n, t, hv;
n = 0;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0);
d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0);
n = 0;
t = 0;
hv = 0;
switch (orient) {
case 2:
t = h;
h = v;
v = t;
/* fall through */
case 0:
case 1:
if (!h) {
@@ -113,7 +111,8 @@ static int t1_init_ctxno_zc(unsigned int f, unsigned int orient) {
return (T1_CTXNO_ZC + n);
}
static int t1_init_ctxno_sc(unsigned int f) {
static int t1_init_ctxno_sc(int f)
{
int hc, vc, n;
n = 0;
@@ -154,7 +153,8 @@ static int t1_init_ctxno_sc(unsigned int f) {
return (T1_CTXNO_SC + n);
}
static int t1_init_spb(unsigned int f) {
static int t1_init_spb(int f)
{
int hc, vc, n;
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
@@ -179,7 +179,8 @@ static int t1_init_spb(unsigned int f) {
return n;
}
static void dump_array16(int array[],int size){
static void dump_array16(int array[],int size)
{
int i;
--size;
for (i = 0; i < size; ++i) {
@@ -192,7 +193,7 @@ static void dump_array16(int array[],int size){
int main(int argc, char **argv)
{
unsigned int i, j;
int i, j;
double u, v, t;
int lut_ctxno_zc[1024];
@@ -200,52 +201,53 @@ int main(int argc, char **argv)
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
(void)argc; (void)argv;
(void)argc;
(void)argv;
printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");
/* lut_ctxno_zc */
for (j = 0U; j < 4U; ++j) {
for (i = 0U; i < 256U; ++i) {
unsigned int orient = j;
if (orient == 2U) {
orient = 1U;
} else if (orient == 1U) {
orient = 2U;
for (j = 0; j < 4; ++j) {
for (i = 0; i < 256; ++i) {
int orient = j;
if (orient == 2) {
orient = 1;
} else if (orient == 1) {
orient = 2;
}
lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
}
}
printf("static const OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
for (i = 0U; i < 1023U; ++i) {
printf("static OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
for (i = 0; i < 1023; ++i) {
printf("%i, ", lut_ctxno_zc[i]);
if(!((i+1U)&0x1fU))
if(!((i+1)&0x1f))
printf("\n ");
}
printf("%i\n};\n\n", lut_ctxno_zc[1023]);
/* lut_ctxno_sc */
printf("static const OPJ_BYTE lut_ctxno_sc[256] = {\n ");
for (i = 0U; i < 255U; ++i) {
printf("static OPJ_BYTE lut_ctxno_sc[256] = {\n ");
for (i = 0; i < 255; ++i) {
printf("0x%x, ", t1_init_ctxno_sc(i << 4));
if(!((i+1U)&0xfU))
if(!((i+1)&0xf))
printf("\n ");
}
printf("0x%x\n};\n\n", t1_init_ctxno_sc(255U << 4));
printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));
/* lut_spb */
printf("static const OPJ_BYTE lut_spb[256] = {\n ");
for (i = 0U; i < 255U; ++i) {
printf("static OPJ_BYTE lut_spb[256] = {\n ");
for (i = 0; i < 255; ++i) {
printf("%i, ", t1_init_spb(i << 4));
if(!((i+1U)&0x1fU))
if(!((i+1)&0x1f))
printf("\n ");
}
printf("%i\n};\n\n", t1_init_spb(255U << 4));
printf("%i\n};\n\n", t1_init_spb(255 << 4));
/* FIXME FIXME FIXME */
/* fprintf(stdout,"nmsedec luts:\n"); */
for (i = 0U; i < (1U << T1_NMSEDEC_BITS); ++i) {
for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
t = i / pow(2, T1_NMSEDEC_FRACBITS);
u = t;
v = t - 1.5;
@@ -269,17 +271,17 @@ int main(int argc, char **argv)
(int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
}
printf("static const OPJ_INT16 lut_nmsedec_sig[1U << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig, 1U << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);
printf("static const OPJ_INT16 lut_nmsedec_sig0[1U << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig0, 1U << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);
printf("static const OPJ_INT16 lut_nmsedec_ref[1U << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref, 1U << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);
printf("static const OPJ_INT16 lut_nmsedec_ref0[1U << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref0, 1U << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS);
return 0;
}

View File

@@ -1,6 +1,6 @@
/* This file was automatically generated by t1_generate_luts.c */
static const OPJ_BYTE lut_ctxno_zc[1024] = {
static OPJ_BYTE lut_ctxno_zc[1024] = {
0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
@@ -35,7 +35,7 @@ static const OPJ_BYTE lut_ctxno_zc[1024] = {
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8
};
static const OPJ_BYTE lut_ctxno_sc[256] = {
static OPJ_BYTE lut_ctxno_sc[256] = {
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xd, 0xc, 0xd, 0xd, 0xd, 0xd, 0xd,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xb, 0xc, 0xb, 0xd, 0xc, 0xd, 0xc,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xd, 0x9, 0xa, 0xd, 0xd, 0xa, 0xa,
@@ -54,7 +54,7 @@ static const OPJ_BYTE lut_ctxno_sc[256] = {
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xd, 0xc, 0xd, 0xd, 0xd, 0xd, 0xd
};
static const OPJ_BYTE lut_spb[256] = {
static OPJ_BYTE lut_spb[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -65,7 +65,7 @@ static const OPJ_BYTE lut_spb[256] = {
0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
static const OPJ_INT16 lut_nmsedec_sig[1U << T1_NMSEDEC_BITS] = {
static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
@@ -84,7 +84,7 @@ static const OPJ_INT16 lut_nmsedec_sig[1U << T1_NMSEDEC_BITS] = {
0x6c00, 0x6d80, 0x6f00, 0x7080, 0x7200, 0x7380, 0x7500, 0x7680
};
static const OPJ_INT16 lut_nmsedec_sig0[1U << T1_NMSEDEC_BITS] = {
static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
@@ -103,7 +103,7 @@ static const OPJ_INT16 lut_nmsedec_sig0[1U << T1_NMSEDEC_BITS] = {
0x7080, 0x7280, 0x7480, 0x7600, 0x7800, 0x7a00, 0x7c00, 0x7e00
};
static const OPJ_INT16 lut_nmsedec_ref[1U << T1_NMSEDEC_BITS] = {
static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {
0x1800, 0x1780, 0x1700, 0x1680, 0x1600, 0x1580, 0x1500, 0x1480,
0x1400, 0x1380, 0x1300, 0x1280, 0x1200, 0x1180, 0x1100, 0x1080,
0x1000, 0x0f80, 0x0f00, 0x0e80, 0x0e00, 0x0d80, 0x0d00, 0x0c80,
@@ -122,7 +122,7 @@ static const OPJ_INT16 lut_nmsedec_ref[1U << T1_NMSEDEC_BITS] = {
0x1400, 0x1480, 0x1500, 0x1580, 0x1600, 0x1680, 0x1700, 0x1780
};
static const OPJ_INT16 lut_nmsedec_ref0[1U << T1_NMSEDEC_BITS] = {
static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {
0x2000, 0x1f00, 0x1e00, 0x1d00, 0x1c00, 0x1b00, 0x1a80, 0x1980,
0x1880, 0x1780, 0x1700, 0x1600, 0x1500, 0x1480, 0x1380, 0x1300,
0x1200, 0x1180, 0x1080, 0x1000, 0x0f00, 0x0e80, 0x0e00, 0x0d00,

View File

@@ -156,7 +156,8 @@ static OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
/* ----------------------------------------------------------------------- */
/* #define RESTART 0x04 */
static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n) {
static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n)
{
while (--n >= 0) {
opj_bio_write(bio, 1, 1);
}
@@ -172,7 +173,8 @@ static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio)
return n;
}
static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) {
static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n)
{
if (n == 1) {
opj_bio_write(bio, 0, 1);
} else if (n == 2) {
@@ -186,7 +188,8 @@ static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) {
}
}
static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) {
static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio)
{
OPJ_UINT32 n;
if (!opj_bio_read(bio, 1))
return 1;
@@ -279,8 +282,7 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
++l_current_pi;
}
}
}
else { /* t2_mode == FINAL_PASS */
} else { /* t2_mode == FINAL_PASS */
opj_pi_create_encode(l_pi, l_cp,p_tile_no,p_pino,p_tp_num,p_tp_pos,p_t2_mode);
l_current_pi = &l_pi[p_pino];
@@ -402,8 +404,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
}
first_pass_failed = (OPJ_BOOL*)opj_malloc(l_image->numcomps * sizeof(OPJ_BOOL));
if (!first_pass_failed)
{
if (!first_pass_failed) {
opj_pi_destroy(l_pi,l_nb_pocs);
return OPJ_FALSE;
}
@@ -427,8 +428,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
l_img_comp = &(l_image->comps[l_current_pi->compno]);
l_img_comp->resno_decoded = opj_uint_max(l_current_pi->resno, l_img_comp->resno_decoded);
}
else {
} else {
l_nb_bytes_read = 0;
if (! opj_t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info, p_manager)) {
opj_pi_destroy(l_pi,l_nb_pocs);
@@ -511,7 +511,8 @@ opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp)
return l_t2;
}
void opj_t2_destroy(opj_t2_t *t2) {
void opj_t2_destroy(opj_t2_t *t2)
{
if(t2) {
opj_free(t2);
}
@@ -868,14 +869,9 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* reset tagtrees */
for (bandno = 0; bandno < l_res->numbands; ++bandno) {
if ( ! ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) ) {
opj_tcd_precinct_t *l_prc = &l_band->precincts[p_pi->precno];
if (!(p_pi->precno < (l_band->precincts_data_size / sizeof(opj_tcd_precinct_t)))) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid precinct\n");
return OPJ_FALSE;
}
if ( ! ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) ) {
opj_tgt_reset(l_prc->incltree);
opj_tgt_reset(l_prc->imsbtree);
l_cblk = l_prc->cblks.dec;
@@ -923,13 +919,11 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
l_header_data = *l_header_data_start;
l_modified_length_ptr = &(l_cp->ppm_len);
}
else if (p_tcp->ppt == 1) { /* PPT */
} else if (p_tcp->ppt == 1) { /* PPT */
l_header_data_start = &(p_tcp->ppt_data);
l_header_data = *l_header_data_start;
l_modified_length_ptr = &(p_tcp->ppt_len);
}
else { /* Normal Case */
} else { /* Normal Case */
l_header_data_start = &(l_current_data);
l_header_data = *l_header_data_start;
l_remaining_length = (OPJ_UINT32)(p_src_data+p_max_length-l_header_data);
@@ -993,8 +987,7 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
if (!l_cblk->numsegs) {
l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1));
/* else one bit */
}
else {
} else {
l_included = opj_bio_read(l_bio, 1);
}
@@ -1031,8 +1024,7 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
opj_bio_destroy(l_bio);
return OPJ_FALSE;
}
}
else {
} else {
l_segno = l_cblk->numsegs - 1;
if (l_cblk->segs[l_segno].numpasses == l_cblk->segs[l_segno].maxpasses) {
++l_segno;
@@ -1149,8 +1141,7 @@ static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
l_seg = l_cblk->segs;
++l_cblk->numsegs;
l_cblk->data_current_size = 0;
}
else {
} else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
if (l_seg->numpasses == l_seg->maxpasses) {
@@ -1284,8 +1275,7 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
l_seg = l_cblk->segs;
++l_cblk->numsegs;
l_cblk->data_current_size = 0;
}
else {
} else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
if (l_seg->numpasses == l_seg->maxpasses) {
@@ -1326,8 +1316,7 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
l_seg->numpasses += l_seg->numnewpasses;
l_cblk->numnewpasses -= l_seg->numnewpasses;
if (l_cblk->numnewpasses > 0)
{
if (l_cblk->numnewpasses > 0) {
++l_seg;
++l_cblk->numsegs;
}
@@ -1371,8 +1360,7 @@ static OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
if (cblksty & J2K_CCP_CBLKSTY_TERMALL) {
seg->maxpasses = 1;
}
else if (cblksty & J2K_CCP_CBLKSTY_LAZY) {
} else if (cblksty & J2K_CCP_CBLKSTY_LAZY) {
if (first) {
seg->maxpasses = 10;
} else {

View File

@@ -44,7 +44,8 @@
/* TODO MSD: */
#ifdef TODO_MSD
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) {
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img)
{
int tileno, compno, resno, bandno, precno;/*, cblkno;*/
fprintf(fd, "image {\n");
@@ -206,7 +207,8 @@ opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder)
/* ----------------------------------------------------------------------- */
void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd) {
void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd)
{
OPJ_UINT32 layno;
for (layno = 0; layno < tcd->tcp->numlayers; layno++) {
@@ -300,7 +302,8 @@ void opj_tcd_makelayer( opj_tcd_t *tcd,
}
}
void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final) {
void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final)
{
OPJ_UINT32 compno, resno, bandno, precno, cblkno;
OPJ_INT32 value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3]; */
OPJ_INT32 matrice[10][10][3];
@@ -486,7 +489,8 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
for (layno = 0; layno < tcd_tcp->numlayers; layno++) {
OPJ_FLOAT64 lo = min;
OPJ_FLOAT64 hi = max;
OPJ_UINT32 maxlen = tcd_tcp->rates[layno] > 0.0f ? opj_uint_min(((OPJ_UINT32) ceil(tcd_tcp->rates[layno])), len) : len;
OPJ_BOOL success = OPJ_FALSE;
OPJ_UINT32 maxlen = tcd_tcp->rates[layno] ? opj_uint_min(((OPJ_UINT32) ceil(tcd_tcp->rates[layno])), len) : len;
OPJ_FLOAT64 goodthresh = 0;
OPJ_FLOAT64 stable_thresh = 0;
OPJ_UINT32 i;
@@ -499,7 +503,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
-r xx,yy,zz,0 (disto_alloc == 1 and rates == 0)
-q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0)
==> possible to have some lossy layers and the last layer for sure lossless */
if ( ((cp->m_specific_param.m_enc.m_disto_alloc==1) && (tcd_tcp->rates[layno]>0.0f)) || ((cp->m_specific_param.m_enc.m_fixed_quality==1) && (tcd_tcp->distoratio[layno]>0.0))) {
if ( ((cp->m_specific_param.m_enc.m_disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->m_specific_param.m_enc.m_fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) {
opj_t2_t*t2 = opj_t2_create(tcd->image, cp);
OPJ_FLOAT64 thresh = 0;
@@ -520,8 +524,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
lo = thresh;
continue;
}
else {
} else {
distoachieved = layno == 0 ?
tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno];
@@ -545,8 +548,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
lo = thresh;
}
} else {
if (! opj_t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest,p_data_written, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC))
{
if (! opj_t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest,p_data_written, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC)) {
/* TODO: what to do with l ??? seek / tell ??? */
/* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */
lo = thresh;
@@ -558,13 +560,19 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
}
}
success = OPJ_TRUE;
goodthresh = stable_thresh == 0? thresh : stable_thresh;
opj_t2_destroy(t2);
} else {
success = OPJ_TRUE;
goodthresh = min;
}
if (!success) {
return OPJ_FALSE;
}
if(cstr_info) { /* Threshold for Marcela Index */
cstr_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh;
}
@@ -580,8 +588,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
opj_image_t * p_image,
opj_cp_t * p_cp,
opj_thread_pool_t* p_tp )
opj_cp_t * p_cp )
{
p_tcd->image = p_image;
p_tcd->cp = p_cp;
@@ -598,7 +605,6 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
p_tcd->tcd_image->tiles->numcomps = p_image->numcomps;
p_tcd->tp_pos = p_cp->m_specific_param.m_enc.m_tp_pos;
p_tcd->thread_pool = p_tp;
return OPJ_TRUE;
}
@@ -606,7 +612,8 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
/**
Destroy a previously created TCD handle
*/
void opj_tcd_destroy(opj_tcd_t *tcd) {
void opj_tcd_destroy(opj_tcd_t *tcd)
{
if (tcd) {
opj_tcd_free_tile(tcd);
@@ -628,8 +635,7 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
/*fprintf(stderr, "tAllocate data of tilec (int): %d x OPJ_UINT32n",l_data_size);*/
l_tilec->data_size = l_tilec->data_size_needed;
l_tilec->ownsData = OPJ_TRUE;
}
else if (l_tilec->data_size_needed > l_tilec->data_size) {
} else if (l_tilec->data_size_needed > l_tilec->data_size) {
/* We don't need to keep old data */
opj_aligned_free(l_tilec->data);
l_tilec->data = (OPJ_INT32 *) opj_aligned_malloc(l_tilec->data_size_needed);
@@ -698,20 +704,9 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
l_tx0 = l_cp->tx0 + p * l_cp->tdx; /* can't be greater than l_image->x1 so won't overflow */
l_tile->x0 = (OPJ_INT32)opj_uint_max(l_tx0, l_image->x0);
l_tile->x1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_tx0, l_cp->tdx), l_image->x1);
/* all those OPJ_UINT32 are casted to OPJ_INT32, let's do some sanity check */
if ((l_tile->x0 < 0) || (l_tile->x1 <= l_tile->x0)) {
opj_event_msg(manager, EVT_ERROR, "Tile X coordinates are not supported\n");
return OPJ_FALSE;
}
l_ty0 = l_cp->ty0 + q * l_cp->tdy; /* can't be greater than l_image->y1 so won't overflow */
l_tile->y0 = (OPJ_INT32)opj_uint_max(l_ty0, l_image->y0);
l_tile->y1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_ty0, l_cp->tdy), l_image->y1);
/* all those OPJ_UINT32 are casted to OPJ_INT32, let's do some sanity check */
if ((l_tile->y0 < 0) || (l_tile->y1 <= l_tile->y0)) {
opj_event_msg(manager, EVT_ERROR, "Tile Y coordinates are not supported\n");
return OPJ_FALSE;
}
/* testcase 1888.pdf.asan.35.988 */
if (l_tccp->numresolutions == 0) {
@@ -733,8 +728,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
/* compute l_data_size with overflow check */
l_data_size = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0);
/* issue 733, l_data_size == 0U, probably something wrong should be checked before getting here */
if ((l_data_size > 0U) && ((((OPJ_UINT32)-1) / l_data_size) < (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0))) {
if ((((OPJ_UINT32)-1) / l_data_size) < (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0)) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile data\n");
return OPJ_FALSE;
}
@@ -748,8 +742,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
l_tilec->numresolutions = l_tccp->numresolutions;
if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_reduce) {
l_tilec->minimum_num_resolutions = 1;
}
else {
} else {
l_tilec->minimum_num_resolutions = l_tccp->numresolutions - l_cp->m_specific_param.m_dec.m_reduce;
}
@@ -769,8 +762,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
/*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %d\n",l_data_size);*/
l_tilec->resolutions_size = l_data_size;
memset(l_tilec->resolutions,0,l_data_size);
}
else if (l_data_size > l_tilec->resolutions_size) {
} else if (l_data_size > l_tilec->resolutions_size) {
opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolution_t *) opj_realloc(l_tilec->resolutions, l_data_size);
if (! new_resolutions) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile resolutions\n");
@@ -785,13 +777,12 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
l_tilec->resolutions_size = l_data_size;
}
l_level_no = l_tilec->numresolutions;
l_level_no = l_tilec->numresolutions - 1;
l_res = l_tilec->resolutions;
l_step_size = l_tccp->stepsizes;
if (l_tccp->qmfbid == 0) {
l_gain_ptr = &opj_dwt_getgain_real;
}
else {
} else {
l_gain_ptr = &opj_dwt_getgain;
}
/*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/
@@ -802,8 +793,6 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
OPJ_UINT32 cbgwidthexpn, cbgheightexpn;
OPJ_UINT32 cblkwidthexpn, cblkheightexpn;
--l_level_no;
/* border for each resolution level (global) */
l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)l_level_no);
l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no);
@@ -821,22 +810,12 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT32)l_pdy) << l_pdy;
/*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end ,l_br_prc_y_end );*/
l_res->pw = (l_res->x0 == l_res->x1) ? 0U : (OPJ_UINT32)((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx);
l_res->ph = (l_res->y0 == l_res->y1) ? 0U : (OPJ_UINT32)((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy);
l_res->pw = (l_res->x0 == l_res->x1) ? 0 : (OPJ_UINT32)((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx);
l_res->ph = (l_res->y0 == l_res->y1) ? 0 : (OPJ_UINT32)((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy);
/*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res->pw, l_res->ph );*/
if ((l_res->pw != 0U) && ((((OPJ_UINT32)-1) / l_res->pw) < l_res->ph)) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile data\n");
return OPJ_FALSE;
}
l_nb_precincts = l_res->pw * l_res->ph;
if ((((OPJ_UINT32)-1) / (OPJ_UINT32)sizeof(opj_tcd_precinct_t)) < l_nb_precincts) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile data\n");
return OPJ_FALSE;
}
l_nb_precinct_size = l_nb_precincts * (OPJ_UINT32)sizeof(opj_tcd_precinct_t);
if (resno == 0) {
tlcbgxstart = l_tl_prc_x_start;
tlcbgystart = l_tl_prc_y_start;
@@ -845,8 +824,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
cbgwidthexpn = l_pdx;
cbgheightexpn = l_pdy;
l_res->numbands = 1;
}
else {
} else {
tlcbgxstart = opj_int_ceildivpow2(l_tl_prc_x_start, 1);
tlcbgystart = opj_int_ceildivpow2(l_tl_prc_y_start, 1);
/*brcbgxend = opj_int_ceildivpow2(l_br_prc_x_end, 1);*/
@@ -870,8 +848,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
l_band->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no);
l_band->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)l_level_no);
l_band->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)l_level_no);
}
else {
} else {
l_band->bandno = bandno + 1;
/* x0b = 1 if bandno = 1 or 3 */
l_x0b = l_band->bandno&1;
@@ -893,14 +870,12 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
if (!l_band->precincts && (l_nb_precincts > 0U)) {
l_band->precincts = (opj_tcd_precinct_t *) opj_malloc( /*3 * */ l_nb_precinct_size);
if (! l_band->precincts) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to handle band precints\n");
return OPJ_FALSE;
}
/*fprintf(stderr, "\t\t\t\tAllocate precincts of a band (opj_tcd_precinct_t): %d\n",l_nb_precinct_size); */
memset(l_band->precincts,0,l_nb_precinct_size);
l_band->precincts_data_size = l_nb_precinct_size;
}
else if (l_band->precincts_data_size < l_nb_precinct_size) {
} else if (l_band->precincts_data_size < l_nb_precinct_size) {
opj_tcd_precinct_t * new_precincts = (opj_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size);
if (! new_precincts) {
@@ -960,8 +935,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
memset(l_current_precinct->cblks.blocks,0,l_nb_code_blocks_size);
l_current_precinct->block_size = l_nb_code_blocks_size;
}
else if (l_nb_code_blocks_size > l_current_precinct->block_size) {
} else if (l_nb_code_blocks_size > l_current_precinct->block_size) {
void *new_blocks = opj_realloc(l_current_precinct->cblks.blocks, l_nb_code_blocks_size);
if (! new_blocks) {
opj_free(l_current_precinct->cblks.blocks);
@@ -982,8 +956,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
if (! l_current_precinct->incltree) {
l_current_precinct->incltree = opj_tgt_create(l_current_precinct->cw, l_current_precinct->ch, manager);
}
else{
} else {
l_current_precinct->incltree = opj_tgt_init(l_current_precinct->incltree, l_current_precinct->cw, l_current_precinct->ch, manager);
}
@@ -994,8 +967,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
if (! l_current_precinct->imsbtree) {
l_current_precinct->imsbtree = opj_tgt_create(l_current_precinct->cw, l_current_precinct->ch, manager);
}
else {
} else {
l_current_precinct->imsbtree = opj_tgt_init(l_current_precinct->imsbtree, l_current_precinct->cw, l_current_precinct->ch, manager);
}
@@ -1044,6 +1016,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
++l_step_size;
} /* bandno */
++l_res;
--l_level_no;
} /* resno */
++l_tccp;
++l_tilec;
@@ -1307,8 +1280,7 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd,
/*--------------TIER2------------------*/
/* FIXME _ProfStart(PGROUP_T2); */
l_data_read = 0;
if (! opj_tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_index, p_manager))
{
if (! opj_tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_index, p_manager)) {
return OPJ_FALSE;
}
/* FIXME _ProfStop(PGROUP_T2); */
@@ -1317,8 +1289,7 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd,
/* FIXME _ProfStart(PGROUP_T1); */
if
(! opj_tcd_t1_decode(p_tcd))
{
(! opj_tcd_t1_decode(p_tcd)) {
return OPJ_FALSE;
}
/* FIXME _ProfStop(PGROUP_T1); */
@@ -1327,8 +1298,7 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd,
/* FIXME _ProfStart(PGROUP_DWT); */
if
(! opj_tcd_dwt_decode(p_tcd))
{
(! opj_tcd_dwt_decode(p_tcd)) {
return OPJ_FALSE;
}
/* FIXME _ProfStop(PGROUP_DWT); */
@@ -1336,16 +1306,14 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd,
/*----------------MCT-------------------*/
/* FIXME _ProfStart(PGROUP_MCT); */
if
(! opj_tcd_mct_decode(p_tcd, p_manager))
{
(! opj_tcd_mct_decode(p_tcd, p_manager)) {
return OPJ_FALSE;
}
/* FIXME _ProfStop(PGROUP_MCT); */
/* FIXME _ProfStart(PGROUP_DC_SHIFT); */
if
(! opj_tcd_dc_level_shift_decode(p_tcd))
{
(! opj_tcd_dc_level_shift_decode(p_tcd)) {
return OPJ_FALSE;
}
/* FIXME _ProfStop(PGROUP_DC_SHIFT); */
@@ -1391,10 +1359,8 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
l_size_comp = 4;
}
switch (l_size_comp)
{
case 1:
{
switch (l_size_comp) {
case 1: {
OPJ_CHAR * l_dest_ptr = (OPJ_CHAR *) p_dest;
const OPJ_INT32 * l_src_ptr = l_tilec->data;
@@ -1405,8 +1371,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
}
l_src_ptr += l_stride;
}
}
else {
} else {
for (j=0; j<l_height; ++j) {
for (k=0; k<l_width; ++k) {
*(l_dest_ptr++) = (OPJ_CHAR) ((*(l_src_ptr++))&0xff);
@@ -1418,8 +1383,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
p_dest = (OPJ_BYTE *)l_dest_ptr;
}
break;
case 2:
{
case 2: {
const OPJ_INT32 * l_src_ptr = l_tilec->data;
OPJ_INT16 * l_dest_ptr = (OPJ_INT16 *) p_dest;
@@ -1430,8 +1394,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
}
l_src_ptr += l_stride;
}
}
else {
} else {
for (j=0; j<l_height; ++j) {
for (k=0; k<l_width; ++k) {
*(l_dest_ptr++) = (OPJ_INT16) ((*(l_src_ptr++))&0xffff);
@@ -1443,8 +1406,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
p_dest = (OPJ_BYTE*) l_dest_ptr;
}
break;
case 4:
{
case 4: {
OPJ_INT32 * l_dest_ptr = (OPJ_INT32 *) p_dest;
OPJ_INT32 * l_src_ptr = l_tilec->data;
@@ -1491,8 +1453,7 @@ static void opj_tcd_free_tile(opj_tcd_t *p_tcd)
if (p_tcd->m_is_decoder) {
l_tcd_code_block_deallocate = opj_tcd_code_block_dec_deallocate;
}
else {
} else {
l_tcd_code_block_deallocate = opj_tcd_code_block_enc_deallocate;
}
@@ -1590,22 +1551,30 @@ static OPJ_BOOL opj_tcd_t2_decode (opj_tcd_t *p_tcd,
static OPJ_BOOL opj_tcd_t1_decode ( opj_tcd_t *p_tcd )
{
OPJ_UINT32 compno;
opj_t1_t * l_t1;
opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles;
opj_tcd_tilecomp_t* l_tile_comp = l_tile->comps;
opj_tccp_t * l_tccp = p_tcd->tcp->tccps;
volatile OPJ_BOOL ret = OPJ_TRUE;
l_t1 = opj_t1_create(OPJ_FALSE);
if (l_t1 == 00) {
return OPJ_FALSE;
}
for (compno = 0; compno < l_tile->numcomps; ++compno) {
opj_t1_decode_cblks(p_tcd->thread_pool, &ret, l_tile_comp, l_tccp);
if( !ret )
break;
/* The +3 is headroom required by the vectorized DWT */
if (OPJ_FALSE == opj_t1_decode_cblks(l_t1, l_tile_comp, l_tccp)) {
opj_t1_destroy(l_t1);
return OPJ_FALSE;
}
++l_tile_comp;
++l_tccp;
}
opj_thread_pool_wait_completion(p_tcd->thread_pool, 0);
opj_t1_destroy(l_t1);
return ret;
return OPJ_TRUE;
}
@@ -1632,11 +1601,10 @@ static OPJ_BOOL opj_tcd_dwt_decode ( opj_tcd_t *p_tcd )
*/
if (l_tccp->qmfbid == 1) {
if (! opj_dwt_decode(p_tcd->thread_pool, l_tile_comp, l_img_comp->resno_decoded+1)) {
if (! opj_dwt_decode(l_tile_comp, l_img_comp->resno_decoded+1)) {
return OPJ_FALSE;
}
}
else {
} else {
if (! opj_dwt_decode_real(l_tile_comp, l_img_comp->resno_decoded+1)) {
return OPJ_FALSE;
}
@@ -1669,8 +1637,7 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
(l_tile->comps[2].x1 - l_tile->comps[2].x0) * (l_tile->comps[2].y1 - l_tile->comps[2].y0) < (OPJ_INT32)l_samples) {
opj_event_msg(p_manager, EVT_ERROR, "Tiles don't all have the same dimension. Skip the MCT step.\n");
return OPJ_FALSE;
}
else if (l_tcp->mct == 2) {
} else if (l_tcp->mct == 2) {
OPJ_BYTE ** l_data;
if (! l_tcp->m_mct_decoding_matrix) {
@@ -1702,23 +1669,20 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
}
opj_free(l_data);
}
else {
} else {
if (l_tcp->tccps->qmfbid == 1) {
opj_mct_decode( l_tile->comps[0].data,
l_tile->comps[1].data,
l_tile->comps[2].data,
l_samples);
}
else {
} else {
opj_mct_decode_real((OPJ_FLOAT32*)l_tile->comps[0].data,
(OPJ_FLOAT32*)l_tile->comps[1].data,
(OPJ_FLOAT32*)l_tile->comps[2].data,
l_samples);
}
}
}
else {
} else {
opj_event_msg(p_manager, EVT_ERROR, "Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",l_tile->numcomps);
}
@@ -1755,8 +1719,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd )
if (l_img_comp->sgnd) {
l_min = -(1 << (l_img_comp->prec - 1));
l_max = (1 << (l_img_comp->prec - 1)) - 1;
}
else {
} else {
l_min = 0;
l_max = (1 << l_img_comp->prec) - 1;
}
@@ -1771,8 +1734,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd )
}
l_current_ptr += l_stride;
}
}
else {
} else {
for (j=0; j<l_height; ++j) {
for (i = 0; i < l_width; ++i) {
OPJ_FLOAT32 l_value = *((OPJ_FLOAT32 *) l_current_ptr);
@@ -1919,10 +1881,9 @@ static OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd )
*l_current_ptr -= l_tccp->m_dc_level_shift ;
++l_current_ptr;
}
}
else {
} else {
for (i = 0; i < l_nb_elem; ++i) {
*l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) * (1 << 11);
*l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) << 11 ;
++l_current_ptr;
}
}
@@ -1972,18 +1933,15 @@ static OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd )
/* nb of components (i.e. size of pData) */
l_tile->numcomps,
/* tells if the data is signed */
p_tcd->image->comps->sgnd) )
{
p_tcd->image->comps->sgnd) ) {
opj_free(l_data);
return OPJ_FALSE;
}
opj_free(l_data);
}
else if (l_tcp->tccps->qmfbid == 0) {
} else if (l_tcp->tccps->qmfbid == 0) {
opj_mct_encode_real(l_tile->comps[0].data, l_tile->comps[1].data, l_tile->comps[2].data, samples);
}
else {
} else {
opj_mct_encode(l_tile->comps[0].data, l_tile->comps[1].data, l_tile->comps[2].data, samples);
}
@@ -2002,8 +1960,7 @@ static OPJ_BOOL opj_tcd_dwt_encode ( opj_tcd_t *p_tcd )
if (! opj_dwt_encode(l_tile_comp)) {
return OPJ_FALSE;
}
}
else if (l_tccp->qmfbid == 0) {
} else if (l_tccp->qmfbid == 0) {
if (! opj_dwt_encode_real(l_tile_comp)) {
return OPJ_FALSE;
}
@@ -2033,12 +1990,10 @@ static OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd )
/* irreversible encoding */
if (l_tcp->tccps->qmfbid == 0) {
l_mct_norms = opj_mct_get_mct_norms_real();
}
else {
} else {
l_mct_norms = opj_mct_get_mct_norms();
}
}
else {
} else {
l_mct_numcomps = p_tcd->image->numcomps;
l_mct_norms = (const OPJ_FLOAT64 *) (l_tcp->mct_norms);
}
@@ -2078,8 +2033,7 @@ static OPJ_BOOL opj_tcd_t2_encode (opj_tcd_t *p_tcd,
p_tcd->tp_num,
p_tcd->tp_pos,
p_tcd->cur_pino,
FINAL_PASS))
{
FINAL_PASS)) {
opj_t2_destroy(l_t2);
return OPJ_FALSE;
}
@@ -2109,8 +2063,7 @@ static OPJ_BOOL opj_tcd_rate_allocate_encode( opj_tcd_t *p_tcd,
if (! opj_tcd_rateallocate(p_tcd, p_dest_data,&l_nb_written, p_max_dest_size, p_cstr_info)) {
return OPJ_FALSE;
}
}
else {
} else {
/* Fixed layer allocation */
opj_tcd_rateallocate_fixed(p_tcd);
}
@@ -2150,8 +2103,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
}
switch (l_size_comp) {
case 1:
{
case 1: {
OPJ_CHAR * l_src_ptr = (OPJ_CHAR *) p_src;
OPJ_INT32 * l_dest_ptr = l_tilec->data;
@@ -2159,8 +2111,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
for (j=0; j<l_nb_elem; ++j) {
*(l_dest_ptr++) = (OPJ_INT32) (*(l_src_ptr++));
}
}
else {
} else {
for (j=0; j<l_nb_elem; ++j) {
*(l_dest_ptr++) = (*(l_src_ptr++))&0xff;
}
@@ -2169,8 +2120,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
p_src = (OPJ_BYTE*) l_src_ptr;
}
break;
case 2:
{
case 2: {
OPJ_INT32 * l_dest_ptr = l_tilec->data;
OPJ_INT16 * l_src_ptr = (OPJ_INT16 *) p_src;
@@ -2178,8 +2128,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
for (j=0; j<l_nb_elem; ++j) {
*(l_dest_ptr++) = (OPJ_INT32) (*(l_src_ptr++));
}
}
else {
} else {
for (j=0; j<l_nb_elem; ++j) {
*(l_dest_ptr++) = (*(l_src_ptr++))&0xffff;
}
@@ -2188,8 +2137,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
p_src = (OPJ_BYTE*) l_src_ptr;
}
break;
case 4:
{
case 4: {
OPJ_INT32 * l_src_ptr = (OPJ_INT32 *) p_src;
OPJ_INT32 * l_dest_ptr = l_tilec->data;

View File

@@ -70,7 +70,7 @@ typedef struct opj_tcd_pass {
OPJ_UINT32 rate;
OPJ_FLOAT64 distortiondec;
OPJ_UINT32 len;
OPJ_BITFIELD term : 1;
OPJ_UINT32 term : 1;
} opj_tcd_pass_t;
/**
@@ -155,8 +155,7 @@ typedef struct opj_tcd_resolution {
/**
FIXME DOC
*/
typedef struct opj_tcd_tilecomp
{
typedef struct opj_tcd_tilecomp {
OPJ_INT32 x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 numresolutions; /* number of resolutions level */
OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/
@@ -186,8 +185,7 @@ typedef struct opj_tcd_tile {
/**
FIXME DOC
*/
typedef struct opj_tcd_image
{
typedef struct opj_tcd_image {
opj_tcd_tile_t *tiles; /* Tiles information */
}
opj_tcd_image_t;
@@ -196,8 +194,7 @@ opj_tcd_image_t;
/**
Tile coder/decoder
*/
typedef struct opj_tcd
{
typedef struct opj_tcd {
/** Position of the tilepart flag in Progression order*/
OPJ_INT32 tp_pos;
/** Tile part number*/
@@ -219,9 +216,7 @@ typedef struct opj_tcd
/** current encoded/decoded tile */
OPJ_UINT32 tcd_tileno;
/** tell if the tcd is a decoder. */
OPJ_BITFIELD m_is_decoder : 1;
/** Thread pool */
opj_thread_pool_t* thread_pool;
OPJ_UINT32 m_is_decoder : 1;
} opj_tcd_t;
/** @name Exported functions */
@@ -251,14 +246,12 @@ void opj_tcd_destroy(opj_tcd_t *tcd);
* @param p_tcd TCD handle.
* @param p_image raw image.
* @param p_cp coding parameters.
* @param p_tp thread pool
*
* @return true if the encoding values could be set (false otherwise).
*/
OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
opj_image_t * p_image,
opj_cp_t * p_cp,
opj_thread_pool_t* p_tp);
opj_cp_t * p_cp );
/**
* Allocates memory for decoding a specific tile.

View File

@@ -45,7 +45,8 @@
==========================================================
*/
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager) {
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager)
{
OPJ_INT32 nplh[32];
OPJ_INT32 nplv[32];
opj_tgt_node_t *node = 00;
@@ -155,15 +156,13 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
l_nplh[0] = (OPJ_INT32)p_num_leafs_h;
l_nplv[0] = (OPJ_INT32)p_num_leafs_v;
p_tree->numnodes = 0;
do
{
do {
n = (OPJ_UINT32)(l_nplh[l_num_levels] * l_nplv[l_num_levels]);
l_nplh[l_num_levels + 1] = (l_nplh[l_num_levels] + 1) / 2;
l_nplv[l_num_levels + 1] = (l_nplv[l_num_levels] + 1) / 2;
p_tree->numnodes += n;
++l_num_levels;
}
while (n > 1);
} while (n > 1);
/* ADD */
if (p_tree->numnodes == 0) {
@@ -199,12 +198,9 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
}
++l_parent_node;
}
if ((j & 1) || j == l_nplv[i] - 1)
{
if ((j & 1) || j == l_nplv[i] - 1) {
l_parent_node0 = l_parent_node;
}
else
{
} else {
l_parent_node = l_parent_node0;
l_parent_node0 += l_nplh[i];
}
@@ -230,7 +226,8 @@ void opj_tgt_destroy(opj_tgt_tree_t *p_tree)
opj_free(p_tree);
}
void opj_tgt_reset(opj_tgt_tree_t *p_tree) {
void opj_tgt_reset(opj_tgt_tree_t *p_tree)
{
OPJ_UINT32 i;
opj_tgt_node_t * l_current_node = 00;;
@@ -239,8 +236,7 @@ void opj_tgt_reset(opj_tgt_tree_t *p_tree) {
}
l_current_node = p_tree->nodes;
for (i = 0; i < p_tree->numnodes; ++i)
{
for (i = 0; i < p_tree->numnodes; ++i) {
l_current_node->value = 999;
l_current_node->low = 0;
l_current_node->known = 0;
@@ -248,7 +244,8 @@ void opj_tgt_reset(opj_tgt_tree_t *p_tree) {
}
}
void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) {
void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value)
{
opj_tgt_node_t *node;
node = &tree->nodes[leafno];
while (node && node->value > value) {
@@ -257,7 +254,8 @@ void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value)
}
}
void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) {
void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold)
{
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
@@ -297,7 +295,8 @@ void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ
}
}
OPJ_UINT32 opj_tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) {
OPJ_UINT32 opj_tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold)
{
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;

View File

@@ -64,8 +64,7 @@ typedef struct opj_tgt_node {
/**
Tag tree
*/
typedef struct opj_tgt_tree
{
typedef struct opj_tgt_tree {
OPJ_UINT32 numleafsh;
OPJ_UINT32 numleafsv;
OPJ_UINT32 numnodes;

View File

@@ -49,9 +49,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
lenp = 0;
box = (opj_jp2_box_t *)opj_calloc( (size_t)(cstr_info.tw*cstr_info.th), sizeof(opj_jp2_box_t));
if(box == NULL){
return 0;
}
for ( i = 0; i < 2 ; i++ ) {
if (i)
opj_stream_seek( cio, lenp, p_manager);

View File

@@ -1,968 +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) 2016, Even Rouault
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
#include "thread.h"
#include <assert.h>
#ifdef MUTEX_win32
/* Some versions of x86_64-w64-mingw32-gc -m32 resolve InterlockedCompareExchange() */
/* as __sync_val_compare_and_swap_4 but fails to link it. As this protects against */
/* a rather unlikely race, skip it */
#if !(defined(__MINGW32__) && defined(__i386__))
#define HAVE_INTERLOCKED_COMPARE_EXCHANGE 1
#endif
#include <windows.h>
#include <process.h>
OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void)
{
return OPJ_TRUE;
}
int OPJ_CALLCONV opj_get_num_cpus(void)
{
SYSTEM_INFO info;
DWORD dwNum;
GetSystemInfo(&info);
dwNum = info.dwNumberOfProcessors;
if( dwNum < 1 )
return 1;
return (int)dwNum;
}
struct opj_mutex_t
{
CRITICAL_SECTION cs;
};
opj_mutex_t* opj_mutex_create(void)
{
opj_mutex_t* mutex = (opj_mutex_t*) opj_malloc(sizeof(opj_mutex_t));
if( !mutex )
return NULL;
InitializeCriticalSectionAndSpinCount(&(mutex->cs), 4000);
return mutex;
}
void opj_mutex_lock(opj_mutex_t* mutex)
{
EnterCriticalSection( &(mutex->cs) );
}
void opj_mutex_unlock(opj_mutex_t* mutex)
{
LeaveCriticalSection( &(mutex->cs) );
}
void opj_mutex_destroy(opj_mutex_t* mutex)
{
if( !mutex ) return;
DeleteCriticalSection( &(mutex->cs) );
opj_free( mutex );
}
struct opj_cond_waiter_list_t
{
HANDLE hEvent;
struct opj_cond_waiter_list_t* next;
};
typedef struct opj_cond_waiter_list_t opj_cond_waiter_list_t;
struct opj_cond_t
{
opj_mutex_t *internal_mutex;
opj_cond_waiter_list_t *waiter_list;
};
static DWORD TLSKey = 0;
static volatile LONG inTLSLockedSection = 0;
static volatile int TLSKeyInit = OPJ_FALSE;
opj_cond_t* opj_cond_create(void)
{
opj_cond_t* cond = (opj_cond_t*) opj_malloc(sizeof(opj_cond_t));
if( !cond )
return NULL;
/* Make sure that the TLS key is allocated in a thread-safe way */
/* We cannot use a global mutex/critical section since its creation itself would not be */
/* thread-safe, so use InterlockedCompareExchange trick */
while( OPJ_TRUE )
{
#if HAVE_INTERLOCKED_COMPARE_EXCHANGE
if( InterlockedCompareExchange(&inTLSLockedSection, 1, 0) == 0 )
#endif
{
if( !TLSKeyInit )
{
TLSKey = TlsAlloc();
TLSKeyInit = OPJ_TRUE;
}
#if HAVE_INTERLOCKED_COMPARE_EXCHANGE
InterlockedCompareExchange(&inTLSLockedSection, 0, 1);
#endif
break;
}
}
if( TLSKey == TLS_OUT_OF_INDEXES )
{
opj_free(cond);
return NULL;
}
cond->internal_mutex = opj_mutex_create();
if (cond->internal_mutex == NULL)
{
opj_free(cond);
return NULL;
}
cond->waiter_list = NULL;
return cond;
}
void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex)
{
opj_cond_waiter_list_t* item;
HANDLE hEvent = (HANDLE) TlsGetValue( TLSKey );
if (hEvent == NULL)
{
hEvent = CreateEvent(NULL, /* security attributes */
0, /* manual reset = no */
0, /* initial state = unsignaled */
NULL /* no name */);
assert(hEvent);
TlsSetValue( TLSKey, hEvent );
}
/* Insert the waiter into the waiter list of the condition */
opj_mutex_lock(cond->internal_mutex);
item = (opj_cond_waiter_list_t*)opj_malloc(sizeof(opj_cond_waiter_list_t));
assert(item != NULL);
item->hEvent = hEvent;
item->next = cond->waiter_list;
cond->waiter_list = item;
opj_mutex_unlock(cond->internal_mutex);
/* Release the client mutex before waiting for the event being signaled */
opj_mutex_unlock(mutex);
/* Ideally we would check that we do not get WAIT_FAILED but it is hard */
/* to report a failure. */
WaitForSingleObject(hEvent, INFINITE);
/* Reacquire the client mutex */
opj_mutex_lock(mutex);
}
void opj_cond_signal(opj_cond_t* cond)
{
opj_cond_waiter_list_t* psIter;
/* Signal the first registered event, and remove it from the list */
opj_mutex_lock(cond->internal_mutex);
psIter = cond->waiter_list;
if (psIter != NULL)
{
SetEvent(psIter->hEvent);
cond->waiter_list = psIter->next;
opj_free(psIter);
}
opj_mutex_unlock(cond->internal_mutex);
}
void opj_cond_destroy(opj_cond_t* cond)
{
if( !cond ) return;
opj_mutex_destroy(cond->internal_mutex);
assert(cond->waiter_list == NULL);
opj_free(cond);
}
struct opj_thread_t
{
opj_thread_fn thread_fn;
void* user_data;
HANDLE hThread;
};
unsigned int __stdcall opj_thread_callback_adapter( void *info )
{
opj_thread_t* thread = (opj_thread_t*) info;
HANDLE hEvent = NULL;
thread->thread_fn( thread->user_data );
/* Free the handle possible allocated by a cond */
while( OPJ_TRUE )
{
/* Make sure TLSKey is not being created just at that moment... */
#if HAVE_INTERLOCKED_COMPARE_EXCHANGE
if( InterlockedCompareExchange(&inTLSLockedSection, 1, 0) == 0 )
#endif
{
if( TLSKeyInit )
{
hEvent = (HANDLE) TlsGetValue( TLSKey );
}
#if HAVE_INTERLOCKED_COMPARE_EXCHANGE
InterlockedCompareExchange(&inTLSLockedSection, 0, 1);
#endif
break;
}
}
if( hEvent )
CloseHandle(hEvent);
return 0;
}
opj_thread_t* opj_thread_create( opj_thread_fn thread_fn, void* user_data )
{
opj_thread_t* thread;
assert( thread_fn );
thread = (opj_thread_t*) opj_malloc( sizeof(opj_thread_t) );
if( !thread )
return NULL;
thread->thread_fn = thread_fn;
thread->user_data = user_data;
thread->hThread = (HANDLE)_beginthreadex(NULL, 0,
opj_thread_callback_adapter, thread, 0, NULL);
if( thread->hThread == NULL )
{
opj_free( thread );
return NULL;
}
return thread;
}
void opj_thread_join( opj_thread_t* thread )
{
WaitForSingleObject(thread->hThread, INFINITE);
CloseHandle( thread->hThread );
opj_free(thread);
}
#elif MUTEX_pthread
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void)
{
return OPJ_TRUE;
}
int OPJ_CALLCONV opj_get_num_cpus(void)
{
#ifdef _SC_NPROCESSORS_ONLN
return (int)sysconf(_SC_NPROCESSORS_ONLN);
#else
return 1;
#endif
}
struct opj_mutex_t
{
pthread_mutex_t mutex;
};
opj_mutex_t* opj_mutex_create(void)
{
opj_mutex_t* mutex = (opj_mutex_t*) opj_calloc(1U, sizeof(opj_mutex_t));
if( mutex != NULL ) {
if ( pthread_mutex_init(&mutex->mutex, NULL) != 0) {
opj_free(mutex);
mutex = NULL;
}
}
return mutex;
}
void opj_mutex_lock(opj_mutex_t* mutex)
{
pthread_mutex_lock(&(mutex->mutex));
}
void opj_mutex_unlock(opj_mutex_t* mutex)
{
pthread_mutex_unlock(&(mutex->mutex));
}
void opj_mutex_destroy(opj_mutex_t* mutex)
{
if( !mutex ) return;
pthread_mutex_destroy(&(mutex->mutex));
opj_free(mutex);
}
struct opj_cond_t
{
pthread_cond_t cond;
};
opj_cond_t* opj_cond_create(void)
{
opj_cond_t* cond = (opj_cond_t*) opj_malloc(sizeof(opj_cond_t));
if( !cond )
return NULL;
if( pthread_cond_init(&(cond->cond), NULL) != 0 )
{
opj_free(cond);
return NULL;
}
return cond;
}
void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex)
{
pthread_cond_wait(&(cond->cond), &(mutex->mutex));
}
void opj_cond_signal(opj_cond_t* cond)
{
int ret = pthread_cond_signal(&(cond->cond));
(void)ret;
assert(ret == 0);
}
void opj_cond_destroy(opj_cond_t* cond)
{
if( !cond ) return;
pthread_cond_destroy(&(cond->cond));
opj_free(cond);
}
struct opj_thread_t
{
opj_thread_fn thread_fn;
void* user_data;
pthread_t thread;
};
static void* opj_thread_callback_adapter( void* info )
{
opj_thread_t* thread = (opj_thread_t*) info;
thread->thread_fn( thread->user_data );
return NULL;
}
opj_thread_t* opj_thread_create( opj_thread_fn thread_fn, void* user_data )
{
pthread_attr_t attr;
opj_thread_t* thread;
assert( thread_fn );
thread = (opj_thread_t*) opj_malloc( sizeof(opj_thread_t) );
if( !thread )
return NULL;
thread->thread_fn = thread_fn;
thread->user_data = user_data;
pthread_attr_init( &attr );
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );
if( pthread_create( &(thread->thread), &attr,
opj_thread_callback_adapter, (void *) thread ) != 0 )
{
opj_free( thread );
return NULL;
}
return thread;
}
void opj_thread_join( opj_thread_t* thread )
{
void* status;
pthread_join( thread->thread, &status);
opj_free(thread);
}
#else
/* Stub implementation */
OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void)
{
return OPJ_FALSE;
}
int OPJ_CALLCONV opj_get_num_cpus(void)
{
return 1;
}
opj_mutex_t* opj_mutex_create(void)
{
return NULL;
}
void opj_mutex_lock(opj_mutex_t* mutex)
{
(void) mutex;
}
void opj_mutex_unlock(opj_mutex_t* mutex)
{
(void) mutex;
}
void opj_mutex_destroy(opj_mutex_t* mutex)
{
(void) mutex;
}
opj_cond_t* opj_cond_create(void)
{
return NULL;
}
void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex)
{
(void) cond;
(void) mutex;
}
void opj_cond_signal(opj_cond_t* cond)
{
(void) cond;
}
void opj_cond_destroy(opj_cond_t* cond)
{
(void) cond;
}
opj_thread_t* opj_thread_create( opj_thread_fn thread_fn, void* user_data )
{
(void) thread_fn;
(void) user_data;
return NULL;
}
void opj_thread_join( opj_thread_t* thread )
{
(void) thread;
}
#endif
typedef struct
{
int key;
void* value;
opj_tls_free_func opj_free_func;
} opj_tls_key_val_t;
struct opj_tls_t
{
opj_tls_key_val_t* key_val;
int key_val_count;
};
static opj_tls_t* opj_tls_new(void)
{
return (opj_tls_t*) opj_calloc(1, sizeof(opj_tls_t));
}
static void opj_tls_destroy(opj_tls_t* tls)
{
int i;
if( !tls ) return;
for(i=0;i<tls->key_val_count;i++)
{
if( tls->key_val[i].opj_free_func )
tls->key_val[i].opj_free_func(tls->key_val[i].value);
}
opj_free(tls->key_val);
opj_free(tls);
}
void* opj_tls_get(opj_tls_t* tls, int key)
{
int i;
for(i=0;i<tls->key_val_count;i++)
{
if( tls->key_val[i].key == key )
return tls->key_val[i].value;
}
return NULL;
}
OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value, opj_tls_free_func opj_free_func)
{
opj_tls_key_val_t* new_key_val;
int i;
if (tls->key_val_count == INT_MAX) {
return OPJ_FALSE;
}
for(i=0;i<tls->key_val_count;i++)
{
if( tls->key_val[i].key == key )
{
if( tls->key_val[i].opj_free_func ) {
tls->key_val[i].opj_free_func(tls->key_val[i].value);
}
tls->key_val[i].value = value;
tls->key_val[i].opj_free_func = opj_free_func;
return OPJ_TRUE;
}
}
new_key_val = (opj_tls_key_val_t*) opj_realloc( tls->key_val,
((size_t)tls->key_val_count + 1U) * sizeof(opj_tls_key_val_t) );
if( !new_key_val )
return OPJ_FALSE;
tls->key_val = new_key_val;
new_key_val[tls->key_val_count].key = key;
new_key_val[tls->key_val_count].value = value;
new_key_val[tls->key_val_count].opj_free_func = opj_free_func;
tls->key_val_count ++;
return OPJ_TRUE;
}
typedef struct
{
opj_job_fn job_fn;
void *user_data;
} opj_worker_thread_job_t;
typedef struct
{
opj_thread_pool_t *tp;
opj_thread_t *thread;
int marked_as_waiting;
opj_mutex_t *mutex;
opj_cond_t *cond;
} opj_worker_thread_t;
typedef enum
{
OPJWTS_OK,
OPJWTS_STOP,
OPJWTS_ERROR
} opj_worker_thread_state;
struct opj_job_list_t
{
opj_worker_thread_job_t* job;
struct opj_job_list_t* next;
};
typedef struct opj_job_list_t opj_job_list_t;
struct opj_worker_thread_list_t
{
opj_worker_thread_t* worker_thread;
struct opj_worker_thread_list_t* next;
};
typedef struct opj_worker_thread_list_t opj_worker_thread_list_t;
struct opj_thread_pool_t
{
opj_worker_thread_t* worker_threads;
int worker_threads_count;
opj_cond_t* cond;
opj_mutex_t* mutex;
volatile opj_worker_thread_state state;
opj_job_list_t* job_queue;
volatile int pending_jobs_count;
opj_worker_thread_list_t* waiting_worker_thread_list;
int waiting_worker_thread_count;
opj_tls_t* tls;
int signaling_threshold;
};
static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads);
static opj_worker_thread_job_t* opj_thread_pool_get_next_job(opj_thread_pool_t* tp,
opj_worker_thread_t* worker_thread,
OPJ_BOOL signal_job_finished);
opj_thread_pool_t* opj_thread_pool_create(int num_threads)
{
opj_thread_pool_t* tp;
tp = (opj_thread_pool_t*) opj_calloc(1, sizeof(opj_thread_pool_t));
if( !tp )
return NULL;
tp->state = OPJWTS_OK;
if( num_threads <= 0 )
{
tp->tls = opj_tls_new();
if( !tp->tls )
{
opj_free(tp);
tp = NULL;
}
return tp;
}
tp->mutex = opj_mutex_create();
if( !tp->mutex )
{
opj_free(tp);
return NULL;
}
if( !opj_thread_pool_setup(tp, num_threads) )
{
opj_thread_pool_destroy(tp);
return NULL;
}
return tp;
}
static void opj_worker_thread_function(void* user_data)
{
opj_worker_thread_t* worker_thread;
opj_thread_pool_t* tp;
opj_tls_t* tls;
OPJ_BOOL job_finished = OPJ_FALSE;
worker_thread = (opj_worker_thread_t* ) user_data;
tp = worker_thread->tp;
tls = opj_tls_new();
while( OPJ_TRUE )
{
opj_worker_thread_job_t* job = opj_thread_pool_get_next_job(tp, worker_thread, job_finished);
if( job == NULL )
break;
if( job->job_fn )
{
job->job_fn(job->user_data, tls);
}
opj_free(job);
job_finished = OPJ_TRUE;
}
opj_tls_destroy(tls);
}
static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads)
{
int i;
OPJ_BOOL bRet = OPJ_TRUE;
assert( num_threads > 0 );
tp->cond = opj_cond_create();
if( tp->cond == NULL )
return OPJ_FALSE;
tp->worker_threads = (opj_worker_thread_t*) opj_calloc( (size_t)num_threads,
sizeof(opj_worker_thread_t) );
if( tp->worker_threads == NULL )
return OPJ_FALSE;
tp->worker_threads_count = num_threads;
for(i=0;i<num_threads;i++)
{
tp->worker_threads[i].tp = tp;
tp->worker_threads[i].mutex = opj_mutex_create();
if( tp->worker_threads[i].mutex == NULL )
{
tp->worker_threads_count = i;
bRet = OPJ_FALSE;
break;
}
tp->worker_threads[i].cond = opj_cond_create();
if( tp->worker_threads[i].cond == NULL )
{
opj_mutex_destroy(tp->worker_threads[i].mutex);
tp->worker_threads_count = i;
bRet = OPJ_FALSE;
break;
}
tp->worker_threads[i].marked_as_waiting = OPJ_FALSE;
tp->worker_threads[i].thread = opj_thread_create(opj_worker_thread_function,
&(tp->worker_threads[i]));
if( tp->worker_threads[i].thread == NULL )
{
tp->worker_threads_count = i;
bRet = OPJ_FALSE;
break;
}
}
/* Wait all threads to be started */
/* printf("waiting for all threads to be started\n"); */
opj_mutex_lock(tp->mutex);
while( tp->waiting_worker_thread_count < num_threads )
{
opj_cond_wait(tp->cond, tp->mutex);
}
opj_mutex_unlock(tp->mutex);
/* printf("all threads started\n"); */
if( tp->state == OPJWTS_ERROR )
bRet = OPJ_FALSE;
return bRet;
}
/*
void opj_waiting()
{
printf("waiting!\n");
}
*/
static opj_worker_thread_job_t* opj_thread_pool_get_next_job(opj_thread_pool_t* tp,
opj_worker_thread_t* worker_thread,
OPJ_BOOL signal_job_finished)
{
while( OPJ_TRUE )
{
opj_job_list_t* top_job_iter;
opj_mutex_lock(tp->mutex);
if( signal_job_finished )
{
signal_job_finished = OPJ_FALSE;
tp->pending_jobs_count --;
/*printf("tp=%p, remaining jobs: %d\n", tp, tp->pending_jobs_count);*/
if( tp->pending_jobs_count <= tp->signaling_threshold )
opj_cond_signal(tp->cond);
}
if( tp->state == OPJWTS_STOP )
{
opj_mutex_unlock(tp->mutex);
return NULL;
}
top_job_iter = tp->job_queue;
if( top_job_iter )
{
opj_worker_thread_job_t* job;
tp->job_queue = top_job_iter->next;
job = top_job_iter->job;
opj_mutex_unlock(tp->mutex);
opj_free(top_job_iter);
return job;
}
/* opj_waiting(); */
if( !worker_thread->marked_as_waiting )
{
opj_worker_thread_list_t* item;
worker_thread->marked_as_waiting = OPJ_TRUE;
tp->waiting_worker_thread_count ++;
assert(tp->waiting_worker_thread_count <= tp->worker_threads_count);
item= (opj_worker_thread_list_t*) opj_malloc(sizeof(opj_worker_thread_list_t));
if( item == NULL )
{
tp->state = OPJWTS_ERROR;
opj_cond_signal(tp->cond);
opj_mutex_unlock(tp->mutex);
return NULL;
}
item->worker_thread = worker_thread;
item->next = tp->waiting_worker_thread_list;
tp->waiting_worker_thread_list = item;
}
/* printf("signaling that worker thread is ready\n"); */
opj_cond_signal(tp->cond);
opj_mutex_lock(worker_thread->mutex);
opj_mutex_unlock(tp->mutex);
/* printf("waiting for job\n"); */
opj_cond_wait( worker_thread->cond, worker_thread->mutex );
opj_mutex_unlock(worker_thread->mutex);
/* printf("got job\n"); */
}
}
OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t* tp,
opj_job_fn job_fn,
void* user_data)
{
opj_worker_thread_job_t* job;
opj_job_list_t* item;
if( tp->mutex == NULL )
{
job_fn( user_data, tp->tls );
return OPJ_TRUE;
}
job = (opj_worker_thread_job_t*)opj_malloc(sizeof(opj_worker_thread_job_t));
if( job == NULL )
return OPJ_FALSE;
job->job_fn = job_fn;
job->user_data = user_data;
item = (opj_job_list_t*) opj_malloc(sizeof(opj_job_list_t));
if( item == NULL )
{
opj_free(job);
return OPJ_FALSE;
}
item->job = job;
opj_mutex_lock(tp->mutex);
tp->signaling_threshold = 100 * tp->worker_threads_count;
while( tp->pending_jobs_count > tp->signaling_threshold )
{
/* printf("%d jobs enqueued. Waiting\n", tp->pending_jobs_count); */
opj_cond_wait(tp->cond, tp->mutex);
/* printf("...%d jobs enqueued.\n", tp->pending_jobs_count); */
}
item->next = tp->job_queue;
tp->job_queue = item;
tp->pending_jobs_count ++;
if( tp->waiting_worker_thread_list )
{
opj_worker_thread_t* worker_thread;
opj_worker_thread_list_t* next;
opj_worker_thread_list_t* to_opj_free;
worker_thread = tp->waiting_worker_thread_list->worker_thread;
assert( worker_thread->marked_as_waiting );
worker_thread->marked_as_waiting = OPJ_FALSE;
next = tp->waiting_worker_thread_list->next;
to_opj_free = tp->waiting_worker_thread_list;
tp->waiting_worker_thread_list = next;
tp->waiting_worker_thread_count --;
opj_mutex_lock(worker_thread->mutex);
opj_mutex_unlock(tp->mutex);
opj_cond_signal(worker_thread->cond);
opj_mutex_unlock(worker_thread->mutex);
opj_free(to_opj_free);
}
else
opj_mutex_unlock(tp->mutex);
return OPJ_TRUE;
}
void opj_thread_pool_wait_completion(opj_thread_pool_t* tp, int max_remaining_jobs)
{
if( tp->mutex == NULL )
{
return;
}
if( max_remaining_jobs < 0 )
max_remaining_jobs = 0;
opj_mutex_lock(tp->mutex);
tp->signaling_threshold = max_remaining_jobs;
while( tp->pending_jobs_count > max_remaining_jobs )
{
/*printf("tp=%p, jobs before wait = %d, max_remaining_jobs = %d\n", tp, tp->pending_jobs_count, max_remaining_jobs);*/
opj_cond_wait(tp->cond, tp->mutex);
/*printf("tp=%p, jobs after wait = %d\n", tp, tp->pending_jobs_count);*/
}
opj_mutex_unlock(tp->mutex);
}
int opj_thread_pool_get_thread_count(opj_thread_pool_t* tp)
{
return tp->worker_threads_count;
}
void opj_thread_pool_destroy(opj_thread_pool_t* tp)
{
if( !tp ) return;
if( tp->cond )
{
int i;
opj_thread_pool_wait_completion(tp, 0);
opj_mutex_lock(tp->mutex);
tp->state = OPJWTS_STOP;
opj_mutex_unlock(tp->mutex);
for(i=0;i<tp->worker_threads_count;i++)
{
opj_mutex_lock(tp->worker_threads[i].mutex);
opj_cond_signal(tp->worker_threads[i].cond);
opj_mutex_unlock(tp->worker_threads[i].mutex);
opj_thread_join(tp->worker_threads[i].thread);
opj_cond_destroy(tp->worker_threads[i].cond);
opj_mutex_destroy(tp->worker_threads[i].mutex);
}
opj_free(tp->worker_threads);
while( tp->waiting_worker_thread_list != NULL )
{
opj_worker_thread_list_t* next = tp->waiting_worker_thread_list->next;
opj_free( tp->waiting_worker_thread_list );
tp->waiting_worker_thread_list = next;
}
opj_cond_destroy(tp->cond);
}
opj_mutex_destroy(tp->mutex);
opj_tls_destroy(tp->tls);
opj_free(tp);
}

View File

@@ -1,253 +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) 2016, Even Rouault
* 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 THREAD_H
#define THREAD_H
#include "openjpeg.h"
/**
@file thread.h
@brief Thread API
The functions in thread.c have for goal to manage mutex, conditions, thread
creation and thread pools that accept jobs.
*/
/** @defgroup THREAD THREAD - Mutex, conditions, threads and thread pools */
/*@{*/
/** @name Mutex */
/*@{*/
/** Opaque type for a mutex */
typedef struct opj_mutex_t opj_mutex_t;
/** Creates a mutex.
* @return the mutex or NULL in case of error (can for example happen if the library
* is built without thread support)
*/
opj_mutex_t* opj_mutex_create(void);
/** Lock/acquire the mutex.
* @param mutex the mutex to acquire.
*/
void opj_mutex_lock(opj_mutex_t* mutex);
/** Unlock/release the mutex.
* @param mutex the mutex to release.
*/
void opj_mutex_unlock(opj_mutex_t* mutex);
/** Destroy a mutex
* @param mutex the mutex to destroy.
*/
void opj_mutex_destroy(opj_mutex_t* mutex);
/*@}*/
/** @name Condition */
/*@{*/
/** Opaque type for a condition */
typedef struct opj_cond_t opj_cond_t;
/** Creates a condition.
* @return the condition or NULL in case of error (can for example happen if the library
* is built without thread support)
*/
opj_cond_t* opj_cond_create(void);
/** Wait for the condition to be signaled.
* The semantics is the same as the POSIX pthread_cond_wait.
* The provided mutex *must* be acquired before calling this function, and
* released afterwards.
* The mutex will be released by this function while it must wait for the condition
* and reacquired afterwards.
* In some particular situations, the function might return even if the condition is not signaled
* with opj_cond_signal(), hence the need to check with an application level
* mechanism.
*
* Waiting thread :
* \code
* opj_mutex_lock(mutex);
* while( !some_application_level_condition )
* {
* opj_cond_wait(cond, mutex);
* }
* opj_mutex_unlock(mutex);
* \endcode
*
* Signaling thread :
* \code
* opj_mutex_lock(mutex);
* some_application_level_condition = TRUE;
* opj_cond_signal(cond);
* opj_mutex_unlock(mutex);
* \endcode
*
* @param cond the condition to wait.
* @param mutex the mutex (in acquired state before calling this function)
*/
void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex);
/** Signal waiting threads on a condition.
* One of the thread waiting with opj_cond_wait() will be waken up.
* It is strongly advised that this call is done with the mutex that is used
* by opj_cond_wait(), in a acquired state.
* @param cond the condition to signal.
*/
void opj_cond_signal(opj_cond_t* cond);
/** Destroy a condition
* @param cond the condition to destroy.
*/
void opj_cond_destroy(opj_cond_t* cond);
/*@}*/
/** @name Thread */
/*@{*/
/** Opaque type for a thread handle */
typedef struct opj_thread_t opj_thread_t;
/** User function to execute in a thread
* @param user_data user data provided with opj_thread_create()
*/
typedef void (*opj_thread_fn)(void* user_data);
/** Creates a new thread.
* @param thread_fn Function to run in the new thread.
* @param user_data user data provided to the thread function. Might be NULL.
* @return a thread handle or NULL in case of failure (can for example happen if the library
* is built without thread support)
*/
opj_thread_t* opj_thread_create( opj_thread_fn thread_fn, void* user_data );
/** Wait for a thread to be finished and release associated resources to the
* thread handle.
* @param thread the thread to wait for being finished.
*/
void opj_thread_join( opj_thread_t* thread );
/*@}*/
/** @name Thread local storage */
/*@{*/
/** Opaque type for a thread local storage */
typedef struct opj_tls_t opj_tls_t;
/** Get a thread local value corresponding to the provided key.
* @param tls thread local storage handle
* @param key key whose value to retrieve.
* @return value associated with the key, or NULL is missing.
*/
void* opj_tls_get(opj_tls_t* tls, int key);
/** Type of the function used to free a TLS value */
typedef void (*opj_tls_free_func)(void* value);
/** Set a thread local value corresponding to the provided key.
* @param tls thread local storage handle
* @param key key whose value to set.
* @param value value to set (may be NULL).
* @param free_func function to call currently installed value.
* @return OPJ_TRUE if successful.
*/
OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value, opj_tls_free_func free_func);
/*@}*/
/** @name Thread pool */
/*@{*/
/** Opaque type for a thread pool */
typedef struct opj_thread_pool_t opj_thread_pool_t;
/** Create a new thread pool.
* num_thread must nominally be >= 1 to create a real thread pool. If num_threads
* is negative or null, then a dummy thread pool will be created. All functions
* operating on the thread pool will work, but job submission will be run
* synchronously in the calling thread.
*
* @param num_threads the number of threads to allocate for this thread pool.
* @return a thread pool handle, or NULL in case of failure (can for example happen if the library
* is built without thread support)
*/
opj_thread_pool_t* opj_thread_pool_create(int num_threads);
/** User function to execute in a thread
* @param user_data user data provided with opj_thread_create()
* @param tls handle to thread local storage
*/
typedef void (*opj_job_fn)(void* user_data, opj_tls_t* tls);
/** Submit a new job to be run by one of the thread in the thread pool.
* The job ( thread_fn, user_data ) will be added in the queue of jobs managed
* by the thread pool, and run by the first thread that is no longer busy.
*
* @param tp the thread pool handle.
* @param job_fn Function to run. Must not be NULL.
* @param user_data User data provided to thread_fn.
* @return OPJ_TRUE if the job was successfully submitted.
*/
OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t* tp, opj_job_fn job_fn, void* user_data);
/** Wait that no more than max_remaining_jobs jobs are remaining in the queue of
* the thread pool. The aim of this function is to avoid submitting too many
* jobs while the thread pool cannot cope fast enough with them, which would
* result potentially in out-of-memory situations with too many job descriptions
* being queued.
*
* @param tp the thread pool handle
* @param max_remaining_jobs maximum number of jobs allowed to be queued without waiting.
*/
void opj_thread_pool_wait_completion(opj_thread_pool_t* tp, int max_remaining_jobs);
/** Return the number of threads associated with the thread pool.
*
* @param tp the thread pool handle.
* @return number of threads associated with the thread pool.
*/
int opj_thread_pool_get_thread_count(opj_thread_pool_t* tp);
/** Destroy a thread pool.
* @param tp the thread pool handle.
*/
void opj_thread_pool_destroy(opj_thread_pool_t* tp);
/*@}*/
/*@}*/
#endif /* THREAD_H */

View File

@@ -1,37 +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) 2016, Even Rouault
* 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 TLS_KEYS_H
#define TLS_KEYS_H
#define OPJ_TLS_KEY_T1 0
#endif

View File

@@ -105,8 +105,7 @@ int opj_write_tpixfaix( int coff,
if( j2klen > pow( 2, 32)) {
size_of_coding = 8;
version = num_max_tile_parts == 1 ? 1:3;
}
else{
} else {
size_of_coding = 4;
version = num_max_tile_parts == 1 ? 0:2;
}
@@ -123,10 +122,8 @@ int opj_write_tpixfaix( int coff,
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++)
{
for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++)
{
for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++) {
for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++) {
tp = cstr_info.tile[i].tp[j];
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */
@@ -134,8 +131,7 @@ int opj_write_tpixfaix( int coff,
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
if (version & 0x02)
{
if (version & 0x02) {
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1);
else
@@ -150,8 +146,7 @@ int opj_write_tpixfaix( int coff,
/*cio_write(0,4);*/
}
/* PADDING */
while (j < num_max_tile_parts)
{
while (j < num_max_tile_parts) {
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);

View File

@@ -5,9 +5,9 @@ include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
)
set(OPENJP3D_LIBRARY_NAME openjp3d)
SET(OPENJP3D_LIBRARY_NAME openjp3d)
# Defines the source code for the library
set(OPENJP3D_SRCS
SET(OPENJP3D_SRCS
bio.c cio.c dwt.c event.c jp3d.c jp3d_lib.c mct.c mqc.c openjp3d.c
pi.c raw.c t1.c t1_3d.c t2.c tcd.c tgt.c volume.c
)

View File

@@ -77,7 +77,8 @@ static int bio_bytein(opj_bio_t *bio);
==========================================================
*/
static int bio_byteout(opj_bio_t *bio) {
static int bio_byteout(opj_bio_t *bio)
{
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
@@ -87,7 +88,8 @@ static int bio_byteout(opj_bio_t *bio) {
return 0;
}
static int bio_bytein(opj_bio_t *bio) {
static int bio_bytein(opj_bio_t *bio)
{
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
@@ -97,7 +99,8 @@ static int bio_bytein(opj_bio_t *bio) {
return 0;
}
static void bio_putbit(opj_bio_t *bio, int b) {
static void bio_putbit(opj_bio_t *bio, int b)
{
if (bio->ct == 0) {
bio_byteout(bio);
}
@@ -106,7 +109,8 @@ static void bio_putbit(opj_bio_t *bio, int b) {
}
/* MOD antonin */
static int bio_getbit(opj_bio_t *bio) {
static int bio_getbit(opj_bio_t *bio)
{
/* DOM */
if (bio->ct == 0) {
bio_bytein(bio);
@@ -121,22 +125,26 @@ static int bio_getbit(opj_bio_t *bio) {
==========================================================
*/
opj_bio_t* bio_create() {
opj_bio_t* bio_create()
{
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
}
void bio_destroy(opj_bio_t *bio) {
void bio_destroy(opj_bio_t *bio)
{
if(bio) {
opj_free(bio);
}
}
int bio_numbytes(opj_bio_t *bio) {
int bio_numbytes(opj_bio_t *bio)
{
return (bio->bp - bio->start);
}
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len)
{
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
@@ -144,7 +152,8 @@ void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {
bio->ct = 8;
}
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len)
{
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
@@ -152,14 +161,16 @@ void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
bio->ct = 0;
}
void bio_write(opj_bio_t *bio, int v, int n) {
void bio_write(opj_bio_t *bio, int v, int n)
{
int i;
for (i = n - 1; i >= 0; i--) {
bio_putbit(bio, (v >> i) & 1);
}
}
int bio_read(opj_bio_t *bio, int n) {
int bio_read(opj_bio_t *bio, int n)
{
int i, v;
v = 0;
for (i = n - 1; i >= 0; i--) {
@@ -168,7 +179,8 @@ int bio_read(opj_bio_t *bio, int n) {
return v;
}
int bio_flush(opj_bio_t *bio) {
int bio_flush(opj_bio_t *bio)
{
bio->ct = 0;
if (bio_byteout(bio)) {
return 1;
@@ -182,7 +194,8 @@ int bio_flush(opj_bio_t *bio) {
return 0;
}
int bio_inalign(opj_bio_t *bio) {
int bio_inalign(opj_bio_t *bio)
{
bio->ct = 0;
if ((bio->buf & 0xff) == 0xff) {
if (bio_bytein(bio)) {

View File

@@ -37,7 +37,8 @@
/* ----------------------------------------------------------------------- */
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) {
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length)
{
opj_cp_t *cp = NULL;
opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t));
if(!cio) return NULL;
@@ -47,8 +48,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
cio->openmode = OPJ_STREAM_READ;
cio->buffer = buffer;
cio->length = length;
}
else if(!buffer && !length && cinfo) {
} else if(!buffer && !length && cinfo) {
/* allocate a buffer for the encoded image */
cio->openmode = OPJ_STREAM_WRITE;
switch(cinfo->codec_format) {
@@ -67,8 +67,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
opj_free(cio);
return NULL;
}
}
else {
} else {
opj_free(cio);
return NULL;
}
@@ -81,7 +80,8 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
return cio;
}
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio)
{
if(cio) {
if(cio->openmode == OPJ_STREAM_WRITE) {
/* destroy the allocated buffer */
@@ -98,7 +98,8 @@ void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
/*
* Get position in byte stream.
*/
int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
int OPJ_CALLCONV cio_tell(opj_cio_t *cio)
{
return cio->bp - cio->start;
}
@@ -107,28 +108,32 @@ int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
*
* pos : position, in number of bytes, from the beginning of the stream
*/
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) {
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos)
{
cio->bp = cio->start + pos;
}
/*
* Number of bytes left before the end of the stream.
*/
int cio_numbytesleft(opj_cio_t *cio) {
int cio_numbytesleft(opj_cio_t *cio)
{
return cio->end - cio->bp;
}
/*
* Get pointer to the current position in the stream.
*/
unsigned char *cio_getbp(opj_cio_t *cio) {
unsigned char *cio_getbp(opj_cio_t *cio)
{
return cio->bp;
}
/*
* Write a byte.
*/
static bool cio_byteout(opj_cio_t *cio, unsigned char v) {
static bool cio_byteout(opj_cio_t *cio, unsigned char v)
{
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
return false;
@@ -140,7 +145,8 @@ static bool cio_byteout(opj_cio_t *cio, unsigned char v) {
/*
* Read a byte.
*/
static unsigned char cio_bytein(opj_cio_t *cio) {
static unsigned char cio_bytein(opj_cio_t *cio)
{
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
return 0;
@@ -154,7 +160,8 @@ static unsigned char cio_bytein(opj_cio_t *cio) {
* v : value to write
* n : number of bytes to write
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) {
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n)
{
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
@@ -170,7 +177,8 @@ unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) {
*
* return : value of the n bytes read
*/
unsigned int cio_read(opj_cio_t *cio, int n) {
unsigned int cio_read(opj_cio_t *cio, int n)
{
int i;
unsigned int v;
v = 0;
@@ -185,7 +193,8 @@ unsigned int cio_read(opj_cio_t *cio, int n) {
*
* n : number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n) {
void cio_skip(opj_cio_t *cio, int n)
{
cio->bp += n;
}
@@ -195,7 +204,8 @@ void cio_skip(opj_cio_t *cio, int n) {
* v : value to write
* n : number of bytes to write
*/
int cio_write_int(opj_cio_t *cio, int v, int n) {
int cio_write_int(opj_cio_t *cio, int v, int n)
{
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) )
@@ -211,7 +221,8 @@ int cio_write_int(opj_cio_t *cio, int v, int n) {
*
* return : value of the n bytes read
*/
int cio_read_int(opj_cio_t *cio, int n) {
int cio_read_int(opj_cio_t *cio, int n)
{
int i;
int v;
v = 0;

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