Automatic Gamma Correction Best Practices
The automatic gamma correction method chooses a gamma value based on the file type
when loading a bitmap file (in certain cases) and when saving a bitmap file. You do
not need to care about the gamma correction because it is automatically done based
on the file type, bit depth, and other properties.
Following are the limitations in the previous method for gamma correction:
- If a file header does not contain a gamma value when loading, the globally defined
gamma value is always used and the file type is ignored. The next file that you attempt
to load from the File dialog also uses the globally defined gamma value even if it
contains a better value in the file header.
- The system default gamma value is always used for saving files and the file type is
ignored.
In the automatic gamma correction method, if a file header does not contain a gamma
value, the file type is considered to determine whether the file must be stored linearly.
For more information about automatic gamma correction, see the Automatic Gamma Correction topic.
The mapping of the flags (BMM_CUSTOM_FILEGAMMA and BMM_CUSTOM_GAMMA) with the gamma options in the File dialog has changed in the automatic gamma correction
method. Additionally, the meaning of the BMM_CUSTOM_FILEGAMMA flag has also changed. A new BitmapIOMetaData interface in the BitmapIO class is used to determine whether the file types are saved and loaded linearly or
with an embedded gamma. For more information about the SDK changes, see the SDK Changes for Automatic Gamma Correction topic.
Best Practices
Following are some best practices for avoiding gamma related issues when writing code:
- Use BitmapInfo and not filenames. If you need to use filenames, avoid changing the extension. If
you change the extension, call BitmapInfo::ResetPiData().
- Use BitmapInfo::GetEffectiveGamma() if you need to know the gamma of a bitmap and to untangle the various flags correctly.
Moreover, it is better to ignore the gamma and always use GetLinearPixels() (instead of GetPixels()) to obtain the proper linear value.
- Implement the BitmapIOMetaData interface if you are writing a BitmapIO plug-in that needs linear data.
- Bitmaps loaded from the file system might have a different encoding or gamma values
and might be non-linear.
- Only linear bitmaps can be saved with proper gamma correction applied, so you must
linearize all bitmaps before saving. You can copy the bitmap to make it linear and
at least 16-bit.