$INCLUDE "RAPIDQ.INC"
$APPTYPE GUI
$TYPECHECK ON
DECLARE SUB formPaint
DECLARE SUB LoadPCXfile
DECLARE SUB ExitApp
TYPE PcxHeaderType
MAN AS STRING * 1
VER AS STRING * 1
ENC AS STRING * 1
BIT AS STRING * 1
Xmin AS SHORT
Ymin AS SHORT
XMax AS SHORT
YMax AS SHORT
HRE AS SHORT
VRE AS SHORT
COL AS STRING * 48
RES AS STRING * 1
nplanes AS STRING * 1
bytesperline AS SHORT
PAL AS SHORT
FIL AS STRING * 58
END TYPE
DIM TheFileName AS STRING
DIM field AS QBITMAP
CREATE Form AS QFORM
CAPTION="PCX Viewer"
Height=444
Width=603
Center
OnClick = LoadPCXfile
OnPaint = formPaint
CREATE MainMenu AS QMAINMENU
CREATE FileMenu AS QMENUITEM
CAPTION = " &File"
CREATE OpenItem AS QMENUITEM
CAPTION = " &Open PCX File"
OnClick = LoadPCXfile
END CREATE
CREATE ExitItem AS QMENUITEM
CAPTION = " E&xit"
OnClick = ExitApp
END CREATE
END CREATE
END CREATE
END CREATE
form.SHOWMODAL
SUB formPaint
Form.draw(0, 0, field.bmp)
END SUB
SUB LoadPCXfile
DIM PCX AS PcxHeaderType
DIM xsize AS INTEGER, Ysize AS INTEGER, Totalbytes AS INTEGER, I AS INTEGER
DIM r AS INTEGER, g AS INTEGER, b AS INTEGER
DIM x AS INTEGER, y AS INTEGER
DIM RepeatPix AS INTEGER, PCXpixel AS INTEGER, DoLne AS INTEGER
DIM PCXcolors(0 TO 255) AS INTEGER
DIM TheFile AS QFILESTREAM
DIM OpenDialog AS QOPENDIALOG
OpenDialog.CAPTION = "Open PCX graphics file"
OpenDialog.Filename = ""
OpenDialog.Filter = "PCX Files (*.PCX)|*.PCX"
OpenDialog.FilterIndex = 1
IF OpenDialog.EXECUTE THEN
TheFileName = OpenDialog.FileName
IF FILEEXISTS(TheFileName)<> True THEN
SHOWMESSAGE "File " + TheFileName + " doesn't exist"
EXIT SUB
END IF
ELSE
EXIT SUB
END IF
Form.CAPTION="PCX Viewer" + TheFileName
Form.Cursor = crHourGlass
TheFile.OPEN(TheFileName,fmOpenRead)
TheFile.position = TheFile.size - 768
FOR i=0 TO 255
r = TheFile.readnum(1)
g = TheFile.readnum(1)
b = TheFile.readnum(1)
PCXColors(i)=RGB(r,g,b)
NEXT i
TheFile.position = 0
TheFile.ReadUDT(PCX)
xsize = PCX.xmax - PCX.xmin + 1
ysize = PCX.ymax - PCX.ymin + 1
totalbytes = ASC(PCX.nplanes) * PCX.bytesperline
field.height = ysize
field.width = xsize
form.height = ysize + 60
form.width = xsize + 20
x=0
y=0
DO
PCXpixel = TheFile.readnum(1)
IF PCXpixel <192 THEN
IF x < xsize THEN INC x
IF x = xsize THEN x = 0 : INC y
field.pset(x,y,PCXColors(PCXpixel))
END IF
IF PCXpixel >192 AND PCXpixel <= 255 THEN
Dolne = PCXpixel - 192
RepeatPix = TheFile.readnum(1)
DEC Dolne
FOR i = DoLne TO 0 STEP -1
IF x < xsize THEN INC x
IF x = xsize THEN x = 0 : INC y
field.pset(x, y ,PCXColors(RepeatPix))
NEXT i
END IF
LOOP UNTIL y =ysize
TheFile.CLOSE
Form.Cursor = crDefault
formPaint
END SUB
SUB ExitApp
Application.Terminate
END SUB
|