bool Image::is_binary() const { for(int x=0 ; x < m_width ; ++x) for(int y=0 ; y < m_height; ++y) { Color c = color_at(x, y); if(c != Color(0,0,0) && c != Color(1,1,1)) return false; } return true; }
void Image::threshold(double d) { greyscale(); for(int x = 0 ; x != width() ; ++x) for(int y = 0 ; y != height() ; ++y) { Color c = color_at(x, y); plot(x, y, (c.red() >= d && c.blue() >= d && c.green() >= d ? Color(1,1,1) : Color(0,0,0))); } }
graphics::color Gradient::color_at(posn point) const { if (contains(point)) { // Maps the bounding box to the unit square sample x = (point.x - get_bbox().left()) / get_bbox().width(); sample y = (point.y - get_bbox().top()) / get_bbox().height(); return color_at(x, y); } else { return color::transparent; } }
void Image::greyscale() { auto color_to_grey = [] (Color c) -> double { Color cc = gamma_decompress(c); double y = 0.2126*cc.red() + 0.7152*cc.green() + 0.0722*cc.blue(); cc = Color(y,y,y); cc = gamma_compress(c); return cc.red(); }; for(int x = 0 ; x != width() ; ++x) for(int y = 0 ; y != height() ; ++y) { double c = color_to_grey(color_at(x, y)); plot(x, y, Color(c, c, c)); } }
unsigned long colorizator(t_list *list, t_vect3d inter\ , t_env *e) { unsigned long ret; if (list->type == 'a') { ret = color_at(e, inter); } if (list->type == 'b') { ret = color_at_p(e, inter); } if (list->type == 'c') { ret = color_at_c(e, inter); } if (list->type == 'd') { ret = color_at_cone(e, inter); } return (ret); }
// Computes the color at an abstract (unit square) position by // projecting it to 1-D and then delegating to color_at(sample). Drawing::color Gradient::color_at(sample x, sample y) const { return color_at(projector_.project(x, y)); }