/* xyz */

/*
 * Copyright (c) 1994, 1995 by Wayne C. Gramlich.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * for any purpose is hereby granted without fee provided that the above
 * copyright notice and this permission are retained.  The author makes
 * no representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 */

/*
 * This file provide a bunch of interface routines for dealing xlib
 * {XColor} objects.
 */

#ifndef XLIB_H
#include "xlib.h"
#endif

/* The initial object: */
Xlib_color_struct xlib_color___initial_object = {
    &xlib_color_map___initial_object,	/* Color map object */
    0					/* Pad the rest with zeros */
};
Xlib_color xlib_color___initial = &xlib_color___initial_object;

/*
 * xlib_color__address_get(color)
 *	This routine will return the address of {color}.
 */
unsigned
xlib_color__address_get(
    Xlib_color color)
{
    return (unsigned)color;
}
    
/*
 * xlib_color__blue_get(color)
 *	This procedure will return the blue intensity associated with {color}
 *	as a number between 0 and 2**16-1 (65535).
 */
unsigned
xlib_color__blue_get(
    Xlib_color color)
{
    return color->color.blue;
}

/*
 * xlib_color__blue_set(color, value)
 *	This procedure will set the blue intensity associated with {color}
 *	to {value} (which must be a number between 0 and 2**16-1 (65535)).
 */
void
xlib_color__blue_set(
    Xlib_color color,
    unsigned value)
{
    color->color.blue = value;
}

/*
 * xlib_color__create(color_map)
 *	This procedure will allocate and return a {color} object for
 *	{color_map}.  No color slot is allocated from
 *	{color_map}; use {color_allocate}@{xlib_color_map}() for that
 *	purpose!
 */
Xlib_color
xlib_color__create(
    Xlib_color_map color_map)
{
    Xlib_color color;

    color = (Xlib_color)malloc(sizeof(*color));
    color->color_map = color_map;
    color->color.blue = 0;
    color->color.flags = 0;
    color->color.green = 0;
    color->color.pixel = 0;
    color->color.red = 0;
    return color;
}

/*
 * xlib_color__external__initialize()
 *	This routine will initialize the {Xlib_color} object:
 */
void
xlib_color__external__initialize(void)
{
    assert(xlib_color___initial == &xlib_color___initial_object);
}

/*
 * xlib_color__green_get(color)
 *	This procedure will return the green intensity associated with {color}
 *	as a number between 0 and 2**16-1 (65535).
 */
unsigned
xlib_color__green_get(
    Xlib_color color)
{
    return color->color.green;
}

/*
 * xlib_color__green_set(color, value)
 *	This procedure will set the green intensity associated with {color}
 *	to {value} (which must be a number between 0 and 2**16-1 (65535)).
 */
void
xlib_color__green_set(
    Xlib_color color,
    unsigned value)
{
    color->color.green = value;
}

/*
 * xlib_color__pixel_get(color)
 *	This procedure will return the pixel associated with {color}.
 */
unsigned
xlib_color__pixel_get(
    Xlib_color color)
{
    return color->color.pixel;
}

/*
 * xlib_color__red_get(color)
 *	This procedure will return the red intensity associated with {color}
 *	as a number between 0 and 2**16-1 (65535).
 */
unsigned
xlib_color__red_get(
    Xlib_color color)
{
    return color->color.red;
}

/*
 * xlib_color__red_set(color, value)
 *	This procedure will set the red intensity associated with {color}
 *	to {value} (which must be a number between 0 and 2**16-1 (65535)).
 */
void
xlib_color__red_set(
    Xlib_color color,
    unsigned value)
{
    color->color.red = value;
}


