Add FrmImage
This commit is contained in:
parent
79c396c1a0
commit
f59c072d68
38
src/art.cc
38
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
|
||||
|
|
20
src/art.h
20
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
|
||||
|
|
Loading…
Reference in New Issue