4 ms·
Yep, that sure is a primitive image format.
by jandrese 11y ago
Yep, that sure is a primitive image format.
- waynecochran 11y agoYes, but very useful since its easy to parse and trivial to generate. You can always pipe input/output through conversion utilities to your format of choice (pgm, jpg, ...).
- jacobolus 11y agoYou know what’s even more trivial to parse and generate? Arrays of uncompressed binary data.
- a_e_k 11y agoIt basically gives you that. The P6 version (".ppm") is a tiny text header followed by uncompressed RGB pixels in binary format. It's about as simple as you can get for an image. Here, for example is a program to generate a red/green gradient: #include <stdio.h> int main( int argc, char **argv ) { printf( "P6 %d %d 255\n", 128, 128 ); for ( int y = 0; y < 128; ++y ) for ( int x = 0; x < 128; ++x ) printf( "%c%c%c", x * 2, y * 2, 0 ); return 0; } Boom. Done. I use this format all the time because it's so simple that I can write programs to generate it off the top of my head. No external image libraries to link, or even a need to consult the spec at this point. A few quick lines and I've got my image. If I really need something like a PNG or JPEG, I can just pipe it through ImageMagick: ./gradient | convert - gradient.png It's not a format I'd store my images in long term, but for quick-and-dirty image creation it's hard to beat.
- ajross 11y agoNo. Unstructured binary data in arbitrary formats if fundamentally impossible to parse successfully. Oh, your parser works you say? It won't next project after the format change again. The pbm stuff is an attempt to specify the simplest possible format that can be used robustly in practice.
- jacobolus 11y agoIt seemed like the parent posters in this thread were talking about the plain text version of the format, which is IMO ridiculous for any non-toy use. My response was half-sarcastic; tone doesn’t make it through the internet though I guess. The binary version is fine, though in general I’d recommend just using PNG, TIF, JPEG, or whatever.
- weinzierl 11y agoMost early image formats were primitive and I'm glad they were. The first image reader and writer I wrote was for the .tga format[1]. This was before the Internet and I had no documentation. The only thing to do back then was to look at several different .tga files in a Hex-Editor and try to make sense of what you saw. If things would have been more complicated I might just have given up - maybe on computers entirely. There was just this "How difficult could it be?" attitude back then I miss a lot today. [1] https://en.wikipedia.org/wiki/Truevision_TGA https://en.wikipedia.org/wiki/Truevision_TGA