2020-12-27 13:30:33 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-03-12 08:26:55 +00:00
|
|
|
#include "base.h"
|
2020-12-27 13:30:33 +00:00
|
|
|
|
|
|
|
namespace msdfgen {
|
|
|
|
|
|
|
|
/// Reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object.
|
|
|
|
template <typename T, int N = 1>
|
|
|
|
struct BitmapRef {
|
|
|
|
|
|
|
|
T *pixels;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
inline BitmapRef() : pixels(NULL), width(0), height(0) { }
|
|
|
|
inline BitmapRef(T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { }
|
|
|
|
|
2024-03-12 08:26:55 +00:00
|
|
|
inline T *operator()(int x, int y) const {
|
2020-12-27 13:30:33 +00:00
|
|
|
return pixels+N*(width*y+x);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Constant reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object.
|
|
|
|
template <typename T, int N = 1>
|
|
|
|
struct BitmapConstRef {
|
|
|
|
|
|
|
|
const T *pixels;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
inline BitmapConstRef() : pixels(NULL), width(0), height(0) { }
|
|
|
|
inline BitmapConstRef(const T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { }
|
|
|
|
inline BitmapConstRef(const BitmapRef<T, N> &orig) : pixels(orig.pixels), width(orig.width), height(orig.height) { }
|
|
|
|
|
2024-03-12 08:26:55 +00:00
|
|
|
inline const T *operator()(int x, int y) const {
|
2020-12-27 13:30:33 +00:00
|
|
|
return pixels+N*(width*y+x);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|