void generate_alpha_mask(int cx, int cy) { delete [] m_alpha_buf; m_alpha_buf = new unsigned char[cx * cy]; g_alpha_mask_rbuf.attach(m_alpha_buf, cx, cy, cx); typedef agg::renderer_base<agg::pixfmt_gray8> ren_base; typedef agg::renderer_scanline_aa_solid<ren_base> renderer; agg::pixfmt_gray8 pixf(g_alpha_mask_rbuf); ren_base rb(pixf); renderer r(rb); agg::scanline_p8 sl; rb.clear(agg::gray8(0)); agg::ellipse ell; int i; for(i = 0; i < 10; i++) { ell.init(rand() % cx, rand() % cy, rand() % 100 + 20, rand() % 100 + 20, 100); g_rasterizer.add_path(ell); r.color(agg::gray8(rand() & 0xFF, rand() & 0xFF)); agg::render_scanlines(g_rasterizer, sl, r); } }
impl(int width, int height) : width(width), height(height) , simperclock(0.01) , m_fman(m_feng), m_curves(m_fman.path_adaptor()), m_contour(m_curves) { if (SDL_Init(SDL_INIT_EVERYTHING) < 0) throw std::runtime_error(SDL_GetError()); screen = SDL_SetVideoMode(width, height, 0, SDL_ANYFORMAT|SDL_HWSURFACE); if(!screen) { SDL_Quit(); throw runtime_error(string("Unable to set screen: ") + SDL_GetError()); } window = intrusive_ptr<SDL_Surface>( SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, screen->format->BitsPerPixel, rmask, gmask, bmask, amask) , false); if (!window) SDL_Quit(); runtime_error (string("Unable to set window: ") + SDL_GetError()); rbwindow.attach((unsigned char*)window->pixels, window->w , window->h, window->pitch); SDL_WM_SetCaption("EOSimulator", 0); }
template<class VertexSource> void generate_alpha_mask(VertexSource& vs) { unsigned cx = (unsigned)width(); unsigned cy = (unsigned)height(); delete [] m_alpha_buf; m_alpha_buf = new unsigned char[cx * cy]; m_alpha_mask_rbuf.attach(m_alpha_buf, cx, cy, cx); typedef agg::renderer_base<agg::pixfmt_gray8> ren_base; typedef agg::renderer_scanline_aa_solid<ren_base> renderer; agg::pixfmt_gray8 pixf(m_alpha_mask_rbuf); ren_base rb(pixf); renderer ren(rb); start_timer(); if(m_operation.cur_item() == 0) { rb.clear(agg::gray8(0)); ren.color(agg::gray8(255)); } else { rb.clear(agg::gray8(255)); ren.color(agg::gray8(0)); } m_ras.add_path(vs); agg::render_scanlines(m_ras, m_sl, ren); double t1 = elapsed_time(); char buf[100]; sprintf(buf, "Generate AlphaMask: %.3fms", t1); draw_text(250, 20, buf); }
static void attach_buffer_to_BBitmap(agg::rendering_buffer& buffer, BBitmap* bitmap, bool flipY) { uint8* bits = (uint8*)bitmap->Bits(); uint32 width = bitmap->Bounds().IntegerWidth() + 1; uint32 height = bitmap->Bounds().IntegerHeight() + 1; int32 bpr = bitmap->BytesPerRow(); if (flipY) { // XXX: why don't I have to do this?!? // bits += bpr * (height - 1); bpr = -bpr; } buffer.attach(bits, width, height, bpr); }
void CAggMemoryDC::PrepareBufferMemory(CDC& dc) { CreateCompatibleDC(dc); if(CreateAggBitmap(m_rcUpdate.Width(), m_rcUpdate.Height(), &m_buf)) { m_oldhbmp=(HBITMAP)::SelectObject(m_hDC, m_hbmp); #if defined(__16BIT_COLOR555__) || defined(__16BIT_COLOR565__) int stride=((m_rcUpdate.Width()*2+3)/4)*4; #else int stride=((m_rcUpdate.Width()*4+3)/4)*4; #endif m_rbuf.attach( (unsigned char*)m_buf, m_rcUpdate.Width(), m_rcUpdate.Height(), -stride); // Use negative stride for Y-axis going down. FillSolidRect(0,0,m_rcUpdate.Width(),m_rcUpdate.Height(),GetSysColor(COLOR_WINDOW)); } }
//------------------------------------------------------------------------ void generate_pattern() { unsigned size = unsigned(m_pattern_size.value()); create_star(m_pattern_size.value() / 2.0, m_pattern_size.value() / 2.0, m_pattern_size.value() / 2.5, m_pattern_size.value() / 6.0, 6, m_pattern_angle.value()); agg::conv_smooth_poly1_curve<agg::path_storage> smooth(m_ps); agg::conv_stroke<agg::conv_smooth_poly1_curve<agg::path_storage> > stroke(smooth); smooth.smooth_value(1.0); smooth.approximation_scale(4.0); stroke.width(m_pattern_size.value() / 15.0); delete [] m_pattern; m_pattern = new agg::int8u[size * size * pixfmt::pix_width]; m_pattern_rbuf.attach(m_pattern, size, size, size * pixfmt::pix_width); pixfmt pixf(m_pattern_rbuf); agg::renderer_base<pixfmt> rb(pixf); agg::renderer_scanline_aa_solid<agg::renderer_base<pixfmt> > rs(rb); rb.clear(agg::rgba_pre(0.4, 0.0, 0.1, m_pattern_alpha.value())); // Pattern background color m_ras.add_path(smooth); rs.color(agg::srgba8(110,130,50)); agg::render_scanlines(m_ras, m_sl, rs); m_ras.add_path(stroke); rs.color(agg::srgba8(0,50,80)); agg::render_scanlines(m_ras, m_sl, rs); }
void roadmap_canvas_agg_configure (unsigned char *buf, int width, int height, int stride) { roadmap_log( ROADMAP_ERROR, "roadmap_canvas_agg_configure, height =%d width=%d",height, width); agg_rbuf.attach(buf, width, height, stride); agg_renb.attach(agg_pixf); agg_renb.reset_clipping(true); ras.clip_box(0, 0, agg_renb.width() - 1, agg_renb.height() - 1); agg::glyph_rendering gren = agg::glyph_ren_outline; agg::glyph_rendering image_gren = agg::glyph_ren_agg_gray8; roadmap_config_declare ("preferences", &RoadMapConfigFont, "font.ttf", NULL); roadmap_config_declare ("preferences", &RoadMapConfigFontNormal, "font_normal.ttf", NULL); char *font_file = roadmap_path_join(roadmap_path_user(), roadmap_config_get (&RoadMapConfigFont)); if ((width) && (height)) roadmap_screen_set_screen_type( width, height ); if (!RoadMapCanvasFontLoaded) { if(m_feng.load_font(font_file, 0, gren) && m_image_feng.load_font(font_file, 0, image_gren)) { m_feng.hinting(true); if ( roadmap_screen_is_hd_screen() ) { m_feng.height(22); m_feng.width(22); } else { #ifdef _WIN32 m_feng.height(12); m_feng.width(12); #else m_feng.height(15); m_feng.width(15); #endif } m_feng.flip_y(true); m_image_feng.hinting(true); m_image_feng.flip_y(true); RoadMapCanvasFontLoaded = 1; } else { RoadMapCanvasFontLoaded = -1; char message[300]; snprintf(message, sizeof(message), "Can't load font: %s\n", font_file); roadmap_messagebox("Error", message); } } RoadMapCanvasFontLoaded = 1; roadmap_path_free(font_file); font_file = roadmap_path_join(roadmap_path_user(), roadmap_config_get (&RoadMapConfigFontNormal)); if(m_feng_nor.load_font(font_file, 0, gren) && m_image_feng_nor.load_font(font_file, 0, image_gren)) { m_feng_nor.hinting(true); if ( roadmap_screen_is_hd_screen() ) { m_feng_nor.height(22); m_feng_nor.width(22); } else { #ifdef _WIN32 m_feng_nor.height(12); m_feng_nor.width(12); #else m_feng_nor.height(15); m_feng_nor.width(15); #endif } m_feng_nor.flip_y(true); m_image_feng_nor.hinting(true); m_image_feng_nor.flip_y(true); RoadMapCanvasNormalFontLoaded = 1; } }
virtual void on_resize(int sx, int sy) { m_gray8_buf.resize(sx * sy); m_gray8_rbuf.attach(m_gray8_buf.data(), sx, sy, sx); }