Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

corona.h

Go to the documentation of this file.
00001 
00019 #ifndef CORONA_H
00020 #define CORONA_H
00021 
00022 
00023 #ifndef __cplusplus
00024 #error Corona requires C++
00025 #endif
00026 
00027 
00028 #include <stddef.h>
00029 
00030 
00031 // DLLs in Windows should use the standard calling convention
00032 #ifndef COR_CALL
00033 #  if defined(WIN32) || defined(_WIN32)
00034 #    define COR_CALL __stdcall
00035 #  else
00036 #    define COR_CALL
00037 #  endif
00038 #endif
00039 
00040 // Export functions from the DLL
00041 #ifndef COR_DECL
00042 #  if defined(WIN32) || defined(_WIN32)
00043 #    ifdef CORONA_EXPORTS
00044 #      define COR_DECL __declspec(dllexport)
00045 #    else
00046 #      define COR_DECL
00047 #    endif
00048 #  else
00049 #    define COR_DECL
00050 #  endif
00051 #endif
00052 
00053 
00054 // evil "identifier is too long in debug information" warning
00055 #ifdef _MSC_VER
00056 #pragma warning(disable : 4786)
00057 #endif
00058 
00059 
00060 #define COR_FUNCTION(ret) extern "C" COR_DECL ret COR_CALL
00061 
00062 
00063 namespace corona {
00064 
00068   enum FileFormat {
00069     FF_AUTODETECT = 0x0100,
00070     FF_PNG        = 0x0101,
00071     FF_JPEG       = 0x0102,
00072     FF_PCX        = 0x0103,
00073     FF_BMP        = 0x0104,
00074     FF_TGA        = 0x0105,
00075     FF_GIF        = 0x0106,
00076   };
00077 
00082   enum PixelFormat {
00083     PF_DONTCARE = 0x0200,  
00085     PF_R8G8B8A8 = 0x0201,  
00086     PF_R8G8B8   = 0x0202,  
00087     PF_I8       = 0x0203,  
00088     PF_B8G8R8A8 = 0x0204,  
00089     PF_B8G8R8   = 0x0205,  
00090   };
00091 
00096   enum CoordinateAxis {
00097     CA_X     = 0x0001,
00098     CA_Y     = 0x0002,
00099   };
00100 
00108   class DLLInterface {
00109   private:
00114     virtual void COR_CALL destroy() = 0;
00115 
00116   public:
00122     void operator delete(void* p) {
00123       if (p) {
00124         DLLInterface* i = static_cast<DLLInterface*>(p);
00125         i->destroy();
00126       }
00127     }
00128   };
00129 
00130 
00135   template<class Interface>
00136   class DLLImplementation : public Interface {
00137   public:
00142     virtual ~DLLImplementation() { }
00143 
00147     virtual void COR_CALL destroy() {
00148       delete this;
00149     }
00150 
00155     void operator delete(void* p) {
00156       ::operator delete(p);
00157     }
00158   };
00159 
00160   
00166   class Image : public DLLInterface {
00167   public:
00172     virtual int COR_CALL getWidth() = 0;
00173 
00178     virtual int COR_CALL getHeight() = 0;
00179 
00184     virtual PixelFormat COR_CALL getFormat() = 0;
00185 
00192     virtual void* COR_CALL getPixels() = 0;
00193 
00200     virtual void* COR_CALL getPalette() = 0;
00201 
00207     virtual int COR_CALL getPaletteSize() = 0;
00208 
00214     virtual PixelFormat COR_CALL getPaletteFormat() = 0;
00215   };
00216 
00217 
00224   class File : public DLLInterface {
00225   public:
00226 
00230     enum SeekMode {
00231       BEGIN,    
00232       CURRENT,  
00233       END       
00235     };
00236 
00245     virtual int COR_CALL read(void* buffer, int size) = 0;
00246 
00255     virtual int COR_CALL write(const void* buffer, int size) = 0;
00256 
00268     virtual bool COR_CALL seek(int position, SeekMode mode) = 0;
00269 
00275     virtual int COR_CALL tell() = 0;
00276   };
00277 
00278 
00280   class FileFormatDesc {
00281   protected:
00282     ~FileFormatDesc() { }
00283 
00284   public:
00286     virtual FileFormat getFormat() = 0;
00287 
00289     virtual const char* getDescription() = 0;
00290 
00293     virtual size_t getExtensionCount() = 0;
00294     virtual const char* getExtension(size_t i) = 0;
00296   };
00297 
00298 
00300   namespace hidden {
00301 
00302     // these are extern "C" so we don't mangle the names
00303 
00304 
00305     // API information
00306 
00307     COR_FUNCTION(const char*) CorGetVersion();
00308 
00309     COR_FUNCTION(FileFormatDesc**) CorGetSupportedReadFormats();
00310     COR_FUNCTION(FileFormatDesc**) CorGetSupportedWriteFormats();
00311 
00312     // creation
00313 
00314     COR_FUNCTION(Image*) CorCreateImage(
00315       int width,
00316       int height,
00317       PixelFormat format);
00318 
00319     COR_FUNCTION(Image*) CorCreateImageWithPixels(
00320       int width,
00321       int height,
00322       PixelFormat format,
00323       void* pixels);
00324 
00325     COR_FUNCTION(Image*) CorCreatePalettizedImage(
00326       int width,
00327       int height,
00328       PixelFormat format, // must be a palettized format
00329       int palette_size,
00330       PixelFormat palette_format);
00331 
00332     COR_FUNCTION(Image*) CorCloneImage(
00333       Image* source,
00334       PixelFormat format);
00335 
00336     // loading
00337 
00338     COR_FUNCTION(Image*) CorOpenImage(
00339       const char* filename,
00340       FileFormat file_format);
00341 
00342     COR_FUNCTION(Image*) CorOpenImageFromFile(
00343       File* file,
00344       FileFormat file_format);
00345 
00346     // saving
00347 
00348     COR_FUNCTION(bool) CorSaveImage(
00349       const char* filename,
00350       FileFormat file_format,
00351       Image* image);
00352 
00353     COR_FUNCTION(bool) CorSaveImageToFile(
00354       File* file,
00355       FileFormat file_format,
00356       Image* image);
00357 
00358     // conversion
00359 
00360     COR_FUNCTION(Image*) CorConvertImage(
00361       Image* image,
00362       PixelFormat format);
00363 
00364     COR_FUNCTION(Image*) CorConvertPalette(
00365       Image* image,
00366       PixelFormat palette_format);
00367 
00368     COR_FUNCTION(Image*) CorFlipImage(
00369       Image* image,
00370       int coordinate_axis);
00371 
00372     // files
00373 
00374     COR_FUNCTION(File*) CorOpenFile(const char* name, bool writeable);
00375     COR_FUNCTION(File*) CorCreateMemoryFile(const void* buffer, int size);
00376 
00377     // utility
00378 
00379     COR_FUNCTION(int) CorGetPixelSize(PixelFormat format);
00380   }
00381 
00382 
00383   /* PUBLIC API */
00384 
00385 
00391   inline const char* GetVersion() {
00392     return hidden::CorGetVersion();
00393   }
00394 
00395 
00401   inline FileFormatDesc** GetSupportedReadFormats() {
00402     return hidden::CorGetSupportedReadFormats();
00403   }
00404 
00410   inline FileFormatDesc** GetSupportedWriteFormats() {
00411     return hidden::CorGetSupportedWriteFormats();
00412   }
00413 
00414 
00430   inline Image* CreateImage(
00431     int width,
00432     int height,
00433     PixelFormat format,
00434     void* pixels = 0)
00435   {
00436     return hidden::CorCreateImageWithPixels(width, height, format, pixels);
00437   }
00438 
00449   inline Image* CreateImage(
00450     int width,
00451     int height,
00452     PixelFormat format,
00453     int palette_size,
00454     PixelFormat palette_format)
00455   {
00456     return hidden::CorCreatePalettizedImage(
00457       width, height, format,
00458       palette_size, palette_format);
00459   }
00460 
00473   inline Image* CloneImage(
00474     Image* source,
00475     PixelFormat format = PF_DONTCARE)
00476   {
00477     return hidden::CorCloneImage(source, format);
00478   }
00479 
00496   inline Image* OpenImage(
00497     const char* filename,
00498     PixelFormat pixel_format = PF_DONTCARE,
00499     FileFormat file_format = FF_AUTODETECT)
00500   {
00501     return hidden::CorConvertImage(
00502       hidden::CorOpenImage(filename, file_format),
00503       pixel_format);
00504   }
00505 
00526   inline Image* OpenImage(
00527     File* file,
00528     PixelFormat pixel_format = PF_DONTCARE,
00529     FileFormat file_format = FF_AUTODETECT)
00530   {
00531     return hidden::CorConvertImage(
00532       hidden::CorOpenImageFromFile(file, file_format),
00533       pixel_format);
00534   }
00535 
00537   inline Image* OpenImage(
00538     const char* filename,
00539     FileFormat file_format,
00540     PixelFormat pixel_format = PF_DONTCARE)
00541   {
00542     return OpenImage(filename, pixel_format, file_format);
00543   }
00544 
00546   inline Image* OpenImage(
00547     File* file,
00548     FileFormat file_format,
00549     PixelFormat pixel_format = PF_DONTCARE)
00550   {
00551     return OpenImage(file, pixel_format, file_format);
00552   }
00553 
00568   inline bool SaveImage(
00569     const char* filename,
00570     FileFormat file_format,
00571     Image* image)
00572   {
00573     return hidden::CorSaveImage(filename, file_format, image);
00574   }
00575 
00593   inline bool SaveImage(
00594     File* file,
00595     FileFormat file_format,
00596     Image* image)
00597   {
00598     return hidden::CorSaveImageToFile(file, file_format, image);
00599   }
00600 
00615   inline Image* ConvertImage(Image* source, PixelFormat format) {
00616     return hidden::CorConvertImage(source, format);
00617   }
00618 
00633   inline Image* ConvertPalette(Image* source, PixelFormat palette_format) {
00634     return hidden::CorConvertPalette(source, palette_format);
00635   }
00636 
00646   inline Image* FlipImage(Image* source, int coordinate_axis) {
00647     return hidden::CorFlipImage(source, coordinate_axis);
00648   }
00649 
00656   inline File* OpenFile(const char* filename, bool writeable) {
00657     return hidden::CorOpenFile(filename, writeable);
00658   }
00659 
00673   inline File* CreateMemoryFile(const void* buffer, int size) {
00674     return hidden::CorCreateMemoryFile(buffer, size);
00675   }
00676 
00684   inline int GetPixelSize(PixelFormat format) {
00685     return hidden::CorGetPixelSize(format);
00686   }
00687 
00696   inline bool IsDirect(PixelFormat format) {
00697     return (format == PF_R8G8B8A8 || format == PF_R8G8B8 ||
00698             format == PF_B8G8R8A8 || format == PF_B8G8R8);
00699   }
00700 
00709   inline bool IsPalettized(PixelFormat format) {
00710     return format == PF_I8;
00711   }
00712 
00721   inline int GetPaletteSize(PixelFormat format) {
00722     return (format == PF_I8 ? 256 : 0);
00723   }
00724 
00725 }
00726 
00727 
00728 #endif

Generated on Thu Oct 2 12:59:30 2003 for corona by doxygen1.3-rc1