png_loader: added open from memory

Added PngLoader::open(const char* data, uint32_t size, bool copy)
Changed variables visibility to private
This commit is contained in:
Michal Maciola 2021-07-02 14:03:18 +02:00 committed by Hermet Park
parent 1507438ecc
commit 1e1f232016
2 changed files with 19 additions and 5 deletions

View file

@ -51,6 +51,18 @@ bool PngLoader::open(const string& path)
return true;
}
bool PngLoader::open(const char* data, uint32_t size, bool copy)
{
image->opaque = NULL;
if (!png_image_begin_read_from_memory(image, data, size)) return false;
vw = w = image->width;
vh = h = image->height;
return true;
}
bool PngLoader::read()
{
png_bytep buffer;
@ -76,4 +88,4 @@ bool PngLoader::close()
const uint32_t* PngLoader::pixels()
{
return this->content;
}
}

View file

@ -28,18 +28,20 @@
class PngLoader : public Loader
{
public:
png_imagep image = nullptr;
const uint32_t* content = nullptr;
PngLoader();
~PngLoader();
using Loader::open;
bool open(const string& path) override;
bool open(const char* data, uint32_t size, bool copy) override;
bool read() override;
bool close() override;
const uint32_t* pixels() override;
private:
png_imagep image = nullptr;
const uint32_t* content = nullptr;
};
#endif //_TVG_PNG_LOADER_H_
#endif //_TVG_PNG_LOADER_H_