The PNG Guide is an eBook based on Greg Roelofs' book, originally published by O'Reilly. 
Home Gamma Correction and Precision Color The gAMA Chunk  
The gAMA Chunk
More precisely (and here we get into a bit of mathematics that will mainly be of interest to application developers), the stored gamma value represents the following relationship between the image samples and the desired output light intensity: image_sample = light_out^{gamma}or: image_sample^{1 / gamma} = light_outOnce again, bear in mind that light_out and image_sample are scaled to the interval between 0 and 1; that is, if the sample depth is 8 bits, the file samples range between 0 and 255, so image_sample is obtained by dividing a given file sample by 255, in floatingpoint arithmetic. The decoding pipeline is represented by this expression: image_sample^{decoding_exponent * LUT_exponent * CRT_exponent} = light_outThe decoding_exponent is simply the gamma correction that the application applies; the combination of the other two exponents is the ``overall display system's exponent,'' to use the language with which we began this section. Notice that the preceding equation and the one before it are very similarin fact, they imply the following relationship between the exponents: (1 / gamma) = decoding_exponent * LUT_exponent * CRT_exponentor, equivalently: decoding_exponent = 1 / (gamma * LUT_exponent * CRT_exponent)The gamma relationship given in English at the beginning of this section simply says that if the product on the right side of this equation equals one (which means decoding_exponent also equals one), then no further conversion is necessarythe image samples are ready to go as is. On the other hand, if the righthand side of the equation differs from one, then that value is decoding_exponent and is what the decoder uses to correct the image samples before sending them to the display system: display_input = image_sample^{decoding_exponent}Note that this procedure applies to each red, green, and blue value in a truecolor image or to each palette value in a colormapped PNG. But it does not apply to transparency values in an image with an alpha channel or a tRNS chunk; alpha samples are always assumed to be linear. Implementors should also be aware that there is no need to perform a computationally expensive exponentiation for every pixel in the image, or three times per pixel for an RGB image! At most, there are only 65,536 possible sample values (for a 16bit grayscale or 48bit RGB image) and usually no more than 256, which means that gamma correction can be accomplished via a simple lookup table computed when the gAMA chunk is read. That brings us to the gAMA chunk itself. Its contents are quite simple: a 4byte, unsigned integer equal to gamma multiplied by 100,000 and rounded to the nearest integer. So if gamma is 1/2.2 (or 0.45454545...), the value in the gAMA chunk is 45,455. There can be only one gAMA chunk, and it must appear before any IDATs and also before the PLTE chunk, if one is present.


Home Gamma Correction and Precision Color The gAMA Chunk 