Pixels, Images, and RGB Colors

In this article, I want to provide some basic concepts of digital images, both in general and in how they are implemented in Second Life™. If you open a photo in an off-world image editor (e.g., Photoshop, Corel Photopaint, Gimp, …) and keep zooming in, you’ll eventually get to a point at which the tiny segment of the image you zoomed to is shown in small squares.

Pixels from an Oxbridge Dock

Pixels from an Oxbridge Dock

Each of the squares is a single color. Within similar parts of the picture, there will be small fluctuations of the colors of nearby pixels. Crossing boundaries of parts of the picture, colors between the squares will change rapidly. These squares are known as pixels, short for picture elements. They are the building blocks for digital images. The image on the right shows the pixels from part of a photo of a dock at Caledon Oxbridge. The mottled brown of the dock changes rapidly into the various blues of the water.

As in the small example picture, full images are composed of rows (horizontal) and columns (vertical) of pixels. For example, an image that is listed as being 1024×768 has rows that all contain 1024 pixels and columns that all contain 768 pixels. The ratio of width to height is known as the aspect ratio of the image, for 1024 to 768, that’s 4:3 or 1.33.

The physical size of an image depends on the display device. Screen resolution is generally 72 dpi (dots per inch equals pixels per inch) or 96 dpi. Printer resolution is often 300 dpi.The choice of needed pixel dimensions depends on how you want to display it.

Outside of Second Life, images can be edited, within reason, to have arbitrary pixel sizes. In contrast, Second Life, limits each dimension of an image to be a power of two (e.g., 32, 64, 128, 256, 512, and 1024) and sets a maximum pixel dimension of 1024. Images that are uploaded with non-conforming dimensions will have their dimensions mapped to a power of two. For example, an image that is 1024×768 will end up inworld as 1024×512. You have more control if, in your off-world image editor, you uncheck “maintain aspect ratio” and map the image dimensions to powers of two yourself. For example, a 1024×768 (4:3 aspect) can be mapped to either 1024×512 (2:1) or 1024×1024 (1:1), either losing some vertical resolution or adding more than needed. Either way, if the distorted image is displayed on a prim (primitive object) with a 4:3 aspect ratio, it will look correct.

Colors in the inworld editor are set by selecting values between zero and 255 for each of the Red, Blue, and Green (RGB) channels. Since this requires 8 bits of data for each channel, this is often referred to a 24-bit color. There can also be an additional channel, the alpha channel, which encodes varying opacities (inverse of transparency) over the image, yielding RGBA color. If the alpha channel only selects full opacity and full transparency over an image, then the alpha-masking mode can be used in-world.If there are partial opacities used, then the slower alpha-blending mode is required. In LSL scripting in Second Life, instead of each channel being zero to 255, the channel values are specified by converting each to a float and dividing by 255, resulting in each component specified as a float between zero and one.

If you are interpolating between two colors, either off-world or in scripts in-world, there’s one additional concept you should know about, gamma encoding..Because the human eye is far more sensitive to relative changes in light intensity than to absolute changes, those zero to 255 values have been manipulated to store more shades at the darker end than at the lighter end. In other words, they are approximately linear in how we perceive colors rather than linear in the energy output. Interpolation, on the other hand, assumes colors that are linear in the energy output and are re-encoded after interpolating. For the details, I’m going to refer you to “What Every Coder Should Know About Gamma”, about the most thorough explanation I’ve found.

As always, thank you for your attention.

Leave a Reply

Your email address will not be published. Required fields are marked *