summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/tcd.h
AgeCommit message (Collapse)Author
2024-02-28Fix some typos (found by `codespell` and `typos`)Stefan Weil
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2022-08-11Cleanup code related to quality layer allocation, and add a few safety checksEven Rouault
2022-08-11Significant speed-up rate allocation by rate/distoratio ratioEven Rouault
- Avoid doing 128 iterations all the time, and stop when the threshold doesn't vary much - Avoid calling costly opj_t2_encode_packets() repeatdly when bisecting the layer ratio if the truncation points haven't changed since the last iteration. When used with the GDAL gdal_translate application to convert a 11977 x 8745 raster with data type UInt16 and 8 channels, the conversion time to JPEG2000 with 20 quality layers using disto/rate allocation ( -co "IC=C8" -co "JPEG2000_DRIVER=JP2OPENJPEG" -co "PROFILE=NPJE_NUMERICALLY_LOSSLESS" creation options of the GDAL NITF driver) goes from 5m56 wall clock (8m20s total, 12 vCPUs) down to 1m16 wall clock (3m45 total).
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-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
2020-04-16Rename mis-named function opj_tcd_get_encoded_tile_size() to ↵Even Rouault
opj_tcd_get_encoder_input_buffer_size()
2017-09-19Add capability to decode only a subset of all components of an image.Even Rouault
This adds a opj_set_decoded_components(opj_codec_t *p_codec, OPJ_UINT32 numcomps, const OPJ_UINT32* comps_indices) function, and equivalent "opj_decompress -c compno[,compno]*" option. When specified, neither the MCT transform nor JP2 channel transformations will be applied. Tests added for various combinations of whole image vs tiled-based decoding, full or reduced resolution, use of decode area or not.
2017-09-01Various changes to allow tile buffers of more than 4giga pixelsEven Rouault
Untested though, since that means a tile buffer of at least 16 GB. So there might be places where uint32 overflow on multiplication still occur...
2017-09-01TCD: allow tile buffer to be greater than 4GB on 64 bit hosts (but number of ↵Even Rouault
pixels must remain under 4 billion)
2017-09-01Sub-tile decoding: only allocate tile component buffer of the needed dimensionEven Rouault
Instead of being the full tile size. * Use a sparse array mechanism to store code-blocks and intermediate stages of IDWT. * IDWT, DC level shift and MCT stages are done just on that smaller array. * Improve copy of tile component array to final image, by saving an intermediate buffer. * For full-tile decoding at reduced resolution, only allocate the tile buffer to the reduced size, instead of the full-resolution size.
2017-08-21Add commentEven Rouault
2017-08-17Sub-tile decoding: only decode precincts and codeblocks that intersect the ↵Even Rouault
window specified in opj_set_decode_area()
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-09Remove useless opj_tcd_t::enumcs field added per #975Even Rouault
2017-08-09Doc: fix error in previous commitEven Rouault
2017-08-09tcd.h: doc fixes and improvementsEven Rouault
2017-08-08Merge pull request #975 from szukw000/changes-for-afl-testsAntonin Descampe
Catch images broken by AFL
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-07-31Catch images broken by AFLszukw000
2017-07-30src/lib/openjp2/*.h: use OPJ_ prefix for inclusion guards instead of ↵Even Rouault
reserved __ (#587)
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-05-15Reformat: apply reformattin on .h files (#128)Even Rouault
2016-09-13Merge branch 'bit-fields-type' of https://github.com/smuehlst/openjpeg into ↵Antonin Descampe
smuehlst-bit-fields-type
2016-07-25Create separate type for bit-fields.Stephan Mühlstrasser
The definition of bit-fields with type OPJ_UINT32 caused complilation errors on IBM iSeries, because OPJ_UINT32 is defined as uint32_t, and uint32_t is defined as unsigned long in <stdint.h>. The definition of bit-fields with an integer type of a specific size doesn't make sense anyway.
2016-05-25Add opj_codec_set_threads() in public API and propagate resulting thread ↵Even Rouault
pool to tcd level By default, only the main thread is used. If opj_codec_set_threads() 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.
2015-09-29Fix typos in comments and stringStefan Weil
Most typos were found by codespell. Signed-off-by: Stefan Weil <sw@weilnetz.de>
2015-07-30Remove printf/fprintf to stdout/stderr throughout openjp2 libmayeut
Update uclouvain/openjpeg#246
2014-12-12[trunk] Reduce encoder code block memory usage for non 64x64 code block ↵Matthieu Darbois
sizes (fixes issue 444)
2014-11-19[trunk] replace OPJ_MACRO_TCD_ALLOCATE macro by inlined function (fixes ↵Matthieu Darbois
issue 433)
2014-11-03[trunk] significantly reduces memory for single tile RGB encoding (fixesAntonin Descampe
issue 375)
2014-04-03[trunk] updated copyright and added copyright notice required by ISO, in ↵Antonin Descampe
each file; updated AUTHORS, NEWS
2012-12-18[trunk] merge from branch 1.5 a correction about large code-block data ↵Mickael Savinaud
(decoding part) and add tests about issue 5 and issue 62
2012-11-15[trunk]update the copyright, the authors and thanks to respect the licenseMickael Savinaud
2012-11-15[trunk] move opj_bool to OPJ_BOOL to follow the other typeMickael Savinaud
2012-10-25[trunk] [trunk] remove old opj_tcp and rename opj_tcp_v2 to opj_tcpMickael Savinaud
2012-10-25[trunk] [trunk] remove old opj_cp and rename opj_cp_v2 to opj_cpMickael Savinaud
2012-10-25[trunk] rename opj_tcd_truct_v2 to opj_tcd_structMickael Savinaud
2012-10-24[trunk] remove old structures from tcd.hMickael Savinaud
2012-09-28[trunk] Start FolderReorgProposal taskMathieu Malaterre
Update issue 177