diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp index 12a378ce4cf..cea9b8e141a 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp @@ -547,19 +547,22 @@ ErrorOr add_headers(Stream& stream, JPEGEncodingContext& context, JPEGWrit return {}; } +ErrorOr add_image(Stream& stream, JPEGEncodingContext& context) +{ + context.fdct_and_quantization(); + TRY(context.write_huffman_stream()); + TRY(add_end_of_image(stream)); + return {}; +} + } ErrorOr JPEGWriter::encode(Stream& stream, Bitmap const& bitmap, Options const& options) { JPEGEncodingContext context { JPEGBigEndianOutputBitStream { stream } }; TRY(add_headers(stream, context, options, bitmap.size())); - TRY(context.initialize_mcu(bitmap)); - context.fdct_and_quantization(); - - TRY(context.write_huffman_stream()); - - TRY(add_end_of_image(stream)); + TRY(add_image(stream, context)); return {}; }