Exemple #1
0
def test_fx_red(ctx):
    #img = Image.new((64, 64))  # TODO make the gradient, oops
    black = RGBColor(0., 0., 0.)
    white = RGBColor(1., 1., 1.)
    img = gradient((64, 64), black, white)
    img = image_filter(lambda *a: black)(*img, channel=Channel.blue | Channel.green)
    ctx.compare(img, 'fx_red.miff')
Exemple #2
0
 def color(self):
     # XXX this needs to do something special to handle non-rgba images
     if self._pixel == ffi.NULL:
         raise ValueError("Pixel has expired")
     array = ffi.new("double[]", 4)
     lib.sanpera_pixel_to_doubles(self._pixel, array)
     return RGBColor(*array)
Exemple #3
0
    def new(cls, size, fill=None):
        """Create a new image (with one frame) of the given size."""
        size = Size.coerce(size)

        image_info = blank_image_info()
        magick_pixel = blank_magick_pixel()

        if fill is None:
            # TODO need a way to explicitly create a certain color
            fill = RGBColor(0., 0., 0., 0.)

        fill._populate_magick_pixel(magick_pixel)

        ptr = lib.NewMagickImage(image_info, size.width, size.height, magick_pixel)
        magick_raise(ptr.exception)

        return cls(ptr)
Exemple #4
0
    def new(cls, size, fill=None):
        """Create a new image (with one frame) of the given size."""
        size = Size.coerce(size)

        image_info = blank_image_info()
        magick_pixel = blank_magick_pixel()

        if fill is None:
            # TODO need a way to explicitly create a certain color
            fill = RGBColor(0., 0., 0., 0.)

        fill._populate_magick_pixel(magick_pixel)

        ptr = lib.NewMagickImage(image_info, size.width, size.height,
                                 magick_pixel)
        magick_raise(ptr.exception)

        return cls(ptr)
Exemple #5
0
def test_color_fx_math(ctx):
    gold = RGBColor.parse('gold')
    def gold_filter(self, *a):
        return gold * 0.7

    img = get_image('test.png')
    img[0].translucent = False
    img = evaluate(gold_filter, *img)
    ctx.compare(img, 'color_fx_math.miff')
Exemple #6
0
def test_color_fx_constant(ctx):
    gold = RGBColor.parse('gold')

    def gold_filter(self, *a):
        return gold

    img = get_image('test.png')
    img[0].translucent = False
    img = evaluate(gold_filter, *img)
    ctx.compare(img, 'color_fx_constant.miff')
Exemple #7
0
def test_color_fx_constant(ctx):
    gold = RGBColor.parse('gold')

    @image_filter
    def gold_filter(self, *a):
        return gold

    img = get_image('test.png')
    img[0].translucent = False
    img = gold_filter(*img)
    ctx.compare(img, 'color_fx_constant.miff')
Exemple #8
0
def test_color_fx_math(ctx):
    gold = RGBColor.parse('gold')

    @image_filter
    def gold_filter(self, *a):
        return gold * 0.7

    img = get_image('test.png')
    img[0].translucent = False
    img = gold_filter(*img)
    ctx.compare(img, 'color_fx_math.miff')
Exemple #9
0
    def __getitem__(self, point):
        point = Vector.coerce(point)

        px = ffi.new("PixelPacket *")

        # TODO retval is t/f
        with magick_try() as exc:
            lib.GetOneCacheViewAuthenticPixel(self._ptr, point.x, point.y, px,
                                              exc.ptr)

        array = ffi.new("double[]", 4)
        lib.sanpera_pixel_to_doubles(px, array)
        return RGBColor(*array)
Exemple #10
0
def test_pixel_iter():
    """Does iterating over pixels appear to work?"""
    img = Image.read(util.find_image('terminal.gif'))
    pixel_iter = iter(img[0].pixels)

    white = RGBColor(1., 1., 1.)

    px = next(pixel_iter)
    assert px.point == Vector(0, 0)
    assert px.color == white

    px = next(pixel_iter)
    assert px.point == Vector(1, 0)
    assert px.color == white
Exemple #11
0
def test_wheat(ctx):
    img = Image.new((100, 100), fill=RGBColor.parse('wheat'))
    ctx.compare(img, 'canvas_wheat.miff')
Exemple #12
0
def test_fx_navy(ctx):
    img = Image.new((64, 64), fill=RGBColor(0., 0., 0.))
    gray = RGBColor(0.5, 0.5, 0.5)
    img = image_filter(lambda *a: gray)(*img, channel=Channel.blue)
    ctx.compare(img, 'fx_navy.miff')
Exemple #13
0
def test_khaki_to_tomato(ctx):
    img = Image.new((100, 100), fill=RGBColor.parse('khaki'))
    img[0].replace_color(RGBColor.parse('khaki'), RGBColor.parse('tomato'))
    ctx.compare(img, 'canvas_opaque.miff')
Exemple #14
0
def test_wheat(ctx):
    img = Image.new((100, 100), fill=RGBColor.parse('wheat'))
    ctx.compare(img, 'canvas_wheat.miff')
Exemple #15
0
def test_khaki(ctx):
    img = Image.new((100, 100), fill=RGBColor.parse('khaki'))
    ctx.compare(img, 'canvas_khaki.miff')
Exemple #16
0
def test_khaki(ctx):
    img = Image.new((100, 100), fill=RGBColor.parse('khaki'))
    ctx.compare(img, 'canvas_khaki.miff')
Exemple #17
0
def test_pixel_get():
    """Does random pixel inspection work?"""
    img = Image.read(util.find_image('terminal.gif'))
    assert img[0].pixels[11, 6] == RGBColor(1., 0., 0.)
Exemple #18
0
def test_khaki_to_tomato(ctx):
    img = Image.new((100, 100), fill=RGBColor.parse('khaki'))
    img[0].replace_color(RGBColor.parse('khaki'), RGBColor.parse('tomato'))
    ctx.compare(img, 'canvas_opaque.miff')
Exemple #19
0
def test_color_colorize(ctx):
    img = get_image('test.png')
    img[0].translucent = False
    img = Colorize(RGBColor.parse('sienna'), 1.0)(*img)
    ctx.compare(img, 'color_colorize.miff')
Exemple #20
0
def test_color_colorize(ctx):
    img = get_image('test.png')
    img[0].translucent = False
    img = Colorize(RGBColor.parse('sienna'), 1.0)(*img)
    ctx.compare(img, 'color_colorize.miff')