Created
January 13, 2014 17:01
-
-
Save alexflint/8403817 to your computer and use it in GitHub Desktop.
Test for images that are too dark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8_t ComputeMax(const uint8_t* image, size_t width, size_t height, size_t stride) { | |
uint8_t m = 0; | |
for (int i = 0; i < height; i++) { | |
const uint8_t* p = &image[i*stride]; | |
for (int j = 0; j < width; j++) { | |
if (*p > m) { | |
m = *p; | |
} | |
p++; | |
} | |
} | |
return m; | |
} | |
- (bool)testDarkness:(CVImageBufferRef)imageBuffer { | |
// Look up buffer size | |
size_t width = CVPixelBufferGetWidth(imageBuffer); | |
size_t height = CVPixelBufferGetHeight(imageBuffer); | |
uint8_t *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer); | |
// TODO: confirm that baseAddress is the address of a YUV plane | |
CVPlanarPixelBufferInfo_YCbCrBiPlanar *bufferInfo = (CVPlanarPixelBufferInfo_YCbCrBiPlanar *)baseAddress; | |
uint32_t yOffset = CFSwapInt32BigToHost(bufferInfo->componentInfoY.offset); | |
uint32_t yPitch = CFSwapInt32BigToHost(bufferInfo->componentInfoY.rowBytes); | |
uint8_t *yBuffer = &baseAddress[yOffset]; | |
uint8_t max = ComputeMax(yBuffer, width, height, yPitch); | |
if (max < 100) { | |
NSLog(@"Too dark! Max: %d\n", max); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment