mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
LibGfx: Prevent a copy in PNGWriter by storing type data at start
This commit is contained in:
parent
d84c4b94da
commit
db36ddc763
1 changed files with 13 additions and 10 deletions
|
@ -28,6 +28,8 @@ public:
|
|||
|
||||
void add_u8(u8);
|
||||
|
||||
void store_type();
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
requires(IsUnsigned<T>) void add(T);
|
||||
|
@ -56,6 +58,14 @@ private:
|
|||
PNGChunk::PNGChunk(String type)
|
||||
: m_type(move(type))
|
||||
{
|
||||
store_type();
|
||||
}
|
||||
|
||||
void PNGChunk::store_type()
|
||||
{
|
||||
for (auto character : type()) {
|
||||
m_data.append(&character, sizeof(character));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -121,19 +131,12 @@ void NonCompressibleBlock::update_adler(u8 data)
|
|||
|
||||
void PNGWriter::add_chunk(PNGChunk const& png_chunk)
|
||||
{
|
||||
ByteBuffer combined;
|
||||
for (auto character : png_chunk.type()) {
|
||||
combined.append(&character, sizeof(character));
|
||||
}
|
||||
|
||||
combined.append(png_chunk.data().data(), png_chunk.data().size());
|
||||
|
||||
auto crc = BigEndian(Crypto::Checksum::CRC32({ (const u8*)combined.data(), combined.size() }).digest());
|
||||
auto data_len = BigEndian(png_chunk.data().size());
|
||||
auto crc = BigEndian(Crypto::Checksum::CRC32({ (const u8*)png_chunk.data().data(), png_chunk.data().size() }).digest());
|
||||
auto data_len = BigEndian(png_chunk.data().size() - png_chunk.type().length());
|
||||
|
||||
ByteBuffer buf;
|
||||
buf.append(&data_len, sizeof(u32));
|
||||
buf.append(combined.data(), combined.size());
|
||||
buf.append(png_chunk.data().data(), png_chunk.data().size());
|
||||
buf.append(&crc, sizeof(u32));
|
||||
|
||||
m_data.append(buf.data(), buf.size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue