Home | History | Annotate | Download | only in video_WebRtcCamera
      1 /*
      2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree.
      7  */
      8 
      9 'use strict';
     10 
     11 function isBlackFrame(data, length) {
     12   var accumulatedLuma = 0;
     13   var nonBlackPixelLumaThreshold = 20;
     14   for (var i = 4; i < length; i += 4) {
     15     // Use Luma as in Rec. 709: Y709 = 0.21R + 0.72G + 0.07B;
     16     accumulatedLuma += (0.21 * data[i] +  0.72 * data[i + 1]
     17         + 0.07 * data[i + 2]);
     18     // Early termination if the average Luma so far is bright enough.
     19     if (accumulatedLuma > (nonBlackPixelLumaThreshold * i / 4)) {
     20       return false;
     21     }
     22   }
     23   return true;
     24 }