]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/image.cpp
fix warnings about parameters shadowing member variables
[wxWidgets.git] / src / common / image.cpp
index be43304ba96464fd14a550bdf7d67056c8526570..92bbdde513e35aa9b79f661b82216eaf62e860cc 100644 (file)
 #define HAS_FILE_STREAMS (wxUSE_STREAMS && (wxUSE_FILE || wxUSE_FFILE))
 
 #if HAS_FILE_STREAMS
-    #if wxUSE_FILE
-        typedef wxFileInputStream wxImageFileInputStream;
-        typedef wxFileOutputStream wxImageFileOutputStream;
-    #elif wxUSE_FFILE
+    #if wxUSE_FFILE
         typedef wxFFileInputStream wxImageFileInputStream;
         typedef wxFFileOutputStream wxImageFileOutputStream;
+    #elif wxUSE_FILE
+        typedef wxFileInputStream wxImageFileInputStream;
+        typedef wxFileOutputStream wxImageFileOutputStream;
     #endif // wxUSE_FILE/wxUSE_FFILE
 #endif // HAS_FILE_STREAMS
 
@@ -675,13 +675,13 @@ wxImage wxImage::ResampleBicubic(int width, int height) const
     for ( int dsty = 0; dsty < height; dsty++ )
     {
         // We need to calculate the source pixel to interpolate from - Y-axis
-        double srcpixy = dsty * M_IMGDATA->m_height / height;
+        double srcpixy = double(dsty * M_IMGDATA->m_height) / height;
         double dy = srcpixy - (int)srcpixy;
 
         for ( int dstx = 0; dstx < width; dstx++ )
         {
             // X-axis of pixel to interpolate from
-            double srcpixx = dstx * M_IMGDATA->m_width / width;
+            double srcpixx = double(dstx * M_IMGDATA->m_width) / width;
             double dx = srcpixx - (int)srcpixx;
 
             // Sums for each color channel
@@ -754,20 +754,17 @@ wxImage wxImage::BlurHorizontal(int blurRadius)
     unsigned char* dst_alpha = NULL;
 
     // Check for a mask or alpha
-    if ( M_IMGDATA->m_hasMask )
+    if ( src_alpha )
+    {
+        ret_image.SetAlpha();
+        dst_alpha = ret_image.GetAlpha();
+    }
+    else if ( M_IMGDATA->m_hasMask )
     {
         ret_image.SetMaskColour(M_IMGDATA->m_maskRed,
                                 M_IMGDATA->m_maskGreen,
                                 M_IMGDATA->m_maskBlue);
     }
-    else
-    {
-        if ( src_alpha )
-        {
-            ret_image.SetAlpha();
-            dst_alpha = ret_image.GetAlpha();
-        }
-    }
 
     // number of pixels we average over
     const int blurArea = blurRadius*2 + 1;
@@ -872,20 +869,17 @@ wxImage wxImage::BlurVertical(int blurRadius)
     unsigned char* dst_alpha = NULL;
 
     // Check for a mask or alpha
-    if ( M_IMGDATA->m_hasMask )
+    if ( src_alpha )
+    {
+        ret_image.SetAlpha();
+        dst_alpha = ret_image.GetAlpha();
+    }
+    else if ( M_IMGDATA->m_hasMask )
     {
         ret_image.SetMaskColour(M_IMGDATA->m_maskRed,
                                 M_IMGDATA->m_maskGreen,
                                 M_IMGDATA->m_maskBlue);
     }
-    else
-    {
-        if ( src_alpha )
-        {
-            ret_image.SetAlpha();
-            dst_alpha = ret_image.GetAlpha();
-        }
-    }
 
     // number of pixels we average over
     const int blurArea = blurRadius*2 + 1;
@@ -1671,7 +1665,9 @@ void wxImage::SetAlpha( unsigned char *alpha, bool static_data )
         alpha = (unsigned char *)malloc(M_IMGDATA->m_width*M_IMGDATA->m_height);
     }
 
-    free(M_IMGDATA->m_alpha);
+    if( !M_IMGDATA->m_staticAlpha )
+        free(M_IMGDATA->m_alpha);
+
     M_IMGDATA->m_alpha = alpha;
     M_IMGDATA->m_staticAlpha = static_data;
 }
@@ -1904,8 +1900,11 @@ bool wxImage::ConvertAlphaToMask(unsigned char threshold)
         }
     }
 
-    free(M_IMGDATA->m_alpha);
+    if( !M_IMGDATA->m_staticAlpha )
+        free(M_IMGDATA->m_alpha);
+
     M_IMGDATA->m_alpha = NULL;
+    M_IMGDATA->m_staticAlpha = false;
 
     return true;
 }
@@ -2237,7 +2236,7 @@ bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int ind
 
     if (stream.IsSeekable() && !handler->CanRead(stream))
     {
-        wxLogError(_("Image file is not of type %s."), (const wxChar*) mimetype);
+        wxLogError(_("Image file is not of type %s."), mimetype);
         return false;
     }
     else
@@ -2651,6 +2650,42 @@ bool wxImageHandler::CallDoCanRead(wxInputStream& stream)
 
 #endif // wxUSE_STREAMS
 
+/* static */
+wxImageResolution
+wxImageHandler::GetResolutionFromOptions(const wxImage& image, int *x, int *y)
+{
+    wxCHECK_MSG( x && y, wxIMAGE_RESOLUTION_NONE, _T("NULL pointer") );
+
+    if ( image.HasOption(wxIMAGE_OPTION_RESOLUTIONX) &&
+         image.HasOption(wxIMAGE_OPTION_RESOLUTIONY) )
+    {
+        *x = image.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX);
+        *y = image.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY);
+    }
+    else if ( image.HasOption(wxIMAGE_OPTION_RESOLUTION) )
+    {
+        *x =
+        *y = image.GetOptionInt(wxIMAGE_OPTION_RESOLUTION);
+    }
+    else // no resolution options specified
+    {
+        *x =
+        *y = 0;
+
+        return wxIMAGE_RESOLUTION_NONE;
+    }
+
+    // get the resolution unit too
+    int resUnit = image.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONUNIT);
+    if ( !resUnit )
+    {
+        // this is the default
+        resUnit = wxIMAGE_RESOLUTION_INCHES;
+    }
+
+    return (wxImageResolution)resUnit;
+}
+
 // ----------------------------------------------------------------------------
 // image histogram stuff
 // ----------------------------------------------------------------------------
@@ -3095,8 +3130,8 @@ class wxImageModule: public wxModule
 DECLARE_DYNAMIC_CLASS(wxImageModule)
 public:
     wxImageModule() {}
-    bool OnInit() { wxImage::InitStandardHandlers(); return true; };
-    void OnExit() { wxImage::CleanUpHandlers(); };
+    bool OnInit() { wxImage::InitStandardHandlers(); return true; }
+    void OnExit() { wxImage::CleanUpHandlers(); }
 };
 
 IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule)