Search code examples
pythonpython-3.xkivytifflibtiff

Python: TIFFReadDirectory warning: unknown field with tag


problem
I am able to load pictures with the Image() module in kivy. This is how I was able to install kivy so that I could view TIFF files. But now every time I load a TIFF image, I get several popup warnings one after another, interrupting the program.

TIFFReadDirectory warning:
unknown field with tag 18246 (0x4746)
TIFFReadDirectory warning:
unknown field with tag 18249 (0x4749)
TIFFReadDirectory warning:
unknown field with tag 20752 (0x5110)
TIFFReadDirectory warning:
unknown field with tag 20753 (0x5111)
TIFFReadDirectory warning:
unknown field with tag 20754 (0x5112)
TIFFReadDirectory warning:
unknown field with tag 40092 (0x9c9c)
TIFFReadDirectory warning:
unknown field with tag 40093 (0x9c9d)
TIFFReadDirectory warning:
unknown field with tag 40094 (0x9c9e)

To clarify, none of these warning appear in the python log. These are all separate warning boxes that appear before my program displays a TIFF file. I hear a library called libtiff tends to cause this issue.

code

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.uix.image import Image

class ContainerBox(BoxLayout):
    def __init__(self, **kwargs):
        super(ContainerBox, self).__init__(**kwargs)
        self.orientation = 'vertical'
        self.picture = Image(allow_stretch=True, source='..\pics\snorlax.tif')
        Clock.schedule_once(lambda dt: self.add_widget(self.picture), timeout=0.1)


class SimpleImage(App):
    def build(self):
        return ContainerBox()

if __name__ == '__main__':
    SimpleImage().run()

technical details

  • The images can be downloaded here.
  • I've modified the exif data of this file. It's possible I added a couple of nonstandard tags into the file. But I've done the same thing with jpg files and png files. Those haven't caused annoying popups like this.
  • I am using Kivy version 1.11.1
  • According to Anaconda, the virtual environment is running Python 3.5.6
  • I am running this via PyCharm on Windows 7
  • These are the details from the python log:
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.1.12
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.1.22
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "C:\Users\H\venvs\env1\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\H\venvs\env1\Scripts\python.exe"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] [Loader      ] using a thread pool of 2 workers
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'4.0.0 - Build 9.18.10.3204'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) HD Graphics 4600'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 0
[INFO   ] [GL          ] Shading version <b'4.00 - Build 9.18.10.3204'>
[INFO   ] [GL          ] Texture max size <8192>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider

my question to you
Is it possible to suppress these warnings? I think they're being generated by some library kivy is calling. It might even be precompiled code that I can't edit.
I spent a very long time making a complex user interface with Kivy. And I really don't want to throw all of that work away. But I might be willing to migrate it to c++ where I could theoretically control more of the code. Is that necessary or even possible?


Solution

  • At the beginning of my script, I added

    import ctypes
    
    libbytiff = ctypes.CDLL("libtiff-5.dll")
    libbytiff.TIFFSetWarningHandler.argtypes = [ctypes.c_void_p]
    libbytiff.TIFFSetWarningHandler.restype = ctypes.c_void_p
    libbytiff.TIFFSetWarningHandler(None)
    

    and the warnings stopped.