/* -*- tab-width: 4 -*- */
/******************************************************************************      
 *
 *	Copyright 2004 The Orion Compiler Group. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE ORION COMPILER GROUP ``AS IS'' AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 * DISCLAIMED. IN NO EVENT SHALL THE ORION COMPILER GROUP OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are 
 * those of the authors and should not be interpreted as representing official 
 * policies, either expressed or implied, of the Orion Compiler Group.
 *
 ******************************************************************************/

/**************************************************************************
	Graphics routine code
 **************************************************************************/

// For the curious, tabs are set to 1, 5, 9, etc... Do not modify and resubmit
// with spaces. It makes the code harder to merge in changes.

#ifndef _GFX_H_
#define _GFX_H_

struct SRasterDecode
{
	UINT32	u32Flags;
	UINT16	u16Width;
	UINT16	u16Height;
	UINT16	u16Image;
	UINT16	u16ImagePitch;
	UINT8	u8Plane;
	UINT32	u32PlanePitch[8];
	UINT8	u8BPP;
	UINT32	u32XOffset[256];
	UINT32	u32YOffset[256];
	UINT8	u8ImageInc;
	UINT8	u8Mirror;
	UINT32	u32Mirror[4];
	UINT8	u8BitShift;
	UINT8	*pu8Transparent;
	UINT8	*pu8Under;			// array of colors which causes bg to show through
};

#define RD_NOMIRROR (~0)

#define DGF_NORMAL		0x00000000
#define DGF_TRANSPARENT 0x00000001
#define DGF_UNDER			0x00000002		// has an "under" field ; where a saveunder shows through
#define RASTER_FULLY_SOLID 0x00004		// Image is totally solid
#define RASTER_FULLY_TRANSPARENT 0x0008 // Image is totally transparent

#define	TILE_VFLIP			0x01
#define	TILE_HFLIP			0x02

struct SImage
{
	UINT8	*pu8Data;
	UINT8	*pu8Mask;
	UINT8	*pu8Under;
	UINT32	*pu32TransFlags;
	UINT32	u32Flags;
	UINT16	u16Width;
	UINT16	u16Height;
	UINT16	u16Images;
	UINT8	u8BPP;
};

// Dirty buffering structure

struct SDirtyBuffer
{
	UINT8 *pu8Buffer;
	UINT32 u32YShift;						// By how much do we shift our Y position?
	UINT32 u32XLineLength;					// Length of each graphic line in bytes
};
// Generic graphics structure used for all graphics calls

struct SGfx
{
	struct SImage *psImage;			// Image base
	UINT32 u32XSize;				// Size of tile/sprite to draw (X)
	UINT32 u32YSize;				// Size of tile/sprite to draw (Y)
	UINT32 u32Offset;				// Our character
	UINT32 u32Color;				// Color value
	UINT32 u32XPos;					// X Position
	UINT32 u32YPos;					// Y Position
	UINT8 *pu8Buffer;				// Pointer to our offscreen buffer to draw to
	UINT8 u8Orientation;			// Our image's orientation
};

struct sVector
{
	INT32 s32FromX;
	INT32 s32FromY;
	INT32 s32ToX;
	INT32 s32ToY;
	UINT8 bColor;
};

extern void GfxInit(void);
extern void GfxShutdown(void);
extern void GfxDecode(struct SRasterDecode *psRD, 
					  UINT8 *pu8Source,
					  struct SImage **psImage);
extern void GfxSetPaletteEntry(UINT32 u32EntryNumber,
							   UINT8 u8Red,
							   UINT8 u8Green,
							   UINT8 u8Blue);
extern void GfxFreeImage(struct SImage **ppsImage);
extern void GfxSetPaletteSize(UINT32 u32Entries);
extern void GfxSetBackBuffer(UINT32 u32XSize,
							 UINT32 u32YSize,
							 UINT32 u32XOverscan,
							 UINT32 u32YOverscan,
							 UINT8 u8ColorDepth);
extern void GfxSetDisplaySurface(UINT32 u32XSize,
								 UINT32 u32YSize,
								 UINT8 u8ColorDepth,
								 BOOL bWindowed);
extern void GfxBlit(void);
extern void GfxDraw(struct SGfx *psGfx);
extern void GfxSetFrameRate(UINT32 u32FramesPerSecond);
extern UINT8 ClipLine(INT32 *dwFromX, INT32 *dwFromY,
					   INT32 *dwToX, INT32 *dwToY,
						INT32 dwLeft, INT32 dwTop,
						INT32 dwRight, INT32 dwBottom);
extern void GfxGetViewportSize(UINT32 *pu32XSize,
							   UINT32 *pu32YSize);
extern void RasterVectorRender(struct sVector *psThisVB, UINT32 dwThisCount,
								 struct sVector *psPriorVB, UINT32 dwPriorCount,
								 struct sVector *psCurrentVB, UINT32 dwCurrentCount);

#endif

