/*********************************************************/ /* program 27: SGI RGB read/write functions */ /*********************************************************/ typedef struct /* SGI RGB header structure */ { short int magic; short int type; short int dim; short int xsize; short int ysize; short int zsize; long int min; long int max; long int waste; char name[80]; long int space[102]; } SGI_HEADER; void read_sgi_header ( fp, xs, ys, pl, type ) /* ******************************************************* */ long int fp; /* file pointer */ long int *xs,*ys; /* x,y size */ long int *pl; /* plane count */ long int *type; /* file type */ { SGI_HEADER header; read ( fp, &header, sizeof(header) ); if (header.magic != 474) { printf("INVALID SGI MAGIC NUMBER: %d\n",header.magic); } else { *xs = (long)header.xsize; *ys = (long)header.ysize; *pl = (long)header.zsize; *type = (long)header.type; if (*type != 1) { printf("SGI TYPE NOT 1: %d\n",header.type); } } return; } void read_sgi_data ( fp, xs, ys, pl, type, r, g, b ) /* ******************************************************* */ long int fp; /* file pointer */ long int xs,ys; /* x,y size */ long int pl; /* plane count */ long int type; /* file type */ unsigned char *r,*g,*b; /* data buffer pointers */ { long int c; unsigned char *d; long int y; for ( c = 0; c < pl; c++ ) { if (c == 0) d = r; if (c == 1) d = g; if (c == 2) d = b; d = d + ((ys - 1) * xs); for ( y = 0; y < ys; y++ ) { read ( fp, d, xs ); d = d - xs; } } return; } void write_sgi_header ( fp, xs, ys, pl, type ) /* ******************************************************* */ long int fp; /* file pointer */ long int xs,ys; /* x,y size */ long int pl; /* plane count */ long int type; /* file type */ { SGI_HEADER header; long int i; header.magic = 474; header.type = type; header.dim = 3; header.xsize = xs; header.ysize = ys; header.zsize = pl; header.min = 0; header.max = 255; header.waste = 0; for ( i = 0; i < 80; i++ ) { header.name[i] = 0; } for ( i = 0; i < 102; i++ ) { header.space[i] = 0; } write ( fp, &header, sizeof(header) ); return; } void write_sgi_data ( fp, xs, ys, pl, r, g, b, type ) /* ******************************************************* */ long int fp; /* file pointer */ long int xs,ys; /* x,y size */ long int pl; /* plane count */ unsigned char *r,*g,*b; /* data buffer pointers */ long int type; /* file type */ { long int c; unsigned char *d; long int y; for ( c = 0; c < pl; c++ ) { if (c == 0) d = r; if (c == 1) d = g; if (c == 2) d = b; d = d + ((ys - 1) * xs); for ( y = 0; y < ys; y++ ) { write ( fp, d, xs ); d = d - xs; } } return; }