# include <fstream>
#endif
-#include <windows.h>
-#include <wx/palette.h>
-#include <wx/bitmap.h>
-#include <wx/mac/pnghand.h>
-#include <wx/mac/pngread.h>
+#ifndef __WXMAC_X__
+# include <windows.h>
+#endif
+#include "wx/msgdlg.h"
+#include "wx/palette.h"
+#include "wx/bitmap.h"
+#include "wx/mac/pnghand.h"
+#include "wx/mac/pngread.h"
extern "C" {
#include "png.h"
extern CTabHandle wxMacCreateColorTable( int numColors ) ;
extern void wxMacDestroyColorTable( CTabHandle colors ) ;
extern void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
-extern GWorldPtr wxMacCreateGWorld( int height , int width , int depth ) ;
+extern GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
extern void wxMacDestroyGWorld( GWorldPtr gw ) ;
void
{
Width = width; Height = height; Depth = depth;
ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0);
+ delete Palette;
+ delete[] RawImage ;
+ RawImage = 0;
+ Palette = 0;
if (lpbi)
{
wxMacDestroyGWorld( lpbi ) ;
-// delete Palette;
}
- RawImage = 0;
- Palette = 0;
- if (lpbi = wxMacCreateGWorld( Width , Height , Depth) )
+ lpbi = wxMacCreateGWorld( Width , Height , Depth);
+ if (lpbi)
{
EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4;
int bitwidth = width ;
bool wxPNGReader::SetPalette(wxPalette* colourmap)
{
+ delete Palette ;
if (!colourmap)
return FALSE;
ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
- Palette = colourmap;
+ Palette = new wxPalette( *colourmap );
return true ;
// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
}
bool
wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b)
{
+ delete Palette ;
Palette = new wxPalette();
if (!Palette)
return FALSE;
bool
wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct)
{
+ delete Palette ;
Palette = new wxPalette();
if (!Palette)
return FALSE;
void wxPNGReader::NullData()
{
+ if (lpbi) {
+ wxMacDestroyGWorld( lpbi ) ;
+ }
+ delete Palette;
lpbi = NULL;
Palette = NULL;
}
{
if ( pixel_depth == 8 )
{
+ for ( int i = 0 ; i < info_ptr->width ; ++i )
+ {
+ png_color_struct* color ;
+ RGBColor col ;
+
+ int index = row_pointers[i] ;
+ color = &info_ptr->palette[index] ;
+ col.red = (((int)color->red) << 8) | ((int)color->red) ;
+ col.green = (((int)color->green) << 8) | ((int)color->green) ;
+ col.blue = (((int)color->blue) << 8) | ((int)color->blue) ;
+ SetCPixel( i, y, &col);
+ }
+ /*
png_color_struct* color ;
RGBColor col ;
unsigned char* p = &row_pointers[0] ;
+ PenNormal() ;
MoveTo( 0 , y ) ;
- unsigned char lastcol = *p ;
- color = &info_ptr->palette[lastcol] ;
+ int index = *p ;
+ color = &info_ptr->palette[index] ;
col.red = (color->red << 8) | color->red ;
col.green = (color->green << 8) | color->green ;
col.blue = (color->blue << 8) | color->blue ;
RGBForeColor( &col ) ;
+ col.red = col.green = col.blue = 0xFFFF ;
+ RGBBackColor( &col ) ;
for ( int i = 0 ; i < info_ptr->width ; ++i , ++p)
{
- if ( *p != lastcol )
+ if ( *p != index )
{
LineTo( i , y ) ;
- lastcol = *p ;
- color = &info_ptr->palette[lastcol] ;
- col.red = (color->red << 8) | color->red ;
- col.green = (color->green << 8) | color->green ;
- col.blue = (color->blue << 8) | color->blue ;
+ index = *p ;
+ color = &info_ptr->palette[index] ;
+ col.red = (((int)color->red) << 8) | ((int)color->red) ;
+ col.green = (((int)color->green) << 8) | ((int)color->green) ;
+ col.blue = (((int)color->blue) << 8) | ((int)color->blue) ;
RGBForeColor( &col ) ;
}
}
- LineTo( info_ptr->width - 1 , y ) ;
+ LineTo( info_ptr->width , y ) ;
+ */
}
else
{
int index = ( row_pointers[byte] >> offset ) & ( 0xFF >> ( 8 - pixel_depth ) );
color = &info_ptr->palette[index] ;
- col.red = (color->red << 8) | color->red ;
- col.green = (color->green << 8) | color->green ;
- col.blue = (color->blue << 8) | color->blue ;
+ col.red = (((int)color->red) << 8) | ((int)color->red) ;
+ col.green = (((int)color->green) << 8) | ((int)color->green) ;
+ col.blue = (((int)color->blue) << 8) | ((int)color->blue) ;
SetCPixel( i, y, &col);
}
}
png_color_struct* color ;
RGBColor col ;
color =(png_color_struct*) (&row_pointers[i*3]) ;
- col.red = (color->red << 8) | color->red ;
- col.green = (color->green << 8) | color->green ;
- col.blue = (color->blue << 8) | color->blue ;
+ col.red = (((int)color->red) << 8) | ((int)color->red) ;
+ col.green = (((int)color->green) << 8) | ((int)color->green) ;
+ col.blue = (((int)color->blue) << 8) | ((int)color->blue) ;
SetCPixel( i, y, &col);
}
}