summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/pi.c
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-04-21 15:55:44 +0200
committerEven Rouault <even.rouault@spatialys.com>2020-04-21 15:55:44 +0200
commit4edb8c83374f52cd6a8f2c7c875e8ffacccb5fa5 (patch)
tree42a5e5ce02d28ee7517ce9a2f3a2dc317eb3e01d /src/lib/openjp2/pi.c
parent64689d05dfaaf52105581d93fb1eb173b20829a4 (diff)
Add support for generation of PLT markers in encoder
* -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
Diffstat (limited to 'src/lib/openjp2/pi.c')
-rw-r--r--src/lib/openjp2/pi.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/lib/openjp2/pi.c b/src/lib/openjp2/pi.c
index 7debc774..3dcdd4e9 100644
--- a/src/lib/openjp2/pi.c
+++ b/src/lib/openjp2/pi.c
@@ -920,7 +920,7 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
OPJ_UINT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
OPJ_UINT32 l_pdx, l_pdy, l_pw, l_ph;
- lResolutionPtr = p_resolutions[compno];
+ lResolutionPtr = p_resolutions ? p_resolutions[compno] : NULL;
l_tcx0 = opj_uint_ceildiv(*p_tx0, l_img_comp->dx);
l_tcy0 = opj_uint_ceildiv(*p_ty0, l_img_comp->dy);
@@ -941,8 +941,10 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
/* precinct width and height*/
l_pdx = l_tccp->prcw[resno];
l_pdy = l_tccp->prch[resno];
- *lResolutionPtr++ = l_pdx;
- *lResolutionPtr++ = l_pdy;
+ if (lResolutionPtr) {
+ *lResolutionPtr++ = l_pdx;
+ *lResolutionPtr++ = l_pdy;
+ }
if (l_pdx + l_level_no < 32 &&
l_img_comp->dx <= UINT_MAX / (1u << (l_pdx + l_level_no))) {
l_dx = l_img_comp->dx * (1u << (l_pdx + l_level_no));
@@ -966,8 +968,10 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
py1 = opj_uint_ceildivpow2(l_ry1, l_pdy) << l_pdy;
l_pw = (l_rx0 == l_rx1) ? 0 : ((l_px1 - l_px0) >> l_pdx);
l_ph = (l_ry0 == l_ry1) ? 0 : ((py1 - l_py0) >> l_pdy);
- *lResolutionPtr++ = l_pw;
- *lResolutionPtr++ = l_ph;
+ if (lResolutionPtr) {
+ *lResolutionPtr++ = l_pw;
+ *lResolutionPtr++ = l_ph;
+ }
l_product = l_pw * l_ph;
/* update precision*/
@@ -1550,6 +1554,28 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
}
+OPJ_UINT32 opj_get_encoding_packet_count(const opj_image_t *p_image,
+ const opj_cp_t *p_cp,
+ OPJ_UINT32 p_tile_no)
+{
+ OPJ_UINT32 l_max_res;
+ OPJ_UINT32 l_max_prec;
+ OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1;
+ OPJ_UINT32 l_dx_min, l_dy_min;
+
+ /* preconditions in debug*/
+ assert(p_cp != 00);
+ assert(p_image != 00);
+ assert(p_tile_no < p_cp->tw * p_cp->th);
+
+ /* get encoding parameters*/
+ opj_get_all_encoding_parameters(p_image, p_cp, p_tile_no, &l_tx0, &l_tx1,
+ &l_ty0, &l_ty1, &l_dx_min, &l_dy_min, &l_max_prec, &l_max_res, NULL);
+
+ return p_cp->tcps[p_tile_no].numlayers * l_max_prec * p_image->numcomps *
+ l_max_res;
+}
+
opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
opj_cp_t *p_cp,