Hacker News new | ask | show | jobs
by a_e_k 1245 days ago
I use this all the time. I love that it's simple enough that I can type something like those two lines off the top of my head at this point. And as an alternative to that fwrite(), another common pattern that I use is:

    for (int y = 0; y < HEIGHT; ++y)
        for (int x = 0; x < WIDTH; ++x)
        {
            // ... compute r, g, and b one pixel at a time
            printf("%c%c%c", r, g, b);
        }
I also find ImageMagick very convenient for working with the format when my program writes a PPM to stdout:

    ./myprog | convert - foo.png
or:

    ./myprog | display -