#define strncasecmp _strnicmp
#else
#include <strings.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/times.h>
#endif /* _WIN32 */
#include "opj_apps_config.h"
fprintf(stdout, "[INFO] %s", msg);
}
+OPJ_FLOAT64 opj_clock(void) {
+#ifdef _WIN32
+ /* _WIN32: use QueryPerformance (very accurate) */
+ LARGE_INTEGER freq , t ;
+ /* freq is the clock speed of the CPU */
+ QueryPerformanceFrequency(&freq) ;
+ /* cout << "freq = " << ((double) freq.QuadPart) << endl; */
+ /* t is the high resolution performance counter (see MSDN) */
+ QueryPerformanceCounter ( & t ) ;
+ return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ;
+#else
+ /* Unix or Linux: use resource usage */
+ struct rusage t;
+ OPJ_FLOAT64 procTime;
+ /* (1) Get the rusage data structure at this moment (man getrusage) */
+ getrusage(0,&t);
+ /* (2) What is the elapsed time ? - CPU time = User time + System time */
+ /* (2a) Get the seconds */
+ procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
+ /* (2b) More precisely! Get the microseconds part ! */
+ return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
+#endif
+}
+
+
/* -------------------------------------------------------------------------- */
/**
* OPJ_COMPRESS MAIN
opj_codec_t* l_codec = 00;
opj_image_t *image = NULL;
raw_cparameters_t raw_cp;
+ OPJ_SIZE_T num_compressed_files = 0;
char indexfilename[OPJ_PATH_LEN]; /* index file name */
OPJ_BOOL bSuccess;
OPJ_BOOL bUseTiles = OPJ_FALSE; /* OPJ_TRUE */
OPJ_UINT32 l_nb_tiles = 4;
+ OPJ_FLOAT64 t = opj_clock();
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(¶meters);
return 1;
}
+ num_compressed_files++;
fprintf(stdout,"[INFO] Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */
opj_stream_destroy(l_stream);
if(parameters.cp_comment) free(parameters.cp_comment);
if(parameters.cp_matrice) free(parameters.cp_matrice);
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");
return 0;
}
#define strncasecmp _strnicmp
#else
#include <strings.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/times.h>
#endif /* _WIN32 */
#include "openjpeg.h"
}
}
+OPJ_FLOAT64 opj_clock(void) {
+#ifdef _WIN32
+ /* _WIN32: use QueryPerformance (very accurate) */
+ LARGE_INTEGER freq , t ;
+ /* freq is the clock speed of the CPU */
+ QueryPerformanceFrequency(&freq) ;
+ /* cout << "freq = " << ((double) freq.QuadPart) << endl; */
+ /* t is the high resolution performance counter (see MSDN) */
+ QueryPerformanceCounter ( & t ) ;
+ return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ;
+#else
+ /* Unix or Linux: use resource usage */
+ struct rusage t;
+ OPJ_FLOAT64 procTime;
+ /* (1) Get the rusage data structure at this moment (man getrusage) */
+ getrusage(0,&t);
+ /* (2) What is the elapsed time ? - CPU time = User time + System time */
+ /* (2a) Get the seconds */
+ procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
+ /* (2b) More precisely! Get the microseconds part ! */
+ return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
+#endif
+}
+
/* -------------------------------------------------------------------------- */
/**
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
int failed = 0;
+ OPJ_FLOAT64 t, tCumulative = 0;
+ OPJ_UINT32 numDecompressedImages = 0;
/* set decoding parameters to default values */
set_default_parameters(¶meters);
opj_set_warning_handler(l_codec, warning_callback,00);
opj_set_error_handler(l_codec, error_callback,00);
+ t = opj_clock();
+
/* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &(parameters.core)) ){
fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n");
fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index);
}
+ tCumulative += opj_clock() - t;
+ numDecompressedImages++;
+
/* Close the byte stream */
opj_stream_destroy(l_stream);
if(failed) remove(parameters.outfile);
}
destroy_parameters(¶meters);
+ fprintf(stdout, "decode time: %d ms \n", (int)( (tCumulative * 1000) / numDecompressedImages));
+ scanf("%d");
return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}
/*end main*/