1 /****************************************************************************
2 * Copyright (c) 2018 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: parse_rgb.h,v 1.4 2018/02/03 23:40:53 tom Exp $
31 * Sample implementation of ncurses RGB extension from user_caps(5).
33 #ifndef PARSE_RBG_H_incl
34 #define PARSE_RBG_H_incl 1
36 #include <test.priv.h>
38 #if HAVE_TIGETSTR && USE_WIDEC_SUPPORT
40 parse_rgb(int *r_max, int *g_max, int *b_max)
42 int colors = tigetnum("colors");
45 *r_max = *g_max = *b_max = 0;
51 int r = 0, g = 0, b = 0;
55 for (max_bits = 0, pwr2 = 1;
57 ++max_bits, pwr2 <<= 1) {
61 if (tigetflag("RGB") > 0) {
63 r = g = b = (max_bits + 2) / 3;
64 } else if ((bits = tigetnum("RGB")) > 0) {
67 } else if ((data = tigetstr("RGB")) != ABSENT_STRING
68 && data != CANCELLED_STRING
69 && sscanf(data, "%d/%d/%d%c", &r, &g, &b, &ch) == 3) {
73 if ((r + g + b) < max_bits) {
75 } else if (result == 0) {
81 if (g > (max_bits -= r)) {
86 if (b > (max_bits -= g)) {
95 #define parse_rgb(r,g,b) (ERR)
98 #endif /* PARSE_RBG_H_incl */