X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/72e7876ba5ad16a1b03bb2449ea7886ec648854a..2fe212b0336512aac9eace69fab09ce856b0bf4b:/src/mac/pnghand.cpp?ds=sidebyside diff --git a/src/mac/pnghand.cpp b/src/mac/pnghand.cpp index d8a662d7da..193676f195 100644 --- a/src/mac/pnghand.cpp +++ b/src/mac/pnghand.cpp @@ -10,15 +10,15 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "pngread.h" -#pragma implementation "pnghand.h" +# pragma implementation "pngread.h" +# pragma implementation "pnghand.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop +# pragma hdrstop #endif #include @@ -31,11 +31,14 @@ # include #endif -#include -#include -#include -#include -#include +#ifndef __DARWIN__ +# 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 @@ -76,7 +79,7 @@ wxPNGReader::wxPNGReader(void) lpbi = NULL; bgindex = -1; - Palette = 0; + m_palette = 0; imageOK = FALSE; } @@ -88,7 +91,7 @@ wxPNGReader::wxPNGReader ( char* ImageFileName ) Width = 0; Height = 0; // Dimensions Depth = 0; // (bits x pixel) - ColorType = 0; // Bit 1 = Palette used + ColorType = 0; // Bit 1 = m_palette used // Bit 2 = Color used // Bit 3 = Alpha used @@ -96,7 +99,7 @@ wxPNGReader::wxPNGReader ( char* ImageFileName ) lpbi = NULL; bgindex = -1; - Palette = 0; + m_palette = 0; imageOK = ReadFile (ImageFileName); } @@ -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 m_palette; + delete[] RawImage ; + RawImage = 0; + m_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 ; @@ -132,7 +137,7 @@ wxPNGReader::~wxPNGReader ( ) if (lpbi) { wxMacDestroyGWorld( lpbi ) ; } - delete Palette; + delete m_palette; } @@ -149,10 +154,10 @@ bool wxPNGReader::GetRGB(int x, int y, byte* r, byte* g, byte* b) { if (!Inside(x, y)) return FALSE; - if (Palette) { - return Palette->GetRGB(GetIndex(x, y), r, g, b); + if (m_palette) { + return m_palette->GetRGB(GetIndex(x, y), r, g, b); /* PALETTEENTRY entry; - ::GetPaletteEntries((HPALETTE) Palette->GetHPALETTE(), GetIndex(x, y), 1, &entry); + ::GetPaletteEntries((HPALETTE) m_palette->GetHPALETTE(), GetIndex(x, y), 1, &entry); *r = entry.peRed; *g = entry.peGreen; *b = entry.peBlue; */ @@ -182,8 +187,8 @@ bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b) if (ColorType & COLORTYPE_PALETTE) { - if (!Palette) return FALSE; - SetIndex(x, y, Palette->GetPixel(r, g, b)); + if (!m_palette) return FALSE; + SetIndex(x, y, m_palette->GetPixel(r, g, b)); } else { ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3); @@ -197,34 +202,37 @@ bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b) bool wxPNGReader::SetPalette(wxPalette* colourmap) { + delete m_palette ; if (!colourmap) return FALSE; ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR); - Palette = colourmap; + m_palette = new wxPalette( *colourmap ); return true ; -// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0); +// return (DibSetUsage(lpbi, (HPALETTE) m_palette->GetHPALETTE(), WXIMA_COLORS ) != 0); } bool wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b) { - Palette = new wxPalette(); - if (!Palette) + delete m_palette ; + m_palette = new wxPalette(); + if (!m_palette) return FALSE; if (!g) g = r; if (!b) b = g; - Palette->Create(n, r, g, b); + m_palette->Create(n, r, g, b); ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR); return true ; -// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0); +// return (DibSetUsage(lpbi, (HPALETTE) m_palette->GetHPALETTE(), WXIMA_COLORS ) != 0); } bool wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct) { - Palette = new wxPalette(); - if (!Palette) + delete m_palette ; + m_palette = new wxPalette(); + if (!m_palette) return FALSE; byte r[256], g[256], b[256]; @@ -241,16 +249,20 @@ wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct) if (bgindex != -1) r[bgindex] = g[bgindex] = b[bgindex] = 0; - Palette->Create(n, r, g, b); + m_palette->Create(n, r, g, b); ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR); return true ; -// return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0); +// return (DibSetUsage(lpbi, (HPALETTE) m_palette->GetHPALETTE(), WXIMA_COLORS ) != 0); } void wxPNGReader::NullData() { + if (lpbi) { + wxMacDestroyGWorld( lpbi ) ; + } + delete m_palette; lpbi = NULL; - Palette = NULL; + m_palette = NULL; } wxBitmap* wxPNGReader::GetBitmap(void) @@ -273,8 +285,8 @@ bool wxPNGReader::InstantiateBitmap(wxBitmap *bitmap) bitmap->SetWidth(GetWidth()); bitmap->SetHeight(GetHeight()); bitmap->SetDepth(GetDepth()); - if ( GetDepth() > 1 && Palette ) - bitmap->SetPalette(*Palette); + if ( GetDepth() > 1 && m_palette ) + bitmap->SetPalette(*m_palette); bitmap->SetOk(TRUE); @@ -305,9 +317,9 @@ bool wxPNGReader::InstantiateBitmap(wxBitmap *bitmap) ReleaseDC(NULL, dc2); HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, tmpBitmap); - if ( Palette ) + if ( m_palette ) { - HPALETTE oldPal = ::SelectPalette(dc, (HPALETTE) Palette->GetHPALETTE(), FALSE); + HPALETTE oldPal = ::SelectPalette(dc, (HPALETTE) m_palette->GetHPALETTE(), FALSE); ::RealizePalette(dc); } @@ -325,8 +337,8 @@ bool wxPNGReader::InstantiateBitmap(wxBitmap *bitmap) bitmap->SetWidth(GetWidth()); bitmap->SetHeight(GetHeight()); bitmap->SetDepth(GetDepth()); - if ( GetDepth() > 1 && Palette ) - bitmap->SetPalette(*Palette); + if ( GetDepth() > 1 && m_palette ) + bitmap->SetPalette(*m_palette); bitmap->SetOk(TRUE); @@ -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); } } @@ -793,7 +823,7 @@ bool wxPNGReader::SaveXPM(char *filename, char *name) if ( !GetPalette() ) return FALSE; - ofstream str(filename); + wxSTD ofstream str(filename); if ( str.bad() ) return FALSE; @@ -857,7 +887,7 @@ bool wxPNGFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long fla return FALSE; } -bool wxPNGFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *pal) +bool wxPNGFileHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *pal) { return FALSE; }