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; 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() bool PngLoader::read()
{ {
png_bytep buffer; png_bytep buffer;

View file

@ -28,18 +28,20 @@
class PngLoader : public Loader class PngLoader : public Loader
{ {
public: public:
png_imagep image = nullptr;
const uint32_t* content = nullptr;
PngLoader(); PngLoader();
~PngLoader(); ~PngLoader();
using Loader::open; using Loader::open;
bool open(const string& path) override; bool open(const string& path) override;
bool open(const char* data, uint32_t size, bool copy) override;
bool read() override; bool read() override;
bool close() override; bool close() override;
const uint32_t* pixels() 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_