libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
413 stars 36 forks source link

tcod.image_load() is deprecated and yet there's no replacement #87

Closed mgedmin closed 3 years ago

mgedmin commented 5 years ago

Using

import tcod
background = tcod.image_load("background.png")

produces a PendingDeprecationWarning: This function may be deprecated in the future. Consider raising an issue on GitHub if you need this feature.

I was unable to find any replacement for this function. Constructing a new image and setting its data by repeated calls to Image.put_pixel() does not seem reasonable (plus I don't wish to write my own PNG loader).

HexDecimal commented 5 years ago

Libtcod's image object has some dynamic internal stuff which makes it hard to port properly.

Image.put_pixel is not an alternative to tcod.image_load. put_pixel would be deprecated itself if Image had an accessible pixel buffer array. If you need to use an Image object then ignore the warning in tcod.image_load.

The long-term plan is to have functions return and accept NumPy arrays instead of Image.

mgedmin commented 5 years ago

Ah, I wondered why many objects had numpy arrays but not Image.

My goal was to take the TCOD Tutorial code and make it run without warnings with the latest python-tcod. I now see that that is impossible. :(

HexDecimal commented 5 years ago

I've added some new functions in the latest version (11.4.0). With tcod.image.load and Console.draw_semigraphics you should be able to avoid the Image class and the related libtcodpy functions.

HexDecimal commented 3 years ago

I might end up removing all of the image loading code from python-tcod.

Officially I recommend using either Pillow or imageio to load images. These libraries load images as NumPy arrays so it's a minor change from using tcod.image.load.