BitmapRef.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <cstdlib>
  3. namespace msdfgen {
  4. typedef unsigned char byte;
  5. /// Reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object.
  6. template <typename T, int N = 1>
  7. struct BitmapRef {
  8. T *pixels;
  9. int width, height;
  10. inline BitmapRef() : pixels(NULL), width(0), height(0) { }
  11. inline BitmapRef(T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { }
  12. inline T * operator()(int x, int y) const {
  13. return pixels+N*(width*y+x);
  14. }
  15. };
  16. /// Constant reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object.
  17. template <typename T, int N = 1>
  18. struct BitmapConstRef {
  19. const T *pixels;
  20. int width, height;
  21. inline BitmapConstRef() : pixels(NULL), width(0), height(0) { }
  22. inline BitmapConstRef(const T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { }
  23. inline BitmapConstRef(const BitmapRef<T, N> &orig) : pixels(orig.pixels), width(orig.width), height(orig.height) { }
  24. inline const T * operator()(int x, int y) const {
  25. return pixels+N*(width*y+x);
  26. }
  27. };
  28. }