World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Image.h
См. документацию.
1 #pragma once
2 #include "Engine/Strings.h"
3 
10 
13 };
14 
17 
18 class ImageLoader;
19 class Image {
20  public:
21  explicit Image(bool lazy_initialization = true)
23  initialized(false),
24  loader(nullptr),
25  width(0),
26  height(0),
28  for (unsigned int i = 0; i < IMAGE_NUM_FORMATS; ++i)
29  pixels[i] = nullptr;
30  }
31  virtual ~Image() {}
32 
33  static Image *Create(unsigned int width, unsigned int height,
34  IMAGE_FORMAT format, const void *pixels = nullptr);
35  static Image *Create(ImageLoader *loader);
36 
37  unsigned int GetWidth();
38  unsigned int GetHeight();
39  const void *GetPixels(IMAGE_FORMAT format);
40  IMAGE_FORMAT GetFormat() const { return native_format; }
41 
42  bool Release();
43 
44  protected:
46  bool initialized = 0;
48 
49  unsigned int width = 0;
50  unsigned int height = 0;
53 
54  virtual bool LoadImageData();
55 };
56 
57 class ImageHelper {
58  public:
59  static int GetWidthLn2(Image *img) {
60  return ImageHelper::GetPowerOf2(img->GetWidth());
61  }
62 
63  static int GetHeightLn2(Image *img) {
64  return ImageHelper::GetPowerOf2(img->GetHeight());
65  }
66 
67  static int GetPowerOf2(int value) {
68  int power = 1;
69  while (1 << power != value) {
70  ++power;
71  }
72 
73  return power;
74  }
75 };
76 
77 #pragma pack(push, 1)
78 struct TextureHeader {
79  char pName[16];
91  uint32_t pBits; // 0x0002 - generate mipmaps
92  // 0x0200 - 0th palette entry is transparent, else colorkey
93  // (7FF)
94 };
95 #pragma pack(pop)
96 
97 struct Texture_MM7 {
98  Texture_MM7();
99  void Release();
100 
105 };
106 
107 /* 323 */
111 };
112 
113 class Texture;
115  public:
116  inline TextureFrame() : tex(nullptr) {}
117 
118  String name = "null";
122 
123  Texture *GetTexture();
124 
125  protected:
127 };
128 
129 /* 40 */
130 #pragma pack(push, 1)
132  inline TextureFrameTable() {
133  pTextures = 0;
134  sNumTextures = 0;
135  }
136  void ToFile();
137  void FromFile(void *data_mm6, void *data_mm7, void *data_mm8);
138  void LoadAnimationSequenceAndPalettes(int uIconID);
139  Texture *GetFrameTexture(int uFrameID, int time);
140  int FindTextureByName(const char *Str2);
141 
144 };
145 #pragma pack(pop)
146 
148 
150  OptionsMenuSkin();
151  void Relaease();
152 
165 };
166 extern OptionsMenuSkin options_menu_skin; // 507C60
167 
168 extern struct stru355 stru_4E82A4; // = {0x20, 0x41, 0, 0x20, 0xFF0000, 0xFF00,
169  // 0xFF, 0xFF000000}; moved to texture.h
170 extern struct stru355 stru_4EFCBC; // = {0x20, 0x41, 0, 0x10, 0x7C00, 0x3E0,
171  // 0x1F, 0x8000}; moved to texture.h
172 
173 struct stru355 {
174  int field_0;
175  int field_4;
176  int field_8;
177  int field_C;
178  int field_10;
179  int field_14;
180  int field_18;
181  int field_1C;
182 };
OptionsMenuSkin
Definition: Image.h:149
uint16_t
unsigned __int16 uint16_t
Definition: SDL_config.h:37
TEXTURE_FRAME_TABLE_FIRST
@ TEXTURE_FRAME_TABLE_FIRST
Definition: Image.h:110
int16_t
signed __int16 int16_t
Definition: SDL_config.h:36
OptionsMenuSkin::uTextureID_SoundLevels
Image * uTextureID_SoundLevels[10]
Definition: Image.h:161
TextureFrame::uFlags
int16_t uFlags
Definition: Image.h:121
IMAGE_FORMAT_BytesPerPixel
unsigned int IMAGE_FORMAT_BytesPerPixel(IMAGE_FORMAT format)
Definition: Image.cpp:46
Image::GetHeight
unsigned int GetHeight()
Definition: Image.cpp:230
Image::native_format
IMAGE_FORMAT native_format
Definition: Image.h:51
TextureFrameTable::FindTextureByName
int FindTextureByName(const char *Str2)
Definition: Image.cpp:136
stru355::field_4
int field_4
Definition: Image.h:175
TextureFrameTable::TextureFrameTable
TextureFrameTable()
Definition: Image.h:132
TextureFrameTable::ToFile
void ToFile()
Definition: Image.cpp:72
OptionsMenuSkin::Relaease
void Relaease()
Definition: UIGame.cpp:622
OptionsMenuSkin::OptionsMenuSkin
OptionsMenuSkin()
Definition: UIGame.cpp:607
Texture_MM7::Texture_MM7
Texture_MM7()
Definition: Image.cpp:187
OptionsMenuSkin::uTextureID_ArrowLeft
Image * uTextureID_ArrowLeft
Definition: Image.h:155
ImageHelper::GetPowerOf2
static int GetPowerOf2(int value)
Definition: Image.h:67
IMAGE_FORMAT_R8G8B8A8
@ IMAGE_FORMAT_R8G8B8A8
Definition: Image.h:9
Image::loader
ImageLoader * loader
Definition: Image.h:47
height
EGLSurface EGLint EGLint EGLint EGLint height
Definition: SDL_egl.h:1596
TextureFrameTable::pTextures
TextureFrame * pTextures
Definition: Image.h:143
OptionsMenuSkin::uTextureID_unused_1
Image * uTextureID_unused_1
Definition: Image.h:158
Image::GetFormat
IMAGE_FORMAT GetFormat() const
Definition: Image.h:40
Texture
Definition: Texture.h:4
OptionsMenuSkin::uTextureID_unused_2
Image * uTextureID_unused_2
Definition: Image.h:159
ImageHelper
Definition: Image.h:57
OptionsMenuSkin::uTextureID_ArrowRight
Image * uTextureID_ArrowRight
Definition: Image.h:156
TextureFrame::uAnimLength
int16_t uAnimLength
Definition: Image.h:120
TextureFrameTable::FromFile
void FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
Definition: Image.cpp:83
OptionsMenuSkin::uTextureID_TurnSpeed
Image * uTextureID_TurnSpeed[3]
Definition: Image.h:154
stru355::field_C
int field_C
Definition: Image.h:177
IMAGE_INVALID_FORMAT
@ IMAGE_INVALID_FORMAT
Definition: Image.h:12
TextureHeader::pBits
uint32_t pBits
Definition: Image.h:91
TextureHeader::uWidthLn2
int16_t uWidthLn2
Definition: Image.h:84
Texture_MM7::paletted_pixels
uint8_t * paletted_pixels
Definition: Image.h:102
TextureFrame::GetTexture
Texture * GetTexture()
Definition: Image.cpp:65
ImageHelper::GetWidthLn2
static int GetWidthLn2(Image *img)
Definition: Image.h:59
IMAGE_FORMAT_A8R8G8B8
@ IMAGE_FORMAT_A8R8G8B8
Definition: Image.h:7
TextureFrameTable
Definition: Image.h:131
format
SDL_AudioFormat format
Definition: SDL_audio.h:194
Image::lazy_initialization
bool lazy_initialization
Definition: Image.h:45
Texture_MM7::header
TextureHeader header
Definition: Image.h:101
Image::GetWidth
unsigned int GetWidth()
Definition: Image.cpp:217
IMAGE_FORMAT_R8G8B8
@ IMAGE_FORMAT_R8G8B8
Definition: Image.h:8
TEXTURE_FRAME_TABLE_MORE_FRAMES
@ TEXTURE_FRAME_TABLE_MORE_FRAMES
Definition: Image.h:109
Image::~Image
virtual ~Image()
Definition: Image.h:31
TextureFrameTable::sNumTextures
uint32_t sNumTextures
Definition: Image.h:142
OptionsMenuSkin::uTextureID_ShowDamage
Image * uTextureID_ShowDamage
Definition: Image.h:164
Image
Definition: Image.h:19
TEXTURE_FRAME_TABLE_FLAGS
TEXTURE_FRAME_TABLE_FLAGS
Definition: Image.h:108
TextureHeader::uHeightMinus1
int16_t uHeightMinus1
Definition: Image.h:87
TextureHeader::pName
char pName[16]
Definition: Image.h:79
TextureFrame::TextureFrame
TextureFrame()
Definition: Image.h:116
options_menu_skin
OptionsMenuSkin options_menu_skin
Definition: UIGame.cpp:606
stru355::field_8
int field_8
Definition: Image.h:176
stru355::field_1C
int field_1C
Definition: Image.h:181
IMAGE_FORMAT_R5G6B5
@ IMAGE_FORMAT_R5G6B5
Definition: Image.h:5
Image::LoadImageData
virtual bool LoadImageData()
Definition: Image.cpp:203
width
EGLSurface EGLint EGLint EGLint width
Definition: SDL_egl.h:1596
TextureHeader::uHeightLn2
int16_t uHeightLn2
Definition: Image.h:85
IMAGE_FORMAT_ToString
const wchar_t * IMAGE_FORMAT_ToString(IMAGE_FORMAT format)
Definition: Image.cpp:27
TextureHeader::uDecompressedSize
uint32_t uDecompressedSize
Definition: Image.h:90
TextureHeader::uWidthMinus1
int16_t uWidthMinus1
Definition: Image.h:86
TextureFrameTable::LoadAnimationSequenceAndPalettes
void LoadAnimationSequenceAndPalettes(int uIconID)
Definition: Image.cpp:118
ImageHelper::GetHeightLn2
static int GetHeightLn2(Image *img)
Definition: Image.h:63
value
EGLSyncKHR EGLint EGLint * value
Definition: SDL_egl.h:899
TextureHeader::uTextureSize
uint32_t uTextureSize
Definition: Image.h:81
ImageLoader
Definition: ImageLoader.h:10
stru_4E82A4
struct stru355 stru_4E82A4
Definition: Image.cpp:22
TextureHeader::uTextureWidth
uint16_t uTextureWidth
Definition: Image.h:82
stru_4EFCBC
struct stru355 stru_4EFCBC
Definition: Image.cpp:23
Texture_MM7
Definition: Image.h:97
IMAGE_FORMAT
IMAGE_FORMAT
Definition: Image.h:4
TextureHeader::uTextureHeight
uint16_t uTextureHeight
Definition: Image.h:83
Image::Image
Image(bool lazy_initialization=true)
Definition: Image.h:21
uint8_t
unsigned __int8 uint8_t
Definition: SDL_config.h:35
TextureHeader::palette_id1
int16_t palette_id1
Definition: Image.h:88
Image::initialized
bool initialized
Definition: Image.h:46
name
EGLImageKHR EGLint * name
Definition: SDL_egl.h:1497
TextureHeader::palette_id2
int16_t palette_id2
Definition: Image.h:89
Image::Create
static Image * Create(unsigned int width, unsigned int height, IMAGE_FORMAT format, const void *pixels=nullptr)
Definition: Image.cpp:243
pTextureFrameTable
TextureFrameTable * pTextureFrameTable
Definition: Image.cpp:20
OptionsMenuSkin::uTextureID_unused_0
Image * uTextureID_unused_0
Definition: Image.h:157
IMAGE_FORMAT_A1R5G5B5
@ IMAGE_FORMAT_A1R5G5B5
Definition: Image.h:6
stru355
Definition: Image.h:173
Image::GetPixels
const void * GetPixels(IMAGE_FORMAT format)
Definition: Image.cpp:270
OptionsMenuSkin::uTextureID_AlwaysRun
Image * uTextureID_AlwaysRun
Definition: Image.h:162
stru355::field_18
int field_18
Definition: Image.h:180
TextureHeader
Definition: Image.h:78
IMAGE_NUM_FORMATS
@ IMAGE_NUM_FORMATS
Definition: Image.h:11
TextureHeader::uSizeOfMaxLevelOfDetail
uint32_t uSizeOfMaxLevelOfDetail
Definition: Image.h:80
Texture_MM7::pLevelOfDetail1
uint8_t * pLevelOfDetail1
Definition: Image.h:103
Texture_MM7::pPalette24
uint8_t * pPalette24
Definition: Image.h:104
TextureFrame
Definition: Image.h:114
TextureFrame::uAnimTime
int16_t uAnimTime
Definition: Image.h:119
stru355::field_14
int field_14
Definition: Image.h:179
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
uint32_t
unsigned __int32 uint32_t
Definition: SDL_config.h:39
OptionsMenuSkin::uTextureID_Background
Image * uTextureID_Background
Definition: Image.h:153
String
std::string String
Definition: Strings.h:10
Image::Release
bool Release()
Definition: Image.cpp:335
stru355::field_10
int field_10
Definition: Image.h:178
Texture_MM7::Release
void Release()
Definition: Image.cpp:165
OptionsMenuSkin::uTextureID_WalkSound
Image * uTextureID_WalkSound
Definition: Image.h:163
img
GLint GLvoid * img
Definition: SDL_opengl.h:1980
TextureFrame::tex
Texture * tex
Definition: Image.h:126
OptionsMenuSkin::uTextureID_FlipOnExit
Image * uTextureID_FlipOnExit
Definition: Image.h:160
stru355::field_0
int field_0
Definition: Image.h:174
Strings.h
TextureFrameTable::GetFrameTexture
Texture * GetFrameTexture(int uFrameID, int time)
Definition: Image.cpp:146