Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include "../../../../Arbeit/Repository/Programming/trunk/edu/rtcv/algorithms/tools/FunctionTimer.h"
  4. #include <iterator>
  5.  
  6.  
  7. class Image
  8. {
  9. public:
  10. Image() : m_width(0), m_height(0), mp_data(nullptr) {}
  11.  
  12. ~Image() { delete[] mp_data; }
  13.  
  14. Image(const Image& rhs)
  15. {
  16. m_width = rhs.m_width;
  17. m_height = rhs.m_height;
  18. mp_data = new unsigned char[m_width*m_height];
  19. std::copy(rhs.mp_data, rhs.mp_data + m_width * m_height, mp_data);
  20. //memcpy(mp_data, rhs.mp_data, m_width*m_height * sizeof(unsigned char));
  21. }
  22.  
  23. Image& operator=(const Image& rhs)
  24. {
  25. m_width = rhs.m_width;
  26. m_height = rhs.m_height;
  27. delete[] mp_data;
  28. mp_data = new unsigned char[m_width*m_height];
  29.  
  30. memcpy(mp_data, rhs.mp_data, m_width*m_height * sizeof(unsigned char));
  31. return *this;
  32. }
  33.  
  34. void resize(unsigned int width, unsigned int height)
  35. {
  36. m_width = width;
  37. m_height = height;
  38. delete[] mp_data;
  39. mp_data = new unsigned char[m_width * m_height];
  40. }
  41.  
  42. void release()
  43. {
  44. delete[] mp_data;
  45. mp_data = nullptr;
  46. m_width = m_height = 0;
  47. }
  48.  
  49. private:
  50. unsigned int m_width;
  51. unsigned int m_height;
  52. unsigned char * mp_data;
  53. };
  54.  
  55.  
  56. void main()
  57. {
  58. Image ref;
  59. ref.resize(1024, 1024);
  60.  
  61. for(int j = 0; j < 10; ++j)
  62. {
  63. int numIter = 5000;
  64. double et = 0;
  65. {
  66. BlockTimer t(et);
  67.  
  68. for (int i = 0; i < numIter; ++i)
  69. {
  70. Image img(ref);
  71. }
  72. }
  73.  
  74. std::cout << et << std::endl;
  75. }
  76.  
  77. system("PAUSE");
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement