diff Engine/Graphics/Texture.cpp @ 2574:dd36326a9994

More texture refactoring GetLeather -> DrawTextureCustomHeight
author a.parshin
date Mon, 07 Mar 2016 03:48:40 +0200
parents 0c67be4ec900
children
line wrap: on
line diff
--- a/Engine/Graphics/Texture.cpp	Sat Mar 05 16:25:53 2016 +0200
+++ b/Engine/Graphics/Texture.cpp	Mon Mar 07 03:48:40 2016 +0200
@@ -27,153 +27,10 @@
 
 
 
-
-
-std::array<Texture *, 2> pTexture_LloydBeacons;
-Texture *pTexture_50635C;
-Texture *pTex_book_button8_off;
-Texture *pTex_book_button8_on;
-Texture *pTex_book_button7_off;
-Texture *pTex_book_button7_on;
-Texture *pTex_book_button6_off;
-Texture *pTex_book_button6_on;
-Texture *pTex_book_button5_off;
-Texture *pTex_book_button5_on;
-Texture *pTex_book_button4_off;
-Texture *pTex_book_button4_on;
-Texture *pTex_book_button3_off;
-Texture *pTex_book_button3_on;
-Texture *pTex_book_button2_off;
-Texture *pTex_book_button1_off;
-Texture *pTex_book_button2_on;
-Texture *pTex_book_button1_on;
-std::array<Texture *, 6> pTexture_TownPortalIcons; // [0]Harmonale, [1]Pierpont, [2]Nighon, [3]Evenmorn Island, [4]Celestia, [5]The Pit
-std::array<Texture *, 12> SBPageCSpellsTextureList;
-std::array<Texture *, 12> SBPageSSpellsTextureList;
-Texture *pSBQuickSpellBtnTextr;
-Texture *pSpellBookClickCloseBtnTextr;
-Texture *pSBClickQuickSpellBtnTextr;
-Texture *pSpellBookCloseBtnTextr;
-std::array<std::array<Texture *, 2>, 9> pTextures_tabs;
-Texture *pTexture_mapbordr; // idb
-Texture *pTexture_pagemask; // idb
-std::array<Texture *, 9> pSpellBookPagesTextr;
-Texture *pSpellBookPagesTextr_9;
-Texture *pSpellBookPagesTextr_10;
-Texture *pSpellBookPagesTextr_11;
-Texture *pSpellBookPagesTextr_12;
-Texture *pSpellBookPagesTextr_13;
-Texture *pTexture_AutonotesBook;
-Texture *pTexture_CurrentBook;
-Texture *pTex_moon_new;
-Texture *pTex_moon_4;
-Texture *pTex_moon_2;
-Texture *pTex_moon_2_2;
-Texture *pTex_moon_ful;
-
-struct Texture *minimap_loop; // 5079D8
-struct Texture *_5079B4_compass; // 5079B4
-struct Texture *_5079C8_init_y; // 5079C8
-struct Texture *_5079CC_init_r; // 5079CC
-struct Texture *_5079D0_init_g; // 5079D0
-
-
-int uTextureID_RestUI_restb4; // weak
-int uTextureID_RestUI_restexit; // weak
-int uTextureID_RestUI_restb3; // weak
-int uTextureID_RestUI_restb1; // weak
-int uTextureID_RestUI_restb2; // weak
-int uTextureID_RestUI_restmain; // weak
-unsigned int uTextureID_Leather;
-int uTextureID_ar_dn_dn; // weak
-int uTextureID_ar_dn_up; // weak
-int uTextureID_ar_up_dn; // weak
-int uTextureID_ar_up_up; // weak
-
-
-unsigned int uTextureID_mhp_yel;
-unsigned int uTextureID_mhp_red;
-unsigned int uTextureID_mhp_grn;
-unsigned int uTextureID_mhp_capr;
-unsigned int uTextureID_mhp_capl;
-unsigned int uTextureID_mhp_bd;
-unsigned int uTextureID_BUTTDESC2;
-unsigned int uTextureID_x_x_u;
-unsigned int uTextureID_BUTTMAKE2;
-unsigned int uTextureID_BUTTMAKE;
-unsigned int uTextureID_BUTTYES2;
-unsigned int uTextureID_x_ok_u;
-std::array<Texture *, 22> pPlayerPortraits;
-std::array<Texture *, 9> pTexture_IC_KNIGHT;
-Texture *pTexture_MAKESKY;
-Texture *pTexture_MAKETOP;
-std::array<Texture *, 20> pTextures_arrowr;
-std::array<Texture *, 20> pTextures_arrowl;
-Texture *pTexture_presleft;
-Texture *pTexture_pressrigh;
-Texture *pTexture_buttminu;
-Texture *pTexture_buttplus;
-unsigned int uTextureID_Quit1; // weak
-unsigned int uTextureID_Resume1; // weak
-unsigned int uTextureID_Controls1; // weak
-unsigned int uTextureID_Save1; // weak
-unsigned int uTextureID_Load1; // weak
-unsigned int uTextureID_New1; // weak
-unsigned int uTextureID_Options; // weak
-
-
-unsigned int uTextureID_ib_td5_A;
-unsigned int uTextureID_ib_td4_A;
-unsigned int uTextureID_ib_td3_A;
-unsigned int uTextureID_ib_td2_A;
-unsigned int uTextureID_ib_td1_A;
-int uTextureID_50795C; // weak
-
-
-unsigned int uTextureID_Btn_GameSettings;
-
-
-unsigned int uTextureID_Btn_Rest;
-unsigned int uTextureID_Btn_CastSpell;
-unsigned int uTextureID_Btn_ZoomIn;
-unsigned int uTextureID_Btn_ZoomOut;
-unsigned int uTextureID_FONTPAL;
-unsigned int uTextureID_Btn_NPCRight;
-unsigned int uTextureID_Btn_NPCLeft;
-std::array<unsigned int, 8> pTextureIDs_pMapDirs;
-
-
-unsigned int uTextureID_BarRed;
-unsigned int uTextureID_BarYellow;
-unsigned int uTextureID_BarGreen;
-unsigned int uTextureID_BarBlue;
-
-
-
-
-Texture *pTexture_Leather;
-Texture *pTexture_RestUI_CurrentSkyFrame; // idb
-Texture *pTexture_RestUI_CurrentHourglassFrame; // idb
-
-
-std::array<unsigned int, 5> uTextureID_Optkb;
-
-unsigned int optvid_base_texture_id;
-unsigned int bloodsplats_texture_id;
-unsigned int us_colored_lights_texture_id;
-unsigned int tinting_texture_id;
-unsigned int uTextureID_507C20; // weak
-unsigned int uTextureID_507C24; // weak
-std::array<unsigned int, 10> pTextureIDs_GammaPositions;
-unsigned int not_available_bloodsplats_texture_id;
-unsigned int not_available_us_colored_lights_texture_id;
-unsigned int not_available_tinting_texture_id;
-
-
 stru355 stru_4E82A4 = {0x20, 0x41, 0, 0x20, 0xFF0000, 0xFF00, 0xFF, 0xFF000000};
 stru355 stru_4EFCBC = {0x20, 0x41, 0, 0x10, 0x7C00, 0x3E0, 0x1F, 0x8000};
 
-Texture pTex_F7CE30;
+//Texture_MM7 pTex_F7CE30;
 
 
 
@@ -334,12 +191,12 @@
 
 
 //----- (0040F806) --------------------------------------------------------
-void *Texture::UnzipPalette()
+void *Texture_MM7::UnzipPalette()
 {
-  Texture *v1; // esi@1
+  Texture_MM7 *v1; // esi@1
 
   void *v2; // edi@1
-  Texture *pSource; // [sp+0h] [bp-4h]@1
+  Texture_MM7 *pSource; // [sp+0h] [bp-4h]@1
 
   pSource = this;
   v1 = this;
@@ -349,7 +206,7 @@
 }
 
 //----- (0040F77C) --------------------------------------------------------
-void Texture::Release()
+void Texture_MM7::Release()
 {
   if (this)
   {
@@ -410,7 +267,7 @@
   unsigned __int16 *v8; // ST20_4@14
   int v9; // eax@14
   char color_map[48]; // [sp+8h] [bp-98h]@9
-  Texture DstBuf; // [sp+38h] [bp-68h]@1
+  Texture_MM7 DstBuf; // [sp+38h] [bp-68h]@1
   PCXHeader1 header1; // [sp+80h] [bp-20h]@9
   PCXHeader2 header2; // [sp+90h] [bp-10h]@9
   FILE *File; // [sp+98h] [bp-8h]@3
@@ -467,7 +324,7 @@
 }
 
 //----- (0040F5BE) --------------------------------------------------------
-Texture::Texture()
+Texture_MM7::Texture_MM7()
 {
   pName[0] = 0;
   uSizeOfMaxLevelOfDetail = 0;
@@ -495,7 +352,7 @@
   FILE *file; // eax@1
   void *v6; // ebx@5
   char color_map[48]; // [sp+Ch] [bp-98h]@7
-  Texture DstBuf; // [sp+3Ch] [bp-68h]@1
+  Texture_MM7 DstBuf; // [sp+3Ch] [bp-68h]@1
   PCXHeader1 header1; // [sp+84h] [bp-20h]@7
   PCXHeader2 header2; // [sp+94h] [bp-10h]@7
   size_t Count; // [sp+A0h] [bp-4h]@4
@@ -2007,6 +1864,67 @@
 
 
 
+struct Image16bit_LOD_Loader : public ImageLoader
+{
+    inline Image16bit_LOD_Loader(LODFile_IconsBitmaps *lod, const wchar_t *name)
+    {
+        wcscpy(this->name, name);
+        this->lod = lod;
+    }
+
+    virtual bool Load(unsigned int *width, unsigned int *height, void **pixels, IMAGE_FORMAT *format);
+
+    wchar_t               name[1024];
+    LODFile_IconsBitmaps *lod;
+};
+
+
+bool Image16bit_LOD_Loader::Load(unsigned int *out_width, unsigned int *out_height, void **out_pixels, IMAGE_FORMAT *out_format)
+{
+    *out_width = 0;
+    *out_height = 0;
+    *out_pixels = nullptr;
+    *out_format = IMAGE_INVALID_FORMAT;
+
+    char namea[1024];
+    sprintf(namea, "%S", name);
+
+    auto tex = lod->GetTexture(lod->LoadTexture(namea, TEXTURE_16BIT_PALETTE));
+    if (tex->pBits & 512)
+        Log::Warning(L"Alpha texture is loaded as Image16bit (%s)", name);
+
+    if (tex->pPalette16 && tex->paletted_pixels)
+    {
+        auto palette = tex->pPalette16;
+        auto paletted_pixels = tex->paletted_pixels;
+
+        auto width = tex->uTextureWidth;
+        auto height = tex->uTextureHeight;
+        auto pixels = new unsigned __int16[width * height];
+        if (pixels)
+        {
+            for (unsigned int y = 0; y < height; ++y)
+                for (unsigned int x = 0; x < width; ++x)
+                {
+                    auto index = paletted_pixels[y * width + x];
+                    auto pixel = tex->pPalette16[index];
+                    
+                    pixels[y * width + x] = pixel;
+                }
+            *out_width = width;
+            *out_height = height;
+            *out_pixels = pixels;
+            *out_format = IMAGE_FORMAT_R5G6B5;
+        }
+    }
+
+    return *out_pixels != nullptr;
+}
+
+
+
+
+
 
 struct Alpha_LOD_Loader : public ImageLoader
 {
@@ -2034,6 +1952,8 @@
     sprintf(namea, "%S", name);
 
     auto tex = lod->GetTexture(lod->LoadTexture(namea, TEXTURE_16BIT_PALETTE));
+    if (~tex->pBits & 512)
+        Log::Warning(L"ColorKey texture is loaded as Alpha (%s)", name);
 
     if (tex->pPalette16 && tex->paletted_pixels)
     {
@@ -2104,6 +2024,8 @@
     sprintf(namea, "%S", name);
 
     auto tex = lod->GetTexture(lod->LoadTexture(namea, TEXTURE_16BIT_PALETTE));
+    if (tex->pBits & 512)
+        Log::Warning(L"Alpha texture is loaded as ColorKey (%s)", name);
 
     if (tex->pPalette16 && tex->paletted_pixels)
     {
@@ -2478,7 +2400,7 @@
     FILE *file; // eax@1
     void *v6; // ebx@5
     char color_map[48]; // [sp+Ch] [bp-98h]@7
-    Texture DstBuf; // [sp+3Ch] [bp-68h]@1
+    Texture_MM7 DstBuf; // [sp+3Ch] [bp-68h]@1
     PCXHeader1 header1; // [sp+84h] [bp-20h]@7
     PCXHeader2 header2; // [sp+94h] [bp-10h]@7
     size_t Count; // [sp+A0h] [bp-4h]@4
@@ -2591,6 +2513,16 @@
     return true;
 }
 
+bool Image::Image16bit_From_LOD(const wchar_t *name)
+{
+    loader = new Image16bit_LOD_Loader(pIcons_LOD, name);
+
+    if (!lazy_initialization)
+        this->LoadImageData();
+
+    return true;
+}
+
 
 
 bool Image::ColorKey_From_LOD(const wchar_t *name, unsigned __int16 colorkey)