summaryrefslogtreecommitdiffstats
path: root/dev/MinGfx/src/color.cc
diff options
context:
space:
mode:
authorunknown <paulx161@umn.edu>2021-02-03 14:22:28 -0600
committerunknown <paulx161@umn.edu>2021-02-03 14:22:28 -0600
commit9b83919815f6a6ce5d73da1c28483970d0ca5589 (patch)
tree4558864445dccc1605e5315e0bb11c46d2018da1 /dev/MinGfx/src/color.cc
parentAdded worksheet and support code for assignment 2 (diff)
downloadcsci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar
csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.gz
csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.bz2
csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.lz
csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.xz
csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.zst
csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.zip
added dev/MinGfx/
Diffstat (limited to '')
-rw-r--r--dev/MinGfx/src/color.cc130
1 files changed, 130 insertions, 0 deletions
diff --git a/dev/MinGfx/src/color.cc b/dev/MinGfx/src/color.cc
new file mode 100644
index 0000000..cc5db87
--- /dev/null
+++ b/dev/MinGfx/src/color.cc
@@ -0,0 +1,130 @@
+/*
+ Copyright (c) 2017,2018 Regents of the University of Minnesota.
+ All Rights Reserved.
+ See corresponding header file for details.
+ */
+
+#include "color.h"
+
+#include <math.h>
+
+namespace mingfx {
+
+Color::Color() {
+ c[0] = 0.0;
+ c[1] = 0.0;
+ c[2] = 0.0;
+ c[3] = 1.0;
+}
+
+Color::Color(float red, float green, float blue, float alpha) {
+ c[0] = red;
+ c[1] = green;
+ c[2] = blue;
+ c[3] = alpha;
+}
+
+Color::Color(float *ptr) {
+ c[0] = ptr[0];
+ c[1] = ptr[1];
+ c[2] = ptr[2];
+ c[3] = ptr[3];
+}
+
+Color::Color(const Color& other) {
+ c[0] = other[0];
+ c[1] = other[1];
+ c[2] = other[2];
+ c[3] = other[3];
+}
+
+Color::Color(const std::vector<float> &vals) {
+ c[0] = vals[0];
+ c[1] = vals[1];
+ c[2] = vals[2];
+ if (vals.size() > 3) {
+ c[3] = vals[3];
+ }
+ else {
+ c[3] = 1.0;
+ }
+}
+
+
+Color::~Color() {
+}
+
+bool Color::operator==(const Color& other) const {
+ return ((other[0] == c[0]) &&
+ (other[1] == c[1]) &&
+ (other[2] == c[2]) &&
+ (other[3] == c[3]));
+}
+
+bool Color::operator!=(const Color& other) const {
+ return ((other[0] != c[0]) ||
+ (other[1] != c[1]) ||
+ (other[2] != c[2]) ||
+ (other[3] != c[3]));
+}
+
+Color& Color::operator=(const Color& other) {
+ c[0] = other[0];
+ c[1] = other[1];
+ c[2] = other[2];
+ c[3] = other[3];
+ return *this;
+}
+
+float Color::operator[](const int i) const {
+ return c[i];
+}
+
+float& Color::operator[](const int i) {
+ return c[i];
+}
+
+
+const float * Color::value_ptr() const {
+ return c;
+}
+
+std::vector<float> Color::ToVector() const {
+ std::vector<float> v;
+ v.push_back(c[0]);
+ v.push_back(c[1]);
+ v.push_back(c[2]);
+ v.push_back(c[3]);
+ return v;
+}
+
+
+Color Color::Lerp(const Color &b, float alpha) const {
+ float red = (1.0f-alpha)*(*this)[0] + alpha*b[0];
+ float grn = (1.0f-alpha)*(*this)[1] + alpha*b[1];
+ float blu = (1.0f-alpha)*(*this)[2] + alpha*b[2];
+ float alp = (1.0f-alpha)*(*this)[3] + alpha*b[3];
+ return Color(red,grn,blu,alp);
+}
+
+Color Color::Lerp(const Color &a, const Color &b, float alpha) {
+ float red = (1.0f-alpha)*a[0] + alpha*b[0];
+ float grn = (1.0f-alpha)*a[1] + alpha*b[1];
+ float blu = (1.0f-alpha)*a[2] + alpha*b[2];
+ float alp = (1.0f-alpha)*a[3] + alpha*b[3];
+ return Color(red,grn,blu,alp);
+}
+
+
+std::ostream & operator<< ( std::ostream &os, const Color &c) {
+ return os << "(" << c[0] << ", " << c[1] << ", " << c[2] << ", " << c[3] << ")";
+}
+
+std::istream & operator>> ( std::istream &is, Color &c) {
+ // format: (r, g, b, a)
+ char dummy;
+ return is >> dummy >> c[0] >> dummy >> c[1] >> dummy >> c[2] >> dummy >> c[3] >> dummy;
+}
+
+
+} // end namespace