summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/t2.c
AgeCommit message (Collapse)Author
2024-02-18opj_t2_read_packet_header(): avoid unsigned integer overflow (alternate fix ↵Even Rouault
to https://github.com/uclouvain/openjpeg/pull/1488)
2023-03-07opj_t2_skip_packet_data(): avoid out-of-bounds reads on truncated images in ↵Even Rouault
non-strict mode (fixes #1459)
2022-08-11Micro-optimization: use directly opj_bio_putbit() instead of opj_bio_write() ↵Even Rouault
to emit single bit
2022-02-10Add support for partial bitstream decoding (#1407) (fixes #715)Robert Gabriel Jakabosky
Add a -allow-partial option to opj_decompress utility and a opj_decoder_set_strict_mode() option to the API Co-authored-by: Chris Hafey <chafey@gmail.com>
2021-12-05Fix some typos (found by codespell)Stefan Weil
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2021-09-25Added support for high throughput (HTJ2K) decoding.Aous Naman
There are a few limitations: - mixed mode (HT and regular code blocks) is not supported. - ROI in HT blocks is not supported. - Placeholder passes are not supported. - MultiHT sets are not support, only a singleHT set. - there are known issues with some compliance testing files related to the parsing of packet header.
2020-12-02Merge pull request #1300 from rouault/complement_1293Even Rouault
pi.c: avoid out of bounds access with POC (refs https://github.com/uclouvain/openjpeg/issues/1293#issuecomment-737122836)
2020-12-02pi.c: avoid out of bounds access with POC (refs ↵Even Rouault
https://github.com/uclouvain/openjpeg/issues/1293#issuecomment-737122836)
2020-12-02opj_t2_encode_packet(): avoid out of bound access of #1297, but likely not ↵Even Rouault
the proper fix
2020-12-01opj_t2_encode_packet(): avoid out of bound access of #1294, but likely not ↵Even Rouault
the proper fix
2020-04-21Add support for generation of PLT markers in encoderEven Rouault
* -PLT switch added to opj_compress * Add a opj_encoder_set_extra_options() function that accepts a PLT=YES option, and could be expanded later for other uses. ------- Testing with a Sentinel2 10m band, T36JTT_20160914T074612_B02.jp2, coming from S2A_MSIL1C_20160914T074612_N0204_R135_T36JTT_20160914T081456.SAFE Decompress it to TIFF: ``` opj_uncompress -i T36JTT_20160914T074612_B02.jp2 -o T36JTT_20160914T074612_B02.tif ``` Recompress it with similar parameters as original: ``` opj_compress -n 5 -c [256,256],[256,256],[256,256],[256,256],[256,256] -t 1024,1024 -PLT -i T36JTT_20160914T074612_B02.tif -o T36JTT_20160914T074612_B02_PLT.jp2 ``` Dump codestream detail with GDAL dump_jp2.py utility (https://github.com/OSGeo/gdal/blob/master/gdal/swig/python/samples/dump_jp2.py) ``` python dump_jp2.py T36JTT_20160914T074612_B02.jp2 > /tmp/dump_sentinel2_ori.txt python dump_jp2.py T36JTT_20160914T074612_B02_PLT.jp2 > /tmp/dump_sentinel2_openjpeg_plt.txt ``` The diff between both show very similar structure, and identical number of packets in PLT markers Now testing with Kakadu (KDU803_Demo_Apps_for_Linux-x86-64_200210) Full file decompression: ``` kdu_expand -i T36JTT_20160914T074612_B02_PLT.jp2 -o tmp.tif Consumed 121 tile-part(s) from a total of 121 tile(s). Consumed 80,318,806 codestream bytes (excluding any file format) = 5.329697 bits/pel. Processed using the multi-threaded environment, with 8 parallel threads of execution ``` Partial decompresson (presumably using PLT markers): ``` kdu_expand -i T36JTT_20160914T074612_B02.jp2 -o tmp.pgm -region "{0.5,0.5},{0.01,0.01}" kdu_expand -i T36JTT_20160914T074612_B02_PLT.jp2 -o tmp2.pgm -region "{0.5,0.5},{0.01,0.01}" diff tmp.pgm tmp2.pgm && echo "same !" ``` ------- Funded by ESA for S2-MPC project
2019-04-25compression: emit POC marker when only one single POC is requested (fixes #1191)Even Rouault
2018-01-08opj_t2_encode_packet(): disable setting empty packet header bit to 1 when ↵Even Rouault
there is an empty packet This effectively reverts commit 2609fb8077125b5b31f1bcc2f98c12ff1e6572d7 since it has been reported that such packets cause decoding issues with cinema J2K hardware decoders: https://groups.google.com/forum/#!topic/openjpeg/M7M_fLX_Bco
2017-08-17Sub-tile decoding: only decode precincts and codeblocks that intersect the ↵Even Rouault
window specified in opj_set_decode_area()
2017-08-16opj_t2_encode_packet(): fix potential write heap buffer overflow (#992)Even Rouault
2017-08-16opj_t2_encode_packet(): only emit an error about insufficiently large output ↵Even Rouault
buffer in FINAL_PASS mode. Fixes (master-only) regression added in 0b4fef6d1901254e41ab74ed681daba477d724c3
2017-08-10Fix argument order in error message of previous commitEven Rouault
2017-08-10Propagate event manager down to opj_t2_encode_packet() and use it to emit an ↵Even Rouault
error message when the output buffer is too small
2017-08-07Slight improvement in management of code block chunksEven Rouault
Instead of having the chunk array at the segment level, we can move it down to the codeblock itself since segments are filled in sequential order. Limit the number of memory allocation, and decrease slightly the memory usage. On MAPA_005.jp2 n4: 1871312549 (heap allocation functions) malloc/new/new[], --alloc-fns, etc. n1: 1610689344 0x4E781E7: opj_aligned_malloc (opj_malloc.c:61) n1: 1610689344 0x4E71D1B: opj_alloc_tile_component_data (tcd.c:676) n1: 1610689344 0x4E726CF: opj_tcd_init_decode_tile (tcd.c:816) n1: 1610689344 0x4E4BE39: opj_j2k_read_tile_header (j2k.c:8617) n1: 1610689344 0x4E4C902: opj_j2k_decode_tiles (j2k.c:10348) n1: 1610689344 0x4E4E3CE: opj_j2k_decode (j2k.c:7846) n1: 1610689344 0x4E53002: opj_jp2_decode (jp2.c:1564) n0: 1610689344 0x40374E: main (opj_decompress.c:1459) n1: 219232541 0x4E4BC50: opj_j2k_read_tile_header (j2k.c:4683) n1: 219232541 0x4E4C902: opj_j2k_decode_tiles (j2k.c:10348) n1: 219232541 0x4E4E3CE: opj_j2k_decode (j2k.c:7846) n1: 219232541 0x4E53002: opj_jp2_decode (jp2.c:1564) n0: 219232541 0x40374E: main (opj_decompress.c:1459) n1: 23893200 0x4E72735: opj_tcd_init_decode_tile (tcd.c:1225) n1: 23893200 0x4E4BE39: opj_j2k_read_tile_header (j2k.c:8617) n1: 23893200 0x4E4C902: opj_j2k_decode_tiles (j2k.c:10348) n1: 23893200 0x4E4E3CE: opj_j2k_decode (j2k.c:7846) n1: 23893200 0x4E53002: opj_jp2_decode (jp2.c:1564) n0: 23893200 0x40374E: main (opj_decompress.c:1459) n0: 17497464 in 52 places, all below massif's threshold (1.00%)
2017-08-07Decoding: do not allocate memory for the codestream of each codeblockEven Rouault
Currently we allocate at least 8192 bytes for each codeblock, and copy the relevant parts of the codestream in that per-codeblock buffer as we decode packets. As the whole codestream for the tile is ingested in memory and alive during the decoding, we can directly point to it instead of copying. But to do that, we need an intermediate concept, a 'chunk' of code-stream segment, given that segments may be made of data at different places in the code-stream when quality layers are used. With that change, the decoding of MAPA_005.jp2 goes down from the previous improvement of 2.7 GB down to 1.9 GB. New profile: n4: 1885648469 (heap allocation functions) malloc/new/new[], --alloc-fns, etc. n1: 1610689344 0x4E78287: opj_aligned_malloc (opj_malloc.c:61) n1: 1610689344 0x4E71D7B: opj_alloc_tile_component_data (tcd.c:676) n1: 1610689344 0x4E7272C: opj_tcd_init_decode_tile (tcd.c:816) n1: 1610689344 0x4E4BDD9: opj_j2k_read_tile_header (j2k.c:8618) n1: 1610689344 0x4E4C8A2: opj_j2k_decode_tiles (j2k.c:10349) n1: 1610689344 0x4E4E36E: opj_j2k_decode (j2k.c:7847) n1: 1610689344 0x4E52FA2: opj_jp2_decode (jp2.c:1564) n0: 1610689344 0x40374E: main (opj_decompress.c:1459) n1: 219232541 0x4E4BBF0: opj_j2k_read_tile_header (j2k.c:4685) n1: 219232541 0x4E4C8A2: opj_j2k_decode_tiles (j2k.c:10349) n1: 219232541 0x4E4E36E: opj_j2k_decode (j2k.c:7847) n1: 219232541 0x4E52FA2: opj_jp2_decode (jp2.c:1564) n0: 219232541 0x40374E: main (opj_decompress.c:1459) n1: 39822000 0x4E727A9: opj_tcd_init_decode_tile (tcd.c:1219) n1: 39822000 0x4E4BDD9: opj_j2k_read_tile_header (j2k.c:8618) n1: 39822000 0x4E4C8A2: opj_j2k_decode_tiles (j2k.c:10349) n1: 39822000 0x4E4E36E: opj_j2k_decode (j2k.c:7847) n1: 39822000 0x4E52FA2: opj_jp2_decode (jp2.c:1564) n0: 39822000 0x40374E: main (opj_decompress.c:1459) n0: 15904584 in 52 places, all below massif's threshold (1.00%)
2017-08-07Add documentation for magic values in the codeEven Rouault
2017-07-30Fix Doxygen warnings (patch derived from Winfried's doxygen-dif.txt.zip, #849)Even Rouault
2017-07-26Avoid potential undefined shift behaviour in opj_bio_read() from ↵Even Rouault
opj_t2_read_packet_header() Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2485 Credit to OSS Fuzz
2017-06-13Merge branch 't1_flag_optimizations'Even Rouault
2017-06-12Packet header writing: set empty packet header bit to 0 when appropriate ↵fix_bypass_pterm_termall_and_lossless_decomposition_issueEven Rouault
(small optimization)
2017-06-12Encoder: fix packet writing of empty sub-bands (#891, #892)Even Rouault
There are situations where, given a tile size, at a resolution level, there are sub-bands with x0==x1 or y0==y1, that consequently don't have any valid codeblocks, but the other sub-bands may be non-empty. Given that we recycle the memory from one tile to another one, those ghost codeblocks might be non-0 and thus candidate for packet inclusion.
2017-06-02MQC/RAW decoder: use an artificial 0xFF 0xFF terminating marker.Even Rouault
This saves comparing the current pointer with the end of buffer pointer. This results at least in tiny speed improvement for raw decoding, and smaller code size for MQC as well. This kills the remains of the raw.h/.c files that were only used for decoding. Encoding using the mqc structure already.
2017-05-09Reformat whole codebase with astyle.options (#128)Even Rouault
2016-05-08Fix Out-of-Bounds Access in function opj_tgt_resetmayeut
Fix uclouvain/openjpeg#775
2015-10-19Fix HP compiler warning about redeclaration of function (#640)Stephan Mühlstrasser
HP compiler warns: cc: "dwt.c", line 798: warning 562: Redeclaration of "opj_v4dwt_decode" with a different storage class specifier: "opj_v4dwt_decode" will have internal linkage. cc: "t2.c", line 1341: warning 562: Redeclaration of "opj_t2_init_seg" with a different storage class specifier: "opj_t2_init_seg" will have internal linkage.
2015-07-30Remove printf/fprintf to stdout/stderr throughout openjp2 libmayeut
Update uclouvain/openjpeg#246
2015-07-18Add some missing staticmayeut
Still needs to check j2k.c & jp2.c Update uclouvain/openjpeg#243
2014-11-20[trunk] fixed memleak in abnormal condition (fixes issue 437)Matthieu Darbois
2014-10-15[trunk] add a check on progression order (fixes issue 413)Antonin Descampe
2014-10-06[trunk] fixed potential negative size params (fixes issue 390)Antonin Descampe
2014-10-03[trunk]fixes buffer overflow in t2.cAntonin Descampe
Update issue 390 Summary: check for negative-size params in code Patch from Matthieu applied. Left open to apply this to other places in code.
2014-09-30[trunk] check possible overflow on size in opj_t2_read_packet_dataAntonin Descampe
Update issue 390 Labels: Priority-Critical Should be rechecked with ASan and pdfium
2014-09-30[trunk] prevent overflow in opj_t2_read_packet_header (update issue 389)Antonin Descampe
2014-09-29[trunk] Ensure cblk->data pointer is correctly initialized (updates issue ↵Antonin Descampe
391). Still need to check if it does not fail anymore with ASan.
2014-09-19added memory allocation checks (fixes issue 355)Antonin Descampe
2014-09-16[trunk] improve memory management (fixes issue 359)Antonin Descampe
2014-04-17[trunk] refactoring of rsiz, profiles, and extensions managementAntonin Descampe
2014-04-03[trunk] updated copyright and added copyright notice required by ISO, in ↵Antonin Descampe
each file; updated AUTHORS, NEWS
2014-03-18[trunk] Revert r2764. It breaks ~230 tests as seen on continuous. Since no ↵Mathieu Malaterre
dataset is available, the issue 296 will be left open. Update issue 296
2014-03-18[trunk] Import git commit fc884aee2b69c78500e65c3d05bf216791a9ea4a from ↵Mathieu Malaterre
ghostscript team Fixes issue 296
2014-03-18[trunk] Import git commit 99a6f1af177c15f4db475186b79d169c993494ef from ↵Mathieu Malaterre
ghostscript team Update issue 296
2014-03-14[trunk] Remove warnings about unused values introduced in r2710Mathieu Malaterre
Thanks to Matthieu Darbois for patch Fixes issue 290
2014-03-13[trunk] Just in case this would be helpful for other, here is the code used ↵Mathieu Malaterre
to track issue 80 Update issue 80
2014-03-13[trunk] Tweak documentation in t2.c. Be more verbose in case of failure.Mathieu Malaterre
2014-03-11[trunk] Re-active old warning about missing SOP markerMathieu Malaterre