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

@@ -84,8 +84,6 @@ const char *pixFormatStr[TJ_NUMPF]=
"RGBA", "BGRA", "ABGR", "ARGB", "CMYK"
};
const int alphaOffset[TJ_NUMPF] = {-1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1};
const int _3byteFormats[]={TJPF_RGB, TJPF_BGR};
const int _4byteFormats[]={TJPF_RGBX, TJPF_BGRX, TJPF_XBGR, TJPF_XRGB,
TJPF_CMYK};
@@ -196,12 +194,14 @@ int checkBuf(unsigned char *buf, int w, int h, int pf, int subsamp,
int roffset=tjRedOffset[pf];
int goffset=tjGreenOffset[pf];
int boffset=tjBlueOffset[pf];
int aoffset=alphaOffset[pf];
int aoffset=tjAlphaOffset[pf];
int ps=tjPixelSize[pf];
int index, row, col, retval=1;
int halfway=16*sf.num/sf.denom;
int blocksize=8*sf.num/sf.denom;
if(pf==TJPF_GRAY) roffset=goffset=boffset=0;
if(pf==TJPF_CMYK)
{
for(row=0; row<h; row++)
@@ -738,7 +738,7 @@ int cmpBitmap(unsigned char *buf, int width, int pitch, int height, int pf,
int roffset=tjRedOffset[pf];
int goffset=tjGreenOffset[pf];
int boffset=tjBlueOffset[pf];
int aoffset=alphaOffset[pf];
int aoffset=tjAlphaOffset[pf];
int ps=tjPixelSize[pf];
int i, j;