1. wxImageHandler::DoCanRead() introduced to solve the virtual function name

hiding problem
2. wxPNMHandler::CanRead() shouldn't use wxT() - should it?


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4005 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-10-15 16:59:32 +00:00
parent 52f13e4930
commit 995612e2ab
8 changed files with 129 additions and 144 deletions

View File

@@ -62,20 +62,22 @@ public:
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
virtual bool CanRead( wxInputStream& stream );
virtual bool CanRead( const wxString& name );
bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); }
bool CanRead( const wxString& name );
#endif
inline void SetName(const wxString& name) { m_name = name; }
inline void SetExtension(const wxString& ext) { m_extension = ext; }
inline void SetType(long type) { m_type = type; }
inline void SetMimeType(const wxString& type) { m_mime = type; }
inline wxString GetName() const { return m_name; }
inline wxString GetExtension() const { return m_extension; }
inline long GetType() const { return m_type; }
inline wxString GetMimeType() const { return m_mime; }
void SetName(const wxString& name) { m_name = name; }
void SetExtension(const wxString& ext) { m_extension = ext; }
void SetType(long type) { m_type = type; }
void SetMimeType(const wxString& type) { m_mime = type; }
wxString GetName() const { return m_name; }
wxString GetExtension() const { return m_extension; }
long GetType() const { return m_type; }
wxString GetMimeType() const { return m_mime; }
protected:
virtual bool DoCanRead( wxInputStream& stream ) = 0;
wxString m_name;
wxString m_extension;
wxString m_mime;
@@ -105,10 +107,7 @@ public:
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
virtual bool CanRead( wxInputStream& stream );
private:
// hiding base class virtuals again!
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
virtual bool DoCanRead( wxInputStream& stream );
#endif
};
#endif
@@ -135,10 +134,7 @@ public:
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
virtual bool CanRead( wxInputStream& stream );
private:
// hiding base class virtuals again!
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
virtual bool DoCanRead( wxInputStream& stream );
#endif
};
#endif
@@ -163,10 +159,7 @@ public:
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool CanRead( wxInputStream& stream );
private:
// hiding base class virtuals again!
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
virtual bool DoCanRead( wxInputStream& stream );
#endif
};
@@ -193,10 +186,7 @@ public:
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
virtual bool CanRead( wxInputStream& stream );
private:
// hiding base class virtuals again!
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
virtual bool DoCanRead( wxInputStream& stream );
#endif
};
#endif
@@ -223,10 +213,7 @@ public:
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
virtual bool CanRead( wxInputStream& stream );
private:
// hiding base class virtuals again!
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
virtual bool DoCanRead( wxInputStream& stream );
#endif
};
#endif
@@ -253,8 +240,7 @@ public:
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
virtual bool CanRead( wxInputStream& stream );
#endif
virtual bool DoCanRead( wxInputStream& stream );
};
#endif

View File

@@ -401,7 +401,7 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
return TRUE;
}
bool wxBMPHandler::CanRead( wxInputStream& stream )
bool wxBMPHandler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[2];

View File

@@ -196,7 +196,7 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (rect.GetRight()<=GetWidth()) && (rect.GetBottom()<=GetHeight())
, image, wxT("invalid subimage size") );
, image, wxT("invalid subimage size") );
int subwidth=rect.GetWidth();
const int subheight=rect.GetHeight();
@@ -220,7 +220,7 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
{
memcpy( subdata, data, subwidth);
subdata+=subwidth;
data+=width;
data+=width;
}
return image;
@@ -449,18 +449,18 @@ bool wxImage::LoadFile( wxInputStream& stream, long type )
if (type==wxBITMAP_TYPE_ANY)
{
wxList &list=GetHandlers();
wxList &list=GetHandlers();
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
{
handler=(wxImageHandler*)node->GetData();
if (handler->CanRead( stream ))
return handler->LoadFile( this, stream );
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
{
handler=(wxImageHandler*)node->GetData();
if (handler->CanRead( stream ))
return handler->LoadFile( this, stream );
}
}
wxLogWarning( wxT("No handler found for this image.") );
return FALSE;
wxLogWarning( wxT("No handler found for this image.") );
return FALSE;
}
handler = FindHandler(type);
@@ -642,11 +642,6 @@ bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSE
return FALSE;
}
bool wxImageHandler::CanRead( wxInputStream& WXUNUSED(stream) )
{
return FALSE;
}
bool wxImageHandler::CanRead( const wxString& name )
{
#if wxUSE_STREAMS
@@ -801,7 +796,7 @@ wxBitmap wxImage::ConvertToBitmap() const
// HDC memdc = ::CreateCompatibleDC( hdc );
// ::SelectObject( memdc, hbitmap);
// ::SetDIBitsToDevice( memdc, 0, 0, width, height,
// 0, 0, 0, height, (void *)lpBits, lpDIBh, DIB_RGB_COLORS);
// 0, 0, 0, height, (void *)lpBits, lpDIBh, DIB_RGB_COLORS);
// ::SelectObject( memdc, 0 );
// ::DeleteDC( memdc );
}
@@ -1060,25 +1055,25 @@ wxBitmap wxImage::ConvertToBitmap() const
{
static bool s_hasInitialized = FALSE;
if (!s_hasInitialized)
{
gdk_rgb_init();
s_hasInitialized = TRUE;
}
if (!s_hasInitialized)
{
gdk_rgb_init();
s_hasInitialized = TRUE;
}
GdkGC *gc = gdk_gc_new( bitmap.GetPixmap() );
gdk_draw_rgb_image( bitmap.GetPixmap(),
gc,
0, 0,
width, height,
GDK_RGB_DITHER_NONE,
GetData(),
width*3 );
gdk_draw_rgb_image( bitmap.GetPixmap(),
gc,
0, 0,
width, height,
GDK_RGB_DITHER_NONE,
GetData(),
width*3 );
gdk_gc_unref( gc );
return bitmap;
return bitmap;
}
#endif
@@ -1282,7 +1277,7 @@ wxImage::wxImage( const wxBitmap &bitmap )
for (int i = 0; i < bitmap.GetWidth(); i++)
{
wxInt32 pixel = gdk_image_get_pixel( gdk_image, i, j );
pixel = wxINT32_SWAP_ON_BE( pixel );
pixel = wxINT32_SWAP_ON_BE( pixel );
if (bpp <= 8)
{
data[pos] = cmap->colors[pixel].red >> 8;

View File

@@ -79,7 +79,7 @@ bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
return FALSE;
}
bool wxGIFHandler::CanRead( wxInputStream& stream )
bool wxGIFHandler::DoCanRead( wxInputStream& stream )
{
wxGIFDecoder *decod;
bool ok;

View File

@@ -28,8 +28,9 @@
#include "wx/debug.h"
#include "wx/log.h"
#include "wx/app.h"
extern "C" {
#include "jpeglib.h"
extern "C"
{
#include "jpeglib.h"
}
#include "wx/filefn.h"
#include "wx/wfstream.h"
@@ -99,7 +100,7 @@ void jpeg_wxio_src( j_decompress_ptr cinfo, wxInputStream& infile )
{
my_src_ptr src;
if (cinfo->src == NULL) { /* first time for this JPEG object? */
if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof(my_source_mgr));
@@ -122,9 +123,9 @@ void jpeg_wxio_src( j_decompress_ptr cinfo, wxInputStream& infile )
// JPEG error manager:
struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
jmp_buf setjmp_buffer; /* for return to caller */
};
typedef struct my_error_mgr * my_error_ptr;
@@ -215,7 +216,7 @@ typedef struct {
typedef my_destination_mgr * my_dest_ptr;
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
METHODDEF(void) init_destination (j_compress_ptr cinfo)
{
@@ -252,7 +253,7 @@ GLOBAL(void) jpeg_wxio_dest (j_compress_ptr cinfo, wxOutputStream& outfile)
{
my_dest_ptr dest;
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof(my_destination_mgr));
@@ -269,9 +270,9 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
{
struct jpeg_compress_struct cinfo;
struct my_error_mgr jerr;
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
JSAMPLE *image_buffer;
int stride; /* physical row width in image buffer */
int stride; /* physical row width in image buffer */
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
@@ -298,7 +299,7 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
jpeg_set_defaults(&cinfo);
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 */
image_buffer = image->GetData();
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = &image_buffer[cinfo.next_scanline * stride];
@@ -311,7 +312,7 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo
}
bool wxJPEGHandler::CanRead( wxInputStream& stream )
bool wxJPEGHandler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[2];

View File

@@ -263,7 +263,7 @@ bool wxPCXHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(
return FALSE;
}
bool wxPCXHandler::CanRead( wxInputStream& stream )
bool wxPCXHandler::DoCanRead( wxInputStream& stream )
{
unsigned char c;
off_t pos;

View File

@@ -278,7 +278,7 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos
return FALSE;
}
if (!verbose) png_set_error_fn(png_ptr, (png_voidp)NULL, png_silent_error, png_silent_warning);
if (!verbose) png_set_error_fn(png_ptr, (png_voidp)NULL, png_silent_error, png_silent_warning);
png_infop info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
@@ -324,7 +324,7 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos
data[(x << 2) + 0] = *ptr++;
data[(x << 2) + 1] = *ptr++;
data[(x << 2) + 2] = *ptr++;
if (( !image->HasMask() ) || \
if (( !image->HasMask() ) || \
(data[(x << 2) + 0] != image->GetMaskRed()) || \
(data[(x << 2) + 1] != image->GetMaskGreen()) || \
(data[(x << 2) + 2] != image->GetMaskBlue()))
@@ -347,7 +347,7 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos
return TRUE;
}
bool wxPNGHandler::CanRead( wxInputStream& stream )
bool wxPNGHandler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[4];

View File

@@ -73,15 +73,15 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
switch (c)
{
case wxT('2'):
wxLogError(wxT("Loading Grey Ascii PNM image is not yet implemented."));
return FALSE;
wxLogError(wxT("Loading Grey Ascii PNM image is not yet implemented."));
return FALSE;
case wxT('5'):
wxLogError(wxT("Loading Grey Raw PNM image is not yet implemented."));
return FALSE;
wxLogError(wxT("Loading Grey Raw PNM image is not yet implemented."));
return FALSE;
case wxT('3'): case wxT('6'): break;
default :
wxLogError(wxT("Loading PNM image : file not recognized."));
return FALSE;
default :
wxLogError(wxT("Loading PNM image : file not recognized."));
return FALSE;
}
text_stream >> line; // for the \n
@@ -96,25 +96,25 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
if (!ptr)
{
wxLogError( wxT("Cannot allocate RAM for RGB data in PNM file.") );
return FALSE;
return FALSE;
}
if (c=='3') // Ascii RBG
{
wxUint32 value, size=3*width*height;
for (wxUint32 i=0; i<size; ++i)
{
//this is very slow !!!
//I wonder how we can make any better ?
value=text_stream.Read32();
*ptr++=(unsigned char)value;
wxUint32 value, size=3*width*height;
for (wxUint32 i=0; i<size; ++i)
{
//this is very slow !!!
//I wonder how we can make any better ?
value=text_stream.Read32();
*ptr++=(unsigned char)value;
if (buf_stream.LastError()!=wxSTREAM_NOERROR)
{
wxLogError(wxT("Loading PNM image : file seems truncated."));
return FALSE;
}
}
if (buf_stream.LastError()!=wxSTREAM_NOERROR)
{
wxLogError(wxT("Loading PNM image : file seems truncated."));
return FALSE;
}
}
}
if (c=='6') // Raw RGB
buf_stream.Read( ptr, 3*width*height );
@@ -137,19 +137,22 @@ bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUS
return (stream.LastError()==wxStream_NOERROR);
}
bool wxPNMHandler::CanRead( wxInputStream& stream )
bool wxPNMHandler::DoCanRead( wxInputStream& stream )
{
off_t pos=stream.TellI();
off_t pos = stream.TellI();
Skip_Comment(stream);
if (stream.GetC()==wxT('P'))
switch (stream.GetC())
{
case wxT('3'): case wxT('6'):
stream.SeekI(pos);
return TRUE;
}
if ( stream.GetC() == 'P' )
{
switch (stream.GetC())
{
case '3':
case '6':
stream.SeekI(pos);
return TRUE;
}
}
stream.SeekI(pos);
return FALSE;