예제 #1
0
def gen_operation(cls):
    op = Vips.Operation.new(cls.name)
    gtype = Vips.type_find("VipsOperation", cls.name)
    nickname = Vips.nickname_find(gtype)
    all_required = find_required(op)

    result = find_first_output(op, all_required)
    this = find_first_input_image(op, all_required)

    # shallow copy
    required = all_required[:]
    if result != None:
        required.remove(result)
    if this != None:
        required.remove(this)

    if result == None:
        print 'void',
    else:
        print '%s' % gtype_to_cpp[result.value_type.name],

    print 'VImage::%s(' % nickname,

    gen_arg_list(op, required)

    print ')'
    print '{'
    if result != None:
        print '    %s %s;' % (get_ctype(result), cppize(result.name))
        print ''

    print '    call( "%s"' % nickname,

    first = True
    for prop in all_required:
        if first:
            print ','
            print '        (options ? options : VImage::option())',
            first = False

        print '->'
        print '           ',
        if prop == this:
            print 'set( "%s", *this )' % prop.name,
        else:
            flags = op.get_argument_flags(prop.name)
            arg = cppize(prop.name)
            if flags & Vips.ArgumentFlags.OUTPUT and prop == result:
                arg = '&' + arg

            print 'set( "%s", %s )' % (prop.name, arg),

    print ');'

    if result != None:
        print ''
        print '    return( %s );' % cppize(result.name)

    print '}'
    print ''
예제 #2
0
def define_class_methods(cls):
    if not cls.is_abstract():
        op = Vips.Operation.new(cls.name)

        found = False
        for prop in op.props:
            flags = op.get_argument_flags(prop.name)
            if flags & Vips.ArgumentFlags.INPUT and flags & Vips.ArgumentFlags.REQUIRED:
                if GObject.type_is_a(vips_type_image, prop.value_type):
                    found = True
                    break

        if not found:
            gtype = Vips.type_find("VipsOperation", cls.name)
            nickname = Vips.nickname_find(gtype)
            logging.debug('adding %s as a class method' % nickname)
            method = lambda *args, **kwargs: vips_image_class_method(
                nickname, args, kwargs)
            setattr(Vips.Image, nickname, classmethod(method))

    if len(cls.children) > 0:
        for child in cls.children:
            # not easy to get at the deprecated flag in an abtract type?
            if cls.name != 'VipsWrap7':
                define_class_methods(child)
예제 #3
0
def gen_operation(cls):
    op = Vips.Operation.new(cls.name)
    gtype = Vips.type_find("VipsOperation", cls.name)
    nickname = Vips.nickname_find(gtype)
    all_required = find_required(op)

    result = find_first_output(op, all_required)
    this = find_first_input_image(op, all_required)

    # shallow copy
    required = all_required[:]
    if result != None:
        required.remove(result)
    if this != None:
        required.remove(this)

    # no "this" available, it's a class method
    if this == None:
        print 'static',

    if result == None:
        print 'void',
    else:
        print '%s' % gtype_to_cpp[result.value_type.name],

    print '%s(' % nickname,

    gen_arg_list(required)

    print ')'
    print '    throw( VError );'
예제 #4
0
def gen_operation(cls):
    op = Vips.Operation.new(cls.name)
    gtype = Vips.type_find("VipsOperation", cls.name)
    nickname = Vips.nickname_find(gtype)
    all_required = find_required(op)

    result = find_first_output(op, all_required)
    this = find_first_input_image(op, all_required)

    # shallow copy
    required = all_required[:]
    if result != None:
        required.remove(result)
    if this != None:
        required.remove(this)

    if result == None:
        print 'void',
    else:
        print '%s' % gtype_to_cpp[result.value_type.name],

    print 'VImage::%s(' % nickname,

    gen_arg_list(op, required)

    print ')'
    print '{'
    if result != None:
        print '    %s %s;' % (get_ctype(result), cppize(result.name))
        print ''

    print '    call( "%s"' % nickname,

    first = True
    for prop in all_required:
        if first:
            print ','
            print '        (options ? options : VImage::option())',
            first = False

        print '->'
        print '           ',
        if prop == this:
            print 'set( "%s", *this )' % prop.name,
        else:
            flags = op.get_argument_flags(prop.name)
            arg = cppize(prop.name)
            if flags & Vips.ArgumentFlags.OUTPUT and prop == result:
                arg = '&' + arg

            print 'set( "%s", %s )' % (prop.name, arg),

    print ');'

    if result != None:
        print ''
        print '    return( %s );' % cppize(result.name)

    print '}'
    print ''
예제 #5
0
def gen_operation(cls):
    op = Vips.Operation.new(cls.name)
    gtype = Vips.type_find("VipsOperation", cls.name)
    nickname = Vips.nickname_find(gtype)
    all_required = find_required(op)

    result = find_first_output(op, all_required)
    this = find_first_input_image(op, all_required)

    # shallow copy
    required = all_required[:]
    if result != None:
        required.remove(result)
    if this != None:
        required.remove(this)

    # no "this" available, it's a class method
    if this == None:
        print 'static',

    if result == None:
        print 'void',
    else:
        print '%s' % gtype_to_cpp[result.value_type.name],

    print '%s(' % nickname,

    gen_arg_list(required)

    print ')'
    print '    throw( VError );'
예제 #6
0
def find_class_methods(cls):
    names = set()

    if not cls.is_abstract():
        op = Vips.Operation.new(cls.name)

        found = False
        for prop in op.props:
            flags = op.get_argument_flags(prop.name)
            if not flags & Vips.ArgumentFlags.INPUT:
                continue
            if not flags & Vips.ArgumentFlags.REQUIRED:
                continue
            if GObject.type_is_a(vips_type_image, prop.value_type):
                found = True
                break

        if not found:
            gtype = Vips.type_find("VipsOperation", cls.name)
            names.add(Vips.nickname_find(gtype))

    if len(cls.children) > 0:
        for child in cls.children:
            # not easy to get at the deprecated flag in an abtract type?
            if cls.name != 'VipsWrap7':
                names.update(find_class_methods(child))

    return names
예제 #7
0
def find_class_methods(cls):
    names = set()

    if not cls.is_abstract():
        op = Vips.Operation.new(cls.name)

        found = False
        for prop in op.props:
            flags = op.get_argument_flags(prop.name)
            if not flags & Vips.ArgumentFlags.INPUT:
                continue
            if not flags & Vips.ArgumentFlags.REQUIRED:
                continue
            if GObject.type_is_a(vips_type_image, prop.value_type):
                found = True
                break

        if not found:
            gtype = Vips.type_find("VipsOperation", cls.name)
            names.add(Vips.nickname_find(gtype))

    if len(cls.children) > 0:
        for child in cls.children:
            # not easy to get at the deprecated flag in an abtract type?
            if cls.name != 'VipsWrap7':
                names.update(find_class_methods(child))

    return names
예제 #8
0
    def save_load_buffer(self, saver, loader, im, max_diff = 0):
        buf = Vips.call(saver, im)
        x = Vips.call(loader, buf)

        self.assertEqual(im.width, x.width)
        self.assertEqual(im.height, x.height)
        self.assertEqual(im.bands, x.bands)
        self.assertLessEqual((im - x).abs().max(), max_diff)
예제 #9
0
    def __init__(self, message, detail = None):
        self.message = message
        if detail == None:
            detail = Vips.error_buffer()
            Vips.error_clear()
        self.detail = detail

        logging.debug('vips: Error %s %s', self.message, self.detail)
예제 #10
0
    def save_load_buffer(self, saver, loader, im, max_diff=0):
        buf = Vips.call(saver, im)
        x = Vips.call(loader, buf)

        self.assertEqual(im.width, x.width)
        self.assertEqual(im.height, x.height)
        self.assertEqual(im.bands, x.bands)
        self.assertLessEqual((im - x).abs().max(), max_diff)
예제 #11
0
    def __init__(self, message, detail=None):
        self.message = message
        if detail == None:
            detail = Vips.error_buffer()
            Vips.error_clear()
        self.detail = detail

        logging.debug('vips: Error %s %s', self.message, self.detail)
예제 #12
0
def vips_image_new_from_file(cls, vips_filename, **kwargs):
    filename = Vips.filename_get_filename(vips_filename)
    option_string = Vips.filename_get_options(vips_filename)
    loader = Vips.Foreign.find_load(filename)
    if loader == None:
        raise Error('No known loader for "%s".' % filename)
    logging.debug('Image.new_from_file: loader = %s' % loader)

    return _call_base(loader, [filename], kwargs, None, option_string)
예제 #13
0
파일: vips.py 프로젝트: MaxMillion/libvips
def vips_image_write_to_buffer(self, vips_filename, **kwargs):
    filename = Vips.filename_get_filename(vips_filename)
    option_string = Vips.filename_get_options(vips_filename)
    saver = Vips.Foreign.find_save_buffer(filename)
    if saver == None:
        raise Error('No known saver for "%s".' % filename)
    logging.debug('Image.write_to_buffer: saver = %s' % saver)

    return _call_base(saver, [], kwargs, self, option_string)
예제 #14
0
파일: vips.py 프로젝트: MaxMillion/libvips
def vips_image_new_from_file(cls, vips_filename, **kwargs):
    filename = Vips.filename_get_filename(vips_filename)
    option_string = Vips.filename_get_options(vips_filename)
    loader = Vips.Foreign.find_load(filename)
    if loader == None:
        raise Error('No known loader for "%s".' % filename)
    logging.debug('Image.new_from_file: loader = %s' % loader)

    return _call_base(loader, [filename], kwargs, None, option_string)
예제 #15
0
def vips_image_write_to_buffer(self, vips_filename, **kwargs):
    filename = Vips.filename_get_filename(vips_filename)
    option_string = Vips.filename_get_options(vips_filename)
    saver = Vips.Foreign.find_save_buffer(filename)
    if saver == None:
        raise Error('No known saver for "%s".' % filename)
    logging.debug('Image.write_to_buffer: saver = %s' % saver)

    return _call_base(saver, [], kwargs, self, option_string)
def gen_function(cls):
    op = Vips.Operation.new(cls.name)
    gtype = Vips.type_find("VipsOperation", cls.name)
    nickname = Vips.nickname_find(gtype)

    print '<row>'
    print '  <entry>%s</entry>' % nickname
    print '  <entry>%s</entry>' % op.get_description()
    print '  <entry>vips_%s()</entry>' % nickname
    print '</row>'
예제 #17
0
def gen_function(cls):
    op = Vips.Operation.new(cls.name)
    gtype = Vips.type_find("VipsOperation", cls.name)
    nickname = Vips.nickname_find(gtype)

    print '<row>'
    print '  <entry>%s</entry>' % nickname
    print '  <entry>%s</entry>' % op.get_description()
    print '  <entry>vips_%s()</entry>' % nickname
    print '</row>'
예제 #18
0
def find_class_methods(cls):
    if not cls.is_abstract():
        gtype = Vips.type_find("VipsOperation", cls.name)
        nickname = Vips.nickname_find(gtype)
        if not nickname in generated:
            gen_operation(cls)
            generated[nickname] = True

    if len(cls.children) > 0:
        for child in cls.children:
            find_class_methods(child)
def gen_function_list(cls):
    if not cls.is_abstract():
        gtype = Vips.type_find("VipsOperation", cls.name)
        nickname = Vips.nickname_find(gtype)
        if not nickname in generated:
            gen_function(cls)
            generated[nickname] = True

    if len(cls.children) > 0:
        for child in cls.children:
            gen_function_list(child)
예제 #20
0
def find_class_methods(cls):
    if not cls.is_abstract():
        gtype = Vips.type_find("VipsOperation", cls.name)
        nickname = Vips.nickname_find(gtype)
        if not nickname in generated:
            gen_operation(cls)
            generated[nickname] = True

    if len(cls.children) > 0:
        for child in cls.children:
            find_class_methods(child)
예제 #21
0
def gen_function_list(cls):
    if not cls.is_abstract():
        gtype = Vips.type_find("VipsOperation", cls.name)
        nickname = Vips.nickname_find(gtype)
        if not nickname in generated:
            gen_function(cls)
            generated[nickname] = True

    if len(cls.children) > 0:
        for child in cls.children:
            gen_function_list(child)
예제 #22
0
    def test_webp(self):
        x = Vips.type_find("VipsForeign", "webpload")
        if not x.is_instantiatable():
            print("no webp support in this vips, skipping test")
            return

        def webp_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [71, 166, 236])
            self.assertEqual(im.width, 550)
            self.assertEqual(im.height, 368)
            self.assertEqual(im.bands, 3)

        self.file_loader("webpload", self.webp_file, webp_valid)
        self.buffer_loader("webpload_buffer", self.webp_file, webp_valid)
        self.save_load_buffer("webpsave_buffer", "webpload_buffer",
                              self.colour, 50)
        self.save_load("%s.webp", self.colour)

        # test lossless mode
        im = Vips.Image.new_from_file(self.webp_file)
        buf = im.webpsave_buffer(lossless=True)
        im2 = Vips.Image.new_from_buffer(buf, "")
        self.assertEqual(im.avg(), im2.avg())

        # higher Q should mean a bigger buffer
        b1 = im.webpsave_buffer(Q=10)
        b2 = im.webpsave_buffer(Q=90)
        self.assertGreater(len(b2), len(b1))
예제 #23
0
    def test_pdfload(self):
        x = Vips.type_find("VipsForeign", "pdfload")
        if not x.is_instantiatable():
            print("no pdf support in this vips, skipping test")
            return

        def pdf_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [35, 31, 32, 255])
            self.assertEqual(im.width, 1133)
            self.assertEqual(im.height, 680)
            self.assertEqual(im.bands, 4)

        self.file_loader("pdfload", self.pdf_file, pdf_valid)
        self.buffer_loader("pdfload_buffer", self.pdf_file, pdf_valid)

        im = Vips.Image.new_from_file(self.pdf_file)
        x = Vips.Image.new_from_file(self.pdf_file, scale=2)
        self.assertLess(abs(im.width * 2 - x.width), 2)
        self.assertLess(abs(im.height * 2 - x.height), 2)

        im = Vips.Image.new_from_file(self.pdf_file)
        x = Vips.Image.new_from_file(self.pdf_file, dpi=144)
        self.assertLess(abs(im.width * 2 - x.width), 2)
        self.assertLess(abs(im.height * 2 - x.height), 2)
예제 #24
0
    def test_pdfload(self):
        x = Vips.type_find("VipsForeign", "pdfload")
        if not x.is_instantiatable():
            print("no pdf support in this vips, skipping test")
            return

        def pdf_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [35, 31, 32, 255])
            self.assertEqual(im.width, 1133)
            self.assertEqual(im.height, 680)
            self.assertEqual(im.bands, 4)

        self.file_loader("pdfload", self.pdf_file, pdf_valid)
        self.buffer_loader("pdfload_buffer", self.pdf_file, pdf_valid)

        im = Vips.Image.new_from_file(self.pdf_file)
        x = Vips.Image.new_from_file(self.pdf_file, scale = 2)
        self.assertLess(abs(im.width * 2 - x.width), 2)
        self.assertLess(abs(im.height * 2 - x.height), 2)

        im = Vips.Image.new_from_file(self.pdf_file)
        x = Vips.Image.new_from_file(self.pdf_file, dpi = 144)
        self.assertLess(abs(im.width * 2 - x.width), 2)
        self.assertLess(abs(im.height * 2 - x.height), 2)
예제 #25
0
    def test_tiff(self):
        if not Vips.type_find("VipsForeign", "tiffload"):
            print("no tiff support in this vips, skipping test")
            return

        def tiff_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [38671.0, 33914.0, 26762.0])
            self.assertEqual(im.width, 290)
            self.assertEqual(im.height, 442)
            self.assertEqual(im.bands, 3)

        self.file_loader("tiffload", self.tiff_file, tiff_valid)
        self.buffer_loader("tiffload_buffer", self.tiff_file, tiff_valid)
        self.save_load("%s.tif", self.mono)
        self.save_load("%s.tif", self.colour)
        self.save_load("%s.tif", self.cmyk)

        self.save_load("%s.tif", self.onebit)
        self.save_load("%s.tif[squash]", self.onebit)
        self.save_load("%s.tif[miniswhite]", self.onebit)
        self.save_load("%s.tif[squash,miniswhite]", self.onebit)

        self.save_load_file("test.tif", "[tile]", self.colour, 0)
        self.save_load_file("test.tif", "[tile,pyramid]", self.colour, 0)
        self.save_load_file("test.tif", 
                            "[tile,pyramid,compression=jpeg]", self.colour, 0)
        self.save_load_file("test.tif", "[bigtiff]", self.colour, 0)
        self.save_load_file("test.tif", "[compression=jpeg]", self.colour, 10)
        self.save_load_file("test.tif", 
                            "[tile,tile-width=256]", self.colour, 10)
예제 #26
0
    def test_tiff(self):
        if not Vips.type_find("VipsForeign", "tiffload"):
            print("no tiff support in this vips, skipping test")
            return

        def tiff_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [38671.0, 33914.0, 26762.0])
            self.assertEqual(im.width, 290)
            self.assertEqual(im.height, 442)
            self.assertEqual(im.bands, 3)

        self.file_loader("tiffload", self.tiff_file, tiff_valid)
        self.buffer_loader("tiffload_buffer", self.tiff_file, tiff_valid)
        self.save_load("%s.tif", self.mono)
        self.save_load("%s.tif", self.colour)
        self.save_load("%s.tif", self.cmyk)

        self.save_load("%s.tif", self.onebit)
        self.save_load("%s.tif[squash]", self.onebit)
        self.save_load("%s.tif[miniswhite]", self.onebit)
        self.save_load("%s.tif[squash,miniswhite]", self.onebit)

        self.save_load_file("test.tif", "[tile]", self.colour, 0)
        self.save_load_file("test.tif", "[tile,pyramid]", self.colour, 0)
        self.save_load_file("test.tif", "[tile,pyramid,compression=jpeg]",
                            self.colour, 0)
        self.save_load_file("test.tif", "[bigtiff]", self.colour, 0)
        self.save_load_file("test.tif", "[compression=jpeg]", self.colour, 10)
        self.save_load_file("test.tif", "[tile,tile-width=256]", self.colour,
                            10)
예제 #27
0
    def test_svgload(self):
        x = Vips.type_find("VipsForeign", "svgload")
        if not x.is_instantiatable():
            print("no svg support in this vips, skipping test")
            return

        def svg_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [0, 0, 77, 255])
            self.assertEqual(im.width, 360)
            self.assertEqual(im.height, 588)
            self.assertEqual(im.bands, 4)

        self.file_loader("svgload", self.svg_file, svg_valid)
        self.buffer_loader("svgload_buffer", self.svg_file, svg_valid)

        im = Vips.Image.new_from_file(self.svg_file)
        x = Vips.Image.new_from_file(self.svg_file, scale=2)
        self.assertLess(abs(im.width * 2 - x.width), 2)
        self.assertLess(abs(im.height * 2 - x.height), 2)

        im = Vips.Image.new_from_file(self.svg_file)
        x = Vips.Image.new_from_file(self.svg_file, dpi=144)
        self.assertLess(abs(im.width * 2 - x.width), 2)
        self.assertLess(abs(im.height * 2 - x.height), 2)
예제 #28
0
    def test_tiff(self):
        x = Vips.type_find("VipsForeign", "tiffload")
        if not x.is_instantiatable():
            print("no tiff support in this vips, skipping test")
            return

        def tiff_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [38671.0, 33914.0, 26762.0])
            self.assertEqual(im.width, 290)
            self.assertEqual(im.height, 442)
            self.assertEqual(im.bands, 3)

        self.file_loader("tiffload", self.tiff_file, tiff_valid)
        self.buffer_loader("tiffload_buffer", self.tiff_file, tiff_valid)
        self.save_load("%s.tif", self.mono)
        self.save_load("%s.tif", self.colour)
        self.save_load("%s.tif", self.cmyk)

        self.save_load("%s.tif", self.onebit)
        self.save_load_file("test-1.tif", "[squash]", self.onebit, 0)
        self.save_load_file("test-2.tif", "[miniswhite]", self.onebit, 0)
        self.save_load_file("test-3.tif", "[squash,miniswhite]", self.onebit, 0)

        self.save_load_file("test-4.tif",
                            "[profile=images/sRGB.icm]",
                            self.colour, 0)
        self.save_load_file("test-5.tif", "[tile]", self.colour, 0)
        self.save_load_file("test-6.tif", "[tile,pyramid]", self.colour, 0)
        self.save_load_file("test-7.tif", 
                            "[tile,pyramid,compression=jpeg]", self.colour, 60)
        self.save_load_file("test-8.tif", "[bigtiff]", self.colour, 0)
        self.save_load_file("test-9.tif", "[compression=jpeg]", self.colour, 60)
        self.save_load_file("test-10.tif", 
                            "[tile,tile-width=256]", self.colour, 10)
예제 #29
0
    def test_svgload(self):
        x = Vips.type_find("VipsForeign", "svgload")
        if not x.is_instantiatable():
            print("no svg support in this vips, skipping test")
            return

        def svg_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [0, 0, 77, 255])
            self.assertEqual(im.width, 360)
            self.assertEqual(im.height, 588)
            self.assertEqual(im.bands, 4)

        self.file_loader("svgload", self.svg_file, svg_valid)
        self.buffer_loader("svgload_buffer", self.svg_file, svg_valid)

        self.file_loader("svgload", self.svgz_file, svg_valid)
        self.buffer_loader("svgload_buffer", self.svgz_file, svg_valid)

        self.file_loader("svgload", self.svg_gz_file, svg_valid)

        im = Vips.Image.new_from_file(self.svg_file)
        x = Vips.Image.new_from_file(self.svg_file, scale = 2)
        self.assertLess(abs(im.width * 2 - x.width), 2)
        self.assertLess(abs(im.height * 2 - x.height), 2)

        im = Vips.Image.new_from_file(self.svg_file)
        x = Vips.Image.new_from_file(self.svg_file, dpi = 144)
        self.assertLess(abs(im.width * 2 - x.width), 2)
        self.assertLess(abs(im.height * 2 - x.height), 2)
예제 #30
0
    def test_rad(self):
        x = Vips.type_find("VipsForeign", "radload")
        if not x.is_instantiatable():
            print("no Radiance support in this vips, skipping test")
            return

        self.save_load("%s.hdr", self.colour)
예제 #31
0
    def test_gifload(self):
        x = Vips.type_find("VipsForeign", "gifload")
        if not x.is_instantiatable():
            print("no gif support in this vips, skipping test")
            return

        def gif_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [33])
            self.assertEqual(im.width, 159)
            self.assertEqual(im.height, 203)
            self.assertEqual(im.bands, 1)

        self.file_loader("gifload", self.gif_file, gif_valid)
        self.buffer_loader("gifload_buffer", self.gif_file, gif_valid)

        x1 = Vips.Image.new_from_file(self.gif_anim_file )
        x2 = Vips.Image.new_from_file(self.gif_anim_file, n = 2 )
        self.assertEqual(x2.height, 2 * x1.height)
        page_height = x2.get_value("page-height")
        self.assertEqual(page_height, x1.height)

        x2 = Vips.Image.new_from_file(self.gif_anim_file, n = -1 )
        self.assertEqual(x2.height, 5 * x1.height)

        x2 = Vips.Image.new_from_file(self.gif_anim_file, page = 1, n = -1 )
        self.assertEqual(x2.height, 4 * x1.height)
예제 #32
0
    def test_gifload(self):
        x = Vips.type_find("VipsForeign", "gifload")
        if not x.is_instantiatable():
            print("no gif support in this vips, skipping test")
            return

        def gif_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [33])
            self.assertEqual(im.width, 159)
            self.assertEqual(im.height, 203)
            self.assertEqual(im.bands, 1)

        self.file_loader("gifload", self.gif_file, gif_valid)
        self.buffer_loader("gifload_buffer", self.gif_file, gif_valid)

        x1 = Vips.Image.new_from_file(self.gif_anim_file )
        x2 = Vips.Image.new_from_file(self.gif_anim_file, n = 2 )
        self.assertEqual(x2.height, 2 * x1.height)
        page_height = x2.get_value("page-height")
        self.assertEqual(page_height, x1.height)

        x2 = Vips.Image.new_from_file(self.gif_anim_file, n = -1 )
        self.assertEqual(x2.height, 5 * x1.height)

        x2 = Vips.Image.new_from_file(self.gif_anim_file, page = 1, n = -1 )
        self.assertEqual(x2.height, 4 * x1.height)
예제 #33
0
    def test_rad(self):
        x = Vips.type_find("VipsForeign", "radload")
        if not x.is_instantiatable():
            print("no Radiance support in this vips, skipping test")
            return

        self.save_load("%s.hdr", self.colour)
예제 #34
0
    def test_webp(self):
        x = Vips.type_find("VipsForeign", "webpload")
        if not x.is_instantiatable():
            print("no webp support in this vips, skipping test")
            return

        def webp_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [71, 166, 236])
            self.assertEqual(im.width, 550)
            self.assertEqual(im.height, 368)
            self.assertEqual(im.bands, 3)

        self.file_loader("webpload", self.webp_file, webp_valid)
        self.buffer_loader("webpload_buffer", self.webp_file, webp_valid)
        self.save_load_buffer("webpsave_buffer", "webpload_buffer", self.colour,
                             50)
        self.save_load("%s.webp", self.colour)

        # test lossless mode
        im = Vips.Image.new_from_file(self.webp_file)
        buf = im.webpsave_buffer(lossless = True)
        im2 = Vips.Image.new_from_buffer(buf, "")
        self.assertEqual(im.avg(), im2.avg())

        # higher Q should mean a bigger buffer
        b1 = im.webpsave_buffer(Q = 10)
        b2 = im.webpsave_buffer(Q = 90)
        self.assertGreater(len(b2), len(b1))
예제 #35
0
    def test_ppm(self):
        x = Vips.type_find("VipsForeign", "ppmload")
        if not x.is_instantiatable():
            print("no PPM support in this vips, skipping test")
            return

        self.save_load("%s.ppm", self.mono)
        self.save_load("%s.ppm", self.colour)
예제 #36
0
파일: try.py 프로젝트: aferrero2707/libvips
def vips_call(name, *required, **optional):
    op = Vips.Operation.new(name)

    # set required input args
    i = 0
    for prop in op.props:
        flags = op.get_argument_flags(prop.name)
        if required_input(flags):
            if i >= len(required):
                print 'too few required args!'

            op.props.__setattr__(prop.name, required[i])
            i += 1

    if i < len(required):
        print 'too many required args!'

    # set optional input args
    for i in optional.keys():
        flags = op.get_argument_flags(i)
        if optional_input(flags):
            op.props.__setattr__(i, optional[i])

    # call
    op2 = Vips.cache_operation_build(op)
    if op2 == None:
        print Vips.error_buffer()

    # gather output args 
    out = []
    for prop in op2.props:
        flags = op2.get_argument_flags(prop.name)
        if required_output(flags):
            out.append(op2.props.__getattribute__(prop.name))
    for i in optional.keys():
        flags = op2.get_argument_flags(i)
        if optional_output(flags):
            out.append(op2.props.__getattribute__(i))

    if len(out) == 1:
        out = out[0]

    # unref everything now we have refs to all outputs we want
    op2.unref_outputs()

    return out
예제 #37
0
    def buffer_loader(self, loader, test_file, validate):
        with open(test_file, 'rb') as f:
            buf = f.read()

        im = Vips.call(loader, buf)
        validate(self, im)
        im = Vips.Image.new_from_buffer(buf, "")
        validate(self, im)
예제 #38
0
    def test_ppm(self):
        x = Vips.type_find("VipsForeign", "ppmload")
        if not x.is_instantiatable():
            print("no PPM support in this vips, skipping test")
            return

        self.save_load("%s.ppm", self.mono)
        self.save_load("%s.ppm", self.colour)
예제 #39
0
    def buffer_loader(self, loader, test_file, validate):
        with open(test_file, 'rb') as f:
            buf = f.read()

        im = Vips.call(loader, buf)
        validate(self, im)
        im = Vips.Image.new_from_buffer(buf, "")
        validate(self, im)
예제 #40
0
def find_class_methods(cls):
    methods = []
    skipped = []
    if not cls.is_abstract():
        gtype = Vips.type_find("VipsOperation", cls.name)
        nickname = Vips.nickname_find(gtype)
        if not nickname in generated:
            try:
                methods.append(gen_operation(cls))
                generated[nickname] = True
            except Exception as e:
                skipped.append('// Unsupported: %s: %s' % (nickname, str(e)))
    if len(cls.children) > 0:
        for child in cls.children:
            m, s = find_class_methods(child)
            methods.extend(m)
            skipped.extend(s)
    return methods, skipped
예제 #41
0
def find_class_methods(cls):
  methods = []
  skipped = []
  if not cls.is_abstract():
    gtype = Vips.type_find("VipsOperation", cls.name)
    nickname = Vips.nickname_find(gtype)
    if not nickname in generated:
      try:
        methods.append(gen_operation(cls))
        generated[nickname] = True
      except Exception as e:
        skipped.append('// Unsupported: %s: %s' % (nickname, str(e)))
  if len(cls.children) > 0:
    for child in cls.children:
      m, s = find_class_methods(child)
      methods.extend(m)
      skipped.extend(s)
  return methods, skipped
예제 #42
0
    def test_magickload(self):
        x = Vips.type_find("VipsForeign", "magickload")
        if not x.is_instantiatable():
            print("no magick support in this vips, skipping test")
            return

        def gif_valid(self, im):
            # some libMagick produce an RGB for this image, some a mono, some
            # rgba, some have a valid alpha, some don't :-( 
            # therefore ... just test channel 0
            a = im(10, 10)[0]

            self.assertAlmostEqual(a, 33)
            self.assertEqual(im.width, 159)
            self.assertEqual(im.height, 203)

        self.file_loader("magickload", self.gif_file, gif_valid)
        self.buffer_loader("magickload_buffer", self.gif_file, gif_valid)

        # we should have rgba for svg files
        im = Vips.Image.magickload(self.svg_file)
        self.assertEqual(im.bands, 4)

        # density should change size of generated svg
        im = Vips.Image.magickload(self.svg_file, density = 100)
        width = im.width
        height = im.height
        im = Vips.Image.magickload(self.svg_file, density = 200)
        # This seems to fail on travis, no idea why, some problem in their IM
        # perhaps
        #self.assertEqual(im.width, width * 2)
        #self.assertEqual(im.height, height * 2)

        # all-frames should load every frame of the animation
        # (though all-frames is deprecated)
        im = Vips.Image.magickload(self.gif_anim_file)
        width = im.width
        height = im.height
        im = Vips.Image.magickload(self.gif_anim_file, all_frames = True)
        self.assertEqual(im.width, width)
        self.assertEqual(im.height, height * 5)

        # page/n let you pick a range of pages
        im = Vips.Image.magickload(self.gif_anim_file)
        width = im.width
        height = im.height
        im = Vips.Image.magickload(self.gif_anim_file, page = 1, n = 2)
        self.assertEqual(im.width, width)
        self.assertEqual(im.height, height * 2)
        page_height = im.get_value("page-height")
        self.assertEqual(page_height, height)

        # should work for dicom
        im = Vips.Image.magickload(self.dicom_file)
        self.assertEqual(im.width, 128)
        self.assertEqual(im.height, 128)
예제 #43
0
    def test_magickload(self):
        x = Vips.type_find("VipsForeign", "magickload")
        if not x.is_instantiatable():
            print("no magick support in this vips, skipping test")
            return

        def gif_valid(self, im):
            # some libMagick produce an RGB for this image, some a mono, some
            # rgba, some have a valid alpha, some don't :-( 
            # therefore ... just test channel 0
            a = im(10, 10)[0]

            self.assertAlmostEqual(a, 33)
            self.assertEqual(im.width, 159)
            self.assertEqual(im.height, 203)

        self.file_loader("magickload", self.gif_file, gif_valid)
        self.buffer_loader("magickload_buffer", self.gif_file, gif_valid)

        # we should have rgba for svg files
        im = Vips.Image.magickload(self.svg_file)
        self.assertEqual(im.bands, 4)

        # density should change size of generated svg
        im = Vips.Image.magickload(self.svg_file, density = 100)
        width = im.width
        height = im.height
        im = Vips.Image.magickload(self.svg_file, density = 200)
        # This seems to fail on travis, no idea why, some problem in their IM
        # perhaps
        #self.assertEqual(im.width, width * 2)
        #self.assertEqual(im.height, height * 2)

        # all-frames should load every frame of the animation
        # (though all-frames is deprecated)
        im = Vips.Image.magickload(self.gif_anim_file)
        width = im.width
        height = im.height
        im = Vips.Image.magickload(self.gif_anim_file, all_frames = True)
        self.assertEqual(im.width, width)
        self.assertEqual(im.height, height * 5)

        # page/n let you pick a range of pages
        im = Vips.Image.magickload(self.gif_anim_file)
        width = im.width
        height = im.height
        im = Vips.Image.magickload(self.gif_anim_file, page = 1, n = 2)
        self.assertEqual(im.width, width)
        self.assertEqual(im.height, height * 2)
        page_height = im.get_value("page-height")
        self.assertEqual(page_height, height)

        # should work for dicom
        im = Vips.Image.magickload(self.dicom_file)
        self.assertEqual(im.width, 128)
        self.assertEqual(im.height, 128)
예제 #44
0
 def test_text(self):
     x = Vips.type_find("VipsOperation", "text")
     if x.is_instantiatable():
         im = Vips.Image.text("Hello, world!")
         self.assertTrue(im.width > 10)
         self.assertTrue(im.height > 10)
         self.assertEqual(im.bands, 1)
         self.assertEqual(im.format, Vips.BandFormat.UCHAR)
         self.assertEqual(im.max(), 255)
         self.assertEqual(im.min(), 0)
예제 #45
0
def zip_expand(x, y):
    if isinstance(x, list) and isinstance(y, list):
        if len(x) != len(y):
            raise Vips.Error("zip_expand list args not equal length")
        return list(zip(x, y))
    elif isinstance(x, list):
        return [[i, y] for i in x]
    elif isinstance(y, list):
        return [[x, j] for j in y]
    else:
        return [[x, y]]
예제 #46
0
    def test_matload(self):
        if not Vips.type_find("VipsForeign", "matload"):
            print("no matlab support in this vips, skipping test")
            return

        def matlab_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [38671.0, 33914.0, 26762.0])
            self.assertEqual(im.width, 290)
            self.assertEqual(im.height, 442)
            self.assertEqual(im.bands, 3)

        self.file_loader("matload", self.matlab_file, matlab_valid)
예제 #47
0
    def test_openslideload(self):
        if not Vips.type_find("VipsForeign", "openslideload"):
            print("no openslide support in this vips, skipping test")
            return

        def openslide_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [244, 250, 243, 255])
            self.assertEqual(im.width, 2220)
            self.assertEqual(im.height, 2967)
            self.assertEqual(im.bands, 4)

        self.file_loader("openslideload", self.openslide_file, openslide_valid)
예제 #48
0
    def save_buffer_tempfile(self, saver, suf, im, max_diff = 0):
        buf = Vips.call(saver, im)
        f = NamedTemporaryFile(suffix=suf, delete=False)
        f.write(buf)
        f.close()
        x = Vips.Image.new_from_file(f.name)

        self.assertEqual(im.width, x.width)
        self.assertEqual(im.height, x.height)
        self.assertEqual(im.bands, x.bands)
        self.assertLessEqual((im - x).abs().max(), max_diff)

        os.unlink(f.name)
예제 #49
0
    def save_buffer_tempfile(self, saver, suf, im, max_diff=0):
        buf = Vips.call(saver, im)
        f = NamedTemporaryFile(suffix=suf, delete=False)
        f.write(buf)
        f.close()
        x = Vips.Image.new_from_file(f.name)

        self.assertEqual(im.width, x.width)
        self.assertEqual(im.height, x.height)
        self.assertEqual(im.bands, x.bands)
        self.assertLessEqual((im - x).abs().max(), max_diff)

        os.unlink(f.name)
예제 #50
0
def define_class_methods(cls):
    if len(cls.children) > 0:
        for child in cls.children:
            # not easy to get at the deprecated flag in an abtract type?
            if cls.name != 'VipsWrap7':
                define_class_methods(child)
    elif cls.is_instantiatable():
        op = Vips.Operation.new(cls.name)
        found = False
        for prop in op.props:
            flags = op.get_argument_flags(prop.name)
            if flags & Vips.ArgumentFlags.INPUT and flags & Vips.ArgumentFlags.REQUIRED:
                if GObject.type_is_a(vips_type_image, prop.value_type):
                    found = True
                    break

        if not found:
            gtype = Vips.type_find("VipsOperation", cls.name)
            nickname = Vips.nickname_find(gtype)
            logging.debug('adding %s as a class method' % nickname)
            method = lambda *args, **kwargs: vips_image_class_method( nickname, args, kwargs)
            setattr(Vips.Image, nickname, classmethod(method))
예제 #51
0
    def test_openslideload(self):
        if not Vips.type_find("VipsForeign", "openslideload"):
            print("no openslide support in this vips, skipping test")
            return

        def openslide_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [244, 250, 243, 255])
            self.assertEqual(im.width, 2220)
            self.assertEqual(im.height, 2967)
            self.assertEqual(im.bands, 4)

        self.file_loader("openslideload", self.openslide_file, openslide_valid)
예제 #52
0
    def test_matload(self):
        if not Vips.type_find("VipsForeign", "matload"):
            print("no matlab support in this vips, skipping test")
            return

        def matlab_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [38671.0, 33914.0, 26762.0])
            self.assertEqual(im.width, 290)
            self.assertEqual(im.height, 442)
            self.assertEqual(im.bands, 3)

        self.file_loader("matload", self.matlab_file, matlab_valid)
예제 #53
0
    def test_magickload(self):
        if not Vips.type_find("VipsForeign", "magickload"):
            print("no magick support in this vips, skipping test")
            return

        def gif_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqual(a, [33, 33, 33])
            self.assertEqual(im.width, 159)
            self.assertEqual(im.height, 203)
            self.assertEqual(im.bands, 3)

        self.file_loader("magickload", self.gif_file, gif_valid)
        self.buffer_loader("magickload_buffer", self.gif_file, gif_valid)
예제 #54
0
    def test_analyzeload(self):
        x = Vips.type_find("VipsForeign", "analyzeload")
        if not x.is_instantiatable():
            print("no analyze support in this vips, skipping test")
            return

        def analyze_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqual(a[0], 3335)
            self.assertEqual(im.width, 128)
            self.assertEqual(im.height, 8064)
            self.assertEqual(im.bands, 1)

        self.file_loader("analyzeload", self.analyze_file, analyze_valid)
예제 #55
0
    def test_webp(self):
        x = Vips.type_find("VipsForeign", "webpload")
        if not x.is_instantiatable():
            print("no webp support in this vips, skipping test")
            return

        def webp_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [71, 166, 236])
            self.assertEqual(im.width, 550)
            self.assertEqual(im.height, 368)
            self.assertEqual(im.bands, 3)

        self.file_loader("webpload", self.webp_file, webp_valid)
        self.buffer_loader("webpload_buffer", self.webp_file, webp_valid)
        self.save_load_buffer("webpsave_buffer", "webpload_buffer", 
                              self.colour, 60)
        self.save_load("%s.webp", self.colour)

        # test lossless mode
        im = Vips.Image.new_from_file(self.webp_file)
        buf = im.webpsave_buffer(lossless = True)
        im2 = Vips.Image.new_from_buffer(buf, "")
        self.assertEqual(im.avg(), im2.avg())

        # higher Q should mean a bigger buffer
        b1 = im.webpsave_buffer(Q = 10)
        b2 = im.webpsave_buffer(Q = 90)
        self.assertGreater(len(b2), len(b1))

        # try saving an image with an ICC profile and reading it back ... if we
        # can do it, our webp supports metadata load/save
        buf = self.colour.webpsave_buffer()
        im = Vips.Image.new_from_buffer(buf, "")
        if im.get_typeof("icc-profile-data") != GObject.TYPE_INVALID:
            # verify that the profile comes back unharmed
            p1 = self.colour.get_value("icc-profile-data")
            p2 = im.get_value("icc-profile-data")
            self.assertEqual(p1, p2)

            # add tests for exif, xmp, exif
            # the exif test will need us to be able to walk the header, we can't
            # just check exif-data

            # we can test that exif changes change the output of webpsave
            x = self.colour.copy()
            x.set_value("orientation", 6)
            buf = x.webpsave_buffer()
            y = Vips.Image.new_from_buffer(buf, "")
            self.assertEqual(y.get_value("orientation"), 6)
예제 #56
0
    def test_analyzeload(self):
        x = Vips.type_find("VipsForeign", "analyzeload")
        if not x.is_instantiatable():
            print("no analyze support in this vips, skipping test")
            return

        def analyze_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqual(a[0], 3335)
            self.assertEqual(im.width, 128)
            self.assertEqual(im.height, 8064)
            self.assertEqual(im.bands, 1)

        self.file_loader("analyzeload", self.analyze_file, analyze_valid)
예제 #57
0
    def test_magickload(self):
        if not Vips.type_find("VipsForeign", "magickload"):
            print("no magick support in this vips, skipping test")
            return

        def gif_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqual(a, [33, 33, 33])
            self.assertEqual(im.width, 159)
            self.assertEqual(im.height, 203)
            self.assertEqual(im.bands, 3)

        self.file_loader("magickload", self.gif_file, gif_valid)
        self.buffer_loader("magickload_buffer", self.gif_file, gif_valid)
예제 #58
0
    def test_gifload(self):
        x = Vips.type_find("VipsForeign", "gifload")
        if not x.is_instantiatable():
            print("no gif support in this vips, skipping test")
            return

        def gif_valid(self, im):
            a = im(10, 10)
            self.assertAlmostEqualObjects(a, [33])
            self.assertEqual(im.width, 159)
            self.assertEqual(im.height, 203)
            self.assertEqual(im.bands, 1)

        self.file_loader("gifload", self.gif_file, gif_valid)
        self.buffer_loader("gifload_buffer", self.gif_file, gif_valid)