From 995612e2abc1131458863ed1d3e55206df7c33de Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 15 Oct 1999 16:59:32 +0000 Subject: [PATCH] 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 --- include/wx/image.h | 50 ++++++++++---------------- src/common/imagbmp.cpp | 4 +-- src/common/image.cpp | 63 +++++++++++++++----------------- src/common/imaggif.cpp | 4 +-- src/common/imagjpeg.cpp | 59 +++++++++++++++--------------- src/common/imagpcx.cpp | 10 +++--- src/common/imagpng.cpp | 6 ++-- src/common/imagpnm.cpp | 79 +++++++++++++++++++++-------------------- 8 files changed, 130 insertions(+), 145 deletions(-) diff --git a/include/wx/image.h b/include/wx/image.h index cc07d24d24..b5eaebc403 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -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 diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index 7b6f02cb3f..52dade70e4 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -401,10 +401,10 @@ 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]; - + stream.Read(&hdr, 2); stream.SeekI(-2, wxFromCurrent); return (hdr[0] == 'B' && hdr[1] == 'M'); diff --git a/src/common/image.cpp b/src/common/image.cpp index 13a92da11a..5c304f0a9d 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -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(); @@ -213,14 +213,14 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const const int subleft=3*rect.GetLeft(); const int width=3*GetWidth(); subwidth*=3; - + data+=rect.GetTop()*width+subleft; for (long j = 0; j < subheight; ++j) { memcpy( subdata, data, subwidth); subdata+=subwidth; - data+=width; + data+=width; } return image; @@ -310,9 +310,9 @@ void wxImage::SetData( char unsigned *data ) newRefData->m_maskGreen = M_IMGDATA->m_maskGreen; newRefData->m_maskBlue = M_IMGDATA->m_maskBlue; newRefData->m_hasMask = M_IMGDATA->m_hasMask; - + UnRef(); - + m_refData = newRefData; } @@ -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; diff --git a/src/common/imaggif.cpp b/src/common/imaggif.cpp index d2d5ef4bd9..94f404a507 100644 --- a/src/common/imaggif.cpp +++ b/src/common/imaggif.cpp @@ -49,7 +49,7 @@ bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose decod = new wxGIFDecoder(&stream, TRUE); if ((error = decod->ReadGIF()) != E_OK) - { + { if (verbose) { switch (error) @@ -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; diff --git a/src/common/imagjpeg.cpp b/src/common/imagjpeg.cpp index b2e4447a02..a4fc184bed 100644 --- a/src/common/imagjpeg.cpp +++ b/src/common/imagjpeg.cpp @@ -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" @@ -65,7 +66,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxJPEGHandler,wxImageHandler) typedef struct { struct jpeg_source_mgr pub; /* public fields */ - + JOCTET* buffer; /* start of buffer */ } my_source_mgr; @@ -83,7 +84,7 @@ METHODDEF(boolean) my_fill_input_buffer ( j_decompress_ptr WXUNUSED(cinfo) ) METHODDEF(void) my_skip_input_data ( j_decompress_ptr cinfo, long num_bytes ) { my_src_ptr src = (my_src_ptr) cinfo->src; - + src->pub.next_input_byte += (size_t) num_bytes; src->pub.bytes_in_buffer -= (size_t) num_bytes; } @@ -91,15 +92,15 @@ METHODDEF(void) my_skip_input_data ( j_decompress_ptr cinfo, long num_bytes ) METHODDEF(void) my_term_source ( j_decompress_ptr cinfo ) { my_src_ptr src = (my_src_ptr) cinfo->src; - + free (src->buffer); } 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)); @@ -110,7 +111,7 @@ void jpeg_wxio_src( j_decompress_ptr cinfo, wxInputStream& infile ) src->buffer = (JOCTET *) malloc (infile.GetSize()); src->pub.next_input_byte = src->buffer; /* until buffer loaded */ infile.Read(src->buffer, infile.GetSize()); - + src->pub.init_source = my_init_source; src->pub.fill_input_buffer = my_fill_input_buffer; src->pub.skip_input_data = my_skip_input_data; @@ -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; @@ -156,7 +157,7 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos JSAMPARRAY tempbuf; unsigned char *ptr; unsigned stride; - + image->Destroy(); cinfo.err = jpeg_std_error( &jerr.pub ); jerr.pub.error_exit = my_error_exit; @@ -179,7 +180,7 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos jpeg_read_header( &cinfo, TRUE ); cinfo.out_color_space = JCS_RGB; jpeg_start_decompress( &cinfo ); - + image->Create( cinfo.image_width, cinfo.image_height ); if (!image->Ok()) { jpeg_finish_decompress( &cinfo ); @@ -191,7 +192,7 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos stride = cinfo.output_width * 3; tempbuf = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, stride, 1 ); - + while ( cinfo.output_scanline < cinfo.output_height ) { jpeg_read_scanlines( &cinfo, tempbuf, 1 ); memcpy( ptr, tempbuf[0], stride ); @@ -208,19 +209,19 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos typedef struct { struct jpeg_destination_mgr pub; - + wxOutputStream *stream; JOCTET * buffer; } my_destination_mgr; 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) { my_dest_ptr dest = (my_dest_ptr) cinfo->dest; - + /* Allocate the output buffer --- it will be released when done with image */ dest->buffer = (JOCTET *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, @@ -232,7 +233,7 @@ METHODDEF(void) init_destination (j_compress_ptr cinfo) METHODDEF(boolean) empty_output_buffer (j_compress_ptr cinfo) { my_dest_ptr dest = (my_dest_ptr) cinfo->dest; - + dest->stream->Write(dest->buffer, OUTPUT_BUF_SIZE); dest->pub.next_output_byte = dest->buffer; dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; @@ -251,13 +252,13 @@ METHODDEF(void) term_destination (j_compress_ptr cinfo) 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)); } - + dest = (my_dest_ptr) cinfo->dest; dest->pub.init_destination = init_destination; dest->pub.empty_output_buffer = empty_output_buffer; @@ -269,10 +270,10 @@ 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; @@ -290,15 +291,15 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo jpeg_create_compress(&cinfo); jpeg_wxio_dest(&cinfo, stream); - + cinfo.image_width = image->GetWidth(); cinfo.image_height = image->GetHeight(); cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; 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]; @@ -306,15 +307,15 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); - + return TRUE; } -bool wxJPEGHandler::CanRead( wxInputStream& stream ) +bool wxJPEGHandler::DoCanRead( wxInputStream& stream ) { unsigned char hdr[2]; - + stream.Read(&hdr, 2); stream.SeekI(-2, wxFromCurrent); return (hdr[0] == 0xFF && hdr[1] == 0xD8); diff --git a/src/common/imagpcx.cpp b/src/common/imagpcx.cpp index 5d72d09ef0..73bee7edf3 100644 --- a/src/common/imagpcx.cpp +++ b/src/common/imagpcx.cpp @@ -24,7 +24,7 @@ # include "wx/defs.h" #endif -#if wxUSE_STREAMS && wxUSE_PCX +#if wxUSE_STREAMS && wxUSE_PCX #include "wx/image.h" #include "wx/wfstream.h" @@ -76,12 +76,12 @@ void RLEdecode(unsigned char *p, unsigned int size, wxInputStream& s) /* PCX header */ -#define HDR_VERSION 1 +#define HDR_VERSION 1 #define HDR_ENCODING 2 #define HDR_BITSPERPIXEL 3 #define HDR_XMIN 4 #define HDR_YMIN 6 -#define HDR_XMAX 8 +#define HDR_XMAX 8 #define HDR_YMAX 10 #define HDR_NPLANES 65 #define HDR_BYTESPERLINE 66 @@ -201,7 +201,7 @@ int ReadPCX(wxImage *image, wxInputStream& stream) { *(dst++) = p[i]; *(dst++) = p[i + bytesperline]; - *(dst++) = p[i + 2 * bytesperline]; + *(dst++) = p[i + 2 * bytesperline]; } break; } @@ -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; diff --git a/src/common/imagpng.cpp b/src/common/imagpng.cpp index a2f0c435ed..132655980c 100644 --- a/src/common/imagpng.cpp +++ b/src/common/imagpng.cpp @@ -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]; diff --git a/src/common/imagpnm.cpp b/src/common/imagpnm.cpp index d29174929c..3447c16544 100644 --- a/src/common/imagpnm.cpp +++ b/src/common/imagpnm.cpp @@ -44,7 +44,7 @@ void Skip_Comment(wxInputStream &stream) wxString line; wxTextInputStream text_stream(stream); - if (stream.Peek()==wxT('#')) + if (stream.Peek()==wxT('#')) { text_stream >> line; Skip_Comment(stream); @@ -57,7 +57,7 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE wxUint16 maxval; wxString line; char c(0); - + image->Destroy(); /* @@ -73,21 +73,21 @@ 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 Skip_Comment(buf_stream); text_stream >> width >> height ; - Skip_Comment(buf_stream); + Skip_Comment(buf_stream); text_stream >> maxval; //cout << line << " " << width << " " << height << " " << maxval << endl; @@ -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; iGetWidth() << " " << image->GetHeight() << endl + + //text_stream << "P6" << endl + //<< image->GetWidth() << " " << image->GetHeight() << endl //<< "255" << endl; text_stream << "P6\n" << image->GetWidth() << " " << image->GetHeight() << "\n255\n"; stream.Write(image->GetData(),3*image->GetWidth()*image->GetHeight()); @@ -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; -- 2.45.2