Getting Color Information
Getting Color Information
If you want information about the colors of a picture or pixel map, you
indicate how many colors you want to know about, what sort of color sampling
you want done, and whether you want colors returned in a palette or color
table.
Currently the Picture Utilities Package has two color-sampling
methods: one that gives you the most frequently used colors and one that gives
you the widest range of colors. Each has advantages in different situations. For
example, suppose a forest image has 400 colors, of which 300 are greens, 80
are browns, and the rest are a scattering of gold sunlight effects. If you ask for
the 250 most popular colors, you might, in early summer, get all greens. If
you ask for a range of 250 colors, you will receive an assortment stretching
from the greens and golds at one locus of RGB space to the browns at the other,
including colors in between that might not actually appear in the image. If you
need to use less than the image's full color set, you now have some information
that may help you make the selection.
You can specify that the Picture Utilities Package chooses which
color-sampling method to use (with the constant systemMethod), or you can
specify one of the two color-sampling methods. By letting the
Picture Utilities Package decide, you assure that when new methods are
made available they will be chosen when appropriate.
systemMethod method chosen by picture utilites
popularMethod most frequently used colors
medianMethod range of colors
You can also supply a color-sampling algorithm of your own, as described in
Creating Custom Color-Sampling Methods . In that case, you pass the
resource ID of your color-sampling method.
Warning: When you ask for color information about a picture, the
Picture Utilities Package only takes into account the version 2
picture opcodes RGBFgCol, RGBBkCol, BkPixPat, PnPixPat,
FillPixPat, and HiliteColor (as well as pixel map or bitmap data).
Each occurrence of these opcodes is treated as 1 pixel, regardless of
the number and sizes of the objects drawn with that color. If you need
an accurate set of colors from a complex picture, create an image of
the picture in an offscreen pixel map, and then call GetPixMapInfo
to obtain color information about that pixel map.
You can request that colors be returned in a color table, a palette, or both, and
that black and white not be returned in palettes or color tables. You can also
ask for information about comments and fonts en countered in the picture.
returnColorTable returns colors in a color table
returnPalette returns colors in a palette
recordComments creates a handle to comments
recordFontInfo creates a handle to fonts
suppressBlackAndWhite suppresses black and white from color tables and
palettes
When you use the returnColorTable, returnPalette, recordComments, and
recordFontInfo values, you create handles to the additional information they
provide. It is your responsibility to dispose of these handles. The
Picture Utilities Package always returns NIL for the palette if you run
system 7.0 with the original QuickDraw.