Skip failing records when rendering WMF images#8506
Skip failing records when rendering WMF images#8506hugovk merged 6 commits intopython-pillow:mainfrom
Conversation
|
Great! As mentioned in the ticket, the C# .NET implementation also uses such record-by-record API's internally and allows the files to be handled, so I wouldn't hesitate to do the same. Also programs like Windows Paint and IrfanView allow the files to be opened without error.👍 |
ee84978 to
e4087f9
Compare
|
It turns out my initial commit didn't work on 32-bit Windows - https://ci.appveyor.com/project/Python-pillow/pillow/builds/50869937/job/3jd42o23cjses7ms#L3048
I've pushed a commit to only use the new behaviour on 64-bit. @petsuter is that sufficient to resolve your issue? Or would you like to see this work on 32-bit as well? |
|
I don't know of any 32-bit Python usage anymore, thanks. (Could it be the return value should be int not BOOL? https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nc-wingdi-enhmfenumproc) |
|
Thanks. No, changing it to
|
src/display.c
Outdated
|
|
||
| BOOL | ||
| enhMetaFileProc( | ||
| HDC hdc, HANDLETABLE FAR *lpht, const ENHMETARECORD *lpmr, int nHandles, LPARAM data |
There was a problem hiding this comment.
Good question. Ok, I've updated the code to match https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nc-wingdi-enhmfenumproc
e4087f9 to
b4ba466
Compare
Skip failing WMF records on 32-bit Windows
Resolves #6980
The issue would like Pillow to be more lenient when rendering invalid EMF files. The API that raises the error is relatively simple
Pillow/src/display.c
Lines 799 to 800 in 81a3bf5
so I asked about it at https://learn.microsoft.com/en-us/answers/questions/2100252/playenhmetafile-fails-without-any-getlasterror-res, and the answer showed that
PlayEnhMetaFileRecordcan be used to render the image gradually, skipping failing records.