1

According to the doxygen documentation (http://www.openjpeg.org/doxygen/structopj__image__comp.html), the opj_image_comp structure contains two fields that are confusing me:

  • prec: precision
  • bpp: image depth in bits

Based on just this info, I would assume that an image with 8 bit pixels (0-255) would have a bpp=8. But when I decompressed some stock 8-bit mono .j2k files, I was finding that prec=8 and bpp=0.

So, what exactly do prec and bpp contain?

I am using OpenJPEG v2.3 if that has any impact on the answer.

Thanks much.

MikeMayer67
  • 570
  • 6
  • 17

2 Answers2

1

I managed to find additional info with more digging.

The prec field contains the number of bits used to encode the image. This corresponds to the lower 7 bits of the Ssiz field in the Image and Tile Size (SIZ) marker segment.

I have not figured out what the bpp field in the OpenJPEG struct opj_image_comp_t actually contains.

MikeMayer67
  • 570
  • 6
  • 17
  • hi! don't suppose you've gained any more insight into this? I've noticed https://github.com/uclouvain/openjpeg/blob/master/tests/test_tile_encoder.c only sets `prec` and has a comment saying "bpp useless" but would be nice to what it's useless for – Sam Mason Jul 12 '21 at 13:17
  • The only place I could find bpp "used" was in src/lib/openjp2/j2k.c. It was used when verifying that the image components were compatible with a specified cinema or IMF profile. But beyond that, I could not find them actually being used when performing the compression. – MikeMayer67 Aug 20 '21 at 15:17
  • have searched around a bit more but didn't find anything so created an issue with the project: https://github.com/uclouvain/openjpeg/issues/1379 – Sam Mason Sep 15 '21 at 08:42
  • just heard back, and `bpp` is disappearing: https://github.com/uclouvain/openjpeg/pull/1383 – Sam Mason Oct 21 '21 at 15:02
0

The bpp is a redundant field and shouldn't be used. To encourage this, it has recently been deprecated by the author, saying:

bpp was redundant with prec, and almost never set by the library, except by opj_image_create(). This change should hopefully not impact existing, working, users of the API, which should already have used prec to get things working.

As per the question, prec is the per-channel bit-depth. So, for an unsigned channel, valid values would be in [0, 2prec-1].

Sam Mason
  • 15,216
  • 1
  • 41
  • 60