-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFostroMask.cpp
More file actions
156 lines (127 loc) · 3.62 KB
/
FostroMask.cpp
File metadata and controls
156 lines (127 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "FostroMask.h"
#include "FostroPixel.h"
#include "FostroImage.h"
#include "FostroDefines.h"
FostroMask::FostroMask(int w, int h) {
width = w;
height = h;
mask = new float[width*height];
}
FostroMask::FostroMask(const FostroMask& other) {
width = other.getWidth();
height = other.getHeight();
for (int i = 0; i < height; i++) {
for (int j = 0; j < height; j++) {
setMaskVal(i, j, other.getMaskVal(i,j));
}
}
}
FostroMask& FostroMask::operator=(const FostroMask& other) {
delete[] mask;
width = other.getWidth();
height = other.getHeight();
for (int i = 0; i < height; i++) {
for (int j = 0; j < height; j++) {
setMaskVal(i, j, other.getMaskVal(i,j));
}
}
return *this;
}
FostroMask::~FostroMask() {
delete[] mask;
}
int FostroMask::getWidth() const {
return width;
}
int FostroMask::getHeight() const {
return height;
}
float FostroMask::getMaskVal(int x, int y) const {
return mask[x*width+y];
}
void FostroMask::setMaskVal(int x, int y, float val) {
mask[x*width+y] = val;
}
void FostroMask::setAllMaskVals(float val) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
setMaskVal(i,j,val);
}
}
}
bool FostroMask::allSameVals() {
return allSame;
}
void FostroMask::checkAllSameVals() {
float val = mask[0];
allSame = true;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (mask[i*width+j] != val) {
allSame = false;
break;
}
}
if (!allSame) {
break;
}
}
}
int FostroMask::calcWidthOffset(int xImage, int xMask) {
int halfWidth = width/2; // intentional truncation
return (xImage - halfWidth + xMask);
}
int FostroMask::calcHeightOffset(int xImage, int xMask) {
int halfHeight = height/2; // intentional truncation
return (xImage - halfHeight + xMask);
}
// returns mask value at mask location multiplied by value in
// image at mask location relatvie to image location
float FostroMask::getImageValAtMaskLoc(int xMask, int yMask, int xImage, int yImage, FostroImage* image, int c) {
FostroPixel* pixel;
float val = 0;
int x = calcHeightOffset(xImage, xMask);
int y = calcWidthOffset(yImage, yMask);
//pixel = image->getPixel(calcWidthOffset(xImage, xMask), calcHeightOffset(yImage, yMask));
pixel = image->getPixel(x, y);
switch (c) {
case RED:
val = pixel->getRedVal();
break;
case GREEN:
val = pixel->getGreenVal();
break;
case BLUE:
val = pixel->getBlueVal();
break;
case ALPHA:
val = pixel->getAlphaVal();
break;
case GRAY:
val = pixel->getGrayscaleIntensity();
break;
default:
val = -1;
}
if (val < 0 || val > MAX_PIXEL_VAL) {
std::cout << "Val is " << val << " something is wrong at pixel location " << x << "," << y << " around loc " << xImage << "," << yImage << std::endl;
if (c == GRAY) {
std::cout << "Gray Value is " << pixel->getGrayscaleIntensity() << " at " << x << "," << y << std::endl;
std::cout << "Red Value is " << pixel->getRedVal() << " at " << x << "," << y << std::endl;
}
if (c == RED) {
std::cout << "Red Value Selected" << std::endl;
}
if (c == GREEN) {
std::cout << "Green Value Selected" << std::endl;
}
if (c == BLUE) {
std::cout << "Blue Value Selected" << std::endl;
}
}
if (val == -1) {
std::cout << "Val is -1, something went wrong in the switch case" << std::endl;
}
// std::cout << "val in getImageValAtMaskLoc = " << val << " from location [" << x << "][" << y << "]" << std::endl;
return val*getMaskVal(xMask, yMask);
}