Board index » delphi » graphics routines

graphics routines

Does anyone out there know how to place PCX, GIF, BMP, or TGA images on the
screen in 320*200*256 mode? I had a unit that could do this but I seem to
have lost it before I could record the code. I would really appreciate if
anyone would please answer me. I want to get a game working and that is the
only thing from getting it back on again.

Please answer me, POST REPLIES!!!

Calvinicus Ashmore

                        0-Q-Z     :-P

thanx

 

Re:graphics routines


Quote
Ron Ashmore wrote:

> Does anyone out there know how to place PCX, GIF, BMP, or TGA images on the
> screen in 320*200*256 mode? I had a unit that could do this but I seem to
> have lost it before I could record the code. I would really appreciate if
> anyone would please answer me. I want to get a game working and that is the
> only thing from getting it back on again.

> Please answer me, POST REPLIES!!!

> Calvinicus Ashmore

>                         0-Q-Z     :-P

> thanx

First, open the file as a binary file. This is done with a statement
like:

******************************
Var
  Data:File of byte;
Begin;
  Assign(Data,"Filename.pcx");
  Reset(Data);
******************************

Then you need to get the size of the file using the function
"Filesize".  If you want to load the image's palette, then you use the
"seek" command to go to the end of the file minus 768 bytes.  The
palette information is stored in the last 768 bytes in 256 sets of three
bytes. Each byte represents the Red, Green, and Blue intensities
respecttivily.  The structure of the palette information is: r0 g0 b0 r1
g1 b1 r2 ......r255 g255 b255.  If you are perceptive you will notice
that under this scheme that the number of colors addressible by this
storage scheme is 256*256*256=16 million and change.  Since standard VGA
only supports 256000 colors, you must throw away the extra two bits by
doing a binary shift to the right by two bits.  This is done with the
statement "red:=red shr 2". Do this for all 768 bytes in the palette
information.

Next comes the actual graphics data.  The Data is stored with one byte
representing one pixel going from top left to bottom right row by row.
First skip the header(I don't have the header format handy, but it is
usually not needed if you load the same size and type of pcx file) by
useing the "seek" command to seek to location 128 in the file. The
graphics data is RLE encoded. This stands for Run Lenght Encoded.  The
way to decode the RLE is:

1.  Read a byte from the file.(Byte1)

2.  If the byte is less than 192 then
    a. Write byte to screen
    b. goto 1

3.  If the byte is greater than 191 then
    a. Read next byte from file.(byte2)
    b. Write byte2 to the screen byte1-192 times.
    c. goto 1

Do this until you have written 64000 pixels to the screen or until you
reach the palette information of the file(which ever you like best)

If this completely confuses you then don't worry, I plan to release a
freeware PCX loader for Pascal as soon as I get the time. I will post
the location of this file to this newsgroup.

Hope this helps...

                            Greg Breland
                            Student at Mississippi State University
                            Does anyone read these footnotes?
                            g...@ra.msstate.edu

Other Threads