bool operator<(const color_range& b) const { if(mid_ != b.mid()) return(mid_ < b.mid()); if(max_ != b.max()) return(max_ < b.max()); if(min_ != b.min()) return(min_ < b.min()); return(rep_ < b.rep()); }
color_range_map recolor_range(const color_range& new_range, const std::vector<color_t>& old_rgb) { color_range_map map_rgb; const uint16_t new_red = new_range.mid().r; const uint16_t new_green = new_range.mid().g; const uint16_t new_blue = new_range.mid().b; const uint16_t max_red = new_range.max().r; const uint16_t max_green = new_range.max().g; const uint16_t max_blue = new_range.max().b; const uint16_t min_red = new_range.min().r; const uint16_t min_green = new_range.min().g; const uint16_t min_blue = new_range.min().b; // Map first color in vector to exact new color const color_t temp_rgb = old_rgb.empty() ? color_t() : old_rgb[0]; const uint16_t reference_avg = (temp_rgb.r + temp_rgb.g + temp_rgb.b) / 3; for(const auto& old_c : old_rgb) { const uint16_t old_avg = (old_c.r + old_c.g + old_c.b) / 3; // Calculate new color uint32_t new_r = 0, new_g = 0, new_b = 0; if(reference_avg && old_avg <= reference_avg) { float old_ratio = static_cast<float>(old_avg) / reference_avg; new_r = static_cast<uint32_t>(old_ratio * new_red + (1 - old_ratio) * min_red); new_g = static_cast<uint32_t>(old_ratio * new_green + (1 - old_ratio) * min_green); new_b = static_cast<uint32_t>(old_ratio * new_blue + (1 - old_ratio) * min_blue); } else if(reference_avg != 255) { float old_ratio = (255.0f - static_cast<float>(old_avg)) / (255.0f - reference_avg); new_r = static_cast<uint32_t>(old_ratio * new_red + (1 - old_ratio) * max_red); new_g = static_cast<uint32_t>(old_ratio * new_green + (1 - old_ratio) * max_green); new_b = static_cast<uint32_t>(old_ratio * new_blue + (1 - old_ratio) * max_blue); } else { // Should never get here. // Would imply old_avg > reference_avg = 255 assert(false); } new_r = std::min<uint32_t>(new_r, 255); new_g = std::min<uint32_t>(new_g, 255); new_b = std::min<uint32_t>(new_b, 255); map_rgb[old_c] = {static_cast<uint8_t>(new_r), static_cast<uint8_t>(new_g), static_cast<uint8_t>(new_b)}; } return map_rgb; }
void CustomPalettes::addRangesMenuEntry(QMenu* menu, const QString& id, const color_range& range, const QString& text) { // TODO: unique keyboard accel for each entry? QAction* const act = menu->addAction(text); act->setData(id); act->setIcon(createColorIcon(range.mid())); connect(act, SIGNAL(triggered()), this, SLOT(handleRcOption())); }
bool operator==(const color_range& b) const { return(mid_ == b.mid() && max_ == b.max() && min_ == b.min() && rep_ == b.rep()); }