Fix Windows build; Add grayscale tests to Windows build; Add proper implementation of snprintf on Windows and use snprintf() in TurboJPEG library and tests instead of sprintf()

This commit is contained in:
DRC
2011-03-02 02:17:30 +00:00
parent 43f33a4d19
commit 0c7b322efe
6 changed files with 57 additions and 58 deletions

View File

@@ -173,7 +173,7 @@ if(WITH_SIMD)
add_dependencies(jpeg-static simd) add_dependencies(jpeg-static simd)
endif() endif()
set(TURBOJPEG_SOURCES turbojpegl.c) set(TURBOJPEG_SOURCES turbojpegl.c transupp.c)
if(WITH_JNI) if(WITH_JNI)
set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES} turbojpeg-jni.c) set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES} turbojpeg-jni.c)
endif() endif()
@@ -187,7 +187,7 @@ target_link_libraries(turbojpeg jpeg-static)
set_target_properties(turbojpeg PROPERTIES LINK_INTERFACE_LIBRARIES "") set_target_properties(turbojpeg PROPERTIES LINK_INTERFACE_LIBRARIES "")
add_library(turbojpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS} add_library(turbojpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS}
turbojpegl.c) turbojpegl.c transupp.c)
if(NOT MSVC) if(NOT MSVC)
set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg) set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg)
endif() endif()
@@ -246,6 +246,8 @@ add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/t
else() else()
add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg) add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
endif() endif()
add_test(cjpeg-int-gray sharedlib/cjpeg -dct int -grayscale -outfile testoutgray.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
add_test(cjpeg-int-gray-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimggray.jpg testoutgray.jpg)
add_test(djpeg-int sharedlib/djpeg -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg) add_test(djpeg-int sharedlib/djpeg -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
add_test(djpeg-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm) add_test(djpeg-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
add_test(djpeg-fast sharedlib/djpeg -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg) add_test(djpeg-fast sharedlib/djpeg -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
@@ -291,6 +293,8 @@ add_test(cjpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE
else() else()
add_test(cjpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg) add_test(cjpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
endif() endif()
add_test(cjpeg-static-int-gray cjpeg-static -dct int -grayscale -outfile testoutgray.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
add_test(cjpeg-static-int-gray-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimggray.jpg testoutgray.jpg)
add_test(djpeg-static-int djpeg-static -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg) add_test(djpeg-static-int djpeg-static -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
add_test(djpeg-static-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm) add_test(djpeg-static-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
add_test(djpeg-static-fast djpeg-static -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg) add_test(djpeg-static-fast djpeg-static -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)

View File

@@ -17,10 +17,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "./rrtimer.h" #include "./rrtimer.h"
#include "./rrutil.h"
#include "./turbojpeg.h" #include "./turbojpeg.h"
#ifndef _WIN32
#define stricmp strcasecmp
#endif
#define _catch(f) {if((f)==-1) {printf("TJPEG: %s\n", tjGetErrorStr()); bailout();}} #define _catch(f) {if((f)==-1) {printf("TJPEG: %s\n", tjGetErrorStr()); bailout();}}
@@ -126,9 +124,10 @@ int checkbuf(unsigned char *buf, int w, int h, int ps, int subsamp,
{ {
int roffset=(flags&TJ_BGR)?2:0, goffset=1, boffset=(flags&TJ_BGR)?0:2, i, int roffset=(flags&TJ_BGR)?2:0, goffset=1, boffset=(flags&TJ_BGR)?0:2, i,
_i, j, retval=1; _i, j, retval=1;
int halfway=16*scale_num/scale_denom, blocksize=8*scale_num/scale_denom;
if(flags&TJ_ALPHAFIRST) {roffset++; goffset++; boffset++;} if(flags&TJ_ALPHAFIRST) {roffset++; goffset++; boffset++;}
if(ps==1) roffset=goffset=boffset=0; if(ps==1) roffset=goffset=boffset=0;
int halfway=16*scale_num/scale_denom, blocksize=8*scale_num/scale_denom;
for(_i=0; _i<halfway; _i++) for(_i=0; _i<halfway; _i++)
{ {
@@ -356,10 +355,10 @@ void gentestjpeg(tjhandle hnd, unsigned char *jpegbuf, unsigned long *size,
t=rrtime()-t; t=rrtime()-t;
if(yuv==YUVENCODE) if(yuv==YUVENCODE)
sprintf(tempstr, "%s_enc_%s_%s_%s.yuv", basefilename, pixformat, snprintf(tempstr, 1024, "%s_enc_%s_%s_%s.yuv", basefilename, pixformat,
(flags&TJ_BOTTOMUP)? "BU":"TD", _subnames[subsamp]); (flags&TJ_BOTTOMUP)? "BU":"TD", _subnames[subsamp]);
else else
sprintf(tempstr, "%s_enc_%s_%s_%sQ%d.jpg", basefilename, pixformat, snprintf(tempstr, 1024, "%s_enc_%s_%s_%sQ%d.jpg", basefilename, pixformat,
(flags&TJ_BOTTOMUP)? "BU":"TD", _subnames[subsamp], qual); (flags&TJ_BOTTOMUP)? "BU":"TD", _subnames[subsamp], qual);
writejpeg(jpegbuf, *size, tempstr); writejpeg(jpegbuf, *size, tempstr);
if(yuv==YUVENCODE) if(yuv==YUVENCODE)

View File

@@ -54,13 +54,13 @@ void printsigfig(double val, int figs)
if(_l<0.) if(_l<0.)
{ {
l=(int)fabs(_l); l=(int)fabs(_l);
sprintf(format, "%%%d.%df", figs+l+2, figs+l); snprintf(format, 80, "%%%d.%df", figs+l+2, figs+l);
} }
else else
{ {
l=(int)_l+1; l=(int)_l+1;
if(figs<=l) sprintf(format, "%%.0f"); if(figs<=l) snprintf(format, 80, "%%.0f");
else sprintf(format, "%%%d.%df", figs+1, figs-l); else snprintf(format, 80, "%%%d.%df", figs+1, figs-l);
} }
printf(format, val); printf(format, val);
} }
@@ -70,7 +70,7 @@ int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf,
unsigned long *comptilesize, unsigned char *rgbbuf, int w, int h, unsigned long *comptilesize, unsigned char *rgbbuf, int w, int h,
int jpegsub, int qual, char *filename, int tilesizex, int tilesizey) int jpegsub, int qual, char *filename, int tilesizex, int tilesizey)
{ {
char tempstr[1024], qualstr[5]="\0"; char tempstr[1024], qualstr[5]="\0", *ptr;
FILE *outfile=NULL; tjhandle hnd=NULL; FILE *outfile=NULL; tjhandle hnd=NULL;
int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0) int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0)
|(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0) |(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0)
@@ -152,7 +152,8 @@ int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf,
} }
if(yuv==YUVDECODE) if(yuv==YUVDECODE)
{ {
sprintf(tempstr, "%s_%s%s.yuv", filename, _subnames[jpegsub], qualstr); snprintf(tempstr, 1024, "%s_%s%s.yuv", filename, _subnames[jpegsub],
qualstr);
if((outfile=fopen(tempstr, "wb"))==NULL) if((outfile=fopen(tempstr, "wb"))==NULL)
_throwunix("opening YUV image for output"); _throwunix("opening YUV image for output");
if(fwrite(rgbbuf, yuvsize, 1, outfile)!=1) if(fwrite(rgbbuf, yuvsize, 1, outfile)!=1)
@@ -164,16 +165,17 @@ int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf,
if(tilesizex==w && tilesizey==h) if(tilesizex==w && tilesizey==h)
{ {
if(decomponly) if(decomponly)
sprintf(tempstr, "%s_full.%s", filename, useppm?"ppm":"bmp"); snprintf(tempstr, 1024, "%s_full.%s", filename, useppm?"ppm":"bmp");
else else
sprintf(tempstr, "%s_%s%s_full.%s", filename, _subnames[jpegsub], snprintf(tempstr, 1024, "%s_%s%s_full.%s", filename,
qualstr, useppm?"ppm":"bmp"); _subnames[jpegsub], qualstr, useppm?"ppm":"bmp");
} }
else sprintf(tempstr, "%s_%s%s_%dx%d.%s", filename, _subnames[jpegsub], else snprintf(tempstr, 1024, "%s_%s%s_%dx%d.%s", filename,
qualstr, tilesizex, tilesizey, useppm?"ppm":"bmp"); _subnames[jpegsub], qualstr, tilesizex, tilesizey, useppm?"ppm":"bmp");
if(savebmp(tempstr, rgbbuf, scaledw, scaledh, pf, pitch, bu)==-1) if(savebmp(tempstr, rgbbuf, scaledw, scaledh, pf, pitch, bu)==-1)
_throwbmp("saving bitmap"); _throwbmp("saving bitmap");
sprintf(strrchr(tempstr, '.'), "-err.%s", useppm?"ppm":"bmp"); ptr=strrchr(tempstr, '.');
snprintf(ptr, 1024-(ptr-tempstr), "-err.%s", useppm?"ppm":"bmp");
if(srcbuf && scale_num==1 && scale_denom==1) if(srcbuf && scale_num==1 && scale_denom==1)
{ {
if(!quiet) if(!quiet)
@@ -337,9 +339,10 @@ void dotest(unsigned char *srcbuf, int w, int h, int jpegsub, int qual,
if(tilesizex==w && tilesizey==h) if(tilesizex==w && tilesizey==h)
{ {
if(yuv==YUVENCODE) if(yuv==YUVENCODE)
sprintf(tempstr, "%s_%s.yuv", filename, _subnames[jpegsub]); snprintf(tempstr, 1024, "%s_%s.yuv", filename, _subnames[jpegsub]);
else else
sprintf(tempstr, "%s_%sQ%d.jpg", filename, _subnames[jpegsub], qual); snprintf(tempstr, 1024, "%s_%sQ%d.jpg", filename, _subnames[jpegsub],
qual);
if((outfile=fopen(tempstr, "wb"))==NULL) if((outfile=fopen(tempstr, "wb"))==NULL)
_throwunix("opening reference image"); _throwunix("opening reference image");
if(fwrite(jpegbuf[0], jpgbufsize, 1, outfile)!=1) if(fwrite(jpegbuf[0], jpgbufsize, 1, outfile)!=1)

View File

@@ -18,8 +18,8 @@
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#define sleep(t) Sleep((t)*1000) #define snprintf(str, n, format, ...) \
#define usleep(t) Sleep((t)/1000) _snprintf_s(str, n, _TRUNCATE, format, __VA_ARGS__)
#else #else
#include <unistd.h> #include <unistd.h>
#define stricmp strcasecmp #define stricmp strcasecmp
@@ -37,30 +37,10 @@
#define pow2(i) (1<<(i)) #define pow2(i) (1<<(i))
#define isPow2(x) (((x)&(x-1))==0) #define isPow2(x) (((x)&(x-1))==0)
#ifdef sgi
#define _SC_NPROCESSORS_CONF _SC_NPROC_CONF
#endif
#ifdef sun #ifdef sun
#define __inline inline #define __inline inline
#endif #endif
static __inline int numprocs(void)
{
#ifdef _WIN32
DWORD_PTR ProcAff, SysAff, i; int count=0;
if(!GetProcessAffinityMask(GetCurrentProcess(), &ProcAff, &SysAff)) return(1);
for(i=0; i<sizeof(long*)*8; i++) if(ProcAff&(1LL<<i)) count++;
return(count);
#elif defined (__APPLE__)
return(1);
#else
long count=1;
if((count=sysconf(_SC_NPROCESSORS_CONF))!=-1) return((int)count);
else return(1);
#endif
}
#define byteswap(i) ( \ #define byteswap(i) ( \
(((i) & 0xff000000) >> 24) | \ (((i) & 0xff000000) >> 24) | \
(((i) & 0x00ff0000) >> 8) | \ (((i) & 0x00ff0000) >> 8) | \

View File

@@ -22,16 +22,16 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug"
endif() endif()
if(SIMD_X86_64) if(SIMD_X86_64)
set(SIMD_BASENAMES jfsseflt-64 jccolss2-64 jdcolss2-64 jcsamss2-64 set(SIMD_BASENAMES jfsseflt-64 jccolss2-64 jdcolss2-64 jcgrass2-64
jdsamss2-64 jdmerss2-64 jcqnts2i-64 jfss2fst-64 jfss2int-64 jiss2red-64 jcsamss2-64 jdsamss2-64 jdmerss2-64 jcqnts2i-64 jfss2fst-64 jfss2int-64
jiss2int-64 jiss2fst-64 jcqnts2f-64 jiss2flt-64) jiss2red-64 jiss2int-64 jiss2fst-64 jcqnts2f-64 jiss2flt-64)
message(STATUS "Building x86_64 SIMD extensions") message(STATUS "Building x86_64 SIMD extensions")
else() else()
set(SIMD_BASENAMES jsimdcpu jccolmmx jdcolmmx jcsammmx jdsammmx jdmermmx set(SIMD_BASENAMES jsimdcpu jccolmmx jcgrammx jdcolmmx jcsammmx jdsammmx
jcqntmmx jfmmxfst jfmmxint jimmxred jimmxint jimmxfst jcqnt3dn jf3dnflt jdmermmx jcqntmmx jfmmxfst jfmmxint jimmxred jimmxint jimmxfst jcqnt3dn
ji3dnflt jcqntsse jfsseflt jisseflt jccolss2 jdcolss2 jcsamss2 jdsamss2 jf3dnflt ji3dnflt jcqntsse jfsseflt jisseflt jccolss2 jcgrass2 jdcolss2
jdmerss2 jcqnts2i jfss2fst jfss2int jiss2red jiss2int jiss2fst jcqnts2f jcsamss2 jdsamss2 jdmerss2 jcqnts2i jfss2fst jfss2int jiss2red jiss2int
jiss2flt) jiss2fst jcqnts2f jiss2flt)
message(STATUS "Building i386 SIMD extensions") message(STATUS "Building i386 SIMD extensions")
endif() endif()

View File

@@ -23,6 +23,7 @@
#include <jerror.h> #include <jerror.h>
#include <setjmp.h> #include <setjmp.h>
#include "./turbojpeg.h" #include "./turbojpeg.h"
#include "./rrutil.h"
#include "transupp.h" #include "transupp.h"
#ifndef min #ifndef min
@@ -82,9 +83,10 @@ static const tjscalingfactor sf[NUMSF]={
{1, 8} {1, 8}
}; };
#define _throw(c) {sprintf(lasterror, "%s", c); retval=-1; goto bailout;} #define _throw(c) {snprintf(lasterror, JMSG_LENGTH_MAX, "%s", c); \
retval=-1; goto bailout;}
#define checkhandle(h) jpgstruct *j=(jpgstruct *)h; \ #define checkhandle(h) jpgstruct *j=(jpgstruct *)h; \
if(!j) {sprintf(lasterror, "Invalid handle"); return -1;} if(!j) {snprintf(lasterror, JMSG_LENGTH_MAX, "Invalid handle"); return -1;}
// CO // CO
@@ -124,7 +126,10 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void)
{ {
jpgstruct *j=NULL; jpgstruct *j=NULL;
if((j=(jpgstruct *)malloc(sizeof(jpgstruct)))==NULL) if((j=(jpgstruct *)malloc(sizeof(jpgstruct)))==NULL)
{sprintf(lasterror, "Memory allocation failure"); return NULL;} {
snprintf(lasterror, JMSG_LENGTH_MAX, "Memory allocation failure");
return NULL;
}
memset(j, 0, sizeof(jpgstruct)); memset(j, 0, sizeof(jpgstruct));
return _tjInitCompress(j); return _tjInitCompress(j);
} }
@@ -408,7 +413,10 @@ DLLEXPORT tjhandle DLLCALL tjInitDecompress(void)
{ {
jpgstruct *j; jpgstruct *j;
if((j=(jpgstruct *)malloc(sizeof(jpgstruct)))==NULL) if((j=(jpgstruct *)malloc(sizeof(jpgstruct)))==NULL)
{sprintf(lasterror, "Memory allocation failure"); return NULL;} {
snprintf(lasterror, JMSG_LENGTH_MAX, "Memory allocation failure");
return NULL;
}
memset(j, 0, sizeof(jpgstruct)); memset(j, 0, sizeof(jpgstruct));
return _tjInitDecompress(j); return _tjInitDecompress(j);
} }
@@ -483,7 +491,8 @@ DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors)
{ {
if(numscalingfactors==NULL) if(numscalingfactors==NULL)
{ {
sprintf(lasterror, "Invalid argument in tjGetScalingFactors()"); snprintf(lasterror, JMSG_LENGTH_MAX,
"Invalid argument in tjGetScalingFactors()");
return NULL; return NULL;
} }
@@ -691,7 +700,10 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void)
{ {
jpgstruct *j=NULL; tjhandle tj=NULL; jpgstruct *j=NULL; tjhandle tj=NULL;
if((j=(jpgstruct *)malloc(sizeof(jpgstruct)))==NULL) if((j=(jpgstruct *)malloc(sizeof(jpgstruct)))==NULL)
{sprintf(lasterror, "Memory allocation failure"); return NULL;} {
snprintf(lasterror, JMSG_LENGTH_MAX, "Memory allocation failure");
return NULL;
}
memset(j, 0, sizeof(jpgstruct)); memset(j, 0, sizeof(jpgstruct));
tj=_tjInitCompress(j); tj=_tjInitCompress(j);
if(!tj) return NULL; if(!tj) return NULL;
@@ -773,7 +785,8 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle hnd,
{ {
if((x%xinfo.iMCU_sample_width)!=0 || (y%xinfo.iMCU_sample_height)!=0) if((x%xinfo.iMCU_sample_width)!=0 || (y%xinfo.iMCU_sample_height)!=0)
{ {
sprintf(lasterror, "To crop this JPEG image, x must be a multiple of %d and y must be a multiple\n" snprintf(lasterror, JMSG_LENGTH_MAX,
"To crop this JPEG image, x must be a multiple of %d and y must be a multiple\n"
"of %d.\n", xinfo.iMCU_sample_width, xinfo.iMCU_sample_height); "of %d.\n", xinfo.iMCU_sample_width, xinfo.iMCU_sample_height);
retval=-1; goto bailout; retval=-1; goto bailout;
} }