home *** CD-ROM | disk | FTP | other *** search
/ vis-ftp.cs.umass.edu / vis-ftp.cs.umass.edu.tar / vis-ftp.cs.umass.edu / pub / Software / universal_plane_file_format / llvs_per_plane.h < prev    next >
C/C++ Source or Header  |  1990-11-05  |  8KB  |  240 lines

  1. /* -*-c-mode-*- */
  2. /*------------------------------------------------------
  3.  *  LLVS_PER_PLANE.H - C Macros for the Per Plane Method
  4.  *  James H. Burrill, Jr.  Created on Thu Mar 13 10:38:29 1986
  5.  *  Last mod - 
  6.  *--------------------------------------------------------
  7.  *  Contents:
  8.  *--------------------------------------------------------
  9.  * (c) Copyright 1986 by The University of Massachusetts
  10.  *------------------------------------------------------*/
  11.  
  12. #define MAXPLANE 9
  13.  
  14. #define PI        3.141592653589
  15. #define PI2       6.283185307178
  16. #define PI_OVER_2 1.570796326945
  17.  
  18. #define NULL 0
  19. #define TRUE 1
  20. #define FALSE 0
  21.  
  22. #define MIN(x,y) (((x) > (y)) ? (y) : (x))
  23. #define MAX(x,y) (((x) < (y)) ? (y) : (x))
  24.  
  25. #define GETBIT(base,offset) \
  26. ((base)[(offset) >> 3] >>((offset) & 0x07) & 0x01)
  27.  
  28. #define SETBIT(base,offset,value) \
  29. if (value != 0) (base)[(offset) >> 3] |= 1 << ((offset) & 0x07); \
  30. else (base)[(offset) >> 3] &= ~(1 << ((offset) & 0x07))
  31.  
  32. /*------------------------------------------------------
  33.  *
  34.  *  PLANE
  35.  *    This structure describes the format of a plane passed
  36.  *  to C. Each plane is passed to the C routine as a separate
  37.  *  argument of type PLANE.
  38.  *
  39.  *-------------------------------------------------------
  40.  */
  41.  
  42. typedef struct {
  43.     int plane_base[1];        /* plane data starts here */
  44.     } PLANE;
  45.  
  46. /*----------------------------------------------------------
  47.  *
  48.  *  PLANE_INFO
  49.  *    Other information is available for each plane. This
  50.  *   information is passed in an array of PLANE_INFO[MAXPLANE].
  51.  *   The Lisp function BUILD-PLANE-INFO-VECTOR-C may be used to
  52.  *   build the array. The background-value is passed as a C float
  53.  *   value if the plane is a floating point plane, C int
  54.  *   type otherwise.
  55.  *
  56.  *----------------------------------------------------------*/
  57.  
  58. /* plane info struct */
  59. typedef struct {
  60.     long int datatype;        /* data type */
  61. #define LLVS_BIT   0            /* bit type */
  62. #define LLVS_BYTE  1            /* unsigned byte type */
  63. #define LLVS_SHORT 2            /* signed 16 bit type */
  64. #define LLVS_INT   3            /* integer type */
  65. #define LLVS_FLOAT 4            /* float type */
  66. #define FLOAT 4            /* float type */
  67.     long int level;        /* plane level */
  68.     long int row_location;    /* row location */
  69.     long int column_location;    /* column location */
  70.     long int row_dimension;    /* row dimension */
  71.     long int column_dimension;    /* column dimension */
  72.     union {
  73.     long int fixnum;    /* background value */
  74.     float flonum;        /* dito, but as a flonum */
  75.     } background;
  76.     } PLANE_INFO;
  77.  
  78. /*---------------------------------------------------------
  79.  *
  80.  *  MASK_VALUES
  81.  *    The mask values are passed as an array on int.
  82.  *   The Lisp function BUILD-MASK-VALUES-C can be used to prepare
  83.  *   structure to be passed to C.
  84.  *
  85.  *---------------------------------------------------------*/
  86.  
  87. typedef struct {
  88.     long int num_values;    /* number of values */
  89.     long int value_base[1];     /* value(s) start here */
  90.     } MASK_VALUES;
  91.  
  92. /*---------------------------------------------------------
  93.  *
  94.  *  LIMITS
  95.  *    The LIMITS are passed in this structure. The Lisp
  96.  *   function BUILD-LIMITS-C may be used to prepare this structure.
  97.  *
  98.  *---------------------------------------------------------*/
  99.  
  100. typedef struct {
  101.    long int startrow,endrow,deltarow,startcol,endcol,deltacol,level;
  102.    } LIMITS;
  103.  
  104. /*------------------------------------------------------------
  105.  *
  106.  *  TRANSLEVEL
  107.  *    This macro converts a row or column index from the
  108.  *   conceptual plane into a row or column index into the
  109.  *   actual plane. 
  110.  *
  111.  *   result - the resultant row or column index.
  112.  *   current - the row or column index to be converted.
  113.  *   deltalevel - a positive or negative integer denoting the
  114.  *                difference in levels between the conceptual
  115.  *                plane and the actual plane ---
  116.  *                (conceptual level - actual level).
  117.  *   location - the row or column location of the actual plane.
  118.  *
  119.  *------------------------------------------------------------*/
  120.  
  121. #define TRANSLEVEL(result,current,deltalevel,location) \
  122. if ((deltalevel) < 0) result = ((current) << -(deltalevel)) - (location);\
  123. else result = ((current) >> (deltalevel)) - (location)
  124.  
  125. /*-------------------------------------------------------------
  126.  *
  127.  *  GET_PIXEL
  128.  *    Gets a pixel from a PLANE.
  129.  *
  130.  *   result - the resultant pixel converted to the type of result.
  131.  *   bkgv - the value to be used if the pixel is not in the actual
  132.  *          plane.
  133.  *   plane - a pointer to a PLANE structure.
  134.  *   row - the row index in the actual plane.
  135.  *   col - the column index in the actual plane.
  136.  *
  137.  *---------------------------------------------------------------*/
  138.  
  139. #define GET_PIXEL(result,bkgv,plane,row,col,pl_info) \
  140.  if ((row) < 0 || (row) >= pl_info.row_dimension || \
  141.      (col) < 0 || (col) >= pl_info.column_dimension) \
  142.    result = (bkgv); \
  143.  else { \
  144.   register llvsoffset; \
  145.   llvsoffset = (col) + ((row) * pl_info.column_dimension); \
  146.   switch (pl_info.datatype) { \
  147.     case LLVS_BIT: \
  148.       result = GETBIT(((char*)  plane->plane_base),llvsoffset); \
  149.       break; \
  150.     case LLVS_BYTE: \
  151.       result = ((unsigned char*)  plane->plane_base)[llvsoffset]; \
  152.       break; \
  153.     case LLVS_SHORT: \
  154.       result = ((short int*)  plane->plane_base)[llvsoffset]; \
  155.       break; \
  156.     case LLVS_INT: \
  157.       result = ((int*)  plane->plane_base)[llvsoffset]; \
  158.       break; \
  159.     case LLVS_FLOAT: \
  160.       result = ((float*)  plane->plane_base)[llvsoffset]; \
  161.       break; \
  162.     }}
  163.  
  164. /*-------------------------------------------------------------------
  165.  *
  166.  *  SET_PIXEL
  167.  *    Sets a pixel in the plane. If the pixel does not exist, nothing
  168.  *   is done.
  169.  *
  170.  *   value - this value is converted to the proper type and put in the
  171.  *           pixel.
  172.  *   plane - a pointer to a structure of type PLANE.
  173.  *   row - the row index into the actual plane.
  174.  *   col - the column index into the actual plane.
  175.  *   pl_info - row, column, dimensions, etc
  176.  *------------------------------------------------------------------*/
  177.  
  178. #define SET_PIXEL(value,plane,row,col,pl_info) \
  179.  if ((row) >= 0 && (row) < pl_info.row_dimension && \
  180.      (col) >= 0 && (col) < pl_info.column_dimension) { \
  181.   register llvsoffset; \
  182.   llvsoffset = (col) + ((row) * pl_info.column_dimension); \
  183.    switch (pl_info.datatype) { \
  184.     case LLVS_BIT: \
  185.       SETBIT(((char*)plane->plane_base),llvsoffset,value); \
  186.       break; \
  187.     case LLVS_BYTE: \
  188.       ((unsigned char*)  plane->plane_base)[llvsoffset] = value; \
  189.       break; \
  190.     case LLVS_SHORT: \
  191.       ((short int*)  plane->plane_base)[llvsoffset] = value; \
  192.       break; \
  193.     case LLVS_INT: \
  194.       ((int*)  plane->plane_base)[llvsoffset] = value; \
  195.       break; \
  196.     case LLVS_FLOAT: \
  197.       ((float*)  plane->plane_base)[llvsoffset] = value; \
  198.       break; \
  199.     }}
  200.  
  201. #define ZERO_PLANE(pl_info) \
  202.    (pl_info.row_dimension == 0 || \
  203.     pl_info.column_dimension == 0)
  204.  
  205. #define PLANE_LEV_ERR(pl_info,pl1,pl2)\
  206.  (pl_info[pl1].level != pl_info[pl2].level)
  207.  
  208. #define PLANE_LOC_ERR(pl_info,pl1,pl2) \
  209.  (pl_info[pl1].row_location != pl_info[pl2].row_location)
  210.  
  211. #define PLANE_SIZE_ERR(pl_info,pl1,pl2) \
  212.  (pl_info[pl1].row_dimension != pl_info[pl2].row_dimension || \
  213.   pl_info[pl1].column_dimension != pl_info[pl2].column_dimension)
  214.  
  215. #define LIMITS_ERR(lims)\
  216.    (lims->deltarow <= 0 || \
  217.     lims->deltacol <= 0 || \
  218.     lims->startrow > lims->endrow || \
  219.     lims->startcol > lims->endcol)
  220.  
  221.  
  222. #define EXTERNAL globalref
  223.  
  224. /* scratch_size
  225.      This macro defines the size of a statically allocated array to be used
  226.  as a scratch area by the image operators written in C. The primary use will
  227.  probably be to receive the pixels returned by a window function. The size of
  228.  this array is guaranteed to be scratch_size*4 bytes. The user is free to use
  229.  an EXTERN statement to declare the type and organization of the array.
  230.  
  231.  Examples:
  232.   extern int scratch[scratch_size];
  233.  
  234.   extern float scratch [scratch_size];
  235.  
  236.   extern char scratch [4 * scratch_size];
  237. */
  238.  
  239. #define SCRATCH_SIZE 2048
  240.