Commit graph

389 commits

Author SHA1 Message Date
Peter Elliott
28db3cd5ef LibGfx: Add TextAlignment::BottomRight 2020-08-23 01:05:22 +02:00
Andreas Kling
50076997f4 LibGfx: Use an enumerator macro for color roles 2020-08-21 21:16:13 +02:00
Andreas Kling
80a9896e83 LibGfx+WindowServer: Simplify WindowTheme::paint_normal_frame() API
Don't require passing in the outer frame rect since the theme can
compute that itself, based on the window rect.
2020-08-21 21:16:13 +02:00
Andreas Kling
7903cfa5e4 LibGfx: Support loading GIF local color maps if present :^) 2020-08-20 19:42:06 +02:00
Andreas Kling
28e34ffe38 LibGfx: Initialize some uninitialized things in GIFLoader 2020-08-20 19:41:29 +02:00
Tom
5cd2a37079 LibGfx: Small improvement for DisjointRectSet::shatter
This avoids a call to clone() which would be discarded immediately.
Also, avoid essentially cloning for each hammer rectangle unless
there is actually a need for it.
2020-08-19 11:20:27 +02:00
Tom
f8903acea2 LibGfx: Add convenience helpers for Rect 2020-08-18 12:12:27 +02:00
Tom
a43ba348e1 LibGfx: Add convenience method Point::constrained 2020-08-18 12:12:27 +02:00
Tom
790eacfbd1 LibGfx: Add a few convenience methods to DisjointRectSet 2020-08-18 12:12:27 +02:00
Sarah
ee912e023c LibGfx: Move original StylePainter code to ClassicStylePainter
StylePainter should continue to work the same as before.
2020-08-17 00:00:34 +02:00
Sarah
d0900228d0 LibGfx: Add abstract StylePainter class
StylePainter's behavior is now handled by a static instance
of BaseStylePainter. The original static behavior of StylePainter
is left as-is for API compatibility.
2020-08-17 00:00:34 +02:00
thankyouverycool
126a03f087 LibGfx: Add initial font family matching
Fonts following the TypefaceWeightSize naming scheme now associate
with bold weights of the same name and glyph size on construction.
2020-08-16 19:39:46 +02:00
Nico Weber
430b265cd4 AK: Rename KB, MB, GB to KiB, MiB, GiB
The SI prefixes "k", "M", "G" mean "10^3", "10^6", "10^9".
The IEC prefixes "Ki", "Mi", "Gi" mean "2^10", "2^20", "2^30".

Let's use the correct name, at least in code.

Only changes the name of the constants, no other behavior change.
2020-08-16 16:33:28 +02:00
Peter Nelson
c8f8f4e6c3 LibGfx: use disposal method of previous frame in GIF transparency
The disposal method on a GIF animation frame now correctly applies to
rendering of the next frame.
2020-08-13 15:49:41 +02:00
Peter Nelson
daa762bb06 LibGfx: correctly handle transparency between GIF frames
This fixes an issue where transparent pixels in GIF animation frames
have their alpha values incorrectly set to zero, allowing the
background behind the GIF to show through, instead of the previous
animation frame.

Additionally, transparent pixels are now correctly identified based on
their index matching the image transparency index, instead of their
color values.
2020-08-13 15:49:41 +02:00
Ben Wiederhake
f2f0c22052 LibGfx: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code.
2020-08-12 20:40:59 +02:00
Linus Groh
7072806234 Meta: Replace remaining LibM/math.h includes with math.h 2020-08-12 16:18:33 +02:00
Andreas Kling
ae0ff13f66 LibGfx: Correct copyright years for {Classic,}WindowTheme.{cpp,h} 2020-08-10 21:20:28 +02:00
Andreas Kling
de1a54c378 WindowServer+LibGfx: Move window frame rect calculation to WindowTheme 2020-08-10 13:03:44 +02:00
Sarah
9714e61d62 ClassicWindowTheme: Fix titlebar redraw issues
This fixes titlebar rects being overly large and leaving smeary
undrawn areas when using a theme with a titlebar height
different to 19px.
2020-08-10 11:48:47 +02:00
Andreas Kling
c81c8b68bb WindowServer+LibGfx: Move notification window frame painting to LibGfx
ClassicWindowTheme can now also paint notification window frames.
2020-08-09 19:34:56 +02:00
Andreas Kling
e7460b6fb4 WindowServer+LibGfx: Move normal window frame painting to a WindowTheme
This patch introduces the ClassicWindowTheme, which is our default
theme implemented as a Gfx::WindowTheme subclass.

In this initial cut, we move normal window frame painting and title
bar metrics helpers out of WindowServer and into LibGfx.

This will eventually allow us much greater flexibility with theming
windows, and also makes it easier to build applications that want to
render a window with a specific style for some reason. :^)
2020-08-09 19:29:15 +02:00
Andreas Kling
a94be95e27 LibGfx: Add a basic abstract WindowTheme class
This class will provide painting and metrics for window themes. :^)
2020-08-09 19:28:36 +02:00
Andreas Kling
0bbced444b LibGfx: Add dummy Font::x_height() getter
Right now we just guess that the x-height is glyph_height/2, which is
obviously not accurate. We currently don't store the x-height in fonts,
so that's something we'll need to fix.
2020-08-07 20:29:32 +02:00
asynts
b3d1a05261 Refactor: Expose const_cast by removing ByteBuffer::warp(const void*, size_t)
This function did a const_cast internally which made the call side look
"safe". This method is removed completely and call sites are replaced
with ByteBuffer::wrap(const_cast<void*>(data), size) which makes the
behaviour obvious.
2020-08-06 10:33:16 +02:00
Nico Weber
ce95628b7f Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:

    git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05 22:33:42 +02:00
Nico Weber
19ac1f6368 Revert "Unicode: s/codepoint/code_point/g"
This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
2020-08-05 22:33:42 +02:00
Andreas Kling
00fe4c7bcb LibGfx: Make draw_scaled_bitmap() apply relative opacity
Instead of overriding the alpha value of all source pixels, apply the
override opacity by multiplying with the source alpha.

Fixes #3004.
2020-08-05 14:43:36 +02:00
Andreas Kling
984683cf34 Revert "LibM: Always include <math.h> instead of <LibM/math.h>"
This reverts commit dc12cbca41.

Sadly this broke the build due to some confusion about <new>.
Reverting until this can be solved fully.
2020-08-04 21:17:43 +02:00
Andreas Kling
dc12cbca41 LibM: Always include <math.h> instead of <LibM/math.h>
This makes Lagom pick up the host math.h, which is what we want.
2020-08-04 19:06:27 +02:00
Andreas Kling
ea9ac3155d Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
2020-08-03 19:06:41 +02:00
Nico Weber
6dd10ad8dc Themes: Fix default theme window stripes and shadow after #2811
Change #2811 made window title stripes and window title shadow themable,
but it used the same stripe and shadow color for all window modes.
This is fine for the new 'basalt' theme which uses the same color
in all four window modes, but it changed the default theme so that
background windows had brown stripes and a brown shadow.

Instead, make the title stripe and title shadow themable per window mode,
and change the default theme to restore the colors it had before
change #2811: The title stripe color is the same as Border1 for all
window modes, and the title shadow is the same as the title stripe
darkened by 0.6.
2020-08-01 19:26:54 +02:00
thankyouverycool
41aacdf815 LibGfx: Add Paths to themes
Paths allows themes to specify directories/files where custom
resources are located.
2020-08-01 07:56:48 +02:00
Andreas Kling
7bb6b1d44d LibGfx: Fix dumb typo in PNG decoder
'=' is not the same as '*', indeed.
2020-07-27 19:10:18 +02:00
Andreas Kling
0b1a40a6fe LibGfx: Simplify some excessive use of pow() in scanline unfiltering 2020-07-27 16:40:12 +02:00
Matthew Olsson
335916d8db LibGfx: Templatize Point, Size, and Rect 2020-07-27 01:06:26 +02:00
Matthew Olsson
943e4f8bf1 LibWeb: Abstract common operations of graphical SVG elements 2020-07-26 14:53:43 +02:00
Matthew Olsson
9cce7f57dd LibGfx: Add FloatPoint methods
Adds some conversion constructors, as well as the missing arithmetic
operations.
2020-07-26 14:53:43 +02:00
Matthew Olsson
1cffde7635 LibGfx: Add elliptical curves to Path 2020-07-26 14:53:43 +02:00
Matthew Olsson
22f0953fe2 LibWeb: Begin SVG element support
This commit starts adding a basic SVG element. Currently, svg elements
have support for the width and height properties, as well as the stroke,
stroke-width, and fill properties. The only child element supported
is the path element, as most other graphical elements are just shorthand
for paths.
2020-07-26 14:53:43 +02:00
AnotherTest
9d349ac646 LibGfx: Add a generic Matrix variant 2020-07-25 02:13:43 +02:00
AnotherTest
2d96437bbb LibGfx: Add Matrix4x4::elements() getters 2020-07-25 02:13:43 +02:00
Nico Weber
3f45e9ab1e Lagom: Add LibGemini, LibGfx
They are dependencies of LibWeb and might be useful for
running test-web on GitHub actions one day.
2020-07-23 23:02:28 +02:00
Andreas Kling
d7be3faab5 LibGfx: Add an "opacity" argument to Painter::draw_scaled_bitmap()
This API is not super perfect as it merely overrides the source alpha
on all source pixels instead of blending the alpha values. There is
room for improvement here for sure.
2020-07-23 20:32:39 +02:00
Nullspeak
51b2b0d5e5 WindowServer: New title bar vars for themes
The theming system can now control title bar height, title button
size, title stripe color and the title text shadow color.
The implemented theme metrics system could be later extended to LibGUI
to allow themes to change widget padding, border width, etc.
2020-07-17 23:19:08 +02:00
stelar7
d871301fd9 LibGfx: Set correct frame type on JPEG images 2020-07-16 17:52:54 +02:00
Tom
7498024805 LibGfx: Minor IntRect::shatter and FloatRect::shatter optimization
All the shards always intersect unless they're empty.
So rather than checking for intersection, just check
whether they're empty or not.
2020-07-15 00:09:28 +02:00
devashish
4924b86b2a LibGfx+JPGLoader: Print failure message for progressive JPEGs 2020-06-28 16:56:59 +02:00
devashish
1eb338ab71 LibGfx+JPGLoader: Fix decoding outside of LibWeb
The DC reset interval was initialized to garbage :)
2020-06-27 18:33:11 +02:00
Hüseyin ASLITÜRK
dc5b73c43a LibGfx: Add PGM image file type support 2020-06-27 13:01:27 +02:00
Andreas Kling
dc22e59a1a LibGfx: Teach AffineTransform how to rotate and multiply 2020-06-26 18:27:12 +02:00
devashish
4b19b99b36 JPGLoader: Move JPGLoader internal structs and #defines to JPGLoader.cpp 2020-06-23 13:51:19 +02:00
devashish
a8b00780a8 LibGfx: Integrate JPEG decoder with rest of the system
This patch adds functions like `load_jpeg` to JPGLoader to make the
JPEG decoder conform to the API that bitmap loader uses :^)
2020-06-23 13:51:19 +02:00
Devashish
8b71b839fa LibGfx+LibWeb: Add JPEG decoder and integrate with LibWeb
This patch adds support for JPEG decoding. The JPEG decoder is capable
of handling standard 2x1 horizontal, 2x1 vertical and quartered chroma
subsampling. The implemented Inverse DCT performs with a decent speed.

As of interchange formats, since we tend to ignore the metadata in APPn
markers, the decoder can handle any format compatible with JFIF, which
includes EXIFs and sometimes WebMs too. The decoder does not support
progressive JPEGs yet.
2020-06-23 13:51:19 +02:00
Andreas Kling
e3782a7f99 ImageDecoder: Add a new service for out-of-process image decoding :^)
The new ImageDecoder service (available for members of "image" via
/tmp/portal/image) allows you to decode images in a separate process.

This will allow programs to confidently load untrusted images, since
the bulk of the security concerns are sandboxed to a separate process.

The only API right now is a synchronous IPC DecodeImage() call that
takes a shbuf with encoded image data and returns a shared buffer and
metadata for the decoded image.

It also comes with a very simple library for interfacing with the
ImageDecoder service: LibImageDecoderClient. The name is a bit of a
mouthful but I guess we can rename it later if we think of something
nicer to call it.

There's obviously a bit of overhead to spawning a separate process
for every image decode, so this is mostly only appropriate for
untrusted images (e.g stuff downloaded from the web) and not necessary
for trusted local images (e.g stuff in /res)
2020-06-22 21:47:00 +02:00
Hüseyin ASLITÜRK
326032b138 LibGfx: Add PPM image file type support 2020-06-22 18:11:22 +02:00
Paul Roukema
82a75bcf5f LibGfx: Prefer the largest image in the file when loading an ICO
Since the current image handling APIs don't provide a way to handle a
file which can contain multiple images, we just pick the largest one.
This gives the best chance of a good looking result.
2020-06-21 17:41:52 +02:00
Paul Roukema
b1e3f728a1 LibGfx: Add support for uncompressed/classic ICO files
This add support to the ICO file decoder for loading uncompressed bitmap icon files.
 It is limited to 32-bit color icons, no 4/8/16 bit or paletted formats yet.
 This is in addition to the PNG compressed ICO format support  added previously.
 With this we can now load the favicons for github, google and twitter.
2020-06-21 17:41:52 +02:00
Paul Roukema
140581d0c3 LibGfx: Initial support for ICO image files.
This adds support for loading the first image from ICO format images only if they are PNG encoded.
This is useful for loading favicons, which are sometimes PNGs with an ICO extension and sometimes actual ICO files.
In particular we can now load the favicon from new.ycombinator.com
2020-06-21 17:41:52 +02:00
Hüseyin ASLITÜRK
9ab82c0ee5 LibGfx: Add PBM image file type support 2020-06-21 16:42:46 +02:00
Matthew Olsson
4e093a7c23 LibGfx: Add BMP loader
Adds an *almost fully featured BMP loader to process .bmp files.

Features:
- All header formats are supported
- Full RLE4/8/24 support
- Color scaling (e.g. distributing a 5-bit color throughout the 8-bit
color spectrum, so 5-bit white is still 0xffffff)
- Full BITMASK/ALPHABITMASK support

*Not included:
- 1D Huffman compression. Good luck actually finding a bmp in the wild
that uses this
- Use of any field in the V4/V5 header. Color spaces? Endpoints? No
thanks :)

This loader was tested with the images at
https://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html. This
loader correctly displays 81 out of the 90 total images (for reference,
firefox displays 64 correctly). Note that not rendering the images at
the bottom is counted as displaying correctly.
2020-06-21 10:08:25 +02:00
Hüseyin ASLITÜRK
49c801f7fd LibGfx: Fix color alfa for transparent color in GIFLoader 2020-06-18 16:35:57 +02:00
Hüseyin ASLITÜRK
56158a4281 LibGfx: Add a new Bitmap::is_path_a_supported_image_format() method
Move the image file detection code to the File class to prevent code duplication.
2020-06-15 22:42:23 +02:00
Andreas Kling
d51c1c136e LibGfx: Painter::draw_line() can just return early if alpha == 0 2020-06-13 20:38:36 +02:00
Andreas Kling
3bba163574 LibGfx: Add Color::Transparent as a named color 2020-06-13 20:03:19 +02:00
Paul Roukema
b6147de1cb LibGfx: Implement support for decoding interlaced PNGs
This adds support for decoding the Adam7 interlacing used in some PNGs.
Notably this includes many of the images (such as the eyes) used in the acid2 test :^)
Note that the HTML engine still doesn't understand the <object> tag well enough to show the eyes on the test.
2020-06-13 19:47:43 +02:00
Paul Roukema
76553f9f06 LibGfx: Fix PNG decoder handling of 16-bit RGB images 2020-06-13 19:47:43 +02:00
Andreas Kling
bc5a862cbe LibGfx: Silence debug spam in the PNG decoder 2020-06-13 15:37:10 +02:00
Andreas Kling
dc0ed5c860 LibGfx: Don't keep an unused GIF decoder plugin in failed ImageDecoders
If we can't decode the input data, just have a null decoder. In this
state we simply return a null bitmap and whatever empty values make
sense for each API.

This way, we don't try to decode the same thing over and over since
it's not gonna work anyway. :^)
2020-06-13 15:29:29 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
thankyouverycool
5a71a57435 LibGfx: Return paint_button() earlier and replace overdrawn rect
Return StylePainter::paint_button() before color initializations
when possible and replace an overdrawn rect in paint_button_new()
with more explicit shadow lines. Also standardize some comments.
2020-06-11 16:56:17 +02:00
Andreas Kling
fea77abcf6 LibGfx: Fail PNG decoding on invalid scanline filter
Only filter types 0 thru 4 are valid.
2020-06-11 16:27:54 +02:00
Andreas Kling
d59a308c7e LibGfx: Minor tweaks in PNG decoder 2020-06-11 16:27:54 +02:00
thankyouverycool
9940a7f6de LibGfx: Return correct color for palette.hover_highlight()
Now correctly returns HoverHighlight instead of ThreedHighlight.
2020-06-10 21:50:33 +02:00
thankyouverycool
c8acd7d5bf LibGfx: Visual enhancement to buttons
This adds a "shine" effect to the bottom-right edges of pressed
and checked buttons, complementing the sunken shadow already
present at top-left and creating greater illusion of depth.

It is similar to the effect used in classic Windows and is
theme agnostic in Serenity, but produces the best result when
ThreedHighlight is a radiant color of Button.
2020-06-10 19:21:43 +02:00
Andreas Kling
3aca84a299 LibGfx: Use size_t for the Streamer offset and sizes 2020-06-10 18:59:58 +02:00
Andreas Kling
116cf92156 LibGfx: Rename Rect,Point,Size => IntRect,IntPoint,IntSize
This fits nicer with FloatRect,FloatPoint,FloatSize and gives a much
better visual clue about what type of metric is being used.
2020-06-10 10:59:04 +02:00
Andreas Kling
43951f18e7 LibGfx: Add FloatSize::to_int_size() 2020-06-10 08:49:41 +02:00
Sergey Bugaev
fc481552f5 LibIPC+LibGfx+IPCCompiler: Drop some unused includes 2020-06-08 13:58:32 +02:00
Andreas Kling
ba6a77f281 LibGfx: Make Painter::add_clip_rect() use logical coordinates
It was really confusing that add_clip_rect() didn't apply transforms
to the new clip rect, but instead interpreted it as an absolute rect.

This makes web pages with <iframe> render correctly when scrolled.

Something might break from this, but we'll find it soon enough. :^)
2020-06-06 19:36:40 +02:00
Sergey Bugaev
f49e83c565 LibGfx: Fix debug-printing colors
The operator has to live in the namespace Gfx.
2020-06-02 21:49:47 +02:00
Andreas Kling
8ea4375d4a LibGfx: Templatize some of the scanline unpacking code 2020-06-02 19:28:55 +02:00
Andreas Kling
19587934f3 LibGfx: Consolidate some types in the PNG decoder 2020-06-02 19:28:55 +02:00
Andreas Kling
7be9cf8d36 LibGfx: Add ImageDecoder factory overload for ByteBuffers 2020-06-01 21:32:54 +02:00
Andreas Kling
d0eb35e5c3 LibGfx: Use a bit of constexpr in Color
This avoids a bunch of strlen()'s when we're parsing web colors.
2020-05-30 17:47:50 +02:00
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Sergey Bugaev
8520d3a425 LibGfx: Add Painter::fill_ellipse() 2020-05-24 23:30:12 +02:00
Hüseyin ASLITÜRK
8b3bd1a54b LibGfx: Font, extend fonts to 384 character to support LatinExtendedA 2020-05-21 01:19:42 +02:00
Hüseyin ASLITÜRK
840a64e2f9 LibGfx: Painter, extend fonts to 384 character to support LatinExtendedA
Replace codepoint variable type from char to u32.
2020-05-21 01:19:42 +02:00
Andreas Kling
0272bbb4fb LibGfx: Add UTF-32 version of the text painting code paths
There's a large amount of code duplication here right now, which will
need to be reduced.
2020-05-17 22:35:25 +02:00
Andreas Kling
bc6f469544 LibGfx: Let's make it Font::width(Utf32View) 2020-05-17 22:35:25 +02:00
Andreas Kling
35875b68f5 LibGfx: Add Font::width(u32* codepoints, size_t)
This allows you to measure the width of a UTF-32 sequence.
2020-05-17 22:35:25 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00
Andreas Kling
fbda28248a LibGfx+IPCCompiler: Add IPC encoders for Color and ShareableBitmap 2020-05-12 19:04:03 +02:00
Andreas Kling
3775983dfe LibIPC+LibGfx: Templatize IPC encoding as well as decoding
Now most classes dictate how they are serialized and deserialized when
transmitted across LibIPC sockets. This also makes the IPC compiler
a bit simpler. :^)
2020-05-12 18:49:24 +02:00
Ben Wiederhake
ebe47de0b2 LibGfx: Eliminate conditional branch in dither
In theory, this should make dithering a teensy bit faster.
2020-05-11 09:47:32 +02:00
Linus Groh
0669dbcf5d LibGfx: Add support for dashed lines
Non-configurable for now.
2020-05-10 19:41:00 +02:00
Andreas Kling
fce0cf18e3 LibGfx: Make buttons slightly chunkier on the top/left side 2020-05-10 14:24:20 +02:00
Linus Groh
59d00e5df6 LibGfx: Replace 'bool dotted' with a LineStyle::{Solid,Dotted} enum
Just a bool is insufficient as we'll have to support dashed lines as well.
2020-05-10 13:34:59 +02:00
Linus Groh
da42279171 LibGfx: Fix dotted lines with thickness > 1
If we just skip every second pixel, we still get a solid line if each
"pixel" is wider than 1!
Now we skip the same amount of pixels as the line is thick.
2020-05-10 13:34:59 +02:00
Andreas Kling
9e74793ce2 LibGUI+LibGfx: Paint scollbar tracks with a dithered pattern
Instead of a solid color, we now paint the track/gutter of scrollbars
using a 2-color dither pattern for a pleasant millennium feel. :^)
2020-05-10 01:02:06 +02:00
Linus Groh
9e0beebdf5 LibGfx: Fix build with FILL_PATH_DEBUG enabled 2020-05-09 23:41:30 +02:00
AnotherTest
6f15f23a40 LibGfx: Add Path::close_all_subpaths()
Unlike Path::close() which closes only the last subpath (if possible),
this closure mechanism closes _all_ available subpaths.
2020-05-09 23:25:39 +02:00
Peter Nelson
b1fee13904 LibGfx: Implement GIFImageDecoderPlugin animation methods
GIFImageDecoderPlugin now lazily decodes GIF frames as they are
requested.
2020-05-09 12:01:59 +02:00
Peter Nelson
ddc4eb7be0 LibGfx: Optimise LZWDecoder
Various optimisations to speed up LZWDecoder
- Take advantage of the fact that we add new codes in the order they are
  discovered so no need to store the code as part of a separate
  CodeTableEntry structure. Instead we store directly store vectors of
  colors and the code is the index into the vector.
- Cache current table capacity to avoid calling pow2 every time.
- Prevent some unnecessary vector copies by returning by reference from
  get_output.
2020-05-09 12:01:59 +02:00
Peter Nelson
d22bb92764 LibGfx: Add support for animated images to ImageDecoder{Plugin}
Adds methods to determine whether an image is animated, how many times
the animation loops, the number of frames, and to get individual frames.

Implements stubs of these methods for PNGImageDecoderPlugin and
GIFImageDecoderPlugin.
2020-05-09 12:01:59 +02:00
Hüseyin ASLITÜRK
e68a08ad7c LibGfx: Add new methods to Font to avoid embedded values in FontEditor 2020-05-09 10:00:13 +02:00
AnotherTest
88738aefa3 LibGfx: Revert #2154 and properly handle simple polygons
The existing scanline method works just fine, and only needs the points
to be available as floats.
This commit reverts the complex polygon mitigation, and instead fixes
the rasterization process to avoid generating complex polygons because
of precision issues.
2020-05-08 19:39:38 +02:00
AnotherTest
677568e3d4 LibGfx: Handle filling complex shapes better
This allows the painter to render filled complex shapes better, by
constructing a path graph for (interesting) intersecting lines and
omitting lines from the containing segments if they are detected
to take no part in defining the edges of a shape.

This approach would still fail if there are multiple logical shapes
that are confined to the collection of lines.
For instance, two polygons intersecting each other in a way that one
vertex of polygon A ends up inside polygon B.
we would detect that polygon A's edges are part of the shape
(technically correct) even though they are not a part of polygon B at
all.
2020-05-08 12:49:15 +02:00
Linus Groh
9dbab2d05e Misc: Replace "String(string_view)" with "string_view.to_string()"
StringView::to_string() was added in 917ccb1 but not actually used
anywhere yet.
2020-05-06 19:28:59 +02:00
AnotherTest
f54b41f748 LibGfx: Implement filling paths
There are some imperfections with intersecting edges (because the main
algorithm used is scanline, and that is not geared towards drawing
complex shapes), however, it behaves mostly fine for normal use :^)
2020-05-06 14:50:29 +02:00
Andreas Kling
1061127ca7 LibGfx: Add missing FloatRect function implementations
These are just clones of the Rect equivalents.
2020-05-05 18:53:34 +02:00
Andreas Kling
b7339745d0 LibGfx: Add a naive "rgba(r,g,b,a)" color parser
It's not very whitespace tolerant but it works.
2020-05-05 15:50:28 +02:00
AnotherTest
0a55679de4 LibWeb: Add canvas.quadraticCurveTo()
Also adds a test, and removes debug spam ™️
2020-05-05 09:21:07 +02:00
AnotherTest
9f3f98d4c0 LibGfx: Add Painter::draw_quadratic_bezier_curve()
Also adds a QuadraticBezierCurveTo mode to Gfx::Path
2020-05-05 09:21:07 +02:00
LepkoQQ
c7f0de14b5 LibGfx: Decode paletted and grayscale images with 1/2/4 bit depth
When dealing with png data that has less than 8 bits per pixel, round
up to the next byte when allocating per row buffers and streamers. This
fixes decoding odd sized PNGs with less than 8 bits per pixel.

Also added a test page with some odd sized palleted PNGs.
2020-05-02 01:28:18 +02:00
Andreas Kling
888e35f0fe AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macros
It's tedious to write (and look at) [[gnu::always_inline]] etc. :^)
2020-04-30 11:43:25 +02:00
Andreas Kling
17e76b4760 LibGfx: Add Color::to_string_without_alpha()
This simply returns an "#rrggbb" string and ignores the alpha value.
2020-04-29 15:31:45 +02:00
LepkoQQ
e5a598414f LibGfx: PNGLoader support for grayscale images with alpha. 2020-04-26 20:29:17 +02:00
LepkoQQ
d009df074f LibGfx: PNGLoader support for grayscale images with 8/16bpp. 2020-04-26 20:29:17 +02:00
Hüseyin ASLITÜRK
c9c1d1fae0 LibGUI: Create thumnail for gif files 2020-04-26 18:44:20 +02:00
Peter Nelson
5adf4901df LibGfx: Fix crash on decoding small gifs
The LZW decode step will now copy and pad LZW data out to 4 bytes if there are
less than 4 bytes remaining in the buffer. This means it will now also work when
the total size of the LZW image data is less than 4 bytes.
2020-04-25 18:37:13 +02:00
Andreas Kling
9c772a64a1 LibGfx: Don't proceed with GIF format sniffing if stream read fails 2020-04-25 17:03:40 +02:00
Peter Nelson
4cb765e520 LibGfx: Remove unnecessary casts 2020-04-25 16:49:09 +02:00
Peter Nelson
76cbfe1c38 LibGfx: Minor changes to adhere to code style guidelines 2020-04-25 16:49:09 +02:00
Peter Nelson
a1c0eb1e1d LibGfx: Remove debug output 2020-04-25 16:49:09 +02:00
Peter Nelson
9a2c8102cd LibGfx: Use content sniffing to choose which ImageDecoder plugin to use 2020-04-25 16:49:09 +02:00
Peter Nelson
2cd9716b38 LibGfx: Add a sniff method to ImageDecoder and implement for GIF and PNG
The sniff method is intended to be used for content sniffing. It should be a
cheap test to rapidly rule out whether a candidate image can be successfully
decoded. For the GIF and PNG implementations it simply attempts to decode the
image header, returning true if successful and false if not.
2020-04-25 16:49:09 +02:00
Peter Nelson
df0d6e241c LibGfx: Extract GIF header decoding into separate function 2020-04-25 16:49:09 +02:00
Peter Nelson
d5af7b220c LibGfx: implement remaining GIFImageDecoderPlugin methods 2020-04-25 16:49:09 +02:00
Peter Nelson
e06518211b LibGfx: decode first frame of GIF LZW data
Also:
- Define the GIFLoadingContext structure.
- The load_gif_impl function now returns load operation success, and takes a
  reference to a GIFLoadingContext as input.
- Implement GIFImageDecoderPlugin::bitmap which calls onto load_gif_impl.
2020-04-25 16:49:09 +02:00
Peter Nelson
9c2a675c38 LibGfx: Implement GIF LZW decoding
Add an LZWDecoder class that can decode GIF LZW data.
2020-04-25 16:49:09 +02:00
Andreas Kling
f0cac83243 WindowServer+LibGfx: Make window borders 1px thicker 2020-04-23 14:37:13 +02:00
Andreas Kling
4393a2a96d LibGfx: Let the PNG decoder fail if the header is missing or too short 2020-04-19 17:48:43 +02:00
Stephan Unverwerth
cbcf317e76 LibGfx: Fix draw_triangle() clipping calculations 2020-04-18 13:24:34 +02:00
Stephan Unverwerth
2dcc38d7bf LibGfx: Add Vector3 and Matrix4x4 classes
This adds two templated 3D math classes. They have already been typedf'd
as FloatVector3, DoubleVector3, FloatMatrix4x4 and DoubleMatrix4x4
2020-04-18 12:28:54 +02:00
Stephan Unverwerth
acd4676803 LibGfx: Add draw_triangle() for drawing filled triangles 2020-04-18 12:28:54 +02:00
Andreas Kling
ecd900b4b4 LibGfx: Add FloatPoint::to_int_point() 2020-04-16 21:11:13 +02:00
Andreas Kling
60c2e41079 LibGfx: Add Gfx::Path, a basic 2D path with <canvas> semantics
This will be used to implement painting of 2D paths. This first patch
adds support for line_to(), move_to() and close().

It will try to have the same semantics as the HTML <canvas> element.

To stroke a Path, simply pass it to Painter::stroke_path().
2020-04-16 21:04:46 +02:00
Andreas Kling
acf2061837 LibGfx: Use Checked::multiplication_would_overflow() 2020-04-15 17:15:06 +02:00
Andreas Kling
f3fc294ac8 LibGfx: Use Checked<T> when creating new bitmaps 2020-04-15 16:58:46 +02:00
Andreas Kling
228ace854c LibGfx: Don't allow creating bitmaps whose sizes would overflow
If the area or size_in_bytes calculation for a Gfx::Bitmap would
overflow, we now refuse to create such a bitmap and return nullptr.

Thanks to @itamar8910 for finding this! :^)
2020-04-15 12:28:49 +02:00
Andreas Kling
6f2c63000d LibGfx: Add a basic AffineTransform class
We can now perform some basic 2D transforms through an affine matrix.
This patch adds translate() and scale() :^)
2020-04-12 19:23:39 +02:00
Andreas Kling
5c780c9ef7 LibGfx: Allow constructing Float{Rect,Point,Size} from integer buddies 2020-04-12 19:23:39 +02:00
Hüseyin ASLITÜRK
8e9d031cb3 LibGfx: Add Bitmap::rotated and Bitmap::flipped 2020-04-12 18:08:11 +02:00
Andreas Kling
e323246517 Meta: Add missing copyright headers 2020-04-06 11:09:01 +02:00
Tibor Nagy
e14d27867c LibGfx: Implement checkerboard drawing for Gfx::Painter 2020-04-05 15:30:53 +02:00
Andreas Kling
7976ef7a79 LibGfx: Add Painter::blit_filtered() and blit_brightened()
blit_filtered() can be used to easily implement per-pixel filtered blit
functions. All you need to do is provide a callback that can compute
the Color for each pixel based on the original Color.
2020-03-30 19:39:37 +02:00
Andreas Kling
cbd7effd3b LibGfx: Support vertical gradient fill (not just horizontal) :^) 2020-03-30 17:00:12 +02:00
Andreas Kling
7cfe712f4d LibGfx+LibIPC: Add Gfx::ShareableBitmap, a bitmap for easy IPC usage
With this patch, it's now possible to pass a Gfx::ShareableBitmap in an
IPC message. As long as the message itself is synchronous, the bitmap
will be adopted by the receiving end, and disowned by the sender nicely
without any accounting effort like we've had to do in the past.

Use this in NotificationServer to allow sending arbitrary bitmaps as
icons instead of paths-to-icons.
2020-03-29 19:37:23 +02:00
Andreas Kling
24a0354ce8 LibIPC+LibGfx: Pass the IPC::Decoder to decoding helpers
Instead of passing the BufferStream, pass the Decoder. I'd like to stop
using BufferStream eventually anyway, so it's good to get it out of any
API's where it's in currently.
2020-03-29 19:37:23 +02:00
Andreas Kling
fd5a3b3c39 LibGfx: Parse "rgb(r,g,b)" style color strings
This parser is not very lenient, but it does the basic job. :^)
2020-03-21 19:06:38 +01:00
Oriko
2b162ef794 LibGUI: Use themes for syntax highlighting 2020-03-16 13:39:34 +01:00
Tibor Nagy
6c32882f05 LibGfx: Do not assert on failed font file loads
Return a nullptr to signal an error instead.
2020-03-11 21:27:03 +01:00
Andreas Kling
37fc6c117c Userspace: Add missing #includes now that AK/StdLibExtras.h is smaller 2020-03-08 13:06:51 +01:00
Andreas Kling
f72e5bbb17 Kernel+LibC: Rename shared buffer syscalls to use a prefix
This feels a lot more consistent and Unixy:

    create_shared_buffer()   => shbuf_create()
    share_buffer_with()      => shbuf_allow_pid()
    share_buffer_globally()  => shbuf_allow_all()
    get_shared_buffer()      => shbuf_get()
    release_shared_buffer()  => shbuf_release()
    seal_shared_buffer()     => shbuf_seal()
    get_shared_buffer_size() => shbuf_get_size()

Also, "shared_buffer_id" is shortened to "shbuf_id" all around.
2020-02-28 12:55:58 +01:00
joshua stein
32e6453b0b LibGfx: SystemTheme is a struct, not a class
SystemTheme.h:81:1: error: 'SystemTheme' defined as a struct here but previously declared as a class; this is valid, but may result in linker errors under the Microsoft C++ ABI
2020-02-25 15:32:58 +01:00
Andreas Kling
ceec1a7d38 AK: Make Vector use size_t for its size and capacity 2020-02-25 14:52:35 +01:00
Emanuel Sprung
074d935c6e AK, LibGfx, LibGUI: Initialize various variables to zero.
The not initialized variables can lead to compiler warnings that
become errors with the -Werror flag.
2020-02-25 10:18:46 +01:00
Tibor Nagy
6fcf4e48f8 LibGfx: Fix accidentally hardcoded font height in Font::clone() 2020-02-23 12:18:17 +01:00
Andreas Kling
98fd6b8767 LibGfx: Add a way to construct an empty Font with arbitrary metrics 2020-02-23 11:10:52 +01:00
Tibor Nagy
6e2a16c8a8 LibGfx+LibGUI: Allow theming the focus outline of AbstractButton 2020-02-20 14:19:30 +01:00
Tibor Nagy
c8bc53e987 LibGfx+LibGUI: Allow theming the text cursor 2020-02-20 14:19:30 +01:00
Tibor Nagy
5cf5ddf6cb LibGfx: Add ColorRoles for rulers 2020-02-19 12:24:39 +01:00
Andreas Kling
2143da6434 LibGUI: Add forwarding header
This patch adds <LibGUI/Forward.h> and uses it a bunch.
It also dragged various header dependency reduction changes into it.
2020-02-16 09:41:56 +01:00
Andreas Kling
2e6ab58117 LibGfx: Reduce header dependencies of StylePainter 2020-02-16 09:41:56 +01:00
Tibor Nagy
99192fd29f LibGfx: Add inactive selection colors 2020-02-15 18:42:13 +01:00
Andreas Kling
a4d857e3c5 LibIPC+IPCCompiler: Add IPC::Decoder, let classes decode themselves
This shaves ~5 seconds off of a full build, not too bad. Also it just
seems nicer to push this logic out to classes. It could be better but
it's a start. :^)
2020-02-15 12:11:19 +01:00
Andreas Kling
93e9c2732b LibGfx: Remove unused Bitmap::load_from_file() for loading raw RGBA
This was not used anywhere but added unnecessary members to Bitmap.
2020-02-15 01:06:32 +01:00
Andreas Kling
9c0c677d57 LibGfx: Reduce header dependencies of Bitmap and Font 2020-02-15 01:03:37 +01:00
Andreas Kling
34b5ff7c29 LibGfx: Move a bunch of LogStream::operator<< to cpp files 2020-02-15 00:58:54 +01:00
Andreas Kling
66903ad987 LibGfx: Remove Utf8View.h dependency from Font.h 2020-02-15 00:27:50 +01:00
Andreas Kling
34c7322d77 LibGUI: Remove some header dependencies from Widget.h 2020-02-14 23:53:11 +01:00
Andreas Kling
08cae2773d LibGfx: More work on header dependency reduction 2020-02-14 23:33:21 +01:00
Andreas Kling
3fe2640c8c LibGfx: Add forward declaration header
This patch adds <LibGfx/Forward.h> with forward declarations for Gfx.
2020-02-14 23:31:18 +01:00
Andreas Kling
3bbf4610d2 AK: Add a forward declaration header
You can now #include <AK/Forward.h> to get most of the AK types as
forward declarations.

Header dependency explosion is one of the main contributors to compile
times at the moment, so this is a step towards smaller include graphs.
2020-02-14 23:31:18 +01:00
Andreas Kling
3f58f0e87c LibGfx: Add Rect::operator!=(Rect) 2020-02-11 11:53:38 +01:00
Shannon Booth
7b6d450b6a LibGfx: Assert that an empty bitmap is not created 2020-02-11 11:00:09 +01:00
Andreas Kling
3b95d61b22 LibGfx: Naive RGB/HSV conversion 2020-02-08 12:30:12 +01:00
Andreas Kling
d17e23bd27 LibCore: Remove leading C from filenames 2020-02-06 15:04:03 +01:00
Andreas Kling
8bb75084fd LibGfx: Unpublish FloatPoint from the global namespace 2020-02-06 14:35:54 +01:00
Andreas Kling
5c2028db24 LibGfx: Unpublish FloatSize from the global namespace 2020-02-06 14:35:06 +01:00
Andreas Kling
8505d8d15d LibGfx: Unpublish FloatRect from the global namespace 2020-02-06 14:33:05 +01:00
Andreas Kling
f8b00aa290 LibGfx: Unpublish Gfx::Size from the global namespace 2020-02-06 13:32:14 +01:00
Andreas Kling
9b87843af1 LibGfx: Unpublish Gfx::Point from global namespace 2020-02-06 13:08:32 +01:00
Andreas Kling
20cfd2a6bf LibGfx: Unpublish Gfx::Rect from global namespace 2020-02-06 13:02:38 +01:00
Andreas Kling
c39d44fc2e LibGfx: Rename GraphicsBitmap.{cpp,h} => Bitmap.{cpp,h} 2020-02-06 12:07:05 +01:00
Andreas Kling
9ac94d393e LibGfx: Rename from LibDraw :^) 2020-02-06 12:04:00 +01:00