1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 18:55:08 +00:00
Commit graph

1164 commits

Author SHA1 Message Date
Lucas CHOLLET
bab2113ec1 LibGfx/PortableFormat: Make read_whitespace return an ErrorOr 2023-03-24 10:56:58 +01:00
Lucas CHOLLET
74f893e9f4 LibGfx/PortableFormat: Make read_comment return an ErrorOr 2023-03-24 10:56:58 +01:00
Lucas CHOLLET
964172754e LibGfx/PortableFormat: Don't accept comments that don't start with # 2023-03-24 10:56:58 +01:00
Lucas CHOLLET
9052a6febf LibGfx/PortableFormat: Simplify read_number signature
The function signature goes from:
`bool read_number(Streamer& streamer, TValue* value)`
to
`ErrorOr<u16> read_number(Streamer& streamer)`

It allows us to, on one hand use `ErrorOr` for error propagation,
removing an out parameter in the meantime, and on the other hand remove
the useless template.
2023-03-24 10:56:58 +01:00
Lucas CHOLLET
387894cdf2 LibGfx: Make PortableImageDecoderPlugin constructor private 2023-03-24 10:56:58 +01:00
MacDue
77456d1d0b LibGfx: Implement simple signed distance field rendering
This is mostly a simple grayscale bilinear scale, with an extra step
of computing the distance and alpha with a little smoothing. This
can be used to paint more scalable UI elements/icons from rather
small distance fields. A tiny 16x16 SDF seems to do a decent job
for simple icons.
2023-03-23 08:27:51 +00:00
MacDue
429d7b002b LibGfx: Add a simple GrayscaleBitmap class
This is very similar to the existing CharacterBitmap class but instead
intended for small static grayscale bitmaps (such as signed distance
fields).
2023-03-23 08:27:51 +00:00
Lucas CHOLLET
f66de973ff LibGfx/JPEG: Replace a FIXME with some explanations
Calling the `ycbcr_to_rgb` function still looks unsuitable for this
usage, but it does the job correctly.
2023-03-22 08:57:51 +01:00
Lucas CHOLLET
496b7ffb2b LibGfx: Move all image loaders and writers to a subdirectory 2023-03-21 22:39:25 +01:00
Cameron Youell
1d24f394c6 Everywhere: Use LibFileSystem where trivial 2023-03-21 19:03:21 +00:00
LukasACH
b5f0f94757 LibGfx/OpenType: Do not preemptively return while searching for kerning
The kerning value for a particular glyph may not be in
the first table. Continue until we either run out of tables or
we find an applicable value.
2023-03-21 19:11:53 +01:00
LukasACH
b6cfacfd9f LibGfx/OpenType: Get size of ValueRecord from PairPos valueFormat field
The stored ValueRecord in the font file only contains the fields
specified in the valueFormat field of the PairPosFormat1 table.
This means we need to construct the ValueRecord dynamically at runtime
and cannot bit_cast it to a struct.
2023-03-21 19:11:53 +01:00
LukasACH
7eb5fa38c4 LibGfx/OpenType: Move function read_value_record, add argument stream
read_value_record(u16 value_format, FixedMemoryStream& stream) takes
a bitmask value_format that describes the available fields of
the ValueRecord and a FixedMemoryStream at the location of the
next ValueRecord. It then advances the stream and returns a complete
ValueRecord.
2023-03-21 19:11:53 +01:00
Andreas Kling
3195c1832a LibWeb: Don't try to parse GPOS lookup types we don't understand yet
At the moment, we only understand lookup type 2 (pair adjustment)
so let's ignore lookup tables with other types.

This fixes an issue where we'd choke on Noto Sans versions that come
with a chained context positioning lookup table (type 8).

Fixes #17924
2023-03-21 15:48:32 +01:00
Andreas Kling
a7a1df42c7 LibGfx/OpenType: Fix typo in 'kern' table parsing
Thanks to Timon for spotting this :^)
2023-03-21 15:32:22 +01:00
LukasACH
83eca15e51 LibGfx/OpenType: Extend support for GPOS glyph positioning
This patch extends the kerning support using the GPOS table to fonts
which use PairPosFormat1. Previously, only PairPosFormat2 was
supported.
2023-03-21 09:50:27 +01:00
Tim Ledbetter
5a6b995444 LibGfx: Use premultiplied alpha when scaling images
This commit replaces usages of `Color::interpolate()` with
`Color::mixed_with()` in image scaling functions. The latter
uses premultiplied alpha, which results in more visually
pleasing edges when images are scaled against a transparent
background.

These changes affect the SmoothPixels and BilinearBlend scaling modes
of `Painter::draw_scaled_bitmap()` as well as the `Bitmap::scaled()`
function.

Fixes #17153.
2023-03-21 00:29:33 +01:00
Lucas CHOLLET
b084759690 LibGfx/JPEG: Make JPEGImageDecoderPlugin's constructor take a Stream
This allows us to get rid of the raw pointer and size in the JPEG
context struct.
2023-03-19 00:41:33 +00:00
Matt Purnell
bc23b07570 LibGfx: Correct the type of Lookup.subtable_offsets
According to the spec (and the variable name), it should be an array of
offsets, not u16s. Noticed while watching Andreas' most recent video.
2023-03-19 00:32:01 +00:00
gohai
d5577002d5 LibGfx/OpenType: Fix bound-check 2023-03-17 15:44:45 +01:00
Andreas Kling
d38a3ca9eb LibGfx/OpenType: Add some initial support for GPOS glyph positioning
This patch parses enough of GPOS tables to be able to support the
kerning information embedded in Inter.

Since that specific font only applies positioning offsets to the first
glyph in each pair, I was able to get away with not changing our API.
Once we start adding support for more sophisticated positioning, we'll
need to be able to communicate more than a simple "kerning offset" to
the clients of this code.
2023-03-17 09:36:20 +01:00
Nico Weber
14581e98ad LibGfx: Remove stray space character in a comment 2023-03-16 09:20:48 -04:00
Andreas Kling
5e81734520 LibGfx: Make the Palette constructor take NNRP<PaletteImpl> 2023-03-15 23:29:00 +01:00
Sam Atkins
6d8f046fd0 LibGfx+Userland: Make TextAttributes::underline_style optional
Rather than having a style AND a field saying whether to use the style,
just make the style Optional.
2023-03-15 14:55:49 +01:00
Nico Weber
609b616085 LibGfx: Make a comment in BMPWriter more precise 2023-03-15 13:54:09 +00:00
Nico Weber
e37000b1ea LibGfx: Let decode_bmp_v5_dib() skip reserved field
This has no effect in practice: decode_bmp_v5_dib() is the last
thing called with the streamer object (...the streamer is passed
to set_dib_bitmasks(), but that doesn't read anything off it except
for DIBType::Info bitmaps, which v5 bitmaps aren't).

But dib_size is 16 larger for v5 than for v4, so we should read
16 bytes.

This is also useful for a hypothetical person who might look at
the reading code to figure out how the writing code should look like.
2023-03-15 13:54:09 +00:00
Nico Weber
8d3ab2de56 LibGfx: Make BMPWriter code a tiny bit shorter 2023-03-15 13:54:09 +00:00
Nico Weber
6189994b24 LibGfx: Let BMPWriter optionally embed an ICC profile 2023-03-15 13:54:09 +00:00
Nico Weber
a93a88c73c LibGfx: Allow BMPWriter to write v5 bmps and make that the default 2023-03-15 13:54:09 +00:00
Nico Weber
1db0883fea LibGfx: VERIFY correct type length in PNGChunk ctor 2023-03-15 11:02:41 +00:00
Nico Weber
bc248d28f7 LibGfx: Make PNGChunk::m_type a String instead of a DeprecatedString
It's always 4 bytes, so the data fits in a String's inline buffer.
(Else I would've used a StringView.)
2023-03-15 11:02:41 +00:00
Nico Weber
fd57ba1d90 LibGfx: Use * a b s t r a c t i o n * in PNGChunk::store_type() 2023-03-15 11:02:41 +00:00
Nico Weber
1a03f45a73 LibGfx: Remove reckless PNGChunk::add(T) method
This method added function using host byte order, which is never what we
want.

In practice, it was fine because it was only called from add_u8()
(which is just 1 byte large) and add_as_big_endian() (since that did
endian swapping before calling the method). But the method doesn't
really help any and is dangerous, so remove it.

No behavior change.
2023-03-15 11:02:41 +00:00
Nico Weber
6a8c8aae9b LibGfx: Remove unused PNGChunk::add_as_little_endian() method
PNG uses big-endian data internally.
2023-03-15 11:02:41 +00:00
Nico Weber
189ea375a5 LibGfx: Let PNGWriter optionally embed an ICC profile 2023-03-15 11:02:41 +00:00
Nico Weber
6e2d3fe0df LibGfx: Add PNGChunk::compress_and_add API 2023-03-15 11:02:41 +00:00
Nico Weber
75895bc892 LibGfx: Use ReadonlyBytes in PNGChunk API 2023-03-15 11:02:41 +00:00
Andreas Kling
a4927f523b LibGfx: Add Font::point_size()
This returns the font size in pt instead of px.
2023-03-15 11:43:54 +01:00
Tim Schumacher
ecd1862859 AK: Rename Stream::write_entire_buffer to Stream::write_until_depleted
No functional changes.
2023-03-13 15:16:20 +00:00
Tim Schumacher
a3f73e7d85 AK: Rename Stream::read_entire_buffer to Stream::read_until_filled
No functional changes.
2023-03-13 15:16:20 +00:00
Lucas CHOLLET
9c9bd271c8 LibGfx/PortableFormat: Add PortableFormatWriter
Currently, the encoder only output ppm files, but it can easily be
extended to support both PBM and PGM.
2023-03-13 15:15:41 +00:00
Nico Weber
c587ada084 LibGfx: Make BMPWriter::dump() return ErrorOr
...and use TRY() consistently in BMPWriter.cpp
2023-03-12 21:07:25 +00:00
Nico Weber
a2ccf38f11 LibGfx: Make BMPWriter::dump() not take a RefPtr 2023-03-12 21:32:21 +01:00
Nico Weber
833d0d95c9 LibGfx: Remove a redundant copy of all data when writing a BMP 2023-03-12 21:32:21 +01:00
Nico Weber
f1a3028ef1 LibGfx: Change BMPWriter API to be consistent with other image writers 2023-03-12 21:32:21 +01:00
Nico Weber
01387eb72b LibGfx: Change second argument of BMPWriter::dump() to Options struct
This makes it more economical to add more options here, and makes it
possible to use similar API surface for the other image writers.

(It looks like nothing currently uses this optional parameter, but
having a way to pass options to image writers seems like something
we generally want.)
2023-03-12 21:32:21 +01:00
Nico Weber
74891ab656 LibGfx: Remove unused BMPWriter::set_compression()
This has always been unused, and after #8440 BMPWriter::dump()
unconditionally writes to m_compression, meaning even if this
method was called, it would have no effect.
2023-03-12 21:32:21 +01:00
Nico Weber
9b297c634f LibGfx: Make QOIWriter use ErrorOr
In addition to it now handling allocation failures, the encode() API is
now consistent with PNGWriter.
2023-03-12 13:23:34 +00:00
MacDue
b698d64ee9 LibGfx: Use StringView literals for CSS color list
And also remove the null terminating entry in favour of for-each loop.
2023-03-12 12:46:24 +00:00
MacDue
952222ec4d LibGfx: Fix segfault and painting off-by-one in fill_path()
Previously, this would paint scanlines one pixel too long and segfault
when painting AA scanlines that were <= 1px long.
2023-03-11 23:51:20 +01:00