Ejemplo n.º 1
0
def convert(components, src, dst, preserve_alpha=True):
    if not preserve_alpha:
        if src == 'Grayscale':
            non_alpha = 1
        elif src == 'CMYK':
            non_alpha = 4
        else:
            non_alpha = 3

        def omit_alpha(*c):
            return c[:non_alpha]

        components = stacked(omit_alpha, components)

    if src == dst:
        return components

    path = _paths.get((src, dst), None)
    if path is None:
        return None

    for s, d in zip(path[:-1], path[1:]):
        func = conversions.get('%s>%s' % (s, d))
        if not func:
            return None
        components = stacked(func, components)

    return components
Ejemplo n.º 2
0
def convert(components, src, dst, preserve_alpha=True):
    if not preserve_alpha:
        if src == 'Grayscale':
            non_alpha = 1
        elif src == 'CMYK':
            non_alpha = 4
        else:
            non_alpha = 3

        def omit_alpha(*c):
            return c[:non_alpha]

        components = stacked(omit_alpha, components)

    if src == dst:
        return components

    path = _paths.get((src, dst), None)
    if path is None:
        return None

    for s, d in zip(path[:-1], path[1:]):
        func = conversions.get('%s>%s' % (s, d))
        if not func:
            return None
        components = stacked(func, components)

    return components
Ejemplo n.º 3
0
    def testImageConversions(self):
        # test that f([x, y, ...]) = [f(x), f(y), ...] for rectangular image arrays.

        for name, convert in colors.conversions.items():
            if name.find("CMYK") < 0:
                self._checkImageConversion(
                    4,
                    lambda p: vectorize(p, 1, lambda q: stacked(convert, q)))
Ejemplo n.º 4
0
    def testImageConversions(self):
        # test that f([x, y, ...]) = [f(x), f(y), ...] for rectangular image arrays.

        for name, convert in colors.conversions.items():
            if name.find('CMYK') < 0:
                self._checkImageConversion(4, lambda p: vectorize(p, 1, lambda q: stacked(convert, q)))