summaryrefslogtreecommitdiff
path: root/thirdparty/msdfgen/core/BitmapRef.hpp
blob: 6f9620dcdfd7364bf8e1be0b84654e68c17ca09e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#pragma once

#include <cstdlib>

namespace msdfgen {

typedef unsigned char byte;

/// 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) { }

    inline T * operator()(int x, int y) const {
        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) { }

    inline const T * operator()(int x, int y) const {
        return pixels+N*(width*y+x);
    }

};

}