AddressLib/vopio.c
MomVop *initvop(TCoor x, TCoor y, int colorformat, MomImageType atype,
	     MomImageType ytype, MomImageType utype, MomImageType vtype)

{
  MomVop* newvop;
/*  int i;*/
  ulong size;
  ulong csize;
  uchar *a, *b;

  newvop=(MomVop *)malloc(sizeof(MomVop));
  if (!newvop) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }

  newvop->a_chan=(MomImage *)malloc(sizeof(MomImage));
  newvop->y_chan=(MomImage *)malloc(sizeof(MomImage));
  if (!(newvop->a_chan && newvop->y_chan)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }

  size=x*y;
/*  newvop->a_chan->data=(MomImageData *)malloc(sizeof(MomImageData));
  newvop->y_chan->data=(MomImageData *)malloc(sizeof(MomImageData));
  if (!(newvop->a_chan->data && newvop->y_chan->data)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }*/
  newvop->a_chan->data=(MomImageData*)&newvop->a_chan->f;	// alpha channel
  newvop->y_chan->data=(MomImageData*)&newvop->y_chan->f;	// Y channel

  a=newvop->a_chan->data->u=(uchar *)malloc(size*typesize(atype));
  b=newvop->y_chan->data->u=(uchar *)malloc(size*typesize(ytype));
  if (!(newvop->a_chan->data->u && newvop->y_chan->data->u)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }

  newvop->pextend=(MomVopExtend *)malloc(sizeof(MomVopExtend));
  if (!newvop->pextend) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }


  newvop->ident=0;
  newvop->width=x;
  newvop->height=y;
  newvop->hor_spat_ref=0;
  newvop->ver_spat_ref=0;
  newvop->scaling=0;
  newvop->arbitrary_shape=1;
  newvop->binary_shape=0;
  newvop->visibility=1;
  newvop->comp_order=0;

  newvop->pnext_spat=0;
  newvop->pnext_temp=0;
/*  newvop->pprev_temp=0;*/


  newvop->a_chan->version=newvop->y_chan->version = 0L;
  newvop->a_chan->x=newvop->y_chan->x = x;
  newvop->a_chan->y=newvop->y_chan->y = y;
  newvop->a_chan->upperodd=newvop->y_chan->upperodd = 0;
  newvop->a_chan->grid=newvop->y_chan->grid = 's';
  newvop->a_chan->type = atype;
  newvop->y_chan->type = ytype;

  memset(newvop->a_chan->data->u,0,size*typesize(atype));
  memset(newvop->y_chan->data->u,0,size*typesize(ytype));


/*  newvop->reseg_levels=0;
  newvop->preseg_list=0;*/

  if (colorformat > 1) x>>=1;
  if (colorformat > 2) y>>=1;
  if (!colorformat) x=y=0;

  newvop->u_chan=(MomImage *)malloc(sizeof(MomImage));
  newvop->v_chan=(MomImage *)malloc(sizeof(MomImage));
  if (!(newvop->u_chan && newvop->v_chan)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }

  csize=x*y;
  newvop->u_chan->version=newvop->v_chan->version=0L;
  newvop->u_chan->x=newvop->v_chan->x=x;
  newvop->u_chan->y=newvop->v_chan->y=y;
  newvop->u_chan->upperodd=newvop->v_chan->upperodd=0;
  newvop->u_chan->grid=newvop->v_chan->grid='s';
  newvop->u_chan->type=utype;
  newvop->v_chan->type=vtype;

/*  newvop->u_chan->data=(MomImageData *)malloc(sizeof(MomImageData));
  newvop->v_chan->data=(MomImageData *)malloc(sizeof(MomImageData));
  if (!(newvop->u_chan->data && newvop->v_chan->data)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }*/
  newvop->u_chan->data=(MomImageData*)&newvop->u_chan->f;
  newvop->v_chan->data=(MomImageData*)&newvop->v_chan->f;

  // not a colored image -- single band
  if (!colorformat) {
    newvop->u_chan->data->u=0;
    newvop->v_chan->data->u=0;
    return(newvop);
  }

  newvop->u_chan->data->u=(uchar *)malloc(csize*typesize(utype));
  newvop->v_chan->data->u=(uchar *)malloc(csize*typesize(vtype));
  if (!(newvop->u_chan->data->u && newvop->v_chan->data->u)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }

  memset(newvop->u_chan->data->u,0,csize*typesize(utype));
  memset(newvop->v_chan->data->u,0,csize*typesize(vtype));

  return(newvop);
}
/**********************************************************************/
/*  initvop  initialises vop structures and allocates memory            */
/**********************************************************************/
initvop  initialises vop structures and allocates memory
initvop initialises vop structures and allocates memory
MomVop *initvop(TCoor x, TCoor y, int colorformat, MomImageType atype,
	     MomImageType ytype, MomImageType utype, MomImageType vtype)
{
  MomVop* newvop;
  ulong size;
  ulong csize;
  uchar *a, *b;
  newvop=(MomVop *)malloc(sizeof(MomVop));
  if (!newvop) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }
  newvop->a_chan=(MomImage *)malloc(sizeof(MomImage));
  newvop->y_chan=(MomImage *)malloc(sizeof(MomImage));
  if (!(newvop->a_chan && newvop->y_chan)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }
  size=x*y;
  newvop->a_chan->data=(MomImageData*)&newvop->a_chan->f;	
  newvop->y_chan->data=(MomImageData*)&newvop->y_chan->f;	
  a=newvop->a_chan->data->u=(uchar *)malloc(size*typesize(atype));
  b=newvop->y_chan->data->u=(uchar *)malloc(size*typesize(ytype));
  if (!(newvop->a_chan->data->u && newvop->y_chan->data->u)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }
  newvop->pextend=(MomVopExtend *)malloc(sizeof(MomVopExtend));
  if (!newvop->pextend) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }
  newvop->ident=0;
  newvop->width=x;
  newvop->height=y;
  newvop->hor_spat_ref=0;
  newvop->ver_spat_ref=0;
  newvop->scaling=0;
  newvop->arbitrary_shape=1;
  newvop->binary_shape=0;
  newvop->visibility=1;
  newvop->comp_order=0;
  newvop->pnext_spat=0;
  newvop->pnext_temp=0;
  newvop->a_chan->version=newvop->y_chan->version = 0L;
  newvop->a_chan->x=newvop->y_chan->x = x;
  newvop->a_chan->y=newvop->y_chan->y = y;
  newvop->a_chan->upperodd=newvop->y_chan->upperodd = 0;
  newvop->a_chan->grid=newvop->y_chan->grid = 's';
  newvop->a_chan->type = atype;
  newvop->y_chan->type = ytype;
  memset(newvop->a_chan->data->u,0,size*typesize(atype));
  memset(newvop->y_chan->data->u,0,size*typesize(ytype));
  if (colorformat > 1) x>>=1;
  if (colorformat > 2) y>>=1;
  if (!colorformat) x=y=0;
  newvop->u_chan=(MomImage *)malloc(sizeof(MomImage));
  newvop->v_chan=(MomImage *)malloc(sizeof(MomImage));
  if (!(newvop->u_chan && newvop->v_chan)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }
  csize=x*y;
  newvop->u_chan->version=newvop->v_chan->version=0L;
  newvop->u_chan->x=newvop->v_chan->x=x;
  newvop->u_chan->y=newvop->v_chan->y=y;
  newvop->u_chan->upperodd=newvop->v_chan->upperodd=0;
  newvop->u_chan->grid=newvop->v_chan->grid='s';
  newvop->u_chan->type=utype;
  newvop->v_chan->type=vtype;
  newvop->u_chan->data=(MomImageData*)&newvop->u_chan->f;
  newvop->v_chan->data=(MomImageData*)&newvop->v_chan->f;
  if (!colorformat) {
    newvop->u_chan->data->u=0;
    newvop->v_chan->data->u=0;
    return(newvop);
  }
  newvop->u_chan->data->u=(uchar *)malloc(csize*typesize(utype));
  newvop->v_chan->data->u=(uchar *)malloc(csize*typesize(vtype));
  if (!(newvop->u_chan->data->u && newvop->v_chan->data->u)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }
  memset(newvop->u_chan->data->u,0,csize*typesize(utype));
  memset(newvop->v_chan->data->u,0,csize*typesize(vtype));
  return(newvop);
}
MomVop * initvop ( TCoor x , TCoor y , int colorformat , MomImageType atype , MomImageType ytype , MomImageType utype , MomImageType vtype ) { MomVop * newvop ; ulong size ; ulong csize ; uchar * a , * b ; newvop = ( MomVop * ) malloc ( sizeof ( MomVop ) ) ; if ( ! newvop ) { fprintf ( stderr , " " ) ; exit ( errno ) ; } newvop -> a_chan = ( MomImage * ) malloc ( sizeof ( MomImage ) ) ; newvop -> y_chan = ( MomImage * ) malloc ( sizeof ( MomImage ) ) ; if ( ! ( newvop -> a_chan && newvop -> y_chan ) ) { fprintf ( stderr , " " ) ; exit ( errno ) ; } size = x * y ; newvop -> a_chan -> data = ( MomImageData * ) & newvop -> a_chan -> f ; newvop -> y_chan -> data = ( MomImageData * ) & newvop -> y_chan -> f ; a = newvop -> a_chan -> data -> u = ( uchar * ) malloc ( size * typesize ( atype ) ) ; b = newvop -> y_chan -> data -> u = ( uchar * ) malloc ( size * typesize ( ytype ) ) ; if ( ! ( newvop -> a_chan -> data -> u && newvop -> y_chan -> data -> u ) ) { fprintf ( stderr , " " ) ; exit ( errno ) ; } newvop -> pextend = ( MomVopExtend * ) malloc ( sizeof ( MomVopExtend ) ) ; if ( ! newvop -> pextend ) { fprintf ( stderr , " " ) ; exit ( errno ) ; } newvop -> ident = 0 ; newvop -> width = x ; newvop -> height = y ; newvop -> hor_spat_ref = 0 ; newvop -> ver_spat_ref = 0 ; newvop -> scaling = 0 ; newvop -> arbitrary_shape = 1 ; newvop -> binary_shape = 0 ; newvop -> visibility = 1 ; newvop -> comp_order = 0 ; newvop -> pnext_spat = 0 ; newvop -> pnext_temp = 0 ; newvop -> a_chan -> version = newvop -> y_chan -> version = 0L ; newvop -> a_chan -> x = newvop -> y_chan -> x = x ; newvop -> a_chan -> y = newvop -> y_chan -> y = y ; newvop -> a_chan -> upperodd = newvop -> y_chan -> upperodd = 0 ; newvop -> a_chan -> grid = newvop -> y_chan -> grid = ' ' ; newvop -> a_chan -> type = atype ; newvop -> y_chan -> type = ytype ; memset ( newvop -> a_chan -> data -> u , 0 , size * typesize ( atype ) ) ; memset ( newvop -> y_chan -> data -> u , 0 , size * typesize ( ytype ) ) ; if ( colorformat > 1 ) x >>= 1 ; if ( colorformat > 2 ) y >>= 1 ; if ( ! colorformat ) x = y = 0 ; newvop -> u_chan = ( MomImage * ) malloc ( sizeof ( MomImage ) ) ; newvop -> v_chan = ( MomImage * ) malloc ( sizeof ( MomImage ) ) ; if ( ! ( newvop -> u_chan && newvop -> v_chan ) ) { fprintf ( stderr , " " ) ; exit ( errno ) ; } csize = x * y ; newvop -> u_chan -> version = newvop -> v_chan -> version = 0L ; newvop -> u_chan -> x = newvop -> v_chan -> x = x ; newvop -> u_chan -> y = newvop -> v_chan -> y = y ; newvop -> u_chan -> upperodd = newvop -> v_chan -> upperodd = 0 ; newvop -> u_chan -> grid = newvop -> v_chan -> grid = ' ' ; newvop -> u_chan -> type = utype ; newvop -> v_chan -> type = vtype ; newvop -> u_chan -> data = ( MomImageData * ) & newvop -> u_chan -> f ; newvop -> v_chan -> data = ( MomImageData * ) & newvop -> v_chan -> f ; if ( ! colorformat ) { newvop -> u_chan -> data -> u = 0 ; newvop -> v_chan -> data -> u = 0 ; return ( newvop ) ; } newvop -> u_chan -> data -> u = ( uchar * ) malloc ( csize * typesize ( utype ) ) ; newvop -> v_chan -> data -> u = ( uchar * ) malloc ( csize * typesize ( vtype ) ) ; if ( ! ( newvop -> u_chan -> data -> u && newvop -> v_chan -> data -> u ) ) { fprintf ( stderr , " " ) ; exit ( errno ) ; } memset ( newvop -> u_chan -> data -> u , 0 , csize * typesize ( utype ) ) ; memset ( newvop -> v_chan -> data -> u , 0 , csize * typesize ( vtype ) ) ; return ( newvop ) ; }
initvop  initialises vop structures and allocates memory
initvop initialises vop structures and allocates memory
/*  int i;*/ /*  newvop->a_chan->data=(MomImageData *)malloc(sizeof(MomImageData));
  newvop->y_chan->data=(MomImageData *)malloc(sizeof(MomImageData));
  if (!(newvop->a_chan->data && newvop->y_chan->data)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }*/ // alpha channel
 // Y channel
 /*  newvop->pprev_temp=0;*/ /*  newvop->reseg_levels=0;
  newvop->preseg_list=0;*/ /*  newvop->u_chan->data=(MomImageData *)malloc(sizeof(MomImageData));
  newvop->v_chan->data=(MomImageData *)malloc(sizeof(MomImageData));
  if (!(newvop->u_chan->data && newvop->v_chan->data)) {
    fprintf(stderr,"ERROR : Out of memory");
    exit(errno);
  }*/ // not a colored image -- single band
