/** * Saves to disk or memory pagecount images, referenced by an array of CxImage pointers. * \param hFile: file handle (CxMemFile or CxIOFile), with write access. * \param pImages: array of CxImage pointers. * \param pagecount: number of images. * \param imagetype: can be CXIMAGE_FORMAT_TIF, CXIMAGE_FORMAT_GIF or CXIMAGE_FORMAT_ICO. * \return true if everything is ok */ bool CxImage::Encode(CxFile * hFile, CxImage ** pImages, int32_t pagecount, uint32_t imagetype) { #if CXIMAGE_SUPPORT_TIF if (imagetype==CXIMAGE_FORMAT_TIF){ CxImageTIF newima; newima.Ghost(this); if (newima.Encode(hFile,pImages,pagecount)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_GIF if (imagetype==CXIMAGE_FORMAT_GIF){ CxImageGIF newima; newima.Ghost(this); if (newima.Encode(hFile,pImages,pagecount)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_ICO if (imagetype==CXIMAGE_FORMAT_ICO){ CxImageICO newima; newima.Ghost(this); if (newima.Encode(hFile,pImages,pagecount)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif strcpy(info.szLastError,"Multipage Encode, Unsupported operation for this format"); return false; }
/** * Loads an image from CxFile object * \param hFile: file handle (CxMemFile or CxIOFile), with read access. * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS * \return true if everything is ok * \sa ENUM_CXIMAGE_FORMATS */ bool CxImage::Decode(CxFile *hFile, uint32_t imagetype) { if (hFile == NULL){ strcpy(info.szLastError,CXIMAGE_ERR_NOFILE); return false; } uint32_t pos = hFile->Tell(); #if CXIMAGE_SUPPORT_BMP if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_BMP==imagetype){ CxImageBMP *newima = new CxImageBMP; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_JPG if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_JPG==imagetype){ CxImageJPG *newima = new CxImageJPG; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_ICO if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_ICO==imagetype){ CxImageICO *newima = new CxImageICO; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { info.nNumFrames = newima->info.nNumFrames; strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_GIF if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_GIF==imagetype){ CxImageGIF *newima = new CxImageGIF; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { info.nNumFrames = newima->info.nNumFrames; strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_PNG if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_PNG==imagetype){ CxImagePNG *newima = new CxImagePNG; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_TIF if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_TIF==imagetype){ CxImageTIF *newima = new CxImageTIF; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { info.nNumFrames = newima->info.nNumFrames; strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_MNG if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_MNG==imagetype){ CxImageMNG *newima = new CxImageMNG; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { info.nNumFrames = newima->info.nNumFrames; strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_TGA if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_TGA==imagetype){ CxImageTGA *newima = new CxImageTGA; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_PCX if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_PCX==imagetype){ CxImagePCX *newima = new CxImagePCX; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_WBMP if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_WBMP==imagetype){ CxImageWBMP *newima = new CxImageWBMP; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_WMF==imagetype){ CxImageWMF *newima = new CxImageWMF; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_JBG if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_JBG==imagetype){ CxImageJBG *newima = new CxImageJBG; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_JASPER if (CXIMAGE_FORMAT_UNKNOWN==imagetype || #if CXIMAGE_SUPPORT_JP2 CXIMAGE_FORMAT_JP2==imagetype || #endif #if CXIMAGE_SUPPORT_JPC CXIMAGE_FORMAT_JPC==imagetype || #endif #if CXIMAGE_SUPPORT_PGX CXIMAGE_FORMAT_PGX==imagetype || #endif #if CXIMAGE_SUPPORT_PNM CXIMAGE_FORMAT_PNM==imagetype || #endif #if CXIMAGE_SUPPORT_RAS CXIMAGE_FORMAT_RAS==imagetype || #endif false ){ CxImageJAS *newima = new CxImageJAS; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_SKA if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_SKA==imagetype){ CxImageSKA *newima = new CxImageSKA; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_RAW if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_RAW==imagetype){ CxImageRAW *newima = new CxImageRAW; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif #if CXIMAGE_SUPPORT_PSD if (CXIMAGE_FORMAT_UNKNOWN==imagetype || CXIMAGE_FORMAT_PSD==imagetype){ CxImagePSD *newima = new CxImagePSD; if (!newima) return false; newima->CopyInfo(*this); if (newima->Decode(hFile)) { Transfer(*newima); delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); hFile->Seek(pos,SEEK_SET); delete newima; if (CXIMAGE_FORMAT_UNKNOWN!=imagetype) return false; } } #endif strcpy(info.szLastError,"Decode: Unknown or wrong format"); return false; }
/** * Saves to disk the image in a specific format. * \param hFile: file handle (CxMemFile or CxIOFile), with write access. * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS * \return true if everything is ok * \sa ENUM_CXIMAGE_FORMATS */ bool CxImage::Encode(CxFile *hFile, uint32_t imagetype) { #if CXIMAGE_SUPPORT_BMP if (CXIMAGE_FORMAT_BMP==imagetype){ CxImageBMP *newima = new CxImageBMP; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_ICO if (CXIMAGE_FORMAT_ICO==imagetype){ CxImageICO *newima = new CxImageICO; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_TIF if (CXIMAGE_FORMAT_TIF==imagetype){ CxImageTIF *newima = new CxImageTIF; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_JPG if (CXIMAGE_FORMAT_JPG==imagetype){ CxImageJPG *newima = new CxImageJPG; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_GIF if (CXIMAGE_FORMAT_GIF==imagetype){ CxImageGIF *newima = new CxImageGIF; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_PNG if (CXIMAGE_FORMAT_PNG==imagetype){ CxImagePNG *newima = new CxImagePNG; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_MNG if (CXIMAGE_FORMAT_MNG==imagetype){ CxImageMNG *newima = new CxImageMNG; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_TGA if (CXIMAGE_FORMAT_TGA==imagetype){ CxImageTGA *newima = new CxImageTGA; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_PCX if (CXIMAGE_FORMAT_PCX==imagetype){ CxImagePCX *newima = new CxImagePCX; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_WBMP if (CXIMAGE_FORMAT_WBMP==imagetype){ CxImageWBMP *newima = new CxImageWBMP; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // <vho> - WMF/EMF support if (CXIMAGE_FORMAT_WMF==imagetype){ CxImageWMF *newima = new CxImageWMF; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_JBG if (CXIMAGE_FORMAT_JBG==imagetype){ CxImageJBG *newima = new CxImageJBG; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_JASPER if ( #if CXIMAGE_SUPPORT_JP2 CXIMAGE_FORMAT_JP2==imagetype || #endif #if CXIMAGE_SUPPORT_JPC CXIMAGE_FORMAT_JPC==imagetype || #endif #if CXIMAGE_SUPPORT_PGX CXIMAGE_FORMAT_PGX==imagetype || #endif #if CXIMAGE_SUPPORT_PNM CXIMAGE_FORMAT_PNM==imagetype || #endif #if CXIMAGE_SUPPORT_RAS CXIMAGE_FORMAT_RAS==imagetype || #endif false ){ CxImageJAS *newima = new CxImageJAS; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile,imagetype)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_SKA if (CXIMAGE_FORMAT_SKA==imagetype){ CxImageSKA *newima = new CxImageSKA; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_RAW if (CXIMAGE_FORMAT_RAW==imagetype){ CxImageRAW *newima = new CxImageRAW; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif #if CXIMAGE_SUPPORT_PSD if (CXIMAGE_FORMAT_PSD==imagetype){ CxImagePSD *newima = new CxImagePSD; if (!newima) return false; newima->Ghost(this); if (newima->Encode(hFile)){ delete newima; return true; } else { strcpy(info.szLastError,newima->GetLastError()); delete newima; return false; } } #endif strcpy(info.szLastError,"Encode: Unknown format"); return false; }
bool CxImage::Decode(CxFile *hFile, DWORD imagetype) #endif { if (hFile == NULL){ strcpy(info.szLastError,CXIMAGE_ERR_NOFILE); return false; } if (imagetype==CXIMAGE_FORMAT_UNKNOWN){ DWORD pos = hFile->Tell(); #if CXIMAGE_SUPPORT_JPG #ifdef XBMC { CxImageJPG newima; try { newima.CopyInfo(*this); if (newima.Decode(hFile, iWidth, iHeight)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } catch (...) { hFile->Seek(pos,SEEK_SET); } } #else { CxImageJPG newima; try { newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } catch (...) { hFile->Seek(pos,SEEK_SET); } } #endif #endif #if CXIMAGE_SUPPORT_PNG { CxImagePNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_GIF { CxImageGIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_BMP { CxImageBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_ICO { CxImageICO newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_TIF { CxImageTIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_MNG { CxImageMNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_TGA { CxImageTGA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_PCX { CxImagePCX newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_WBMP { CxImageWBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS { CxImageWMF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_JBG { CxImageJBG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_JASPER { CxImageJAS newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_SKA { CxImageSKA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_RAW { CxImageRAW newima; newima.CopyInfo(*this); // libDCR performs a high volume of seeks/reads which XBMC's // VFS cannot sustain efficiently, therefore read the file into // memory and send it to the decoder. long buffer_size = hFile->Size(); if (buffer_size < 0) return false; unsigned char* buffer = (unsigned char*)malloc( buffer_size ); // if we were able to allocate the buffer, transfer to a CxMemFile if ( buffer ) { hFile->Read( buffer, buffer_size, 1 ); CxMemFile hMemFile( buffer, buffer_size ); if (newima.Decode( &hMemFile )) { Transfer(newima); return true; } else hFile->Seek(pos, SEEK_SET); } else { // fallback to default method if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } } #endif } #if CXIMAGE_SUPPORT_BMP if (imagetype==CXIMAGE_FORMAT_BMP){ CxImageBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JPG if (imagetype==CXIMAGE_FORMAT_JPG){ CxImageJPG newima; newima.CopyInfo(*this); // <ignacio> #ifdef XBMC if (newima.Decode(hFile, iWidth, iHeight)){ #else if (newima.Decode(hFile)){ #endif Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_ICO if (imagetype==CXIMAGE_FORMAT_ICO){ CxImageICO newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { info.nNumFrames = newima.info.nNumFrames; strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_GIF if (imagetype==CXIMAGE_FORMAT_GIF){ CxImageGIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { info.nNumFrames = newima.info.nNumFrames; strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_PNG if (imagetype==CXIMAGE_FORMAT_PNG){ CxImagePNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_TIF if (imagetype==CXIMAGE_FORMAT_TIF){ CxImageTIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { info.nNumFrames = newima.info.nNumFrames; strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_MNG if (imagetype==CXIMAGE_FORMAT_MNG){ CxImageMNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { info.nNumFrames = newima.info.nNumFrames; strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_TGA if (imagetype==CXIMAGE_FORMAT_TGA){ CxImageTGA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_PCX if (imagetype==CXIMAGE_FORMAT_PCX){ CxImagePCX newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_WBMP if (imagetype==CXIMAGE_FORMAT_WBMP){ CxImageWBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // vho - WMF support if (imagetype == CXIMAGE_FORMAT_WMF){ CxImageWMF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JBG if (imagetype==CXIMAGE_FORMAT_JBG){ CxImageJBG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JASPER if ( #if CXIMAGE_SUPPORT_JP2 imagetype==CXIMAGE_FORMAT_JP2 || #endif #if CXIMAGE_SUPPORT_JPC imagetype==CXIMAGE_FORMAT_JPC || #endif #if CXIMAGE_SUPPORT_PGX imagetype==CXIMAGE_FORMAT_PGX || #endif #if CXIMAGE_SUPPORT_PNM imagetype==CXIMAGE_FORMAT_PNM || #endif #if CXIMAGE_SUPPORT_RAS imagetype==CXIMAGE_FORMAT_RAS || #endif false ){ CxImageJAS newima; newima.CopyInfo(*this); if (newima.Decode(hFile,imagetype)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_SKA if (imagetype==CXIMAGE_FORMAT_SKA){ CxImageSKA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_RAW if (imagetype==CXIMAGE_FORMAT_RAW) { CxImageRAW newima; newima.CopyInfo(*this); // libDCR performs a high volume of seeks/reads which XBMC's // VFS cannot sustain efficiently, therefore read the file into // memory and send it to the decoder. long buffer_size = hFile->Size(); unsigned char* buffer = (unsigned char*)malloc( buffer_size ); // if we were able to allocate the buffer, transfer to a CxMemFile if ( buffer ) { hFile->Read( buffer, buffer_size, 1 ); CxMemFile hMemFile( buffer, buffer_size ); if (newima.Decode( &hMemFile )) { Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } else { // fallback to default method if (newima.Decode(hFile)) { Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } } #endif strcpy(info.szLastError,"Decode: Unknown or wrong format"); return false; } //////////////////////////////////////////////////////////////////////////////// /** * Loads an image from CxFile object * \param hFile: file handle (CxMemFile or CxIOFile), with read access. * \param imagetype: file format, default = 0 (CXIMAGE_FORMAT_UNKNOWN) * \return : if imagetype is not 0, the function returns true when imagetype * matches the file image format. If imagetype is 0, the function returns true * when the file image format is recognized as a supported format. * If the returned value is true, use GetHeight(), GetWidth() or GetType() * to retrieve the basic image information. * \sa ENUM_CXIMAGE_FORMATS */ bool CxImage::CheckFormat(CxFile * hFile, DWORD imagetype) { SetType(CXIMAGE_FORMAT_UNKNOWN); SetEscape(-1); if (!Decode(hFile,imagetype)) return false; if (GetType() == CXIMAGE_FORMAT_UNKNOWN || GetType() != imagetype) return false; return true; }
/** * Saves to disk the image in a specific format. * \param hFile: file handle (CxMemFile or CxIOFile), with write access. * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS * \return true if everything is ok * \sa ENUM_CXIMAGE_FORMATS */ bool CxImage::Encode(CxFile *hFile, DWORD imagetype) { #if CXIMAGE_SUPPORT_BMP if (imagetype==CXIMAGE_FORMAT_BMP){ CxImageBMP newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_ICO if (imagetype==CXIMAGE_FORMAT_ICO){ CxImageICO newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_TIF if (imagetype==CXIMAGE_FORMAT_TIF){ CxImageTIF newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JPG if (imagetype==CXIMAGE_FORMAT_JPG){ CxImageJPG newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_GIF if (imagetype==CXIMAGE_FORMAT_GIF){ CxImageGIF newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_PNG if (imagetype==CXIMAGE_FORMAT_PNG){ CxImagePNG newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_MNG if (imagetype==CXIMAGE_FORMAT_MNG){ CxImageMNG newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_TGA if (imagetype==CXIMAGE_FORMAT_TGA){ CxImageTGA newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_PCX if (imagetype==CXIMAGE_FORMAT_PCX){ CxImagePCX newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_WBMP if (imagetype==CXIMAGE_FORMAT_WBMP){ CxImageWBMP newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // <vho> - WMF/EMF support if (imagetype==CXIMAGE_FORMAT_WMF){ CxImageWMF newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JBG if (imagetype==CXIMAGE_FORMAT_JBG){ CxImageJBG newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JASPER if ( #if CXIMAGE_SUPPORT_JP2 imagetype==CXIMAGE_FORMAT_JP2 || #endif #if CXIMAGE_SUPPORT_JPC imagetype==CXIMAGE_FORMAT_JPC || #endif #if CXIMAGE_SUPPORT_PGX imagetype==CXIMAGE_FORMAT_PGX || #endif #if CXIMAGE_SUPPORT_PNM imagetype==CXIMAGE_FORMAT_PNM || #endif #if CXIMAGE_SUPPORT_RAS imagetype==CXIMAGE_FORMAT_RAS || #endif false ){ CxImageJAS newima; newima.Ghost(this); if (newima.Encode(hFile,imagetype)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_SKA if (imagetype==CXIMAGE_FORMAT_SKA){ CxImageSKA newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_RAW if (imagetype==CXIMAGE_FORMAT_RAW){ CxImageRAW newima; newima.Ghost(this); if (newima.Encode(hFile)){ return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif strcpy(info.szLastError,"Encode: Unknown format"); return false; }
/** * Loads an image from CxFile object * \param hFile: file handle (CxMemFile or CxIOFile), with read access. * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS * \return true if everything is ok * \sa ENUM_CXIMAGE_FORMATS */ bool CxImage::Decode(CxFile *hFile, DWORD imagetype) { if (hFile == NULL){ strcpy(info.szLastError,CXIMAGE_ERR_NOFILE); return false; } if (imagetype==CXIMAGE_FORMAT_UNKNOWN){ DWORD pos = hFile->Tell(); #if CXIMAGE_SUPPORT_BMP { CxImageBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_PNG { CxImagePNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_JPG { CxImageJPG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_MNG { CxImageMNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_TGA { CxImageTGA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_ICO { CxImageICO newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_GIF { CxImageGIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_TIF { CxImageTIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_PCX { CxImagePCX newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_WBMP { CxImageWBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS { CxImageWMF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_JBG { CxImageJBG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_JASPER { CxImageJAS newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_SKA { CxImageSKA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif #if CXIMAGE_SUPPORT_RAW { CxImageRAW newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } #endif } #if CXIMAGE_SUPPORT_BMP if (imagetype==CXIMAGE_FORMAT_BMP){ CxImageBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_PNG if (imagetype==CXIMAGE_FORMAT_PNG){ CxImagePNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JPG if (imagetype==CXIMAGE_FORMAT_JPG){ CxImageJPG newima; newima.CopyInfo(*this); // <ignacio> if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_MNG if (imagetype==CXIMAGE_FORMAT_MNG){ CxImageMNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { info.nNumFrames = newima.info.nNumFrames; strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_TGA if (imagetype==CXIMAGE_FORMAT_TGA){ CxImageTGA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_ICO if (imagetype==CXIMAGE_FORMAT_ICO){ CxImageICO newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { info.nNumFrames = newima.info.nNumFrames; strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_GIF if (imagetype==CXIMAGE_FORMAT_GIF){ CxImageGIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { info.nNumFrames = newima.info.nNumFrames; strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_TIF if (imagetype==CXIMAGE_FORMAT_TIF){ CxImageTIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { info.nNumFrames = newima.info.nNumFrames; strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_PCX if (imagetype==CXIMAGE_FORMAT_PCX){ CxImagePCX newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_WBMP if (imagetype==CXIMAGE_FORMAT_WBMP){ CxImageWBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // vho - WMF support if (imagetype == CXIMAGE_FORMAT_WMF){ CxImageWMF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JBG if (imagetype==CXIMAGE_FORMAT_JBG){ CxImageJBG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_JASPER if ( #if CXIMAGE_SUPPORT_JP2 imagetype==CXIMAGE_FORMAT_JP2 || #endif #if CXIMAGE_SUPPORT_JPC imagetype==CXIMAGE_FORMAT_JPC || #endif #if CXIMAGE_SUPPORT_PGX imagetype==CXIMAGE_FORMAT_PGX || #endif #if CXIMAGE_SUPPORT_PNM imagetype==CXIMAGE_FORMAT_PNM || #endif #if CXIMAGE_SUPPORT_RAS imagetype==CXIMAGE_FORMAT_RAS || #endif false ){ CxImageJAS newima; newima.CopyInfo(*this); if (newima.Decode(hFile,imagetype)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_SKA if (imagetype==CXIMAGE_FORMAT_SKA){ CxImageSKA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif #if CXIMAGE_SUPPORT_RAW if (imagetype==CXIMAGE_FORMAT_RAW){ CxImageRAW newima; newima.CopyInfo(*this); if (newima.Decode(hFile)){ Transfer(newima); return true; } else { strcpy(info.szLastError,newima.GetLastError()); return false; } } #endif strcpy(info.szLastError,"Decode: Unknown or wrong format"); return false; }