Board index » delphi » VGA 256 color 320 by 200 PCX/GIF Viewer Source Code

VGA 256 color 320 by 200 PCX/GIF Viewer Source Code

OK, I can't get PCX/GIF to view with any of my source codes
that I donwload off the web. Do any of you have any PCX/GIF
(GIF Preferrably)Source code that will work with any version of the
file types? I really need this. I'll give you some tips in exchange.

 

Re:VGA 256 color 320 by 200 PCX/GIF Viewer Source Code


Hi,
  I've got one for you. It's object oriented and acts like a filter. It takes
an input .GIF file, decodes it and puts the result in another file in a plain
format described below :

Width of picture     (1 word)
Height of picture    (1 word)
Colordepth in bits   (1 byte)
PaletteSize          (1 word)
Palette              (PaletteSize RGB triplets)
Simple image scanline data (Width*Height bytes)

In your case this would give :

320
200
8
256
{ 256 RGB triplets = 768 bytes }
{ 64000 (320*200) bytes of pixel data }

This is simple to read and understand. The code reads all formats (gif87/89a,
interlaced and non-interlaced) except multiple image gifs (it only reads the
first in that case). You can also write gif's which simply works in reverse
order : you give a file with the plain format as input and it outputs a .GIF
file. The only thing I'm not sure about is the legal side of this. Unisys has
patented the LZW algorithm used in .GIF files and I don't know if they allow
free/shareware implementations of .GIF readers without registering !

Mail me if you want it and I'll send it to you.

E-mail : s795...@dutiwy.twi.tudelft.nl

Ciao,
Menno

Re:VGA 256 color 320 by 200 PCX/GIF Viewer Source Code


Quote
>   sethho...@juno.com writes:
>  OK, I can't get PCX/GIF to view with any of my source codes
>  that I donwload off the web. Do any of you have any PCX/GIF
>  (GIF Preferrably)Source code that will work with any version of the
>  file types? I really need this. I'll give you some tips in exchange.

I don't know where I found this, (it's real limited and REAL slow, but it
does work....)  Don't flame me for it :)

unit PCX;

{   The following display modes are supported:

          Mode      TP GraphMode     Resolution    Colors
          ~~~~      ~~~~~~~~~~~~     ~~~~~~~~~~    ~~~~~~
          $04       CGAC0 to C3      320 x 200         4
          $06       CGAHi            640 x 200         2
          $0D        ---             320 x 200        16
          $0E       EGALo/VGALo      640 x 200        16
          $10       EGAHi/VGAMed     640 x 350        16
          $12       VGAHi            640 x 480        16
          $13        ---             320 x 200       256

   Mode $13 is supported only for files containing palette information,
   i.e. not those produced by versions of Paintbrush earlier than 3.0.}

INTERFACE

uses DOS, GRAPH;

type    RGBrec = record
                   redval, greenval, blueval: byte;
                 end;

var     pcxfilename: pathstr;
        file_error: boolean;
        pal: palettetype;
        RGBpal: array[0..15] of RGBrec;
        RGB256: array[0..255] of RGBrec;
        page_addr: word;
        bytes_per_line: word;
        buff0, buff1: pointer;

        { CGA display memory banks: }
        screenbuff0: array[0..7999] of byte absolute $b800:$0000;
        screenbuff1: array[0..7999] of byte absolute $b800:$2000;

const   page0 = $A000;           { EGA/VGA display segment }

procedure SETMODE(mode: byte);
procedure SETREGISTERS(var palrec);
procedure READ_PCX_FILE(gdriver: integer; pfilename: pathstr);
procedure READ_PCX256(pfilename: pathstr);

{========================================================================}

IMPLEMENTATION

var     scratch, abuff0, abuff1: pointer;
        is_CGA, is_VGA: boolean;
        repeatcount: byte;
        datalength: word;
        columncount, plane, video_index: word;
        regs: registers;

const   buffsize = 65521;   { Largest possible }

{ -------------------------- BIOS calls --------------------------------- }

{ For modes not supported by the BGI, use SetMode to initialize the
  graphics. Since SetRGBPalette won't work if Turbo hasn't done the
  graphics initialization itself, use SetRegisters to change the colors
  in mode $13. }

procedure SETMODE(mode: byte);

begin
regs.ah:= 0;                 { BIOS set mode function }
regs.al:= mode;              { Display mode }
intr($10, regs);             { Call BIOS }
end;

procedure SETREGISTERS(var palrec);

{ Palrec is any string of 768 bytes containing the RGB data. }

begin
regs.ah:= $10;               { BIOS color register function }
regs.al:= $12;               { Subfunction }
regs.es:= seg(palrec);       { Address of palette info. }
regs.dx:= ofs(palrec);
regs.bx:= 0;                 { First register to change }
regs.cx:= $100;              { Number of registers to change }
intr($10, regs);             { Call BIOS }
end;

{ ====================== EGA/VGA 16-color files ========================= }

procedure DECODE_16; assembler;

asm
push    bp

{ ----------------- Assembler procedure for 16-color files -------------- }

{ The first section is initialization done on each run through the
  input buffer. }

@startproc:
mov     bp, plane           { plane in BP }
mov     es, page_addr       { video display segment }
mov     di, video_index     { index into video segment }
mov     ah, byte ptr bytes_per_line  { line length in AH }
mov     dx, columncount     { column counter }
mov     bx, datalength      { no. of bytes to read }
xor     cx, cx              { clean up CX for loop counter }
mov     cl, repeatcount     { count in CX }
push    ds                  { save DS }
lds     si, scratch         { input buffer pointer in DS:SI }
add     bx, si
cld                         { clear DF for stosb }
cmp     cl, 0               { was last byte a count? }
jne     @multi_data         { yes, so next is data }
jmp     @getbyte            { no, so find out what next is }

{ -------------- Procedure to write EGA/VGA image to video -------------- }

@writebyte:
stosb                       { AL into ES:DI, inc DI }
inc     dl                  { increment column }
cmp     dl, ah              { reached end of scanline? }
je      @doneline           { yes }
loop    @writebyte          { no, do another }
jmp     @getbyte            {   or get more data }
@doneline:
shl     bp, 1               { shift to next plane }
cmp     bp, 8               { done 4 planes? }
jle     @setindex           { no }
mov     bp, 1               { yes, reset plane to 1 but don't reset index }
jmp     @setplane
@setindex:
sub     di, dx              { reset to start of line }
@setplane:
push    ax                  { save AX }
cli                         { no interrupts }
mov     ax, bp              { plane is 1, 2, 4, or 8 }
mov     dx, 3C5h            { sequencer data register }
out     dx, al              { mask out 3 planes }
sti                         { enable interrupts }
pop     ax                  { restore AX }
xor     dx, dx              { reset column count }
loop    @writebyte          { do it again, or fetch more data }

@getbyte:                   { last byte was not a count }
cmp     si, bx              { end of input buffer? }
je      @exit               { yes, quit }
lodsb                       { get a byte from DS:SI into AL, increment SI }
cmp     al, 192             { test high bits }
jb      @one_data           { not set, it's data to be written once }
 { It's a count byte: }
xor     al, 192             { get count from 6 low bits }
mov     cl, al              { store repeat count }
cmp     si, bx              { end of input buffer? }
je      @exit               { yes, quit }
@multi_data:
lodsb                       { get data byte }
jmp     @writebyte          { write it CL times }
@one_data:
mov     cl, 1               { write byte once }
jmp     @writebyte

{ ---------------------- Finished with buffer --------------------------- }

@exit:
pop     ds                  { restore Turbo's data segment }
mov     plane, bp           { save status for next run thru buffer }
mov     repeatcount, cl
mov     columncount, dx
mov     video_index, di
pop     bp
end;  { asm }

{ ===================== CGA 2- and 4-color files ======================== }

procedure DECODE_CGA; assembler;

asm

push    bp
jmp     @startproc

{ ------------- Procedure to store CGA image in buffers ----------------- }

@storebyte:
stosb                       { AL into ES:DI, increment DI }
inc     dx                  { increment column count }
cmp     dl, ah              { reached end of line? }
je      @row_ends           { yes }
loop    @storebyte          { not end of row, do another byte }
ret
@row_ends:
xor     bp, 1               { switch banks }
cmp     bp, 1               { is bank 1? }
je      @bank1              { yes }
mov     word ptr abuff1, di { no, save index into bank 1 }
les     di, abuff0          { bank 0 pointer into ES:DI }
xor     dx, dx              { reset column counter }
loop    @storebyte
ret
@bank1:
mov     word ptr abuff0, di { save index into bank 0 }
les     di, abuff1          { bank 1 pointer into ES:DI }
xor     dx, dx              { reset column counter }
loop    @storebyte
ret

{ ---------------- Main assembler procedure for CGA --------------------- }

@startproc:
mov     bp, 0                        { bank in BP }
mov     es, word ptr abuff0[2]       { segment of bank 0 buffer }
mov     di, word ptr abuff0          { offset of buffer }
mov     ah, byte ptr bytes_per_line  { line length in AH }
mov     bx, datalength               { no. of bytes to read }
xor     cx, cx                       { clean up CX for loop counter }
xor     dx, dx                       { initialize column counter }
mov     si, dx                       { initialize input index }
cld                                  { clear DF for stosb }

{ -------------------- Loop through input buffer ------------------------ }

@getbyte:
cmp     si, bx              { end of input buffer? }
je      @exit               { yes, quit }
push    es                  { save output pointer }
push    di
les     di, scratch         { get input pointer in ES:DI }
add     di, si              { add current offset }
mov     al, [es:di]         { get a byte }
inc     si                  { advance input index }
pop     di                  { restore output pointer }
pop     es
cmp     cl, 0               { was previous byte a count? }
jg      @multi_data         { yes, this is data }
cmp     al, 192             { no, test high bits }
jb      @one_data           { not set, not a count }
 { It's a count byte: }
xor     al, 192             { get count from 6 low bits }
mov     cl, al              { store repeat count }
jmp     @getbyte            { go get data byte }
@one_data:
mov     cl, 1               { write byte once }
call    @storebyte
jmp     @getbyte
@multi_data:
call    @storebyte          { CL already set }
jmp     @getbyte

{ ---------------------- Finished with buffer --------------------------- }

@exit:
pop     bp
end;  { asm }

{ ============= Main procedure for CGA and 16-color files =============== }

procedure READ_PCX_FILE(gdriver: integer; pfilename: pathstr);

type    ptrrec = record
                   segm, offs: word;
                 end;

var     entry, gun, pcxcode, mask, colorID: byte;
        palbuf: array[0..66] of byte;
        pcxfile: file;

begin   { READ_PCX_FILE }
is_CGA:= (gdriver = CGA);   { 2 or 4 colors }
is_VGA:= (gdriver = VGA);   { 16 of 256K possible colors }
                            { Otherwise EGA - 16 of 64 possible colors }
assign(pcxfile, pfilename);
{$I-} reset(pcxfile, 1);  {$I+}
...

read more »

Other Threads