uclouvain / openjpeg

Official repository of the OpenJPEG project
Other
971 stars 456 forks source link

Implement partial jpx-write support and add new `opj_merge` utility #1523

Open dgarciabriseno opened 6 months ago

dgarciabriseno commented 6 months ago

In this PR I've added partial support for writing jpx files.

What's New

Public API

I've added a new jpx codec which is created when you call opj_create_compress(OPJ_CODEC_JPX).

From there the usual interface of opj_encoder_set_extra_options, opj_setup_encoder, opj_start_compress, opj_end_compress, should all be called to complete the process.

For this codec, opj_encoder_set_extra_options is used to specify the list of files that will be merged into the jpx file.

Internal Changes

Overview of What I've Done

I manage an application which relies on kdu_merge -link. The opj_merge utility I've written has similar behavior as the kdu_merge command. What this merge does, is it creates a jpeg2000 file with only boxes, and no codestreams. The boxes included are:

  1. signature box
  2. file type box -> special note that for jpx, the brand is "jpx " and the compatibility list (cl) includes ["jpx ", "jp2 ", "jpxb"].
  3. A reader requirements box which specifies the features supported in the jpx. I put values "(2) Contains multiple composition layers" and "(15) Fragmented codestream where not all fragments are within the file but all are in locally accessible files" See Table M.14 in ISO/IEC 15444-2 for more details on the values available for this box.
  4. A jp2h header which is a shared header among all images. More on this below.
  5. A series of fragment table boxes. 5.1 Each fragment table contains a fragment list box 5.2 Each fragment list box points to a j2k codestream in the jp2 files being merged. Specifically the codestream's file offset and length.
  6. A series of association tables 6.1 The association table uses a Number List Box to designate which jp2 the association is being made for 6.2 Any XML boxes in the source jp2s are embedded here. With an association table made for each xml box. If there's no xml box in the source jp2, then no association is added to the jpx.
  7. A Data Reference Box. This is where the actual local paths to the jp2 files are stored.

Partial Support

Next Steps / Things I need help with