handle& = _NewImage(800, 600, 32)
Screen handle&
Dim palentry As String * 3
Dim rgbpalette(256) As Long
Dim dat As String * 1
Open "c:\shu01.pcx" For Binary As #1
header$ = Space$(128)
Get #1, , header$: Cls
bitsper = Asc(Mid$(header$, 4, 1))
plane = Asc(Mid$(header$, 66, 1))
Seek #1, &H81
c = 1: sum = 1: j% = 1
Do
Get #1, , dat
Select Case Asc(dat)
Case Is < 192
mqh(c, j) = Asc(dat)
c = c + 1
sum = sum + 1
If c = scanline + 1 Then
j% = j% + 1
If j% = YRes + 1 Then Exit Do
c = 1
End If
Case Is > 192 And Asc(dat) <= 255
lps = Asc(dat) - 192
Seek #1, 129 + sum
Get #1, , dat
For a = 1 To lps
mqh(c, j%) = Asc(dat)
c = c + 1
If c = scanline + 1 Then
j% = j% + 1
If j% = YRes + 1 Then Exit Do
c = 1
End If
Next a
sum = sum + 2
End Select
Loop
For i% = 1 To YRes
For j% = 1 To XRes
PSet (j%, i%), rgbpalette&(mqh(j%, i%))
Next j%, i%
Close #1
End If
I would convert the PCX Palette to RGBA values and store them in an array. Then just use the Color Indx value's as an index into the RGBA array to display the image properly in 24/32 bit color mode.
I wrote this a long time ago when the pcx loader was not a thing in QB64-PE. It's a lot slower than QB64-PE's builtin loader but it should work with most 8bpp and 24bpp pcx files.
' Loads a 256 color (8-bit) or true color (24-bit) PCX image to a QB64 32-bit image buffer FUNCTIONLoadPCX& (filename ASSTRING) ' By default we assume a failure LoadPCX& = -1
' Read RLE encoded PCX data IF colorPlanes = 1THEN ' 256 color (8-bit) PCX file FOR y = 0TO pcxSizeY - 1
x = 0 WHILE x < bytesPerLine
ch = ASC(INPUT$(1, fileHandle)) IF (ch AND&HC0) = &HC0THEN
c = ch AND&H3F
ch = ASC(INPUT$(1, fileHandle)) ELSE
c = 1 END IF WHILE c > 0 IF x < pcxSizeX THEN img8(x, y) = ch
x = x + 1
c = c - 1 WEND WEND NEXT
07-05-2024, 01:39 PM (This post was last modified: 07-05-2024, 01:39 PM by SMcNeill.)
(07-05-2024, 01:13 PM)macalwen Wrote: I found the reason why the previous mqh(c,j) should be mqh(c,j%), causing this part of the data to be all 0. Thank you for your replies.
Is there some reason why you can't just use _LoadImage for this? Just curious.