UNLESS YOU WOULD LIKE TO READ ON, OTHERWISE THE THREAD IS CLOSED AS i HAVE MEANWHILE SOLVED THE PROBLEM ALREADY -- SEE "EDITED" AT BOTTOM PART OF THIS POSTING.
This thread is created with the prompt of La Volpe in Posting #41 at
http://www.vbforums.com/showthread.p...ght=PCX&page=2
Attached 2 zips contain 24bpp.pcx and 8bpp.pcx respectively, both RLE-compressed.
24bpp.pcx appears to display okay on IrfanView, FreeImage and PhotoShop7. (Remarks: This one happens to be so, other tests had shown it might not always be the case on PhotoShop7)
However, for 8bpp.pcx there is a difference between the display by IrfanView on one hand and that by FreeImage/PhotoShop7 on the other (see images shown below).
Any possible explanation? Likely an error in RLE subroutine?
Appended below is the RLE subroutine used. Please note that PCX files produced by using this subroutine are always displayed perfectly okay on IrfanView, but not so on FreeImage/PhotoShop7 (as said above).
Code:Private Function CompressPCX(inArr() As Byte, inScanW As Long) As Boolean
Dim arrNew() As Byte
Dim x As Long
Dim K As Long
Dim newPos As Long
Dim mPos As Long
Dim LineCtn As Long
On Error GoTo errHandler
If inScanW Mod 2 <> 0 Then Exit Function 'PCX scanline must be an even number
'Temporarily provide a tentative new array, will adj at the end.
'Notes: (a) If a file dosen't have many "runs", RLE could augment the data size by as much as twice.
'(b) To gain a smaller size, arrange more frequently used colors in early part in palette sequence.
ReDim arrNew(UBound(inArr) * 2)
Do While x <= UBound(inArr)
If x + 1 <= UBound(inArr) Then
Do Until inArr(x) <> inArr(x + 1)
If x + 1 > UBound(inArr) Then Exit Do
'Scanline break reached, exit to handle
If x + 1 > (inScanW * LineCtn) Then Exit Do
'Max of 63 reached? (Max run length in PCX is 63. K is 0-based)
If K = 62 Then Exit Do
x = x + 1
K = K + 1
Loop
End If
If inArr(x) >= 192 Or K > 0 Then
'Since K is limited to max of 62, 193+62 would not execeed 255.
arrNew(newPos) = 193 + K
arrNew(newPos + 1) = inArr(x)
mPos = newPos + 1
newPos = newPos + 2
Else
'If color < 192, then input value directly in a single byte
arrNew(newPos) = inArr(x)
mPos = newPos
newPos = newPos + 1
End If
'Scanline break
If x + 1 = (inScanW * LineCtn) Then
arrNew(newPos) = 0
mPos = newPos
newPos = newPos + 1
LineCtn = LineCtn + 1
End If
If mPos >= UBound(arrNew) Then
GoTo errHandler
End If
K = 0 'Renew max run length counter k, 0-based here
x = x + 1 'Increment byte pointer x
Loop
If mPos > 1 Then
ReDim inArr(mPos)
CopyMemory inArr(0), arrNew(0), mPos + 1
CompressPCX = True
End If
Erase arrNew
Exit Function
errHandler:
End Function
Edited: The whole trouble turns out to be just a typo! By changing "If (x + 1) = UBound(inArr) Then Exit Do" to "If (x + 1) > UBound(inArr) Then Exit Do", the image is displayed alright on FreeImage and PhotoShop7 now.
Tested all okay on AZ Paint Pro, IrfanView, FreeImage and PhotoShop.
.

