AndyQ / NFCPassportReader

NFCPassportReader for iOS 13
MIT License
733 stars 235 forks source link

Some Portuguese and Spanish passports will not have image from DG2 #218

Closed rbrouwer closed 2 months ago

rbrouwer commented 3 months ago

The images in Portuguese and Spanish passports have images encode in JPEG2000 format with JPEG2000 features (Guessing because it is a JPEG2000 codestream) that iOS does not support.

Therefore: https://github.com/AndyQ/NFCPassportReader/blob/306eac9e0de491128f7d8d595cc10ca114acea88/Sources/NFCPassportReader/DataGroups/DataGroup2.swift#L46 and https://github.com/AndyQ/NFCPassportReader/blob/306eac9e0de491128f7d8d595cc10ca114acea88/Sources/NFCPassportReader/DataGroups/DataGroup7.swift#L30

will return nil, because UIImage is unable the decode the imagedata which is correctly read by the library.

Workaround would be to integrate libopenjp2 (or any other jpeg2000 lib) to decode/transcode the image into something UIImage would understand or hope iOS would complete their JPEG2000 integration within iOS/MacOS.

AndyQ commented 2 months ago

I did have a little look at JPEG2000, but at the moment, its not something I'm going to add support for (unless for some reason it suddenly become really popular) as it seems to be really uncommon - I haven't yet seen one. However, I do provide access to the raw image data so you could add support if it was really important for you.

rbrouwer commented 2 months ago

It was more of a documentation case. I already have an extension for NfcPassportModel giving me a UIImage in those cases.

Although I am not fully certain, I am fairly certain images, which start with jpeg2000CodestreamBitmapHeader, will very likely not work using that case. All you could consider is to handle (UnsupportedImageFormat error or such) and/or document it. That way other devs will not have to dig as deep to figure out why that specific document does properly have DG 2, but not have any image show up.

AndyQ commented 2 months ago

Thanks for the comment - I'll add this to the docs!