/*----------------------------------------------------- Parameters: Returns value: Description ------------------------------------------------------*/ int ImageFWrite(IMAGE *I, FILE *fp, const char*fname) { byte *image ; int ecode, type, frame; char buf[100] ; if (!fname) fname = "ImageFWrite" ; strcpy(buf, fname) ; /* don't destroy callers string */ ImageUnpackFileName(buf, &frame, &type, buf) ; switch (type) { case RGBI_IMAGE: RGBwrite(I, buf, frame) ; break ; case TIFF_IMAGE: TiffWriteImage(I, buf, frame) ; break ; default: case JPEG_IMAGE: JPEGWriteImage(I, buf, frame); break; case PGM_IMAGE: PGMWriteImage(I, buf, frame); break; case PPM_IMAGE: PPMWriteImage(I, buf, frame); break; case HIPS_IMAGE: if (endian == END_UNDEF) endian = FindMachineEndian(); if (findparam(I,"endian")) clearparam(I,"endian"); /* Clear any existing endian parameter */ setparam(I, "endian", PFBYTE, 1, endian); ecode = fwrite_header(fp,I,"fwrite") ; if (ecode != HIPS_OK) ErrorExit(ERROR_NO_FILE,"ImageFWrite: fwrite_header failed (%d)\n",ecode); image = I->image ; for (frame = 0 ; frame < I->num_frame ; frame++) { ecode = fwrite_image(fp, I, frame, "fwrite") ; if (ecode != HIPS_OK) ErrorExit(ERROR_NO_FILE, "ImageFWrite: fwrite_image frame %d failed (%d)\n",ecode,frame); I->image += I->sizeimage ; /* next frame */ } I->image = image ; break ; } return(0) ; }
int Image32::WriteImage(char* fileName) { char* ext=GetFileExtension(fileName); int ret=0; if(!(width()*height())) { delete[] ext; return 0; } if(!strcasecmp(ext,"bmp")) { ret=BMPWriteImage(*this,fileName); } else if(!strcasecmp(ext,"jpg") || !strcasecmp(ext,"jpeg")) { ret=JPEGWriteImage(*this,fileName); } else {}; // Unknown format delete[] ext; return ret; }