Added Set/Get/HasOption members and moved palette to ref data class.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7893 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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}
|
\membersection{wxImage::InitStandardHandlers}
|
||||||
|
|
||||||
\func{static void}{InitStandardHandlers}{\void}
|
\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}
|
\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}}
|
\func{void}{SetRGB}{\param{int }{x}, \param{int }{y}, \param{unsigned char }{red}, \param{unsigned char }{green}, \param{unsigned char }{blue}}
|
||||||
|
@@ -169,7 +169,8 @@ public:
|
|||||||
char unsigned *GetData() const;
|
char unsigned *GetData() const;
|
||||||
void SetData( char unsigned *data );
|
void SetData( char unsigned *data );
|
||||||
void SetData( char unsigned *data, int new_width, int new_height );
|
void SetData( char unsigned *data, int new_width, int new_height );
|
||||||
|
|
||||||
|
// Mask functions
|
||||||
void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
|
void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
|
||||||
unsigned char GetMaskRed() const;
|
unsigned char GetMaskRed() const;
|
||||||
unsigned char GetMaskGreen() const;
|
unsigned char GetMaskGreen() const;
|
||||||
@@ -177,9 +178,17 @@ public:
|
|||||||
void SetMask( bool mask = TRUE );
|
void SetMask( bool mask = TRUE );
|
||||||
bool HasMask() const;
|
bool HasMask() const;
|
||||||
|
|
||||||
bool HasPalette() const { return m_palette.Ok(); }
|
// Palette functions
|
||||||
const wxPalette& GetPalette() const { return m_palette; }
|
bool HasPalette() const;
|
||||||
void SetPalette(const wxPalette& palette) { m_palette = palette; }
|
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 CountColours( unsigned long stopafter = (unsigned long) -1 );
|
||||||
unsigned long ComputeHistogram( wxHashTable &h );
|
unsigned long ComputeHistogram( wxHashTable &h );
|
||||||
@@ -209,8 +218,7 @@ public:
|
|||||||
static void InitStandardHandlers();
|
static void InitStandardHandlers();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static wxList sm_handlers;
|
static wxList sm_handlers;
|
||||||
wxPalette m_palette;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class WXDLLEXPORT wxImageHandler;
|
friend class WXDLLEXPORT wxImageHandler;
|
||||||
|
@@ -57,6 +57,9 @@ public:
|
|||||||
unsigned char m_maskRed,m_maskGreen,m_maskBlue;
|
unsigned char m_maskRed,m_maskGreen,m_maskBlue;
|
||||||
bool m_ok;
|
bool m_ok;
|
||||||
bool m_static;
|
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 )
|
bool wxImage::LoadFile( const wxString& filename, long type )
|
||||||
{
|
{
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
|
@@ -325,6 +325,16 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
|
|||||||
cinfo.input_components = 3;
|
cinfo.input_components = 3;
|
||||||
cinfo.in_color_space = JCS_RGB;
|
cinfo.in_color_space = JCS_RGB;
|
||||||
jpeg_set_defaults(&cinfo);
|
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);
|
jpeg_start_compress(&cinfo, TRUE);
|
||||||
|
|
||||||
stride = cinfo.image_width * 3; /* JSAMPLEs per row in image_buffer */
|
stride = cinfo.image_width * 3; /* JSAMPLEs per row in image_buffer */
|
||||||
|
Reference in New Issue
Block a user