📄 corona.h
字号:
PixelFormat palette_format);
COR_FUNCTION(Image*) CorFlipImage(
Image* image,
int coordinate_axis);
// files
COR_FUNCTION(File*) CorOpenFile(const char* name, bool writeable);
COR_FUNCTION(File*) CorCreateMemoryFile(const void* buffer, int size);
// utility
COR_FUNCTION(int) CorGetPixelSize(PixelFormat format);
}
/* PUBLIC API */
/**
* Return the Corona version string.
*
* @return Corona version information
*/
inline const char* GetVersion() {
return hidden::CorGetVersion();
}
/**
* Returns a null-terminated array of FileFormatDesc* pointers that
* describe the file formats Corona can read. The array is owned by
* Corona, so do not delete it when you are done using it.
*/
inline FileFormatDesc** GetSupportedReadFormats() {
return hidden::CorGetSupportedReadFormats();
}
/**
* Returns a null-terminated array of FileFormatDesc* pointers that
* describe the file formats Corona can write. The array is owned
* by Corona, so do not delete it when you are done using it.
*/
inline FileFormatDesc** GetSupportedWriteFormats() {
return hidden::CorGetSupportedWriteFormats();
}
/**
* Create a new, blank image with a specified width, height, and
* format. If pixels is specified, Corona uses them to initialize
* the contents of the image. Corona does *not* take ownership of
* the pixel memory, so the caller is responsible for cleaning up
* after itself. If pixels is not specified, the new image is
* filled with zeroes.
*
* @param width width of the new image
* @param height height of the new image
* @param format format the pixels are stored in, cannot be PF_DONTCARE
* @param pixels pixel buffer used to initialize the new image
*
* @return newly created blank image
*/
inline Image* CreateImage(
int width,
int height,
PixelFormat format,
void* pixels = 0)
{
return hidden::CorCreateImageWithPixels(width, height, format, pixels);
}
/**
* Create a new, blank image with a specified width, height, format,
* and palette.
*
* @param width width of image
* @param height height of image
* @param format format of palette indices, should be PF_I8
* @param palette_size number of colors in palette
* @param palette_format pixel format of palette entries
*/
inline Image* CreateImage(
int width,
int height,
PixelFormat format,
int palette_size,
PixelFormat palette_format)
{
return hidden::CorCreatePalettizedImage(
width, height, format,
palette_size, palette_format);
}
/**
* Create a new image from an old one. If format is specified, the
* new image is converted to that pixel format. If format is not
* specified, the new image simply uses the same format as the
* source. If the image could not be cloned or the pixel format is
* invalid, CloneImage returns 0.
*
* @param source image to clone
* @param format format the new image is stored in, defaults to PF_DONTCARE
*
* @return new image cloned from the source, 0 if failure
*/
inline Image* CloneImage(
Image* source,
PixelFormat format = PF_DONTCARE)
{
return hidden::CorCloneImage(source, format);
}
/**
* Opens an image from the default filesystem. This function simply
* forwards the call to OpenImage(file, file_format, pixel_format)
* with a standard C library file.
*
* See OpenImage(fs, filename, file_format, pixel_format) for more
* information.
*
* @param filename image filename to open
* @param file_format file format the image is stored in, or FF_AUTODETECT
* to try all loaders
* @param pixel_format desired pixel format, or PF_DONTCARE to use image's
* native format
*
* @return the image loaded from the disk, or 0 if it cannot be opened
*/
inline Image* OpenImage(
const char* filename,
PixelFormat pixel_format = PF_DONTCARE,
FileFormat file_format = FF_AUTODETECT)
{
return hidden::CorConvertImage(
hidden::CorOpenImage(filename, file_format),
pixel_format);
}
/**
* Opens an image from the specified file.
*
* If file_format is FF_AUTODETECT, the loader tries
* to load each format until it finds one that succeeds. Otherwise,
* it tries the specific loader specified.
*
* If pixel_format is PF_DONTCARE, the new image object has the
* pixel format closest to the image's format on disk. Otherwise,
* the pixels are converted to the specified format before the image
* is returned.
*
* @param file name of the file that contains the image
* @param file_format file format the image is stored in, or FF_AUTODETECT
* to try all loaders
* @param pixel_format desired pixel format, or PF_DONTCARE to use image's
* native format
*
* @return the image loaded from the file, or 0 if it cannot be opened
*/
inline Image* OpenImage(
File* file,
PixelFormat pixel_format = PF_DONTCARE,
FileFormat file_format = FF_AUTODETECT)
{
return hidden::CorConvertImage(
hidden::CorOpenImageFromFile(file, file_format),
pixel_format);
}
/// For compatibility. This function may be deprecated.
inline Image* OpenImage(
const char* filename,
FileFormat file_format,
PixelFormat pixel_format = PF_DONTCARE)
{
return OpenImage(filename, pixel_format, file_format);
}
/// For compatibility. This function may be deprecated.
inline Image* OpenImage(
File* file,
FileFormat file_format,
PixelFormat pixel_format = PF_DONTCARE)
{
return OpenImage(file, pixel_format, file_format);
}
/**
* Saves an image to a file in the default filesystem. This
* function simply calls SaveImage(file, file_format, image)
* with a standard C library file.
*
* See SaveImage(fs, filename, file_format, image) for more information.
*
* @param filename name of the file to save the image to
* @param file_format file format in which to save image. if FF_AUTODETECT,
* SaveImage guesses the type from the file extension
* @param image image to save
*
* @return true if save succeeds, false otherwise
*/
inline bool SaveImage(
const char* filename,
FileFormat file_format,
Image* image)
{
return hidden::CorSaveImage(filename, file_format, image);
}
/**
* Saves an image to the specified file. This function saves image
* to a file of type file_format. If file_format is not a supported
* output type, the function fails. As of now, Corona only supports
* saving images of type FF_PNG and FF_TGA.
*
* @note This function may create the file even if the save does not
* succeed, so users of this library should remove the file after
* the call to SaveImage().
*
* @param file file in which to save the image
* @param file_format file format in which to save image -- must not be
* FF_AUTODETECT
* @param image image to save
*
* @return true if the save succeeds, false otherwise
*/
inline bool SaveImage(
File* file,
FileFormat file_format,
Image* image)
{
return hidden::CorSaveImageToFile(file, file_format, image);
}
/**
* Converts an image from one format to another, destroying the old
* image. If source is 0, the function returns 0. If format is
* PF_DONTCARE or the source and target formats match, returns the
* unmodified source image. If a valid conversion is not found,
* ConvertImage destroys the old image and returns 0. For example,
* ConvertImage does not support creating a palettized image from a
* direct color image yet.
*
* @param source image to convert
* @param format desired format -- can be PF_DONTCARE
*
* @return valid image object if conversion succeeds, 0 otherwise
*/
inline Image* ConvertImage(Image* source, PixelFormat format) {
return hidden::CorConvertImage(source, format);
}
/**
* Converts the palette of a palettized image from one format to
* another, destroying the old image. If the source is 0, the
* palette_format is PF_DONTCARE, or the source and target formats
* match, the function returns the unmodified source image. If a
* valid conversion is not found or invalid inputs are given (such
* as a direct-color source image), this function destroys the old
* image and returns 0.
*
* @param source palettized image to convert
* @param palette_format desired pixel format of palette
*
* @return valid image object if conversion succeeds, 0 otherwise
*/
inline Image* ConvertPalette(Image* source, PixelFormat palette_format) {
return hidden::CorConvertPalette(source, palette_format);
}
/**
* Flips the pixels in the image around the given axis.
*
* @param source image to flip
* @param coordinate_axis Axis around which to flip. Both CA_X and CA_Y
* can be specified by ORing them together.
*
* @return the image passed in
*/
inline Image* FlipImage(Image* source, int coordinate_axis) {
return hidden::CorFlipImage(source, coordinate_axis);
}
/**
* Returns a default File implementation.
*
* @param filename name of the file on local filesystem
* @param writeable whether the file can be written to
*/
inline File* OpenFile(const char* filename, bool writeable) {
return hidden::CorOpenFile(filename, writeable);
}
/**
* Creates a File implementation that reads from a buffer in memory.
* It stores a copy of the buffer that is passed in.
*
* The File object does <i>not</i> take ownership of the memory buffer.
* When the file is destroyed, it will not free the memory.
*
* @param buffer Pointer to the beginning of the data.
* @param size Size of the buffer in bytes.
*
* @return 0 if size is non-zero and buffer is null. Otherwise,
* returns a valid File object.
*/
inline File* CreateMemoryFile(const void* buffer, int size) {
return hidden::CorCreateMemoryFile(buffer, size);
}
/**
* Returns the number of bytes needed to store a pixel of a gixen format.
*
* @param format The format to query.
*
* @return Number of bytes each pixel takes, or 0 if the format is invalid.
*/
inline int GetPixelSize(PixelFormat format) {
return hidden::CorGetPixelSize(format);
}
/**
* Returns true if the pixel format does not require a palette; that
* is, if each pixel itself contains color data.
*
* @param format The format to query.
*
* @return True if format is direct color, false otherwise.
*/
inline bool IsDirect(PixelFormat format) {
return (format == PF_R8G8B8A8 || format == PF_R8G8B8 ||
format == PF_B8G8R8A8 || format == PF_B8G8R8);
}
/**
* Returns true if the pixel format requires a palette; that
* is, if each pixel is an index into a separate palette.
*
* @param format The format to query.
*
* @return True if format is palettized, false otherwise.
*/
inline bool IsPalettized(PixelFormat format) {
return format == PF_I8;
}
/**
* Returns the number of color entries in a palette for an image
* of the given format.
*
* @param format The format to query.
*
* @return Number of color entries, or 0 if the format is not palettized.
*/
inline int GetPaletteSize(PixelFormat format) {
return (format == PF_I8 ? 256 : 0);
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -