void isometric_engine::render_torchblock( image_operations_ptr o, int bt, pos_t px, pos_t py, color top, color side ) { o->add_pixel(px, py, top); o->add_pixel(px - 1, py, top); top.lighten(0x20); top.a -= 0xb0; o->add_pixel(px, py + 1, top); o->add_pixel(px - 1, py + 1, top); o->add_pixel(px - 1, py + 1, side); o->add_pixel(px - 1, py + 2, side); side.lighten(0x20); o->add_pixel(px, py + 1, side); o->add_pixel(px, py + 2, side); o->add_pixel(px - 2, py, top); o->add_pixel(px + 1, py, top); o->add_pixel(px, py - 1, top); o->add_pixel(px - 1, py - 1, top); }
static color foo(color color, signed char degree) { if (degree < 0) return color.blend(color::black(-degree)); else return color.blend(color::white(+degree)); }
inline std::vector<std::string> getColorInfo(const color & col, const color & otherColor, bool getHeader = false, bool ansi = false){ if(getHeader){ return std::vector<std::string>{"hexStr", "hue", "sat", "lum", "alpha", "r;g;b", "r", "g", "b", "lastDiff", "closestAnsi"}; }else{ //"hexStr", "hue", "sat", "lum", "r;g;b", "lastDiff" ,"closestWord", "closestAnsi" auto closeAnsi = getClosetAnsiColor(col); if(ansi){ return std::vector<std::string>{estd::to_string(col.hexStr_), estd::to_string(col.hue_), estd::to_string(col.lSat_), estd::to_string(col.lum_), estd::to_string(col.alpha_), col.getRGBStr(), estd::to_string(std::round(col.red_ * 255)), estd::to_string(std::round(col.green_ * 255)), estd::to_string(std::round(col.blue_ * 255)), estd::to_string(otherColor.getHSLDistance(col)), bib::bashCT::addBGColor(closeAnsi.first) + estd::to_string(closeAnsi.first) + bib::bashCT::reset }; }else{ return std::vector<std::string>{estd::to_string(col.hexStr_), estd::to_string(col.hue_), estd::to_string(col.lSat_), estd::to_string(col.lum_), estd::to_string(col.alpha_), col.getRGBStr(), estd::to_string(std::round(col.red_ * 255)), estd::to_string(std::round(col.green_ *255)), estd::to_string(std::round(col.blue_ *255)), estd::to_string(otherColor.getHSLDistance(col)), estd::to_string(closeAnsi.first) }; } } }
inline bool operator==(color const& rhs) const { return (red_== rhs.red()) && (green_ == rhs.green()) && (blue_ == rhs.blue()) && (alpha_ == rhs.alpha()); }
bool color_factory::parse_from_string(color & c, std::string const& css_color, mapnik::css_color_grammar<std::string::const_iterator> const& g) { std::string::const_iterator first = css_color.begin(); std::string::const_iterator last = css_color.end(); // boost 1.41 -> 1.44 compatibility, to be removed in mapnik 2.1 (dane) #if BOOST_VERSION >= 104500 bool result = boost::spirit::qi::phrase_parse(first, last, g, boost::spirit::ascii::space, c); return result && (first == last); #else mapnik::css css_; bool result = boost::spirit::qi::phrase_parse(first, last, g, boost::spirit::ascii::space, css_); if (result && (first == last)) { c.set_red(css_.r); c.set_green(css_.g); c.set_blue(css_.b); c.set_alpha(css_.a); return true; } return false; #endif }
color overlay(const color& fg, const color& bg) noexcept { if (opaque(fg) || transparent(bg)) return fg; if (transparent(fg)) return bg; return interpolate(bg, fg.alpha(), color{fg.red(), fg.green(), fg.blue()}); }
void dx11render::renderLine(const point& begin, const point& end, const color& col) { if( m_device == NULL ) return; UINT viewportNumber = 1; D3D11_VIEWPORT vp; m_deviceContext->RSGetViewports( &viewportNumber, &vp ); float xx0 = 2.0f * ( begin.getX() - 0.5f ) / vp.Width - 1.0f; float yy0 = 1.0f - 2.0f * ( begin.getY() - 0.5f ) / vp.Height; float xx1 = 2.0f * ( end.getX() - 0.5f ) / vp.Width - 1.0f; float yy1 = 1.0f - 2.0f * ( end.getY() - 0.5f ) / vp.Height; COLOR_VERTEX* v = NULL; D3D11_MAPPED_SUBRESOURCE mapData; if( FAILED( m_deviceContext->Map( m_pVertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &mapData ) ) ) return; v = ( COLOR_VERTEX* ) mapData.pData; v[0].Position.x = xx0; v[0].Position.y = yy0; v[0].Position.z = 0; v[0].Color = col.toD3DXCOLOR(); v[1].Position.x = xx1; v[1].Position.y = yy1; v[1].Position.z = 0; v[1].Color = col.toD3DXCOLOR(); m_deviceContext->Unmap( m_pVertexBuffer, NULL ); m_deviceContext->IASetInputLayout( m_pInputLayout ); UINT Stride = sizeof( COLOR_VERTEX ); UINT Offset = 0; m_deviceContext->IASetVertexBuffers( 0, 1, &m_pVertexBuffer, &Stride, &Offset ); m_deviceContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP ); D3DX11_TECHNIQUE_DESC techDesc; if( FAILED( m_pTechnique->GetDesc( &techDesc ) ) ) { return; } for( UINT p = 0; p < techDesc.Passes; ++p ) { m_pTechnique->GetPassByIndex( p )->Apply( 0, m_deviceContext ); m_deviceContext->Draw( 2, 0 ); } }
void CDX9Renderer::Line(point p1, point p2, const color& c1, const color& c2) { // No support for textured lines SetTexture(NULL); BeginBatch(batch_lines); CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back()); AddVertex(c1.getD3DCOLOR(), p1, 0.0f, 0.0f); AddVertex(c2.getD3DCOLOR(), p2, 1.0f, 1.0f); draw_op->vertex_count += 2; }
void CDX9Renderer::Box(const rect& r, cr_float angle, point hotspot, const color& c) { // No support for textured lines SetTexture(NULL); quad q((r - hotspot).rotate_to_quad(angle, r.topleft())); BeginBatch(batch_linestrip); CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back()); D3DCOLOR color = c.getD3DCOLOR(); // 4 vertices and use 5th index to repeat first vertex closing the strip as a box AddVertex(color, q.tl, 0.0f, 0.0f); AddVertex(color, q.tr, 0.0f, 0.0f); AddVertex(color, q.br, 0.0f, 0.0f); AddVertex(color, q.bl, 0.0f, 0.0f); unsigned short index = draw_op->vertex_count; AddIndex(index); AddIndex(index + 1); AddIndex(index + 2); AddIndex(index + 3); AddIndex(index); draw_op->vertex_count += 4; draw_op->index_count += 5; }
void CDX9Renderer::Box(const rect& r, const color& c) { // No support for textured lines SetTexture(NULL); BeginBatch(batch_linestrip); CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back()); D3DCOLOR color = c.getD3DCOLOR(); // 4 vertices and use 5th index to repeat first vertex closing the strip as a box AddVertex(color, r.topleft(), 0.0f, 0.0f); AddVertex(color, r.topright(), 0.0f, 0.0f); AddVertex(color, r.bottomright(), 0.0f, 0.0f); AddVertex(color, r.bottomleft(), 0.0f, 0.0f); unsigned short index = draw_op->vertex_count; AddIndex(index); AddIndex(index + 1); AddIndex(index + 2); AddIndex(index + 3); AddIndex(index); draw_op->vertex_count += 4; draw_op->index_count += 5; }
rect_output_attributes(const int x, const int y, const unsigned width, const unsigned height, color const& fill_color) : x_(x), y_(y), width_(width), height_(height), fill_color_(fill_color.to_hex_string()) {}
void surface::fill(rectangle rect,color col) { SDL_Surface* ptr = get_low(); SDL_Rect r = rectangle::exchange_rect<SDL_Rect>(rect); uint32_t c = col.map_rgba(); if(SDL_FillRect(ptr,&r,c)==-1) throw exception_sdl(); }
void CDX9Renderer::Point(point p, const color& c) { BeginBatch(batch_points); CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back()); AddVertex(c.getD3DCOLOR(), p, origin); draw_op->vertex_count++; }
void color::blend(const color &other) { if (other.is_invisible()) return; r = alpha_over_c(other.r, other.a, r, a); g = alpha_over_c(other.g, other.a, g, a); b = alpha_over_c(other.b, other.a, b, a); a = a + (other.a * (0xff - a)) / 0xff; r = ((r * 0xff) / a); g = ((g * 0xff) / a); b = ((b * 0xff) / a); }
virtual void set_background ( color& c ) { m_background = &c; XSetWindowBackground ( m_display, m_window, c.pixel() ); XClearWindow ( m_display, m_window ); XFlush ( m_display ); }
virtual void set_background ( color& c ) { // hold a ref to the alloc'ed color m_background.set ( c ); XSetWindowBackground ( m_display, m_window, c.pixel() ); refresh(); }
void display::define_light(const int & light_number, const math::transform & modelview, const math::vector & position, const color & ambient, const color & diffuse, const color & specular, const gsgl::real_t & attenuation_constant, const gsgl::real_t & attenuation_linear, const gsgl::real_t & attenuation_quadratic) { bind(); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(modelview.ptr()); int gl_light = GL_LIGHT0 + light_number; glEnable(gl_light); glLightfv(gl_light, GL_AMBIENT, ambient.ptr()); glLightfv(gl_light, GL_DIFFUSE, diffuse.ptr()); glLightfv(gl_light, GL_SPECULAR, specular.ptr()); glLightfv(gl_light, GL_POSITION, position.ptr()); glLightf(gl_light, GL_CONSTANT_ATTENUATION, attenuation_constant); glLightf(gl_light, GL_LINEAR_ATTENUATION, attenuation_linear); glLightf(gl_light, GL_QUADRATIC_ATTENUATION, attenuation_quadratic); } // display::define_light()
void linux_framebuffer::setcolor(const color & c) { if(m_var.bits_per_pixel == 16) { //printf("R %d %d\n", m_var.red.offset, m_var.red.length); //printf("G %d %d\n", m_var.green.offset, m_var.green.length); //printf("B %d %d\n", m_var.blue.offset, m_var.blue.length); //printf("A %d %d\n", m_var.transp.offset, m_var.transp.length); constexpr size_t sizeof_colorcomponent = sizeof(c.ir()) * 8; const uint16_t r = (c.ir() >> (sizeof_colorcomponent - m_var.red.length)) << m_var.red.offset; const uint16_t g = (c.ig() >> (sizeof_colorcomponent - m_var.green.length)) << m_var.green.offset; const uint16_t b = (c.ib() >> (sizeof_colorcomponent - m_var.blue.length)) << m_var.blue.offset; const uint16_t a = (c.ia() >> (sizeof_colorcomponent - m_var.transp.length)) << m_var.transp.offset; //printf("assign %08x + %08x = %08x\n", m_map, offset, pos); m_col16 = r|g|b|a; } }
void color_factory::init_from_string(color & c, std::string const& css_color) { typedef std::string::const_iterator iterator_type; typedef mapnik::css_color_grammar<iterator_type> css_color_grammar; css_color_grammar g; iterator_type first = css_color.begin(); iterator_type last = css_color.end(); // boost 1.41 -> 1.44 compatibility, to be removed in mapnik 2.1 (dane) #if BOOST_VERSION >= 104500 bool result = boost::spirit::qi::phrase_parse(first, last, g, boost::spirit::ascii::space, c); if (!result) { throw config_error(std::string("Failed to parse color value: ") + "Expected a CSS color, but got '" + css_color + "'"); } #else mapnik::css css_; bool result = boost::spirit::qi::phrase_parse(first, last, g, boost::spirit::ascii::space, css_); if (!result) { throw config_error(std::string("Failed to parse color value: ") + "Expected a CSS color, but got '" + css_color + "'"); } c.set_red(css_.r); c.set_green(css_.g); c.set_blue(css_.b); c.set_alpha(css_.a); #endif }
void draw_radial_marks(canvas& cnv, circle cp, float size, color c) { using namespace radial_consts; auto state = cnv.new_state(); auto center = cp.center(); constexpr auto num_divs = 50; float div = range / num_divs; auto const& theme = get_theme(); cnv.translate({ center.x, center.y }); cnv.stroke_style(theme.ticks_color); for (int i = 0; i != num_divs+1; ++i) { float from = cp.radius; if (i % (num_divs / 10)) { // Minor ticks from -= size / 4; cnv.line_width(theme.minor_ticks_width); cnv.stroke_style(c.level(theme.minor_ticks_level)); } else { // Major ticks cnv.line_width(theme.major_ticks_width); cnv.stroke_style(c.level(theme.major_ticks_level)); } float angle = offset + (M_PI / 2) + (i * div); float sin_ = std::sin(angle); float cos_ = std::cos(angle); float to = cp.radius - (size / 2); cnv.move_to({ from * cos_, from * sin_ }); cnv.line_to({ to * cos_, to * sin_ }); cnv.stroke(); } }
color map_palette(const color& c, int palette) { if(palette < 0 || palette >= palettes.size() || palettes[palette].mapping.empty()) { return c; } const std::map<uint32_t,uint32_t>& mapping = palettes[palette].mapping; std::map<uint32_t,uint32_t>::const_iterator i = mapping.find(c.value()); if(i != mapping.end()) { return color(color::convert_pixel_byte_order(i->second)); } else { return c; } }
void d3d9_prim2d_lines::render_segments(const vec2* points, unsigned int point_count, const color& color) { ASSERT(_is_rendering); if (point_count > 1) { static_assert(sizeof(solar::vec2) == sizeof(D3DXVECTOR2), "solar::vec2 cannot be casted to D3DXVECTOR2"); auto d3dx_points = reinterpret_cast<const D3DXVECTOR2*>(points); if (_viewport.X != 0 || _viewport.Y != 0) { //NOTE: ID3DXLine will internally transform all the points by the viewport's top left position. This causes problems because //all clients expect the points to be in screen space, not in the current viewport space. D3DMATRIX old_projection; D3D9_VERIFY(_context.get_device()->GetTransform(D3DTS_PROJECTION, &old_projection)); D3DXMATRIX new_projection; ::D3DXMatrixTranslation(&new_projection, -uint_to_float(_viewport.X), -uint_to_float(_viewport.Y), 0.f); new_projection *= old_projection; D3D9_VERIFY(_context.get_device()->SetTransform(D3DTS_PROJECTION, &new_projection)); D3D9_VERIFY(_d3dx_line->Draw(d3dx_points, point_count, color.to_argb32())); D3D9_VERIFY(_context.get_device()->SetTransform(D3DTS_PROJECTION, &old_projection)); } else { D3D9_VERIFY(_d3dx_line->Draw(d3dx_points, point_count, color.to_argb32())); } } }
void obliqueangle_engine::render_block( image_operations_ptr o, int bt, pos_t px, pos_t py, color top, color side ) { o->add_pixel(px, py, top); o->add_pixel(px + 1, py, top); o->add_pixel(px, py + 1, side); side.lighten(0x20); o->add_pixel(px + 1, py + 1, side); }
// Draw quad void CDX9Renderer::Quad(const quad& q, const color& filter, const rect* _uv) { if (current_texture != NULL && current_texture == current_rendertarget) throw error(_T("Illegal rendering operation attempted"), E_FAIL); // Not allowed to draw with texture being the render target BeginBatch(batch_quads); CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back()); rect uv; // No texture: UV coords don't matter if (current_texture == NULL) uv = zero_rect; else { // Texture supplied but no UV given: draw entire texture if (_uv == NULL) uv = point(current_texture->xf, current_texture->yf).make_rect(); else uv = (*_uv) * point(current_texture->xf, current_texture->yf); } D3DCOLOR c = filter.getD3DCOLOR(); AddVertex(c, q.tl + point(state.x_skew, 0.0), uv.topleft()); AddVertex(c, q.tr + point(state.x_skew, state.y_skew), uv.topright()); AddVertex(c, q.bl, uv.bottomleft()); AddVertex(c, q.br + point(0.0, state.y_skew), uv.bottomright()); unsigned short index = draw_op->vertex_count; AddIndex(index); AddIndex(index + 1); AddIndex(index + 2); AddIndex(index + 2); AddIndex(index + 1); AddIndex(index + 3); draw_op->vertex_count += 4; draw_op->index_count += 6; }
/** Convert a color in CIE(x,y,Y) to SRGB. */ inline const color xyY_to_srgb(const color& in) { // First convert xyY to XYZ tristimulus values color t{in.Y() * in.x() / in.y(), in.Y(), in.Y() * (1.0f - in.x() - in.y()) / in.y()}; // Then perform the matrix multiplication to linear RGB color lin{3.2406f * t[0] + -1.5372f * t[1] + -0.4986f * t[2], -0.9689f * t[0] + 1.8758f * t[1] + 0.0415f * t[2], 0.0557f * t[0] + -0.2040f * t[1] + 1.0570f * t[2]}; // Assume a 80 cd/m2 display. lin /= 80.f; // Finally, apply gamma and return sRGB const float gamma = 1.0f / 2.2f; return pow(clamp_elements(lin, 0.0f, 1.0f), gamma); }
void spherical_clipmap::draw(context *c) { // don't bother drawing on the first frame, as we don't have a modelview yet... if (clipmap_rings.size()) { glPushAttrib(GL_ALL_ATTRIB_BITS); glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_INDEX_ARRAY); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); color::WHITE.set(); for (int i = 0; i <= last_ring; ++i) { if (i >= first_ring) clipmap_rings[i]->draw(); if (c->render_flags & context::RENDER_WIREFRAME) { if (i % 2) color::WHITE.set(); else GRAY.set(); } } clipmap_cap->draw(); // glPopClientAttrib(); glPopAttrib(); } } // spherical_clipmap::draw()
void image_operations::add_pixel(pos_t x, pos_t y, color &c) { if (c.is_invisible()) { return; } if (!(x >= min_x)) { return; } if (!(y >= min_y)) { return; } if (!(x < max_x)) { return; } if (!(y < max_y)) { return; } color n = color(c); // tag with depth. n.z = z; image_operation oper; oper.x = (uint16_t)x; oper.y = (uint16_t)y; oper.c = n; operations.push_back(oper); }
color make_window_alpha_scaled_color(const window& window, const color& c) { return color(c, c.get_a() * window.get_alpha()); }
void path_output_attributes::set_stroke_color(color const& stroke_color) { stroke_color_ = stroke_color.to_hex_string(); }
void path_output_attributes::set_fill_color(color const& fill_color) { fill_color_ = fill_color.to_hex_string(); }