1 // ximainfo.cpp : main attributes
\r
2 /* 03/10/2004 v1.00 - Davide Pizzolato - www.xdp.it
\r
3 * CxImage version 6.0.0 02/Feb/2008
\r
8 ////////////////////////////////////////////////////////////////////////////////
\r
10 * \return the color used for transparency, and/or for background color
\r
12 RGBQUAD CxImage::GetTransColor()
\r
14 if (head.biBitCount<24 && info.nBkgndIndex>=0) return GetPaletteColor((BYTE)info.nBkgndIndex);
\r
15 return info.nBkgndColor;
\r
17 ////////////////////////////////////////////////////////////////////////////////
\r
19 * Gets the index used for transparency. Returns -1 for no transparancy.
\r
21 long CxImage::GetTransIndex() const
\r
23 return info.nBkgndIndex;
\r
25 ////////////////////////////////////////////////////////////////////////////////
\r
27 * Sets the index used for transparency with 1, 4 and 8 bpp images. Set to -1 to remove the effect.
\r
29 void CxImage::SetTransIndex(long idx)
\r
31 if (idx<(long)head.biClrUsed)
\r
32 info.nBkgndIndex = idx;
\r
34 info.nBkgndIndex = 0;
\r
36 ////////////////////////////////////////////////////////////////////////////////
\r
38 * Sets the color used for transparency with 24 bpp images.
\r
39 * You must call SetTransIndex(0) to enable the effect, SetTransIndex(-1) to disable it.
\r
41 void CxImage::SetTransColor(RGBQUAD rgb)
\r
44 info.nBkgndColor = rgb;
\r
46 ////////////////////////////////////////////////////////////////////////////////
\r
47 bool CxImage::IsTransparent() const
\r
49 return info.nBkgndIndex>=0; // <vho>
\r
51 ////////////////////////////////////////////////////////////////////////////////
\r
53 * Returns true if the image has 256 colors or less.
\r
55 bool CxImage::IsIndexed() const
\r
57 return head.biClrUsed!=0;
\r
59 ////////////////////////////////////////////////////////////////////////////////
\r
61 * \return 1 = indexed, 2 = RGB, 4 = RGBA
\r
63 BYTE CxImage::GetColorType()
\r
65 BYTE b = (BYTE)((head.biBitCount>8) ? 2 /*COLORTYPE_COLOR*/ : 1 /*COLORTYPE_PALETTE*/);
\r
66 #if CXIMAGE_SUPPORT_ALPHA
\r
67 if (AlphaIsValid()) b = 4 /*COLORTYPE_ALPHA*/;
\r
68 #endif //CXIMAGE_SUPPORT_ALPHA
\r
71 ////////////////////////////////////////////////////////////////////////////////
\r
73 * \return Resolution for TIFF, JPEG, PNG and BMP formats.
\r
75 long CxImage::GetXDPI() const
\r
79 ////////////////////////////////////////////////////////////////////////////////
\r
81 * \return Resolution for TIFF, JPEG, PNG and BMP formats.
\r
83 long CxImage::GetYDPI() const
\r
87 ////////////////////////////////////////////////////////////////////////////////
\r
89 * Set resolution for TIFF, JPEG, PNG and BMP formats.
\r
91 void CxImage::SetXDPI(long dpi)
\r
93 if (dpi<=0) dpi = CXIMAGE_DEFAULT_DPI;
\r
95 head.biXPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5);
\r
96 if (pDib) ((BITMAPINFOHEADER*)pDib)->biXPelsPerMeter = head.biXPelsPerMeter;
\r
98 ////////////////////////////////////////////////////////////////////////////////
\r
100 * Set resolution for TIFF, JPEG, PNG and BMP formats.
\r
102 void CxImage::SetYDPI(long dpi)
\r
104 if (dpi<=0) dpi = CXIMAGE_DEFAULT_DPI;
\r
106 head.biYPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5);
\r
107 if (pDib) ((BITMAPINFOHEADER*)pDib)->biYPelsPerMeter = head.biYPelsPerMeter;
\r
109 ////////////////////////////////////////////////////////////////////////////////
\r
113 DWORD CxImage::GetFlags() const
\r
115 return info.dwFlags;
\r
117 ////////////////////////////////////////////////////////////////////////////////
\r
119 * Image flags, for future use
\r
121 * - 0x??00000 = reserved for 16 bit, CMYK, multilayer
\r
122 * - 0x00??0000 = blend modes
\r
123 * - 0x0000???? = layer id or user flags
\r
125 * \param bLockReservedFlags protects the "reserved" and "blend modes" flags
\r
127 void CxImage::SetFlags(DWORD flags, bool bLockReservedFlags)
\r
129 if (bLockReservedFlags) info.dwFlags = flags & 0x0000ffff;
\r
130 else info.dwFlags = flags;
\r
132 ////////////////////////////////////////////////////////////////////////////////
\r
134 * \sa SetCodecOption
\r
136 DWORD CxImage::GetCodecOption(DWORD imagetype)
\r
138 imagetype = GetTypeIndexFromId(imagetype);
\r
140 imagetype = GetTypeIndexFromId(GetType());
\r
142 return info.dwCodecOpt[imagetype];
\r
144 ////////////////////////////////////////////////////////////////////////////////
\r
146 * Encode option for GIF, TIF and JPG.
\r
147 * - GIF : 0 = LZW (default), 1 = none, 2 = RLE.
\r
148 * - TIF : 0 = automatic (default), or a valid compression code as defined in "tiff.h" (COMPRESSION_NONE = 1, COMPRESSION_CCITTRLE = 2, ...)
\r
149 * - JPG : valid values stored in enum CODEC_OPTION ( ENCODE_BASELINE = 0x01, ENCODE_PROGRESSIVE = 0x10, ...)
\r
150 * - RAW : valid values stored in enum CODEC_OPTION ( DECODE_QUALITY_LIN = 0x00, DECODE_QUALITY_VNG = 0x01, ...)
\r
152 * \return true if everything is ok
\r
154 bool CxImage::SetCodecOption(DWORD opt, DWORD imagetype)
\r
156 imagetype = GetTypeIndexFromId(imagetype);
\r
158 imagetype = GetTypeIndexFromId(GetType());
\r
160 info.dwCodecOpt[imagetype] = opt;
\r
163 ////////////////////////////////////////////////////////////////////////////////
\r
165 * \return internal hDib object..
\r
167 void* CxImage::GetDIB() const
\r
171 ////////////////////////////////////////////////////////////////////////////////
\r
172 DWORD CxImage::GetHeight() const
\r
174 return head.biHeight;
\r
176 ////////////////////////////////////////////////////////////////////////////////
\r
177 DWORD CxImage::GetWidth() const
\r
179 return head.biWidth;
\r
181 ////////////////////////////////////////////////////////////////////////////////
\r
183 * \return DWORD aligned width of the image.
\r
185 DWORD CxImage::GetEffWidth() const
\r
187 return info.dwEffWidth;
\r
189 ////////////////////////////////////////////////////////////////////////////////
\r
191 * \return 2, 16, 256; 0 for RGB images.
\r
193 DWORD CxImage::GetNumColors() const
\r
195 return head.biClrUsed;
\r
197 ////////////////////////////////////////////////////////////////////////////////
\r
199 * \return: 1, 4, 8, 24.
\r
201 WORD CxImage::GetBpp() const
\r
203 return head.biBitCount;
\r
205 ////////////////////////////////////////////////////////////////////////////////
\r
207 * \return original image format
\r
208 * \sa ENUM_CXIMAGE_FORMATS.
\r
210 DWORD CxImage::GetType() const
\r
212 return info.dwType;
\r
214 ////////////////////////////////////////////////////////////////////////////////
\r
216 * change image format identifier
\r
217 * \sa ENUM_CXIMAGE_FORMATS.
\r
219 bool CxImage::SetType(DWORD type)
\r
222 #if CXIMAGE_SUPPORT_BMP
\r
223 case CXIMAGE_FORMAT_BMP:
\r
225 #if CXIMAGE_SUPPORT_GIF
\r
226 case CXIMAGE_FORMAT_GIF:
\r
228 #if CXIMAGE_SUPPORT_JPG
\r
229 case CXIMAGE_FORMAT_JPG:
\r
231 #if CXIMAGE_SUPPORT_PNG
\r
232 case CXIMAGE_FORMAT_PNG:
\r
234 #if CXIMAGE_SUPPORT_MNG
\r
235 case CXIMAGE_FORMAT_MNG:
\r
237 #if CXIMAGE_SUPPORT_ICO
\r
238 case CXIMAGE_FORMAT_ICO:
\r
240 #if CXIMAGE_SUPPORT_TIF
\r
241 case CXIMAGE_FORMAT_TIF:
\r
243 #if CXIMAGE_SUPPORT_TGA
\r
244 case CXIMAGE_FORMAT_TGA:
\r
246 #if CXIMAGE_SUPPORT_PCX
\r
247 case CXIMAGE_FORMAT_PCX:
\r
249 #if CXIMAGE_SUPPORT_WBMP
\r
250 case CXIMAGE_FORMAT_WBMP:
\r
252 #if CXIMAGE_SUPPORT_WMF
\r
253 case CXIMAGE_FORMAT_WMF:
\r
255 #if CXIMAGE_SUPPORT_JBG
\r
256 case CXIMAGE_FORMAT_JBG:
\r
258 #if CXIMAGE_SUPPORT_JP2
\r
259 case CXIMAGE_FORMAT_JP2:
\r
261 #if CXIMAGE_SUPPORT_JPC
\r
262 case CXIMAGE_FORMAT_JPC:
\r
264 #if CXIMAGE_SUPPORT_PGX
\r
265 case CXIMAGE_FORMAT_PGX:
\r
267 #if CXIMAGE_SUPPORT_PNM
\r
268 case CXIMAGE_FORMAT_PNM:
\r
270 #if CXIMAGE_SUPPORT_RAS
\r
271 case CXIMAGE_FORMAT_RAS:
\r
273 #if CXIMAGE_SUPPORT_SKA
\r
274 case CXIMAGE_FORMAT_SKA:
\r
276 #if CXIMAGE_SUPPORT_RAW
\r
277 case CXIMAGE_FORMAT_RAW:
\r
279 info.dwType = type;
\r
282 info.dwType = CXIMAGE_FORMAT_UNKNOWN;
\r
285 ////////////////////////////////////////////////////////////////////////////////
\r
286 DWORD CxImage::GetNumTypes()
\r
288 return CMAX_IMAGE_FORMATS-1;
\r
290 ////////////////////////////////////////////////////////////////////////////////
\r
291 DWORD CxImage::GetTypeIdFromName(const TCHAR* ext)
\r
293 #if CXIMAGE_SUPPORT_BMP
\r
294 if (_tcsnicmp(ext,_T("bmp"),3)==0 ) return CXIMAGE_FORMAT_BMP;
\r
296 #if CXIMAGE_SUPPORT_JPG
\r
297 if (_tcsnicmp(ext,_T("jpg"),3)==0 ||
\r
298 _tcsnicmp(ext,_T("jpe"),3)==0 ||
\r
299 _tcsnicmp(ext,_T("jfi"),3)==0 ) return CXIMAGE_FORMAT_JPG;
\r
301 #if CXIMAGE_SUPPORT_GIF
\r
302 if (_tcsnicmp(ext,_T("gif"),3)==0 ) return CXIMAGE_FORMAT_GIF;
\r
304 #if CXIMAGE_SUPPORT_PNG
\r
305 if (_tcsnicmp(ext,_T("png"),3)==0 ) return CXIMAGE_FORMAT_PNG;
\r
307 #if CXIMAGE_SUPPORT_ICO
\r
308 if (_tcsnicmp(ext,_T("ico"),3)==0 ||
\r
309 _tcsnicmp(ext,_T("cur"),3)==0 ) return CXIMAGE_FORMAT_ICO;
\r
311 #if CXIMAGE_SUPPORT_TIF
\r
312 if (_tcsnicmp(ext,_T("tif"),3)==0 ) return CXIMAGE_FORMAT_TIF;
\r
314 #if CXIMAGE_SUPPORT_TGA
\r
315 if (_tcsnicmp(ext,_T("tga"),3)==0 ) return CXIMAGE_FORMAT_TGA;
\r
317 #if CXIMAGE_SUPPORT_PCX
\r
318 if (_tcsnicmp(ext,_T("pcx"),3)==0 ) return CXIMAGE_FORMAT_PCX;
\r
320 #if CXIMAGE_SUPPORT_WBMP
\r
321 if (_tcsnicmp(ext,_T("wbm"),3)==0 ) return CXIMAGE_FORMAT_WBMP;
\r
323 #if CXIMAGE_SUPPORT_WMF
\r
324 if (_tcsnicmp(ext,_T("wmf"),3)==0 ||
\r
325 _tcsnicmp(ext,_T("emf"),3)==0 ) return CXIMAGE_FORMAT_WMF;
\r
327 #if CXIMAGE_SUPPORT_JP2
\r
328 if (_tcsnicmp(ext,_T("jp2"),3)==0 ||
\r
329 _tcsnicmp(ext,_T("j2k"),3)==0 ) return CXIMAGE_FORMAT_JP2;
\r
331 #if CXIMAGE_SUPPORT_JPC
\r
332 if (_tcsnicmp(ext,_T("jpc"),3)==0 ||
\r
333 _tcsnicmp(ext,_T("j2c"),3)==0 ) return CXIMAGE_FORMAT_JPC;
\r
335 #if CXIMAGE_SUPPORT_PGX
\r
336 if (_tcsnicmp(ext,_T("pgx"),3)==0 ) return CXIMAGE_FORMAT_PGX;
\r
338 #if CXIMAGE_SUPPORT_RAS
\r
339 if (_tcsnicmp(ext,_T("ras"),3)==0 ) return CXIMAGE_FORMAT_RAS;
\r
341 #if CXIMAGE_SUPPORT_PNM
\r
342 if (_tcsnicmp(ext,_T("pnm"),3)==0 ||
\r
343 _tcsnicmp(ext,_T("pgm"),3)==0 ||
\r
344 _tcsnicmp(ext,_T("ppm"),3)==0 ) return CXIMAGE_FORMAT_PNM;
\r
346 #if CXIMAGE_SUPPORT_JBG
\r
347 if (_tcsnicmp(ext,_T("jbg"),3)==0 ) return CXIMAGE_FORMAT_JBG;
\r
349 #if CXIMAGE_SUPPORT_MNG
\r
350 if (_tcsnicmp(ext,_T("mng"),3)==0 ||
\r
351 _tcsnicmp(ext,_T("jng"),3)==0 ) return CXIMAGE_FORMAT_MNG;
\r
353 #if CXIMAGE_SUPPORT_SKA
\r
354 if (_tcsnicmp(ext,_T("ska"),3)==0 ) return CXIMAGE_FORMAT_SKA;
\r
356 #if CXIMAGE_SUPPORT_RAW
\r
357 if (_tcsnicmp(ext,_T("nef"),3)==0 ||
\r
358 _tcsnicmp(ext,_T("crw"),3)==0 ||
\r
359 _tcsnicmp(ext,_T("cr2"),3)==0 ||
\r
360 _tcsnicmp(ext,_T("dng"),3)==0 ||
\r
361 _tcsnicmp(ext,_T("arw"),3)==0 ||
\r
362 _tcsnicmp(ext,_T("erf"),3)==0 ||
\r
363 _tcsnicmp(ext,_T("3fr"),3)==0 ||
\r
364 _tcsnicmp(ext,_T("dcr"),3)==0 ||
\r
365 _tcsnicmp(ext,_T("raw"),3)==0 ||
\r
366 _tcsnicmp(ext,_T("x3f"),3)==0 ||
\r
367 _tcsnicmp(ext,_T("mef"),3)==0 ||
\r
368 _tcsnicmp(ext,_T("raf"),3)==0 ||
\r
369 _tcsnicmp(ext,_T("mrw"),3)==0 ||
\r
370 _tcsnicmp(ext,_T("pef"),3)==0 ||
\r
371 _tcsnicmp(ext,_T("sr2"),3)==0 ||
\r
372 _tcsnicmp(ext,_T("orf"),3)==0 ) return CXIMAGE_FORMAT_RAW;
\r
375 return CXIMAGE_FORMAT_UNKNOWN;
\r
377 ////////////////////////////////////////////////////////////////////////////////
\r
378 DWORD CxImage::GetTypeIdFromIndex(const DWORD index)
\r
382 n=0; if (index == n) return CXIMAGE_FORMAT_UNKNOWN;
\r
383 #if CXIMAGE_SUPPORT_BMP
\r
384 n++; if (index == n) return CXIMAGE_FORMAT_BMP;
\r
386 #if CXIMAGE_SUPPORT_GIF
\r
387 n++; if (index == n) return CXIMAGE_FORMAT_GIF;
\r
389 #if CXIMAGE_SUPPORT_JPG
\r
390 n++; if (index == n) return CXIMAGE_FORMAT_JPG;
\r
392 #if CXIMAGE_SUPPORT_PNG
\r
393 n++; if (index == n) return CXIMAGE_FORMAT_PNG;
\r
395 #if CXIMAGE_SUPPORT_ICO
\r
396 n++; if (index == n) return CXIMAGE_FORMAT_ICO;
\r
398 #if CXIMAGE_SUPPORT_TIF
\r
399 n++; if (index == n) return CXIMAGE_FORMAT_TIF;
\r
401 #if CXIMAGE_SUPPORT_TGA
\r
402 n++; if (index == n) return CXIMAGE_FORMAT_TGA;
\r
404 #if CXIMAGE_SUPPORT_PCX
\r
405 n++; if (index == n) return CXIMAGE_FORMAT_PCX;
\r
407 #if CXIMAGE_SUPPORT_WBMP
\r
408 n++; if (index == n) return CXIMAGE_FORMAT_WBMP;
\r
410 #if CXIMAGE_SUPPORT_WMF
\r
411 n++; if (index == n) return CXIMAGE_FORMAT_WMF;
\r
413 #if CXIMAGE_SUPPORT_JP2
\r
414 n++; if (index == n) return CXIMAGE_FORMAT_JP2;
\r
416 #if CXIMAGE_SUPPORT_JPC
\r
417 n++; if (index == n) return CXIMAGE_FORMAT_JPC;
\r
419 #if CXIMAGE_SUPPORT_PGX
\r
420 n++; if (index == n) return CXIMAGE_FORMAT_PGX;
\r
422 #if CXIMAGE_SUPPORT_PNM
\r
423 n++; if (index == n) return CXIMAGE_FORMAT_PNM;
\r
425 #if CXIMAGE_SUPPORT_RAS
\r
426 n++; if (index == n) return CXIMAGE_FORMAT_RAS;
\r
428 #if CXIMAGE_SUPPORT_JBG
\r
429 n++; if (index == n) return CXIMAGE_FORMAT_JBG;
\r
431 #if CXIMAGE_SUPPORT_MNG
\r
432 n++; if (index == n) return CXIMAGE_FORMAT_MNG;
\r
434 #if CXIMAGE_SUPPORT_SKA
\r
435 n++; if (index == n) return CXIMAGE_FORMAT_SKA;
\r
437 #if CXIMAGE_SUPPORT_RAW
\r
438 n++; if (index == n) return CXIMAGE_FORMAT_RAW;
\r
441 return CXIMAGE_FORMAT_UNKNOWN;
\r
443 ////////////////////////////////////////////////////////////////////////////////
\r
444 DWORD CxImage::GetTypeIndexFromId(const DWORD id)
\r
448 n=0; if (id == CXIMAGE_FORMAT_UNKNOWN) return n;
\r
449 #if CXIMAGE_SUPPORT_BMP
\r
450 n++; if (id == CXIMAGE_FORMAT_BMP) return n;
\r
452 #if CXIMAGE_SUPPORT_GIF
\r
453 n++; if (id == CXIMAGE_FORMAT_GIF) return n;
\r
455 #if CXIMAGE_SUPPORT_JPG
\r
456 n++; if (id == CXIMAGE_FORMAT_JPG) return n;
\r
458 #if CXIMAGE_SUPPORT_PNG
\r
459 n++; if (id == CXIMAGE_FORMAT_PNG) return n;
\r
461 #if CXIMAGE_SUPPORT_ICO
\r
462 n++; if (id == CXIMAGE_FORMAT_ICO) return n;
\r
464 #if CXIMAGE_SUPPORT_TIF
\r
465 n++; if (id == CXIMAGE_FORMAT_TIF) return n;
\r
467 #if CXIMAGE_SUPPORT_TGA
\r
468 n++; if (id == CXIMAGE_FORMAT_TGA) return n;
\r
470 #if CXIMAGE_SUPPORT_PCX
\r
471 n++; if (id == CXIMAGE_FORMAT_PCX) return n;
\r
473 #if CXIMAGE_SUPPORT_WBMP
\r
474 n++; if (id == CXIMAGE_FORMAT_WBMP) return n;
\r
476 #if CXIMAGE_SUPPORT_WMF
\r
477 n++; if (id == CXIMAGE_FORMAT_WMF) return n;
\r
479 #if CXIMAGE_SUPPORT_JP2
\r
480 n++; if (id == CXIMAGE_FORMAT_JP2) return n;
\r
482 #if CXIMAGE_SUPPORT_JPC
\r
483 n++; if (id == CXIMAGE_FORMAT_JPC) return n;
\r
485 #if CXIMAGE_SUPPORT_PGX
\r
486 n++; if (id == CXIMAGE_FORMAT_PGX) return n;
\r
488 #if CXIMAGE_SUPPORT_PNM
\r
489 n++; if (id == CXIMAGE_FORMAT_PNM) return n;
\r
491 #if CXIMAGE_SUPPORT_RAS
\r
492 n++; if (id == CXIMAGE_FORMAT_RAS) return n;
\r
494 #if CXIMAGE_SUPPORT_JBG
\r
495 n++; if (id == CXIMAGE_FORMAT_JBG) return n;
\r
497 #if CXIMAGE_SUPPORT_MNG
\r
498 n++; if (id == CXIMAGE_FORMAT_MNG) return n;
\r
500 #if CXIMAGE_SUPPORT_SKA
\r
501 n++; if (id == CXIMAGE_FORMAT_SKA) return n;
\r
503 #if CXIMAGE_SUPPORT_RAW
\r
504 n++; if (id == CXIMAGE_FORMAT_RAW) return n;
\r
509 ////////////////////////////////////////////////////////////////////////////////
\r
511 * \return current frame delay in milliseconds. Only for GIF and MNG formats.
\r
513 DWORD CxImage::GetFrameDelay() const
\r
515 return info.dwFrameDelay;
\r
517 ////////////////////////////////////////////////////////////////////////////////
\r
519 * Sets current frame delay. Only for GIF format.
\r
520 * \param d = delay in milliseconds
\r
522 void CxImage::SetFrameDelay(DWORD d)
\r
524 info.dwFrameDelay=d;
\r
526 ////////////////////////////////////////////////////////////////////////////////
\r
527 void CxImage::GetOffset(long *x,long *y)
\r
532 ////////////////////////////////////////////////////////////////////////////////
\r
533 void CxImage::SetOffset(long x,long y)
\r
538 ////////////////////////////////////////////////////////////////////////////////
\r
540 * \sa SetJpegQuality, GetJpegQualityF
\r
541 * \author [DP]; changes [Stefan Schürmans]
\r
543 BYTE CxImage::GetJpegQuality() const
\r
545 return (BYTE)(info.fQuality + 0.5f);
\r
547 ////////////////////////////////////////////////////////////////////////////////
\r
549 * \sa SetJpegQuality, GetJpegQuality
\r
550 * \author [Stefan Schürmans]
\r
552 float CxImage::GetJpegQualityF() const
\r
554 return info.fQuality;
\r
556 ////////////////////////////////////////////////////////////////////////////////
\r
558 * quality level for JPEG and JPEG2000
\r
559 * \param q: can be from 0 to 100
\r
560 * \author [DP]; changes [Stefan Schürmans]
\r
562 void CxImage::SetJpegQuality(BYTE q){
\r
563 info.fQuality = (float)q;
\r
565 ////////////////////////////////////////////////////////////////////////////////
\r
567 * quality level for JPEG and JPEG2000
\r
568 * necessary for JPEG2000 when quality is between 0.0 and 1.0
\r
569 * \param q: can be from 0.0 to 100.0
\r
570 * \author [Stefan Schürmans]
\r
572 void CxImage::SetJpegQualityF(float q){
\r
573 if (q>0) info.fQuality = q;
\r
574 else info.fQuality = 0.0f;
\r
576 ////////////////////////////////////////////////////////////////////////////////
\r
580 BYTE CxImage::GetJpegScale() const
\r
582 return info.nJpegScale;
\r
584 ////////////////////////////////////////////////////////////////////////////////
\r
586 * scaling down during JPEG decoding valid numbers are 1, 2, 4, 8
\r
587 * \author [ignacio]
\r
589 void CxImage::SetJpegScale(BYTE q){
\r
590 info.nJpegScale = q;
\r
592 ////////////////////////////////////////////////////////////////////////////////
\r
594 * Used to monitor the slow loops.
\r
595 * \return value is from 0 to 100.
\r
598 long CxImage::GetProgress() const
\r
600 return info.nProgress;
\r
602 ////////////////////////////////////////////////////////////////////////////////
\r
604 * \return the escape code.
\r
607 long CxImage::GetEscape() const
\r
609 return info.nEscape;
\r
611 ////////////////////////////////////////////////////////////////////////////////
\r
613 * Forces the value of the internal progress variable.
\r
614 * \param p should be from 0 to 100.
\r
617 void CxImage::SetProgress(long p)
\r
619 info.nProgress = p;
\r
621 ////////////////////////////////////////////////////////////////////////////////
\r
623 * Used to quit the slow loops or the codecs.
\r
624 * - SetEscape(-1) before Decode forces the function to exit, right after
\r
625 * the image width and height are available ( for bmp, jpg, gif, tif )
\r
627 void CxImage::SetEscape(long i)
\r
631 ////////////////////////////////////////////////////////////////////////////////
\r
633 * Checks if the image is correctly initializated.
\r
635 bool CxImage::IsValid() const
\r
639 ////////////////////////////////////////////////////////////////////////////////
\r
641 * True if the image is enabled for painting.
\r
643 bool CxImage::IsEnabled() const
\r
645 return info.bEnabled;
\r
647 ////////////////////////////////////////////////////////////////////////////////
\r
649 * Enables/disables the image.
\r
651 void CxImage::Enable(bool enable)
\r
653 info.bEnabled=enable;
\r
655 ////////////////////////////////////////////////////////////////////////////////
\r
657 * This function must be used after a Decode() / Load() call.
\r
658 * Use the sequence SetFrame(-1); Load(...); GetNumFrames();
\r
659 * to get the number of images without loading the first image.
\r
660 * \return the number of images in the file.
\r
662 long CxImage::GetNumFrames() const
\r
664 return info.nNumFrames;
\r
666 ////////////////////////////////////////////////////////////////////////////////
\r
668 * \return the current selected image (zero-based index).
\r
670 long CxImage::GetFrame() const
\r
672 return info.nFrame;
\r
674 ////////////////////////////////////////////////////////////////////////////////
\r
676 * Sets the image number that the next Decode() / Load() call will load
\r
678 void CxImage::SetFrame(long nFrame){
\r
679 info.nFrame=nFrame;
\r
681 ////////////////////////////////////////////////////////////////////////////////
\r
683 * Sets the method for drawing the frame related to others
\r
684 * \sa GetDisposalMethod
\r
686 void CxImage::SetDisposalMethod(BYTE dm)
\r
687 { info.dispmeth=dm; }
\r
688 ////////////////////////////////////////////////////////////////////////////////
\r
690 * Gets the method for drawing the frame related to others
\r
691 * Values : 0 - No disposal specified. The decoder is
\r
692 * not required to take any action.
\r
693 * 1 - Do not dispose. The graphic is to be left
\r
695 * 2 - Restore to background color. The area used by the
\r
696 * graphic must be restored to the background color.
\r
697 * 3 - Restore to previous. The decoder is required to
\r
698 * restore the area overwritten by the graphic with
\r
699 * what was there prior to rendering the graphic.
\r
700 * 4-7 - To be defined.
\r
702 BYTE CxImage::GetDisposalMethod() const
\r
703 { return info.dispmeth; }
\r
704 ////////////////////////////////////////////////////////////////////////////////
\r
705 bool CxImage::GetRetreiveAllFrames() const
\r
706 { return info.bGetAllFrames; }
\r
707 ////////////////////////////////////////////////////////////////////////////////
\r
708 void CxImage::SetRetreiveAllFrames(bool flag)
\r
709 { info.bGetAllFrames = flag; }
\r
710 ////////////////////////////////////////////////////////////////////////////////
\r
711 CxImage * CxImage::GetFrame(long nFrame) const
\r
713 if ( ppFrames == NULL) return NULL;
\r
714 if ( info.nNumFrames == 0) return NULL;
\r
715 if ( nFrame >= info.nNumFrames ) return NULL;
\r
716 if ( nFrame < 0) nFrame = info.nNumFrames - 1;
\r
717 return ppFrames[nFrame];
\r
719 ////////////////////////////////////////////////////////////////////////////////
\r
720 short CxImage::ntohs(const short word)
\r
722 if (info.bLittleEndianHost) return word;
\r
723 return ( (word & 0xff) << 8 ) | ( (word >> 8) & 0xff );
\r
725 ////////////////////////////////////////////////////////////////////////////////
\r
726 long CxImage::ntohl(const long dword)
\r
728 if (info.bLittleEndianHost) return dword;
\r
729 return ((dword & 0xff) << 24 ) | ((dword & 0xff00) << 8 ) |
\r
730 ((dword >> 8) & 0xff00) | ((dword >> 24) & 0xff);
\r
732 ////////////////////////////////////////////////////////////////////////////////
\r
733 void CxImage::bihtoh(BITMAPINFOHEADER* bih)
\r
735 bih->biSize = ntohl(bih->biSize);
\r
736 bih->biWidth = ntohl(bih->biWidth);
\r
737 bih->biHeight = ntohl(bih->biHeight);
\r
738 bih->biPlanes = ntohs(bih->biPlanes);
\r
739 bih->biBitCount = ntohs(bih->biBitCount);
\r
740 bih->biCompression = ntohl(bih->biCompression);
\r
741 bih->biSizeImage = ntohl(bih->biSizeImage);
\r
742 bih->biXPelsPerMeter = ntohl(bih->biXPelsPerMeter);
\r
743 bih->biYPelsPerMeter = ntohl(bih->biYPelsPerMeter);
\r
744 bih->biClrUsed = ntohl(bih->biClrUsed);
\r
745 bih->biClrImportant = ntohl(bih->biClrImportant);
\r
747 ////////////////////////////////////////////////////////////////////////////////
\r
749 * Returns the last reported error.
\r
751 const char* CxImage::GetLastError()
\r
753 return info.szLastError;
\r
755 ////////////////////////////////////////////////////////////////////////////////
\r
756 DWORD CxImage::DumpSize()
\r
759 n = sizeof(BITMAPINFOHEADER) + sizeof(CXIMAGEINFO) + GetSize();
\r
762 n += 1 + head.biWidth * head.biHeight;
\r
766 n += 1 + head.biWidth * head.biHeight;
\r
770 for (long m=0; m<GetNumLayers(); m++){
\r
772 n += 1 + GetLayer(m)->DumpSize();
\r
778 for (long m=0; m<GetNumFrames(); m++){
\r
780 n += 1 + GetFrame(m)->DumpSize();
\r
787 ////////////////////////////////////////////////////////////////////////////////
\r
788 DWORD CxImage::Dump(BYTE * dst)
\r
790 if (!dst) return 0;
\r
792 memcpy(dst,&head,sizeof(BITMAPINFOHEADER));
\r
793 dst += sizeof(BITMAPINFOHEADER);
\r
795 memcpy(dst,&info,sizeof(CXIMAGEINFO));
\r
796 dst += sizeof(CXIMAGEINFO);
\r
798 memcpy(dst,pDib,GetSize());
\r
802 memset(dst++, 1, 1);
\r
803 memcpy(dst,pAlpha,head.biWidth * head.biHeight);
\r
804 dst += head.biWidth * head.biHeight;
\r
806 memset(dst++, 0, 1);
\r
810 memset(dst++, 1, 1);
\r
811 memcpy(dst,pSelection,head.biWidth * head.biHeight);
\r
812 dst += head.biWidth * head.biHeight;
\r
814 memset(dst++, 0, 1);
\r
818 memset(dst++, 1, 1);
\r
819 for (long m=0; m<GetNumLayers(); m++){
\r
821 dst += GetLayer(m)->Dump(dst);
\r
825 memset(dst++, 0, 1);
\r
829 memset(dst++, 1, 1);
\r
830 for (long m=0; m<GetNumFrames(); m++){
\r
832 dst += GetFrame(m)->Dump(dst);
\r
836 memset(dst++, 0, 1);
\r
841 ////////////////////////////////////////////////////////////////////////////////
\r
842 DWORD CxImage::UnDump(const BYTE * src)
\r
848 if (!DestroyFrames())
\r
853 memcpy(&head,src,sizeof(BITMAPINFOHEADER));
\r
854 n += sizeof(BITMAPINFOHEADER);
\r
856 memcpy(&info,&src[n],sizeof(CXIMAGEINFO));
\r
857 n += sizeof(CXIMAGEINFO);
\r
859 if (!Create(head.biWidth, head.biHeight, head.biBitCount, info.dwType))
\r
862 memcpy(pDib,&src[n],GetSize());
\r
866 if (AlphaCreate()){
\r
867 memcpy(pAlpha, &src[n], head.biWidth * head.biHeight);
\r
869 n += head.biWidth * head.biHeight;
\r
873 RECT box = info.rSelectionBox;
\r
874 if (SelectionCreate()){
\r
875 info.rSelectionBox = box;
\r
876 memcpy(pSelection, &src[n], head.biWidth * head.biHeight);
\r
878 n += head.biWidth * head.biHeight;
\r
882 ppLayers = new CxImage*[info.nNumLayers];
\r
883 for (long m=0; m<GetNumLayers(); m++){
\r
884 ppLayers[m] = new CxImage();
\r
885 n += ppLayers[m]->UnDump(&src[n]);
\r
890 ppFrames = new CxImage*[info.nNumFrames];
\r
891 for (long m=0; m<GetNumFrames(); m++){
\r
892 ppFrames[m] = new CxImage();
\r
893 n += ppFrames[m]->UnDump(&src[n]);
\r
899 ////////////////////////////////////////////////////////////////////////////////
\r
901 * \return A.BBCCCDDDD
\r
902 * - A = main version
\r
903 * - BB = main revision
\r
904 * - CCC = minor revision (letter)
\r
905 * - DDDD = experimental revision
\r
907 const float CxImage::GetVersionNumber()
\r
909 return 6.000000015f;
\r
911 ////////////////////////////////////////////////////////////////////////////////
\r
912 const TCHAR* CxImage::GetVersion()
\r
914 static const TCHAR CxImageVersion[] = _T("CxImage 6.0.0");
\r
915 return (CxImageVersion);
\r
917 ////////////////////////////////////////////////////////////////////////////////
\r