/usr/share/doc/xviewg/examples/color/example4.c is in xview-examples 3.2p1.4-28.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | /*
* xv_colors.c
* This simple application demonstates the use of the XView color
* API. The colormap segment can be created in a combination of the
* following ways:
* - static or dynamic
* - control or non-control
* - using named colors or RGB values
*/
#include <stdio.h>
#include <xview/xview.h>
#include <xview/canvas.h>
#include <xview/cms.h>
#include <X11/Xlib.h>
#include <xview/xv_xrect.h>
#define CHIP_WIDTH 50
#define CHIP_HEIGHT 50
/* color definitions */
#define GRAY 0
#define YELLOW 1
#define PINK 2
#define VIOLET 3
#define RED 4
#define GREEN 5
#define BLACK 6
#define BLUE 7
#define NUM_COLORS 8
unsigned long *index_table;
unsigned long cms_size;
main(argc, argv)
int argc;
char **argv;
{
Frame frame;
Canvas canvas;
Cms cms;
short dynamic_colors = FALSE;
short control_cms = FALSE;
short named_colors = FALSE;
short print_colors = FALSE;
int i;
Xv_Singlecolor *cms_colors;
XColor *cms_x_colors;
Xv_Singlecolor colors[NUM_COLORS];
void canvas_repaint_proc();
while (--argc) {
switch (**(++argv)) {
case 'c':
case 'C':
control_cms = TRUE;
printf("Control cms set \n");
break;
case 'd':
case 'D':
dynamic_colors = TRUE;
printf("Dynamic color set \n");
break;
case 'n':
case 'N':
named_colors = TRUE;
printf("Named colors set \n");
break;
case 'p':
case 'P':
print_colors = TRUE;
printf("Print colors set \n");
break;
default:
break;
}
}
printf("\n");
xv_init(XV_INIT_ARGS, argc, argv, 0);
frame = xv_create(0, FRAME,
XV_LABEL, "XView Colors",
0);
/* create the colormap segment based on flags */
cms = xv_create(0, CMS,
CMS_TYPE,
(dynamic_colors == TRUE) ? XV_DYNAMIC_CMS : XV_STATIC_CMS,
CMS_CONTROL_CMS, control_cms,
CMS_SIZE,
control_cms ? NUM_COLORS + CMS_CONTROL_COLORS : NUM_COLORS,
NULL);
if (named_colors == TRUE) {
xv_set(cms,
CMS_NAMED_COLORS,
"gray",
"yellow",
"pink",
"violet",
"red",
"green",
"black",
"blue",
NULL,
NULL);
} else {
initialize_colors(colors);
xv_set(cms, CMS_COLORS, colors, NULL);
}
/*
* the frame height is adjusted based on the number of colors
* to be displayed
*/
cms_size = (unsigned long)xv_get(cms, CMS_SIZE);
printf("Cms size = %d\n", (int)cms_size);
xv_set(frame,
WIN_WIDTH, CHIP_WIDTH * 3,
WIN_HEIGHT, (cms_size + 2) * CHIP_HEIGHT,
0);
/* conversion table for pixel values from XView to X11 */
index_table = (unsigned long *)xv_get(cms, CMS_INDEX_TABLE);
if (print_colors == TRUE) {
/*
* Colormap segment RGB values can be set or retreived either as
* an array of Xv_Singlecolor or XColor.
*/
cms_colors = (Xv_Singlecolor *)malloc(cms_size * sizeof(Xv_Singlecolor));
cms_colors = (Xv_Singlecolor *)xv_get(cms, CMS_COLORS, cms_colors);
printf("Cms colors: \n");
for(i = 0; i <= cms_size - 1; i++)
printf("%d %d %d \n", (int)(cms_colors + i)->red,
(int)(cms_colors + i)->green,
(int)(cms_colors + i)->blue);
free(cms_colors);
printf("\n");
cms_x_colors = (XColor *)malloc(cms_size * sizeof(XColor));
cms_x_colors = (XColor *)xv_get(cms, CMS_X_COLORS, cms_x_colors);
printf("Cms XColors: \n");
for(i = 0; i <= cms_size - 1; i++)
printf("%d %d %d \n", (int)(cms_x_colors + i)->red,
(int)(cms_x_colors + i)->green,
(int)(cms_x_colors + i)->blue);
free(cms_x_colors);
printf("\n");
}
canvas = xv_create(frame, CANVAS,
/* WIN_DYNAMIC_VISUAL, dynamic_colors, */
XV_VISUAL_CLASS, PseudoColor,
CANVAS_REPAINT_PROC, canvas_repaint_proc,
CANVAS_X_PAINT_WINDOW, TRUE,
WIN_CMS, cms,
0);
window_fit(frame);
xv_main_loop(frame);
return(0);
}
/*
* canvas_repaint_proc()
* Draws onto the canvas using Xlib drawing functions.
*/
void
canvas_repaint_proc(canvas, pw, display, xid, xrects)
Canvas canvas;
Xv_Window pw;
Display *display;
Window xid;
Xv_xrectlist *xrects;
{
static GC gc = NULL;
XGCValues gcvalues;
int gcvaluemask;
register int i;
if (gc == NULL) {
/* setup gc for rendering colors */
gcvalues.function = GXcopy;
gcvalues.fill_style = FillSolid;
gcvaluemask = GCFunction | GCFillStyle;
gc = XCreateGC(display, xid, gcvaluemask, &gcvalues);
if(gc == NULL) {
fprintf(stderr, "XCreateGC failed ... exiting... \n");
exit(1);
}
}
for (i = 0; i <= cms_size - 1; i++) {
XSetForeground(display, gc, index_table[i]);
XFillRectangle(display, xid, gc, CHIP_WIDTH,
CHIP_HEIGHT * (i + 1), CHIP_WIDTH, CHIP_HEIGHT);
}
}
initialize_colors(colors)
Xv_Singlecolor *colors;
{
colors[GRAY].red = 220;
colors[GRAY].green = 220;
colors[GRAY].blue = 220;
colors[YELLOW].red = 255;
colors[YELLOW].green = 255;
colors[YELLOW].blue = 0;
colors[PINK].red = 188;
colors[PINK].green = 143;
colors[PINK].blue = 143;
colors[VIOLET].red = 159;
colors[VIOLET].green = 95;
colors[VIOLET].blue = 159;
colors[RED].red = 255;
colors[RED].green = 0;
colors[RED].blue = 0;
colors[GREEN].red = 0;
colors[GREEN].green = 255;
colors[GREEN].blue = 0;
colors[BLACK].red = 0;
colors[BLACK].green = 0;
colors[BLACK].blue = 0;
colors[BLUE].red = 0;
colors[BLUE].green = 0;
colors[BLUE].blue = 255;
}
|