Mercurial > mm7
changeset 2295:6fd03869f65c
LoadTexture cleaned and add ConvertPNG function
author | Ritor1 |
---|---|
date | Mon, 17 Mar 2014 01:20:15 +0600 |
parents | d65414f65bd4 |
children | 6e178010fc29 |
files | Build/Visual Studio 2012/World of Might and Magic.vcxproj Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters LOD.cpp MMT.cpp |
diffstat | 4 files changed, 194 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj Sun Mar 16 19:34:51 2014 +0600 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj Mon Mar 17 01:20:15 2014 +0600 @@ -117,6 +117,21 @@ <ClCompile Include="..\..\Items.cpp" /> <ClCompile Include="..\..\Keyboard.cpp" /> <ClCompile Include="..\..\Level\Decoration.cpp" /> + <ClCompile Include="..\..\lib\libpng\png.c" /> + <ClCompile Include="..\..\lib\libpng\pngerror.c" /> + <ClCompile Include="..\..\lib\libpng\pngget.c" /> + <ClCompile Include="..\..\lib\libpng\pngmem.c" /> + <ClCompile Include="..\..\lib\libpng\pngpread.c" /> + <ClCompile Include="..\..\lib\libpng\pngread.c" /> + <ClCompile Include="..\..\lib\libpng\pngrio.c" /> + <ClCompile Include="..\..\lib\libpng\pngrtran.c" /> + <ClCompile Include="..\..\lib\libpng\pngrutil.c" /> + <ClCompile Include="..\..\lib\libpng\pngset.c" /> + <ClCompile Include="..\..\lib\libpng\pngtrans.c" /> + <ClCompile Include="..\..\lib\libpng\pngwio.c" /> + <ClCompile Include="..\..\lib\libpng\pngwrite.c" /> + <ClCompile Include="..\..\lib\libpng\pngwtran.c" /> + <ClCompile Include="..\..\lib\libpng\pngwutil.c" /> <ClCompile Include="..\..\lib\lua\lua-5.2.2\lapi.c" /> <ClCompile Include="..\..\lib\lua\lua-5.2.2\lauxlib.c" /> <ClCompile Include="..\..\lib\lua\lua-5.2.2\lbaselib.c" /> @@ -351,6 +366,13 @@ <ClInclude Include="..\..\lib\libavutil\timestamp.h" /> <ClInclude Include="..\..\lib\libavutil\version.h" /> <ClInclude Include="..\..\lib\libavutil\xtea.h" /> + <ClInclude Include="..\..\lib\libpng\png.h" /> + <ClInclude Include="..\..\lib\libpng\pngconf.h" /> + <ClInclude Include="..\..\lib\libpng\pngdebug.h" /> + <ClInclude Include="..\..\lib\libpng\pnginfo.h" /> + <ClInclude Include="..\..\lib\libpng\pnglibconf.h" /> + <ClInclude Include="..\..\lib\libpng\pngpriv.h" /> + <ClInclude Include="..\..\lib\libpng\pngstruct.h" /> <ClInclude Include="..\..\lib\libswresample\swresample.h" /> <ClInclude Include="..\..\lib\libswresample\version.h" /> <ClInclude Include="..\..\lib\libswscale\swscale.h" />
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Sun Mar 16 19:34:51 2014 +0600 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Mon Mar 17 01:20:15 2014 +0600 @@ -64,6 +64,9 @@ <Filter Include="lib\libswscale"> <UniqueIdentifier>{293e30b6-9ded-426f-a0be-425b0a877e93}</UniqueIdentifier> </Filter> + <Filter Include="lib\libpng"> + <UniqueIdentifier>{a768f30d-81a0-4858-a264-dd7120e64106}</UniqueIdentifier> + </Filter> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\Level\Decoration.cpp" /> @@ -336,6 +339,51 @@ </ClCompile> <ClCompile Include="..\..\MapInfo.cpp" /> <ClCompile Include="..\..\MMT.cpp" /> + <ClCompile Include="..\..\lib\libpng\png.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngerror.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngget.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngmem.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngpread.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngread.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngrio.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngrtran.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngrutil.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngset.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngtrans.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngwio.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngwrite.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngwtran.c"> + <Filter>lib\libpng</Filter> + </ClCompile> + <ClCompile Include="..\..\lib\libpng\pngwutil.c"> + <Filter>lib\libpng</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\Level\Decoration.h" /> @@ -838,6 +886,27 @@ </ClInclude> <ClInclude Include="..\..\mm7_unsorted_subs.h" /> <ClInclude Include="..\..\MMT.h" /> + <ClInclude Include="..\..\lib\libpng\png.h"> + <Filter>lib\libpng</Filter> + </ClInclude> + <ClInclude Include="..\..\lib\libpng\pngconf.h"> + <Filter>lib\libpng</Filter> + </ClInclude> + <ClInclude Include="..\..\lib\libpng\pngdebug.h"> + <Filter>lib\libpng</Filter> + </ClInclude> + <ClInclude Include="..\..\lib\libpng\pnginfo.h"> + <Filter>lib\libpng</Filter> + </ClInclude> + <ClInclude Include="..\..\lib\libpng\pnglibconf.h"> + <Filter>lib\libpng</Filter> + </ClInclude> + <ClInclude Include="..\..\lib\libpng\pngpriv.h"> + <Filter>lib\libpng</Filter> + </ClInclude> + <ClInclude Include="..\..\lib\libpng\pngstruct.h"> + <Filter>lib\libpng</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\..\Player.swig" />
--- a/LOD.cpp Sun Mar 16 19:34:51 2014 +0600 +++ b/LOD.cpp Mon Mar 17 01:20:15 2014 +0600 @@ -2817,8 +2817,6 @@ //LODFile_IconsBitmaps *v3; // esi@1 //unsigned int v4; // edi@1 //Texture *v5; // ebx@2 - unsigned int v6; // ebx@8 - const char *Sourcea; // [sp+14h] [bp+8h]@9 //v3 = this; //v4 = 0; @@ -2841,20 +2839,11 @@ }*/ if (LoadTextureFromLOD(&pTextures[uNumLoadedFiles], pContainer, uTextureType) == -1) { - v6 = 0; - if (uNumLoadedFiles > 0) + for ( uint i = 0; i < uNumLoadedFiles; ++i ) { - Sourcea = (const char *)pTextures; - while ( _stricmp(Sourcea, "pending") ) - { - Sourcea += 72; - ++v6; - if (v6 >= uNumLoadedFiles) - goto LABEL_15; - } - return v6; + if (!_stricmp(pTextures[i].pName, "pending")) + return i; } -LABEL_15: LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending", uTextureType); } areWeLoadingTexture = 0;
--- a/MMT.cpp Sun Mar 16 19:34:51 2014 +0600 +++ b/MMT.cpp Mon Mar 17 01:20:15 2014 +0600 @@ -11,6 +11,7 @@ #include "VideoPlayer.h" #include "CShow.h" #include "GUIFont.h" +#include "lib/libpng/png.h" void ShowLogoVideo() { @@ -61,6 +62,96 @@ bGameoverLoop = 0; } +void abort_(const char * s, ...) +{ + va_list args; + va_start(args, s); + vfprintf(stderr, s, args); + fprintf(stderr, "\n"); + va_end(args); + abort(); +} + +Texture *ConvertPNG(const char *name) +{ + int x, y; + int width, height; + png_byte color_type; + png_byte bit_depth; + png_structp png_ptr; + png_infop info_ptr; + int number_of_passes; + png_bytep * row_pointers; + uint i = 0; + Texture *tex; + + char header[8]; // 8 is the maximum size that can be checked + + /* open file and test for it being a png */ + FILE *fp = fopen(name, "rb"); + if (!fp) + Log::Warning(L"[read_png_file] File %s could not be opened for reading", name); + fread(header, 1, 8, fp); + //if (png_sig_cmp(header, 0, 8)) + //Log::Warning(L"[read_png_file] File %s is not recognized as a PNG file", pContainerName); + /* initialize stuff */ + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + + if (!png_ptr) + abort_("[read_png_file] png_create_read_struct failed"); + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + abort_("[read_png_file] png_create_info_struct failed"); + + if (setjmp(png_jmpbuf(png_ptr))) + abort_("[read_png_file] Error during init_io"); + + png_init_io(png_ptr, fp); + png_set_sig_bytes(png_ptr, 8); + + png_read_info(png_ptr, info_ptr); + + width = png_get_image_width(png_ptr, info_ptr); + height = png_get_image_height(png_ptr, info_ptr); + color_type = png_get_color_type(png_ptr, info_ptr); + bit_depth = png_get_bit_depth(png_ptr, info_ptr); + + number_of_passes = png_set_interlace_handling(png_ptr); + png_read_update_info(png_ptr, info_ptr); + + + /* read file */ + if (setjmp(png_jmpbuf(png_ptr))) + abort_("[read_png_file] Error during read_image"); + + row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height); + for (y=0; y<height; y++) + row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr)); + unsigned __int16 * pl = (unsigned __int16 *)row_pointers; + png_read_image(png_ptr, row_pointers); + + fclose(fp); + tex = pIcons_LOD->GetTexture(pIcons_LOD->FindTextureByName("Pending"));//не знаю как зачистить + tex->uTextureHeight = height; + tex->uTextureWidth = width; + tex->uSizeOfMaxLevelOfDetail = png_get_rowbytes(png_ptr, info_ptr); + tex->uTextureSize = png_get_rowbytes(png_ptr, info_ptr); + tex->uDecompressedSize = png_get_rowbytes(png_ptr, info_ptr); + + for (y=0; y<height; y++) + { + for (x=0; x<width; x++) + { + if ( pl ) + tex->pPalette16[i] = Color16(LOBYTE(pl), BYTE1(pl), BYTE2(pl)); + i++; + pl++; + } + } + return tex; +} + void MMT_MainMenu_Loop() { GUIButton *pButton; // eax@27 @@ -71,6 +162,9 @@ unsigned int pY; // [sp-18h] [bp-54h]@39 Texture *pTexture; // [sp-14h] [bp-50h]@39 GUIButton *pButton2; // [sp+0h] [bp-3Ch]@27 + char pContainerName[64]; + + pCurrentScreen = SCREEN_GAME; @@ -81,7 +175,12 @@ pIcons_LOD->_inlined_sub2(); pWindow_MMT_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0); - Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE); + //Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE); + + sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png"); + Texture* MMT_MM6 = ConvertPNG(pContainerName); + + Texture* MMT_MM7 = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE); Texture* MMT_MM8 = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE); Texture* MMT_Continue = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE); @@ -95,8 +194,6 @@ pTexture_PCX.Release(); - char pContainerName[64]; - sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx"); pTexture_PCX.LoadPCXFile(pContainerName, 0); SetCurrentMenuID(MENU_MMT_MAIN_MENU);