From 96c71b7042688c7ddbb9ed9c8e6fb09b9d7b5474 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 24 Jan 2024 10:05:20 -0500 Subject: [PATCH] image: Move image loading code into a separate function Haters will say this is overkill, but this function will do a bit more once we allow loading CMYK data. No behavior change. --- Userland/Utilities/image.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/image.cpp b/Userland/Utilities/image.cpp index f92193167f..e698bb44bd 100644 --- a/Userland/Utilities/image.cpp +++ b/Userland/Utilities/image.cpp @@ -20,6 +20,11 @@ struct LoadedImage { Optional icc_data; }; +static ErrorOr load_image(RefPtr const& decoder, int frame_index) +{ + return LoadedImage { TRY(decoder->frame(frame_index)).image, TRY(decoder->icc_data()) }; +} + static ErrorOr do_move_alpha_to_rgb(LoadedImage& image) { auto frame = image.bitmap; @@ -151,7 +156,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (!decoder) return Error::from_string_view("Failed to decode input file"sv); - LoadedImage image = { TRY(decoder->frame(frame_index)).image, TRY(decoder->icc_data()) }; + LoadedImage image = TRY(load_image(*decoder, frame_index)); if (move_alpha_to_rgb) TRY(do_move_alpha_to_rgb(image));