]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_color.c
ncurses 5.6 - patch 20080412
[ncurses.git] / ncurses / base / lib_color.c
index f81a1914a6067b8afb15f315eb300fa748593b77..9cae495436fecc4f3a3b80546e6a18d05fe4dbec 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 #include <term.h>
 #include <tic.h>
 
-MODULE_ID("$Id: lib_color.c,v 1.82 2006/12/31 00:22:19 tom Exp $")
+MODULE_ID("$Id: lib_color.c,v 1.85 2007/04/07 17:07:28 tom Exp $")
 
 /*
  * These should be screen structure members.  They need to be globals for
  * historical reasons.  So we assign them in start_color() and also in
  * set_term()'s screen-switching logic.
  */
+#if USE_REENTRANT
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(COLOR_PAIRS) (void)
+{
+    return SP ? SP->_pair_count : -1;
+}
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(COLORS) (void)
+{
+    return SP ? SP->_color_count : -1;
+}
+#else
 NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0;
 NCURSES_EXPORT_VAR(int) COLORS = 0;
+#endif
 
 #define DATA(r,g,b) {r,g,b, 0,0,0, 0}
 
 #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
 
+#define MAX_PALETTE    8
+
 #define OkColorHi(n)   (((n) < COLORS) && ((n) < max_colors))
+#define InPalette(n)   ((n) >= 0 && (n) < MAX_PALETTE)
 
 /*
  * Given a RGB range of 0..1000, we'll normally set the individual values
@@ -162,10 +178,10 @@ init_color_table(void)
 
     tp = (hue_lightness_saturation) ? hls_palette : cga_palette;
     for (n = 0; n < COLORS; n++) {
-       if (n < 8) {
+       if (InPalette(n)) {
            SP->_color_table[n] = tp[n];
        } else {
-           SP->_color_table[n] = tp[n % 8];
+           SP->_color_table[n] = tp[n % MAX_PALETTE];
            if (hue_lightness_saturation) {
                SP->_color_table[n].green = 100;
            } else {
@@ -239,8 +255,12 @@ start_color(void)
        }
 
        if (max_pairs > 0 && max_colors > 0) {
-           COLOR_PAIRS = SP->_pair_count = max_pairs;
-           COLORS = SP->_color_count = max_colors;
+           SP->_pair_count = max_pairs;
+           SP->_color_count = max_colors;
+#if !USE_REENTRANT
+           COLOR_PAIRS = max_pairs;
+           COLORS = max_colors;
+#endif
 
            if ((SP->_color_pairs = TYPE_CALLOC(colorpair_t,
                                                max_pairs)) != 0) {
@@ -365,7 +385,7 @@ init_pair(short pair, short f, short b)
     if (GET_SCREEN_PAIR(SP) == pair)
        SET_SCREEN_PAIR(SP, (chtype) (~0));     /* force attribute update */
 
-    if (initialize_pair) {
+    if (initialize_pair && InPalette(f) && InPalette(b)) {
        const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette;
 
        TR(TRACE_ATTRS,
@@ -494,7 +514,7 @@ pair_content(short pair, short *f, short *b)
        if (b)
            *b = bg;
 
-       T(("...pair_content(%d,%d,%d)", pair, fg, bg));
+       TR(TRACE_ATTRS, ("...pair_content(%d,%d,%d)", pair, fg, bg));
        result = OK;
     }
     returnCode(result);