Win: Fix build with Visual Studio 2010

(broken by 607b668ff9)

- Visual Studio 2010 apparently doesn't have the snprintf() inline
  function, so restore the macro that emulates that function using
  _snprintf_s().

- Explicitly include errno.h in strtest.c, since jinclude.h doesn't
  include it when building with Visual Studio.
This commit is contained in:
DRC
2022-03-11 10:50:47 -06:00
parent f3c716a2bc
commit a014845403
9 changed files with 64 additions and 35 deletions

View File

@@ -10,7 +10,7 @@ if(CMAKE_EXECUTABLE_SUFFIX)
endif()
project(libjpeg-turbo C)
set(VERSION 2.1.3)
set(VERSION 2.1.4)
set(COPYRIGHT_YEAR "1991-2022")
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)

View File

@@ -1,3 +1,12 @@
2.1.4
=====
### Significant changes relative to 2.1.3
1. Fixed a regression introduced in 2.1.3 that caused build failures with
Visual Studio 2010.
2.1.3
=====

View File

@@ -189,9 +189,9 @@ format_message(j_common_ptr cinfo, char *buffer)
/* Format the message into the passed buffer */
if (isstring)
snprintf(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
else
snprintf(buffer, JMSG_LENGTH_MAX, msgtext,
SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext,
err->msg_parm.i[0], err->msg_parm.i[1],
err->msg_parm.i[2], err->msg_parm.i[3],
err->msg_parm.i[4], err->msg_parm.i[5],

View File

@@ -45,6 +45,18 @@
*/
#ifdef _MSC_VER
#define SNPRINTF(str, n, format, ...) \
_snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
#else
#define SNPRINTF snprintf
#endif
#ifndef NO_GETENV
#ifdef _MSC_VER

View File

@@ -27,6 +27,7 @@
*/
#include "jinclude.h"
#include <errno.h>
#define CHECK_VALUE(actual, expected, desc) \

View File

@@ -107,7 +107,7 @@ static char *formatName(int subsamp, int cs, char *buf)
if (cs == TJCS_YCbCr)
return (char *)subNameLong[subsamp];
else if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
snprintf(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
SNPRINTF(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
return buf;
} else
return (char *)csName[cs];
@@ -120,10 +120,10 @@ static char *sigfig(double val, int figs, char *buf, int len)
int digitsAfterDecimal = figs - (int)ceil(log10(fabs(val)));
if (digitsAfterDecimal < 1)
snprintf(format, 80, "%%.0f");
SNPRINTF(format, 80, "%%.0f");
else
snprintf(format, 80, "%%.%df", digitsAfterDecimal);
snprintf(buf, len, format, val);
SNPRINTF(format, 80, "%%.%df", digitsAfterDecimal);
SNPRINTF(buf, len, format, val);
return buf;
}
@@ -160,7 +160,7 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
if (jpegQual > 0) {
snprintf(qualStr, 13, "_Q%d", jpegQual);
SNPRINTF(qualStr, 13, "_Q%d", jpegQual);
qualStr[12] = 0;
}
@@ -262,20 +262,20 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
if (!doWrite) goto bailout;
if (sf.num != 1 || sf.denom != 1)
snprintf(sizeStr, 24, "%d_%d", sf.num, sf.denom);
SNPRINTF(sizeStr, 24, "%d_%d", sf.num, sf.denom);
else if (tilew != w || tileh != h)
snprintf(sizeStr, 24, "%dx%d", tilew, tileh);
else snprintf(sizeStr, 24, "full");
SNPRINTF(sizeStr, 24, "%dx%d", tilew, tileh);
else SNPRINTF(sizeStr, 24, "full");
if (decompOnly)
snprintf(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
SNPRINTF(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
else
snprintf(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
SNPRINTF(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
qualStr, sizeStr, ext);
if (tjSaveImage(tempStr, dstBuf, scaledw, 0, scaledh, pf, flags) == -1)
THROW_TJG("saving bitmap");
ptr = strrchr(tempStr, '.');
snprintf(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
SNPRINTF(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
if (srcBuf && sf.num == 1 && sf.denom == 1) {
if (!quiet) printf("Compression error written to %s.\n", tempStr);
if (subsamp == TJ_GRAYSCALE) {
@@ -478,7 +478,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
(double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed);
}
if (tilew == w && tileh == h && doWrite) {
snprintf(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
SNPRINTF(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
jpegQual);
if ((file = fopen(tempStr, "wb")) == NULL)
THROW_UNIX("opening reference image");

View File

@@ -409,7 +409,7 @@ static void compTest(tjhandle handle, unsigned char **dstBuf,
jpegQual, flags));
}
snprintf(tempStr, 1024, "%s_enc_%s_%s_%s_Q%d.jpg", basename, pfStr, buStr,
SNPRINTF(tempStr, 1024, "%s_enc_%s_%s_%s_Q%d.jpg", basename, pfStr, buStr,
subName[subsamp], jpegQual);
writeJPEG(*dstBuf, *dstSize, tempStr);
printf("Done.\n Result in %s\n", tempStr);
@@ -782,7 +782,7 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
THROW("Could not allocate memory");
initBitmap(buf, width, pitch, height, pf, flags);
snprintf(filename, 80, "test_bmp_%s_%d_%s.%s", pixFormatStr[pf], align,
SNPRINTF(filename, 80, "test_bmp_%s_%d_%s.%s", pixFormatStr[pf], align,
(flags & TJFLAG_BOTTOMUP) ? "bu" : "td", ext);
TRY_TJ(tjSaveImage(filename, buf, width, pitch, height, pf, flags));
md5sum = MD5File(filename, md5buf);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C)2011 D. R. Commander. All Rights Reserved.
* Copyright (C)2011, 2022 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -31,6 +31,13 @@
#define strncasecmp strnicmp
#endif
#ifdef _MSC_VER
#define SNPRINTF(str, n, format, ...) \
_snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
#else
#define SNPRINTF snprintf
#endif
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

View File

@@ -126,9 +126,9 @@ static void my_progress_monitor(j_common_ptr dinfo)
int scan_no = ((j_decompress_ptr)dinfo)->input_scan_number;
if (scan_no > 500) {
snprintf(myprog->this->errStr, JMSG_LENGTH_MAX,
SNPRINTF(myprog->this->errStr, JMSG_LENGTH_MAX,
"Progressive JPEG image has more than 500 scans");
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"Progressive JPEG image has more than 500 scans");
myprog->this->isInstanceError = TRUE;
myerr->warning = FALSE;
@@ -191,24 +191,24 @@ static int cs2pf[JPEG_NUMCS] = {
};
#define THROWG(m) { \
snprintf(errStr, JMSG_LENGTH_MAX, "%s", m); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s", m); \
retval = -1; goto bailout; \
}
#ifdef _MSC_VER
#define THROW_UNIX(m) { \
char strerrorBuf[80] = { 0 }; \
strerror_s(strerrorBuf, 80, errno); \
snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerrorBuf); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerrorBuf); \
retval = -1; goto bailout; \
}
#else
#define THROW_UNIX(m) { \
snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerror(errno)); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerror(errno)); \
retval = -1; goto bailout; \
}
#endif
#define THROW(m) { \
snprintf(this->errStr, JMSG_LENGTH_MAX, "%s", m); \
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s", m); \
this->isInstanceError = TRUE; THROWG(m) \
}
@@ -223,7 +223,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_decompress_ptr dinfo = NULL; \
\
if (!this) { \
snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
cinfo = &this->cinfo; dinfo = &this->dinfo; \
@@ -235,7 +235,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_compress_ptr cinfo = NULL; \
\
if (!this) { \
snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
cinfo = &this->cinfo; \
@@ -247,7 +247,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_decompress_ptr dinfo = NULL; \
\
if (!this) { \
snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
dinfo = &this->dinfo; \
@@ -519,12 +519,12 @@ DLLEXPORT tjhandle tjInitCompress(void)
tjinstance *this = NULL;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitCompress(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
return _tjInitCompress(this);
}
@@ -1193,12 +1193,12 @@ DLLEXPORT tjhandle tjInitDecompress(void)
tjinstance *this;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitDecompress(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
return _tjInitDecompress(this);
}
@@ -1277,7 +1277,7 @@ DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf,
DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors)
{
if (numscalingfactors == NULL) {
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjGetScalingFactors(): Invalid argument");
return NULL;
}
@@ -1884,12 +1884,12 @@ DLLEXPORT tjhandle tjInitTransform(void)
tjhandle handle = NULL;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitTransform(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
handle = _tjInitCompress(this);
if (!handle) return NULL;
handle = _tjInitDecompress(this);
@@ -1980,7 +1980,7 @@ DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf,
if (xinfo[i].crop) {
if ((t[i].r.x % tjMCUWidth[jpegSubsamp]) != 0 ||
(t[i].r.y % tjMCUHeight[jpegSubsamp]) != 0) {
snprintf(this->errStr, JMSG_LENGTH_MAX,
SNPRINTF(this->errStr, JMSG_LENGTH_MAX,
"To crop this JPEG image, x must be a multiple of %d\n"
"and y must be a multiple of %d.\n",
tjMCUWidth[jpegSubsamp], tjMCUHeight[jpegSubsamp]);