JpegImage.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef JPEGIMAGE_H
  2. #define JPEGIMAGE_H
  3. #include <string>
  4. #include <vector>
  5. #include <jpeglib.h>
  6. namespace Image {
  7. class JpegImage
  8. {
  9. public:
  10. JpegImage();
  11. void SetImageData(const std::string& data);
  12. unsigned int Width() const;
  13. unsigned int Height() const;
  14. unsigned int StrideX() const;
  15. unsigned int StrideY() const;
  16. const std::vector<char>& Data() const;
  17. private:
  18. struct SourceMgr
  19. {
  20. struct jpeg_source_mgr pub;
  21. const JOCTET *data;
  22. size_t len;
  23. };
  24. typedef SourceMgr* SourceMgrPtr;
  25. private:
  26. static void InitSource(j_decompress_ptr pCinfo);
  27. static boolean FillInputBuffer(j_decompress_ptr pCinfo);
  28. static void SkipInputData(j_decompress_ptr pCinfo, long numBytes);
  29. static void TermSource(j_decompress_ptr pCinfo);
  30. void SetSourceMgr(j_decompress_ptr pCinfo, const char* pData, size_t len) const;
  31. void DecompressImage(const char* pData, size_t len);
  32. private:
  33. unsigned int m_width;
  34. unsigned int m_height;
  35. unsigned int m_strideX;
  36. unsigned int m_strideY;
  37. std::vector<char> m_data;
  38. };
  39. } // namespace Image
  40. #endif // JPEGIMAGE_H