Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

colors.cc

Go to the documentation of this file.
00001 #include "Vision/colors.h"
00002 #include <cstdio>
00003 
00004 //! displays an rgb value in the form '[r,g,b]'
00005 std::ostream& operator<<(std::ostream &os, const rgb &rgbval) {
00006   os << "[" << (unsigned int)rgbval.red
00007      << "," << (unsigned int)rgbval.green
00008      << "," << (unsigned int)rgbval.blue
00009      << "]";
00010   return os;
00011 }
00012 
00013 //! returns @a rgbval in the string form 'r g b'
00014 std::string toString(const rgb &rgbval) {
00015   char buff[15];
00016   snprintf(buff,15,"%d %d %d",rgbval.red,rgbval.green,rgbval.blue);
00017   return buff;
00018 }
00019 
00020 
00021 //! displays a yuv value in the form '[y,u,v]'
00022 std::ostream& operator<<(std::ostream &os, const yuv &yuvval) {
00023   os << "yuv[" << (unsigned int)yuvval.y
00024      << "," << (unsigned int)yuvval.u
00025      << "," << (unsigned int)yuvval.v
00026      << "]";
00027   return os;
00028 }
00029 
00030 //! returns @a yuvval in the string form 'y u v'
00031 std::string toString(const yuv &yuvval) {
00032   char buff[15];
00033   snprintf(buff,15,"%d %d %d",yuvval.y,yuvval.u,yuvval.v);
00034   return buff;
00035 }
00036 
00037 //! converts rgb to yuv
00038 yuv rgb2yuv(const rgb x) {
00039   int yval = int((8.0 * x.red / 27.0) + (16.0 * x.green / 27.0) + (x.blue / 9.0));
00040   int uval = int(128.0 - (4.0 * x.red / 27.0) - (8.0 * x.green / 27.0) + (4.0 * x.blue / 9.0));
00041   int vval = int((19.0 * x.red / 27.0) - (16.0 * x.green / 27.0) - (x.blue / 9.0) + 128.0);
00042 
00043   if (yval > 255) yval = 255;
00044   if (yval < 0) yval = 0;
00045   else if (uval > 255) uval = 255;
00046   if (vval < 0) vval = 0;
00047   else if (vval > 255) vval = 255;
00048 
00049   return yuv(yval, uval, vval);
00050 }

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:37 2016 by Doxygen 1.6.3