From da5220acdd525242bff4e40b1d90324ebb889825 Mon Sep 17 00:00:00 2001 From: DRC Date: Wed, 2 Mar 2011 02:17:30 +0000 Subject: [PATCH] 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() git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@486 632fc199-4ca6-4c93-a231-07263d6284db --- CMakeLists.txt | 8 ++++++-- jpegut.c | 11 +++++------ jpgtest.c | 29 ++++++++++++++++------------- rrutil.h | 24 ++---------------------- simd/CMakeLists.txt | 16 ++++++++-------- turbojpegl.c | 27 ++++++++++++++++++++------- 6 files changed, 57 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7dc27f..74ec2a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,7 +173,7 @@ if(WITH_SIMD) add_dependencies(jpeg-static simd) endif() -set(TURBOJPEG_SOURCES turbojpegl.c) +set(TURBOJPEG_SOURCES turbojpegl.c transupp.c) if(WITH_JNI) set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES} turbojpeg-jni.c) endif() @@ -187,7 +187,7 @@ target_link_libraries(turbojpeg jpeg-static) set_target_properties(turbojpeg PROPERTIES LINK_INTERFACE_LIBRARIES "") add_library(turbojpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS} - turbojpegl.c) + turbojpegl.c transupp.c) if(NOT MSVC) set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg) endif() @@ -246,6 +246,8 @@ add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/t else() add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg) 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-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) @@ -291,6 +293,8 @@ add_test(cjpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE else() add_test(cjpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg) 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-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) diff --git a/jpegut.c b/jpegut.c index 4486c07..70f4fc8 100644 --- a/jpegut.c +++ b/jpegut.c @@ -17,10 +17,8 @@ #include #include #include "./rrtimer.h" +#include "./rrutil.h" #include "./turbojpeg.h" -#ifndef _WIN32 - #define stricmp strcasecmp -#endif #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, _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(ps==1) roffset=goffset=boffset=0; - int halfway=16*scale_num/scale_denom, blocksize=8*scale_num/scale_denom; for(_i=0; _i - #define sleep(t) Sleep((t)*1000) - #define usleep(t) Sleep((t)/1000) + #define snprintf(str, n, format, ...) \ + _snprintf_s(str, n, _TRUNCATE, format, __VA_ARGS__) #else #include #define stricmp strcasecmp @@ -37,30 +37,10 @@ #define pow2(i) (1<<(i)) #define isPow2(x) (((x)&(x-1))==0) -#ifdef sgi -#define _SC_NPROCESSORS_CONF _SC_NPROC_CONF -#endif - #ifdef sun #define __inline inline #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> 24) | \ (((i) & 0x00ff0000) >> 8) | \ diff --git a/simd/CMakeLists.txt b/simd/CMakeLists.txt index 5be325e..b1977ce 100755 --- a/simd/CMakeLists.txt +++ b/simd/CMakeLists.txt @@ -22,16 +22,16 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug" endif() if(SIMD_X86_64) - set(SIMD_BASENAMES jfsseflt-64 jccolss2-64 jdcolss2-64 jcsamss2-64 - jdsamss2-64 jdmerss2-64 jcqnts2i-64 jfss2fst-64 jfss2int-64 jiss2red-64 - jiss2int-64 jiss2fst-64 jcqnts2f-64 jiss2flt-64) + set(SIMD_BASENAMES jfsseflt-64 jccolss2-64 jdcolss2-64 jcgrass2-64 + jcsamss2-64 jdsamss2-64 jdmerss2-64 jcqnts2i-64 jfss2fst-64 jfss2int-64 + jiss2red-64 jiss2int-64 jiss2fst-64 jcqnts2f-64 jiss2flt-64) message(STATUS "Building x86_64 SIMD extensions") else() - set(SIMD_BASENAMES jsimdcpu jccolmmx jdcolmmx jcsammmx jdsammmx jdmermmx - jcqntmmx jfmmxfst jfmmxint jimmxred jimmxint jimmxfst jcqnt3dn jf3dnflt - ji3dnflt jcqntsse jfsseflt jisseflt jccolss2 jdcolss2 jcsamss2 jdsamss2 - jdmerss2 jcqnts2i jfss2fst jfss2int jiss2red jiss2int jiss2fst jcqnts2f - jiss2flt) + set(SIMD_BASENAMES jsimdcpu jccolmmx jcgrammx jdcolmmx jcsammmx jdsammmx + jdmermmx jcqntmmx jfmmxfst jfmmxint jimmxred jimmxint jimmxfst jcqnt3dn + jf3dnflt ji3dnflt jcqntsse jfsseflt jisseflt jccolss2 jcgrass2 jdcolss2 + jcsamss2 jdsamss2 jdmerss2 jcqnts2i jfss2fst jfss2int jiss2red jiss2int + jiss2fst jcqnts2f jiss2flt) message(STATUS "Building i386 SIMD extensions") endif() diff --git a/turbojpegl.c b/turbojpegl.c index 4ae41b7..dc1578d 100644 --- a/turbojpegl.c +++ b/turbojpegl.c @@ -23,6 +23,7 @@ #include #include #include "./turbojpeg.h" +#include "./rrutil.h" #include "transupp.h" #ifndef min @@ -82,9 +83,10 @@ static const tjscalingfactor sf[NUMSF]={ {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; \ - if(!j) {sprintf(lasterror, "Invalid handle"); return -1;} + if(!j) {snprintf(lasterror, JMSG_LENGTH_MAX, "Invalid handle"); return -1;} // CO @@ -124,7 +126,10 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void) { jpgstruct *j=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)); return _tjInitCompress(j); } @@ -408,7 +413,10 @@ DLLEXPORT tjhandle DLLCALL tjInitDecompress(void) { jpgstruct *j; 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)); return _tjInitDecompress(j); } @@ -483,7 +491,8 @@ DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors) { if(numscalingfactors==NULL) { - sprintf(lasterror, "Invalid argument in tjGetScalingFactors()"); + snprintf(lasterror, JMSG_LENGTH_MAX, + "Invalid argument in tjGetScalingFactors()"); return NULL; } @@ -691,7 +700,10 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void) { jpgstruct *j=NULL; tjhandle tj=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)); tj=_tjInitCompress(j); 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) { - 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); retval=-1; goto bailout; } -- 2.40.0