Created
February 16, 2011 01:56
-
-
Save nowl/828710 to your computer and use it in GitHub Desktop.
simple PPM output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void | |
write_header(FILE *out, int width, int height, int max_color_val) | |
{ | |
fprintf(out, "P3\n%d %d\n%d\n", height, width, max_color_val); | |
} | |
static void | |
write_color_val(FILE *out, int red, int green, int blue) | |
{ | |
fprintf(out, "%d %d %d\n", red, green, blue); | |
} | |
static void | |
write_image(FILE *out, int *image, int width, int height) | |
{ | |
int i; | |
for(i=0; i<width*height; i++) | |
{ | |
int color = image[i]; | |
write_color_val(out, color&0xff, (color>>8)&0xff, (color>>16)&0xff); | |
} | |
} | |
void | |
write_to_file(char *filename, int *image, int width, int height) | |
{ | |
FILE *fout = fopen(filename, "w"); | |
write_header(fout, width, height, 256); | |
write_image(fout, image, width, height); | |
fclose(fout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment