Color quantization/C: Difference between revisions
m
Replace <lang> by <syntaxhighlight> block so it's better formatted
m (enough with the frogs) |
m (Replace <lang> by <syntaxhighlight> block so it's better formatted) |
||
(One intermediate revision by one other user not shown) | |||
Line 1:
[[file:Quantum_frog_dithered.png|200px|thumb]]This is a complete program that takes a PPM P6 image and a number, then writes out the image reduced to the number of colors to out.ppm. There is optional dithering, too, which doesn't make a whole lot of difference with say 64 colors or more. And with low colors, the quantization did such a good job of picking average colors that it actually hurts the dithering process.
<
#include <stdlib.h>
#include <fcntl.h>
Line 16:
int write_ppm(image im, char *fn)
{
FILE *fp = fopen(fn, "
if (!fp) return 0;
fprintf(fp, "P6\n%d %d\n255\n", im->w, im->h);
Line 47:
image read_ppm(char *fn)
{
FILE *fp = fopen(fn, "
int w, h, maxval;
image im = 0;
Line 366:
return 0;
}</
|