From f59c072d68755b8dabc8e5098428c04ffbadb43f Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sat, 24 Sep 2022 16:14:54 +0300 Subject: [PATCH] Add FrmImage --- src/art.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/art.h | 20 ++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/art.cc b/src/art.cc index 51d1cb6..bc229eb 100644 --- a/src/art.cc +++ b/src/art.cc @@ -1231,4 +1231,42 @@ int artWrite(const char* path, unsigned char* data) return 0; } +FrmImage::FrmImage() +{ + _key = nullptr; + _data = nullptr; + _width = 0; + _height = 0; +} + +FrmImage::~FrmImage() +{ + unlock(); +} + +bool FrmImage::lock(unsigned int fid) +{ + if (isLocked()) { + return false; + } + + _data = artLockFrameDataReturningSize(fid, &_key, &_width, &_height); + if (!_data) { + return false; + } + + return true; +} + +void FrmImage::unlock() +{ + if (isLocked()) { + artUnlock(_key); + _key = nullptr; + _data = nullptr; + _width = 0; + _height = 0; + } +} + } // namespace fallout diff --git a/src/art.h b/src/art.h index de5d64a..9f0d628 100644 --- a/src/art.h +++ b/src/art.h @@ -151,6 +151,26 @@ int buildFid(int objectType, int frmId, int animType, int a4, int rotation); int artRead(const char* path, unsigned char* data); int artWrite(const char* path, unsigned char* data); +class FrmImage { +public: + FrmImage(); + ~FrmImage(); + + bool isLocked() const { return _key != nullptr; } + bool lock(unsigned int fid); + void unlock(); + + int getWidth() const { return _width; } + int getHeight() const { return _height; } + unsigned char* getData() const { return _data; } + +private: + CacheEntry* _key; + unsigned char* _data; + int _width; + int _height; +}; + } // namespace fallout #endif