head	1.2;
access
	monica
	thoth;
symbols;
locks; strict;
comment	@// @;


1.2
date	94.08.24.00.30.59;	author monica;	state Exp;
branches;
next	1.1;

1.1
date	94.02.18.19.03.17;	author thoth;	state Exp;
branches;
next	;


desc
@experimental RGB khoros image reader
@


1.2
log
@int main & exit(0)
@
text
@// Emacs -*- C++ -*-
static char test116_rcsid[] = "$Id: test116.c,v 1.1 1994/02/18 19:03:17 thoth Exp monica $";

//
// experimental RGB khoros image reader
//

//
// $Log: test116.c,v $
//Revision 1.1  1994/02/18  19:03:17  thoth
//Initial revision
//

#include <iostream.h>
#include <stdlib.h>

#include "viff.h"
extern "C" {
struct xvimage *readimage(const char*);
}

#include "IntPointSet.h"
#include "IntDiscreteImage.h"

int ac=0;
char **av=0;
char *program="test116";

template <class T,class S>
inline int *map_vec(const T *data, int dlen, const S *map, int maplen)
{
    int	*rval = new int[dlen];

    if (map) {
	for (int i=0; i<dlen; i++) {
	    T	val=data[i];
	    if (val<0)
		val=0;
	    else if (val>=maplen)
		val=maplen-1;
	    rval[i] = map[val];
	}
    } else {
	for (int i=0; i<dlen; i++)
	    rval[i] = data[i];
    }
    return rval;
}

IA_IntDiscreteImage to_idi(xvimage *ip, int band_n=0, int map_n=-1)
{
  IA_IntPointSet	ps(IA_IntPoint(0,0),
			   IA_IntPoint((int)ip->col_size,
				       (int)ip->row_size)-1);

  int	*data;
  int	size = (int)(ip->col_size*ip->row_size);
  int	mapsize = (int)ip->map_col_size;
  if (map_n<0) {
      data = map_vec((unsigned char*)ip->imagedata, size,
			     (unsigned char*)0, 0);
  } else {
      switch (ip->data_storage_type) {
      case VFF_TYP_1_BYTE:
	  switch (ip->map_storage_type) {
	  case VFF_MAPTYP_1_BYTE:
	      data = map_vec(band_n*size+(unsigned char*)ip->imagedata, size,
			     (unsigned char*)ip->maps+map_n*mapsize,
			     mapsize);
	      break;
	  default:
	      data=0;
	      cerr << "unhandled map_storage_type: " << ip->map_storage_type
		   << "\n";
	      break;
	  }
	  break;
	  default:
	  data=0;
	  cerr << "unhandled data_storage_type: " << ip->data_storage_type
	       << "\n";
	  break;
      }

  }
  return IA_IntDiscreteImage(ps, data, size, 1);
}

int main(int argc, char**argv)

{

  if (argc<2) {
    cerr << "Usage:\n"<< argv[0] << " viff-file\n";
    exit(1);
  }

  struct xvimage *imgp;

  imgp = readimage(argv[1]);

  if (imgp==0) {
      cerr << "error reading image "<< argv[1] << "\n";
      exit(1);
  }

  IA_IntDiscreteImage	idi;

  to_idi(imgp, 0, 0).write_PGM("plane0",255);
  to_idi(imgp, 0, 1).write_PGM("plane1",255);
  to_idi(imgp, 0, 2).write_PGM("plane2",255);

  exit(0);
}
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
static char test116_rcsid[] = "$Id: test105.c,v 1.1 93/03/10 13:57:00 thoth Exp $";
d9 4
a12 1
// $Log$
d112 2
@
