Example #1
0
    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);
        }
    }
Example #2
0
        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);
        }
Example #3
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);
    }
Example #4
0
// Draw a black frame around the rendering buffer, assuming it has 
// RGB-structure, one byte per color component
//--------------------------------------------------
void draw_black_frame(agg::rendering_buffer& rbuf)
{
	unsigned i;
	for(i = 0; i < rbuf.height(); ++i)
	{
		unsigned char* p = rbuf.row_ptr(i);
		*p++ = 0; *p++ = 0; *p++ = 0; *p++=0; // 3 black in header
		p += (rbuf.width() - 2) * sizeof(pixfmt);
		*p++ = 0; *p++ = 0; *p++ = 0; *p++=0; // 3 black in tail
	}
	memset(rbuf.row_ptr(0), 0, rbuf.width() * sizeof(pixfmt));
	memset(rbuf.row_ptr(rbuf.height() - 1), 0, rbuf.width() * sizeof(pixfmt));
}
Example #5
0
bool write_ppm(const agg::rendering_buffer& buffer,
               const char* file_name)
{
  FILE* fd=fopen(file_name, "wb");

  if (fd) {
    fprintf(fd,"P6 %d %d 255\n", buffer.width(),buffer.height());

    for (size_t y=0; y<buffer.height();y++)
    {
      const unsigned char* row=buffer.row_ptr(y);

      fwrite(row,1,buffer.width()*3,fd);
    }

    fclose(fd);
    return true;
  }

  return false;
}
Example #6
0
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);
}
Example #7
0
// _DrawBitmap
void
Painter::_DrawBitmap(const agg::rendering_buffer& srcBuffer, color_space format,
					 BRect actualBitmapRect, BRect bitmapRect, BRect viewRect) const
{
	switch (format) {
		case B_RGB32:
		case B_RGBA32:
			_DrawBitmap32(srcBuffer, actualBitmapRect, bitmapRect, viewRect);
			break;
		default:
fprintf(stderr, "Painter::_DrawBitmap() - non-native colorspace: %d\n", format);
#ifdef __ANTARES__
			// TODO: this is only a temporary implementation,
			// to really handle other colorspaces, one would
			// rather do the conversion with much less overhead,
			// for example in the nn filter (hm), or in the
			// scanline generator
			BBitmap temp(actualBitmapRect, 0, B_RGB32);
			status_t err = temp.ImportBits(srcBuffer.buf(),
										   srcBuffer.height() * srcBuffer.stride(),
										   srcBuffer.stride(),
										   0, format);
			if (err >= B_OK) {
				agg::rendering_buffer convertedBuffer;
				convertedBuffer.attach((uint8*)temp.Bits(),
									   (uint32)actualBitmapRect.IntegerWidth() + 1,
									   (uint32)actualBitmapRect.IntegerHeight() + 1,
									   temp.BytesPerRow());
				_DrawBitmap32(convertedBuffer, actualBitmapRect, bitmapRect, viewRect);
			} else {
fprintf(stderr, "Painter::_DrawBitmap() - colorspace conversion failed: %s\n", strerror(err));
			}
#endif // __ANTARES__
			break;
	}
}
Example #8
0
bool save_image_file (agg::rendering_buffer& rbuf, const char *fn)
{
  FILE* fd = fopen(fn, "wb");
  if(fd == 0) return false;
            
  unsigned w = rbuf.width();
  unsigned h = rbuf.height();
            
  fprintf(fd, "P6\n%d %d\n255\n", w, h);
                
  unsigned y; 
  agg::pod_array<unsigned char> row_buf(w * 3);
  unsigned char *tmp_buf = row_buf.data();

  for(y = 0; y < rbuf.height(); y++)
    {
      const unsigned char* src = rbuf.row_ptr(app_flip_y ? h - 1 - y : y);
      agg::color_conv_row(tmp_buf, src, w, agg::color_conv_bgr24_to_rgb24());
      fwrite(tmp_buf, 1, w * 3, fd);
    }

  fclose(fd);
  return true;
}
Example #9
0
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));
    }
}
Example #10
0
    //------------------------------------------------------------------------
    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);
    }
Example #11
0
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;
   }
}
Example #12
0
 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);
 }