gifdecod.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gifdecod.h
  3. // Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
  4. // Author: Guillermo Rodriguez Garcia <guille@iies.es>
  5. // Version: 3.02
  6. // Copyright: (c) 1999 Guillermo Rodriguez Garcia
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_GIFDECOD_H_
  10. #define _WX_GIFDECOD_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_STREAMS && wxUSE_GIF
  13. #include "wx/stream.h"
  14. #include "wx/image.h"
  15. #include "wx/animdecod.h"
  16. #include "wx/dynarray.h"
  17. // internal utility used to store a frame in 8bit-per-pixel format
  18. class GIFImage;
  19. // --------------------------------------------------------------------------
  20. // Constants
  21. // --------------------------------------------------------------------------
  22. // Error codes:
  23. // Note that the error code wxGIF_TRUNCATED means that the image itself
  24. // is most probably OK, but the decoder didn't reach the end of the data
  25. // stream; this means that if it was not reading directly from file,
  26. // the stream will not be correctly positioned.
  27. //
  28. enum wxGIFErrorCode
  29. {
  30. wxGIF_OK = 0, // everything was OK
  31. wxGIF_INVFORMAT, // error in GIF header
  32. wxGIF_MEMERR, // error allocating memory
  33. wxGIF_TRUNCATED // file appears to be truncated
  34. };
  35. // --------------------------------------------------------------------------
  36. // wxGIFDecoder class
  37. // --------------------------------------------------------------------------
  38. class WXDLLIMPEXP_CORE wxGIFDecoder : public wxAnimationDecoder
  39. {
  40. public:
  41. // constructor, destructor, etc.
  42. wxGIFDecoder();
  43. ~wxGIFDecoder();
  44. // get data of current frame
  45. unsigned char* GetData(unsigned int frame) const;
  46. unsigned char* GetPalette(unsigned int frame) const;
  47. unsigned int GetNcolours(unsigned int frame) const;
  48. int GetTransparentColourIndex(unsigned int frame) const;
  49. wxColour GetTransparentColour(unsigned int frame) const;
  50. virtual wxSize GetFrameSize(unsigned int frame) const;
  51. virtual wxPoint GetFramePosition(unsigned int frame) const;
  52. virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const;
  53. virtual long GetDelay(unsigned int frame) const;
  54. // GIFs can contain both static images and animations
  55. bool IsAnimation() const
  56. { return m_nFrames > 1; }
  57. // load function which returns more info than just Load():
  58. wxGIFErrorCode LoadGIF( wxInputStream& stream );
  59. // free all internal frames
  60. void Destroy();
  61. // implementation of wxAnimationDecoder's pure virtuals
  62. virtual bool Load( wxInputStream& stream )
  63. { return LoadGIF(stream) == wxGIF_OK; }
  64. bool ConvertToImage(unsigned int frame, wxImage *image) const;
  65. wxAnimationDecoder *Clone() const
  66. { return new wxGIFDecoder; }
  67. wxAnimationType GetType() const
  68. { return wxANIMATION_TYPE_GIF; }
  69. private:
  70. // wxAnimationDecoder pure virtual
  71. virtual bool DoCanRead( wxInputStream& stream ) const;
  72. // modifies current stream position (see wxAnimationDecoder::CanRead)
  73. int getcode(wxInputStream& stream, int bits, int abfin);
  74. wxGIFErrorCode dgif(wxInputStream& stream,
  75. GIFImage *img, int interl, int bits);
  76. // array of all frames
  77. wxArrayPtrVoid m_frames;
  78. // decoder state vars
  79. int m_restbits; // remaining valid bits
  80. unsigned int m_restbyte; // remaining bytes in this block
  81. unsigned int m_lastbyte; // last byte read
  82. unsigned char m_buffer[256]; // buffer for reading
  83. unsigned char *m_bufp; // pointer to next byte in buffer
  84. wxDECLARE_NO_COPY_CLASS(wxGIFDecoder);
  85. };
  86. #endif // wxUSE_STREAMS && wxUSE_GIF
  87. #endif // _WX_GIFDECOD_H_