Path: blob/master/thirdparty/msdfgen/core/Bitmap.hpp
10279 views
1#include "Bitmap.h"23#include <cstdlib>4#include <cstring>56namespace msdfgen {78template <typename T, int N>9Bitmap<T, N>::Bitmap() : pixels(NULL), w(0), h(0) { }1011template <typename T, int N>12Bitmap<T, N>::Bitmap(int width, int height) : w(width), h(height) {13pixels = new T[N*w*h];14}1516template <typename T, int N>17Bitmap<T, N>::Bitmap(const BitmapConstRef<T, N> &orig) : w(orig.width), h(orig.height) {18pixels = new T[N*w*h];19memcpy(pixels, orig.pixels, sizeof(T)*N*w*h);20}2122template <typename T, int N>23Bitmap<T, N>::Bitmap(const Bitmap<T, N> &orig) : w(orig.w), h(orig.h) {24pixels = new T[N*w*h];25memcpy(pixels, orig.pixels, sizeof(T)*N*w*h);26}2728#ifdef MSDFGEN_USE_CPP1129template <typename T, int N>30Bitmap<T, N>::Bitmap(Bitmap<T, N> &&orig) : pixels(orig.pixels), w(orig.w), h(orig.h) {31orig.pixels = NULL;32orig.w = 0, orig.h = 0;33}34#endif3536template <typename T, int N>37Bitmap<T, N>::~Bitmap() {38delete [] pixels;39}4041template <typename T, int N>42Bitmap<T, N> &Bitmap<T, N>::operator=(const BitmapConstRef<T, N> &orig) {43if (pixels != orig.pixels) {44delete [] pixels;45w = orig.width, h = orig.height;46pixels = new T[N*w*h];47memcpy(pixels, orig.pixels, sizeof(T)*N*w*h);48}49return *this;50}5152template <typename T, int N>53Bitmap<T, N> &Bitmap<T, N>::operator=(const Bitmap<T, N> &orig) {54if (this != &orig) {55delete [] pixels;56w = orig.w, h = orig.h;57pixels = new T[N*w*h];58memcpy(pixels, orig.pixels, sizeof(T)*N*w*h);59}60return *this;61}6263#ifdef MSDFGEN_USE_CPP1164template <typename T, int N>65Bitmap<T, N> &Bitmap<T, N>::operator=(Bitmap<T, N> &&orig) {66if (this != &orig) {67delete [] pixels;68pixels = orig.pixels;69w = orig.w, h = orig.h;70orig.pixels = NULL;71}72return *this;73}74#endif7576template <typename T, int N>77int Bitmap<T, N>::width() const {78return w;79}8081template <typename T, int N>82int Bitmap<T, N>::height() const {83return h;84}8586template <typename T, int N>87T *Bitmap<T, N>::operator()(int x, int y) {88return pixels+N*(w*y+x);89}9091template <typename T, int N>92const T *Bitmap<T, N>::operator()(int x, int y) const {93return pixels+N*(w*y+x);94}9596template <typename T, int N>97Bitmap<T, N>::operator T *() {98return pixels;99}100101template <typename T, int N>102Bitmap<T, N>::operator const T *() const {103return pixels;104}105106template <typename T, int N>107Bitmap<T, N>::operator BitmapRef<T, N>() {108return BitmapRef<T, N>(pixels, w, h);109}110111template <typename T, int N>112Bitmap<T, N>::operator BitmapConstRef<T, N>() const {113return BitmapConstRef<T, N>(pixels, w, h);114}115116}117118119