X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/185d7c3ee4c6e4a9ddaf811ae38e57d68a0fdff3..f9ee64b1356530b7f5c957d250d2a1dcbef60f60:/wxPython/src/image.i diff --git a/wxPython/src/image.i b/wxPython/src/image.i index f3155144f1..93afd3115c 100644 --- a/wxPython/src/image.i +++ b/wxPython/src/image.i @@ -30,7 +30,7 @@ //--------------------------------------------------------------------------- -class wxImageHandler { +class wxImageHandler : public wxObject { public: // wxImageHandler(); Abstract Base Class wxString GetName(); @@ -40,6 +40,10 @@ public: //bool LoadFile(wxImage* image, wxInputStream& stream); //bool SaveFile(wxImage* image, wxOutputStream& stream); + //virtual int GetImageCount( wxInputStream& stream ); + //bool CanRead( wxInputStream& stream ); + + bool CanRead( const wxString& name ); void SetName(const wxString& name); void SetExtension(const wxString& extension); @@ -66,6 +70,20 @@ public: wxBMPHandler(); }; +class wxICOHandler : public wxBMPHandler { +public: + wxICOHandler(); +}; + +class wxCURHandler : public wxICOHandler { +public: + wxCURHandler(); +}; + +class wxANIHandler : public wxCURHandler { +public: + wxANIHandler(); +}; class wxGIFHandler : public wxImageHandler { public: @@ -88,16 +106,21 @@ public: }; + //--------------------------------------------------------------------------- -class wxImage { +class wxImage : public wxObject { public: - wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY ); + wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); ~wxImage(); - wxBitmap ConvertToBitmap(); + wxBitmap ConvertToBitmap(); // deprecated +#ifdef __WXGTK__ + wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const; +#endif void Create( int width, int height ); void Destroy(); + wxImage Scale( int width, int height ); wxImage& Rescale(int width, int height); @@ -106,8 +129,11 @@ public: unsigned char GetGreen( int x, int y ); unsigned char GetBlue( int x, int y ); - bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG ); - %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype ); + static bool CanRead( const wxString& name ); + static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY ); + + bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); + %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ); bool SaveFile( const wxString& name, int type ); %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype ); @@ -160,43 +186,85 @@ public: void Replace( unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2 ); + // convert to monochrome image ( will be replaced by white, everything else by black) + wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; + + void SetOption(const wxString& name, const wxString& value); + %name(SetOptionInt)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 ); // TODO: unsigned long ComputeHistogram( wxHashTable &h ); + static void AddHandler( wxImageHandler *handler ); + static void InsertHandler( wxImageHandler *handler ); + static bool RemoveHandler( const wxString& name ); }; + // Alternate constructors -%new wxImage* wxNullImage(); -%new wxImage* wxEmptyImage(int width, int height); -%new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype); +%new wxImage* wxEmptyImage(int width=0, int height=0); +%new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1); %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap); +%new wxImage* wxImageFromData(int width, int height, unsigned char* data); %{ - wxImage* wxNullImage() { - return new wxImage; + wxImage* wxEmptyImage(int width=0, int height=0) { + if (width == 0 && height == 0) + return new wxImage; + else + return new wxImage(width, height); } - wxImage* wxEmptyImage(int width, int height) { - return new wxImage(width, height); - } - - wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype) { - return new wxImage(name, mimetype); + wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) { + return new wxImage(name, mimetype, index); } wxImage* wxImageFromBitmap(const wxBitmap &bitmap) { return new wxImage(bitmap); } -%} -// Static Methods -void wxImage_AddHandler(wxImageHandler *handler); -%{ - void wxImage_AddHandler(wxImageHandler *handler) { - wxImage::AddHandler(handler); + wxImage* wxImageFromData(int width, int height, unsigned char* data) { + // Copy the source data so the wxImage can clean it up later + unsigned char* copy = (unsigned char*)malloc(width*height*3); + if (copy == NULL) { + PyErr_NoMemory(); + return NULL; + } + memcpy(copy, data, width*height*3); + return new wxImage(width, height, copy, FALSE); } %} void wxInitAllImageHandlers(); + +%readonly +%{ +#if 0 +%} + +extern wxImage wxNullImage; + +%readwrite +%{ +#endif +%} + + + //--------------------------------------------------------------------------- +// This one is here to avoid circular imports + +%new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1); + +%{ + wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) { + return new wxBitmap(img, depth); + } + +%} + + //---------------------------------------------------------------------------