home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qimage.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  12KB  |  417 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qimage.h   3.0.0   edited Sep 5 18:49 $
  3. **
  4. ** Definition of QImage and QImageIO classes
  5. **
  6. ** Created : 950207
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the kernel module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QIMAGE_H
  39. #define QIMAGE_H
  40.  
  41. #ifndef QT_H
  42. #include "qpixmap.h"
  43. #include "qstrlist.h"
  44. #include "qstringlist.h"
  45. #endif // QT_H
  46.  
  47. class QImageDataMisc; // internal
  48. #ifndef QT_NO_IMAGE_TEXT
  49. class Q_EXPORT QImageTextKeyLang {
  50. public:
  51.     QImageTextKeyLang(const char* k, const char* l) : key(k), lang(l) { }
  52.     QImageTextKeyLang() { }
  53.  
  54.     QCString key;
  55.     QCString lang;
  56.  
  57.     bool operator< (const QImageTextKeyLang& other) const
  58.     { return key < other.key || key==other.key && lang < other.lang; }
  59.     bool operator== (const QImageTextKeyLang& other) const
  60.     { return key==other.key && lang==other.lang; }
  61. };
  62. #endif //QT_NO_IMAGE_TEXT
  63.  
  64.  
  65. class Q_EXPORT QImage
  66. {
  67. public:
  68.     enum Endian { IgnoreEndian, BigEndian, LittleEndian };
  69.  
  70.     QImage();
  71.     QImage( int width, int height, int depth, int numColors=0,
  72.         Endian bitOrder=IgnoreEndian );
  73.     QImage( const QSize&, int depth, int numColors=0,
  74.         Endian bitOrder=IgnoreEndian );
  75. #ifndef QT_NO_IMAGEIO
  76.     QImage( const QString &fileName, const char* format=0 );
  77.     QImage( const char * const xpm[] );
  78.     QImage( const QByteArray &data );
  79. #endif
  80.     QImage( uchar* data, int w, int h, int depth,
  81.         QRgb* colortable, int numColors,
  82.         Endian bitOrder );
  83. #ifdef Q_WS_QWS
  84.     QImage( uchar* data, int w, int h, int depth, int pbl,
  85.         QRgb* colortable, int numColors,
  86.         Endian bitOrder );
  87. #endif
  88.     QImage( const QImage & );
  89.    ~QImage();
  90.  
  91.     QImage     &operator=( const QImage & );
  92.     QImage     &operator=( const QPixmap & );
  93.     bool    operator==( const QImage & ) const;
  94.     bool    operator!=( const QImage & ) const;
  95.     void    detach();
  96.     QImage    copy()        const;
  97.     QImage    copy(int x, int y, int w, int h, int conversion_flags=0) const;
  98.     QImage    copy(const QRect&)    const;
  99.  
  100.     bool    isNull()    const    { return data->bits == 0; }
  101.  
  102.     int        width()        const    { return data->w; }
  103.     int        height()    const    { return data->h; }
  104.     QSize    size()        const    { return QSize(data->w,data->h); }
  105.     QRect    rect()        const    { return QRect(0,0,data->w,data->h); }
  106.     int        depth()        const    { return data->d; }
  107.     int        numColors()    const    { return data->ncols; }
  108.     Endian    bitOrder()    const    { return (Endian) data->bitordr; }
  109.  
  110.     QRgb    color( int i )    const;
  111.     void    setColor( int i, QRgb c );
  112.     void    setNumColors( int );
  113.  
  114.     bool    hasAlphaBuffer() const;
  115.     void    setAlphaBuffer( bool );
  116.  
  117.     bool    allGray() const;
  118.     bool        isGrayscale() const;
  119.  
  120.     uchar      *bits()        const;
  121.     uchar      *scanLine( int ) const;
  122.     uchar     **jumpTable()    const;
  123.     QRgb       *colorTable()    const;
  124.     int        numBytes()    const;
  125.     int        bytesPerLine()    const;
  126.  
  127. #ifdef Q_WS_QWS
  128.     QGfx * graphicsContext();
  129. #endif
  130.  
  131.     bool    create( int width, int height, int depth, int numColors=0,
  132.             Endian bitOrder=IgnoreEndian );
  133.     bool    create( const QSize&, int depth, int numColors=0,
  134.             Endian bitOrder=IgnoreEndian );
  135.     void    reset();
  136.  
  137.     void    fill( uint pixel );
  138.     void    invertPixels( bool invertAlpha = TRUE );
  139.  
  140.     QImage    convertDepth( int ) const;
  141. #ifndef QT_NO_IMAGE_TRUECOLOR
  142.     QImage    convertDepthWithPalette( int, QRgb* p, int pc, int cf=0 ) const;
  143. #endif
  144.     QImage    convertDepth( int, int conversion_flags ) const;
  145.     QImage    convertBitOrder( Endian ) const;
  146.  
  147.     enum ScaleMode {
  148.     ScaleFree,
  149.     ScaleMin,
  150.     ScaleMax
  151.     };
  152. #ifndef QT_NO_IMAGE_SMOOTHSCALE
  153.     QImage smoothScale( int w, int h, ScaleMode mode=ScaleFree ) const;
  154.     QImage smoothScale( const QSize& s, ScaleMode mode=ScaleFree ) const;
  155. #endif
  156. #ifndef QT_NO_IMAGE_TRANSFORMATION
  157.     QImage scale( int w, int h, ScaleMode mode=ScaleFree ) const;
  158.     QImage scale( const QSize& s, ScaleMode mode=ScaleFree ) const;
  159.     QImage scaleWidth( int w ) const;
  160.     QImage scaleHeight( int h ) const;
  161.     QImage xForm( const QWMatrix &matrix ) const;
  162. #endif
  163.  
  164. #ifndef QT_NO_IMAGE_DITHER_TO_1
  165.     QImage    createAlphaMask( int conversion_flags=0 ) const;
  166. #endif
  167. #ifndef QT_NO_IMAGE_HEURISTIC_MASK
  168.     QImage    createHeuristicMask( bool clipTight=TRUE ) const;
  169. #endif
  170. #ifndef QT_NO_IMAGE_MIRROR
  171.     QImage    mirror() const;
  172.     QImage    mirror(bool horizontally, bool vertically) const;
  173. #endif
  174.     QImage    swapRGB() const;
  175.  
  176.     static Endian systemBitOrder();
  177.     static Endian systemByteOrder();
  178.  
  179. #ifndef QT_NO_IMAGEIO
  180.     static const char* imageFormat( const QString &fileName );
  181.     static QStrList inputFormats();
  182.     static QStrList outputFormats();
  183. #ifndef QT_NO_STRINGLIST
  184.     static QStringList inputFormatList();
  185.     static QStringList outputFormatList();
  186. #endif
  187.     bool    load( const QString &fileName, const char* format=0 );
  188.     bool    loadFromData( const uchar *buf, uint len,
  189.                   const char *format=0 );
  190.     bool    loadFromData( QByteArray data, const char* format=0 );
  191.     bool    save( const QString &fileName, const char* format,
  192.               int quality=-1 ) const;
  193. #endif //QT_NO_IMAGEIO
  194.  
  195.     bool    valid( int x, int y ) const;
  196.     int        pixelIndex( int x, int y ) const;
  197.     QRgb    pixel( int x, int y ) const;
  198.     void    setPixel( int x, int y, uint index_or_rgb );
  199.  
  200.     // Auxiliary data
  201.     int dotsPerMeterX() const;
  202.     int dotsPerMeterY() const;
  203.     void setDotsPerMeterX(int);
  204.     void setDotsPerMeterY(int);
  205.     QPoint offset() const;
  206.     void setOffset(const QPoint&);
  207. #ifndef QT_NO_IMAGE_TEXT
  208.     QValueList<QImageTextKeyLang> textList() const;
  209.     QStringList textLanguages() const;
  210.     QStringList textKeys() const;
  211.     QString text(const char* key, const char* lang=0) const;
  212.     QString text(const QImageTextKeyLang&) const;
  213.     void setText(const char* key, const char* lang, const QString&);
  214. #endif
  215. private:
  216.     void    init();
  217.     void    reinit();
  218.     void    freeBits();
  219.     static void    warningIndexRange( const char *, int );
  220.     QSize    scaleSize( const QSize &s, ScaleMode mode ) const;
  221.  
  222.     struct QImageData : public QShared {    // internal image data
  223.     int    w;                // image width
  224.     int    h;                // image height
  225.     int    d;                // image depth
  226.     int    ncols;                // number of colors
  227.     int    nbytes;                // number of bytes data
  228.     int    bitordr;            // bit order (1 bit depth)
  229.     QRgb   *ctbl;                // color table
  230.     uchar **bits;                // image data
  231.     bool    alpha;                // alpha buffer
  232.     int    dpmx;                // dots per meter X (or 0)
  233.     int    dpmy;                // dots per meter Y (or 0)
  234.     QPoint    offset;                // offset in pixels
  235. #ifndef QT_NO_IMAGE_TEXT
  236.     QImageDataMisc* misc;            // less common stuff
  237. #endif
  238.     bool    ctbl_mine;            // this allocated ctbl
  239.     } *data;
  240. #ifndef QT_NO_IMAGE_TEXT
  241.     QImageDataMisc& misc() const;
  242. #endif
  243.     friend Q_EXPORT void bitBlt( QImage* dst, int dx, int dy,
  244.                  const QImage* src, int sx, int sy,
  245.                  int sw, int sh, int conversion_flags );
  246. };
  247.  
  248.  
  249. // QImage stream functions
  250.  
  251. #if !defined(QT_NO_DATASTREAM) && !defined(QT_NO_IMAGEIO)
  252. Q_EXPORT QDataStream &operator<<( QDataStream &, const QImage & );
  253. Q_EXPORT QDataStream &operator>>( QDataStream &, QImage & );
  254. #endif
  255.  
  256. #ifndef QT_NO_IMAGEIO
  257. class QIODevice;
  258. typedef void (*image_io_handler)( QImageIO * ); // image IO handler
  259.  
  260.  
  261. struct QImageIOData;
  262.  
  263.  
  264. class Q_EXPORT QImageIO
  265. {
  266. public:
  267.     QImageIO();
  268.     QImageIO( QIODevice     *ioDevice, const char *format );
  269.     QImageIO( const QString &fileName, const char* format );
  270.    ~QImageIO();
  271.  
  272.  
  273.     const QImage &image()    const    { return im; }
  274.     int        status()    const    { return iostat; }
  275.     const char *format()    const    { return frmt; }
  276.     QIODevice  *ioDevice()    const    { return iodev; }
  277.     QString    fileName()    const    { return fname; }
  278.     int        quality()    const;
  279.     QString    description()    const    { return descr; }
  280.     const char *parameters()    const;
  281.     float gamma() const;
  282.  
  283.     void    setImage( const QImage & );
  284.     void    setStatus( int );
  285.     void    setFormat( const char * );
  286.     void    setIODevice( QIODevice * );
  287.     void    setFileName( const QString & );
  288.     void    setQuality( int );
  289.     void    setDescription( const QString & );
  290.     void    setParameters( const char * );
  291.     void    setGamma( float );
  292.     
  293.     bool    read();
  294.     bool    write();
  295.  
  296.     static const char* imageFormat( const QString &fileName );
  297.     static const char *imageFormat( QIODevice * );
  298.     static QStrList inputFormats();
  299.     static QStrList outputFormats();
  300.  
  301.     static void defineIOHandler( const char *format,
  302.                  const char *header,
  303.                  const char *flags,
  304.                  image_io_handler read_image,
  305.                  image_io_handler write_image );
  306.  
  307. private:
  308.     void    init();
  309.  
  310.     QImage    im;                // image
  311.     int        iostat;                // IO status
  312.     QCString    frmt;                // image format
  313.     QIODevice  *iodev;                // IO device
  314.     QString    fname;                // file name
  315.     char       *params;                // image parameters //### change to QImageIOData *d in 3.0
  316.     QString     descr;                // image description
  317.     QImageIOData *d;
  318.  
  319. private:    // Disabled copy constructor and operator=
  320. #if defined(Q_DISABLE_COPY)
  321.     QImageIO( const QImageIO & );
  322.     QImageIO &operator=( const QImageIO & );
  323. #endif
  324. };
  325.  
  326. #endif //QT_NO_IMAGEIO
  327.  
  328. Q_EXPORT void bitBlt( QImage* dst, int dx, int dy, const QImage* src,
  329.               int sx=0, int sy=0, int sw=-1, int sh=-1,
  330.               int conversion_flags=0 );
  331.  
  332.  
  333. /*****************************************************************************
  334.   QImage member functions
  335.  *****************************************************************************/
  336.  
  337. inline bool QImage::hasAlphaBuffer() const
  338. {
  339.     return data->alpha;
  340. }
  341.  
  342. inline uchar *QImage::bits() const
  343. {
  344.     return data->bits ? data->bits[0] : 0;
  345. }
  346.  
  347. inline uchar **QImage::jumpTable() const
  348. {
  349.     return data->bits;
  350. }
  351.  
  352. inline QRgb *QImage::colorTable() const
  353. {
  354.     return data->ctbl;
  355. }
  356.  
  357. inline int QImage::numBytes() const
  358. {
  359.     return data->nbytes;
  360. }
  361.  
  362. inline int QImage::bytesPerLine() const
  363. {
  364.     return data->h ? data->nbytes/data->h : 0;
  365. }
  366.  
  367. inline QImage QImage::copy(const QRect& r) const
  368. {
  369.     return copy(r.x(), r.y(), r.width(), r.height());
  370. }
  371.  
  372. inline QRgb QImage::color( int i ) const
  373. {
  374. #if defined(QT_CHECK_RANGE)
  375.     if ( i >= data->ncols )
  376.     warningIndexRange( "color", i );
  377. #endif
  378.     return data->ctbl ? data->ctbl[i] : (QRgb)-1;
  379. }
  380.  
  381. inline void QImage::setColor( int i, QRgb c )
  382. {
  383. #if defined(QT_CHECK_RANGE)
  384.     if ( i >= data->ncols )
  385.     warningIndexRange( "setColor", i );
  386. #endif
  387.     if ( data->ctbl )
  388.     data->ctbl[i] = c;
  389. }
  390.  
  391. inline uchar *QImage::scanLine( int i ) const
  392. {
  393. #if defined(QT_CHECK_RANGE)
  394.     if ( i >= data->h )
  395.     warningIndexRange( "scanLine", i );
  396. #endif
  397.     return data->bits ? data->bits[i] : 0;
  398. }
  399.  
  400. inline int QImage::dotsPerMeterX() const
  401. {
  402.     return data->dpmx;
  403. }
  404.  
  405. inline int QImage::dotsPerMeterY() const
  406. {
  407.     return data->dpmy;
  408. }
  409.  
  410. inline QPoint QImage::offset() const
  411. {
  412.     return data->offset;
  413. }
  414.  
  415.  
  416. #endif // QIMAGE_H
  417.