1

I wrote a little program using lua LÖVE. Now I would like to make it read some TIFF files, since LÖVE does not support this image format. And I failed.

Basically, LÖVE can read the file from some userdata. I thought that I might read the data with another library and convert it internally to a format that LÖVE supports, but can't find anything suitable. I looked at graphicsmagick lua bindings, but unfortunately it does not appear to be up to date. I tried to get it too run, but gave up after a while; I would probably have to rewrite the whole package and I can't even find some of the modules it uses (for example the "sys" module).

EDIT: Some more background. I need a fast image viewer to quickly browse through files on the disk. I do not like to use the file manager for that purpose, and I would like it to behave exactly as I want it to behave. I was using xzgv for this purpose for years.

When I discovered lua and LÖVE, I decided to write one both as an exercise and because I want to have a little tool like that (you can see how it looks like here).

Aiq0
  • 306
  • 1
  • 11
January
  • 16,320
  • 6
  • 52
  • 74
  • 1
    If you have ffmpeg than you can do from LÖVE: ```os.execute('ffmpeg -i CYI1f.tiff CYI1f.png')``` - But this works only if the game is not zipped. – koyaanisqatsi Nov 16 '22 at 15:22
  • 1
    I don't understand what you are doing but you can easily convert TIFF images to PNG, or GIF, or NetPBM with **ImageMagick** in your Terminal with `magick INPUT.TIF OUTPUT.PNG` for example. – Mark Setchell Nov 17 '22 at 16:28
  • 1
    Sure, I could convert the files on the command line and read the converted file. What I am doing, however, is a fast image viewer (for my own purposes) and reading + writing + reading the file again is much slower than reading and then converting in memory to a format that LÖVE understands. – January Nov 17 '22 at 18:32
  • Ok, I see. Cool - and good luck. – Mark Setchell Nov 17 '22 at 18:35
  • Hah, but you were right, actually! I can simply read the file with Imagemagick but instead of saving the file redirect it to stdout and read the data directly! Thank you! – January Nov 17 '22 at 18:42
  • Cool. Just FYI, you can force a given filetype on `stdout` with **ImageMagick** like this `magick INPUT.TIF JPEG:-` for JPEG output, or `magick INPUT.TIF PNG32:-` for RGBA8888 PNG output or `magick INPUT.TIF PNG8:-` for palette (indexed) PNG output. And plenty more... – Mark Setchell Nov 17 '22 at 19:52
  • Yeah, I know, been using Imagemagick many years already ;-) I already implemented it and it works. The only problem I have now is that RAW files don't work: the imagemagick compiled for Ubuntu tries to use `ufraw-batch` and `ufraw` is no longer distributed with Ubuntu. But that is another problem entirely... Also, feel free to formulate the above as an answer, I will accept it. – January Nov 17 '22 at 20:10
  • This may help https://stackoverflow.com/a/57712079/2836621 – Mark Setchell Nov 17 '22 at 20:13
  • 1
    Sorry, I can't make an answer - that's why I just commented. I know very little about Lua and have no idea how to *"shell out"* to **ImageMagick** with some type of `system()` call and even less idea about how to capture the output of the spawned process, so I'll have to leave it up to you to enlighten me and others. – Mark Setchell Nov 17 '22 at 20:52

1 Answers1

1

Here is a solution which does not requires any libraries. Basically, the idea is that you convert an image using the convert program from the ImageMagick suite and pipe its output to a filehandle with io.popen. That way the file is read only once from the storage.

local cmd = "/usr/bin/convert %s -format JPG:-"
local file = "test.tiff"

local fh = io.popen(cmd:format(file), "r")
local fdata = fh:read("*a") -- read all
fh:close()

fdata = love.filesystem.newFileData(fdata, file)
local img = love.graphics.newImage(fdata)
January
  • 16,320
  • 6
  • 52
  • 74