TurboJPEG: Add alpha offset array/method

Also, set the red/green/blue offsets for TJPF_GRAY to -1 rather than 0.
It was undefined behavior for an application to use those arrays/methods
with TJPF_GRAY anyhow, and this makes it easier for applications to
programmatically detect whether a given pixel format has red, green, and
blue components.
This commit is contained in:
DRC
2017-11-16 20:43:12 -06:00
parent aa7459050d
commit dc4b900223
26 changed files with 265 additions and 81 deletions

View File

@@ -256,33 +256,54 @@ enum TJPF
TJPF_UNKNOWN = -1
};
/**
* Red offset (in bytes) for a given pixel format. This specifies the number
* of bytes that the red component is offset from the start of the pixel. For
* instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
* then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>.
* then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>. This
* will be -1 if the pixel format does not have a red component.
*/
static const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1, -1};
static const int tjRedOffset[TJ_NUMPF] = {
0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1
};
/**
* Green offset (in bytes) for a given pixel format. This specifies the number
* of bytes that the green component is offset from the start of the pixel.
* For instance, if a pixel of format TJ_BGRX is stored in
* <tt>char pixel[]</tt>, then the green component will be
* <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>.
* <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>. This will be -1 if the pixel format
* does not have a green component.
*/
static const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2, -1};
static const int tjGreenOffset[TJ_NUMPF] = {
1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1
};
/**
* Blue offset (in bytes) for a given pixel format. This specifies the number
* of bytes that the Blue component is offset from the start of the pixel. For
* instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
* then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>.
* then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>. This
* will be -1 if the pixel format does not have a blue component.
*/
static const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3, -1};
static const int tjBlueOffset[TJ_NUMPF] = {
2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1
};
/**
* Pixel size (in bytes) for a given pixel format.
* Alpha offset (in bytes) for a given pixel format. This specifies the number
* of bytes that the Alpha component is offset from the start of the pixel.
* For instance, if a pixel of format TJ_BGRA is stored in
* <tt>char pixel[]</tt>, then the alpha component will be
* <tt>pixel[tjAlphaOffset[TJ_BGRA]]</tt>. This will be -1 if the pixel format
* does not have an alpha component.
*/
static const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4};
static const int tjAlphaOffset[TJ_NUMPF] = {
-1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
};
/**
* Pixel size (in bytes) for a given pixel format
*/
static const int tjPixelSize[TJ_NUMPF] = {
3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4
};
/**