Hi I have writen two pairs of functions to read png files in Windows. The first pair uses DirectX 9. The second pair uses libPNG. Both pairs work the same way, by reading the data and putting the images into a GDI bitmap. Both files are attached to this post. I have used the DX9 version in both Z+ 0.3.3 and V 3.2.0. I have used the PNG version only in V 3.2.0. I have posted the first function of the DX9 version in another thread (Angband 64x64 pixel tiles), but that version does not load the display mask from an alpha channel in the file.
To use add the function prototypes somewhere, like in readdib.h or above init_graphics() in main-win.c:
extern BOOL ReadDIB_DX9(HWND, LPSTR, DIBINIT *);
extern BOOL ReadDIB2_DX9(HWND, LPSTR, DIBINIT *, DIBINIT *);
or :
extern BOOL ReadDIB_PNG(HWND, LPSTR, DIBINIT *);
extern BOOL ReadDIB2_PNG(HWND, LPSTR, DIBINIT *, DIBINIT *);
Then in init_graphics() in main-win.c change the section between /* Load the bitmap or quit */ and /* Activate a palette */ with:
/* Load the bitmap or quit */
if (mask)
{
if (!ReadDIB_DX9(data[0].w, buf, &infGraph))
{
plog_fmt("Cannot read bitmap file '%s'", name);
return (FALSE);
}
/* Access the mask file */
path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, mask);
/* Load the bitmap or quit */
if (!ReadDIB_DX9(data[0].w, buf, &infMask))
{
plog_fmt("Cannot read bitmap file '%s'", buf);
return (FALSE);
}
}
else
{
if (!ReadDIB2_DX9(data[0].w, buf, &infGraph, &infMask))
{
plog_fmt("Cannot read bitmap file '%s'", name);
return (FALSE);
}
}
/* Save the new sizes */
infGraph.CellWidth = wid;
infGraph.CellHeight = hgt;
/* Activate a palette */
Or replace DX9 with PNG in the 3 function calls above.
Of course you need to have the right headers in your include path and link against the right libraries.
For DX9 the libraries are d3d9.lib and d3dx9.lib. For the PNG version the library is libpng.lib, libpng15.lib, or whatever you named it when you built it.
If you want to replace ReadDIB() entirely (after testing this alot), remember that FreeDIB() in readdib.c is still needed.
These functions are hacks, but they work for me, and may work for you until something better comes along.
To use add the function prototypes somewhere, like in readdib.h or above init_graphics() in main-win.c:
extern BOOL ReadDIB_DX9(HWND, LPSTR, DIBINIT *);
extern BOOL ReadDIB2_DX9(HWND, LPSTR, DIBINIT *, DIBINIT *);
or :
extern BOOL ReadDIB_PNG(HWND, LPSTR, DIBINIT *);
extern BOOL ReadDIB2_PNG(HWND, LPSTR, DIBINIT *, DIBINIT *);
Then in init_graphics() in main-win.c change the section between /* Load the bitmap or quit */ and /* Activate a palette */ with:
/* Load the bitmap or quit */
if (mask)
{
if (!ReadDIB_DX9(data[0].w, buf, &infGraph))
{
plog_fmt("Cannot read bitmap file '%s'", name);
return (FALSE);
}
/* Access the mask file */
path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, mask);
/* Load the bitmap or quit */
if (!ReadDIB_DX9(data[0].w, buf, &infMask))
{
plog_fmt("Cannot read bitmap file '%s'", buf);
return (FALSE);
}
}
else
{
if (!ReadDIB2_DX9(data[0].w, buf, &infGraph, &infMask))
{
plog_fmt("Cannot read bitmap file '%s'", name);
return (FALSE);
}
}
/* Save the new sizes */
infGraph.CellWidth = wid;
infGraph.CellHeight = hgt;
/* Activate a palette */
Or replace DX9 with PNG in the 3 function calls above.
Of course you need to have the right headers in your include path and link against the right libraries.
For DX9 the libraries are d3d9.lib and d3dx9.lib. For the PNG version the library is libpng.lib, libpng15.lib, or whatever you named it when you built it.
If you want to replace ReadDIB() entirely (after testing this alot), remember that FreeDIB() in readdib.c is still needed.
These functions are hacks, but they work for me, and may work for you until something better comes along.
Comment