libcmo21/LibCmo/CK2/CKBitmapData.hpp

204 lines
6.8 KiB
C++
Raw Normal View History

#pragma once
#include "../VTInternal.hpp"
namespace LibCmo::CK2 {
2023-09-10 13:23:04 +08:00
struct CKBitmapDataReadIdentifiers {
CKDWORD m_SpecificFormat; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXREADER(0x100000) in default. */
CKDWORD m_RawData; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXCOMPRESSED(0x20000) in default. */
CKDWORD m_OldRawData; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXBITMAPS(0x4000) in default. */
CKDWORD m_FileNames; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXFILENAMES(0x10000) in default. */
CKDWORD m_MovieFileName; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXAVIFILENAME(0x1000) in default. */
};
struct CKBitmapDataWriteIdentifiers {
CKDWORD m_SpecificFormat; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXREADER(0x100000) in default. */
CKDWORD m_RawData; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXCOMPRESSED(0x20000) in default. */
CKDWORD m_FileNames; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXFILENAMES(0x10000) in default. */
CKDWORD m_MovieFileName; /**< CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXAVIFILENAME(0x1000) in default. */
};
class CKBitmapSlot {
public:
CKBitmapSlot() :
2023-09-11 14:39:07 +08:00
m_ImageData(), m_FileName() {}
~CKBitmapSlot() {}
YYCC_DEF_CLS_COPY_MOVE(CKBitmapSlot);
2023-09-10 21:33:43 +08:00
2023-09-11 14:39:07 +08:00
VxMath::VxImageDescEx m_ImageData;
2023-09-10 13:23:04 +08:00
XContainer::XString m_FileName;
};
class CKBitmapData {
public:
2023-09-10 13:23:04 +08:00
CKBitmapData(CKContext* ctx);
~CKBitmapData();
YYCC_DEL_CLS_COPY_MOVE(CKBitmapData);
2023-09-10 13:23:04 +08:00
#pragma region RW Funcs
2023-09-11 14:39:07 +08:00
static bool ReadSpecificFormatBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot);
static bool ReadRawBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot);
static bool ReadOldRawBitmap(CKStateChunk* chk, VxMath::VxImageDescEx* slot);
2023-09-28 23:29:52 +08:00
static void WriteSpecificFormatBitmap(CKStateChunk* chk, const VxMath::VxImageDescEx* slot, const CKBitmapProperties* savefmt);
2023-09-11 14:39:07 +08:00
static void WriteRawBitmap(CKStateChunk* chk, const VxMath::VxImageDescEx* slot);
2023-09-10 13:23:04 +08:00
bool ReadFromChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataReadIdentifiers& identifiers);
bool DumpToChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataWriteIdentifiers& identifiers);
#pragma endregion
#pragma region Slot funcs
2023-09-10 13:23:04 +08:00
void SetSlotCount(CKDWORD count);
CKDWORD GetSlotCount() const;
2023-09-10 13:23:04 +08:00
void SetCurrentSlot(CKDWORD slot);
CKDWORD GetCurrentSlot() const;
2023-09-10 13:23:04 +08:00
/**
* @brief Create a black image with full alpha in specified slot.
2024-08-23 11:28:49 +08:00
* @param[in] Width Image width
* @param[in] Height Image height
* @param[in] Slot The slot placing image.
* @return True if creating success.
*/
bool CreateImage(CKDWORD Width, CKDWORD Height, CKDWORD Slot);
/**
* @brief Load image into specified slot.
2024-08-23 11:28:49 +08:00
* @param[in] filename The file name of loading image.
* @param[in] slot The slot placing loaded image.
* @return True if load successfully.
*/
2023-09-10 13:23:04 +08:00
bool LoadImage(CKSTRING filename, CKDWORD slot);
/**
* @brief Save image for specified slot.
2024-08-23 11:28:49 +08:00
* @param[in] filename The file name of saving image.
* @param[in] slot The slot will be saved.
* @param[in] isForceThisFmt True to use this class specified format to save image. Otherwise use the format evaluated by the image file name.
* @return True if success.
*/
2023-09-11 22:20:45 +08:00
bool SaveImage(CKSTRING filename, CKDWORD slot, bool isForceThisFmt = false);
/**
* @brief Get specified slot image descriptor.
2024-08-23 11:28:49 +08:00
* @param[in] slot The slot to get.
* @return The descriptor. nullptr if failed.
*/
2023-09-10 13:23:04 +08:00
VxMath::VxImageDescEx* GetImageDesc(CKDWORD slot);
/**
* @brief Release specified slot image.
2024-08-23 11:28:49 +08:00
* @param[in] slot The slot to free.
*/
2023-09-10 13:23:04 +08:00
void ReleaseImage(CKDWORD slot);
/**
* @brief Set associated file name for specified slot.
2024-08-23 11:28:49 +08:00
* @param[in] slot The slot to set.
* @param[in] filename The associated file name.
*/
bool SetSlotFileName(CKDWORD slot, CKSTRING filename);
/**
* @brief Get associated file name for specified slot.
2024-08-23 11:28:49 +08:00
* @param[in] slot The slot to get.
* @return The file name. nullptr if failed.
*/
CKSTRING GetSlotFileName(CKDWORD slot) const;
/**
* @brief Get first valid image's width.
* @return 0 if no valid image.
*/
CKDWORD GetWidth() const;
/**
* @brief Get first valid image's height.
* @return 0 if no valid image
*/
CKDWORD GetHeight() const;
#pragma endregion
#pragma region Not important funcs
2023-09-10 13:23:04 +08:00
2023-09-22 22:31:51 +08:00
CK_BITMAPDATA_FLAGS GetBitmapFlags() const;
void SetCubeMap(bool is_cube);
bool IsCubeMap() const;
const CKBitmapProperties& GetSaveFormat() const;
2023-09-10 21:33:43 +08:00
void SetSaveFormat(const CKBitmapProperties& props);
CK_TEXTURE_SAVEOPTIONS GetSaveOptions() const;
2023-09-10 13:23:04 +08:00
void SetSaveOptions(CK_TEXTURE_SAVEOPTIONS opts);
/**
@brief Enables or disables the color key transparency.
2024-08-23 11:28:49 +08:00
@param[in] Transparency TRUE activates transparency, FALSE disables it.
@remark
2023-09-10 13:23:04 +08:00
+ 0x00000000 (black) is the default transparent color.
+ Setting on the transparency and a transparent color automatically
updates the alpha channel so that pixel with the transparent color have
a 0 alpha value.
@see IsTransparent, SetTranparentColor
2023-09-10 13:23:04 +08:00
*/
void SetTransparent(bool Transparency);
/**
@brief Returns whether color keyed transparency is enabled.
@return TRUE if color keying is enabled.
@see SetTransparent
2023-09-10 13:23:04 +08:00
*/
bool IsTransparent() const;
2023-09-10 13:23:04 +08:00
/**
@brief Sets the transparent color.
2024-08-23 11:28:49 +08:00
@param[in] Color A 32 bit ARGB transparent color.
@remark
2023-09-10 13:23:04 +08:00
+ 0x00000000 (black) is the default transparent color.
+ Setting on the transparency and a transparent color automatically
updates the alpha channel so that pixel with the transparent color have
a 0 alpha value.
@see GetTranparentColor, SetTransparent
2023-09-10 13:23:04 +08:00
*/
void SetTransparentColor(CKDWORD col);
2023-09-10 21:33:43 +08:00
/**
@brief Returns the transparent color.
@return A 32 bit ARGB transparent color.
@remark
2023-09-10 21:33:43 +08:00
+ 0x00000000 (black) is the default transparent color.
@see SetTranparentColor, SetTransparent
2023-09-10 21:33:43 +08:00
*/
CKDWORD GetTransparentColor() const;
2023-09-12 17:03:06 +08:00
/**
@brief Sets pick threshold value.
2024-08-23 11:28:49 +08:00
@param[in] pt Pick threshold value to be set.
@remark
2023-09-12 17:03:06 +08:00
+ The pick threshold is used when picking object with
transparent textures.
+ It is the minimum value for alpha component
below which picking is not valid.So this value is supposed to be in the range 0..255
and the default value 0 means the picking is always valid.
+ But if a value >0 is used and the texture use transparency (some pixels of the bitmap will have
alpha component of 0) an object will not be picked on its transparent part.
@see CKRenderContext::Pick
2023-09-12 17:03:06 +08:00
*/
void SetPickThreshold(CKDWORD threshold);
/**
@brief Gets pick threshold value.
@return Pick threshold value
2023-09-12 17:03:06 +08:00
*/
CKDWORD GetPickThreshold() const;
#pragma endregion
protected:
2023-09-10 13:23:04 +08:00
CKContext* m_Context;
XContainer::XArray<CKBitmapSlot> m_Slots;
CKDWORD m_CurrentSlot;
2023-09-12 17:03:06 +08:00
CKDWORD m_PickThreshold;
2023-09-10 21:33:43 +08:00
CK_BITMAPDATA_FLAGS m_BitmapFlags;
2023-09-10 13:23:04 +08:00
CKDWORD m_TransColor;
2023-09-10 13:23:04 +08:00
CKBitmapProperties m_SaveProperties;
CK_TEXTURE_SAVEOPTIONS m_SaveOptions;
};
}