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