What's the most efficient way to check of CVPixelBufferRef has white pixels?
Below is the code that I'm currently using, but it's not returning an white pixels, when a photo clearly has white pixels.
const int kBytesPerPixel = 4;
CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
int bufferWidth = (int)CVPixelBufferGetWidth( pixelBuffer );
int bufferHeight = (int)CVPixelBufferGetHeight( pixelBuffer );
size_t bytesPerRow = CVPixelBufferGetBytesPerRow( pixelBuffer );
uint8_t *baseAddress = CVPixelBufferGetBaseAddress( pixelBuffer );
int count = 0;
BOOL hasWhitePixels = NO;
for ( int row = 0; row < bufferHeight; row++ ){
uint8_t *pixel = baseAddress + row * bytesPerRow;
for ( int column = 0; column < bufferWidth; column++ ){
if (pixel[0] == 255 && pixel[1] == 255 && pixel[2] == 255) {
count++;
hasWhitePixels = YES;
NSLog(@"HAS WHITE PIXELS");
break;
}
pixel += kBytesPerPixel;
}
}
CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );