~ubuntu-branches/ubuntu/gutsy/amsn/gutsy

« back to all changes in this revision

Viewing changes to utils/TkCximage/src/CxImage/ximage.h

  • Committer: Bazaar Package Importer
  • Author(s): Theodore Karkoulis
  • Date: 2006-01-04 15:26:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060104152602-ipe1yg00rl3nlklv
Tags: 0.95-1
New Upstream Release (closes: #345052, #278575).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * File:        ximage.h
 
3
 * Purpose:     General Purpose Image Class 
 
4
 */
 
5
/*
 
6
  --------------------------------------------------------------------------------
 
7
 
 
8
        COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
 
9
 
 
10
        CxImage version 5.99c 17/Oct/2004
 
11
 
 
12
        CxImage : Copyright (C) 2001 - 2004, Davide Pizzolato
 
13
 
 
14
        Original CImage and CImageIterator implementation are:
 
15
        Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx)
 
16
 
 
17
        Covered code is provided under this license on an "as is" basis, without warranty
 
18
        of any kind, either expressed or implied, including, without limitation, warranties
 
19
        that the covered code is free of defects, merchantable, fit for a particular purpose
 
20
        or non-infringing. The entire risk as to the quality and performance of the covered
 
21
        code is with you. Should any covered code prove defective in any respect, you (not
 
22
        the initial developer or any other contributor) assume the cost of any necessary
 
23
        servicing, repair or correction. This disclaimer of warranty constitutes an essential
 
24
        part of this license. No use of any covered code is authorized hereunder except under
 
25
        this disclaimer.
 
26
 
 
27
        Permission is hereby granted to use, copy, modify, and distribute this
 
28
        source code, or portions hereof, for any purpose, including commercial applications,
 
29
        freely and without fee, subject to the following restrictions: 
 
30
 
 
31
        1. The origin of this software must not be misrepresented; you must not
 
32
        claim that you wrote the original software. If you use this software
 
33
        in a product, an acknowledgment in the product documentation would be
 
34
        appreciated but is not required.
 
35
 
 
36
        2. Altered source versions must be plainly marked as such, and must not be
 
37
        misrepresented as being the original software.
 
38
 
 
39
        3. This notice may not be removed or altered from any source distribution.
 
40
 
 
41
  --------------------------------------------------------------------------------
 
42
 
 
43
        Other information: about CxImage, and the latest version, can be found at the
 
44
        CxImage home page: http://www.xdp.it
 
45
 
 
46
  --------------------------------------------------------------------------------
 
47
 */
 
48
#if !defined(__CXIMAGE_H)
 
49
#define __CXIMAGE_H
 
50
 
 
51
#if _MSC_VER > 1000
 
52
#pragma once
 
53
#endif 
 
54
 
 
55
/////////////////////////////////////////////////////////////////////////////
 
56
#include "xfile.h"
 
57
#include "xiofile.h"
 
58
#include "xmemfile.h"
 
59
#include "ximadef.h"    //<vho> adjust some #define
 
60
 
 
61
/* see "ximacfg.h" for CxImage configuration options */
 
62
 
 
63
/////////////////////////////////////////////////////////////////////////////
 
64
// CxImage formats enumerator
 
65
enum ENUM_CXIMAGE_FORMATS{
 
66
CXIMAGE_FORMAT_UNKNOWN,
 
67
#if CXIMAGE_SUPPORT_BMP
 
68
CXIMAGE_FORMAT_BMP,
 
69
#endif
 
70
#if CXIMAGE_SUPPORT_GIF
 
71
CXIMAGE_FORMAT_GIF,
 
72
#endif
 
73
#if CXIMAGE_SUPPORT_JPG
 
74
CXIMAGE_FORMAT_JPG,
 
75
#endif
 
76
#if CXIMAGE_SUPPORT_PNG
 
77
CXIMAGE_FORMAT_PNG,
 
78
#endif
 
79
#if CXIMAGE_SUPPORT_MNG
 
80
CXIMAGE_FORMAT_MNG,
 
81
#endif
 
82
#if CXIMAGE_SUPPORT_ICO
 
83
CXIMAGE_FORMAT_ICO,
 
84
#endif
 
85
#if CXIMAGE_SUPPORT_TIF
 
86
CXIMAGE_FORMAT_TIF,
 
87
#endif
 
88
#if CXIMAGE_SUPPORT_TGA
 
89
CXIMAGE_FORMAT_TGA,
 
90
#endif
 
91
#if CXIMAGE_SUPPORT_PCX
 
92
CXIMAGE_FORMAT_PCX,
 
93
#endif
 
94
#if CXIMAGE_SUPPORT_WBMP
 
95
CXIMAGE_FORMAT_WBMP,
 
96
#endif
 
97
#if CXIMAGE_SUPPORT_WMF
 
98
CXIMAGE_FORMAT_WMF,
 
99
#endif
 
100
#if CXIMAGE_SUPPORT_J2K
 
101
CXIMAGE_FORMAT_J2K,
 
102
#endif
 
103
#if CXIMAGE_SUPPORT_JBG
 
104
CXIMAGE_FORMAT_JBG,
 
105
#endif
 
106
#if CXIMAGE_SUPPORT_JP2
 
107
CXIMAGE_FORMAT_JP2,
 
108
#endif
 
109
#if CXIMAGE_SUPPORT_JPC
 
110
CXIMAGE_FORMAT_JPC,
 
111
#endif
 
112
#if CXIMAGE_SUPPORT_PGX
 
113
CXIMAGE_FORMAT_PGX,
 
114
#endif
 
115
#if CXIMAGE_SUPPORT_PNM
 
116
CXIMAGE_FORMAT_PNM,
 
117
#endif
 
118
#if CXIMAGE_SUPPORT_RAS
 
119
CXIMAGE_FORMAT_RAS,
 
120
#endif
 
121
CMAX_IMAGE_FORMATS
 
122
};
 
123
 
 
124
/////////////////////////////////////////////////////////////////////////////
 
125
// CxImage class
 
126
/////////////////////////////////////////////////////////////////////////////
 
127
class DLL_EXP CxImage
 
128
{
 
129
//extensible information collector
 
130
typedef struct tagCxImageInfo {
 
131
        DWORD   dwEffWidth;                     ///< DWORD aligned scan line width
 
132
        BYTE*   pImage;                         ///< THE IMAGE BITS
 
133
        CxImage* pGhost;                        ///< if this is a ghost, pGhost points to the body
 
134
        CxImage* pParent;                       ///< if this is a layer, pParent points to the body
 
135
        DWORD   dwType;                         ///< original image format
 
136
        char    szLastError[256];       ///< debugging
 
137
        long    nProgress;                      ///< monitor
 
138
        long    nEscape;                        ///< escape
 
139
        long    nBkgndIndex;            ///< used for GIF, PNG, MNG
 
140
        RGBQUAD nBkgndColor;            ///< used for RGB transparency
 
141
        int     m_dispmeth;             ///< used for GIF
 
142
        BYTE    nQuality;                       ///< used for JPEG
 
143
        BYTE    nJpegScale;                     ///< used for JPEG [ignacio]
 
144
        long    nFrame;                         ///< used for TIF, GIF, MNG : actual frame
 
145
        long    nNumFrames;                     ///< used for TIF, GIF, MNG : total number of frames
 
146
        DWORD   dwFrameDelay;           ///< used for GIF, MNG
 
147
        long    xDPI;                           ///< horizontal resolution
 
148
        long    yDPI;                           ///< vertical resolution
 
149
        RECT    rSelectionBox;          ///< bounding rectangle
 
150
        BYTE    nAlphaMax;                      ///< max opacity (fade)
 
151
        bool    bAlphaPaletteEnabled; ///< true if alpha values in the palette are enabled.
 
152
        bool    bEnabled;                       ///< enables the painting functions
 
153
        long    xOffset;
 
154
        long    yOffset;
 
155
        DWORD   dwCodecOpt[CMAX_IMAGE_FORMATS]; ///< for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg
 
156
        RGBQUAD last_c;                         ///< for GetNearestIndex optimization
 
157
        BYTE    last_c_index;
 
158
        bool    last_c_isvalid;
 
159
        long    nNumLayers;
 
160
        DWORD   dwFlags;                        ///< 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags
 
161
        bool    bGetAllFrames;
 
162
        CxImage ** GifFrames;
 
163
 
 
164
} CXIMAGEINFO;
 
165
 
 
166
public:
 
167
        //public structures
 
168
struct rgb_color { BYTE r,g,b; };
 
169
 
 
170
#if CXIMAGE_SUPPORT_WINDOWS
 
171
// <VATI> text placement data
 
172
// members must be initialized with the InitTextInfo(&this) function.
 
173
typedef struct tagCxTextInfo
 
174
{
 
175
        TCHAR    text[4096]; ///< text (char -> TCHAR for UNICODE [Cesar M])
 
176
        LOGFONT  lfont;      ///< font and codepage data
 
177
    COLORREF fcolor;     ///< foreground color
 
178
    long     align;      ///< DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text
 
179
    BYTE     opaque;     ///< text has background or hasn't. Default is true.
 
180
                                                 ///< data for background (ignored if .opaque==FALSE) 
 
181
    COLORREF bcolor;     ///< background color
 
182
    float    b_opacity;  ///< opacity value for background between 0.0-1.0 Default is 0. (opaque)
 
183
    BYTE     b_outline;  ///< outline width for background (zero: no outline)
 
184
    BYTE     b_round;    ///< rounding radius for background rectangle. % of the height, between 0-50. Default is 10.
 
185
                         ///< (backgr. always has a frame: width = 3 pixel + 10% of height by default.)
 
186
} CXTEXTINFO;
 
187
#endif
 
188
 
 
189
public:
 
190
/** \addtogroup Constructors */ //@{
 
191
        CxImage(DWORD imagetype = 0);
 
192
        CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
 
193
        CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
 
194
        CxImage(const TCHAR * filename, DWORD imagetype);       // For UNICODE support: char -> TCHAR
 
195
        CxImage(FILE * stream, DWORD imagetype);
 
196
        CxImage(CxFile * stream, DWORD imagetype);
 
197
        CxImage(BYTE * buffer, DWORD size, DWORD imagetype);
 
198
        virtual ~CxImage() { Destroy(); DestroyGifFrames();};
 
199
        CxImage& operator = (const CxImage&);
 
200
//@}
 
201
 
 
202
/** \addtogroup Initialization */ //@{
 
203
        void*   Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
 
204
        bool    Destroy();
 
205
        bool    DestroyGifFrames();
 
206
        void    Clear(BYTE bval=0);
 
207
        void    Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
 
208
        bool    Transfer(CxImage &from);
 
209
        bool    CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage);
 
210
        bool    CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage);
 
211
        void    FreeMemory(void* memblock);
 
212
//@}
 
213
 
 
214
/** \addtogroup Attributes */ //@{
 
215
        long    GetSize();
 
216
        BYTE*   GetBits(DWORD row = 0);
 
217
        BYTE    GetColorType();
 
218
        void*   GetDIB() const;
 
219
        DWORD   GetHeight() const;
 
220
        DWORD   GetWidth() const;
 
221
        DWORD   GetEffWidth() const;
 
222
        DWORD   GetNumColors() const;
 
223
        WORD    GetBpp() const;
 
224
        DWORD   GetType() const;
 
225
        const char*     GetLastError();
 
226
        const TCHAR* GetVersion();
 
227
        const float GetVersionNumber();
 
228
 
 
229
        DWORD   GetFrameDelay() const;
 
230
        void    SetFrameDelay(DWORD d);
 
231
 
 
232
        void    GetOffset(long *x,long *y);
 
233
        void    SetOffset(long x,long y);
 
234
 
 
235
        BYTE    GetJpegQuality() const;
 
236
        void    SetJpegQuality(BYTE q);
 
237
 
 
238
        BYTE    GetJpegScale() const;
 
239
        void    SetJpegScale(BYTE q);
 
240
 
 
241
        long    GetXDPI() const;
 
242
        long    GetYDPI() const;
 
243
        void    SetXDPI(long dpi);
 
244
        void    SetYDPI(long dpi);
 
245
 
 
246
        DWORD   GetClrImportant() const;
 
247
        void    SetClrImportant(DWORD ncolors = 0);
 
248
 
 
249
        long    GetProgress() const;
 
250
        long    GetEscape() const;
 
251
        void    SetProgress(long p);
 
252
        void    SetEscape(long i);
 
253
 
 
254
        long    GetTransIndex() const;
 
255
        RGBQUAD GetTransColor();
 
256
        void    SetTransIndex(long idx);
 
257
        void    SetTransColor(RGBQUAD rgb);
 
258
        bool    IsTransparent() const;
 
259
        void    SetDisposalMethod(int dm);
 
260
        long    GetDisposalMethod();
 
261
 
 
262
        DWORD   GetCodecOption(DWORD imagetype = 0);
 
263
        bool    SetCodecOption(DWORD opt, DWORD imagetype = 0);
 
264
 
 
265
        DWORD   GetFlags() const;
 
266
        void    SetFlags(DWORD flags, bool bLockReservedFlags = true);
 
267
 
 
268
        //void* GetUserData() const {return info.pUserData;}
 
269
        //void  SetUserData(void* pUserData) {info.pUserData = pUserData;}
 
270
//@}
 
271
 
 
272
/** \addtogroup Palette
 
273
 * These functions have no effects on RGB images and in this case the returned value is always 0.
 
274
 * @{ */
 
275
        bool    IsGrayScale();
 
276
        bool    IsIndexed() const;
 
277
        bool    IsSamePalette(CxImage &img, bool bCheckAlpha = true);
 
278
        DWORD   GetPaletteSize();
 
279
        RGBQUAD* GetPalette() const;
 
280
        RGBQUAD GetPaletteColor(BYTE idx);
 
281
        bool    GetPaletteColor(BYTE i, BYTE* r, BYTE* g, BYTE* b);
 
282
        BYTE    GetNearestIndex(RGBQUAD c);
 
283
        void    BlendPalette(COLORREF cr,long perc);
 
284
        void    SetGrayPalette();
 
285
        void    SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b);
 
286
        void    SetPalette(RGBQUAD* pPal,DWORD nColors=256);
 
287
        void    SetPalette(rgb_color *rgb,DWORD nColors=256);
 
288
        void    SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha=0);
 
289
        void    SetPaletteColor(BYTE idx, RGBQUAD c);
 
290
        void    SetPaletteColor(BYTE idx, COLORREF cr);
 
291
        void    SwapIndex(BYTE idx1, BYTE idx2);
 
292
        void    SetStdPalette();
 
293
//@}
 
294
 
 
295
/** \addtogroup Pixel */ //@{
 
296
        bool    IsInside(long x, long y);
 
297
        bool    IsTransparent(long x,long y);
 
298
        RGBQUAD GetPixelColor(long x,long y, bool bGetAlpha = true);
 
299
        BYTE    GetPixelIndex(long x,long y);
 
300
        BYTE    GetPixelGray(long x, long y);
 
301
        void    SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false);
 
302
        void    SetPixelColor(long x,long y,COLORREF cr);
 
303
        void    SetPixelIndex(long x,long y,BYTE i);
 
304
        void    DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha=false);
 
305
        void    DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr);
 
306
        void    BlendPixelColor(long x,long y,RGBQUAD c, float blend, bool bSetAlpha = false);
 
307
//@}
 
308
 
 
309
protected:
 
310
/** \addtogroup Protected */ //@{
 
311
        BYTE BlindGetPixelIndex(const long x,const long y);
 
312
        RGBQUAD BlindGetPixelColor(const long x,const long y);
 
313
        void *BlindGetPixelPointer(const long x,const  long y);
 
314
//@}
 
315
 
 
316
public:
 
317
 
 
318
#if CXIMAGE_SUPPORT_INTERPOLATION
 
319
/** \addtogroup Interpolation */ //@{
 
320
        //overflow methods:
 
321
        enum OverflowMethod {
 
322
                OM_COLOR=1,
 
323
                OM_BACKGROUND=2,
 
324
                OM_TRANSPARENT=3,
 
325
                OM_WRAP=4,
 
326
                OM_REPEAT=5,
 
327
                OM_MIRROR=6
 
328
        };
 
329
        void OverflowCoordinates(float &x, float &y, OverflowMethod const ofMethod);
 
330
        void OverflowCoordinates(long  &x, long &y, OverflowMethod const ofMethod);
 
331
        RGBQUAD GetPixelColorWithOverflow(long x, long y, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
 
332
        //interpolation methods:
 
333
        enum InterpolationMethod {
 
334
                IM_NEAREST_NEIGHBOUR=1,
 
335
                IM_BILINEAR             =2,
 
336
                IM_BSPLINE              =3,
 
337
                IM_BICUBIC              =4,
 
338
                IM_BICUBIC2             =5,
 
339
                IM_LANCZOS              =6,
 
340
                IM_BOX                  =7,
 
341
                IM_HERMITE              =8,
 
342
                IM_HAMMING              =9,
 
343
                IM_SINC                 =10,
 
344
                IM_BLACKMAN             =11,
 
345
                IM_BESSEL               =12,
 
346
                IM_GAUSSIAN             =13,
 
347
                IM_QUADRATIC    =14,
 
348
                IM_MITCHELL             =15,
 
349
                IM_CATROM               =16
 
350
        };
 
351
        RGBQUAD GetPixelColorInterpolated(float x,float y, InterpolationMethod const inMethod=IM_BILINEAR, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
 
352
        RGBQUAD GetAreaColorInterpolated(float const xc, float const yc, float const w, float const h, InterpolationMethod const inMethod, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
 
353
//@}
 
354
 
 
355
protected:
 
356
/** \addtogroup Protected */ //@{
 
357
        void  AddAveragingCont(RGBQUAD const &color, float const surf, float &rr, float &gg, float &bb, float &aa);
 
358
//@}
 
359
 
 
360
/** \addtogroup Kernels */ //@{
 
361
public:
 
362
        static float KernelBSpline(const float x);
 
363
        static float KernelLinear(const float t);
 
364
        static float KernelCubic(const float t);
 
365
        static float KernelGeneralizedCubic(const float t, const float a=-1);
 
366
        static float KernelLanczosSinc(const float t, const float r = 3);
 
367
        static float KernelBox(const float x);
 
368
        static float KernelHermite(const float x);
 
369
        static float KernelHamming(const float x);
 
370
        static float KernelSinc(const float x);
 
371
        static float KernelBlackman(const float x);
 
372
        static float KernelBessel_J1(const float x);
 
373
        static float KernelBessel_P1(const float x);
 
374
        static float KernelBessel_Q1(const float x);
 
375
        static float KernelBessel_Order1(float x);
 
376
        static float KernelBessel(const float x);
 
377
        static float KernelGaussian(const float x);
 
378
        static float KernelQuadratic(const float x);
 
379
        static float KernelMitchell(const float x);
 
380
        static float KernelCatrom(const float x);
 
381
//@}
 
382
#endif //CXIMAGE_SUPPORT_INTERPOLATION
 
383
        
 
384
/** \addtogroup Painting */ //@{
 
385
#if CXIMAGE_SUPPORT_WINCE
 
386
        long    Blt(HDC pDC, long x=0, long y=0);
 
387
#endif
 
388
#if CXIMAGE_SUPPORT_WINDOWS
 
389
        HBITMAP MakeBitmap(HDC hdc = NULL);
 
390
        HANDLE  CopyToHandle();
 
391
        bool    CreateFromHANDLE(HANDLE hMem);          //Windows objects (clipboard)
 
392
        bool    CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0);       //Windows resource
 
393
        bool    CreateFromHICON(HICON hico);
 
394
        long    Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
 
395
        long    Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
 
396
        long    Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY);
 
397
        long    Stretch(HDC hdc, const RECT& rect, DWORD dwRop = SRCCOPY);
 
398
        long    Tile(HDC hdc, RECT *rc);
 
399
        long    Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1);
 
400
        long    Draw2(HDC hdc, const RECT& rect);
 
401
        //long  DrawString(HDC hdc, long x, long y, const char* text, RGBQUAD color, const char* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false);
 
402
        long    DrawString(HDC hdc, long x, long y, const TCHAR* text, RGBQUAD color, const TCHAR* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false);
 
403
        // <VATI> extensions
 
404
        long    DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false );
 
405
        void    InitTextInfo( CXTEXTINFO *txt );
 
406
#endif //CXIMAGE_SUPPORT_WINDOWS
 
407
//@}
 
408
 
 
409
        // file operations
 
410
#if CXIMAGE_SUPPORT_DECODE
 
411
/** \addtogroup Decode */ //@{
 
412
#ifdef WIN32
 
413
        //bool Load(LPCWSTR filename, DWORD imagetype=0);
 
414
        bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL);
 
415
#endif
 
416
        // For UNICODE support: char -> TCHAR
 
417
        bool Load(const TCHAR* filename, DWORD imagetype=0);
 
418
        //bool Load(const char * filename, DWORD imagetype=0);
 
419
        bool Decode(FILE * hFile, DWORD imagetype);
 
420
        bool Decode(CxFile * hFile, DWORD imagetype);
 
421
        bool Decode(BYTE * buffer, DWORD size, DWORD imagetype);
 
422
//@}
 
423
#endif //CXIMAGE_SUPPORT_DECODE
 
424
 
 
425
#if CXIMAGE_SUPPORT_ENCODE
 
426
protected:
 
427
/** \addtogroup Protected */ //@{
 
428
        bool EncodeSafeCheck(CxFile *hFile);
 
429
//@}
 
430
 
 
431
public:
 
432
/** \addtogroup Encode */ //@{
 
433
#ifdef WIN32
 
434
        //bool Save(LPCWSTR filename, DWORD imagetype=0);
 
435
#endif
 
436
        // For UNICODE support: char -> TCHAR
 
437
        bool Save(const TCHAR* filename, DWORD imagetype);
 
438
        //bool Save(const char * filename, DWORD imagetype=0);
 
439
        bool Encode(FILE * hFile, DWORD imagetype);
 
440
        bool Encode(CxFile * hFile, DWORD imagetype);
 
441
        bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
 
442
        bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
 
443
        bool Encode(BYTE * &buffer, long &size, DWORD imagetype);
 
444
 
 
445
        bool Encode2RGBA(CxFile *hFile);
 
446
        bool Encode2RGBA(BYTE * &buffer, long &size);
 
447
//@}
 
448
#endif //CXIMAGE_SUPPORT_ENCODE
 
449
 
 
450
/** \addtogroup Attributes */ //@{
 
451
        //misc.
 
452
        bool IsValid() const;
 
453
        bool IsEnabled() const;
 
454
        void Enable(bool enable=true);
 
455
 
 
456
        // frame operations
 
457
        long GetNumFrames() const;
 
458
        long GetFrame() const;
 
459
        void SetFrame(long nFrame);
 
460
                
 
461
        CxImage * GetFrameNo(long nFrame) const;
 
462
        void RetreiveAllFrame();
 
463
        void RetreiveSingleFrame();
 
464
//@}
 
465
 
 
466
#if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
 
467
/** \addtogroup BasicTransformations */ //@{
 
468
        bool GrayScale();
 
469
        bool Flip();
 
470
        bool Mirror();
 
471
        bool Negative();
 
472
        bool RotateLeft(CxImage* iDst = NULL);
 
473
        bool RotateRight(CxImage* iDst = NULL);
 
474
//@}
 
475
#endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
 
476
 
 
477
#if CXIMAGE_SUPPORT_TRANSFORMATION
 
478
/** \addtogroup Transformations */ //@{
 
479
        // image operations
 
480
        bool Rotate(float angle, CxImage* iDst = NULL);
 
481
        bool Rotate2(float angle, CxImage *iDst = NULL, InterpolationMethod inMethod=IM_BILINEAR,
 
482
                OverflowMethod ofMethod=OM_BACKGROUND, RGBQUAD *replColor=0,
 
483
                bool const optimizeRightAngles=true, bool const bKeepOriginalSize=false);
 
484
        bool Rotate180(CxImage* iDst = NULL);
 
485
        bool Resample(long newx, long newy, int mode = 1, CxImage* iDst = NULL);
 
486
        bool Resample2(long newx, long newy, InterpolationMethod const inMethod=IM_BICUBIC2,
 
487
                                OverflowMethod const ofMethod=OM_REPEAT, CxImage* const iDst = NULL,
 
488
                                bool const disableAveraging=false);
 
489
        bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0);
 
490
        bool IncreaseBpp(DWORD nbit);
 
491
        bool Dither(long method = 0);
 
492
        bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL);
 
493
        bool Crop(const RECT& rect, CxImage* iDst = NULL);
 
494
        bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL);
 
495
        bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0, bool bEnableInterpolation = false);
 
496
        bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0);
 
497
        bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
 
498
        bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
 
499
        bool CircleTransform(int type,long rmax=0,float Koeff=1.0f);
 
500
        bool RedEyeRemove();
 
501
        bool QIShrink(long newx, long newy, CxImage* const iDst = NULL);
 
502
//@}
 
503
#endif //CXIMAGE_SUPPORT_TRANSFORMATION
 
504
 
 
505
#if CXIMAGE_SUPPORT_DSP
 
506
/** \addtogroup DSP */ //@{
 
507
        bool Contour();
 
508
        bool HistogramStretch(long method = 0);
 
509
        bool HistogramEqualize();
 
510
        bool HistogramNormalize();
 
511
        bool HistogramRoot();
 
512
        bool HistogramLog();
 
513
        long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0);
 
514
        bool Jitter(long radius=2);
 
515
        bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0);
 
516
        bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0);
 
517
        bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true);
 
518
        bool Noise(long level);
 
519
        bool Median(long Ksize=3);
 
520
        bool Gamma(float gamma);
 
521
        bool ShiftRGB(long r, long g, long b);
 
522
        bool Threshold(BYTE level);
 
523
        bool Colorize(BYTE hue, BYTE sat, float blend = 1.0f);
 
524
        bool Light(long brightness, long contrast = 0);
 
525
        float Mean();
 
526
        bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset);
 
527
        bool Erode(long Ksize=2);
 
528
        bool Dilate(long Ksize=2);
 
529
        bool Edge(long Ksize=2);
 
530
        void HuePalette(float correction=1);
 
531
        enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend, OpScreen };
 
532
        void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0, bool bMixAlpha = false);
 
533
        void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset);
 
534
        bool UnsharpMask(float radius = 5.0, float amount = 0.5, int threshold = 0);
 
535
        bool Lut(BYTE* pLut);
 
536
        bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0);
 
537
//@}
 
538
 
 
539
protected:
 
540
/** \addtogroup Protected */ //@{
 
541
        bool IsPowerof2(long x);
 
542
        bool FFT(int dir,int m,double *x,double *y);
 
543
        bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2);
 
544
        bool RepairChannel(CxImage *ch, float radius);
 
545
        // <nipper>
 
546
        int gen_convolve_matrix (float radius, float **cmatrix_p);
 
547
        float* gen_lookup_table (float *cmatrix, int cmatrix_length);
 
548
        void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes);
 
549
//@}
 
550
 
 
551
public:
 
552
/** \addtogroup ColorSpace */ //@{
 
553
        bool SplitRGB(CxImage* r,CxImage* g,CxImage* b);
 
554
        bool SplitYUV(CxImage* y,CxImage* u,CxImage* v);
 
555
        bool SplitHSL(CxImage* h,CxImage* s,CxImage* l);
 
556
        bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q);
 
557
        bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z);
 
558
        bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k);
 
559
        static RGBQUAD HSLtoRGB(COLORREF cHSLColor);
 
560
        static RGBQUAD RGBtoHSL(RGBQUAD lRGBColor);
 
561
        static RGBQUAD HSLtoRGB(RGBQUAD lHSLColor);
 
562
        static RGBQUAD YUVtoRGB(RGBQUAD lYUVColor);
 
563
        static RGBQUAD RGBtoYUV(RGBQUAD lRGBColor);
 
564
        static RGBQUAD YIQtoRGB(RGBQUAD lYIQColor);
 
565
        static RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor);
 
566
        static RGBQUAD XYZtoRGB(RGBQUAD lXYZColor);
 
567
        static RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor);
 
568
#endif //CXIMAGE_SUPPORT_DSP
 
569
        static RGBQUAD RGBtoRGBQUAD(COLORREF cr);
 
570
        static COLORREF RGBQUADtoRGB (RGBQUAD c);
 
571
//@}
 
572
 
 
573
#if CXIMAGE_SUPPORT_SELECTION
 
574
/** \addtogroup Selection */ //@{
 
575
        bool SelectionClear();
 
576
        bool SelectionCreate();
 
577
        bool SelectionDelete();
 
578
        bool SelectionInvert();
 
579
        bool SelectionAddRect(RECT r);
 
580
        bool SelectionAddEllipse(RECT r);
 
581
        bool SelectionAddPolygon(POINT *points, long npoints);
 
582
        bool SelectionAddColor(RGBQUAD c);
 
583
        bool SelectionAddPixel(int x, int y);
 
584
        bool SelectionCopy(CxImage &from);
 
585
        bool SelectionIsInside(long x, long y);
 
586
        bool SelectionIsValid();
 
587
        void SelectionGetBox(RECT& r);
 
588
        bool SelectionToHRGN(HRGN& region);
 
589
        bool SelectionSplit(CxImage *dest);
 
590
//@}
 
591
#endif //CXIMAGE_SUPPORT_SELECTION
 
592
 
 
593
#if CXIMAGE_SUPPORT_ALPHA
 
594
/** \addtogroup Alpha */ //@{
 
595
        void AlphaClear();
 
596
        void AlphaCreate();
 
597
        void AlphaDelete();
 
598
        void AlphaInvert();
 
599
        bool AlphaMirror();
 
600
        bool AlphaFlip();
 
601
        bool AlphaCopy(CxImage &from);
 
602
        bool AlphaSplit(CxImage *dest);
 
603
        void AlphaStrip();
 
604
        void AlphaSet(BYTE level);
 
605
        bool AlphaSet(CxImage &from);
 
606
        void AlphaSet(const long x,const long y,const BYTE level);
 
607
        BYTE AlphaGet(const long x,const long y);
 
608
        BYTE AlphaGetMax() const;
 
609
        void AlphaSetMax(BYTE nAlphaMax);
 
610
        bool AlphaIsValid();
 
611
        BYTE* AlphaGetPointer(const long x = 0,const long y = 0);
 
612
 
 
613
        void AlphaPaletteClear();
 
614
        void AlphaPaletteEnable(bool enable=true);
 
615
        bool AlphaPaletteIsEnabled();
 
616
        bool AlphaPaletteIsValid();
 
617
        bool AlphaPaletteSplit(CxImage *dest);
 
618
//@}
 
619
 
 
620
protected:
 
621
/** \addtogroup Protected */ //@{
 
622
        BYTE BlindAlphaGet(const long x,const long y);
 
623
//@}
 
624
#endif //CXIMAGE_SUPPORT_ALPHA
 
625
 
 
626
public:
 
627
#if CXIMAGE_SUPPORT_LAYERS
 
628
/** \addtogroup Layers */ //@{
 
629
        bool LayerCreate(long position = -1);
 
630
        bool LayerDelete(long position = -1);
 
631
        void LayerDeleteAll();
 
632
        CxImage* GetLayer(long position);
 
633
        CxImage* GetParent() const;
 
634
        long GetNumLayers() const;
 
635
//@}
 
636
#endif //CXIMAGE_SUPPORT_LAYERS
 
637
 
 
638
protected:
 
639
/** \addtogroup Protected */ //@{
 
640
        void Startup(DWORD imagetype = 0);
 
641
        void CopyInfo(const CxImage &src);
 
642
        void Ghost(CxImage *src);
 
643
        void RGBtoBGR(BYTE *buffer, int length);
 
644
        static float HueToRGB(float n1,float n2, float hue);
 
645
        void Bitfield2RGB(BYTE *src, WORD redmask, WORD greenmask, WORD bluemask, BYTE bpp);
 
646
        static int CompareColors(const void *elem1, const void *elem2);
 
647
 
 
648
        void*                           pDib; //contains the header, the palette, the pixels
 
649
    BITMAPINFOHEADER    head; //standard header
 
650
        CXIMAGEINFO                     info; //extended information
 
651
        BYTE*                           pSelection;     //selected region
 
652
        BYTE*                           pAlpha; //alpha channel
 
653
        CxImage**                       pLayers; //generic layers
 
654
//@}
 
655
};
 
656
 
 
657
////////////////////////////////////////////////////////////////////////////
 
658
#endif // !defined(__CXIMAGE_H)