summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-03-12 12:09:29 -0400
committerJelle Raaijmakers <jelle@gmta.nl>2023-03-12 21:32:21 +0100
commitf1a3028ef10db2756fa672668b1cecb7cc2cbee0 (patch)
tree81feaa65cf3359cf8396cc31c2a7be4abe3452da
parent01387eb72b63e30b6a39249ad819e2ba98e6b82d (diff)
downloadserenity-f1a3028ef10db2756fa672668b1cecb7cc2cbee0.zip
LibGfx: Change BMPWriter API to be consistent with other image writers
-rw-r--r--Userland/Applications/Magnifier/main.cpp3
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp3
-rw-r--r--Userland/Demos/Mandelbrot/Mandelbrot.cpp6
-rw-r--r--Userland/Libraries/LibGfx/BMPWriter.cpp5
-rw-r--r--Userland/Libraries/LibGfx/BMPWriter.h6
-rw-r--r--Userland/Utilities/image.cpp2
6 files changed, 14 insertions, 11 deletions
diff --git a/Userland/Applications/Magnifier/main.cpp b/Userland/Applications/Magnifier/main.cpp
index 5cceafd8a7..9595c89eac 100644
--- a/Userland/Applications/Magnifier/main.cpp
+++ b/Userland/Applications/Magnifier/main.cpp
@@ -27,8 +27,7 @@
static ErrorOr<ByteBuffer> dump_bitmap(RefPtr<Gfx::Bitmap> bitmap, AK::StringView extension)
{
if (extension == "bmp") {
- Gfx::BMPWriter dumper;
- return dumper.dump(bitmap);
+ return Gfx::BMPWriter::encode(*bitmap);
} else if (extension == "png") {
return Gfx::PNGWriter::encode(*bitmap);
} else if (extension == "qoi") {
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp
index c6beb8f60f..81b3ca6569 100644
--- a/Userland/Applications/PixelPaint/Image.cpp
+++ b/Userland/Applications/PixelPaint/Image.cpp
@@ -176,8 +176,7 @@ ErrorOr<void> Image::export_bmp_to_file(NonnullOwnPtr<Stream> stream, bool prese
auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888;
auto bitmap = TRY(compose_bitmap(bitmap_format));
- Gfx::BMPWriter dumper;
- auto encoded_data = dumper.dump(bitmap);
+ auto encoded_data = TRY(Gfx::BMPWriter::encode(*bitmap));
TRY(stream->write_entire_buffer(encoded_data));
return {};
}
diff --git a/Userland/Demos/Mandelbrot/Mandelbrot.cpp b/Userland/Demos/Mandelbrot/Mandelbrot.cpp
index c975bbaf9c..405481e1ad 100644
--- a/Userland/Demos/Mandelbrot/Mandelbrot.cpp
+++ b/Userland/Demos/Mandelbrot/Mandelbrot.cpp
@@ -371,11 +371,9 @@ ErrorOr<void> Mandelbrot::export_image(DeprecatedString const& export_path, Imag
m_set.resize(Gfx::IntSize { 1920, 1080 });
ByteBuffer encoded_data;
switch (image_type) {
- case ImageType::BMP: {
- Gfx::BMPWriter dumper;
- encoded_data = dumper.dump(m_set.bitmap());
+ case ImageType::BMP:
+ encoded_data = TRY(Gfx::BMPWriter::encode(m_set.bitmap()));
break;
- }
case ImageType::PNG:
encoded_data = TRY(Gfx::PNGWriter::encode(m_set.bitmap()));
break;
diff --git a/Userland/Libraries/LibGfx/BMPWriter.cpp b/Userland/Libraries/LibGfx/BMPWriter.cpp
index ed320ac7b1..0a1fd43afa 100644
--- a/Userland/Libraries/LibGfx/BMPWriter.cpp
+++ b/Userland/Libraries/LibGfx/BMPWriter.cpp
@@ -67,6 +67,11 @@ static ByteBuffer write_pixel_data(RefPtr<Bitmap const> bitmap, int pixel_row_da
return buffer;
}
+ErrorOr<ByteBuffer> BMPWriter::encode(Bitmap const& bitmap, Options options)
+{
+ return BMPWriter().dump(bitmap, options);
+}
+
ByteBuffer BMPWriter::compress_pixel_data(ByteBuffer const& pixel_data, BMPWriter::Compression compression)
{
switch (compression) {
diff --git a/Userland/Libraries/LibGfx/BMPWriter.h b/Userland/Libraries/LibGfx/BMPWriter.h
index 723e6ee7ed..467540b55b 100644
--- a/Userland/Libraries/LibGfx/BMPWriter.h
+++ b/Userland/Libraries/LibGfx/BMPWriter.h
@@ -25,11 +25,13 @@ struct BMPWriterOptions {
class BMPWriter {
public:
using Options = BMPWriterOptions;
+ static ErrorOr<ByteBuffer> encode(Bitmap const&, Options options = Options {});
+
+private:
BMPWriter() = default;
- ByteBuffer dump(RefPtr<Bitmap const>, Options options = Options {});
+ ByteBuffer dump(RefPtr<Bitmap const>, Options options);
-private:
enum class Compression : u32 {
BI_RGB = 0,
BI_BITFIELDS = 3,
diff --git a/Userland/Utilities/image.cpp b/Userland/Utilities/image.cpp
index e53814f992..a523dee603 100644
--- a/Userland/Utilities/image.cpp
+++ b/Userland/Utilities/image.cpp
@@ -38,7 +38,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
ByteBuffer bytes;
if (out_path.ends_with(".bmp"sv, CaseSensitivity::CaseInsensitive)) {
- bytes = Gfx::BMPWriter().dump(frame);
+ bytes = TRY(Gfx::BMPWriter::encode(*frame));
} else if (out_path.ends_with(".png"sv, CaseSensitivity::CaseInsensitive)) {
bytes = TRY(Gfx::PNGWriter::encode(*frame));
} else if (out_path.ends_with(".qoi"sv, CaseSensitivity::CaseInsensitive)) {