~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to add_three_colors.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                add_three_colors.c
 
6
 
 
7
Purpose:
 
8
        Add (interpolate) three additional colors.
 
9
 
 
10
Input:
 
11
        (1) The first input color.
 
12
        (2) The second input color.
 
13
        (3) Pointer to GUIS structure.
 
14
        (4) Pointer to the first output color.
 
15
        (5) Pointer to the second output color.
 
16
        (6) Pointer to the third output color.
 
17
 
 
18
Output:
 
19
        (1) The first output color prepared.
 
20
        (2) The second output color prepared.
 
21
        (3) The third output color prepared.
 
22
 
 
23
Return value:
 
24
        No return value.
 
25
 
 
26
=============================================================================*/
 
27
 
 
28
#include <stdio.h>
 
29
 
 
30
#include <X11/Xlib.h>
 
31
#include <X11/Xutil.h>
 
32
#include <X11/Xos.h>
 
33
#include <X11/Xatom.h>
 
34
 
 
35
#include "defines.h"
 
36
#include "typedefs.h"
 
37
 
 
38
/*======add (interpolate) three colors:======================================*/
 
39
 
 
40
void AddThreeColors_ (unsigned long input_color1ID,
 
41
                      unsigned long input_color2ID,
 
42
                      GUIS *guiSP,
 
43
                      unsigned long *output_color1IDP,
 
44
                      unsigned long *output_color2IDP,
 
45
                      unsigned long *output_color3IDP)
 
46
{
 
47
unsigned long           red_mask, green_mask, blue_mask;
 
48
unsigned long           red1, red2, red;
 
49
unsigned long           green1, green2, green;
 
50
unsigned long           blue1, blue2, blue;
 
51
double                  r1, r2, g1, g2, b1, b2;
 
52
static double           w1 = 0.75, w2 = 0.25, w3 = 0.50;
 
53
double                  r, g, b;
 
54
 
 
55
/* Copy masks: */
 
56
red_mask   = guiSP->visual_infoS.red_mask;
 
57
green_mask = guiSP->visual_infoS.green_mask;
 
58
blue_mask  = guiSP->visual_infoS.blue_mask;
 
59
 
 
60
/* Extract input color components: */
 
61
red1   = input_color1ID & red_mask;
 
62
red2   = input_color2ID & red_mask;
 
63
green1 = input_color1ID & green_mask;
 
64
green2 = input_color2ID & green_mask;
 
65
blue1  = input_color1ID & blue_mask;
 
66
blue2  = input_color2ID & blue_mask;
 
67
 
 
68
/* Convert to doubles: */
 
69
r1 = (double) red1;
 
70
r2 = (double) red2;
 
71
g1 = (double) green1;
 
72
g2 = (double) green2;
 
73
b1 = (double) blue1;
 
74
b2 = (double) blue2;
 
75
 
 
76
/* The first output color (components): */
 
77
r = w1 * r1 + w2 * r2;
 
78
g = w1 * g1 + w2 * g2;
 
79
b = w1 * b1 + w2 * b2;
 
80
red   = ((unsigned long) r) & red_mask;
 
81
green = ((unsigned long) g) & green_mask;
 
82
blue  = ((unsigned long) b) & blue_mask;
 
83
 
 
84
/* The first output color (value): */
 
85
*output_color1IDP = red | green | blue;
 
86
 
 
87
/* The second output color (components): */
 
88
r = w3 * (r1 + r2);
 
89
g = w3 * (g1 + g2);
 
90
b = w3 * (b1 + b2);
 
91
red   = ((unsigned long) r) & red_mask;
 
92
green = ((unsigned long) g) & green_mask;
 
93
blue  = ((unsigned long) b) & blue_mask;
 
94
 
 
95
/* The second output color (value): */
 
96
*output_color2IDP = red | green | blue;
 
97
 
 
98
/* The third output color (components): */
 
99
r = w2 * r1 + w1 * r2;
 
100
g = w2 * g1 + w1 * g2;
 
101
b = w2 * b1 + w1 * b2;
 
102
red   = ((unsigned long) r) & red_mask;
 
103
green = ((unsigned long) g) & green_mask;
 
104
blue  = ((unsigned long) b) & blue_mask;
 
105
 
 
106
/* The third output color (value): */
 
107
*output_color3IDP = red | green | blue;
 
108
 
 
109
}
 
110
 
 
111
/*===========================================================================*/
 
112
 
 
113