std::ostream& writeTexture(std::ostream& file, const GL::Texture2D& tex) { glBindTexture(GL_TEXTURE_2D, tex); GLint levels = 1; GLint format; glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format); GLint width; glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); GLint height; glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); if (format == GL_RGBA16F || format == GL_RGBA32F) { std::unique_ptr<float[]> buffer(new float[width * height * 3]); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, buffer.get()); writeImageRGB(file, width, height, buffer.get()); } else if (format == GL_R16F || GL_R32F) { std::unique_ptr<float[]> buffer(new float[width * height]); glGetTexImage(GL_TEXTURE_2D, 0, GL_RED, GL_FLOAT, buffer.get()); writeImageR(file, width, height, buffer.get()); } GL_CHECK_ERROR(); return file; }
void PCLWrapper::benchmark_png(){ int count = 0; //generate a set of random points int width = 640; int height = 480; unsigned short *test1 = (unsigned short *)malloc(width*height*sizeof(unsigned short)); //depth unsigned char *test2 = (unsigned char *)malloc(width*height*sizeof(unsigned char)*3); //rgb //load the input points with some random numbers //worst case for the image compression for (size_t i = 0; i < width*height*3; ++i) { *(test2+i)=rand(); } for (size_t i = 0; i < width*height; ++i) { *(test1+i)=rand(); } int counter=0; int iterations = 50; int average = 25; while (iterations > 0){ struct timeval start, end; double t1, t2; static double elapsed_sec = 0; const int MAX_COUNT = average; //average 10 results before printing gettimeofday(&start, NULL); //do some work here. char my_path[512]; sprintf(my_path, "/data/ni/out_rgb_%06d.png", counter); writeImageRGB(my_path, width, height, test2, my_path); sprintf(my_path, "/data/ni/out_depth_%06d.png", counter); writeImageDepth(my_path, width, height, test1, my_path); gettimeofday(&end, NULL); t1 = start.tv_sec + (start.tv_usec / 1000000.0); t2 = end.tv_sec + (end.tv_usec / 1000000.0); elapsed_sec += (t2 - t1); count++; counter++; if (count >= MAX_COUNT) { char buf[512]; sprintf(buf, "Number of Points: %d, Runtime: %f (s)\n", width*height, (elapsed_sec) / MAX_COUNT); elapsed_sec = 0; count = 0; __android_log_write(ANDROID_LOG_INFO, "PCL Benchmark:", buf); } iterations--; } free(test1); free(test2); }
void JpegOutput::writeImageRGBA(const unsigned char* rgbaData) { const size_t components = 3; const size_t size = _width * _height; std::unique_ptr<unsigned char[]> data( new unsigned char[size * components]); for (size_t pixel = 0; pixel < size; ++pixel) { data[pixel * 3] = rgbaData[pixel * 4]; data[pixel * 3 + 1] = rgbaData[pixel * 4 + 1]; data[pixel * 3 + 2] = rgbaData[pixel * 4 + 2]; } writeImageRGB(data.get()); }
void calculate_flow_write_img(float* img1, float* img2, char* filename, char* h5outfile,char* h5dset){ //copy view to image pair. int dims[10]; for(int j=0; j<g_ny; j++) { for(int i=0; i<g_nx; i++) { g_f1[i+g_bx][j+g_by]= img1[j*g_nx+i]*255; g_f2[i+g_bx][j+g_by]= img2[j*g_nx+i]*255; } } printf(" Start to calculate displacement for %s \n", filename); handleComputeDisplacements(); //printf("Finish calculate flowfield, write to image \n"); float* flow = convert_displacements_to_image(g_u,g_v,g_nx,g_ny,g_bx,g_by,(float)0.0,g_g_max_disp); //printf("Finish convert to rgb %d %d %d %d \n", g_nx, g_ny, g_bx, g_by); writeImageRGB(filename,g_nx,g_ny,flow,filename); free(flow); //write to output dims[0] = 2; //u or v dims[1] = g_nx; // width; dims[2] = g_ny; //height; //copy flow to buffer* for(int j=0; j<g_ny; j++) { for(int i=0; i<g_nx; i++) { uvbuffer[ i*g_ny + j ] = g_u[g_bx+i][g_by+j]; uvbuffer[ g_ny*g_nx + i*g_ny +j ]=g_v[g_bx+i][g_by+j]; } } hdf5_write_data_simple(h5outfile,h5dset,dims, 3, uvbuffer); //printf("write ok \n"); }