Name
SetDepth -- set palette depth (V9.0)
Synopsis
SetDepth(depth[, t])
Function
This function sets the depth of the currently active palette to the one specified in depth. depth must be a bit depth ranging from 1 (= 2 colors) to 8 (= 256 colors). See Palette overview for details. Note that if the specified depth is less than that of the pixel data attached to the palette, the pixel data will be remapped to match the new depth.

By default, the current display's palette is the active palette but of course only in case the current display is a palette mode display. See Palette mode displays for details. A palette can be made the active one by using the SelectPalette() command.

Alternatively, the specified depth can also be set to a different palette object. To do so, you need to pass the optional table argument to SetDepth() and specify the Type and ID tags. See below for an example.

The following tags are supported by the optional table argument t:

Type:
Set this to the type identifier of the object whose depth you want to set. This can be one of the following object types:

 
#ANIM
#BGPIC
#BRUSH
#DISPLAY
#LAYER
#PALETTE
#SPRITE

Note that if you use types #ANIM or #SPRITE, you also need to set the Frame tag (see below) to indicate the frame whose depth you want to modify. If you use #LAYER and the specified layer is an anim layer, you also need to set the Frame tag.

Type defaults to the type of the currently active palette selected using SelectPalette(). See SelectPalette for details.

ID:
Set this tag to the identifier of the object whose depth you want to set. The default is the identifier of the currently active palette selected using SelectPalette(). See SelectPalette for details.

Frame:
If the target type is an animation, sprite, or anim layer, you need to set this tag to specify the frame whose depth should be set. Frames are counted from 1. Defaults to 1 when used with anims and sprites and to the current frame when used with anim layers.

Remap:
If this tag is set to False, out-of-range pens will not be remapped to existing pens but instead they will simply be set to the pen specified in the ClipPen tag (see below), i.e. no remapping will take place. Note that Remap is only effective when reducing colors. If the new depth has more pens than the old depth, Remap won't do anything. (V10.0)

ClipPen:
This is only used in case the Remap tag is set to False (see above). In that case, out-of-range pens will not be remapped to existing pens but will simply be set to the pen specified in the ClipPen tag, i.e. no remapping will take place. Note that ClipPen is only effective when reducing colors. If the new depth has more pens than the old depth, ClipPen won't do anything. (V10.0)

Inputs
depth
desired new palette depth (ranging from 1 to 8)
t
optional: table for specifying further options (see above)
Example
SetDepth(4, {Type = #BRUSH, ID = 2})
The code above sets the palette depth of brush 2 to 4 (= 16 colors).

Show TOC