[comp.lang.pascal] VGA Graphics

jrn@csd4.csd.uwm.edu (James Ray Norton) (09/26/89)

Hi,

I have a slight problem....

I am trying to write a program using Turbo Pascal Version 5.  This program is
supposed to save a graphics image (VGA 640 x 480) to the disk and later reload
the image back to the display...

I have written a routine that will save the image (tested it by putting the
image back on the screen)...However my routine to load the image file to
the screen will not work...

THe source code for my routines are as follows...


procedure  SaveGraph(GraphicFile:  string; x,y,xw,yw: real; xres,yres: integer;
                     var IOR:  integer);

var  ImageChunk:  pointer;
     DiskFile:  File;
     Junk:  word;
     InfoFile:  Text;

begin
 Assign(DiskFile, GraphicFile);
   .
   .
   .
 Rewrite(DiskFile, 65533);
 GetMem(ImageChunk, 65533);
 GetImage(0,0,480,480, ImageChunk^);
 BlockWrite(DiskFile, ImageChunk^,1);
 FreeMem(ImageChunk, 65533);
 Close(DiskFile);
end;

The above routine is working....

Now for the routine that does not work..

procedure  LoadGraph(GraphicFile:  string;
                     var  x,y,xw,yw: real;
                     var  PixX,PixY,Size:  integer;
                     var  IOR:  integer);

Var  DiskFile:  File;
     InfoFile:  Text;
     DataBuffer:  Pointer;

Begin
 Assign(DiskFile, GraphicFile);
   .
   .
   .
   .
 Reset(DiskFile, 65533);
 GetMem(DataBuffer, 65533);
 BlockRead(DiskFile, DataBuffer^,1);
 PutImage(0,0,DataBuffer^,0);
end;

This procedure causes no errors....But it just causes the screen to go blank..

I would greatly appreciate any help that could be given....

thanks in advance..

--
_______________________________________________________________________________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 _    _ _       _ _ _
' )  / ' )   / ' ) ) )                                  jrn@csd4.csd.uwm.edu

sigthor@rhi.hi.is (Sigthor Orn Gudmundsson) (09/27/89)

In article <216@uwm.edu> jrn@csd4.csd.uwm.edu (James Ray Norton) writes:
>
>I am trying to write a program using Turbo Pascal Version 5.  This program is
>supposed to save a graphics image (VGA 640 x 480) to the disk and later reload
>the image back to the display...
>
>I have written a routine that will save the image (tested it by putting the
>image back on the screen)...However my routine to load the image file to
>the screen will not work...
>
>THe source code for my routines are as follows...

    Source deleted... 

   I hope that you can use this small program as a help to your problem.
   I do not comment my code. (You will understand the code)
   I used blockwrite to make the code similar to yours.


PROGRAM save_get_screen;    { Demostration program for screen saving }
USES
   crt,graph;
VAR
   gd,gm:INTEGER;

PROCEDURE draw_screen;  { This procedure draws the image to save }
BEGIN
   SETCOLOR(yellow);
   RECTANGLE (0,0,getmaxx,getmaxy);
END;

PROCEDURE save_screen(filename:STRING);

{ CODE tested on CGA,EGA,VGA: (all screenmodes)  }
VAR
   p:POINTER;
   size,sulta:WORD;
   hl:INTEGER;
   save_file:FILE;
BEGIN
   ASSIGN(save_file,filename);
   REWRITE(save_file);
   size:=IMAGESIZE(0,0,getmaxx,ROUND((getmaxy+1)/7));
   GETMEM(p,size);
   FOR hl:=1 TO 7 DO BEGIN
      getimage(0,ROUND((getmaxy/7)*(hl-1)),getmaxx,ROUND((getmaxy/7)*hl),p^);
      BLOCKWRITE(save_file,p^,size,sulta);
   END;
   freemem(p,size);
   close(save_file);
END;



PROCEDURE get_screen(filename:STRING);
VAR
   p:POINTER;
   size,sulta:WORD;
   hl:INTEGER;
   get_file:FILE;
BEGIN
   ASSIGN(get_file,filename);
   RESET(get_file);
   size:=IMAGESIZE(0,0,getmaxx,ROUND((getmaxy+1)/7));
   GETMEM(p,size);
   FOR hl:=1 TO 7 DO BEGIN
      BLOCKREAD(get_file,p^,size,sulta);
      PUTIMAGE(0,ROUND((getmaxy/7)*(hl-1)),p^,NORMALPUT);
   END;
   freemem(p,size);
   close(get_file);
END;


BEGIN
   DETECTGRAPH(gd,gm);
   INITGRAPH(gd,gm,'');
   draw_screen;
   save_screen('temp.tmp');
   get_screen('temp.tmp');
   RESTORECRTMODE;
END.

-- 
This is a signature. 

I hope it is funny.

UD092096@NDSUVM1.BITNET (Barry Pederson) (09/28/89)

I've written a unit to save VGA screens, and it looks very much like the
code Sigthor Orn Gudmundsson posted, but with one extra part.  Before I did
a BlockWrite all the pixel data, I got a copy of the color palette using
the GetPalette procedure and BlockWrote it to the file.  When reading the
file, I BlockRead the palette and set it using the SetAllPalette procedure.

This probably would make no sense with CGA screens, but VGA would need this
unless you were just using the default palette all the time.

Hope this helps.

-------
Barry Pederson         InterNet: ud092096@vm1.nodak.edu (might be faster)
                         BitNet: ud092096@ndsuvm1