QSDK 1.1 Documentation
Main Page | Modules | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

image.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1999-2003 Qube Software, Ltd.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are
00007  * met:
00008  *
00009  * 1. Redistributions of the source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  *
00012  * 2. Any redistribution solely in binary form must conspicuously
00013  *    reproduce the following disclaimer in documentation provided with the
00014  *    binary redistribution.
00015  *
00016  * THIS SOFTWARE IS PROVIDED ``AS IS'', WITHOUT ANY WARRANTIES, EXPRESS
00017  * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  LICENSOR SHALL
00019  * NOT BE LIABLE FOR ANY LOSS OR DAMAGES RESULTING FROM THE USE OF THIS
00020  * SOFTWARE, EITHER ALONE OR IN COMBINATION WITH ANY OTHER SOFTWARE.
00021  *
00022  *      $Qube: Q/image/sdk/image.h,v 1.38.2.1 2003/09/24 14:20:09 jamief Exp $
00023  */
00024 
00025 #ifndef __image_h__
00026 #define __image_h__
00027 
00032 #define QImage_version  10002000
00033 
00034 #ifndef IMAGE_BEGIN
00035 #define IMAGE_BEGIN     namespace Image {
00036 #define IMAGE_END       }
00037 #endif
00038 
00039 #include <Q/linkage.h>
00040 
00041 namespace Net {
00042     struct ReadStream;
00043     struct WriteStream;
00044 };
00045 
00046 IMAGE_BEGIN
00047 
00058 struct Pixmap;
00059 
00066 struct PixelIterator
00067 {
00071     enum Type {
00075         Single,
00076 
00081         Double
00082     };
00083 
00084     virtual                     ~PixelIterator() {}
00085 
00090     virtual Maths::Color4b      get() const = 0;
00091 
00095     virtual void                put(const Maths::Color4b&) = 0;
00096 
00103     virtual size_t              read(Maths::Color4b* buf, size_t n) = 0;
00104 
00111     virtual size_t              write(const Maths::Color4b* buf, size_t n) = 0;
00112 
00117     virtual bool                next() = 0;
00118 
00122     virtual bool                valid() = 0;
00123 
00127     virtual void                set(unsigned int x, unsigned int y) = 0;
00128 };
00129 
00135 struct Format : public Utils::Object
00136 {
00141     enum Type {
00142         Unknown,        // This is used for formats implemented elsewhere .
00143         RGB565,
00144         RGBA5551,
00145         RGBA4444,
00146         RGB888,
00147         RGBA8888,
00148         BGR565,
00149         BGRA5551,
00150         BGRA4444,
00151         BGR888,
00152         BGRA8888,
00153         GREY8,
00154         IDX8,
00155         IDX4
00156     };
00157 
00158     typedef Utils::Ref<Format> REF;
00159 
00163     static EXPORT_QIMAGE Format* create(Type);
00164 
00165     virtual                     ~Format() {}
00166 
00170     virtual size_t              bitsPerPixel() const = 0;
00171 
00176     virtual bool                hasAlpha() const = 0;
00177 
00181     virtual Type                type() const = 0;
00182 
00186     virtual Maths::Color4b      get(unsigned int x,
00187                                     unsigned int y,
00188                                     const Pixmap*) const = 0;
00189 
00193     virtual void*               getScanlineAddress(unsigned int y,
00194                                                    Pixmap*) const = 0;
00195 
00199     virtual void                put(unsigned int x,
00200                                     unsigned int y,
00201                                     const Maths::Color4b& pixel,
00202                                     Pixmap*) const = 0;
00203 
00208     virtual PixelIterator*      createIterator(Pixmap*,
00209                                                PixelIterator::Type) const = 0;
00210 };
00211 
00218 struct IndexedColorFormat : public Format
00219 {
00220     typedef Utils::Ref<IndexedColorFormat> REF;
00221 
00226     static EXPORT_QIMAGE IndexedColorFormat* create(Type);
00227 
00228     // Palette controls
00233     virtual size_t              entries() const = 0;
00234 
00238     virtual void                setEntry(unsigned int idx,
00239                                          const Maths::Color4b& value) = 0;
00240 
00244     virtual Maths::Color4b      getEntry(unsigned int idx) const = 0;
00245 
00250     virtual unsigned int        getIndex(unsigned int x,
00251                                          unsigned int y,
00252                                          const Pixmap* p) const = 0;
00253 
00257     virtual void                putIndex(unsigned int x,
00258                                          unsigned int y,
00259                                          unsigned int idx,
00260                                          const Pixmap*) const = 0;
00261 };
00262 
00272 struct EXPORT_QIMAGE Pixmap : public Utils::Object
00273 {
00274     typedef Utils::Ref<Pixmap> REF;
00275 
00280                         Pixmap(unsigned int width,
00281                                unsigned int height,
00282                                Format* format);
00283 
00294                         Pixmap(unsigned int width,
00295                                unsigned int height,
00296                                unsigned int stride,
00297                                void* data,
00298                                Format* format);
00299 
00303                         ~Pixmap();
00304 
00308     unsigned int        width() const { return width_; }
00309 
00313     unsigned int        height() const { return height_; }
00314 
00318     unsigned int        stride() const { return stride_; }
00319 
00323     unsigned int        depth() const { return format_->bitsPerPixel(); }
00324 
00328     Format*             format() const { return format_; }
00329 
00333     void*               data() const { return bits_; }
00334 
00340     void                copyTo(Pixmap* dest) const;
00341 
00348     void                copyFrom(Pixmap* source, const Maths::Vec2ui& off);
00349 
00350 private:
00351     void                init();
00352 
00353     unsigned short      width_;
00354     unsigned short      height_;
00355     unsigned int        stride_;        // bytes per line
00356     Format::REF         format_;        // what kind of image
00357     void*               bits_;          // image data
00358     bool                ownsData_;      // Did we allocate bits_ ?
00359 };
00360 
00368 struct Source : public Utils::Object
00369 {
00370     typedef Utils::Ref<Source> REF;
00371 
00372     virtual             ~Source() {}
00373 
00377     virtual unsigned int width() = 0;
00378 
00382     virtual unsigned int height() = 0;
00383 
00387     virtual Format*     format() = 0;
00388 
00395     virtual bool        unpack(Pixmap*, unsigned int scanlines = 0) = 0;
00396 
00401     virtual bool        isValid() = 0;
00402 
00409     static EXPORT_QIMAGE
00410     Source*     create(const char* filename);
00411 
00419     static EXPORT_QIMAGE
00420     Source*     create(Net::ReadStream*);
00421 
00422 };
00423 
00431 struct Destination : public Utils::Object
00432 {
00433     typedef Utils::Ref<Destination> REF;
00434 
00435     virtual             ~Destination() {}
00436 
00440     virtual void        pack() = 0;
00441 
00446     static EXPORT_QIMAGE
00447     Destination*        create(const char* filename, Image::Pixmap*);
00448 
00454     static EXPORT_QIMAGE
00455     Destination*        create(Net::WriteStream*, Image::Pixmap*);
00456 };
00457 
00458 
00459 IMAGE_END
00460 
00461 #endif // __image_h__
00462 
00463 // Local Variables:
00464 // mode: c++
00465 // End:

Return to QSDK documentation Contents page. Contact details for support, information and fault-reporting.
Qube Software Limited © 2000-2004