コード例 #1
0
ファイル: sample_common.c プロジェクト: rib/piglit
enum piglit_result
dma_buf_create_and_sample_32bpp(unsigned w, unsigned h, unsigned cpp,
				int fourcc, const unsigned char *src)
{
	struct piglit_dma_buf *buf;
	unsigned stride, offset;
	int fd;
	enum piglit_result res;

	unsigned buffer_height;

	switch (fourcc) {
	case DRM_FORMAT_NV12:
	case DRM_FORMAT_YUV420:
	case DRM_FORMAT_YVU420:
		buffer_height = h * 3 / 2;
		break;
	default:
		buffer_height = h;
		break;
	}

	res = piglit_create_dma_buf(w, buffer_height,
				    cpp, src, w * cpp, &buf, &fd, &stride,
				    &offset);
	if (res != PIGLIT_PASS)
		return res;

	return sample_buffer(buf, fd, fourcc, w, h, stride, offset);
}
コード例 #2
0
ファイル: bitvector.cpp プロジェクト: migumar2/uiHRDC
BitVector::BitVector(VectorEncoder& encoder, usint universe_size) :
  size(universe_size), items(encoder.items),
  block_size(encoder.block_size),
  number_of_blocks(encoder.blocks),
  rank_index(0), select_index(0)
{
  usint* array_buffer = new usint[this->block_size * this->number_of_blocks];

  this->integer_bits = length(this->size);
  WriteBuffer sample_buffer(2 * (this->number_of_blocks + 1), this->integer_bits);

  // Copy & linearize the array.
  usint pos = 0;
  for(std::list<usint*>::iterator iter = encoder.array_blocks.begin(); iter != encoder.array_blocks.end(); iter++)
  {
    memcpy(array_buffer + pos, *iter, encoder.superblock_bytes);
    pos += encoder.block_size * encoder.blocks_in_superblock;
  }
  memcpy(array_buffer + pos, encoder.array, encoder.current_blocks * encoder.block_size * sizeof(usint));
  this->array = array_buffer;

  // Compress the samples.
  for(std::list<usint*>::iterator iter = encoder.sample_blocks.begin(); iter != encoder.sample_blocks.end(); iter++)
  {
    usint* buf = *iter;
    for(usint i = 0; i < 2 * encoder.samples_in_superblock; i++)
    {
      sample_buffer.writeItem(buf[i]);
    }
  }
  for(usint i = 0; i < 2 * encoder.current_samples; i++)
  {
    sample_buffer.writeItem(encoder.samples[i]);
  }
  sample_buffer.writeItem(this->items);
  sample_buffer.writeItem(this->size);

  this->samples = sample_buffer.getReadBuffer();

  this->indexForRank();
  this->indexForSelect();
}
コード例 #3
0
BitVector::BitVector(VectorEncoder& encoder, usint universe_size) :
  size(universe_size), items(encoder.items),
  block_size(encoder.block_size),
  number_of_blocks(encoder.blocks),
  rank_index(0), select_index(0)
{
  if(this->items == 0)
  {
    std::cerr << "BitVector: Cannot create a bitvector with no 1-bits!" << std::endl;
    return;
  }
  this->copyArray(encoder);

  this->integer_bits = length(this->size);
  WriteBuffer sample_buffer(2 * (this->number_of_blocks + 1), this->integer_bits);

  // Compress the samples.
  for(std::list<usint*>::iterator iter = encoder.sample_blocks.begin(); iter != encoder.sample_blocks.end(); iter++)
  {
    usint* buf = *iter;
    for(usint i = 0; i < 2 * encoder.samples_in_superblock; i++)
    {
      sample_buffer.writeItem(buf[i]);
    }
  }
  for(usint i = 0; i < 2 * encoder.current_samples; i++)
  {
    sample_buffer.writeItem(encoder.samples[i]);
  }
  sample_buffer.writeItem(this->items);
  sample_buffer.writeItem(this->size);

  this->samples = sample_buffer.getReadBuffer();

  this->indexForRank();
  this->indexForSelect();
}
コード例 #4
0
int main()
{
    double x = -2.5;
    double w = 3.5;
    double y = 0.5*w*SAMPLES_HEIGHT/SAMPLES_WIDTH;
    double h = 2*y;

    std::vector<unsigned> sample_buffer(SAMPLES_WIDTH*SAMPLES_HEIGHT);
    mandelbrot(sample_buffer.data(), SAMPLES_WIDTH, SAMPLES_HEIGHT,
            x, y, x+w, y-h, MAX_ITERATIONS,
            std::thread::hardware_concurrency());
    std::vector<std::uint8_t> total;
    unsigned zoom_count = 0;
    while(true) { //zoom_count != 10) {
        std::printf("zoom level %u\n", zoom_count);
        unsigned best_iterations = 0;
        unsigned best_sample_x = 0;
        unsigned best_sample_y = 0;
        for(unsigned i=0; i!=SAMPLES_WIDTH*SAMPLES_HEIGHT; ++i) {
            if(sample_buffer[i] == MAX_ITERATIONS)
                sample_buffer[i] = 0;
        }
                
        for(unsigned y1=0; y1!=SAMPLES_HEIGHT-SEARCH_BOX_HEIGHT; ++y1) {
            for(unsigned x1=0; x1!=SAMPLES_WIDTH-SEARCH_BOX_WIDTH; ++x1) {
                unsigned x2 = x1 + SEARCH_BOX_WIDTH;
                unsigned y2 = y1 + SEARCH_BOX_HEIGHT;
                unsigned total_iterations = 0;
                //unsigned total_inside = 0;
                for(unsigned y=y1; y!=y2; ++y) {
                    unsigned sample_offset = y*SAMPLES_WIDTH;
                    for(unsigned x=x1; x!=x2; ++x) {
                        unsigned iterations = sample_buffer[sample_offset + x]; 
                        //if(iterations == MAX_ITERATIONS)
                        //    total_inside += 1;
                        //else
                            total_iterations += iterations;
                    }
                }
                //if(total_inside < MAX_INSIDE && total_iterations > best_iterations)
                if(total_iterations > best_iterations)
                {
                    best_iterations = total_iterations;
                    best_sample_x = x1;
                    best_sample_y = y1;
                }
            }
        }
        
        x = x + best_sample_x*w/SAMPLES_WIDTH;
        y = y - best_sample_y*h/SAMPLES_HEIGHT;
        w = w*SEARCH_BOX_WIDTH/SAMPLES_WIDTH;
        h = h*SEARCH_BOX_HEIGHT/SAMPLES_HEIGHT;
        std::printf("x=%.17g\n"
            "y=%.17g\n"
            "w=%.17g\n"
            "h=%.17g\n"
            "sample_x=%u\n"
            "sample_y=%u\n"
            "\n",
            x, y, w, h,
            best_sample_x, best_sample_y);
        auto start = std::chrono::system_clock::now();
        mandelbrot(sample_buffer.data(), SAMPLES_WIDTH, SAMPLES_HEIGHT,
                x, y, x+w, y-h, MAX_ITERATIONS,
                std::thread::hardware_concurrency());
        auto end = std::chrono::system_clock::now();
        auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
        printf("%lu ms\n", milliseconds);
        if(zoom_count > 4 && milliseconds > 5000)
            break;
        
        ++zoom_count;
    }
    std::vector<char> image(3*SAMPLES_WIDTH*SAMPLES_HEIGHT);
    color_mandelbrot(image.data(), sample_buffer.data(),
            SAMPLES_WIDTH, SAMPLES_HEIGHT, MAX_ITERATIONS);
    std::ofstream ofs("mandelbrot.data");
    ofs.write(image.data(), image.size());
    //std::ofstream ofs2("total.data");
    //ofs2.write(reinterpret_cast<char const*>(total.data()), total.size());
    return 0;
}