[comp.graphics] Where/what is the UBC Lab for Computational Vision?

jdm@hodge.UUCP (jdm) (08/22/89)

	I ran across a small software package on a Xenix BBS that provides
	routines for reading/writing Sun raster image files.  It was written
	by a Marc Majka of the UBC Laboratory for Computational Vision.
	All attempts to contact this person via UUCP have failed and I was
	wondering if anyone has any information on this organization and
	possibly any other software packages they might have released dealing
	with imaging and computer vision.

	Thanks,

-- 

"I'm an anthropologist, not a computer systems architect, damit!"

jdm@hodge.cts.com [uunet zardoz crash]!hodge!jdm

James D. Murray, Ethnounixologist	TEL: (714) 998-7750 Ext. 129	
Hodge Computer Research Corporation	FAX: (714) 921-8038
1588 North Batavia Street 
Orange, California 92667  USA

annala@neuro.usc.edu (A J Annala) (08/22/89)

In article <21542@hodge.UUCP> jdm@hodge.UUCP (jdm) writes:
>
>	I ran across a small software package on a Xenix BBS that provides
>	routines for reading/writing Sun raster image files.  It was written
>	by a Marc Majka of the UBC Laboratory for Computational Vision.
>	All attempts to contact this person via UUCP have failed and I was
>	wondering if anyone has any information on this organization and
>	possibly any other software packages they might have released dealing
>	with imaging and computer vision.
>
>	Thanks,
>
>-- 
>
>"I'm an anthropologist, not a computer systems architect, damit!"
>
>jdm@hodge.cts.com [uunet zardoz crash]!hodge!jdm
>
>James D. Murray, Ethnounixologist	TEL: (714) 998-7750 Ext. 129	
>Hodge Computer Research Corporation	FAX: (714) 921-8038
>1588 North Batavia Street 
>Orange, California 92667  USA

/****************************************************************************/
/***                                                                      ***/
/*** dsun4.c -- display 8 bit per pixel color mapped sun rasterfile.      ***/
/***                                                                      ***/
/*** code to display sun rasterfiles on an ibm pc equipped with a frame   ***/
/*** buffer capable of a 256 entry colormap and 8 bits per pixel.  hacked ***/
/*** from the original xviewsun (Jim Frost, Associative Design Technology ***/
/*** madd@bu-it.but.edu) which was hacked from the original xbgsun.       ***/
/***                                                                      ***/
/*** this source code will compile under MSC 5.1                          ***/
/***                                                                      ***/
/*** you will have to link in code appropriate to use your frame buffer   ***/
/*** for the following routines: (pr_init, pr_setcolormap, and pr_put).   ***/
/*** i can send you code for an ivg128 frame buffer.  but i don't have    ***/
/*** any other appropriate hardware at my site.  i'd be happy to adapt    ***/
/*** this software to other frame buffers in exchange for a donation of   ***/
/*** the appropriate frame buffer to my laboratory.                       ***/
/***                                                                      ***/
/*** my modifications to this code are hereby released into the public    ***/
/*** domain.  assuming that the previous programs upon which this code    ***/
/*** is based are public domain, i see no reason you can't do anything    ***/
/*** you want with this code including sale for profit - you don't even   ***/
/*** have to mention where you obtained this code if you don't want to.   ***/
/***                                                                      ***/
/*** while i appreciate the intent of the free software project people    ***/
/*** i personally feel awkward about basing any of my projects on code    ***/
/*** where someone else claims the right to control what i can do with    ***/
/*** my modifications to their code.  i would hate to get a point some    ***/
/*** time down the road where question might be raised about whether or   ***/
/*** not i can market the value added component of software based on a    ***/
/*** a so called "free" software product.  i bill $300 per hour for my    ***/
/*** consulting services.  expropriation of my effort to enhance "free"   ***/
/*** software carries too high a price.  i would rather be able to base   ***/
/*** my work on "free" software products that allow me to decide whether  ***/
/*** to give or sell the resulting code to other users.                   ***/
/***                                                                      ***/
/*** A.J. Annala, Neuroscience Program, USC, Los Angeles, CA 90089-1061   ***/
/***                                                                      ***/
/****************************************************************************/
#include <stdio.h>
#include <malloc.h>

#define TRUE 1
#define FALSE 0

/* this describes the header for Sun rasterfiles.  if you have SunOS, a
 * better description is in /usr/include/rasterfile.h.  this is used
 * instead to improve portability and to avoid distribution problems.
 */

struct rheader {
  unsigned char magic[4];   /* magic number */
  unsigned char width[4];   /* width of image in pixels */
  unsigned char height[4];  /* height of image in pixels */
  unsigned char depth[4];   /* depth of each pixel */
  unsigned char length[4];  /* length of the image in bytes */
  unsigned char type[4];    /* format of file */
  unsigned char maptype[4]; /* type of colormap */
  unsigned char maplen[4];  /* length of colormap in bytes */
};

/* following the header is the colormap (unless maplen is zero) then
 * the image.  each row of the image is rounded to 2 bytes.
 */

#define RMAGICNUMBER 0x59a66a95 /* magic number of this file type */

/* these are the possible file formats
 */

#define ROLD       0 /* old format, see /usr/include/rasterfile.h */
#define RSTANDARD  1 /* standard format */
#define RRLENCODED 2 /* run length encoding to compress the image */

/* these are the possible colormap types.  if it's in RGB format,
 * the map is made up of three byte arrays (red, green, then blue)
 * that are each 1/3 of the colormap length.
 */

#define RNOMAP  0 /* no colormap follows the header */
#define RRGBMAP 1 /* rgb colormap */
#define RRAWMAP 2 /* raw colormap; good luck */

/* global variables.  mostly these are used so we don't have to pass
 * umpteen-million values to functions.
 */

int               width, height;       /* image dimensions */
int               depth;
int               mapsize;             /* size of colormap */
int               bytesperline;
int               docorrupt;           /* try to use a corrupt image anyway */
char              *fgcolor;            /* colors to use for mono images */
char              *bgcolor;
unsigned char     *data;
unsigned char     *red, *green, *blue; /* color values */

/* memToVal and valToMem convert 68000-ordered numbers into whatever the
 * local ordering is.  if you have bit or byte ordering problems, fix
 * them here.  this was tested on machines with differing bit and byte
 * orders so it should work fine.  your mileage may vary.
 */

unsigned long memToVal(d, l)
unsigned char *d; /* char array of number */
int      l;       /* length of array */
{ int a;
  unsigned long i;
  i= 0;
  for (a= 0; a < l; a++)
    i= (i << 8) + *(d++);
  return(i);
}

void valToMem(d, l, v)
unsigned char *d;
int l;
unsigned long v;
{ int a;

  for (a= l - 1; a >= 0; a--) {
    *(d + a)= v & 0xff;
    v >>= 8;
  }
}

/* macro to do 68000 to local integer conversions
 */

#define localint(d) memToVal(d, 4)

/* this loads the rasterfile into memory
 */

int loadImage(name)
     char *name;
{ FILE           *f;
  char           cmd[BUFSIZ];
  struct rheader header;
  unsigned char  *colormap;
  int            a, maplen;
  int            x, y;

  /* get rasterfile; we get it from uncompress -c if it ends in .Z, or
   * look for a .Z if we don't find an uncompressed one.
   */

  if ((f= fopen(name, "rb")) == NULL)
  {
    perror(name);
    return(-1);
  }

  if (fread(&header, sizeof(struct rheader), 1, f) != 1) {
    printf("%s: error loading rasterfile header.\n", name);
    return(-1);
  }

  /* check magic number
   */

  if (localint(header.magic) != RMAGICNUMBER) {
    printf("I don't know what '%s' is, but it's not a Sun raster image.\n",
	   name);
    return(-1);
  }

  /* we only support standard type rasterfiles and RBG type colormaps
   */

  if (localint(header.type) != RSTANDARD) {
    printf("%s: unsupported rasterfile type\n", name);
    return(-1);
  }
  if ((localint(header.maptype) != RNOMAP) &&  /* no map, no problem */
      (localint(header.maptype) != RRGBMAP)) {
    printf("%s: unsupported colormap type\n", name);
    return(-1);
  }

  width= (int) localint(header.width);
  height= (int) localint(header.height);
  depth= (int) localint(header.depth);

  /* read the colormap
   */

  if ((maplen= (int) localint(header.maplen)) > 0) 
    {
      if ((colormap= (unsigned char *)malloc(maplen)) == NULL) 
        {
          printf("%s: malloc error (cannot load colormap)\n", name);
          exit(1);
        }
      if (fread(colormap, maplen, 1, f) != 1) 
        {
          printf("%s: error reading colormap\n", name);
          return(-1);
        }
    }
  bytesperline= ((width * depth) / 8);
/******* begin erroneous original code **************************************
  if ((width) % 16 > 8)          / * images are rounded out to 16 bits * /
    bytesperline += 2;
  else if (width % 16)
    bytesperline += 1;
 ******* end erroneous original code ***************************************/
/******* begin corrected code **********************************************/
  if ( width % 2 )
    bytesperline++;
/******* end corrected code ************************************************/
  if (depth) {
    mapsize= (int) localint(header.maplen) / 3;
    red= colormap;
    green= colormap + mapsize;
    blue= colormap + (mapsize * 2);
  }
  else {
    mapsize= 0;
    red= green= blue= NULL;
  }

  /* load image data
   */
  pr_init();
  pr_setcolormap(red, green, blue, mapsize);

  if ((data= (unsigned char *)malloc(height * bytesperline)) == NULL) {
    printf("%s: malloc error (cannot load image)\n", name);
    exit(1);
  }

  for (a= 0; a < height; a++) 
  {
    if (fread(data, bytesperline, 1, f) != 1) 
      {
        printf("%s: error reading image data (possibly short image)\n", name);
        return(-1);
      }
    for (x=0; x<384; x++)
      if (a<485)
        if (x<((int)(((float)width)*0.6)))
          pr_put(x, a, *(data+((int)(x/0.6))));
        else
          pr_put(x, a, 1);
  }
  for (y=height; y<485; y++)
    for (x=0; x<384; x++)
      pr_put(x, y, 1);
  return(0);
}

int debugging = FALSE;

main(argc, argv)
  int argc;
  char *argv[];
{
  int i, j;
  unsigned char *ptr;
  unsigned char *infile;
  
  for (i=1; i<argc; i++)
    {
      if (strncmp(argv[i], "-d", 3) == 0)
        {
          debugging = TRUE;
          continue;
        }
      if (strncmp(argv[i], "-i", 2) == 0)
        {
          infile = argv[++i];  
          continue;
        }
    }

  if (loadImage(infile) < 0)
    {
      printf("failed\n");
      exit(1);
    }
  else
    {
      if (debugging)
        {
          printf("header.width   = %d\n", width);
          printf("header.height  = %d\n", height);
          printf("header.depth   = %d\n", depth);
          printf("header.maplen  = %d\n", mapsize);
          printf("bytesperline   = %d\n", bytesperline);
        }
      exit(0);
    }
}

pun@cui.unige.ch (PUN Thierry) (08/24/89)

Try David Lowe: lowe@vision.cs.ubc.ca
Good luck.
        Thierry Pun, Computer Vision Group
	Computing Science Center, U-Geneva
        12, rue du Lac, CH-1207 Geneva SWITZERLAND  
        Phone : +41(22) 787 65 82; fax: +41(22) 735 39 05
        E-mail: pun@cui.unige.ch, pun@cgeuge51.bitnet