256 color PCX reader

 BBS: Inland Empire Archive
Date: 11-21-92 (13:56)             Number: 393
From: HARRY GISH                   Refer#: NONE
  To: ALL                           Recvd: NO  
Subj: 256 color PCX reader           Conf: (2) Quik_Bas
"Notes to non-ZBasic types: In ZBasic a label is any quoted string. We're"
"using that here for documentation. Also in ZB source code is case-sensitive,"
"so get used to seeing keywords in uppercase and variables in mixed or lower"
"case. Thus PRINT is a keyword and Print {or even PRINt} is a variable name."

"Size# must be set to actual PCX file size in bytes"
DEFINTA-Z

OPEN"R",2,FileName$,1

"The first 128 bytes in the file are a header. Much of it is unused, or of no"
"practical use. For simplicity we'll cover the important ones only."

READ#2,Header$;128:CLS

"The first position is a PCX 'signature'".

Sig$=LEFT$(Header$,1)
IFSig$<>CHR$(10)PRINT"Invalid PCX file, no ZSoft header found":END

"The next header byte specifies the version. For 256 color it must be 5."

Ver$=MID$(Header$,2,1):Ver=ASC(Ver$)
IFVer<>0ANDVer<>2ANDVer<>3ANDVer<>5PRINT"Invalid version number":END

"The next header byte specifies the color bits. For 256 color it must be 8."

ColorBits$=MID$(Header$,4,1):ColorBits=ASC(ColorBits$)
IFColorBits<>1ANDColorBits<>8PRINT"Invalid number of color bits":END

"The image size is contained in 4 bytes starting at position 9 of the header."

XRes$=MID$(Header$,9,2)
XRes1$=LEFT$(XRes$,1):XRes2$=RIGHT$(XRes$,1)
XRes=ASC(XRes1$)+ASC(XRes2$)*256+1

YRes$=MID$(Header$,11,2)
YRes1$=LEFT$(YRes$,1):YRes2$=RIGHT$(YRes$,1)
YRes=ASC(YRes1$)+ASC(YRes2$)*256+1

"256 Color PCX"

Bytes#=128
Pointer=0

"The palette information (definitions of the 256 colors) is contained in the"
"last 768 bytes of the file. There is a 'leading check-byte' of 0C (hex)"
"preceding it. Here we're positioning to that check-byte."

RECORD#2,Size#-769
READ#2,A$;1

"Now we read the next 768 bytes {256 x 3 for Red, Green and Blue definitions"
"respectively}. Current paletting for PCX requires division by 4. If there is"
"a 'true-color' PCX format {and there may be and I don't know about it} I'd"
"expect it to simply drop the division by 4 and make it the actual number."
"ZBasic-PC/386 allows simple 256 color setting with one advanced palette"
"command DEF COLOR, where the format is DEF COLOR color to define, red level,"
"green level and blue levels of intensity."

FORX=0TO255
READ#2,A$;1:R=ASC(A$):READ#2,A$;1:G=ASC(A$):READ#2,A$;1:B=ASC(A$)
DEFCOLORX,R/4,G/4,B/4
NEXT


--- Maximus/2 2.01wb
 * Origin: ACCESS BBS (1:124/2122)
Outer Court
Echo Basic Postings

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