I doubt that one could declare the variables in 20 lines of code......
Code:
#define ADC_RANGE (1<<14)
#define ADC_MAX (ADC_RANGE-1)
#define MAX_X 6720
#define MAX_Y 4480
int aiHistogram[ ADC_RANGE ];
memset( &aiHistogram, '\0', sizeof( aiHistogram ) );
for ( int x = 0; x < MAX_X; x++ )
for ( int y = 0; y < MAX_Y; y++ )
aiHistogram[ max3( aaiImage[x][y][0], aaiImage[x][y][1], aaiImage[x][y][2] ) ]++; // use max of RGB
At that point, if aiHistogram[0] is zero, then you know you're getting ALL the shadow detail in the scene (though I think read noise and shot noise may give you some zeros anyway, so rather than compare the count to zero, compare to a low constant).
If aiHistogram[ADC_MAX] is zero, then you're getting ALL the highlight detail and I think read noise and shot noise can be discounted.
If BOTH are true, scene DR < sensor DR capability. We therefore have a range of exposures that would capture the scene and we can choose which exposure we want, based on minimizing shadow noise and hand-holdability.
Specifically: if the camera seems to be on a tripod (based on motion sensor history), use ETTR: pick the slowest shutter speed that won't clip the highlights you do see. If the camera seems to be hand-held, get as close to reciprocal rule (adjusted by a factor for IS and an additional user preference for shorter or longer) as possible. This means if the SLOWEST shutter in your range is still ABOVE recip, use that slowest shutter. If the FASTEST is still BELOW recip, use the fastest (sacrificing shadow noise for an attempt to avoid camera motion blur). Otherwise use recip (minimizing shadow noise to the extent possible without going into camera motion blur territory.)
Examples for shooting with 50/1.4:
- Shutter could be from 1/90 to 1/320? Shoot 1/90.
- Shutter could be from 1/15 to 1/90? Shoot 1/50.
- Shutter could be from 1/4 to 1/15? Shoot 1/15.
RESULT: in scenes where DR is below sensor capability, shadow detail is optimized to the extent recip rule allows.
And despite what the brain surgeon denies he's said before, doing this calculation wouldn't affect the histogram shown on the LCD, nor the live view image simulated exposure.
BTW, that suggestion is for modes full-auto, P, AP, where camera has free reign to decide shutter speed. For SP, where the camera has to decide aperture, you could likewise bias exposure towards say f/5.6 instead of recip, on grounds that 5.6 is nearly always the sharpest aperture, as well as rendering a healthy amount of the scen in DOF. It's unclear whether shallow DOF and soft image is worse than shadow noise, but say it is. (Or say the user has set a setting that it is.)
Examples for shooting with 50/1.4:
- Aperture could be from f/8 to f/22? Use f/8.
- Aperture could be from f/2 to f/8? Use f/5.6.
- Aperture could be from f/1.4 to f/2? Use f/2.