What exactly are bpp and prec records of opj_image_comp structure

193 views Asked by At

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.

2

There are 2 answers

4
MikeMayer67 On

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.

0
Sam Mason On

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].