📄 ximage.h
字号:
/* * File: ximage.h * Purpose: General Purpose Image Class *//* === C R E D I T S & D I S C L A I M E R S ============== * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * original CImage and CImageIterator implementation are: * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx> * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */#if !defined(__CXIMAGE_H)#define __CXIMAGE_H#if _MSC_VER > 1000#pragma once#endif /////////////////////////////////////////////////////////////////////////////// CxImage supported features#define CXIMAGE_SUPPORT_ALPHA 1#define CXIMAGE_SUPPORT_SELECTION 0#define CXIMAGE_SUPPORT_TRANSFORMATION 0#define CXIMAGE_SUPPORT_DSP 0#define CXIMAGE_SUPPORT_LAYERS 0#define CXIMAGE_SUPPORT_DECODE 1#define CXIMAGE_SUPPORT_ENCODE 0 //<vho><T.Peck>#define CXIMAGE_SUPPORT_WINDOWS 1#define CXIMAGE_SUPPORT_WINCE 0 //<T.Peck>/////////////////////////////////////////////////////////////////////////////// CxImage supported formats#define CXIMAGE_SUPPORT_BMP 1#define CXIMAGE_SUPPORT_GIF 0#define CXIMAGE_SUPPORT_JPG 1#define CXIMAGE_SUPPORT_PNG 1#define CXIMAGE_SUPPORT_MNG 0#define CXIMAGE_SUPPORT_ICO 0#define CXIMAGE_SUPPORT_TIF 0#define CXIMAGE_SUPPORT_TGA 0#define CXIMAGE_SUPPORT_PCX 0#define CXIMAGE_SUPPORT_WBMP 0#define CXIMAGE_SUPPORT_WMF 0#define CXIMAGE_SUPPORT_J2K 0 // Beta, use JP2#define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm#define CXIMAGE_SUPPORT_JP2 0#define CXIMAGE_SUPPORT_JPC 0#define CXIMAGE_SUPPORT_PGX 0#define CXIMAGE_SUPPORT_PNM 0#define CXIMAGE_SUPPORT_RAS 0/////////////////////////////////////////////////////////////////////////////#include <TCHAR.h> // For UNICODE support#include "xfile.h"#include "xiofile.h"#include "xmemfile.h"#include "ximadefs.h" //<vho> adjust some #define/////////////////////////////////////////////////////////////////////////////// CxImage formats enumeratorenum ENUM_CXIMAGE_FORMATS{CXIMAGE_FORMAT_UNKNOWN,#if CXIMAGE_SUPPORT_BMPCXIMAGE_FORMAT_BMP,#endif#if CXIMAGE_SUPPORT_GIFCXIMAGE_FORMAT_GIF,#endif#if CXIMAGE_SUPPORT_JPGCXIMAGE_FORMAT_JPG,#endif#if CXIMAGE_SUPPORT_PNGCXIMAGE_FORMAT_PNG,#endif#if CXIMAGE_SUPPORT_MNGCXIMAGE_FORMAT_MNG,#endif#if CXIMAGE_SUPPORT_ICOCXIMAGE_FORMAT_ICO,#endif#if CXIMAGE_SUPPORT_TIFCXIMAGE_FORMAT_TIF,#endif#if CXIMAGE_SUPPORT_TGACXIMAGE_FORMAT_TGA,#endif#if CXIMAGE_SUPPORT_PCXCXIMAGE_FORMAT_PCX,#endif#if CXIMAGE_SUPPORT_WBMPCXIMAGE_FORMAT_WBMP,#endif#if CXIMAGE_SUPPORT_WMFCXIMAGE_FORMAT_WMF,#endif#if CXIMAGE_SUPPORT_J2KCXIMAGE_FORMAT_J2K,#endif#if CXIMAGE_SUPPORT_JBGCXIMAGE_FORMAT_JBG,#endif#if CXIMAGE_SUPPORT_JP2CXIMAGE_FORMAT_JP2,#endif#if CXIMAGE_SUPPORT_JPCCXIMAGE_FORMAT_JPC,#endif#if CXIMAGE_SUPPORT_PGXCXIMAGE_FORMAT_PGX,#endif#if CXIMAGE_SUPPORT_PNMCXIMAGE_FORMAT_PNM,#endif#if CXIMAGE_SUPPORT_RASCXIMAGE_FORMAT_RAS,#endifCMAX_IMAGE_FORMATS};//color to grey mapping <H. Muelner> <jurgene>//#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000)#define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10)struct rgb_color { BYTE r,g,b; };// <VATI> text placement data// members must be initialized with the InitTextInfo(&this) function.typedef struct DLL_EXP tagCxTextInfo{ char text[4096]; // text LOGFONT lfont; // font and codepage data COLORREF fcolor; // foreground color long align; // DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text BYTE opaque; // text has background or hasn't. Default is true. // data for background (ignored if .opaque==FALSE) COLORREF bcolor; // background color float b_opacity; // opacity value for background between 0.0-1.0 Default is 0. (opaque) BYTE b_outline; // outline width for background (zero: no outline) BYTE b_round; // rounding radius for background rectangle. % of the height, between 0-50. Default is 10. // (backgr. always has a frame: width = 3 pixel + 10% of height by default.)} CXTEXTINFO;/////////////////////////////////////////////////////////////////////////////// CxImage class/////////////////////////////////////////////////////////////////////////////class DLL_EXP CxImage{//extensible information collectortypedef struct tagCxImageInfo { DWORD dwEffWidth; //DWORD aligned scan line width BYTE* pImage; //THE IMAGE BITS CxImage* pGhost; //if this is a ghost, pGhost points to the body CxImage* pParent; //if this is a layer, pParent points to the body DWORD dwType; //original image format char szLastError[256]; //debugging long nProgress; //monitor long nEscape; //escape long nBkgndIndex; //used for GIF, PNG, MNG RGBQUAD nBkgndColor; //used for RGB transparency BYTE nQuality; //used for JPEG BYTE nScale; //used for JPEG <ignacio> long nFrame; //used for TIF, GIF, MNG : actual frame long nNumFrames; //used for TIF, GIF, MNG : total number of frames DWORD dwFrameDelay; //used for GIF, MNG long xDPI; //horizontal resolution long yDPI; //vertical resolution RECT rSelectionBox; //bounding rectangle BYTE nAlphaMax; //max opacity (fade) bool bAlphaPaletteEnabled; //true if alpha values in the palette are enabled. bool bEnabled; //enables the painting functions long xOffset; long yOffset; DWORD dwCodecOption; //for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg RGBQUAD last_c; //for GetNearestIndex optimization BYTE last_c_index; bool last_c_isvalid; long nNumLayers; DWORD dwFlags; // 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags} CXIMAGEINFO;public: //constructors CxImage(DWORD imagetype = 0); CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); CxImage(const TCHAR * filename, DWORD imagetype); // For UNICODE support: char -> TCHAR// CxImage(const char * filename, DWORD imagetype); CxImage(FILE * stream, DWORD imagetype); CxImage(CxFile * stream, DWORD imagetype); CxImage(BYTE * buffer, DWORD size, DWORD imagetype); virtual ~CxImage() { Destroy(); }; CxImage& operator = (const CxImage&); //initializzation void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); bool Destroy(); void Clear(BYTE bval=0); void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); bool Transfer(CxImage &from); bool CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); bool CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); //Attributes long GetSize(); BYTE* GetBits(DWORD row = 0); BYTE GetColorType(); void* GetDIB() const {return pDib;} DWORD GetHeight() const {return head.biHeight;} DWORD GetWidth() const {return head.biWidth;} DWORD GetEffWidth() const {return info.dwEffWidth;} DWORD GetNumColors() const {return head.biClrUsed;} WORD GetBpp() const {return head.biBitCount;} DWORD GetType() const {return info.dwType;} char* GetLastError() {return info.szLastError;} const TCHAR* GetVersion(); DWORD GetFrameDelay() const {return info.dwFrameDelay;} void SetFrameDelay(DWORD d) {info.dwFrameDelay=d;} void GetOffset(long *x,long *y) {*x=info.xOffset; *y=info.yOffset;} void SetOffset(long x,long y) {info.xOffset=x; info.yOffset=y;} BYTE GetJpegQuality() const {return info.nQuality;} void SetJpegQuality(BYTE q) {info.nQuality = q;} //<ignacio> used for scaling down during JPEG decoding valid numbers are 1, 2, 4, 8 BYTE GetJpegScale() const {return info.nScale;} void SetJpegScale(BYTE q) {info.nScale = q;} long GetXDPI() const {return info.xDPI;} long GetYDPI() const {return info.yDPI;} void SetXDPI(long dpi); void SetYDPI(long dpi); DWORD GetClrImportant() const {return head.biClrImportant;} void SetClrImportant(DWORD ncolors = 0); long GetProgress() const {return info.nProgress;} long GetEscape() const {return info.nEscape;} void SetProgress(long p) {info.nProgress = p;} void SetEscape(long i) {info.nEscape = i;} long GetTransIndex() const {return info.nBkgndIndex;} RGBQUAD GetTransColor(); void SetTransIndex(long idx) {info.nBkgndIndex = idx;} void SetTransColor(RGBQUAD rgb) {rgb.rgbReserved=0; info.nBkgndColor = rgb;} bool IsTransparent() const {return info.nBkgndIndex>=0;} // <vho> DWORD GetCodecOption() const {return info.dwCodecOption;} void SetCodecOption(DWORD opt) {info.dwCodecOption = opt;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -