Clipboard: Remove-unused bpp metadata
It's just more attack surface, and can be deduced from the format anyway.
This commit is contained in:
parent
4427da989f
commit
6c2ea4c4e9
Notes:
sideshowbarker
2024-07-19 00:59:58 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/6c2ea4c4e96 Pull-request: https://github.com/SerenityOS/serenity/pull/4351 Reviewed-by: https://github.com/bugaevc
2 changed files with 24 additions and 2 deletions
|
@ -161,7 +161,6 @@ void Clipboard::set_bitmap(const Gfx::Bitmap& bitmap)
|
|||
metadata.set("height", String::number(bitmap.height()));
|
||||
metadata.set("format", String::number((int)bitmap.format()));
|
||||
metadata.set("pitch", String::number(bitmap.pitch()));
|
||||
metadata.set("bpp", String::number(bitmap.bpp()));
|
||||
set_data({ bitmap.scanline(0), bitmap.size_in_bytes() }, "image/x-serenityos", metadata);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,29 @@ String ClipboardHistoryModel::column_name(int column) const
|
|||
}
|
||||
}
|
||||
|
||||
static const char* bpp_for_format_resilient(String format)
|
||||
{
|
||||
unsigned format_uint = format.to_uint().value_or(static_cast<unsigned>(Gfx::BitmapFormat::Invalid));
|
||||
// Cannot use Gfx::Bitmap::bpp_for_format here, as we have to accept invalid enum values.
|
||||
switch (static_cast<Gfx::BitmapFormat>(format_uint)) {
|
||||
case Gfx::BitmapFormat::Indexed1:
|
||||
return "1";
|
||||
case Gfx::BitmapFormat::Indexed2:
|
||||
return "2";
|
||||
case Gfx::BitmapFormat::Indexed4:
|
||||
return "4";
|
||||
case Gfx::BitmapFormat::Indexed8:
|
||||
return "8";
|
||||
case Gfx::BitmapFormat::RGB32:
|
||||
case Gfx::BitmapFormat::RGBA32:
|
||||
return "32";
|
||||
case Gfx::BitmapFormat::Invalid:
|
||||
/* fall-through */
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
if (role != GUI::ModelRole::Display)
|
||||
|
@ -67,7 +90,7 @@ GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, GUI::Mode
|
|||
builder.append('x');
|
||||
builder.append(data_and_type.metadata.get("height").value_or("?"));
|
||||
builder.append('x');
|
||||
builder.append(data_and_type.metadata.get("bpp").value_or("?"));
|
||||
builder.append(bpp_for_format_resilient(data_and_type.metadata.get("height").value_or("0")));
|
||||
builder.append(" bitmap");
|
||||
builder.append("]");
|
||||
return builder.to_string();
|
||||
|
|
Loading…
Add table
Reference in a new issue