//================================================================== void SaveJPEG( const Image &img, const char *pFName ) { // make sure it's RGB if ( !img.IsSamplesNames( "rgb" ) || img.IsSamplesType( Image::ST_U8 ) ) { Image tmpImg( img.mWd, img.mHe, 3, Image::ST_U8, -1, "rgb" ); DIMG::ConvertImages( tmpImg, img ); write_JPEG_file( pFName, 100, (const JSAMPLE *)tmpImg.GetPixelPtrR(0,0), img.mWd, img.mHe ); } else { write_JPEG_file( pFName, 100, (const JSAMPLE *)img.GetPixelPtrR(0,0), img.mWd, img.mHe ); } }
virtual WriteResult writeImage(const osg::Image& img,std::ostream& fout,const osgDB::ReaderWriter::Options *options) const { osg::ref_ptr<osg::Image> tmp_img = new osg::Image(img); tmp_img->flipVertical(); WriteResult::WriteStatus ws = write_JPEG_file(fout, *(tmp_img.get()), getQuality(options)); return ws; }
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; }
int os9x_savesnap() { u16 *snes_image; if (os9x_softrendering<2) snes_image=(u16*)(0x44000000+512*272*2*2); else snes_image=(u16*)(0x44000000+2*512*272*2+256*240*2+2*256*256*2); write_JPEG_file ((char*)S9xGetSaveFilename(".jpg"),75,snes_image,256,os9x_snesheight,256); return 0; }
//************************************************************ //write jpeg file //************************************************************ void writeJpegFile(char *filename,double jpeg_quality) { int image_width; int image_height; GLubyte *rgb=readPixels(image_width, image_height); if(rgb){ write_JPEG_file (filename, rgb, image_width,image_height,jpeg_quality); FREE(rgb); } }
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; }
int main(int argc, char **argv) { int fd; fprintf(stderr, "Test stderr.\n"); if (argc < 2) { printf("Usage: %s <FILE> \n", argv[0]); return 0; } printf("output file: %s\n", argv[1]); //fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0644); //if (fd < 0) { // fprintf(stderr, " open %s failed ", argv[1]); // perror(" "); // //dlclose(dlp); // return -1; //} screen2image_init("/dev/graphics/fb0"); void *raw_image = screen2image_allocbuf(); screen2image_getscreensize(&image_width, &image_height); int bufsize = image_width * image_height * sizeof(JSAMPLE) * 3; image_buffer = malloc(bufsize); int i; for (i = 0; i < 30; i++) // Performance Test { int img_size = screen2image_getscreen(raw_image); int bpp = screen2image_getscreenbpp(); if (img_size > image_width * image_height * (bpp / 8)) { img_size = image_width * image_height * (bpp / 8); } //screen2image_writetofile(fd); int ret = screen2image_pixel16to24pack(raw_image, img_size, image_buffer, bufsize); if (ret < 0) { printf("pixel conversion failed.\n"); break; } char jpgname[200]; sprintf(jpgname, "%s_%03d.jpg", argv[1], i); //size_t imglen = lseek(fd, 0, SEEK_END); //image_buffer = mmap(NULL, imglen, PROT_READ, MAP_PRIVATE, fd, 0); write_JPEG_file(jpgname, 9); } free(image_buffer); screen2image_freebuf(raw_image); screen2image_destroy(); //munmap(image_buffer, imglen); //close(fd); //dlclose(dlp); return 0; }
/* 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 main(void) { write_JPEG_file(); }
//将采集好的数据放到文件中 int process_image(void *addr,int length) { FILE *fp; static int num = 0; char picture_name[20]; printf("process-image len=%d\n",length); //#define YUYV_2_JPG_FILE #ifdef YUYV_2_JPG_FILE //jpg压缩文件 sprintf(picture_name,"picture%d.jpg",num++); u8 s[640*480*3]; int i=0;int j=0;int k=0; u8 y1,u,y2,v; //依次读取4字节/2像素 for(i=0;i<c_hight;i++) //行 for(j=0;j<c_width*2;){ //列 y1=*(int*)(addr+i*c_width*2+j+0); u=*(int*)(addr+i*c_width*2+j+1); y2=*(int*)(addr+i*c_width*2+j+2); v=*(int*)(addr+i*c_width*2+j+3); j+=4;//source :move to next 2 pixels (4byte) yuyv2rgb(y1,u,v ,&s[k+0],&s[k+1],&s[k+2]); yuyv2rgb(y1,u,v ,&s[k+3],&s[k+4],&s[k+5]); k+=6;//detct :move to next 2 pixels (6byte) } // char *d[c_width*c_hight*3]; // int i=0;int j=0; // //YUYV ->YUV YUV(yuv422) // for(i=0;i<length;i+=4,j+=6){ // d[j+0]=*((char *)addr+i+0); //Y1 // d[j+1]=*((char *)addr+i+1); //U1 // d[j+2]=*((char *)addr+i+3); //V1 // d[j+3]=*((char *)addr+i+2); //Y2 // d[j+4]=*((char *)addr+i+1); //U1 // d[j+5]=*((char *)addr+i+3); //V1 // } //数据格式RGB24 write_JPEG_file(s,c_width,c_hight,picture_name,100); usleep(500); #else #define CHANGE_PIC_FORMAT_TO_BMP //转换图像格式YUYV RGB888 bmpfile #ifdef CHANGE_PIC_FORMAT_TO_BMP //bmp位图格式文件 sprintf(picture_name,"picture%d.bmp",num++); if((fp = fopen(picture_name,"w")) == NULL){ perror("Fail to fopen"); exit(EXIT_FAILURE); } //每次读取4字节(2像素)的YUYV格式:Y0 U0 Y1 V0 //写入6字节(2像素) BGR BGR u8 s[640*480*3]; int i=0;int j=0;int k=0; u8 y1,u,y2,v; //依次读取4字节/2像素 //printf("size of head=%d",sizeof(head));// write_file_head(&fp,c_width,c_hight); //文件头 for(i=c_hight-1;i>=0;i--) //行 从最 底行->顶行 *** bottom -> top for(j=0;j<c_width*2;){ //列 2byte/pix lift -> right y1=*(int*)(addr+i*c_width*2+j+0); u=*(int*)(addr+i*c_width*2+j+1); y2=*(int*)(addr+i*c_width*2+j+2); v=*(int*)(addr+i*c_width*2+j+3); j+=4;//source :move to next 2 pixs (4byte) //RGB->BGR(windows bmp file format!) yuyv2rgb(y1,u,v ,&s[k+2],&s[k+1],&s[k+0]); yuyv2rgb(y1,u,v ,&s[k+5],&s[k+4],&s[k+3]); k+=6;//detct :move to next 2 pixs (6byte) } if(fwrite(s,sizeof(s),1,fp)<=0){ perror("write data "); } #else //原始格式图片 sprintf(picture_name,"picture%d.raw",num++); if((fp = fopen(picture_name,"w")) == NULL){ perror("Fail to fopen"); exit(EXIT_FAILURE); } fwrite(addr,length,1,fp); #endif usleep(500); fclose(fp); #endif printf("end of process-image\n"); return 0; }
int change_res_JPEG_F (FILE *infile, char ** output, int *output_size) { /* This struct contains the JPEG decompression parameters and pointers to * working space (which is allocated as needed by the JPEG library). */ struct jpeg_decompress_struct cinfo; /* We use our private extension JPEG error handler. * Note that this struct must live as long as the main JPEG parameter * struct, to avoid dangling-pointer problems. */ struct my_error_mgr jerr; /* More stuff */ JSAMPARRAY buffer; /* Output row buffer */ int row_stride; /* physical row width in output buffer */ /* Step 1: allocate and initialize JPEG decompression object */ /* We set up the normal JPEG error routines, then override error_exit. */ cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object, close the input file, and return. */ jpeg_destroy_decompress(&cinfo); fclose(infile); return 0; } /* Now we can initialize the JPEG decompression object. */ jpeg_create_decompress(&cinfo); /* Step 2: specify data source (eg, a file) */ jpeg_stdio_src(&cinfo, infile); /* Step 3: read file parameters with jpeg_read_header() */ (void) jpeg_read_header(&cinfo, TRUE); /* We can ignore the return value from jpeg_read_header since * (a) suspension is not possible with the stdio data source, and * (b) we passed TRUE to reject a tables-only JPEG file as an error. * See libjpeg.doc for more info. */ /* Step 4: set parameters for decompression */ /* In this example, we don't need to change any of the defaults set by * jpeg_read_header(), so we do nothing here. */ /* Step 5: Start decompressor */ (void) jpeg_start_decompress(&cinfo); /* We can ignore the return value since suspension is not possible * with the stdio data source. */ /* We may need to do some setup of our own at this point before reading * the data. After jpeg_start_decompress() we have the correct scaled * output image dimensions available, as well as the output colormap * if we asked for color quantization. * In this example, we need to make an output work buffer of the right size. */ /* JSAMPLEs per row in output buffer */ row_stride = cinfo.output_width * cinfo.output_components; buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, cinfo.output_height); /* Step 6: while (scan lines remain to be read) */ /* jpeg_read_scanlines(...); */ while (cinfo.output_scanline < cinfo.output_height) { /* jpeg_read_scanlines expects an array of pointers to scanlines.*/ (void) jpeg_read_scanlines(&cinfo, &buffer[cinfo.output_scanline], cinfo.output_height); } /* Perform the size reduction */ write_JPEG_file(buffer, cinfo.output_width, cinfo.output_height, cinfo.output_components, cinfo.out_color_space, LOW_QUALITY, (JOCTET **)output, output_size); /* Step 7: Finish decompression */ (void) jpeg_finish_decompress(&cinfo); /* YANNIS: What a deranged idea! Buffers allocated using the JPEG allocator are freed when the "jpeg_finish_decompress" routine is called, not when "jpeg_destroy_decompress" is called! */ /* Step 8: Release JPEG decompression object */ /* This is an important step since it will release a good deal of memory. */ jpeg_destroy_decompress(&cinfo); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, * so as to simplify the setjmp error logic above. (Actually, I don't * think that jpeg_destroy can do an error exit, but why assume anything...) */ fclose(infile); /* At this point you may want to check to see whether any corrupt-data * warnings occurred (test whether jerr.pub.num_warnings is nonzero). */ /* And we're done! */ return 1; }
int bmJpegWriteJfif( const BitmapDescription * bd, const unsigned char * buffer, SimpleOutputStream * sos ) { int rval= 0; BmJpegOutputDestination bjod; bjod.bjodBd= bd; bjod.bjodBuffer= buffer; bjod.bjodSos= sos; bjod.bjodScratchBuffer= (unsigned char *)0; bjod.pub.init_destination= bmJpegInitDestination; bjod.pub.empty_output_buffer= bmJpegWriteOutputBuffer; bjod.pub.term_destination= bmJpegFinishDestination; switch( bd->bdColorEncoding ) { case BMcoBLACKWHITE: bjod.bjodScratchBuffer= malloc( bd->bdBytesPerRow ); if ( ! bjod.bjodScratchBuffer ) { LXDEB(bd->bdBytesPerRow,bjod.bjodScratchBuffer); rval= -1; goto ready; } break; case BMcoRGB8PALETTE: bjod.bjodScratchBuffer= malloc( 3* bd->bdPixelsWide ); if ( ! bjod.bjodScratchBuffer ) { LXDEB(bd->bdBytesPerRow,bjod.bjodScratchBuffer); rval= -1; goto ready; } break; case BMcoRGB: if ( bd->bdHasAlpha ) { bjod.bjodScratchBuffer= malloc( 3* bd->bdPixelsWide ); if ( ! bjod.bjodScratchBuffer ) { LXDEB(bd->bdBytesPerRow,bjod.bjodScratchBuffer); rval= -1; goto ready; } } break; default: break; } if ( write_JPEG_file( &bjod ) ) { LDEB(1); rval= -1; goto ready; } ready: if ( bjod.bjodScratchBuffer ) { free( bjod.bjodScratchBuffer ); } return rval; }