Bitmap.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "Bitmap.h"
  2. #include <cstring>
  3. namespace msdfgen {
  4. template <typename T>
  5. Bitmap<T>::Bitmap() : content(NULL), w(0), h(0) { }
  6. template <typename T>
  7. Bitmap<T>::Bitmap(int width, int height) : w(width), h(height) {
  8. content = new T[w*h];
  9. }
  10. template <typename T>
  11. Bitmap<T>::Bitmap(const Bitmap<T> &orig) : w(orig.w), h(orig.h) {
  12. content = new T[w*h];
  13. memcpy(content, orig.content, w*h*sizeof(T));
  14. }
  15. #ifdef MSDFGEN_USE_CPP11
  16. template <typename T>
  17. Bitmap<T>::Bitmap(Bitmap<T> &&orig) : content(orig.content), w(orig.w), h(orig.h) {
  18. orig.content = NULL;
  19. }
  20. #endif
  21. template <typename T>
  22. Bitmap<T>::~Bitmap() {
  23. delete [] content;
  24. }
  25. template <typename T>
  26. Bitmap<T> & Bitmap<T>::operator=(const Bitmap<T> &orig) {
  27. delete [] content;
  28. w = orig.w, h = orig.h;
  29. content = new T[w*h];
  30. memcpy(content, orig.content, w*h*sizeof(T));
  31. return *this;
  32. }
  33. #ifdef MSDFGEN_USE_CPP11
  34. template <typename T>
  35. Bitmap<T> & Bitmap<T>::operator=(Bitmap<T> &&orig) {
  36. delete [] content;
  37. content = orig.content;
  38. w = orig.w, h = orig.h;
  39. orig.content = NULL;
  40. return *this;
  41. }
  42. #endif
  43. template <typename T>
  44. int Bitmap<T>::width() const {
  45. return w;
  46. }
  47. template <typename T>
  48. int Bitmap<T>::height() const {
  49. return h;
  50. }
  51. template <typename T>
  52. T & Bitmap<T>::operator()(int x, int y) {
  53. return content[y*w+x];
  54. }
  55. template <typename T>
  56. const T & Bitmap<T>::operator()(int x, int y) const {
  57. return content[y*w+x];
  58. }
  59. template class Bitmap<float>;
  60. template class Bitmap<FloatRGB>;
  61. }