Navigation
Home
gpl
danovitschwebcam
1.0
overlay.c








































overlay.c
   
   /*
    *
    * overlay.c - part of Danovitsch Webcam
    *
    * Copyright (C) 2001 by Daan Vreeken
    *
    * Published under the terms of the GNU Public License 2.0
    * (or any later version)
    *
    */
   
   
   
   
   #include <stdio.h>
   #include <stdlib.h>
   #include <stdarg.h>
   
   #include "capture.h"
   #include "overlayfont.h"
   #include "webcam.h"
   
   
   
   unsigned long		White = 0xffffff;
   unsigned long		Black = 0x000000;
   unsigned long		Red = 0xff0000;
   unsigned long		Green = 0x00ff00;
   unsigned long		Blue = 0x0000ff;
   
   
   
   void Overlay_Pixel(int X, int Y, unsigned long *Color)
   {
   	unsigned long		*Ptr = (unsigned long *)FrameBuffer;
   
   	if (FrameBuffer==NULL)
   		return;
   	if ((X<0) || (Y<0) || (X>=ImageWidth) || (Y>=ImageHeight))
   		return;
   
   	Ptr+=X + Y*ImageWidth;
   	*Ptr=*Color;
   }
   
   
   
   void Overlay_PutLetter(int X1, int Y1, unsigned char Letter, unsigned long *Color, unsigned long *BgColor)
   {
   	int		X,Y;
   	int		Bit;
   
   	for (Y=0; Y<16; Y++)
   		for (X=0; X<8; X++)
   		{
   			Bit=(Overlay_Font[Letter][Y] << X) & 128;
   
   			if (Bit)
   			{
   				if (Color!=NULL)
   					Overlay_Pixel(X1+X,Y1+Y,Color);
   			}
   			else
   			{
   				if (BgColor!=NULL)
   					Overlay_Pixel(X1+X,Y1+Y,BgColor);
   			}
   		}
   }
   
   
   
   void Overlay_PutString(int X, int Y, unsigned long *Color, unsigned long *BgColor, char *Txt)
   {
   	char		*Ptr = Txt;
   
   	while (*Ptr)
   	{
   		Overlay_PutLetter(X,Y,*Ptr++,Color,BgColor);
   		X+=8;
   	}
   }
   
   
   
   
   
   void Overlay_PrintF(int X, int Y, int Border, unsigned long *Color, unsigned long *BgColor, char *Txt, ...)
   {
   	va_list		List;
   	char		Buf[100];
   
   	va_start(List,Txt);
   
   	vsnprintf(Buf,sizeof(Buf),Txt,List);
   	Buf[sizeof(Buf)-1]=0;
   
   	va_end(List);
   
   	if (Border)
   	{
   		Overlay_PutString(X-1,Y,BgColor,NULL,Buf);
   		Overlay_PutString(X+1,Y,BgColor,NULL,Buf);
   		Overlay_PutString(X,Y-1,BgColor,NULL,Buf);
   		Overlay_PutString(X,Y+1,BgColor,NULL,Buf);
   		Overlay_PutString(X,Y,Color,NULL,Buf);
   	}
   	else
   		Overlay_PutString(X,Y,Color,BgColor,Buf);
   }
   
   
   

syntax highlighted by Code2HTML, v. 0.9.1


Email me with questions/comments : Daan <Danovitsch @ Vitsch . net>