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.
This commit is contained in:
Nico Weber 2024-01-24 10:05:20 -05:00 committed by Andreas Kling
parent 653b614611
commit 96c71b7042

View file

@ -20,6 +20,11 @@ struct LoadedImage {
Optional<ReadonlyBytes> icc_data;
};
static ErrorOr<LoadedImage> load_image(RefPtr<Gfx::ImageDecoder> const& decoder, int frame_index)
{
return LoadedImage { TRY(decoder->frame(frame_index)).image, TRY(decoder->icc_data()) };
}
static ErrorOr<void> do_move_alpha_to_rgb(LoadedImage& image)
{
auto frame = image.bitmap;
@ -151,7 +156,7 @@ ErrorOr<int> 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));