home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qasyncimageio.h.z / qasyncimageio.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  4.0 KB  |  167 lines

  1. /****************************************************************************
  2. ** $Id: qasyncimageio.h,v 1.18 1998/07/03 00:09:30 hanord Exp $
  3. **
  4. **              ***   INTERNAL HEADER FILE   ***
  5. **
  6. **        This file is NOT a part of the Qt interface!
  7. **
  8. ** Definition of asynchronous image/movie loading classes
  9. **
  10. ** Created : 970617
  11. **
  12. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  13. **
  14. ** This file is part of Qt Free Edition, version 1.40.
  15. **
  16. ** See the file LICENSE included in the distribution for the usage
  17. ** and distribution terms, or http://www.troll.no/free-license.html.
  18. **
  19. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  20. ** your own programs or libraries.
  21. **
  22. ** Please see http://www.troll.no/pricing.html for information about 
  23. ** Qt Professional Edition, which is this same library but with a
  24. ** license which allows creation of commercial/proprietary software.
  25. **
  26. *****************************************************************************/
  27.  
  28. #ifndef QASYNCIMAGEIO_H
  29. #define QASYNCIMAGEIO_H
  30.  
  31. #ifndef QT_H
  32. #include "qimage.h"
  33. #endif // QT_H
  34.  
  35.  
  36.  
  37. class QImageConsumer {
  38. public:
  39.     virtual void changed(const QRect&)=0;
  40.     virtual void end()=0;
  41.     virtual void frameDone()=0;
  42.     virtual void setLooping(int)=0;
  43.     virtual void setFramePeriod(int)=0;
  44.     virtual void setSize(int, int)=0;
  45. };
  46.  
  47. class QImageFormat {
  48. public:
  49.     virtual ~QImageFormat();
  50.     virtual int decode(QImage& img, QImageConsumer* consumer,
  51.         const uchar* buffer, int length)=0;
  52. };
  53.  
  54. class QImageFormatType {
  55. public:
  56.     virtual ~QImageFormatType();
  57.     virtual QImageFormat* decoderFor(const uchar* buffer, int length)=0;
  58.     virtual const char* formatName() const=0;
  59. protected:
  60.     QImageFormatType();
  61. };
  62.  
  63. struct QImageDecoderPrivate;
  64.  
  65. class QImageDecoder {
  66. public:
  67.     QImageDecoder(QImageConsumer* c);
  68.     ~QImageDecoder();
  69.  
  70.     const QImage& image() { return img; }
  71.     int decode(const uchar* buffer, int length);
  72.  
  73.     static const char* formatName(const uchar* buffer, int length);
  74.  
  75.     static QStrList inputFormats();
  76.     static void registerDecoderFactory(QImageFormatType*);
  77.     static void unregisterDecoderFactory(QImageFormatType*);
  78.  
  79. private:
  80.     QImageFormat* actual_decoder;
  81.     QImageConsumer* consumer;
  82.     QImage img;
  83.     QImageDecoderPrivate *d;
  84. };
  85.  
  86.  
  87. class QGIFFormat : public QImageFormat {
  88. public:
  89.     QGIFFormat();
  90.     virtual ~QGIFFormat();
  91.  
  92.     int decode(QImage& img, QImageConsumer* consumer,
  93.         const uchar* buffer, int length);
  94.  
  95. private:
  96.     void fillRect(QImage&, int x, int y, int w, int h, uchar col);
  97.  
  98.     // GIF specific stuff
  99.     QRgb* globalcmap;
  100.     QImage backingstore;
  101.     unsigned char hold[16];
  102.     bool gif89;
  103.     int count;
  104.     int ccount;
  105.     int expectcount;
  106.     enum State {
  107.     Header,
  108.     LogicalScreenDescriptor,
  109.     GlobalColorMap,
  110.     LocalColorMap,
  111.     Introducer,
  112.     ImageDescriptor,
  113.     TableImageLZWSize,
  114.     ImageDataBlockSize,
  115.     ImageDataBlock,
  116.     ExtensionLabel,
  117.     GraphicControlExtension,
  118.     ApplicationExtension,
  119.     NetscapeExtensionBlockSize,
  120.     NetscapeExtensionBlock,
  121.     SkipBlockSize,
  122.     SkipBlock,
  123.     Done,
  124.     Error
  125.     } state;
  126.     int gncols;
  127.     int ncols;
  128.     int lzwsize;
  129.     bool lcmap;
  130.     int swidth, sheight;
  131.     int left, top, right, bottom;
  132.     enum Disposal { NoDisposal, DoNotChange, RestoreBackground, RestoreImage };
  133.     Disposal disposal;
  134.     bool disposed;
  135.     int trans;
  136.     bool preserve_trans;
  137.     bool gcmap;
  138.     int bgcol;
  139.     int interlace;
  140.     int accum;
  141.     int bitcount;
  142.  
  143.     enum { max_lzw_bits=12 }; // (poor-compiler's static const int)
  144.  
  145.     int code_size, clear_code, end_code, max_code_size, max_code;
  146.     int firstcode, oldcode, incode;
  147.     short table[2][1<< max_lzw_bits];
  148.     short stack[(1<<(max_lzw_bits))*2];
  149.     short *sp;
  150.     bool needfirst;
  151.     int x, y;
  152.     int frame;
  153.     bool out_of_bounds;
  154.     bool digress;
  155.     void nextY(QImage& img, QImageConsumer* consumer);
  156.     void disposePrevious( QImage& img, QImageConsumer* consumer );
  157. };
  158.  
  159. class QGIFFormatType : public QImageFormatType
  160. {
  161.     QImageFormat* decoderFor(const uchar* buffer, int length);
  162.     const char* formatName() const;
  163. };
  164.  
  165.  
  166. #endif // QASYNCIMAGEIO_H
  167.