Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.1 KiB

  1. #ifndef __1fe1d0e2_d009_4c25_a3bc_d0620c61ed8d__
  2. #define __1fe1d0e2_d009_4c25_a3bc_d0620c61ed8d__
  3. #include <windows.h>
  4. #include "simstr.h"
  5. #include <gdiplus.h>
  6. #include "simarray.h"
  7. //
  8. // We will define this when explicit initialization is implemented correctly
  9. //
  10. #define GDIPLUSHELPER_EXPLICIT_INITIALIZATION
  11. #if defined(GDIPLUSHELPER_EXPLICIT_INITIALIZATION)
  12. #include <gdiplusinit.h>
  13. #endif
  14. class CGdiPlusHelper
  15. {
  16. private:
  17. Gdiplus::ImageCodecInfo *m_pImageEncoderInfo;
  18. UINT m_nImageEncoderCount;
  19. Gdiplus::ImageCodecInfo *m_pImageDecoderInfo;
  20. UINT m_nImageDecoderCount;
  21. #if defined(GDIPLUSHELPER_EXPLICIT_INITIALIZATION)
  22. //
  23. // GDI+ Initialization stuff
  24. //
  25. ULONG_PTR m_pGdiplusToken;
  26. bool m_bGdiplusInitialized;
  27. #endif
  28. private:
  29. CGdiPlusHelper( const CGdiPlusHelper & );
  30. CGdiPlusHelper &operator=( const CGdiPlusHelper & );
  31. public:
  32. CGdiPlusHelper(void);
  33. ~CGdiPlusHelper(void);
  34. protected:
  35. HRESULT Initialize(void);
  36. static HRESULT ConstructCodecExtensionSearchStrings( CSimpleString &strExtensions, Gdiplus::ImageCodecInfo *pImageCodecInfo, UINT nImageCodecCount );
  37. void Destroy(void);
  38. public:
  39. bool IsValid(void) const;
  40. HRESULT ConstructDecoderExtensionSearchStrings( CSimpleString &strExtensions );
  41. HRESULT ConstructEncoderExtensionSearchStrings( CSimpleString &strExtensions );
  42. HRESULT GetClsidOfEncoder( const GUID &guidFormatId, CLSID &clsidFormat ) const;
  43. HRESULT GetClsidOfDecoder( const GUID &guidFormatId, CLSID &clsidFormat ) const;
  44. HRESULT Convert( LPCWSTR pszInputFilename, LPCWSTR pszOutputFilename, const CLSID &guidOutputFormat ) const;
  45. HRESULT LoadAndScale( HBITMAP &hTargetBitmap, LPCTSTR pszFilename, UINT nMaxWidth, UINT nMaxHeight, bool bStretchSmallImages );
  46. HRESULT SaveMultipleImagesAsMultiPage( const CSimpleDynamicArray<CSimpleStringWide> &Filenames, const CSimpleStringWide &strFilename, const CLSID &guidOutputFormat );
  47. static Gdiplus::EncoderParameters *AppendEncoderParameter( Gdiplus::EncoderParameters *pEncoderParameters, const GUID &guidProp, ULONG nType, PVOID pVoid );
  48. static inline GDISTATUS_TO_HRESULT(Gdiplus::Status status) { return (status == Gdiplus::Ok) ? S_OK : E_FAIL; }
  49. };
  50. class CImageFileFormatVerifier
  51. {
  52. private:
  53. //
  54. // Internal class used to store the file signatures
  55. //
  56. class CImageFileFormatVerifierItem
  57. {
  58. private:
  59. PBYTE m_pSignature;
  60. PBYTE m_pMask;
  61. int m_nLength;
  62. GUID m_guidFormat;
  63. CLSID m_clsidDecoder;
  64. public:
  65. //
  66. // Constructors, assignment operator and destructor
  67. //
  68. CImageFileFormatVerifierItem(void);
  69. CImageFileFormatVerifierItem( const PBYTE pSignature, const PBYTE pMask, int nLength, const GUID &guidFormat, const CLSID &guidDecoder );
  70. CImageFileFormatVerifierItem( const CImageFileFormatVerifierItem &other );
  71. CImageFileFormatVerifierItem &operator=( const CImageFileFormatVerifierItem &other );
  72. CImageFileFormatVerifierItem &Assign( const PBYTE pSignature, const PBYTE pMask, int nLength, const GUID &Format, const CLSID &guidDecoder );
  73. ~CImageFileFormatVerifierItem(void);
  74. protected:
  75. void Destroy(void);
  76. public:
  77. //
  78. // Accessor functions
  79. //
  80. PBYTE Signature(void) const;
  81. PBYTE Mask(void) const;
  82. int Length(void) const;
  83. GUID Format(void) const;
  84. CLSID Decoder(void) const;
  85. //
  86. // Does this stream of bytes match this format?
  87. //
  88. bool Match( PBYTE pBytes, int nLen ) const;
  89. };
  90. private:
  91. CSimpleDynamicArray<CImageFileFormatVerifierItem> m_FileFormatVerifierList;
  92. int m_nMaxSignatureLength;
  93. PBYTE m_pSignatureBuffer;
  94. private:
  95. CImageFileFormatVerifier( const CImageFileFormatVerifier & );
  96. CImageFileFormatVerifier &operator=( const CImageFileFormatVerifier & );
  97. public:
  98. CImageFileFormatVerifier(void);
  99. ~CImageFileFormatVerifier(void);
  100. void Destroy(void);
  101. bool IsValid(void) const;
  102. bool IsImageFile( LPCTSTR pszFilename );
  103. GUID GetImageType( LPCTSTR pszFilename );
  104. };
  105. #endif