Viewer offers a way to fine-tune 256-color images so you can display them on both 4-bit and 8-bit video displays. You can tell Viewer to display 256-color bitmaps using dithering. This saves you having to create separate versions of an image for display on 4-bit and 8-bit displays.
A dithered image mixes colors from the 16-color palette to produce the illusion that more colors were used in the image. For example, to display the color purple with pure palette colors, the pixel arrangement might look like this:
purple purple
purple purple
The same arrangement using dithered colors might look like this:
red blue
blue red
A 16-color dithered image looks more natural than a 16-color image that does not use dithering. To display an image using dithered colors, use the bitmap command [dither]. Like other bitmap commands, the [dither] command precedes bitmap filenames in the ew embedded-window and HDisplayBmp extended-window commands, as in the following example:
{ewc mvbmp, ViewerBmp, [dither]bitmapfile}
!HDisplayBmp(hwndContext, qchPath, "[dither]bitmapfile", "title")
Viewer displays the given bitmap using its usual colors on an 8-bit video display or using dithered colors on a 4-bit video display.
The [dither] command comes with several advanced features you can use to fine-tune the color in the dithered image:
You can map colors with RGB values in a particular range to white, light gray, dark gray, or black.
For colors in the 256-color image that cannot be displayed on the 16-color video display, you can balance the surrounding colors in the 16-color dithered image.
You can specify a multiplier to increase the intensity of colors in the 16-color dithered image.
The [dither] command has the following syntax:
[dither=gray-threshold, low-threshold, high-threshold, propagation, red-multiplier, green-multiplier, blue-multiplier]
The following sections discuss each set of options.
When dithering an image, you can achieve the best results by mapping certain colors in the original 256-color image to white, black, or a shade of gray. To perform these mappings, you can specify any of three threshold values in the [dither] command: the gray threshold, low threshold, and high threshold.
Each threshold value is an integer ranging from 0 through 255. For each color in the 16-color image, Viewer compares the RGB values with the thresholds you specify in the [dither] command. Viewer maps the colors based on this comparison, as described in the following table:
RGB Values | Viewer Displays As |
Below low threshold | Black |
Between low and gray thresholds | Dark gray |
Between gray and high thresholds | Light gray |
Above high threshold | White |
As indicated in the previous table, the gray threshold value must be between the high and low thresholds, and the high threshold must be greater than the low threshold. For example, suppose the [dither] command specified the following values:
[dither=135, 120, 200, ...]
Any colors with RGB values below 120 would appear as black. Colors with RGB values between 121 and 134 would appear as dark gray. Colors with RGB values between 135 and 200 would appear as light gray. And colors with RGB values greater than 200 would appear as white.
When mapping from a 256-color image to a dithered image, you'll notice that the closer the new and original colors match, the less detail remains in the picture. The propagation value in the [dither] command allows you to balance fidelity to the original image colors against image resolution. This value can be any whole number between 0 and 16.
The higher the number you use, the closer the colors in the dithered image will be to the colors in the original image. However, higher numbers can cause loss of detail in the dithered image. You should experiment with different values to find the optimum balance between fidelity and resolution.
The red-, green-, and blue-multiplier values increase the intensity of RGB values for all colors in the dithered image at one time. Each value is divided by 32, then multiplied by the corresponding red, green, or blue value in the original image color. For example, if the RGB multipliers are 64, 64, 64, all RGB values in the original colors are multiplied by 2 (64/32=2) in the dithered image. If the RGB multipliers are 32, 32, 64, red and green intensities remain the same but blue intensities are doubled.
The following ewc command displays DITHER.DIB in an embedded window using dithered colors:
{ewc MVBMP, ViewerBmp, [dither=135}
In the embedded window, DITHER.DIB uses the gray-, low-, and high-threshold values from the examples earlier in this section. It uses a propagation value of 8 and multiplies the red, green, and blue values in the original picture by 2 (64/32=2).