File tree Expand file tree Collapse file tree 1 file changed +34
-7
lines changed
Expand file tree Collapse file tree 1 file changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -235,21 +235,48 @@ public class @MAIN_NAME@UiTest {
235235 if (pixels == null || pixels.length == 0) {
236236 return false;
237237 }
238- int reference = pixels[0];
238+
239+ final int minVisiblePixels = 32;
240+ final int minDifferingPixels = 8;
241+ final int minLumaSpread = 12;
242+
243+ int reference = -1;
239244 int differing = 0;
245+ int visible = 0;
246+ int minLuma = 255;
247+ int maxLuma = 0;
248+
240249 for (int argb : pixels) {
241250 int alpha = (argb >>> 24) & 0xFF;
242- if (alpha == 0 ) {
251+ if (alpha < 16 ) {
243252 continue;
244253 }
245- if (argb != reference) {
254+
255+ visible++;
256+ int rgb = argb & 0x00FFFFFF;
257+ if (reference == -1) {
258+ reference = rgb;
259+ } else if (rgb != reference) {
246260 differing++;
247- if (differing > pixels.length / 100) {
248- return true;
249- }
261+ }
262+
263+ int r = (rgb >>> 16) & 0xFF;
264+ int g = (rgb >>> 8) & 0xFF;
265+ int b = rgb & 0xFF;
266+ int luma = (299 * r + 587 * g + 114 * b) / 1000;
267+ if (luma < minLuma) {
268+ minLuma = luma;
269+ }
270+ if (luma > maxLuma) {
271+ maxLuma = luma;
272+ }
273+
274+ if (visible >= minVisiblePixels && differing >= minDifferingPixels) {
275+ return true;
250276 }
251277 }
252- return false;
278+
279+ return visible >= minVisiblePixels && (differing >= minDifferingPixels || (maxLuma - minLuma) >= minLumaSpread);
253280 }
254281
255282 private static File saveBitmap(Bitmap bitmap, String fileName) throws IOException {
You can’t perform that action at this time.
0 commit comments