#ifndef GRAPHICS_EXT_GFX_H
#define GRAPHICS_EXT_GFX_H

/*
**	$VER: extgfx.h 41.0 (18.12.96)
**	Includes Release 41.0 
**  (first public preview release)
**
**	extension to the original Amiga graphics/gfx.h
**
**	(C) Copyright 1996 Point Design by Jürgen Schober
**	    All Rights Reserved
**
**  The definitions in this file may be used by other
**  emulation developer, it is my wish to have 
**  common guides to one graphics.library extension !
*/

#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

// ------------------------------------------------------------------------------
// new flags for extended graphics 
// ------------------------------------------------------------------------------

#ifndef BMF_EXTENDED

#define BMB_BITMAPTAGS 6    // this is used for the TAG Flag
#define BMB_SPECIALFMT 7    // CyberGraphics
#define BMB_EXTENDED   8    // A flag to check if bitmap is struct ExtBitMap
#define BMB_RESERVED1  9    // the following 3 bits are reserved for
#define BMB_RESERVED2  10   // future use in Extended Graphics !!
#define BMB_RESERVED3  11


#define BMF_BITMAPTAGS  (1l<<BMB_BITMAPTAGS)
#define BMF_SPECIALFMT  (1l<<BMB_SPECIALFMT)
#define BMF_EXTENDED    (1l<<BMB_EXTENDED)
#define BMF_RESERVED1   (1l<<BMB_RESERVED1)   // the following 3 bits are reserved for
#define BMF_RESERVED2   (1l<<BMB_RESERVED2)   // future use in Extended Graphics !!
#define BMF_RESERVED3   (1l<<BMB_RESERVED3)

#endif 

// ------------------------------------------------------------------------------
// Extended Graphics provides a new API for AllocBitMap() that allows you to 
// define some TAGs to the BitMap. However, this is a bit dangerous. As I can
// not add a new function to the graphics.library I overload the original
// AllocBitMap(). To tell AllocBitMap() that Tags are present you have to set
// the BMF_BITMAPTAGS flag in the Flags field of the call - else TAGS are ignored !
// See below on how to check if a Bitmap is a struct ExtBitMap.
// Tags are not supported by EGSPlus V1 at the moment because I have to deal
// the current EGS Emualtion which uses the planepointers internally.
// A main function of the Tags is to hook custom data to the Bitmap. 
// This means you can allocate a chunky buffer (8 bit/pixel only, yet)
// and hook it into your bitmap. You may then access this buffer directly because
// the memory the buffer is located in will be locked by the system.
// You can then use standard blit functions to move this memory around.
//
// To the current EGSPlus, AllocBitMap(..,BMF_BITMAPTAGS, ..); will return NULL !
// ------------------------------------------------------------------------------

#ifdef BMF_BITMAPTAGS

// this might be moved to the protos.h 
struct ExtBitMap* __asm AllocBitMapTagList(register __d0 ULONG SizeX,register __d1 ULONG SizeY,
                                           register __d2 ULONG Depth, register __d3 ULONG Flags,
                                           register __a0 struct ExtBitMap *Friend,
                                           register __a1 struct TagItem *TagList);

#define BA_Dummy            (TAG_USER + 0x00100032)
#define BA_Width            (BA_Dummy + 0x0001)
#define BA_Height           (BA_Dummy + 0x0002)
#define BA_Depth            (BA_Dummy + 0x0003)
#define BA_Friend           (BA_Dummy + 0x0004)
#define BA_Flags            (BA_Dummy + 0x0005) // standard bitmap flags
#define BA_Class            (BA_Dummy + 0x0006) // reserved for later extgraphics classes
#define BA_Format           (BA_Dummy + 0x0007) // cyber style pixel format
#define BA_Plane            (BA_Dummy + 0x0008) // custom chunky data are provided
#define BA_BitPlanes        (BA_Dummy + 0x0009) // up to 24 custom bitplanes have to be added 
#define BA_BytesPerRow      (BA_Dummy + 0x000a) // bytes per row if set
#define BA_BytesPerPixel    (BA_Dummy + 0x000b) // bytes per pixel if set

#endif

// ------------------------------------------------------------------------------
// The NEW Extended BitMap structure used by EGSPlus and later by Extended Graphics.
//
// Basically all these fields in this structure may be accessed under special
// circumstances. Special rules are valid for the plane pointers. Under 
// EGSPlus only the chunky <ExtBitMap.Plane> pointer is accessable, since
// the other plane pointers are still used by the EGS Emulation. 
// Rules to access a plane pointer:
//
// 1. The BitMap was alllocated useing AllocBitMapTagList() and a custom
//    memory provided in BA_Planes or BA_BitPlanes
//    -- this is not yet available and will result a NULL on EGSPlus (v1)
//
// 2. The BitMap was allocated useing the BMF_SPECIALFMT flag (see above)
//    and provides a cybergraphics compatible pixelformat. Currently only
//    8 bit chunky is supported by EGSPlus (default Pixfmt, FORMAT = 0, see
//    the cybergraphics documentation for details). In this case the 
//    BitMap data are locked.
//
// 3. You have to check if the resulting BitMap is an strcut ExtBitMap.
//    This is done with the standard GetBitMapAttr():
//
//      BOOL IsExtGraphics = (GetBitMapAttr(BitMap,BMA_FLAGS) & BMF_EXTENDED);
//
// 4. now, if (IsExtGraphics) you may access the plane ptr
//
// 
// IT IS STRONGLY FORBIDDEN TO ACCESS PLANE POINTERS OF WINDOWS OR SCREENS !!!!
//
//
// It could even happen that a graphics device doesn't even have plane pointers,
// neither chunky nor planes (e.g. a display list device ! or e.g. the 2410).
// 
// ------------------------------------------------------------------------------

struct ExtBitMap        
{
// --------------------------------------------------------------------
// standard <struct BitMap>
// --------------------------------------------------------------------

    UWORD   BytesPerRow;
    UWORD   Rows;
    UBYTE   Flags;
    UBYTE   Depth;
    UWORD   pad;
    UBYTE   *Planes[24];    // extended to 24 bitplanes - hardly used though

// --------------------------------------------------------------------
// extended stuff here 
// --------------------------------------------------------------------

    APTR    Plane;          // chunky plane data
	LONG    Width,Height;

// --------------------------------------------------------------------
// below this point entries are system private
// I do not know how Viscorp will handle things, but they may change !
// --------------------------------------------------------------------

// ... ULONG[-1L];  DO NEVER USE sizeof(struct ExtBitMap) since this will grow !!!

};

#endif
