Skip to content

Commit

Permalink
LibGfx: Add formatters for Gfx::Color's different representations
Browse files Browse the repository at this point in the history
This makes debugging these values a bit easier
  • Loading branch information
mattco98 authored and kalenikaliaksandr committed Mar 3, 2024
1 parent 1f88ca2 commit 29b7048
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Userland/Libraries/LibGfx/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,18 @@ ErrorOr<void> AK::Formatter<Gfx::Color>::format(FormatBuilder& builder, Gfx::Col
{
return Formatter<StringView>::format(builder, value.to_byte_string());
}

ErrorOr<void> AK::Formatter<Gfx::YUV>::format(FormatBuilder& builder, Gfx::YUV value)
{
return Formatter<FormatString>::format(builder, "{} {} {}"sv, value.y, value.u, value.v);
}

ErrorOr<void> AK::Formatter<Gfx::HSV>::format(FormatBuilder& builder, Gfx::HSV value)
{
return Formatter<FormatString>::format(builder, "{} {} {}"sv, value.hue, value.saturation, value.value);
}

ErrorOr<void> AK::Formatter<Gfx::Oklab>::format(FormatBuilder& builder, Gfx::Oklab value)
{
return Formatter<FormatString>::format(builder, "{} {} {}"sv, value.L, value.a, value.b);
}
15 changes: 15 additions & 0 deletions Userland/Libraries/LibGfx/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,21 @@ struct Formatter<Gfx::Color> : public Formatter<StringView> {
ErrorOr<void> format(FormatBuilder&, Gfx::Color);
};

template<>
struct Formatter<Gfx::YUV> : public Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder&, Gfx::YUV);
};

template<>
struct Formatter<Gfx::HSV> : public Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder&, Gfx::HSV);
};

template<>
struct Formatter<Gfx::Oklab> : public Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder&, Gfx::Oklab);
};

}

namespace IPC {
Expand Down

0 comments on commit 29b7048

Please sign in to comment.