Loading .GIF and .PCX

 BBS: Inland Empire Archive
Date: 12-13-92 (18:57)             Number: 386
From: PETER BARNEY                 Refer#: NONE
  To: CRUZ MONCIVAIS                Recvd: NO  
Subj: Loading .GIF and .PCX          Conf: (2) Quik_Bas
 >  PB> Your reply chain got tangled.  You should've sent the reply to Harry
 >  PB> Gish. He did post some code for 256-pcx though.  Did you get it?

 >  No I did not get that code?   Is it possible to re-post?

I don't have the EXACT original code (it was written in
ZBASIC, I converted to QB), hope you don't mind Harry.

'(1127)  Sat 21 Nov 92  1:56p
'By: Harry Gish
'To: All
'Re: 256 color PCX reader
'St:
'
DEFINT A-Z SCREEN 13 FileName$ = "256COLOR.PCX" 'fill in the blank OPEN FileName$ FOR BINARY AS #2 LEN = 11 'Size# must be set to actual PCX file size in bytes Size# = LOF(2) '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. header$ = SPACE$(128) GET #2, , header$: CLS 'The first position is a PCX 'signature'. Sig$ = LEFT$(header$, 1) IF Sig$ <> CHR$(10) THEN 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$) IF Ver <> 0 AND Ver <> 2 AND Ver <> 3 AND Ver <> 5 THEN PRINT "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$) IF ColorBits <> 1 AND ColorBits <> 8 THEN PRINT "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. SEEK #2, Size# - 769 a$ = " " GET #2, , a$ '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. FOR X = 0 TO 255 a$ = " " GET #2, , a$ R = (ASC(MID$(a$, 1, 1)) / 4) AND 63 G = (ASC(MID$(a$, 2, 1)) / 4) AND 63 B = (ASC(MID$(a$, 3, 1)) / 4) AND 63 PALETTE X, R + G * 256 + B * 65536 NEXT 'Now we position at the 128th byte, 'which is where the data begins. SEEK #2, 128 'Read a byte DecodeGroup: X$ = " " IF EOF(2) THEN GOTO done GET #2, , X$: X = ASC(X$): Bytes# = Bytes# + 1 'Now we must see if the byte represents a single color 'value or if it is a multiplier value. A quirk of 256 'COLOR PCX's is that a single value of the top 64 colors 'must be encoded as a multiplier of 1 times the color. 'You can't say COLOR 255, you must say 1 times 255. This 'makes many 256 color PCX files actually larger than a 'simple value dump. In this case if the byte value is 'less than 193 then it is an actual value. 'LONGIF ? - Harry, what the heck does LONGIF mean? IF X < 193 THEN PSET (Pointer, LineNo), X Pointer = Pointer + 1 END IF 'Otherwise we interpret it as a multiplier. 'Multiplier value can be as large as 63. 'LONGIF ? - again? IF X > 192 THEN X = X - 192: X$ = " " GET #2, , X$: y = ASC(X$): Bytes# = Bytes# + 1 LINE (Pointer, LineNo)-(Pointer + X - 1, LineNo), y Pointer = Pointer + X END IF 'Pointer notes the current position in the X line scan. 'When the line is done Pointer gets reset to zero. IF Pointer < XRes GOTO DecodeGroup Pointer = 0 'If we're at end of line now we need to see if all lines are decoded. 'If so we end, otherwise we start processing the next line. IF LineNo = YRes GOTO done LineNo = LineNo + 1 GOTO DecodeGroup done: BEEP WHILE INKEY$ = "": WEND SCREEN 2, 1: SCREEN 0, 0: COLOR 15, 1, 4: CLS : END --- FMail 0.92
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