]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/image.cpp
Made wxGTK compile and link again. Broke wxMSW a little.
[wxWidgets.git] / src / common / image.cpp
index 13a92da11a92a389ca210f94e4e04e644f3dbc9e..05344a678fc2f928c108393d1b2af8623b8988dd 100644 (file)
@@ -196,7 +196,7 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
     wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (rect.GetRight()<=GetWidth()) && (rect.GetBottom()<=GetHeight())
-                , image, wxT("invalid subimage size") );
+                 , image, wxT("invalid subimage size") );
 
     int subwidth=rect.GetWidth();
     const int subheight=rect.GetHeight();
@@ -213,14 +213,14 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
     const int subleft=3*rect.GetLeft();
     const int width=3*GetWidth();
     subwidth*=3;
-    
+
     data+=rect.GetTop()*width+subleft;
 
     for (long j = 0; j < subheight; ++j)
     {
         memcpy( subdata, data, subwidth);
         subdata+=subwidth;
-       data+=width;
+        data+=width;
     }
 
     return image;
@@ -310,9 +310,9 @@ void wxImage::SetData( char unsigned *data )
     newRefData->m_maskGreen = M_IMGDATA->m_maskGreen;
     newRefData->m_maskBlue = M_IMGDATA->m_maskBlue;
     newRefData->m_hasMask = M_IMGDATA->m_hasMask;
-    
+
     UnRef();
-    
+
     m_refData = newRefData;
 }
 
@@ -437,8 +437,32 @@ bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype )
         return FALSE;
 }
 
+bool wxImage::CanRead( const wxString &name )
+{
+#if wxUSE_STREAMS
+  wxFileInputStream stream(name);
+  return CanRead(stream);
+#else
+  return FALSE;
+#endif
+}
+
 #if wxUSE_STREAMS
 
+bool wxImage::CanRead( wxInputStream &stream )
+{
+  wxList &list=GetHandlers();
+  
+  for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
+    {  
+      wxImageHandler *handler=(wxImageHandler*)node->GetData();
+      if (handler->CanRead( stream ))
+       return TRUE;
+    }
+
+  return FALSE;
+}
+
 bool wxImage::LoadFile( wxInputStream& stream, long type )
 {
     UnRef();
@@ -449,18 +473,18 @@ bool wxImage::LoadFile( wxInputStream& stream, long type )
 
     if (type==wxBITMAP_TYPE_ANY)
     {
-       wxList &list=GetHandlers();
+        wxList &list=GetHandlers();
 
-       for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
-       {  
-           handler=(wxImageHandler*)node->GetData();
-        if (handler->CanRead( stream ))
-            return handler->LoadFile( this, stream );
+        for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
+        {
+             handler=(wxImageHandler*)node->GetData();
+             if (handler->CanRead( stream ))
+                 return handler->LoadFile( this, stream );
 
-       }
+        }
 
-       wxLogWarning( wxT("No handler found for this image.") );
-       return FALSE;
+        wxLogWarning( wxT("No handler found for this image.") );
+        return FALSE;
     }
 
     handler = FindHandler(type);
@@ -628,7 +652,7 @@ void wxImage::CleanUpHandlers()
 //-----------------------------------------------------------------------------
 
 #if !USE_SHARED_LIBRARIES
-IMPLEMENT_DYNAMIC_CLASS(wxImageHandler,wxObject)
+IMPLEMENT_ABSTRACT_CLASS(wxImageHandler,wxObject)
 #endif
 
 #if wxUSE_STREAMS
@@ -642,11 +666,6 @@ bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSE
     return FALSE;
 }
 
-bool wxImageHandler::CanRead( wxInputStream& WXUNUSED(stream) )
-{
-    return FALSE;
-}
-
 bool wxImageHandler::CanRead( const wxString& name )
 {
 #if wxUSE_STREAMS
@@ -801,7 +820,7 @@ wxBitmap wxImage::ConvertToBitmap() const
         //    HDC memdc = ::CreateCompatibleDC( hdc );
         //    ::SelectObject( memdc, hbitmap);
         //    ::SetDIBitsToDevice( memdc, 0, 0, width, height,
-        //         0, 0, 0, height, (void *)lpBits, lpDIBh, DIB_RGB_COLORS);
+        //            0, 0, 0, height, (void *)lpBits, lpDIBh, DIB_RGB_COLORS);
         //    ::SelectObject( memdc, 0 );
         //    ::DeleteDC( memdc );
     }
@@ -1060,25 +1079,25 @@ wxBitmap wxImage::ConvertToBitmap() const
     {
         static bool s_hasInitialized = FALSE;
 
-       if (!s_hasInitialized)
-       {
-           gdk_rgb_init();
-           s_hasInitialized = TRUE;
-       }
+        if (!s_hasInitialized)
+        {
+            gdk_rgb_init();
+            s_hasInitialized = TRUE;
+        }
 
         GdkGC *gc = gdk_gc_new( bitmap.GetPixmap() );
 
-       gdk_draw_rgb_image( bitmap.GetPixmap(),
-                           gc,
-                           0, 0,
-                           width, height,
-                           GDK_RGB_DITHER_NONE,
-                           GetData(),
-                           width*3 );
+        gdk_draw_rgb_image( bitmap.GetPixmap(),
+                            gc,
+                            0, 0,
+                            width, height,
+                            GDK_RGB_DITHER_NONE,
+                            GetData(),
+                            width*3 );
 
         gdk_gc_unref( gc );
 
-       return bitmap;
+        return bitmap;
     }
 
 #endif
@@ -1243,9 +1262,22 @@ wxImage::wxImage( const wxBitmap &bitmap )
 {
     wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") );
 
-    GdkImage *gdk_image = gdk_image_get( bitmap.GetPixmap(),
-        0, 0,
-        bitmap.GetWidth(), bitmap.GetHeight() );
+    GdkImage *gdk_image = (GdkImage*) NULL;
+    if (bitmap.GetPixmap())
+    {
+        gdk_image = gdk_image_get( bitmap.GetPixmap(),
+            0, 0,
+            bitmap.GetWidth(), bitmap.GetHeight() );
+    } else
+    if (bitmap.GetBitmap())
+    {
+        gdk_image = gdk_image_get( bitmap.GetBitmap(),
+            0, 0,
+            bitmap.GetWidth(), bitmap.GetHeight() );
+    } else
+    {
+        wxFAIL_MSG( wxT("Ill-formed bitmap") );
+    }
 
     wxCHECK_RET( gdk_image, wxT("couldn't create image") );
 
@@ -1269,7 +1301,12 @@ wxImage::wxImage( const wxBitmap &bitmap )
         SetMaskColour( 16, 16, 16 );  // anything unlikely and dividable
     }
 
-    GdkVisual *visual = gdk_window_get_visual( bitmap.GetPixmap() );
+    GdkVisual *visual = (GdkVisual*) NULL;
+    if (bitmap.GetPixmap())
+        visual = gdk_window_get_visual( bitmap.GetPixmap() );
+    else
+        visual = gdk_window_get_visual( bitmap.GetBitmap() );
+
     if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
     int bpp = visual->depth;
     if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
@@ -1282,7 +1319,7 @@ wxImage::wxImage( const wxBitmap &bitmap )
         for (int i = 0; i < bitmap.GetWidth(); i++)
         {
             wxInt32 pixel = gdk_image_get_pixel( gdk_image, i, j );
-           pixel = wxINT32_SWAP_ON_BE( pixel );
+            // pixel = wxINT32_SWAP_ON_BE( pixel );
             if (bpp <= 8)
             {
                 data[pos] = cmap->colors[pixel].red >> 8;