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