include/imageutils/imageblock.h

Go to the documentation of this file.
00001 
00002 // Name:        imageblock.h
00003 // Purpose:     A block of image data
00004 // Author:      Julian Smart
00005 // Modified by:
00006 // Created:     2006-05-11
00007 // RCS-ID:      $$
00008 // Copyright:   (c) Julian Smart
00009 // Licence:     New BSD License
00011 
00012 #ifndef _WX_IMAGEBLOCK_H_
00013 #define _WX_IMAGEBLOCK_H_
00014 
00015 #include "wx/defs.h"
00016 #include "wx/variant.h"
00017 #include "wx/image.h"
00018 
00023 class WXDLLIMPEXP_BASE wxDataInputStream;
00024 class WXDLLIMPEXP_BASE wxDataOutputStream;
00025 
00026 class wxImageBlock: public wxObject
00027 {
00028 public:
00029     wxImageBlock();
00030     wxImageBlock(const wxImageBlock& block);
00031     ~wxImageBlock();
00032 
00033     void Init();
00034     void Clear();
00035 
00036     // Load the original image into a memory block.
00037     // If the image is not a JPEG, we must convert it into a JPEG
00038     // to conserve space.
00039     // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
00040     // load the image a 2nd time.
00041     virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = true);
00042 
00043     // Make an image block from the wxImage in the given
00044     // format.
00045     virtual bool MakeImageBlock(const wxString& filename, wxImage& image, int imageType = wxBITMAP_TYPE_PNG, int quality = 80);
00046     virtual bool MakeImageBlock(wxImage& image, int imageType = wxBITMAP_TYPE_PNG, int quality = 80);
00047     virtual bool MakeImageBlock(const wxImage& image, int imageType = wxBITMAP_TYPE_PNG, int quality = 80);
00048 
00049     // Write to a file
00050     bool Write(const wxString& filename);
00051 
00052     // Write to a stream
00053     bool Write(wxOutputStream& stream);
00054     bool Write(wxOutputStream& stream, wxDataOutputStream& dataStream);
00055 
00056     // Write data in hex to a stream
00057     bool WriteHex(wxOutputStream& stream);
00058 
00059     // Read data in hex from a stream
00060     bool ReadHex(wxInputStream& stream, int length, int imageType);
00061 
00062     // Read from a stream
00063     bool Read(wxInputStream& stream);
00064     bool Read(wxInputStream& stream, wxDataInputStream& dataStream);
00065 
00066     // Copy from 'block'
00067     void Copy(const wxImageBlock& block);
00068 
00069     // Load a wxImage from the block
00070     bool Load(wxImage& image);
00071 
00073     void operator=(const wxImageBlock& block);
00074 
00076 
00077     unsigned char* GetData() const { return m_data; }
00078     size_t GetDataSize() const { return m_dataSize; }
00079     int GetImageType() const { return m_imageType; }
00080 
00081     void SetData(unsigned char* image) { m_data = image; }
00082     void SetDataSize(size_t size) { m_dataSize = size; }
00083     void SetImageType(int imageType) { m_imageType = imageType; }
00084 
00085     bool Ok() const { return GetData() != NULL; }
00086     
00088 
00090     static unsigned char* ReadBlock(wxInputStream& stream, size_t size);
00091     static unsigned char* ReadBlock(const wxString& filename, size_t size);
00092 
00093     // Write memory block to stream
00094     static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size);
00095 
00096     // Write memory block to file
00097     static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size);
00098 
00099     // Returns the image type, or -1, determined from the extension.
00100     static int DetermineImageType(const wxString& filename);
00101 
00102     // Return an extension for the given file type
00103     static wxString DetermineExtension(int imageType = -1);
00104 
00105 protected:
00106     // Size in bytes of the image stored.
00107     // This is in the raw, original form such as a JPEG file.
00108     unsigned char*      m_data;
00109     size_t              m_dataSize;
00110     int                 m_imageType; // wxWin type id
00111 };
00112 
00113 #endif
00114     // _WX_IMAGEBLOCK_H_

Generated on Wed May 6 19:20:19 2009 for AxTk by  doxygen 1.5.1