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

« back to all changes in this revision

Viewing changes to weight_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
                                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).
 
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
 
 
36
unsigned long WeightColors_ (unsigned long color1ID, unsigned long color2ID,
 
37
                             double scale_factor, GUIS *guiSP)
 
38
{
 
39
unsigned long           new_colorID;
 
40
unsigned long           red_mask, green_mask, blue_mask;
 
41
unsigned long           red1, red2, green1, green2, blue1, blue2;
 
42
double                  r1, r2, g1, g2, b1, b2;
 
43
double                  r, g, b;
 
44
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 = (double) red1;
 
61
r2 = (double) red2;
 
62
g1 = (double) green1;
 
63
g2 = (double) green2;
 
64
b1 = (double) blue1;
 
65
b2 = (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