/**********************************************************************
 *
 * ibitmapm.h - basic bitmap operation interface
 *
 * there are three bitmap operate for software bitmap interface:
 *
 * create  - create a new bitmap and return the struct address
 * release - free the bitmap 
 * blit    - copy the speciafied rectangle from one bitmap to another
 *
 * the history of this file:
 * Feb. 7 2003    skywind    created including create/release/blit
 *
 * aim to platform independence, all of the sources are writen in ansi 
 * c but you can replace the default blitter by ibitmap_funcset() to 
 * optimized the benchmark of ibitmap_blit in the speciafied platform
 *
 **********************************************************************/

#ifndef __IBITMAPM_H__
#define __IBITMAPM_H__

#include "ibitmap.h"


/**********************************************************************
 * Bitmap Global Interface
 **********************************************************************/
#ifndef IBLIT_CLIP
#define IBLIT_CLIP    1    /* blit mode: enable clip */
#endif

#ifndef IBLIT_MASK
#define IBLIT_MASK    2    /* blit mode: enable transparent blit */
#endif

#ifndef IBLIT_HFLIP
#define IBLIT_HFLIP   4    /* flip horizon */
#endif

#ifndef IBLIT_VFLIP
#define IBLIT_VFLIP   8    /* flip vertical */
#endif


#ifdef  __cplusplus
extern "C" {
#endif



/**********************************************************************
 * Bitmap Function Definition
 **********************************************************************/

/*
 * ibitmap_create - create bitmap and return the pointer to struct IBITMAP
 * width  - bitmap width
 * height - bitmap height
 * bpp    - bitmap color depth (8, 16, 24, 32)
 */
struct IBITMAP *ibitmap_create(int width, int height, int bpp);


/*
 * ibitmap_release - release bitmap
 * bmp - pointer to the IBITMAP struct
 */
void ibitmap_release(struct IBITMAP *bmp);


/*
 * iclip - clip the rectangle from the source rectangle and 
 * caculate a new rectangle which is shared between dest and src rectangle:
 * (dw, dh) - dest bitmap width and height
 * (sw, sh) - source bitmap width and height
 * (x1, x2) - position in dest bitmap to blit at
 * (x2, y2, r2, b2) - rect (left,top,right,bottom) in source bitmap 
 * return zero for successful, return non-zero if there is no shared part
 */
int ibitmap_clip(int dw, int dh, int sw, int sh, int *x1, int *y1, 
             int *x2, int *y2, int *r2, int *b2);


/*
 * ibitmap_blit - blit from source bitmap to dest bitmap
 * returns zero for successful, others for error    
 * dst       - dest bitmap to draw on
 * x, y      - target position of dest bitmap to draw on
 * src       - source bitmap 
 * sx, sy    - source rectangle position in source bitmap
 * w, h      - source rectangle width and height in source bitmap
 * mask      - coloekey of source bitmap, ignored if no IBLIT_MASK
 * mode      - blit flag bits (IBLIT_CLIP, IBLIT_MASK)
 */
int ibitmap_blit(struct IBITMAP *dest, int dx, int dy, struct IBITMAP *src, 
          int x, int y, int w, int h, unsigned long mask, int mode);


/* ibitmap_fill - fill the rectangle with given color 
 * returns zero for successful, others for error
 * dst     - dest bitmap to draw on
 * dx, dy  - target position of dest bitmap to draw on
 * w, h    - width and height of the rectangle to be filled
 * col     - indicate the color to fill the rectangle
 */
int ibitmap_fill(struct IBITMAP *dst, int dx, int dy, int w, int h,
    unsigned long col, int noclip);



/**********************************************************************
 * Bitmap Basic Interface
 **********************************************************************/
typedef int (*ibitmap_blitter_norm)(char *, long, const char *, 
              int, int, long, int, long);
typedef int (*ibitmap_blitter_mask)(char *, long, const char *, 
              int, int, long, int, long, unsigned long);

typedef int (*ibitmap_blitter_flip)(char *, long, const char *,
              int, int, long, int, long, unsigned long, int);

typedef int (*ibitmap_filler)(char *, long, int, int, int, unsigned long);


#define IBITMAP_BLITER_NORM  0
#define IBITMAP_BLITER_MASK  1
#define IBITMAP_BLITER_FLIP  2

#define IBITMAP_FILLER   3

#define IBITMAP_MALLOC   4
#define IBITMAP_FREE     5



/*
 * ibitmap_funcset - set basic bitmap functions, returns zero for successful
 * mode - function index, there are two blitters, (0/1 normal/transparent) 
 * proc - extra function pointer, set it to null to use default method:
 *   int imyblitter0(char *dst, long pitch1, const char *src, 
 *       int w, int h, long pitch2, int pixelbyte);
 *   int imyblitter1(char *dst, long pitch1, const char *src, 
 *       int w, int h, long pitch2, int pixelbyte, unsigned long ckey);
 * there are two blitters, normal blitter and transparent blitter, which 
 * ibitmap_blit() will call to complete blit operation. 
 */
int ibitmap_funcset(int functionid, const void *proc);


/*
 * ibitmap_funcget - get the blitter function pointer, returns the address
 * of the blitter function, and returns NULL for error. for more information
 * please see the comment of ibitmap_funcset.
 */
void *ibitmap_funcget(int functionid, int version);


#ifdef  __cplusplus
}
#endif


#endif

