1 /* Copyright (C) 2000-2002 Damir Zucic */
2 
3 /*=============================================================================
4 
5 				weight_colors.c
6 
7 Purpose:
8 	Weight two colors to prepare the third color.
9 
10 Input:
11 	(1) The first color identifier.
12 	(2) The second color identifier.
13 	(3) Scale factor (double), which weights the second color.
14 	(4) Pointer to GUIS structure.
15 
16 Output:
17 	Return value.
18 
19 Return value:
20 	The identifier of the prepared (new) color.
21 
22 =============================================================================*/
23 
24 #include <stdio.h>
25 
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/Xos.h>
29 #include <X11/Xatom.h>
30 
31 #include "defines.h"
32 #include "typedefs.h"
33 
34 /*======weight two colors:===================================================*/
35 
WeightColors_(unsigned long color1ID,unsigned long color2ID,double scale_factor,GUIS * guiSP)36 unsigned long WeightColors_ (unsigned long color1ID, unsigned long color2ID,
37 			     double scale_factor, GUIS *guiSP)
38 {
39 static unsigned long	new_colorID;
40 static unsigned long	red_mask, green_mask, blue_mask;
41 static unsigned long	red1, red2, green1, green2, blue1, blue2;
42 static long double	r1, r2, g1, g2, b1, b2;
43 static long double	r, g, b;
44 static unsigned long	red, green, blue;
45 
46 /* Copy masks: */
47 red_mask   = guiSP->visual_infoS.red_mask;
48 green_mask = guiSP->visual_infoS.green_mask;
49 blue_mask  = guiSP->visual_infoS.blue_mask;
50 
51 /* Extract input color components: */
52 red1   = color1ID & red_mask;
53 red2   = color2ID & red_mask;
54 green1 = color1ID & green_mask;
55 green2 = color2ID & green_mask;
56 blue1  = color1ID & blue_mask;
57 blue2  = color2ID & blue_mask;
58 
59 /* Convert to doubles: */
60 r1 = (long double) red1;
61 r2 = (long double) red2;
62 g1 = (long double) green1;
63 g2 = (long double) green2;
64 b1 = (long double) blue1;
65 b2 = (long double) blue2;
66 
67 /* Calculate new color components: */
68 r = r1 + scale_factor * (r2 - r1);
69 g = g1 + scale_factor * (g2 - g1);
70 b = b1 + scale_factor * (b2 - b1);
71 red   = ((unsigned long) r) & red_mask;
72 green = ((unsigned long) g) & green_mask;
73 blue  = ((unsigned long) b) & blue_mask;
74 
75 /* Combine new color components: */
76 new_colorID = red | green | blue;
77 
78 /* Return the identifier of the prepared color: */
79 return new_colorID;
80 }
81 
82 /*===========================================================================*/
83 
84 
85