Esempio n. 1
0
    def test_alias_cap_square(self):
        """ Square caps should extend beyond the end of the line. by
            half the width of the line.
        """
        gc = GraphicsContextArray((6,6), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(2, 3)
        gc.line_to(4, 3)

        # Set up line
        gc. set_stroke_color((0.0, 0.0, 0.0)) # black
        gc.set_antialias(False)
        gc.set_line_width(2)
        gc.set_line_cap(kiva.CAP_SQUARE)
        gc.set_line_join(kiva.JOIN_MITER)

        gc.stroke_path()

        desired = array(((255, 255, 255, 255, 255, 255),
                         (255, 255, 255, 255, 255, 255),
                         (255,   0,   0,   0,   0, 255),
                         (255,   0,   0,   0,   0, 255),
                         (255, 255, 255, 255, 255, 255),
                         (255, 255, 255, 255, 255, 255)))

        actual = gc.bmp_array[:,:,0]
        self.assertRavelEqual(desired, actual)
Esempio n. 2
0
    def test_alias_width_two_outline_aa(self):
        """ When  width>1, alias text is drawn using a couple of different
            paths through the underlying C++ code. This test the faster of the
            two which uses the agg::rasterizer_outline_aa C++ code.  It is only
            used when 2<=width<=10, and cap is ROUND or BUTT, and join is MITER

            The C++ classes used in the underlying C++ code for this is
            agg::rasterizer_outline_aa and agg::renderer_outline_aa
        """
        gc = GraphicsContextArray((3, 2), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(0, 0)
        gc.line_to(3, 0)

        # Settings allow the 2nd fastest path.
        gc. set_stroke_color((0.0, 0.0, 0.0)) # black
        gc.set_antialias(False)
        gc.set_line_width(2)
        gc.set_line_cap(kiva.CAP_ROUND)
        gc.set_line_join(kiva.JOIN_MITER)

        gc.stroke_path()

        # test a single color channel.
        desired = array(((255, 255, 255),
                         (  0,   0,   0)))
        actual = gc.bmp_array[:,:,0]
        self.assertRavelEqual(actual, desired)
Esempio n. 3
0
    def test_alias_cap_round(self):
        """ Round caps should extend beyond the end of the line.  We
            don't really test the shape here.  To do this, a test of
            a wider line would be needed.

            fix me: This is rendering antialiased end points currently.
        """
        gc = GraphicsContextArray((6,6), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(2, 3)
        gc.line_to(4, 3)

        # Set up line
        gc. set_stroke_color((0.0, 0.0, 0.0)) # black
        gc.set_antialias(False)
        gc.set_line_width(2)
        gc.set_line_cap(kiva.CAP_ROUND)
        gc.set_line_join(kiva.JOIN_MITER)

        gc.stroke_path()

        desired = array(((255, 255, 255, 255, 255, 255),
                         (255, 255, 255, 255, 255, 255),
                         (255,   0,   0,   0,   0, 255),
                         (255,   0,   0,   0,   0, 255),
                         (255, 255, 255, 255, 255, 255),
                         (255, 255, 255, 255, 255, 255)))

        actual = gc.bmp_array[:,:,0]
        self.assertRavelEqual(desired, actual)
Esempio n. 4
0
    def test_alias_width_two_outline_aa(self):
        """ When  width>1, alias text is drawn using a couple of different
            paths through the underlying C++ code. This test the faster of the
            two which uses the agg::rasterizer_outline_aa C++ code.  It is only
            used when 2<=width<=10, and cap is ROUND or BUTT, and join is MITER

            The C++ classes used in the underlying C++ code for this is
            agg::rasterizer_outline_aa and agg::renderer_outline_aa
        """
        gc = GraphicsContextArray((3, 2), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(0, 0)
        gc.line_to(3, 0)

        # Settings allow the 2nd fastest path.
        gc.set_stroke_color((0.0, 0.0, 0.0))  # black
        gc.set_antialias(False)
        gc.set_line_width(2)
        gc.set_line_cap(kiva.CAP_ROUND)
        gc.set_line_join(kiva.JOIN_MITER)

        gc.stroke_path()

        # test a single color channel.
        desired = array(((255, 255, 255), (0, 0, 0)))
        actual = gc.bmp_array[:, :, 0]
        self.assertRavelEqual(actual, desired)
Esempio n. 5
0
def dash(sz=(1000, 1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0, 0.0, 0.0, 0.1))
    gc.set_stroke_color((0.0, 1.0, 0.0, 0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5
    pattern = width * numpy.array((5, 5))
    gc.set_line_dash(pattern, phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = perf_counter()
    gc.move_to(10, 10)
    gc.line_to(sz[0] - 10, sz[1] - 10)
    gc.line_to(10, sz[1] - 10)
    gc.close_path()
    gc.draw_path()
    t2 = perf_counter()
    with tempfile.NamedTemporaryFile(suffix=".bmp") as fid:
        gc.save(fid.name)
        image = Image.from_file(fid.name,
                                resist_width="weak",
                                resist_height="weak")
    tot_time = t2 - t1
    print("time:", tot_time)
    return image
Esempio n. 6
0
    def test_alias_cap_square(self):
        """ Square caps should extend beyond the end of the line. by
            half the width of the line.
        """
        gc = GraphicsContextArray((6, 6), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(2, 3)
        gc.line_to(4, 3)

        # Set up line
        gc.set_stroke_color((0.0, 0.0, 0.0))  # black
        gc.set_antialias(False)
        gc.set_line_width(2)
        gc.set_line_cap(kiva.CAP_SQUARE)
        gc.set_line_join(kiva.JOIN_MITER)

        gc.stroke_path()

        desired = array(
            ((255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255),
             (255, 0, 0, 0, 0, 255), (255, 0, 0, 0, 0, 255),
             (255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255)))

        actual = gc.bmp_array[:, :, 0]
        self.assertRavelEqual(desired, actual)
Esempio n. 7
0
    def test_antialias_width_slower_path(self):
        """ An anti-aliased horizontal line of width=1 has its energy
            centered between the bottom row of pixels and the next lower
            row of pixels (which is off the page).  It dumps half
            its energy in each, so we end up with a single line of
            127,127,127 pixel values in the last row of pixels.

            This particular set of flags is handled by the
            agg::rasterizer_scanline_aa path through the C++ code.

        """
        gc = GraphicsContextArray((3, 2), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(0, 0)
        gc.line_to(3, 0)

        # Set up stroke
        gc.set_stroke_color((0.0, 0.0, 0.0))  # black
        gc.set_antialias(True)
        gc.set_line_width(1)
        gc.set_line_cap(kiva.CAP_BUTT)
        gc.set_line_join(kiva.JOIN_BEVEL)

        gc.stroke_path()

        # test a single color channel.
        desired = array(((255, 255, 255), (127, 127, 127)))
        actual = gc.bmp_array[:, :, 0]
        self.assertRavelEqual(desired, actual)
Esempio n. 8
0
    def test_alias_cap_round(self):
        """ Round caps should extend beyond the end of the line.  We
            don't really test the shape here.  To do this, a test of
            a wider line would be needed.

            fix me: This is rendering antialiased end points currently.
        """
        gc = GraphicsContextArray((6, 6), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(2, 3)
        gc.line_to(4, 3)

        # Set up line
        gc.set_stroke_color((0.0, 0.0, 0.0))  # black
        gc.set_antialias(False)
        gc.set_line_width(2)
        gc.set_line_cap(kiva.CAP_ROUND)
        gc.set_line_join(kiva.JOIN_MITER)

        gc.stroke_path()

        desired = array(
            ((255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255),
             (255, 0, 0, 0, 0, 255), (255, 0, 0, 0, 0, 255),
             (255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255)))

        actual = gc.bmp_array[:, :, 0]
        self.assertRavelEqual(desired, actual)
Esempio n. 9
0
    def cap_equality_helper(self,
                            antialias,
                            width,
                            line_cap,
                            line_join,
                            size=(6, 6)):

        gc = GraphicsContextArray(size, pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(2, 3)
        gc.line_to(4, 3)

        # Settings allow the faster outline path through C++ code
        gc.set_stroke_color((0.0, 0.0, 0.0))  # black
        gc.set_antialias(antialias)
        gc.set_line_width(width)
        gc.set_line_cap(line_cap)
        gc.set_line_join(line_join)

        gc.stroke_path()
        return gc
Esempio n. 10
0
    def test_alias_width_two_scanline_aa(self):
        """ When width > 1, alias text is drawn using a couple of different
            paths through the underlying C++ code. This test the slower of the
            two which uses the agg::rasterizer_scanline_aa C++ code.  We've set
            the line join to bevel to trigger this path.
        """
        gc = GraphicsContextArray((3, 2), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(0, 0)
        gc.line_to(3, 0)

        # Settings allow the 2nd fastest path.
        gc.set_stroke_color((0.0, 0.0, 0.0))  # black
        gc.set_antialias(False)
        gc.set_line_width(2)
        gc.set_line_cap(kiva.CAP_ROUND)
        gc.set_line_join(kiva.JOIN_BEVEL)

        gc.stroke_path()

        # test a single color channel.
        desired = array(((255, 255, 255), (0, 0, 0)))
        actual = gc.bmp_array[:, :, 0]
        self.assertRavelEqual(actual, desired)
Esempio n. 11
0
    def test_antialias_width_slower_path(self):
        """ An anti-aliased horizontal line of width=1 has its energy
            centered between the bottom row of pixels and the next lower
            row of pixels (which is off the page).  It dumps half
            its energy in each, so we end up with a single line of
            127,127,127 pixel values in the last row of pixels.

            This particular set of flags is handled by the
            agg::rasterizer_scanline_aa path through the C++ code.

        """
        gc = GraphicsContextArray((3, 2), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(0, 0)
        gc.line_to(3, 0)

        # Set up stroke
        gc. set_stroke_color((0.0, 0.0, 0.0)) # black
        gc.set_antialias(True)
        gc.set_line_width(1)
        gc.set_line_cap(kiva.CAP_BUTT)
        gc.set_line_join(kiva.JOIN_BEVEL)

        gc.stroke_path()

        # test a single color channel.
        desired = array(((255, 255, 255),
                         (127, 127, 127)))
        actual = gc.bmp_array[:,:,0]
        self.assertRavelEqual(desired, actual)
Esempio n. 12
0
    def test_alias_width_two_scanline_aa(self):
        """ When width > 1, alias text is drawn using a couple of different
            paths through the underlying C++ code. This test the slower of the
            two which uses the agg::rasterizer_scanline_aa C++ code.  We've set
            the line join to bevel to trigger this path.
        """
        gc = GraphicsContextArray((3, 2), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(0, 0)
        gc.line_to(3, 0)

        # Settings allow the 2nd fastest path.
        gc. set_stroke_color((0.0, 0.0, 0.0)) # black
        gc.set_antialias(False)
        gc.set_line_width(2)
        gc.set_line_cap(kiva.CAP_ROUND)
        gc.set_line_join(kiva.JOIN_BEVEL)

        gc.stroke_path()

        # test a single color channel.
        desired = array(((255, 255, 255),
                         (  0,   0,   0)))
        actual = gc.bmp_array[:,:,0]
        self.assertRavelEqual(actual, desired)
Esempio n. 13
0
    def test_curve_to(self):
        """ curve_to

            conv_curve happens early in the agg rendering pipeline,
            so it isn't neccessary to test every combination of
            antialias, line_cap, line_join, etc.  If it works for
            one, we should be in good shape for the others (until
            the implementation is changed of course...)

        """
        gc = GraphicsContextArray((10, 10), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        x0, y0 = 1.0, 5.0
        x1, y1 = 4.0, 9.0
        x2, y2 = 6.0, 1.0
        x3, y3 = 9.0, 5.0
        gc.move_to(x0, y0)
        gc.curve_to(x1, y1, x2, y2, x3, y3)

        # Set up stroke
        gc.set_stroke_color((0.0, 0.0, 0.0))  # black
        gc.set_antialias(True)
        gc.set_line_width(1)
        gc.set_line_cap(kiva.CAP_BUTT)
        gc.set_line_join(kiva.JOIN_MITER)

        gc.stroke_path()

        gc.set_stroke_color((0.0, 1.0, 1.0))
        gc.move_to(x0, y0)
        gc.line_to(x1, y1)
        gc.move_to(x2, y2)
        gc.line_to(x3, y3)

        gc.stroke_path()
        # test a single color channel.
        # note: This is a "screen capture" from running this
        #       test.  It looks right, but hasn't been checked closely.
        desired = array([
            [255, 255, 255, 230, 255, 255, 255, 255, 255, 255],
            [255, 255, 231, 25, 212, 255, 255, 255, 255, 255],
            [255, 252, 65, 128, 255, 255, 255, 255, 255, 255],
            [255, 103, 26, 143, 229, 255, 255, 255, 255, 255],
            [180, 2, 118, 96, 23, 189, 255, 255, 205, 255],
            [255, 206, 255, 255, 189, 23, 97, 119, 2, 180],
            [255, 255, 255, 255, 255, 229, 142, 25, 103, 255],
            [255, 255, 255, 255, 255, 255, 127, 66, 252, 255],
            [255, 255, 255, 255, 255, 212, 26, 231, 255, 255],
            [255, 255, 255, 255, 255, 255, 231, 255, 255, 255],
        ])
        actual = gc.bmp_array[:, :, 0]
        self.assertRavelEqual(desired, actual)
Esempio n. 14
0
    def test_curve_to(self):
        """ curve_to

            conv_curve happens early in the agg rendering pipeline,
            so it isn't neccessary to test every combination of
            antialias, line_cap, line_join, etc.  If it works for
            one, we should be in good shape for the others (until
            the implementation is changed of course...)

        """
        gc = GraphicsContextArray((10, 10), pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        x0, y0 = 1.0, 5.0
        x1, y1 = 4.0, 9.0
        x2, y2 = 6.0, 1.0
        x3, y3 = 9.0, 5.0
        gc.move_to(x0, y0)
        gc.curve_to(x1, y1, x2, y2, x3, y3);

        # Set up stroke
        gc. set_stroke_color((0.0, 0.0, 0.0)) # black
        gc.set_antialias(True)
        gc.set_line_width(1)
        gc.set_line_cap(kiva.CAP_BUTT)
        gc.set_line_join(kiva.JOIN_MITER)

        gc.stroke_path()

        gc. set_stroke_color((0.0, 1.0, 1.0))
        gc.move_to(x0, y0)
        gc.line_to(x1, y1)
        gc.move_to(x2, y2)
        gc.line_to(x3, y3)

        gc.stroke_path()
        # test a single color channel.
        # note: This is a "screen capture" from running this
        #       test.  It looks right, but hasn't been check closely.
        desired = array([[255, 255, 255, 230, 255, 255, 255, 255, 255, 255],
                         [255, 255, 231,  25, 212, 255, 255, 255, 255, 255],
                         [255, 252,  65, 128, 255, 255, 255, 255, 255, 255],
                         [255, 103,  26, 143, 229, 255, 255, 255, 255, 255],
                         [179,   2, 115,  96,  23, 189, 255, 255, 204, 255],
                         [255, 205, 255, 255, 189,  23,  97, 116,   2, 179],
                         [255, 255, 255, 255, 255, 229, 142,  25, 103, 255],
                         [255, 255, 255, 255, 255, 255, 127,  66, 252, 255],
                         [255, 255, 255, 255, 255, 212,  26, 231, 255, 255],
                         [255, 255, 255, 255, 255, 255, 231, 255, 255, 255]])
        actual = gc.bmp_array[:,:,0]
        self.assertRavelEqual(desired, actual)
Esempio n. 15
0
    def cap_equality_helper(self, antialias, width, line_cap, line_join,
                                 size=(6,6)):

        gc = GraphicsContextArray(size, pix_format="rgb24")

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        # single horizontal line across bottom of buffer
        gc.move_to(2, 3)
        gc.line_to(4, 3)

        # Settings allow the faster outline path through C++ code
        gc. set_stroke_color((0.0, 0.0, 0.0)) # black
        gc.set_antialias(antialias)
        gc.set_line_width(width)
        gc.set_line_cap(line_cap)
        gc.set_line_join(line_join)

        gc.stroke_path()
        return gc
Esempio n. 16
0
def dash(sz=(1000,1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0,0.0,0.0,0.1))
    gc.set_stroke_color((0.0,1.0,0.0,0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5;
    pattern = width * numpy.array((5,5))
    gc.set_line_dash(pattern,phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = time.clock()
    gc.move_to(10,10)
    gc.line_to(sz[0]-10,sz[1]-10)
    gc.line_to(10,sz[1]-10)
    gc.close_path()
    gc.draw_path()
    t2 = time.clock()
    gc.save("dash.bmp")
    tot_time = t2 - t1
    print 'time:', tot_time
def dash(sz=(1000, 1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0, 0.0, 0.0, 0.1))
    gc.set_stroke_color((0.0, 1.0, 0.0, 0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5
    pattern = width * numpy.array((5, 5))
    gc.set_line_dash(pattern, phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = time.clock()
    gc.move_to(10, 10)
    gc.line_to(sz[0] - 10, sz[1] - 10)
    gc.line_to(10, sz[1] - 10)
    gc.close_path()
    gc.draw_path()
    t2 = time.clock()
    gc.save("dash.bmp")
    tot_time = t2 - t1
    print('time:', tot_time)