📄 cximage.htm
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<link rel="stylesheet" href="xdp.css" type="text/css">
</HEAD>
<BODY background="img5/grid02.gif">
<h2><b>CxImage 5.99c</b></h2>
<P><IMG height=456 alt="" src="cximage.png" width=631></P>
<H2>Introduction</H2>
<P><CODE>CxImage</CODE> is a C++ class to manage almost any kind of images.
It can load, save, display, transform images in a very simple and fast way. </P>
<P><I>Why another image library?</I> Around there are many good libraries
(OpenIL, FreeImage, PaintLib ...), these are powerful, complete, and constantly
updated. However if you ever try to use them, you may find some difficulties;
because these libraries are mainly platform independent, written in C, sometimes
with a basic C++ wrapper and with tons of compiler switch declarations. Now with
the new GDI+ classes on the scene, maybe CxImage isn't so useful, but at least
here you have the source code. It is not a MFC library, altogether it's a
windows library, because of some particular constructors and the painting
functions, but the backbone is platform independent.</P>
<h2>CxImage structure<a name="structure"></a></h2>
<P>In the vertical hierarchy of the library, <CODE>CxImage </CODE>stays on the
top of the other modules, it's not a clean OOP approach, but the result was good
since the first release and now it's too late to change again. Anyway you can
always use the derived classes to perform the format specific operations, like
for <CODE>CxImageTIF</CODE> to save multipage TIFFs.</P>
<P>The glue to connect all the modules and the C libraries is
<CODE>CxFile</CODE>, a virtual class that provides the standard methods to
access the data from a file on the disk or in memory.</P>
<P><IMG height=243 alt="" src="structure2.png" width=416></P>
<P>A <CODE>Cximage </CODE>object is basically a bitmap, with the addition of
some member variables to store useful information:</P><PRE> class CxImage
{
...
protected:
void* pDib; //contains the header, the palette, the pixels
BITMAPINFOHEADER head; //standard header
CXIMAGEINFO info; //extended information
BYTE* pSelection; //selected region
BYTE* pAlpha; //alpha channel
CxImage** pLayers; //generic layers
}</PRE>
<P><CODE>CxImage::head</CODE> is the bitmap header and
<CODE>CxImage::pDib</CODE> is a normal bitmap (as you can see in the
implementation of <CODE>CxImageBMP::Encode</CODE>).</P>
<P><CODE>CxImage::info</CODE> is a handy container of many information shared
between different formats, and for all the member functions.</P><PRE>typedef struct tagCxImageInfo {
DWORD dwEffWidth; //DWORD aligned scan line width
BYTE* pImage; //THE IMAGE BITS
void* pGhost; //if this is a ghost, pGhost point 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
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 dwEncodeOption; //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;
} CXIMAGEINFO;</PRE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>
<P>A CxImage object is also a set of layers. The buffers in each layer are
allocated only when necessary.</P>
<P><CODE>CxImage::pDib</CODE> is the background image.
<CODE>CxImage::pAlpha</CODE> is the transparency layer.
<CODE>CxImage::pSelection</CODE> is the selection layer, used to create
regions of interest for image processing.<BR>Over these 3 specific planes,
you can add other generic layers, stored in <CODE>CxImage::pLayers</CODE>.
The generic layers are full <CODE>CxImage</CODE> objects, so you can build
complex structures of nested layers.</P></TD>
<TD vAlign=top><IMG height=177 alt="" src="layers.jpg"
width=486 align=right></TD>
</TR></TBODY></TABLE>
<H2>Supported formats and options<A name=options></A></H2>
<P>The whole library is quite big, in the configuration header file<B>
<I>ximacfg.h</I></B> you'll find the switches to enable or disable a specific
graphic format or feature. Each JPG, PNG and TIFF library adds about 100KB to
the final application, while the<CODE> CxImage</CODE> impact is about 50KB. So
you should support and link only the formats that your application really
needs.</P>
<TABLE cellSpacing=0 cellPadding=2 width="100%" border=1>
<TBODY>
<TR>
<TD width="43%"><B>formats</B></TD>
<TD width="20%"><B>#define</B></TD>
<TD width="27%"><B>required libraries</B></TD>
<TD width="10%"><B>size [Kbyte]</B></TD></TR>
<TR>
<TD width="43%">BMP<BR>GIF<BR>ICO<BR>TGA<BR>PCX<BR>WBMP<BR>WMF<BR></TD>
<TD
width="20%">CXIMAGE_SUPPORT_BMP<BR>CXIMAGE_SUPPORT_GIF<BR>CXIMAGE_SUPPORT_ICO<BR>CXIMAGE_SUPPORT_TGA<BR>CXIMAGE_SUPPORT_PCX<BR>CXIMAGE_SUPPORT_WBMP<BR>CXIMAGE_SUPPORT_WMF<BR></TD>
<TD width="27%"><BR>built in<BR></TD>
<TD width="10%"><BR>24<BR></TD></TR>
<TR>
<TD width="43%">JPEG</TD>
<TD width="20%">CXIMAGE_SUPPORT_JPG<BR></TD>
<TD width="27%"><BR>jpeg<BR></TD>
<TD width="10%"><BR>88<BR></TD></TR>
<TR>
<TD width="43%">PNG</TD>
<TD width="20%">CXIMAGE_SUPPORT_PNG<BR></TD>
<TD width="27%"><BR>png, zlib<BR></TD>
<TD width="10%"><BR>104<BR></TD></TR>
<TR>
<TD width="43%">MNG</TD>
<TD width="20%">CXIMAGE_SUPPORT_MNG<BR></TD>
<TD width="27%"><BR>mng, zlib, jpeg<BR></TD>
<TD width="10%"><BR>148<BR></TD></TR>
<TR>
<TD width="43%">TIFF</TD>
<TD width="20%">CXIMAGE_SUPPORT_TIF<BR></TD>
<TD width="27%"><BR>tiff, zlib, jpeg<BR></TD>
<TD width="10%"><BR>124<BR></TD></TR>
<TR>
<TD width="43%">JBIG</TD>
<TD width="20%">CXIMAGE_SUPPORT_JBG</TD>
<TD width="27%"><BR>jbig<BR></TD>
<TD width="10%"><BR>28<BR></TD></TR>
<TR>
<TD width="43%">PNM,PPM,PGM<BR>RAS </TD>
<TD width="20%">CXIMAGE_SUPPORT_PNM<BR>CXIMAGE_SUPPORT_RAS</TD>
<TD width="27%"><BR>jasper<BR></TD>
<TD width="10%"><BR>176<BR></TD></TR>
<TR>
<TD width="43%">JPEG-2000<BR></TD>
<TD
width="20%">CXIMAGE_SUPPORT_JP2<BR>CXIMAGE_SUPPORT_JPC<BR>CXIMAGE_SUPPORT_PGX<BR></TD>
<TD width="27%"><BR>jasper<BR></TD>
<TD width="10%"><BR>176<BR></TD></TR></TBODY></TABLE><BR>
<TABLE cellSpacing=0 cellPadding=2 width="100%" border=1>
<TBODY>
<TR>
<TD width="43%"><B>Option</B></TD>
<TD width="47%"><B>#define</B></TD>
<TD width="10%"><B>Size [Kbyte]</B></TD></TR>
<TR>
<TD width="43%">CxImage core</TD>
<TD width="47%">all switches off</TD>
<TD width="10%">20</TD></TR>
<TR>
<TD width="43%" height=13>geometric transformations</TD>
<TD width="47%" height=13>CXIMAGE_SUPPORT_TRANSFORMATION</TD>
<TD width="10%" height=13>16</TD></TR>
<TR>
<TD width="43%">image processing</TD>
<TD width="47%">CXIMAGE_SUPPORT_DSP</TD>
<TD width="10%">24</TD></TR>
<TR>
<TD width="43%">drawing and windows specific functions</TD>
<TD width="47%">CXIMAGE_SUPPORT_WINDOWS</TD>
<TD width="10%">12</TD></TR>
<TR>
<TD width="43%">transparency</TD>
<TD width="47%">CXIMAGE_SUPPORT_ALPHA</TD>
<TD width="10%">4</TD></TR>
<TR>
<TD width="43%">selections</TD>
<TD width="47%">CXIMAGE_SUPPORT_SELECTION</TD>
<TD width="10%">4</TD></TR>
<TR>
<TD width="43%">multiple layers</TD>
<TD width="47%">CXIMAGE_SUPPORT_LAYERS</TD>
<TD width="10%">< 4</TD></TR>
<TR>
<TD width="43%">graphic formats conversion<BR></TD>
<TD width="47%">CXIMAGE_SUPPORT_DECODE<BR>CXIMAGE_SUPPORT_ENCODE </TD>
<TD width="10%">< 4</TD></TR></TBODY></TABLE>
<H2>Using CxImage in your projects<A name=projects></A></H2>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top>
<P>The <B>CxImgLib.dsw</B> workspace shows the libraries required to build
an application (demo.exe) including almost all the features and the
formats available in CxImage. You must compile all the libraries before
you can link the final application.<BR>In the same workspace you'll find
the projects to build different libraries and applications:</P>
<UL>
<LI>CxImage : <I>cximage.lib</I> - static library
<LI>CxImageCrtDll : <I>cximagecrt.dll</I> - DLL not using mfc
<LI>CxImageMfcDll : <I>cximage.dll</I> - DLL using mfc
<LI>Demo : <I>demo.exe</I> - program linked with <I>cximage.lib</I> and
the C libraries
<LI>DemoDll : <I>demodll.exe</I> - program linked with
<I>cximagecrt.dll</I>
<LI>j2k,jasper,jbig,jpeg,png,tiff,zlib : static C libraries </LI></UL>
<P>Building the projects will need some minutes to complete (the
intermediate files occupy 60MB!). When everything is done, select the demo
project and launch the application.</P></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -