]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 730686 ] wxImage::Scale speed improvements
authorJulian Smart <julian@anthemion.co.uk>
Sat, 3 May 2003 15:06:07 +0000 (15:06 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sat, 3 May 2003 15:06:07 +0000 (15:06 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20453 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/image.tex
include/wx/image.h
src/common/image.cpp

index 7b3837ca628597934c4454b23bc645c39b75905c..77cc3231c7e55797521184307ec03a00f5006c9f 100644 (file)
@@ -93,9 +93,10 @@ instead.) Constructs an image from a platform-dependent bitmap. This preserves
 mask information so that bitmaps and images can be converted back
 and forth without loss in that respect.
 
 mask information so that bitmaps and images can be converted back
 and forth without loss in that respect.
 
-\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}}
+\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{bool}{ clear=true}}
 
 
-Creates an image with the given width and height.
+Creates an image with the given width and height.  If {\it clear} is true, the new image will be initialized to black.
+Otherwise, the image data will be uninitialized.
 
 \func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{unsigned char*}{ data}, \param{bool}{ static\_data=false}}
 
 
 \func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{unsigned char*}{ data}, \param{bool}{ static\_data=false}}
 
@@ -275,9 +276,10 @@ Returns an identical copy of the image.
 
 \membersection{wxImage::Create}\label{wximagecreate}
 
 
 \membersection{wxImage::Create}\label{wximagecreate}
 
-\func{bool}{Create}{\param{int}{ width}, \param{int}{ height}}
+\func{bool}{Create}{\param{int}{ width}, \param{int}{ height}, \param{bool}{ clear=true}}
 
 
-Creates a fresh image.
+Creates a fresh image.  If {\it clear} is true, the new image will be initialized to black.
+Otherwise, the image data will be uninitialized.
 
 \wxheading{Parameters}
 
 
 \wxheading{Parameters}
 
index bc19ddd607f9c6fd78c52b2283ac6461071293f3..62e50e8cd19cc9b0874f55d50cce97b906065eee 100644 (file)
@@ -140,7 +140,7 @@ class WXDLLEXPORT wxImage: public wxObject
 {
 public:
     wxImage();
 {
 public:
     wxImage();
-    wxImage( int width, int height );
+    wxImage( int width, int height, bool clear = true );
     wxImage( int width, int height, unsigned char* data, bool static_data = FALSE );
     wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
     wxImage( const wxString& name, const wxString& mimetype, int index = -1 );
     wxImage( int width, int height, unsigned char* data, bool static_data = FALSE );
     wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
     wxImage( const wxString& name, const wxString& mimetype, int index = -1 );
@@ -162,7 +162,7 @@ public:
 #endif
 #endif
 
 #endif
 #endif
 
-    void Create( int width, int height );
+    void Create( int width, int height, bool clear = true );
     void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
     void Destroy();
 
     void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
     void Destroy();
 
index aa19e4ea35089200e9dd5c067e8bde3083c5831e..289eb7875980949967ba65842e51449728a05418 100644 (file)
@@ -113,9 +113,9 @@ wxImage::wxImage()
 {
 }
 
 {
 }
 
-wxImage::wxImage( int width, int height )
+wxImage::wxImage( int width, int height, bool clear )
 {
 {
-    Create( width, height );
+    Create( width, height, clear );
 }
 
 wxImage::wxImage( int width, int height, unsigned char* data, bool static_data )
 }
 
 wxImage::wxImage( int width, int height, unsigned char* data, bool static_data )
@@ -156,7 +156,7 @@ wxImage::wxImage( const wxImage* image )
     if (image) Ref(*image);
 }
 
     if (image) Ref(*image);
 }
 
-void wxImage::Create( int width, int height )
+void wxImage::Create( int width, int height, bool clear )
 {
     UnRef();
 
 {
     UnRef();
 
@@ -165,7 +165,7 @@ void wxImage::Create( int width, int height )
     M_IMGDATA->m_data = (unsigned char *) malloc( width*height*3 );
     if (M_IMGDATA->m_data)
     {
     M_IMGDATA->m_data = (unsigned char *) malloc( width*height*3 );
     if (M_IMGDATA->m_data)
     {
-        for (int l = 0; l < width*height*3; l++) M_IMGDATA->m_data[l] = 0;
+        if (clear) memset(M_IMGDATA->m_data, 0, width*height*3);
 
         M_IMGDATA->m_width = width;
         M_IMGDATA->m_height = height;
 
         M_IMGDATA->m_width = width;
         M_IMGDATA->m_height = height;
@@ -208,7 +208,7 @@ wxImage wxImage::Copy() const
 
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
 
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
-    image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height );
+    image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
 
     unsigned char *data = image.GetData();
 
 
     unsigned char *data = image.GetData();
 
@@ -244,7 +244,7 @@ wxImage wxImage::ShrinkBy( int xFactor , int yFactor ) const
     long width = old_width / xFactor ;
     long height = old_height / yFactor ;
 
     long width = old_width / xFactor ;
     long height = old_height / yFactor ;
 
-    image.Create( width , height );
+    image.Create( width, height, false );
 
     char unsigned *data = image.GetData();
 
 
     char unsigned *data = image.GetData();
 
@@ -341,7 +341,7 @@ wxImage wxImage::Scale( int width, int height ) const
     {
         return ShrinkBy( old_width / width , old_height / height ) ;
     }
     {
         return ShrinkBy( old_width / width , old_height / height ) ;
     }
-    image.Create( width, height );
+    image.Create( width, height, false );
 
     unsigned char *data = image.GetData();
 
 
     unsigned char *data = image.GetData();
 
@@ -357,43 +357,29 @@ wxImage wxImage::Scale( int width, int height ) const
     unsigned char *source_data = M_IMGDATA->m_data;
     unsigned char *target_data = data;
 
     unsigned char *source_data = M_IMGDATA->m_data;
     unsigned char *target_data = data;
 
-#if 0
-    // This is nonsense, RR.
-
-    // We do (x, y) -> (x, y)*oldSize/newSize but the valid values of x and y
-    // are from 0 to size-1, hence all decrement the sizes
-    long old_old_width = old_width;
-    old_height--;
-    old_width--;
-    height--;
-    width--;
-    for ( long j = 0; j <= height; j++ )
-    {
-        // don't crash for images with height == 1
-        long y_offset = height ? (j * old_height / height)* old_old_width : 0;
+    long x_delta = (old_width<<16) / width;
+    long y_delta = (old_height<<16) / height;
 
 
-        for ( long i = 0; i <= width; i++ )
-        {
-            long x_offset = width ? (i * old_width) / width : 0;
+    unsigned char* dest_pixel = target_data;
 
 
-            memcpy( target_data, source_data + 3*(y_offset + x_offset), 3 );
-            target_data += 3;
-        }
-    }
-#else
-    for (long j = 0; j < height; j++)
-    {
-        long y_offset = (j * old_height / height) * old_width;
+    long y = 0;
+    for ( long j = 0; j < height; j++ )
+        {
+        unsigned char* src_line = &source_data[(y>>16)*old_width*3];
 
 
-        for (long i = 0; i < width; i++)
+        long x = 0;
+        for ( long i = 0; i < width; i++ )
         {
         {
-            memcpy( target_data,
-                source_data + 3*(y_offset + ((i * old_width )/ width)),
-                3 );
-            target_data += 3;
+             unsigned char* src_pixel = &src_line[(x>>16)*3];
+             dest_pixel[0] = src_pixel[0];
+             dest_pixel[1] = src_pixel[1];
+             dest_pixel[2] = src_pixel[2];
+             dest_pixel += 3;
+             x += x_delta;
         }
         }
+
+        y += y_delta;
     }
     }
-#endif
 
     // In case this is a cursor, make sure the hotspot is scalled accordingly:
     if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
 
     // In case this is a cursor, make sure the hotspot is scalled accordingly:
     if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
@@ -412,7 +398,7 @@ wxImage wxImage::Rotate90( bool clockwise ) const
 
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
 
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
-    image.Create( M_IMGDATA->m_height, M_IMGDATA->m_width );
+    image.Create( M_IMGDATA->m_height, M_IMGDATA->m_width, false );
 
     unsigned char *data = image.GetData();
 
 
     unsigned char *data = image.GetData();
 
@@ -449,7 +435,7 @@ wxImage wxImage::Mirror( bool horizontally ) const
 
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
 
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
-    image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height );
+    image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
 
     unsigned char *data = image.GetData();
 
 
     unsigned char *data = image.GetData();
 
@@ -503,7 +489,7 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
     int subwidth=rect.GetWidth();
     const int subheight=rect.GetHeight();
 
     int subwidth=rect.GetWidth();
     const int subheight=rect.GetHeight();
 
-    image.Create( subwidth, subheight );
+    image.Create( subwidth, subheight, false );
 
     unsigned char *subdata = image.GetData(), *data=GetData();
 
 
     unsigned char *subdata = image.GetData(), *data=GetData();
 
@@ -637,7 +623,7 @@ wxImage wxImage::ConvertToMono( unsigned char r, unsigned char g, unsigned char
 
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
 
     wxCHECK_MSG( Ok(), image, wxT("invalid image") );
 
-    image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height );
+    image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
 
     unsigned char *data = image.GetData();
 
 
     unsigned char *data = image.GetData();
 
@@ -1405,6 +1391,7 @@ void wxImage::CleanUpHandlers()
     }
 }
 
     }
 }
 
+
 //-----------------------------------------------------------------------------
 // wxImageHandler
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // wxImageHandler
 //-----------------------------------------------------------------------------
@@ -1690,7 +1677,7 @@ wxImage wxImage::Rotate(double angle, const wxPoint & centre_of_rotation, bool i
     int x2 = (int) ceil (wxMax (wxMax(p1.x, p2.x), wxMax(p3.x, p4.x)));
     int y2 = (int) ceil (wxMax (wxMax(p1.y, p2.y), wxMax(p3.y, p4.y)));
 
     int x2 = (int) ceil (wxMax (wxMax(p1.x, p2.x), wxMax(p3.x, p4.x)));
     int y2 = (int) ceil (wxMax (wxMax(p1.y, p2.y), wxMax(p3.y, p4.y)));
 
-    wxImage rotated (x2 - x1 + 1, y2 - y1 + 1);
+    wxImage rotated (x2 - x1 + 1, y2 - y1 + 1, false);
 
     if (offset_after_rotation != NULL)
     {
 
     if (offset_after_rotation != NULL)
     {