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

« back to all changes in this revision

Viewing changes to utils/TkCximage/src/CxImage/ximainfo.cpp

  • 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
// ximainfo.cpp : main attributes
 
2
/* 03/10/2004 v1.00 - Davide Pizzolato - www.xdp.it
 
3
 * CxImage version 5.99c 17/Oct/2004
 
4
 */
 
5
 
 
6
#include "ximage.h"
 
7
 
 
8
////////////////////////////////////////////////////////////////////////////////
 
9
/**
 
10
 * \return the color used for transparency, and/or for background color
 
11
 */
 
12
RGBQUAD CxImage::GetTransColor()
 
13
{
 
14
        if (head.biBitCount<24 && info.nBkgndIndex != -1) return GetPaletteColor((BYTE)info.nBkgndIndex);
 
15
        return info.nBkgndColor;
 
16
}
 
17
////////////////////////////////////////////////////////////////////////////////
 
18
/**
 
19
 * Gets the index used for transparency. Returns -1 for no transparancy.
 
20
 */
 
21
long CxImage::GetTransIndex() const
 
22
{
 
23
        return info.nBkgndIndex;
 
24
}
 
25
////////////////////////////////////////////////////////////////////////////////
 
26
/**
 
27
 * Sets the index used for transparency with 1, 4 and 8 bpp images. Set to -1 to remove the effect.
 
28
 */
 
29
void CxImage::SetTransIndex(long idx)
 
30
{
 
31
        info.nBkgndIndex = idx;
 
32
}
 
33
////////////////////////////////////////////////////////////////////////////////
 
34
/**
 
35
 * Sets the color used for transparency with 24 bpp images.
 
36
 * You must call SetTransIndex(0) to enable the effect, SetTransIndex(-1) to disable it.
 
37
 */
 
38
void CxImage::SetTransColor(RGBQUAD rgb)
 
39
{
 
40
        rgb.rgbReserved=0;
 
41
        info.nBkgndColor = rgb;
 
42
}
 
43
////////////////////////////////////////////////////////////////////////////////
 
44
bool CxImage::IsTransparent() const
 
45
{
 
46
        return info.nBkgndIndex>=0; // <vho>
 
47
}
 
48
////////////////////////////////////////////////////////////////////////////////
 
49
/**
 
50
 * Returns true if the image has 256 colors or less.
 
51
 */
 
52
bool CxImage::IsIndexed() const
 
53
{
 
54
        return head.biClrUsed!=0;
 
55
}
 
56
////////////////////////////////////////////////////////////////////////////////
 
57
/**
 
58
 * Sets the method for drawing the frame related to others
 
59
 */
 
60
void CxImage::SetDisposalMethod(int dm)
 
61
{       info.m_dispmeth=dm; }
 
62
////////////////////////////////////////////////////////////////////////////////
 
63
/**
 
64
 * Gets the method for drawing the frame related to others
 
65
 * Values :    0 -   No disposal specified. The decoder is
 
66
 *                   not required to take any action.
 
67
 *             1 -   Do not dispose. The graphic is to be left
 
68
 *                   in place.
 
69
 *             2 -   Restore to background color. The area used by the
 
70
 *                   graphic must be restored to the background color.
 
71
 *             3 -   Restore to previous. The decoder is required to
 
72
 *                   restore the area overwritten by the graphic with
 
73
 *                   what was there prior to rendering the graphic.
 
74
 *             4-7 -    To be defined.
 
75
 */
 
76
long CxImage::GetDisposalMethod()
 
77
{       return info.m_dispmeth; }
 
78
////////////////////////////////////////////////////////////////////////////////
 
79
/**
 
80
 * \return 1 = indexed, 2 = RGB, 4 = RGBA
 
81
 */
 
82
BYTE CxImage::GetColorType()
 
83
{
 
84
        BYTE b = (BYTE)((head.biBitCount>8) ? 2 /*COLORTYPE_COLOR*/ : 1 /*COLORTYPE_PALETTE*/);
 
85
#if CXIMAGE_SUPPORT_ALPHA
 
86
        if (AlphaIsValid()) b = 4 /*COLORTYPE_ALPHA*/;
 
87
#endif //CXIMAGE_SUPPORT_ALPHA
 
88
        return b;
 
89
}
 
90
////////////////////////////////////////////////////////////////////////////////
 
91
/**
 
92
 * \return Resolution for TIFF, JPEG, PNG and BMP formats.
 
93
 */
 
94
long CxImage::GetXDPI() const
 
95
{
 
96
        return info.xDPI;
 
97
}
 
98
////////////////////////////////////////////////////////////////////////////////
 
99
/**
 
100
 * \return Resolution for TIFF, JPEG, PNG and BMP formats.
 
101
 */
 
102
long CxImage::GetYDPI() const
 
103
{
 
104
        return info.yDPI;
 
105
}
 
106
////////////////////////////////////////////////////////////////////////////////
 
107
/**
 
108
 * Set resolution for TIFF, JPEG, PNG and BMP formats.
 
109
 */
 
110
void CxImage::SetXDPI(long dpi)
 
111
{
 
112
        if (dpi<=0) dpi=96;
 
113
        info.xDPI = dpi;
 
114
        head.biXPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5);
 
115
}
 
116
////////////////////////////////////////////////////////////////////////////////
 
117
/**
 
118
 * Set resolution for TIFF, JPEG, PNG and BMP formats.
 
119
 */
 
120
void CxImage::SetYDPI(long dpi)
 
121
{
 
122
        if (dpi<=0) dpi=96;
 
123
        info.yDPI = dpi;
 
124
        head.biYPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5);
 
125
}
 
126
////////////////////////////////////////////////////////////////////////////////
 
127
/**
 
128
 * \sa SetFlags
 
129
 */
 
130
DWORD CxImage::GetFlags() const
 
131
{
 
132
        return info.dwFlags;
 
133
}
 
134
////////////////////////////////////////////////////////////////////////////////
 
135
/**
 
136
 * Image flags, for future use
 
137
 * \param flags
 
138
 *  - 0x??00000 = reserved for 16 bit, CMYK, multilayer
 
139
 *  - 0x00??0000 = blend modes
 
140
 *  - 0x0000???? = layer id or user flags
 
141
 *
 
142
 * \param bLockReservedFlags protects the "reserved" and "blend modes" flags 
 
143
 */
 
144
void CxImage::SetFlags(DWORD flags, bool bLockReservedFlags)
 
145
{
 
146
        if (bLockReservedFlags) info.dwFlags = flags & 0x0000ffff;
 
147
        else info.dwFlags = flags;
 
148
}
 
149
////////////////////////////////////////////////////////////////////////////////
 
150
/**
 
151
 * \sa SetCodecOption
 
152
 */
 
153
DWORD CxImage::GetCodecOption(DWORD imagetype)
 
154
{
 
155
        if (imagetype<CMAX_IMAGE_FORMATS){
 
156
                if (imagetype==0){
 
157
                        imagetype = GetType();
 
158
                }
 
159
                return info.dwCodecOpt[imagetype];
 
160
        }
 
161
        return 0;
 
162
}
 
163
////////////////////////////////////////////////////////////////////////////////
 
164
/**
 
165
 * Encode option for GIF, TIF and JPG.
 
166
 * - GIF : 0 = LZW (default), 1 = none, 2 = RLE.
 
167
 * - TIF : 0 = automatic (default), or a valid compression code as defined in "tiff.h" (COMPRESSION_NONE = 1, COMPRESSION_CCITTRLE = 2, ...)
 
168
 * - JPG : valid values stored in enum CODEC_OPTION ( ENCODE_BASELINE = 0x01, ENCODE_PROGRESSIVE = 0x10, ...)
 
169
 *
 
170
 * \return true if everything is ok
 
171
 */
 
172
bool CxImage::SetCodecOption(DWORD opt, DWORD imagetype)
 
173
{
 
174
        if (imagetype<CMAX_IMAGE_FORMATS){
 
175
                if (imagetype==0){
 
176
                        imagetype = GetType();
 
177
                }
 
178
                info.dwCodecOpt[imagetype] = opt;
 
179
                return true;
 
180
        }
 
181
        return false;
 
182
}
 
183
////////////////////////////////////////////////////////////////////////////////
 
184
/**
 
185
 * \return internal hDib object..
 
186
 */
 
187
void* CxImage::GetDIB() const
 
188
{
 
189
        return pDib;
 
190
}
 
191
////////////////////////////////////////////////////////////////////////////////
 
192
DWORD CxImage::GetHeight() const
 
193
{
 
194
        return head.biHeight;
 
195
}
 
196
////////////////////////////////////////////////////////////////////////////////
 
197
DWORD CxImage::GetWidth() const
 
198
{
 
199
        return head.biWidth;
 
200
}
 
201
////////////////////////////////////////////////////////////////////////////////
 
202
/**
 
203
 * \return DWORD aligned width of the image.
 
204
 */
 
205
DWORD CxImage::GetEffWidth() const
 
206
{
 
207
        return info.dwEffWidth;
 
208
}
 
209
////////////////////////////////////////////////////////////////////////////////
 
210
/**
 
211
 * \return 2, 16, 256; 0 for RGB images.
 
212
 */
 
213
DWORD CxImage::GetNumColors() const
 
214
{
 
215
        return head.biClrUsed;
 
216
}
 
217
////////////////////////////////////////////////////////////////////////////////
 
218
/**
 
219
 * \return: 1, 4, 8, 24.
 
220
 */
 
221
WORD CxImage::GetBpp() const
 
222
{
 
223
        return head.biBitCount;
 
224
}
 
225
////////////////////////////////////////////////////////////////////////////////
 
226
/**
 
227
 * \return original image format
 
228
 * \sa ENUM_CXIMAGE_FORMATS.
 
229
 */
 
230
DWORD CxImage::GetType() const
 
231
{
 
232
        return info.dwType;
 
233
}
 
234
////////////////////////////////////////////////////////////////////////////////
 
235
/**
 
236
 * \return current frame delay in milliseconds. Only for GIF and MNG formats.
 
237
 */
 
238
DWORD CxImage::GetFrameDelay() const
 
239
{
 
240
        return info.dwFrameDelay;
 
241
}
 
242
////////////////////////////////////////////////////////////////////////////////
 
243
/**
 
244
 * Sets current frame delay. Only for GIF format.
 
245
 * \param d = delay in milliseconds
 
246
 */
 
247
void CxImage::SetFrameDelay(DWORD d)
 
248
{
 
249
        info.dwFrameDelay=d;
 
250
}
 
251
////////////////////////////////////////////////////////////////////////////////
 
252
void CxImage::GetOffset(long *x,long *y)
 
253
{
 
254
        *x=info.xOffset;
 
255
        *y=info.yOffset;
 
256
}
 
257
////////////////////////////////////////////////////////////////////////////////
 
258
void CxImage::SetOffset(long x,long y)
 
259
{
 
260
        info.xOffset=x;
 
261
        info.yOffset=y;
 
262
}
 
263
////////////////////////////////////////////////////////////////////////////////
 
264
/**
 
265
 * \sa SetJpegQuality
 
266
 */
 
267
BYTE CxImage::GetJpegQuality() const
 
268
{
 
269
        return info.nQuality;
 
270
}
 
271
////////////////////////////////////////////////////////////////////////////////
 
272
/**
 
273
 * quality level for JPEG and JPEG2000
 
274
 * \param q: can be from 0 to 100
 
275
 */
 
276
void CxImage::SetJpegQuality(BYTE q){
 
277
        info.nQuality = q;
 
278
}
 
279
////////////////////////////////////////////////////////////////////////////////
 
280
/**
 
281
 * \sa SetJpegScale
 
282
 */
 
283
BYTE CxImage::GetJpegScale() const
 
284
{
 
285
        return info.nJpegScale;
 
286
}
 
287
////////////////////////////////////////////////////////////////////////////////
 
288
/**
 
289
 * scaling down during JPEG decoding valid numbers are 1, 2, 4, 8
 
290
 * \author [ignacio]
 
291
 */
 
292
void CxImage::SetJpegScale(BYTE q){
 
293
        info.nJpegScale = q;
 
294
}
 
295
////////////////////////////////////////////////////////////////////////////////
 
296
/**
 
297
 * Used to monitor the slow loops.
 
298
 * \return value is from 0 to 100.
 
299
 * \sa SetProgress
 
300
 */
 
301
long CxImage::GetProgress() const
 
302
{
 
303
        return info.nProgress;
 
304
}
 
305
////////////////////////////////////////////////////////////////////////////////
 
306
/**
 
307
 * \return the escape code.
 
308
 * \sa SetEscape
 
309
 */
 
310
long CxImage::GetEscape() const
 
311
{
 
312
        return info.nEscape;
 
313
}
 
314
////////////////////////////////////////////////////////////////////////////////
 
315
/**
 
316
 * Forces the value of the internal progress variable.
 
317
 * \param p should be from 0 to 100.
 
318
 * \sa GetProgress
 
319
 */
 
320
void CxImage::SetProgress(long p)
 
321
{
 
322
        info.nProgress = p;
 
323
}
 
324
////////////////////////////////////////////////////////////////////////////////
 
325
/**
 
326
 * Used to quit the slow loops or the codecs.
 
327
 * - SetEscape(-1) before Decode forces the function to exit, right after  
 
328
 *   the image width and height are available ( for bmp, jpg, gif, tif )
 
329
 */
 
330
void CxImage::SetEscape(long i)
 
331
{
 
332
        info.nEscape = i;
 
333
}
 
334
////////////////////////////////////////////////////////////////////////////////
 
335
/**
 
336
 * Checks if the image is correctly initializated.
 
337
 */
 
338
bool CxImage::IsValid() const
 
339
{
 
340
        return pDib!=0;
 
341
}
 
342
////////////////////////////////////////////////////////////////////////////////
 
343
/**
 
344
 * True if the image is enabled for painting.
 
345
 */
 
346
bool CxImage::IsEnabled() const
 
347
{
 
348
        return info.bEnabled;
 
349
}
 
350
////////////////////////////////////////////////////////////////////////////////
 
351
/**
 
352
 * Enables/disables the image.
 
353
 */
 
354
void CxImage::Enable(bool enable)
 
355
{
 
356
        info.bEnabled=enable;
 
357
}
 
358
////////////////////////////////////////////////////////////////////////////////
 
359
/**
 
360
 * This function must be used after a Decode() / Load() call.
 
361
 * Use the sequence SetFrame(-1); Load(...); GetNumFrames();
 
362
 * to get the number of images without loading the first image.
 
363
 * \return the number of images in the file.
 
364
 */
 
365
long CxImage::GetNumFrames() const
 
366
{
 
367
        return info.nNumFrames;
 
368
}
 
369
////////////////////////////////////////////////////////////////////////////////
 
370
/**
 
371
 * \return the current selected image (zero-based index).
 
372
 */
 
373
long CxImage::GetFrame() const
 
374
{
 
375
        return info.nFrame;
 
376
}
 
377
////////////////////////////////////////////////////////////////////////////////
 
378
/**
 
379
 * Sets the image number that the next Decode() / Load() call will load
 
380
 */
 
381
void CxImage::SetFrame(long nFrame){
 
382
        info.nFrame=nFrame;
 
383
}
 
384
 
 
385
CxImage * CxImage::GetFrameNo(long nFrame) const {
 
386
        if (info.GifFrames && nFrame <= info.nNumFrames && info.GifFrames[nFrame]) {
 
387
                return info.GifFrames[nFrame];
 
388
        }
 
389
        return (CxImage * const)this;
 
390
}
 
391
 
 
392
void CxImage::RetreiveAllFrame() {
 
393
        info.bGetAllFrames = true;
 
394
}
 
395
 
 
396
void CxImage::RetreiveSingleFrame() {
 
397
        info.bGetAllFrames = false;
 
398
}
 
399
 
 
400
////////////////////////////////////////////////////////////////////////////////
 
401
/**
 
402
 * Returns the last reported error.
 
403
 */
 
404
const char* CxImage::GetLastError()
 
405
{
 
406
        return info.szLastError;
 
407
}
 
408
////////////////////////////////////////////////////////////////////////////////
 
409
/**
 
410
 * \return A.BBCCCDDDD
 
411
 *  - A = main version
 
412
 *  - BB = main revision
 
413
 *  - CCC = minor revision (letter)
 
414
 *  - DDDD = experimental revision
 
415
 */
 
416
const float CxImage::GetVersionNumber()
 
417
{
 
418
        return 5.99003f;
 
419
}
 
420
////////////////////////////////////////////////////////////////////////////////
 
421
const TCHAR* CxImage::GetVersion()
 
422
{
 
423
        static const TCHAR CxImageVersion[] = _T("CxImage 5.99c");
 
424
        return (CxImageVersion);
 
425
}
 
426
////////////////////////////////////////////////////////////////////////////////