+ // first we need to find the mask color, therefore we check all 4 edge pixel and take the color which
+ // appears most often (we only need to check three edges, the 4th is implicitly clear)
+ unsigned int topLeft = data[0], topRight = data[w-1], bottomLeft = data[w*h-w], bottomRight = data[w*h-1];
+ int max = (topLeft == topRight) + (topLeft == bottomLeft) + (topLeft == bottomRight);
+ int maskPos = 0;
+ if ( max < (topRight == topLeft) + (topRight == bottomLeft) + (topRight == bottomRight) ) {
+ max = (topRight == topLeft) + (topRight == bottomLeft) + (topRight == bottomRight);
+ maskPos = w-1;
+ }
+ if ( max < (bottomLeft == topRight) + (bottomLeft == topLeft) + (bottomLeft == bottomRight) )
+ maskPos = w*h-w;
+
+ // now mask out every pixel which has the same color as the edge pixels