What is the simplest RGB image format? What is the simplest RGB image format? c c

What is the simplest RGB image format?


You probably want to use the PPM format which is what you're looking for: a minimal header followed by raw RGB.


The recently created farbfeld format is quite minimal, though there is not much software supporting it (at least so far).

Bytes                  │ Description8"farbfeld" magic value432-Bit BE unsigned integer (width)4                      │ 32-Bit BE unsigned integer (height)(2+2+2+2)*width*height │ 4*16-Bit BE unsigned integers [RGBA] / pixel, row-major


TARGA (file name extension .tga) may be the simplest widely supported binary image file format if you don't use compression and don't use any of its extensions. It's even simpler than Windows .bmp files and is supported by ImageMagick and many paint programs. It has been my go-to format when I just need to output some pixels from a throwaway program.

Here's a minimal C program to generate an image to standard output:

#include <stdio.h>#include <string.h>enum { width = 550, height = 400 };int main(void) {  static unsigned char pixels[width * height * 3];  static unsigned char tga[18];  unsigned char *p;  size_t x, y;  p = pixels;  for (y = 0; y < height; y++) {    for (x = 0; x < width; x++) {      *p++ = 255 * ((float)y / height);      *p++ = 255 * ((float)x / width);      *p++ = 255 * ((float)y / height);    }  }  tga[2] = 2;  tga[12] = 255 & width;  tga[13] = 255 & (width >> 8);  tga[14] = 255 & height;  tga[15] = 255 & (height >> 8);  tga[16] = 24;  tga[17] = 32;  return !((1 == fwrite(tga, sizeof(tga), 1, stdout)) &&           (1 == fwrite(pixels, sizeof(pixels), 1, stdout)));}