dslinux/user/pixil/packages/dvdview/dvdview/oldlibgfx/libvideogfx/postscript image2ps.cc image2ps.hh layout.cc layout.eps layout.hh layout2.eps mvfield.cc mvfield.hh regions.cc regions.hh

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


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

Added Files:
	image2ps.cc image2ps.hh layout.cc layout.eps layout.hh 
	layout2.eps mvfield.cc mvfield.hh regions.cc regions.hh 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: image2ps.hh ---
/*********************************************************************
  postscript/image2ps.hh

  purpose:
    Print image as postscript.

  notes:

  to do:
   - a unified filter approach could be useful. This would allow
     to build a filter chain like "RunLength"->"Ascii85".

  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:
    28/Jul/99 - Dirk Farin - RGB color image output
    26/Jul/99 - Dirk Farin - first implementation
 *********************************************************************/

#ifndef LIBVIDEOGFX_POSTSCRIPT_IMAGE2PS_HH
#define LIBVIDEOGFX_POSTSCRIPT_IMAGE2PS_HH

#include "libvideogfx/graphics/basic/image.hh"
#include "libvideogfx/postscript/layout.hh"
#include <iostream.h>


class Image2Postscript
{
public:
  enum PSImageEncoding { Hex, Ascii85 };


   Image2Postscript() : d_ostr(NULL), d_enc(Ascii85) { }
  ~Image2Postscript() { }

  void SetOutput(ostream& ostr) { d_ostr=&ostr; }

  void SetPrintingArea(const PrintingArea& a) { d_area=a; }
  void SetEncodingMethod(PSImageEncoding enc) { d_enc=enc; }
  void DrawImage(const Image_YUV<Pixel>&);
  void DrawImage(const Image_RGB<Pixel>&);

private:
  void WriteLine_ASCIIHex(const Pixel*,int len);
  void WriteLine_ASCII85 (const Pixel*,int len);

  PrintingArea    d_area;
  PSImageEncoding d_enc;
  ostream*        d_ostr;
};

#endif

--- NEW FILE: mvfield.hh ---
/*********************************************************************
  mvfield.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:
   02/Jun/99 - Dirk Farin
     - first implementation
 *********************************************************************/

#ifndef LIBVIDEOGFX_POSTSCRIPT_MVFIELD_HH
#define LIBVIDEOGFX_POSTSCRIPT_MVFIELD_HH

#include "libvideogfx/graphics/motvec/mv.hh"
#include "libvideogfx/graphics/basic/bitmap.hh"
#include "libvideogfx/postscript/layout.hh"
#include <iostream.h>


class MotionField2Postscript
{
public:
  MotionField2Postscript();
  ~MotionField2Postscript();

  void SetOutput(ostream& ostr) { d_ostr=&ostr; }

  void SetPrintingArea(const PrintingArea& a) { d_area=a; }

  void DrawMotionField(const Bitmap<MotVec>&,int hperblk,int vperblk);

private:
  PrintingArea d_area;
  ostream*     d_ostr;
};

#endif

--- NEW FILE: layout2.eps ---
%!
%%BoundingBox: 34 408 505 825
%%Title: layout2
%%CreationDate: Mon Jul 26 12:20:58 1999
%%Creator: Tgif-3.0-p17 by William Chia-Wei Cheng (william at cs.UCLA.edu)

/tgifdict 4 dict def
tgifdict begin

/tgifarrowtipdict 8 dict def
tgifarrowtipdict /mtrx matrix put

/tgifarrowtip
 { tgifarrowtipdict begin
      /dy exch def
      /dx exch def
      /h exch def
      /w exch def
      /y exch def
      /x exch def
      /savematrix mtrx currentmatrix def
      x y translate
      dy dx atan rotate
      0 0 moveto
      w neg h lineto
      w neg h neg lineto
      savematrix setmatrix
   end
 } def

end

%%PageBoundingBox: 34 408 505 825
tgifdict begin
/tgifsavedpage save def

1 setmiterlimit
1 setlinewidth

0 setgray

72 0 mul 72 11.70 mul translate
72 128 div 100.000 mul 100 div dup neg scale

gsave

/tgiforigctm matrix currentmatrix def

% BOX
0 setgray
newpath
   352 336 moveto 752 336 lineto 752 400 lineto 352 400 lineto
closepath 1 setgray fill
   0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         352 336 moveto 752 336 lineto 752 400 lineto 352 400 lineto
      closepath
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         64 128 moveto 128 128 lineto 128 768 lineto 64 768 lineto
      closepath
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         832 192 moveto 896 192 lineto 896 768 lineto 832 768 lineto
      closepath
      stroke
   grestore
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      576 64 moveto
      576 176 lineto
      0 -64 atan dup cos 10.000 mul 512 exch sub
      exch sin 10.000 mul 176 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      512 176 10.000 4.000 -64 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      512 176 10.000 4.000 -64 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      688 182 moveto (Init\(\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      608 96 moveto
      608 208 lineto
      0 -96 atan dup cos 10.000 mul 512 exch sub
      exch sin 10.000 mul 208 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      512 208 10.000 4.000 -96 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      512 208 10.000 4.000 -96 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      560 54 moveto (SetOutput\(\)) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      592 86 moveto (SetParam\(...\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      448 208 moveto
      0 -320 atan dup cos 10.000 mul 128 exch sub
      exch sin 10.000 mul 208 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      128 208 10.000 4.000 -320 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      128 208 10.000 4.000 -320 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      192 198 moveto (_SetParam\(...\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      640 128 moveto
      640 240 lineto
      0 -512 atan dup cos 10.000 mul 128 exch sub
      exch sin 10.000 mul 240 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      128 240 10.000 4.000 -512 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      128 240 10.000 4.000 -512 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      624 118 moveto (DrawBorder\(.\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      704 192 moveto
      704 304 lineto
      0 -192 atan dup cos 10.000 mul 512 exch sub
      exch sin 10.000 mul 304 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      512 304 10.000 4.000 -192 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      512 304 10.000 4.000 -192 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      448 304 moveto
      0 -320 atan dup cos 10.000 mul 128 exch sub
      exch sin 10.000 mul 304 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      128 304 10.000 4.000 -320 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      128 304 10.000 4.000 -320 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      224 294 moveto (_Init\(\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      128 320 moveto
      752 320 lineto
      752 304 lineto
      832 368 lineto
      752 432 lineto
      752 416 lineto
      128 416 lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   [] 0 setdash
   1 setlinewidth
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      128 368 moveto
      0 224 atan dup cos 10.000 mul 352 exch sub
      exch sin 10.000 mul 368 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      352 368 10.000 4.000 224 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      352 368 10.000 4.000 224 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      128 400 moveto
      0 224 atan dup cos 10.000 mul 352 exch sub
      exch sin 10.000 mul 400 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      352 400 10.000 4.000 224 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      352 400 10.000 4.000 224 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      144 358 moveto (EmitPrologCode\(\)) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      144 390 moveto (EmitSetupCode\(\)) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      528 502 moveto (GetNextArea\(\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      560 512 moveto
      560 544 lineto
      0 -48 atan dup cos 10.000 mul 512 exch sub
      exch sin 10.000 mul 544 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      512 544 10.000 4.000 -48 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      512 544 10.000 4.000 -48 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [12 4] 0 setdash
   newpath
      448 528 moveto
      0 -320 atan dup cos 10.000 mul 128 exch sub
      exch sin 10.000 mul 528 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   [] 0 setdash
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      128 528 10.000 4.000 -320 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      128 528 10.000 4.000 -320 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      176 518 moveto (_BeginNewPage\(\)) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      176 550 moveto (_DoDrawBorder\(\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [12 4] 0 setdash
   newpath
      448 560 moveto
      0 -320 atan dup cos 10.000 mul 128 exch sub
      exch sin 10.000 mul 560 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   [] 0 setdash
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      128 560 10.000 4.000 -320 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      128 560 10.000 4.000 -320 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      528 678 moveto (Finish\(\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      560 688 moveto
      560 720 lineto
      0 -48 atan dup cos 10.000 mul 512 exch sub
      exch sin 10.000 mul 720 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      512 720 10.000 4.000 -48 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      512 720 10.000 4.000 -48 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      448 720 moveto
      0 -320 atan dup cos 10.000 mul 128 exch sub
      exch sin 10.000 mul 720 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      128 720 10.000 4.000 -320 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      128 720 10.000 4.000 -320 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [24 0 0 -24 0 0] makefont setfont
   gsave
      224 710 moveto (_Finish\(\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      128 480 moveto
      752 480 lineto
      752 464 lineto
      832 528 lineto
      752 592 lineto
      752 576 lineto
      128 576 lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   [] 0 setdash
   1 setlinewidth
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      128 640 moveto
      752 640 lineto
      752 624 lineto
      832 688 lineto
      752 752 lineto
      752 736 lineto
      128 736 lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   [] 0 setdash
   1 setlinewidth
grestore

% TEXT
0 setgray
gsave
   -116 434 translate
   [0.000 -1.000 1.000 0.000 189 107] concat
   -116 neg 434 neg translate
grestore
/Times-Roman findfont [34 0 0 -34 0 0] makefont setfont
   gsave
      -116 434 translate
      [0.000 -1.000 1.000 0.000 189 107] concat
      0 30 moveto (PrintAreaLayouter) show
   grestore

% TEXT
0 setgray
gsave
   701 476 translate
   [0.000 -1.000 1.000 0.000 141 81] concat
   701 neg 476 neg translate
grestore
/Times-Roman findfont [34 0 0 -34 0 0] makefont setfont
   gsave
      701 476 translate
      [0.000 -1.000 1.000 0.000 141 81] concat
      0 30 moveto (output stream) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      672 160 moveto
      672 272 lineto
      0 -544 atan dup cos 10.000 mul 128 exch sub
      exch sin 10.000 mul 272 exch sub lineto
   tgiforigctm setmatrix
   2 setlinewidth
   stroke
   1 setlinewidth
grestore
gsave
   tgiforigctm setmatrix
   newpath
      128 272 10.000 4.000 -544 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      128 272 10.000 4.000 -544 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [25 0 0 -25 0 0] makefont setfont
   gsave
      656 151 moveto (AddPostscriptModule\(.\)) show
   grestore

% BOX
0 setgray
newpath
   448 128 moveto 512 128 lineto 512 768 lineto 448 768 lineto
closepath 1 setgray fill
   0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         448 128 moveto 512 128 lineto 512 768 lineto 448 768 lineto
      closepath
      stroke
   grestore
grestore

% TEXT
0 setgray
gsave
   77 541 translate
   [0.000 -1.000 1.000 0.000 379 208] concat
   77 neg 541 neg translate
grestore
/Times-Roman findfont [34 0 0 -34 0 0] makefont setfont
   gsave
      77 541 translate
      [0.000 -1.000 1.000 0.000 379 208] concat
      0 30 moveto (class derived from PrintAreaLayouter) show
   grestore

% TEXT
0 setgray
newpath
   543 351 moveto 718 351 lineto 718 389 lineto 543 389 lineto
closepath 1 setgray fill
0 setgray
/Times-Roman findfont [34 0 0 -34 0 0] makefont setfont
   gsave
      544 382 moveto (PSModule\(s\)) show
   grestore

grestore
tgifsavedpage restore
end
%MatchingCreationDate: Mon Jul 26 12:20:58 1999

--- NEW FILE: image2ps.cc ---

#include "libvideogfx/postscript/image2ps.hh"


void Image2Postscript::DrawImage(const Image_YUV<Pixel>& img)
{
  ImageParam param;
  img.Image<Pixel>::GetParam(param);

  const int w = param.width;
  const int h = param.height;

  assert(d_ostr);

  const Pixel*const* yy = img.AskFrameY_const();


  // write postscript commands to display image

  *d_ostr << "/oldstate save def\n"
	  << "/picstr " << w << " string def\n"
	  << d_area.xoffs*cm2pts << " " << (d_area.yoffs-d_area.height)*cm2pts  << " translate\n"
	  << d_area.width*cm2pts << " " << d_area.height*cm2pts << " scale\n"
	  << w << " " << h << " 8\n"
	  << "[" << w << " 0 0 -" << h << " 0 " << h << "]\n"
	  << "{ currentfile ";

       if (d_enc==Image2Postscript::Hex)     *d_ostr << "/ASCIIHexDecode";
  else if (d_enc==Image2Postscript::Ascii85) *d_ostr << "/ASCII85Decode";
  else { assert(0); }

  *d_ostr << " filter picstr readstring pop }\n"
	  << "image\n";


  // write inline image data
      
  for (int y=0;y<h;y++)
    {
           if (d_enc==Image2Postscript::Hex)     { WriteLine_ASCIIHex(yy[y],w); *d_ostr << ">"  << endl; }
      else if (d_enc==Image2Postscript::Ascii85) { WriteLine_ASCII85 (yy[y],w); *d_ostr << "~>" << endl; }
      else { assert(0); }
    }


  // cleanup
  
  *d_ostr << "oldstate restore\n";
}


void Image2Postscript::DrawImage(const Image_RGB<Pixel>& img)
{
  ImageParam param;
  img.Image<Pixel>::GetParam(param);

  const int w = param.width;
  const int h = param.height;

  assert(d_ostr);

  const Pixel*const* rp = img.AskFrameR_const();
  const Pixel*const* gp = img.AskFrameG_const();
  const Pixel*const* bp = img.AskFrameB_const();

  
  // write postscript commands to display image

  *d_ostr << "/oldstate save def\n"
	  << "/picstr " << w*3 << " string def\n"
	  << d_area.xoffs*cm2pts << " " << (d_area.yoffs-d_area.height)*cm2pts  << " translate\n"
	  << d_area.width*cm2pts << " " << d_area.height*cm2pts << " scale\n"
	  << w << " " << h << " 8\n"
	  << "[" << w << " 0 0 -" << h << " 0 " << h << "]\n"
	  << "{ currentfile ";

       if (d_enc==Image2Postscript::Hex)     *d_ostr << "/ASCIIHexDecode";
  else if (d_enc==Image2Postscript::Ascii85) *d_ostr << "/ASCII85Decode";
  else { assert(0); }

  *d_ostr << " filter picstr readstring pop }\n"
	  << "false 3 colorimage\n";

       
  // write inline image data

  Pixel* line = new Pixel[w*3];
  
  for (int y=0;y<h;y++)
    {
      Pixel* p = line;
      const Pixel* r = rp[y];
      const Pixel* g = gp[y];
      const Pixel* b = bp[y];
      for (int x=0;x<w;x++)
	{
	  *p++ = *r++;
	  *p++ = *g++;
	  *p++ = *b++;
	}
      
           if (d_enc==Image2Postscript::Hex)     { WriteLine_ASCIIHex(line,w*3); *d_ostr << ">"  << endl; }
      else if (d_enc==Image2Postscript::Ascii85) { WriteLine_ASCII85 (line,w*3); *d_ostr << "~>" << endl; }
      else { assert(0); }
    }

  delete[] line;

      
  // cleanup

  *d_ostr << "oldstate restore\n";
}




#define MAXLINELEN 80

void Image2Postscript::WriteLine_ASCIIHex(const Pixel* pix,int len)
{
  if (len>MAXLINELEN/2)
    {
      WriteLine_ASCIIHex(pix              ,     MAXLINELEN/2);
      WriteLine_ASCIIHex(pix+MAXLINELEN/2 , len-MAXLINELEN/2);
      return;
    }

  char buf[MAXLINELEN+1];
  char* p=buf;
  static char tohex[16+1] = "0123456789abcdef";

  for (int i=0; i<len; i++,pix++)
    {
      *p++ = tohex[(*pix)>>4];
      *p++ = tohex[(*pix)&0x0F];
    }
  *p = 0;

  *d_ostr << buf << endl;
}



void Image2Postscript::WriteLine_ASCII85 (const Pixel* pix,int len)
{
  assert((len%4)==0);

  const int maxlen = MAXLINELEN/5*4;

  if (len>maxlen)
    {
      WriteLine_ASCII85(pix        ,     maxlen);
      WriteLine_ASCII85(pix+maxlen , len-maxlen);
      return;
    }

  char buf[MAXLINELEN+1];
  char* p=buf;

  for (int x=0;x<len;x+=4)
    {
      unsigned long n;
      n  = (pix[x  ]<<24);
      n |= (pix[x+1]<<16);
      n |= (pix[x+2]<< 8);
      n |=  pix[x+3];
	      
      char c1,c2,c3,c4,c5;
	      
      c5 = n%85; n/=85;
      c4 = n%85; n/=85;
      c3 = n%85; n/=85;
      c2 = n%85; n/=85;
      c1 = n;
      
      p[0] = c1 + 33;
      p[1] = c2 + 33;
      p[2] = c3 + 33;
      p[3] = c4 + 33;
      p[4] = c5 + 33;
      p+=5;
    }

  *p=0;
  *d_ostr << buf << endl;
}

--- NEW FILE: mvfield.cc ---

#include "libvideogfx/postscript/mvfield.hh"

MotionField2Postscript::MotionField2Postscript()
  : d_ostr(NULL)
{
}

MotionField2Postscript::~MotionField2Postscript()
{
}

void MotionField2Postscript::DrawMotionField(const Bitmap<MotVec>& mv,int hperblk,int vperblk)
{
  double blkwidth  = d_area.width /mv.AskWidth();
  double blkheight = d_area.height/mv.AskHeight();

  const MotVec*const* mvptr = mv.AskFrame_const();

  *d_ostr << "0 setlinewidth\n";
  for (int y=0;y<=mv.AskHeight();y++)
    {
      *d_ostr << (d_area.xoffs*cm2pts) << ' ' << (d_area.yoffs-y*blkheight)*cm2pts << " moveto " << d_area.width*cm2pts << " 0 rlineto\n";
    }
  *d_ostr << "stroke\n";

  for (int x=0;x<=mv.AskWidth();x++)
    {
      *d_ostr << (d_area.xoffs+x*blkwidth)*cm2pts << ' ' << (d_area.yoffs*cm2pts) << " moveto 0 " << -d_area.height*cm2pts << " rlineto\n";
    }
  *d_ostr << "stroke\n";

  *d_ostr << "1 setlinewidth\n";

  for (int y=0;y<mv.AskHeight();y++)
    {
      for (int x=0;x<mv.AskWidth();x++)
	{
	  *d_ostr << (d_area.xoffs+x*blkwidth+blkwidth/2)*cm2pts << ' ' << (d_area.yoffs-y*blkheight-blkheight/2)*cm2pts << " moveto "
		  << mvptr[y][x].h*blkwidth*cm2pts/hperblk       << ' ' << -mvptr[y][x].v*blkheight*cm2pts/vperblk << " rlineto\n";
	}
      *d_ostr << "stroke\n";
    }
}

--- NEW FILE: layout.cc ---

#include "libvideogfx/postscript/layout.hh"

// struct PaperSize_A4 Paper_A4;
struct PaperSize Paper_A3(29.70,42.00);
struct PaperSize Paper_A4(21.00,29.70);
struct PaperSize Paper_A5(14.85,21.00);


PrintAreaLayouter::PrintAreaLayouter()
  : d_str(NULL), d_DrawBorder(true), d_currPage(1),
    d_nPSmodules(0)
{
}


void PrintAreaLayouter::AddPostscriptModule(PostscriptModule& mod)
{
  assert(d_nPSmodules<MAX_PS_MODULES);

  d_PSmodule[d_nPSmodules++] = &mod;
}


void PrintAreaLayouter::_Init()
{
  assert(d_str);

  *d_str << "%!PS-Adobe-2.0\n"
	 << "%%Creator: libvideogfx visualization class\n"
	 << "%%Orientation: " << (d_landscape ? "Landscape\n" : "Portrait\n")
	 << "%%PageOrder: Ascend\n"
	 << "%%EndComments\n"
	 << "%%BeginProlog\n"
	 << "/cm { 28.5634 mul } def\n";

  if (d_landscape)
    {
      *d_str << "/turntolandscape { 90 rotate 0 " << (-d_paperwidth*cm2pts) << " translate } def\n";
    }

  for (int i=0;i<d_nPSmodules;i++)
    d_PSmodule[i]->EmitPrologCode();

  *d_str << "%%EndProlog\n"
	 << "%%BeginSetup\n";

  for (int i=0;i<d_nPSmodules;i++)
    d_PSmodule[i]->EmitSetupCode();

  *d_str << "%%EndSetup\n";
}


void PrintAreaLayouter::_BeginNewPage()
{
  assert(d_str);

  if (d_currPage>1) *d_str << "showpage\n";
  *d_str << "%%Page: " << d_currPage << endl;
  if (d_landscape) *d_str << "turntolandscape\n";
  d_currPage++;
}

void PrintAreaLayouter::_Finish()
{
  assert(d_str);
  *d_str << "showpage\n";
}

void PrintAreaLayouter::_DoDrawBorder(PrintingArea& area)
{
  if (d_DrawBorder)
    {
      *d_str << "gsave\n1 setlinewidth\n"
	     << (area.xoffs*cm2pts) << " "
	     << (area.yoffs*cm2pts) << " moveto\n"
	     << (area.width*cm2pts) << " 0 rlineto\n"
	     << "0 " << (-area.height*cm2pts) << " rlineto\n"
	     << (-area.width*cm2pts) << " 0 rlineto\n"
	     << "0 " << (area.height*cm2pts) << " rlineto\nstroke\ngrestore\n";
    }
}




// ------------------ PrintAreaLayouter_nUp ------------------------



PrintAreaLayouter_nUp::PrintAreaLayouter_nUp()
  : d_nextAreaNr(0)
{
  AddPostscriptModule(*this);
}

int PrintAreaLayouter_nUp::SetParams(double aspect,bool landscape,int nup,double spacing,PaperSize paper)
{
try_again:
  double width  = (landscape ? paper.height : paper.width )-2*paper.border;
  double height = (landscape ? paper.width  : paper.height)-2*paper.border;

  int    bestcol=0;
  int    bestrow=0;
  double bestaw=0.0;
  double bestah=0.0;

  // Try all possible number of columns and take that one that results in largest area sizes.
  for (int ncol=1;ncol<=nup;ncol++)
    {
      int nrow = (nup+ncol-1)/ncol;

      double aw = (width -(ncol-1)*spacing)/ncol;
      double ah = (height-(nrow-1)*spacing)/nrow;

      if (aw<=0.0 || ah <= 0.0)
	continue;

      if (aw/ah >= aspect)
	{
	  aw = aspect*ah;
	}
      else
	{
	  ah = aw/aspect;
	}

      if (aw>bestaw)
	{
	  bestaw =aw;   bestah =ah;
	  bestcol=ncol; bestrow=nrow;
	}
    }

  // If it does not fit on the page, try to place fewer areas on the page.
  if (bestcol==0)
    {
      assert(nup>0);
      nup--;
      goto try_again;
    }

  double aox = (width -(bestcol-1)*spacing - bestcol*bestaw)/bestcol/2;
  double aoy = (height-(bestrow-1)*spacing - bestrow*bestah)/bestrow/2;

  d_nCols = bestcol;
  d_nRows = bestrow;
  d_xOffs = paper.border+aox;
  d_yOffs = height+paper.border-aoy;
  d_xStep = (width -(bestcol-1)*spacing)/bestcol+spacing;
  d_yStep = (height-(bestrow-1)*spacing)/bestrow+spacing;
  d_xSize = bestaw;
  d_ySize = bestah;

  _SetParams(landscape,paper.width);
}

void PrintAreaLayouter_nUp::Init()
{
  _Init();
}

PrintingArea PrintAreaLayouter_nUp::GetNextArea()
{
  assert(d_str);

  if (d_nextAreaNr==0 || d_nextAreaNr == d_nCols*d_nRows)
    {
      _BeginNewPage();
      d_nextAreaNr=0;
    }

  PrintingArea area;
  area.xoffs  = (d_xOffs + (d_nextAreaNr%d_nCols)*d_xStep);
  area.yoffs  = (d_yOffs - (d_nextAreaNr/d_nCols)*d_yStep);
  area.width  = d_xSize;
  area.height = d_ySize;

  _DoDrawBorder(area);

  d_nextAreaNr++;

  return area;
}

void PrintAreaLayouter_nUp::Finish()
{
  _Finish();
}

void PrintAreaLayouter_nUp::EmitSetupCode()
{
  *d_str << "0 setgray\n"
	 << "0 setlinewidth\n";
}

--- NEW FILE: regions.hh ---
/*********************************************************************
  postscript/regions.hh

  purpose:
    Draw segmented regions.
    Takes a bitmap a input that has a region id assigned to each
    element. The visualizer class will then draw the borders between
    adjacent regions.

  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:
    23/Jul/99 - Dirk Farin - speedup and output file size reduction
      by combining adjacent line segments into a single line.
    21/Jul/99 - Dirk Farin - first implementation
 *********************************************************************/

#ifndef LIBVIDEOGFX_POSTSCRIPT_REGIONS_HH
#define LIBVIDEOGFX_POSTSCRIPT_REGIONS_HH

#include "libvideogfx/graphics/basic/bitmap.hh"
#include "libvideogfx/postscript/layout.hh"
#include <iostream.h>


class Regions2Postscript
{
public:
   Regions2Postscript() : d_ostr(NULL) { }
  ~Regions2Postscript() { }

  void SetOutput(ostream& ostr) { d_ostr=&ostr; }

  void SetPrintingArea(const PrintingArea& a) { area=a; }
  void DrawRegions(const Bitmap<int>&);

private:
  PrintingArea area;
  ostream* d_ostr;
};

#endif

--- NEW FILE: layout.hh ---
/*********************************************************************
  graphics/visualize/layout.hh

  purpose:
    Data structures and layout manager for the positioning of
    postscript output on paper.

  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:
    27/Jul/99 - Dirk Farin - implemented "Document Structuring Conventions"
    21/Jul/99 - Dirk Farin - first implementation
 *********************************************************************/

#ifndef LIBVIDEOGFX_POSTSCRIPT_LAYOUT_HH
#define LIBVIDEOGFX_POSTSCRIPT_LAYOUT_HH

#include "libvideogfx/types.hh"
#include <iostream.h>

/* Size of paper to be printed on. */
struct PaperSize
{
  PaperSize() : border(1.5) { }
  PaperSize(double w,double h) : width(w), height(h), border(1.5) { }

  // All measures in 'cm'.
  double width,height;

  double border; // Unprintable area on each side of paper.
};

// Several common paper sizes
extern PaperSize Paper_A3;
extern PaperSize Paper_A4;
extern PaperSize Paper_A5;




/* Area where to print on. The offset defines the location of the
   top left corner of the area. The coordinate system has 0/0 in
   the bottom left (postscript standard).
*/
struct PrintingArea
{
  // All measures in 'cm'.
  double xoffs,yoffs;
  double width,height;
};

#define cm2pts 28.5634



/* A PostscriptModule gives every postscript generating object the
   possibility to emit its own code into the postscript document
   header.
*/
class PostscriptModule
{
public:
  virtual ~PostscriptModule() { }

  virtual void EmitPrologCode() { }
  virtual void EmitSetupCode()  { }
};

#define MAX_PS_MODULES 10  // Maximum number of PostscriptModules that may be attached to a PrintAreaLayouter.


class PrintAreaLayouter
{
public:
           PrintAreaLayouter();
  virtual ~PrintAreaLayouter() { }

  void     SetOutput(ostream& str) { d_str = &str;  } // Set output stream.
  ostream& AskOutput()             { return *d_str; } // Ask output stream.

  void     AddPostscriptModule(PostscriptModule& mod);

  void     DrawBorder(bool flag=true) { d_DrawBorder=flag; } // Toggle drawing of borders on and off.

  virtual void         Init()        = 0;
  virtual PrintingArea GetNextArea() = 0;
  virtual void         Finish()      = 0;

protected:
  void _SetParams(bool landscape,double paperwidth) { d_landscape=landscape; d_paperwidth=paperwidth; }

  void _Init();
  void _BeginNewPage();
  void _Finish();
  void _DoDrawBorder(PrintingArea&);

  ostream* d_str;

private:
  bool     d_landscape;
  double   d_paperwidth;

  bool     d_DrawBorder;
  int      d_currPage;

  PostscriptModule* d_PSmodule[MAX_PS_MODULES];
  int d_nPSmodules;
};


/* This layouter makes the automatic placement of PrintingAreas on all sorts of paper easy.
   Specify the aspect ratio of the images you want to place on the page, whether the page should
   be turned to landscape, the number of images you want on one sheet, the spacing between the
   images and the paper size. The layouter will try to find the best arrangement of the images
   so that the images size is maximized.

   Other nice features are:
   - It takes care of all necessary postscript headers and 'showpage's .
   - It can automatically draw a border around each image.
*/
class PrintAreaLayouter_nUp : public  PrintAreaLayouter,
			      private PostscriptModule
{
public:
   PrintAreaLayouter_nUp();
  ~PrintAreaLayouter_nUp() { }

  int  SetParams(double aspect,          // width/height
		 bool   landscape=false,
		 int nup=2,              // Number of areas on one sheet of paper (actual number may be greater)
		 double spacing=1.0,     // spacing between areas (in 'cm')
		 PaperSize paper=Paper_A4);


  // Do initializations and write postscript header.
  void Init();

  /* Get next PrintingArea. If enabled, a border will be automatically drawn around it.
     Takes even care of full pages in which case it will emit a new-page postscript sequence.
  */
  PrintingArea GetNextArea();

  // Do cleanup and write some postscript cleanup code.
  void Finish();

private:
  int      d_nCols,d_nRows;
  double   d_xOffs,d_yOffs;
  double   d_xStep,d_yStep;
  double   d_xSize,d_ySize;

  int      d_nextAreaNr;


  // overriding methods from PostscriptModule

  void EmitSetupCode();
};

#endif

--- NEW FILE: layout.eps ---
%!
%%BoundingBox: 70 513 401 839
%%Title: layout
%%CreationDate: Fri Jul 23 16:36:59 1999
%%Creator: Tgif-3.0-p17 by William Chia-Wei Cheng (william at cs.UCLA.edu)

150 -220 translate

/tgifdict 4 dict def
tgifdict begin

/tgifarrowtipdict 8 dict def
tgifarrowtipdict /mtrx matrix put

/tgifarrowtip
 { tgifarrowtipdict begin
      /dy exch def
      /dx exch def
      /h exch def
      /w exch def
      /y exch def
      /x exch def
      /savematrix mtrx currentmatrix def
      x y translate
      dy dx atan rotate
      0 0 moveto
      w neg h lineto
      w neg h neg lineto
      savematrix setmatrix
   end
 } def

end

%%PageBoundingBox: 70 513 401 839
tgifdict begin
/tgifsavedpage save def

1 setmiterlimit
1 setlinewidth

0 setgray

72 0 mul 72 11.70 mul translate
72 128 div 100.000 mul 100 div dup neg scale

gsave

/tgiforigctm matrix currentmatrix def

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         192 64 moveto 576 64 lineto 576 544 lineto 192 544 lineto
      closepath
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         256 128 moveto 368 128 lineto 368 224 lineto 256 224 lineto
      closepath
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         400 128 moveto 512 128 lineto 512 224 lineto 400 224 lineto
      closepath
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         256 256 moveto 368 256 lineto 368 352 lineto 256 352 lineto
      closepath
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         400 256 moveto 512 256 lineto 512 352 lineto 400 352 lineto
      closepath
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         256 384 moveto 368 384 lineto 368 480 lineto 256 480 lineto
      closepath
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         400 384 moveto 512 384 lineto 512 480 lineto 400 480 lineto
      closepath
      stroke
   grestore
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      368 32 moveto
      0 32 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      0 32 atan dup cos 8.000 mul 400 exch sub
      exch sin 8.000 mul 32 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      368 32 8.000 3.000 -32 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      368 32 8.000 3.000 -32 0 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      400 32 8.000 3.000 32 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      400 32 8.000 3.000 32 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      368 128 moveto
      368 32 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      400 32 moveto
      400 128 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      360 25 moveto (spacing) show
   grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         272 128 moveto 352 128 lineto 352 224 lineto 272 224 lineto
      closepath
      2 setlinewidth
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         416 128 moveto 496 128 lineto 496 224 lineto 416 224 lineto
      closepath
      2 setlinewidth
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         272 256 moveto 352 256 lineto 352 352 lineto 272 352 lineto
      closepath
      2 setlinewidth
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         416 256 moveto 496 256 lineto 496 352 lineto 416 352 lineto
      closepath
      2 setlinewidth
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         272 384 moveto 352 384 lineto 352 480 lineto 272 480 lineto
      closepath
      2 setlinewidth
      stroke
   grestore
grestore

% BOX
0 setgray
gsave
   10 setmiterlimit
   gsave
      newpath
         416 384 moveto 496 384 lineto 496 480 lineto 416 480 lineto
      closepath
      2 setlinewidth
      stroke
   grestore
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      512 128 moveto
      512 16 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      520 128 moveto
      632 128 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      520 224 moveto
      624 224 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      520 256 moveto
      624 256 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      576 32 moveto
      576 56 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      576 64 moveto
      640 64 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      272 128 moveto
      272 40 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      256 128 moveto
      256 40 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      400 32 moveto
      0 112 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      0 112 atan dup cos 8.000 mul 512 exch sub
      exch sin 8.000 mul 32 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      400 32 8.000 3.000 -112 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      400 32 8.000 3.000 -112 0 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      512 32 8.000 3.000 112 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      512 32 8.000 3.000 112 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      512 32 moveto
      0 64 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      0 64 atan dup cos 8.000 mul 576 exch sub
      exch sin 8.000 mul 32 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      512 32 8.000 3.000 -64 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      512 32 8.000 3.000 -64 0 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      576 32 8.000 3.000 64 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      576 32 8.000 3.000 64 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      608 64 moveto
      64 0 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      64 0 atan dup cos 8.000 mul 608 exch sub
      exch sin 8.000 mul 128 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      608 64 8.000 3.000 0 -64 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      608 64 8.000 3.000 0 -64 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      608 128 8.000 3.000 0 64 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      608 128 8.000 3.000 0 64 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      608 128 moveto
      96 0 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      96 0 atan dup cos 8.000 mul 608 exch sub
      exch sin 8.000 mul 224 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      608 128 8.000 3.000 0 -96 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      608 128 8.000 3.000 0 -96 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      608 224 8.000 3.000 0 96 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      608 224 8.000 3.000 0 96 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      608 224 moveto
      32 0 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      32 0 atan dup cos 8.000 mul 608 exch sub
      exch sin 8.000 mul 256 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      608 224 8.000 3.000 0 -32 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      608 224 8.000 3.000 0 -32 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      608 256 8.000 3.000 0 32 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      608 256 8.000 3.000 0 32 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      616 249 moveto (spacing) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      616 105 moveto (paper.border) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      520 25 moveto (paper.border) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      192 560 moveto
      0 384 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      0 384 atan dup cos 8.000 mul 576 exch sub
      exch sin 8.000 mul 560 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      192 560 8.000 3.000 -384 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      192 560 8.000 3.000 -384 0 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      576 560 8.000 3.000 384 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      576 560 8.000 3.000 384 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      176 544 moveto
      -480 0 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      -480 0 atan dup cos 8.000 mul 176 exch sub
      exch sin 8.000 mul 64 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      176 544 8.000 3.000 0 480 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      176 544 8.000 3.000 0 480 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      176 64 8.000 3.000 0 -480 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      176 64 8.000 3.000 0 -480 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      360 577 moveto (width) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      128 313 moveto (height) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      440 25 moveto (aw) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      616 185 moveto (ah) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      248 41 moveto (aox) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      192 137 moveto (\(aoy=0\)) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      272 480 moveto
      272 544 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      416 480 moveto
      416 544 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      192 512 moveto
      0 80 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      0 80 atan dup cos 8.000 mul 272 exch sub
      exch sin 8.000 mul 512 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      192 512 8.000 3.000 -80 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      192 512 8.000 3.000 -80 0 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      272 512 8.000 3.000 80 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      272 512 8.000 3.000 80 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      272 512 moveto
      0 144 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      0 144 atan dup cos 8.000 mul 416 exch sub
      exch sin 8.000 mul 512 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      272 512 8.000 3.000 -144 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      272 512 8.000 3.000 -144 0 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      416 512 8.000 3.000 144 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      416 512 8.000 3.000 144 0 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      208 529 moveto (xOffs) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      328 529 moveto (xStep) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      496 536 moveto
      496 480 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      496 512 moveto
      0 -80 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      0 -80 atan dup cos 8.000 mul 416 exch sub
      exch sin 8.000 mul 512 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      496 512 8.000 3.000 80 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      496 512 8.000 3.000 80 0 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      416 512 8.000 3.000 -80 0 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      416 512 8.000 3.000 -80 0 tgifarrowtip
   closepath fill
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      528 384 moveto
      96 0 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      96 0 atan dup cos 8.000 mul 528 exch sub
      exch sin 8.000 mul 480 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      528 384 8.000 3.000 0 -96 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      528 384 8.000 3.000 0 -96 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      528 480 8.000 3.000 0 96 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      528 480 8.000 3.000 0 96 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      432 529 moveto (xSize) show
   grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      536 433 moveto (ySize) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      704 544 moveto
      -416 0 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      -416 0 atan dup cos 8.000 mul 704 exch sub
      exch sin 8.000 mul 128 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      704 544 8.000 3.000 0 416 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      704 544 8.000 3.000 0 416 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      704 128 8.000 3.000 0 -416 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      704 128 8.000 3.000 0 -416 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      664 313 moveto (yOffs) show
   grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      576 544 moveto
      712 544 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      520 480 moveto
      648 480 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   [8 8] 0 setdash
   newpath
      520 352 moveto
      640 352 lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
   [] 0 setdash
grestore

% POLY/OPEN-SPLINE
0 setgray
gsave
   newpath
      608 480 moveto
      -128 0 atan dup cos 8.000 mul exch sin 8.000 mul rmoveto
      -128 0 atan dup cos 8.000 mul 608 exch sub
      exch sin 8.000 mul 352 exch sub lineto
   tgiforigctm setmatrix
   1 setlinewidth
   stroke
grestore
gsave
   tgiforigctm setmatrix
   newpath
      608 480 8.000 3.000 0 128 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      608 480 8.000 3.000 0 128 tgifarrowtip
   closepath fill
grestore
gsave
   tgiforigctm setmatrix
   newpath
      608 352 8.000 3.000 0 -128 tgifarrowtip
   1 setgray closepath fill
   0 setgray
   newpath
      608 352 8.000 3.000 0 -128 tgifarrowtip
   closepath fill
grestore

% TEXT
0 setgray
/Times-Roman findfont [18 0 0 -18 0 0] makefont setfont
   gsave
      616 425 moveto (yStep) show
   grestore

grestore
tgifsavedpage restore
end
showpage
%MatchingCreationDate: Fri Jul 23 16:36:59 1999

--- NEW FILE: regions.cc ---

#include "libvideogfx/postscript/regions.hh"


void Regions2Postscript::DrawRegions(const Bitmap<int>& bm)
{
  const int*const* p = bm.AskFrame_const();

  const int w = bm.AskWidth();
  const int h = bm.AskHeight();

  assert(d_ostr);


  // Draw horizontal boundaries.

  *d_ostr << "0 setlinewidth\n";
  for (int y=0;y<h-1;y++)
    {
      for (int x=0;x<w;x++)
	{
	  if (p[y][x] != p[y+1][x])
	    {
	      // begin line
	      
	      *d_ostr << ((area.xoffs+area.width *x/w)*cm2pts) << ' '
		      << ((area.yoffs-area.height*(y+1)/h)*cm2pts) << " moveto ";


	      // find end

	      int n=1;

	      x++;
	      while (x<w && p[y][x] != p[y+1][x])
		{
		  x++; n++;
		}

	      // draw line

	      *d_ostr << n*area.width/w*cm2pts << " 0 rlineto\n";
	    }
	}
      *d_ostr << "stroke\n";
    }


  // Draw vertical boundaries.

  for (int x=0;x<w-1;x++)
    {
      for (int y=0;y<h;y++)
	{
	  if (p[y][x] != p[y][x+1])
	    {
	      // begin line

	      *d_ostr << ((area.xoffs+area.width *(x+1)/w)*cm2pts) << ' '
		      << ((area.yoffs-area.height*y/h)*cm2pts) << " moveto 0 ";

	      // find end

	      int n=1;

	      y++;
	      while (y<h && p[y][x] != p[y][x+1])
		{
		  y++; n++;
		}

	      // draw line

	      *d_ostr << -n*area.height/h*cm2pts << " rlineto\n";
	    }
	}
      *d_ostr << "stroke\n";
    }
}




More information about the dslinux-commit mailing list