mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
LibGfx/PortableFormat: Simplify read_number
signature
The function signature goes from: `bool read_number(Streamer& streamer, TValue* value)` to `ErrorOr<u16> read_number(Streamer& streamer)` It allows us to, on one hand use `ErrorOr` for error propagation, removing an out parameter in the meantime, and on the other hand remove the useless template.
This commit is contained in:
parent
387894cdf2
commit
9052a6febf
3 changed files with 26 additions and 29 deletions
|
@ -22,30 +22,29 @@ bool read_image_data(PPMLoadingContext& context, Streamer& streamer)
|
|||
color_data.ensure_capacity(context.width * context.height);
|
||||
|
||||
if (context.type == PPMLoadingContext::Type::ASCII) {
|
||||
u16 red;
|
||||
u16 green;
|
||||
u16 blue;
|
||||
|
||||
while (true) {
|
||||
if (!read_number(streamer, &red))
|
||||
auto const red_or_error = read_number(streamer);
|
||||
if (red_or_error.is_error())
|
||||
break;
|
||||
|
||||
if (!read_whitespace(context, streamer))
|
||||
break;
|
||||
|
||||
if (!read_number(streamer, &green))
|
||||
auto const green_or_error = read_number(streamer);
|
||||
if (green_or_error.is_error())
|
||||
break;
|
||||
|
||||
if (!read_whitespace(context, streamer))
|
||||
break;
|
||||
|
||||
if (!read_number(streamer, &blue))
|
||||
auto const blue_or_error = read_number(streamer);
|
||||
if (blue_or_error.is_error())
|
||||
break;
|
||||
|
||||
if (!read_whitespace(context, streamer))
|
||||
break;
|
||||
|
||||
Color color { (u8)red, (u8)green, (u8)blue };
|
||||
Color color { (u8)red_or_error.value(), (u8)green_or_error.value(), (u8)blue_or_error.value() };
|
||||
if (context.format_details.max_val < 255)
|
||||
color = adjust_color(context.format_details.max_val, color);
|
||||
color_data.append(color);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue