Changeset 931 for trunk/lib


Ignore:
Timestamp:
Dec 2, 2009, 1:43:52 PM (14 years ago)
Author:
Peter Johansson
Message:

refs #413 adding support for shorter hexadecimal color format (e.g. 'a0b equivalent to 'aa00bb')

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Colors.cc

    r930 r931  
    7070      color c;
    7171      c.label=i->first;
    72       c.r= 16*to_decimal(i->second[0]) + to_decimal(i->second[1]);
    73       c.g= 16*to_decimal(i->second[2]) + to_decimal(i->second[3]);
    74       c.b= 16*to_decimal(i->second[4]) + to_decimal(i->second[5]);
     72      if (i->second.size()==6) {
     73        c.r= 16*to_decimal(i->second[0]) + to_decimal(i->second[1]);
     74        c.g= 16*to_decimal(i->second[2]) + to_decimal(i->second[3]);
     75        c.b= 16*to_decimal(i->second[4]) + to_decimal(i->second[5]);
     76      }
     77      else if (i->second.size()==3) {
     78        c.r= 16*to_decimal(i->second[0]) + to_decimal(i->second[0]);
     79        c.g= 16*to_decimal(i->second[1]) + to_decimal(i->second[1]);
     80        c.b= 16*to_decimal(i->second[2]) + to_decimal(i->second[2]);
     81      }
     82      else
     83        throw std::runtime_error("invalid color format: " + i->second);
    7584      next_color_=color_map_.insert(next_color_,c);
    7685      author_map_.insert(std::make_pair(c.label, next_color_++));
Note: See TracChangeset for help on using the changeset viewer.