1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:27:45 +00:00

LibGfx: Allow BMPWriter to write v5 bmps and make that the default

This commit is contained in:
Nico Weber 2023-03-15 11:54:24 +01:00 committed by Linus Groh
parent 1db0883fea
commit a93a88c73c
2 changed files with 12 additions and 3 deletions

View file

@ -91,6 +91,7 @@ ErrorOr<ByteBuffer> BMPWriter::dump(Bitmap const& bitmap, Options options)
break; break;
case Options::DibHeader::V3: case Options::DibHeader::V3:
case Options::DibHeader::V4: case Options::DibHeader::V4:
case Options::DibHeader::V5:
m_compression = Compression::BI_BITFIELDS; m_compression = Compression::BI_BITFIELDS;
m_bytes_per_pixel = 4; m_bytes_per_pixel = 4;
m_include_alpha_channel = true; m_include_alpha_channel = true;
@ -126,14 +127,14 @@ ErrorOr<ByteBuffer> BMPWriter::dump(Bitmap const& bitmap, Options options)
streamer.write_u32(0); // TotalColors streamer.write_u32(0); // TotalColors
streamer.write_u32(0); // ImportantColors streamer.write_u32(0); // ImportantColors
if (dib_header == Options::DibHeader::V3 || dib_header == Options::DibHeader::V4) { if (dib_header >= Options::DibHeader::V3) {
streamer.write_u32(0x00ff0000); // Red bitmask streamer.write_u32(0x00ff0000); // Red bitmask
streamer.write_u32(0x0000ff00); // Green bitmask streamer.write_u32(0x0000ff00); // Green bitmask
streamer.write_u32(0x000000ff); // Blue bitmask streamer.write_u32(0x000000ff); // Blue bitmask
streamer.write_u32(0xff000000); // Alpha bitmask streamer.write_u32(0xff000000); // Alpha bitmask
} }
if (dib_header == Options::DibHeader::V4) { if (dib_header >= Options::DibHeader::V4) {
streamer.write_u32(0); // Colorspace streamer.write_u32(0); // Colorspace
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
@ -141,6 +142,13 @@ ErrorOr<ByteBuffer> BMPWriter::dump(Bitmap const& bitmap, Options options)
} }
} }
if (dib_header >= Options::DibHeader::V5) {
streamer.write_u32(4); // Rendering intent IMAGES / Perceptual.
streamer.write_u32(0); // Profile data
streamer.write_u32(0); // Profile size
streamer.write_u32(0); // Reserved
}
TRY(buffer.try_append(pixel_data.data(), pixel_data.size())); TRY(buffer.try_append(pixel_data.data(), pixel_data.size()));
return buffer; return buffer;
} }

View file

@ -18,8 +18,9 @@ struct BMPWriterOptions {
Info = 40, Info = 40,
V3 = 56, V3 = 56,
V4 = 108, V4 = 108,
V5 = 124,
}; };
DibHeader dib_header = DibHeader::V4; DibHeader dib_header = DibHeader::V5;
}; };
class BMPWriter { class BMPWriter {