From 39f1a6eb6f9e7c8f56e3168d10c2bc565ce10257 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 28 Jan 2023 20:12:17 +0000 Subject: [PATCH] PixelPaint: Remove `try_` prefix from fallible Image methods --- .../PixelPaint/HistogramWidget.cpp | 2 +- Userland/Applications/PixelPaint/Image.cpp | 30 +++++++++---------- Userland/Applications/PixelPaint/Image.h | 12 ++++---- .../Applications/PixelPaint/MainWidget.cpp | 10 +++---- .../Applications/PixelPaint/ProjectLoader.cpp | 6 ++-- .../PixelPaint/VectorscopeWidget.cpp | 2 +- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Userland/Applications/PixelPaint/HistogramWidget.cpp b/Userland/Applications/PixelPaint/HistogramWidget.cpp index fb940caf762..60159b14654 100644 --- a/Userland/Applications/PixelPaint/HistogramWidget.cpp +++ b/Userland/Applications/PixelPaint/HistogramWidget.cpp @@ -21,7 +21,7 @@ ErrorOr HistogramWidget::rebuild_histogram_data() if (!m_image) return {}; - auto full_bitmap = TRY(m_image->try_compose_bitmap(Gfx::BitmapFormat::BGRA8888)); + auto full_bitmap = TRY(m_image->compose_bitmap(Gfx::BitmapFormat::BGRA8888)); m_data.red.clear_with_capacity(); m_data.green.clear_with_capacity(); diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index d83d41d0e1b..fa72b928a3c 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -21,7 +21,7 @@ namespace PixelPaint { -ErrorOr> Image::try_create_with_size(Gfx::IntSize size) +ErrorOr> Image::create_with_size(Gfx::IntSize size) { VERIFY(!size.is_empty()); @@ -51,7 +51,7 @@ void Image::paint_into(GUI::Painter& painter, Gfx::IntRect const& dest_rect) con } } -ErrorOr> Image::try_decode_bitmap(ReadonlyBytes bitmap_data) +ErrorOr> Image::decode_bitmap(ReadonlyBytes bitmap_data) { // Spawn a new ImageDecoder service process and connect to it. auto client = TRY(ImageDecoderClient::Client::try_create()); @@ -72,18 +72,18 @@ ErrorOr> Image::try_decode_bitmap(ReadonlyBytes bitma return decoded_bitmap.release_nonnull(); } -ErrorOr> Image::try_create_from_bitmap(NonnullRefPtr const& bitmap) +ErrorOr> Image::create_from_bitmap(NonnullRefPtr const& bitmap) { - auto image = TRY(try_create_with_size({ bitmap->width(), bitmap->height() })); + auto image = TRY(create_with_size({ bitmap->width(), bitmap->height() })); auto layer = TRY(Layer::try_create_with_bitmap(*image, *bitmap, "Background")); image->add_layer(move(layer)); return image; } -ErrorOr> Image::try_create_from_pixel_paint_json(JsonObject const& json) +ErrorOr> Image::create_from_pixel_paint_json(JsonObject const& json) { // FIXME: Handle invalid JSON data - auto image = TRY(try_create_with_size({ json.get_i32("width"sv).value_or(0), json.get_i32("height"sv).value_or(0) })); + auto image = TRY(create_with_size({ json.get_i32("width"sv).value_or(0), json.get_i32("height"sv).value_or(0) })); auto layers_value = json.get_array("layers"sv).value(); for (auto& layer_value : layers_value.values()) { @@ -92,13 +92,13 @@ ErrorOr> Image::try_create_from_pixel_paint_json(JsonObject auto bitmap_base64_encoded = layer_object.get_deprecated_string("bitmap"sv).value(); auto bitmap_data = TRY(decode_base64(bitmap_base64_encoded)); - auto bitmap = TRY(try_decode_bitmap(bitmap_data)); + auto bitmap = TRY(decode_bitmap(bitmap_data)); auto layer = TRY(Layer::try_create_with_bitmap(*image, move(bitmap), name)); if (auto const& mask_object = layer_object.get_deprecated_string("mask"sv); mask_object.has_value()) { auto mask_base64_encoded = mask_object.value(); auto mask_data = TRY(decode_base64(mask_base64_encoded)); - auto mask = TRY(try_decode_bitmap(mask_data)); + auto mask = TRY(decode_bitmap(mask_data)); TRY(layer->try_set_bitmaps(layer->content_bitmap(), mask)); } @@ -146,7 +146,7 @@ ErrorOr Image::serialize_as_json(JsonObjectSerializer& json return {}; } -ErrorOr> Image::try_compose_bitmap(Gfx::BitmapFormat format) const +ErrorOr> Image::compose_bitmap(Gfx::BitmapFormat format) const { auto bitmap = TRY(Gfx::Bitmap::create(format, m_size)); GUI::Painter painter(bitmap); @@ -154,14 +154,14 @@ ErrorOr> Image::try_compose_bitmap(Gfx::BitmapFormat return bitmap; } -RefPtr Image::try_copy_bitmap(Selection const& selection) const +RefPtr Image::copy_bitmap(Selection const& selection) const { if (selection.is_empty()) return {}; auto selection_rect = selection.bounding_rect(); // FIXME: Add a way to only compose a certain part of the image - auto bitmap_or_error = try_compose_bitmap(Gfx::BitmapFormat::BGRA8888); + auto bitmap_or_error = compose_bitmap(Gfx::BitmapFormat::BGRA8888); if (bitmap_or_error.is_error()) return {}; auto full_bitmap = bitmap_or_error.release_value(); @@ -175,7 +175,7 @@ RefPtr Image::try_copy_bitmap(Selection const& selection) const ErrorOr Image::export_bmp_to_file(NonnullOwnPtr stream, bool preserve_alpha_channel) const { auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; - auto bitmap = TRY(try_compose_bitmap(bitmap_format)); + auto bitmap = TRY(compose_bitmap(bitmap_format)); Gfx::BMPWriter dumper; auto encoded_data = dumper.dump(bitmap); @@ -186,7 +186,7 @@ ErrorOr Image::export_bmp_to_file(NonnullOwnPtr stre ErrorOr Image::export_png_to_file(NonnullOwnPtr stream, bool preserve_alpha_channel) const { auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; - auto bitmap = TRY(try_compose_bitmap(bitmap_format)); + auto bitmap = TRY(compose_bitmap(bitmap_format)); auto encoded_data = TRY(Gfx::PNGWriter::encode(*bitmap)); TRY(stream->write_entire_buffer(encoded_data)); @@ -195,7 +195,7 @@ ErrorOr Image::export_png_to_file(NonnullOwnPtr stre ErrorOr Image::export_qoi_to_file(NonnullOwnPtr stream) const { - auto bitmap = TRY(try_compose_bitmap(Gfx::BitmapFormat::BGRA8888)); + auto bitmap = TRY(compose_bitmap(Gfx::BitmapFormat::BGRA8888)); auto encoded_data = Gfx::QOIWriter::encode(bitmap); TRY(stream->write_entire_buffer(encoded_data)); @@ -217,7 +217,7 @@ void Image::add_layer(NonnullRefPtr layer) ErrorOr> Image::take_snapshot() const { - auto snapshot = TRY(try_create_with_size(m_size)); + auto snapshot = TRY(create_with_size(m_size)); for (auto const& layer : m_layers) { auto layer_snapshot = TRY(Layer::try_create_snapshot(*snapshot, layer)); snapshot->add_layer(move(layer_snapshot)); diff --git a/Userland/Applications/PixelPaint/Image.h b/Userland/Applications/PixelPaint/Image.h index b029056d228..b78dde7372b 100644 --- a/Userland/Applications/PixelPaint/Image.h +++ b/Userland/Applications/PixelPaint/Image.h @@ -45,15 +45,15 @@ protected: class Image : public RefCounted { public: - static ErrorOr> try_create_with_size(Gfx::IntSize); - static ErrorOr> try_create_from_pixel_paint_json(JsonObject const&); - static ErrorOr> try_create_from_bitmap(NonnullRefPtr const&); + static ErrorOr> create_with_size(Gfx::IntSize); + static ErrorOr> create_from_pixel_paint_json(JsonObject const&); + static ErrorOr> create_from_bitmap(NonnullRefPtr const&); - static ErrorOr> try_decode_bitmap(ReadonlyBytes); + static ErrorOr> decode_bitmap(ReadonlyBytes); // This generates a new Bitmap with the final image (all layers composed according to their attributes.) - ErrorOr> try_compose_bitmap(Gfx::BitmapFormat format) const; - RefPtr try_copy_bitmap(Selection const&) const; + ErrorOr> compose_bitmap(Gfx::BitmapFormat format) const; + RefPtr copy_bitmap(Selection const&) const; Selection& selection() { return m_selection; } Selection const& selection() const { return m_selection; } diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 88e4956430a..b20923820a6 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -152,7 +152,7 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) "&New Image...", { Mod_Ctrl, Key_N }, g_icon_bag.filetype_pixelpaint, [&](auto&) { auto dialog = PixelPaint::CreateNewImageDialog::construct(&window); if (dialog->exec() == GUI::Dialog::ExecResult::OK) { - auto image_result = PixelPaint::Image::try_create_with_size(dialog->image_size()); + auto image_result = PixelPaint::Image::create_with_size(dialog->image_size()); if (image_result.is_error()) { GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Failed to create image with size {}, error: {}", dialog->image_size(), image_result.error())); return; @@ -320,9 +320,9 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) auto* editor = current_image_editor(); VERIFY(editor); - auto bitmap = editor->image().try_copy_bitmap(editor->image().selection()); + auto bitmap = editor->image().copy_bitmap(editor->image().selection()); if (!bitmap) { - dbgln("try_copy_bitmap() from Image failed"); + dbgln("copy_bitmap() from Image failed"); return; } GUI::Clipboard::the().set_bitmap(*bitmap); @@ -1113,7 +1113,7 @@ void MainWidget::open_image(FileSystemAccessClient::File file) ErrorOr MainWidget::create_default_image() { - auto image = TRY(Image::try_create_with_size({ 510, 356 })); + auto image = TRY(Image::create_with_size({ 510, 356 })); auto bg_layer = TRY(Layer::try_create_with_size(*image, image->size(), "Background")); image->add_layer(*bg_layer); @@ -1136,7 +1136,7 @@ ErrorOr MainWidget::create_image_from_clipboard() return Error::from_string_view("There is no image in a clipboard to paste."sv); } - auto image = TRY(PixelPaint::Image::try_create_with_size(bitmap->size())); + auto image = TRY(PixelPaint::Image::create_with_size(bitmap->size())); auto layer = TRY(PixelPaint::Layer::try_create_with_bitmap(image, *bitmap, "Pasted layer")); image->add_layer(*layer); diff --git a/Userland/Applications/PixelPaint/ProjectLoader.cpp b/Userland/Applications/PixelPaint/ProjectLoader.cpp index b26ca0900b5..c00e435204b 100644 --- a/Userland/Applications/PixelPaint/ProjectLoader.cpp +++ b/Userland/Applications/PixelPaint/ProjectLoader.cpp @@ -24,15 +24,15 @@ ErrorOr ProjectLoader::try_load_from_file(NonnullOwnPtr VectorscopeWidget::rebuild_vectorscope_data() m_vectorscope_data.fill({}); VERIFY(AK::abs(m_vectorscope_data[0][0]) < 0.01f); - auto full_bitmap = TRY(m_image->try_compose_bitmap(Gfx::BitmapFormat::BGRA8888)); + auto full_bitmap = TRY(m_image->compose_bitmap(Gfx::BitmapFormat::BGRA8888)); for (size_t x = 0; x < static_cast(full_bitmap->width()); ++x) { for (size_t y = 0; y < static_cast(full_bitmap->height()); ++y) {