//Dessine un pixel.
__inline void DessPix(register int x,register int y,register int c)		{
	register unsigned char *ptr;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;

	*(ptr++)=(unsigned char)((c&0x00ff0000)>>16);
	*(ptr++)=(unsigned char)((c&0x0000ff00)>>8);
	*(ptr++)=(unsigned char)(c&0x000000ff);
}

__inline void AddPix(register int x,register int y,int c)		{
	register unsigned char *ptr, *spr;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;

	spr=((unsigned char *)(&c))+2;
	if (*ptr>=255-*spr)			*ptr=255;
	else						*ptr+=*spr;
	ptr++, spr--;
	if (*ptr>=255-*spr)			*ptr=255;
	else						*ptr+=*spr;
	ptr++, spr--;
	if (*ptr>=255-*spr)			*ptr=255;
	else						*ptr+=*spr;
	ptr++, spr--;
}


__inline void SousPix(register int x,register int y,int c)		{
	register unsigned char *ptr, *spr;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;

	spr=((unsigned char *)(&c))+2;
	if (*ptr<=*spr)				*ptr=0;
	else						*ptr-=*spr;
	ptr++, spr--;
	if (*ptr<=*spr)				*ptr=0;
	else						*ptr-=*spr;
	ptr++, spr--;
	if (*ptr<=*spr)				*ptr=0;
	else						*ptr-=*spr;
	ptr++, spr--;
}

__inline void TransPix(register int x,register int y,int c, register int niveau)		{
	register unsigned char *ptr, *spr, nv=255-niveau;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;

	spr=((unsigned char *)(&c))+2;
	*(ptr++)=((*ptr)*nv+niveau*(*spr--))>>8;
	*(ptr++)=((*ptr)*nv+niveau*(*spr--))>>8;
	*(ptr++)=((*ptr)*nv+niveau*(*spr--))>>8;
}

__inline void XorPix(register int x,register int y,int c)		{
	register unsigned char *ptr, *spr;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;

	spr=((unsigned char *)(&c))+2;
	*(ptr++)^=*(spr--);
	*(ptr++)^=*(spr--);
	*(ptr++)^=*(spr--);
}

__inline void OrPix(register int x,register int y,int c)		{
	register unsigned char *ptr, *spr;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;

	spr=((unsigned char *)(&c))+2;
	*(ptr++)|=*(spr--);
	*(ptr++)|=*(spr--);
	*(ptr++)|=*(spr--);
}

__inline void AndPix(register int x,register int y,int c)		{
	register unsigned char *ptr, *spr;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;

	spr=((unsigned char *)(&c))+2;
	*(ptr++)&=*(spr--);
	*(ptr++)&=*(spr--);
	*(ptr++)&=*(spr--);
}

//Lit un pixel et stocke les valeurs r,v,b de celui-ci dans les paramètre correspondants.
__inline void LitPixRVB(register int x,register int y, register unsigned char *r, register unsigned char *v, register unsigned char *b)		{
	register unsigned char *ptr;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;
	*b=*(ptr++);
	*v=*(ptr++);
	*r=*(ptr++);
}

//Lit un pixel et stocke les valeurs r,v,b de celui-ci dans les paramètre correspondants.
__inline void LitPixRVBMasque(register int x,register int y, register unsigned char *r, register unsigned char *v, register unsigned char *b)		{
	register unsigned char *ptr;
	x+=CLIP_X0;
	y+=CLIP_Y0;
	if (x<0 || y<0 || x>=CLIP_X1 || y>=CLIP_Y1)
		return;
	ptr=Bits+LARG_BUF*3*(HAUT_BUF-y)+3*x;
	if (*ptr==0xfe)
		return;
	*b=*(ptr++);
	*v=*(ptr++);
	*r=*(ptr++);
}

__inline int RVB(register short r, register short v, register short b)		{
	if (r>255)	r=255;
	if (r<0)	r=0;
	if (v>255)	v=255;
	if (v<0)	v=0;
	if (b>255)	b=255;
	if (b<0)	b=0;
	return ((r) | (v<<8) | (b<<16));
}

