void createTextures(GLuint texID[]) { char *image; int w, h, bpp; #ifdef _WIN32 AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL #endif glGenTextures(NUM_TEXTURAS,texID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); #ifdef _WIN32 if (TextureImage[0]=LoadBMP(NOME_TEXTURA_CUBOS)) { // Create MipMapped Texture glBindTexture(GL_TEXTURE_2D, texID[ID_TEXTURA_CUBOS]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); } #else if (read_JPEG_file(NOME_TEXTURA_CUBOS, &image, &w, &h, &bpp)) { // Create MipMapped Texture glBindTexture(GL_TEXTURE_2D, texID[ID_TEXTURA_CUBOS]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, image); } #endif else { printf("Textura %s not Found\n",NOME_TEXTURA_CUBOS); exit(0); } if( read_JPEG_file(NOME_TEXTURA_CHAO, &image, &w, &h, &bpp)) { glBindTexture(GL_TEXTURE_2D, texID[ID_TEXTURA_CHAO]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, image); }else{ printf("Textura %s not Found\n",NOME_TEXTURA_CHAO); exit(0); } glBindTexture(GL_TEXTURE_2D, NULL); }
int main(int argc, char **argv) { int i; printf("JPEG\n"); if ((argc > 2) && (strcmp(argv[1], "read") == 0)) { read_JPEG_file(argv[2]); } if ((argc > 1) && (strcmp(argv[1], "write") == 0)) { image_width = 640; image_height = 480; image_buffer = (char*) malloc(image_width * image_height * 3); for (i = 0; i < image_height * image_height; i++) { image_buffer[i * 3] = i * 255; image_buffer[i * 3 + 1] = 128 - ((i * 255) & 0x7f); image_buffer[i * 3 + 2] = 255 - ((i * 255) & 0xff); } printf("image_buffer [%p]\n", image_buffer); write_JPEG_file("w.jpg", 2); free(image_buffer); } return 0; }
void main ( int argc, char **argv) { if (argc < 3) { return ; } fprintf (stderr," Infile:%s\nOutfile:%s\n", argv[1], argv[2]); read_JPEG_file (argv[1], argv[2]); }
//************************************************************ //read jpeg file //************************************************************ void showJpegFile(char *filename) { int width=0; int height=0; int comps=0; GLubyte *image=0; if(read_JPEG_file(filename,&image,width,height,comps)){ writePixels(image,width,height); FREE(image); } }
int bmJpegReadJfif( BitmapDescription * bd, unsigned char ** pBuffer, SimpleInputStream * sis ) { BmJpegInputSource bjis; bmInitDescription( &(bjis.bjisBd) ); bjis.bjisBitmapBuffer= (unsigned char *)0; bjis.bjisSis= (SimpleInputStream *)0; bjis.bjisRowsReceived= 0; bjis.pub.init_source= bmJpegStartInputSource; bjis.pub.fill_input_buffer= bmJpegFillInputBuffer; bjis.pub.skip_input_data= bmJpegSkipInputData; bjis.pub.resync_to_restart= jpeg_resync_to_restart; /* use default method */ bjis.pub.term_source= bmJpegTerminateInputSource; bjis.pub.bytes_in_buffer= 0; /* forces fill_input_buffer */ /* on first read */ bjis.pub.next_input_byte = NULL; /* until buffer loaded */ bjis.bjisSis= sis; if ( ! read_JPEG_file ( &bjis ) ) { XDEB(sis); if ( bjis.bjisBitmapBuffer ) { free( bjis.bjisBitmapBuffer ); } bmCleanDescription( &(bjis.bjisBd) ); return -1; } *bd= bjis.bjisBd; *pBuffer= bjis.bjisBitmapBuffer; return 0; }
int main() { // Init parameter IMAGE_DATA * sdata = (IMAGE_DATA *)malloc(sizeof(IMAGE_DATA)); // Screen data IMAGE_DATA * cdata = (IMAGE_DATA *)malloc(sizeof(IMAGE_DATA)); // Cut data int height = 768; int width = 1376; int flag = 0; sdata->iData = (unsigned char *)malloc(height * width * 4); cdata->iData = (unsigned char *)malloc(height * 1366 * 3); clock_t start_time; clock_t end_time; printf("\n"); printf("============================================================================\n"); // get fb start_time = clock(); flag = GetFramebuffer(sdata); if (!flag) { printf("Get failed!\n"); return 0; } end_time=clock(); printf(" Get fb Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // cut data start_time = clock(); flag = CutFbData(sdata, cdata); if (!flag) { printf("Cut failed!\n"); return 0; } end_time=clock(); printf(" Cut data Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // Save data as jpeg start_time = clock(); flag = write_JPEG_file(cdata, "/data/eeds/save1.jpeg", 90); if (!flag) { printf("Save failed!\n"); return 0; } end_time=clock(); printf(" Save jpeg Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // Read jpeg start_time = clock(); flag = read_JPEG_file(sdata, "/data/eeds/save1.jpeg"); if (!flag) { printf("Read failed!\n"); return 0; } end_time=clock(); printf(" Read jpeg Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // Save data as bmp start_time = clock(); flag = SaveBMP(cdata, "/data/eeds/save2.bmp"); if (!flag) { printf("Save failed!\n"); return 0; } end_time=clock(); printf(" Save bmp Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // Free memory free(sdata->iData); free(cdata->iData); free(sdata); free(cdata); printf("****************************************************************************\n"); printf("\n"); return 1; }
/* The shell's main routine. Consists of several steps: * 1> Reads JPEGs using first command-line parameter(s) * 2> Records the process's elapsed time * 3> Lets the user play with the images * 4> Checks the elapsed time again, prints out the difference * 5> Writes JPEGs out using last command-line parameter(s) */ int main(int argc, char *argv[]) { int i; int num_inputs; /* Number of JPEG input-output files */ int num_runs, run; /* Number of runs, for multi-run code */ double run_time, total_time; /* Amount of time we've run */ struct timeval start_time, end_time; /* Time before/after user code */ /* Step 0A: Check & process command line */ if (argc != 1 + NUM_INPUTS + NUM_OUTPUTS + RUNS_COMMAND + RUNS_PROCS) { fprintf(stderr, "Usage: %s runs procs input1.jpg %soutput.jpg\n", argv[0], NUM_INPUTS > 1 ? "input2.jpg " : ""); exit(1); } num_inputs = argc - 1 - NUM_OUTPUTS - RUNS_COMMAND - RUNS_PROCS; num_runs = atoi(argv[1]); if (num_runs < 1) num_runs = 1; if (num_runs > 10) num_runs = 10; /* Change if you like LOTS of runs */ fprintf(stderr, "Making %d runs . . .\n", num_runs); num_procs = atoi(argv[1 + RUNS_COMMAND]); if (num_procs < 1) num_procs = 1; if (num_procs > 256) num_procs = 256; fprintf(stderr, "Using %d processors . . .\n", num_procs); /* Step 1: Get some JPEGs into memory, uncompressed */ for (i=0; i < num_inputs; i++) input_frames[i] = read_JPEG_file(argv[i+1+RUNS_COMMAND+RUNS_PROCS]); /* Step 2: Allocate output frames */ for (i=0; i < NUM_OUTPUTS; i++) output_frames[i] = allocate_frame(input_frames[i]->image_height, input_frames[i]->image_width, input_frames[i]->num_components); /* Loop over multiple runs, if desired */ total_time = 0.0; run = 0; while ((run < num_runs)) { /* Step 3: Record elapsed time */ gettimeofday(&start_time, NULL); /* Step 4: Call a user function! */ EEE4084F_parallel(); /* Step 5: Check & print elapsed time */ gettimeofday(&end_time, NULL); run_time = ((double)(end_time.tv_sec) + (double)(end_time.tv_usec)/1000000.0) - ((double)(start_time.tv_sec) + (double)(start_time.tv_usec)/1000000.0); fprintf(stderr, "%d. ELAPSED TIME = %20.3f sec\n", run, run_time); total_time += run_time; #ifdef NO_FIRST if (run == 0) { fprintf(stderr, " . . . first run discarded\n"); total_time = 0.0; } #endif run++; } /* Print out final, average time, if desired */ #ifdef NO_FIRST fprintf(stderr, "AVERAGE ELAPSED TIME = %20.3f seconds\n", total_time / ((double)(run - 1))); #else fprintf(stderr, "AVERAGE ELAPSED TIME = %20.3f seconds\n", total_time / ((double)run)); #endif /* Step 6: Write JPEGs out from memory buffers */ for (i=0; i < NUM_OUTPUTS; i++) write_JPEG_file(argv[argc - NUM_OUTPUTS + i], output_frames[i], OUT_QUALITY); destroy_frame(input_frames[0]); printf("input_frame[0]!\n"); destroy_frame(output_frames[0]); printf("output_frame[0]!\n"); }
int os9x_loadsnap(char *fname,u16 *snes_image,int *height) { if (read_JPEG_file (fname,snes_image,256,240,256,height)) return 1; return 0; }
GLubyte *readJpegFile(char *path,int &width, int &height, int &comps){ GLubyte *pxls=0; read_JPEG_file (path, &pxls, width, height, comps); return pxls; }
int main(int argc, char **argv) { unsigned int width = 0, height = 0, size = 0; float rate = 0.0; int ret = get_JPEG_info(argv[1], &width, &height, &size, &rate); //得到图片的大小长度宽度等属性 if (ret == 0) printf("widhth*height = %u * %u; size=%u; rate=%.2f\n", width, height, size, rate); unsigned char *bffer; bffer = read_JPEG_file(argv[1]); // u32_t buf32 = read_JPEG_file(argv[1]); frameBuffer = open_fb_ioctl(argv[2],&vinfo,&finfo); //打开/dev/fbx,并得到fb的属性vinfo,finfo,然后mmap到内存,返回内存的首地址 printf("x = %d y = %d\n",vinfo.xres,vinfo.yres); if(width != vinfo.xres || height != vinfo.yres) { printf("photo is worrg\n"); return 2; } printf("photo is ok\n"); fb_info jpeg_inf; jpeg_inf.w = width; jpeg_inf.h = height; u32_t *buf32; u16_t *buf16; printf("%d\n",vinfo.bits_per_pixel); switch(vinfo.bits_per_pixel){ case 32: buf32 = rgb24to32((u8_t *)bffer,jpeg_inf); printf("24 to 32\n"); break; case 24: // u24_t *buf = (u24_t *)buffer; printf("24 to 24\n"); break; case 16: // u16_t *buf = rgb24to16((u8_t *)buffer,jpeg_inf); printf("24 to 16\n"); break; default: printf("worrg /dev/fb.bits_per_pixel\n"); return 1; } // 随机产生特效 srand((unsigned)time(NULL)); switch(rand()%3) { case 0: down_sector(frameBuffer, width, height, buf32); break; case 1: left(frameBuffer, width, height, buf32); break; case 2: down(frameBuffer, width, height, buf32); break; } #if 0 //根据不同的显卡色位转换图片色位 int i = 0; int j = 0; for(j = 0;j < height;j ++) { for(i = 0; i < width; i++) { drawRect_rgbtest(i,width,j,buf32[j*width+i],frameBuffer); } usleep(5000); } //循环打印到屏幕 // int k = 0; // int i; // int j; // for(i = 0; i < width; i = i + 256) // { // for(j = 0;j < height;j++) // { // for(k = i; k < i + 256; k++) // { // drawRect_rgbtest(k,width,j,height,buf32[j*width+k],frameBuffer); // } // } // usleep(100000); // } sleep(10); #endif return 0; }
int main(int argc, char *argv[]) { int nprocs = sysconf(_SC_NPROCESSORS_ONLN); int c; char *inName = NULL; char *outName = NULL; int n=1; int width=-1,height=-1; frame_ptr frame; pixel_t *inPix=NULL; pixel_t *outPix=NULL; int *blur_radii = NULL; srand(5); while((c = getopt(argc, argv, "i:n:o:"))!=-1) { switch(c) { case 'i': inName = optarg; break; case 'o': outName = optarg; break; case 'n': n = atoi(optarg); break; } } if(inName==0 || outName == 0) { printf("need input filename and output filename\n"); return -1; } frame = read_JPEG_file(inName); if(!frame) { printf("unable to read %s\n", inName); exit(-1); } width = frame->image_width; height = frame->image_height; inPix = new pixel_t[width*height]; outPix = new pixel_t[width*height]; blur_radii = new int[width*height]; for (int i = 1; i <= nprocs; i++) { for(int y = 0; y < height; y+=(height/16)) { for(int x = 0; x < width; x+=(width/16)) { int r = 1; if(n > 1) { r += (rand() % n); } for(int yy = y; yy < std::min(height, (y + (height/16))); yy++) { for(int xx = x; xx < std::min(width, (x + (width/16))); xx++) { blur_radii[yy*width+xx] = r; } } } } convert_to_pixel(inPix, frame); double t0 = timestamp(); pthread_blur_frame(width, height, blur_radii, inPix, outPix, i); t0 = timestamp() - t0; printf("%d, %g sec\n", i,t0); } return 0; }