예제 #1
0
void GREX::calculate(){
//fprintf(stderr,"CALCULATE %d %d\n",intercomm.Get_rank(),partner);
  unsigned nn=buffer.size();
  vector<char> rbuf(nn);
  localDeltaBias=-plumedMain.getBias();
  if(intracomm.Get_rank()==0){
    Communicator::Request req=intercomm.Isend(buffer,partner,1066);
    intercomm.Recv(rbuf,partner,1066);
    req.wait();
  }
  intracomm.Bcast(rbuf,0);
  istringstream i(string(&rbuf[0],rbuf.size()));
  atoms.readBinary(i);
  plumedMain.setExchangeStep(true);
  plumedMain.prepareDependencies();
  plumedMain.justCalculate();
  plumedMain.setExchangeStep(false);
  localDeltaBias+=plumedMain.getBias();
  localDeltaBias+=localUSwap-localUNow;
  if(intracomm.Get_rank()==0){
    Communicator::Request req=intercomm.Isend(localDeltaBias,partner,1067);
    intercomm.Recv(foreignDeltaBias,partner,1067);
    req.wait();
//fprintf(stderr,">>> %d %d %20.12f %20.12f %20.12f %20.12f\n",intercomm.Get_rank(),partner,localDeltaBias,foreignDeltaBias,localUSwap,localUNow);
  }
  intracomm.Bcast(foreignDeltaBias,0);
}
예제 #2
0
파일: test_variant.cpp 프로젝트: SSE4/vmf-1
TEST_P(TestVariantRawBuffer_Base64Decoding, TestDecode)
{
    data = std::get<0>(GetParam());
    unsigned int idx = std::get<1>(GetParam());
    switch(idx)
    {
    case 0:
        ASSERT_THROW(v1.fromString(vmf::Variant::type_rawbuffer, data), vmf::IncorrectParamException);
        break;
    case 1:
        ASSERT_THROW(v1.fromString(vmf::Variant::type_rawbuffer, data), vmf::IncorrectParamException);
        break;
    case 2:
        ASSERT_THROW(v1.fromString(vmf::Variant::type_rawbuffer, data), vmf::IncorrectParamException);
        break;
    case 3:
        {
            v1.fromString(vmf::Variant::type_rawbuffer, data);
            vmf::vmf_rawbuffer rbuf("foob\0\0", 6);
            v2 = vmf::Variant(rbuf);
            bool result = v1 == v2;
            ASSERT_TRUE(result);
            break;
        }
    case 4:
        {
            v1.fromString(vmf::Variant::type_rawbuffer, data);
            v2 = vmf::Variant(vmf::vmf_rawbuffer());
            bool result = v1 == v2;
            ASSERT_TRUE(result);
            break;
        }
    }
}
예제 #3
0
int main()
{
    //--------------------
    // Allocate the buffer.
    // Clear the buffer, for now "manually"
    // Create the rendering buffer object
    // Create the Pixel Format renderer
    // Do something simple, draw a diagonal line
    // Write the buffer to agg_test.ppm
    // Free memory

    unsigned char* buffer = new unsigned char[frame_width * frame_height * 3];

    memset(buffer, 255, frame_width * frame_height * 3);

    agg::rendering_buffer rbuf(buffer, 
                               frame_width, 
                               frame_height, 
                               frame_width * 3);

    agg::pixfmt_rgb24 pixf(rbuf);

    unsigned i;
    for(i = 0; i < pixf.height()/2; ++i)
    {
        pixf.copy_pixel(i, i, agg::rgba8(127, 200, 98));
    }

    draw_black_frame(pixf);
    write_ppm(buffer, frame_width, frame_height, "agg_test.ppm");

    delete [] buffer;
    return 0;
}
예제 #4
0
color blend(color const& source, color const& dest, unsigned cover=255)
{
    unsigned stride = 4;
    unsigned size = 1;

    color source_pre = source;
    source_pre.premultiply();
    color dest_pre = dest;
    dest_pre.premultiply();

    unsigned char* buffer = new unsigned char[size*size*stride];
    memset(buffer, 0, size*size*stride);
    buffer[0] = dest_pre.r;
    buffer[1] = dest_pre.g;
    buffer[2] = dest_pre.b;
    buffer[3] = dest_pre.a;
    // http://www.antigrain.com/doc/basic_renderers/basic_renderers.agdoc.html
    agg::rendering_buffer rbuf(buffer, 
                               size, 
                               size, 
                               size * stride);
    color::value_type* psource = (color::value_type*)rbuf.row_ptr(0,0,1);
    blender::blend_pix(psource,source_pre.r,source_pre.g,source_pre.b,source_pre.a,cover);
    color color_result(psource[0],psource[1],psource[2],psource[3]);
    color_result.demultiply();
    delete [] buffer;
    return color_result;
}
예제 #5
0
void check_file_content(const std::string &fname)
{
	int fd = open(fname.c_str(), O_RDONLY);
	assert(fd >= 0);
	Buffer rbuf(BUFFER_SIZE);
	for (off_t pos = 0; pos < FILE_SIZE; pos += BUFFER_SIZE) {
		size_t count = BUFFER_SIZE;
		off_t start = pos;
		char *buf = rbuf.get();
		while (count > 0) {
			ssize_t ret = pread(fd, buf, count, start);
			if (ret > 0) {
				buf += ret;
				start += ret;
				count -= ret;
			} else {
				std::cout << "Read ERROR: " << ret << ", "
					  << errno << std::endl;
			}
		}
		assert(rbuf.checkAt(pos));
	}
	close(fd);
	std::cout << fname << " is checked correctly." << std::endl;
}
예제 #6
0
파일: clip_buffer.cpp 프로젝트: svgpp/svgpp
void ClipBuffer::intersectClipPath(XMLDocument & xml_document, svg_string_t const & id, transform_t const & transform)
{
  if (XMLElement node = xml_document.findElementById(id))
  {
    try
    {
#if defined(RENDERER_AGG)
      std::vector<unsigned char> clip_path_buffer(width_ * height_, 0xff);
      agg::rendering_buffer clip_path_rbuf(&clip_path_buffer[0], width_, height_, width_);
      ElementBase root_context(xml_document, clip_path_rbuf, transform);
      document_traversal::load_expected_element(node, root_context, svgpp::tag::element::clipPath());

      typedef agg::amask_no_clip_gray8 alpha_mask_t;
      alpha_mask_t clip_path_alpha_mask(clip_path_rbuf);
      agg::rendering_buffer rbuf(&buffer_[0], width_, height_, width_);
      pixfmt_t buffer_pixfmt(rbuf);
      typedef agg::pixfmt_amask_adaptor<pixfmt_t, alpha_mask_t> pixfmt_masked_t;
      pixfmt_masked_t pixfmt_masked(buffer_pixfmt, clip_path_alpha_mask);
      agg::renderer_base<pixfmt_masked_t> renderer_base(pixfmt_masked);
      renderer_base.clear(agg::gray8(0));
#endif
    } 
    catch (std::exception const & e)
    {
      std::cerr << "Error loading clipPath \"" << std::string(id.begin(), id.end()) << "\": " << e.what() << "\n";
    }
  }
}
예제 #7
0
파일: test_variant.cpp 프로젝트: SSE4/vmf-1
TEST_F(TestVariant, CreateRawbuffer)
{
    vmf::vmf_rawbuffer rbuf("Raw <buffer \0 content>\n&", 25);
    vmf::Variant v(rbuf);
    ASSERT_EQ(v.getTypeName(), "rawbuffer");
    bool result = v.get_rawbuffer() == rbuf;
    ASSERT_TRUE(result);
}
uint32 nuiAudioDevice_DS_ProcessingTh::WriteToRingBuf(const std::vector<float*>& inbuf, uint32 nbSampleFrames, uint32 nbChannels)
{
  uint32 nbWrite, nbWrite2, c, i;
  std::vector<float*>  rbuf(nbChannels);
  bool need2ndPass=true;

  // prepare 1st pass writing
  nbWrite  = mpRingBuffer->GetWritableToEnd();
  if (nbWrite>=nbSampleFrames)
  {
    nbWrite = nbSampleFrames;
    need2ndPass=false;
  }

  // 1st pass writing
  for (c=0; c < nbChannels; c++)
    rbuf[c] = (float*)mpRingBuffer->GetWritePointer(c);

  for (i=0; i < nbWrite; i++)
  {
    for (c=0; c < nbChannels; c++)
      rbuf[c][i] = inbuf[c][i];
  } 

  // update ringbuf pointer
  mpRingBuffer->AdvanceWriteIndex(nbWrite);


  if (!need2ndPass)
    return nbWrite;

  // prepare 2nd pass writing
  nbWrite2  = mpRingBuffer->GetWritableToEnd();

  if ((nbWrite+nbWrite2) > nbSampleFrames)
  {
    nbWrite2 = nbSampleFrames - nbWrite;
  }

  // 2nd pass writing
  for (c=0; c<nbChannels; c++)
    rbuf[c] = (float*)mpRingBuffer->GetWritePointer(c);        

  for (i=nbWrite; i < nbWrite+nbWrite2; i++)
  {
    for (c=0; c < nbChannels; c++)
      rbuf[c][i] = inbuf[c][i];
  }

  // update ringbuf pointer
  mpRingBuffer->AdvanceWriteIndex(nbWrite2);

  return nbWrite+nbWrite2;
}
예제 #9
0
bool ReplicaExchange::do_exchange(double myscore0, double myscore1, int findex)
{
 double myscore=myscore0-myscore1;
 double fscore;
 int myindex=index_[myrank_];
 int frank=get_rank(findex);


 MPI_Sendrecv(&myscore,1,MPI_DOUBLE,frank,myrank_,
               &fscore,1,MPI_DOUBLE,frank,frank,
                MPI_COMM_WORLD, &status_);

 bool do_accept=get_acceptance(myscore,fscore);

 boost::scoped_array<int> sdel(new int[nproc_ - 1]);
 boost::scoped_array<int> rdel(new int[nproc_ - 1]);

 for(int i=0;i<nproc_-1;++i) {sdel[i]=0;}

 if(do_accept){
  std::map<std::string,Floats>::iterator it;
  for (it = parameters_.begin(); it != parameters_.end(); it++){
   Floats param = get_friend_parameter((*it).first,findex);
   set_my_parameter((*it).first,param);
  }
  //update the increment vector only to those replicas that upgraded to
  //a higher temperature to avoid double
  // calculations (excluding the transition 0 -> nrep-1)
  int delindex=findex-myindex;
  if (delindex==1){
   //std::cout << myindex << " " << findex << " " << std::endl;
   sdel[myindex]=1;
  }
  //update the indexes
  myindex=findex;
 }

 MPI_Barrier(MPI_COMM_WORLD);
 //get the increment vector from all replicas and copy it to the
 //exchange array
 MPI_Allreduce(sdel.get(),rdel.get(),nproc_-1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
 for(int i=0;i<nproc_-1;++i) {exarray_[i]=rdel[i];}
 // in any case, update index vector
 boost::scoped_array<int> sbuf(new int[nproc_]);
 boost::scoped_array<int> rbuf(new int[nproc_]);
 for(int i=0;i<nproc_;++i) {sbuf[i]=0;}
 sbuf[myrank_]=myindex;
 MPI_Allreduce(sbuf.get(),rbuf.get(),nproc_,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
 for(int i=0;i<nproc_;++i){index_[i]=rbuf[i];}
 return do_accept;

}
예제 #10
0
bool THRawBitmap::_checkScaled(THRenderTarget* pCanvas, SDL_Rect& rcDest)
{
    float fFactor;
    if(!pCanvas->shouldScaleBitmaps(&fFactor))
        return false;
    int iScaledWidth = (int)((float)m_pBitmap->w * fFactor);
    if(!m_pCachedScaledBitmap || m_pCachedScaledBitmap->w != iScaledWidth)
    {
        SDL_FreeSurface(m_pCachedScaledBitmap);
        Uint32 iRMask, iGMask, iBMask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        iRMask = 0xff000000;
        iGMask = 0x00ff0000;
        iBMask = 0x0000ff00;
#else
        iRMask = 0x000000ff;
        iGMask = 0x0000ff00;
        iBMask = 0x00ff0000;
#endif

        m_pCachedScaledBitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, iScaledWidth, (int)((float)m_pBitmap->h * fFactor), 24, iRMask, iGMask, iBMask, 0);
        SDL_LockSurface(m_pCachedScaledBitmap);
        SDL_LockSurface(m_pBitmap);

        typedef agg::pixfmt_rgb24_pre pixfmt_pre_t;
        typedef agg::renderer_base<pixfmt_pre_t> renbase_pre_t;
        typedef image_accessor_clip_rgb24_pal8<pixfmt_pre_t> imgsrc_t;
        typedef agg::span_interpolator_linear<> interpolator_t;
        typedef agg::span_image_filter_rgb_2x2<imgsrc_t, interpolator_t> span_gen_type;
        agg::scanline_p8 sl;
        agg::span_allocator<pixfmt_pre_t::color_type> sa;
        agg::image_filter<agg::image_filter_bilinear> filter;
        agg::trans_affine_scaling img_mtx(1.0 / fFactor);
        agg::rendering_buffer rbuf_src(m_pData, m_pBitmap->w, m_pBitmap->h, m_pBitmap->pitch);
        imgsrc_t img_src(rbuf_src, *m_pPalette, agg::rgba(0.0, 0.0, 0.0));
        interpolator_t interpolator(img_mtx);
        span_gen_type sg(img_src, interpolator, filter);
        agg::rendering_buffer rbuf(reinterpret_cast<unsigned char*>(m_pCachedScaledBitmap->pixels), m_pCachedScaledBitmap->w, m_pCachedScaledBitmap->h, m_pCachedScaledBitmap->pitch);
        pixfmt_pre_t pixf_pre(rbuf);
        renbase_pre_t rbase_pre(pixf_pre);
        rasterizer_scanline_rect ras(0, 0, rbuf.width(), rbuf.height());
        rbase_pre.clear(agg::rgba(1.0,0,0,0));
        agg::render_scanlines_aa(ras, sl, rbase_pre, sa, sg);

        SDL_UnlockSurface(m_pBitmap);
        SDL_UnlockSurface(m_pCachedScaledBitmap);
    }
    rcDest.x = (Sint16)((float)rcDest.x * fFactor);
    rcDest.y = (Sint16)((float)rcDest.y * fFactor);
    return true;
}
예제 #11
0
파일: test_variant.cpp 프로젝트: SSE4/vmf-1
TEST_P(TestVariantRawBuffer_Base64Encoding, TestEncode)
{
    data = std::get<0>(GetParam());
    size_t size = std::get<1>(GetParam());

    vmf::vmf_rawbuffer rbuf(data, size);
    v1 = vmf::Variant(rbuf);
    std::string result = v1.toString();
    if(rbuf == vmf::vmf_rawbuffer(0,0))
        ASSERT_EQ(result, "");
    else if( rbuf == vmf::vmf_rawbuffer("\0", 1) )
        ASSERT_EQ(result, "AA==");
    else if( rbuf == vmf::vmf_rawbuffer("foob", 4) )
        ASSERT_EQ(result, "Zm9vYg==");
    else if( rbuf == vmf::vmf_rawbuffer("foobar", 6) )
        ASSERT_EQ(result, "Zm9vYmFy");
}
예제 #12
0
int main()
{
    //--------------------
    // Allocate the buffer.
    // Clear the buffer, for now "manually"
    // Create the rendering buffer object
    // Create the Pixel Format renderer
    // Create one line (span) of type rgba8.
    // Fill the buffer using blend_color_span
    // Write the buffer to agg_test.ppm
    // Free memory

    unsigned char* buffer = new unsigned char[frame_width * frame_height * 3];

    memset(buffer, 255, frame_width * frame_height * 3);

    agg::rendering_buffer rbuf(buffer, 
                               frame_width, 
                               frame_height, 
                               frame_width * 3);

    agg::pixfmt_rgb24 pixf(rbuf);

    agg::rgba8 span[frame_width];

    unsigned i;
    for(i = 0; i < frame_width; ++i)
    {
        agg::rgba c(380.0 + 400.0 * i / frame_width, 0.8);
        span[i] = agg::rgba8(c);
    }

    for(i = 0; i < frame_height; ++i)
    {
        pixf.blend_color_hspan(0, i, frame_width, span, 0, 255);
    }


    write_ppm(buffer, frame_width, frame_height, "agg_test.ppm");

    delete [] buffer;
    return 0;
}
예제 #13
0
void THLine::draw(THRenderTarget* pCanvas, int iX, int iY)
{
    // Strangely drawing at 0,0 would draw outside of the screen
    // so we start at 1,0. This makes SDL behave like DirectX.
    SDL_Rect rcDest;
    rcDest.x = iX + 1;
    rcDest.y = iY;

    // Try to get a cached line surface
    if (m_pBitmap) {
        SDL_BlitSurface(m_pBitmap, NULL, pCanvas->getRawSurface(), &rcDest);
        return;
    }

    // No cache, let's build a new one
    SDL_FreeSurface(m_pBitmap);

    Uint32 amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    amask = 0x000000ff;
#else
    amask = 0xff000000;
#endif

    const SDL_PixelFormat& fmt = *(pCanvas->getRawSurface()->format);
    m_pBitmap = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, (int)ceil(m_fMaxX), (int)ceil(m_fMaxY), fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, amask);

    agg::rendering_buffer rbuf(reinterpret_cast<agg::int8u*>(m_pBitmap->pixels), m_pBitmap->w, m_pBitmap->h, m_pBitmap->pitch);
    agg::pixfmt_rgba32 pixf(rbuf);
    agg::renderer_base<agg::pixfmt_rgba32> renb(pixf);

    agg::conv_stroke<agg::path_storage> stroke(*m_oPath);
    stroke.width(m_fWidth);

    agg::rasterizer_scanline_aa<> ras;
    ras.add_path(stroke);

    agg::scanline_p8 sl;
    agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba8(m_iB, m_iG, m_iR, m_iA));

    SDL_BlitSurface(m_pBitmap, NULL, pCanvas->getRawSurface(), &rcDest);
}
예제 #14
0
파일: test_variant.cpp 프로젝트: SSE4/vmf-1
TEST_P(TestVariantRawByfferType, ToStringFromString)
{
    size_t size = GetParam();
    switch(size)
    {
    case 0:
        ASSERT_THROW(vmf::vmf_rawbuffer("", 0), vmf::IncorrectParamException);
        ASSERT_THROW(vmf::vmf_rawbuffer(0, 10), vmf::IncorrectParamException);
        ASSERT_NO_THROW(vmf::vmf_rawbuffer(0, 0));
        return;
    default:
        data = std::unique_ptr<char[]>(new char[size]);
        for(unsigned int i = 0; i < size; i++)
            data[i] = (unsigned char)i;
        break;
    }
    vmf::vmf_rawbuffer rbuf(data.get(), size);
    v1 = vmf::Variant(rbuf);
    v2.fromString(vmf::Variant::type_rawbuffer, v1.toString());
    bool result = v1 == v2;
    ASSERT_TRUE(result);
}
예제 #15
0
파일: clip_buffer.cpp 프로젝트: svgpp/svgpp
void ClipBuffer::intersectClipRect(transform_t const & transform, number_t x, number_t y, number_t width, number_t height)
{
#if defined(RENDERER_AGG)
  typedef agg::renderer_scanline_aa_solid<renderer_base_t> renderer_t;

  agg::rendering_buffer rbuf(&buffer_[0], width_, height_, width_);
  pixfmt_t pixfmt(rbuf);
  renderer_base_t renderer_base(pixfmt);
  agg::scanline_p8 scanline;

  agg::rasterizer_scanline_aa<> rasterizer;
  rasterizer.filling_rule(agg::fill_even_odd);

  rasterizer.move_to_d(0, 0);
  rasterizer.line_to_d(pixfmt.width(), 0);
  rasterizer.line_to_d(pixfmt.width(), pixfmt.height());
  rasterizer.line_to_d(0, pixfmt.height());
  rasterizer.close_polygon();

  number_t px = x, py = y;
  transform.transform(&px, &py);
  rasterizer.move_to_d(px, py);
  px = x + width; py = y;
  transform.transform(&px, &py);
  rasterizer.line_to_d(px, py);
  px = x + width; py = y + height;
  transform.transform(&px, &py);
  rasterizer.line_to_d(px, py);
  px = x; py = y + height;
  transform.transform(&px, &py);
  rasterizer.line_to_d(px, py);
  rasterizer.close_polygon();

  agg::render_scanlines_aa_solid(rasterizer, scanline, renderer_base, agg::gray8(0));
#elif defined(RENDERER_GDIPLUS)

#endif
}
예제 #16
0
파일: main.cpp 프로젝트: franko/agg-intro
int
main()
{
  typedef agg::pixfmt_bgr24 pixel_type;
  
  const unsigned w = 60, h = 50;
  
  unsigned row_size = pixel_type::pix_width * w;
  unsigned buf_size = row_size * h;
  agg::pod_array<unsigned char> img_buf(buf_size);
  
  agg::rendering_buffer rbuf(img_buf.data(), w, h, app_flip_y ? -row_size : row_size);
  pixel_type pixf(rbuf);
  
  typedef agg::renderer_base<pixel_type> renderer_base;
  typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;

  renderer_base rb(pixf);
  renderer_solid rs(rb);
  
  agg::rasterizer_scanline_aa<> ras;
  agg::scanline_p8 sl;

  agg::rgba8 white(255, 255, 255);
  rb.clear(white);

  agg::rgba8 color(160, 0, 0);

  agg::ellipse shape(30.0, 25.0, 12.0, 12.0);
  
  ras.add_path(shape);
  rs.color(color);
  agg::render_scanlines(ras, sl, rs);
  
  save_image_file(rbuf, "output.ppm");
  
  return 0;
}
예제 #17
0
int main()
{
  //Allocate the buffer.
  unsigned char * buffer = new unsigned char[frameWidth * frameHeight * 3];

  //Clear the buffer, manually
  memset(buffer, 255, frameWidth * frameHeight * 3);

  //Create the rendering buffer object
  agg::rendering_buffer rbuf(buffer, frameWidth, frameHeight, frameWidth * 3);
  
  //Create the Pixel format renderer
  agg::pixfmt_rgb24 pixf(rbuf);

  //Create one line (span) of type rgba8
  agg::rgba8 span[frameWidth];

  //Fill the buffer using blender color
  unsigned i;
  puts("Span...");
  for (i = 0; i < frameWidth; ++i)
  {
    agg::rgba c(380.0 + 400.0 * i / frameWidth, 0.8);
    span[i] = agg::rgba8(c);
  }

  for (i = 0; i < frameHeight; ++i)
  {
    pixf.blend_color_hspan(0, i, frameWidth, span, 0, 255);
  }
  puts("write...");
  writePPM(buffer, frameWidth, frameHeight, "agg_test.ppm");

  delete [] buffer;
  return 0;
}
예제 #18
0
int main()
{
	// Allocate the framebuffer
	unsigned char* buf = new unsigned char[width * height * 3];

	// Create the rendering buffer
	agg::rendering_buffer rbuf(buf, width, height, width * 3);

	// Create the renderer and the rasterizer
	agg::renderer<agg::span_rgb24> ren(rbuf);
	agg::rasterizer ras;

	// Setup the rasterizer
	ras.gamma(1.3);
	ras.filling_rule(agg::fill_even_odd);

	ren.clear(agg::rgba8(255, 255, 255));

	int i;

	// Draw random polygons
	for(i = 0; i < 10; i++) {
		int n = rand() % 6 + 3;

		// Make the polygon. One can call move_to() more than once.
		// In this case the rasterizer behaves like Win32 API PolyPolygon().
		ras.move_to_d(random(-30, rbuf.width() + 30),
		              random(-30, rbuf.height() + 30));

		int j;
		for(j = 1; j < n; j++) {
			ras.line_to_d(random(-30, rbuf.width() + 30),
			              random(-30, rbuf.height() + 30));
		}

		// Render
		ras.render(ren, agg::rgba8(rand() & 0xFF,
		                           rand() & 0xFF,
		                           rand() & 0xFF,
		                           rand() & 0xFF));
	}

	// Draw random ellipses
	for(i = 0; i < 50; i++) {
		draw_ellipse(ras,
		             random(-30, rbuf.width()  + 30),
		             random(-30, rbuf.height() + 30),
		             random(3, 50),
		             random(3, 50));
		ras.render(ren, agg::rgba8(rand() & 0x7F,
		                           rand() & 0x7F,
		                           rand() & 0x7F,
		                           (rand() & 0x7F) + 100));
	}

	// Draw random straight lines
	for(i = 0; i < 20; i++) {
		draw_line(ras,
		          random(-30, rbuf.width()  + 30),
		          random(-30, rbuf.height() + 30),
		          random(-30, rbuf.width()  + 30),
		          random(-30, rbuf.height() + 30),
		          random(0.1, 10));

		ras.render(ren, agg::rgba8(rand() & 0x7F,
		                           rand() & 0x7F,
		                           rand() & 0x7F));
	}

	// Write a .ppm file
	FILE* fd = fopen("agg_test.ppm", "wb");
	fprintf(fd, "P6\n%d %d\n255\n", rbuf.width(), rbuf.height());
	fwrite(buf, 1, rbuf.width() * rbuf.height() * 3, fd);
	fclose(fd);

	delete [] buf;
	return 0;
}
예제 #19
0
void nuiAudioTrack::Read(uint32 sampleFrames)
{
    NGL_ASSERT(mpRingBuf);
    uint32 nbRead=sampleFrames;
    uint32 nbWrite=0;
    uint32 nbWrite2=0;
    std::vector<float*> rbuf(mNbChannels);
    uint32 c;




    //NGL_LOG(_T("nuiAudioFifo"), NGL_LOG_DEBUG, _T("\nWrite : read %d from source\n"), nbRead);



    //*******************************************
    //
    // first pass writing in ringBuffer
    //
    nbWrite  = mpRingBuf->GetWritableToEnd ();

    // the writable space may have grown since the last call of GetWritable, check that
    nbWrite  = (nbWrite > nbRead) ? nbRead : nbWrite;

    for (c=0; c<mNbChannels; c++)
        rbuf[c] = (float*)mpRingBuf->GetWritePointer(c);


    //NGL_LOG(_T("nuiAudioFifo"), NGL_LOG_DEBUG, _T("\nBEFORE BUFFERING %d\n"), nbWrite);

    // read audio samples from the source
    uint32 nbReadSamples = ReadSamples(nbWrite, rbuf/*ref for output*/);
    if (!nbReadSamples)
        return;




    //NGL_LOG(_T("nuiAudioFifo"), NGL_LOG_DEBUG, _T("\nAFTER BUFFERING %d\n"), nbWrite);


    mpRingBuf->AdvanceWriteIndex(nbWrite);

    //NGL_LOG(_T("nuiAudioFifo"), NGL_LOG_DEBUG, _T("\nWrite %d\n"), nbWrite);



    // everything has been written. no need of 2nd pass
    if (nbWrite == nbRead)
        return;



    //*******************************************
    //
    // second pass writing in ringBuffer
    //
    nbWrite2  = mpRingBuf->GetWritableToEnd();
    if (nbWrite2 < (nbRead - nbWrite))
    {
        NGL_LOG(_T("nuiAudioTrack"), NGL_LOG_ERROR, _T("ERROR : ringbuffer could not locked enough space to write data (%d requested, %d provided!)"), (nbRead-nbWrite), nbWrite2);
        NGL_ASSERT(0);
        return;
    }
    nbWrite2 = nbRead - nbWrite;

    for (c=0; c<mNbChannels; c++)
        rbuf[c] = (float*)mpRingBuf->GetWritePointer(c);


    // read audio samples from the source
    nbReadSamples = ReadSamples(nbWrite2, rbuf/*ref for output*/);
    if (!nbReadSamples)
        return;


    mpRingBuf->AdvanceWriteIndex (nbWrite2);

    //NGL_LOG(_T("nuiAudioTrack"), NGL_LOG_DEBUG, _T("\nWrite %d\n"), nbWrite);
}
예제 #20
0
int main(int argc, char* argv[])
{
  std::string  map;
  std::string  style;
  double       latTop,latBottom,lonLeft,lonRight;
  unsigned int startLevel;
  unsigned int endLevel;

  if (argc!=9) {
    std::cerr << "DrawMap ";
    std::cerr << "<map directory> <style-file> ";
    std::cerr << "<lat_top> <lon_left> <lat_bottom> <lon_right> ";
    std::cerr << "<start_zoom>" << std::endl;
    std::cerr << "<end_zoom>" << std::endl;
    return 1;
  }

  map=argv[1];
  style=argv[2];

  if (sscanf(argv[3],"%lf",&latTop)!=1) {
    std::cerr << "lon is not numeric!" << std::endl;
    return 1;
  }

  if (sscanf(argv[4],"%lf",&lonLeft)!=1) {
    std::cerr << "lat is not numeric!" << std::endl;
    return 1;
  }

  if (sscanf(argv[5],"%lf",&latBottom)!=1) {
    std::cerr << "lon is not numeric!" << std::endl;
    return 1;
  }

  if (sscanf(argv[6],"%lf",&lonRight)!=1) {
    std::cerr << "lat is not numeric!" << std::endl;
    return 1;
  }

  if (sscanf(argv[7],"%u",&startLevel)!=1) {
    std::cerr << "start zoom is not numeric!" << std::endl;
    return 1;
  }

  if (sscanf(argv[8],"%u",&endLevel)!=1) {
    std::cerr << "end zoom is not numeric!" << std::endl;
    return 1;
  }

  osmscout::DatabaseParameter databaseParameter;
  osmscout::DatabaseRef       database=std::make_shared<osmscout::Database>(databaseParameter);
  osmscout::MapServiceRef     mapService=std::make_shared<osmscout::MapService>(database);

  if (!database->Open(map.c_str())) {
    std::cerr << "Cannot open database" << std::endl;

    return 1;
  }

  osmscout::StyleConfigRef styleConfig=std::make_shared<osmscout::StyleConfig>(database->GetTypeConfig());

  if (!styleConfig->Load(style)) {
    std::cerr << "Cannot open style" << std::endl;
  }

  osmscout::TileProjection      projection;
  osmscout::MapParameter        drawParameter;
  osmscout::AreaSearchParameter searchParameter;
  osmscout::MapData             data;

  // Change this, to match your system
  drawParameter.SetFontName("/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf");
  drawParameter.SetFontName("/usr/share/fonts/TTF/DejaVuSans.ttf");
  drawParameter.SetFontSize(5.0);
  // Fadings make problems with tile approach, we disable it
  drawParameter.SetDrawFadings(false);
  // To get accurate label drawing at tile borders, we take into account labels
  // of other than the current tile, too.
  drawParameter.SetDropNotVisiblePointLabels(false);

  searchParameter.SetUseLowZoomOptimization(false);
  searchParameter.SetMaximumAreaLevel(3);

  osmscout::MapPainterAgg painter(styleConfig);

  for (size_t level=std::min(startLevel,endLevel);
       level<=std::max(startLevel,endLevel);
       level++) {
    osmscout::Magnification magnification;
    int                     xTileStart,xTileEnd,xTileCount,yTileStart,yTileEnd,yTileCount;

    magnification.SetLevel(level);

    xTileStart=osmscout::LonToTileX(std::min(lonLeft,lonRight),
                                    magnification);
    xTileEnd=osmscout::LonToTileX(std::max(lonLeft,lonRight),
                                  magnification);
    xTileCount=xTileEnd-xTileStart+1;

    yTileStart=osmscout::LatToTileY(std::max(latTop,latBottom),
                                    magnification);
    yTileEnd=osmscout::LatToTileY(std::min(latTop,latBottom),
                                  magnification);

    yTileCount=yTileEnd-yTileStart+1;

    std::cout << "Drawing zoom " << level << ", " << (xTileCount)*(yTileCount) << " tiles [" << xTileStart << "," << yTileStart << " - " <<  xTileEnd << "," << yTileEnd << "]" << std::endl;

    unsigned long bitmapSize=tileWidth*tileHeight*3*xTileCount*yTileCount;
    unsigned char *buffer=new unsigned char[bitmapSize];


    memset(buffer,0,bitmapSize);

    agg::rendering_buffer rbuf(buffer,
                               tileWidth*xTileCount,
                               tileHeight*yTileCount,
                               tileWidth*xTileCount*3);

    double minTime=std::numeric_limits<double>::max();
    double maxTime=0.0;
    double totalTime=0.0;

    osmscout::TypeInfoSet nodeTypes;
    osmscout::TypeInfoSet wayTypes;
    osmscout::TypeInfoSet areaTypes;

    styleConfig->GetNodeTypesWithMaxMag(magnification,
                                        nodeTypes);

    styleConfig->GetWayTypesWithMaxMag(magnification,
                                       wayTypes);

    styleConfig->GetAreaTypesWithMaxMag(magnification,
                                        areaTypes);

    for (int y=yTileStart; y<=yTileEnd; y++) {
      for (int x=xTileStart; x<=xTileEnd; x++) {
        agg::pixfmt_rgb24   pf(rbuf);
        osmscout::StopClock timer;
        osmscout::GeoBox    boundingBox;

        projection.Set(x,y,
                       magnification,
                       DPI,
                       tileWidth,
                       tileHeight);

        projection.GetDimensions(boundingBox);

        std::cout << "Drawing tile " << level << "." << y << "." << x << " " << boundingBox.GetDisplayText() << std::endl;

        osmscout::GeoBox dataBoundingBox(osmscout::GeoCoord(osmscout::TileYToLat(y-1,magnification),osmscout::TileXToLon(x-1,magnification)),
                                         osmscout::GeoCoord(osmscout::TileYToLat(y+1,magnification),osmscout::TileXToLon(x+1,magnification)));

        std::list<osmscout::TileRef> tiles;

        mapService->LookupTiles(magnification,dataBoundingBox,tiles);
        mapService->LoadMissingTileData(searchParameter,*styleConfig,tiles);
        mapService->ConvertTilesToMapData(tiles,data);

        size_t bufferOffset=xTileCount*tileWidth*3*(y-yTileStart)*tileHeight+
                            (x-xTileStart)*tileWidth*3;

        rbuf.attach(buffer+bufferOffset,
                    tileWidth,tileHeight,
                    tileWidth*xTileCount*3);

        painter.DrawMap(projection,
                        drawParameter,
                        data,
                        &pf);

        timer.Stop();

        double time=timer.GetMilliseconds();

        minTime=std::min(minTime,time);
        maxTime=std::max(maxTime,time);
        totalTime+=time;

        std::string output=osmscout::NumberToString(level)+"_"+osmscout::NumberToString(x)+"_"+osmscout::NumberToString(y)+".ppm";

        write_ppm(rbuf,output.c_str());
      }
    }

    rbuf.attach(buffer,
                tileWidth*xTileCount,
                tileHeight*yTileCount,
                tileWidth*xTileCount*3);

    std::string output=osmscout::NumberToString(level)+"_full_map.ppm";

    write_ppm(rbuf,output.c_str());

    delete[] buffer;

    std::cout << "=> Time: ";
    std::cout << "total: " << totalTime << " msec ";
    std::cout << "min: " << minTime << " msec ";
    std::cout << "avg: " << totalTime/(xTileCount*yTileCount) << " msec ";
    std::cout << "max: " << maxTime << " msec" << std::endl;
  }

  database->Close();

  return 0;
}
예제 #21
0
static  void    read_byte_code (void)

{
	long    body_id, bsize;
	int     i;

	printf ("Analyzing Byte code\n");

	bfp = fopen ("bytecode.eif", "wb");

	if (bfp == (FILE *) 0)
	{
		fprintf (stderr,"Cannot open file <%s>\n", "bytecode.eif");
		panic ();
	}

	msize = rlong ();
	melt  = (char **) malloc (msize * sizeof (char *));

	if (melt == (char **) 0)
	{
		fprintf (stderr,"Out of memory (read_byte_code)\n");
		panic ();
	}

	/* Write dynamic type names */

	if (fwrite (&dtype_max, sizeof (int), 1, bfp) != 1)
	{
		fprintf (stderr,"Write error\n");
		panic ();
	}

	for (i = 0; i <= dtype_max; ++i)
	{
		if (dtype_names [i] != (char *) 0)
			fprintf (bfp, "%s%c", dtype_names [i], '\0');
		else
			fprintf (bfp, "%c", '\0');
	}

	/* Write classtypes names */

	if (fwrite (&ctype_max, sizeof (int), 1, bfp) != 1)
	{
		fprintf (stderr,"Write error\n");
		panic ();
	}

	for (i = 0; i <= ctype_max; ++i)
	{
		if (ctype_names [i] != (char *) 0)
			fprintf (bfp, "%s%c", ctype_names [i], '\0');
		else
			fprintf (bfp, "%c", '\0');
	}

	for (;;)
	{
		body_id = rlong ();

		if (fwrite (&body_id, sizeof (int), 1, bfp) != 1)
		{
			fprintf (stderr,"Write error\n");
			panic ();
		}

		if (body_id == -1)
			break;

		fprintf (mfp,"    Body id    : %ld\n", body_id);

		bsize = rlong ();

		fprintf (mfp,"    Size       : %ld\n", bsize);
		fprintf (mfp,"    Pattern id : %d\n", rlong ());

		melt [body_id] = rbuf ((int) bsize);

		if (fwrite (&bsize, sizeof (int), 1, bfp) != 1)
		{
			fprintf (stderr,"Write error\n");
			panic ();
		}

		if (fwrite (melt [body_id], sizeof (char), bsize, bfp) != (size_t) bsize)
		{
			fprintf (stderr,"Write error\n");
			panic ();
		}

		free ((char *) (melt [body_id]));
	}

	free ((char *) melt);

	print_line ();
}
예제 #22
0
void Gear_Vectorial2Raster::runVideo()
{

  _image = _VIDEO_IN->type();
  if (_image->isNull())
    return;

  _outImage = _VIDEO_OUT->type();
  _outImage->resize(_image->width(), _image->height());

  _imageIn  = (const unsigned char*) _image->data();
  _imageOut = (unsigned char*) _outImage->data();

  float xoff = _XOFF->type()->value();
  float yoff = _YOFF->type()->value();

  _vecIn  = _VEC_IN->type();
  
  zepath  = _vecIn->path();

  memcpy(&_imageOut[0],&_imageIn[0], _image->width() * _image->height() * 4);
  
  agg::rendering_buffer rbuf(&_imageOut[0], 
                               _image->width(), 
                               _image->height(), 
                               _image->width() * 4);

        typedef agg::pixfmt_rgba32 pixfmt;
        typedef agg::renderer_base<pixfmt> renderer_base;
        typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
 	
	

        pixfmt pixf(rbuf);
        renderer_base rb(pixf);
        renderer_solid ren(rb);

        //rb.clear(agg::rgba(1,1,1));

        agg::rasterizer_scanline_aa<> ras;
        agg::scanline_p8 sl;
        agg::trans_affine mtx;
	mtx *= agg::trans_affine_translation(xoff,yoff);
   
 
        zepath->render(ras, sl, ren, mtx, rb.clip_box(), 1.0);
/*
        char buf[128]; 
        agg::gsv_text t;
        t.size(10.0);
        t.flip(true);

        agg::conv_stroke<agg::gsv_text> pt(t);
        pt.width(1.5);

        sprintf(buf, "Vertices=%d", m_path.vertex_count());

        t.start_point(10.0, 40.0);
        t.text(buf);

        ras.add_path(pt);
*/
        ren.color(agg::rgba(0,0,0));
        agg::render_scanlines(ras, sl, ren);

  


}
예제 #23
0
파일: test_variant.cpp 프로젝트: SSE4/vmf-1
TEST_F(TestVariant, GetTypeNameRawbuffer)
{
    vmf::vmf_rawbuffer rbuf("Raw <buffer \0 content>\n&", 25);
    vmf::Variant v(rbuf);
    ASSERT_EQ(v.getTypeName(), "rawbuffer");
}
예제 #24
0
    void GraphAggRenderer::render(QImage *image1, QRectF clip, 
            agg::trans_affine *t)
    {
        agg::trans_affine transform = *t;

        QImage &image = *image1;
        agg::rendering_buffer rbuf(image.bits(),
                image.width(), 
                image.height(), 
                image.width() * 4);

        agg::pixfmt_bgra32 pixf(rbuf);

        ren_base ren(pixf);
        renderer_solid r(ren);
        ren.clear(agg::rgba(1, 1, 1));

        scanline_type sl;
        agg::rasterizer_scanline_aa<> ras;

        clip.setX(-500);
        clip.setY(-500);
        clip.setWidth(1000);
        clip.setHeight(1000);
        qDebug() << "clip: box " << clip;

        agg::path_storage clip_ps;
        clip_ps.move_to(clip.x(), clip.y());
        clip_ps.line_to(clip.x() + clip.width(), clip.y());
        clip_ps.line_to(clip.x() + clip.width(), clip.y() + clip.height());
        clip_ps.line_to(clip.x(), clip.y() + clip.height());
        //clip_ps.line_to(clip.x(), clip.y());
        clip_ps.close_polygon();

        agg::path_storage &ps = m_data->ps;

        for (unsigned i = 0; i < m_data->as.size(); ++i) {
            const path_attributes &attr = m_data->as[i];
            if (attr.fill_flag) {
                //qDebug() << "++attr.fill_flag";
                ras.reset();

                agg::conv_contour<agg::path_storage> cc(ps);
                agg::conv_transform
                    < agg::conv_contour 
                    < agg::path_storage > > ct(cc, transform);

                agg::conv_gpc< 
                    agg::conv_transform < 
                    agg::conv_contour < 
                    agg::path_storage > >,
                    agg::path_storage> gpc(ct, clip_ps);
                gpc.operation(agg::gpc_and);

                //ras.add_path(ct, attr.index);
                ras.add_path(gpc, attr.index);

                r.color(attr.fill_color);
                agg::render_scanlines(ras, sl, r);
            } else if (attr.stroke_flag) {
                ras.reset();

                typedef conv_curve<path_storage> curved;
                typedef conv_stroke<curved> curved_stroked;
                typedef conv_transform<curved_stroked> curved_stroked_trans;

                agg::conv_stroke<agg::path_storage> pg(ps);
                agg::conv_transform< agg::conv_stroke < agg::path_storage >
                    > ct(pg, transform);

                agg::conv_gpc<agg::path_storage,
                    agg::path_storage> gpc(clip_ps, ps);
                /*
                agg::conv_gpc< 
                    agg::conv_transform < 
                    agg::conv_stroke < 
                    agg::path_storage > >,
                    agg::path_storage> gpc(ct, clip_ps);
                    */
                gpc.operation(agg::gpc_or);
                //gpc.operation(agg::gpc_and);

                qDebug() << attr.index;
                pg.width(attr.stroke_width);
                //ras.add_path(ct, attr.index);
                //ras.add_path(gpc, attr.index);

                ras.reset();
                gpc.rewind(attr.index);
                double x;
                double y;
                unsigned cmd;
                while(!agg::is_stop(cmd = gpc.vertex(&x, &y))) {
                    ras.add_vertex(x, y, cmd);
                    qDebug() << "++";
                }
                //ras.reset();
                //ras.add_path(clip_ps);
                //ras.add_path(ps, attr.index);

                //ras.reset();
                //ras.add_path(clip_ps);

                r.color(attr.stroke_color);
                agg::render_scanlines(ras, sl, r);
            }
        }
    }