How to perform gamma correction in Inkscape
We’re quite proud of the fact that everything we do here at Denexa Games is done using 100% open-source software. One of the many open-source programs we use is Inkscape. All of the art used on Denexa 100% Plastic Playing Cards starts its life as an Inkscape SVG file, before being passed off to other programs to process it further to get it print-ready.
Open-source software is great, but because the documentation comes from volunteers, sometimes the programs hide features that are not obvious to even an experienced user. Inkscape’s ability to perform gamma correction is one of these hidden gems.
What is gamma correction?
One of the many tasks we need to perform to our SVG files is gamma correction. This is a color-correction tool that may be familiar to those who have used a raster graphics editor like GIMP or Photoshop. Basically, gamma correction allows you to adjust the red, green, and blue channels by a known value. Done to all three channels, this will make the image darker or lighter. Our printers have a tendency to print darker colors than what appears on our screen, so we adjust for this with gamma correction.
However, Inkscape has no internal gamma-correction tool. This meant that we had to use the gamma box in GIMP’s “Levels” tool to gamma correct a raster version of the image, then change the colors by hand using the color-dropper tool against the imported raster image.
Or so we thought, anyway.
How to perform gamma correction using the “Custom” color extension
Gamma correction can be achieved entirely within Inkscape using the “Custom” color extension. First, select all of the elements of the image you want to correct; if you select nothing, it will apply to the entire document. Then, go to Extensions → Color → Custom…
The dialog that pops up doesn’t look like much. It asks for three functions, red, green, and blue. By using r
, g
, and b
in a mathematical expression, you can alter the red, green, and blue color values for the selection. r + 5
in the red function would increase the red value by 5. (So an element with a red value of 120 would be adjusted to 125.)
This doesn’t seem too useful on the face of it…but gamma correction is just a mathematical function!
To perform gamma correction, just enter the following values. Replace “gamma” with the gamma value you want to adjust by. (In the screenshot above, we’re using 1.66 as our gamma value.)
- Red Function:
255 * (r / 255) ** (1/gamma)
- Green Function:
255 * (g / 255) ** (1/gamma)
- Blue Function:
255 * (b / 255) ** (1/gamma)
- Input (r,g,b) Color Range: 0 – 255
These are the formulas used to perform gamma correction in any program, so there’s no reason they can’t work in Inkscape too. Note that this extension is written in Python, so Python math syntax is used. The **
performs exponentiation. (That is, we are raising the expression to the power of 1/gamma
).
Click apply and your image will be gamma corrected!