Skip to content

Commit a1b3e22

Browse files
committed
XBM images: wrap up import support
Relates to #544. Thank you to @manfromarce for catching and reporting. PhotoDemon can now load XBM (X BitMap) image files without crashing. Rather than lean on the 3rd-party FreeImage library for this format (because it crashes on XBM images for reasons unknown), I wrote my own XBM importer. The format is ancient but relatively simple, and PD now covers it comprehensively. I do not have plans to add export capabilities for the XBM format, but can revisit if users complain.
1 parent 611c435 commit a1b3e22

File tree

7 files changed

+296
-47
lines changed

7 files changed

+296
-47
lines changed

Classes/pdPSDLayer.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,8 +2411,7 @@ Private Function ExpandMonochrome(ByRef srcChannel As PSD_ChannelInfo, ByVal num
24112411
Dim numPixelsProcessed As Long
24122412

24132413
'There's not a performance-friendly way to mask flags in VB, so let's just use a byte array for clarity
2414-
Dim bitFlags() As Byte
2415-
ReDim bitFlags(0 To 7) As Byte
2414+
Dim bitFlags(0 To 7) As Byte
24162415
bitFlags(0) = 128
24172416
bitFlags(1) = 64
24182417
bitFlags(2) = 32

Classes/pdXBM.cls

Lines changed: 286 additions & 31 deletions
Large diffs are not rendered by default.

Modules/ImageFormats.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Attribute VB_Name = "ImageFormats"
33
'PhotoDemon Image Format Manager
44
'Copyright 2012-2024 by Tanner Helland
55
'Created: 18/November/12
6-
'Last updated: 23/February/24
7-
'Last update: wire up PDF import
6+
'Last updated: 18/March/24
7+
'Last update: wire up XBM import
88
'
99
'This module determines run-time read/write support for various image formats.
1010
'

Modules/ImageLoader.bas

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Attribute VB_Name = "ImageImporter"
33
'Low-level image import interfaces
44
'Copyright 2001-2024 by Tanner Helland
55
'Created: 4/15/01
6-
'Last updated: 27/February/24
7-
'Last update: initial build of PDF import
6+
'Last updated: 18/March/24
7+
'Last update: initial build of XBM import
88
'
99
'This module provides low-level "import" functionality for importing image files into PD.
1010
' You will not generally want to interface with this module directly; instead, rely on the
@@ -2114,12 +2114,6 @@ Private Function LoadXBM(ByRef srcFile As String, ByRef dstImage As pdImage, ByR
21142114
'XBM images are always 1-bit
21152115
dstImage.SetOriginalColorDepth 1
21162116

2117-
'Funny quirk: this function has no use for the dstDIB parameter, but if that DIB returns
2118-
' a width/height of zero, the upstream load function will think the load process failed.
2119-
' Because of that, we must initialize the DIB to *something*.
2120-
If (dstDIB Is Nothing) Then Set dstDIB = New pdDIB
2121-
dstDIB.CreateBlank 16, 16, 32, 0
2122-
21232117
'As simple 1-bit icons, XBM files obviously don't support color management!
21242118
dstDIB.SetColorManagementState cms_ProfileConverted
21252119

Modules/Loading.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,8 @@ Private Function GetDecoderName(ByVal srcDecoder As PD_ImageDecoder) As String
872872
GetDecoderName = "libjxl"
873873
Case id_pdfium
874874
GetDecoderName = "pdfium"
875+
Case id_XBMParser
876+
GetDecoderName = "Internal XBM parser"
875877
Case Else
876878
GetDecoderName = "unknown?!"
877879
End Select

Modules/PublicEnumsAndTypes.bas

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ Public Enum PD_ImageDecoder
301301
id_PSDParser
302302
id_PSPParser
303303
id_QOIParser
304+
id_XBMParser
304305
id_XCFParser
305306
id_WIC
306307
id_libavif
@@ -309,15 +310,13 @@ Public Enum PD_ImageDecoder
309310
id_resvg
310311
id_libjxl
311312
id_pdfium
312-
id_XBMParser
313313
End Enum
314314

315315
#If False Then
316316
Private Const id_Failure = -1, id_GDIPlus = 0, id_FreeImage = 0
317317
Private Const id_CBZParser = 0, id_HGTParser = 0, id_ICOParser = 0, id_MBMParser = 0, id_ORAParser = 0, id_PDIParser = 0
318-
Private Const id_PNGParser = 0, id_PSDParser = 0, id_PSPParser = 0, id_QOIParser = 0, id_XCFParser = 0
318+
Private Const id_PNGParser = 0, id_PSDParser = 0, id_PSPParser = 0, id_QOIParser = 0, id_XBMParser = 0, id_XCFParser = 0
319319
Private Const id_WIC = 0, id_libavif = 0, id_CharLS = 0, id_libwebp = 0, id_resvg = 0, id_libjxl = 0, id_pdfium = 0
320-
Private Const id_XBMParser = 0
321320
#End If
322321

323322
'Some UI DIBs are generated at run-time. These DIBs can be requested by using the getRuntimeUIDIB() function.

PhotoDemon.vbp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ Description="PhotoDemon Photo Editor"
525525
CompatibleMode="0"
526526
MajorVer=9
527527
MinorVer=1
528-
RevisionVer=325
528+
RevisionVer=331
529529
AutoIncrementVer=1
530530
ServerSupportFiles=0
531531
VersionComments="Copyright 2000-2024 Tanner Helland - photodemon.org"

0 commit comments

Comments
 (0)