ImageMagick – MagickCore, C API: Count the Colors in an Image
Author: ImageMagick Studio LLC
Description: ImageMagick is a powerful, open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for web developers, graphic designers, and researchers, it offers versatile tools for image processing, including batch processing, format conversion, and complex image transformations.
Keywords: MagickCore, C API: Count the Colors in an Image, Image Processing, Digital Image Editing, Image Conversion, Open-Source Software, Image Manipulation, Command-Line Image Tools

# Color

## AcquireColorCache

AcquireColorCache() caches one or more color configurations which provides a mapping between color attributes and a color name.

The format of the AcquireColorCache method is:

    LinkedListInfo *AcquireColorCache(const char *filename,
      ExceptionInfo *exception)

A description of each parameter follows:

filename
  the font file name.
exception
  return any errors or warnings in this structure.

## GetColorInfoList

GetColorInfoList() returns any colors that match the specified pattern.

The format of the GetColorInfoList function is:

    const ColorInfo **GetColorInfoList(const char *pattern,
      size_t *number_colors,ExceptionInfo *exception)

A description of each parameter follows:

pattern
  Specifies a pointer to a text string containing a pattern.
number_colors
  This integer returns the number of colors in the list.
exception
  return any errors or warnings in this structure.

## GetColorList

GetColorList() returns any colors that match the specified pattern.

The format of the GetColorList function is:

    char **GetColorList(const char *pattern,size_t *number_colors,
      ExceptionInfo *exception)

A description of each parameter follows:

pattern
  Specifies a pointer to a text string containing a pattern.
number_colors
  This integer returns the number of colors in the list.
exception
  return any errors or warnings in this structure.

## ListColorInfo

ListColorInfo() lists color names to the specified file. Color names are a convenience. Rather than defining a color by its red, green, and blue intensities just use a color name such as white, blue, or yellow.

The format of the ListColorInfo method is:

    MagickBooleanType ListColorInfo(FILE *file,ExceptionInfo *exception)

A description of each parameter follows.

file

List color names to this file handle.

exception

return any errors or warnings in this structure.

## QueryColorCompliance

QueryColorCompliance() returns the red, green, blue, and opacity intensities for a given color name.

The format of the QueryColorCompliance method is:

    MagickBooleanType QueryColorCompliance(const char *name,
      const ComplianceType compliance,PixelPacket *color,
      ExceptionInfo *exception)

A description of each parameter follows:

name
  the color name (e.g. white, blue, yellow).
compliance
  Adhere to this color standard: SVG, X11, or XPM.
color
  the red, green, blue, and opacity intensities values of the named color in this structure.
exception
  return any errors or warnings in this structure.

## QueryColorDatabase

QueryColorDatabase() returns the red, green, blue, and opacity intensities for a given color name.

The format of the QueryColorDatabase method is:

    MagickBooleanType QueryColorDatabase(const char *name,PixelPacket *color,
      ExceptionInfo *exception)

A description of each parameter follows:

name
  the color name (e.g. white, blue, yellow).
color
  the red, green, blue, and opacity intensities values of the named color in this structure.
exception
  return any errors or warnings in this structure.

## QueryColorname

QueryColorname() returns a named color for the given color intensity. If an exact match is not found, a rgb() color is returned instead.

The format of the QueryColorname method is:

    MagickBooleanType QueryColorname(const Image *image,
      const PixelPacket *color,const ComplianceType compliance,char *name,
      ExceptionInfo *exception)

A description of each parameter follows.

image

the image.

color

the color intensities.

compliance

Adhere to this color standard: SVG, X11, or XPM.

name

Return the color name or hex value.

exception

return any errors or warnings in this structure.

## QueryMagickColorCompliance

QueryMagickColorCompliance() returns the red, green, blue, and opacity intensities for a given color name and standards compliance.

The format of the QueryMagickColor method is:

    MagickBooleanType QueryMagickColorCompiliance(const char *name,
      const ComplianceType compliance,MagickPixelPacket *color,
      ExceptionInfo *exception)

A description of each parameter follows:

name
  the color name (e.g. white, blue, yellow).
compliance
  Adhere to this color standard: SVG, X11, or XPM.
color
  the red, green, blue, and opacity intensities values of the named color in this structure.
exception
  return any errors or warnings in this structure.

## QueryMagickColor

QueryMagickColor() returns the red, green, blue, and opacity intensities for a given color name.

The format of the QueryMagickColor method is:

    MagickBooleanType QueryMagickColor(const char *name,
      MagickPixelPacket *color,ExceptionInfo *exception)

A description of each parameter follows:

name
  the color name (e.g. white, blue, yellow).
color
  the red, green, blue, and opacity intensities values of the named color in this structure.
exception
  return any errors or warnings in this structure.

## QueryMagickColorname

QueryMagickColorname() returns a named color for the given color intensity. If an exact match is not found, a hex value is returned instead. For example an intensity of rgb:(0,0,0) returns black whereas rgb:(223,223,223) returns #dfdfdf.

The format of the QueryMagickColorname method is:

    MagickBooleanType QueryMagickColorname(const Image *image,
      const PixelPacket *color,const ComplianceType compliance,char *name,
      ExceptionInfo *exception)

A description of each parameter follows.

image

the image.

color

the color intensities.

Compliance

Adhere to this color standard: SVG, X11, or XPM.

name

Return the color name or hex value.

exception

return any errors or warnings in this structure.