Site iconJava PDF Blog

How does a decodeArray work?

When you create an image in a PDF file it is possible to specify that it is inverted or control the range of values. You do this by using the decodeArray. This consists of 2 values for each colour element – a minimum and a maximum. So for a gray colorspace you might see

decodeArray [0.0 1.0]

while CMYK would have

decodeArray [0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0]

It can also be defined as an 8 bit value ( decodeArray [0 254])

This allows control over the allowable values and out of range values will be set to the minimum or maximum. If you reverse these the image can be inverted (ie decodeArray [1.0 0.0]) which is a neat little trick. You can also do some simple image processing with it.

Where it can get slightly tricky is that you can also apply a decoder Array to a Mask on an image – I’ll leave you to figure this one out…