/****
 *
 * Copyright (c) 1988 by Sun Microsystems, Inc.
 * @(#)sh_color.h 22.1 89/08/10 Copyright 1988 Sun Micro
 *
 * COLOR.H - Shapes COLOR structures and macros
 * This file depends on sh_point.h for sh_path_op
 *
 ****/
#ifndef	_SH_COLOR

/*
 * COLOR object
 * A color object can represent a color map index or it can
 * be broken up into a type and RGB or HSV components.
 * The type will be COL_INDEX if it is a color map index and
 * COL_RGB or COL_HSV to indicate an RGB or HSV format.
 * The first part of all COLOR structures (the dd and t fields)
 * match the PATH_ITEM_TYPE definition in sh_PATH.h so that all
 * path items have a common header.
 *
 * The contents of the COLOR, COLOR_RGB, COLOR_HSV and
 * COLOR_INDEX structures are NOT PUBLIC! The user should only
 * access them via the macros because they may be different
 * for different devices!
 *
 * COLOR *Color_Index((COLOR *) c, n)
 * Initialize a color object from an integer index
 * to be of type COLOR_INDEX
 *
 * COLOR *Color_RGB((COLOR *) c, r, g, b)
 * Initialize a color object from its RGB components
 * to be of type COLOR_RGB
 *
 * COLOR *Color_HSV((COLOR *) c, h, s, v)
 * Initialize a color object from its HSV components
 * to be of type COLOR_HSV
 *
 * COL_type Color_Type((COLOR *) c)
 * Returns the type of the color object
 *
 * Get_Col_Index((COLOR *) c, n)
 * Assigns the index associated with the color object to N.
 * N must be an lref and C must reference a COL_INDEX type.
 *
 * Get_Col_RGB((COLOR *) c, r, g, b)
 * Assigns the RGB components associated with the color object
 * to R, G, B. R,G,B must be a lrefs and C must reference
 * a COL_RGB type. The values returned will be float 0. - 1.
 *
 * Get_Col_HSV((COLOR *) c, h, s, v)
 * Assigns the HSV components associated with the color object
 * to H, S, V. H,S,V must be a lrefs and C must reference
 * a COL_HSV type. The values returned will be float 0. - 1.
 *
 */
typedef short COL_type;

typedef  struct
  {
#ifdef  LITTLEENDIAN
   COL_type       t;
   unsigned short dd;
#else   /* LITTLEENDIAN */
   unsigned short dd;
   COL_type	  t;
#endif  /* LITTLEENDIAN */
   unsigned char  a, b, g, r;
  } COLOR_RGB;

typedef  struct
  {
#ifdef  LITTLEENDIAN
   COL_type       t;
   unsigned short dd;
#else   /* LITTLEENDIAN */
   unsigned short dd;
   COL_type	  t;
#endif  /* LITTLEENDIAN */
   unsigned char  a, v, s, h;
  } COLOR_HSV;

typedef  struct
  {
#ifdef  LITTLEENDIAN
   COL_type       t;
   unsigned short dd;
#else   /* LITTLEENDIAN */
   unsigned short dd;
   COL_type	  t;
#endif  /* LITTLEENDIAN */
   unsigned long  i;
  } COLOR_INDEX;

typedef union
  {
   COLOR_RGB c_rgb;
   COLOR_HSV c_hsv;
   COLOR_INDEX c_index;
  } COLOR;

#define	Color_Type(C) (((COLOR *) (C))->c_rgb.t)
#define	Color_Index(C, n) (((COLOR *) (C))->c_rgb.t = COL_INDEX,\
		((COLOR *) (C))->c_index.i = (n), C)
#define	Color_RGB(C, R, G, B) (((COLOR *) (C))->c_rgb.t = COL_RGB,\
		((COLOR *) (C))->c_rgb.a = 0,\
		((COLOR *) (C))->c_rgb.r = (R) * 255,\
		((COLOR *) (C))->c_rgb.g = (G) * 255,\
		((COLOR *) (C))->c_rgb.b = (B) * 255, C)
#define	Color_HSV(C, H, S, V) (((COLOR *) (C))->c_hsv.t = COL_HSV,\
		((COLOR *) (C))->c_rgb.a = 0,\
		((COLOR *) (C))->c_hsv.h = (H) * 255,\
		((COLOR *) (C))->c_hsv.s = (S) * 255,\
		((COLOR *) (C))->c_hsv.v = (V) * 255, C)

#define	Get_Col_Type(C) (((COLOR *) (C))->c_rgb.t)
#define	Get_Col_Index(C) (((COLOR *) (C))->c_index.i)
#define	Get_Col_RGB(C, R, G, B) (((R) = ((COLOR *) (C))->c_rgb.r / 255.), \
		((G) = ((COLOR *) (C))->c_rgb.g / 255.), \
		((B) = ((COLOR *) (C))->c_rgb.b / 255.))
#define	Get_Col_HSV(C, H, S, V) (((H) = ((COLOR *) (C))->c_hsv.h / 255.), \
		((S) = ((COLOR *) (C))->c_hsv.s / 255.), \
		((V) = ((COLOR *) (C))->c_hsv.v / 255.))

#define	_SH_COLOR
#endif	/* _SH_COLOR */
