/*
*  Author: Philip R. Thompson
*  Address:  phils@athena.mit.edu, 9-532
*  $Header: /mit/crldev/src/xim/lib/RCS/ximdefs.h,v 1.15 92/10/05 18:55:55 phils Exp Locker: phils $
*  $Date: 92/10/05 18:55:55 $
*  $Source: /mit/crldev/src/xim/lib/RCS/ximdefs.h,v $
*  Copyright (c) 1989, 1990 Massachusetts Institute of Technology
*                1988, Philip R. Thompson (phils@athena.mit.edu)
*                Computer Resource Laboratory (CRL)
*                Dept. of Architecture and Planning
*                M.I.T., Rm 9-532
*                Cambridge, MA  02139
*   This  software and its documentation may be used, copied, modified,
*   and distributed for any purpose without fee, provided:
*       --  The above copyright notice appears in all copies.
*       --  This disclaimer appears in all source code copies.
*       --  The names of M.I.T. and the CRL are not used in advertising
*           or publicity pertaining to distribution of the software
*           without prior specific written permission from me or CRL.
*   I provide this software freely as a public service.  It is NOT
*   public domain nor a commercial product, and therefore is not subject
*   to an an implied warranty of merchantability or fitness for a
*   particular purpose.  I provide it as is, without warranty.
*
*   This software is furnished  only on the basis that any party who
*   receives it indemnifies and holds harmless the parties who furnish
*   it against any claims, demands, or liabilities connected with using
*   it, furnishing it to adatas, or providing it to a third party.
*/
#ifndef _XIMDEFS_H_
#define _XIMDEFS_H_
#if (!defined(lint) && !defined(SABER) && !defined(__GNUC__))
static char ximdefs_rcsid[] =
"$Header: /mit/crldev/src/xim/lib/RCS/ximdefs.h,v 1.15 92/10/05 18:55:55 phils Exp Locker: phils $";

#endif

#ifndef PI
#define PI          3.14159265358979323846264338327
#endif
#define _DEGS       57.2957795130823208768
#define BELL        7
#ifndef HUGEREAL
#define HUGEREAL    1.23456789e19       /* ~ sqrt of HUGE */
#define TINYREAL    9.87654321e-20      /* ~ 1.0 / HUGEREAL */
#endif
#define EPSILON     1.0e-6
#define HUGESH0RT   32767       /* 16 bit */
#define HUGEINT     2147483647  /* 24 bit */

#ifndef FALSE
#define FALSE       0
#define TRUE        1
#endif                          /* false */

#define XIM_FORMAT      0      /* File formats */
#define XBM_FORMAT      1
#define FBM_FORMAT      2
#define RLE_FORMAT      3
#define PS_FORMAT       4
#define XWD_FORMAT      5
#define PLX_FORMAT      6
#define GIF_FORMAT      7   /* jeffg@amarok.wv.tek.com */
#define IW_FORMAT       8   /* jeffg@amarok.wv.tek.com */
#define GRF_FORMAT      9   /* jeffg@amarok.wv.tek.com */
#define TIFF_FORMAT     10
#define ILBM_FORMAT     11
#define VGER_FORMAT     12  /* jeffg@amarok.wv.tek.com */
#define RAD_FORMAT      13
#define PPM_FORMAT      14

#define XIM_DEPTH(xim)  ((xim)->nchannels * (xim)->bits_channel)
#define XIM_IS_24BIT(xim)       (((xim)->nchannels == 3) && \
                ((xim)->bits_channel == 8))
#define XIM_IS_8BIT(xim)        (((xim)->nchannels == 1) && \
                ((xim)->bits_channel == 8))
#define XIM_IS_1BIT(xim)        (((xim)->nchannels == 1) && \
                ((xim)->bits_channel == 1))
#define XIM_IS_GREY(xim)        (((xim)->nchannels == 1) && \
                ((xim)->bits_channel == 8) && (xim)->grey_flag)

#define XIM_HAS_DATA(xim)       (((xim)->datasize > 0) && \
                ((xim)->data != (byte*)NULL))
#define XIM_HAS_COLORS(xim)     (((xim)->ncolors > 0) && \
                ((xim)->colors != (Color*)NULL))


#define XIMDEBUGFUNC   0x01
#define XIMDEBUGDATA   0x02
#define XIMDEBUGALL    0x0f

#ifndef TODEGREES
#define TODEGREES(a)    ((a) * _DEGS)
#define TORADIANS(a)    ((a) / _DEGS)
#endif


/* numerical function macros */

/* absolute value of a */
#define ABS(a)          (((a) < 0) ? -(a) : (a))
#define NEG(a)          (((a) < 0) ? (a) : -(a))

/* round a to nearest integer towards 0 */
#define FLOOR(a)                ((a)>0 ? (int)(a) : -(int)(-a))

/* round a to nearest integer away from 0 */
#ifndef CEILING
#define CEILING(a) \
    ((a)==(int)(a) ? (a) : (a)>0 ? 1+(int)(a) : -(1+(int)(-a)))
#endif

/* round a to nearest int */
#define ROUND(a)        ((a)>0 ? (int)((a)+0.5) : (int)((a)-0.5))

/* take sign of a, either -1, 0, or 1 */
#define ZSIGN(a)         (((a) < 0) ? -1 : (a) > 0 ? 1 : 0)

/* take binary sign of a, either -1, or 1 if >= 0 */
#define SIGN(a)          (((a) < 0) ? -1 : 0)

/* square a */
#define SQR(a)          ((a)*(a))

/* swap a and b (see Gem by Wyvill) */
#define SWAP(a,b)       { a^=b; b^=a; a^=b; }

/* clamp the input to the specified range */
#define CLAMP(v,l,h)    ((v)<(l) ? (l) : (v) > (h) ? (h) : v)

#ifndef BZERO
#define BZERO(a,b)    bzero((char*)(a), (int)(b))
#define BCOPY(a,b,c)  bcopy((char*)(a), (char*)(b), (int)c)
#define FREE(a)   if ((char*)(a) != NULL)  free((char*)(a)), (a) = NULL
#endif

#ifndef MIN
#define MIN(a,b)  ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b)  ((a) > (b) ? (a) : (b))
#endif

#endif                          /* _XIMDEFS_H_ */
/*** end ximdefs.h ***/
