#include "Bitmap.h" #include #include namespace msdfgen { template Bitmap::Bitmap() : pixels(NULL), w(0), h(0), yOrientation(MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) { } template Bitmap::Bitmap(int width, int height, YAxisOrientation yOrientation) : w(width), h(height), yOrientation(yOrientation) { pixels = new T[N*w*h]; } template Bitmap::Bitmap(const BitmapConstRef &orig) : w(orig.width), h(orig.height), yOrientation(orig.yOrientation) { pixels = new T[N*w*h]; memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); } template Bitmap::Bitmap(const BitmapConstSection &orig) : w(orig.width), h(orig.height), yOrientation(orig.yOrientation) { pixels = new T[N*w*h]; T *dst = pixels; const T *src = orig.pixels; int rowLength = N*w; for (int y = 0; y < h; ++y) { memcpy(dst, src, sizeof(T)*rowLength); dst += rowLength; src += orig.rowStride; } } template Bitmap::Bitmap(const Bitmap &orig) : w(orig.w), h(orig.h), yOrientation(orig.yOrientation) { pixels = new T[N*w*h]; memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); } #ifdef MSDFGEN_USE_CPP11 template Bitmap::Bitmap(Bitmap &&orig) : pixels(orig.pixels), w(orig.w), h(orig.h), yOrientation(orig.yOrientation) { orig.pixels = NULL; orig.w = 0, orig.h = 0; } #endif template Bitmap::~Bitmap() { delete[] pixels; } template Bitmap &Bitmap::operator=(const BitmapConstRef &orig) { if (pixels != orig.pixels) { delete[] pixels; w = orig.width, h = orig.height; yOrientation = orig.yOrientation; pixels = new T[N*w*h]; memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); } return *this; } template Bitmap &Bitmap::operator=(const BitmapConstSection &orig) { if (orig.pixels && orig.pixels >= pixels && orig.pixels < pixels+N*w*h) return *this = Bitmap(orig); delete[] pixels; w = orig.width, h = orig.height; yOrientation = orig.yOrientation; pixels = new T[N*w*h]; T *dst = pixels; const T *src = orig.pixels; int rowLength = N*w; for (int y = 0; y < h; ++y) { memcpy(dst, src, sizeof(T)*rowLength); dst += rowLength; src += orig.rowStride; } return *this; } template Bitmap &Bitmap::operator=(const Bitmap &orig) { if (this != &orig) { delete[] pixels; w = orig.w, h = orig.h; yOrientation = orig.yOrientation; pixels = new T[N*w*h]; memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); } return *this; } #ifdef MSDFGEN_USE_CPP11 template Bitmap &Bitmap::operator=(Bitmap &&orig) { if (this != &orig) { delete[] pixels; pixels = orig.pixels; w = orig.w, h = orig.h; yOrientation = orig.yOrientation; orig.pixels = NULL; } return *this; } #endif template int Bitmap::width() const { return w; } template int Bitmap::height() const { return h; } template T *Bitmap::operator()(int x, int y) { return pixels+N*(w*y+x); } template const T *Bitmap::operator()(int x, int y) const { return pixels+N*(w*y+x); } template Bitmap::operator T *() { return pixels; } template Bitmap::operator const T *() const { return pixels; } template Bitmap::operator BitmapRef() { return BitmapRef(pixels, w, h, yOrientation); } template Bitmap::operator BitmapConstRef() const { return BitmapConstRef(pixels, w, h, yOrientation); } template Bitmap::operator BitmapSection() { return BitmapSection(pixels, w, h, yOrientation); } template Bitmap::operator BitmapConstSection() const { return BitmapConstSection(pixels, w, h, yOrientation); } template BitmapSection Bitmap::getSection(int xMin, int yMin, int xMax, int yMax) { return BitmapSection(pixels+N*(w*yMin+xMin), xMax-xMin, yMax-yMin, N*w, yOrientation); } template BitmapConstSection Bitmap::getConstSection(int xMin, int yMin, int xMax, int yMax) const { return BitmapConstSection(pixels+N*(w*yMin+xMin), xMax-xMin, yMax-yMin, N*w, yOrientation); } }