int main(int argc, const char ** argv) { FILE * ifP; struct CmdlineInfo cmdline; struct SbigHeader hdr; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); readSbigHeader(ifP, &hdr); pm_message("SBIG '%s' %ux%u %s image, saturation level = %u", (hdr.haveCameraType ? hdr.cameraType : "ST-?"), hdr.cols, hdr.rows, hdr.isCompressed ? "compressed" : "uncompressed", hdr.maxval); if (hdr.maxval > PGM_OVERALLMAXVAL) { pm_error("Saturation level (%u levels) is too large" "This program's limit is %u.", hdr.maxval, PGM_OVERALLMAXVAL); } pgm_writepgminit(stdout, hdr.cols, hdr.rows, hdr.maxval, 0); writeRaster(ifP, hdr, stdout); pm_close(ifP); pm_close(stdout); return 0; }
void writeImage(char *fileName, IMAGE *image, bool printInfo) { if(printInfo) printf("Writing File...\n"); BMPHeader bmpHeader; FileHeader fileHeader; createDataHeader(image->width, image->height, image->numColors, &bmpHeader); createFileHeader(&bmpHeader,&fileHeader); FILE *fhandle = fopen(fileName,"wb"); writeFileHeader(fhandle, fileHeader, printInfo); writeDataHeader(fhandle, bmpHeader, printInfo); if(image->numColors == 1) writeGreyPalette(fhandle); writeRaster(fhandle, image, printInfo); fclose(fhandle); }