Replace INT32 with a new internal datatype (JLONG)
These days, INT32 is a commonly-defined datatype in system headers. We
cannot eliminate the definition of that datatype from jmorecfg.h, since
the INT32 typedef has technically been part of the libjpeg API since
version 5 (1994.) However, using INT32 internally is risky, because the
inclusion of a particular header (Xmd.h, for instance) could change the
definition of INT32 from long to int on 64-bit platforms and thus change
the internal behavior of libjpeg-turbo in unexpected ways (for instance,
failing to correctly set __INT32_IS_ACTUALLY_LONG to match the INT32
typedef-- perhaps as a result of including the wrong version of
jpeglib.h-- could cause libjpeg-turbo to produce incorrect results.)
The library has always been built in environments in which INT32 is
effectively long (on Windows, long is always 32-bit, so effectively it's
the same as int), so it makes sense to turn INT32 into an explicitly
long datatype. This ensures that libjpeg-turbo will always behave
consistently, regardless of the headers included at compile time.
Addresses a concern expressed in #26.
diff --git a/jdcolor.c b/jdcolor.c
index ac96b23..6a5d819 100644
--- a/jdcolor.c
+++ b/jdcolor.c
@@ -29,11 +29,11 @@
/* Private state for YCC->RGB conversion */
int * Cr_r_tab; /* => table for Cr to R conversion */
int * Cb_b_tab; /* => table for Cb to B conversion */
- INT32 * Cr_g_tab; /* => table for Cr to G conversion */
- INT32 * Cb_g_tab; /* => table for Cb to G conversion */
+ JLONG * Cr_g_tab; /* => table for Cr to G conversion */
+ JLONG * Cb_g_tab; /* => table for Cb to G conversion */
/* Private state for RGB->Y conversion */
- INT32 * rgb_y_tab; /* => table for RGB to Y conversion */
+ JLONG * rgb_y_tab; /* => table for RGB to Y conversion */
} my_color_deconverter;
typedef my_color_deconverter * my_cconvert_ptr;
@@ -74,8 +74,8 @@
*/
#define SCALEBITS 16 /* speediest right-shift on some machines */
-#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
-#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
+#define ONE_HALF ((JLONG) 1 << (SCALEBITS-1))
+#define FIX(x) ((JLONG) ((x) * (1L<<SCALEBITS) + 0.5))
/* We allocate one big table for RGB->Y conversion and divide it up into
* three parts, instead of doing three alloc_small requests. This lets us
@@ -212,7 +212,7 @@
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
int i;
- INT32 x;
+ JLONG x;
SHIFT_TEMPS
cconvert->Cr_r_tab = (int *)
@@ -221,12 +221,12 @@
cconvert->Cb_b_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(int));
- cconvert->Cr_g_tab = (INT32 *)
+ cconvert->Cr_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
- (MAXJSAMPLE+1) * sizeof(INT32));
- cconvert->Cb_g_tab = (INT32 *)
+ (MAXJSAMPLE+1) * sizeof(JLONG));
+ cconvert->Cb_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
- (MAXJSAMPLE+1) * sizeof(INT32));
+ (MAXJSAMPLE+1) * sizeof(JLONG));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
@@ -303,13 +303,13 @@
build_rgb_y_table (j_decompress_ptr cinfo)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
- INT32 * rgb_y_tab;
- INT32 i;
+ JLONG * rgb_y_tab;
+ JLONG i;
/* Allocate and fill in the conversion tables. */
- cconvert->rgb_y_tab = rgb_y_tab = (INT32 *)
+ cconvert->rgb_y_tab = rgb_y_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
- (TABLE_SIZE * sizeof(INT32)));
+ (TABLE_SIZE * sizeof(JLONG)));
for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i;
@@ -330,7 +330,7 @@
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
- register INT32 * ctab = cconvert->rgb_y_tab;
+ register JLONG * ctab = cconvert->rgb_y_tab;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
@@ -546,8 +546,8 @@
register JSAMPLE * range_limit = cinfo->sample_range_limit;
register int * Crrtab = cconvert->Cr_r_tab;
register int * Cbbtab = cconvert->Cb_b_tab;
- register INT32 * Crgtab = cconvert->Cr_g_tab;
- register INT32 * Cbgtab = cconvert->Cb_g_tab;
+ register JLONG * Crgtab = cconvert->Cr_g_tab;
+ register JLONG * Cbgtab = cconvert->Cb_g_tab;
SHIFT_TEMPS
while (--num_rows >= 0) {
@@ -605,7 +605,7 @@
#define DITHER_MASK 0x3
#define DITHER_ROTATE(x) (((x) << 24) | (((x) >> 8) & 0x00FFFFFF))
-static const INT32 dither_matrix[4] = {
+static const JLONG dither_matrix[4] = {
0x0008020A,
0x0C040E06,
0x030B0109,