Commit Graph

43 Commits

Author SHA1 Message Date
Sam Atkins
83f31cb4a7 LibGfx: Add int overloads for (AntiAliasing)Painter float methods
Without this change, the upcoming LibWeb pixel types will require a
silly doubled conversion in some places.

eg: `some_rect.to_type<int>().to_type<float>()`

With these overloads, we can get away with `some_rect.to_type<int>()`.
2022-12-08 12:46:03 +00:00
MacDue
e011eafd37 Meta+Userland: Pass Gfx::FloatPoint by value
Just a small 8-byte value like Gfx::IntPoint.
2022-12-07 11:48:27 +01:00
MacDue
7be0b27dd3 Meta+Userland: Pass Gfx::IntPoint by value
This is just two ints or 8 bytes or the size of the reference on
x86_64 or AArch64.
2022-12-07 11:48:27 +01:00
MacDue
40e978df85 LibGfx: Fix some more antialiased line off-by-ones
Turns out most things expect lines to include the endpoint,
e.g. 0,0 -> 3,0 is a 4px long line. But the fill_path() implementation
seems to expect the line to be the distance between the two points
(so the above example is a 3px line instead).

This now adds an option to pick between PointToPoint line length or
Distance line length and uses the latter for fill_path().
2022-12-03 15:36:58 +00:00
MacDue
acc0fceaae LibGfx: Remove some unused AntiAliasingPainter methods 2022-12-03 15:36:58 +00:00
MacDue
b85af4e9bf LibGfx: Add some AntiAliasingPainter FIXMEs
Also fixup the style on some comments.

See #16270... Hopefully someone will land on these :^)
2022-12-03 15:36:58 +00:00
MacDue
b8492006da LibGfx: Disable line intersection stroking for 1px lines
1px lines are already connected, so this just makes things look worse
and is often painting in the wrong spot anyway.
2022-11-30 07:58:44 +01:00
MacDue
8dfe43273c LibGfx: Fix off-by-one for antialiased line length
Previously the line did not include the endpoint.
2022-11-30 07:58:44 +01:00
MacDue
754b8a643d LibGfx: Remove unnecessary path members from AntiAliasingPainter
m_rotated_rectangle_path was unused and m_intersection_edge_path was
cleared/free'd each time it was used. So sticking in the class just
bloats the size.
2022-11-30 07:58:44 +01:00
MacDue
613963cbce LibGfx: Don't bother painting transparent lines 2022-11-29 11:08:50 +01:00
MacDue
db235a87bf LibGfx: Allow float thickness lines and fix fill path glitches
The main fix is stopping fill_path() scanlines being rounded to the
wrong pixel. The y-value is now floored to ensure it always snaps
in the same direction.
2022-11-27 20:34:17 +01:00
MacDue
76de41c3b7 LibGfx: Add draw_line_for_path() and remove AntiAliasPolicy
draw_line_for_path() is the same as the standard antialiased
draw_line() but with a few few small hacks to improve the look of
paths.

AntiAliasPolicy is also removed as it's now unused.
2022-11-26 01:17:04 +01:00
MacDue
f7a680f30a LibGfx: Implement nicer antialiased lines
This is not any 'proper' algorithm, this was just a shower thought
idea. There probably is a better algorithm to achieve the same effect
out there, if someone knows of one please replace this code :^).

This works by rendering the line a scanline at a time, which avoids
repainting over any pixel on the line (so opacity now works with AA
lines). This generally seems to achieve a much nicer looking line.

I've not done any proper benchmarking of this, but some little messing
around showed that this new implementation was a little faster than
the old one too, so that's a nice little bonus.

With the inclusion of a few minor hacks this also goes a surprisingly
far way in improving our SVG rendering too (for both filled and stroked
paths). :^)
2022-11-26 01:17:04 +01:00
Torstennator
b2a6066042 LibGfx: Optimize anti-aliased line drawing and stroking
This patch optimizes the drawing of aa-lines by rotating the drawn
rectangle to the direction where the line points. That enables us to
draw non-straight lines with the proper width.
If a aa-line is drawn that is infact a straigt line we now dont plot
those lines with multipe rectangles across the line - insted we draw
straight lines in one go with just one rectangle of proper size.
Stroking of lines has been enhanced to take care of the edges between
two lines with drawing the stroke till the intersections of two
connected lines.
2022-11-15 22:59:25 +01:00
Nico Weber
2af028132a AK+Everywhere: Add AK_COMPILER_{GCC,CLANG} and use them most places
Doesn't use them in libc headers so that those don't have to pull in
AK/Platform.h.

AK_COMPILER_GCC is set _only_ for gcc, not for clang too. (__GNUC__ is
defined in clang builds as well.) Using AK_COMPILER_GCC simplifies
things some.

AK_COMPILER_CLANG isn't as much of a win, other than that it's
consistent with AK_COMPILER_GCC.
2022-10-04 23:35:07 +01:00
Brian Gianforcaro
d0a1775369 Everywhere: Fix a variety of typos
Spelling fixes found by `codespell`.
2022-09-14 04:46:49 +00:00
MacDue
f9b08272db LibGfx: Add AntiAliasingPainter::fill_rect
This function is able to draw rectangles of floating-point pixel
precision.
2022-09-03 16:57:37 +01:00
MacDue
bb48a61d50 LibGfx: Flatten AntiAliasingPainter::draw_ellipse_part()
This seemed to drop the time spent here a few percent in profiling.
2022-06-23 19:13:24 +01:00
MacDue
9ed5b2dfb5 LibGfx: Move AntiAliasingPainter.cpp into Gfx namespace 2022-06-18 02:34:56 +01:00
MacDue
6139fc5c87 LibGfx: Add AA dotted horizontal/vertical lines
This adds simple dotted lines (horizontal/vertical only for now).

There's a little number fudging added in to make sure the final
dot is always drawn at the endpoint (for lines with at least a
handful of dots).
2022-06-18 02:34:56 +01:00
MacDue
c1798620d9 LibGfx: Support AlphaSubtract blend mode for AA rounded rectangle 2022-06-14 00:25:12 +01:00
MacDue
c0486f93d4 LibGfx: Optimize rounded rectangle with all radii 50% to single ellipse
It's a common pattern on the web to draw a circle/ellipse by setting
the border-radius to 50%. Previously the painter would do a lot of
extra work painting and clipping each corner, this now detects that
case and replaces it with a single call to fill_ellipse().
2022-06-13 12:00:39 +01:00
MacDue
2366a73474 LibGfx: Support AA rounded rectangles with elliptical borders 2022-06-13 09:43:45 +01:00
MacDue
0120c8580f LibGfx: Clip outside the corners when painting an AA rounded rectangle 2022-06-11 17:46:46 +01:00
MacDue
5bc5c0f31b LibGfx: Fix rendering of bottom corners in AA rounded rectangle
Previously, the left corner was using the right's radius and the
right corner was using the left's. This corrects that.
2022-06-11 17:46:46 +01:00
MacDue
5fd3716e2f LibGfx: Fix antialiased circles becoming too pointy at small sizes
The issue mentioned in the previous FIXME also applied to circles,
I just had not noticed. This is still not a prefect fix rather it
just papers over it, but it now seems to render circles correctly.
2022-06-05 13:58:40 +01:00
MacDue
8c2a5bbc15 LibGfx: Implement antialiased outline ellipsis
This is a first pass at antialiased outline ellipses, currently
this is done by painting two filled AA ellipses, and then
subtracting the inner ellipse from the outer.

This produces a good result, but unfortunately requires allocating
a temporary bitmap in the painter. I did try a simpler method
using the existing line painting functions, and drawing the
ellipse as many line segments, but that produced very poor results.

I think with some work it should be possible to remove the extra
allocation, and I've left a big FIXME for this, but I could not
get this working well.
2022-06-01 19:33:45 +02:00
MacDue
8ac5f625e9 LibGfx: Rename draw_ellipse/circle to fill_ellipse/circle
This makes these functions more consistent with the non-aa painter.
2022-06-01 19:33:45 +02:00
Linus Groh
de90faa4c4 LibGfx: Change one instance of 'colour' to 'color'
The system's official language is American English.
2022-05-29 15:22:00 +02:00
Linus Groh
173dcfb7cb Everywhere: Fix a bunch of typos 2022-05-29 15:22:00 +02:00
MacDue
60aba4c9f3 LibGfx: Implement AntiAliasingPainter::draw_ellipse()
This commit adds draw_ellipse() and moves the shared code
for circles and ellipses to draw_ellipse_part().

draw_ellipse_part() can draw an entire circle in one call using
8-way symmetry and an ellipse in two calls using 4-way symmetry.
2022-05-07 22:59:02 +02:00
Florian Stellbrink
af3174c9ce LibGFX: Transform vertices when drawing antialiased lines
Previously we transformed each rasterized point when drawing a line.
Now we transform the lines' endpoints instead.

That means running two transforms per line instead of transforms for
each pixel. It is not clear that the overhead for the fast path is
still worth it. If we still want to optimize identity and translations,
it is probably better to do that inside AffineTransform.

In addition this will behave nicer if the transform includes scaling.
Previously this would rasterize lines before scaling. Which means
drawing too many points when scaling down, and not drawing enough
points when scaling up.
With the new approach we will automatically rasterize at pixel scale.

This is essentially the same as OpenGL, where vertices are transformed
and rasterization happens in screen space.
2022-04-11 03:16:37 +02:00
Andreas Kling
f1d44da422 LibGfx: Simplify draw_anti_aliased_line() by avoiding transform callback
Instead of taking a callback that performs the coordinate transformation
we now just take a bool template parameter.

Thanks to Idan for suggesting this! :^)
2022-04-10 22:06:46 +02:00
Andreas Kling
c6e79124c7 LibGfx: Slap an -O3 optimization #pragma on Gfx::AntiAliasingPainter
We're already doing this for Gfx::Painter, so let's do it here as well.
2022-04-10 21:35:55 +02:00
Andreas Kling
908d42d0ba LibGfx: Add fast path to AA line drawing with simple 2D transform
If the effective 2D transform is just a basic translation, we now simply
translate the underlying painter before & after drawing AA lines.

This avoids all the extra math that otherwise has to happen when mapping
points through an affine transform.

This noticeably increase "mousing around" performance on Wikipedia. :^)
2022-04-10 21:35:55 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
MacDue
3c0e17f29f LibGfx: Support scaling in AntiAliasingPainter::draw_circle()
Previously the painter would crash if scaling was enabled.
2022-03-26 18:24:11 +00:00
Andreas Kling
6b5f0d11ce LibGfx: Fix draw_anti_aliased_line() for steep lines with "OnlyEnds"
Regression from ab794a199b.
2022-03-19 22:32:38 +01:00
Andreas Kling
ab794a199b LibGfx: Transcribe "Xiaolin Wu's line algorithm" more accurately
This improves the appearance of anti-aliased lines significantly.
2022-03-19 22:04:43 +01:00
MacDue
51e54ab1ba LibGfx: AntiAliasingPainter::draw_circle/fill_rect_with_rounded_corners
Follows the efficient algorithm from this paper:
https://cs.uwaterloo.ca/research/tr/1984/CS-84-38.pdf

Can be extended ellipses in future.
2022-03-18 11:31:33 +01:00
Ali Mohammad Pur
433725fef2 LibGfx: Implement cubic bezier curves by splitting them to subcurves
This makes them significantly more nicer-looking, and fixes a FIXME :^)
2021-09-18 02:12:38 +04:30
Ali Mohammad Pur
5a2e7d30ce LibWeb: Use Gfx::AntiAliasingPainter to draw SVG paths
This is still quite bad, but it's much more pleasing to look at when
drawing random SVGs :^)
2021-09-18 02:12:38 +04:30
Ali Mohammad Pur
e2cd558101 LibGfx: Start a very basic anti-aliased Painter implementation
This can currently draw AA lines (and by proxy, AA paths), and passes
all its output through a 2D affine transform to an underlying
Gfx::Painter.
2021-09-18 02:12:38 +04:30