]> git.saurik.com Git - wxWidgets.git/commitdiff
Added Set/Get/HasOption members and moved palette to ref data class.
authorJulian Smart <julian@anthemion.co.uk>
Sat, 29 Jul 2000 11:44:57 +0000 (11:44 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sat, 29 Jul 2000 11:44:57 +0000 (11:44 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7893 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

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

index 3b161649a9c0836e50b2a5b5319bc78c365644f3..f8efd1e7243ce44c35de1417c270244ae3f4a62b 100644 (file)
@@ -332,6 +332,45 @@ Gets the width of the image in pixels.
 
 Returns TRUE if there is a mask active, FALSE otherwise.
 
 
 Returns TRUE if there is a mask active, FALSE otherwise.
 
+\membersection{wxImage::GetOption}\label{wximagegetoption}
+
+\constfunc{wxString}{GetOption}{\param{const wxString\&}{ name}}
+
+Gets a user-defined option. The function is case-insensitive to {\it name}.
+
+For example, when saving as a JPEG file, the option {\bf quality} is
+used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
+
+\wxheading{See also}
+
+\helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
+\helpref{wxImage::GetOptionInt}{wximagegetoptionint},\rtfsp
+\helpref{wxImage::HasOption}{wximagehasoption}
+
+\membersection{wxImage::GetOptionInt}\label{wximagegetoptionint}
+
+\constfunc{int}{GetOptionInt}{\param{const wxString\&}{ name}}
+
+Gets a user-defined option as an integer. The function is case-insensitive to {\it name}.
+
+\wxheading{See also}
+
+\helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
+\helpref{wxImage::GetOption}{wximagegetoption},\rtfsp
+\helpref{wxImage::HasOption}{wximagehasoption}
+
+\membersection{wxImage::HasOption}\label{wximagehasoption}
+
+\constfunc{bool}{HasOption}{\param{const wxString\&}{ name}}
+
+Returns TRUE if the given option is present. The function is case-insensitive to {\it name}.
+
+\wxheading{See also}
+
+\helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
+\helpref{wxImage::GetOption}{wximagegetoption},\rtfsp
+\helpref{wxImage::GetOptionInt}{wximagegetoptionint}
+
 \membersection{wxImage::InitStandardHandlers}
 
 \func{static void}{InitStandardHandlers}{\void}
 \membersection{wxImage::InitStandardHandlers}
 
 \func{static void}{InitStandardHandlers}{\void}
@@ -597,6 +636,23 @@ Specifies whether there is a mask or not. The area of the mask is determined by
 
 Sets the mask colour for this image (and tells the image to use the mask).
 
 
 Sets the mask colour for this image (and tells the image to use the mask).
 
+\membersection{wxImage::SetOption}\label{wximagesetoption}
+
+\func{void}{SetOption}{\param{const wxString\&}{ name}, \param{const wxString\&}{ value}}
+
+\func{void}{SetOption}{\param{const wxString\&}{ name}, \param{int}{ value}}
+
+Sets a user-defined option. The function is case-insensitive to {\it name}.
+
+For example, when saving as a JPEG file, the option {\bf quality} is
+used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
+
+\wxheading{See also}
+
+\helpref{wxImage::GetOption}{wximagegetoption},\rtfsp
+\helpref{wxImage::GetOptionInt}{wximagegetoptionint},\rtfsp
+\helpref{wxImage::HasOption}{wximagehasoption}
+
 \membersection{wxImage::SetRGB}\label{wximagesetrgb}
 
 \func{void}{SetRGB}{\param{int }{x}, \param{int }{y}, \param{unsigned char }{red}, \param{unsigned char }{green}, \param{unsigned char }{blue}}
 \membersection{wxImage::SetRGB}\label{wximagesetrgb}
 
 \func{void}{SetRGB}{\param{int }{x}, \param{int }{y}, \param{unsigned char }{red}, \param{unsigned char }{green}, \param{unsigned char }{blue}}
index af2bd95b709037162cf41dd3ca17e811ddc23305..7e872e39118a630c193ecd9259e1f28cdfcd48f9 100644 (file)
@@ -169,7 +169,8 @@ public:
     char unsigned *GetData() const;
     void SetData( char unsigned *data );
     void SetData( char unsigned *data, int new_width, int new_height );
     char unsigned *GetData() const;
     void SetData( char unsigned *data );
     void SetData( char unsigned *data, int new_width, int new_height );
-    
+
+    // Mask functions
     void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
     unsigned char GetMaskRed() const;
     unsigned char GetMaskGreen() const;
     void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
     unsigned char GetMaskRed() const;
     unsigned char GetMaskGreen() const;
@@ -177,9 +178,17 @@ public:
     void SetMask( bool mask = TRUE );
     bool HasMask() const;
 
     void SetMask( bool mask = TRUE );
     bool HasMask() const;
 
-    bool HasPalette() const { return m_palette.Ok(); }
-    const wxPalette& GetPalette() const { return m_palette; }
-    void SetPalette(const wxPalette& palette) { m_palette = palette; }
+    // Palette functions
+    bool HasPalette() const;
+    const wxPalette& GetPalette() const;
+    void SetPalette(const wxPalette& palette);
+
+    // Option functions (arbitrary name/value mapping)
+    void SetOption(const wxString& name, const wxString& value);
+    void SetOption(const wxString& name, int value);
+    wxString GetOption(const wxString& name) const;
+    int GetOptionInt(const wxString& name) const;
+    bool HasOption(const wxString& name) const;
 
     unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
     unsigned long ComputeHistogram( wxHashTable &h );
 
     unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
     unsigned long ComputeHistogram( wxHashTable &h );
@@ -209,8 +218,7 @@ public:
     static void InitStandardHandlers();
 
 protected:
     static void InitStandardHandlers();
 
 protected:
-    static wxList sm_handlers;
-    wxPalette m_palette;
+    static wxList   sm_handlers;
 
 private:
     friend class WXDLLEXPORT wxImageHandler;
 
 private:
     friend class WXDLLEXPORT wxImageHandler;
index d25fdd0f7fd950e8100c8e5d5690ab5392cb1cf5..9e4921bd8760e0776dafc332c9b1abe2ca02bb01 100644 (file)
@@ -57,6 +57,9 @@ public:
     unsigned char   m_maskRed,m_maskGreen,m_maskBlue;
     bool            m_ok;
     bool            m_static;
     unsigned char   m_maskRed,m_maskGreen,m_maskBlue;
     bool            m_ok;
     bool            m_static;
+    wxPalette       m_palette;
+    wxArrayString   m_optionNames;
+    wxArrayString   m_optionValues;
 };
 
 wxImageRefData::wxImageRefData()
 };
 
 wxImageRefData::wxImageRefData()
@@ -84,7 +87,7 @@ wxList wxImage::sm_handlers;
 
 #define M_IMGDATA ((wxImageRefData *)m_refData)
 
 
 #define M_IMGDATA ((wxImageRefData *)m_refData)
 
-    IMPLEMENT_DYNAMIC_CLASS(wxImage, wxObject)
+IMPLEMENT_DYNAMIC_CLASS(wxImage, wxObject)
 
 wxImage::wxImage()
 {
 
 wxImage::wxImage()
 {
@@ -612,6 +615,80 @@ int wxImage::GetHeight() const
     return M_IMGDATA->m_height;
 }
 
     return M_IMGDATA->m_height;
 }
 
+// Palette functions
+
+bool wxImage::HasPalette() const
+{
+    if (!Ok())
+        return FALSE;
+
+    return M_IMGDATA->m_palette.Ok();
+}
+
+const wxPalette& wxImage::GetPalette() const
+{
+    wxCHECK_MSG( Ok(), wxNullPalette, wxT("invalid image") );
+
+    return M_IMGDATA->m_palette;
+}
+
+void wxImage::SetPalette(const wxPalette& palette)
+{
+    wxCHECK_RET( Ok(), wxT("invalid image") );
+
+    M_IMGDATA->m_palette = palette;
+}
+
+// Option functions (arbitrary name/value mapping)
+void wxImage::SetOption(const wxString& name, const wxString& value)
+{
+    wxCHECK_RET( Ok(), wxT("invalid image") );
+
+    int idx = M_IMGDATA->m_optionNames.Index(name, FALSE);
+    if (idx == wxNOT_FOUND)
+    {
+        M_IMGDATA->m_optionNames.Add(name);
+        M_IMGDATA->m_optionValues.Add(value);
+    }
+    else
+    {
+        M_IMGDATA->m_optionNames[idx] = name;
+        M_IMGDATA->m_optionValues[idx] = value;
+    }
+}
+
+void wxImage::SetOption(const wxString& name, int value)
+{
+    wxString valStr;
+    valStr.Printf(wxT("%d"), value);
+    SetOption(name, valStr);
+}
+
+wxString wxImage::GetOption(const wxString& name) const
+{
+    wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid image") );
+
+    int idx = M_IMGDATA->m_optionNames.Index(name, FALSE);
+    if (idx == wxNOT_FOUND)
+        return wxEmptyString;
+    else
+        return M_IMGDATA->m_optionValues[idx];
+}
+
+int wxImage::GetOptionInt(const wxString& name) const
+{
+    wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
+
+    return wxAtoi(GetOption(name));
+}
+
+bool wxImage::HasOption(const wxString& name) const
+{
+    wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
+
+    return (M_IMGDATA->m_optionNames.Index(name, FALSE) != wxNOT_FOUND);
+}
+
 bool wxImage::LoadFile( const wxString& filename, long type )
 {
 #if wxUSE_STREAMS
 bool wxImage::LoadFile( const wxString& filename, long type )
 {
 #if wxUSE_STREAMS
index 5e3f56ce3418c9592a759b4d34d6ae6291f8a60e..8d6496294002c7a76c9f73baa636fd1c81cdc4d2 100644 (file)
@@ -325,6 +325,16 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
     cinfo.input_components = 3;
     cinfo.in_color_space = JCS_RGB;
     jpeg_set_defaults(&cinfo);
     cinfo.input_components = 3;
     cinfo.in_color_space = JCS_RGB;
     jpeg_set_defaults(&cinfo);
+
+    // TODO: 3rd parameter is force_baseline, what value should this be?
+    // Code says: "If force_baseline is TRUE, the computed quantization table entries
+    // are limited to 1..255 for JPEG baseline compatibility."
+    // 'Quality' is a number between 0 (terrible) and 100 (very good).
+    // The default (in jcparam.c, jpeg_set_defaults) is 75,
+    // and force_baseline is TRUE.
+    if (image->HasOption(wxT("quality")))
+        jpeg_set_quality(&cinfo, image->GetOptionInt(wxT("quality")), TRUE);
+
     jpeg_start_compress(&cinfo, TRUE);
 
     stride = cinfo.image_width * 3;    /* JSAMPLEs per row in image_buffer */
     jpeg_start_compress(&cinfo, TRUE);
 
     stride = cinfo.image_width * 3;    /* JSAMPLEs per row in image_buffer */