This is image.c in view mode; [Download] [Up]
/* * image.c * * Jim W Kiraly * July 29 1991 * * includes and other things * */ #include <stdio.h> extern FILE *in, *out; /* * invertImage - invert an image by 255-current color * */ int invertImage ( colors ) int colors; { int count; unsigned char byte; fprintf ( stderr, "inverting...\n" ); for (count=1; count<=colors*3; count++) { byte = getc(in); putc ( 255-byte, out ); } return 1; } /* * greyImage - grey scale an image by using the highest of the rgb's * */ int greyImage ( colors ) int colors; { int count, temp; unsigned char rgb[3]; fprintf ( stderr, "grey scaling...\n" ); for (count=1; count<=colors; count++) { rgb[0] = getc (in); rgb[1] = getc (in); rgb[2] = getc (in); temp = 0.30*rgb[0] + 0.59*rgb[1] + 0.11*rgb[2]; if (temp>255) rgb[0] = 255; else rgb[0] = (unsigned char) temp; putc ( rgb[0], out ); putc ( rgb[0], out ); putc ( rgb[0], out ); } return 1; } /* * rgbImage - modify the red, green, and blue of an image * */ int rgbImage ( colors, red, green, blue ) int colors; char *red; char *green; char *blue; { int rValue, gValue, bValue; int count, temp; unsigned char rgb[3], abRed=0, abGreen=0, abBlue=0; static char *prm[] = { "adjusted", "ABSOLUTE" }; fprintf ( stderr, "modifying rgb's...\n" ); if (!red) rValue=0; else { if (red[0]!='+' && red[0]!='-') abRed=1; sscanf ( red, "%x", &rValue ); } if (!blue) bValue=0; else { if (blue[0]!='+' && blue[0]!='-') abBlue=1; sscanf ( blue, "%x", &bValue ); } if (!green) gValue=0; else { if (green[0]!='+' && green[0]!='-') abGreen=1; sscanf ( green, "%x", &gValue ); } fprintf ( stderr, "Red modification - %s %03d\n", prm[abRed], rValue ); fprintf ( stderr, "Green modification - %s %03d\n", prm[abGreen], gValue ); fprintf ( stderr, "Blue modification - %s %03d\n", prm[abBlue], bValue ); for (count=1; count<=colors; count++) { rgb[0] = getc (in); rgb[1] = getc (in); rgb[2] = getc (in); temp = rgb[0]; if (abRed) /* Adjust the red */ temp=rValue; else if (temp+rValue>255) temp = 255; else if (temp+rValue<0) temp = 0; else temp += rValue; rgb[0] = (unsigned char) temp; temp = rgb[1]; if (abGreen) /* Adjust the green */ temp=gValue; else if (temp+gValue>255) temp=255; else if (temp+gValue<0) temp=0; else temp += gValue; rgb[1] = (unsigned char) temp; temp = rgb[2]; if (abBlue) /* Adjust the blue */ temp=bValue; else if (temp+bValue>255) temp=255; else if (temp+bValue<0) temp=0; else temp += bValue; rgb[2] = (unsigned char) temp; putc ( rgb[0], out ); putc ( rgb[1], out ); putc ( rgb[2], out ); } return 1; }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.