From 917c43de100807f4397e36b66b1a748dbf44370e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 7 Feb 2021 18:15:18 +0200 Subject: [PATCH] Make it possible to load an image into an externally allocated buffer --- source/graphics/bmploader.cpp | 1 - source/graphics/devil/devilloader.cpp | 1 - source/graphics/image.cpp | 18 +++++++++++++----- source/graphics/image.h | 2 ++ source/graphics/imageloader.cpp | 2 ++ source/graphics/jpeg/jpegloader.cpp | 1 - source/graphics/png/pngloader.cpp | 2 -- source/graphics/quartz/quartzloader.cpp | 1 - 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/source/graphics/bmploader.cpp b/source/graphics/bmploader.cpp index d88e2aa..a339463 100644 --- a/source/graphics/bmploader.cpp +++ b/source/graphics/bmploader.cpp @@ -98,7 +98,6 @@ void BmpLoader::load_headers_(Image::Data &data) void BmpLoader::load_pixels_(Image::Data &data) { - data.pixels = new char[data.stride*data.height]; if(invert_row_order) { for(unsigned y=0; y(buffer); + load(loader); +} + void Image::load_headers(ImageLoader &loader) { if(loader.get_state()==ImageLoader::INITIAL) diff --git a/source/graphics/image.h b/source/graphics/image.h index 7b5236e..51147ce 100644 --- a/source/graphics/image.h +++ b/source/graphics/image.h @@ -20,6 +20,7 @@ public: unsigned width; unsigned height; unsigned stride; + char *owned_pixels; char *pixels; Data(); @@ -35,6 +36,7 @@ public: void load_file(const std::string &); void load_io(IO::Seekable &); void load(ImageLoader &); + void load_into(ImageLoader &, void *); void load_headers(ImageLoader &); PixelFormat get_format() const { return data.fmt; } diff --git a/source/graphics/imageloader.cpp b/source/graphics/imageloader.cpp index fa6fcf8..52b0874 100644 --- a/source/graphics/imageloader.cpp +++ b/source/graphics/imageloader.cpp @@ -91,6 +91,8 @@ void ImageLoader::load(Image::Data &data) if(statejpeg.output_scanlinemessage); } - data.pixels = new char[data.stride*data.height]; - if(priv->interlace==PNG_INTERLACE_ADAM7) { // ADAM7 requires all rows to be loaded at once diff --git a/source/graphics/quartz/quartzloader.cpp b/source/graphics/quartz/quartzloader.cpp index e025b66..3799bcd 100644 --- a/source/graphics/quartz/quartzloader.cpp +++ b/source/graphics/quartz/quartzloader.cpp @@ -121,7 +121,6 @@ void QuartzLoader::load_(Image::Data &data) { CGDataProviderRef dp = CGImageGetDataProvider(image); CFDataRef image_data = CGDataProviderCopyData(dp); - data.pixels = new char[data.height*data.stride]; unsigned offset = (alpha==kCGImageAlphaNoneSkipFirst); CFRange range = CFRangeMake(offset, CFDataGetLength(image_data)-offset); CFDataGetBytes(image_data, range, reinterpret_cast(data.pixels)); -- 2.45.2