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:
@@ -62,20 +62,22 @@ public:
|
|||||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
||||||
|
|
||||||
virtual bool CanRead( wxInputStream& stream );
|
bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); }
|
||||||
virtual bool CanRead( const wxString& name );
|
bool CanRead( const wxString& name );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline void SetName(const wxString& name) { m_name = name; }
|
void SetName(const wxString& name) { m_name = name; }
|
||||||
inline void SetExtension(const wxString& ext) { m_extension = ext; }
|
void SetExtension(const wxString& ext) { m_extension = ext; }
|
||||||
inline void SetType(long type) { m_type = type; }
|
void SetType(long type) { m_type = type; }
|
||||||
inline void SetMimeType(const wxString& type) { m_mime = type; }
|
void SetMimeType(const wxString& type) { m_mime = type; }
|
||||||
inline wxString GetName() const { return m_name; }
|
wxString GetName() const { return m_name; }
|
||||||
inline wxString GetExtension() const { return m_extension; }
|
wxString GetExtension() const { return m_extension; }
|
||||||
inline long GetType() const { return m_type; }
|
long GetType() const { return m_type; }
|
||||||
inline wxString GetMimeType() const { return m_mime; }
|
wxString GetMimeType() const { return m_mime; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool DoCanRead( wxInputStream& stream ) = 0;
|
||||||
|
|
||||||
wxString m_name;
|
wxString m_name;
|
||||||
wxString m_extension;
|
wxString m_extension;
|
||||||
wxString m_mime;
|
wxString m_mime;
|
||||||
@@ -105,10 +107,7 @@ public:
|
|||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool CanRead( wxInputStream& stream );
|
virtual bool DoCanRead( wxInputStream& stream );
|
||||||
private:
|
|
||||||
// hiding base class virtuals again!
|
|
||||||
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -135,10 +134,7 @@ public:
|
|||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool CanRead( wxInputStream& stream );
|
virtual bool DoCanRead( wxInputStream& stream );
|
||||||
private:
|
|
||||||
// hiding base class virtuals again!
|
|
||||||
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -163,10 +159,7 @@ public:
|
|||||||
|
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool CanRead( wxInputStream& stream );
|
virtual bool DoCanRead( wxInputStream& stream );
|
||||||
private:
|
|
||||||
// hiding base class virtuals again!
|
|
||||||
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -193,10 +186,7 @@ public:
|
|||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool CanRead( wxInputStream& stream );
|
virtual bool DoCanRead( wxInputStream& stream );
|
||||||
private:
|
|
||||||
// hiding base class virtuals again!
|
|
||||||
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -223,10 +213,7 @@ public:
|
|||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool CanRead( wxInputStream& stream );
|
virtual bool DoCanRead( wxInputStream& stream );
|
||||||
private:
|
|
||||||
// hiding base class virtuals again!
|
|
||||||
inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -253,8 +240,7 @@ public:
|
|||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
||||||
virtual bool CanRead( wxInputStream& stream );
|
virtual bool DoCanRead( wxInputStream& stream );
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -401,10 +401,10 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBMPHandler::CanRead( wxInputStream& stream )
|
bool wxBMPHandler::DoCanRead( wxInputStream& stream )
|
||||||
{
|
{
|
||||||
unsigned char hdr[2];
|
unsigned char hdr[2];
|
||||||
|
|
||||||
stream.Read(&hdr, 2);
|
stream.Read(&hdr, 2);
|
||||||
stream.SeekI(-2, wxFromCurrent);
|
stream.SeekI(-2, wxFromCurrent);
|
||||||
return (hdr[0] == 'B' && hdr[1] == 'M');
|
return (hdr[0] == 'B' && hdr[1] == 'M');
|
||||||
|
@@ -196,7 +196,7 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
|
|||||||
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
|
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
|
||||||
|
|
||||||
wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (rect.GetRight()<=GetWidth()) && (rect.GetBottom()<=GetHeight())
|
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();
|
int subwidth=rect.GetWidth();
|
||||||
const int subheight=rect.GetHeight();
|
const int subheight=rect.GetHeight();
|
||||||
@@ -213,14 +213,14 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
|
|||||||
const int subleft=3*rect.GetLeft();
|
const int subleft=3*rect.GetLeft();
|
||||||
const int width=3*GetWidth();
|
const int width=3*GetWidth();
|
||||||
subwidth*=3;
|
subwidth*=3;
|
||||||
|
|
||||||
data+=rect.GetTop()*width+subleft;
|
data+=rect.GetTop()*width+subleft;
|
||||||
|
|
||||||
for (long j = 0; j < subheight; ++j)
|
for (long j = 0; j < subheight; ++j)
|
||||||
{
|
{
|
||||||
memcpy( subdata, data, subwidth);
|
memcpy( subdata, data, subwidth);
|
||||||
subdata+=subwidth;
|
subdata+=subwidth;
|
||||||
data+=width;
|
data+=width;
|
||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
@@ -310,9 +310,9 @@ void wxImage::SetData( char unsigned *data )
|
|||||||
newRefData->m_maskGreen = M_IMGDATA->m_maskGreen;
|
newRefData->m_maskGreen = M_IMGDATA->m_maskGreen;
|
||||||
newRefData->m_maskBlue = M_IMGDATA->m_maskBlue;
|
newRefData->m_maskBlue = M_IMGDATA->m_maskBlue;
|
||||||
newRefData->m_hasMask = M_IMGDATA->m_hasMask;
|
newRefData->m_hasMask = M_IMGDATA->m_hasMask;
|
||||||
|
|
||||||
UnRef();
|
UnRef();
|
||||||
|
|
||||||
m_refData = newRefData;
|
m_refData = newRefData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,18 +449,18 @@ bool wxImage::LoadFile( wxInputStream& stream, long type )
|
|||||||
|
|
||||||
if (type==wxBITMAP_TYPE_ANY)
|
if (type==wxBITMAP_TYPE_ANY)
|
||||||
{
|
{
|
||||||
wxList &list=GetHandlers();
|
wxList &list=GetHandlers();
|
||||||
|
|
||||||
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
|
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
|
||||||
{
|
{
|
||||||
handler=(wxImageHandler*)node->GetData();
|
handler=(wxImageHandler*)node->GetData();
|
||||||
if (handler->CanRead( stream ))
|
if (handler->CanRead( stream ))
|
||||||
return handler->LoadFile( this, stream );
|
return handler->LoadFile( this, stream );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxLogWarning( wxT("No handler found for this image.") );
|
wxLogWarning( wxT("No handler found for this image.") );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
handler = FindHandler(type);
|
handler = FindHandler(type);
|
||||||
@@ -642,11 +642,6 @@ bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSE
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxImageHandler::CanRead( wxInputStream& WXUNUSED(stream) )
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxImageHandler::CanRead( const wxString& name )
|
bool wxImageHandler::CanRead( const wxString& name )
|
||||||
{
|
{
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
@@ -801,7 +796,7 @@ wxBitmap wxImage::ConvertToBitmap() const
|
|||||||
// HDC memdc = ::CreateCompatibleDC( hdc );
|
// HDC memdc = ::CreateCompatibleDC( hdc );
|
||||||
// ::SelectObject( memdc, hbitmap);
|
// ::SelectObject( memdc, hbitmap);
|
||||||
// ::SetDIBitsToDevice( memdc, 0, 0, width, height,
|
// ::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 );
|
// ::SelectObject( memdc, 0 );
|
||||||
// ::DeleteDC( memdc );
|
// ::DeleteDC( memdc );
|
||||||
}
|
}
|
||||||
@@ -1060,25 +1055,25 @@ wxBitmap wxImage::ConvertToBitmap() const
|
|||||||
{
|
{
|
||||||
static bool s_hasInitialized = FALSE;
|
static bool s_hasInitialized = FALSE;
|
||||||
|
|
||||||
if (!s_hasInitialized)
|
if (!s_hasInitialized)
|
||||||
{
|
{
|
||||||
gdk_rgb_init();
|
gdk_rgb_init();
|
||||||
s_hasInitialized = TRUE;
|
s_hasInitialized = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkGC *gc = gdk_gc_new( bitmap.GetPixmap() );
|
GdkGC *gc = gdk_gc_new( bitmap.GetPixmap() );
|
||||||
|
|
||||||
gdk_draw_rgb_image( bitmap.GetPixmap(),
|
gdk_draw_rgb_image( bitmap.GetPixmap(),
|
||||||
gc,
|
gc,
|
||||||
0, 0,
|
0, 0,
|
||||||
width, height,
|
width, height,
|
||||||
GDK_RGB_DITHER_NONE,
|
GDK_RGB_DITHER_NONE,
|
||||||
GetData(),
|
GetData(),
|
||||||
width*3 );
|
width*3 );
|
||||||
|
|
||||||
gdk_gc_unref( gc );
|
gdk_gc_unref( gc );
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1282,7 +1277,7 @@ wxImage::wxImage( const wxBitmap &bitmap )
|
|||||||
for (int i = 0; i < bitmap.GetWidth(); i++)
|
for (int i = 0; i < bitmap.GetWidth(); i++)
|
||||||
{
|
{
|
||||||
wxInt32 pixel = gdk_image_get_pixel( gdk_image, i, j );
|
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)
|
if (bpp <= 8)
|
||||||
{
|
{
|
||||||
data[pos] = cmap->colors[pixel].red >> 8;
|
data[pos] = cmap->colors[pixel].red >> 8;
|
||||||
|
@@ -49,7 +49,7 @@ bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
|
|||||||
decod = new wxGIFDecoder(&stream, TRUE);
|
decod = new wxGIFDecoder(&stream, TRUE);
|
||||||
|
|
||||||
if ((error = decod->ReadGIF()) != E_OK)
|
if ((error = decod->ReadGIF()) != E_OK)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
switch (error)
|
switch (error)
|
||||||
@@ -79,7 +79,7 @@ bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGIFHandler::CanRead( wxInputStream& stream )
|
bool wxGIFHandler::DoCanRead( wxInputStream& stream )
|
||||||
{
|
{
|
||||||
wxGIFDecoder *decod;
|
wxGIFDecoder *decod;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
@@ -28,8 +28,9 @@
|
|||||||
#include "wx/debug.h"
|
#include "wx/debug.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
extern "C" {
|
extern "C"
|
||||||
#include "jpeglib.h"
|
{
|
||||||
|
#include "jpeglib.h"
|
||||||
}
|
}
|
||||||
#include "wx/filefn.h"
|
#include "wx/filefn.h"
|
||||||
#include "wx/wfstream.h"
|
#include "wx/wfstream.h"
|
||||||
@@ -65,7 +66,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxJPEGHandler,wxImageHandler)
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct jpeg_source_mgr pub; /* public fields */
|
struct jpeg_source_mgr pub; /* public fields */
|
||||||
|
|
||||||
JOCTET* buffer; /* start of buffer */
|
JOCTET* buffer; /* start of buffer */
|
||||||
} my_source_mgr;
|
} 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 )
|
METHODDEF(void) my_skip_input_data ( j_decompress_ptr cinfo, long num_bytes )
|
||||||
{
|
{
|
||||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||||
|
|
||||||
src->pub.next_input_byte += (size_t) num_bytes;
|
src->pub.next_input_byte += (size_t) num_bytes;
|
||||||
src->pub.bytes_in_buffer -= (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 )
|
METHODDEF(void) my_term_source ( j_decompress_ptr cinfo )
|
||||||
{
|
{
|
||||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||||
|
|
||||||
free (src->buffer);
|
free (src->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jpeg_wxio_src( j_decompress_ptr cinfo, wxInputStream& infile )
|
void jpeg_wxio_src( j_decompress_ptr cinfo, wxInputStream& infile )
|
||||||
{
|
{
|
||||||
my_src_ptr src;
|
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->src = (struct jpeg_source_mgr *)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||||
sizeof(my_source_mgr));
|
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->buffer = (JOCTET *) malloc (infile.GetSize());
|
||||||
src->pub.next_input_byte = src->buffer; /* until buffer loaded */
|
src->pub.next_input_byte = src->buffer; /* until buffer loaded */
|
||||||
infile.Read(src->buffer, infile.GetSize());
|
infile.Read(src->buffer, infile.GetSize());
|
||||||
|
|
||||||
src->pub.init_source = my_init_source;
|
src->pub.init_source = my_init_source;
|
||||||
src->pub.fill_input_buffer = my_fill_input_buffer;
|
src->pub.fill_input_buffer = my_fill_input_buffer;
|
||||||
src->pub.skip_input_data = my_skip_input_data;
|
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:
|
// JPEG error manager:
|
||||||
|
|
||||||
struct my_error_mgr {
|
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;
|
typedef struct my_error_mgr * my_error_ptr;
|
||||||
@@ -156,7 +157,7 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos
|
|||||||
JSAMPARRAY tempbuf;
|
JSAMPARRAY tempbuf;
|
||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
unsigned stride;
|
unsigned stride;
|
||||||
|
|
||||||
image->Destroy();
|
image->Destroy();
|
||||||
cinfo.err = jpeg_std_error( &jerr.pub );
|
cinfo.err = jpeg_std_error( &jerr.pub );
|
||||||
jerr.pub.error_exit = my_error_exit;
|
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 );
|
jpeg_read_header( &cinfo, TRUE );
|
||||||
cinfo.out_color_space = JCS_RGB;
|
cinfo.out_color_space = JCS_RGB;
|
||||||
jpeg_start_decompress( &cinfo );
|
jpeg_start_decompress( &cinfo );
|
||||||
|
|
||||||
image->Create( cinfo.image_width, cinfo.image_height );
|
image->Create( cinfo.image_width, cinfo.image_height );
|
||||||
if (!image->Ok()) {
|
if (!image->Ok()) {
|
||||||
jpeg_finish_decompress( &cinfo );
|
jpeg_finish_decompress( &cinfo );
|
||||||
@@ -191,7 +192,7 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos
|
|||||||
stride = cinfo.output_width * 3;
|
stride = cinfo.output_width * 3;
|
||||||
tempbuf = (*cinfo.mem->alloc_sarray)
|
tempbuf = (*cinfo.mem->alloc_sarray)
|
||||||
((j_common_ptr) &cinfo, JPOOL_IMAGE, stride, 1 );
|
((j_common_ptr) &cinfo, JPOOL_IMAGE, stride, 1 );
|
||||||
|
|
||||||
while ( cinfo.output_scanline < cinfo.output_height ) {
|
while ( cinfo.output_scanline < cinfo.output_height ) {
|
||||||
jpeg_read_scanlines( &cinfo, tempbuf, 1 );
|
jpeg_read_scanlines( &cinfo, tempbuf, 1 );
|
||||||
memcpy( ptr, tempbuf[0], stride );
|
memcpy( ptr, tempbuf[0], stride );
|
||||||
@@ -208,19 +209,19 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct jpeg_destination_mgr pub;
|
struct jpeg_destination_mgr pub;
|
||||||
|
|
||||||
wxOutputStream *stream;
|
wxOutputStream *stream;
|
||||||
JOCTET * buffer;
|
JOCTET * buffer;
|
||||||
} my_destination_mgr;
|
} my_destination_mgr;
|
||||||
|
|
||||||
typedef my_destination_mgr * my_dest_ptr;
|
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)
|
METHODDEF(void) init_destination (j_compress_ptr cinfo)
|
||||||
{
|
{
|
||||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||||
|
|
||||||
/* Allocate the output buffer --- it will be released when done with image */
|
/* Allocate the output buffer --- it will be released when done with image */
|
||||||
dest->buffer = (JOCTET *)
|
dest->buffer = (JOCTET *)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
(*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)
|
METHODDEF(boolean) empty_output_buffer (j_compress_ptr cinfo)
|
||||||
{
|
{
|
||||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||||
|
|
||||||
dest->stream->Write(dest->buffer, OUTPUT_BUF_SIZE);
|
dest->stream->Write(dest->buffer, OUTPUT_BUF_SIZE);
|
||||||
dest->pub.next_output_byte = dest->buffer;
|
dest->pub.next_output_byte = dest->buffer;
|
||||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
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)
|
GLOBAL(void) jpeg_wxio_dest (j_compress_ptr cinfo, wxOutputStream& outfile)
|
||||||
{
|
{
|
||||||
my_dest_ptr dest;
|
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->dest = (struct jpeg_destination_mgr *)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||||
sizeof(my_destination_mgr));
|
sizeof(my_destination_mgr));
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = (my_dest_ptr) cinfo->dest;
|
dest = (my_dest_ptr) cinfo->dest;
|
||||||
dest->pub.init_destination = init_destination;
|
dest->pub.init_destination = init_destination;
|
||||||
dest->pub.empty_output_buffer = empty_output_buffer;
|
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 jpeg_compress_struct cinfo;
|
||||||
struct my_error_mgr jerr;
|
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;
|
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);
|
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||||
jerr.pub.error_exit = my_error_exit;
|
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_create_compress(&cinfo);
|
||||||
jpeg_wxio_dest(&cinfo, stream);
|
jpeg_wxio_dest(&cinfo, stream);
|
||||||
|
|
||||||
cinfo.image_width = image->GetWidth();
|
cinfo.image_width = image->GetWidth();
|
||||||
cinfo.image_height = image->GetHeight();
|
cinfo.image_height = image->GetHeight();
|
||||||
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);
|
||||||
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 */
|
||||||
image_buffer = image->GetData();
|
image_buffer = image->GetData();
|
||||||
while (cinfo.next_scanline < cinfo.image_height) {
|
while (cinfo.next_scanline < cinfo.image_height) {
|
||||||
row_pointer[0] = &image_buffer[cinfo.next_scanline * stride];
|
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_finish_compress(&cinfo);
|
||||||
jpeg_destroy_compress(&cinfo);
|
jpeg_destroy_compress(&cinfo);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxJPEGHandler::CanRead( wxInputStream& stream )
|
bool wxJPEGHandler::DoCanRead( wxInputStream& stream )
|
||||||
{
|
{
|
||||||
unsigned char hdr[2];
|
unsigned char hdr[2];
|
||||||
|
|
||||||
stream.Read(&hdr, 2);
|
stream.Read(&hdr, 2);
|
||||||
stream.SeekI(-2, wxFromCurrent);
|
stream.SeekI(-2, wxFromCurrent);
|
||||||
return (hdr[0] == 0xFF && hdr[1] == 0xD8);
|
return (hdr[0] == 0xFF && hdr[1] == 0xD8);
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
# include "wx/defs.h"
|
# include "wx/defs.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxUSE_STREAMS && wxUSE_PCX
|
#if wxUSE_STREAMS && wxUSE_PCX
|
||||||
|
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
#include "wx/wfstream.h"
|
#include "wx/wfstream.h"
|
||||||
@@ -76,12 +76,12 @@ void RLEdecode(unsigned char *p, unsigned int size, wxInputStream& s)
|
|||||||
|
|
||||||
|
|
||||||
/* PCX header */
|
/* PCX header */
|
||||||
#define HDR_VERSION 1
|
#define HDR_VERSION 1
|
||||||
#define HDR_ENCODING 2
|
#define HDR_ENCODING 2
|
||||||
#define HDR_BITSPERPIXEL 3
|
#define HDR_BITSPERPIXEL 3
|
||||||
#define HDR_XMIN 4
|
#define HDR_XMIN 4
|
||||||
#define HDR_YMIN 6
|
#define HDR_YMIN 6
|
||||||
#define HDR_XMAX 8
|
#define HDR_XMAX 8
|
||||||
#define HDR_YMAX 10
|
#define HDR_YMAX 10
|
||||||
#define HDR_NPLANES 65
|
#define HDR_NPLANES 65
|
||||||
#define HDR_BYTESPERLINE 66
|
#define HDR_BYTESPERLINE 66
|
||||||
@@ -201,7 +201,7 @@ int ReadPCX(wxImage *image, wxInputStream& stream)
|
|||||||
{
|
{
|
||||||
*(dst++) = p[i];
|
*(dst++) = p[i];
|
||||||
*(dst++) = p[i + bytesperline];
|
*(dst++) = p[i + bytesperline];
|
||||||
*(dst++) = p[i + 2 * bytesperline];
|
*(dst++) = p[i + 2 * bytesperline];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ bool wxPCXHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxPCXHandler::CanRead( wxInputStream& stream )
|
bool wxPCXHandler::DoCanRead( wxInputStream& stream )
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
off_t pos;
|
off_t pos;
|
||||||
|
@@ -278,7 +278,7 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos
|
|||||||
return FALSE;
|
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);
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (info_ptr == NULL)
|
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) + 0] = *ptr++;
|
||||||
data[(x << 2) + 1] = *ptr++;
|
data[(x << 2) + 1] = *ptr++;
|
||||||
data[(x << 2) + 2] = *ptr++;
|
data[(x << 2) + 2] = *ptr++;
|
||||||
if (( !image->HasMask() ) || \
|
if (( !image->HasMask() ) || \
|
||||||
(data[(x << 2) + 0] != image->GetMaskRed()) || \
|
(data[(x << 2) + 0] != image->GetMaskRed()) || \
|
||||||
(data[(x << 2) + 1] != image->GetMaskGreen()) || \
|
(data[(x << 2) + 1] != image->GetMaskGreen()) || \
|
||||||
(data[(x << 2) + 2] != image->GetMaskBlue()))
|
(data[(x << 2) + 2] != image->GetMaskBlue()))
|
||||||
@@ -347,7 +347,7 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxPNGHandler::CanRead( wxInputStream& stream )
|
bool wxPNGHandler::DoCanRead( wxInputStream& stream )
|
||||||
{
|
{
|
||||||
unsigned char hdr[4];
|
unsigned char hdr[4];
|
||||||
|
|
||||||
|
@@ -44,7 +44,7 @@ void Skip_Comment(wxInputStream &stream)
|
|||||||
wxString line;
|
wxString line;
|
||||||
wxTextInputStream text_stream(stream);
|
wxTextInputStream text_stream(stream);
|
||||||
|
|
||||||
if (stream.Peek()==wxT('#'))
|
if (stream.Peek()==wxT('#'))
|
||||||
{
|
{
|
||||||
text_stream >> line;
|
text_stream >> line;
|
||||||
Skip_Comment(stream);
|
Skip_Comment(stream);
|
||||||
@@ -57,7 +57,7 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
|
|||||||
wxUint16 maxval;
|
wxUint16 maxval;
|
||||||
wxString line;
|
wxString line;
|
||||||
char c(0);
|
char c(0);
|
||||||
|
|
||||||
image->Destroy();
|
image->Destroy();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -73,21 +73,21 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
|
|||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case wxT('2'):
|
case wxT('2'):
|
||||||
wxLogError(wxT("Loading Grey Ascii PNM image is not yet implemented."));
|
wxLogError(wxT("Loading Grey Ascii PNM image is not yet implemented."));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
case wxT('5'):
|
case wxT('5'):
|
||||||
wxLogError(wxT("Loading Grey Raw PNM image is not yet implemented."));
|
wxLogError(wxT("Loading Grey Raw PNM image is not yet implemented."));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
case wxT('3'): case wxT('6'): break;
|
case wxT('3'): case wxT('6'): break;
|
||||||
default :
|
default :
|
||||||
wxLogError(wxT("Loading PNM image : file not recognized."));
|
wxLogError(wxT("Loading PNM image : file not recognized."));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
text_stream >> line; // for the \n
|
text_stream >> line; // for the \n
|
||||||
Skip_Comment(buf_stream);
|
Skip_Comment(buf_stream);
|
||||||
text_stream >> width >> height ;
|
text_stream >> width >> height ;
|
||||||
Skip_Comment(buf_stream);
|
Skip_Comment(buf_stream);
|
||||||
text_stream >> maxval;
|
text_stream >> maxval;
|
||||||
|
|
||||||
//cout << line << " " << width << " " << height << " " << maxval << endl;
|
//cout << line << " " << width << " " << height << " " << maxval << endl;
|
||||||
@@ -96,25 +96,25 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
|
|||||||
if (!ptr)
|
if (!ptr)
|
||||||
{
|
{
|
||||||
wxLogError( wxT("Cannot allocate RAM for RGB data in PNM file.") );
|
wxLogError( wxT("Cannot allocate RAM for RGB data in PNM file.") );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c=='3') // Ascii RBG
|
if (c=='3') // Ascii RBG
|
||||||
{
|
{
|
||||||
wxUint32 value, size=3*width*height;
|
wxUint32 value, size=3*width*height;
|
||||||
for (wxUint32 i=0; i<size; ++i)
|
for (wxUint32 i=0; i<size; ++i)
|
||||||
{
|
{
|
||||||
//this is very slow !!!
|
//this is very slow !!!
|
||||||
//I wonder how we can make any better ?
|
//I wonder how we can make any better ?
|
||||||
value=text_stream.Read32();
|
value=text_stream.Read32();
|
||||||
*ptr++=(unsigned char)value;
|
*ptr++=(unsigned char)value;
|
||||||
|
|
||||||
if (buf_stream.LastError()!=wxSTREAM_NOERROR)
|
if (buf_stream.LastError()!=wxSTREAM_NOERROR)
|
||||||
{
|
{
|
||||||
wxLogError(wxT("Loading PNM image : file seems truncated."));
|
wxLogError(wxT("Loading PNM image : file seems truncated."));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c=='6') // Raw RGB
|
if (c=='6') // Raw RGB
|
||||||
buf_stream.Read( ptr, 3*width*height );
|
buf_stream.Read( ptr, 3*width*height );
|
||||||
@@ -127,9 +127,9 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
|
|||||||
bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUSED(verbose) )
|
bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUSED(verbose) )
|
||||||
{
|
{
|
||||||
wxTextOutputStream text_stream(stream);
|
wxTextOutputStream text_stream(stream);
|
||||||
|
|
||||||
//text_stream << "P6" << endl
|
//text_stream << "P6" << endl
|
||||||
//<< image->GetWidth() << " " << image->GetHeight() << endl
|
//<< image->GetWidth() << " " << image->GetHeight() << endl
|
||||||
//<< "255" << endl;
|
//<< "255" << endl;
|
||||||
text_stream << "P6\n" << image->GetWidth() << " " << image->GetHeight() << "\n255\n";
|
text_stream << "P6\n" << image->GetWidth() << " " << image->GetHeight() << "\n255\n";
|
||||||
stream.Write(image->GetData(),3*image->GetWidth()*image->GetHeight());
|
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);
|
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);
|
Skip_Comment(stream);
|
||||||
|
|
||||||
if (stream.GetC()==wxT('P'))
|
if ( stream.GetC() == 'P' )
|
||||||
switch (stream.GetC())
|
{
|
||||||
{
|
switch (stream.GetC())
|
||||||
case wxT('3'): case wxT('6'):
|
{
|
||||||
stream.SeekI(pos);
|
case '3':
|
||||||
return TRUE;
|
case '6':
|
||||||
}
|
stream.SeekI(pos);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stream.SeekI(pos);
|
stream.SeekI(pos);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Reference in New Issue
Block a user