refactor VxImageDescEx

This commit is contained in:
yyc12345 2023-09-11 14:39:07 +08:00
parent 1e0ed360bd
commit e2647ed39b
7 changed files with 195 additions and 149 deletions

View File

@ -9,23 +9,23 @@ namespace LibCmo::CK2 {
#pragma region Assist RW Functions #pragma region Assist RW Functions
bool CKBitmapData::ReadSpecificFormatBitmap(CKStateChunk* chk, CKBitmapSlot* slot) { bool CKBitmapData::ReadSpecificFormatBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot) {
return false; return false;
} }
bool CKBitmapData::ReadRawBitmap(CKStateChunk* chk, CKBitmapSlot* slot) { bool CKBitmapData::ReadRawBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot) {
return false; return false;
} }
bool CKBitmapData::ReadOldRawBitmap(CKStateChunk* chk, CKBitmapSlot* slot) { bool CKBitmapData::ReadOldRawBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot) {
return false; return false;
} }
void CKBitmapData::WriteSpecificFormatBitmap(CKStateChunk* chk, CKBitmapSlot* slot) { void CKBitmapData::WriteSpecificFormatBitmap(CKStateChunk* chk, const VxMath::VxImageDescEx* slot) {
} }
void CKBitmapData::WriteRawBitmap(CKStateChunk* chk, CKBitmapSlot* slot) { void CKBitmapData::WriteRawBitmap(CKStateChunk* chk, const VxMath::VxImageDescEx* slot) {
} }
@ -51,7 +51,7 @@ namespace LibCmo::CK2 {
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
for (CKDWORD i = 0; i < slotcount; ++i) { for (CKDWORD i = 0; i < slotcount; ++i) {
CreateImage(width, height, i); CreateImage(width, height, i);
if (ReadSpecificFormatBitmap(chunk, GetImageSlot(i))) { if (ReadSpecificFormatBitmap(chunk, GetImageDesc(i))) {
notReadSlot[i] = true; notReadSlot[i] = true;
} else { } else {
ReleaseImage(i); ReleaseImage(i);
@ -68,7 +68,7 @@ namespace LibCmo::CK2 {
notReadSlot.resize(slotcount, false); notReadSlot.resize(slotcount, false);
for (CKDWORD i = 0; i < slotcount; ++i) { for (CKDWORD i = 0; i < slotcount; ++i) {
if (ReadRawBitmap(chunk, GetImageSlot(i))) { if (ReadRawBitmap(chunk, GetImageDesc(i))) {
notReadSlot[i] = true; notReadSlot[i] = true;
} else { } else {
ReleaseImage(i); ReleaseImage(i);
@ -84,7 +84,7 @@ namespace LibCmo::CK2 {
notReadSlot.resize(slotcount, false); notReadSlot.resize(slotcount, false);
for (CKDWORD i = 0; i < slotcount; ++i) { for (CKDWORD i = 0; i < slotcount; ++i) {
if (ReadOldRawBitmap(chunk, GetImageSlot(i))) { if (ReadOldRawBitmap(chunk, GetImageDesc(i))) {
notReadSlot[i] = true; notReadSlot[i] = true;
} else { } else {
ReleaseImage(i); ReleaseImage(i);
@ -165,7 +165,8 @@ namespace LibCmo::CK2 {
if (Slot >= m_Slots.size()) return; if (Slot >= m_Slots.size()) return;
CKBitmapSlot& slotdata = m_Slots[Slot]; CKBitmapSlot& slotdata = m_Slots[Slot];
slotdata.CreateImage(Width, Height); slotdata.m_ImageData.CreateImage(Width, Height);
VxMath::VxDoAlphaBlit(&slotdata.m_ImageData, 0xFFu);
} }
bool CKBitmapData::LoadImage(CKSTRING filename, CKDWORD slot) { bool CKBitmapData::LoadImage(CKSTRING filename, CKDWORD slot) {
@ -203,17 +204,12 @@ namespace LibCmo::CK2 {
VxMath::VxImageDescEx* CKBitmapData::GetImageDesc(CKDWORD slot) { VxMath::VxImageDescEx* CKBitmapData::GetImageDesc(CKDWORD slot) {
if (slot >= m_Slots.size()) return nullptr; if (slot >= m_Slots.size()) return nullptr;
return m_Slots[slot].m_ImageData; return &m_Slots[slot].m_ImageData;
}
CKBitmapSlot* CKBitmapData::GetImageSlot(CKDWORD slot) {
if (slot >= m_Slots.size()) return nullptr;
return &m_Slots[slot];
} }
void CKBitmapData::ReleaseImage(CKDWORD slot) { void CKBitmapData::ReleaseImage(CKDWORD slot) {
if (slot >= m_Slots.size()) return; if (slot >= m_Slots.size()) return;
m_Slots[slot].FreeImage(); m_Slots[slot].m_ImageData.FreeImage();
} }
void CKBitmapData::SetSlotFileName(CKDWORD slot, CKSTRING filename) { void CKBitmapData::SetSlotFileName(CKDWORD slot, CKSTRING filename) {

View File

@ -24,50 +24,11 @@ namespace LibCmo::CK2 {
class CKBitmapSlot { class CKBitmapSlot {
public: public:
CKBitmapSlot() : CKBitmapSlot() :
m_ImageData(nullptr), m_FileName() {} m_ImageData(), m_FileName() {}
~CKBitmapSlot() { ~CKBitmapSlot() {}
FreeImage(); LIBCMO_DEFAULT_COPY_MOVE(CKBitmapSlot);
}
CKBitmapSlot(const CKBitmapSlot& rhs) :
m_ImageData(nullptr), m_FileName(rhs.m_FileName) {
if (rhs.m_ImageData != nullptr) {
m_ImageData = new VxMath::VxImageDescEx(*rhs.m_ImageData);
}
}
CKBitmapSlot(CKBitmapSlot&& rhs) :
m_ImageData(rhs.m_ImageData), m_FileName(std::move(rhs.m_FileName)) {
rhs.m_ImageData = nullptr;
}
CKBitmapSlot& operator=(const CKBitmapSlot& rhs) {
m_FileName = rhs.m_FileName;
FreeImage(); VxMath::VxImageDescEx m_ImageData;
if (rhs.m_ImageData != nullptr) {
m_ImageData = new VxMath::VxImageDescEx(*rhs.m_ImageData);
}
return *this;
}
CKBitmapSlot& operator=(CKBitmapSlot&& rhs) {
m_FileName = std::move(rhs.m_FileName);
FreeImage();
m_ImageData = rhs.m_ImageData;
rhs.m_ImageData = nullptr;
}
void CreateImage(CKDWORD Width, CKDWORD Height) {
FreeImage();
m_ImageData = new VxMath::VxImageDescEx(Width, Height);
}
void FreeImage() {
if (m_ImageData != nullptr) {
delete m_ImageData;
m_ImageData = nullptr;
}
}
VxMath::VxImageDescEx* m_ImageData;
XContainer::XString m_FileName; XContainer::XString m_FileName;
}; };
@ -77,11 +38,11 @@ namespace LibCmo::CK2 {
~CKBitmapData(); ~CKBitmapData();
LIBCMO_DISABLE_COPY_MOVE(CKBitmapData); LIBCMO_DISABLE_COPY_MOVE(CKBitmapData);
static bool ReadSpecificFormatBitmap(CKStateChunk* chk, CKBitmapSlot* slot); static bool ReadSpecificFormatBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot);
static bool ReadRawBitmap(CKStateChunk* chk, CKBitmapSlot* slot); static bool ReadRawBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot);
static bool ReadOldRawBitmap(CKStateChunk* chk, CKBitmapSlot* slot); static bool ReadOldRawBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot);
static void WriteSpecificFormatBitmap(CKStateChunk* chk, CKBitmapSlot* slot); static void WriteSpecificFormatBitmap(CKStateChunk* chk, const VxMath::VxImageDescEx* slot);
static void WriteRawBitmap(CKStateChunk* chk, CKBitmapSlot* slot); static void WriteRawBitmap(CKStateChunk* chk, const VxMath::VxImageDescEx* slot);
bool ReadFromChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataReadIdentifiers& identifiers); bool ReadFromChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataReadIdentifiers& identifiers);
bool DumpToChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataWriteIdentifiers& identifiers); bool DumpToChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataWriteIdentifiers& identifiers);
@ -95,7 +56,6 @@ namespace LibCmo::CK2 {
bool LoadImage(CKSTRING filename, CKDWORD slot); bool LoadImage(CKSTRING filename, CKDWORD slot);
bool SaveImage(CKSTRING filename, CKDWORD slot); bool SaveImage(CKSTRING filename, CKDWORD slot);
VxMath::VxImageDescEx* GetImageDesc(CKDWORD slot); VxMath::VxImageDescEx* GetImageDesc(CKDWORD slot);
CKBitmapSlot* GetImageSlot(CKDWORD slot);
void ReleaseImage(CKDWORD slot); void ReleaseImage(CKDWORD slot);
void SetSlotFileName(CKDWORD slot, CKSTRING filename); void SetSlotFileName(CKDWORD slot, CKSTRING filename);

View File

@ -53,29 +53,6 @@ namespace LibCmo::CK2::DataHandlers {
); );
} }
static void PostRead(stbi_uc* data, int x, int y, VxMath::VxImageDescEx* read_image) {
// scale image if need
if (x != read_image->GetWidth() || y != read_image->GetHeight()) {
// alloc
CKBYTE* newdata = new CKBYTE[read_image->GetImageSize()];
// resize
stbir_resize(
data, x, y, 0,
newdata, static_cast<int>(read_image->GetWidth()), static_cast<int>(read_image->GetHeight()), 0,
STBIR_TYPE_UINT8, 4, STBIR_ALPHA_CHANNEL_NONE, 0, // no alpha channel, mean we treat alpha channel as a normal color factor.
STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,
STBIR_FILTER_BOX, STBIR_FILTER_BOX,
STBIR_COLORSPACE_SRGB, nullptr
);
// copy data
RGBAToARGB(read_image->GetPixelCount(), newdata, read_image->GetMutableImage());
// free
delete[] newdata;
} else {
// copy data RGBA -> ARGB
RGBAToARGB(read_image->GetPixelCount(), data, read_image->GetMutableImage());
}
}
static bool StbReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) { static bool StbReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) {
if (u8filename == nullptr || read_image == nullptr) return false; if (u8filename == nullptr || read_image == nullptr) return false;
FILE* fs = EncodingHelper::U8FOpen(u8filename, "rb"); FILE* fs = EncodingHelper::U8FOpen(u8filename, "rb");
@ -87,8 +64,11 @@ namespace LibCmo::CK2::DataHandlers {
std::fclose(fs); std::fclose(fs);
if (data == nullptr) return false; if (data == nullptr) return false;
// scale image if need // create read image
PostRead(data, x, y, read_image); read_image->CreateImage(static_cast<CKDWORD>(x), static_cast<CKDWORD>(y));
// copy data
RGBAToARGB(read_image->GetPixelCount(), data, read_image->GetMutableImage());
// clear data // clear data
stbi_image_free(data); stbi_image_free(data);
@ -106,9 +86,12 @@ namespace LibCmo::CK2::DataHandlers {
&x, &y, &channels_in_file, 4 // 4 == RGBA8888 &x, &y, &channels_in_file, 4 // 4 == RGBA8888
); );
if (data == nullptr) return false; if (data == nullptr) return false;
// create read image
read_image->CreateImage(static_cast<CKDWORD>(x), static_cast<CKDWORD>(y));
// scale image if need // copy data
PostRead(data, x, y, read_image); RGBAToARGB(read_image->GetPixelCount(), data, read_image->GetMutableImage());
// clear data // clear data
stbi_image_free(data); stbi_image_free(data);

View File

@ -31,17 +31,11 @@ namespace LibCmo::CK2::DataHandlers {
*/ */
static void ReleaseBitmapHandler(CKBitmapHandler* handler); static void ReleaseBitmapHandler(CKBitmapHandler* handler);
/**
* @brief Returns the current default bitmap options.
* @return Current default bitmap options
*/
virtual const CKBitmapProperties& GetBitmapDefaultProperties() = 0;
/** /**
@brief Loads a bitmap file. @brief Loads a bitmap file.
@return Returns true if successful. @return Returns true if successful.
@param u8filename[in] The file ready to read. @param u8filename[in] The file ready to read.
@param read_image[out] The pointer point to existed image desc which describe this image HW. @param read_image[out] The pointer point to a blank image desc to receive read image.
@see ReadMemory @see ReadMemory
*/ */
virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) = 0; virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) = 0;
@ -50,7 +44,7 @@ namespace LibCmo::CK2::DataHandlers {
@return Returns true if successful. @return Returns true if successful.
@param memory[in] The pointer to memory. @param memory[in] The pointer to memory.
@param size[in] The size of memory. @param size[in] The size of memory.
@param read_image[out] The pointer point to existed image desc which describe this image HW. @param read_image[out] The pointer point to a blank image desc to receive read image.
@see ReadFile @see ReadFile
*/ */
virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) = 0; virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) = 0;
@ -97,7 +91,8 @@ namespace LibCmo::CK2::DataHandlers {
virtual ~CKBitmapBMPHandler(); virtual ~CKBitmapBMPHandler();
LIBCMO_DISABLE_COPY_MOVE(CKBitmapBMPHandler); LIBCMO_DISABLE_COPY_MOVE(CKBitmapBMPHandler);
virtual const CKBitmapProperties& GetBitmapDefaultProperties() override; static const CKBitmapProperties& GetBitmapDefaultProperties();
virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) override; virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) override;
virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) override; virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) override;
virtual bool SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) override; virtual bool SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) override;
@ -111,7 +106,8 @@ namespace LibCmo::CK2::DataHandlers {
virtual ~CKBitmapTGAHandler(); virtual ~CKBitmapTGAHandler();
LIBCMO_DISABLE_COPY_MOVE(CKBitmapTGAHandler); LIBCMO_DISABLE_COPY_MOVE(CKBitmapTGAHandler);
virtual const CKBitmapProperties& GetBitmapDefaultProperties() override; static const CKBitmapProperties& GetBitmapDefaultProperties();
virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) override; virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) override;
virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) override; virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) override;
virtual bool SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) override; virtual bool SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) override;

View File

@ -1,4 +1,6 @@
#include "VxMath.hpp" #include "VxMath.hpp"
#include "stb_image.h"
#include "stb_image_resize.h"
namespace LibCmo::VxMath { namespace LibCmo::VxMath {
@ -24,26 +26,68 @@ namespace LibCmo::VxMath {
#pragma region Graphic Utilities #pragma region Graphic Utilities
//CK2::CKDWORD VxGetBitCount(CK2::CKDWORD dwMask) { void VxDoBlit(const VxImageDescEx* origin, VxImageDescEx* dst) {
// if (dwMask == 0u) return 0; if (dst == nullptr || origin == nullptr) return;
// dwMask >>= VxGetBitShift(dwMask); if (!dst->IsValid() || !origin->IsValid()) return;
// CK2::CKDWORD count = 0;
// while ((dwMask & 1u) == 0u) {
// dwMask >>= 1u;
// ++count;
// }
// return count;
//}
//CK2::CKDWORD VxGetBitShift(CK2::CKDWORD dwMask) { // if have same size, directly copy it
// if (dwMask == 0u) return 0; if (dst->IsHWEqual(*origin)) {
// CK2::CKDWORD count = 0; std::memcpy(dst->GetMutableImage(), origin->GetImage(), dst->GetImageSize());
// while ((dwMask & 1u) != 0u) { return;
// dwMask >>= 1u; }
// ++count;
// } // perform resize by stb
// return count; stbir_resize(
//} origin->GetImage(), static_cast<int>(origin->GetWidth()), static_cast<int>(origin->GetHeight()), 0,
dst->GetMutableImage(), static_cast<int>(dst->GetWidth()), static_cast<int>(dst->GetHeight()), 0,
STBIR_TYPE_UINT8, 4, STBIR_ALPHA_CHANNEL_NONE, 0, // no alpha channel, mean we treat alpha channel as a normal color factor.
STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,
STBIR_FILTER_BOX, STBIR_FILTER_BOX,
STBIR_COLORSPACE_SRGB, nullptr
);
}
void VxDoBlitUpsideDown(const VxImageDescEx* origin, VxImageDescEx* dst) {
if (dst == nullptr || origin == nullptr) return;
if (!dst->IsValid() || !origin->IsValid()) return;
// if size is not matched, return
if (!dst->IsHWEqual(*origin)) {
return;
}
// copy and swap data by line
CK2::CKDWORD height = dst->GetHeight(),
rowsize = sizeof(uint32_t) * dst->GetWidth();
for (CK2::CKDWORD row = 0; row < height; ++row) {
std::memcpy(
dst->GetMutableImage() + (row * rowsize),
dst->GetImage() + ((height - row - 1) * rowsize),
rowsize
);
}
}
CK2::CKDWORD VxGetBitCount(CK2::CKDWORD dwMask) {
if (dwMask == 0u) return 0;
dwMask >>= VxGetBitShift(dwMask);
CK2::CKDWORD count = 0;
while ((dwMask & 1u) == 0u) {
dwMask >>= 1u;
++count;
}
return count;
}
CK2::CKDWORD VxGetBitShift(CK2::CKDWORD dwMask) {
if (dwMask == 0u) return 0;
CK2::CKDWORD count = 0;
while ((dwMask & 1u) != 0u) {
dwMask >>= 1u;
++count;
}
return count;
}
//CK2::CKDWORD VxScaleFactor(CK2::CKDWORD val, CK2::CKDWORD srcBitCount, CK2::CKDWORD dstBitCount) { //CK2::CKDWORD VxScaleFactor(CK2::CKDWORD val, CK2::CKDWORD srcBitCount, CK2::CKDWORD dstBitCount) {
// if (srcBitCount == dstBitCount) return val; // if (srcBitCount == dstBitCount) return val;

View File

@ -29,23 +29,33 @@ namespace LibCmo::VxMath {
void VxCopyStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD OutStride, CK2::CKDWORD SizeSrc, const void* Src, CK2::CKDWORD InStride); void VxCopyStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD OutStride, CK2::CKDWORD SizeSrc, const void* Src, CK2::CKDWORD InStride);
// ========== Graphic Utilities ========== // ========== Graphic Utilities ==========
//
///** /**
// * @brief Copy origin image to dest image. * @brief Performs a blit between two images. This method can resize (shrink or grow) images.
// * Supporting for size scaling. If the size is matched, just a direct copy. * @remark The source image must be in a 32 bit ARGB8888 per pixel format.
// * @param dest[out] The dest image. * @param dest[out] The dest image.
// * @param origin[in] The origin image. * @param origin[in] The origin image.
//*/ */
//void VxDoBlit(VxImageDescEx* dst, const VxImageDescEx* origin); void VxDoBlit(const VxImageDescEx* origin, VxImageDescEx* dst);
/**
* @brief Performs a blit between two images. This method can inverts the destination image.
* @remark
+ The source image must be in a 32 bit ARGB8888 per pixel format.
+ This function usually used in the covertion between texture coordinate
system and UV coordinate system.
* @param dest[out] The dest image.
* @param origin[in] The origin image.
*/
void VxDoBlitUpsideDown(const VxImageDescEx* origin, VxImageDescEx* dst);
///** /**
// * @brief Counts number of bits to representing a value in dwMask * @brief Counts number of bits to representing a value in dwMask
//*/ */
//CK2::CKDWORD VxGetBitCount(CK2::CKDWORD dwMask); CK2::CKDWORD VxGetBitCount(CK2::CKDWORD dwMask);
///** /**
// * @brief Counts number of bits to shift to acces a non zero value in dwMask. * @brief Counts number of bits to shift to acces a non zero value in dwMask.
//*/ */
//CK2::CKDWORD VxGetBitShift(CK2::CKDWORD dwMask); CK2::CKDWORD VxGetBitShift(CK2::CKDWORD dwMask);
///** ///**
// * @brief scale the integer to a new range. // * @brief scale the integer to a new range.
@ -59,6 +69,7 @@ namespace LibCmo::VxMath {
/** /**
* @brief Sets the alpha component of an image. * @brief Sets the alpha component of an image.
* @remark The source image must be in a 32 bit ARGB8888 per pixel format.
* @param dst_desc[in] A pointer to a structure describing the destination image format. * @param dst_desc[in] A pointer to a structure describing the destination image format.
* @param AlphaValue[in] A CKBYTE value containing the alpha value to set to the whole image * @param AlphaValue[in] A CKBYTE value containing the alpha value to set to the whole image
* @remark If the destination image does not have alpha information the function returns immediatly. * @remark If the destination image does not have alpha information the function returns immediatly.
@ -66,6 +77,7 @@ namespace LibCmo::VxMath {
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE AlphaValue); void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE AlphaValue);
/** /**
* @brief Sets the alpha component of an image. * @brief Sets the alpha component of an image.
* @remark The source image must be in a 32 bit ARGB8888 per pixel format.
* @param dst_desc[in] A pointer to a structure describing the destination image format. * @param dst_desc[in] A pointer to a structure describing the destination image format.
* @param AlphaValues[in] A BYTE array containing the alpha values for each pixel. This array should be allocated to Width*Height bytes. * @param AlphaValues[in] A BYTE array containing the alpha values for each pixel. This array should be allocated to Width*Height bytes.
* @remark If the destination image does not have alpha information the function returns immediatly. * @remark If the destination image does not have alpha information the function returns immediatly.

View File

@ -73,28 +73,76 @@ namespace LibCmo::VxMath {
* VxImageDescEx describe the height, width, * VxImageDescEx describe the height, width,
* and etc for image. * and etc for image.
* Also it hold a pointer to raw image data. * Also it hold a pointer to raw image data.
* The image data must be 32bit format. * The image data must be 32bit ARGB8888 format.
* Thus the size of Image must be 4 * Width * Height. * Thus the size of Image must be 4 * Width * Height.
*/ */
class VxImageDescEx { class VxImageDescEx {
public: public:
VxImageDescEx() :
m_Width(0), m_Height(0), m_Image(nullptr) {}
VxImageDescEx(CK2::CKDWORD width, CK2::CKDWORD height) : VxImageDescEx(CK2::CKDWORD width, CK2::CKDWORD height) :
m_Width(width), m_Height(height), m_Width(width), m_Height(height), m_Image(nullptr) {
//m_RedMask(0), m_GreenMask(0), m_BlueMask(0), m_AlphaMask(0), CreateImage(width, height);
m_Image(nullptr) {
m_Image = new CK2::CKBYTE[GetImageSize()];
} }
VxImageDescEx(const VxImageDescEx& rhs) : VxImageDescEx(const VxImageDescEx& rhs) :
m_Width(rhs.m_Width), m_Height(rhs.m_Height), m_Width(rhs.m_Width), m_Height(rhs.m_Height), m_Image(nullptr) {
m_Image(nullptr) {
// copy image // copy image
m_Image = new CK2::CKBYTE[GetImageSize()]; if (rhs.m_Image != nullptr) {
std::memcpy(m_Image, rhs.m_Image, GetImageSize()); CreateImage(rhs.m_Width, rhs.m_Height, rhs.m_Image);
}
}
VxImageDescEx(VxImageDescEx&& rhs) :
m_Width(rhs.m_Width), m_Height(rhs.m_Height), m_Image(rhs.m_Image) {
// move image
rhs.m_Height = 0;
rhs.m_Width = 0;
rhs.m_Image = nullptr;
}
VxImageDescEx& operator=(const VxImageDescEx& rhs) {
FreeImage();
m_Width = rhs.m_Width;
m_Height = rhs.m_Height;
if (rhs.m_Image != nullptr) {
CreateImage(rhs.m_Width, rhs.m_Height, rhs.m_Image);
}
return *this;
}
VxImageDescEx& operator=(VxImageDescEx&& rhs) {
FreeImage();
m_Height = rhs.m_Height;
m_Width = rhs.m_Width;
m_Image = rhs.m_Image;
rhs.m_Height = 0;
rhs.m_Width = 0;
rhs.m_Image = nullptr;
return *this;
} }
~VxImageDescEx() { ~VxImageDescEx() {
delete[] m_Image; FreeImage();
}
void CreateImage(CK2::CKDWORD Width, CK2::CKDWORD Height) {
FreeImage();
m_Width = Width;
m_Height = Height;
m_Image = new CK2::CKBYTE[GetImageSize()];
}
void CreateImage(CK2::CKDWORD Width, CK2::CKDWORD Height, void* dataptr) {
CreateImage(Width, Height);
std::memcpy(m_Image, dataptr, GetImageSize());
}
void FreeImage() {
m_Width = 0;
m_Height = 0;
if (m_Image != nullptr) {
delete[] m_Image;
m_Image = nullptr;
}
} }
LIBCMO_DISABLE_COPY_MOVE(VxImageDescEx);
CK2::CKDWORD GetImageSize() const { CK2::CKDWORD GetImageSize() const {
return static_cast<CK2::CKDWORD>(sizeof(uint32_t) * m_Width * m_Height); return static_cast<CK2::CKDWORD>(sizeof(uint32_t) * m_Width * m_Height);
@ -123,10 +171,17 @@ namespace LibCmo::VxMath {
return m_Height; return m_Height;
} }
bool IsValid() const {
return (
m_Width != 0u &&
m_Height != 0u &&
m_Image != nullptr
);
}
bool IsHWEqual(const VxImageDescEx& rhs) const { bool IsHWEqual(const VxImageDescEx& rhs) const {
return (m_Width == rhs.m_Width && m_Height == rhs.m_Height); return (m_Width == rhs.m_Width && m_Height == rhs.m_Height);
} }
// bool IsMaskEqual(const VxImageDescEx& rhs) const { // bool IsMaskEqual(const VxImageDescEx& rhs) const {
// return ( // return (
// m_RedMask == rhs.m_RedMask && // m_RedMask == rhs.m_RedMask &&
// m_GreenMask == rhs.m_GreenMask && // m_GreenMask == rhs.m_GreenMask &&