112 static_assert(tFactor == 2u,
"Invalid factor!");
113 static_assert(tNeighborhood == 1u || tNeighborhood == 9u,
"Invalid neighborhood!");
115 const unsigned int width = layerI_.width();
116 const unsigned int height = layerI_.height();
118 const unsigned int coarserWidth = coarserLayerI_.width();
119 const unsigned int coarserHeight = coarserLayerI_.height();
121 ocean_assert(width / tFactor == coarserWidth);
122 ocean_assert(height / tFactor == coarserHeight);
124 MappingI& mapping = layerI_.mapping();
125 const MappingI& coarserMapping = coarserLayerI_.mapping();
129 const uint8_t*
const mask = layerI_.mask().template constdata<uint8_t>();
130 const uint8_t*
const coarserMask = coarserLayerI_.mask().template constdata<uint8_t>();
131 uint8_t*
const costMask = costMask_.data<uint8_t>();
132 const uint8_t*
const coarserCostMask = coarserCostMask_.constdata<uint8_t>();
134 const unsigned int maskStrideElements = layerI_.mask().strideElements();
135 const unsigned int coarserMaskStrideElements = coarserLayerI_.mask().strideElements();
136 const unsigned int costMaskStrideElements = costMask_.strideElements();
137 const unsigned int coarserCostMaskStrideElements = coarserCostMask_.strideElements();
139 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
141 const uint8_t* maskRow = mask + y * maskStrideElements;
144 const unsigned int yCoarser = min(y / tFactor, coarserHeight - 1u);
146 const uint8_t* coarserMaskRow = coarserMask + yCoarser * coarserMaskStrideElements;
149 for (
unsigned int x = firstColumn; x < firstColumn + numberColumns; ++x)
151 if (maskRow[x] != 0xFFu)
153 const unsigned int xCoarser = min(x / tFactor, coarserWidth - 1u);
156 if (coarserMaskRow[xCoarser] != 0xFFu)
158 const PixelPosition& coarserPosition = coarserPositionRow[xCoarser];
159 ocean_assert(coarserPosition.
x() < coarserLayerI_.width());
160 ocean_assert(coarserPosition.
y() < coarserLayerI_.height());
162 const unsigned int candidateX = (
unsigned int)(
int(x) + (int(coarserPosition.
x()) - int(xCoarser)) *
int(tFactor));
163 const unsigned int candidateY = (
unsigned int)(
int(y) + (int(coarserPosition.
y()) - int(yCoarser)) *
int(tFactor));
165 ocean_assert(candidateX < width);
166 ocean_assert(candidateY < height);
168 if (mask[candidateY * maskStrideElements + candidateX] == 0xFFu)
172 if constexpr (tNeighborhood == 1u)
174 if (coarserCostMask[yCoarser * coarserCostMaskStrideElements + xCoarser] == 0x80u)
176 costMask[y * costMaskStrideElements + x] = 0xFFu;
181 if (xCoarser - 1u < coarserWidth - 2u && yCoarser - 1u < coarserHeight - 2u)
183 const uint8_t*
const coarserCostData = coarserCostMask + (yCoarser - 1u) * coarserCostMaskStrideElements + (xCoarser - 1u);
185 if (coarserCostData[0] == 0x80u && coarserCostData[1] == 0x80u && coarserCostData[2] == 0x80u
186 && coarserCostData[coarserCostMaskStrideElements + 0u] == 0x80u && coarserCostData[coarserCostMaskStrideElements + 1u] == 0x80u && coarserCostData[coarserCostMaskStrideElements + 2u] == 0x80u
187 && coarserCostData[2u * coarserCostMaskStrideElements + 0u] == 0x80u && coarserCostData[2u * coarserCostMaskStrideElements + 1u] == 0x80u && coarserCostData[2u * coarserCostMaskStrideElements + 2u] == 0x80u)
189 costMask[y * costMaskStrideElements + x] = 0xFFu;
194 bool zeroBlock =
true;
196 for (
int xxCoarser =
int(xCoarser) - 1; zeroBlock && xxCoarser <= int(xCoarser) + 1; ++xxCoarser)
198 for (
int yyCoarser =
int(yCoarser) - 1; zeroBlock && yyCoarser <= int(yCoarser) + 1; ++yyCoarser)
200 if ((
unsigned int)(xxCoarser) < coarserWidth && (
unsigned int)(yyCoarser) < coarserHeight)
202 if (coarserCostMask[(
unsigned int)(yyCoarser) * coarserCostMaskStrideElements + (
unsigned int)(xxCoarser)] != 0x80u)
212 costMask[y * costMaskStrideElements + x] = 0xFFu;
222 unsigned int candidateX, candidateY;
228 while (mask[candidateY * maskStrideElements + candidateX] != 0xFFu);