Bitmap.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include "YAxisOrientation.h"
  3. #include "BitmapRef.hpp"
  4. namespace msdfgen {
  5. /// A 2D image bitmap with N channels of type T. Pixel memory is managed by the class.
  6. template <typename T, int N = 1>
  7. class Bitmap {
  8. public:
  9. Bitmap();
  10. Bitmap(int width, int height, YAxisOrientation yOrientation = MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION);
  11. explicit Bitmap(const BitmapConstRef<T, N> &orig);
  12. explicit Bitmap(const BitmapConstSection<T, N> &orig);
  13. Bitmap(const Bitmap<T, N> &orig);
  14. #ifdef MSDFGEN_USE_CPP11
  15. Bitmap(Bitmap<T, N> &&orig);
  16. #endif
  17. ~Bitmap();
  18. Bitmap<T, N> &operator=(const BitmapConstRef<T, N> &orig);
  19. Bitmap<T, N> &operator=(const BitmapConstSection<T, N> &orig);
  20. Bitmap<T, N> &operator=(const Bitmap<T, N> &orig);
  21. #ifdef MSDFGEN_USE_CPP11
  22. Bitmap<T, N> &operator=(Bitmap<T, N> &&orig);
  23. #endif
  24. /// Bitmap width in pixels.
  25. int width() const;
  26. /// Bitmap height in pixels.
  27. int height() const;
  28. T *operator()(int x, int y);
  29. const T *operator()(int x, int y) const;
  30. #ifdef MSDFGEN_USE_CPP11
  31. explicit operator T *();
  32. explicit operator const T *() const;
  33. #else
  34. operator T *();
  35. operator const T *() const;
  36. #endif
  37. operator BitmapRef<T, N>();
  38. operator BitmapConstRef<T, N>() const;
  39. operator BitmapSection<T, N>();
  40. operator BitmapConstSection<T, N>() const;
  41. /// Returns a reference to a rectangular section of the bitmap specified by bounds (excluding xMax, yMax).
  42. BitmapSection<T, N> getSection(int xMin, int yMin, int xMax, int yMax);
  43. /// Returns a constant reference to a rectangular section of the bitmap specified by bounds (excluding xMax, yMax).
  44. BitmapConstSection<T, N> getConstSection(int xMin, int yMin, int xMax, int yMax) const;
  45. private:
  46. T *pixels;
  47. int w, h;
  48. YAxisOrientation yOrientation;
  49. };
  50. }
  51. #include "Bitmap.hpp"