This is contrast.c in view mode; [Download] [Up]
/*
* contrast.c
*
* Jim Kiraly
* July 19 1991
*
* This routine will adjust the contrast of an image
*
* I am fairly sure that this doesn't work correctly.
*
*/
#include <stdio.h>
extern FILE *in, *out;
/*
* contImage - adjust the contrast of an image
*
*/
int contImage ( colors, number )
int colors;
char *number;
{
int count, j, cValue;
int max[3], low[3], mid[3], temp;
unsigned char rgbs[3][256];
fprintf ( stderr, "adjusting contrast...\n" );
sscanf ( number, "%x", &cValue );
max[0] = max[1] = max[2] = 0;
low[0] = low[1] = low[2] = 0;
for (count=0; count<colors; count++)
for (j=0; j<=2; j++) {
rgbs[j][count] = getc ( in );
if (rgbs[j][count]>max[j])
max[j]=rgbs[j][count];
if (rgbs[j][count]<low[j])
low[j]=rgbs[j][count];
}
for (j=0; j<=2; j++)
mid[j]=(low[j] + max[j])/2;
for (count=0; count<colors; count++)
for (j=0; j<=2; j++) {
if (mid[j]<1)
mid[j]=1;
if (rgbs[j][count]>mid[j])
temp = rgbs[j][count] + (cValue * ((rgbs[j][count]+1)/mid[j]));
else
if (rgbs[j][count]<mid[j])
temp = rgbs[j][count] - (cValue * ((rgbs[j][count]+1)/mid[j]));
else
temp = rgbs[j][count];
if (temp>255) temp = 255;
if (temp<0) temp = 0;
rgbs[j][count] = (unsigned char) temp;
putc ( rgbs[j][count], out );
}
return 1;
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.