forked from libvips/lua-vips
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests are still missing. It works with luajit, but produces slightly wrong images with Lua 5.2, 5.3 and crashes with Lua 5.4
- Loading branch information
Showing
9 changed files
with
245 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- abstract base Connection class | ||
|
||
local ffi = require "ffi" | ||
|
||
local vobject = require "vips.vobject" | ||
|
||
local vips_lib = ffi.load(ffi.os == "Windows" and "libvips-42.dll" or "vips") | ||
|
||
local Connection = {} | ||
|
||
Connection.vobject = function(self) | ||
return ffi.cast(vobject.typeof, self) | ||
end | ||
|
||
Connection.new = function(self) | ||
return vobject.new(self) | ||
end | ||
Connection.filename = function(self) | ||
-- Get the filename asscoiated with a connection. Return nil if there is no associated file. | ||
local so = ffi.cast('VipsConnection *', self.pointer) | ||
local filename = vips_lib.vips_connection_filename(so) | ||
if filename == ffi.NULL then | ||
return nil | ||
else | ||
return ffi.string(filename) | ||
end | ||
end | ||
|
||
Connection.nick = function(self) | ||
-- Make a human-readable name for a connection suitable for error messages. | ||
|
||
local so = ffi.cast('VipsConnection *', self.pointer) | ||
local nick = vips_lib.vips_connection_nick(so) | ||
if nick == ffi.NULL then | ||
return nil | ||
else | ||
return ffi.string(nick) | ||
end | ||
end | ||
|
||
return ffi.metatype("VipsConnection", { | ||
__index = Connection | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- An input connection | ||
|
||
local ffi = require "ffi" | ||
|
||
local verror = require "vips.verror" | ||
local vobject = require "vips.vobject" | ||
local Connection = require "vips.Connection" | ||
|
||
local vips_lib = ffi.load(ffi.os == "Windows" and "libvips-42.dll" or "vips") | ||
|
||
local Source = {} | ||
|
||
Source.vobject = function(self) | ||
return ffi.cast(vobject.typeof, self) | ||
end | ||
|
||
Source.new_from_descriptor = function(descriptor) | ||
local source = vips_lib.vips_source_new_from_descriptor(descriptor) | ||
if source == ffi.NULL then | ||
error("Can't create source from descriptor " .. descriptor .. "\n" .. verror.get()) | ||
end | ||
|
||
return Connection.new(source) | ||
end | ||
|
||
Source.new_from_file = function(filename) | ||
local source = vips_lib.vips_source_new_from_file(filename) | ||
if source == ffi.NULL then | ||
error("Can't create source from filename " .. filename .. "\n" .. verror.get()) | ||
end | ||
|
||
return Connection.new(source) | ||
end | ||
|
||
Source.new_from_memory = function(data) -- data is an FFI memory array formatted as a C-style array | ||
local source = vips_lib.vips_source_new_from_memory(data, ffi.sizeof(data)) | ||
if source == ffi.NULL then | ||
error("Can't create input source from memory \n" .. verror.get()) | ||
end | ||
|
||
return Connection.new(source) | ||
end | ||
|
||
return ffi.metatype("VipsSource", { | ||
__index = Source | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-- An input connection | ||
|
||
local ffi = require "ffi" | ||
|
||
local vobject = require "vips.vobject" | ||
local Connection = require "vips.Connection" | ||
|
||
local vips_lib = ffi.load(ffi.os == "Windows" and "libvips-42.dll" or "vips") | ||
|
||
local Target = {} | ||
|
||
Target.vobject = function(self) | ||
return ffi.cast(vobject.typeof, self) | ||
end | ||
|
||
Target.new_to_descriptor = function(descriptor) | ||
local target = vips_lib.vips_target_new_to_descriptor(descriptor) | ||
if target == ffi.NULL then | ||
error("can't create output target from descriptor " .. descriptor) | ||
else | ||
return Connection.new(target) | ||
end | ||
end | ||
|
||
Target.new_to_file = function(filename) | ||
local target = vips_lib.vips_target_new_to_file(filename) | ||
if target == ffi.NULL then | ||
error("can't create output target from filename " .. filename) | ||
else | ||
return Connection.new(target) | ||
end | ||
end | ||
|
||
Target.new_to_memory = function() | ||
local target = vips_lib.vips_target_new_to_memory() | ||
if target == ffi.NULL then | ||
error("can't create output target from memory") | ||
else | ||
return Connection.new(target) | ||
end | ||
end | ||
|
||
return ffi.metatype("VipsTarget", { | ||
__index = Target | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters