diff --git a/build-number.txt b/build-number.txt index 2bc4cd6..c0556fb 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -510 +511 diff --git a/src/ov7670.c b/src/ov7670.c index 5d33cdf..12cd17f 100644 --- a/src/ov7670.c +++ b/src/ov7670.c @@ -155,7 +155,10 @@ int LineCount = 0; static volatile int FrameCount = 0; volatile int Camera_Captured = 0; static unsigned int BlackPixels = 0; + +#ifdef CAMERA_USE_EXPOSURE_CORRECTION static volatile int ExposureCorrection = 0; +#endif static uint8_t ReadRegister(uint8_t reg) { @@ -312,8 +315,10 @@ void TIM1_CC_IRQHandler(void) CurrentLine = 0; FrameCount++; +#ifdef CAMERA_USE_EXPOSURE_CORRECTION // Correct exposure across frames ExposureCorrection += 32 * BlackPixels / CAMERA_PIXELS - 16; +#endif // Check if the last frame's exposure is reasonable if(FrameCount >= 5) @@ -373,6 +378,7 @@ void TIM3_IRQHandler(void) for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++) { int pixel = LineBuffer[i + 15] + x_error; +#ifdef CAMERA_USE_EXPOSURE_CORRECTION if(ExposureCorrection < 0) { if(pixel < -ExposureCorrection) @@ -387,6 +393,7 @@ void TIM3_IRQHandler(void) else pixel += ExposureCorrection; } +#endif int line = CurrentLine / 2; int error; diff --git a/src/ov7670.h b/src/ov7670.h index 6249870..8ffa57d 100644 --- a/src/ov7670.h +++ b/src/ov7670.h @@ -11,6 +11,10 @@ // dithering. #define CAMERA_USE_2D_DITHERING +// Use a primitive autoexposure by shifting each frames luminosity based on the +// ratio of white to black pixels in the previous frames +// #define CAMERA_USE_EXPOSURE_CORRECTION + extern volatile int Camera_Captured; void Camera_Init(void); \ No newline at end of file