void main() { int i, xoff; Image *image1, *image2; // image1 = ImageCreate(200,100); //ImageClear(image1, 210,180,40); /* mustard color */ //ImageWrite(image1, "try1.ppm"); //printf("created try1.ppm\n"); image2 = ImageRead("try1.ppm"); /* put a blue-ish stripe in image */ for (i = 0; i < 100; i++) { for (xoff = 45; xoff < 85; xoff++) { ImageSetPixel(image2, i+xoff, i, 0, 50); /* red channel */ ImageSetPixel(image2, i+xoff, i, 1, 80); /* green */ ImageSetPixel(image2, i+xoff, i, 2, 250); /* blue */ } } ImageWrite(image2, "try2.ppm"); printf("created try2.ppm\n"); }
void software_3x3_filter(const char *input) { filter_params filter; Image iImage = IMAGE_INITIALIZER; Image oImage = IMAGE_INITIALIZER; Benchmark b; int val = 0; initBenchmark(&b, "Software 3x3 Filter", ""); filter_Init(&filter, 4, 2, 1, 4); ImageRead(input, &iImage); startBenchmark(&b); val = filter_Execute(&filter, &iImage, &oImage); stopBenchmark(&b); if(val != 0) { fprintf(stderr, "software_3x3_filter: ERROR: Filter failed.\n"); } printBenchmark(&b); ImageWrite("software_3x3.tif",&oImage); ImageCleanup(&oImage); ImageCleanup(&iImage); }
int main(int argc,char**argv){ Image *dst,*src,*dst3; char filename[256]; src=ImageRead(argv[1]); dst=ImageAlloc(src->W,src->H); dst3=ImageAlloc(src->W*3,src->H*3); Process(dst,src); sprintf(filename,"p1_%s.%s",argv[2],argv[3]); ImageWrite(filename,dst); memset(filename,'0',sizeof(filename)); Process2(dst,src,100); sprintf(filename,"p2_%s_r00.%s",argv[2],argv[3]); ImageWrite(filename,dst); memset(filename,'0',sizeof(filename)); Process2(dst,src, 10); sprintf(filename,"p2_%s_0g0.%s",argv[2],argv[3]); ImageWrite(filename,dst); memset(filename,'0',sizeof(filename)); Process2(dst,src, 1); sprintf(filename,"p2_%s_00b.%s",argv[2],argv[3]); ImageWrite(filename,dst); memset(filename,'0',sizeof(filename)); Process2(dst,src,110); sprintf(filename,"p2_%s_rg0.%s",argv[2],argv[3]); ImageWrite(filename,dst); memset(filename,'0',sizeof(filename)); Process2(dst,src, 11); sprintf(filename,"p2_%s_0gb.%s",argv[2],argv[3]); ImageWrite(filename,dst); memset(filename,'0',sizeof(filename)); Process2(dst,src,101); sprintf(filename,"p2_%s_r0b.%s",argv[2],argv[3]); ImageWrite(filename,dst); memset(filename,'0',sizeof(filename)); Process2(dst,src,111); sprintf(filename,"p2_%s_rgb.%s",argv[2],argv[3]); ImageWrite(filename,dst); memset(filename,'0',sizeof(filename)); Process3(dst3,src,3); sprintf(filename,"p3_%s.%s",argv[2],argv[3]); ImageWrite(filename,dst3); memset(filename,'0',sizeof(filename)); return 0; }
static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url, video_format_t *p_fmt_in, video_format_t *p_fmt_out ) { block_t *p_block; picture_t *p_pic; stream_t *p_stream = NULL; uint64_t i_size; p_stream = vlc_stream_NewMRL( p_image->p_parent, psz_url ); if( !p_stream ) { msg_Dbg( p_image->p_parent, "could not open %s for reading", psz_url ); return NULL; } if( vlc_stream_GetSize( p_stream, &i_size ) || i_size > SSIZE_MAX ) { msg_Dbg( p_image->p_parent, "could not read %s", psz_url ); goto error; } p_block = vlc_stream_Block( p_stream, i_size ); if( p_block == NULL ) goto error; if( !p_fmt_in->i_chroma ) { char *psz_mime = stream_ContentType( p_stream ); if( psz_mime != NULL ) { p_fmt_in->i_chroma = image_Mime2Fourcc( psz_mime ); free( psz_mime ); } } vlc_stream_Delete( p_stream ); if( !p_fmt_in->i_chroma ) { /* Try to guess format from file name */ p_fmt_in->i_chroma = image_Ext2Fourcc( psz_url ); } p_pic = ImageRead( p_image, p_block, p_fmt_in, p_fmt_out ); return p_pic; error: vlc_stream_Delete( p_stream ); return NULL; }
/*---------------------------------------------------------------------- Parameters: Description: ----------------------------------------------------------------------*/ KIMAGE * KernelImageRead(char *fname) { KIMAGE *kimage ; IMAGE *image ; image = ImageRead(fname) ; if (!image) return(NULL) ; kimage = KernelImageFromSeq(image) ; ImageFree(&image) ; return(kimage) ; }
Exception ImageConstruct ( const char* sFilePathName, Image** ppImage_o ) { Exception e; *ppImage_o = (Image*)calloc( 1, sizeof(Image) ); if( !*ppImage_o ) return ERROR_ALLOC; e = ImageRead( sFilePathName, *ppImage_o ); if( e ) return free( *ppImage_o ), e; return 0; }
void Window::open() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath()); if(fileName.isEmpty()) { return; } pic::Image *pic_im = new pic::Image; ImageRead(fileName.toStdString(), pic_im); if(!pic_im->isValid()) { QMessageBox::information(this, tr("Simple QT"), tr("Cannot load %1.").arg(fileName)); delete pic_im; save_as_action->setEnabled(false); zoom_fit_action->setEnabled(false); zoom_in_action->setEnabled(false); zoom_out_action->setEnabled(false); zoom_original_action->setEnabled(false); gaussian_blur_action->setEnabled(false); scale_factor = 1.0; return; } if(last_filename != NULL) { delete last_filename; } last_filename = new QString(fileName); if(image != NULL) { delete image; } image = pic_im; update_pixmap(); save_as_action->setEnabled(true); zoom_fit_action->setEnabled(true); gaussian_blur_action->setEnabled(true); scale_factor = 1.0; update_actions(); if (!zoom_fit_action->isChecked()) image_label->adjustSize(); }
void software_hardware_exhaustive(const char *input) { #ifdef ZYNQ const int nRuns = 500; int i = 0; hardware_config hard_config; filter_params filter; Image iImage = IMAGE_INITIALIZER; Image oImage = IMAGE_INITIALIZER; int val = 0; volatile int j = 0; Benchmark b_software; Benchmark b_hardware; initBenchmark(&b_software, "Software 3x3 filter", ""); initBenchmark(&b_hardware, "Hardware 3x3 filter", ""); ImageRead(input, &iImage); filter_Init(&filter, 4, 2, 1, 4); val = hardware_filter_init(&iImage, &hard_config); fprintf(stdout, "Running hardware %d times\n", nRuns); startBenchmark(&b_hardware); for(i = 0; i < nRuns; i++) { val = hardware_filter_execute(&hard_config); } stopBenchmark(&b_hardware); val = hardware_filter_cleanup(&iImage, &oImage, &hard_config); fprintf(stdout, "Hardware runs complete\n"); fprintf(stdout, "Runnning software %d times\n", nRuns); for(i = 0; i < nRuns; i++) { val = filter_Execute(&filter, &iImage, &oImage); } stopBenchmark(&b_software); fprintf(stdout, "Software runs complete\n"); printBenchmarkAvg(&b_hardware,nRuns); printBenchmarkAvg(&b_software,nRuns); #else fprintf(stderr, "Hardware exhaustive run not supported on x86 platform\n"); #endif }
static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url, video_format_t *p_fmt_in, video_format_t *p_fmt_out ) { block_t *p_block; picture_t *p_pic; stream_t *p_stream = NULL; int i_size; p_stream = stream_UrlNew( p_image->p_parent, psz_url ); if( !p_stream ) { msg_Dbg( p_image->p_parent, "could not open %s for reading", psz_url ); return NULL; } i_size = stream_Size( p_stream ); p_block = block_New( p_image->p_parent, i_size ); stream_Read( p_stream, p_block->p_buffer, i_size ); if( !p_fmt_in->i_chroma ) { char *psz_mime = NULL; stream_Control( p_stream, STREAM_GET_CONTENT_TYPE, &psz_mime ); if( psz_mime ) p_fmt_in->i_chroma = image_Mime2Fourcc( psz_mime ); free( psz_mime ); } stream_Delete( p_stream ); if( !p_fmt_in->i_chroma ) { /* Try to guess format from file name */ p_fmt_in->i_chroma = image_Ext2Fourcc( psz_url ); } p_pic = ImageRead( p_image, p_block, p_fmt_in, p_fmt_out ); return p_pic; }
/*----------------------------------------------------- Parameters: Returns value: Description read an image from file and convert it to the specified format. ------------------------------------------------------*/ IMAGE * ImageReadType(const char*fname, int pixel_format) { IMAGE *Itmp, *I ; Itmp = ImageRead(fname) ; if (!Itmp) ErrorReturn(NULL, (ERROR_NO_FILE, "ImageReadType(%s, %d): could not read image", fname, pixel_format)) ; if (Itmp->pixel_format != pixel_format) { I = ImageAlloc(Itmp->rows, Itmp->cols, pixel_format, Itmp->num_frame) ; ImageCopy(Itmp, I) ; ImageFree(&Itmp) ; } else I = Itmp ; return(I) ; }
void ConvertImages(int nframes, char **argv) { IMAGE *I; int i, rows = 0, cols = 0; for (i=0;i<nframes;i++) { I = ImageRead(argv[i+1]); if (!I) ErrorExit(ERROR_NOFILE, "%s: could not read image file %s\n", Progname,argv[i+1]); if (i == 0) { rows = I->rows ; cols = I->cols ; } else if (rows != I->rows || cols != I->cols) { #if 0 ErrorExit ( ERROR_BADFILE, "%s: image %s dimensions (%d x %d) " "don't match first image (%d x %d)", Progname, argv[i+1],I->cols, I->rows, cols, rows) ; #else ErrorPrintf (ERROR_BADFILE, "%s: image %s dimensions (%d x %d) " "don't match first image (%d x %d)", Progname, argv[i+1],I->cols, I->rows, cols, rows) ; #endif argv++ ; nframes-- ; i-- ; continue ; } rgb2xcol(I,imgdata,i); ImageFree(&I); } }
void hardware_3x3_filter(const char *input) { #ifdef ZYNQ Image iImage = IMAGE_INITIALIZER; Image oImage = IMAGE_INITIALIZER; hardware_config hard_config; Benchmark b; int val = 0; initBenchmark(&b, "Hardware 3x3 Filter", ""); ImageRead(input, &iImage); if(hardware_filter_init(&iImage, &hard_config) != 0) { fprintf(stderr, "hardware_3x3_filter: ERROR: Failed to initialize hardware driver\n"); return; } startBenchmark(&b); val = hardware_filter_execute(&hard_config); stopBenchmark(&b); if(val != 0) { fprintf(stderr, "hardware_3x3_filter: ERROR: Filter failed.\n"); } val = hardware_filter_cleanup(&iImage, &oImage, &hard_config); if(val != 0) { fprintf(stderr, "hardware_3x3_filter: ERROR: Hardware filter failed to clean up.\n"); } printBenchmark(&b); ImageWrite("hardware_3x3.tif",&oImage); ImageCleanup(&oImage); ImageCleanup(&iImage); #else fprintf(stderr, "Hardware 3x3 filter not supported on x86 platform\n"); #endif }
void verify_hardware(const char *input) { #ifdef ZYNQ hardware_config hard_config; filter_params filter; Image iImage = IMAGE_INITIALIZER; Image oImage_software = IMAGE_INITIALIZER; Image oImage_hardware = IMAGE_INITIALIZER; unsigned char *hImage = NULL; unsigned char *sImage = NULL; int i = 0; int val = 0; int r = 0; int c = 0; int error = 0; ImageRead(input, &iImage); filter_Init(&filter, 4, 2, 1, 4); if(hardware_filter_init(&iImage, &hard_config) != 0) { fprintf(stderr, "hardware_3x3_filter: ERROR: Failed to initialize hardware driver\n"); return; } val = hardware_filter_execute(&hard_config); if(val != 0) { fprintf(stderr, "hardwaree_3x3_filter: ERROR: Filter failed.\n"); } val = hardware_filter_cleanup(&iImage, &oImage_hardware, &hard_config); val = filter_Execute(&filter, &iImage, &oImage_software); if(val != 0) { fprintf(stderr, "software_3x3_filter: ERROR: Filter failed.\n"); } hImage = oImage_hardware.data; sImage = oImage_software.data; for(r = 0; r < oImage_software.height; r++) { for(c = 0; c < oImage_software.width; c++, sImage++, hImage++) { if((r <= 2) || (r >= oImage_software.height-3)) { continue; } if((c <= 2) || (c >= oImage_software.width-3)) { continue; } if(*(hImage) != *(sImage)) { fprintf(stderr, "Mismatch: Row %d, Col %d, %d != %d\n", r, c, *sImage, *hImage); error = 1; } } } if(!error) { fprintf(stdout, "Images verified correct!\n"); } ImageCleanup(&oImage_software); ImageCleanup(&oImage_hardware); ImageCleanup(&iImage); #else fprintf(stderr, "Hardware verification of 3x3 filter not supported on x86 platform\n"); #endif }