ImageMagick – MagickCore, C API: Dealing with Image Colorspaces
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: Dealing with Image Colorspaces, Image Processing, Digital Image Editing, Image Conversion, Open-Source Software, Image Manipulation, Command-Line Image Tools

# Colorspace

## ConvertGenericToRGB

ConvertGenericToRGB() transforms a generic pixel (X, Y, Z) to a (red, green, blue) triple.

The format of the ConvertGenericToRGBImage method is:

    void ConvertHSLToRGB(const double hue,const double saturation,
      const double lightness,const double white_luminance,
      const double illuminant,double *red,double *green,double *blue)

A description of each parameter follows:

X, Y, Z
  A double value representing a component of a generic color space.
white_luminance
  white luminance.
illuminant
  illuminant, typically D65.
red, green, blue
  A pointer to a pixel component of type Quantum.

## ConvertHSLToRGB

ConvertHSLToRGB() transforms a (hue, saturation, lightness) to a (red, green, blue) triple.

The format of the ConvertHSLToRGBImage method is:

    void ConvertHSLToRGB(const double hue,const double saturation,
      const double lightness,double *red,double *green,double *blue)

A description of each parameter follows:

hue, saturation, lightness
  A double value representing a component of the HSL color space.
red, green, blue
  A pointer to a pixel component of type Quantum.

## ConvertRGBToGeneric

ConvertRGBToGeneric() transforms a (red, green, blue) to a generic (X, Y, Z) triple.

The format of the ConvertRGBToGeneric method is:

    void ConvertRGBToGeneric(const double red,const double green,
      const double blue,double *hue,double *saturation,double *lightness)

A description of each parameter follows:

red, green, blue
  A Quantum value representing the red, green, and blue component of a pixel..
white_luminance
  white luminance.
illuminant
  illuminant, typically D65.
X, Y, Z
  A pointer to a double value representing a component of a generic color space.

## ConvertRGBToHSL

ConvertRGBToHSL() transforms a (red, green, blue) to a (hue, saturation, lightness) triple.

The format of the ConvertRGBToHSL method is:

    void ConvertRGBToHSL(const double red,const double green,
      const double blue,double *hue,double *saturation,double *lightness)

A description of each parameter follows:

red, green, blue
  A Quantum value representing the red, green, and blue component of a pixel..
hue, saturation, lightness
  A pointer to a double value representing a component of the HSL color space.

## GetImageColorspaceType

GetImageColorspaceType() returns the potential type of image: sRGBColorspaceType, RGBColorspaceType, GRAYColorspaceType, etc.

To ensure the image type matches its potential, use SetImageColorspaceType():

        (void) SetImageColorspaceType(image,GetImageColorspaceType(image),
    exception);

The format of the GetImageColorspaceType method is:

    ColorspaceType GetImageColorspaceType(const Image *image,
      ExceptionInfo *exception)

A description of each parameter follows:

image
  the image.
exception
  return any errors or warnings in this structure.

## SetImageColorspace

SetImageColorspace() sets the colorspace member of the Image structure.

The format of the SetImageColorspace method is:

    MagickBooleanType SetImageColorspace(Image *image,
      const ColorspaceType colorspace,ExceptionInfo *exception)

A description of each parameter follows:

image
  the image.
colorspace
  the colorspace.
exception
  return any errors or warnings in this structure.

## SetImageGray

SetImageGray() returns MagickTrue if all the pixels in the image have the same red, green, and blue intensities and changes the type of the image to bi-level or grayscale.

The format of the SetImageGray method is:

    MagickBooleanType SetImageGray(const Image *image,
      ExceptionInfo *exception)

A description of each parameter follows:

image
  the image.
exception
  return any errors or warnings in this structure.

## SetImageMonochrome

SetImageMonochrome() returns MagickTrue if all the pixels in the image have the same red, green, and blue intensities and the intensity is either 0 or QuantumRange and changes the type of the image to bi-level.

The format of the SetImageMonochrome method is:

    MagickBooleanType SetImageMonochrome(Image *image,
      ExceptionInfo *exception)

A description of each parameter follows:

image
  the image.
exception
  return any errors or warnings in this structure.

## TransformImageColorspace

TransformImageColorspace() transforms an image colorspace, changing the image data to reflect the new colorspace.

The format of the TransformImageColorspace method is:

    MagickBooleanType TransformImageColorspace(Image *image,
      const ColorspaceType colorspace,ExceptionInfo *exception)

A description of each parameter follows:

image
  the image.
colorspace
  the colorspace.
exception
  return any errors or warnings in this structure.