clean up, ellipse comparison test

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11246 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-02-04 15:40:37 +00:00
parent eafe61c06b
commit 2ad954608f
+124 -163
View File
@@ -17,22 +17,21 @@ const pattern kStripes = (pattern){ { 0xc7, 0x8f, 0x1f, 0x3e, 0x7c, 0xf8, 0xf1,
const pattern kDotted = (pattern){ { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa } }; const pattern kDotted = (pattern){ { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa } };
const pattern kDottedBigger = (pattern){ { 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc } }; const pattern kDottedBigger = (pattern){ { 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc } };
// test_straight_lines
template<class Surface> template<class Surface>
bigtime_t bigtime_t
test_straight_lines(Surface& s, uint32 width, uint32 height, test_straight_lines(Surface& s, uint32 width, uint32 height)
float penSize, drawing_mode mode,
source_alpha alphaSrcMode, alpha_function alphaFncMode,
rgb_color highColor, rgb_color lowColor, pattern pat)
{ {
bigtime_t now = system_time(); bigtime_t now = system_time();
s.SetPenSize(penSize); s.SetPenSize(1.0);
s.SetDrawingMode(mode); s.SetDrawingMode(B_OP_COPY);
s.SetBlendingMode(alphaSrcMode, alphaFncMode); s.SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
s.SetHighColor(highColor); s.SetHighColor(0, 0, 0, 255);
s.SetLowColor(lowColor); s.SetLowColor(130, 0, 20, 255);
const pattern pat = B_SOLID_HIGH;
for (uint32 y = 0; y <= height; y += 5) { for (uint32 y = 0; y <= height; y += 5) {
s.StrokeLine(BPoint(0, y), BPoint(width - 1, y), pat); s.StrokeLine(BPoint(0, y), BPoint(width - 1, y), pat);
@@ -46,22 +45,52 @@ test_straight_lines(Surface& s, uint32 width, uint32 height,
return system_time() - now; return system_time() - now;
} }
// test_ellipses
template<class Surface> template<class Surface>
bigtime_t bigtime_t
test_lines(Surface& s, uint32 width, uint32 height, test_ellipses(Surface& s, uint32 width, uint32 height)
float penSize, drawing_mode mode,
source_alpha alphaSrcMode, alpha_function alphaFncMode,
rgb_color highColor, rgb_color lowColor, pattern pat)
{ {
bigtime_t now = system_time(); bigtime_t now = system_time();
s.SetPenSize(penSize); s.SetPenSize(2.0);
s.SetDrawingMode(mode); s.SetDrawingMode(B_OP_COPY);
s.SetBlendingMode(alphaSrcMode, alphaFncMode); s.SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
s.SetHighColor(highColor); s.SetHighColor(0, 0, 0, 255);
s.SetLowColor(lowColor); s.SetLowColor(130, 0, 20, 255);
const pattern pat = B_SOLID_HIGH;
BPoint center(floorf(width / 2.0), floorf(height / 2.0));
float xRadius = width / 2.0;
float yRadius = height / 2.0;
uint32 count = 40;
for (uint32 i = 0; i < count; i ++) {
s.StrokeEllipse(center, xRadius * (i / (float)count),
yRadius * (i / (float)count), pat);
}
s.Sync();
return system_time() - now;
}
// test_lines
template<class Surface>
bigtime_t
test_lines(Surface& s, uint32 width, uint32 height)
{
bigtime_t now = system_time();
s.SetPenSize(1.0);
s.SetDrawingMode(B_OP_COPY);
s.SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
s.SetHighColor(0, 0, 0, 255);
s.SetLowColor(130, 0, 20, 255);
const pattern pat = B_SOLID_HIGH;
for (uint32 y = 0; y <= height; y += 10) { for (uint32 y = 0; y <= height; y += 10) {
s.StrokeLine(BPoint(0, 0), BPoint(width, y), pat); s.StrokeLine(BPoint(0, 0), BPoint(width, y), pat);
@@ -77,50 +106,42 @@ test_lines(Surface& s, uint32 width, uint32 height,
return system_time() - now; return system_time() - now;
} }
// test
template<class Surface> template<class Surface>
bigtime_t bigtime_t
test(Surface& s, test(Surface& s, uint32 width, uint32 height, BBitmap* testBitmap)
uint32 width, uint32 height, BPoint origin, float scale,
float penSize,
rgb_color lineColor1, rgb_color lineColor2,
BRect rect, BRect roundRect,
rgb_color rectColorH, rgb_color rectColorL,
float angle, float span, rgb_color arcColor,
rgb_color ellipseColorH, rgb_color ellipseColorL,
BPoint center, float xRadius, float yRadius,
rgb_color roundRectColorH, rgb_color roundRectColorL,
BFont* font, BPoint stringLocation1, BPoint stringLocation2,
const char* string1, const char* string2,
rgb_color textColor1, rgb_color textColor2, rgb_color alphaColor,
BBitmap* testBitmap, BRect testBitmapCrop, BRect testBitmapDestRect)
{ {
bigtime_t now = system_time(); bigtime_t now = system_time();
// TODO: Painter behaves differently when origin has subpixel offset
// BPoint origin(20.3, 10.8);
BPoint origin(20, 10);
BPoint center(width / 2.0, height / 2.0);
float xRadius = 30.0;
float yRadius = 20.0;
s.SetOrigin(origin); s.SetOrigin(origin);
s.SetScale(scale); s.SetScale(1.0);
s.SetDrawingMode(B_OP_COPY); s.SetDrawingMode(B_OP_COPY);
// s.SetDrawingMode(B_OP_SUBTRACT); // s.SetDrawingMode(B_OP_SUBTRACT);
// s.SetDrawingMode(B_OP_OVER); // s.SetDrawingMode(B_OP_OVER);
s.SetHighColor(lineColor1); s.SetHighColor(20, 20, 20, 255);
s.SetLowColor(lineColor2); s.SetLowColor(220, 120, 80, 255);
for (uint32 y = 0; y <= height / 2; y += 10) for (uint32 y = 0; y <= height / 2; y += 10)
s.StrokeLine(BPoint(0, 0), BPoint(width / 2, y)/*, kDottedBigger*/); s.StrokeLine(BPoint(0, 0), BPoint(width / 2, y)/*, kDottedBigger*/);
for (uint32 x = 0; x <= width; x += 10) for (uint32 x = 0; x <= width; x += 10)
s.StrokeLine(BPoint(0, 0), BPoint(x, height)/*, kDottedBigger*/); s.StrokeLine(BPoint(0, 0), BPoint(x, height)/*, kDottedBigger*/);
s.SetPenSize(penSize * 5); s.SetPenSize(1.0 * 5);
s.SetHighColor(rectColorH); s.SetHighColor(255, 0, 0, 255);
s.SetLowColor(rectColorL); s.SetLowColor(0, 0, 255, 255);
// s.SetScale(1.0); // s.SetScale(1.0);
// s.SetOrigin(B_ORIGIN); // s.SetOrigin(B_ORIGIN);
// s.SetDrawingMode(B_OP_INVERT); // s.SetDrawingMode(B_OP_INVERT);
s.SetDrawingMode(B_OP_COPY); s.SetDrawingMode(B_OP_COPY);
// s.StrokeRect(rect); // s.StrokeRect(BRect(20.2, 45.6, 219.0, 139.0));
s.StrokeRect(rect, kStripes); s.StrokeRect(BRect(20.2, 45.6, 219.0, 139.0), kStripes);
// s.ConstrainClipping(noClip); // s.ConstrainClipping(noClip);
/* s.SetPenLocation(BPoint(230.0, 30.0)); /* s.SetPenLocation(BPoint(230.0, 30.0));
@@ -129,30 +150,41 @@ test(Surface& s,
s.StrokeLine(BPoint(230.0, 50.0)); s.StrokeLine(BPoint(230.0, 50.0));
s.StrokeLine(BPoint(230.0, 30.0));*/ s.StrokeLine(BPoint(230.0, 30.0));*/
s.SetHighColor(ellipseColorH); s.SetHighColor(255, 255, 0, 255);
s.SetLowColor(ellipseColorL); s.SetLowColor(128, 0, 50, 255);
// s.SetDrawingMode(B_OP_OVER); // s.SetDrawingMode(B_OP_OVER);
s.SetDrawingMode(B_OP_ERASE); s.SetDrawingMode(B_OP_ERASE);
s.StrokeEllipse(center, xRadius, yRadius, kDottedBigger); s.StrokeEllipse(center, xRadius, yRadius, kDottedBigger);
s.SetHighColor(arcColor); s.SetHighColor(255, 0, 0, 255);
s.SetDrawingMode(B_OP_INVERT); s.SetDrawingMode(B_OP_INVERT);
s.FillArc(center, xRadius * 2, yRadius * 2, angle, span); s.FillArc(center, xRadius * 2, yRadius * 2, 40.0, 230.0);
// s.StrokeArc(center, xRadius * 2, yRadius * 2, angle, span); // s.StrokeArc(center, xRadius * 2, yRadius * 2, 40.0, 230.0);
s.SetDrawingMode(B_OP_OVER); s.SetDrawingMode(B_OP_OVER);
s.SetPenSize(2.0); s.SetPenSize(2.0);
s.StrokeEllipse(center, xRadius * 3, yRadius * 2); s.StrokeEllipse(center, xRadius * 3, yRadius * 2);
// s.FillEllipse(center, xRadius * 3, yRadius * 2); // s.FillEllipse(center, xRadius * 3, yRadius * 2);
// s.StrokeLine(bounds.RightTop()); // s.StrokeLine(bounds.RightTop());
// s.FillRect(rect); // s.FillRect(rect);
s.SetHighColor(roundRectColorH); s.SetHighColor(0, 0, 255, 255);
s.SetLowColor(roundRectColorL); s.SetLowColor(255, 0, 0, 255);
s.SetPenSize(1.0); s.SetPenSize(1.0);
// s.SetDrawingMode(B_OP_SELECT); // s.SetDrawingMode(B_OP_SELECT);
s.StrokeRoundRect(roundRect, 40, 40); s.StrokeRoundRect(BRect(40, 100, 250, 220.0), 40, 40);
// s.FillRoundRect(roundRect, 40, 40); // s.FillRoundRect(BRect(40, 100, 250, 220.0), 40, 40);
// text rendering
const char* string1 = "The Quick Brown Fox...";
const char* string2 = "jumps!";
BPoint stringLocation1(10.0, 220.0);
BPoint stringLocation2(30.0 / 2.5, 115.0 / 2.5);
BFont font(be_plain_font);
font.SetSize(12.0);
font.SetRotation(8.0);
// font.SetFamilyAndStyle(1);
s.SetFont(font); s.SetFont(font);
s.SetHighColor(textColor1); s.SetHighColor(91, 105, 98, 120);
s.SetDrawingMode(B_OP_OVER); s.SetDrawingMode(B_OP_OVER);
s.DrawString(string1, stringLocation1); s.DrawString(string1, stringLocation1);
s.DrawString(string2); s.DrawString(string2);
@@ -160,7 +192,7 @@ test(Surface& s,
// s.SetScale(2.5); // s.SetScale(2.5);
s.SetDrawingMode(B_OP_INVERT); s.SetDrawingMode(B_OP_INVERT);
s.SetHighColor(textColor2); s.SetHighColor(200, 200, 200, 255);
s.DrawString("H", stringLocation2); s.DrawString("H", stringLocation2);
s.DrawString("e"); s.DrawString("e");
s.DrawString("l"); s.DrawString("l");
@@ -173,15 +205,19 @@ test(Surface& s,
s.DrawString("s"); s.DrawString("s");
s.DrawString("e"); s.DrawString("e");
s.DrawString("!"); s.DrawString("!");
// do the char locations match up?
// s.SetHighColor(0, 60, 240); // s.SetHighColor(0, 60, 240);
// s.DrawString("Hello Nurse!", stringLocation2); // s.DrawString("Hello Nurse!", stringLocation2);
// bitmap drawing // bitmap drawing
BRect testBitmapCrop(bitmap->Bounds());
testBitmapCrop.left += 20.0;
BRect testBitmapDestRect(testBitmapCrop);
testBitmapDestRect.OffsetBy(50, 20);
s.SetScale(1.5); s.SetScale(1.5);
s.SetDrawingMode(B_OP_ALPHA); s.SetDrawingMode(B_OP_ALPHA);
// s.SetDrawingMode(B_OP_SELECT); s.SetHighColor(0, 0, 0, 120);
// s.SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
s.SetHighColor(alphaColor);
s.DrawBitmap(testBitmap, testBitmapCrop, testBitmapDestRect); s.DrawBitmap(testBitmap, testBitmapCrop, testBitmapDestRect);
s.Sync(); s.Sync();
@@ -201,17 +237,16 @@ main(int argc, char **argv)
// It takes a bit to scan through the font files; // It takes a bit to scan through the font files;
// "true" means to do the font scanning inline, not // "true" means to do the font scanning inline, not
// in a separate thread. // in a separate thread.
fprintf(stdout, "scanning font files..."); fprintf(stdout, "scanning font files...");
fflush(stdout); fflush(stdout);
FontManager::CreateDefault(true); FontManager::CreateDefault(true);
fprintf(stdout, "done\n"); fprintf(stdout, "done\n");
BRect bounds(0.0, 0.0, 319.0, 239.0); BRect bounds(0.0, 0.0, 319.0, 239.0);
// test the clipping
BRegion noClip(bounds); BRegion noClip(bounds);
// BRegion clip(BRect(50, 50, 100, 100));
// clip.Include(BRect(20, 10, 80, 110));
// clip.Include(BRect(120, -20, 180, 250));
int32 clipCount = 5; int32 clipCount = 5;
BRegion clip; BRegion clip;
float h = bounds.Width() / clipCount; float h = bounds.Width() / clipCount;
@@ -232,41 +267,8 @@ fprintf(stdout, "done\n");
b.InsetBy(-hInset, 0.0); b.InsetBy(-hInset, 0.0);
clip.Include(b); clip.Include(b);
} }
float penSize = 1.0;
float scale = 1.0;
rgb_color lineColor1 = (rgb_color){ 20, 20, 20, 255 };
rgb_color lineColor2 = (rgb_color){ 220, 120, 80, 255 };
rgb_color textColor1 = (rgb_color){ 91, 105, 98, 120 };
rgb_color textColor2 = (rgb_color){ 200, 200, 200, 255 };
// rgb_color textColor2 = (rgb_color){ 200, 200, 200, 255 };
rgb_color rectColorH = (rgb_color){ 255, 0, 0, 255 };
rgb_color rectColorL = (rgb_color){ 0, 0, 255, 255 };
rgb_color arcColor = (rgb_color){ 255, 0, 0, 255 };
rgb_color ellipseColorH = (rgb_color){ 255, 255, 0, 255 };
rgb_color ellipseColorL = (rgb_color){ 128, 0, 50, 255 };
rgb_color roundRectColorH = (rgb_color){ 0, 0, 255, 255 };
rgb_color roundRectColorL = (rgb_color){ 255, 0, 0, 255 };
rgb_color alphaColor = (rgb_color){ 0, 0, 0, 120 };
// TODO: Painter behaves differently when origin has subpixel offset
// BPoint origin(20.3, 10.8);
BPoint origin(20, 10);
BRect rect(20.2, 45.6, 219.0, 139.0);
BRect roundRect(40, 100, 250, 220.0);
BPoint center(bounds.Width() / 2.0, bounds.Height() / 2.0);
float xRadius = 30.0;
float yRadius = 20.0;
float angle = 40.0;
float span = 230.0;
const char* string1 = "The Quick Brown Fox...";
const char* string2 = "jumps!";
BPoint stringLocation1(10.0, 220.0);
BPoint stringLocation2(30.0 / 2.5, 115.0 / 2.5);
BFont font(be_plain_font);
font.SetSize(12.0);
font.SetRotation(8.0);
// font.SetFamilyAndStyle(1);
// prepare a test bitmap for bitmap rendering
BBitmap* testBitmap = new BBitmap(BRect(20, 0, 150, 50), 0, B_RGB32); BBitmap* testBitmap = new BBitmap(BRect(20, 0, 150, 50), 0, B_RGB32);
// fill testBitmap with content // fill testBitmap with content
uint8* bits = (uint8*)testBitmap->Bits(); uint8* bits = (uint8*)testBitmap->Bits();
@@ -291,15 +293,7 @@ fprintf(stdout, "done\n");
*(uint32*)(&bits[(bitmapHeight - 1) * bpr]) = 0; *(uint32*)(&bits[(bitmapHeight - 1) * bpr]) = 0;
*(uint32*)(&bits[(bitmapHeight - 1) * bpr + (bitmapWidth - 1) * 4]) = 0; *(uint32*)(&bits[(bitmapHeight - 1) * bpr + (bitmapWidth - 1) * 4]) = 0;
BRect testBitmapCrop(testBitmap->Bounds()); // create a frame buffer
testBitmapCrop.left += 20.0;
BRect testBitmapDestRect = testBitmapCrop;
testBitmapDestRect.OffsetBy(50, 20);
// testBitmapDestRect.OffsetTo(0, 0);
// testBitmapDestRect.right = testBitmapDestRect.left + testBitmapDestRect.Width() * 2;
// testBitmapDestRect.bottom = testBitmapDestRect.top + testBitmapDestRect.Height() * 2;
// frame buffer
BBitmap* bitmap = new BBitmap(bounds, B_RGB32); BBitmap* bitmap = new BBitmap(bounds, B_RGB32);
//memset(bitmap->Bits(), 0, bitmap->BitsLength()); //memset(bitmap->Bits(), 0, bitmap->BitsLength());
BitmapBuffer* buffer = new BitmapBuffer(bitmap); BitmapBuffer* buffer = new BitmapBuffer(bitmap);
@@ -308,42 +302,23 @@ fprintf(stdout, "done\n");
uint32 width = buffer->Width(); uint32 width = buffer->Width();
uint32 height = buffer->Height(); uint32 height = buffer->Height();
drawing_mode mode = B_OP_COPY;
source_alpha alphaSrcMode = B_PIXEL_ALPHA;
alpha_function alphaFncMode = B_ALPHA_OVERLAY;
pattern pat = B_SOLID_HIGH;
// painter.ConstrainClipping(clip); // painter.ConstrainClipping(clip);
int32 iterations = 20; int32 iterations = 40;
fprintf(stdout, "Painter..."); fprintf(stdout, "Painter...");
fflush(stdout); fflush(stdout);
bigtime_t painterNow = 0; bigtime_t painterNow = 0;
for (int32 i = 0; i < iterations; i++) { for (int32 i = 0; i < iterations; i++) {
// reset bitmap contents // reset bitmap contents
memset(bitmap->Bits(), 255, bitmap->BitsLength()); memset(bitmap->Bits(), 255, bitmap->BitsLength());
// run test // run test
/* painterNow += test(painter, // painterNow += test(painter, width, height, testBitmap);
width, height, origin, scale, penSize, // painterNow += test_lines(painter, width, height);
lineColor1, lineColor2, // painterNow += test_straight_lines(painter, width, height);
rect, roundRect, painterNow += test_ellipses(painter, width, height);
rectColorH, rectColorL,
angle, span, arcColor,
ellipseColorH, ellipseColorL,
center, xRadius, yRadius,
roundRectColorH, roundRectColorL,
&font, stringLocation1, stringLocation2,
string1, string2,
textColor1, textColor2, alphaColor,
testBitmap, testBitmapCrop, testBitmapDestRect);*/
/* painterNow += test_lines(painter, width, height,
penSize, mode, alphaSrcMode, alphaFncMode,
lineColor1, lineColor2, pat);*/
painterNow += test_straight_lines(painter, width, height,
penSize, mode, alphaSrcMode, alphaFncMode,
lineColor1, lineColor2, pat);
} }
fprintf(stdout, " %lld µsecs\n", painterNow / iterations); fprintf(stdout, " %lld µsecs\n", painterNow / iterations);
@@ -358,44 +333,30 @@ fprintf(stdout, " %lld µsecs\n", painterNow / iterations);
// view->ConstrainClippingRegion(&clip); // view->ConstrainClippingRegion(&clip);
fprintf(stdout, "BView..."); fprintf(stdout, "BView...");
fflush(stdout); fflush(stdout);
bigtime_t viewNow = 0; bigtime_t viewNow = 0;
for (int32 i = 0; i < iterations; i++) { for (int32 i = 0; i < iterations; i++) {
// reset bitmap contents // reset bitmap contents
memset(bitmap->Bits(), 255, bitmap->BitsLength()); memset(bitmap->Bits(), 255, bitmap->BitsLength());
// run test // run test
/* viewNow += test(*view, // viewNow += test(*view, width, height, testBitmap, );
width, height, origin, scale, penSize, // viewNow += test_lines(*view, width, height);
lineColor1, lineColor2, // viewNow += test_straight_lines(*view, width, height);
rect, roundRect, viewNow += test_ellipses(*view, width, height);
rectColorH, rectColorL,
angle, span, arcColor,
ellipseColorH, ellipseColorL,
center, xRadius, yRadius,
roundRectColorH, roundRectColorL,
&font, stringLocation1, stringLocation2,
string1, string2,
textColor1, textColor2, alphaColor,
testBitmap, testBitmapCrop, testBitmapDestRect);*/
/* viewNow += test_lines(*view, width, height,
penSize, mode, alphaSrcMode, alphaFncMode,
lineColor1, lineColor2, pat);*/
viewNow += test_straight_lines(*view, width, height,
penSize, mode, alphaSrcMode, alphaFncMode,
lineColor1, lineColor2, pat);
} }
fprintf(stdout, " %lld µsecs\n", viewNow / iterations);
if (painterNow > viewNow)
printf("BView is %.2f times faster.\n", (float)painterNow / (float)viewNow);
else
printf("Painter is %.2f times faster.\n", (float)viewNow / (float)painterNow);
bitmap->Unlock(); bitmap->Unlock();
fprintf(stdout, " %lld µsecs\n", viewNow / iterations);
if (painterNow > viewNow)
printf("BView is %.2f times faster.\n", (float)painterNow / (float)viewNow);
else
printf("Painter is %.2f times faster.\n", (float)viewNow / (float)painterNow);
BitmapView* bViewView = new BitmapView(bounds, "view", bitmap); BitmapView* bViewView = new BitmapView(bounds, "view", bitmap);
bViewView->MoveTo(BPoint(bounds.left, bounds.bottom + 1)); bViewView->MoveTo(BPoint(bounds.left, bounds.bottom + 1));