BitmapRef.hpp 1.1 KB

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