refactor VxImageDescEx
This commit is contained in:
@ -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) {
|
||||
if (u8filename == nullptr || read_image == nullptr) return false;
|
||||
FILE* fs = EncodingHelper::U8FOpen(u8filename, "rb");
|
||||
@ -87,8 +64,11 @@ namespace LibCmo::CK2::DataHandlers {
|
||||
std::fclose(fs);
|
||||
if (data == nullptr) return false;
|
||||
|
||||
// scale image if need
|
||||
PostRead(data, x, y, read_image);
|
||||
// create 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
|
||||
stbi_image_free(data);
|
||||
@ -106,9 +86,12 @@ namespace LibCmo::CK2::DataHandlers {
|
||||
&x, &y, &channels_in_file, 4 // 4 == RGBA8888
|
||||
);
|
||||
if (data == nullptr) return false;
|
||||
|
||||
// create read image
|
||||
read_image->CreateImage(static_cast<CKDWORD>(x), static_cast<CKDWORD>(y));
|
||||
|
||||
// scale image if need
|
||||
PostRead(data, x, y, read_image);
|
||||
// copy data
|
||||
RGBAToARGB(read_image->GetPixelCount(), data, read_image->GetMutableImage());
|
||||
|
||||
// clear data
|
||||
stbi_image_free(data);
|
||||
|
@ -31,17 +31,11 @@ namespace LibCmo::CK2::DataHandlers {
|
||||
*/
|
||||
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.
|
||||
@return Returns true if successful.
|
||||
@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
|
||||
*/
|
||||
virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) = 0;
|
||||
@ -50,7 +44,7 @@ namespace LibCmo::CK2::DataHandlers {
|
||||
@return Returns true if successful.
|
||||
@param memory[in] The pointer to 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
|
||||
*/
|
||||
virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) = 0;
|
||||
@ -97,7 +91,8 @@ namespace LibCmo::CK2::DataHandlers {
|
||||
virtual ~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 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;
|
||||
@ -111,7 +106,8 @@ namespace LibCmo::CK2::DataHandlers {
|
||||
virtual ~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 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;
|
||||
|
Reference in New Issue
Block a user