New version of BGRABitmap 10.1
https://github.com/bgrabitmap/bgrabitmap/releasesColorspacesColorspaces were added some time ago, though you could not really use it to draw something, as anyway sRGB 8 bit was used. This release, introduces universal bitmaps and brushes. The types TCustomUniversalBitmap and TUniversalBrush can be used in principle with any colorspace. The following bitmap types are available:
- TBGRABitmap: sRGB, 8 bit per channel
- TGrayscaleBitmap: linear 8 bit grayscale. It now has drawing functions, so you can prepare a mask in 8 bit per pixel, avoiding to consume memory
- TExpandedBitmap: linear RGB, 16 bit per channel. It has more precision than TBGRABitmap and is linear, so that dmLinearBlend and dmDrawWithTransparency are equivalent.
- TLinearRGBABitmap: linear RGB, 32 bit per channel (single precision float). It has even more precision. Not really recommended though as it uses a lot of memory.
- TWordXYZABitmap: XYZ, 16 bit per channel. Can store any real and reflect color with great precision (see below for remarks about XYZ).
- TXYZABitmap: XYZ, 32 bit per channel (single precision float). It has even more precision and also a wider range, so that it can store fluorescent colors and light sources that would otherwise saturate.
XYZ is a colorspace that stores the actual stimulation of the average eye, relative to a max luminance (Y=1) considered as white. Fluorescent colors or light sources may have greater values for X/Y/Z so in this case you would rather use TXYZA floating-point format to avoid saturation. Otherwise, for most use cases, when the image represents an object reflecting daylight, TWordXYZA is sufficient.
The reference white is the color of an object that reflects all light, it depends on the illuminant. ICC recommends to use D50 as reference, which is a kind of natural daylight. While the reference white is always at Y = 1, its hue changes (X and Z values). So white is not necessary the simple value (1,1,1). This is only the case with the theoretical equal-energy illuminant (E).
So if you are not working with a specific illuminant, you would rather avoid defining colors as XYZ values. If they are in the RGB range, you can use automatic conversion and provide color constants as usual. Otherwise a convenient way is to use L*a*b* colors. For example those colors are outside of the RGB scope:
- TLabA.New(60,-145,45) is a deep mint color (greenish cyan)
- TLabA.New(90,0,140) is a deep golden yellow
While L*a*b* is convenient to specify colors, it is not so to merge colors and draw, so there isn't any bitmap that stores Lab values. Also it is worth noting that L*a*b* values do not have the exact same appearance depending on the illuminant. So I would rather use D50 to have the same values as ICC profiles.
If you want to change the reference white anyway, you can use SetReferenceWhite function. ReferenceWhite2E, ReferenceWhite2D50 and ReferenceWhite2D65 are provided as global variables.
It is also worth noting that in order to have the same values as most programs, the gamma value is now set to 2.2. This may give some gradients a different appearence, so you may want to switch back to the old 1.7 value or use your own with BGRASetGamma function.
When saving an image in XYZ colorspace, usual formats like PNG or BMP will result in colors being clipped or distorted. You need to use TIF format so that it will be saved in Lab colorspace. This format though is limited to -128..127 values for a and b, so unfortunately not all colors can be saved. If someone has an idea for a format, please let me know. You can use the Serialize/Deserialize function, though this would be readable by most programs and you need to take into account the endianness.
List of the changesUniversal bitmap:
- now TBGRACustomBitmap derives from TCustomUniversalBitmap
- TGrayscaleMask as well so it has drawing features
- brush can be customized as TUniversalBrush
- added bitmap types: TExpandedBitmap, TLinearRGBABitmap, TWordXYZABitmap, TXYZABitmap
- 16 bit/float colorspaces are saved by default as 16 bit when using PNG and TIFF format
Colorspaces:
- fixed color conversions by using gamma 2.2, D50 white point and chromatic adaptation
- bridged conversion via TExpandedPixel to reduced generated conversion code
- replace HasReferenceWhite function by GetFlags, fixed reference white point logic
- TIFF reader can handle L*a*b* colorspace
- added SpectrumRangeReflectToXYZA to get XYZ from spectrum range
- add check function for real colors in XYZABitmap unit
- can preserve hue when converting XYZ to RGB
Vectorized text:
- mirrored glyph when RTL context
- fix TexFitInfo, GetCharIndexAt
- ff ligatures
Layered bitmap:
- add render storage per layer for originals
SVG:
- handle xml:id alias to id
- container dimension applies to ComputedWidth/Height and Width/HeightAsPixels/Cm