/*		 
		note: compilation de ce fichier optimisée en vitesse
*/


//
// Modifications History
//
//$LB (20/12/2002) : 16bits to 24bits
//



#include "CObjBuffer.h"
#include "utils.h"
#include "colors.h"



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)
{
    int dcx, dcy, scx, scy, color;
	unsigned char r, g, b;
	register i, j;
	register OBJBITMAP_BUFFER BufS;
	register OBJBITMAP_BUFFER BufD;

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\nclassicBlit");
#endif
//***********************************


	dcy = destY * DestBPL + (destX * 3);
    scy = srcY  * SrcBPL  + (srcX * 3);

	if ( transparency == NIL ) 
	{            
	   BufS = ((OBJBITMAP_BUFFER) bSrc ) + scy ;
	   BufD = ((OBJBITMAP_BUFFER) bDest ) + dcy ;

	   for ( j = 0 ; j < height ; j ++ )
	   {                 
				memcpy( BufD, BufS, width*3) ;
				BufD += DestBPL ;
				BufS += SrcBPL ;
	   }
	}
	else
	{
		for ( j = 0 ; j < height ; j ++ )
		{
			dcx = dcy ;
			scx = scy ;
			for ( i = 0 ; i < width ; i ++ , dcx +=3 , scx +=3 )
			{
				b = bSrc[ scx ];
				g = bSrc[ scx+1 ];
				r = bSrc[ scx+2 ];

				color = _COLOR_BGR_TO_I (b, g, r);

				if (color != transparency)
				{
					bDest[ dcx ] = b;
					bDest[ dcx+1 ] = g;
					bDest[ dcx+2 ] = r;
				}
			}
			dcy += DestBPL;
			scy += SrcBPL;
		}
	}


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\nclassicBlit end");
#endif
//***********************************

	return bDest;
}
