Commit graph

353 commits

Author SHA1 Message Date
Srimanta Barua
1e1d2cdedf LibTTF: Initial work on parsing and rasterizing composite glyphs.
This doesn't handle every case yet.
2020-12-30 20:40:30 +01:00
Srimanta Barua
bd354bc2ae LibTTF: Reorganized TTF parsing code into LibTTF 2020-12-30 20:40:30 +01:00
Srimanta Barua
22fbe59126 LibGfx: Address awesomekling's comments on API and codestyle 2020-12-30 20:40:30 +01:00
Srimanta Barua
1931535218 LibGfx: Cut down on magic constants in the TTF parser. 2020-12-30 20:40:30 +01:00
Srimanta Barua
186499cc25 LibGfx: Update Painter's bezier curve drawing algorithm.
The new algorithm is an iterative one with an arbitrary threshold for splitting
curves. It splits curves evenly. This should theoretically be less accurate
than the existing recursive approach, but seems to give subjectively better
results in practice.
2020-12-30 20:40:30 +01:00
Srimanta Barua
0e9fb803c8 LibGfx: Finally render simple TTF outlines. 2020-12-30 20:40:30 +01:00
Srimanta Barua
b70c1fe181 LibGfx: Rasterize simple TTF glyphs. 2020-12-30 20:40:30 +01:00
Srimanta Barua
e3b5d2afeb LibGfx: Load glyph definition from "glyf" table for TTF fonts.
CFF fonts don't have "glyf" or "loca", so this code will need to be
extended to handle them.
2020-12-30 20:40:30 +01:00
Srimanta Barua
675237180f LibGfx: Get glyph ID for codepoint, from the CMAP table. 2020-12-30 20:40:30 +01:00
Srimanta Barua
be1586850d LibGfx: Started working on TTF font parser.
I'm planning to make this a minimal-allocation TTF parser. This will
speed up start-up time for applications, but have some overhead for
rasterizing glyphs. Which should be okay, since rasterized glyph bitmaps
should be cached anyway.

This commit just adds the loading of the HEAD table.
2020-12-30 20:40:30 +01:00
asynts
7e62ffbc6e AK+Format: Remove TypeErasedFormatParams& from format function. 2020-12-30 20:33:53 +01:00
Andreas Kling
13594b7146 LibGfx+AK: Make text elision work with multi-byte characters
This was causing WindowServer and Taskbar to crash sometimes when the
stars aligned and we tried cutting off a string ending with "..." right
on top of an emoji. :^)
2020-12-28 23:54:10 +01:00
Andreas Kling
9af33e2e4b LibGfx: Make Painter::draw_text() interpret StringView as UTF-8 2020-12-28 23:54:10 +01:00
Andreas Kling
105eb8e1bc LibGfx: Add FontDatabase::get(family, size, weight)
This function allows you to look up a font by its exact parameters.
2020-12-28 15:53:10 +01:00
Peter Nelson
476911e1f9 LibGfx: fix OOB access in LZW decoder on bad input
This fixes an issue where a corrupted LZW code can result in the first
element of an empty buffer being accessed.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27863
2020-12-28 15:12:29 +01:00
Andreas Kling
92c073a9d1 LIbGUI+LibGfx: Paint focused push buttons with a heavier look
Draw a heavy shadow frame around focused push buttons for emphasis.
For now I've used the ThreedShadow2 color role as it feels dark enough.
2020-12-28 12:41:26 +01:00
Sahan Fernando
d780e2265d LibC: Fix some incorrect printf usages 2020-12-26 10:05:50 +01:00
Linus Groh
d8899ea65b WindowServer: Validate cursor type in SetWindowCursor message handler
Fixes #4536.
2020-12-25 23:07:06 +01:00
Andreas Kling
edf01803cd LibGfx: Make all image decoders reject image sizes above 16384 pixels
Let's just say no to shenanigans by capping images at 16384 pixels both
wide and tall. If a day comes in the future where we need to handle
images larger than this, we can deal with it then.
2020-12-25 00:19:06 +01:00
Andreas Kling
80ae407d73 LibGfx: Always compute the DIB mask shifts and sizes if needed
The pixel decoding logic later on assumes that if we have DIB masks,
we also have shifts and sizes, so we should make sure they are
always computed.

Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28237
2020-12-23 20:16:53 +01:00
Andreas Kling
cd046fae44 LibGfx: Fail JPEG decode instead of asserting on bogus start-of-scan
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28628
2020-12-23 19:22:15 +01:00
Andreas Kling
0fc8561029 LibGfx: Catch integer overflows in PNG decoder and fail the decode
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28134&sort=reported&q=serenity
2020-12-23 19:04:12 +01:00
Andreas Kling
491a5f5e34 LibGfx: Avoid a ByteBuffer heap allocation in PNG filtering 2020-12-23 18:06:25 +01:00
Andreas Kling
068615fe5e LibGfx: Reject PNG files with invalid filter/interlace methods
Might as well reject these when parsing the IHDR chunk instead of
continuing to load something invalid.
2020-12-23 15:45:59 +01:00
Andreas Kling
531c3fe72e LibGfx: Fix OOB access in GIF deinterlacing
It was possible to go outside the interlacing row strid/offset arrays.
Just fail the decode if this is about to happen. I've added a FIXME
about rejecting such images earlier, since it's a bit sad to only do
this once we realize the pass index is about to overflow.

Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28239
2020-12-22 10:09:41 +01:00
Lenny Maiorani
a95d230a3e LibGfx: Commonize functions in P*MLoader class implementations
Problem:
- Functions are duplicated in [PBM,PGM,PPM]Loader class
  implementations. They are functionally equivalent. This does not
  follow the DRY (Don't Repeat Yourself) principle.

Solution:
- Factor out the common functions into a separate file.
- Refactor common code to generic functions.
- Change `PPM_DEBUG` macro to be `PORTABLE_IMAGE_LOADER_DEBUG` to work
  with all the supported types. This requires adding the image type to
  the debug log messages for easier debugging.
2020-12-22 09:24:12 +01:00
Lenny Maiorani
58c52b155a LibGfx: Extraction of Streamer from P*MLoader
Problem:
- `Streamer` is the same in [PBM,PGM,PPM]Loader class implementations.

Solution:
- Extract it to its own header file to reduce maintenance burden.
- Implement `read` in terms of `read_bytes` to make the class "DRY".
- Decorate all functions with `constexpr`.
2020-12-21 09:58:27 +01:00
Lenny Maiorani
765936ebae
Everywhere: Switch from (void) to [[maybe_unused]] (#4473)
Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
2020-12-21 00:09:48 +01:00
Andreas Kling
c7d0c2ee7a LibGfx: Teach all image decoders to fail on bitmap allocation failure
We don't need to wait for oss-fuzz to find this for us. :^)
2020-12-20 16:04:29 +01:00
Andreas Kling
3e0b913e44 LibGfx: Fail PNG decode if output bitmap can't be allocated
Otherwise we'll assert soon afterwards.

Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28838
2020-12-20 15:24:50 +01:00
Andreas Kling
77515fead2 LibGfx: Remove use of ByteBuffer::wrap() in BMP decoder 2020-12-19 13:05:48 +01:00
Andreas Kling
8cf6b75dd9 LibGfx: Remove use of ByteBuffer::wrap() in PNG decoder 2020-12-19 12:00:35 +01:00
Nico Weber
573d5b7ff2 LibGfx: Give Size and Rect * and *= operators 2020-12-18 17:35:30 +01:00
Nico Weber
b67eed5b80 LibGfx: Fix type of scale factor in Point scale operators 2020-12-18 17:35:30 +01:00
Itamar
efe4da57df Loader: Stabilize loader & Use shared libraries everywhere :^)
The dynamic loader is now stable enough to be used everywhere in the
system - so this commit does just that.
No More .a Files, Long Live .so's!
2020-12-14 23:05:53 +01:00
Andreas Kling
96233bfc53 LibGfx: Draw checked buttons with a dithered base background
This looks just so right in the taskbar. :^)
2020-12-14 21:47:07 +01:00
AnotherTest
0918d8b1f8 LibGfx: Make fill_path() less bad at filling paths
This patchset fixes:
- Some parts of the path being skipped and not drawn (often horizontal)
- The filled shape moving around on an int grid depending on the winding
  number
- Winding number mess-up with four-way intersections
2020-12-12 20:10:04 +01:00
Sahan Fernando
fe3963f3d4 LibGfx: SIMD optimized alpha blending 2020-12-08 09:39:43 +01:00
Sahan Fernando
893adbb79c LibGfx: Simplify and refactor Gamma.h
Remove ACCURATE_GAMMA_ADJUSTMENT, since it makes the implementation
uglier, isn't guaranteed to make gamma adjustment accurate and is much
slower.  gamma_accurate_blend4 should either be always used or not
exist based on compilation flags, so there is no need to have it in
its own function. Finally, we should use AK/SIMD.h instead of defining
our own f32x4 type.
2020-12-08 09:39:43 +01:00
Andreas Kling
70c9cfddc5 LibGfx: Fix font x-height computation
Line indices start from the top, so the baseline is a higher number
than the mean line. :^)
2020-12-06 01:01:15 +01:00
Ben Wiederhake
ecb16f421d LibGfx: Handle OOM slightly better
When create_with_shared_buffer() is called in the next line, the
RefPtr::operator* asserts that the RefPtr is not null. That can happen when
we're low-ish on memory, and the image is huge.
2020-12-06 00:06:05 +01:00
Ben Wiederhake
aec8983819 LibGfx: Accept BMP RLE of 255 repeated bytes
Previously, in the case of RLE4, parsing took suspiciously long.
What happened was that 'pixel_count' was 255, and 'i' was incremented
by *two* in each iteration, so the for-loop continued until the
entire output buffer was full, and then rejected the RLE data
as bogus.

This little diff allows pixel_count to reach 256, be greater than
pixel_count, and thus terminate the loop in the intended way.
2020-12-02 22:51:05 +01:00
Ben Wiederhake
453c63fd04 LibGfx+BMP: Remove set_remaining, fix size check
The set_remaining method is inherently dangerous. It can be avoided easily here,
so let's do that.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
36daeee34f LibGfx: Fix BMP mask detection off-by-one
Also, since the loops can be replaced by a little bit-twiddling,
call ctz() directly. This might be a bit faster, or it might not.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
6be9b6349d LibGfx: Prevent potential heap-overflow in BMP non-RLE 2020-12-02 10:46:40 +01:00
Ben Wiederhake
461bdeda2b LibGfx: Fix heap-overflow in BMP RLE
The field previously named 'data_size' apparently was misunderstood.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
d66b0683eb LibGfx: Distinguish between RGB data and file data
This was confusing and has hidden a bug, so let's change it.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
9ff001c4d3 LibGfx: Avoid ByteBuffer assertions for huge bitmaps 2020-12-02 10:46:40 +01:00
Ben Wiederhake
d6c0776b45 LibGfx: Reject OS/2 BMP files with invalid bpp values 2020-12-02 10:46:40 +01:00
Ben Wiederhake
bd6d365166 LibGfx: Disallow RLE8 compression for 16bpp BMPs
Also, disallow similar silly combinations. Technically, we support *more* than
the definition seems to require.

For future reference:
https://archive.org/details/mac_Graphics_File_Formats_Second_Edition_1996/page/n607/mode/2up
Book page 580 (pdf page 608)
2020-12-02 10:46:40 +01:00