home *** CD-ROM | disk | FTP | other *** search
- /* wasp - copyright 1991 by Steven Reiz
- * see wasp.c for further info,
- * ppm.c, 24/7/91
- */
-
- #include "wasp.h"
- /* #include "ppm.sh" */
-
- static char typ[3];
- static long depth;
-
- #ifdef __STDC__
- read_ppm(void)
- #else
- read_ppm()
- #endif
- {
- char c;
- int y;
-
- cread(typ, 3);
- if (typ[0]!='P' || typ[1]<'0' || typ[1]>'9' || typ[2]!='\n') {
- lseek(infd, 0L, 0);
- return 0;
- }
- typ[2]='\0';
- xsz=getn(' ');
- ysz=getn('\n');
- depth=getn('\n')+1;
- printf("PPM/%s input; %ld x %ld, depth: %ld\n", typ, xsz, ysz, depth);
- fflush(stdout);
- if (!outfilename)
- exit(0);
- if (typ[1]!='6') {
- printe("types other than P6 are not supported\n");
- exit(1);
- }
- if (depth!=256) {
- printe("depths other than 256 are not supported\n");
- exit(1);
- }
- rgb=Malloc(ysz*sizeof(u_short *));
- for (y=0; y<ysz; ++y)
- rgb[y]=Malloc(xsz*sizeof(u_short));
- read_rgb24();
- return 1;
- }
-
-
- #ifdef __STDC__
- PRIVATE int getn(char terminator)
- #else
- PRIVATE int getn(terminator)
- char terminator;
- #endif
- {
- int n;
- char c;
-
- n=0;
- while (1) {
- cread(&c, 1);
- if (c<'0' || c>'9')
- break;
- n=10*n+c-'0';
- }
- assert(c==terminator);
- return n;
- }
-
-
- #ifdef __STDC__
- read_rgb24(void)
- #else
- read_rgb24()
- #endif
- {
- char *buf;
- int width, color;
- int y, x;
- char *bufp;
- u_short *p;
-
- width=xsz*3;
- buf=Malloc(width);
- init_counter(0, (int)ysz, 10, NULL);
- for (y=0; y<ysz; ++y) {
- counter();
- cread(buf, width);
- x=xsz-1;
- bufp=buf;
- p=rgb[y];
- do {
- color=(*bufp++ & 0xf0)<<4;
- color|= *bufp++ & 0xf0;
- color|=(*bufp++ >>4) & 0x0f;
- *p++ =color;
- } while (--x>=0);
- }
- erase_counter(NULL);
- free(buf);
- }
-