Exemple #1
0
def main4():
    """ Test drawing an rgb24 into a bgra32"""
    from PIL import Image
    pil_img = Image.open('doubleprom_soho_full.jpg')
    img = fromstring(pil_img.tostring(), UInt8)
    img = img.resize((pil_img.size[1], pil_img.size[0], 3))
    print('typecode:', typecode(img), iscontiguous(img))
    print(shape(img))
    agg_img = agg.Image(img, "rgb24", interpolation_scheme="simple")
    gc = agg.GraphicsContextArray((1000, 1000))
    N = 1
    t1 = time.clock()
    for i in range(N):
        with gc:
            #gc.rotate_ctm(.2)
            #gc.set_alpha(0.5)
            gc.draw_image(agg_img)
            #print pil_img.getpixel((300,300)), img[300,300], gc.bmp_array[300,300]
            gc.translate_ctm(150, 300)
            gc.scale_ctm(10, 10)
            gc.set_fill_color((0.0, 0, 1.0, .5))
            #gc.show_text("SUN")
    t2 = time.clock()
    print("images per second: %g" % (N / (t2 - t1)))
    gc.save('sun2.bmp')
Exemple #2
0
def main3():

    from PIL import Image
    pil_img = Image.open('doubleprom_soho_full.jpg')
    img = fromstring(pil_img.tostring(), UInt8)
    img = img.resize((pil_img.size[1], pil_img.size[0], 3))

    alpha = ones(pil_img.size, UInt8) * 255
    img = concatenate((img[:, :, ::-1], alpha[:, :, NewAxis]), -1).copy()
    print('typecode:', typecode(img), iscontiguous(img))
    print(shape(img))
    agg_img = agg.Image(img, "bgra32", interpolation_scheme="simple")
    gc = agg.GraphicsContextArray((760, 760))
    N = 100
    gc.show_text("SUN")
    t1 = time.clock()
    for i in range(N):
        with gc:
            #gc.rotate_ctm(.2)
            gc.set_alpha(1.0)
            gc.draw_image(agg_img)
            #print pil_img.getpixel((300,300)), img[300,300], gc.bmp_array[300,300]
            gc.translate_ctm(150, 300)
            gc.scale_ctm(10, 10)
            gc.set_fill_color((0.0, 0, 1.0, .25))
            #gc.show_text("SUN")
    t2 = time.clock()
    print("images per second: %g" % (N / (t2 - t1)))
    gc.save('sun3.bmp')
Exemple #3
0
    def do_check_format(self, fmt):
        # FIXME:

        gc = agg.GraphicsContextArray((2, 2), fmt)
        gc.set_stroke_color((1.0, 0.0, 0.0))
        gc.move_to(0.0, 0.5)
        gc.line_to(2.0, 0.5)
        gc.stroke_path()
        gc.save(fmt + ".png")
        img = agg.Image(fmt + ".png")
        os.unlink(fmt + ".png")
        self.assertEqual(list(ravel(img.bmp_array)),
                         self.format_output_map[fmt])