Interface_ImageHandleFactory.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) =USTC= Fu Li
  3. *
  4. * Author : Fu Li
  5. * Create : 2005-6-21
  6. * Home : http://www.crazy-bit.com/
  7. * Mail : crazybit@263.net
  8. * History :
  9. */
  10. #ifndef __FOO_INTERFACE_IMAGEHANDLE_FACTORY__2005_06_21__H__
  11. #define __FOO_INTERFACE_IMAGEHANDLE_FACTORY__2005_06_21__H__
  12. class FCImageHandleBase ; // external class
  13. //=============================================================================
  14. /**
  15. * Interface of image handle's factory.
  16. * Used by FCObjImage::SetImageHandleFactory.
  17. */
  18. class FCImageHandleFactory
  19. {
  20. public:
  21. /**
  22. * Get image's format by file's ext name.
  23. * you can override this function to judge format by content of file.
  24. */
  25. virtual IMAGE_TYPE QueryImageFileType (const char* szFileName)
  26. {
  27. if (!szFileName)
  28. {assert(false); return IMG_UNKNOW;}
  29. std::string strExt (FCOXOHelper::GetFileExt(szFileName)) ;
  30. PCL_array<char> szConvert (new char[strExt.length() + 8]) ;
  31. memset (szConvert.get(), 0, strExt.length() + 8) ;
  32. memcpy (szConvert.get(), strExt.c_str(), strExt.length()) ;
  33. // convert to lowercase
  34. for (size_t i=0 ; i < strExt.length() ; i++)
  35. szConvert[i] = tolower(szConvert[i]) ;
  36. PCL_TT_Convertor<IMAGE_TYPE, std::string> aTab ;
  37. aTab.AddElement (IMG_JPG, "jpg") ;
  38. aTab.AddElement (IMG_JPG, "jpeg") ;
  39. aTab.AddElement (IMG_GIF, "gif") ;
  40. aTab.AddElement (IMG_PNG, "png") ;
  41. aTab.AddElement (IMG_BMP, "bmp") ;
  42. aTab.AddElement (IMG_PCX, "pcx") ;
  43. aTab.AddElement (IMG_TIF, "tif") ;
  44. aTab.AddElement (IMG_TIF, "tiff") ;
  45. aTab.AddElement (IMG_TGA, "tga") ;
  46. aTab.AddElement (IMG_ICO, "ico") ;
  47. aTab.AddElement (IMG_PSD, "psd") ;
  48. aTab.AddElement (IMG_XPM, "xpm") ;
  49. aTab.AddElement (IMG_PHOXO, "oxo") ;
  50. return aTab.Second_to_First (szConvert.get(), IMG_UNKNOW) ;
  51. }
  52. /**
  53. * Create image handle by image type.
  54. * Derived class must use <B>new</B> to create handle and return it, user must use <B>delete</B> to delete returned handler.
  55. * @return you are high recommended to use std::auto_ptr wrap returned pointer.
  56. @code
  57. IMAGE_TYPE imgType = FCObjImage::GetImageHandleFactory()->QueryImageFileType(szFileName) ;
  58. std::auto_ptr<FCImageHandleBase> pHandler (FCObjImage::GetImageHandleFactory()->CreateImageHandle(imgType)) ;
  59. @endcode
  60. */
  61. virtual FCImageHandleBase* CreateImageHandle (IMAGE_TYPE imgType) =0 ;
  62. virtual ~FCImageHandleFactory() {}
  63. };
  64. #endif