source: liacs/MIR2010/SourceCode/cximage/ximainfo.cpp@ 210

Last change on this file since 210 was 95, checked in by Rick van der Zwet, 15 years ago

Bad boy, improper move of directory

File size: 25.5 KB
RevLine 
[95]1// ximainfo.cpp : main attributes
2/* 03/10/2004 v1.00 - Davide Pizzolato - www.xdp.it
3 * CxImage version 6.0.0 02/Feb/2008
4 */
5
6#include "ximage.h"
7
8////////////////////////////////////////////////////////////////////////////////
9/**
10 * \return the color used for transparency, and/or for background color
11 */
12RGBQUAD CxImage::GetTransColor()
13{
14 if (head.biBitCount<24 && info.nBkgndIndex>=0) 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 */
21long 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 */
29void CxImage::SetTransIndex(long idx)
30{
31 if (idx<(long)head.biClrUsed)
32 info.nBkgndIndex = idx;
33 else
34 info.nBkgndIndex = 0;
35}
36////////////////////////////////////////////////////////////////////////////////
37/**
38 * Sets the color used for transparency with 24 bpp images.
39 * You must call SetTransIndex(0) to enable the effect, SetTransIndex(-1) to disable it.
40 */
41void CxImage::SetTransColor(RGBQUAD rgb)
42{
43 rgb.rgbReserved=0;
44 info.nBkgndColor = rgb;
45}
46////////////////////////////////////////////////////////////////////////////////
47bool CxImage::IsTransparent() const
48{
49 return info.nBkgndIndex>=0; // <vho>
50}
51////////////////////////////////////////////////////////////////////////////////
52/**
53 * Returns true if the image has 256 colors or less.
54 */
55bool CxImage::IsIndexed() const
56{
57 return head.biClrUsed!=0;
58}
59////////////////////////////////////////////////////////////////////////////////
60/**
61 * \return 1 = indexed, 2 = RGB, 4 = RGBA
62 */
63BYTE CxImage::GetColorType()
64{
65 BYTE b = (BYTE)((head.biBitCount>8) ? 2 /*COLORTYPE_COLOR*/ : 1 /*COLORTYPE_PALETTE*/);
66#if CXIMAGE_SUPPORT_ALPHA
67 if (AlphaIsValid()) b = 4 /*COLORTYPE_ALPHA*/;
68#endif //CXIMAGE_SUPPORT_ALPHA
69 return b;
70}
71////////////////////////////////////////////////////////////////////////////////
72/**
73 * \return Resolution for TIFF, JPEG, PNG and BMP formats.
74 */
75long CxImage::GetXDPI() const
76{
77 return info.xDPI;
78}
79////////////////////////////////////////////////////////////////////////////////
80/**
81 * \return Resolution for TIFF, JPEG, PNG and BMP formats.
82 */
83long CxImage::GetYDPI() const
84{
85 return info.yDPI;
86}
87////////////////////////////////////////////////////////////////////////////////
88/**
89 * Set resolution for TIFF, JPEG, PNG and BMP formats.
90 */
91void CxImage::SetXDPI(long dpi)
92{
93 if (dpi<=0) dpi = CXIMAGE_DEFAULT_DPI;
94 info.xDPI = dpi;
95 head.biXPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5);
96 if (pDib) ((BITMAPINFOHEADER*)pDib)->biXPelsPerMeter = head.biXPelsPerMeter;
97}
98////////////////////////////////////////////////////////////////////////////////
99/**
100 * Set resolution for TIFF, JPEG, PNG and BMP formats.
101 */
102void CxImage::SetYDPI(long dpi)
103{
104 if (dpi<=0) dpi = CXIMAGE_DEFAULT_DPI;
105 info.yDPI = dpi;
106 head.biYPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5);
107 if (pDib) ((BITMAPINFOHEADER*)pDib)->biYPelsPerMeter = head.biYPelsPerMeter;
108}
109////////////////////////////////////////////////////////////////////////////////
110/**
111 * \sa SetFlags
112 */
113DWORD CxImage::GetFlags() const
114{
115 return info.dwFlags;
116}
117////////////////////////////////////////////////////////////////////////////////
118/**
119 * Image flags, for future use
120 * \param flags
121 * - 0x??00000 = reserved for 16 bit, CMYK, multilayer
122 * - 0x00??0000 = blend modes
123 * - 0x0000???? = layer id or user flags
124 *
125 * \param bLockReservedFlags protects the "reserved" and "blend modes" flags
126 */
127void CxImage::SetFlags(DWORD flags, bool bLockReservedFlags)
128{
129 if (bLockReservedFlags) info.dwFlags = flags & 0x0000ffff;
130 else info.dwFlags = flags;
131}
132////////////////////////////////////////////////////////////////////////////////
133/**
134 * \sa SetCodecOption
135 */
136DWORD CxImage::GetCodecOption(DWORD imagetype)
137{
138 imagetype = GetTypeIndexFromId(imagetype);
139 if (imagetype==0){
140 imagetype = GetTypeIndexFromId(GetType());
141 }
142 return info.dwCodecOpt[imagetype];
143}
144////////////////////////////////////////////////////////////////////////////////
145/**
146 * Encode option for GIF, TIF and JPG.
147 * - GIF : 0 = LZW (default), 1 = none, 2 = RLE.
148 * - TIF : 0 = automatic (default), or a valid compression code as defined in "tiff.h" (COMPRESSION_NONE = 1, COMPRESSION_CCITTRLE = 2, ...)
149 * - JPG : valid values stored in enum CODEC_OPTION ( ENCODE_BASELINE = 0x01, ENCODE_PROGRESSIVE = 0x10, ...)
150 * - RAW : valid values stored in enum CODEC_OPTION ( DECODE_QUALITY_LIN = 0x00, DECODE_QUALITY_VNG = 0x01, ...)
151 *
152 * \return true if everything is ok
153 */
154bool CxImage::SetCodecOption(DWORD opt, DWORD imagetype)
155{
156 imagetype = GetTypeIndexFromId(imagetype);
157 if (imagetype==0){
158 imagetype = GetTypeIndexFromId(GetType());
159 }
160 info.dwCodecOpt[imagetype] = opt;
161 return true;
162}
163////////////////////////////////////////////////////////////////////////////////
164/**
165 * \return internal hDib object..
166 */
167void* CxImage::GetDIB() const
168{
169 return pDib;
170}
171////////////////////////////////////////////////////////////////////////////////
172DWORD CxImage::GetHeight() const
173{
174 return head.biHeight;
175}
176////////////////////////////////////////////////////////////////////////////////
177DWORD CxImage::GetWidth() const
178{
179 return head.biWidth;
180}
181////////////////////////////////////////////////////////////////////////////////
182/**
183 * \return DWORD aligned width of the image.
184 */
185DWORD CxImage::GetEffWidth() const
186{
187 return info.dwEffWidth;
188}
189////////////////////////////////////////////////////////////////////////////////
190/**
191 * \return 2, 16, 256; 0 for RGB images.
192 */
193DWORD CxImage::GetNumColors() const
194{
195 return head.biClrUsed;
196}
197////////////////////////////////////////////////////////////////////////////////
198/**
199 * \return: 1, 4, 8, 24.
200 */
201WORD CxImage::GetBpp() const
202{
203 return head.biBitCount;
204}
205////////////////////////////////////////////////////////////////////////////////
206/**
207 * \return original image format
208 * \sa ENUM_CXIMAGE_FORMATS.
209 */
210DWORD CxImage::GetType() const
211{
212 return info.dwType;
213}
214////////////////////////////////////////////////////////////////////////////////
215/**
216 * change image format identifier
217 * \sa ENUM_CXIMAGE_FORMATS.
218 */
219bool CxImage::SetType(DWORD type)
220{
221 switch (type){
222#if CXIMAGE_SUPPORT_BMP
223 case CXIMAGE_FORMAT_BMP:
224#endif
225#if CXIMAGE_SUPPORT_GIF
226 case CXIMAGE_FORMAT_GIF:
227#endif
228#if CXIMAGE_SUPPORT_JPG
229 case CXIMAGE_FORMAT_JPG:
230#endif
231#if CXIMAGE_SUPPORT_PNG
232 case CXIMAGE_FORMAT_PNG:
233#endif
234#if CXIMAGE_SUPPORT_MNG
235 case CXIMAGE_FORMAT_MNG:
236#endif
237#if CXIMAGE_SUPPORT_ICO
238 case CXIMAGE_FORMAT_ICO:
239#endif
240#if CXIMAGE_SUPPORT_TIF
241 case CXIMAGE_FORMAT_TIF:
242#endif
243#if CXIMAGE_SUPPORT_TGA
244 case CXIMAGE_FORMAT_TGA:
245#endif
246#if CXIMAGE_SUPPORT_PCX
247 case CXIMAGE_FORMAT_PCX:
248#endif
249#if CXIMAGE_SUPPORT_WBMP
250 case CXIMAGE_FORMAT_WBMP:
251#endif
252#if CXIMAGE_SUPPORT_WMF
253 case CXIMAGE_FORMAT_WMF:
254#endif
255#if CXIMAGE_SUPPORT_JBG
256 case CXIMAGE_FORMAT_JBG:
257#endif
258#if CXIMAGE_SUPPORT_JP2
259 case CXIMAGE_FORMAT_JP2:
260#endif
261#if CXIMAGE_SUPPORT_JPC
262 case CXIMAGE_FORMAT_JPC:
263#endif
264#if CXIMAGE_SUPPORT_PGX
265 case CXIMAGE_FORMAT_PGX:
266#endif
267#if CXIMAGE_SUPPORT_PNM
268 case CXIMAGE_FORMAT_PNM:
269#endif
270#if CXIMAGE_SUPPORT_RAS
271 case CXIMAGE_FORMAT_RAS:
272#endif
273#if CXIMAGE_SUPPORT_SKA
274 case CXIMAGE_FORMAT_SKA:
275#endif
276#if CXIMAGE_SUPPORT_RAW
277 case CXIMAGE_FORMAT_RAW:
278#endif
279 info.dwType = type;
280 return true;
281 }
282 info.dwType = CXIMAGE_FORMAT_UNKNOWN;
283 return false;
284}
285////////////////////////////////////////////////////////////////////////////////
286DWORD CxImage::GetNumTypes()
287{
288 return CMAX_IMAGE_FORMATS-1;
289}
290////////////////////////////////////////////////////////////////////////////////
291DWORD CxImage::GetTypeIdFromName(const TCHAR* ext)
292{
293#if CXIMAGE_SUPPORT_BMP
294 if (_tcsnicmp(ext,_T("bmp"),3)==0 ) return CXIMAGE_FORMAT_BMP;
295#endif
296#if CXIMAGE_SUPPORT_JPG
297 if (_tcsnicmp(ext,_T("jpg"),3)==0 ||
298 _tcsnicmp(ext,_T("jpe"),3)==0 ||
299 _tcsnicmp(ext,_T("jfi"),3)==0 ) return CXIMAGE_FORMAT_JPG;
300#endif
301#if CXIMAGE_SUPPORT_GIF
302 if (_tcsnicmp(ext,_T("gif"),3)==0 ) return CXIMAGE_FORMAT_GIF;
303#endif
304#if CXIMAGE_SUPPORT_PNG
305 if (_tcsnicmp(ext,_T("png"),3)==0 ) return CXIMAGE_FORMAT_PNG;
306#endif
307#if CXIMAGE_SUPPORT_ICO
308 if (_tcsnicmp(ext,_T("ico"),3)==0 ||
309 _tcsnicmp(ext,_T("cur"),3)==0 ) return CXIMAGE_FORMAT_ICO;
310#endif
311#if CXIMAGE_SUPPORT_TIF
312 if (_tcsnicmp(ext,_T("tif"),3)==0 ) return CXIMAGE_FORMAT_TIF;
313#endif
314#if CXIMAGE_SUPPORT_TGA
315 if (_tcsnicmp(ext,_T("tga"),3)==0 ) return CXIMAGE_FORMAT_TGA;
316#endif
317#if CXIMAGE_SUPPORT_PCX
318 if (_tcsnicmp(ext,_T("pcx"),3)==0 ) return CXIMAGE_FORMAT_PCX;
319#endif
320#if CXIMAGE_SUPPORT_WBMP
321 if (_tcsnicmp(ext,_T("wbm"),3)==0 ) return CXIMAGE_FORMAT_WBMP;
322#endif
323#if CXIMAGE_SUPPORT_WMF
324 if (_tcsnicmp(ext,_T("wmf"),3)==0 ||
325 _tcsnicmp(ext,_T("emf"),3)==0 ) return CXIMAGE_FORMAT_WMF;
326#endif
327#if CXIMAGE_SUPPORT_JP2
328 if (_tcsnicmp(ext,_T("jp2"),3)==0 ||
329 _tcsnicmp(ext,_T("j2k"),3)==0 ) return CXIMAGE_FORMAT_JP2;
330#endif
331#if CXIMAGE_SUPPORT_JPC
332 if (_tcsnicmp(ext,_T("jpc"),3)==0 ||
333 _tcsnicmp(ext,_T("j2c"),3)==0 ) return CXIMAGE_FORMAT_JPC;
334#endif
335#if CXIMAGE_SUPPORT_PGX
336 if (_tcsnicmp(ext,_T("pgx"),3)==0 ) return CXIMAGE_FORMAT_PGX;
337#endif
338#if CXIMAGE_SUPPORT_RAS
339 if (_tcsnicmp(ext,_T("ras"),3)==0 ) return CXIMAGE_FORMAT_RAS;
340#endif
341#if CXIMAGE_SUPPORT_PNM
342 if (_tcsnicmp(ext,_T("pnm"),3)==0 ||
343 _tcsnicmp(ext,_T("pgm"),3)==0 ||
344 _tcsnicmp(ext,_T("ppm"),3)==0 ) return CXIMAGE_FORMAT_PNM;
345#endif
346#if CXIMAGE_SUPPORT_JBG
347 if (_tcsnicmp(ext,_T("jbg"),3)==0 ) return CXIMAGE_FORMAT_JBG;
348#endif
349#if CXIMAGE_SUPPORT_MNG
350 if (_tcsnicmp(ext,_T("mng"),3)==0 ||
351 _tcsnicmp(ext,_T("jng"),3)==0 ) return CXIMAGE_FORMAT_MNG;
352#endif
353#if CXIMAGE_SUPPORT_SKA
354 if (_tcsnicmp(ext,_T("ska"),3)==0 ) return CXIMAGE_FORMAT_SKA;
355#endif
356#if CXIMAGE_SUPPORT_RAW
357 if (_tcsnicmp(ext,_T("nef"),3)==0 ||
358 _tcsnicmp(ext,_T("crw"),3)==0 ||
359 _tcsnicmp(ext,_T("cr2"),3)==0 ||
360 _tcsnicmp(ext,_T("dng"),3)==0 ||
361 _tcsnicmp(ext,_T("arw"),3)==0 ||
362 _tcsnicmp(ext,_T("erf"),3)==0 ||
363 _tcsnicmp(ext,_T("3fr"),3)==0 ||
364 _tcsnicmp(ext,_T("dcr"),3)==0 ||
365 _tcsnicmp(ext,_T("raw"),3)==0 ||
366 _tcsnicmp(ext,_T("x3f"),3)==0 ||
367 _tcsnicmp(ext,_T("mef"),3)==0 ||
368 _tcsnicmp(ext,_T("raf"),3)==0 ||
369 _tcsnicmp(ext,_T("mrw"),3)==0 ||
370 _tcsnicmp(ext,_T("pef"),3)==0 ||
371 _tcsnicmp(ext,_T("sr2"),3)==0 ||
372 _tcsnicmp(ext,_T("orf"),3)==0 ) return CXIMAGE_FORMAT_RAW;
373#endif
374
375 return CXIMAGE_FORMAT_UNKNOWN;
376}
377////////////////////////////////////////////////////////////////////////////////
378DWORD CxImage::GetTypeIdFromIndex(const DWORD index)
379{
380 DWORD n;
381
382 n=0; if (index == n) return CXIMAGE_FORMAT_UNKNOWN;
383#if CXIMAGE_SUPPORT_BMP
384 n++; if (index == n) return CXIMAGE_FORMAT_BMP;
385#endif
386#if CXIMAGE_SUPPORT_GIF
387 n++; if (index == n) return CXIMAGE_FORMAT_GIF;
388#endif
389#if CXIMAGE_SUPPORT_JPG
390 n++; if (index == n) return CXIMAGE_FORMAT_JPG;
391#endif
392#if CXIMAGE_SUPPORT_PNG
393 n++; if (index == n) return CXIMAGE_FORMAT_PNG;
394#endif
395#if CXIMAGE_SUPPORT_ICO
396 n++; if (index == n) return CXIMAGE_FORMAT_ICO;
397#endif
398#if CXIMAGE_SUPPORT_TIF
399 n++; if (index == n) return CXIMAGE_FORMAT_TIF;
400#endif
401#if CXIMAGE_SUPPORT_TGA
402 n++; if (index == n) return CXIMAGE_FORMAT_TGA;
403#endif
404#if CXIMAGE_SUPPORT_PCX
405 n++; if (index == n) return CXIMAGE_FORMAT_PCX;
406#endif
407#if CXIMAGE_SUPPORT_WBMP
408 n++; if (index == n) return CXIMAGE_FORMAT_WBMP;
409#endif
410#if CXIMAGE_SUPPORT_WMF
411 n++; if (index == n) return CXIMAGE_FORMAT_WMF;
412#endif
413#if CXIMAGE_SUPPORT_JP2
414 n++; if (index == n) return CXIMAGE_FORMAT_JP2;
415#endif
416#if CXIMAGE_SUPPORT_JPC
417 n++; if (index == n) return CXIMAGE_FORMAT_JPC;
418#endif
419#if CXIMAGE_SUPPORT_PGX
420 n++; if (index == n) return CXIMAGE_FORMAT_PGX;
421#endif
422#if CXIMAGE_SUPPORT_PNM
423 n++; if (index == n) return CXIMAGE_FORMAT_PNM;
424#endif
425#if CXIMAGE_SUPPORT_RAS
426 n++; if (index == n) return CXIMAGE_FORMAT_RAS;
427#endif
428#if CXIMAGE_SUPPORT_JBG
429 n++; if (index == n) return CXIMAGE_FORMAT_JBG;
430#endif
431#if CXIMAGE_SUPPORT_MNG
432 n++; if (index == n) return CXIMAGE_FORMAT_MNG;
433#endif
434#if CXIMAGE_SUPPORT_SKA
435 n++; if (index == n) return CXIMAGE_FORMAT_SKA;
436#endif
437#if CXIMAGE_SUPPORT_RAW
438 n++; if (index == n) return CXIMAGE_FORMAT_RAW;
439#endif
440
441 return CXIMAGE_FORMAT_UNKNOWN;
442}
443////////////////////////////////////////////////////////////////////////////////
444DWORD CxImage::GetTypeIndexFromId(const DWORD id)
445{
446 DWORD n;
447
448 n=0; if (id == CXIMAGE_FORMAT_UNKNOWN) return n;
449#if CXIMAGE_SUPPORT_BMP
450 n++; if (id == CXIMAGE_FORMAT_BMP) return n;
451#endif
452#if CXIMAGE_SUPPORT_GIF
453 n++; if (id == CXIMAGE_FORMAT_GIF) return n;
454#endif
455#if CXIMAGE_SUPPORT_JPG
456 n++; if (id == CXIMAGE_FORMAT_JPG) return n;
457#endif
458#if CXIMAGE_SUPPORT_PNG
459 n++; if (id == CXIMAGE_FORMAT_PNG) return n;
460#endif
461#if CXIMAGE_SUPPORT_ICO
462 n++; if (id == CXIMAGE_FORMAT_ICO) return n;
463#endif
464#if CXIMAGE_SUPPORT_TIF
465 n++; if (id == CXIMAGE_FORMAT_TIF) return n;
466#endif
467#if CXIMAGE_SUPPORT_TGA
468 n++; if (id == CXIMAGE_FORMAT_TGA) return n;
469#endif
470#if CXIMAGE_SUPPORT_PCX
471 n++; if (id == CXIMAGE_FORMAT_PCX) return n;
472#endif
473#if CXIMAGE_SUPPORT_WBMP
474 n++; if (id == CXIMAGE_FORMAT_WBMP) return n;
475#endif
476#if CXIMAGE_SUPPORT_WMF
477 n++; if (id == CXIMAGE_FORMAT_WMF) return n;
478#endif
479#if CXIMAGE_SUPPORT_JP2
480 n++; if (id == CXIMAGE_FORMAT_JP2) return n;
481#endif
482#if CXIMAGE_SUPPORT_JPC
483 n++; if (id == CXIMAGE_FORMAT_JPC) return n;
484#endif
485#if CXIMAGE_SUPPORT_PGX
486 n++; if (id == CXIMAGE_FORMAT_PGX) return n;
487#endif
488#if CXIMAGE_SUPPORT_PNM
489 n++; if (id == CXIMAGE_FORMAT_PNM) return n;
490#endif
491#if CXIMAGE_SUPPORT_RAS
492 n++; if (id == CXIMAGE_FORMAT_RAS) return n;
493#endif
494#if CXIMAGE_SUPPORT_JBG
495 n++; if (id == CXIMAGE_FORMAT_JBG) return n;
496#endif
497#if CXIMAGE_SUPPORT_MNG
498 n++; if (id == CXIMAGE_FORMAT_MNG) return n;
499#endif
500#if CXIMAGE_SUPPORT_SKA
501 n++; if (id == CXIMAGE_FORMAT_SKA) return n;
502#endif
503#if CXIMAGE_SUPPORT_RAW
504 n++; if (id == CXIMAGE_FORMAT_RAW) return n;
505#endif
506
507 return 0;
508}
509////////////////////////////////////////////////////////////////////////////////
510/**
511 * \return current frame delay in milliseconds. Only for GIF and MNG formats.
512 */
513DWORD CxImage::GetFrameDelay() const
514{
515 return info.dwFrameDelay;
516}
517////////////////////////////////////////////////////////////////////////////////
518/**
519 * Sets current frame delay. Only for GIF format.
520 * \param d = delay in milliseconds
521 */
522void CxImage::SetFrameDelay(DWORD d)
523{
524 info.dwFrameDelay=d;
525}
526////////////////////////////////////////////////////////////////////////////////
527void CxImage::GetOffset(long *x,long *y)
528{
529 *x=info.xOffset;
530 *y=info.yOffset;
531}
532////////////////////////////////////////////////////////////////////////////////
533void CxImage::SetOffset(long x,long y)
534{
535 info.xOffset=x;
536 info.yOffset=y;
537}
538////////////////////////////////////////////////////////////////////////////////
539/**
540 * \sa SetJpegQuality, GetJpegQualityF
541 * \author [DP]; changes [Stefan Schürmans]
542 */
543BYTE CxImage::GetJpegQuality() const
544{
545 return (BYTE)(info.fQuality + 0.5f);
546}
547////////////////////////////////////////////////////////////////////////////////
548/**
549 * \sa SetJpegQuality, GetJpegQuality
550 * \author [Stefan Schürmans]
551 */
552float CxImage::GetJpegQualityF() const
553{
554 return info.fQuality;
555}
556////////////////////////////////////////////////////////////////////////////////
557/**
558 * quality level for JPEG and JPEG2000
559 * \param q: can be from 0 to 100
560 * \author [DP]; changes [Stefan Schürmans]
561 */
562void CxImage::SetJpegQuality(BYTE q){
563 info.fQuality = (float)q;
564}
565////////////////////////////////////////////////////////////////////////////////
566/**
567 * quality level for JPEG and JPEG2000
568 * necessary for JPEG2000 when quality is between 0.0 and 1.0
569 * \param q: can be from 0.0 to 100.0
570 * \author [Stefan Schürmans]
571 */
572void CxImage::SetJpegQualityF(float q){
573 if (q>0) info.fQuality = q;
574 else info.fQuality = 0.0f;
575}
576////////////////////////////////////////////////////////////////////////////////
577/**
578 * \sa SetJpegScale
579 */
580BYTE CxImage::GetJpegScale() const
581{
582 return info.nJpegScale;
583}
584////////////////////////////////////////////////////////////////////////////////
585/**
586 * scaling down during JPEG decoding valid numbers are 1, 2, 4, 8
587 * \author [ignacio]
588 */
589void CxImage::SetJpegScale(BYTE q){
590 info.nJpegScale = q;
591}
592////////////////////////////////////////////////////////////////////////////////
593/**
594 * Used to monitor the slow loops.
595 * \return value is from 0 to 100.
596 * \sa SetProgress
597 */
598long CxImage::GetProgress() const
599{
600 return info.nProgress;
601}
602////////////////////////////////////////////////////////////////////////////////
603/**
604 * \return the escape code.
605 * \sa SetEscape
606 */
607long CxImage::GetEscape() const
608{
609 return info.nEscape;
610}
611////////////////////////////////////////////////////////////////////////////////
612/**
613 * Forces the value of the internal progress variable.
614 * \param p should be from 0 to 100.
615 * \sa GetProgress
616 */
617void CxImage::SetProgress(long p)
618{
619 info.nProgress = p;
620}
621////////////////////////////////////////////////////////////////////////////////
622/**
623 * Used to quit the slow loops or the codecs.
624 * - SetEscape(-1) before Decode forces the function to exit, right after
625 * the image width and height are available ( for bmp, jpg, gif, tif )
626 */
627void CxImage::SetEscape(long i)
628{
629 info.nEscape = i;
630}
631////////////////////////////////////////////////////////////////////////////////
632/**
633 * Checks if the image is correctly initializated.
634 */
635bool CxImage::IsValid() const
636{
637 return pDib!=0;
638}
639////////////////////////////////////////////////////////////////////////////////
640/**
641 * True if the image is enabled for painting.
642 */
643bool CxImage::IsEnabled() const
644{
645 return info.bEnabled;
646}
647////////////////////////////////////////////////////////////////////////////////
648/**
649 * Enables/disables the image.
650 */
651void CxImage::Enable(bool enable)
652{
653 info.bEnabled=enable;
654}
655////////////////////////////////////////////////////////////////////////////////
656/**
657 * This function must be used after a Decode() / Load() call.
658 * Use the sequence SetFrame(-1); Load(...); GetNumFrames();
659 * to get the number of images without loading the first image.
660 * \return the number of images in the file.
661 */
662long CxImage::GetNumFrames() const
663{
664 return info.nNumFrames;
665}
666////////////////////////////////////////////////////////////////////////////////
667/**
668 * \return the current selected image (zero-based index).
669 */
670long CxImage::GetFrame() const
671{
672 return info.nFrame;
673}
674////////////////////////////////////////////////////////////////////////////////
675/**
676 * Sets the image number that the next Decode() / Load() call will load
677 */
678void CxImage::SetFrame(long nFrame){
679 info.nFrame=nFrame;
680}
681////////////////////////////////////////////////////////////////////////////////
682/**
683 * Sets the method for drawing the frame related to others
684 * \sa GetDisposalMethod
685 */
686void CxImage::SetDisposalMethod(BYTE dm)
687{ info.dispmeth=dm; }
688////////////////////////////////////////////////////////////////////////////////
689/**
690 * Gets the method for drawing the frame related to others
691 * Values : 0 - No disposal specified. The decoder is
692 * not required to take any action.
693 * 1 - Do not dispose. The graphic is to be left
694 * in place.
695 * 2 - Restore to background color. The area used by the
696 * graphic must be restored to the background color.
697 * 3 - Restore to previous. The decoder is required to
698 * restore the area overwritten by the graphic with
699 * what was there prior to rendering the graphic.
700 * 4-7 - To be defined.
701 */
702BYTE CxImage::GetDisposalMethod() const
703{ return info.dispmeth; }
704////////////////////////////////////////////////////////////////////////////////
705bool CxImage::GetRetreiveAllFrames() const
706{ return info.bGetAllFrames; }
707////////////////////////////////////////////////////////////////////////////////
708void CxImage::SetRetreiveAllFrames(bool flag)
709{ info.bGetAllFrames = flag; }
710////////////////////////////////////////////////////////////////////////////////
711CxImage * CxImage::GetFrame(long nFrame) const
712{
713 if ( ppFrames == NULL) return NULL;
714 if ( info.nNumFrames == 0) return NULL;
715 if ( nFrame >= info.nNumFrames ) return NULL;
716 if ( nFrame < 0) nFrame = info.nNumFrames - 1;
717 return ppFrames[nFrame];
718}
719////////////////////////////////////////////////////////////////////////////////
720short CxImage::ntohs(const short word)
721{
722 if (info.bLittleEndianHost) return word;
723 return ( (word & 0xff) << 8 ) | ( (word >> 8) & 0xff );
724}
725////////////////////////////////////////////////////////////////////////////////
726long CxImage::ntohl(const long dword)
727{
728 if (info.bLittleEndianHost) return dword;
729 return ((dword & 0xff) << 24 ) | ((dword & 0xff00) << 8 ) |
730 ((dword >> 8) & 0xff00) | ((dword >> 24) & 0xff);
731}
732////////////////////////////////////////////////////////////////////////////////
733void CxImage::bihtoh(BITMAPINFOHEADER* bih)
734{
735 bih->biSize = ntohl(bih->biSize);
736 bih->biWidth = ntohl(bih->biWidth);
737 bih->biHeight = ntohl(bih->biHeight);
738 bih->biPlanes = ntohs(bih->biPlanes);
739 bih->biBitCount = ntohs(bih->biBitCount);
740 bih->biCompression = ntohl(bih->biCompression);
741 bih->biSizeImage = ntohl(bih->biSizeImage);
742 bih->biXPelsPerMeter = ntohl(bih->biXPelsPerMeter);
743 bih->biYPelsPerMeter = ntohl(bih->biYPelsPerMeter);
744 bih->biClrUsed = ntohl(bih->biClrUsed);
745 bih->biClrImportant = ntohl(bih->biClrImportant);
746}
747////////////////////////////////////////////////////////////////////////////////
748/**
749 * Returns the last reported error.
750 */
751const char* CxImage::GetLastError()
752{
753 return info.szLastError;
754}
755////////////////////////////////////////////////////////////////////////////////
756DWORD CxImage::DumpSize()
757{
758 DWORD n;
759 n = sizeof(BITMAPINFOHEADER) + sizeof(CXIMAGEINFO) + GetSize();
760
761 if (pAlpha){
762 n += 1 + head.biWidth * head.biHeight;
763 } else n++;
764
765 if (pSelection){
766 n += 1 + head.biWidth * head.biHeight;
767 } else n++;
768
769 if (ppLayers){
770 for (long m=0; m<GetNumLayers(); m++){
771 if (GetLayer(m)){
772 n += 1 + GetLayer(m)->DumpSize();
773 }
774 }
775 } else n++;
776
777 if (ppFrames){
778 for (long m=0; m<GetNumFrames(); m++){
779 if (GetFrame(m)){
780 n += 1 + GetFrame(m)->DumpSize();
781 }
782 }
783 } else n++;
784
785 return n;
786}
787////////////////////////////////////////////////////////////////////////////////
788DWORD CxImage::Dump(BYTE * dst)
789{
790 if (!dst) return 0;
791
792 memcpy(dst,&head,sizeof(BITMAPINFOHEADER));
793 dst += sizeof(BITMAPINFOHEADER);
794
795 memcpy(dst,&info,sizeof(CXIMAGEINFO));
796 dst += sizeof(CXIMAGEINFO);
797
798 memcpy(dst,pDib,GetSize());
799 dst += GetSize();
800
801 if (pAlpha){
802 memset(dst++, 1, 1);
803 memcpy(dst,pAlpha,head.biWidth * head.biHeight);
804 dst += head.biWidth * head.biHeight;
805 } else {
806 memset(dst++, 0, 1);
807 }
808
809 if (pSelection){
810 memset(dst++, 1, 1);
811 memcpy(dst,pSelection,head.biWidth * head.biHeight);
812 dst += head.biWidth * head.biHeight;
813 } else {
814 memset(dst++, 0, 1);
815 }
816
817 if (ppLayers){
818 memset(dst++, 1, 1);
819 for (long m=0; m<GetNumLayers(); m++){
820 if (GetLayer(m)){
821 dst += GetLayer(m)->Dump(dst);
822 }
823 }
824 } else {
825 memset(dst++, 0, 1);
826 }
827
828 if (ppFrames){
829 memset(dst++, 1, 1);
830 for (long m=0; m<GetNumFrames(); m++){
831 if (GetFrame(m)){
832 dst += GetFrame(m)->Dump(dst);
833 }
834 }
835 } else {
836 memset(dst++, 0, 1);
837 }
838
839 return DumpSize();
840}
841////////////////////////////////////////////////////////////////////////////////
842DWORD CxImage::UnDump(const BYTE * src)
843{
844 if (!src)
845 return 0;
846 if (!Destroy())
847 return 0;
848 if (!DestroyFrames())
849 return 0;
850
851 DWORD n = 0;
852
853 memcpy(&head,src,sizeof(BITMAPINFOHEADER));
854 n += sizeof(BITMAPINFOHEADER);
855
856 memcpy(&info,&src[n],sizeof(CXIMAGEINFO));
857 n += sizeof(CXIMAGEINFO);
858
859 if (!Create(head.biWidth, head.biHeight, head.biBitCount, info.dwType))
860 return 0;
861
862 memcpy(pDib,&src[n],GetSize());
863 n += GetSize();
864
865 if (src[n++]){
866 if (AlphaCreate()){
867 memcpy(pAlpha, &src[n], head.biWidth * head.biHeight);
868 }
869 n += head.biWidth * head.biHeight;
870 }
871
872 if (src[n++]){
873 RECT box = info.rSelectionBox;
874 if (SelectionCreate()){
875 info.rSelectionBox = box;
876 memcpy(pSelection, &src[n], head.biWidth * head.biHeight);
877 }
878 n += head.biWidth * head.biHeight;
879 }
880
881 if (src[n++]){
882 ppLayers = new CxImage*[info.nNumLayers];
883 for (long m=0; m<GetNumLayers(); m++){
884 ppLayers[m] = new CxImage();
885 n += ppLayers[m]->UnDump(&src[n]);
886 }
887 }
888
889 if (src[n++]){
890 ppFrames = new CxImage*[info.nNumFrames];
891 for (long m=0; m<GetNumFrames(); m++){
892 ppFrames[m] = new CxImage();
893 n += ppFrames[m]->UnDump(&src[n]);
894 }
895 }
896
897 return n;
898}
899////////////////////////////////////////////////////////////////////////////////
900/**
901 * \return A.BBCCCDDDD
902 * - A = main version
903 * - BB = main revision
904 * - CCC = minor revision (letter)
905 * - DDDD = experimental revision
906 */
907const float CxImage::GetVersionNumber()
908{
909 return 6.000000015f;
910}
911////////////////////////////////////////////////////////////////////////////////
912const TCHAR* CxImage::GetVersion()
913{
914 static const TCHAR CxImageVersion[] = _T("CxImage 6.0.0");
915 return (CxImageVersion);
916}
917////////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.