@@ -1052,32 +1052,52 @@ TRasterGR8P IwRenderInstance::createMatteRas(ShapePair* shape) {
1052
1052
for (int y = 0 ; y < matteRas->getLy (); y++) {
1053
1053
TPixelGR8* mattePix = matteRas->pixels (y);
1054
1054
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
+
1056
1062
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;
1058
1072
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 ()) {
1063
1076
*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))
1075
1079
*mattePix = 1 ;
1076
- inPixList.append (*orgPix);
1077
- } else {
1080
+ else if (inPixList.contains (*orgPix))
1078
1081
*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
+ }
1080
1099
}
1100
+ orgPix++;
1081
1101
}
1082
1102
}
1083
1103
}
0 commit comments