25.16 Palette displays

When showing a palette BGPic using DisplayBGPic() or assigning a palette BGPic to a display using the @DISPLAY preprocessor command or SetDisplayAttributes(), Hollywood will put the display into palette mode. This means that the only colors available for drawing on that display are the colors that are part of the palette. This is very similar to old graphics hardware from the 1980s and early 1990s which was only capable of showing a fixed amount of colors, ranging from 2 to 256 colors, on screen.

An advantage of putting a display into palette mode is that by changing the color of a pen in the palette, all pixels which use that pen will change their color instantly as well. This makes it possible to easily write code that fades palette colors or cycles them. Color cycling effects were a very popular way of animating graphics like waterfalls or rain in the 1980s and early 1990s. By using a Hollywood display in palette mode, these effects can be easily replicated in Hollywood.

Another advantage of palette mode displays is that the memory consumption is much lower than when using true colour displays. In 32-bit true colour mode, a single pixel will require 4 bytes of memory whereas in palette mode, a single pixel will just require 1 byte of memory. Thus, a 1920x1080 image will require about 8 megabytes of memory in 32-bit mode but only 2 megabytes of memory in palette mode.

However, great care needs to be taken when using displays in palette mode because otherwise drawing can become really slow. This is because by default, all graphics that you draw to a palette mode display will be remapped to the display's palette so that their appearance is as close to the original as possible. Precisely, remapping means that Hollywood has to scan all pixels of the source graphics and find the closest match for each pixel in the display's palette. This is of course a very time-consuming operation and will make drawing very slow. That's why the fastest way of drawing to a palette mode display is to make sure all graphics use the same palette. Then no remapping needs to be done and the graphics data can just be copied to the display without any expensive pixel adaptation algorithm.

To disable remapping in a palette mode display, you have to pass #PALETTEMODE_PEN to SetPaletteMode(). This will enable pen-based drawing and whenever you draw palette graphics to the display, Hollywood will assume that they use the same palette as the display. Thus, they can just be copied to the display as they are.

Furthermore, when the palette mode has been set to #PALETTEMODE_PEN, single-color drawing functions like Box() or Circle() will ignore the RGB color that is passed to them. Instead, they will simply draw the shapes using the pen that has been set using SetDrawPen(). Shadow and border effects that might be active will also ignore the standard shadow and border color set using SetFormStyle() or SetFontStyle() and will draw the shadow and border using the pen that has been set using SetShadowPen() and SetBorderPen(), respectively. Also, antialiasing will be disabled when #PALETTEMODE_PEN is active because in most cases palettes don't have enough colors for satisfactorily anti-aliasing edges.

Note, however, that even if #PALETTEMODE_PEN is active, RGB graphics, of course, still have to be remapped because it's obviously impossible to draw RGB graphics to a palette mode display in any other way. Thus, drawing 32-bit true color graphics to palette displays should be avoided because it will always be slow because remapping needs to be done for those graphics and there is no way around this.

The way graphics data is remapped to a display's palette can be configured by calling SetDitherMode(). This allows you to enable or disable dithering and you can also specify the dithering algorithm to use.

Palette mode displays support all features of normal displays. It is possible to use layers, sprites, transition effects, clipping regions, videos, and double buffers with palette mode displays as well. Keep in mind, however, to pay attention to the remarks mentioned above or drawing might become very slow.

See Palette overview to learn more about palettes.


Show TOC