please help me I'm desperate... 
Author Message
 please help me I'm desperate...

I've found the code that shows pcx images, and also saves screen in pcx
image. But it only works in 320x200x256 mode, so I would like to modify it
so that the code could work under 640x480x256. Can anyone tell me how to do
it? I'm using svga256.bgi driver.
Here's the code:

Unit vgapcx;
{ This is a modified version of ZSoft's SHOW_PCX                        }
{ If you use it in any of your own programs, ZSoft requests that you    }
{ unclude the following notice:                                         }
{                                                                       }
{     Includes portions of SHOW_PCX.                                    }
{     Used by permission of ZSoft Corporation.                          }
Interface
uses
  Dos;
const
  MaxWidth = 4000;    { arbitrary - maximum width (in bytes) of a PCX
image }
  CompressNum = $C0;  { this is the upper two bits that indicate a count }
  MaxBlock = 4096;
  Red = 0;
  Green = 1;
  Blue = 2;
  MCGA = $13;
type
  FileBuffer = array [0..127] of byte;
  BlockArray = array [0..MaxBlock] of byte;
  PalArray = array [0..255, Red..Blue] of byte;
  Pal16Array = array[0..15, Red..Blue] of byte;
  EGAArray = array [0..16] of byte;
  LineArray = array [0..MaxWidth] of byte;
  PCXHeader = record
                Manufacturer: byte;     { Always 10 for PCX file }
                Version: byte;          { 2 - old PCX - no palette (not used
anymore),
                                          3 - no palette,
                                          4 - Microsoft Windows - no palette
(only in
                                              old files, new Windows version
uses 3),
                                          5 - with palette }
                Encoding: byte;         { 1 is PCX, it is possible that we
may add
                                          additional encoding methods in the
future }
                BitsPerPixel: byte;     { Number of bits to represent a
pixel
                                          (per plane) - 1, 2, 4, or 8 }
                XMin: integer;          { Image window dimensions
(inclusive) }
                YMin: integer;          { Xmin, Ymin are usually zero (not
always) }
                XMax: integer;
                YMax: integer;
                HDPI: integer;          { Resolution of image (dots per
inch) }
                VDPI: integer;          { Set to scanner resolution - 300 is
default }
                ColorMap: Pal16Array;
                                        { RGB palette data (16 colors or
less)
                                          256 color palette is appended to
end of file }
                Reserved: byte;         { (used to contain video mode)
                                          now it is ignoRed - just set to
zero }
                NPlanes: byte;          { Number of planes }
                BytesPerLinePerPlane: integer;   { Number of bytes to
allocate
                                                   for a scanline plane.
                                                   MUST be an an EVEN
number!
                                                   Do NOT calculate from
Xmax-Xmin! }
                PaletteInfo: integer;   { 1 = black & white or color image,
                                          2 = grayscale image - ignoRed in
PB4, PB4+
                                          palette must also be set to shades
of gray! }
                HscreenSize: integer;   { added for PC Paintbrush IV Plus
ver 1.0,  }
                VscreenSize: integer;   { PC Paintbrush IV ver 1.02 (and
later)     }
                                        { I know it is tempting to use these
fields
                                          to determine what video mode
should be used
                                          to display the image - but it is
NOT
                                          recommended since the fields will
probably
                                          just contain garbage. It is better
to have
                                          the user install for the graphics
mode he
                                          wants to use... }
                Filler: array [74..127] of byte;     { Just set to zeros }
              end;
procedure ReadPCX(iname: PathStr);
procedure displaypcx(iname: PathStr);
procedure WritePCX(iname: PathStr; pal: pointer; VGAPal: boolean);
Implementation
Uses
  crt;
var
  Name:                                 PathStr;
  BlockFile:                            file;
  BlockData:                            BlockArray;
  Header:                               PCXHeader;
  Palette256:                           PalArray;
  PaletteEGA:                           EGAArray;
  PCXline:                              LineArray;
  YMax:                                 integer;
  NextByte: integer;                  { index into file buffer in ReadByte }
  Index: integer;                     { PCXline index - where to put Data }
  Data: byte;                         { PCX compressed data byte }
  PictureMode: integer;               { Graphics mode number }
  Reg:                                  Registers;
  fs, fp:                               longint;
procedure Error(s: string);
Begin
  WriteLn(s);
  halt;
end;
procedure ReadError(msg: integer);
{ called to check for an error reading the file }
begin
  if IOresult <> 0 then
    case msg of
      1:  Error ('Can''t open file - ' + Name);
      2:  Error ('Error closing file - ' + Name + ' - disk may be full');
      3:  Error ('Error reading file - ' + Name);
    else
      Error ('Error doing file I/O - ' + Name);
    end;   { case }
end;   { ReadError }
procedure VideoMode(n: integer);
{ the simplest possible video mode setting procedure }
begin
  Reg.ah := $00;
  Reg.al := n;                         { mode number }
  intr ($10, Reg);                     { call interrupt }
end;  { VideoMode }
procedure EntireVGApalette;
{ takes a PCX format palette (all colors 0..255) and transforms it to a }
{ VGA palette (all colors 0..63) }
var
   i:                                   integer;
begin
  for i:=0 to 255 do
  begin                                          { R, G, and B must be
0..63 }
    Palette256[i, Red]:=Palette256[i, Red] shr 2;
    Palette256[i, Green]:=Palette256[i, Green] shr 2;
    Palette256[i, Blue]:=Palette256[i, Blue] shr 2;
  end;
  Reg.ah:=$10;                       { Set DAC Call }
  Reg.al:=$12;                       { set a block of DAC registers }
  Reg.bx:=0;                         { first DAC register number }
  Reg.cx:=255;                       { number of registers to update }
  Reg.dx:=ofs (Palette256);          { offset of block }
  Reg.es:=seg (Palette256);          { segment of block }
  intr($10, Reg);                     { call interrupt }
end;  { EntireVGApalette }
procedure ShowMCGA (Y: integer);
{ Shows one line of an MCGA image }
var
  l:                                    integer;
  MCGAscreen:                           array [0..64000] of byte absolute
$A000:$0000;
begin
  l:=Header.XMax-Header.Xmin;            { compute number of bytes to
display }
  if l>320 then l:=320;                               { don't overrun screen
width }
  Move(PCXline[0], MCGAScreen[Y*320], l);
end;   { ShowMCGA }
procedure Read256palette;
{ Reads a 256-color palette (if present) off the end of the PCX file }
var
  i:                                    integer;
  b:                                    byte;
begin
  seek(BlockFile, FileSize(BlockFile)-769);
  BlockRead(BlockFile, b, 1);           { read indicator byte }
  ReadError(3);
  if b <> 12 then exit;                  { no palette here... }
  BlockRead(BlockFile, Palette256, 3*256);
  ReadError(3);
  seek(BlockFile, 128);                 { go back to start of PCX data }
end;  { Read256palette }
procedure ReadHeader;

Procedure WrongFormat;
begin
  close (BlockFile);
  Error ('PCX file is in wrong format - It must be an MCGA image');
end;

begin
{$I-}
  BlockRead(BlockFile, Header, 128);         { read 128 byte PCX header }
  ReadError(3);
  if (Header.Manufacturer <> 10) or (Header.Encoding <> 1) then
  begin
    close(BlockFile);
    Error('This is not a valid PCX image file.');
  end;
  if (Header.Nplanes = 1) then
  begin
    Ymax := 199;
    if (Header.BitsPerPixel = 8) then
    begin
      PictureMode := MCGA;
      if Header.Version = 5 then Read256palette;
    end else WrongFormat;
  end else WrongFormat;
  Index := 0;
  NextByte := MaxBlock;          { indicates no data read in yet... }
end;  { ReadHeader }
Function ReadByte: byte;
begin
  if NextByte=MaxBlock then
    if FileSize(BlockFile)-FilePos(BlockFile)>=MaxBlock then
    begin
      BlockRead(BlockFile, BlockData, MaxBlock);
      NextByte:=0;
    end else
    begin
      BlockRead(BlockFile, BlockData,
FileSize(BlockFile)-FilePos(BlockFile));
      NextByte:=0;
    end;
  ReadByte:=BlockData[NextByte];
  inc(NextByte);                         { NextByte++; }
end;  { ReadByte }
procedure ReadPCXLine;
var
  count, BytesPerLine:                  integer;
begin
{$I-}
  BytesPerLine:=Header.BytesPerLinePerPlane * Header.Nplanes;
  if Index <> 0 then FillChar(PCXline[0], Index, data);    { fills a
contiguous block of data }
  while (Index < BytesPerLine) do          { read 1 line of data (all
planes) }
  begin
    data:=ReadByte;
    if (data and $C0) = CompressNum then
    begin
      count:=data and $3F;
      data:=ReadByte;
      FillChar(PCXline [Index], count, data);  { fills a contiguous block }
      inc(Index, count);                       { Index += count; }
    end   else
    begin
      PCXline [Index] := data;
      inc(Index);                              { Index++; }
    end;
  end;
  ReadError(3);
  Index:=Index-BytesPerLine;
{$I+}
end;  { ReadPCXLine }
procedure ReadPCX(iname: PathStr);
var
  k, kmax:                              integer;
begin
{$I-}
  name:=iname;
  assign(BlockFile, name);
  reset(BlockFile, 1);                  { use 1 byte blocks }
  ReadError(1);
...

read more »



Wed, 18 Jun 1902 08:00:00 GMT  
 please help me I'm desperate...
this program only does 8 bits per pixel.. very versatile. :P  i have Pascal
PCX code that does 1,4,8,and 24-bit images (24-bit uses true color palette,
no dithering yet).  it also has XMS and mouse scrolling.  however, it
doesn't save the screen to a file, and it doesn't use svga256.bgi.  the
VESA unit is fairly fast, but it won't work on all vesa cards - just a
large majority.  mail me if yer interested..  (btw, the prog is
640x480x256)

there's also a great vesa unit by Peter DeJong, which can save PCXs and
supports more svga cards.  i don't recall if it has PCX scrolling though.


: I've found the code that shows pcx images, and also saves screen in pcx
: image. But it only works in 320x200x256 mode, so I would like to modify it
: so that the code could work under 640x480x256. Can anyone tell me how to do
: it? I'm using svga256.bgi driver.
: Here's the code:

: Unit vgapcx;
: { This is a modified version of ZSoft's SHOW_PCX                        }
: { If you use it in any of your own programs, ZSoft requests that you    }
: { unclude the following notice:                                         }
: {                                                                       }
: {     Includes portions of SHOW_PCX.                                    }
: {     Used by permission of ZSoft Corporation.                          }
: Interface
: uses
:   Dos;
: const
:   MaxWidth = 4000;    { arbitrary - maximum width (in bytes) of a PCX
: image }
:   CompressNum = $C0;  { this is the upper two bits that indicate a count }
:   MaxBlock = 4096;
:   Red = 0;
:   Green = 1;
:   Blue = 2;
:   MCGA = $13;
: type
:   FileBuffer = array [0..127] of byte;
:   BlockArray = array [0..MaxBlock] of byte;
:   PalArray = array [0..255, Red..Blue] of byte;
:   Pal16Array = array[0..15, Red..Blue] of byte;
:   EGAArray = array [0..16] of byte;
:   LineArray = array [0..MaxWidth] of byte;
:   PCXHeader = record
:                 Manufacturer: byte;     { Always 10 for PCX file }
:                 Version: byte;          { 2 - old PCX - no palette (not used
: anymore),
:                                           3 - no palette,
:                                           4 - Microsoft Windows - no palette
: (only in
:                                               old files, new Windows version
: uses 3),
:                                           5 - with palette }
:                 Encoding: byte;         { 1 is PCX, it is possible that we
: may add
:                                           additional encoding methods in the
: future }
:                 BitsPerPixel: byte;     { Number of bits to represent a
: pixel
:                                           (per plane) - 1, 2, 4, or 8 }
:                 XMin: integer;          { Image window dimensions
: (inclusive) }
:                 YMin: integer;          { Xmin, Ymin are usually zero (not
: always) }
:                 XMax: integer;
:                 YMax: integer;
:                 HDPI: integer;          { Resolution of image (dots per
: inch) }
:                 VDPI: integer;          { Set to scanner resolution - 300 is
: default }
:                 ColorMap: Pal16Array;
:                                         { RGB palette data (16 colors or
: less)
:                                           256 color palette is appended to
: end of file }
:                 Reserved: byte;         { (used to contain video mode)
:                                           now it is ignoRed - just set to
: zero }
:                 NPlanes: byte;          { Number of planes }
:                 BytesPerLinePerPlane: integer;   { Number of bytes to
: allocate
:                                                    for a scanline plane.
:                                                    MUST be an an EVEN
: number!
:                                                    Do NOT calculate from
: Xmax-Xmin! }
:                 PaletteInfo: integer;   { 1 = black & white or color image,
:                                           2 = grayscale image - ignoRed in
: PB4, PB4+
:                                           palette must also be set to shades
: of gray! }
:                 HscreenSize: integer;   { added for PC Paintbrush IV Plus
: ver 1.0,  }
:                 VscreenSize: integer;   { PC Paintbrush IV ver 1.02 (and
: later)     }
:                                         { I know it is tempting to use these
: fields
:                                           to determine what video mode
: should be used
:                                           to display the image - but it is
: NOT
:                                           recommended since the fields will
: probably
:                                           just contain garbage. It is better
: to have
:                                           the user install for the graphics
: mode he
:                                           wants to use... }
:                 Filler: array [74..127] of byte;     { Just set to zeros }
:               end;
: procedure ReadPCX(iname: PathStr);
: procedure displaypcx(iname: PathStr);
: procedure WritePCX(iname: PathStr; pal: pointer; VGAPal: boolean);
: Implementation
: Uses
:   crt;
: var
:   Name:                                 PathStr;
:   BlockFile:                            file;
:   BlockData:                            BlockArray;
:   Header:                               PCXHeader;
:   Palette256:                           PalArray;
:   PaletteEGA:                           EGAArray;
:   PCXline:                              LineArray;
:   YMax:                                 integer;
:   NextByte: integer;                  { index into file buffer in ReadByte }
:   Index: integer;                     { PCXline index - where to put Data }
:   Data: byte;                         { PCX compressed data byte }
:   PictureMode: integer;               { Graphics mode number }
:   Reg:                                  Registers;
:   fs, fp:                               longint;
: procedure Error(s: string);
: Begin
:   WriteLn(s);
:   halt;
: end;
: procedure ReadError(msg: integer);
: { called to check for an error reading the file }
: begin
:   if IOresult <> 0 then
:     case msg of
:       1:  Error ('Can''t open file - ' + Name);
:       2:  Error ('Error closing file - ' + Name + ' - disk may be full');
:       3:  Error ('Error reading file - ' + Name);
:     else
:       Error ('Error doing file I/O - ' + Name);
:     end;   { case }
: end;   { ReadError }
: procedure VideoMode(n: integer);
: { the simplest possible video mode setting procedure }
: begin
:   Reg.ah := $00;
:   Reg.al := n;                         { mode number }
:   intr ($10, Reg);                     { call interrupt }
: end;  { VideoMode }
: procedure EntireVGApalette;
: { takes a PCX format palette (all colors 0..255) and transforms it to a }
: { VGA palette (all colors 0..63) }
: var
:    i:                                   integer;
: begin
:   for i:=0 to 255 do
:   begin                                          { R, G, and B must be
: 0..63 }
:     Palette256[i, Red]:=Palette256[i, Red] shr 2;
:     Palette256[i, Green]:=Palette256[i, Green] shr 2;
:     Palette256[i, Blue]:=Palette256[i, Blue] shr 2;
:   end;
:   Reg.ah:=$10;                       { Set DAC Call }
:   Reg.al:=$12;                       { set a block of DAC registers }
:   Reg.bx:=0;                         { first DAC register number }
:   Reg.cx:=255;                       { number of registers to update }
:   Reg.dx:=ofs (Palette256);          { offset of block }
:   Reg.es:=seg (Palette256);          { segment of block }
:   intr($10, Reg);                     { call interrupt }
: end;  { EntireVGApalette }
: procedure ShowMCGA (Y: integer);
: { Shows one line of an MCGA image }
: var
:   l:                                    integer;
:   MCGAscreen:                           array [0..64000] of byte absolute
: $A000:$0000;
: begin
:   l:=Header.XMax-Header.Xmin;            { compute number of bytes to
: display }
:   if l>320 then l:=320;                               { don't overrun screen
: width }
:   Move(PCXline[0], MCGAScreen[Y*320], l);
: end;   { ShowMCGA }
: procedure Read256palette;
: { Reads a 256-color palette (if present) off the end of the PCX file }
: var
:   i:                                    integer;
:   b:                                    byte;
: begin
:   seek(BlockFile, FileSize(BlockFile)-769);
:   BlockRead(BlockFile, b, 1);           { read indicator byte }
:   ReadError(3);
:   if b <> 12 then exit;                  { no palette here... }
:   BlockRead(BlockFile, Palette256, 3*256);
:   ReadError(3);
:   seek(BlockFile, 128);                 { go back to start of PCX data }
: end;  { Read256palette }
: procedure ReadHeader;

: Procedure WrongFormat;
: begin
:   close (BlockFile);
:   Error ('PCX file is in wrong format - It must be an MCGA image');
: end;

: begin
: {$I-}
:   BlockRead(BlockFile, Header, 128);         { read 128 byte PCX header }
:   ReadError(3);
:   if (Header.Manufacturer <> 10) or (Header.Encoding <> 1) then
:   begin
:     close(BlockFile);
:     Error('This is not a valid PCX image file.');
:   end;
:   if (Header.Nplanes = 1) then
:   begin
:     Ymax := 199;
:     if (Header.BitsPerPixel = 8) then
:     begin
:       PictureMode := MCGA;
:       if Header.Version = 5 then Read256palette;
:     end else WrongFormat;
:   end else WrongFormat;
:   Index := 0;
:   NextByte := MaxBlock;          { indicates no data read in yet... }
: end;  { ReadHeader }
: Function ReadByte: byte;
: begin
:   if NextByte=MaxBlock then
:     if FileSize(BlockFile)-FilePos(BlockFile)>=MaxBlock then
:     begin
:       BlockRead(BlockFile, BlockData, MaxBlock);
:       NextByte:=0;
:     end else
:     begin
:       BlockRead(BlockFile, BlockData,
: FileSize(BlockFile)-FilePos(BlockFile));
:       NextByte:=0;
:  
...

read more »



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. OK I'm desperate- QR hell, please help

2. IndexDefs.Add('Help','Please',[ixD2WorksGreat, ixD3Errors])

3. ReportSmith-I'm getting desperate now!

4. DESPERATE - DELPHI Q's

5. More noob help needed please: 'asm'

6. Please Help: Duplicate DatabaseName : 'xxxx' error

7. help with doing a program!!!! please, i'm desperate

8. help with doing a program!!!! please, i'm desperate

9. Desperate for HELP on 'Lock Violation' ???

10. What's wrong with this .pas please help - grabar.pas (0/1)

11. What's wrong with this .pas please help - grabar.pas (1/1)

12. Pascal Guru's please help....................................................................

 

 
Powered by phpBB® Forum Software