Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use luaffifb to make it work in places other than luajit #9

Closed
jcupitt opened this issue Jun 4, 2017 · 7 comments
Closed

use luaffifb to make it work in places other than luajit #9

jcupitt opened this issue Jun 4, 2017 · 7 comments

Comments

@jcupitt
Copy link
Member

jcupitt commented Jun 4, 2017

See https://github.com/facebook/luaffifb

@rolandlo
Copy link
Collaborator

rolandlo commented May 2, 2023

So should lua-vips work with Lua 5.3 when luaffifb is installed?
I did so and added a replacement for bit.band (bitwise and), which looks like the only thing required from other libraries.
However I get a segmentation fault after a short while:

Lua 5.3.6  Copyright (C) 1994-2020 Lua.org, PUC-Rio
> vips = require "vips"
> vips.Image
table: 0x558ea766a7a0
> im = vips.Image.new_from_file("dog.png")
Speicherzugriffsfehler (Speicherabzug geschrieben)

@jcupitt
Copy link
Member Author

jcupitt commented May 2, 2023

Hi @rolandlo, I think it would need some dev work to make this happen. I've not had time, but if you do, a PR would be great.

@rolandlo
Copy link
Collaborator

Seems I managed to get it working on Lua 5.3.6. At least the example from the Readme works when I rebase my patches onto lua-vips version 1.1.9 (commit 4115e8e).

grafik

The images created (tiny.jpg and x.png) look fine. For this to work I also had to add some changes to Tekenlight's fork of luaffifb.

So far I haven't had time to test further. Without rebasing on version 1.1.9 I get a segfault when executing

image = image = image + {1,2,3}

from the example.

Let me point out that I don't have much experience with Lua and the Lua C API and have not worked with lua-vips before, so most likely my solution can and should be improved a lot.

The code changes are motivated by the following observations:

  • Currently (on master) lua-vips uses unpack which should be table.unpack in Lua 5.3. So I replaced it by unpack or table.unpack
  • Currently lua-vips compares gv.gtype (which is of type cdata) with Lua numbers like gvalue.gbool_type, so I used tonumber to convert gv.gtype into a Lua number
  • Currently luaffifb (both on the Facebook repo and on Tekenlight's fork) doesn't support things like voperation.call (or more generally <ffi-metatype>.<function name>) since the ctype_mt doesn't support the __index metamethod. So I simply added ctype_index by copying the relevant part from cdata_index. That looks a bit hacky, but it works.

@jcupitt
Copy link
Member Author

jcupitt commented May 19, 2023

That's very cool!

Sorry, I have no free time right now :( After July I should have some time to look at this again.

@rolandlo
Copy link
Collaborator

rolandlo commented Aug 5, 2023

A little update: I have used my patched versions of lua-vips and luaffifb to write a Xournal++ plugin, where images in a Xournal++ document can be manipulated in various ways, see xournalpp/xournalpp#4884. It seems to work fine (using Lua 5.3.6 on Ubuntu 23.04).

@rolandlo
Copy link
Collaborator

rolandlo commented Aug 6, 2023

One more update:

  • Rebased on master
  • Fixed some segfaults related to comparing with nil instead of ffi.NULL
  • All examples in the example directory except of array.lua work now. In array.lua,
local ptype = ffi.typeof("typedef unsigned short int[$][?]", im:bands())

results in the error message:

lua: array.lua:14: unknown type typedef on line 1
stack traceback:
	[C]: in function 'ffi.typeof'
	array.lua:14: in main chunk
	[C]: in ?

In watermark.lua I had to replace division / by integer division // in text:replicate (which requires integer arguments)

@rolandlo
Copy link
Collaborator

Fixed by #60.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants