source: trunk/packages/vizservers/nanovis/Color.cpp @ 3464

Last change on this file since 3464 was 3177, checked in by mmc, 7 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ----------------------------------------------------------------------
4 * Color.cpp: Color class
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16#include <stdio.h>
17#include <assert.h>
18
19#include "Color.h"
20
21Color::Color() :
22    _r(0),
23    _g(0),
24    _b(0)
25{
26}
27
28Color::Color(double r, double g, double b) :
29    _r(r),
30    _g(g),
31    _b(b)
32{
33}
34
35Color::Color(const Color& c) :
36    _r(c._r),
37    _g(c._g),
38    _b(c._b)
39{
40}
41
42Color::~Color()
43{
44}
45
46Color&
47Color::operator=(const Color& c)
48{
49    _r = c._r;
50    _g = c._g;
51    _b = c._b;
52    return *this;
53}
54
55// Limits the color to be in range of [0,1]
56void Color::clamp()
57{
58    if (_r > 1.0) _r = 1.0;
59    if (_g > 1.0) _g = 1.0;
60    if (_b > 1.0) _b = 1.0;
61
62    if (_r < 0.0) _r = 0.0;
63    if (_g < 0.0) _g = 0.0;
64    if (_b < 0.0) _b = 0.0;
65}
66
67Color Color::operator*(double k) const
68{
69    return Color(_r * k, _g * k, _b * k);
70}
71
72Color Color::operator*(const Color& other) const
73{
74    return Color(_r * other._r, _g * other._g, _b * other._b);
75}
76
77Color Color::operator+(const Color& other) const
78{
79    return Color(_r + other._r, _g + other._g, _b + other._b);
80}
81
82void Color::getRGB(unsigned char *result)
83{
84    result[0] = (unsigned char)(_r*255.0);
85    result[1] = (unsigned char)(_g*255.0);
86    result[2] = (unsigned char)(_b*255.0);
87}
88
89void Color::getRGB(float *result)
90{
91    result[0] = (float)_r;
92    result[1] = (float)_g;
93    result[2] = (float)_b;
94}
Note: See TracBrowser for help on using the repository browser.