include include include include "rastoim.h" procedure t_rashead () # Display the header of a rasterfile, optionally including the colormap. # See rastoim for more information. # 12/22/92 ZGL # 12/29/92 Reorganize slightly and add more map type output. # 12/31/92 More wordy output. pointer sp pointer rasfile # Raster file name pointer rf # Raster file descriptor int width, height # Image size int depth # Image depth (bits per pixel) int length # Data size int type # Raster file type int maptype # Color map type int maplength # Map size int verbosity # Verbosity of output int bytsiz, chsiz, nch int totsiz pointer rs, rb int open(), clgeti(), read(), miipksize() begin call smark (sp) call salloc (rasfile, SZ_FNAME, TY_CHAR) # Get task parameters call clgstr ("rasfile", Memc[rasfile], SZ_FNAME) verbosity = clgeti ("verbosity") if (verbosity > 1) { call printf ("%s\n") call pargstr (Memc[rasfile]) call flush (STDOUT) } # Open the rasterfile rf = open (Memc[rasfile], READ_ONLY, BINARY_FILE) # Read the header -- fixed, eight ints call rh_rashead (rf, width, height, length, depth, type, maptype, maplength, verbosity) if (verbosity > 1) { # Full file size (color map + pixels, excluding header) # In chars -- the number of chars to read totsiz = maplength + length bytsiz = ((totsiz - 1) / 2 + 1) * 2 chsiz = miipksize (bytsiz, MII_BYTE) call calloc (rb, chsiz, TY_CHAR) call calloc (rs, bytsiz, TY_SHORT) # Read the colormap and image nch = read (rf, Memc[rb], chsiz) if (verbosity > 2) { call printf ("Read %d chars\n") call pargi (nch) } if (maplength > 0 && maptype != RMT_NONE) { # Unpack the colormap call miiupk (Memc[rb], Mems[rs], bytsiz, MII_BYTE, TY_SHORT) # Print the colormap call rh_prtmap (Mems[rs], maplength) } } call sfree (sp) end procedure rh_rashead (rf, width, height, length, depth, type, maptype, maplength, verbosity) # Read the rasterfile header (8 ints) pointer rf # Raster file descriptor int width, height # Image size int length # Data size int depth # Image depth (bits per pixel) int type # Raster file type int maptype # Color map type int maplength # Map size int verbosity # Verbosity of output pointer sp pointer rh # Rasterfile header descriptor pointer rts # Ras type string pointer rds # Ras type string pointer mts # Map type string int read() begin call smark (sp) call salloc (rh, SZ_RASHEAD, TY_INT) call salloc (rts, SZ_LINE, TY_CHAR) call salloc (rds, SZ_LINE, TY_CHAR) call salloc (mts, SZ_LINE, TY_CHAR) # Read the header (8 ints), filling the header structure if (read (rf, Memi[rh], SZ_RASHEAD*SZ_INT) != SZ_RASHEAD*SZ_INT) call error (0, "Can't read rasterfile header") if (RAS_MAGIC(rh) != RF_MAGIC_NUM) call error (0, "Not a rasterfile") width = RAS_WIDTH(rh) height = RAS_HEIGHT(rh) type = RAS_TYPE(rh) switch (RAS_TYPE(rh)) { case RT_OLD: call strcpy ("Old", Memc[rts], SZ_LINE) case RT_STANDARD: call strcpy ("Standard", Memc[rts], SZ_LINE) case RT_BYTE_ENCODED: call strcpy ("Byte-Encoded", Memc[rts], SZ_LINE) case RT_FORMAT_RGB: call strcpy ("RGB, not BGR", Memc[rts], SZ_LINE) case RT_FORMAT_TIFF: call strcpy ("TIFF", Memc[rts], SZ_LINE) case RT_FORMAT_IFF: call strcpy ("IFF", Memc[rts], SZ_LINE) default: call strcpy ("Invalid", Memc[rts], SZ_LINE) } if (RAS_TYPE(rh) == RT_EXPERIMENTAL) call strcpy ("Experimental", Memc[rts], SZ_LINE) if (RAS_TYPE(rh) == RT_OLD) # Compute the file size length = RAS_WIDTH(rh) * RAS_HEIGHT(rh) * RAS_DEPTH(rh) / 8 else length = RAS_LENGTH(rh) depth = RAS_DEPTH(rh) switch (depth) { case 1: call strcpy ("Bitmap", Memc[rds], SZ_LINE) case 8: call strcpy ("Gray/Mapped", Memc[rds], SZ_LINE) case 24: call strcpy ("RGB Color", Memc[rds], SZ_LINE) } maptype = RAS_MAPTYPE(rh) maplength = RAS_MAPLENGTH(rh) switch (maptype) { case RMT_RAW: call strcpy ("Raw", Memc[mts], SZ_LINE) case RMT_NONE: call strcpy ("None", Memc[mts], SZ_LINE) case RMT_EQUAL_RGB: call strcpy ("Equal RGB", Memc[mts], SZ_LINE) default: call strcpy ("Invalid", Memc[mts], SZ_LINE) } call printf ("%d x %d File size: %d\n") call pargi (width) call pargi (height) call pargi (length) call printf ("Depth: %d bits/pixel %s\n") call pargi (depth) call pargstr (Memc[rds]) call printf ("Raster type: %d %s\n") call pargi (type) call pargstr (Memc[rts]) call printf ("Color map: type %d %s, size %d\n") call pargi (maptype) call pargstr (Memc[mts]) call pargi (maplength) end procedure rh_prtmap (colormap, maplength) # Print the rasterfile colormap short colormap[ARB] # Colorsap int maplength # Map size int elem int goff, boff begin goff = maplength / 3 boff = 2 * goff do elem = 1, goff { call printf ("%3d %3d %3d %3d\n") call pargi (elem) call pargs (colormap[elem]) call pargs (colormap[elem+goff]) call pargs (colormap[elem+boff]) } end