BBS: Inland Empire Archive Date: 03-02-94 (00:16) Number: 377 From: PETER MIKALAJUNAS Refer#: NONE To: JEFFREY ZAPATKA Recvd: NO Subj: .PCX 1/2 Conf: (2) Quik_Bas
JZ>Can Anyone help me with a routinie or file to give an
JZ>example on how I'd JZ>begin (or do it) to view a .PCX file
JZ>in my QuickBASIC Program? JZ> - Jeffrey
JZ>Zapatka
' Date: Mon 10-18-93 From: FRANCOIS ROY To: PETER MIKALAJUNAS
' Subject: Re: Using PCX images
' This code was posted via Fido Basic7 echo to me
' I have no idea if the author is or is not Francois Roy
' nor do I know if it is public domain, but I assume so.
' I might also add, that I recently saw the code to read a
PCX file ' posted in C. It has some very good comments and
explains quite a bit ' about the PCX format. I will try
and grab just the comments and post ' them separately. In
the meantime, this should get you going.
DECLARE SUB SetPalette (pcxpal$)
DECLARE SUB SelectScreen ()
DECLARE SUB ReadPcxLine (PcxFile%, TotalBytes%, ScanLine%())
DECLARE SUB ReadPcxByte (PcxFile%, value%)
DECLARE SUB OpenPcxFile (PcxName$, xsize%, ysize%,
TotalBytes%, pcxpal$) DECLARE SUB ShowPcx (PcxName$)
DEFINT A-Z
TYPE PCXHeaderStruc
Manufacxturer AS STRING * 1
Version AS STRING * 1
Encoding AS STRING * 1
BitsPerPixel AS STRING * 1
xmin AS INTEGER
ymin AS INTEGER
xmax AS INTEGER
ymax AS INTEGER
Hres AS INTEGER
Vres AS INTEGER
ColorMap AS STRING * 48
Reserved1 AS STRING * 1
NumPlanes AS STRING * 1
BytesPerLine AS INTEGER
PaletteType AS INTEGER
HScrSize AS INTEGER
VScrSize AS INTEGER
Resreved2 AS STRING * 54
END TYPE
DIM SHARED PCXheader AS PCXHeaderStruc
DIM SHARED PcxFile
DIM SHARED ScrMode, ScrMaxX, ScrMaxY
DIM SHARED ScrMaxColor, ScrBitsPerPixel
DIM SHARED Byte AS STRING * 1
DIM SHARED MaxScrMode
SCREEN 0
Cm$ = COMMAND$
IF Cm$ = "" THEN
PRINT "Please enter the complete name of the pcx file"
END
END IF
CALL ShowPcx(Cm$)
NoVGA:
MaxScrMode = 9
' the following section was not part of the original post
SCREEN 0
Version = ASC(PCXheader.Version)
plan = ASC(PCXheader.NumPlanes)
xsize = PCXheader.xmax - PCXheader.xmin + 1
ysize = PCXheader.ymax - PCXheader.ymin + 1
' there appears to be a bug somewhere in this source code
' it sometimes incorrectly identifies the size and the planes
' also it does not always correctly display the palette
' however it does work, so it is a good starting point
' that is why I added this section to the original post.
PRINT "info retrieved"
PRINT "PCX_Version"; Version
PRINT "Planes"; plan
PRINT "Xsize"; xsize
PRINT "Ysize"; ysize
SUB OpenPcxFile (PcxName$, xsize, ysize, TotalBytes, pcxpal$)
PcxFile = FREEFILE
OPEN PcxName$ FOR BINARY AS #PcxFile
GET #PcxFile, 1, PCXheader
pcxpal$ = LEFT$(PCXheader.ColorMap + STRING$(768, 0), 768)
IF ASC(PCXheader.Version) = 5 THEN
SEEK #PcxFile, LOF(PcxFile) - 768&
GET #PcxFile, , Byte
IF ASC(Byte) = 12 THEN GET #PcxFile, , pcxpal$
END IF
xsize = PCXheader.xmax - PCXheader.xmin + 1
ysize = PCXheader.ymax - PCXheader.ymin + 1
TotalBytes = ASC(PCXheader.NumPlanes) * PCXheader.BytesPerLine
END SUB
SUB ReadPcxByte (PcxFile, value)
STATIC count, CountValue, BufferLOC, Buffer$
IF count > 0 THEN
value = CountValue
count = count - 1
ELSE
IF BufferLOC > LEN(Buffer$) OR LEN(Buffer$) = 0 THEN
BufferLEN& = LOF(PcxFile) - LOC(PcxFile)
IF BufferLEN& > 15000 THEN
BufferLEN& = 15000
END IF
IF BufferLEN& <= 0 OR EOF(PcxFile) THEN
EXIT SUB
END IF
Buffer$ = SPACE$(BufferLEN&)
GET #PcxFile, , Buffer$
BufferLOC = 1
END IF
value = ASC(MID$(Buffer$, BufferLOC, 1))
BufferLOC = BufferLOC + 1
IF value >= 192 THEN
count = value - 193
IF BufferLOC >= LEN(Buffer$) THEN
BufferLEN& = LOF(PcxFile) - LOC(PcxFile)
IF BufferLEN& > 15000 THEN
BufferLEN& = 15000
END IF
IF BufferLEN& <= 0 OR EOF(PcxFile) THEN
EXIT SUB
END IF
Buffer$ = SPACE$(BufferLEN&)
GET #PcxFile, , Buffer$
BufferLOC = 1
END IF
CountValue = ASC(MID$(Buffer$, BufferLOC, 1))
BufferLOC = BufferLOC + 1
value = CountValue
END IF
END IF
END SUB
SUB ReadPcxLine (PcxFile, TotalBytes, ScanLine())
zero$ = CHR$(0)
index = LBOUND(ScanLine) + 2
count = 0
DO
ReadPcxByte PcxFile, pixels
ScanLine(index) = pixels
IF count = TotalBytes THEN EXIT DO
ReadPcxByte PcxFile, pixels
ScanLine(index) = ScanLine(index) + CVI(zero$ + CHR$(pixels))
count = count + 2
index = index + 1
LOOP WHILE count < TotalBytes
END SUB
>>> Continued to next message
* SLMR 2.1a * Back Up My Hard Drive? I Can't Find The Reverse Switch!
--- GEcho 1.00
* Origin: The Hideaway BBS 708.748.1911 HST/V32bis (1:115/748)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET