X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/72e7876ba5ad16a1b03bb2449ea7886ec648854a..dd107c50be43e8d4dbdba20df162faf119a3781c:/src/mac/carbon/pnghand.cpp diff --git a/src/mac/carbon/pnghand.cpp b/src/mac/carbon/pnghand.cpp index d8a662d7da..5e6840f40d 100644 --- a/src/mac/carbon/pnghand.cpp +++ b/src/mac/carbon/pnghand.cpp @@ -31,11 +31,14 @@ # include #endif -#include -#include -#include -#include -#include +#ifndef __WXMAC_X__ +# include +#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" @@ -47,7 +50,7 @@ extern "C" void png_write_init PNGARG((png_structp png_ptr)); 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 @@ -106,15 +109,17 @@ wxPNGReader::Create(int width, int height, int depth, int colortype) { 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 ; @@ -197,10 +202,11 @@ bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b) 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); } @@ -208,6 +214,7 @@ bool wxPNGReader::SetPalette(wxPalette* colourmap) bool wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b) { + delete Palette ; Palette = new wxPalette(); if (!Palette) return FALSE; @@ -223,6 +230,7 @@ wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b) bool wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct) { + delete Palette ; Palette = new wxPalette(); if (!Palette) return FALSE; @@ -249,6 +257,10 @@ wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct) void wxPNGReader::NullData() { + if (lpbi) { + wxMacDestroyGWorld( lpbi ) ; + } + delete Palette; lpbi = NULL; Palette = NULL; } @@ -402,7 +414,8 @@ bool wxPNGReader::ReadFile(char * ImageFileName) wxPNGReaderIter iter(this); /* open the file */ - fp = fopen(wxUnix2MacFilename( ImageFileName ), "rb"); + fp = fopen( ImageFileName , "rb" ); + if (!fp) return FALSE; @@ -516,30 +529,47 @@ bool wxPNGReader::ReadFile(char * ImageFileName) { 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 { @@ -553,9 +583,9 @@ bool wxPNGReader::ReadFile(char * ImageFileName) 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); } } @@ -567,9 +597,9 @@ bool wxPNGReader::ReadFile(char * ImageFileName) 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); } }