
openjpeg - issue #444
Reduce encoder code block memory usage for non 64x64 code block sizes
Currently, all encoder code blocks allocate 8192*2 bytes, which is equivalent to 64 x 64 x sizeof(OPJ_UINT32) bytes. i.e. it covers the worst case scenario (no compression) on a 64x64 size code block.
For DCP encoding, for example, which mandates 32x32 code blocks, this uses 4 times the worst-case memory needed.
I have attached a simple fix: use the code block dimensions to decide how much memory to allocate.
Comment #1
Posted on Nov 30, 2014 by Happy WombatFor this fix, it may be good to add some sanity checks on the code block dimensions. I have not done so in this patch.
Comment #2
Posted on Dec 12, 2014 by Quick LionAaron,
I think that sanity checks shall be implemented. However, given that this is a coder patch, they should probably be elsewhere (like parameter validation). This might (should) already be the case.
Your patch does not take into account different sizes of block per tile/component & I'll add that.
Comment #3
Posted on Dec 12, 2014 by Quick LionOn ElephantDream_4K.tif from the test suite encoded to j2k with -cinema4k option,
Before patch Bytes Used Count Name 696.65 MB 99.9% main 544.94 MB 78.2% opj_j2k_encode 542.39 MB 77.8% opj_tcd_init_tile 412.33 MB 59.1% malloc 128.32 MB 18.4% calloc 1.73 MB 0.2% opj_tgt_create 2.56 MB 0.3% opj_j2k_post_write_tile 101.33 MB 14.5% tiftoimage 49.36 MB 7.0% opj_j2k_start_compress 1.00 MB 0.1% opj_stream_create_file_stream 9.62 KB 0.0% opj_setup_encoder 1.62 KB 0.0% opj_create_compress
After patch Bytes Used Count Name 387.31 MB 99.9% main 235.60 MB 60.8% opj_j2k_encode 233.05 MB 60.1% opj_tcd_init_tile 128.32 MB 33.1% calloc 102.99 MB 26.5% malloc 1.73 MB 0.4% opj_tgt_create 2.56 MB 0.6% opj_j2k_post_write_tile 101.33 MB 26.1% tiftoimage 49.36 MB 12.7% opj_j2k_start_compress 1.00 MB 0.2% opj_stream_create_file_stream 9.62 KB 0.0% opj_setup_encoder 1.62 KB 0.0% opj_create_compress
Comment #4
Posted on Dec 12, 2014 by Quick LionThis issue was closed by revision r2955.
Status: Fixed
Labels:
Type-Enhancement
Priority-Medium