/*
(c) Copyright 1994 HEWLETT-PACKARD COMPANY

To anyone who acknowledges that this file is provided 
"AS IS" without any express or implied warranty:
permission to use, copy, modify, and distribute this 
file for any purpose is hereby granted without fee, 
provided that the above copyright notice and this 
notice appears in all copies, and that the name of 
Hewlett-Packard Company not be used in advertising or 
publicity pertaining to distribution of the software 
without specific, written prior permission.  Hewlett-
Packard Company makes no representations about the 
suitability of this software for any purpose.
*/



#ifndef _XSCM_LIBINT_H
#define _XSCM_LIBINT_H

#include <stdio.h>
#include <string.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include <X11/Xatom.h>

#include "xscmlib.h"

#define FALSE 0
#define TRUE  1
#define NULL  0


     /*  Definition of parameters to all render functions. */
#define RENDER_PARS \
    pInfo, src, srcRowBytes, width, height, pRed, pGreen, pBlue, dstRowBytes, dst

#define RENDER_PARS_FULL \
    XscmInfoRec  *pInfo; \
    unsigned char *src; \
    int           srcRowBytes; \
    int           width; \
    int           height; \
    int          *pRed; \
    int          *pGreen; \
    int          *pBlue; \
    int           dstRowBytes; \
    unsigned char *dst;


     /*  Definition of parameters to all display functions. */
#define DISPLAY_PARS \
    pInfo, src, srcRowBytes, width, height, pRed, pGreen, pBlue, \
    drawable, gc, x, y

#define DISPLAY_PARS_FULL \
    XscmInfoRec  *pInfo; \
    unsigned char *src; \
    int           srcRowBytes; \
    int           width; \
    int           height; \
    int          *pRed; \
    int          *pGreen; \
    int          *pBlue; \
    Drawable      drawable; \
    GC            gc; \
    int           x; \
    int           y;

    /*  Macro to generate Display function. */
#define DISPLAY_FUNCTION(_display, _render) \
 \
int _display (DISPLAY_PARS) \
    DISPLAY_PARS_FULL \
{ \
XImage           *image; \
unsigned char    *dst; \
int               dstRowBytes; \
 \
    dstRowBytes = width * pInfo->bytesPerPixel; \
    dst = (unsigned char *)malloc (height * dstRowBytes); \
    if (!dst) \
        return FALSE; \
    image = XCreateImage (pInfo->display, pInfo->visual, pInfo->depth, ZPixmap,  \
                0, (char *)dst, width, height, 8 * pInfo->bytesPerPixel, \
                dstRowBytes); \
    if (!image) { \
        free (dst); \
        return FALSE; \
        } \
    if (!_render (RENDER_PARS)) { \
        XDestroyImage (image); \
        return FALSE; \
        } \
    XPutImage (pInfo->display, drawable, gc, image, 0, 0, x, y, width, height); \
    XDestroyImage (image); \
    return TRUE; \
}

#endif
