You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FreeImage identifies images written via PPM-FI as PBM-FI. #677
I found a strange behavior in freeimage. When I write an image using PPM-FI then FreeImage identifies the written file as an image in PBM format instead of PPM format. Here is the snippet to show the failure
I have traced the source code for writing up to the point we hand the image over to FreeImage and confirmed that it is indeed PPM all the way. Later on, we read the file's header and identify the format based on that using fi.getFIF(request.filename, "r", request.firstbytes). This then re-identifies the file as PBM which is treated as incompatible with PPM.
@almarklein I am a bit lost, because I am only loosely familiar with FreeImage. I discovered this while refactoring imopen (more on that in the PR, in short: I want to configure the plugin manager using imageio.config and add lazy-loading of plugins upon first use.) and it would be important here that PPM-FI correctly reports that it can read PPM-FI.
ifrequest._fif==self.fif:
returnTrueelifrequest._fif==7andself.fif==14:
# PPM gets identified as PBM and PPM can read PBM# see: https://github.com/imageio/imageio/issues/677returnTrue
which fixes the symptom. Not sure if we should go more low-level though. Does FreeImage have an issue tracker?
Activity
almarklein commentedon Nov 5, 2021
This is the code path deeper in freeimage. You could see which step eventually sets
ftype. It might be a bug in freeimage.imageio/imageio/plugins/_freeimage.py
Lines 584 to 592 in e1226c7
FirefoxMetzger commentedon Nov 5, 2021
@almarklein This could be indeed inside freeimage. We associate
ftype==14in our wrapper here:imageio/imageio/plugins/freeimage.py
Line 442 in e1226c7
and this is what we eventually pass to freeimage when writing. However when we read the buffer here
imageio/imageio/plugins/_freeimage.py
Lines 587 to 589 in e1226c7
the returned
fytpeis7which we associate with PBM:imageio/imageio/plugins/freeimage.py
Line 433 in e1226c7
almarklein commentedon Nov 5, 2021
We could create a workaround. Something like if
FreeImage_GetFileTypeFromMemoryreturns 7, also check the file extension.FirefoxMetzger commentedon Nov 5, 2021
I'm currently doing this in my feature branch
which fixes the symptom. Not sure if we should go more low-level though. Does FreeImage have an issue tracker?