X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03e11df5470fd64d9d9a669d0b50b84c2d714736..bf60426831535738b1b784629f08e9dd00bf9ecc:/src/mac/carbon/pnghand.cpp?ds=inline diff --git a/src/mac/carbon/pnghand.cpp b/src/mac/carbon/pnghand.cpp index 6134439271..52b07f6e60 100644 --- a/src/mac/carbon/pnghand.cpp +++ b/src/mac/carbon/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,7 +31,7 @@ # include #endif -#ifndef __WXMAC_X__ +#ifndef __DARWIN__ # include #endif #include "wx/msgdlg.h" @@ -39,6 +39,7 @@ #include "wx/bitmap.h" #include "wx/mac/pnghand.h" #include "wx/mac/pngread.h" +#include "wx/mac/private.h" extern "C" { #include "png.h" @@ -79,7 +80,7 @@ wxPNGReader::wxPNGReader(void) lpbi = NULL; bgindex = -1; - Palette = 0; + m_palette = 0; imageOK = FALSE; } @@ -91,7 +92,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 @@ -99,7 +100,7 @@ wxPNGReader::wxPNGReader ( char* ImageFileName ) lpbi = NULL; bgindex = -1; - Palette = 0; + m_palette = 0; imageOK = ReadFile (ImageFileName); } @@ -109,14 +110,13 @@ 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; + delete m_palette; + m_palette = NULL; + delete[] RawImage; + RawImage = NULL; - if (lpbi) - { - wxMacDestroyGWorld( lpbi ) ; + if (lpbi) { + wxMacDestroyGWorld( (GWorldPtr) lpbi ) ; } lpbi = wxMacCreateGWorld( Width , Height , Depth); if (lpbi) @@ -133,11 +133,18 @@ wxPNGReader::Create(int width, int height, int depth, int colortype) wxPNGReader::~wxPNGReader ( ) { - delete[] RawImage ; - if (lpbi) { - wxMacDestroyGWorld( lpbi ) ; - } - delete Palette; + if (RawImage != NULL) { + delete[] RawImage ; + RawImage = NULL; + } + if (lpbi) { + wxMacDestroyGWorld( (GWorldPtr) lpbi ) ; + lpbi = NULL; + } + if (m_palette != NULL) { + delete m_palette; + m_palette = NULL; + } } @@ -154,10 +161,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; */ @@ -187,8 +194,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); @@ -202,37 +209,37 @@ bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b) bool wxPNGReader::SetPalette(wxPalette* colourmap) { - delete Palette ; + delete m_palette ; if (!colourmap) return FALSE; ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR); - Palette = new wxPalette( *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) { - delete Palette ; - 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) { - delete Palette ; - Palette = new wxPalette(); - if (!Palette) + delete m_palette ; + m_palette = new wxPalette(); + if (!m_palette) return FALSE; byte r[256], g[256], b[256]; @@ -249,20 +256,22 @@ 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 ) ; + wxMacDestroyGWorld( (GWorldPtr) lpbi ) ; + lpbi = NULL; + } + if (m_palette != NULL) { + delete m_palette; + m_palette = NULL; } - delete Palette; - lpbi = NULL; - Palette = NULL; } wxBitmap* wxPNGReader::GetBitmap(void) @@ -285,8 +294,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); @@ -317,9 +326,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); } @@ -337,8 +346,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); @@ -414,7 +423,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; @@ -430,7 +440,7 @@ bool wxPNGReader::ReadFile(char * ImageFileName) if (!info_ptr) { fclose(fp); - delete(png_ptr); + delete png_ptr; return FALSE; } /* set error handling */ @@ -438,8 +448,8 @@ bool wxPNGReader::ReadFile(char * ImageFileName) { png_read_destroy(png_ptr, info_ptr, (png_info *)0); fclose(fp); - delete(png_ptr); - delete(info_ptr); + delete png_ptr; + delete info_ptr; /* If we get here, we had a problem reading the file */ return FALSE; @@ -511,7 +521,7 @@ bool wxPNGReader::ReadFile(char * ImageFileName) GetGWorld( &origPort , &origDevice ) ; // ignore shapedc - SetGWorld( lpbi , NULL ) ; + SetGWorld( (GWorldPtr) lpbi , NULL ) ; do { // (unsigned char *)iter.GetRow(); @@ -528,7 +538,7 @@ bool wxPNGReader::ReadFile(char * ImageFileName) { if ( pixel_depth == 8 ) { - for ( int i = 0 ; i < info_ptr->width ; ++i ) + for ( size_t i = 0 ; i < info_ptr->width ; ++i ) { png_color_struct* color ; RGBColor col ; @@ -572,7 +582,7 @@ bool wxPNGReader::ReadFile(char * ImageFileName) } else { - for ( int i = 0 ; i < info_ptr->width ; ++i ) + for ( size_t i = 0 ; i < info_ptr->width ; ++i ) { png_color_struct* color ; RGBColor col ; @@ -591,7 +601,7 @@ bool wxPNGReader::ReadFile(char * ImageFileName) } else { - for ( int i = 0 ; i < info_ptr->width ; ++i ) + for ( size_t i = 0 ; i < info_ptr->width ; ++i ) { png_color_struct* color ; RGBColor col ; @@ -621,8 +631,8 @@ bool wxPNGReader::ReadFile(char * ImageFileName) png_read_destroy(png_ptr, info_ptr, (png_info *)0); /* free the structures */ - delete(png_ptr); - delete(info_ptr); + delete png_ptr; + delete info_ptr; /* close the file */ fclose(fp); @@ -661,7 +671,7 @@ bool wxPNGReader::SaveFile(char * ImageFileName) if (!info_ptr) { fclose(fp); - delete(png_ptr); + delete png_ptr; return FALSE; } @@ -670,8 +680,8 @@ bool wxPNGReader::SaveFile(char * ImageFileName) { png_write_destroy(png_ptr); fclose(fp); - delete(png_ptr); - delete(info_ptr); + delete png_ptr; + delete info_ptr; /* If we get here, we had a problem reading the file */ return FALSE; @@ -768,8 +778,8 @@ bool wxPNGReader::SaveFile(char * ImageFileName) delete[] (info_ptr->palette); /* free the structures */ - delete(png_ptr); - delete(info_ptr); + delete png_ptr; + delete info_ptr; /* close the file */ fclose(fp); @@ -822,7 +832,7 @@ bool wxPNGReader::SaveXPM(char *filename, char *name) if ( !GetPalette() ) return FALSE; - ofstream str(filename); + wxSTD ofstream str(filename); if ( str.bad() ) return FALSE; @@ -886,7 +896,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; }