📄 imagereader.h
字号:
#ifndef _IMG_IMAGEREADER_H
#define _IMG_IMAGEREADER_H
#include <gr/SurfaceFormat.h>
#include <lang/Array.h>
#include <stdint.h>
namespace io {
class InputStream;}
namespace img
{
/**
* Low level image file reader.
*/
class ImageReader
{
public:
/**
* Supported image file formats.
*/
enum FileFormat
{
/** Unknown image file format. */
FILEFORMAT_UNKNOWN,
/** BMP image file. */
FILEFORMAT_BMP,
/** TGA image file. */
FILEFORMAT_TGA,
/** JPG image file. */
FILEFORMAT_JPG,
};
/**
* Starts reading image file using specified format.
* Note that ImageReader does not add a reference to InputStream,
* so you must make sure InputStream exists as long as the image is read from it.
* @exception IOException
*/
ImageReader( io::InputStream* in, FileFormat filefmt );
///
~ImageReader();
/**
* Returns true if surfaces still left.
* Call to start iterating through surfaces.
* @see surfaces
*/
bool nextSurface();
/**
* Reads data of current active surface.
* @exception IOException
*/
void readSurface( void* bits, int pitch, int w, int h, gr::SurfaceFormat fmt,
const void* pal, gr::SurfaceFormat palfmt );
/**
* Returns total number of surfaces to be read.
*/
int surfaces() const;
/**
* Returns pixel format of the image.
*/
gr::SurfaceFormat format() const;
/**
* Returns pointer to palette data if any.
* Palette data is file format dependent.
* @return 0 if no palette.
*/
const void* paletteData() const;
/**
* Returns pixel format of the palette if any.
* @return SURFACE_UNKNOWN if palette data format is non-standard.
*/
gr::SurfaceFormat paletteFormat() const;
/**
* Returns width of current active surface in pixels.
* nextSurface() must be called before this method is used.
* Updated in nextSurface().
*/
int surfaceWidth() const;
/**
* Returns height of current active surface in pixels.
* nextSurface() must be called before this method is used.
* Updated in nextSurface().
*/
int surfaceHeight() const;
/**
* Guesses image file type based on file name.
* @return FILEFORMAT_UNKNOWN if format cannot be guessed from file name suffix.
*/
static FileFormat guessFileFormat( const char* filename );
private:
io::InputStream* m_in;
int m_width;
int m_height;
int m_bitsPerPixel;
int m_pitch;
int m_surfaces;
uint8_t m_colormap[256][4];
lang::Array<uint8_t> m_scanlinebuffer;
gr::SurfaceFormat m_fmt;
gr::SurfaceFormat m_palfmt;
FileFormat m_filefmt;
bool m_bottomUp;
uint8_t m_ffbuffer[800]; // file format specific buffer
static void readFully( io::InputStream* in, void* buf, int bytes );
static void readColorMap( io::InputStream* in, int entrysize, int entries, uint8_t* colormap );
static uint16_t getUInt16LE( const void* data, int offset );
static uint32_t getUInt32LE( const void* data, int offset );
void readHeader_bmp();
void readHeader_tga();
void readHeader_jpg();
void readSurface_jpg( void* bits, int pitch, int w, int h, gr::SurfaceFormat fmt, const void* pal, gr::SurfaceFormat palfmt );
void readScanlines( void* bits, int pitch, int w, int h, gr::SurfaceFormat fmt, const void* pal, gr::SurfaceFormat palfmt );
void readScanline_jpg( void* buffer );
void finish_jpg();
ImageReader( const ImageReader& );
ImageReader& operator=( const ImageReader& );
};
} // img
#endif // _IMG_IMAGEREADER_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -