BSEImg.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "afx.h"
  3. #include "XMLSerialization.h"
  4. namespace OTSDATA {
  5. // CBSEImage command target
  6. class __declspec(dllexport) CBSEImg : public CObject
  7. {
  8. protected:
  9. DECLARE_SERIAL(CBSEImg)
  10. public:
  11. CBSEImg(CRect); // constructor
  12. CBSEImg(const CBSEImg&); // copy constructor
  13. CBSEImg(CBSEImg*); // copy constructor
  14. CBSEImg& operator=(const CBSEImg&); // =operator
  15. virtual ~CBSEImg(); // destructor
  16. // sterilizations
  17. void Serialize(CArchive& ar);
  18. //virtual void Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode);
  19. // image rectangle
  20. CRect GetImageRect() const { return m_rectImage; }
  21. void SetImageRect(const CRect& a_rectImage);
  22. int GetWidth() { return m_rectImage.Width(); }
  23. int GetHeight() { return m_rectImage.Height(); }
  24. // how to use this value??
  25. CSize GetImageSize() const { return m_rectImage.Size(); }
  26. // image data
  27. void InitImageData(int imgwidth, int imgheight);
  28. BYTE* GetImageDataPointer() const { return m_pnImageData; }
  29. void SetImageData(BYTE* a_pnImageData,int imgwidth,int imgheight);
  30. // BSE chart
  31. // NOTE: to use chart data, call SetChartData method first!
  32. void SetChartData();
  33. WORD* GetBSEChart() { return m_nBSEChart; }
  34. long CalBSEChartHigh();
  35. long CalBSEChartLow();
  36. // cal BSE value by position
  37. int GetBSEValue(const CPoint& a_position);
  38. int GetBSEValue(const int a_nX, const int a_nY);
  39. void SetBSEValue(const int a_nX, const int a_nY, int value);
  40. int GetValueDirect(const CPoint& a_position) const;
  41. inline int GetValueDirectF(int inX, int inY) const
  42. {
  43. return ((inX >= 0) && (inX < m_rectImage.Width()) && (inY >= 0) && (inY < m_rectImage.Height()))
  44. ? m_pnImageData[inY * m_rectImage.Width() + inX]
  45. : 0;
  46. }
  47. bool DoesContainPixelValue(int inValue, int a_nPixel = 1) const;
  48. // cal area
  49. DWORD CalArea();
  50. protected:
  51. CBSEImg();
  52. // image rectangle
  53. CRect m_rectImage;
  54. // image data
  55. BYTE* m_pnImageData;
  56. // BSE chart
  57. WORD m_nBSEChart[MAXBYTE];
  58. void InitChartData();
  59. // cleanup
  60. void Cleanup();
  61. // Initialization
  62. void Init();
  63. // duplication
  64. void Duplicate(const CBSEImg& a_oSource);
  65. };
  66. typedef std::shared_ptr<CBSEImg> __declspec(dllexport) CBSEImgPtr;
  67. typedef std::vector<CBSEImgPtr> __declspec(dllexport) CBSEImgPtrVec;
  68. }