mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Implemented ContourMask (mask for text fields)
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@251 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -49,3 +49,53 @@ bool AlphaMask::isTransparent(int x, int y) const {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ContourMask
|
||||
|
||||
ContourMask::ContourMask()
|
||||
: width(0), height(0), lefts(nullptr), rights(nullptr)
|
||||
{}
|
||||
ContourMask::~ContourMask() {
|
||||
unload();
|
||||
}
|
||||
|
||||
void ContourMask::load(const Image& image) {
|
||||
unload();
|
||||
width = image.GetWidth();
|
||||
height = image.GetHeight();
|
||||
lefts = new int[height];
|
||||
rights = new int[height];
|
||||
// for each row: determine left and rightmost white pixel
|
||||
Byte* data = image.GetData();
|
||||
for (int y = 0 ; y < height ; ++y) {
|
||||
lefts[y] = width; rights[y] = width;
|
||||
for (int x = 0 ; x < width ; ++x) {
|
||||
int v = data[0] + data[1] + data[2];
|
||||
if (v > 50) { // white enough
|
||||
rights[y] = x;
|
||||
if (x < lefts[y]) lefts[y] = x;
|
||||
}
|
||||
data += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ContourMask::unload() {
|
||||
delete lefts;
|
||||
delete rights;
|
||||
lefts = rights = nullptr;
|
||||
width = height = 0;
|
||||
}
|
||||
|
||||
double ContourMask::rowLeft (double y, RealSize size) const {
|
||||
if (!ok() || y < 0 || y >= size.height) {
|
||||
// no mask, or outside it
|
||||
return 0;
|
||||
}
|
||||
return lefts[(int)(y * size.height / height)] * size.width / width;
|
||||
}
|
||||
double ContourMask::rowRight(double y, RealSize size) const {
|
||||
if (!ok() || y < 0 || y >= size.height) {
|
||||
// no mask, or outside it
|
||||
return size.width;
|
||||
}
|
||||
return rights[(int)(y * size.height / height)] * size.width / width;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user