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

1239 commits

Author SHA1 Message Date
Nico Weber
b161f5ea05 LibGfx: Make ICC reader check that profile size is a multiple of 4
With this, I would've found e8bd067ce5 earlier.

(If this turns out to be too strict in practice, we can always relax
it again.)
2023-02-24 19:17:20 +01:00
Nico Weber
e8bd067ce5 LibGfx: Pad last element in ICC files to 4-byte boundary too
The spec wants that to happen.
2023-02-23 16:39:17 +01:00
Nico Weber
7853be7869 LibGfx: Implement serialization of LutAToBTagData and LutBToATagData
With this, we can write all tag types we can currently read :^)
2023-02-23 15:35:02 +01:00
Timothy Flynn
fcd4535a55 LibGfx: Do not exclude all ASCII code points from emoji lookups
Keycap emoji, for example, begin with ASCII digits. Instead, check the
first code point for the Emoji Unicode property.

On a profile of scrolling around on the welcome page in the Browser,
this raises the runtime percentage of Font::glyph_or_emoji_width from
about 0.8% to 1.3%.
2023-02-22 21:51:09 +00:00
Timothy Flynn
f33ead7f5f LibGfx: Bail early from Emoji::emoji_for_code_point_iterator for ASCII
On a profile of scrolling around on the welcome page in the Browser,
this drops the runtime percentage of Font::glyph_or_emoji_width from
about 70% to 0.8%.
2023-02-22 21:11:48 +01:00
Timothy Flynn
2bc7c11e8d LibGfx: Consult Unicode data to decode emoji sequences
For example, consider the Pirate Flag emoji, which is the code point
sequence U+1F3F4 U+200D U+2620 U+FE0F. Our current emoji resolution does
not consider U+200D (Zero Width Joiner) as part of an emoji sequence.
Therefore fonts like Katica, which have a glyph for U+1F3F4, will draw
that glyph without checking if we have an emoji bitmap.

This removes some hard-coded code points and consults the UCD's code
point properties for emoji sequence components and variation selectors.
This recognizes the ZWJ code point as part of an emoji sequence.
2023-02-22 10:14:36 +01:00
Timothy Flynn
b823f3d29f LibGfx: Consider multi-code point glyphs when computing text width
Currently, we compute the width of text one code point at a time. This
ignores grapheme clusters (emoji in particular). One effect of this is
when highlighting a multi-code point emoji. We will errantly increase
the highlight rect to the sum of all code point widths, rather than
just the width of the resolved emoji bitmap.
2023-02-22 10:14:36 +01:00
Timothy Flynn
a391ea3da3 LibGfx: Support computing a font's glyph width with code point iterators
This allows consideration of multi-code point glyphs.
2023-02-22 10:14:36 +01:00
Timothy Flynn
71967bc5de LibGfx: Implement Emoji::emoji_for_code_point_iterator for UTF-32 views 2023-02-22 10:14:36 +01:00
Lucas CHOLLET
ad13c45c28 LibGfx: Log the underlying error when failing to decode a macroblock 2023-02-22 09:22:45 +01:00
Lucas CHOLLET
cf6bceeb2c LibGfx: Don't assume that scans are always full when filling macroblocks
In other words: only consider coefficient of the current scan when
adding coefficients to a macroblock. Information about which
coefficients are present in the stream are passed through the spectral
information in the context.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
d421967394 LibGfx: Save spectral information in the context
These variables are useless for baseline JPEG, but they will become
useful for other encodings.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
3a8c52cabc LibGfx: Put code to add AC coefficients to a macroblock in a function 2023-02-22 09:22:45 +01:00
Lucas CHOLLET
48f7b93a23 LibGfx: Put code to add the DC coefficient to a macroblock in a function 2023-02-22 09:22:45 +01:00
Lucas CHOLLET
e38cd8eb4e LibGfx: Don't store the size of a Vector in an external variable 2023-02-22 09:22:45 +01:00
Lucas CHOLLET
8ed630a7ec LibGfx: Put the code to reset the encoder in its own function
With it, we can also add a spec reference. And it will remind to anyone
who wants to add support for a new coding to not forget to update it.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
3fefb696a3 LibGfx: Make decode_huffman_stream take macroblocks by reference
In progressive mode, this functions will need to be called multiple time
on the same macroblocks, so it shouldn't create the vector every
time it's called.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
bae37676c2 LibGfx: Prepare the decoder to handle multiples scans
This means that we should read markers in a loop instead of quiting on
the first scan. This is useless for now as `SOF0` frames only have one
scan, but this is a step forward `SOF2` support.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
c0c48afe06 LibGfx: Return from scan_huffman_stream before JPEG_EOI
As a JPEG file can contain multiples scans, we should return from
`scan_huffman_stream` on all new markers (except restart markers) and
not only `JPEG_EOI`.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
f1aa189027 LibGfx: Factorize handling of miscellaneous and tables segments
Miscellaneous and tables segments can also be placed between scans,
placing this code in a function will allow us to avoid duplication when
we get there.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
90573652fd LibGfx: Rename "skip_marker_with_length" to "skip_segment"
As it, in fact, does not skip a marker but a segment :^).
2023-02-22 09:22:45 +01:00
Andreas Kling
bfe081caad LibGfx: Fix const-correctness issues 2023-02-21 00:54:04 +01:00
Andreas Kling
ca44b26b2a LibGfx: Make Gfx::Path const-correct internally (segment list) 2023-02-21 00:54:04 +01:00
Andreas Kling
2530b301db LibGfx: Add const hack in Bitmap::to_bitmap_backed_by_anonymous_buffer() 2023-02-21 00:54:04 +01:00
Andreas Kling
4b3e229157 LibGfx: Replace Bitmap::invert() with Bitmap::inverted()
The new function return a new bitmap instead of mutating the current
one in place.
2023-02-21 00:54:04 +01:00
Andreas Kling
1f907a834f LibGfx: Make Bitmap::scaled(1) return a clone
While returning the same image is a cute optimization, it violates the
expectation that the returned Bitmap is a new bitmap, not shared with
anyone else.
2023-02-21 00:54:04 +01:00
Nico Weber
1d124af66f LibGfx: Implement serialization of Lut16TagData and Lut8TagData 2023-02-19 23:46:36 +01:00
Nico Weber
4bafdaba3f LibGfx: Make Lut16TagData and Lut8TagData ctors verify table sizes
The from_bytes() methods error out on invalid table sizes,
but let's make sure other potential future callers get it right too.
2023-02-19 23:46:36 +01:00
Nico Weber
51be964884 LibGfx: Fix 7-bit ASCII checks in textDescriptionType and textType
This used to check the empty, moved-from parameter instead of
the member variable (-‸ლ)
2023-02-19 23:46:36 +01:00
Nico Weber
8f181e0e94 LibGfx: Implement serialization of NamedColor2TagData 2023-02-19 23:46:36 +01:00
Nico Weber
eac9941766 LibGfx: Make NamedColor2TagData verify inputs are 32-byte 7-bit ASCII
NamedColor2TagData::from_bytes() errors out if that isn't the case,
but let's make sure other potential future callers get it right too.
2023-02-19 23:46:36 +01:00
Nico Weber
7ad11fa59a LibGfx: Mark a few ICC:NamedColor2TagData methods as const 2023-02-19 23:46:36 +01:00
Nico Weber
47cfcf5dca LibGfx: Move NamedColorHeader to BinaryFormat.h 2023-02-19 23:46:36 +01:00
Nico Weber
937d018fc6 LibGfx: Use ICC::Profile::try_for_each_tag in encode_tag_datas() 2023-02-19 23:46:36 +01:00
Nico Weber
8179327068 LibGfx: Add fallible ICC::Profile::try_for_each_tag
Similar to 13b18a1 or d0f3f3d.
2023-02-19 23:46:36 +01:00
Nico Weber
0f0694edb1 LibGfx: Remove an ICC writing FIXME, and a comment 2023-02-19 23:46:36 +01:00
Lucas CHOLLET
fa24f13452 LibGfx: Bring variables names closer to spec
Rename "reset_marker" to "restart_marker" as described by the spec. It
also concerns disambiguate the situation as the DRI was also called a
reset marker.
2023-02-19 23:39:59 +01:00
Lucas CHOLLET
51000961f2 LibGfx: Add a spec reference for JPEG constants definitions 2023-02-19 23:39:59 +01:00
Lucas CHOLLET
acc5161535 LibGfx: Add a spec link for the JPEG decoder 2023-02-19 23:39:59 +01:00
Lucas CHOLLET
71afef6466 LibGfx: Remove some magic variables in JPEGLoader 2023-02-19 23:39:59 +01:00
Lucas CHOLLET
c8213c24dd LibGfx: Rename is_valid_marker() to is_supported_marker() 2023-02-19 23:39:59 +01:00
Nico Weber
e2dde64628 LibGfx: Use static_cast in ICC writing code
It's what project leadership wants.
2023-02-19 22:31:41 +01:00
Nico Weber
0e66a5c3ed LibGfx: Write multiLocalizedUnicodeType with multiple strings correctly
Found by reencoding Tests/LibGfx/test-inputs/icc-v2.png, the 'dscm' tag.
2023-02-19 22:31:41 +01:00
Nico Weber
07bf2d944c LibGfx: Add a FIXME to ICC encode_tag_data() 2023-02-19 22:31:41 +01:00
Nico Weber
7e769c7217 LibGfx: Partially implement serialization of TextDescriptionTagData
It only implements serialization of the 7-bit ASCII string, not yet
serialization of the UCS-2 and Macintosh ScriptCode strings.

With this, matrix-based v2 profiles can be reencoded :^)
2023-02-19 22:31:41 +01:00
Nico Weber
b2cf773d85 LibGfx: Make TextDescriptionTagData verify input is 7-bit ASCII
TextDescriptionTagData::from_bytes() errors out if that isn't the case,
but let's make sure other potential future callers get it right too.
2023-02-19 22:31:41 +01:00
Nico Weber
e76f1caf79 LibGfx: Re-alphabetize TagData classes
This moves TextDescriptionTagData below SignatureTagData.
It just moves code around and doesn't change anything.
2023-02-19 22:31:41 +01:00
Nico Weber
4d972ab975 LibGfx: Add spec comment to ICC encode_tag_table() 2023-02-19 22:31:41 +01:00
MacDue
bb8c8a67dc LibGfx: Fix a slight mistake in AA ellipse error calculation
The initial signs were wrong for the deltas of f(x), the ellipse
equation. This seemed to be fine for larger circles/ellipses but
broke things at a small scale, this was previously fixed with a
horrible "error = error / 4" hack. With this change, all ellipses
look a little better :^)

This also fixed a signed integer overflow Andreas found with UBSAN,
which happened for circles with a 1px radius.
2023-02-19 18:40:15 +01:00
Sam Atkins
2db168acc1 LibTextCodec+Everywhere: Port Decoders to new Strings 2023-02-19 17:15:47 +01:00