library(lofi)

Introduction

Colours in R are usually stored as 8-bits per channel for red, green and blue - with a total of 24-bits then required for a single RGB colour. This means that there are a total of 2^24 = 16777216 possible colour values.

Each 8-bit value is usually represented as hex e.g. 255 = FF, and then all the values are concatenated to specify a colour e.g.red = #FF0000.

Note: lofi has no built-in support for colours with alpha values.

Storing a colour in 8-bits

To store a colour in 8-bits, lofi truncates the lower bits from each of the colour channels, keepingly 3 bits for red and green channels, and only 2 bits for blue. More information about the 8-bit colour format is available on wikipedia.

8-bit colour means that only 256 colours can be represented, so conversion to this low-fidelity representation and back again will results in the loss of colour accuracy.

Viridis palette in 8-bits

In the following example, 64 colours from a viridis palette are converted to 8-bit colour and then reconstructed. Visually, the reconstructed palette looks similar to the original colours, but the errors in colour accuracy are quite apparent.

Viridis palette in 12-bits

In the following example, 64 colours from a viridis palette are converted to 12-bit colour and then reconstructed. Visually, the reconstructed palette looks similar to the original colours, and the errors in colour accuracy are less apparent than with only 8-bits