Commit Graph

60 Commits

Author SHA1 Message Date
Matthew Olsson
29b70485fc LibGfx: Add formatters for Gfx::Color's different representations
This makes debugging these values a bit easier
2024-03-03 19:50:25 +01:00
Matthew Olsson
70ded2ef42 LibGfx: Add Oklab support to Gfx::Color
Interpolation of color on the web is done via the oklab colorspace
2024-02-25 08:51:50 +01:00
Nico Weber
d60758a947 LibGfx: Remove now-unused Color::from_cmyk()
`CMYKBitmap::to_low_quality_rgb()` morally still does the same thing,
but it has a slightly more scary name, and it doesn't use this exact
function. So let's toss it :^)
2024-02-01 13:42:04 -07:00
MacDue
9f710b0fb6 Revert "LibGfx: Slightly simplify Color::blend()"
This was producing incorrect results.

This reverts commit a1bafafd78.
2024-01-22 07:12:25 +01:00
MacDue
a1bafafd78 LibGfx: Slightly simplify Color::blend()
No behaviour change.
2024-01-08 09:26:43 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Shannon Booth
6c9fffc4c1 LibGfx: Add String variants of Color::to_string*() 2023-11-20 15:00:19 +01:00
Jelle Raaijmakers
5bac9df865 LibGfx: Remove SSE version of Color::blend()
I could not discover proof that this is actually faster than the non-SSE
version. In addition, for these relatively simple structures, the
compiler is often sufficiently smart to generate SSE code itself.

For a synthetic font benchmark I wrote, this results in a nice 11%
decrease in runtime.
2023-06-01 15:13:47 +02:00
Shannon Booth
15151d7a4c LibGfx: Add Color::from_named_css_color_string
This is factored out from Color::from_string and determines the color
only from performing an ASCII case-insensitive search over the named
CSS colors.
2023-05-28 13:24:37 +02:00
MacDue
120e5b6b6f LibGfx: Add Color::with_opacity(float opacity)
This returns the color with its alpha scaled by the opacity.
2023-05-20 08:52:19 +02:00
MacDue
6ceb185865 LibGfx: Add ALWAYS_INLINE to Color::mixed_with()/interpolate()
I can see small speedup of about 6-7% with this for some gradient
painting, though Tim has been able to see an ~30% speedup in some
resizing cases so this seems like a worthwhile change.

Co-authored-by: Tim Ledbetter <timledbetter@gmail.com>
2023-02-18 17:10:04 +01:00
MacDue
3cc074c1b0 LibGfx: De-duplicate color interpolation code 2023-02-18 17:10:04 +01:00
MacDue
e5a39d134b LibGfx: Move Color::mixed_with() inline
This seems to give a small speedup to gradient painting and removes
Color::mixed_with() (which was 10% of the time) from the profile.
2023-02-18 17:10:04 +01:00
Timothy Flynn
027aee2c66 Userland: Add missing Math.h and IntegralMath.h header includes
These are currently being implicitly including by FixedPoint.h by way of
Format.h. The former will soon be removed from the latter, which would
otherwise cause a compile error in these files.
2023-01-19 11:29:48 +00:00
Timothy Flynn
ab99ed5fba LibIPC+Everywhere: Change IPC::encode's return type to ErrorOr
In doing so, this removes all uses of the Encoder's stream operator,
except for where it is currently still used in the generated IPC code.
So the stream operator currently discards any errors, which is the
existing behavior. A subsequent commit will propagate the errors.
2023-01-04 11:49:15 +01:00
Timothy Flynn
9b483625e6 LibIPC+Everywhere: Change IPC decoders to construct values in-place
Currently, the generated IPC decoders will default-construct the type to
be decoded, then pass that value by reference to the concrete decoder.
This, of course, requires that the type is default-constructible. This
was an issue for decoding Variants, which had to require the first type
in the Variant list is Empty, to ensure it is default constructible.

Further, this made it possible for values to become uninitialized in
user-defined decoders.

This patch makes the decoder interface such that the concrete decoders
themselves contruct the decoded type upon return from the decoder. To do
so, the default decoders in IPC::Decoder had to be moved to the IPC
namespace scope, as these decoders are now specializations instead of
overloaded methods (C++ requires specializations to be in a namespace
scope).
2022-12-26 09:36:16 +01:00
MacDue
bbc149ebb9 Meta+Userland: Pass Gfx::Color by value
Gfx::Color is always 4 bytes (it's just a wrapper over u32) it's less
work just to pass the color directly.

This also updates IPCCompiler to prevent from generating
Gfx::Color const &, which makes replacement easier.
2022-12-07 11:48:27 +01:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Andreas Oppebøen
29de0dbea5 LibGfx: Add missing color LightBlue
Will be used in a follow-up commit as alternative to Blue
2022-11-30 12:56:29 +00:00
MacDue
f274f04e35 LibGfx: Handle alpha in color distance
This gives a slightly more reasonable result when comparing different
colors with low alpha values.

For example comparing white with alpha 100 to transparent:

	Before
		distance: 0.78
	After
		distance: 0.07

   (Where distance is between 0 and 1)

The result is unchanged for comparing colors without alpha values.
2022-11-29 11:08:50 +01:00
Timothy Flynn
05f41382bb Userland: Properly define IPC::encode and IPC::decode specializations
In order to avoid the base encode/decode methods from being used (and
failing a static assertion), we must be sure to declare/define the
custom type implementations as template specializations.

After this, LibIPC is no longer sensitive to include order.
2022-11-15 13:25:51 -05:00
Daniel Bertalan
4296425bd8 Everywhere: Remove redundant inequality comparison operators
C++20 can automatically synthesize `operator!=` from `operator==`, so
there is no point in writing such functions by hand if all they do is
call through to `operator==`.

This fixes a compile error with compilers that implement P2468 (Clang
16 currently). This paper restores the C++17 behavior that if both
`T::operator==(U)` and `T::operator!=(U)` exist, `U == T` won't be
rewritten in reverse to call `T::operator==(U)`. Removing `!=` operators
makes the rewriting possible again.
See https://reviews.llvm.org/D134529#3853062
2022-11-06 10:25:08 -07:00
Timothy Slater
eec881ea34 LibGfx: Implement flood fill algorithm in Bitmap class
This change implements a flood fill algorithm for the Bitmap class. This
will be leveraged by various Tools in PixelPaint. Moving the code into
Bitmap reduces the duplication of the algorithm throughout the
PixelPaint Tools (currently Bucket Tool and Wand Select).

The flood fill function requires you to pass in a threshold value (0 -
100) as well as a lambda for what to do when a pixel gets reached. The
lambda is provided an IntPoint representing the coordinates of the pixel
that was just reached.

The genericized lambda approach allows for a variety of things to be
done as the flood algorithm progresses. For example, the Bucket Tool
will paint each pixel that gets reached with the fill_color. The Wand
Select tool wont actually alter the bitmap itself, instead it uses the
reached pixels to alter a selection mask.
2022-10-14 13:39:33 +02:00
MacDue
7bc0c66290 LibWeb+LibGfx: Move premultiplied alpha mixing to color.mixed_with()
This will be needed for mixing filters in LibGfx (and may be
generally useful elsewhere).
2022-09-16 10:50:48 +01:00
kleines Filmröllchen
049c1a536c LibGfx: Add saturation modification functions to Color
This operates via the HSV color space; I'm not 100% sure whether the
conversions are lossless.
2022-09-03 16:57:37 +01:00
kleines Filmröllchen
5bb277d9ec LibGfx: Add YUV conversion functions to Color 2022-09-03 16:57:37 +01:00
kleines Filmröllchen
ac23b806a2 LibGfx: Make Color::set_alpha constexpr 2022-09-03 16:57:37 +01:00
MacDue
73b05364e8 LibGfx: Add Color::contrast_ratio() 2022-05-26 00:07:24 +01:00
Hendiadyoin1
5fd49b9d9f LibGfx: Avoid some unnecessary Rounding in AffineTransform and Color
Casts suffice in these cases.
(Assuming standard rounding mode)
2022-05-07 20:25:39 +02:00
César Torres
4b0b22d897 LibGfx: Fix typo in Color constructor 2022-05-02 01:45:14 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Sam Atkins
404a7cb63a LibGfx+LibWeb: Use floats not doubles to create HSL colors
There's really no reason to use doubles here, except at the time I
wanted to use doubles everywhere in CSS. I now realize that is
excessive, so everything can be floats instead.
2022-03-22 15:47:36 +01:00
Andreas Kling
a6a8ba80fc LibGfx: Rename Color::from_rgba() => Color::from_argb()
This matches the rename of RGBA32 to ARGB32. It also makes more sense
when you see it used with 32-bit hexadecimal literals:

Before:
    Color::from_rgba(0xaarrggbb)

After:
    Color::from_argb(0xaarrggbb)
2022-03-04 23:40:21 +01:00
Andreas Kling
5ace66a903 LibGfx: Rename RGBA32 => ARGB32
The ARGB32 typedef is used for 32-bit #AARRGGBB quadruplets. As such,
the name RGBA32 was misleading, so let's call it ARGB32 instead.

Since endianness is a thing, let's not encode any assumptions about byte
order in the name of this type. ARGB32 is basically a "machine word"
of color.
2022-03-04 23:40:21 +01:00
Andreas Kling
5c4bb03926 LibGfx+GameOfLife: Remove Gfx::make_rgb() and its one user 2022-03-04 23:40:21 +01:00
Xavier Defrang
b1a15b02f1 PixelPaint+LibGfx: Add sepia color filter 2022-01-08 12:31:11 +01:00
Andreas Kling
cb9cac4e40 LibIPC+IPCCompiler+AK: Make IPC value decoders return ErrorOr<void>
This allows us to use TRY() in decoding helpers, leading to a nice
reduction in line count.
2021-11-28 23:14:19 +01:00
Andreas Kling
216e21a1fa AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
2021-11-17 00:21:13 +01:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling
5f7d008791 AK+Everywhere: Stop including Vector.h from StringView.h
Preparation for using Error.h from Vector.h. This required moving some
things out of line.
2021-11-10 21:58:58 +01:00
Sam Atkins
639c913e58 LibGfx: Make Color use east-const 2021-10-24 22:12:35 +02:00
Brian Gianforcaro
f327f54399 LibGfx: Use default instead of an empty constructor/destructor
Default implementations allow for more optimizations.
See: https://pvs-studio.com/en/docs/warnings/v832/
2021-09-16 17:17:13 +02:00
Mustafa Quraish
1cbab1c7e6 LibGfx/Color: Add suggested_foreground_color() method
This allows you to ask the color to recommend either white/black
as a contrasting text color if you were using the color as the
background. This uses the previously added luminosity() method.
2021-09-03 01:51:05 +02:00
Mustafa Quraish
882d57326c LibGfx/Color: Use luminosity to compute grayscale value
Issue #9758 discusses this.
2021-09-03 01:51:05 +02:00
Nicholas Hollett
4fe380f6da LibGfx: Add color helper for getting shades and tints
Shades are colors darker than the color, tints are colors lighter.
This is helpful in places where we need a bunch of similar colors
with some small differences.
2021-08-31 12:40:51 +02:00
Sam Atkins
fabbd06de4 LibGfx: Implement Color::from_hsl/hsla()
This is required by CSS, and implemented based on the CSS standard's
algorithm.
2021-07-22 23:09:01 +02:00
Samuel Kelemen
49999006ef LibGfx: remove constexpr, add noexcept on interpolate method
This removes `constexpr` from the interpolate method in Color.h and adds
`noexcept`. The roundf call cannot be constexpr on clang. This is the
only incompatibility preventing serenity from building under clang. I
tested this on OSX Big Sur 11.3 and 11.3.1, and everything works with
this change.
2021-05-27 00:01:38 +04:30
Matthew Olsson
f4941f5940 LibGfx: Add Color::from_cmyk 2021-05-25 00:24:09 +04:30
Linus Groh
d60ebbbba6 Revert "Userland: static vs non-static constexpr variables"
This reverts commit 800ea8ea96.

Booting the system no longer worked after these changes.
2021-05-21 10:30:52 +01:00