3 ms·
Been doing this forever. From C it's the easiest way to output images, using popen and piping to netpbm or imagemagick. Without error handling it goes like th
by rwmj 6y ago
Been doing this forever. From C it's the easiest way to output images, using popen and piping to netpbm or imagemagick. Without error handling it goes like this:
fp = popen ("pnmtojpeg > output.jpg", "w");
fprintf (fp, "P3 %d %d 255", width, height);
/* print pixels as R G B triples */
pclose (fp);
- RBerenguel 6y agoLikewise, I used it back when I rendered fractals (code in C, too) for some papers. PPM/PNM is a lovely (if bulky) format since it’s human debuggable as well.
- lelandbatey 6y agoPPM is especially useful for fractals because, as an optionally text-based format, the max brightness of any pixel is arbitrary. This means you can have unlimited color depth, something that's really useful when you want to do things like brighten up _really_ dim areas of an image, areas that would be aliased to 0 if represented with only 24 bit color (like in PNG). This was really useful for a toy buddhabrot renderer I wrote a while back: https://github.com/lelandbatey/rust_buddhabrot https://github.com/lelandbatey/rust_buddhabrot