1 /////////////////////////////////////////////////////////////////////////////////
3 // $Id: png.cpp,v 1.1 2002/06/29 15:03:33 nedko Exp $
9 /////////////////////////////////////////////////////////////////////////////////
14 #define NOT_LOADED_BITMAP_HEIGHT 50
15 #define NOT_LOADED_BITMAP_WIDTH 300
17 CPNGImage::CPNGImage()
24 CPNGImage::~CPNGImage()
29 CPNGImage::PNG_ErrorHandler
PNGARG((png_structp s
, png_const_charp str
))
31 ::MessageBox(NULL
,str
,"PNG Error",MB_OK
);
35 CPNGImage::LoadPNGImage(const char *pszPath
)
39 unsigned int sig_read
= 0;
41 FILE *fp
= fopen(pszPath
, "rb");
47 png_ptr
= png_create_read_struct(PNG_LIBPNG_VER_STRING
,
58 info_ptr
= png_create_info_struct(png_ptr
);
62 png_destroy_read_struct(&png_ptr
, png_infopp_NULL
, png_infopp_NULL
);
66 if (setjmp(png_jmpbuf(png_ptr
)))
68 /* Free all of the memory associated with the png_ptr and info_ptr */
69 png_destroy_read_struct(&png_ptr
, &info_ptr
, png_infopp_NULL
);
71 /* If we get here, we had a problem reading the file */
75 png_init_io(png_ptr
, fp
);
77 /* If we have already read some of the signature */
78 png_set_sig_bytes(png_ptr
, sig_read
);
82 PNG_TRANSFORM_IDENTITY
,
86 /* clean up after the read, and free any memory allocated - REQUIRED */
87 png_destroy_read_struct(&png_ptr
, &info_ptr
, png_infopp_NULL
);
101 return NOT_LOADED_BITMAP_WIDTH
;
105 CPNGImage::GetHeight()
110 return NOT_LOADED_BITMAP_HEIGHT
;
114 CPNGImage::SelectBitmap(HDC hMemoryDC
)
117 ZeroMemory(&BIH
,sizeof(BIH
));
118 BIH
.bV4Size
= sizeof(BIH
);
120 unsigned char *pPixel
;
122 unsigned char *pInternalData
= new unsigned char[327*45*4];
123 for (y
= 0 ; y
< 45; y
++)
125 pPixel
= pInternalData
+ 327 * 4 * y
;
127 for (x
= 0 ; x
< 327 ; x
++)
129 pPixel
[0]= 0xFF; // blue
130 pPixel
[1]= 0xFF; // green
131 pPixel
[2]= 0xFF; // red
132 pPixel
[3]= 180; // alpha
137 HBITMAP hBitmap
= CreateBitmap(NOT_LOADED_BITMAP_WIDTH
,NOT_LOADED_BITMAP_HEIGHT
,1,32,pInternalData
);
139 // delete pInternalData;
144 if (!GetDIBits(hMemoryDC
, hBitmap
, 0, 0, NULL
, (BITMAPINFO
*)&BIH
, DIB_RGB_COLORS
))
147 BIH
.bV4RedMask
= 0x00FF0000;
148 BIH
.bV4GreenMask
= 0x0000FF00;
149 BIH
.bV4BlueMask
= 0x000000FF;
150 BIH
.bV4AlphaMask
= 0xFF000000;
152 unsigned char *pData
= new unsigned char[BIH
.bV4SizeImage
];
153 if (!GetDIBits(hMemoryDC
, hBitmap
, 0, BIH
.bV4Height
, pData
, (BITMAPINFO
*)&BIH
, DIB_RGB_COLORS
))
159 for (y
= 0 ; y
< BIH
.bV4Height
; y
++)
161 pPixel
= pData
+ BIH
.bV4Width
* 4 * y
;
163 for (x
= 0 ; x
< BIH
.bV4Width
; x
++)
165 pPixel
[0]= (unsigned __int8
)(((unsigned int)pPixel
[0])*pPixel
[3]/255);
166 pPixel
[1]= (unsigned __int8
)(((unsigned int)pPixel
[1])*pPixel
[3]/255);
167 pPixel
[2]= (unsigned __int8
)(((unsigned int)pPixel
[2])*pPixel
[3]/255);
172 if (!SetDIBits(hMemoryDC
, hBitmap
, 0, BIH
.bV4Height
, pData
, (BITMAPINFO
*)&BIH
, DIB_RGB_COLORS
))
180 SelectObject(hMemoryDC
, hBitmap
);
185 /////////////////////////////////////////////////////////////////////////////////
187 // Modifications log:
189 // !!! WARNING !!! Following lines are automatically updated by the CVS system.
192 // Revision 1.1 2002/06/29 15:03:33 nedko
193 // *** empty log message ***
195 /////////////////////////////////////////////////////////////////////////////////