dslinux/user/pixil/packages/dvdview/dvdview/oldlibgfx/libvideogfx/graphics/datatypes .cvsignore Makefile.am motionfield.cc motionfield.hh primitives.hh region.cc region.hh

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


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

Added Files:
	.cvsignore Makefile.am motionfield.cc motionfield.hh 
	primitives.hh region.cc region.hh 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: .cvsignore ---
Makefile
Makefile.in
*.lo
_libs
.libs
.deps
libvideogfx-graphics-datatypes.la

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

noinst_LTLIBRARIES = libvideogfx-graphics-datatypes.la

libvideogfx_graphics_datatypes_la_SOURCES = \
	motionfield.cc	\
	motionfield.hh	\
	primitives.hh	\
	region.cc	\
	region.hh

INCLUDES = \
	-I$(top_srcdir)

.PHONY: files

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

--- NEW FILE: primitives.hh ---
/********************************************************************************
  libvideogfx/graphics/datatypes/primitives.hh

  purpose:
    Very basic data types.

  notes:

  to do:

  author(s):
   - Dirk Farin, farin at ti.uni-mannheim.de

  modifications:
    17/Nov/1999 - Dirk Farin - first revision
 ********************************************************************************
    Copyright (C) 1999  Dirk Farin

    This program is distributed under GNU Public License (GPL) as
    outlined in the COPYING file that comes with the source distribution.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ********************************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_DATATYPES_PRIMITIVES_HH
#define LIBVIDEOGFX_GRAPHICS_DATATYPES_PRIMITIVES_HH

template <class T> struct Point2D
{
  T x,y;
};

template <class T> struct Rect2D
{
  Point2D<T> upperleft;
  Point2D<T> lowerright;
};

#endif

--- NEW FILE: motionfield.hh ---
/*********************************************************************
  libvideogfx/graphics/datatypes/motionfield.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

  modifications:
    1999/Oct/19 - Dirk Farin - integration into CVS, mostly rewritten
 *********************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_DATATYPES_MOTIONFIELD_HH
#define LIBVIDEOGFX_GRAPHICS_DATATYPES_MOTIONFIELD_HH

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


struct MotionVector
{
  double h,v;
};


struct MotionVectorField
{
  MotionVectorField(int p_nblks_h,
                    int p_nblks_v,
                    int p_blksize_h = 16,
                    int p_blksize_v = 16)
  {
    blksize_h = p_blksize_h;
    blksize_v = p_blksize_v;
    nblks_h   = p_nblks_h;
    nblks_v   = p_nblks_v;
    mv.Create(nblks_h, nblks_v);
  }

  Bitmap<MotionVector> mv;
  int blksize_h,blksize_v;
  int nblks_h  ,nblks_v;
};

#endif


--- NEW FILE: region.hh ---
/*********************************************************************
  libvideogfx/graphics/datatypes/region.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

  modifications:
    17/Nov/1999 - Dirk Farin - first revision
 *********************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_DATATYPES_REGION_HH
#define LIBVIDEOGFX_GRAPHICS_DATATYPES_REGION_HH

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


class RegionStripe
{
public:
  int x,y;
  int xrun;

  bool operator==(const RegionStripe& s) const { return x==s.x && y==s.y && xrun==s.xrun; }
};


class RegionStripeIterator
{
  friend class Region;
public:
  RegionStripe Get();
  bool NoMoreStripes();

private:
  RegionStripeIterator(bool sglpixel,const class Region*);

  const class Region* d_region;
  bool d_sglPixel;
  int  d_nextIdx;
  int  d_currRun;
};


class Region
{
  friend class RegionStripeIterator;

public:
  Region();
  Region(const Region&);
  ~Region();

  const Region& operator=(const Region&);

  void AddPixel(int x,int y) { AddHRun(x,y,1); }
  void AddHRun(int x,int y,int xrun);
  void AddStripe(const RegionStripe& s) { AddHRun(s.x,s.y,s.xrun); }

  void RemovePixel(int x,int y);

  RegionStripeIterator GetStripeIterator(bool sglpixel=true) const;
  bool ContainsPixel(int x,int y) const;
  //void GetPixelList(Point2D<int>*);

  void Shift(int x,int y); // Shift region x (y) pixels right (down).

  void   Union(const Region&);
  void   Cut  (const Region&);
  Region Intersection(const Region&);

  bool operator<=(const Region&) const;
  bool operator>=(const Region& r) const { return  r <= *this; }
  bool operator==(const Region& r) const { return (r <= *this) && (*this <= r); }

private:
  RegionStripe* d_stripes;
  int d_nStripes;
  int d_nSize;
};

/* String example:
   "  X  \n"
   " X0XX\n"  // Use '.' for '0', when the pixel is not included in the mask.
   "  X  \n";
 */
Region RegionFromString(const char*);
template <class T> void DrawRegion(Bitmap<T>&,const Region&,T color);

#endif


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

#include "motionfield.hh"


template class Bitmap<MotionVector>;


#include "libvideogfx/graphics/basic/bitmap.cc"

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

#include "region.hh"


RegionStripeIterator::RegionStripeIterator(bool sglpixel,const class Region* region)
  : d_region(region),
    d_sglPixel(sglpixel),
    d_nextIdx(0),
    d_currRun(0)
{
}


RegionStripe RegionStripeIterator::Get()
{
  if (d_sglPixel)
    {
      RegionStripe s = d_region->d_stripes[d_nextIdx];
      s.x += d_currRun;
      s.xrun = 1;
      d_currRun++;

      if (d_currRun == d_region->d_stripes[d_nextIdx].xrun)
	{
	  d_currRun=0;
	  d_nextIdx++;
	}

      return s;
    }
  else
    {
      return d_region->d_stripes[d_nextIdx++];
    }
}


bool RegionStripeIterator::NoMoreStripes()
{
  return d_nextIdx == d_region->d_nStripes;
}




Region::Region()
{
  d_stripes = new RegionStripe[1000];
  d_nStripes = 0;
  d_nSize = 1000;
}


Region::~Region()
{
  delete[] d_stripes;
}


Region::Region(const Region& r)
{
  d_nSize = max(r.d_nStripes,10);
  d_stripes = new RegionStripe[d_nSize];
  d_nStripes = r.d_nStripes;

  for (int i=0;i<d_nStripes;i++)
    d_stripes[i] = r.d_stripes[i];
}


const Region& Region::operator=(const Region& r)
{
  delete[] d_stripes;
  d_nSize = max(r.d_nStripes,10);
  d_stripes = new RegionStripe[d_nSize];
  d_nStripes = r.d_nStripes;

  for (int i=0;i<d_nStripes;i++)
    d_stripes[i] = r.d_stripes[i];
}


void Region::AddHRun(int newx,int newy,int newxrun)
{
  for(int i=0;i<newxrun;i++)
    {
      if (d_nStripes == d_nSize)
	{
	  RegionStripe* s = new RegionStripe[d_nSize*2];
	  for (int n=0;n<d_nSize;n++)
	    s[n]=d_stripes[n];

	  delete[] d_stripes;
	  d_stripes=s;
	  d_nSize *= 2;
	}

      RegionStripe s;
      s.x    = newx+i;
      s.y    = newy;
      s.xrun = 1;

      bool alreadycontained=false;

      for (int n=0;n<d_nStripes && !alreadycontained;n++)
	{
	  if (d_stripes[n] == s)
	    { alreadycontained=true; }
	}

      if (!alreadycontained)
	{
	  d_stripes[d_nStripes] = s;
	  d_nStripes++;
	}
    }

#if 0
  // Check if we can append the new stripe to an existing one.

  for (int i=d_nStripes-1;i>=0 && d_stripes[i].y>=newy ;i--)
    {
      if (d_stripes[i].y == newy)
	{
	  RegionStripe& s = d_stripes[i];

	  // 3 combination cases: new stripe connects to the front, to the end or is in the middle

	  if (newx < s.x && newx+newxrun>=s.x)
	    {
	      int newend = max(s.x+s.xrun , newx+xrun);
	      s.x = newx;
	      s.xrun = newend-s.x;
	    }

	  // Handle this case:
	  //     XXXXXXXXXXXXXX                   <- new
	  // AAAAAAAA      BBBBBBBBBBBBBB
	}
    }
#endif
}


void Region::RemovePixel(int x,int y)
{
  for (int i=0;i<d_nStripes;i++)
    {
      if (d_stripes[i].y == y &&
	  d_stripes[i].x == x)
	{
	  assert(d_stripes[i].xrun==1);
	  d_nStripes--;
	  d_stripes[i]=d_stripes[d_nStripes];
	  return;
	}
    }
}


bool Region::ContainsPixel(int x,int y) const
{
  for (int i=0;i<d_nStripes;i++)
    if (d_stripes[i].y == y &&
	d_stripes[i].x <= x &&
	d_stripes[i].x+d_stripes[i].xrun-1 >= x)
      return true;

  return false;
}


void Region::Shift(int x,int y) // Shift region x,y pixels right,down.
{
  for (int i=0;i<d_nStripes;i++)
    {
      d_stripes[i].x += x;
      d_stripes[i].y += y;
    }
}


void Region::Union(const Region& r)
{
  RegionStripeIterator iter=r.GetStripeIterator(false);

  while (!iter.NoMoreStripes())
    {
      AddStripe(iter.Get());
    }
}

void Region::Cut(const Region& r)
{
  RegionStripeIterator iter=r.GetStripeIterator(false);

  while (!iter.NoMoreStripes())
    {
      RegionStripe s = iter.Get();
      RemovePixel(s.x,s.y);
    }
}


Region Region::Intersection(const Region& r)
{
  Region newreg;
  RegionStripeIterator iter=r.GetStripeIterator(true);

  while (!iter.NoMoreStripes())
    {
      RegionStripe s = iter.Get();
      if (ContainsPixel(s.x,s.y))
	newreg.AddPixel(s.x,s.y);
    }

  return newreg;
}


bool Region::operator<=(const Region& r) const
{
  RegionStripeIterator iter=GetStripeIterator(true);

  while (!iter.NoMoreStripes())
    {
      RegionStripe s=iter.Get();
      if (!r.ContainsPixel(s.x,s.y))
	return false;
    }

  return true;
}


RegionStripeIterator Region::GetStripeIterator(bool sglpixel) const
{
  return RegionStripeIterator(sglpixel,this);
}


Region RegionFromString(const char* str)
{
  // Find zero point.

  int x0=0,y0=0;

  for (const char* p=str;*p!='0' && *p!='.';p++,x0++)
    {
      if (*p=='\n') { x0=-1; y0++; }
    }

  int x=0,y=0;
  Region r;
  for (const char* p=str;*p!=0;p++,x++)
    {
      if (*p=='X' || *p=='0') { r.AddPixel(x-x0,y-y0); }
      if (*p=='\n') { x=-1; y++; }
    }

  return r;
}


template <class T> void DrawRegion(Bitmap<T>& bm,const Region& r,T color)
{
  RegionStripeIterator iter=r.GetStripeIterator(false);
  T*const* p = bm.AskFrame();

  while (!iter.NoMoreStripes())
    {
      RegionStripe s = iter.Get();
      for (int x=0;x<s.xrun;x++)
	p[s.y][s.x+x]=color;
    }
}


template void DrawRegion(Bitmap<bool>& ,const Region&,bool);
template void DrawRegion(Bitmap<Pixel>&,const Region&,Pixel);




More information about the dslinux-commit mailing list