]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxIMAGE_OPTION_ORIGINAL_{WIDTH,HEIGHT} wxImage options.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 14 Nov 2011 13:35:48 +0000 (13:35 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 14 Nov 2011 13:35:48 +0000 (13:35 +0000)
These options allow to retrieve the original image size if the image was
scaled during load.

Closes #13662.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69759 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/image.h
interface/wx/image.h
samples/image/image.cpp
src/common/image.cpp
src/common/imagjpeg.cpp

index 5048f67c6743e749f21431713768fbee9858e924..71959ce5f5b25383f3929a9575d0411820c8fa7e 100644 (file)
@@ -490,6 +490,7 @@ All (GUI):
 - Add "checked" property for toolbar tool elements in XRC.
 - Allow customization of the locations where persistent settings are stored.
 - Restore support for reusing ids more than 254 times (Armel Asselin).
 - Add "checked" property for toolbar tool elements in XRC.
 - Allow customization of the locations where persistent settings are stored.
 - Restore support for reusing ids more than 254 times (Armel Asselin).
+- Added wxIMAGE_OPTION_ORIGINAL_{WIDTH,HEIGHT} (Catalin Raceanu).
 
 OSX:
 
 
 OSX:
 
index e9fb5c54694005d4fb7621610723e28bf0ff4f08..0122ed6f64625e71293d2c7b0f22cc00dfdaa285 100644 (file)
@@ -40,6 +40,9 @@
 #define wxIMAGE_OPTION_MAX_WIDTH             wxString(wxT("MaxWidth"))
 #define wxIMAGE_OPTION_MAX_HEIGHT            wxString(wxT("MaxHeight"))
 
 #define wxIMAGE_OPTION_MAX_WIDTH             wxString(wxT("MaxWidth"))
 #define wxIMAGE_OPTION_MAX_HEIGHT            wxString(wxT("MaxHeight"))
 
+#define wxIMAGE_OPTION_ORIGINAL_WIDTH        wxString(wxT("OriginalWidth"))
+#define wxIMAGE_OPTION_ORIGINAL_HEIGHT       wxString(wxT("OriginalHeight"))
+
 // constants used with wxIMAGE_OPTION_RESOLUTIONUNIT
 //
 // NB: don't change these values, they correspond to libjpeg constants
 // constants used with wxIMAGE_OPTION_RESOLUTIONUNIT
 //
 // NB: don't change these values, they correspond to libjpeg constants
index aa83b98a7fca7d4c32190007b1cb070de2bd8d65..11bc7e782e592c62d6a830cd059d8327d312b9b8 100644 (file)
@@ -86,6 +86,8 @@ enum wxImagePNGType
 #define wxIMAGE_OPTION_RESOLUTIONUNIT                   wxString(wxT("ResolutionUnit"))
 #define wxIMAGE_OPTION_MAX_WIDTH                        wxString(wxT("MaxWidth"))
 #define wxIMAGE_OPTION_MAX_HEIGHT                       wxString(wxT("MaxHeight"))
 #define wxIMAGE_OPTION_RESOLUTIONUNIT                   wxString(wxT("ResolutionUnit"))
 #define wxIMAGE_OPTION_MAX_WIDTH                        wxString(wxT("MaxWidth"))
 #define wxIMAGE_OPTION_MAX_HEIGHT                       wxString(wxT("MaxHeight"))
+#define wxIMAGE_OPTION_ORIGINAL_WIDTH                   wxString(wxT("OriginalWidth"))
+#define wxIMAGE_OPTION_ORIGINAL_HEIGHT                  wxString(wxT("OriginalHeight"))
 
 #define wxIMAGE_OPTION_BMP_FORMAT                       wxString(wxT("wxBMP_FORMAT"))
 #define wxIMAGE_OPTION_CUR_HOTSPOT_X                    wxString(wxT("HotSpotX"))
 
 #define wxIMAGE_OPTION_BMP_FORMAT                       wxString(wxT("wxBMP_FORMAT"))
 #define wxIMAGE_OPTION_CUR_HOTSPOT_X                    wxString(wxT("HotSpotX"))
@@ -1182,6 +1184,12 @@ public:
             handler, this is still what happens however). These options must be
             set before calling LoadFile() to have any effect.
 
             handler, this is still what happens however). These options must be
             set before calling LoadFile() to have any effect.
 
+        @li @c wxIMAGE_OPTION_ORIGINAL_WIDTH and @c wxIMAGE_OPTION_ORIGINAL_HEIGHT:
+            These options will return the original size of the image if either
+            @c wxIMAGE_OPTION_MAX_WIDTH or @c wxIMAGE_OPTION_MAX_HEIGHT is
+            specified.
+            @since 2.9.3
+
         @li @c wxIMAGE_OPTION_QUALITY: JPEG quality used when saving. This is an
             integer in 0..100 range with 0 meaning very poor and 100 excellent
             (but very badly compressed). This option is currently ignored for
         @li @c wxIMAGE_OPTION_QUALITY: JPEG quality used when saving. This is an
             integer in 0..100 range with 0 meaning very poor and 100 excellent
             (but very badly compressed). This option is currently ignored for
index 5daf5736b6cf8b29aceaed2f184a7c3d6293be7b..9002c5b84f1032e24260f1b59a45184260c9ab24 100644 (file)
@@ -944,10 +944,14 @@ void MyFrame::OnThumbnail( wxCommandEvent &WXUNUSED(event) )
         return;
     }
 
         return;
     }
 
+    int origWidth = image.GetOptionInt( wxIMAGE_OPTION_ORIGINAL_WIDTH );
+    int origHeight = image.GetOptionInt( wxIMAGE_OPTION_ORIGINAL_HEIGHT );
+
     const long loadTime = sw.Time();
 
     MyImageFrame * const frame = new MyImageFrame(this, filename, image);
     const long loadTime = sw.Time();
 
     MyImageFrame * const frame = new MyImageFrame(this, filename, image);
-    wxLogStatus(frame, "Loaded \"%s\" in %ldms", filename, loadTime);
+    wxLogStatus(frame, "Loaded \"%s\" in %ldms; original size was (%d, %d)",
+                filename, loadTime, origWidth, origHeight);
 #else
     wxLogError( wxT("Couldn't create file selector dialog") );
     return;
 #else
     wxLogError( wxT("Couldn't create file selector dialog") );
     return;
index 0cb1adf7886f143d508fd58617e1b0260fbb89fa..ebb8931854b6ee6b068e76cd696ab786efcd9ef2 100644 (file)
@@ -2450,7 +2450,17 @@ bool wxImage::DoLoad(wxImageHandler& handler, wxInputStream& stream, int index)
         }
 
         if ( width != widthOrig || height != heightOrig )
         }
 
         if ( width != widthOrig || height != heightOrig )
+        {
+            // get the original size if it was set by the image handler
+            // but also in order to restore it after Rescale
+            int widthOrigOption = GetOptionInt(wxIMAGE_OPTION_ORIGINAL_WIDTH),
+                heightOrigOption = GetOptionInt(wxIMAGE_OPTION_ORIGINAL_HEIGHT);
+
             Rescale(width, height, wxIMAGE_QUALITY_HIGH);
             Rescale(width, height, wxIMAGE_QUALITY_HIGH);
+
+            SetOption(wxIMAGE_OPTION_ORIGINAL_WIDTH, widthOrigOption ? widthOrigOption : widthOrig);
+            SetOption(wxIMAGE_OPTION_ORIGINAL_HEIGHT, heightOrigOption ? heightOrigOption : heightOrig);
+        }
     }
 
     // Set this after Rescale, which currently does not preserve it
     }
 
     // Set this after Rescale, which currently does not preserve it
index 2a24dce9902edd7ab37b245a52e69adc5d5fbeef..88bcb4f313d4cdd54a4f2cfb8d1141ea8b003639 100644 (file)
@@ -334,6 +334,13 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos
         image->SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, cinfo.density_unit);
     }
 
         image->SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, cinfo.density_unit);
     }
 
+    if ( cinfo.image_width != cinfo.output_width || cinfo.image_height != cinfo.output_height )
+    {
+        // save the original image size
+        image->SetOption(wxIMAGE_OPTION_ORIGINAL_WIDTH, cinfo.image_width);
+        image->SetOption(wxIMAGE_OPTION_ORIGINAL_HEIGHT, cinfo.image_height);
+    }
+
     jpeg_finish_decompress( &cinfo );
     jpeg_destroy_decompress( &cinfo );
     return true;
     jpeg_finish_decompress( &cinfo );
     jpeg_destroy_decompress( &cinfo );
     return true;