summaryrefslogtreecommitdiffstats
path: root/tksao
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2020-01-11 19:36:49 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2020-01-11 19:36:49 (GMT)
commitded365f2a66a1258155335bbc62a5c9dc8f6bc89 (patch)
tree60067bd12af335f9c1247e59746596dcf3bf913a /tksao
parent657072f4a523cc51d415663e02882014055709a2 (diff)
downloadblt-ded365f2a66a1258155335bbc62a5c9dc8f6bc89.zip
blt-ded365f2a66a1258155335bbc62a5c9dc8f6bc89.tar.gz
blt-ded365f2a66a1258155335bbc62a5c9dc8f6bc89.tar.bz2
MASK: each layer is opaque
Diffstat (limited to 'tksao')
-rw-r--r--tksao/frame/frame.C102
-rw-r--r--tksao/frame/frame.h1
2 files changed, 76 insertions, 27 deletions
diff --git a/tksao/frame/frame.C b/tksao/frame/frame.C
index 6fc2d0e..0b156af 100644
--- a/tksao/frame/frame.C
+++ b/tksao/frame/frame.C
@@ -67,18 +67,19 @@ unsigned char* Frame::blend(unsigned char* src, unsigned char* msk,
int width, int height)
{
unsigned char* sptr = src; // 3 component
- unsigned char* mptr = msk; // 4 component, premultiplied
+ unsigned char* mptr = msk; // 4 component
+ float aa = 1-maskAlpha;
- for (int jj=0; jj<height; jj++)
+ for (int jj=0; jj<height; jj++) {
for (int ii=0; ii<width; ii++) {
if (*(mptr+3)) {
- float aa = 1-maskAlpha;
- *sptr = *mptr++ + *sptr * aa;
+ *sptr = (*sptr*aa) + (*mptr++ *maskAlpha);
sptr++;
- *sptr = *mptr++ + *sptr * aa;
+ *sptr = (*sptr*aa) + (*mptr++ *maskAlpha);
sptr++;
- *sptr = *mptr++ + *sptr * aa;
+ *sptr = (*sptr*aa) + (*mptr++ *maskAlpha);
sptr++;
+
mptr++;
}
else {
@@ -86,10 +87,35 @@ unsigned char* Frame::blend(unsigned char* src, unsigned char* msk,
sptr+=3;
}
}
+ }
return src;
}
+unsigned char* Frame::stackmask(unsigned char* dest, unsigned char* msk,
+ int width, int height)
+{
+ unsigned char* dptr = dest; // 4 component
+ unsigned char* mptr = msk; // 4 component
+
+ for (int jj=0; jj<height; jj++) {
+ for (int ii=0; ii<width; ii++) {
+ if (*(mptr+3)) {
+ *dptr++ = *mptr++;
+ *dptr++ = *mptr++;
+ *dptr++ = *mptr++;
+ *dptr++ = *mptr++;
+ }
+ else {
+ dptr+=4;
+ mptr+=4;
+ }
+ }
+ }
+
+ return dest;
+}
+
unsigned char* Frame::fillImage(int width, int height,
Coord::InternalSystem sys)
{
@@ -200,12 +226,34 @@ unsigned char* Frame::fillImage(int width, int height,
CLEARSIGBUS
if (img) {
- FitsMask* mptr = mask.tail();
- while (mptr) {
- unsigned char* msk = fillMask(mptr, width, height, sys);
- blend(img,msk,width,height);
- delete [] msk;
- mptr = mptr->previous();
+ switch (mask.count()) {
+ case 0:
+ break;
+ case 1:
+ {
+ FitsMask* mptr = mask.tail();
+ unsigned char* msk = fillMask(mptr, width, height, sys);
+ blend(img,msk,width,height);
+ delete [] msk;
+ }
+ break;
+ default:
+ {
+ unsigned char* msk = new unsigned char[width*height*4];
+ memset(msk,0,width*height*4);
+
+ FitsMask* mptr = mask.head();
+ while (mptr) {
+ unsigned char* mm = fillMask(mptr, width, height, sys);
+ stackmask(msk,mm,width,height);
+ delete [] mm;
+ mptr = mptr->next();
+ }
+
+ blend(img,msk,width,height);
+ delete [] msk;
+ }
+ break;
}
}
@@ -265,41 +313,41 @@ unsigned char* Frame::fillMask(FitsMask* msk, int width, int height,
switch (mark) {
case FitsMask::ZERO:
if (value==0) {
- *dest = ((unsigned char)maskColor->red)*maskAlpha;
- *(dest+1) = ((unsigned char)maskColor->green)*maskAlpha;
- *(dest+2) = ((unsigned char)maskColor->blue)*maskAlpha;
+ *dest = ((unsigned char)maskColor->red);
+ *(dest+1) = ((unsigned char)maskColor->green);
+ *(dest+2) = ((unsigned char)maskColor->blue);
*(dest+3) = 1;
}
break;
case FitsMask::NONZERO:
if (value!=0) {
- *dest = ((unsigned char)maskColor->red)*maskAlpha;
- *(dest+1) = ((unsigned char)maskColor->green)*maskAlpha;
- *(dest+2) = ((unsigned char)maskColor->blue)*maskAlpha;
+ *dest = ((unsigned char)maskColor->red);
+ *(dest+1) = ((unsigned char)maskColor->green);
+ *(dest+2) = ((unsigned char)maskColor->blue);
*(dest+3) = 1;
}
break;
case FitsMask::NaN:
if (isnan(value) || isinf(value)) {
- *dest = ((unsigned char)maskColor->red)*maskAlpha;
- *(dest+1) = ((unsigned char)maskColor->green)*maskAlpha;
- *(dest+2) = ((unsigned char)maskColor->blue)*maskAlpha;
+ *dest = ((unsigned char)maskColor->red);
+ *(dest+1) = ((unsigned char)maskColor->green);
+ *(dest+2) = ((unsigned char)maskColor->blue);
*(dest+3) = 1;
}
break;
case FitsMask::NONNaN:
if (!isnan(value) && !isinf(value)) {
- *dest = ((unsigned char)maskColor->red)*maskAlpha;
- *(dest+1) = ((unsigned char)maskColor->green)*maskAlpha;
- *(dest+2) = ((unsigned char)maskColor->blue)*maskAlpha;
+ *dest = ((unsigned char)maskColor->red);
+ *(dest+1) = ((unsigned char)maskColor->green);
+ *(dest+2) = ((unsigned char)maskColor->blue);
*(dest+3) = 1;
}
break;
case FitsMask::RANGE:
if (value>=low && value<=high) {
- *dest = ((unsigned char)maskColor->red)*maskAlpha;
- *(dest+1) = ((unsigned char)maskColor->green)*maskAlpha;
- *(dest+2) = ((unsigned char)maskColor->blue)*maskAlpha;
+ *dest = ((unsigned char)maskColor->red);
+ *(dest+1) = ((unsigned char)maskColor->green);
+ *(dest+2) = ((unsigned char)maskColor->blue);
*(dest+3) = 1;
}
break;
diff --git a/tksao/frame/frame.h b/tksao/frame/frame.h
index 2f09da5..0aa3935 100644
--- a/tksao/frame/frame.h
+++ b/tksao/frame/frame.h
@@ -35,6 +35,7 @@ class Frame : public FrameBase {
private:
unsigned char* blend(unsigned char*, unsigned char*, int, int);
+ unsigned char* stackmask(unsigned char*, unsigned char*, int, int);
int isIIS();
void pushMatrices();
void pushMagnifierMatrices();