Skip to content

Commit fd36041

Browse files
authored
fix matte raster computation (#32)
1 parent d69e86a commit fd36041

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

sources/iwrenderinstance.cpp

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,32 +1052,52 @@ TRasterGR8P IwRenderInstance::createMatteRas(ShapePair* shape) {
10521052
for (int y = 0; y < matteRas->getLy(); y++) {
10531053
TPixelGR8* mattePix = matteRas->pixels(y);
10541054

1055-
int orgY = y + (int)std::round(sampleOffset.y());
1055+
int orgY = y + (int)std::round(sampleOffset.y());
1056+
// matteLayerの外側の場合、matteは0
1057+
if (orgY < 0 || orgY >= ras->getLy()) {
1058+
for (int x = 0; x < matteRas->getLx(); x++, mattePix++) *mattePix = 0;
1059+
continue; // 次の行へ
1060+
}
1061+
10561062
TPixel32* orgPix = ras->pixels(orgY);
1057-
orgPix += (int)std::round(sampleOffset.x());
1063+
int orgX = (int)std::round(sampleOffset.x());
1064+
1065+
// matteLayerが左にはみ出ている部分、matteは0
1066+
int x = 0;
1067+
for (; orgX < 0; orgX++, mattePix++, x++) {
1068+
*mattePix = 0;
1069+
}
1070+
1071+
orgPix += orgX;
10581072

1059-
for (int x = 0; x < matteRas->getLx(); x++, mattePix++, orgPix++) {
1060-
if (inPixList.contains(*orgPix))
1061-
*mattePix = 1;
1062-
else if (inPixList.contains(*orgPix))
1073+
for (; x < matteRas->getLx(); x++, mattePix++, orgX++) {
1074+
// matteLayerが右にはみ出ている部分、matteは0
1075+
if (orgX >= ras->getLy()) {
10631076
*mattePix = 0;
1064-
else { // 判定処理を行う
1065-
bool found = false;
1066-
for (auto matteCol : matteInfo.colors) {
1067-
if (std::abs(matteCol.red() - orgPix->r) <= matteInfo.tolerance &&
1068-
std::abs(matteCol.green() - orgPix->g) <= matteInfo.tolerance &&
1069-
std::abs(matteCol.blue() - orgPix->b) <= matteInfo.tolerance) {
1070-
found = true;
1071-
break;
1072-
}
1073-
}
1074-
if (found) {
1077+
} else {
1078+
if (inPixList.contains(*orgPix))
10751079
*mattePix = 1;
1076-
inPixList.append(*orgPix);
1077-
} else {
1080+
else if (inPixList.contains(*orgPix))
10781081
*mattePix = 0;
1079-
outPixList.append(*orgPix);
1082+
else { // 判定処理を行う
1083+
bool found = false;
1084+
for (auto matteCol : matteInfo.colors) {
1085+
if (std::abs(matteCol.red() - orgPix->r) <= matteInfo.tolerance &&
1086+
std::abs(matteCol.green() - orgPix->g) <= matteInfo.tolerance &&
1087+
std::abs(matteCol.blue() - orgPix->b) <= matteInfo.tolerance) {
1088+
found = true;
1089+
break;
1090+
}
1091+
}
1092+
if (found) {
1093+
*mattePix = 1;
1094+
inPixList.append(*orgPix);
1095+
} else {
1096+
*mattePix = 0;
1097+
outPixList.append(*orgPix);
1098+
}
10801099
}
1100+
orgPix++;
10811101
}
10821102
}
10831103
}

0 commit comments

Comments
 (0)