auto array-ize scalars in python
This commit is contained in:
parent
8a6a846452
commit
e6dba689ce
21
TODO
21
TODO
@ -2,6 +2,10 @@
|
||||
|
||||
- add more constructors
|
||||
|
||||
- need more writers
|
||||
|
||||
- need operator overloads
|
||||
|
||||
- could import like this:
|
||||
|
||||
from gi.repository import Vips
|
||||
@ -10,23 +14,6 @@
|
||||
ie. make it a module, not a package, and make it clear that it
|
||||
modifies Vips rather than adding anything itself
|
||||
|
||||
- need the filename splitter
|
||||
|
||||
- need more writers
|
||||
|
||||
- GBoxed
|
||||
|
||||
from gi.repository import Vips
|
||||
|
||||
a = Vips.ArrayDouble.new([1,2,3])
|
||||
a.get()
|
||||
|
||||
a = Vips.ArrayInt.new([1,2,3])
|
||||
a.get()
|
||||
|
||||
a = Vips.ArrayImage.new([c, d, e])
|
||||
a.get()
|
||||
|
||||
|
||||
|
||||
- can we pick the vipsthumbnail int shrink factor more intelligently?
|
||||
|
@ -105,10 +105,10 @@ int vips__leak = 0;
|
||||
/**
|
||||
* vips_get_argv0:
|
||||
*
|
||||
* See also: vips_init().
|
||||
* See also: VIPS_INIT().
|
||||
*
|
||||
* Returns: a pointer to an internal copy of the argv0 string passed to
|
||||
* vips_init(). Do not free this value
|
||||
* VIPS_INIT(). Do not free this value
|
||||
*/
|
||||
const char *
|
||||
vips_get_argv0( void )
|
||||
|
@ -1457,7 +1457,7 @@ vips_value_set_array_object( GValue *value, int n )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Make the types we need for basic functioning. Called from init_world().
|
||||
/* Make the types we need for basic functioning. Called from vips_init().
|
||||
*/
|
||||
void
|
||||
vips__meta_init_types( void )
|
||||
@ -1467,6 +1467,7 @@ vips__meta_init_types( void )
|
||||
(void) vips_area_get_type();
|
||||
(void) vips_ref_string_get_type();
|
||||
(void) vips_blob_get_type();
|
||||
(void) vips_array_int_get_type();
|
||||
(void) vips_array_double_get_type();
|
||||
(void) vips_array_image_get_type();
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
import sys
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level = logging.DEBUG)
|
||||
#import logging
|
||||
#logging.basicConfig(level = logging.DEBUG)
|
||||
|
||||
from gi.repository import Vips
|
||||
from vips8 import vips
|
||||
@ -14,4 +14,6 @@ b = Vips.Image.new_from_file(sys.argv[2])
|
||||
|
||||
c = a.join(b, Vips.Direction.HORIZONTAL, expand = True)
|
||||
|
||||
c.write_to_file(sys.argv[3])
|
||||
d = c.linear(2, 3)
|
||||
|
||||
d.write_to_file(sys.argv[3])
|
||||
|
@ -11,6 +11,14 @@ from gi.repository import GObject
|
||||
# export GI_TYPELIB_PATH=$VIPSHOME/lib/girepository-1.0
|
||||
from gi.repository import Vips
|
||||
|
||||
# start up vips!
|
||||
Vips.init(sys.argv[0])
|
||||
|
||||
# need the gtypes for the vips array types
|
||||
vips_type_array_int = GObject.GType.from_name("VipsArrayInt")
|
||||
vips_type_array_double = GObject.GType.from_name("VipsArrayDouble")
|
||||
vips_type_array_image = GObject.GType.from_name("VipsArrayImage")
|
||||
|
||||
class Error(Exception):
|
||||
|
||||
"""An error from vips.
|
||||
@ -43,6 +51,18 @@ class Argument:
|
||||
def set_value(self, value):
|
||||
logging.debug('assigning %s to %s' % (value, self.name))
|
||||
logging.debug('%s needs a %s' % (self.name, self.prop.value_type))
|
||||
|
||||
# array-ize some types, if necessary
|
||||
if not isinstance(value, list):
|
||||
if GObject.type_is_a(self.prop.value_type, vips_type_array_int):
|
||||
value = Vips.ArrayInt.new([value])
|
||||
if GObject.type_is_a(self.prop.value_type, vips_type_array_double):
|
||||
value = Vips.ArrayDouble.new([value])
|
||||
if GObject.type_is_a(self.prop.value_type, vips_type_array_image):
|
||||
value = Vips.ArrayImage.new([value])
|
||||
|
||||
logging.debug('assigning %s' % self.prop.value_type)
|
||||
|
||||
self.op.props.__setattr__(self.name, value)
|
||||
|
||||
def _call_base(name, required, optional, self = None, option_string = None):
|
||||
@ -197,6 +217,3 @@ Vips.Error = Error
|
||||
Vips.Argument = Argument
|
||||
Vips.call = call
|
||||
|
||||
# start up vips!
|
||||
Vips.init(sys.argv[0])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user