📄 imageobject.h
字号:
// ImageObject.h
#ifndef __IMAGEOBJECT_H__
#define __IMAGEOBJECT_H__
#define IMAGELIB_SUCCESS 0
// File errors
#define IMAGELIB_FILE_OPEN_ERROR -1
#define IMAGELIB_FILE_CREATION_ERROR -2
#define IMAGELIB_FILE_WRITE_ERROR -3
#define IMAGELIB_FILE_READ_ERROR -4
// Memory erros
#define IMAGELIB_MEMORY_ALLOCATION_ERROR -50
#define IMAGELIB_MEMORY_LOCK_ERROR -51
// Argument errors
#define IMAGELIB_NODIB -100
//
#define IMAGELIB_UNSUPPORTED_FILETYPE -200
#define IMAGELIB_HDIB_NULL -201
#define IMAGELIB_LOGICAL_PALETTE_CREATION_ERROR -202
#define IMAGELIB_NO_PALETTE_FOR_HIGH_COLOR -203
#define IMAGELIB_STRETCHDIBITS_ERROR -204
#define IMAGELIB_PALETTE_QUANTIZE_ERROR -205
#define IMAGELIB_ATTEMPT_CHANGE_TO_SAME 206
#define IMAGELIB_ROTATION_VALUE_ERROR -207
#define IMAGELIB_ROTATE_ERROR -208
#define POPULARITY_PALETTE 0
#define MEDIAN_CUT_PALETTE 1
#define FIXED_PALETTE 2
#pragma pack(1)
typedef struct{
unsigned short m_nBlueList[256];
} GREENLIST;
typedef struct{
GREENLIST *m_pGreenList[256];
} REDLIST;
typedef struct{
unsigned short nCount;
unsigned char ucRed;
unsigned char ucGreen;
unsigned char ucBlue;
} COUNTLIST;
#pragma pack()
#define GETRGB555( a, b, c, d ) { WORD *wData = (WORD *) d; a = (unsigned char) ( ( (*wData) & 0x7c00 ) >> 7 ); b = (unsigned char) ( ( (*wData) & 0x03e0 ) >> 2 ); c = (unsigned char) ( ( (*wData) & 0x001f ) << 3 ); }
#define GETRGB565( a, b, c, d ) { WORD *wData = (WORD *) d; a = (unsigned char) ( ( (*wData) & 0xf800 ) >> 8 ); b = (unsigned char) ( ( (*wData) & 0x07e0 ) >> 3 ); c = (unsigned char) ( ( (*wData) & 0x001f ) << 3 ); }
#define GETRGB888( a, b, c, d ) { DWORD *dwData = (DWORD *) d; a = (unsigned char) ( (*dwData) >> 16 ); b = (unsigned char) ( ( (*dwData) & 0x0000ff00 ) >> 8 ); c = (unsigned char) ( (*dwData) & 0x000000ff ); }
#define PUTRGB555( a, b, c, d ) { WORD *wData = (WORD *) d; *wData = ( ( ( (WORD) a & 0x00f8 ) << 7 ) | ( ( (WORD) b & 0x00f8 ) << 2 ) | ( (WORD) c >> 3 ) ); }
#define PUTRGB565( a, b, c, d ) { WORD *wData = (WORD *) d; *wData = ( ( ( (WORD) a & 0x00f8 ) << 8 ) | ( ( (WORD) b & 0x00fc ) << 3 ) | ( (WORD) c >> 3 ) ); }
#define PUTRGB888( a, b, c, d ) { DWORD *dwData = (DWORD *) d; *dwData = ( (DWORD) a << 16 ) | ( (DWORD) b << 8 ) | (DWORD) c; }
#define _RGB(r,g,b) (WORD)(((b)&~7)<<7)|(((g)&~7)<<2)|((r)>>3)
class CImageObject
{
// Construction
public:
CImageObject();
CImageObject( const char *, CDC *pDC = NULL, int nX = -1, int nY = -1 );
~CImageObject();
//attrib
public:
int m_nLastError,m_nScreenPlanes, m_nScreenBits, m_nPaletteBytes;
static char *szExtensions[7];
protected:
int m_nWidth, m_nHeight, m_nPlanes, m_nBits, m_nColors, m_nImageType;
int m_nX, m_nY;
int m_nQuality;
int m_nPaletteCreationType;
CPalette m_Palette;
HGLOBAL m_hDib;
char* m_pszFilename;
LOGPALETTE* m_pLogPal;
// Operations
public:
BOOL Load( const char *, CDC *pDC = NULL, int nX = -1, int nY = -1 );
int GetLastError( void );
BOOL Save( const char *, int nType = -1 );
int GetWidth( void );
int GetHeight( void );
int GetNumBits( void );
int GetNumColors( void );
BOOL GetPaletteData( RGBQUAD * );
RGBQUAD* GetPaletteData( void );
int GetImageType( const char * );
int GetImageType( void );
BOOL GetImageInfo( const char *, int *pnWidth = NULL,
int *pnHeight = NULL, int *pnPlanes = NULL,
int *pnBitsPerPixel = NULL, int *pnNumColors = NULL );
BOOL Draw( CDC *, int x = -1, int y = -1 );
BOOL Draw( CDC *pDC, CRect rRect );
BOOL DrawInRect( CDC *pDC, CRect rRect );
BOOL SetPalette( CDC * );
void SetPaletteCreationType( int );
int GetPaletteCreationType( void );
BOOL IsLoaded( void );
int ExtensionIndex( const char * );
BOOL Crop( int, int, int, int );
BOOL Stretch( int, int );
BOOL Rotate( int );
BOOL Invert( void );
BOOL Reverse( void );
BOOL RotateIt( int );
void Rotate90( unsigned char *, unsigned char * );
void Rotate270( unsigned char *, unsigned char * );
BOOL ChangeFormat( int );
int GetPaletteBytes( void );
HGLOBAL GetDib( void );
CPalette* GetPalette( void );
void operator= (const CImageObject &ImageObject);
void NormalizeCoordinates( int *, int *, int *, int *, BOOL *bCompleteImage = NULL, BOOL *bLessThanHalf = NULL );
void* GetDIBPointer( int *nWidthBytes = NULL, int nNewBits = 0, int *nNewWidthBytes = NULL, int nNewWidth = -1 );
LOGPALETTE* GetLogPal( void );
LOGPALETTE* CreateLogPalette( RGBQUAD *Palette, int NumColors );
int GetNearestIndex( unsigned char, unsigned char, unsigned char, RGBQUAD *, int );
void SetQuality( int nQual ){ m_nQuality = nQual; }
void ProcessPalette( void );
int WidthBytes( int, int );
void SetDib( HGLOBAL hDib ){ m_hDib = hDib; }
void SetLogPal( LOGPALETTE *pLogPal ){ m_pLogPal = pLogPal; }
protected:
void InitVars( BOOL bFlag = FALSE );
void ProcessImageHeader( void );
void KillImage( void );
void CreatePaletteFromDIB( RGBQUAD *, int );
LOGPALETTE* CreatePaletteFromBitmap( int, unsigned char *, int, int, int );
RGBQUAD* MakePopularityPalette( int, unsigned char *, int, int, int );
RGBQUAD* MakeMedianCutPalette( int, unsigned char *, int, int, int );
RGBQUAD* MakeFixedPalette( int );
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -