Add FrmImage

This commit is contained in:
Alexander Batalov 2022-09-24 16:14:54 +03:00
parent 79c396c1a0
commit f59c072d68
2 changed files with 58 additions and 0 deletions

View File

@ -1231,4 +1231,42 @@ int artWrite(const char* path, unsigned char* data)
return 0; 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 } // namespace fallout

View File

@ -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 artRead(const char* path, unsigned char* data);
int artWrite(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 } // namespace fallout
#endif #endif