⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 corona.h

📁 这个刚才那个的源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/**
 * Corona Image I/O Library
 * Version 1.0.2
 * (c) 2003 Chad Austin
 *
 * This API uses principles explained at
 * http://aegisknight.org/cppinterface.html
 *
 * This code licensed under the terms of the zlib license.  See
 * license.txt.
 *
 *
 * Note: When compiling this header in gcc, you may want to use the
 * -Wno-non-virtual-dtor flag to get rid of those annoying "class has
 * virtual functions but no virtual destructor" warnings.
 */


#ifndef CORONA_H
#define CORONA_H


#ifndef __cplusplus
#error Corona requires C++
#endif


#include <stddef.h>


// DLLs in Windows should use the standard calling convention
#ifndef COR_CALL
#  if defined(WIN32) || defined(_WIN32)
#    define COR_CALL __stdcall
#  else
#    define COR_CALL
#  endif
#endif

// Export functions from the DLL
#ifndef COR_DECL
#  if defined(WIN32) || defined(_WIN32)
#    ifdef CORONA_EXPORTS
#      define COR_DECL __declspec(dllexport)
#    else
#      define COR_DECL
#    endif
#  else
#    define COR_DECL
#  endif
#endif


// evil "identifier is too long in debug information" warning
#ifdef _MSC_VER
#pragma warning(disable : 4786)
#endif


#define COR_FUNCTION(ret) extern "C" COR_DECL ret COR_CALL


namespace corona {

  /**
   * File formats supported for reading or writing.
   */
  enum FileFormat {
    FF_AUTODETECT = 0x0100,
    FF_PNG        = 0x0101,
    FF_JPEG       = 0x0102,
    FF_PCX        = 0x0103,
    FF_BMP        = 0x0104,
    FF_TGA        = 0x0105,
    FF_GIF        = 0x0106,
  };

  /**
   * Pixel format specifications.  Pixel data can be packed in one of
   * the following ways.
   */
  enum PixelFormat {
    PF_DONTCARE = 0x0200,  /**< special format used when specifying a
                                desired pixel format */
    PF_R8G8B8A8 = 0x0201,  /**< RGBA, channels have eight bits of precision */
    PF_R8G8B8   = 0x0202,  /**< RGB, channels have eight bits of precision  */
    PF_I8       = 0x0203,  /**< Palettized, 8-bit indices into palette      */
    PF_B8G8R8A8 = 0x0204,  /**< BGRA, channels have eight bits of precision */
    PF_B8G8R8   = 0x0205,  /**< BGR, channels have eight bits of precision  */
  };

  /**
   * Axis specifications.  The image can be flipped along the following
   * axes.
   */
  enum CoordinateAxis {
    CA_X     = 0x0001,
    CA_Y     = 0x0002,
  };

  /**
   * A helper class for DLL-compatible interfaces.  Derive your cross-DLL
   * interfaces from this class.
   *
   * When deriving from this class, do not declare a virtual destructor
   * on your interface.
   */
  class DLLInterface {
  private:
    /**
     * Destroy the object, freeing all associated memory.  This is
     * the same as a destructor.
     */
    virtual void COR_CALL destroy() = 0;

  public:
    /**
     * "delete image" should actually call image->destroy(), thus putting the
     * burden of calling the destructor and freeing the memory on the image
     * object, and thus on Corona's side of the DLL boundary.
     */
    void operator delete(void* p) {
      if (p) {
        DLLInterface* i = static_cast<DLLInterface*>(p);
        i->destroy();
      }
    }
  };


  /**
   * A helper class for DLL-compatible interface implementations.  Derive
   * your implementations from DLLImplementation<YourInterface>.
   */
  template<class Interface>
  class DLLImplementation : public Interface {
  public:
    /**
     * So the implementation can put its destruction logic in the destructor,
     * as natural C++ code does.
     */
    virtual ~DLLImplementation() { }

    /**
     * Call the destructor in a Win32 ABI-compatible way.
     */
    virtual void COR_CALL destroy() {
      delete this;
    }

    /**
     * So destroy()'s "delete this" doesn't go into an infinite loop,
     * calling the interface's operator delete, which calls destroy()...
     */
    void operator delete(void* p) {
      ::operator delete(p);
    }
  };

  
  /**
   * An image object represents a rectangular collections of pixels.
   * They have a width, a height, and a pixel format.  Images cannot
   * be resized.
   */
  class Image : public DLLInterface {
  public:
    /**
     * Get image width.
     * @return  image width
     */
    virtual int COR_CALL getWidth() = 0;

    /**
     * Get image height.
     * @return  image height
     */
    virtual int COR_CALL getHeight() = 0;

    /**
     * Get pixel format.
     * @return  pixel format
     */
    virtual PixelFormat COR_CALL getFormat() = 0;

    /**
     * Get pixel buffer.  The pixels are packed in the format defined
     * by the image's pixel format.
     *
     * @return  pointer to first element in pixel buffer
     */
    virtual void* COR_CALL getPixels() = 0;

    /**
     * Get the palette.  Pixels are packed in the format defined by
     * getPaletteFormat().
     *
     * @return  pointer to first palette entry
     */
    virtual void* COR_CALL getPalette() = 0;

    /**
     * Get the number of entries in the palette.
     *
     * @return  number of palette entries
     */
    virtual int COR_CALL getPaletteSize() = 0;

    /**
     * Get the format of the colors in the palette.
     *
     * @return  pixel format of palette entries
     */
    virtual PixelFormat COR_CALL getPaletteFormat() = 0;
  };


  /**
   * Represents a random-access file, usually stored on a disk.  Files
   * are always binary: that is, they do no end-of-line
   * transformations.  File objects are roughly analogous to ANSI C
   * FILE* objects.
   */
  class File : public DLLInterface {
  public:

    /**
     * The different ways you can seek within a file.
     */
    enum SeekMode {
      BEGIN,    /**< relative to the beginning of the file */
      CURRENT,  /**< relative to the current position in the file */
      END       /**< relative to the end of the file: position should
                     be negative*/
    };

    /**
     * Read size bytes from the file, storing them in buffer.
     *
     * @param buffer  buffer to read into
     * @param size    number of bytes to read
     *
     * @return  number of bytes successfully read
     */
    virtual int COR_CALL read(void* buffer, int size) = 0;

    /**
     * Write size bytes from buffer to the file.
     *
     * @param buffer  buffer that contains the data to write
     * @param size    number of bytes to write
     *
     * @return  number of bytes successfully written
     */
    virtual int COR_CALL write(const void* buffer, int size) = 0;

    /**
     * Jump to a new position in the file, using the specified seek
     * mode.  Remember: if mode is END, the position must be negative,
     * to seek backwards from the end of the file into its contents.
     * If the seek fails, the current position is undefined.
     *
     * @param position  position relative to the mode
     * @param mode      where to seek from in the file
     *
     * @return  true on success, false otherwise
     */
    virtual bool COR_CALL seek(int position, SeekMode mode) = 0;

    /**
     * Get current position within the file.
     *
     * @return  current position
     */
    virtual int COR_CALL tell() = 0;
  };


  /// Describes a file format that Corona supports.
  class FileFormatDesc {
  protected:
    ~FileFormatDesc() { }

  public:
    /// Actual FileFormat being described.
    virtual FileFormat getFormat() = 0;

    /// Short description of format, such as "PNG Files" or "JPEG Files"
    virtual const char* getDescription() = 0;

    /// @{
    /// List of supported extensions, such as {"bmp", "rle", "dib"}
    virtual size_t getExtensionCount() = 0;
    virtual const char* getExtension(size_t i) = 0;
    /// @}
  };


  /// PRIVATE API - for internal use only
  namespace hidden {

    // these are extern "C" so we don't mangle the names


    // API information

    COR_FUNCTION(const char*) CorGetVersion();

    COR_FUNCTION(FileFormatDesc**) CorGetSupportedReadFormats();
    COR_FUNCTION(FileFormatDesc**) CorGetSupportedWriteFormats();

    // creation

    COR_FUNCTION(Image*) CorCreateImage(
      int width,
      int height,
      PixelFormat format);

    COR_FUNCTION(Image*) CorCreateImageWithPixels(
      int width,
      int height,
      PixelFormat format,
      void* pixels);

    COR_FUNCTION(Image*) CorCreatePalettizedImage(
      int width,
      int height,
      PixelFormat format, // must be a palettized format
      int palette_size,
      PixelFormat palette_format);

    COR_FUNCTION(Image*) CorCloneImage(
      Image* source,
      PixelFormat format);

    // loading

    COR_FUNCTION(Image*) CorOpenImage(
      const char* filename,
      FileFormat file_format);

    COR_FUNCTION(Image*) CorOpenImageFromFile(
      File* file,
      FileFormat file_format);

    // saving

    COR_FUNCTION(bool) CorSaveImage(
      const char* filename,
      FileFormat file_format,
      Image* image);

    COR_FUNCTION(bool) CorSaveImageToFile(
      File* file,
      FileFormat file_format,
      Image* image);

    // conversion

    COR_FUNCTION(Image*) CorConvertImage(
      Image* image,
      PixelFormat format);

    COR_FUNCTION(Image*) CorConvertPalette(
      Image* image,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -