/*---------------------------------------------------------------------- Parameters: image - the image to write fname - the name of the file to write to. Description: write a hips image to file 'fname' ----------------------------------------------------------------------*/ int ImageWriteFrames(IMAGE *image, const char*fname, int start, int nframes) { IMAGE *tmp_image ; tmp_image = ImageAlloc(image->rows, image->cols,image->pixel_format,nframes); ImageCopyFrames(image, tmp_image, start, nframes, 0) ; ImageWrite(tmp_image, fname) ; ImageFree(&tmp_image) ; return(NO_ERROR); }
/*---------------------------------------------------------------------- Parameters: Description: ----------------------------------------------------------------------*/ KIMAGE * KernelImageRead(char *fname) { KIMAGE *kimage ; IMAGE *image ; image = ImageRead(fname) ; if (!image) return(NULL) ; kimage = KernelImageFromSeq(image) ; ImageFree(&image) ; return(kimage) ; }
/*----------------------------------------------------- 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); } }
/*---------------------------------------------------------------------- Parameters: Description: ----------------------------------------------------------------------*/ void KernelImageWrite(KIMAGE *kimage, char *fname, int argc, char *argv[]) { IMAGE *image ; int i ; char str[100] ; image = KernelImageToSeq(kimage) ; for (i = 0 ; i < argc ; i++) { argv[0] = argv[i] ; update_header(image, 1, argv) ; } if (kimage->fname) { free(image->orig_name) ; image->orig_name = STRCPALLOC(kimage->fname) ; } sprintf(str, "%d %d", kimage->rows, kimage->cols) ; image->seq_name = STRCPALLOC(str) ; ImageWrite(image, fname) ; ImageFree(&image) ; }
/*----------------------------------------------------- Parameters: Returns value: Description ------------------------------------------------------*/ IMAGE * ImageFRead(FILE *fp, const char*fname, int start, int nframes) { int ecode, end_frame, frame, count = 1; IMAGE *I ; byte *startpix, end = END_UNDEF; if (!fname) fname = "ImageFRead" ; I = (IMAGE *)calloc(1, sizeof(IMAGE)) ; if (!I) ErrorExit(ERROR_NO_MEMORY,"ImageFRead: could not allocate header\n") ; ecode = fread_header(fp, I, fname) ; if (ecode != HIPS_OK) ErrorExit(ERROR_NO_FILE, "ImageFRead: fread_header failed (%d)\n",ecode); if (endian == END_UNDEF) endian = FindMachineEndian(); if (findparam(I, "endian")) getparam(I, "endian", PFBYTE, &count, &end); if (start < 0) /* read all frames */ { start = 0 ; nframes = I->num_frame ; } else /* read only specified frames */ { if (fseek(fp, (long)I->sizeimage*(long)start, SEEK_CUR) < 0) { ImageFree(&I) ; ErrorReturn(NULL, (ERROR_BADFILE, "ImageFRead(%s, %d) - could not seek to specified frame", fname, start)) ; } } if (nframes < 0) nframes = I->num_frame - start + 1 ; end_frame = start + nframes - 1 ; if (end_frame >= I->num_frame) ErrorReturn(NULL, (ERROR_BADFILE, "ImageFRead(%s, %d) - frame out of bounds", fname,end_frame)); I->num_frame = nframes ; if (ImageAllocBuffer(I) != NO_ERROR) ErrorExit(Gerror, "ImageAllocBuffer failed") ; startpix = I->image ; for (frame = start ; frame <= end_frame ; frame++) { ecode = fread_image(fp, I, frame, fname) ; if (ecode != HIPS_OK) ErrorExit(ERROR_NO_FILE, "ImageFRead: fread_image failed (%d)\n", ecode); I->image += I->sizeimage ; } I->image = startpix ; /* We only swap endians if there wasn't an endian parameter and the image is invalid (ie. values in the image seem to be extreme) OR the endian of the machine does not match the endian of the image */ switch (end) { case END_UNDEF: if (!ImageValid(I)) ImageSwapEndian(I); break; case END_BIG: case END_SMALL: if (end != endian) ImageSwapEndian(I); break; } return(I) ; }
int main(int argc, char **argv) { IMAGE *I; int i; int ac, nargs ; char **av ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: nmovie.c,v 1.29.2.1 2011/09/28 21:14:00 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } XInit(&argc,&argv); if (argc<2) useage(); for (i=1;i<argc;i++) { I = ImageReadHeader(argv[i]); if (!I) ErrorExit(ERROR_NOFILE, "%s: could not read image file %s\n",Progname,argv[i]); switch (I->pixel_format) { case PFBYTE: case PFSHORT: case PFFLOAT: nocolor = 1 ; break ; default: break ; } if ((rows && (I->orows != rows)) || (cols && (I->ocols != cols))) { ErrorPrintf (ERROR_BADFILE, "%s: image %s dimensions (%d x %d) " "don't match first image (%d x %d)", Progname, argv[i],I->ocols, I->orows, cols, rows) ; ImageFree(&I) ; memmove(&argv[i], &argv[i+1], argc-i) ; i-- ; argc-- ; continue ; } nm_pfmt = MAX(nm_pfmt,I->pixel_format); rows = MAX(rows,I->orows); cols = MAX(cols,I->ocols); ImageFree(&I); } nframes = argc-1; XSetupDisplay(nframes); MakeDispNames(argc,argv); ConvertImages(nframes,argv); XtMapWidget(toplevel); XtAppMainLoop(xi.context); return 0; /* Make -Wall happy! */ }
/* Функция деинициализации информационного объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * vg4UNIT_INFO *Unit; * - указатель на контекст анимации: * vg4ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID InfoUnitClose( vg4UNIT_INFO *Unit, vg4ANIM *Ani ) { ImageFree(&Unit->And); ImageFree(&Unit->Xor); } /* End of 'InfoUnitClose' function */
int LPAFwriteImageAnswer(LPAF *lpaf, int current) { char *fullname, tmpname[100], fname[100] ; IMAGE Iheader, *I ; FILE *infp, *outfp ; int ecode, frame, nframes, *parms, i, current_frame, type ; LP_BOX *lpb ; struct extpar *xp ; fullname = lpaf->filelist[current] ; ImageUnpackFileName(fullname, ¤t_frame, &type, fname) ; if (type != HIPS_IMAGE) return(0) ; infp = fopen(fname, "rb") ; if (!infp) ErrorReturn(-1,(ERROR_NO_FILE, "LPAFwriteImageAnswer(%d): could not open %s", current, fname)) ; ecode = fread_header(infp, &Iheader, fname) ; if (ecode) { fclose(infp) ; ErrorReturn(-2, (ERROR_BADFILE, "LPAFwriteImageAnswer(%d): could not read header", current)); } fclose(infp) ; if (Iheader.numparam == 0) /* must make room for header in image file */ { lpafAllocParms(&Iheader) ; /* now copy the old image file to a new one which has room for parms */ nframes = Iheader.num_frame ; strcpy(tmpname, FileTmpName(NULL)) ; outfp = fopen(tmpname, "wb") ; Iheader.num_frame = 0 ; /* ImageAppend will bump num_frame on each call */ ecode = fwrite_header(outfp, &Iheader, tmpname) ; fclose(outfp) ; /* flush file */ fprintf(stderr, "rewriting image file to make room for parms...\n") ; for (frame = 0 ; frame < nframes ; frame++) { I = ImageReadFrames(fname, frame, 1) ; if (!I) ErrorExit(ERROR_BADFILE, "LPwriteImageAnswer: could not read frame"); ImageAppend(I, tmpname) ; ImageFree(&I) ; } FileRename(tmpname, fname) ; Iheader.num_frame = nframes ; /* reset correct # of frames */ } /* now put answer into header */ lpb = &lpaf->coords[current] ; for (frame = 0, xp = Iheader.params ; xp ; xp = xp->nextp) if (frame++ == current_frame) break ; parms = xp->val.v_pi ; parms[0] = lpb->xc ; parms[1] = lpb->yc ; for (i = 0 ; i < NPOINTS ; i++) { parms[2+2*i] = lpb->xp[i] ; parms[2+2*i+1] = lpb->yp[i] ; } ImageUpdateHeader(&Iheader, fname) ; free_hdrcon(&Iheader) ; return(1) ; }