/*		 
		GESTION DU FORMAT DE FICHIER GRAPHIQUE AVEC COUCHE ALPHA POUR SCOL
								Mathieu CHAMPLON
									jul. 99
*/


//
// Modifications History
//
//$ LB (15/12/2002) : 16 bits to 24 bits
//
//$LB (07/02/2003) : flags debug
//

#include "x/Version.h"
#include "x/scolplugin.h"


#include <stdio.h>
#include <string.h>

#include "objstr.h"

#include "lib/png/png.h"

#include "readpng.h"
#include "importAPI2d.h"
#include "macros.h"
#include "colors.h"

int GRCreateBitmap(mmachine m);
int GRCreateBitmap8(mmachine m);
int GRDestroyBitmap(mmachine m);
int GRCopyBitmap(mmachine m);

/*cbmachine ww;
// added by Mat, temporary
int (*GRCreateBitmap)(mmachine m);
int (*GRCreateBitmap8)(mmachine m);
int (*GRDestroyBitmap)(mmachine m);
int (*GRCopyBitmap)(mmachine m);
*/
// UTILS






//
// GESTION DU FORMAT DE FICHIER GRAPHIQUE AVEC COUCHE ALPHA POUR SCOL
//


// prototypes
// classicBlit.c
OBJBITMAP_BUFFER classicBlit( OBJBITMAP_BUFFER bDest, OBJBITMAP_BUFFER bSrc,
					    int DestBPL, int SrcBPL,
					    int destX, int destY, int srcX, int srcY, int width, int height,
						int transparency);

OBJBITMAP_BUFFER classicStretchBlit( OBJBITMAP_BUFFER bDest, OBJBITMAP_BUFFER bRGB,
 	  						   int DestBPL, int RGBBPL,
							   int destX1, int destY1, int destX2, int destY2,
							   int srcX1, int srcY1, int srcX2, int srcY2,
							   int transparency );
// alphaBlit.c
OBJBITMAP_BUFFER alphaBlit( OBJBITMAP_BUFFER bDest, OBJBITMAP_BUFFER bRGB, OBJBITMAP_BUFFER bA,
					  int DestBPL, int RGBBPL, int ABPL,
					  int destX, int destY, int srcX, int srcY, int width, int height,
					  int transparency );

OBJBITMAP_BUFFER alphaStretchBlit( OBJBITMAP_BUFFER bDest, OBJBITMAP_BUFFER bRGB, OBJBITMAP_BUFFER bA,
	  					     int DestBPL, int RGBBPL, int ABPL,
							 int destX1, int destY1, int destX2, int destY2,
							 int srcX1, int srcY1, int srcX2, int srcY2,
							 int transparency);


// optimisation: passer en couleur de transparence qd alpha homogene et opaque
void separateRGBfromA( uch *data, OBJBITMAP_BUFFER RGBbitmap, OBJBITMAP_BUFFER Abitmap,
					   ulg image_rowbytes, int RGB_rowbytes, int A_rowbytes,
					   int image_channels, ulg image_width, ulg image_height )
{
ulg i, row, lastrow;
uch r, g, b, a;
uch *src;
OBJBITMAP_BUFFER destRGB;
OBJBITMAP_BUFFER destA;

/*****************************/
#if DEBUG_LIB2DOS
MMechostr (0, "\nseparateRGBfromA");
#endif
/*****************************/


	for ( lastrow = row = 0;  row < image_height; ++row ) 
	{

        src = data + row * image_rowbytes;
        destRGB = RGBbitmap + row * RGB_rowbytes;
        destA = Abitmap + row * A_rowbytes;

        if ( image_channels == 3 ) 
		{
            for ( i = image_width ; i > 0; --i ) 
			{
                r = *src++;
                g = *src++;
                b = *src++;
				*(destRGB++) = b;
				*(destRGB++) = g;
				*(destRGB++) = r;
				*destA++ = 255;
            }
        } else /* if ( image_channels == 4 ) */ 
		{
            for ( i = image_width ; i > 0; --i ) 
			{
                r = *src++;
                g = *src++;
                b = *src++;
                a = *src++;
				*(destRGB++) = b;
				*(destRGB++) = g;
				*(destRGB++) = r;
				*destA++ = a; 
            }
		}
	}

/*****************************/
#if DEBUG_LIB2DOS
MMechostr (0, "\nseparateRGBfromA end");
#endif
/*****************************/

}







/*
	 note: la couleur de transparence est NIL pour un png chargé dû à des conflits
		dans la palette de couleur dans le cas d'une image palettée (la valeur de 
		la couleur de transparence peut-être identique à celle d'une autre couleur,
		soit une autre entrée dans la palette).
*/
int _LDpngBitmap( mmachine m )
{
	FILE *infile = NULL;
	int tmp_res;
	int file_str;
	int channel;
	int bmpRGB, bmpA;
	char *filename;
	ulg image_width, image_height;
	uch bg_red=0, bg_green=0, bg_blue=0;
	uch trn_red=0, trn_green=0, trn_blue=0;
	int transparency = NIL;
	ulg image_rowbytes;
	int image_channels;
	uch *image_data;

/*****************************/
#if DEBUG_LIB2DOS
MMechostr (0, "\n_LDpngBitmap");
#endif
/*****************************/


	file_str = MTOP( MMpull( m ) );
	if ( file_str == NIL )
	{
		MMset( m, 0, NIL );
		return 0;
	}

	channel = MMget( m, 0 );
	if ( channel == NIL ) return 0;
	CHECK( MMpush( m, channel ) );  // on double le channel

	filename = (char *)MMstartstr( m, file_str );
	infile = fopen( filename, "rb" );

	if ( infile == NULL )
	{
		MMpull( m );
		MMset( m, 0, NIL );
		return 0;
	}


	if ( readpng_init( infile, &image_width, &image_height ) != 0 )
	{
		fclose( infile );
        readpng_cleanup( TRUE );
		MMpull( m );
		MMset( m, 0, NIL );
		return 0;
	}


	if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1)
	{
		fclose( infile );
        readpng_cleanup( TRUE );
		MMpull( m );
		MMset( m, 0, NIL );
		return 0;
	}

	/* tmp_res == 1 => pas de transparence */


	image_data = readpng_get_image( &image_channels, &image_rowbytes );

    fclose(infile);

    if (!image_data)
	{
		readpng_cleanup(TRUE);
		MMpull( m );
		MMset( m, 0, NIL );
		return 0;
	}


	// on cree les 2 bitmaps necessaires, les Chn sont deja empiles
	CHECK( MMpush( m, ITOM((int)image_width) ) );
	CHECK( MMpush( m, ITOM((int)image_height) ) );
	CHECK( GRCreateBitmap( m ) );

	bmpRGB = MTOP( MMget( m, 0 ) );
	if ( bmpRGB == NIL )
	{
        readpng_cleanup( TRUE );
		MMpull( m );
		MMset( m, 0, NIL ); // 2e channel
		return 0;
	}

	// on inverse l'ObjBitmap et le Chn
	INVERT( m, 0, 1 );
	CHECK( MMpush( m, ITOM((int)image_width) ) );
	CHECK( MMpush( m, ITOM((int)image_height) ) );
	CHECK( GRCreateBitmap8( m ) );

	bmpA = MTOP( MMget( m, 0 ) );
	if ( bmpA == NIL )
	{
        readpng_cleanup( TRUE );
		MMpull( m );
		MMset( m, 0, NIL );
		return 0;
	}

	bmpRGB = MTOP( MMget( m, 1 ) );

	separateRGBfromA( image_data,
					  GET_PTR_OBJ_BITMAP( bmpRGB )->bits,
					  GET_PTR_OBJ_BITMAP( bmpA )->bits,
					  image_rowbytes,
					  GET_PTR_OBJ_BITMAP( bmpRGB )->BPL,
					  GET_PTR_OBJ_BITMAP( bmpA )->BPL,
					  image_channels,
					  image_width,
					  image_height
					);

	readpng_cleanup(TRUE);

	CHECK( MMpush( m, ITOM ( _COLOR_BGR_TO_I ( bg_blue, bg_green, bg_red ))));
	CHECK( MMpush( m, transparency ) ); // NIL
	CHECK( MMpush( m, ITOM( 4 ) ) );
	CHECK( MBdeftab( m ) );

/*****************************/
#if DEBUG_LIB2DOS
MMechostr (0, "\n_LDpngBitmap end");
#endif
/*****************************/
	return 0; 
}




int _LDalphaBitmap( mmachine m )
{
	return _LDpngBitmap( m );
}




int _CRalphaBitmap( mmachine m )
{
	int tmp_res;
	int bitmapRGB, bitmapA, channel;
	int Width;
	int Height;

	int transparency = MMpull( m );
	int background = MMpull( m );

/*****************************/
#if DEBUG_LIB2DOS
MMechostr (0, "\n_CRalphaBitmap");
#endif
/*****************************/


	bitmapRGB = MTOP( MMget( m, 1 ) );
	channel = MMget( m, 2 );
	if ( channel == NIL || GET_PTR_OBJ_BITMAP( bitmapRGB ) == NULL )
	{
		MMpull( m );
		MMpull( m );
		MMset( m, 0, NIL );
		return 0;
	}

	// pile: Chn ObjBitmap ObjBitmap8

	bitmapA = MTOP( MMget( m, 0 ) );
	if ( bitmapA != NIL )
	{
		if ( GET_PTR_OBJ_BITMAP( bitmapA ) == NULL )
			MMset( m, 0, NIL );
		else
		{
			Width = GET_PTR_OBJ_BITMAP( bitmapA )->TailleW;
			Height = GET_PTR_OBJ_BITMAP( bitmapA )->TailleH;
			// prevision de la copie de bitmap
			CHECK( MMpush( m, ITOM( 0 ) ) );
			CHECK( MMpush( m, ITOM( 0 ) ) );
			// creation du bitmap
			// pile: Chn ObjBitmap ObjBitmap8 0 0
			CHECK( MMpush( m, MMget( m, 4 ) ) );  // cannal
			CHECK( MMpush( m, ITOM( Width ) ) );
			CHECK( MMpush( m, ITOM( Height ) ) );
			// pile: Chn ObjBitmap ObjBitmap8 0 0 Chn Width Height
			CHECK( GRCreateBitmap8( m ) );
			// pile: Chn ObjBitmap ObjBitmap8 0 0 ObjBitmap8
			// copie du bitmap
			// on commence par inverser source et destination
			INVERT( m, 0, 3 );
			CHECK( MMpush( m, ITOM( 0 ) ) );
			CHECK( MMpush( m, ITOM( 0 ) ) );
			CHECK( MMpush( m, ITOM( Width ) ) );
			CHECK( MMpush( m, ITOM( Height ) ) );
			CHECK( MMpush( m, NIL ) );
			// pile: Chn ObjBitmap ObjBitmap8 0 0 ObjBitmap8 0 0 Width Height NIL
			CHECK( GRCopyBitmap( m ) );
		}
	}


	// pile: Chn ObjBitmap ObjBitmap8

	// on inverse les 2 dernieres references...
	// ...et on fait la meme chose sur le bitmap RGB
	INVERT( m, 0, 1 );

	// pile: Chn ObjBitmap8 ObjBitmap
	
	bitmapRGB = MTOP( MMget( m, 0 ) );
	Width = GET_PTR_OBJ_BITMAP( bitmapRGB )->TailleW;
	Height = GET_PTR_OBJ_BITMAP( bitmapRGB )->TailleH;

	// prevision de la copie de bitmap
	CHECK( MMpush( m, ITOM( 0 ) ) );
	CHECK( MMpush( m, ITOM( 0 ) ) );
	// creation du bitmap
	// pile: Chn ObjBitmap8 ObjBitmap 0 0
	CHECK( MMpush( m, MMget( m, 4 ) ) );  // canal
	CHECK( MMpush( m, ITOM( Width ) ) );
	CHECK( MMpush( m, ITOM( Height ) ) );
	// pile: Chn ObjBitmap8 ObjBitmap 0 0 Chn Width Height

	CHECK( GRCreateBitmap( m ) );

	// pile: Chn ObjBitmap8 ObjBitmap 0 0 ObjBitmap
	// copie du bitmap
	// on commence par inverser source et destination
	INVERT( m, 0, 3 );
	CHECK( MMpush( m, ITOM( 0 ) ) );
	CHECK( MMpush( m, ITOM( 0 ) ) );
	CHECK( MMpush( m, ITOM( Width ) ) );
	CHECK( MMpush( m, ITOM( Height ) ) );
	CHECK( MMpush( m, NIL ) );
	// pile: Chn ObjBitmap8 ObjBitmap 0 0 ObjBitmap 0 0 Width Height NIL

	CHECK( GRCopyBitmap( m ) );
	// pile: Chn ObjBitmap8 ObjBitmap


	// on retire le canal
	INVERT( m, 0, 2 );
	MMpull( m );

	// pile: ObjBitmap ObjBitmap8
	CHECK( MMpush( m, background ) );
	CHECK( MMpush( m, transparency ) );
	CHECK( MMpush( m, ITOM( 4 ) ) );
	CHECK( MBdeftab( m ) );


/*****************************/
#if DEBUG_LIB2DOS
MMechostr (0, "\n_CRalphaBitmap end");
#endif
/*****************************/

	return 0;
}




int _DSalphaBitmap( mmachine m )
{
	int extern_res, tmp_res;
	int pABmp = MTOP( MMget( m, 0 ) );

//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\n_DSalphaBitmap");
#endif
//***********************************


	if ( pABmp == NIL ) return 0;

	CHECK( MMpush( m, MMfetch( m, pABmp, 0 ) ) );
	CHECK( GRDestroyBitmap( m ) );
	extern_res = MMpull( m );

	pABmp = MTOP( MMget( m, 0 ) );
	CHECK( MMpush( m, MMfetch( m, pABmp, 1 ) ) );
	CHECK( GRDestroyBitmap( m ) );
	extern_res = MMpull( m ) && extern_res;

	pABmp = MTOP( MMpull( m ) );
	MMstore( m, pABmp, 0, NIL );
	MMstore( m, pABmp, 1, NIL );
	MMstore( m, pABmp, 2, NIL );
	MMstore( m, pABmp, 3, NIL );

//**********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\n_DSalphaBitmap end");
#endif
//**********************************

	return MMpush( m, ITOM( extern_res ) );
}




int _CPalphaBitmap( mmachine m )
{
	int bitmapAlpha, bitmapDest;
	int width, height, srcX, srcY, destX, destY;
	int transparency;
	PtrObjBitmap ObjDest, ObjSrcRGB, ObjSrcA;
	int srcA;

//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\n_CPalphaBitmap");
#endif
//***********************************


	height = MTOI( MMpull( m ) );
	width = MTOI( MMpull( m ) );
	srcY = MTOI( MMpull( m ) );
	srcX = MTOI( MMpull( m ) );
	bitmapAlpha = MTOP( MMpull( m ) );
	destY = MTOI( MMpull( m ) );
	destX = MTOI( MMpull( m ) );
	bitmapDest = MTOP( MMget( m, 0 ) );

	if ( bitmapDest == NIL || bitmapAlpha == NIL )
		return 0;

	ObjSrcRGB = GET_PTR_OBJ_BITMAP( MTOP( MMfetch( m, bitmapAlpha, 0 ) ) );
	srcA = MTOP( MMfetch( m, bitmapAlpha, 1 ) );
	if ( srcA != NIL )
		ObjSrcA = GET_PTR_OBJ_BITMAP( srcA );
	else
		ObjSrcA = NULL;
	ObjDest =   GET_PTR_OBJ_BITMAP( bitmapDest );
	transparency = MTOI( MMfetch( m, bitmapAlpha, 3 ) );

	if ( ObjDest == NULL )
	{
		MMpull( m );
		return MMpush( m, NIL );
	}

	// bitmaps detruites ?
	if ( ObjSrcRGB == NULL )
		return 0;

	if ( ObjSrcA != NULL )
	{
		if ( ClipBlit( ObjDest->TailleW, ObjDest->TailleH, min(ObjSrcRGB->TailleW, ObjSrcA->TailleW), min(ObjSrcRGB->TailleH, ObjSrcA->TailleH),
					   &destX, &destY, &srcX, &srcY, &width, &height ) )
			alphaBlit( (OBJBITMAP_BUFFER)ObjDest->bits, (OBJBITMAP_BUFFER)ObjSrcRGB->bits,
					   (OBJBITMAP_BUFFER)ObjSrcA->bits, ObjDest->BPL, ObjSrcRGB->BPL, ObjSrcA->BPL,
					   destX, destY, srcX, srcY, width, height, transparency );
	} 
	else
	{
		if ( ClipBlit( ObjDest->TailleW, ObjDest->TailleH, ObjSrcRGB->TailleW, ObjSrcRGB->TailleH,
					   &destX, &destY, &srcX, &srcY, &width, &height ) )
			classicBlit( (OBJBITMAP_BUFFER)ObjDest->bits, (OBJBITMAP_BUFFER)ObjSrcRGB->bits,
				 	     ObjDest->BPL, ObjSrcRGB->BPL,
					     destX, destY, srcX, srcY, width, height, transparency );
	}

//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\n_CPalphaBitmap");
#endif
//***********************************

	return 0;
}


int _SCPalphaBitmap( mmachine m )
{
	int srcX1, srcY1, srcX2, srcY2, destX1, destY1, destX2, destY2;
	int bitmapAlpha, bitmapDest;
	int transparency;
    PtrObjBitmap ObjDest, ObjSrcRGB, ObjSrcA;
	int srcA;

//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\n_SCPalphaBitmap");
#endif
//***********************************

    srcY2 = MTOI( MMpull(m) );
    srcX2 = MTOI( MMpull(m) );
    srcY1 = MTOI( MMpull(m) );
    srcX1 = MTOI( MMpull(m) );
    bitmapAlpha = MTOP( MMpull(m) );
    destY2 = MTOI( MMpull(m) );
    destX2 = MTOI( MMpull(m) );
    destY1 = MTOI( MMpull(m) );
    destX1 = MTOI( MMpull(m) );
    bitmapDest = MTOP( MMget( m, 0 ) );
    
	if ( bitmapDest == NIL || bitmapAlpha == NIL )
		return 0;

	ObjSrcRGB = GET_PTR_OBJ_BITMAP( MTOP( MMfetch( m, bitmapAlpha, 0 ) ) );
	srcA = MTOP( MMfetch( m, bitmapAlpha, 1 ) );
	if ( srcA != NIL )
		ObjSrcA = GET_PTR_OBJ_BITMAP( srcA );
	else
		ObjSrcA = NULL;
	ObjDest =   GET_PTR_OBJ_BITMAP( bitmapDest );
	transparency = MTOI( MMfetch( m, bitmapAlpha, 3 ) );

	if ( ObjDest == NULL )
	{
		MMpull( m ) ;
		return MMpush( m, NIL );
	}

	// bitmaps detruites
	if ( ObjSrcRGB == NULL )
		return 0;

	if ( ObjSrcA != NULL )
	{
		if ( ClipStretch( ObjDest->TailleW, ObjDest->TailleH, min(ObjSrcRGB->TailleW, ObjSrcA->TailleW), min(ObjSrcRGB->TailleH, ObjSrcA->TailleH),
						  &destX1, &destY1, &destX2, &destY2, &srcX1, &srcY1, &srcX2, &srcY2 ) )
			alphaStretchBlit( (OBJBITMAP_BUFFER)ObjDest->bits, (OBJBITMAP_BUFFER)ObjSrcRGB->bits, (OBJBITMAP_BUFFER)ObjSrcA->bits,
							  ObjDest->BPL, ObjSrcRGB->BPL, ObjSrcA->BPL,
							  destX1, destY1, destX2, destY2, srcX1, srcY1, srcX2, srcY2,
							  transparency);
	}
	else
	{
		if ( ClipStretch( ObjDest->TailleW, ObjDest->TailleH, ObjSrcRGB->TailleW, ObjSrcRGB->TailleH,
						  &destX1, &destY1, &destX2, &destY2, &srcX1, &srcY1, &srcX2, &srcY2 ) )
			classicStretchBlit( (OBJBITMAP_BUFFER)ObjDest->bits, (OBJBITMAP_BUFFER)ObjSrcRGB->bits,
							  ObjDest->BPL, ObjSrcRGB->BPL,
							  destX1, destY1, destX2, destY2, srcX1, srcY1, srcX2, srcY2,
							  transparency);
	}

//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\n_SCPalphaBitmap end");
#endif
//***********************************

	return 0;
}



int _GETalphaBitmapSize( mmachine m )
{
	int tmp_res;
	int pABmp;
	int pRGB, pA;
	int Width, Height;

//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\n_GETalphaBitmapSize");
#endif
//***********************************

	pABmp = MTOP( MMpull( m ) );

	if ( pABmp == NIL ) return MMpush( m, NIL );

	pRGB = MTOP( MMfetch( m, pABmp, 0 ) );
	pA = MTOP( MMfetch( m, pABmp, 1 ) );

	if ( GET_PTR_OBJ_BITMAP( pRGB ) == NULL )
		return MMpush( m, NIL );

	if ( GET_PTR_OBJ_BITMAP( pA ) == NULL )
	{
		Width  = GET_PTR_OBJ_BITMAP( pRGB )->TailleW;
		Height = GET_PTR_OBJ_BITMAP( pRGB )->TailleH;
	}
	else
	{
		Width  = min( GET_PTR_OBJ_BITMAP( pRGB )->TailleW, GET_PTR_OBJ_BITMAP( pA )->TailleW );
		Height = min( GET_PTR_OBJ_BITMAP( pRGB )->TailleH, GET_PTR_OBJ_BITMAP( pA )->TailleH );
	}
	CHECK( MMpush( m, ITOM( Width ) ) );
	CHECK( MMpush( m, ITOM( Height ) ) );
	CHECK( MMpush( m, ITOM( 2 ) ) );

//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\n_GETalphaBitmapSize end");
#endif
//***********************************

	return MBdeftab( m );
}





int _GETalphaBitmapBackground( mmachine m )
{
	int pABmp = MTOP( MMpull( m ) );

	if ( pABmp == NIL )
		return MMpush( m, NIL );

	return MMpush( m, MMfetch( m, pABmp, 2 ) );
}



int _GETalphaBitmapTransparency( mmachine m )
{
	int pABmp = MTOP( MMpull( m ) );

	if ( pABmp == NIL )
		return MMpush( m, NIL );

	return MMpush( m, MMfetch( m, pABmp, 3 ) );
}

int _GETalphaBitmaps( mmachine m )
{
	int tmp_res;
	int pABmp = MTOP( MMpull ( m ));

	if ( pABmp == NIL )
		return MMpush( m, NIL );

	CHECK( MMpush( m, MMfetch( m, pABmp, 0 ) ) );
	CHECK( MMpush( m, MMfetch( m, pABmp, 1 ) ) );
	CHECK( MMpush( m, ITOM( 2 ) ) );
	return MBdeftab( m );
}

int _SETalphaBitmapBackground( mmachine m )
{
	int color = MMpull( m );
	int pABMP = MTOP( MMpull( m ) );

	if ( pABMP == NIL )
		return MMpush( m, ITOM( 0 ) );

	MMstore( m, pABMP, 2, color );

	return MMpush( m, 1 );
}

int _SETalphaBitmapTransparency( mmachine m )
{
	int color = MMpull( m );
	int pABMP = MTOP( MMpull( m ) );

	if ( pABMP == NIL )
		return MMpush( m, ITOM( 0 ) );

	MMstore( m, pABMP, 3, color );

	return MMpush( m, 1 );
}

#define NPLGPKG 12

char* mPLGname[NPLGPKG]=
{
 "AlphaBitmap",
 "_LDalphaBitmap", "_CRalphaBitmap", "_DSalphaBitmap",
 "_CPalphaBitmap", "_SCPalphaBitmap",
 "_GETalphaBitmaps", "_GETalphaBitmapSize", "_GETalphaBitmapBackground", "_GETalphaBitmapTransparency",
 "_SETalphaBitmapBackground", "_SETalphaBitmapTransparency"
};

int (*mPLGfun[NPLGPKG])(mmachine m)=
{
 NULL,
 _LDalphaBitmap, _CRalphaBitmap, _DSalphaBitmap,
 _CPalphaBitmap, _SCPalphaBitmap,
 _GETalphaBitmaps, _GETalphaBitmapSize, _GETalphaBitmapBackground, _GETalphaBitmapTransparency,
 _SETalphaBitmapBackground, _SETalphaBitmapTransparency
};

int mPLGnarg[NPLGPKG]=
{
 TYPTYPE,
 2, 5, 1,
 8, 10,
 1, 1, 1, 1,
 2, 2
};

char* mPLGtype[NPLGPKG]=
{
 NULL,
 "fun [Chn P] AlphaBitmap", "fun [Chn ObjBitmap ObjBitmap8 I I] AlphaBitmap", "fun [AlphaBitmap] I",
 "fun [ObjBitmap I I AlphaBitmap I I I I] ObjBitmap", "fun [ObjBitmap I I I I AlphaBitmap I I I I] ObjBitmap",
 "fun [AlphaBitmap] [ObjBitmap ObjBitmap8]", "fun [AlphaBitmap] [I I]", "fun [AlphaBitmap] I", "fun [AlphaBitmap] I",
 "fun [AlphaBitmap I] I", "fun [AlphaBitmap I] I"
};

int SCOLloadAlphaBitmap(mmachine m)
{
    int k;

#ifdef _DEBUG
	k=PKhardpak(m,"AlphaBitmap.pkg-1.1-debug",NPLGPKG,mPLGname,mPLGfun,mPLGnarg,mPLGtype);
#else
	k=PKhardpak(m,"AlphaBitmap.pkg-1.1",NPLGPKG,mPLGname,mPLGfun,mPLGnarg,mPLGtype);
#endif
    return k;
}
