From 63476863856513a5bc3aa40654395977b0f9f9df Mon Sep 17 00:00:00 2001 From: Aaron Boxer Date: Sat, 20 Jun 2015 00:01:19 -0400 Subject: [PATCH] fixed a few bugs --- src/bin/jp2/opj_compress.c | 7 ++++--- src/bin/jp2/opj_decompress.c | 7 ++++--- src/lib/openjp2/opj_includes.h | 32 ++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 9ad6175f..ba3bb281 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -1547,7 +1547,7 @@ OPJ_FLOAT64 opj_clock(void) { /* cout << "freq = " << ((double) freq.QuadPart) << endl; */ /* t is the high resolution performance counter (see MSDN) */ QueryPerformanceCounter ( & t ) ; - return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ; + return freq.QuadPart ? ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) : 0 ; #else /* Unix or Linux: use resource usage */ struct rusage t; @@ -1871,8 +1871,9 @@ int main(int argc, char **argv) { if(raw_cp.rawComps) free(raw_cp.rawComps); t = opj_clock() - t; - fprintf(stdout, "encode time: %d ms \n", (int)((t * 1000)/num_compressed_files)); - scanf("%d"); + if (num_compressed_files) + fprintf(stdout, "encode time: %d ms \n", (int)((t * 1000)/num_compressed_files)); + //getch()); return 0; } diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index cfc04a9e..c6e5cff8 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -852,7 +852,7 @@ OPJ_FLOAT64 opj_clock(void) { /* cout << "freq = " << ((double) freq.QuadPart) << endl; */ /* t is the high resolution performance counter (see MSDN) */ QueryPerformanceCounter ( & t ) ; - return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ; + return freq.QuadPart ? (t.QuadPart / (OPJ_FLOAT64)freq.QuadPart) : 0; #else /* Unix or Linux: use resource usage */ struct rusage t; @@ -1535,8 +1535,9 @@ int main(int argc, char **argv) if(failed) remove(parameters.outfile); } destroy_parameters(¶meters); - fprintf(stdout, "decode time: %d ms \n", (int)( (tCumulative * 1000) / numDecompressedImages)); - scanf("%d"); + if (numDecompressedImages) + fprintf(stdout, "decode time: %d ms \n", (int)( (tCumulative * 1000) / numDecompressedImages)); + //getch(); return failed ? EXIT_FAILURE : EXIT_SUCCESS; } /*end main*/ diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index 8fbe1a53..d0130028 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -118,15 +118,20 @@ #endif #endif + + /* MSVC before 2013 and Borland C do not have lrintf */ -#if defined(_MSC_VER) || defined(__BORLANDC__) +#if defined(_MSC_VER) +#include static INLINE long lrintf(float f){ #ifdef _M_X64 - return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); + return _mm_cvt_ss2si(_mm_load_ss(&f)); + + // commented out line breaks many tests + ///return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); #else int i; - - _asm{ + _asm{ fld f fistp i }; @@ -136,6 +141,25 @@ static INLINE long lrintf(float f){ } #endif +#if defined(__BORLANDC__) +static INLINE long lrintf(float f) { +#ifdef _M_X64 + return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); +#else + int i; + + _asm { + fld f + fistp i + }; + + return i; +#endif +} +#endif + + + #if defined(_MSC_VER) && (_MSC_VER < 1400) #define vsnprintf _vsnprintf #endif