[comp.lang.pascal] Displaying EGA/VGA graphics.

tjr@ac.dal.ca (03/12/91)

I am trying to incorporate EGA/VGA graphics into a program. What I 
would like to be able to do is either read in a small .PCX file and 
display it or do a EGA/VGA Screen capture and display the results. 

I have been successful in displaying CGA bitmaps, but have not been 
able to get anywhere with the higher resolutions. Any help would be 
greatly appreciated.

amead@s.psych.uiuc.edu (alan mead) (03/13/91)

amead@s.psych.uiuc.edu (alan mead) writes:

>tjr@ac.dal.ca writes:

>>I have been successful in displaying CGA bitmaps, but have not been 
>>able to get anywhere with the higher resolutions. Any help would be 
>>greatly appreciated.

>This is the easiest way the caputure/display screens in TP:  

Well, I decided to just write it.  Here it is.  Sorry, but I seem
unable to kill my original followup.

This code seems to mistreat TP (or perhaps TP has a bug).  There are
lines left on the screen after restoring the captured image.

To save the screen to disk, you need to write bytes equal to the Size
field starting with the one pointed to by the Image field.  Is that 
clear?  Perhaps I'll add that later.

----------------------------------------------------------------------

program GraphicsScreenSave;
uses graph;
{
       PURPOSE:    A quick graphics mode screen save demo routine

       WRITTEN:    03-12-91 by Alan D Mead

       COPYRIGHT:  Feel free to use this code--however, if you use
                   it without substantially modifying it, please
                   give me credit. 

       BUGS:       What are those annoying lines at the top of each
                   restored chuck?

                   Use your own path in InitGraph

                   This is the first linked list I've ever written :(
}
type
  ListPtr = ^ListType;
  ListType = record
               Image : pointer;
               Size : word;
               ULx,
               Uly  : integer;
               next : ListPtr;
             end;
var
  head,
  tail,
  P        : ListPtr; { to the ends of a singly linked list }

  procedure ListInsert( L:ListPtr );
    var p,pred:ListPtr;
    begin
      L^.Next := nil;
      if ( Head=nil ) then
        begin
          Head := L;
          Tail := L;
        end
      else
        begin
          tail^.next := L;
          Tail := L;
        end;
    end;

  procedure SaveScreen( ULx,ULy,LRx,LRy:integer );
    var i,j,k : integer; Size:word; l:ListPtr;
    begin
      Size := ImageSize( ULx,ULy,LRx,LRy );
      if Size = 0 then
        begin
          SaveScreen( ULx,ULy,LRx,2+(ULy+((LRy-ULy) DIV 2)));
          SaveScreen( ULx,(ULy-2+((LRy-ULy) DIV 2)),LRx,LRy );
        end
      else
        begin
          new( l );
          GetMem( l^.Image, Size); { Get memory from heap }
          GetImage( ULx,ULy,LRx,LRy,l^.Image );
          l^.Size := Size;
          l^.ULx := ULx;
          l^.ULy := ULy;
          ListInsert( l );
        end;
    end;

var
  Gd, Gm : Integer;
  Size   : Word;
  I      : Integer;
begin
  randomize;
  head := nil;
  tail := nil;
  Gd := Detect;
  InitGraph(Gd, Gm, 'C:\TP5');
  if GraphResult <> grOk then
    Halt(1);
  for i := 1 to 10 do
    Bar(  Random(50), Random(50), Random(GetMaxX), Random(GetMaxY));
  SaveScreen( 0,0,GetMaxX,GetMaxY );
  ReadLn;
  ClearDevice;
  p := head;
  while P <> nil do
    begin
      PutImage( P^.ULx, P^.ULy, P^.Image, NormalPut );
      P := P^.next;
{      readln;}
    end;
  ReadLn;
  CloseGraph;
end.

am42+@andrew.cmu.edu (Alexander Paul Morris) (03/17/91)

The problem in the code (the BUG, as it is called) is very simple to
correct. The author (I believe Alan Mead) overlooked, since he was using
a linked list, to declare the image as a pointer when he called it with
getimage/putimage.  To correct everything, simply replace in the lines
that say  GetImage  and  PutImage   the parameter   l^.Image   to  
l^.Image^ .  Note that those are the ONLY places where anything must be
changed.  All those weird lines will dissapear.  Actually, I'm surprised
the whole program didn't crash!  Seems like it would overwrite all
memory past the location in mem where that variable is stored, but
perhaps that was just other TP vars or something that weren't important
at the time.  Hope this helps.

    Alexander Morris                  "People die, things change...
    Carnegie Mellon                             It's sad."