open-src/app/xcolor/sun-src/XCrHsbCmap.c
author X gate hg captive account <xhg@xserver.us.oracle.com>
Wed, 19 Aug 2015 13:48:41 -0700
changeset 1484 bc8922b8e1d2
parent 1131 7dc974a70bc8
permissions -rw-r--r--
Added tag s11u3_30 for changeset 221e9d9cc9cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
509
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     1
/*-
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     2
 * XCrHsbCmap.c - X11 library routine to create an HSB ramp colormaps.
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     3
 *
1131
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
     4
 * Copyright (c) 1991, 2011, Oracle and/or its affiliates. All rights reserved.
509
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     5
 *
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     6
 * Permission is hereby granted, free of charge, to any person obtaining a
919
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
     7
 * copy of this software and associated documentation files (the "Software"),
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
     8
 * to deal in the Software without restriction, including without limitation
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
     9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    10
 * and/or sell copies of the Software, and to permit persons to whom the
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    11
 * Software is furnished to do so, subject to the following conditions:
509
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    12
 *
919
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    13
 * The above copyright notice and this permission notice (including the next
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    14
 * paragraph) shall be included in all copies or substantial portions of the
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    15
 * Software.
509
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    16
 *
919
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    20
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    23
 * DEALINGS IN THE SOFTWARE.
509
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    24
 *
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    25
 * Author: Patrick J. Naughton
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    26
 * [email protected]
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    27
 */
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    28
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    29
#include <X11/X.h>
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    30
#include <X11/Xos.h>
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    31
#include <X11/Xlib.h>
1131
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    32
#include "xcolor.h"
509
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    33
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    34
Status
1131
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    35
XCreateHSBColormap(
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    36
    Display    *dsp,
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    37
    int         screen,
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    38
    Colormap   *cmap,		/* colormap return value */
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    39
    int         count,		/* number of entries to use */
509
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    40
    double      h1,		/* starting hue */
1131
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    41
    double      s1,		/* starting saturation */
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    42
    double      b1,		/* starting brightness */
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    43
    double      h2,		/* ending hue */
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    44
    double      s2,		/* ending saturation */
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    45
    double      b2,		/* ending brightness */
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    46
    int         bw,		/* Boolean: True = save black and white */
7dc974a70bc8 7047071 xcolor segfaults on startup
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    47
    Visual    **visual)
509
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    48
{
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    49
    u_char      red[256];
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    50
    u_char      green[256];
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    51
    u_char      blue[256];
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    52
    unsigned long pixel;
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    53
    Status      status;
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    54
    XColor      xcolors[256];
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    55
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    56
    if (count > 256)
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    57
	return BadValue;
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    58
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    59
    HSBramp(h1, s1, b1, h2, s2, b2, 0, count - 1, red, green, blue);
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    60
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    61
    if (bw) {
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    62
	pixel = WhitePixel(dsp, screen);
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    63
	if (pixel < 256)
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    64
	    red[pixel] = green[pixel] = blue[pixel] = 0xff;
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    65
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    66
	pixel = BlackPixel(dsp, screen);
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    67
	if (pixel < 256)
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    68
	    red[pixel] = green[pixel] = blue[pixel] = 0;
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    69
    }
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    70
    status = XCreateDynamicColormap(dsp, screen, cmap, visual, xcolors,
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    71
				    count, red, green, blue);
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    72
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    73
    return status;
9469d4c6010a 6736024 Replace xcolor with open src version
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    74
}