regularguy
Posts: 2
Joined: Tue Jun 13, 2017 7:38 pm

minimum line width of 1 pixel?

Tue Jun 13, 2017 9:40 pm

Hi,

this is my first post and I just started with the Raspberry Pi.
For my project I need to draw grid lines and decided to use ajstarks lib.
Actually it was quite easy to generate the lines but there is still one problem. I would like to draw lines with a minimum width of 1 pixel.
Is this possible with openVG?
As you can see below I use Line and Stroke functions to draw lines. In that specific case I try to draw a single line at the bottom of the HDMI display but it actually draws two rows at the bottom.
i.e. the width of the line is 2 pixels.
Changing the StrokeWidth to values below 1 just dims the line(s).
How can I create lines with a single pixel width with openVG?

Best regards,
Kai

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"

int main() {
	int width, height;
	char s[3];
	
	init(&width, &height);          // Graphics initialization
	Start(width, height);           // Start the picture
	Background(0, 0, 0);            // Black background
	Stroke(255, 255, 0, 1);         // Set the stroke color
	StrokeWidth(1);                 // Set the stroke width
	Line(1, 1, 1920, 1);            // define line
	End();                          // End the picture

	fgets(s, 2, stdin);             // end with [RETURN]
	finish();                       // Graphics cleanup
	exit(0);
}

User avatar
Paeryn
Posts: 2105
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: minimum line width of 1 pixel?

Tue Jun 13, 2017 11:53 pm

It's mainly down to anti-aliasing which is by default set to quality. And that a stroke width of 1 is drawn (approx.) 1/2 above and 1/2 below the infinitely thin line which is why anti-aliasing causes 2 lines to be drawn, pixels above (or below) are partially in the path too. This is also why the two lines are dimmer, neither row of pixels is wholly within the path. Turning anti-aliasing off causes only pixels whose centre is within the path to be drawn (and at full coverage). Sorry if that's not a very good explanation...

<Edit> When you give coordinate (1,1) that is the lower left corner of the pixel at (1,1) not the centre of the pixel which will be at (1.5,1.5) so a horizontal line from it e.g. (1,1)->(2,1) is actually a box from (1,0.5)->(2,1.5) So an anti-aliased horizontal line will draw to the row below as well as the row given. Similarly a vertical line will draw to the column to the left as well as the given column.

You can turn anti-aliasing off with

Code: Select all

vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);
and turn it back on again with

Code: Select all

vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);
There is an intermediary value of

Code: Select all

vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_FASTER);
but I don't know if the RPi handles FASTER differently to BETTER. I don't think the spec forces there to be any difference, just that FASTER is a possible lower quality anti-aliasing targeting speed over quality.

Code: Select all

   init(&width, &height);          // Graphics initialization
   Start(width, height);           // Start the picture
   Background(0, 0, 0);            // Black background
   Stroke(255, 255, 0, 1);         // Set the stroke color
   StrokeWidth(1);                 // Set the stroke width

   vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); // Turn anti-aliasing off
   Line(1, 10, 1920, 10);
   vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_FASTER); // Turn anti-aliasing on, speed over quality
   Line(1, 20, 1920, 20);
   vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER); // Turn anti-aliasing on, quality over speed
   Line(1, 30, 1920, 30);

   End();                          // End the picture
She who travels light — forgot something.

regularguy
Posts: 2
Joined: Tue Jun 13, 2017 7:38 pm

Re: minimum line width of 1 pixel?

Wed Jun 14, 2017 10:15 pm

That's exactly what I need. Many thanks for this very helpful and detailed answer!!!

Best regards

Return to “OpenVG”

Who is online

Users browsing this forum: No registered users and 1 guest