Posterizing Images

A message on a Flash list posed the question of whether there was any way to dynamically generate a posterized version of a bitmap image in Director. My response: “Nothing could be simpler.”

The following movie script takes an image object and applies the built-in Web 216 palette to the picture without dithering, which results in a fair amount of posterization. Using a more restricted palette would result in more dramatic effects.

on posterize imageRef
  memberRef = new (#bitmap)
  posterizedImage = image (imageRef.rect.width, imageRef.rect.height, 8, #web216)
  posterizedImage.copyPixels (imageRef, imageRef.rect, imageRef.rect)
  memberRef.image = posterizedImage
end

You can see the results of this script here (click to open up a larger version):

To execute the script, if you’ve got a bitmap image in cast member position 1, you just type “posterize member (1).image” in the Message window.

The first command creates a new cast member for the posterized bitmap.

The second command assigns an image object to a variable, using the size of the original image, setting the color depth of the posterized image, and specifying a palette to use.

The third command copies the original image into the image object.

Finally, the image object is assigned to the image property of the new member.

To make the third version of the original image in the JPG, I just substituted a 4 for the 8 in the third parameter of the image function, to make it 16-color instead of 256-color. For more control over the colors of the posterization, you can create a custom palette and substitute its member reference for the fourth parameter. There are all other sorts of effects you can do automatically using copyPixels, including things like inverting the brightness of the colors. If you’re not in a hurry, it’s certainly possible to do a pixel-by-pixel processing of the image.

You can download the source file (compatible with Director 8.5 and later) here.