diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2023-03-12 22:30:40 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-13 15:15:41 +0000 |
commit | 516d2f4892d98fc27814685bfc4af096eee029d4 (patch) | |
tree | 460d9fbf9fdaeb4f1eebea226a7277f78df5170e | |
parent | 13d172185226c3f3fa978232da593d94d0c58c4a (diff) | |
download | serenity-516d2f4892d98fc27814685bfc4af096eee029d4.zip |
image: Add an argument to choose to write PPMs in binary or in ASCII
-rw-r--r-- | Userland/Utilities/image.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Userland/Utilities/image.cpp b/Userland/Utilities/image.cpp index 7b3ec04782..2d93854d39 100644 --- a/Userland/Utilities/image.cpp +++ b/Userland/Utilities/image.cpp @@ -23,6 +23,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) StringView out_path; args_parser.add_option(out_path, "Path to output image file", "output", 'o', "FILE"); + bool ppm_ascii; + args_parser.add_option(ppm_ascii, "Convert to a PPM in ASCII", "ppm-ascii", {}); + args_parser.parse(arguments); if (out_path.is_empty()) { @@ -43,7 +46,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } else if (out_path.ends_with(".png"sv, CaseSensitivity::CaseInsensitive)) { bytes = TRY(Gfx::PNGWriter::encode(*frame)); } else if (out_path.ends_with(".ppm"sv, CaseSensitivity::CaseInsensitive)) { - bytes = TRY(Gfx::PortableFormatWriter::encode(*frame)); + auto const format = ppm_ascii ? Gfx::PortableFormatWriter::Options::Format::ASCII : Gfx::PortableFormatWriter::Options::Format::Raw; + bytes = TRY(Gfx::PortableFormatWriter::encode(*frame, Gfx::PortableFormatWriter::Options { .format = format })); } else if (out_path.ends_with(".qoi"sv, CaseSensitivity::CaseInsensitive)) { bytes = TRY(Gfx::QOIWriter::encode(*frame)); } else { |