Make auto-exposure optional

This commit is contained in:
fruchti 2019-11-14 19:06:39 +01:00
parent 91dc86102f
commit 912a16628a
3 changed files with 12 additions and 1 deletions

View file

@ -1 +1 @@
510 511

View file

@ -155,7 +155,10 @@ int LineCount = 0;
static volatile int FrameCount = 0; static volatile int FrameCount = 0;
volatile int Camera_Captured = 0; volatile int Camera_Captured = 0;
static unsigned int BlackPixels = 0; static unsigned int BlackPixels = 0;
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
static volatile int ExposureCorrection = 0; static volatile int ExposureCorrection = 0;
#endif
static uint8_t ReadRegister(uint8_t reg) static uint8_t ReadRegister(uint8_t reg)
{ {
@ -312,8 +315,10 @@ void TIM1_CC_IRQHandler(void)
CurrentLine = 0; CurrentLine = 0;
FrameCount++; FrameCount++;
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
// Correct exposure across frames // Correct exposure across frames
ExposureCorrection += 32 * BlackPixels / CAMERA_PIXELS - 16; ExposureCorrection += 32 * BlackPixels / CAMERA_PIXELS - 16;
#endif
// Check if the last frame's exposure is reasonable // Check if the last frame's exposure is reasonable
if(FrameCount >= 5) if(FrameCount >= 5)
@ -373,6 +378,7 @@ void TIM3_IRQHandler(void)
for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++) for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++)
{ {
int pixel = LineBuffer[i + 15] + x_error; int pixel = LineBuffer[i + 15] + x_error;
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
if(ExposureCorrection < 0) if(ExposureCorrection < 0)
{ {
if(pixel < -ExposureCorrection) if(pixel < -ExposureCorrection)
@ -387,6 +393,7 @@ void TIM3_IRQHandler(void)
else else
pixel += ExposureCorrection; pixel += ExposureCorrection;
} }
#endif
int line = CurrentLine / 2; int line = CurrentLine / 2;
int error; int error;

View file

@ -11,6 +11,10 @@
// dithering. // dithering.
#define CAMERA_USE_2D_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; extern volatile int Camera_Captured;
void Camera_Init(void); void Camera_Init(void);