1 // xImaCodec.cpp : Encode Decode functions
2 /* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it
3 * CxImage version 6.0.0 02/Feb/2008
8 #if CXIMAGE_SUPPORT_JPG
12 #if CXIMAGE_SUPPORT_GIF
16 #if CXIMAGE_SUPPORT_PNG
20 #if CXIMAGE_SUPPORT_MNG
24 #if CXIMAGE_SUPPORT_BMP
28 #if CXIMAGE_SUPPORT_ICO
32 #if CXIMAGE_SUPPORT_TIF
36 #if CXIMAGE_SUPPORT_TGA
40 #if CXIMAGE_SUPPORT_PCX
44 #if CXIMAGE_SUPPORT_WBMP
48 #if CXIMAGE_SUPPORT_WMF
49 #include "ximawmf.h" // <vho> - WMF/EMF support
52 #if CXIMAGE_SUPPORT_JBG
56 #if CXIMAGE_SUPPORT_JASPER
60 #if CXIMAGE_SUPPORT_SKA
64 #if CXIMAGE_SUPPORT_RAW
68 ////////////////////////////////////////////////////////////////////////////////
69 #if CXIMAGE_SUPPORT_ENCODE
70 ////////////////////////////////////////////////////////////////////////////////
71 bool CxImage::EncodeSafeCheck(CxFile *hFile)
74 strcpy(info.szLastError,CXIMAGE_ERR_NOFILE);
79 strcpy(info.szLastError,CXIMAGE_ERR_NOIMAGE);
84 ////////////////////////////////////////////////////////////////////////////////
86 //bool CxImage::Save(LPCWSTR filename, DWORD imagetype)
88 // FILE* hFile; //file handle to write the image
89 // if ((hFile=_wfopen(filename,L"wb"))==NULL) return false;
90 // bool bOK = Encode(hFile,imagetype);
95 ////////////////////////////////////////////////////////////////////////////////
96 // For UNICODE support: char -> TCHAR
98 * Saves to disk the image in a specific format.
99 * \param filename: file name
100 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
101 * \return true if everything is ok
103 bool CxImage::Save(const TCHAR * filename, DWORD imagetype)
105 FILE* hFile; //file handle to write the image
108 if ((hFile=_tfopen(filename,_T("wb")))==NULL) return false; // For UNICODE support
110 if ((hFile=fopen(filename,"wb"))==NULL) return false;
113 bool bOK = Encode(hFile,imagetype);
117 ////////////////////////////////////////////////////////////////////////////////
119 * Saves to disk the image in a specific format.
120 * \param hFile: file handle, open and enabled for writing.
121 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
122 * \return true if everything is ok
124 bool CxImage::Encode(FILE *hFile, DWORD imagetype)
126 CxIOFile file(hFile);
127 return Encode(&file,imagetype);
129 ////////////////////////////////////////////////////////////////////////////////
131 * Saves to memory buffer the image in a specific format.
132 * \param buffer: output memory buffer pointer. Must be NULL,
133 * the function allocates and fill the memory,
134 * the application must free the buffer, see also FreeMemory().
135 * \param size: output memory buffer size.
136 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
137 * \return true if everything is ok
139 bool CxImage::Encode(BYTE * &buffer, long &size, DWORD imagetype)
142 strcpy(info.szLastError,"the buffer must be empty");
147 if(Encode(&file,imagetype)){
148 buffer=file.GetBuffer();
154 ////////////////////////////////////////////////////////////////////////////////
156 * Saves to disk the image in a specific format.
157 * \param hFile: file handle (CxMemFile or CxIOFile), with write access.
158 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
159 * \return true if everything is ok
160 * \sa ENUM_CXIMAGE_FORMATS
162 bool CxImage::Encode(CxFile *hFile, DWORD imagetype)
165 #if CXIMAGE_SUPPORT_BMP
167 if (imagetype==CXIMAGE_FORMAT_BMP){
170 if (newima.Encode(hFile)){
173 strcpy(info.szLastError,newima.GetLastError());
178 #if CXIMAGE_SUPPORT_ICO
179 if (imagetype==CXIMAGE_FORMAT_ICO){
182 if (newima.Encode(hFile)){
185 strcpy(info.szLastError,newima.GetLastError());
190 #if CXIMAGE_SUPPORT_TIF
191 if (imagetype==CXIMAGE_FORMAT_TIF){
194 if (newima.Encode(hFile)){
197 strcpy(info.szLastError,newima.GetLastError());
202 #if CXIMAGE_SUPPORT_JPG
203 if (imagetype==CXIMAGE_FORMAT_JPG){
206 if (newima.Encode(hFile)){
209 strcpy(info.szLastError,newima.GetLastError());
214 #if CXIMAGE_SUPPORT_GIF
215 if (imagetype==CXIMAGE_FORMAT_GIF){
218 if (newima.Encode(hFile)){
221 strcpy(info.szLastError,newima.GetLastError());
226 #if CXIMAGE_SUPPORT_PNG
227 if (imagetype==CXIMAGE_FORMAT_PNG){
230 if (newima.Encode(hFile)){
233 strcpy(info.szLastError,newima.GetLastError());
238 #if CXIMAGE_SUPPORT_MNG
239 if (imagetype==CXIMAGE_FORMAT_MNG){
242 if (newima.Encode(hFile)){
245 strcpy(info.szLastError,newima.GetLastError());
250 #if CXIMAGE_SUPPORT_TGA
251 if (imagetype==CXIMAGE_FORMAT_TGA){
254 if (newima.Encode(hFile)){
257 strcpy(info.szLastError,newima.GetLastError());
262 #if CXIMAGE_SUPPORT_PCX
263 if (imagetype==CXIMAGE_FORMAT_PCX){
266 if (newima.Encode(hFile)){
269 strcpy(info.szLastError,newima.GetLastError());
274 #if CXIMAGE_SUPPORT_WBMP
275 if (imagetype==CXIMAGE_FORMAT_WBMP){
278 if (newima.Encode(hFile)){
281 strcpy(info.szLastError,newima.GetLastError());
286 #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // <vho> - WMF/EMF support
287 if (imagetype==CXIMAGE_FORMAT_WMF){
290 if (newima.Encode(hFile)){
293 strcpy(info.szLastError,newima.GetLastError());
298 #if CXIMAGE_SUPPORT_JBG
299 if (imagetype==CXIMAGE_FORMAT_JBG){
302 if (newima.Encode(hFile)){
305 strcpy(info.szLastError,newima.GetLastError());
310 #if CXIMAGE_SUPPORT_JASPER
312 #if CXIMAGE_SUPPORT_JP2
313 imagetype==CXIMAGE_FORMAT_JP2 ||
315 #if CXIMAGE_SUPPORT_JPC
316 imagetype==CXIMAGE_FORMAT_JPC ||
318 #if CXIMAGE_SUPPORT_PGX
319 imagetype==CXIMAGE_FORMAT_PGX ||
321 #if CXIMAGE_SUPPORT_PNM
322 imagetype==CXIMAGE_FORMAT_PNM ||
324 #if CXIMAGE_SUPPORT_RAS
325 imagetype==CXIMAGE_FORMAT_RAS ||
330 if (newima.Encode(hFile,imagetype)){
333 strcpy(info.szLastError,newima.GetLastError());
339 #if CXIMAGE_SUPPORT_SKA
340 if (imagetype==CXIMAGE_FORMAT_SKA){
343 if (newima.Encode(hFile)){
346 strcpy(info.szLastError,newima.GetLastError());
352 #if CXIMAGE_SUPPORT_RAW
353 if (imagetype==CXIMAGE_FORMAT_RAW){
356 if (newima.Encode(hFile)){
359 strcpy(info.szLastError,newima.GetLastError());
365 strcpy(info.szLastError,"Encode: Unknown format");
368 ////////////////////////////////////////////////////////////////////////////////
370 * Saves to disk or memory pagecount images, referenced by an array of CxImage pointers.
371 * \param hFile: file handle.
372 * \param pImages: array of CxImage pointers.
373 * \param pagecount: number of images.
374 * \param imagetype: can be CXIMAGE_FORMAT_TIF or CXIMAGE_FORMAT_GIF.
375 * \return true if everything is ok
377 bool CxImage::Encode(FILE * hFile, CxImage ** pImages, int pagecount, DWORD imagetype)
379 CxIOFile file(hFile);
380 return Encode(&file, pImages, pagecount,imagetype);
382 ////////////////////////////////////////////////////////////////////////////////
384 * Saves to disk or memory pagecount images, referenced by an array of CxImage pointers.
385 * \param hFile: file handle (CxMemFile or CxIOFile), with write access.
386 * \param pImages: array of CxImage pointers.
387 * \param pagecount: number of images.
388 * \param imagetype: can be CXIMAGE_FORMAT_TIF, CXIMAGE_FORMAT_GIF or CXIMAGE_FORMAT_ICO.
389 * \return true if everything is ok
391 bool CxImage::Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype)
393 #if CXIMAGE_SUPPORT_TIF
394 if (imagetype==CXIMAGE_FORMAT_TIF){
397 if (newima.Encode(hFile,pImages,pagecount)){
400 strcpy(info.szLastError,newima.GetLastError());
405 #if CXIMAGE_SUPPORT_GIF
406 if (imagetype==CXIMAGE_FORMAT_GIF){
409 if (newima.Encode(hFile,pImages,pagecount)){
412 strcpy(info.szLastError,newima.GetLastError());
417 #if CXIMAGE_SUPPORT_ICO
418 if (imagetype==CXIMAGE_FORMAT_ICO){
421 if (newima.Encode(hFile,pImages,pagecount)){
424 strcpy(info.szLastError,newima.GetLastError());
429 strcpy(info.szLastError,"Multipage Encode, Unsupported operation for this format");
433 ////////////////////////////////////////////////////////////////////////////////
435 * exports the image into a RGBA buffer, Useful for OpenGL applications.
436 * \param buffer: output memory buffer pointer. Must be NULL,
437 * the function allocates and fill the memory,
438 * the application must free the buffer, see also FreeMemory().
439 * \param size: output memory buffer size.
440 * \param bFlipY: direction of Y axis. default = false.
441 * \return true if everything is ok
443 bool CxImage::Encode2RGBA(BYTE * &buffer, long &size, bool bFlipY)
446 strcpy(info.szLastError,"the buffer must be empty");
451 if(Encode2RGBA(&file,bFlipY)){
452 buffer=file.GetBuffer();
458 ////////////////////////////////////////////////////////////////////////////////
460 * exports the image into a RGBA buffer, Useful for OpenGL applications.
461 * \param hFile: file handle (CxMemFile or CxIOFile), with write access.
462 * \param bFlipY: direction of Y axis. default = false.
463 * \return true if everything is ok
465 bool CxImage::Encode2RGBA(CxFile *hFile, bool bFlipY)
467 if (EncodeSafeCheck(hFile)) return false;
469 for (long y1 = 0; y1 < head.biHeight; y1++) {
470 long y = bFlipY ? head.biHeight - 1 - y1 : y1;
471 for(long x = 0; x < head.biWidth; x++) {
472 RGBQUAD color = BlindGetPixelColor(x,y);
473 hFile->PutC(color.rgbRed);
474 hFile->PutC(color.rgbGreen);
475 hFile->PutC(color.rgbBlue);
476 hFile->PutC(color.rgbReserved);
482 ////////////////////////////////////////////////////////////////////////////////
483 #endif //CXIMAGE_SUPPORT_ENCODE
484 ////////////////////////////////////////////////////////////////////////////////
486 ////////////////////////////////////////////////////////////////////////////////
487 #if CXIMAGE_SUPPORT_DECODE
488 ////////////////////////////////////////////////////////////////////////////////
489 // For UNICODE support: char -> TCHAR
491 * Reads from disk the image in a specific format.
492 * - If decoding fails using the specified image format,
493 * the function will try the automatic file format recognition.
495 * \param filename: file name
496 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
497 * \return true if everything is ok
499 bool CxImage::Load(const TCHAR * filename, DWORD imagetype)
500 //bool CxImage::Load(const char * filename, DWORD imagetype)
502 /*FILE* hFile; //file handle to read the image
503 if ((hFile=fopen(filename,"rb"))==NULL) return false;
504 bool bOK = Decode(hFile,imagetype);
507 /* automatic file type recognition */
509 if ( GetTypeIndexFromId(imagetype) ){
510 FILE* hFile; //file handle to read the image
513 if ((hFile=_tfopen(filename,_T("rb")))==NULL) return false; // For UNICODE support
515 if ((hFile=fopen(filename,"rb"))==NULL) return false;
518 bOK = Decode(hFile,imagetype);
524 strcpy(szError,info.szLastError); //save the first error
526 // if failed, try automatic recognition of the file...
530 if ((hFile=_tfopen(filename,_T("rb")))==NULL) return false; // For UNICODE support
532 if ((hFile=fopen(filename,"rb"))==NULL) return false;
535 bOK = Decode(hFile,CXIMAGE_FORMAT_UNKNOWN);
538 if (!bOK && imagetype > 0) strcpy(info.szLastError,szError); //restore the first error
542 ////////////////////////////////////////////////////////////////////////////////
544 //bool CxImage::Load(LPCWSTR filename, DWORD imagetype)
546 // /*FILE* hFile; //file handle to read the image
547 // if ((hFile=_wfopen(filename, L"rb"))==NULL) return false;
548 // bool bOK = Decode(hFile,imagetype);
551 // /* automatic file type recognition */
553 // if ( GetTypeIndexFromId(imagetype) ){
554 // FILE* hFile; //file handle to read the image
555 // if ((hFile=_wfopen(filename,L"rb"))==NULL) return false;
556 // bOK = Decode(hFile,imagetype);
558 // if (bOK) return bOK;
561 // char szError[256];
562 // strcpy(szError,info.szLastError); //save the first error
564 // // if failed, try automatic recognition of the file...
565 // FILE* hFile; //file handle to read the image
566 // if ((hFile=_wfopen(filename,L"rb"))==NULL) return false;
567 // bOK = Decode(hFile,CXIMAGE_FORMAT_UNKNOWN);
570 // if (!bOK && imagetype > 0) strcpy(info.szLastError,szError); //restore the first error
574 ////////////////////////////////////////////////////////////////////////////////
576 * Loads an image from the application resources.
577 * \param hRes: the resource handle returned by FindResource().
578 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS.
579 * \param hModule: NULL for internal resource, or external application/DLL hinstance returned by LoadLibray.
580 * \return true if everything is ok
582 bool CxImage::LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule)
584 DWORD rsize=SizeofResource(hModule,hRes);
585 HGLOBAL hMem=::LoadResource(hModule,hRes);
587 char* lpVoid=(char*)LockResource(hMem);
589 // FILE* fTmp=tmpfile(); doesn't work with network
590 /*char tmpPath[MAX_PATH] = {0};
591 char tmpFile[MAX_PATH] = {0};
592 GetTempPath(MAX_PATH,tmpPath);
593 GetTempFileName(tmpPath,"IMG",0,tmpFile);
594 FILE* fTmp=fopen(tmpFile,"w+b");
596 fwrite(lpVoid,rsize,1,fTmp);
597 fseek(fTmp,0,SEEK_SET);
598 bool bOK = Decode(fTmp,imagetype);
604 CxMemFile fTmp((BYTE*)lpVoid,rsize);
605 return Decode(&fTmp,imagetype);
607 } else strcpy(info.szLastError,"Unable to load resource!");
611 ////////////////////////////////////////////////////////////////////////////////
613 * Constructor from file name, see Load()
614 * \param filename: file name
615 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
618 // > filename: file name
619 // > imagetype: specify the image format (CXIMAGE_FORMAT_BMP,...)
620 // For UNICODE support: char -> TCHAR
621 CxImage::CxImage(const TCHAR * filename, DWORD imagetype)
622 //CxImage::CxImage(const char * filename, DWORD imagetype)
625 Load(filename,imagetype);
627 ////////////////////////////////////////////////////////////////////////////////
629 * Constructor from file handle, see Decode()
630 * \param stream: file handle, with read access.
631 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
633 CxImage::CxImage(FILE * stream, DWORD imagetype)
636 Decode(stream,imagetype);
638 ////////////////////////////////////////////////////////////////////////////////
640 * Constructor from CxFile object, see Decode()
641 * \param stream: file handle (CxMemFile or CxIOFile), with read access.
642 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
644 CxImage::CxImage(CxFile * stream, DWORD imagetype)
647 Decode(stream,imagetype);
649 ////////////////////////////////////////////////////////////////////////////////
651 * Constructor from memory buffer, see Decode()
652 * \param buffer: memory buffer
653 * \param size: size of buffer
654 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
656 CxImage::CxImage(BYTE * buffer, DWORD size, DWORD imagetype)
659 CxMemFile stream(buffer,size);
660 Decode(&stream,imagetype);
662 ////////////////////////////////////////////////////////////////////////////////
664 * Loads an image from memory buffer
665 * \param buffer: memory buffer
666 * \param size: size of buffer
667 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
668 * \return true if everything is ok
670 bool CxImage::Decode(BYTE * buffer, DWORD size, DWORD imagetype)
672 CxMemFile file(buffer,size);
673 return Decode(&file,imagetype);
675 ////////////////////////////////////////////////////////////////////////////////
677 * Loads an image from file handle.
678 * \param hFile: file handle, with read access.
679 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
680 * \return true if everything is ok
682 bool CxImage::Decode(FILE *hFile, DWORD imagetype)
684 CxIOFile file(hFile);
685 return Decode(&file,imagetype);
687 ////////////////////////////////////////////////////////////////////////////////
689 * Loads an image from CxFile object
690 * \param hFile: file handle (CxMemFile or CxIOFile), with read access.
691 * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
692 * \return true if everything is ok
693 * \sa ENUM_CXIMAGE_FORMATS
695 bool CxImage::Decode(CxFile *hFile, DWORD imagetype)
698 strcpy(info.szLastError,CXIMAGE_ERR_NOFILE);
702 if (imagetype==CXIMAGE_FORMAT_UNKNOWN){
703 DWORD pos = hFile->Tell();
704 #if CXIMAGE_SUPPORT_BMP
705 { CxImageBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
707 #if CXIMAGE_SUPPORT_JPG
708 { CxImageJPG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
710 #if CXIMAGE_SUPPORT_ICO
711 { CxImageICO newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
713 #if CXIMAGE_SUPPORT_GIF
714 { CxImageGIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
716 #if CXIMAGE_SUPPORT_PNG
717 { CxImagePNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
719 #if CXIMAGE_SUPPORT_TIF
720 { CxImageTIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
722 #if CXIMAGE_SUPPORT_MNG
723 { CxImageMNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
725 #if CXIMAGE_SUPPORT_TGA
726 { CxImageTGA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
728 #if CXIMAGE_SUPPORT_PCX
729 { CxImagePCX newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
731 #if CXIMAGE_SUPPORT_WBMP
732 { CxImageWBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
734 #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS
735 { CxImageWMF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
737 #if CXIMAGE_SUPPORT_JBG
738 { CxImageJBG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
740 #if CXIMAGE_SUPPORT_JASPER
741 { CxImageJAS newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
743 #if CXIMAGE_SUPPORT_SKA
744 { CxImageSKA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
746 #if CXIMAGE_SUPPORT_RAW
747 { CxImageRAW newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
751 #if CXIMAGE_SUPPORT_BMP
752 if (imagetype==CXIMAGE_FORMAT_BMP){
754 newima.CopyInfo(*this);
755 if (newima.Decode(hFile)){
759 strcpy(info.szLastError,newima.GetLastError());
764 #if CXIMAGE_SUPPORT_JPG
765 if (imagetype==CXIMAGE_FORMAT_JPG){
767 newima.CopyInfo(*this); // <ignacio>
768 if (newima.Decode(hFile)){
772 strcpy(info.szLastError,newima.GetLastError());
777 #if CXIMAGE_SUPPORT_ICO
778 if (imagetype==CXIMAGE_FORMAT_ICO){
780 newima.CopyInfo(*this);
781 if (newima.Decode(hFile)){
785 info.nNumFrames = newima.info.nNumFrames;
786 strcpy(info.szLastError,newima.GetLastError());
791 #if CXIMAGE_SUPPORT_GIF
792 if (imagetype==CXIMAGE_FORMAT_GIF){
794 newima.CopyInfo(*this);
795 if (newima.Decode(hFile)){
799 info.nNumFrames = newima.info.nNumFrames;
800 strcpy(info.szLastError,newima.GetLastError());
805 #if CXIMAGE_SUPPORT_PNG
806 if (imagetype==CXIMAGE_FORMAT_PNG){
808 newima.CopyInfo(*this);
809 if (newima.Decode(hFile)){
813 strcpy(info.szLastError,newima.GetLastError());
818 #if CXIMAGE_SUPPORT_TIF
819 if (imagetype==CXIMAGE_FORMAT_TIF){
821 newima.CopyInfo(*this);
822 if (newima.Decode(hFile)){
826 info.nNumFrames = newima.info.nNumFrames;
827 strcpy(info.szLastError,newima.GetLastError());
832 #if CXIMAGE_SUPPORT_MNG
833 if (imagetype==CXIMAGE_FORMAT_MNG){
835 newima.CopyInfo(*this);
836 if (newima.Decode(hFile)){
840 info.nNumFrames = newima.info.nNumFrames;
841 strcpy(info.szLastError,newima.GetLastError());
846 #if CXIMAGE_SUPPORT_TGA
847 if (imagetype==CXIMAGE_FORMAT_TGA){
849 newima.CopyInfo(*this);
850 if (newima.Decode(hFile)){
854 strcpy(info.szLastError,newima.GetLastError());
859 #if CXIMAGE_SUPPORT_PCX
860 if (imagetype==CXIMAGE_FORMAT_PCX){
862 newima.CopyInfo(*this);
863 if (newima.Decode(hFile)){
867 strcpy(info.szLastError,newima.GetLastError());
872 #if CXIMAGE_SUPPORT_WBMP
873 if (imagetype==CXIMAGE_FORMAT_WBMP){
875 newima.CopyInfo(*this);
876 if (newima.Decode(hFile)){
880 strcpy(info.szLastError,newima.GetLastError());
885 #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // vho - WMF support
886 if (imagetype == CXIMAGE_FORMAT_WMF){
888 newima.CopyInfo(*this);
889 if (newima.Decode(hFile)){
893 strcpy(info.szLastError,newima.GetLastError());
898 #if CXIMAGE_SUPPORT_JBG
899 if (imagetype==CXIMAGE_FORMAT_JBG){
901 newima.CopyInfo(*this);
902 if (newima.Decode(hFile)){
906 strcpy(info.szLastError,newima.GetLastError());
911 #if CXIMAGE_SUPPORT_JASPER
913 #if CXIMAGE_SUPPORT_JP2
914 imagetype==CXIMAGE_FORMAT_JP2 ||
916 #if CXIMAGE_SUPPORT_JPC
917 imagetype==CXIMAGE_FORMAT_JPC ||
919 #if CXIMAGE_SUPPORT_PGX
920 imagetype==CXIMAGE_FORMAT_PGX ||
922 #if CXIMAGE_SUPPORT_PNM
923 imagetype==CXIMAGE_FORMAT_PNM ||
925 #if CXIMAGE_SUPPORT_RAS
926 imagetype==CXIMAGE_FORMAT_RAS ||
930 newima.CopyInfo(*this);
931 if (newima.Decode(hFile,imagetype)){
935 strcpy(info.szLastError,newima.GetLastError());
940 #if CXIMAGE_SUPPORT_SKA
941 if (imagetype==CXIMAGE_FORMAT_SKA){
943 newima.CopyInfo(*this);
944 if (newima.Decode(hFile)){
948 strcpy(info.szLastError,newima.GetLastError());
954 #if CXIMAGE_SUPPORT_RAW
955 if (imagetype==CXIMAGE_FORMAT_RAW){
957 newima.CopyInfo(*this);
958 if (newima.Decode(hFile)){
962 strcpy(info.szLastError,newima.GetLastError());
968 strcpy(info.szLastError,"Decode: Unknown or wrong format");
971 ////////////////////////////////////////////////////////////////////////////////
973 * Loads an image from CxFile object
974 * \param hFile: file handle (CxMemFile or CxIOFile), with read access.
975 * \param imagetype: file format, default = 0 (CXIMAGE_FORMAT_UNKNOWN)
976 * \return : if imagetype is not 0, the function returns true when imagetype
977 * matches the file image format. If imagetype is 0, the function returns true
978 * when the file image format is recognized as a supported format.
979 * If the returned value is true, use GetHeight(), GetWidth() or GetType()
980 * to retrieve the basic image information.
981 * \sa ENUM_CXIMAGE_FORMATS
983 bool CxImage::CheckFormat(CxFile * hFile, DWORD imagetype)
985 SetType(CXIMAGE_FORMAT_UNKNOWN);
988 if (!Decode(hFile,imagetype))
991 if (GetType() == CXIMAGE_FORMAT_UNKNOWN || GetType() != imagetype)
996 ////////////////////////////////////////////////////////////////////////////////
997 bool CxImage::CheckFormat(BYTE * buffer, DWORD size, DWORD imagetype)
999 if (buffer==NULL || size==0){
1000 strcpy(info.szLastError,"invalid or empty buffer");
1003 CxMemFile file(buffer,size);
1004 return CheckFormat(&file,imagetype);
1006 ////////////////////////////////////////////////////////////////////////////////
1007 #endif //CXIMAGE_SUPPORT_DECODE
1008 ////////////////////////////////////////////////////////////////////////////////