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;
#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
#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
#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
};
#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
#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
#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
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');
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();
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;
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;
}
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);
return FALSE;
}
-bool wxImageHandler::CanRead( wxInputStream& WXUNUSED(stream) )
-{
- return FALSE;
-}
-
bool wxImageHandler::CanRead( const wxString& name )
{
#if wxUSE_STREAMS
// 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 );
}
{
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
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;
decod = new wxGIFDecoder(&stream, TRUE);
if ((error = decod->ReadGIF()) != E_OK)
- {
+ {
if (verbose)
{
switch (error)
return FALSE;
}
-bool wxGIFHandler::CanRead( wxInputStream& stream )
+bool wxGIFHandler::DoCanRead( wxInputStream& stream )
{
wxGIFDecoder *decod;
bool ok;
#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"
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
-
+
JOCTET* buffer; /* start of buffer */
} my_source_mgr;
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;
}
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));
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;
// 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;
JSAMPARRAY tempbuf;
unsigned char *ptr;
unsigned stride;
-
+
image->Destroy();
cinfo.err = jpeg_std_error( &jerr.pub );
jerr.pub.error_exit = my_error_exit;
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 );
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 );
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,
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;
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;
{
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;
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];
}
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);
# include "wx/defs.h"
#endif
-#if wxUSE_STREAMS && wxUSE_PCX
+#if wxUSE_STREAMS && wxUSE_PCX
#include "wx/image.h"
#include "wx/wfstream.h"
/* 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
{
*(dst++) = p[i];
*(dst++) = p[i + bytesperline];
- *(dst++) = p[i + 2 * bytesperline];
+ *(dst++) = p[i + 2 * bytesperline];
}
break;
}
return FALSE;
}
-bool wxPCXHandler::CanRead( wxInputStream& stream )
+bool wxPCXHandler::DoCanRead( wxInputStream& stream )
{
unsigned char c;
off_t pos;
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)
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()))
return TRUE;
}
-bool wxPNGHandler::CanRead( wxInputStream& stream )
+bool wxPNGHandler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[4];
wxString line;
wxTextInputStream text_stream(stream);
- if (stream.Peek()==wxT('#'))
+ if (stream.Peek()==wxT('#'))
{
text_stream >> line;
Skip_Comment(stream);
wxUint16 maxval;
wxString line;
char c(0);
-
+
image->Destroy();
/*
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;
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;
-
- if (buf_stream.LastError()!=wxSTREAM_NOERROR)
- {
- wxLogError(wxT("Loading PNM image : file seems truncated."));
- return FALSE;
- }
- }
+ {
+ 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 (c=='6') // Raw RGB
buf_stream.Read( ptr, 3*width*height );
bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUSED(verbose) )
{
wxTextOutputStream text_stream(stream);
-
- //text_stream << "P6" << endl
- //<< image->GetWidth() << " " << 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());
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;