ladybird/Userland/Utilities/image2bin.cpp
Ali Mohammad Pur 5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30

40 lines
1.2 KiB
C++

/*
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteString.h>
#include <AK/Random.h>
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DirIterator.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/Desktop.h>
#include <LibMain/Main.h>
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath unix"));
ByteString path;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(path, "Path to image", "path");
args_parser.parse(arguments);
auto bitmap = TRY(Gfx::Bitmap::load_from_file(path));
TRY(Core::System::pledge("stdio"));
Vector<u8> data;
for (auto height = 0; height < bitmap->size().height(); height++) {
auto* scanline = bitmap->scanline_u8(height);
for (auto byte_index_in_row = 0u; byte_index_in_row < bitmap->pitch(); byte_index_in_row++) {
TRY(data.try_append(scanline[byte_index_in_row]));
}
}
VERIFY(data.size() == bitmap->size_in_bytes());
TRY(Core::System::write(STDOUT_FILENO, data.span()));
return 0;
}