Error displaying 256 color PCX image program? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Error displaying 256 color PCX image program? (/showthread.php?tid=2849) |
Error displaying 256 color PCX image program? - macalwen - 07-04-2024 Code: (Select All)
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)) 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 Dim mqh(800, 800) As Integer scanline$ = Mid$(header$, 67, 2) scanline1$ = Left$(scanline$, 1): scanline2$ = Right$(scanline$, 1) scanline = Asc(scanline1$) + Asc(scanline2$) * 256 If plane = 1 And bitsper = 8 Then Seek #1, LOF(1) - 767 For i% = 0 To 255 Get #1, , palentry$ R& = Asc(Mid$(palentry$, 1, 1)) G& = Asc(Mid$(palentry$, 2, 1)) B& = Asc(Mid$(palentry$, 3, 1)) rgbpalette&(i%) = _RGB(R&, G&, B&) Next i% 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 RE: Error displaying 256 color PCX image program? - bplus - 07-04-2024 try 256 for _newimage instead of 32 bit color pallet RE: Error displaying 256 color PCX image program? - ahenry3068 - 07-04-2024 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. RE: Error displaying 256 color PCX image program? - SMcNeill - 07-04-2024 This is all it takes to work for me: Code: (Select All)
RE: Error displaying 256 color PCX image program? - TerryRitchie - 07-04-2024 (07-04-2024, 03:40 PM)SMcNeill Wrote: This is all it takes to work for me:I was thinking the same thing. RE: Error displaying 256 color PCX image program? - a740g - 07-04-2024 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. Code: (Select All)
RE: Error displaying 256 color PCX image program? - Pete - 07-04-2024 I ran it using SCREEN 0 and got far better object resolution... -------------- | ^^-^-^^ | | O O O | | ][ ][ ][ | -------------- Pete RE: Error displaying 256 color PCX image program? - macalwen - 07-05-2024 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. RE: Error displaying 256 color PCX image program? - SMcNeill - 07-05-2024 (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. |