Using images to hold MUD data.

From: Tony Robbins (robbinwa@mailbox.orst.edu)
Date: 03/30/01


Some of you may remember me mentioning, a few weeks back, my intent to
generate my wilderness from an image file, as specified by Patrick Dughi in
his Imaginary Realities article.

I ended up going with the TIFF image format (uncompressed), but I'm running
into some major problems.  Basically, I'm not able to read the file
properly.  While the code I'm going to attach is not part of stock
CircleMUD, it's the algorithm I've written to read a TIFF file.

The exact section, in readImage() is marked appropriately with a comment.
If anybody could provide clues on how to fix that part, I'd appreciate it
tremendously.

If anybody knows of a better image file format to use (bitmap style), please
let me know.  If there were a library function to read them, and find data
at specific pixels, all the better.  I've been held up by this for too long.

struct TIFImage {
  char *filename;       /* name of the file to read/write.              */
  unsigned char header[18];     /* header.                              */
  int   res[2];         /* TIF_X, TIF_Y.                                */
  int   height;         /* Number of lines of pixels, horizontal.       */
  unsigned char **rgb;  /* TIF_RED, TIF_GREEN, TIF_BLUE.                */
};


TIFF *readImage(char *filename)
{
  FILE *fp;
  TIFF *image;
  int i, j;

  CREATE(image, TIFF, 1);
  image->filename = str_dup(filename);

  fp = fopen(filename, "r");

  if (fp == NULL)
  {
    printf("SYSERR: Couldn't readImage(%s).", filename);
    return NULL;
  }

  for (i = 0; i < 18; i++)
    image->header[i] = fgetc(out);

  /* here is the problem.  I'm unable to calculate the width *
   * and height of the image properly.                       */
  i = image->header[13] * 256 + image->header[12];
  j = image->header[15] * 256 + image->header[14];

  TIF_X(image) = i;
  TIF_Y(image) = j;
  image->height = TIF_Y(image);

  CREATE(rgb, unsigned char *, TIF_Y(image));
  for (i = 0; i < TIF_Y(image); i++)
    CREATE(rgb[i], unsigned char, TIF_X(image));

  for (i = 0; i < TIF_Y(image) && !feof(fp); i++)
    for (j = 0; j < TIF_X(image) && !feof(fp); j++) {
      TIF_BLUE(image, i * TIF_X(image) + j) = fgetc(fp);
      TIF_GREEN(image, i * TIF_X(image) + j) = fgetc(fp);
      TIF_RED(image, i * TIF_X(image) + j) = fgetc(fp);
    }

  fclose(fp);

  return (image);
}

I will post a TIFF file, which I was using for testing, at:
http://kupoppo.net/temperature.zip

The file is 3 megs when uncompressed, and just over 3 _kilobytes_ when
zipped.

Thanks,
-k.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



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