Skip to content

Commit

Permalink
Antigrain-lite test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Bourdeauducq committed Mar 25, 2013
1 parent facb816 commit 10f9d16
Show file tree
Hide file tree
Showing 9 changed files with 2,337 additions and 874 deletions.
12 changes: 9 additions & 3 deletions Makefile
@@ -1,10 +1,12 @@
MISPDIR=.
include $(MISPDIR)/common.mak

OBJECTS=crt0.o isr.o luainit.o main.o
OURLIBS=m mm yaffs2 glue lua lfs freetype
OBJECTS=crt0.o isr.o luainit.o agg_test.o main.o
OURLIBS=m mm yaffs2 glue lua lfs agl

CFLAGS+=-I$(MISPDIR)/libm/include -I$(MISPDIR)/libmm/include -I$(MISPDIR)/libglue/include -I$(LUADIR)/src -I$(MISPDIR)/liblfs/include
INCFLAGS=-I$(MISPDIR)/libm/include -I$(MISPDIR)/libmm/include -I$(MISPDIR)/libglue/include -I$(LUADIR)/src -I$(MISPDIR)/liblfs/include -I$(MISPDIR)/libagl/include
CFLAGS+=$(INCFLAGS)
CXXFLAGS+=$(INCFLAGS)

all: misp.bin

Expand All @@ -25,9 +27,13 @@ misp.elf: linker.ld $(OBJECTS) libs
--start-group -lbase -lcompiler-rt $(addprefix -l,$(OURLIBS)) --end-group
chmod -x $@

%.o: %.cpp
$(compilexx-dep)

%.o: %.c
$(compile-dep)


libs:
set -e; \
for lib in $(OURLIBS); do \
Expand Down
141 changes: 141 additions & 0 deletions agg_test.cpp
@@ -0,0 +1,141 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <hw/csr.h>
#include "agg.h"

enum
{
width = 640,
height = 480
};


double random(double min, double max)
{
int r = (rand() << 15) | rand();
return ((r & 0xFFFFFFF) / double(0xFFFFFFF + 1)) * (max - min) + min;
}


void draw_ellipse(agg::rasterizer& ras,
double x, double y,
double rx, double ry)
{
int i;
ras.move_to_d(x + rx, y);

// Here we have a fixed number of approximation steps, namely 360
// while in reality it's supposed to be smarter.
for(i = 1; i < 360; i++)
{
double a = double(i) * 3.1415926 / 180.0;
ras.line_to_d(x + cos(a) * rx, y + sin(a) * ry);
}
}


void draw_line(agg::rasterizer& ras,
double x1, double y1,
double x2, double y2,
double width)
{

double dx = x2 - x1;
double dy = y2 - y1;
double d = sqrt(dx*dx + dy*dy);

dx = width * (y2 - y1) / d;
dy = width * (x2 - x1) / d;

ras.move_to_d(x1 - dx, y1 + dy);
ras.line_to_d(x2 - dx, y2 + dy);
ras.line_to_d(x2 + dx, y2 - dy);
ras.line_to_d(x1 + dx, y1 - dy);
}

static void start_fb(unsigned char *addr)
{
fb_base_write((unsigned int)addr);
fb_enable_write(1);
}

extern "C" void agg_test(void);
void agg_test(void)
{
// Allocate the framebuffer
unsigned char* buf = new unsigned char[width * height * 4];

start_fb(buf);

// Create the rendering buffer
agg::rendering_buffer rbuf(buf, width, height, width * 4);

// Create the renderer and the rasterizer
agg::renderer<agg::span_rgba32> ren(rbuf);
agg::rasterizer ras;

// Setup the rasterizer
ras.gamma(1.3);
ras.filling_rule(agg::fill_even_odd);

ren.clear(agg::rgba8(255, 255, 255));

int i;

// Draw random polygons
for(i = 0; i < 10; i++)
{
int n = rand() % 6 + 3;

// Make the polygon. One can call move_to() more than once.
// In this case the rasterizer behaves like Win32 API PolyPolygon().
ras.move_to_d(random(-30, rbuf.width() + 30),
random(-30, rbuf.height() + 30));

int j;
for(j = 1; j < n; j++)
{
ras.line_to_d(random(-30, rbuf.width() + 30),
random(-30, rbuf.height() + 30));
}

// Render
ras.render(ren, agg::rgba8(rand() & 0xFF,
rand() & 0xFF,
rand() & 0xFF,
rand() & 0xFF));
}

// Draw random ellipses
for(i = 0; i < 50; i++)
{
draw_ellipse(ras,
random(-30, rbuf.width() + 30),
random(-30, rbuf.height() + 30),
random(3, 50),
random(3, 50));
ras.render(ren, agg::rgba8(rand() & 0x7F,
rand() & 0x7F,
rand() & 0x7F,
(rand() & 0x7F) + 100));
}

// Draw random straight lines
for(i = 0; i < 20; i++)
{
draw_line(ras,
random(-30, rbuf.width() + 30),
random(-30, rbuf.height() + 30),
random(-30, rbuf.width() + 30),
random(-30, rbuf.height() + 30),
random(0.1, 10));

ras.render(ren, agg::rgba8(rand() & 0x7F,
rand() & 0x7F,
rand() & 0x7F));
}

delete [] buf;
}

22 changes: 22 additions & 0 deletions libagl/Makefile
@@ -0,0 +1,22 @@
MISPDIR=..
include $(MISPDIR)/common.mak

CXXFLAGS+=-I$(MISPDIR)/libagl/include -I$(MISPDIR)/libm/include
OBJECTS=agg.o

all: libagl.a

# pull in dependency info for *existing* .o files
-include $(OBJECTS:.o=.d)

libagl.a: $(OBJECTS)
$(AR) clr libagl.a $(OBJECTS)
$(RANLIB) libagl.a

%.o: %.cpp
$(compilexx-dep)

.PHONY: clean

clean:
rm -f $(OBJECTS) $(OBJECTS:.o=.d) libagl.a .*~ *~

0 comments on commit 10f9d16

Please sign in to comment.