micro-gl / micro-gl

Headers Only C++11 CPU Vector Graphics. no std-lib, no FPU and no GPU required !

Home Page:http://micro-gl.github.io/docs/microgl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

antialiasing=false is broken

Azq2 opened this issue · comments

commented

drawRoundedRect with x1 = 10, x2 = 10, y1 = 132-10, y2 = 176-10, radius = 10

Expected result:
image

But actual:
image

@Azq2 there are more parameters which you can control, such as the thickness of the contour. It might be that if the contour is 1 pixel thickness and AA is off, then you would see this behaviour.

I will have to run it on my end to fully confirm that. I do remember running through these scenarios of 1 pixel width of stroke around the rectangle.

commented

Yes, I want a 1px border without AA (Pixel Perfect). Something like this:

image

This reference example is painted with a "pixel-perfect" canvas engine which was used in the ancient Siemens C81 phone.

// Settings is same
int round_x = 10;
int round_y = 10;
DrawRoundedFrame(10 ,10, scr_w - 10, scr_h - 10, round_x, round_y, flags, clrBlack, clrWhite);

I was looking for a way to reproduce this with an open source library.

Example of problem:

#include "src/example.h"
#include <microgl/canvas.h>
#include <microgl/bitmaps/bitmap.h>
#include <microgl/color.h>
#include <microgl/pixel_coders/RGB888_PACKED_32.h>
#include <microgl/samplers/flat_color.h>

#define W 132
#define H 176

int main() {
	using Canvas24= canvas<bitmap<coder::RGB888_PACKED_32>>;
	
	Canvas24 canvas(W, H);
	
	auto render = [&](void*, void*, void*) -> void {
		canvas.clear(color_t{255, 0, 255});
		
		sampling::flat_color<Canvas24::rgba> stroke_color{{0, 0, 0, 255}};
		sampling::flat_color<Canvas24::rgba> bg_color{{250, 250, 250, 255}};
		
		canvas.drawRoundedRect<blendmode::Normal, porterduff::FastSourceOverOnOpaque, false>(bg_color, stroke_color, 10, 10, W - 10, H - 10, 10, 1);
	};

	example_run(&canvas, render);
	
	return 0;
}

image

Sorry, if your lib not intended for pixel perfect painting.
I just thought that AA=off is the equal to pixel-perfect painting.

Hi @Azq2 . First of all, thank you for pointing it out. The algorithms here are picked mostly for performance, it is true. But, maybe try a stroke of 1.5 ? It interests me if it will do good ? I do remember tackling the 1 pixel border problem because it is widely used and desirable.

I promise to run it on my side as well to investigate.

And thank a lot for your feedback, it is great and really helps to shape things.