/* * lpscl.c: Log Polar Mapping. * * May.15,'94. Oshiro. * Oct. 6,'94. Oshiro. 入力ファイルの形式を ppm にした. */ static char rcsid[]="$Id: lpscl.c,v 1.1 1995/05/10 18:19:27 oshiro Exp oshiro $"; #include #include #include #include #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 int main(int argc, char **argv) { FILE *fp; int width, height; int trans_length; long x, y; int uwidth, vwidth; int img_type, depth; long u, v; long len; char *data; char *fname; if (argc != 3 && argc != 4) { fprintf(stderr, "Usage: lpscl lpwidth lpheight [infile]\n"); exit(EXIT_FAILURE); } vwidth=atoi(argv[1]); uwidth=atoi(argv[2]); if (argc==4) { fname=argv[3]; fp=OpenAndCheckPPMFile(fname, &img_type, &width, &height, &depth); if (fp==NULL) { fprintf(stderr, "lpscl: Incorrect ppm file (%s).\n", fname); exit(EXIT_FAILURE); } } else { fp=stdin; if (CheckPPMFile(fp, &img_type, &width, &height, &depth)!=0) { fprintf(stderr, "lpscl: Incorrect ppm file (stdin).\n"); exit(EXIT_FAILURE); } } data=malloc(sizeof(char)*(long)width*height*3); if (data == NULL) { fprintf(stderr, "lpscl: Fatal: Not enough memory.\n"); fclose(fp); exit(EXIT_FAILURE); } len=fread(data, sizeof(char), (long)width*height*3, fp); fclose(fp); if (len < width*height) { fprintf(stderr, "lpscl: Warning: Not enough data.\n"); } trans_length=((width>height)? width:height)/2; printf("P6\n%d %d\n255\n", uwidth, vwidth); for (v=0; v=width/2 || y<=-height/2 || y>=height/2) { putchar(0); putchar(0); putchar(0); continue; } y+=height/2; y=height-y-1; x+=width/2; putchar(data[y*(width*3) + x*3 ]); putchar(data[y*(width*3) + x*3+1]); putchar(data[y*(width*3) + x*3+2]); } } return(EXIT_SUCCESS); }