-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalette.h
More file actions
75 lines (65 loc) · 2.17 KB
/
Copy pathPalette.h
File metadata and controls
75 lines (65 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Copyright (c) 2024-2025 Toksisitee. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, refer to license.md or https://opensource.org/licenses/MIT
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*/
#pragma once
#include <string>
#include "AssetTypes.h"
#include "Editor.h"
class CTexture2D;
typedef struct IDirect3DDevice9* LPDIRECT3DDEVICE9, * PDIRECT3DDEVICE9;
extern inline void SafeDestroyTexture( CTexture2D*& pTexture );
namespace Assets
{
namespace Palette
{
constexpr size_t k_uNumColors = 256;
constexpr size_t k_uColorsPerRow = 16;
constexpr size_t k_uCellScale = 8;
constexpr size_t k_uWidth = k_uCellScale * k_uColorsPerRow;
constexpr size_t k_uHeight = k_uCellScale * (k_uNumColors / k_uColorsPerRow);
constexpr uint8_t k_uNumColorKeys = 2;
constexpr size_t k_uSize = k_uNumColors * 4;
}
class CPalette
{
public:
Result LoadBin( const std::string& sFilePath );
Result ExportBin( const std::string& sFilePath );
Result ExportImg( const std::string& sFilePath );
bool CreateTexture( LPDIRECT3DDEVICE9 pD3DDevice );
[[nodiscard]] uint8_t* GetPtr();
inline void DestroyTexture()
{
SafeDestroyTexture( m_pTexture );
}
[[nodiscard]] inline CTexture2D* GetTexture()
{
return m_pTexture;
}
[[nodiscard]] inline bool HasChanged()
{
return m_bModified;
}
inline void SetChanged( bool bState )
{
m_bModified = bState;
DestroyTexture();
}
[[nodiscard]] Color* GetColor( uint8_t uIndex ) { return &m_ColorTable[uIndex]; }
[[nodiscard]] Color* GetColorTable();
[[nodiscard]] uint8_t FindColor( const Color& clr, size_t uMin = 0, size_t uMax = Palette::k_uNumColors );
[[nodiscard]] uint8_t FindExactColor( const Color& clr, bool bFallback = false );
[[nodiscard]] uint8_t GetColorKey( size_t uSlot = 0 );
[[nodiscard]] bool IndexIsColorKey( size_t uIndex );
private:
uint8_t m_uColorKeys[Palette::k_uNumColorKeys] = { 255, 255 };;
Color m_ColorTable[Palette::k_uNumColors];
CTexture2D* m_pTexture;
bool m_bModified = false;
};
};