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

« back to all changes in this revision

Viewing changes to interpolate_color.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
                                interpolate_color.c
 
6
 
 
7
Purpose:
 
8
        Interpolate (calculate) additional color, using two old colors.
 
9
 
 
10
Input:
 
11
        (1) The first input color.
 
12
        (2) The second input color.
 
13
        (3) Pointer to GUIS structure.
 
14
 
 
15
Output:
 
16
        (1) Return value.
 
17
 
 
18
Return value:
 
19
        The pixel value calculated.
 
20
 
 
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
/*======interpolate color:===================================================*/
 
35
 
 
36
unsigned long InterpolateColor_ (unsigned long color1ID,
 
37
                                 unsigned long color2ID,
 
38
                                 GUIS *guiSP)
 
39
{
 
40
unsigned long           colorID;
 
41
unsigned long           red_mask, green_mask, blue_mask;
 
42
unsigned long           red1, red2, red;
 
43
unsigned long           green1, green2, green;
 
44
unsigned long           blue1, blue2, blue;
 
45
double                  r1, r2, g1, g2, b1, b2;
 
46
double                  w = 0.5;
 
47
double                  r, g, b;
 
48
 
 
49
/* Copy masks: */
 
50
red_mask   = guiSP->visual_infoS.red_mask;
 
51
green_mask = guiSP->visual_infoS.green_mask;
 
52
blue_mask  = guiSP->visual_infoS.blue_mask;
 
53
 
 
54
/* Extract input color components: */
 
55
red1   = color1ID & red_mask;
 
56
red2   = color2ID & red_mask;
 
57
green1 = color1ID & green_mask;
 
58
green2 = color2ID & green_mask;
 
59
blue1  = color1ID & blue_mask;
 
60
blue2  = color2ID & blue_mask;
 
61
 
 
62
/* Convert to doubles: */
 
63
r1 = (double) red1;
 
64
r2 = (double) red2;
 
65
g1 = (double) green1;
 
66
g2 = (double) green2;
 
67
b1 = (double) blue1;
 
68
b2 = (double) blue2;
 
69
 
 
70
/* Calculate new color components: */
 
71
r = w * (r1 + r2);
 
72
g = w * (g1 + g2);
 
73
b = w * (b1 + b2);
 
74
red   = ((unsigned long) r) & red_mask;
 
75
green = ((unsigned long) g) & green_mask;
 
76
blue  = ((unsigned long) b) & blue_mask;
 
77
 
 
78
/* Combine new color components: */
 
79
colorID = red | green | blue;
 
80
 
 
81
/* Return the pixel value: */
 
82
return colorID;
 
83
}
 
84
 
 
85
/*===========================================================================*/
 
86
 
 
87