File: add_three_colors.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (113 lines) | stat: -rw-r--r-- 2,965 bytes parent folder | download | duplicates (6)
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
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				add_three_colors.c

Purpose:
	Add (interpolate) three additional colors.

Input:
	(1) The first input color.
	(2) The second input color.
	(3) Pointer to GUIS structure.
	(4) Pointer to the first output color.
	(5) Pointer to the second output color.
	(6) Pointer to the third output color.

Output:
	(1) The first output color prepared.
	(2) The second output color prepared.
	(3) The third output color prepared.

Return value:
	No return value.

=============================================================================*/

#include <stdio.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======add (interpolate) three colors:======================================*/

void AddThreeColors_ (unsigned long input_color1ID,
		      unsigned long input_color2ID,
		      GUIS *guiSP,
		      unsigned long *output_color1IDP,
		      unsigned long *output_color2IDP,
		      unsigned long *output_color3IDP)
{
unsigned long		red_mask, green_mask, blue_mask;
unsigned long		red1, red2, red;
unsigned long		green1, green2, green;
unsigned long		blue1, blue2, blue;
double			r1, r2, g1, g2, b1, b2;
static double		w1 = 0.75, w2 = 0.25, w3 = 0.50;
double			r, g, b;

/* Copy masks: */
red_mask   = guiSP->visual_infoS.red_mask;
green_mask = guiSP->visual_infoS.green_mask;
blue_mask  = guiSP->visual_infoS.blue_mask;

/* Extract input color components: */
red1   = input_color1ID & red_mask;
red2   = input_color2ID & red_mask;
green1 = input_color1ID & green_mask;
green2 = input_color2ID & green_mask;
blue1  = input_color1ID & blue_mask;
blue2  = input_color2ID & blue_mask;

/* Convert to doubles: */
r1 = (double) red1;
r2 = (double) red2;
g1 = (double) green1;
g2 = (double) green2;
b1 = (double) blue1;
b2 = (double) blue2;

/* The first output color (components): */
r = w1 * r1 + w2 * r2;
g = w1 * g1 + w2 * g2;
b = w1 * b1 + w2 * b2;
red   = ((unsigned long) r) & red_mask;
green = ((unsigned long) g) & green_mask;
blue  = ((unsigned long) b) & blue_mask;

/* The first output color (value): */
*output_color1IDP = red | green | blue;

/* The second output color (components): */
r = w3 * (r1 + r2);
g = w3 * (g1 + g2);
b = w3 * (b1 + b2);
red   = ((unsigned long) r) & red_mask;
green = ((unsigned long) g) & green_mask;
blue  = ((unsigned long) b) & blue_mask;

/* The second output color (value): */
*output_color2IDP = red | green | blue;

/* The third output color (components): */
r = w2 * r1 + w1 * r2;
g = w2 * g1 + w1 * g2;
b = w2 * b1 + w1 * b2;
red   = ((unsigned long) r) & red_mask;
green = ((unsigned long) g) & green_mask;
blue  = ((unsigned long) b) & blue_mask;

/* The third output color (value): */
*output_color3IDP = red | green | blue;

}

/*===========================================================================*/