dslinux/user/pixil/packages/dvdview/dvdview/libvideogfx/libvideogfx/graphics/draw Makefile.am Makefile.in bmformat.cc bmformat.hh draw.cc draw.hh draw_mwin.cc draw_x11.cc draw_x11.hh

amadeus dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:25:40 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/pixil/packages/dvdview/dvdview/libvideogfx/libvideogfx/graphics/draw
In directory antilope:/tmp/cvs-serv11916/packages/dvdview/dvdview/libvideogfx/libvideogfx/graphics/draw

Added Files:
	Makefile.am Makefile.in bmformat.cc bmformat.hh draw.cc 
	draw.hh draw_mwin.cc draw_x11.cc draw_x11.hh 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: draw.cc ---
/*
 *  draw.cc
 */

#include <string.h>

#include "draw.hh"


template <class T> void DrawPoint(Bitmap<T>& bm,int x,int y,T color)
{
  if (x<0 || y<0) return;
  if (x>=bm.AskWidth() || y>=bm.AskHeight()) return;

  bm.AskFrame()[y][x]=color;
}


template <class T> void DrawLineSlow(Bitmap<T>& bm,int x1,int y1,int x2,int y2,T color)
{
  int vx = x2-x1;
  int vy = y2-y1;

  DrawPoint(bm,x1,y1,color);

  if (abs(vx)>abs(vy))
    {
      for (int x=0;x!=vx;x+=sign(vx))
	DrawPoint(bm , x1+x , vy*x/vx+y1 , color);
    }
  else
    {
      for (int y=0;y!=vy;y+=sign(vy))
	DrawPoint(bm , x1+vx*y/vy , y1+y , color);
    }
}


template <class T> void DrawDottedLine(Bitmap<T>& bm,int x1,int y1,int x2,int y2,T color)
{
  int vx = x2-x1;
  int vy = y2-y1;
  DrawPoint(bm,x1,y1,color);

  if (abs(vx)>abs(vy))
    {
      for (int x=0;x!=vx;x+=4*sign(vx))
	DrawPoint(bm , x1+x , vy*x/vx+y1 , color);
    }
  else
    {
      for (int y=0;y!=vy;y+=4*sign(vy))
	DrawPoint(bm , x1+vx*y/vy , y1+y , color);
    }
}


template <class T> void DrawFilledRectangleHV(Bitmap<T>& bm,int x0,int y0,int x1,int y1,T color)
{
  T*const* p = bm.AskFrame();

  for (int y=y0;y<=y1;y++)
    for (int x=x0;x<=x1;x++)
      p[y][x] = color;
}


template <class T> void Clear(Bitmap<T>& bm,T color)
{
  bm.Hint_ContentsIsNotUsedAnymore();

  T*const* p = bm.AskFrame();
  
  if (sizeof(T)==1)
    {
      for (int y=0;y<bm.AskHeight();y++)
	memset(p[y],color,bm.AskWidth());
    }
  else
    {
      DrawFilledRectangleHV(bm,0,0,bm.AskWidth()-1,bm.AskHeight()-1,color);
    }
}


#if 0
void CopyInnerBorder(const Image<Pixel>& src,Image<Pixel>& dst,int hwidth,int vwidth)
{
  for (int i=0;i<4;i++)
    {
            Bitmap<Pixel>& dstbm = dst.AskBitmap      ((Image<Pixel>::BitmapChannel)i);
      const Bitmap<Pixel>& srcbm = src.AskBitmap_const((Image<Pixel>::BitmapChannel)i);


      // Skip empty bitmaps.

      assert(srcbm.IsEmpty() == dstbm.IsEmpty());

      if (srcbm.IsEmpty())
	continue;


      // Copy border.

      int w = srcbm.AskWidth();
      int h = srcbm.AskHeight();

      assert(dstbm.AskWidth()  == w);
      assert(dstbm.AskHeight() == h);

            Pixel*const* dp = dstbm.AskFrame();
      const Pixel*const* sp = srcbm.AskFrame_const();

      // Horizontal stripes.

      for (int x=0;x<w;x++)
	for (int y=0;x<vwidth;y++)
	  {
	    dp[    y][x]=sp[    y][x];
	    dp[h-1-y][x]=sp[h-1-y][x];
	  }

      // Vertical stripes.
      
      for (int y=vwidth;y<h-vwidth;y++)
	for (int x=0;x<hwidth;x++)
	  {
	    dp[y][    x]=sp[y][    x];
	    dp[y][w-1-x]=sp[y][w-1-x];
	  }
    }
}
#endif

#if 1
void EnhanceImageWithBorder(Image<Pixel>& img,int borderwidth,bool exactsize)
{
  for (int i=0;i<4;i++)
    {
      Bitmap<Pixel>& srcbm = img.AskBitmap((Image<Pixel>::BitmapChannel)i);
      Bitmap<Pixel>* dstbm;
      Bitmap<Pixel>  newbm;

      if (srcbm.IsEmpty())
	continue;

      int w = srcbm.AskWidth(), h = srcbm.AskHeight();

      bool replacebm;

      if ((!exactsize && srcbm.AskBorderWidth() >= borderwidth) ||
	  ( exactsize && srcbm.AskBorderWidth() == borderwidth))
	{
	  dstbm = &srcbm;
	  replacebm=false;
	}
      else
	{
	  newbm.Create(w,h,1,1,borderwidth);
	  dstbm = &newbm;
	  replacebm = true;
	}

      const Pixel*const* sp = srcbm.AskFrame_const();
            Pixel*const* dp = dstbm->AskFrame();

      for (int y=0;y<h;y++)
	for (int x=0;x<w;x++)
	  {
	    dp[y][x] = sp[y][x];
	  }

      for (int y=0;y<h;y++)
	for (int x=0;x<borderwidth;x++)
	  {
	    dp[y][-1-x]=dp[y][0];
	    dp[y][w+x] =dp[y][w-1];
	  }

      for (int x=-borderwidth;x<w+borderwidth;x++)
	for (int y=0;y<borderwidth;y++)
	  {
	    dp[-1-y][x]=dp[0][x];
	    dp[h+y][x] = dp[h-1][x];
	  }

      if (replacebm)
	img.ReplaceBitmap((Image<Pixel>::BitmapChannel)i,*dstbm);
    }
}
#endif



// This function draws a rectangle. To do so it calls four times the DrawLine(...) function 
template <class T> void DrawRectangle(Bitmap<T>& bm,int x1,int y1,int w, int h,T color)
{
T*const* p = bm.AskFrame();

 DrawLine(bm,x1,y1,x1+w,y1,color);
 DrawLine(bm,x1+w,y1,x1+w,y1+h,color);
 DrawLine(bm,x1+w,y1+h,x1,y1+h,color);
 DrawLine(bm,x1,y1+h,x1,y1,color);
}

// This function is a part of the DrawLine algorithm. Do not call this function directly
static bool Clipt(double denom,double num, double& tE, double& tL)
{
  double t;
  bool accept = true;

  if (denom > 0)
    {
      t = num/denom;
      if (t > tL)
	accept = false;
      else
	if (t > tE)
	  tE = t;
    }
  else if (denom < 0)
    {
      t = num/denom;
      if (t < tE)
	accept = false;
      else
	if (t < tL)
	  tL = t;
    }
  else
    if (num > 0)
      accept = false;

  return accept;
}

// This function is a part of the DrawLine algorithm. Do not call it dirctly
void ClipLine(int& x0,int& y0,int& x1, int& y1, int xMax, int yMax, bool& visible)
{

  double dx = (double)(x1 - x0);
  double dy = (double)(y1 - y0);
  double tE = 0.0;
  double tL = 1.0;
  visible = false;
    
  if (Clipt(dx,0-(x0),tE,tL))
    if (Clipt(-dx,x0-xMax+1,tE,tL))
      if (Clipt(dy,0-(y0),tE,tL))
	if (Clipt(-dy,y0-yMax+1,tE,tL))
	  {
	    visible = true;
	    if (tL < 1.0)
	      {
		x1 = (int)(x0 + tL * dx+.5);
		y1 = (int)(y0 + tL * dy+.5);
	      }
	    if (tE > 0.0)
	      {
		x0 =(int)( x0 + tE * dx+.5);
		y0 =(int)( y0 + tE * dy+.5);
	      }
	  }

  if (visible)
    {
      assert(x0>=0);
      assert(y0>=0);
      assert(x0<xMax);
      assert(y0<yMax);
    }
}


template <class Pel> ArrowPainter<Pel>::ArrowPainter()
{
  SetAlpha(30);
  len  =10;
  bothheads=false;
  color=255;
}

// This function draws a line and places a head on one (arrows == false) or both (arrows==true) sides of the line.
template <class T> void DrawArrow(Bitmap<T>& bm,int x0,int y0,int x1, int y1,double alpha,int l,T color,bool arrows = false)
{
  DrawLine(bm,x0,y0,x1,y1,color);     

  // zeichnen der Pfeilspitze
  int xa,ya,dxp,dyp;
  double norm;
      
  dxp = x1-x0;
  dyp = y1-y0;

  norm = sqrt(dxp*dxp+dyp*dyp);
      
  xa = (int)((cos(alpha)*dxp-sin(alpha)*dyp)*l/norm);
  ya = (int)((sin(alpha)*dxp+cos(alpha)*dyp)*l/norm);

  DrawLine(bm,x1,y1,x1-xa,y1-ya,color);     

  if (arrows == true)
    {
      DrawLine(bm,x0,y0,x0+xa,y0+ya,color);
    }

  xa = (int)(( cos(alpha)*dxp+sin(alpha)*dyp)*l/norm);
  ya = (int)((-sin(alpha)*dxp+cos(alpha)*dyp)*l/norm);

  DrawLine(bm,x1,y1,x1-xa,y1-ya,color);  

  if (arrows == true)
    {
      DrawLine(bm,x0,y0,x0+xa,y0+ya,color);
    }


}

// main function to draw a line very fast. Clipping is included, so don't think about it
template <class T> void DrawLine(Bitmap<T>& bm,int x0,int y0,int x1, int y1,T color)
{
  T*const* p = bm.AskFrame();
  bool visible = true;

  int xMax= bm.AskWidth();
  int yMax= bm.AskHeight();

  if ((x0<0) || (y0<0) || (x1<0) || (y1<0) || (x0>=xMax) || (y0>=yMax) || (x1>=xMax) || (y1>=yMax))
    {
      ClipLine(x0,y0,x1,y1,xMax,yMax,visible);
#if 0
      cout << "x0 = " << x0 << endl;
      cout << "y0 = " << y0 << endl;
      cout << "x1 = " << x1 << endl;
      cout << "y1 = " << y1 << endl;
#endif
    }

  if (visible)
    {
      if (abs(y1-y0)>abs(x1-x0))
	{
	  if (y1<y0) {  swap(x0,x1); swap(y0,y1); }

	  int xinc;
	  int dy = y1 - y0;
	  int dx = x1 - x0;

	  if (dx < 0)
	    {
	      xinc = -1;
	      dx = -dx;
	    }
	  else
	    xinc = 1;

	  int d = 2* dx - dy;
	  int incrE = 2 * dx;  // Increment used for move to E
	  int incrNE = 2 * (dx - dy);   // increment used for move to NE
	  int y = y0;
	  int x = x0;

	  while (y <= y1)
	    {
	  
	      p[y][x] = color;
     
	      if (d <= 0)   // Choose E
		{
		  d = d + incrE;
		  y++;
		}
	      else         // Choose NE
		{
		  d = d + incrNE;
		  y++;
		  x = x + xinc;
		}
	    }
	}
      else{
	if (x1<x0) {  swap(x0,x1); swap(y0,y1); }

	int yinc;
	int dx = x1 - x0;
	int dy = y1 - y0;

	if (dy < 0)
	  {
	    yinc = -1;
	    dy = -dy;
	  }
	else
	  yinc = 1;

	int d = 2* dy - dx;
	int incrE = 2 * dy;  // Increment used for move to E
	int incrNE = 2 * (dy - dx);   // increment used for move to NE
	int x = x0;
	int y = y0;

	while (x <= x1)
	  {
	  
	    p[y][x] = color;
     
	    if (d <= 0)   // Choose E
	      {
		d = d + incrE;
		x++;
	      }
	    else         // Choose NE
	      {
		d = d + incrNE;
		x++;
		y = y + yinc;
	      }
	  }
      }
    }
}

//Pointer is set to this function if the circle is full visible 
template <class T> static void CirclePoints_Direct(Bitmap<T>& bm,int x0,int y0,int dx,int dy,T color,bool fill=false)
{
  T*const* p = bm.AskFrame();

  static int xMax= bm.AskWidth();
  static int yMax= bm.AskHeight();

  int y0dy1=y0-dy;
  int y0dy2=y0+dy;
  int x0dx1=x0-dx;
  int x0dx2=x0+dx;

  int y0dx1=y0-dx;
  int y0dx2=y0+dx;
  int x0dy1=x0-dy;
  int x0dy2=x0+dy;

  
  p[y0dy1][x0dx1]=color;
  p[y0dy1][x0dx2]=color;
  p[y0+dy][x0-dx]=color;
  p[y0+dy][x0+dx]=color;

  p[y0-dx][x0-dy]=color;
  p[y0-dx][x0+dy]=color;
  p[y0+dx][x0-dy]=color;
  p[y0+dx][x0+dy]=color;
  if (fill == true)   // if fill is true, fill up the circle from the top to the bottom
    {
      DrawLine(bm,x0dx1,y0dy1,x0dx2,y0dy1,color);
      DrawLine(bm,x0dy1,y0dx1,x0dy2,y0dx1,color);
      DrawLine(bm,x0dy2,y0dx2,x0dy1,y0dx2,color);
      DrawLine(bm,x0dx2,y0dy2,x0dx1,y0dy2,color);      
    }

}

//Pointer is set to this function if the circle is not fully visible 
template <class T> static void CirclePoints_Save(Bitmap<T>& bm,int x0,int y0,int dx,int dy,T color,bool fill=false)
{
  T*const* p = bm.AskFrame();

  static int xMax= bm.AskWidth();
  static int yMax= bm.AskHeight();

  int y0dy1=y0-dy;
  int y0dy2=y0+dy;
  int x0dx1=x0-dx;
  int x0dx2=x0+dx;

  int y0dx1=y0-dx;
  int y0dx2=y0+dx;
  int x0dy1=x0-dy;
  int x0dy2=x0+dy;

  
  if ((y0dy1)>=0 && (x0dx1)>=0 && (y0dy1)<yMax && (x0dx1)<xMax)
    p[y0dy1][x0dx1]=color;
  if ((y0dy1)>=0 && (x0dx2)>=0 && (y0dy1)<yMax && (x0dx2)<xMax)
    p[y0dy1][x0dx2]=color;
  if ((y0dy2)>=0 && (x0dx1)>=0 && (y0dy2)<yMax && (x0dx1)<xMax)
    p[y0+dy][x0-dx]=color;
  if ((y0dy2)>=0 && (x0dx2)>=0 && (y0dy2)<yMax && (x0dx2)<xMax)
    p[y0+dy][x0+dx]=color;


  if ((y0dx1)>=0 && (x0dy1)>=0 && (y0dx1)<yMax && (x0dy1)<xMax)
    p[y0-dx][x0-dy]=color;
  if ((y0dx1)>=0 && (x0dy2)>=0 && (y0dx1)<yMax && (x0dy2)<xMax)
    p[y0-dx][x0+dy]=color;
  if ((y0dx2)>=0 && (x0dy1)>=0 && (y0dx2)<yMax && (x0dy1)<xMax)
    p[y0+dx][x0-dy]=color;
  if ((y0dx2)>=0 && (x0dy2)>=0 && (y0dx2)<yMax && (x0dy2)<xMax)
    p[y0+dx][x0+dy]=color;

  if (fill == true) // if fill is true, fill up the circle from the top to the bottom
    {
      DrawLine(bm,x0dx1,y0dy1,x0dx2,y0dy1,color);
      DrawLine(bm,x0dy1,y0dx1,x0dy2,y0dx1,color);
      DrawLine(bm,x0dy2,y0dx2,x0dy1,y0dx2,color);
      DrawLine(bm,x0dx2,y0dy2,x0dx1,y0dy2,color);      
    }
}

// main function to draw a circle
template <class T> void DrawCircle(Bitmap<T>& bm,int x0,int y0, int radius,T color,bool fill = false)
{
  int x,y,d;

  void (*drawpoints)(Bitmap<T>& bm,int x0,int y0,int dx,int dy,T color,bool fill =false);

  /* int octant[8];*/ /* -1: draussen
		     0: drin
		     1: halb drin/draussen */

  x=0;
  y=radius;
  d=1-radius;

  if (x0-radius>=0 && x0+radius<bm.AskWidth() &&
      y0-radius>=0 && y0+radius<bm.AskHeight())
    { drawpoints = CirclePoints_Direct; }
  else
    { drawpoints = CirclePoints_Save; }

  drawpoints(bm,x0,y0,x,y,color,fill);

  while (y>x)
    {
      if (d<0)
	{
	  d=d+2*x+3;
	  x++;
	}
      else
	{
	  d=d+2*(x-y)+5;
	  x++;
	  y--;
	}
      drawpoints(bm,x0,y0,x,y,color,fill);
    }
}

// this function draws an ellipse. Clipping is also included.
template <class T> void DrawEllipse(Bitmap<T>& bm,int xm,int ym, int a,int b,double angle,T color)
{
  T*const* p = bm.AskFrame();
  static int flag = 0;

  const double beta = angle*M_PI/180;

  const double cosb = cos(beta);
  const double sinb = sin(beta);
  static double alpha_step = M_PI/180;
  int x[3],y[3];

  for (double alpha=0;alpha<2*M_PI;alpha+=alpha_step)
    {

      double sina,cosa;

      cosa = cos(alpha)*a;
      sina = sin(alpha)*b;

      x[0] = (int)((cosa*cosb - sina*sinb)+0.5);
      y[0] = (int)((sinb*cosa + sina*cosb)+0.5);
      
      //      cout << x[0] << "," << y[0] << " = ";
      

      if (flag < 1 || (abs(x[0]-x[1])==1 && abs(y[0]-y[1])==1) || 
	  (abs(x[0]-x[1])==0 && abs(y[0]-y[1])==1) || 
	  (abs(x[0]-x[1])==1 && abs(y[0]-y[1])==0))
	{
	  if (flag == 0)
	    {
	      x[1]=x[0];
	      y[1]=y[0];
	      flag = 1;
	    }
	  if (flag == 1)
	    {
 	      x[2]=x[1];
	      y[2]=y[1];
	      x[1]=x[0];
	      y[1]=y[0];

	      flag = 2;
	    }
	  
	  if (!(abs(x[0]-x[2])==1 && abs(y[0]-y[2])==1))
	  {
	    
	    if (!(x[1]+xm<0 || y[1]+ym<0 || x[1]+xm>=bm.AskWidth() || y[1]+ym>=bm.AskHeight()))
	      p[x[1]+xm][y[1]+ym]=color;
    
	    x[2]=x[1];
	    y[2]=y[1];
	    
	    x[1]=x[0];
	    y[1]=y[0];

	    //	    cout << "draw!" << endl;
	  }
	  else
	    {
	    x[1]=x[0];
	    y[1]=y[0];
	    //	    cout << "cut!" << endl;
	    }
	}
      else if (abs(x[0]-x[1])==0 && abs(y[0]-y[1])==0)
	{
	  alpha -= alpha_step;
	  alpha_step += alpha_step;
	  //	  cout << "alpha_step up =" << alpha_step << endl;
	}
      else
	{
	  alpha -= alpha_step;
	  alpha_step *= 0.9;
	  //	  cout << "alpha_step down =" << alpha_step << endl;
	}
 

    }
  if (!(x[0]+xm<0 || y[0]+ym<0 || x[0]+xm>=bm.AskWidth() || y[0]+ym>=bm.AskHeight()))
    p[x[0]+xm][y[0]+ym]=color;
}



template void DrawRectangle(Bitmap<Pixel>& bm,int x1,int y1,int w, int h,Pixel color);
template void DrawArrow(Bitmap<Pixel>& bm,int x0,int y0,int x1, int y1,double alpha,int l,
			Pixel color,bool arrows);
template void DrawLine(Bitmap<Pixel>& bm,int x0,int y0,int x1, int y1,Pixel color);
template void DrawCircle(Bitmap<Pixel>& bm,int x0,int y0, int radius,Pixel color,bool);
template void DrawEllipse(Bitmap<Pixel>& bm,int xm,int ym, int a,int b,double angle,Pixel);
template class ArrowPainter<Pixel>;


template void DrawPoint     (Bitmap<Pixel>&,int x,int y,Pixel color);
template void DrawLineSlow  (Bitmap<Pixel>&,int x1,int y1,int x2,int y2,Pixel color);
template void DrawDottedLine(Bitmap<Pixel>&,int x1,int y1,int x2,int y2,Pixel color);
template void DrawFilledRectangleHV(Bitmap<Pixel>&,int x0,int y0,int x1,int y1,Pixel color);
template void Clear         (Bitmap<Pixel>&,Pixel color);

template void Clear         (Bitmap<bool>&,bool color);

--- NEW FILE: draw_x11.hh ---
/*********************************************************************
  draw/draw_x11.hh

  purpose:
    Drawing routines that need X11 but that do not create any
    GUI windows in that sense. X11 is needed for example to get
    access to the fonts that are installed on the system.

  notes:

  to do:

  author(s):
   - Dirk Farin, farin at ti.uni-mannheim.de
     University Mannheim, Dept. Circuitry and Simulation
     B 6,26 EG, room 0.10 / D-68131 Mannheim / Germany

  modifications:
    21/Jul/1999 - Dirk Farin - cleanup
 *********************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_DRAW_DRAW_X11_HH
#define LIBVIDEOGFX_GRAPHICS_DRAW_DRAW_X11_HH

#include "libvideogfx/graphics/basic/bitmap.hh"
#include "libvideogfx/graphics/basic/image.hh"


/* Draw text into the bitmap. */
enum HTextAlign   { HAlign_Left,HAlign_Center,HAlign_Right  };
enum VTextAlign   { VAlign_Top ,VAlign_Center,VAlign_Bottom };
enum TextDrawMode { TextDrawMode_Transparent,TextDrawMode_Opaque };

void WriteText(Bitmap<Pixel>&,const char* txt,int x,int y,const char* x11fontname="9x15",
	       HTextAlign halign=HAlign_Left,VTextAlign valign=VAlign_Top,
	       TextDrawMode mode = TextDrawMode_Transparent,Pixel front=255,Pixel back=0);

#endif

--- NEW FILE: bmformat.hh ---
#/*********************************************************************
  libvideogfx/graphics/draw/bmformat.hh

  purpose:
    Functions for extending borders, change format of bitmaps...

  notes:

  to do:

  author(s):
   - Dirk Farin, farin at ti.uni-mannheim.de
     University Mannheim, Dept. Circuitry and Simulation
     B 6,26 EG, room 0.10 / D-68131 Mannheim / Germany

  modifications:
    04/Jul/2000 - Dirk Farin - bitmap format conversion and helpers
 *********************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_DRAW_BMFORMAT_HH
#define LIBVIDEOGFX_GRAPHICS_DRAW_BMFORMAT_HH

#include "libvideogfx/graphics/basic/bitmap.hh"
#include "libvideogfx/graphics/basic/image.hh"


template <class A,class B> void ConvertBitmap(const Bitmap<A>& src,Bitmap<B>& dst);

/* Copy a number of lines at the inner border of the image. */
template <class T> void CopyInnerBorder(const Image<T>& src,Image<T>& dst,int hwidth,int vwidth);

/* Creates a border of the specified with around the image and copies the border
   pixel values into it. */
template <class T> void ExtrudeIntoBorder(Image<T>&);
template <class T> void ExtrudeIntoBorder(Bitmap<T>&);

#define CopyImageIntoBorder  ExtrudeIntoBorder      // OBSOLET
#define CopyBitmapIntoBorder ExtrudeIntoBorder      // OBSOLET

template <class T> void SetBitmapBorder(Bitmap<T>&,const T& val);


template <class T> void RemoveColor(Image_YUV<T>&);
template <class T> void ConvertGreyToRGB(const Image_YUV<T>&,Image_RGB<T>&);

#endif

--- NEW FILE: Makefile.in ---
# Makefile.in generated automatically by automake 1.4 from Makefile.am

# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.


SHELL = @SHELL@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include

DESTDIR =

pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@

top_builddir = ../../..

ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@

NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_alias = @build_alias@
build_triplet = @build@
host_alias = @host_alias@
host_triplet = @host@
target_alias = @target_alias@
target_triplet = @target@
AS = @AS@
CC = @CC@
CXX = @CXX@
DLLTOOL = @DLLTOOL@
LIBTOOL = @LIBTOOL@
LIBVIDEOGFX_BINARY_AGE = @LIBVIDEOGFX_BINARY_AGE@
LIBVIDEOGFX_INTERFACE_AGE = @LIBVIDEOGFX_INTERFACE_AGE@
LIBVIDEOGFX_MAJOR_VERSION = @LIBVIDEOGFX_MAJOR_VERSION@
LIBVIDEOGFX_MICRO_VERSION = @LIBVIDEOGFX_MICRO_VERSION@
LIBVIDEOGFX_MINOR_VERSION = @LIBVIDEOGFX_MINOR_VERSION@
LIBVIDEOGFX_VERSION = @LIBVIDEOGFX_VERSION@
LN_S = @LN_S@
LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
LT_RELEASE = @LT_RELEASE@
LT_REVISION = @LT_REVISION@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
OBJDUMP = @OBJDUMP@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
VERSION = @VERSION@
X_LDFLAGS = @X_LDFLAGS@

noinst_LTLIBRARIES = libvideogfx-graphics-draw.la

libvideogfx_graphics_draw_la_SOURCES =  	bmformat.cc		bmformat.hh		draw.cc			draw.hh


INCLUDES =  	-I$(top_srcdir)

mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../../../config.h
CONFIG_CLEAN_FILES = 
LTLIBRARIES =  $(noinst_LTLIBRARIES)


DEFS = @DEFS@ -I. -I$(srcdir) -I../../..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libvideogfx_graphics_draw_la_LDFLAGS = 
libvideogfx_graphics_draw_la_LIBADD = 
libvideogfx_graphics_draw_la_OBJECTS =  bmformat.lo draw.lo
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
DIST_COMMON =  Makefile.am Makefile.in


DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)

TAR = gtar
GZIP_ENV = --best
DEP_FILES =  .deps/bmformat.P .deps/draw.P
SOURCES = $(libvideogfx_graphics_draw_la_SOURCES)
OBJECTS = $(libvideogfx_graphics_draw_la_OBJECTS)

all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .cc .lo .o .s
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
	cd $(top_srcdir) && $(AUTOMAKE) --gnu libvideogfx/graphics/draw/Makefile

Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status $(BUILT_SOURCES)
	cd $(top_builddir) \
	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status


mostlyclean-noinstLTLIBRARIES:

clean-noinstLTLIBRARIES:
	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)

distclean-noinstLTLIBRARIES:

maintainer-clean-noinstLTLIBRARIES:

.s.o:
	$(COMPILE) -c $<

.S.o:
	$(COMPILE) -c $<

mostlyclean-compile:
	-rm -f *.o core *.core

clean-compile:

distclean-compile:
	-rm -f *.tab.c

maintainer-clean-compile:

.s.lo:
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<

.S.lo:
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<

mostlyclean-libtool:
	-rm -f *.lo

clean-libtool:
	-rm -rf .libs _libs

distclean-libtool:

maintainer-clean-libtool:

libvideogfx-graphics-draw.la: $(libvideogfx_graphics_draw_la_OBJECTS) $(libvideogfx_graphics_draw_la_DEPENDENCIES)
	$(CXXLINK)  $(libvideogfx_graphics_draw_la_LDFLAGS) $(libvideogfx_graphics_draw_la_OBJECTS) $(libvideogfx_graphics_draw_la_LIBADD) $(LIBS)
.cc.o:
	$(CXXCOMPILE) -c $<
.cc.lo:
	$(LTCXXCOMPILE) -c $<

tags: TAGS

ID: $(HEADERS) $(SOURCES) $(LISP)
	list='$(SOURCES) $(HEADERS)'; \
	unique=`for i in $$list; do echo $$i; done | \
	  awk '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	here=`pwd` && cd $(srcdir) \
	  && mkid -f$$here/ID $$unique $(LISP)

TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)'; \
	unique=`for i in $$list; do echo $$i; done | \
	  awk '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
	  || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags  $$unique $(LISP) -o $$here/TAGS)

mostlyclean-tags:

clean-tags:

distclean-tags:
	-rm -f TAGS ID

maintainer-clean-tags:

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)

subdir = libvideogfx/graphics/draw

distdir: $(DISTFILES)
	here=`cd $(top_builddir) && pwd`; \
	top_distdir=`cd $(top_distdir) && pwd`; \
	distdir=`cd $(distdir) && pwd`; \
	cd $(top_srcdir) \
	  && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu libvideogfx/graphics/draw/Makefile
	@for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  if test -d $$d/$$file; then \
	    cp -pr $$d/$$file $(distdir)/$$file; \
	  else \
	    test -f $(distdir)/$$file \
	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
	    || cp -p $$d/$$file $(distdir)/$$file || :; \
	  fi; \
	done

DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)

-include $(DEP_FILES)

mostlyclean-depend:

clean-depend:

distclean-depend:
	-rm -rf .deps

maintainer-clean-depend:

%.o: %.c
	@echo '$(COMPILE) -c $<'; \
	$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
	@-cp .deps/$(*F).pp .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm .deps/$(*F).pp

%.lo: %.c
	@echo '$(LTCOMPILE) -c $<'; \
	$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
	@-sed -e 's/^\([^:]*\)\.o[ 	]*:/\1.lo \1.o :/' \
	  < .deps/$(*F).pp > .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm -f .deps/$(*F).pp

%.o: %.cc
	@echo '$(CXXCOMPILE) -c $<'; \
	$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
	@-cp .deps/$(*F).pp .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm .deps/$(*F).pp

%.lo: %.cc
	@echo '$(LTCXXCOMPILE) -c $<'; \
	$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
	@-sed -e 's/^\([^:]*\)\.o[ 	]*:/\1.lo \1.o :/' \
	  < .deps/$(*F).pp > .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am

install-data-am:
install-data: install-data-am

install-am: all-am
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LTLIBRARIES)
all-redirect: all-am
install-strip:
	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:


mostlyclean-generic:

clean-generic:

distclean-generic:
	-rm -f Makefile $(CONFIG_CLEAN_FILES)
	-rm -f config.cache config.log stamp-h stamp-h[0-9]*

maintainer-clean-generic:
mostlyclean-am:  mostlyclean-noinstLTLIBRARIES mostlyclean-compile \
		mostlyclean-libtool mostlyclean-tags mostlyclean-depend \
		mostlyclean-generic

mostlyclean: mostlyclean-am

clean-am:  clean-noinstLTLIBRARIES clean-compile clean-libtool \
		clean-tags clean-depend clean-generic mostlyclean-am

clean: clean-am

distclean-am:  distclean-noinstLTLIBRARIES distclean-compile \
		distclean-libtool distclean-tags distclean-depend \
		distclean-generic clean-am
	-rm -f libtool

distclean: distclean-am

maintainer-clean-am:  maintainer-clean-noinstLTLIBRARIES \
		maintainer-clean-compile maintainer-clean-libtool \
		maintainer-clean-tags maintainer-clean-depend \
		maintainer-clean-generic distclean-am
	@echo "This command is intended for maintainers to use;"
	@echo "it deletes files that may require special tools to rebuild."

maintainer-clean: maintainer-clean-am

.PHONY: mostlyclean-noinstLTLIBRARIES distclean-noinstLTLIBRARIES \
clean-noinstLTLIBRARIES maintainer-clean-noinstLTLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile mostlyclean-libtool distclean-libtool \
clean-libtool maintainer-clean-libtool tags mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir \
mostlyclean-depend distclean-depend clean-depend \
maintainer-clean-depend info-am info dvi-am dvi check check-am \
installcheck-am installcheck install-exec-am install-exec \
install-data-am install-data install-am install uninstall-am uninstall \
all-redirect all-am all installdirs mostlyclean-generic \
distclean-generic clean-generic maintainer-clean-generic clean \
mostlyclean distclean maintainer-clean


.PHONY: files

files:
	@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
	  echo $$p; \
	done

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

--- NEW FILE: bmformat.cc ---
/*
 *  bmformat.cc
 */

#include <string.h>

#include "bmformat.hh"


template <class A,class B> void ConvertBitmap(const Bitmap<A>& src,Bitmap<B>& dst)
{
  int w=src.AskWidth();
  int h=src.AskHeight();

  dst.Create(w,h,1,1,src.AskBorderWidth());

  const A*const* ap = src.AskFrame_const();
        B*const* bp = dst.AskFrame();

  for (int y=0;y<h;y++)
    for (int x=0;x<w;x++)
      bp[y][x] = static_cast<B>(ap[y][x]);
}


template <class T> void CopyInnerBorder(const Image<T>& src,Image<T>& dst,int hwidth,int vwidth)
{
  for (int i=0;i<4;i++)
    {
            Bitmap<T>& dstbm = dst.AskBitmap      ((Image<T>::BitmapChannel)i);
      const Bitmap<T>& srcbm = src.AskBitmap_const((Image<T>::BitmapChannel)i);


      // Skip empty bitmaps.

      assert(srcbm.IsEmpty() == dstbm.IsEmpty());

      if (srcbm.IsEmpty())
	continue;


      // Copy border.

      int w = srcbm.AskWidth();
      int h = srcbm.AskHeight();

      assert(dstbm.AskWidth()  == w);
      assert(dstbm.AskHeight() == h);

            T*const* dp = dstbm.AskFrame();
      const T*const* sp = srcbm.AskFrame_const();

      // Horizontal stripes.

      for (int x=0;x<w;x++)
	for (int y=0;x<vwidth;y++)
	  {
	    dp[    y][x]=sp[    y][x];
	    dp[h-1-y][x]=sp[h-1-y][x];
	  }

      // Vertical stripes.
      
      for (int y=vwidth;y<h-vwidth;y++)
	for (int x=0;x<hwidth;x++)
	  {
	    dp[y][    x]=sp[y][    x];
	    dp[y][w-1-x]=sp[y][w-1-x];
	  }
    }
}

template <class T> void ExtrudeIntoBorder (Image<T>&  img)
{
  for (int i=0;i<4;i++)
    {
      Bitmap<T>& bm = img.AskBitmap((Image<T>::BitmapChannel)i);

      if (bm.IsEmpty())
	continue;

      CopyBitmapIntoBorder(bm);
    }
}


template <class T> void ExtrudeIntoBorder(Bitmap<T>& bm)
{
  int w = bm.AskWidth(), h = bm.AskHeight();
  int borderwidth = bm.AskBorderWidth();

  T*const* p = bm.AskFrame();

  for (int y=0;y<h;y++)
    for (int x=1;x<=borderwidth;x++)
      {
	p[y][-x]   =p[y][0];
	p[y][w-1+x]=p[y][w-1];
      }

  for (int x=-borderwidth;x<w+borderwidth;x++)
    for (int y=1;y<=borderwidth;y++)
      {
	p[-y][x]   =p[0][x];
	p[h-1+y][x]=p[h-1][x];
      }
}


template <class T> void SetBitmapBorder(Bitmap<T>& bm,const T& val)
{
  int w = bm.AskWidth(), h = bm.AskHeight();
  int borderwidth = bm.AskBorderWidth();

  T*const* p = bm.AskFrame();

  for (int y=0;y<h;y++)
    for (int x=1;x<=borderwidth;x++)
      {
	p[y][-x] = p[y][w-1+x] = val;
      }

  for (int x=-borderwidth;x<w+borderwidth;x++)
    for (int y=1;y<=borderwidth;y++)
      {
	p[-y][x] = p[h-1+y][x] = val;
      }
}

template <class T> void RemoveColor(Image_YUV<T>& img)
{
  img.AskBitmap(Image<Pixel>::Bitmap_U).Destroy();
  img.AskBitmap(Image<Pixel>::Bitmap_V).Destroy();

  ImageParam_YUV param;
  img.GetParam(param);
  param.nocolor=true;
  img.SetParam(param);
}

template <class T> void ConvertGreyToRGB(const Image_YUV<T>& src,Image_RGB<T>& dst)
{
  ImageParam_YUV yuvparam;
  src.GetParam(yuvparam);

  assert(yuvparam.nocolor);

  ImageSpec spec; 
  spec.ImageParam::operator=(yuvparam);
  dst.Create(spec);

  const T*const* yp = src.AskFrameY_const();

  T*const* rp = dst.AskFrameR();
  T*const* gp = dst.AskFrameG();
  T*const* bp = dst.AskFrameB();

  for (int y=0;y<spec.height;y++)
    for (int x=0;x<spec.width;x++)
      {
	rp[y][x] = gp[y][x] = bp[y][x] = yp[y][x];
      }
}

template void CopyInnerBorder(const Image<Pixel>& src,Image<Pixel>& dst,int hwidth,int vwidth);
template void ExtrudeIntoBorder (Image<Pixel>&);
template void ExtrudeIntoBorder(Bitmap<Pixel>&);
template void RemoveColor(Image_YUV<Pixel>&);
template void ConvertGreyToRGB(const Image_YUV<Pixel>&,Image_RGB<Pixel>&);

--- NEW FILE: draw_x11.cc ---

#include "libvideogfx/graphics/draw/draw_x11.hh"

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <iostream.h>
#include "libvideogfx/x11/server.hh"

void WriteText(Bitmap<Pixel>& bm,const char* txt,int x0,int y0,const char* fontname,
	       HTextAlign halign,VTextAlign valign,
	       TextDrawMode mode,Pixel front,Pixel back)
{
  Pixel*const* yp = bm.AskFrame();

  // Get access to font.

  Display* display = default_x11server.AskDisplay();

  Font font = XLoadFont(display,fontname);
  XFontStruct* fontstr = XQueryFont(display,font);


  // Calculate pixel dimensions of text if written in the font specified.

  int dummy;
  XCharStruct overallsize;
  XTextExtents(fontstr,txt,strlen(txt),&dummy,&dummy,&dummy,&overallsize);

  const int w = overallsize.width;
  const int h = overallsize.ascent+overallsize.descent;


  // Create a pixmap to draw the text into.

  Pixmap pixmap = XCreatePixmap(display,RootWindow(display,DefaultScreen(display)),w,h,1);
  GC gc = XCreateGC(display,pixmap,0,NULL);


  // Clear pixmap.

  XSetForeground(display,gc,0);
  XSetBackground(display,gc,0);
  XFillRectangle(display,pixmap,gc,0,0,w,h);


  // Draw text.

  XSetForeground(display,gc,1);
  XSetFont(display,gc,font);
  XDrawString(display,pixmap,gc,0,overallsize.ascent,txt,strlen(txt));


  // Transfer pixmap data into X11-client XImage.

  XImage* ximg = XGetImage(display,pixmap,0,0,w,h,0x01,ZPixmap);

  if (halign==HAlign_Center) x0 -= w/2;
  if (halign==HAlign_Right)  x0 += (bm.AskWidth()-w);

  if (valign==VAlign_Center) y0 -= h/2;
  if (valign==VAlign_Bottom) y0 += (bm.AskHeight()-h);

  if (mode==TextDrawMode_Opaque)
    {
      for (int y=0;y<ximg->height;y++)
	for (int x=0;x<ximg->width;x++)
	  {
	    unsigned char bitpos = 0x80>>(x%8);
	    yp[y+y0][x+x0] = ((ximg->data[ximg->bytes_per_line*y+x/8]&bitpos) ? front : back );
	  }
    }
  else
    {
      assert(mode==TextDrawMode_Transparent);

      for (int y=0;y<ximg->height;y++)
	for (int x=0;x<ximg->width;x++)
	  {
	    unsigned char bitpos = 0x80>>(x%8);
	    if (ximg->data[ximg->bytes_per_line*y+x/8]&bitpos) yp[y+y0][x+x0] = front;
	  }
    }


  // Clean up

  XDestroyImage(ximg);
}


--- NEW FILE: draw.hh ---
/*********************************************************************
  libvideogfx/graphics/draw/draw.hh

  purpose:

  notes:

  to do:

  author(s):
   - Dirk Farin, farin at ti.uni-mannheim.de
     University Mannheim, Dept. Circuitry and Simulation
     B 6,26 EG, room 0.10 / D-68131 Mannheim / Germany
   - Alexander Staller, alexander.staller at engineer.com

  modifications:
    14/Aug/2000 - Alexander Staller - New functions: 
      DrawRectangle(), DrawCircle(), DrawEllipse(), DrawArrow()
      new class ArrowPainter, new implementation of DrawLine().
    14/Aug/2000 - Dirk Farin - new function: DrawFilledRectangleHV()
    17/Nov/1999 - Dirk Farin - converted bitmap drawing functions to
                               function templates.
 *********************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_DRAW_DRAW_HH
#define LIBVIDEOGFX_GRAPHICS_DRAW_DRAW_HH

#include <math.h>

#include "libvideogfx/graphics/basic/bitmap.hh"
#include "libvideogfx/graphics/basic/image.hh"


/* This function-call is very inefficient but provides clipping. */
template <class T> void DrawPoint     (Bitmap<T>&,int x,int y,T color);

// main function to draw a line very fast. Clipping is included, so don't think about it
template <class T> void DrawLine(Bitmap<T>& bm,int x0,int y0,int x1, int y1,T color);

/* Only draws every 4th dot. */
template <class T> void DrawDottedLine(Bitmap<T>&,int x1,int y1,int x2,int y2,T color);

/* Draw filled H/V-aligned rectangle. */
template <class T> void DrawFilledRectangleHV(Bitmap<T>&,int x0,int y0,int x1,int y1,T color);

/* Set all of the bitmap to the specified color. */
template <class T> void Clear         (Bitmap<T>&,T color);

// This function draws a rectangle. To do so it calls four times the DrawLineFast(...) function 
template <class T> void DrawRectangle(Bitmap<T>& bm,int x1,int y1,int w, int h,T color);

/* This function draws a line and places a head on one (arrows == false) or
   both (arrows==true) sides of the line. */
template <class T> void DrawArrow(Bitmap<T>& bm,int x0,int y0,int x1, int y1,double alpha,int len,
				  T color,bool arrows = false);

// main function to draw a circle
template <class T> void DrawCircle(Bitmap<T>& bm,int x0,int y0, int radius,T color,bool fill = false);

// this function draws an ellipse. Clipping is also included.
template <class T> void DrawEllipse(Bitmap<T>& bm,int xm,int ym, int a,int b,double angle,T color);

template <class Pel> class ArrowPainter
{
public:
  ArrowPainter();

  void SetAlpha(double a) { alpha=a*M_PI/180; }
  void SetHeadLength(int l) { len=l; }
  void DrawBothHeads(bool flag=true) { bothheads=flag; }
  void SetColor(Pel c) { color=c; }

  void DrawArrow(Bitmap<Pel>& bm,int x0,int y0,int x1, int y1)
    { ::DrawArrow(bm,x0,y0,x1,y1,alpha,len,color,bothheads); }

private:
  double alpha;
  int    len;
  bool   bothheads;
  Pel    color;
};

#if 0
/* Copy a number of lines at the inner border of the image. */
void CopyInnerBorder(const Image<Pixel>& src,Image<Pixel>& dst,int hwidth,int vwidth);
#endif

#if 1
/* Creates a border of the specified with around the image and copies the border
   pixel values into it. */
void EnhanceImageWithBorder(Image<Pixel>& img,int borderwidth,bool exactsize=false);
#endif


/* Old (obsolete) drawline code */
template <class T> void DrawLineSlow  (Bitmap<T>&,int x1,int y1,int x2,int y2,T color);

#endif

--- NEW FILE: draw_mwin.cc ---

#include "libvideogfx/graphics/draw/draw_x11.hh"

#include <microwin/nano-X.h>
#include <iostream.h>
#include "libvideogfx/x11/server.hh"

void WriteText(Bitmap<Pixel>& bm,const char* txt,int x0,int y0,const char* fontname,
	       HTextAlign halign,VTextAlign valign,
	       TextDrawMode mode,Pixel front,Pixel back)
{
  Pixel*const* yp = bm.AskFrame();

  // Get access to font.
  //Font font = XLoadFont(display,fontname);
  //XFontStruct* fontstr = XQueryFont(display,font);
  GR_GC_ID gc = GrNewGC();
  GR_FONT_ID font = GrCreateFont(0, MWFONT_SYSTEM_FIXED, 0);
  GrSetGCFont(gc, font);

  // Calculate pixel dimensions of text if written in the font specified.

  int width, height, base;
  //XCharStruct overallsize;
  //XTextExtents(fontstr,txt,strlen(txt),&dummy,&dummy,&dummy,&overallsize);
  //const int w = overallsize.width;
  //const int h = overallsize.ascent+overallsize.descent;

  GrGetGCTextSize(gc, txt, strlen(txt), GR_TFASCII|GR_TFTOP, &width,
  	&height, &base);
  const int w = width;
  const int h = height;

  // Create a pixmap to draw the text into.

  GR_WINDOW_ID pixmap = GrCreatePixmap(w,h,NULL);

  // Clear pixmap.
  //XSetForeground(display,gc,0);
  //XSetBackground(display,gc,0);
  //XFillRectangle(display,pixmap,gc,0,0,w,h);

  // Draw text.

  //XSetForeground(display,gc,1);
  //XSetFont(display,gc,font);
  //XDrawString(display,pixmap,gc,0,overallsize.ascent,txt,strlen(txt));
  GrText(pixmap, gc, 0, 0, txt, strlen(txt), GR_TFASCII|GR_TFTOP);

  // Transfer pixmap data into X11-client XImage.
  //XImage* ximg = XGetImage(display,pixmap,0,0,w,h,0x01,ZPixmap);
  GR_PIXELVAL bits[w*h];
  GrReadArea(pixmap, 0, 0, w, h, bits);

  if (halign==HAlign_Center) x0 -= w/2;
  if (halign==HAlign_Right)  x0 += (bm.AskWidth()-w);

  if (valign==VAlign_Center) y0 -= h/2;
  if (valign==VAlign_Bottom) y0 += (bm.AskHeight()-h);

  if (mode==TextDrawMode_Opaque)
    {
      for (int y=0;y<h;y++)
	for (int x=0;x<w;x++)
	  {
	    //unsigned char bitpos = 0x80>>(x%8);
	    //yp[y+y0][x+x0] = ((ximg->data[ximg->bytes_per_line*y+x/8]&bitpos) ? front : back );
	    yp[y+y0][x+x0] = ((bits[w*y+x]) ? front : back );
	  }
    }
  else
    {
      assert(mode==TextDrawMode_Transparent);

      for (int y=0;y<h;y++)
	for (int x=0;x<w;x++)
	  {
	    //unsigned char bitpos = 0x80>>(x%8);
	    //if (ximg->data[ximg->bytes_per_line*y+x/8]&bitpos) yp[y+y0][x+x0] = front;
	    if (bits[w*y+x]) yp[y+y0][x+x0] = front;
	  }
    }

  GrDestroyGC(gc);
  GrDestroyFont(font);
  GrDestroyWindow(pixmap);
}

--- NEW FILE: Makefile.am ---
## Makefile.am for libvideogfx/libvideogfx/graphics/draw

noinst_LTLIBRARIES = libvideogfx-graphics-draw.la

libvideogfx_graphics_draw_la_SOURCES = \
	bmformat.cc	\
	bmformat.hh	\
	draw.cc		\
	draw.hh

INCLUDES = \
	-I$(top_srcdir)

.PHONY: files

files:
	@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
	  echo $$p; \
	done




More information about the dslinux-commit mailing list