#include "stdio.h" #include "stdlib.h" #include "string.h" #include "utils.h" #include "image.h" #include "readpic.h" /* SoftImage pic to ppm converter Also supports the raw format */ int main(int argc,char **argv) { int i,j; int raw = FALSE,flip = FALSE,alpha = FALSE; unsigned char r,g,b,a; Image *img; uint32 pixel; /* Check the arguments */ if (argc < 2) { fprintf(stderr,"Usage: %s [-a -h -f] picfilename\n",argv[0]); fprintf(stderr," -r create a raw file instead\n"); fprintf(stderr," -f flip the image about horizontal axis\n"); fprintf(stderr," -a include the alpha channel\n"); exit(-1); } /* Parse the command line options */ for (i=1;iwidth,img->height); printf("255\n"); } /* Write the binary data */ for (j=0;jheight;j++) { for (i=0;iwidth;i++) { if (flip) pixel = img->bitmap[(img->height-j-1)*img->width+i]; else pixel = img->bitmap[j*img->width+i]; a = (pixel & 0xff000000) >> 24; b = (pixel & 0x00ff0000) >> 16; g = (pixel & 0x0000ff00) >> 8; r = (pixel & 0x000000ff); if (alpha) { fwrite(&pixel,sizeof(uint32),1,stdout); } else { fwrite(&r,sizeof(char),1,stdout); fwrite(&g,sizeof(char),1,stdout); fwrite(&b,sizeof(char),1,stdout); } } } }