WICImageLoader-winrt.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /****************************************************************************
  2. Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
  3. The MIT License (MIT)
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. Based upon code from the DirectX Tool Kit by Microsoft Corporation,
  20. obtained from https://directxtk.codeplex.com
  21. ****************************************************************************/
  22. #ifndef __WIC_IMAGE_LOADER_H__
  23. #define __WIC_IMAGE_LOADER_H__
  24. #include "base/ccConfig.h"
  25. #if CC_USE_WIC
  26. #include <memory>
  27. #include <string>
  28. #include <wincodec.h>
  29. #include "platform/CCPlatformMacros.h"
  30. NS_CC_BEGIN
  31. typedef const unsigned char* ImageBlob;
  32. struct WICConvert
  33. {
  34. WICPixelFormatGUID source;
  35. WICPixelFormatGUID target;
  36. };
  37. class CC_DLL WICImageLoader
  38. {
  39. public:
  40. WICImageLoader();
  41. ~WICImageLoader();
  42. int getWidth();
  43. int getHeight();
  44. size_t getImageDataSize();
  45. WICPixelFormatGUID getPixelFormat();
  46. size_t getImageData(ImageBlob rawData, size_t dataLen);
  47. bool decodeImageData(ImageBlob data, size_t dataLen);
  48. bool encodeImageData(std::string path, const unsigned char* data, size_t dataLen, WICPixelFormatGUID pixelFormat, int width, int height, GUID containerFormat);
  49. protected:
  50. bool processImage(IWICBitmapDecoder* decoder);
  51. size_t getBitsPerPixel(WICPixelFormatGUID format);
  52. HRESULT convertFormatIfRequired(IWICBitmapFrameDecode* pFrame, IWICFormatConverter** ppConv);
  53. static IWICImagingFactory* getWICFactory();
  54. private:
  55. int _height;
  56. int _width;
  57. size_t _dataLen;
  58. size_t _bpp;
  59. WICPixelFormatGUID _format;
  60. BYTE* _data;
  61. static IWICImagingFactory* _wicFactory;
  62. };
  63. template<typename T>
  64. void SafeRelease(T **ppObj)
  65. {
  66. if(*ppObj != NULL)
  67. {
  68. (*ppObj)->Release();
  69. *ppObj = NULL;
  70. }
  71. }
  72. NS_CC_END
  73. #endif
  74. #endif // #ifndef __WIC_IMAGE_LOADER_H__