forked from Chlumsky/msdfgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
498 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,45 @@ | ||
|
||
#pragma once | ||
|
||
namespace msdfgen { | ||
#include "BitmapRef.hpp" | ||
|
||
/// A floating-point RGB pixel. | ||
struct FloatRGB { | ||
float r, g, b; | ||
}; | ||
namespace msdfgen { | ||
|
||
/// A 2D image bitmap. | ||
template <typename T> | ||
/// A 2D image bitmap with N channels of type T. Pixel memory is managed by the class. | ||
template <typename T, int N = 1> | ||
class Bitmap { | ||
|
||
public: | ||
Bitmap(); | ||
Bitmap(int width, int height); | ||
Bitmap(const Bitmap<T> &orig); | ||
Bitmap(const BitmapConstRef<T, N> &orig); | ||
Bitmap(const Bitmap<T, N> &orig); | ||
#ifdef MSDFGEN_USE_CPP11 | ||
Bitmap(Bitmap<T> &&orig); | ||
Bitmap(Bitmap<T, N> &&orig); | ||
#endif | ||
~Bitmap(); | ||
Bitmap<T> & operator=(const Bitmap<T> &orig); | ||
Bitmap<T, N> & operator=(const BitmapConstRef<T, N> &orig); | ||
Bitmap<T, N> & operator=(const Bitmap<T, N> &orig); | ||
#ifdef MSDFGEN_USE_CPP11 | ||
Bitmap<T> & operator=(Bitmap<T> &&orig); | ||
Bitmap<T, N> & operator=(Bitmap<T, N> &&orig); | ||
#endif | ||
/// Bitmap width in pixels. | ||
int width() const; | ||
/// Bitmap height in pixels. | ||
int height() const; | ||
T & operator()(int x, int y); | ||
const T & operator()(int x, int y) const; | ||
T * operator()(int x, int y); | ||
const T * operator()(int x, int y) const; | ||
explicit operator T *(); | ||
explicit operator const T *() const; | ||
operator BitmapRef<T, N>(); | ||
operator BitmapConstRef<T, N>() const; | ||
|
||
private: | ||
T *content; | ||
T *pixels; | ||
int w, h; | ||
|
||
}; | ||
|
||
} | ||
|
||
#include "Bitmap.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
|
||
#include "Bitmap.h" | ||
|
||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
namespace msdfgen { | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::Bitmap() : pixels(NULL), w(0), h(0) { } | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::Bitmap(int width, int height) : w(width), h(height) { | ||
pixels = new T[N*w*h]; | ||
} | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::Bitmap(const BitmapConstRef<T, N> &orig) : w(orig.width), h(orig.height) { | ||
pixels = new T[N*w*h]; | ||
memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); | ||
} | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::Bitmap(const Bitmap<T, N> &orig) : w(orig.w), h(orig.h) { | ||
pixels = new T[N*w*h]; | ||
memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); | ||
} | ||
|
||
#ifdef MSDFGEN_USE_CPP11 | ||
template <typename T, int N> | ||
Bitmap<T, N>::Bitmap(Bitmap<T, N> &&orig) : pixels(orig.pixels), w(orig.w), h(orig.h) { | ||
orig.pixels = NULL; | ||
orig.w = 0, orig.h = 0; | ||
} | ||
#endif | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::~Bitmap() { | ||
delete [] pixels; | ||
} | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N> & Bitmap<T, N>::operator=(const BitmapConstRef<T, N> &orig) { | ||
if (pixels != orig.pixels) { | ||
delete [] pixels; | ||
w = orig.width, h = orig.height; | ||
pixels = new T[N*w*h]; | ||
memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); | ||
} | ||
return *this; | ||
} | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N> & Bitmap<T, N>::operator=(const Bitmap<T, N> &orig) { | ||
if (this != &orig) { | ||
delete [] pixels; | ||
w = orig.w, h = orig.h; | ||
pixels = new T[N*w*h]; | ||
memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); | ||
} | ||
return *this; | ||
} | ||
|
||
#ifdef MSDFGEN_USE_CPP11 | ||
template <typename T, int N> | ||
Bitmap<T, N> & Bitmap<T, N>::operator=(Bitmap<T, N> &&orig) { | ||
if (this != &orig) { | ||
delete [] pixels; | ||
pixels = orig.pixels; | ||
w = orig.w, h = orig.h; | ||
orig.pixels = NULL; | ||
} | ||
return *this; | ||
} | ||
#endif | ||
|
||
template <typename T, int N> | ||
int Bitmap<T, N>::width() const { | ||
return w; | ||
} | ||
|
||
template <typename T, int N> | ||
int Bitmap<T, N>::height() const { | ||
return h; | ||
} | ||
|
||
template <typename T, int N> | ||
T * Bitmap<T, N>::operator()(int x, int y) { | ||
return pixels+N*(w*y+x); | ||
} | ||
|
||
template <typename T, int N> | ||
const T * Bitmap<T, N>::operator()(int x, int y) const { | ||
return pixels+N*(w*y+x); | ||
} | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::operator T *() { | ||
return pixels; | ||
} | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::operator const T *() const { | ||
return pixels; | ||
} | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::operator BitmapRef<T, N>() { | ||
return BitmapRef<T, N>(pixels, w, h); | ||
} | ||
|
||
template <typename T, int N> | ||
Bitmap<T, N>::operator BitmapConstRef<T, N>() const { | ||
return BitmapConstRef<T, N>(pixels, w, h); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.