mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 21:55:07 +00:00
PNGLoader: Allocate enough space for the compressed data buffer up front.
This is a 2x speedup on wallpaper loading.
This commit is contained in:
parent
332b5a96f6
commit
fe25f957e5
1 changed files with 4 additions and 3 deletions
|
@ -99,7 +99,6 @@ static bool process_chunk(Streamer&, PNGLoadingContext& context);
|
||||||
|
|
||||||
RetainPtr<GraphicsBitmap> load_png(const String& path)
|
RetainPtr<GraphicsBitmap> load_png(const String& path)
|
||||||
{
|
{
|
||||||
Stopwatch sw("load_png");
|
|
||||||
int fd = open(path.characters(), O_RDONLY);
|
int fd = open(path.characters(), O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("open");
|
perror("open");
|
||||||
|
@ -153,7 +152,7 @@ static byte paeth_predictor(int a, int b, int c)
|
||||||
|
|
||||||
static RetainPtr<GraphicsBitmap> load_png_impl(const byte* data, int data_size)
|
static RetainPtr<GraphicsBitmap> load_png_impl(const byte* data, int data_size)
|
||||||
{
|
{
|
||||||
Stopwatch sw("load_png_impl");
|
Stopwatch sw("load_png_impl: total");
|
||||||
const byte* data_ptr = data;
|
const byte* data_ptr = data;
|
||||||
int data_remaining = data_size;
|
int data_remaining = data_size;
|
||||||
|
|
||||||
|
@ -165,6 +164,8 @@ static RetainPtr<GraphicsBitmap> load_png_impl(const byte* data, int data_size)
|
||||||
|
|
||||||
PNGLoadingContext context;
|
PNGLoadingContext context;
|
||||||
|
|
||||||
|
context.compressed_data.ensure_capacity(data_size);
|
||||||
|
|
||||||
data_ptr += sizeof(png_header);
|
data_ptr += sizeof(png_header);
|
||||||
data_remaining -= sizeof(png_header);
|
data_remaining -= sizeof(png_header);
|
||||||
|
|
||||||
|
@ -205,7 +206,7 @@ static RetainPtr<GraphicsBitmap> load_png_impl(const byte* data, int data_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Stopwatch sw("create bitmap");
|
Stopwatch sw("load_png_impl: create bitmap");
|
||||||
context.bitmap = GraphicsBitmap::create(GraphicsBitmap::Format::RGBA32, { context.width, context.height });
|
context.bitmap = GraphicsBitmap::create(GraphicsBitmap::Format::RGBA32, { context.width, context.height });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue