JpegImage.h 1.1 KB

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