X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce4169a4d129fc6cd165b2e9ccc5cf5d48356020..40d4abbc708eb214e48566091f85ba6e3d50c93f:/src/common/image.cpp?ds=sidebyside diff --git a/src/common/image.cpp b/src/common/image.cpp index 91fc0fb9be..18d73f4668 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -15,7 +15,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #include "wx/image.h" @@ -32,13 +32,11 @@ #include #ifdef __SALFORDC__ -#ifdef FAR -#undef FAR -#endif + #undef FAR #endif #ifdef __WXMSW__ -#include + #include "wx/msw/private.h" #endif //----------------------------------------------------------------------------- @@ -49,8 +47,8 @@ class wxImageRefData: public wxObjectRefData { public: - wxImageRefData(void); - ~wxImageRefData(void); + wxImageRefData(); + ~wxImageRefData(); int m_width; int m_height; @@ -60,7 +58,7 @@ public: bool m_ok; }; -wxImageRefData::wxImageRefData(void) +wxImageRefData::wxImageRefData() { m_width = 0; m_height = 0; @@ -72,7 +70,7 @@ wxImageRefData::wxImageRefData(void) m_hasMask = FALSE; } -wxImageRefData::~wxImageRefData(void) +wxImageRefData::~wxImageRefData() { if (m_data) free( m_data ); } @@ -84,7 +82,7 @@ wxList wxImage::sm_handlers; #define M_IMGDATA ((wxImageRefData *)m_refData) #if !USE_SHARED_LIBRARIES -IMPLEMENT_DYNAMIC_CLASS(wxImage, wxObject) + IMPLEMENT_DYNAMIC_CLASS(wxImage, wxObject) #endif wxImage::wxImage() @@ -152,7 +150,7 @@ void wxImage::Destroy() UnRef(); } -wxImage wxImage::Scale( int width, int height ) +wxImage wxImage::Scale( int width, int height ) const { wxImage image; @@ -584,6 +582,9 @@ bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSE wxBitmap wxImage::ConvertToBitmap() const { + if ( !Ok() ) + return wxNullBitmap; + // sizeLimit is the MS upper limit for the DIB size int sizeLimit = 1024*768*3; @@ -594,11 +595,11 @@ wxBitmap wxImage::ConvertToBitmap() const // calc the number of bytes per scanline and padding int bytePerLine = width*3; int sizeDWORD = sizeof( DWORD ); - div_t lineBoundary = div( bytePerLine, sizeDWORD ); + int lineBoundary = bytePerLine % sizeDWORD; int padding = 0; - if( lineBoundary.rem > 0 ) + if( lineBoundary > 0 ) { - padding = sizeDWORD - lineBoundary.rem; + padding = sizeDWORD - lineBoundary; bytePerLine += padding; } // calc the number of DIBs and heights of DIBs @@ -609,9 +610,8 @@ wxBitmap wxImage::ConvertToBitmap() const height = bmpHeight; else { - div_t result = div( bmpHeight, height ); - numDIB = result.quot; - hRemain = result.rem; + numDIB = bmpHeight / height; + hRemain = bmpHeight % height; if( hRemain >0 ) numDIB++; } @@ -807,11 +807,11 @@ wxImage::wxImage( const wxBitmap &bitmap ) // calc the number of bytes per scanline and padding in the DIB int bytePerLine = width*3; int sizeDWORD = sizeof( DWORD ); - div_t lineBoundary = div( bytePerLine, sizeDWORD ); + int lineBoundary = bytePerLine % sizeDWORD; int padding = 0; - if( lineBoundary.rem > 0 ) + if( lineBoundary > 0 ) { - padding = sizeDWORD - lineBoundary.rem; + padding = sizeDWORD - lineBoundary; bytePerLine += padding; } @@ -946,7 +946,7 @@ wxBitmap wxImage::ConvertToBitmap() const // Retrieve depth GdkVisual *visual = gdk_window_get_visual( bitmap.GetPixmap() ); - if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent ); + if (visual == NULL) visual = gdk_visual_get_system(); int bpp = visual->depth; bitmap.SetDepth( bpp ); @@ -1181,7 +1181,8 @@ wxImage::wxImage( const wxBitmap &bitmap ) { for (int i = 0; i < bitmap.GetWidth(); i++) { - int pixel = gdk_image_get_pixel( gdk_image, i, j ); + wxInt32 pixel = gdk_image_get_pixel( gdk_image, i, j ); + pixel = wxINT32_SWAP_ON_BE( pixel ); if (bpp <= 8) { data[pos] = cmap->colors[pixel].red >> 8; @@ -1487,7 +1488,7 @@ wxImage::wxImage( const wxBitmap &bitmap ) vi = XGetVisualInfo( dpy, VisualIDMask|VisualDepthMask, &vinfo_template, &nitem ); - wxCHECK_MSG( vi, wxNullBitmap, _T("no visual") ); + wxCHECK_RET( vi, _T("no visual") ); if ((bpp == 16) && (vi->red_mask != 0xf800)) bpp = 15;