25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more...
Home   Projects   Up   Sitemap   Search   Blog   Forum+Chat   About Us   Privacy   Terms of Use   Feedback   FAQ   Images   Services   Payments   Humor   Music

Invert the "elevation" values in a Mandelbrot .PIC graphics file, DeSmet C

My Mandelbrot display program saves the escape times 0-255 to a .PIC file. When the .PIC file is displayed graphically, the escape times are mapped to colors. 

This program inverts all the escape times in a .PIC file so that the range 0-255 becomes 255-0. Mountains turn into valleys, and valleys turn into mountains. I think this was mainly for use by the 3D program that attempted to view Mandelbrot images from the side.

/*	inverpic.c	11/22/93
	Copyright (C)1993 Steven Whitney.
	Published under GNU GPL (General Public License) Version 3, with ABSOLUTELY NO WARRANTY.
	Initially published by http://25yearsofprogramming.com.

	INVERTS VALUES FROM A .PIC FILE.
	THE RANGE 0 -> 255 BECOMES 255 -> 0
	SO MOUNTAINS BECOME VALLEYS & VICE VERSA.

*/
#include "stdio.h"
main(argc,argv)
int argc;
char **argv;
{
FILE *infile, *outfile;
char buf[640];
unsigned i, j;

if(argc < 2)
	abort("Usage: INVERPIC source      (output is INVERTED.PIC)\n");

if(!(infile = fopen(argv[1],"r")))
	abort("Input file not found.\n");

outfile = fopen("inverted.pic","w");

j = 0;
while(fread(buf,1,640,infile))
{
	printf("Line %d of 225\n",++j);
	for(i = 0 ; i < 640 ; i++)
		buf[i] = 255 - buf[i];
	fwrite(buf,1,640,outfile);	
}
closeall();
exit(0);
}

 

 

Valid HTML 4.01 Transitional Valid CSS
Yahoo! Search
Search the web Search this site
View content labeling at ICRA.