]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/image.cpp
Include wx/colour.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / common / image.cpp
index 9cac98dcbdd9c020231704bbfba3460631d98500..8711e3d1cd47ae69f068b917f5b44731594ee09f 100644 (file)
     #pragma hdrstop
 #endif
 
-#include "wx/defs.h"
-
 #if wxUSE_IMAGE
 
 #include "wx/image.h"
-#include "wx/bitmap.h"
-#include "wx/debug.h"
-#include "wx/log.h"
-#include "wx/app.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/log.h"
+    #include "wx/app.h"
+    #include "wx/hash.h"
+    #include "wx/utils.h"
+    #include "wx/bitmap.h"
+#endif
+
 #include "wx/filefn.h"
 #include "wx/wfstream.h"
 #include "wx/intl.h"
 #include "wx/module.h"
-#include "wx/hash.h"
-#include "wx/utils.h"
 #include "wx/math.h"
 
 #if wxUSE_XPM
-#include "wx/xpmdecod.h"
+    #include "wx/xpmdecod.h"
 #endif
 
 // For memcpy
@@ -707,6 +708,10 @@ wxImage wxImage::Size( const wxSize& size, const wxPoint& pos,
 
     wxRect subRect(pos.x, pos.y, width, height);
     wxRect finalRect(0, 0, size.GetWidth(), size.GetHeight());
+    if (pos.x < 0)
+        finalRect.width -= pos.x;
+    if (pos.y < 0)
+        finalRect.height -= pos.y;
 
     subRect.Intersect(finalRect);
 
@@ -862,6 +867,16 @@ wxImage wxImage::ConvertToGreyscale( double lr, double lg, double lb ) const
         }
     }
 
+    // copy the alpha channel, if any
+    if (HasAlpha())
+    {
+        const size_t alphaSize = GetWidth() * GetHeight();
+        unsigned char *alpha = (unsigned char*)malloc(alphaSize);
+        memcpy(alpha, GetAlpha(), alphaSize);
+        image.InitAlpha();
+        image.SetAlpha(alpha);
+    }
+
     return image;
 }
 
@@ -1445,7 +1460,9 @@ bool wxImage::HasOption(const wxString& name) const
 // image I/O
 // ----------------------------------------------------------------------------
 
-bool wxImage::LoadFile( const wxString& filename, long type, int index )
+bool wxImage::LoadFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename),
+                        long WXUNUSED_UNLESS_STREAMS(type),
+                        int WXUNUSED_UNLESS_STREAMS(index) )
 {
 #if wxUSE_STREAMS
     if (wxFileExists(filename))
@@ -1465,7 +1482,9 @@ bool wxImage::LoadFile( const wxString& filename, long type, int index )
 #endif // wxUSE_STREAMS
 }
 
-bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype, int index )
+bool wxImage::LoadFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename),
+                        const wxString& WXUNUSED_UNLESS_STREAMS(mimetype),
+                        int WXUNUSED_UNLESS_STREAMS(index) )
 {
 #if wxUSE_STREAMS
     if (wxFileExists(filename))
@@ -1503,7 +1522,8 @@ bool wxImage::SaveFile( const wxString& filename ) const
     return false;
 }
 
-bool wxImage::SaveFile( const wxString& filename, int type ) const
+bool wxImage::SaveFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename),
+                        int WXUNUSED_UNLESS_STREAMS(type) ) const
 {
 #if wxUSE_STREAMS
     wxCHECK_MSG( Ok(), false, wxT("invalid image") );
@@ -1522,7 +1542,8 @@ bool wxImage::SaveFile( const wxString& filename, int type ) const
     return false;
 }
 
-bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) const
+bool wxImage::SaveFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename),
+                        const wxString& WXUNUSED_UNLESS_STREAMS(mimetype) ) const
 {
 #if wxUSE_STREAMS
     wxCHECK_MSG( Ok(), false, wxT("invalid image") );
@@ -1541,22 +1562,23 @@ bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) con
     return false;
 }
 
-bool wxImage::CanRead( const wxString &name )
+bool wxImage::CanRead( const wxString& WXUNUSED_UNLESS_STREAMS(name) )
 {
 #if wxUSE_STREAMS
-  wxFileInputStream stream(name);
-  return CanRead(stream);
+    wxFileInputStream stream(name);
+    return CanRead(stream);
 #else
-  return false;
+    return false;
 #endif
 }
 
-int wxImage::GetImageCount( const wxString &name, long type )
+int wxImage::GetImageCount( const wxString& WXUNUSED_UNLESS_STREAMS(name),
+                            long WXUNUSED_UNLESS_STREAMS(type) )
 {
 #if wxUSE_STREAMS
-  wxFileInputStream stream(name);
-  if (stream.Ok())
-      return GetImageCount(stream, type);
+    wxFileInputStream stream(name);
+    if (stream.Ok())
+        return GetImageCount(stream, type);
 #endif
 
   return 0;