Re: Using images to hold MUD data.

From: Daniel A. Koepke (
Date: 04/01/01

On Fri, 30 Mar 2001, Tony Robbins wrote:

> I ended up going with the TIFF image format (uncompressed), but I'm
> running into some major problems.

TIFF is a complex graphics file format.  I would recommend against this
choice, not only because writing a proper reader for the format will be
difficult and time-consuming, but also because its overkill for what you

PPM is incredibly simple, especially with raw bits mode.  A simple reader:

  struct PpmImage {
    ulong width;
    ulong height;
    char *bitmap;

  struct PpmImage *load_ppm_bitmap(const char *fname)
    struct PpmImage *ppm;
    ush_int magic;
    int bmpsize;
    int cols;
    int rows;
    FILE *fp;
    char c;
    int mv;

    if (!(fp = fopen(fname, "r"))) {
      return (NULL);
    } else if (fscanf("%hu %d %d %d\n", &magic, &cols, &rows, &mv) != 4) {
      log("SYSERR: %s: corrupt header", fname);
      return (NULL);
    } else if (magic != 0x3650) { /* "P6" */
      log("SYSERR: %s: not a rawbits ppm file", fname);
      return (NULL);
    } else if (mv > 255) {
      /* The file is corrupt -- it's not in the format it says it is. */
      log("SYSERR: %s: header is P6 but max color value implies P3",
      return (NULL);

    bpmsize = cols * rows;
    CREATE(ppm, sizeof(struct PpmImage), 1);
    CREATE(ppm->bitmap, char, bmpsize);
    ppm->width = cols;
    ppm->height = rows;

    /* ppm(5) says no whitespace in pixel area, so this should suffice */
    if ((mv = fread(ppm->bitmap, sizeof(char), bmpsize, fp)) != bmpsize)
      log("WARNING: %s: expected %d bytes, got %d", bmpsize, mv);

    return (ppm);

This doesn't support comments, isn't very robust, blah, blah.  But I think
it should work.  YMMV -- it's Mailer Code(tm).  More information on PPM
can be found by typing 'man ppm' on most UNIX machines -- this
documentation is what I used to write the above.

Most programs should be capable of outputting raw bits PPM.  Writing a
reader for the color triplet version of PPM (magic number would be "P3",
or 0x3350 encoded as a short) is not much more difficult (i.e., it's
nothing that couldn't be accomplished by just adding a loop that does
fscanf for the RGB pixel values), but is left as an exercise to the reader
if he really wants/needs it.


   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/05/01 PST