diff --git a/LibCmo/CK2/CKBitmapData.cpp b/LibCmo/CK2/CKBitmapData.cpp new file mode 100644 index 0000000..b3ad2cc --- /dev/null +++ b/LibCmo/CK2/CKBitmapData.cpp @@ -0,0 +1,9 @@ +#include "CKBitmapData.hpp" + +namespace LibCmo::CK2 { + + CKBitmapData::CKBitmapData() {} + + CKBitmapData::~CKBitmapData() {} + +} diff --git a/LibCmo/CK2/CKBitmapData.hpp b/LibCmo/CK2/CKBitmapData.hpp new file mode 100644 index 0000000..69d4eeb --- /dev/null +++ b/LibCmo/CK2/CKBitmapData.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "../VTAll.hpp" + +namespace LibCmo::CK2 { + + class CKBitmapData { + public: + CKBitmapData(); + ~CKBitmapData(); + + protected: + + }; + +} diff --git a/LibCmo/CK2/CKStructs.hpp b/LibCmo/CK2/CKStructs.hpp new file mode 100644 index 0000000..55da193 --- /dev/null +++ b/LibCmo/CK2/CKStructs.hpp @@ -0,0 +1,79 @@ +#pragma once + +#include "CKGlobals.hpp" + +namespace LibCmo::CK2 { + + // a stupid forward decl to remove something + /** + * @brief Storage class for filename extensions + */ + class CKFileExtension { + public: + CKFileExtension() : m_Data() { + std::memset(m_Data, 0, c_DataLen); + } + CKFileExtension(CKSTRING s) : CKFileExtension() { + SetExt(s); + } + CKFileExtension(const CKFileExtension& rhs) : CKFileExtension() { + std::memcpy(m_Data, rhs.m_Data, c_DataLen); + } + CKFileExtension(CKFileExtension&& rhs) : CKFileExtension() { + std::memmove(m_Data, rhs.m_Data, c_DataLen); + std::memset(rhs.m_Data, 0, c_DataLen); + } + CKFileExtension& operator=(const CKFileExtension& rhs) { + std::memcpy(m_Data, rhs.m_Data, c_DataLen); + return *this; + } + CKFileExtension& operator=(CKFileExtension&& rhs) { + std::memmove(m_Data, rhs.m_Data, c_DataLen); + std::memset(rhs.m_Data, 0, c_DataLen); + return *this; + } + + void SetExt(CKSTRING s) { + if (s == nullptr) { + m_Data[0] = '\0'; + } else { + if (s[0] == '.') ++s; // skip dot + size_t len = std::strlen(s); + if (len > (c_DataLen - 1)) len = c_DataLen - 1; + std::memcpy(m_Data, s, len); + } + } + + CKSTRING GetExt() const { + return m_Data; + } + + bool operator==(const CKFileExtension& rhs) const { + return CKStrEqualI(m_Data, rhs.m_Data); + } + + protected: + static const size_t c_DataLen = 4u; + CKCHAR m_Data[c_DataLen]; + }; + + /** + * The struct describe the bitmap handler's infomation, + * including its GUID and supported file extension. + * This struct also will store some parameters related to bitmap handler, + * such as jpeg compress level and etc. But currently there are no + * such parameters. + */ + class CKBitmapProperties { + public: + CKBitmapProperties() : + m_ReaderGuid(), m_Ext() {} + CKBitmapProperties(const CKGUID& guid, CKSTRING ext) : + m_ReaderGuid(guid), m_Ext(ext) {} + LIBCMO_DEFAULT_COPY_MOVE(CKBitmapProperties); + + CKGUID m_ReaderGuid; /**< CKGUID that uniquely identifies the reader that created this properties structure */ + CKFileExtension m_Ext; /**< File Extension of the image being described by this structure */ + }; + +} diff --git a/LibCmo/CK2/CKTypes.hpp b/LibCmo/CK2/CKTypes.hpp index 2c1fa86..688880b 100644 --- a/LibCmo/CK2/CKTypes.hpp +++ b/LibCmo/CK2/CKTypes.hpp @@ -266,7 +266,8 @@ namespace LibCmo::CK2 { class CKObjectArray; class CKObjectDeclaration; //class CKContext; - //struct CKBitmapProperties; + class CKBitmapProperties; + class CKFileExtension; class CKVertexBuffer; //--- Managers @@ -366,74 +367,4 @@ namespace LibCmo::CK2 { } }; - /** - * @brief Storage class for filename extensions - */ - class CKFileExtension { - public: - CKFileExtension() : m_Data() { - std::memset(m_Data, 0, c_DataLen); - } - CKFileExtension(CKSTRING s) : CKFileExtension() { - SetExt(s); - } - CKFileExtension(const CKFileExtension& rhs) : CKFileExtension() { - std::memcpy(m_Data, rhs.m_Data, c_DataLen); - } - CKFileExtension(CKFileExtension&& rhs) : CKFileExtension() { - std::memmove(m_Data, rhs.m_Data, c_DataLen); - std::memset(rhs.m_Data, 0, c_DataLen); - } - CKFileExtension& operator=(const CKFileExtension& rhs) { - std::memcpy(m_Data, rhs.m_Data, c_DataLen); - } - CKFileExtension& operator=(CKFileExtension&& rhs) { - std::memmove(m_Data, rhs.m_Data, c_DataLen); - std::memset(rhs.m_Data, 0, c_DataLen); - } - - void SetExt(CKSTRING s) { - if (s == nullptr) { - m_Data[0] = '\0'; - } else { - if (s[0] == '.') ++s; // skip dot - size_t len = std::strlen(s); - if (len > (c_DataLen - 1)) len = c_DataLen - 1; - std::memcpy(m_Data, s, len); - } - } - - CKSTRING GetExt() const { - return m_Data; - } - - bool operator==(const CKFileExtension& rhs) const { - return CKStrEqualI(m_Data, rhs.m_Data); - } - - protected: - static const size_t c_DataLen = 4u; - CKCHAR m_Data[c_DataLen]; - }; - - /** - * The struct describe the bitmap handler's infomation, - * including its GUID and supported file extension. - * This struct also will store some parameters related to bitmap handler, - * such as jpeg compress level and etc. But currently there are no - * such parameters. - */ - class CKBitmapProperties { - public: - CKBitmapProperties() : - m_ReaderGuid(), m_Ext() {} - CKBitmapProperties(const CKGUID& guid, CKSTRING ext) : - m_ReaderGuid(guid), m_Ext(ext) {} - LIBCMO_DEFAULT_COPY_MOVE(CKBitmapProperties); - - CKGUID m_ReaderGuid; /**< CKGUID that uniquely identifies the reader that created this properties structure */ - CKFileExtension m_Ext; /**< File Extension of the image being described by this structure */ - }; - - } diff --git a/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp b/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp index 49db592..5e5fcd6 100644 --- a/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp +++ b/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp @@ -178,7 +178,7 @@ namespace LibCmo::CK2::DataHandlers { // write data MemorySaveContext* ctx = new MemorySaveContext(memory); int ret = oper( - &FileWriteFunction, ctx, + &MemoryWriteFunction, ctx, static_cast(write_image->GetWidth()), static_cast(write_image->GetHeight()), 4, data // 4 == RGBA8888 ); @@ -208,11 +208,11 @@ namespace LibCmo::CK2::DataHandlers { } bool CKBitmapBMPHandler::ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) { - StbReadFile(u8filename, read_image); + return StbReadFile(u8filename, read_image); } bool CKBitmapBMPHandler::ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) { - StbReadMemory(memory, size, read_image); + return StbReadMemory(memory, size, read_image); } bool CKBitmapBMPHandler::SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) { @@ -245,11 +245,11 @@ namespace LibCmo::CK2::DataHandlers { } bool CKBitmapTGAHandler::ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) { - StbReadFile(u8filename, read_image); + return StbReadFile(u8filename, read_image); } bool CKBitmapTGAHandler::ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) { - StbReadMemory(memory, size, read_image); + return StbReadMemory(memory, size, read_image); } bool CKBitmapTGAHandler::SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) { diff --git a/LibCmo/CK2/MgrImpls/CKPathManager.cpp b/LibCmo/CK2/MgrImpls/CKPathManager.cpp index 6904e34..28b187e 100644 --- a/LibCmo/CK2/MgrImpls/CKPathManager.cpp +++ b/LibCmo/CK2/MgrImpls/CKPathManager.cpp @@ -49,7 +49,7 @@ namespace LibCmo::CK2::MgrImpls { } bool CKPathManager::AddPath(CKSTRING u8path) { - if (u8path == nullptr) return; + if (u8path == nullptr) return false; std::filesystem::path newpath; EncodingHelper::U8PathToStdPath(newpath, u8path); if (std::filesystem::is_directory(newpath)) { @@ -86,7 +86,7 @@ namespace LibCmo::CK2::MgrImpls { // test in temp folder auto tempfile = m_TempFolder / filepath; if (std::filesystem::is_regular_file(tempfile)) { - EncodingHelper::StdPathToU8Path(u8_filename, combinedpath); + EncodingHelper::StdPathToU8Path(u8_filename, tempfile); return true; } diff --git a/LibCmo/LibCmo.vcxproj b/LibCmo/LibCmo.vcxproj index af85d3c..fbc7aac 100644 --- a/LibCmo/LibCmo.vcxproj +++ b/LibCmo/LibCmo.vcxproj @@ -175,6 +175,7 @@ + @@ -199,11 +200,13 @@ + + diff --git a/LibCmo/LibCmo.vcxproj.filters b/LibCmo/LibCmo.vcxproj.filters index f5415e4..7b4d72c 100644 --- a/LibCmo/LibCmo.vcxproj.filters +++ b/LibCmo/LibCmo.vcxproj.filters @@ -117,6 +117,9 @@ Sources\VxMath + + Sources\CK2 + @@ -203,5 +206,11 @@ Headers\CK2\DataHandlers + + Headers\CK2 + + + Headers\CK2 + \ No newline at end of file diff --git a/LibCmo/VTAll.hpp b/LibCmo/VTAll.hpp index d7ff244..77083a1 100644 --- a/LibCmo/VTAll.hpp +++ b/LibCmo/VTAll.hpp @@ -21,6 +21,7 @@ Except the file listed in there, they should include "VTUtils.hpp" first. #include "CK2/CKEnums.hpp" // All CK used enums except CKStateChunk identifiers. #include "CK2/CKIdentifiers.hpp" // CKStateChunk identifiers. #include "CK2/CKGlobals.hpp" // CK global functions, such as CKUnPack and etc. +#include "CK2/CKStructs.hpp" // Some essential and useful classes + structs. #include "VxMath/VxEnums.hpp" #include "VxMath/VxTypes.hpp"